76 lines · 1.8 KB · Text
RawDownload
.TH ENCRYPT 2.SH NAMEencrypt, decrypt, netcrypt \- DES encryption.SH SYNOPSIS.B #include <u.h>.br.B #include <libc.h>.PP.Bint	encrypt(void *key, void *data, int len).PP.Bint	decrypt(void *key, void *data, int len).PP.Bint	netcrypt(void *key, void *data).SH DESCRIPTION.I Encryptand.I decryptperform DES encryption and decryption..I Keyis an array of.B DESKEYLEN(defined as 7 in.BR <auth.h> )bytes containing the encryption key..I Datais an array of.I lenbytes;it must be at least 8 bytes long.The bytes are encrypted or decrypted in place..PPThe DES algorithm encrypts an individual 8-byte block of data..I Encryptuses the following method to encrypt data longer than 8 bytes.The first 8 bytes are encrypted as usual.The last byte of the encrypted resultis prefixed to the next 7 unencrypted bytes to make the next 8bytes to encrypt.This is repeated until fewer than 7 bytes remain unencrypted.Any remaining unencrypted bytes are encrypted with enough of the precedingencrypted bytes to make a full 8-byte block..I Decryptuses the inverse algorithm..PP.I Netcryptperforms the same encryption as a SecureNet Key..I Datapoints to an.SM ASCIIstring of decimal digits with numeric value between 0 and 10000.These digits are copied into an 8-byte buffer with trailing binary zero filland encrypted as one DES block.The first four bytes are each formatted as two digit.SM ASCIIhexadecimal numbers,and the string is copied into.IR data ..SH SOURCE.B /sys/src/libc/port.SH DIAGNOSTICSThese routines return 1 if the data was encrypted,and 0 if the encryption fails..I Encryptand.I decryptfail if the data passed is less than 8 bytes long..I Netcryptcan fail if it is passed invalid data..SH SEE ALSO.IR securenet (8).SH BUGSThe implementation is broken in a way that makesit unsuitable for anything but authentication.