📄 des_crypt.man
字号:
.TH DES_CRYPT 3 .SH NAMEdes_read_password, des_read_2password,des_string_to_key, des_string_to_2key, des_read_pw_string,des_random_key, des_set_key,des_key_sched, des_ecb_encrypt, des_3ecb_encrypt, des_cbc_encrypt,des_3cbc_encrypt,des_pcbc_encrypt, des_cfb_encrypt, des_ofb_encrypt,des_cbc_cksum, des_quad_cksum,des_enc_read, des_enc_write, des_set_odd_parity,des_is_weak_key, crypt \- (non USA) DES encryption.SH SYNOPSIS.nf.nj.ft B#include <des.h>.PP.B int des_read_password(key,prompt,verify)des_cblock *key;char *prompt;int verify;.PP.B int des_read_2password(key1,key2,prompt,verify)des_cblock *key1,*key2;char *prompt;int verify;.PP.B int des_string_to_key(str,key)char *str;des_cblock *key;.PP.B int des_string_to_2keys(str,key1,key2)char *str;des_cblock *key1,*key2;.PP.B int des_read_pw_string(buf,length,prompt,verify)char *buf;int length;char *prompt;int verify;.PP.B int des_random_key(key)des_cblock *key;.PP.B int des_set_key(key,schedule)des_cblock *key;des_key_schedule schedule;.PP.B int des_key_sched(key,schedule)des_cblock *key;des_key_schedule schedule;.PP.B int des_ecb_encrypt(input,output,schedule,encrypt)des_cblock *input;des_cblock *output;des_key_schedule schedule;int encrypt;.PP.B int des_3ecb_encrypt(input,output,ks1,ks2,encrypt)des_cblock *input;des_cblock *output;des_key_schedule ks1,ks2;int encrypt;.PP.B int des_cbc_encrypt(input,output,length,schedule,ivec,encrypt)des_cblock *input;des_cblock *output;long length;des_key_schedule schedule;des_cblock *ivec;int encrypt;.PP.B int des_3cbc_encrypt(input,output,length,sk1,sk2,ivec1,ivec2,encrypt)des_cblock *input;des_cblock *output;long length;des_key_schedule sk1;des_key_schedule sk2;des_cblock *ivec1;des_cblock *ivec2;int encrypt;.PP.B int des_pcbc_encrypt(input,output,length,schedule,ivec,encrypt)des_cblock *input;des_cblock *output;long length;des_key_schedule schedule;des_cblock *ivec;int encrypt;.PP.B int des_cfb_encrypt(input,output,numbits,length,schedule,ivec,encrypt)unsigned char *input;unsigned char *output;int numbits;long length;des_key_schedule schedule;des_cblock *ivec;int encrypt;.PP.B int des_ofb_encrypt(input,output,numbits,length,schedule,ivec)unsigned char *input,*output;int numbits;long length;des_key_schedule schedule;des_cblock *ivec;.PP.B unsigned long des_cbc_cksum(input,output,length,schedule,ivec)des_cblock *input;des_cblock *output;long length;des_key_schedule schedule;des_cblock *ivec;.PP.B unsigned long des_quad_cksum(input,output,length,out_count,seed)des_cblock *input;des_cblock *output;long length;int out_count;des_cblock *seed;.PP.B int des_check_key;.PP.B int des_enc_read(fd,buf,len,sched,iv)int fd;char *buf;int len;des_key_schedule sched;des_cblock *iv;.PP.B int des_enc_write(fd,buf,len,sched,iv)int fd;char *buf;int len;des_key_schedule sched;des_cblock *iv;.PP.B extern int des_rw_mode;.PP.B void des_set_odd_parity(key)des_cblock *key;.PP.B int des_is_weak_key(key)des_cblock *key;.PP.B char *crypt(passwd,salt)char *passwd;char *salt;.PP.fi.SH DESCRIPTIONThis library contains a fast implementation of the DES encryptionalgorithm..PPThere are two phases to the use of DES encryption.The first is the generation of a.I des_key_schedulefrom a key,the second is the actual encryption.A des key is of type.I des_cblock.This type is made from 8 characters with odd parity.The least significant bit in the character is the parity bit.The key schedule is an expanded form of the key; it is used to speed theencryption process..PP.I des_read_passwordwrites the string specified by prompt to the standard output,turns off echo and reads an input string from standard inputuntil terminated with a newline.If verify is non-zero, it prompts and reads the input again and verifiesthat both entered passwords are the same.The entered string is converted into a des key by using the.I des_string_to_keyroutine.The new key is placed in the.I des_cblockthat was passed (by reference) to the routine.If there were no errors,.I des_read_passwordreturns 0,-1 is returned if there was a terminal error and 1 is returned forany other error..PP.I des_read_2passwordoperates in the same way as.I des_read_passwordexcept that it generates 2 keys by using the.I des_string_to_2keyfunction..PP.I des_read_pw_stringis called by.I des_read_passwordto read and verify a string from a terminal device.The string is returned in.I buf.The size of.I bufis passed to the routine via the.I lengthparameter..PP.I des_string_to_keyconverts a string into a valid des key..PP.I des_string_to_2keyconverts a string into 2 valid des keys.This routine is best suited for used to generate keys for use with.I des_3ecb_encrypt..PP.I des_random_keyreturns a random key that is made of a combination of process id,time and an increasing counter..PPBefore a des key can be used it is converted into a.I des_key_schedulevia the.I des_set_keyroutine.If the.I des_check_keyflag is non-zero,.I des_set_keywill check that the key passed is of odd parity and is not a week orsemi-weak key.If the parity is wrong,then -1 is returned.If the key is a weak key,then -2 is returned.If an error is returned,the key schedule is not generated..PP.I des_key_schedis another name for the.I des_set_keyfunction..PPThe following routines mostly operate on an input and output stream of.I des_cblock's..PP.I des_ecb_encryptis the basic DES encryption routine that encrypts or decrypts a single 8-byte.I des_cblockin.I electronic code bookmode.It always transforms the input data, pointed to by.I input,into the output data,pointed to by the.I outputargument.If the.I encryptargument is non-zero (DES_ENCRYPT),the.I input(cleartext) is encrypted in to the.I output(ciphertext) using the key_schedule specified by the.I scheduleargument,previously set via.I des_set_key.If.I encryptis zero (DES_DECRYPT),the.I input(now ciphertext)is decrypted into the.I output(now cleartext).Input and output may overlap.No meaningful value is returned..PP.I des_3ecb_encryptencrypts/decrypts the.I inputblock by using triple ecb DES encryption.This involves encrypting the input with .I ks1,decryption with the key schedule.I ks2,and then encryption with the first again.This routine greatly reduces the chances of brute force breaking ofDES and has the advantage of if.I ks1and.I ks2are the same, it is equivalent to just encryption using ecb mode and.I ks1as the key..PP.I des_cbc_encryptencrypts/decrypts using the.I cipher-block-chainingmode of DES.If the.I encryptargument is non-zero,the routine cipher-block-chain encrypts the cleartext data pointed to by the.I inputargument into the ciphertext pointed to by the.I outputargument,using the key schedule provided by the.I scheduleargument,and initialisation vector provided by the.I ivecargument.If the.I lengthargument is not an integral multiple of eight bytes, the last block is copied to a temporary area and zero filled.The output is alwaysan integral multiple of eight bytes.To make multiple cbc encrypt calls on a large amount of data appear tobe one .I des_cbc_encryptcall, the.I ivecof subsequent calls should be the last 8 bytes of the output..PP.I des_3cbc_encryptencrypts/decrypts the.I inputblock by using triple cbc DES encryption.This involves encrypting the input with key schedule.I ks1,decryption with the key schedule.I ks2,and then encryption with the first again.2 initialisation vectors are required,.I ivec1and.I ivec2.Unlike.I des_cbc_encrypt,these initialisation vectors are modified by the subroutine.This routine greatly reduces the chances of brute force breaking ofDES and has the advantage of if.I ks1and.I ks2are the same, it is equivalent to just encryption using cbc mode and.I ks1as the key..PP.I des_pcbc_encryptencrypt/decrypts using a modified block chaining mode.It provides better error propagation characteristics than cbcencryption..PP.I des_cfb_encryptencrypt/decrypts using cipher feedback mode. This method takes anarray of characters as input and outputs and array of characters. Itdoes not require any padding to 8 character groups. Note: the ivecvariable is changed and the new changed value needs to be passed tothe next call to this function. Since this function runs a completeDES ecb encryption per numbits, this function is only suggested foruse when sending small numbers of characters..PP.I des_ofb_encryptencrypt using output feedback mode. This method takes anarray of characters as input and outputs and array of characters. Itdoes not require any padding to 8 character groups. Note: the ivecvariable is changed and the new changed value needs to be passed tothe next call to this function. Since this function runs a completeDES ecb encryption per numbits, this function is only suggested foruse when sending small numbers of characters..PP.I des_cbc_cksumproduces an 8 byte checksum based on the input stream (via cbc encryption).The last 4 bytes of the checksum is returned and the complete 8 bytes isplaced in.I output..PP.I des_quad_cksumreturns a 4 byte checksum from the input bytes.The algorithm can be iterated over the input,depending on.I out_count,1, 2, 3 or 4 times.If.I outputis non-NULL,the 8 bytes generated by each pass are written into.I output..PP.I des_enc_writeis used to write.I lenbytesto file descriptor.I fdfrom buffer.I buf.The data is encrypted via.I pcbc_encrypt(default) using.I schedfor the key and.I ivas a starting vector.The actual data send down.I fdconsists of 4 bytes (in network byte order) containing the length of thefollowing encrypted data. The encrypted data then follows, padded with randomdata out to a multiple of 8 bytes..PP.I des_enc_readis used to read.I lenbytesfrom file descriptor.I fdinto buffer.I buf.The data being read from.I fdis assumed to have come from.I des_enc_writeand is decrypted using.I schedfor the key schedule and.I ivfor the initial vector.The.I des_enc_read/des_enc_writepair can be used to read/write to files, pipes and sockets.I have used them in implementing a version of rlogin in which alldata is encrypted..PP.I des_rw_modeis used to specify the encryption mode to use with .I des_enc_readand .I des_end_write.If set to.I DES_PCBC_MODE(the default), des_pcbc_encrypt is used.If set to.I DES_CBC_MODEdes_cbc_encrypt is used.These two routines and the variable are not part of the normal MIT library..PP.I des_set_odd_paritysets the parity of the passed.I keyto odd. This routine is not part of the standard MIT library..PP.I des_is_weak_keyreturns 1 is the passed key is a weak key (pick again :-),0 if it is ok.This routine is not part of the standard MIT library..PP.I cryptis a replacement for the normal system crypt.It is much faster than the system crypt..PP.SH FILES/usr/include/des.h.br/usr/lib/libdes.a.PPThe encryption routines have been tested on 16bit, 32bit and 64bitmachines of various endian and even works under VMS..PP.SH BUGS.PPIf you think this manual is sparse,read the des_crypt(3) manual from the MIT kerberos (or bones outsideof the USA) distribution..PP.I des_cfb_encryptand.I des_ofb_encryptoperates on input of 8 bits. What this means is that if you setnumbits to 12, and length to 2, the first 12 bits will come from the 1stinput byte and the low half of the second input byte. The second 12bits will have the low 8 bits taken from the 3rd input byte and thetop 4 bits taken from the 4th input byte. The same holds for output.This function has been implemented this way because most people willbe using a multiple of 8 and because once you get into pulling bytes inputbytes apart things get ugly!.PP.I des_read_pw_stringis the most machine/OS dependent function and normally generates themost problems when porting this code..PP.I des_string_to_keyis probably different from the MIT version since there are lotsof fun ways to implement one-way encryption of a text string..PPThe routines are optimised for 32 bit machines and so are not efficienton IBM PCs..SH AUTHOREric Young (eay@psych.psy.uq.oz.au),Psychology Department,University of Queensland, Australia.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -