home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Club Elmshorn Atari PD
/
CCE_PD.iso
/
pc
/
0600
/
CCE_0679.ZIP
/
CCE_0679.PD
/
DES301
/
DES_CRYP.3
< prev
next >
Wrap
Text File
|
1993-11-10
|
20KB
|
463 lines
DES_CRYPT(3) DES_CRYPT(3)
N✓NA✓AM✓ME✓E
des_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
S✓SY✓YN✓NO✓OP✓PS✓SI✓IS✓S
#✓#i✓in✓nc✓cl✓lu✓ud✓de✓e <✓<d✓de✓es✓s.✓.h✓h>✓>
i✓in✓nt✓t d✓de✓es✓s_✓_r✓re✓ea✓ad✓d_✓_p✓pa✓as✓ss✓sw✓wo✓or✓rd✓d(✓(k✓ke✓ey✓y,✓,p✓pr✓ro✓om✓mp✓pt✓t,✓,v✓ve✓er✓ri✓if✓fy✓y)✓)
des_cblock *key;
char *prompt;
int verify;
i✓in✓nt✓t d✓de✓es✓s_✓_r✓re✓ea✓ad✓d_✓_2✓2p✓pa✓as✓ss✓sw✓wo✓or✓rd✓d(✓(k✓ke✓ey✓y1✓1,✓,k✓ke✓ey✓y2✓2,✓,p✓pr✓ro✓om✓mp✓pt✓t,✓,v✓ve✓er✓ri✓if✓fy✓y)✓)
des_cblock *key1,*key2;
char *prompt;
int verify;
i✓in✓nt✓t d✓de✓es✓s_✓_s✓st✓tr✓ri✓in✓ng✓g_✓_t✓to✓o_✓_k✓ke✓ey✓y(✓(s✓st✓tr✓r,✓,k✓ke✓ey✓y)✓)
char *str;
des_cblock *key;
i✓in✓nt✓t d✓de✓es✓s_✓_s✓st✓tr✓ri✓in✓ng✓g_✓_t✓to✓o_✓_2✓2k✓ke✓ey✓ys✓s(✓(s✓st✓tr✓r,✓,k✓ke✓ey✓y1✓1,✓,k✓ke✓ey✓y2✓2)✓)
char *str;
des_cblock *key1,*key2;
i✓in✓nt✓t d✓de✓es✓s_✓_r✓re✓ea✓ad✓d_✓_p✓pw✓w_✓_s✓st✓tr✓ri✓in✓ng✓g(✓(b✓bu✓uf✓f,✓,l✓le✓en✓ng✓gt✓th✓h,✓,p✓pr✓ro✓om✓mp✓pt✓t,✓,v✓ve✓er✓ri✓if✓fy✓y)✓)
char *buf;
int length;
char *prompt;
int verify;
i✓in✓nt✓t d✓de✓es✓s_✓_r✓ra✓an✓nd✓do✓om✓m_✓_k✓ke✓ey✓y(✓(k✓ke✓ey✓y)✓)
des_cblock *key;
i✓in✓nt✓t d✓de✓es✓s_✓_s✓se✓et✓t_✓_k✓ke✓ey✓y(✓(k✓ke✓ey✓y,✓,s✓sc✓ch✓he✓ed✓du✓ul✓le✓e)✓)
des_cblock *key;
des_key_schedule schedule;
i✓in✓nt✓t d✓de✓es✓s_✓_k✓ke✓ey✓y_✓_s✓sc✓ch✓he✓ed✓d(✓(k✓ke✓ey✓y,✓,s✓sc✓ch✓he✓ed✓du✓ul✓le✓e)✓)
des_cblock *key;
des_key_schedule schedule;
i✓in✓nt✓t d✓de✓es✓s_✓_e✓ec✓cb✓b_✓_e✓en✓nc✓cr✓ry✓yp✓pt✓t(✓(i✓in✓np✓pu✓ut✓t,✓,o✓ou✓ut✓tp✓pu✓ut✓t,✓,s✓sc✓ch✓he✓ed✓du✓ul✓le✓e,✓,e✓en✓nc✓cr✓ry✓yp✓pt✓t)✓)
des_cblock *input;
des_cblock *output;
des_key_schedule schedule;
int encrypt;
1
DES_CRYPT(3) DES_CRYPT(3)
i✓in✓nt✓t d✓de✓es✓s_✓_3✓3e✓ec✓cb✓b_✓_e✓en✓nc✓cr✓ry✓yp✓pt✓t(✓(i✓in✓np✓pu✓ut✓t,✓,o✓ou✓ut✓tp✓pu✓ut✓t,✓,k✓ks✓s1✓1,✓,k✓ks✓s2✓2,✓,e✓en✓nc✓cr✓ry✓yp✓pt✓t)✓)
des_cblock *input;
des_cblock *output;
des_key_schedule ks1,ks2;
int encrypt;
i✓in✓nt✓t d✓de✓es✓s_✓_c✓cb✓bc✓c_✓_e✓en✓nc✓cr✓ry✓yp✓pt✓t(✓(i✓in✓np✓pu✓ut✓t,✓,o✓ou✓ut✓tp✓pu✓ut✓t,✓,l✓le✓en✓ng✓gt✓th✓h,✓,s✓sc✓ch✓he✓ed✓du✓ul✓le✓e,✓,i✓iv✓ve✓ec✓c,✓,e✓en✓nc✓cr✓ry✓yp✓pt✓t)✓)
des_cblock *input;
des_cblock *output;
long length;
des_key_schedule schedule;
des_cblock *ivec;
int encrypt;
i✓in✓nt✓t d✓de✓es✓s_✓_3✓3c✓cb✓bc✓c_✓_e✓en✓nc✓cr✓ry✓yp✓pt✓t(✓(i✓in✓np✓pu✓ut✓t,✓,o✓ou✓ut✓tp✓pu✓ut✓t,✓,l✓le✓en✓ng✓gt✓th✓h,✓,s✓sk✓k1✓1,✓,s✓sk✓k2✓2,✓,i✓iv✓ve✓ec✓c1✓1,✓,i✓iv✓ve✓ec✓c2✓2,✓,e✓en✓nc✓cr✓ry✓yp✓pt✓t)✓)
des_cblock *input;
des_cblock *output;
long length;
des_key_schedule sk1;
des_key_schedule sk2;
des_cblock *ivec1;
des_cblock *ivec2;
int encrypt;
i✓in✓nt✓t d✓de✓es✓s_✓_p✓pc✓cb✓bc✓c_✓_e✓en✓nc✓cr✓ry✓yp✓pt✓t(✓(i✓in✓np✓pu✓ut✓t,✓,o✓ou✓ut✓tp✓pu✓ut✓t,✓,l✓le✓en✓ng✓gt✓th✓h,✓,s✓sc✓ch✓he✓ed✓du✓ul✓le✓e,✓,i✓iv✓ve✓ec✓c,✓,e✓en✓nc✓cr✓ry✓yp✓pt✓t)✓)
des_cblock *input;
des_cblock *output;
long length;
des_key_schedule schedule;
des_cblock *ivec;
int encrypt;
i✓in✓nt✓t d✓de✓es✓s_✓_c✓cf✓fb✓b_✓_e✓en✓nc✓cr✓ry✓yp✓pt✓t(✓(i✓in✓np✓pu✓ut✓t,✓,o✓ou✓ut✓tp✓pu✓ut✓t,✓,n✓nu✓um✓mb✓bi✓it✓ts✓s,✓,l✓le✓en✓ng✓gt✓th✓h,✓,s✓sc✓ch✓he✓ed✓du✓ul✓le✓e,✓,i✓iv✓ve✓ec✓c,✓,e✓en✓nc✓cr✓ry✓yp✓pt✓t)✓)
unsigned char *input;
unsigned char *output;
int numbits;
long length;
des_key_schedule schedule;
des_cblock *ivec;
int encrypt;
i✓in✓nt✓t d✓de✓es✓s_✓_o✓of✓fb✓b_✓_e✓en✓nc✓cr✓ry✓yp✓pt✓t(✓(i✓in✓np✓pu✓ut✓t,✓,o✓ou✓ut✓tp✓pu✓ut✓t,✓,n✓nu✓um✓mb✓bi✓it✓ts✓s,✓,l✓le✓en✓ng✓gt✓th✓h,✓,s✓sc✓ch✓he✓ed✓du✓ul✓le✓e,✓,i✓iv✓ve✓ec✓c)✓)
unsigned char *input,*output;
int numbits;
long length;
des_key_schedule schedule;
des_cblock *ivec;
u✓un✓ns✓si✓ig✓gn✓ne✓ed✓d l✓lo✓on✓ng✓g d✓de✓es✓s_✓_c✓cb✓bc✓c_✓_c✓ck✓ks✓su✓um✓m(✓(i✓in✓np✓pu✓ut✓t,✓,o✓ou✓ut✓tp✓pu✓ut✓t,✓,l✓le✓en✓ng✓gt✓th✓h,✓,s✓sc✓ch✓he✓ed✓du✓ul✓le✓e,✓,i✓iv✓ve✓ec✓c)✓)
des_cblock *input;
des_cblock *output;
long length;
des_key_schedule schedule;
des_cblock *ivec;
2
DES_CRYPT(3) DES_CRYPT(3)
u✓un✓ns✓si✓ig✓gn✓ne✓ed✓d l✓lo✓on✓ng✓g d✓de✓es✓s_✓_q✓qu✓ua✓ad✓d_✓_c✓ck✓ks✓su✓um✓m(✓(i✓in✓np✓pu✓ut✓t,✓,o✓ou✓ut✓tp✓pu✓ut✓t,✓,l✓le✓en✓ng✓gt✓th✓h,✓,o✓ou✓ut✓t_✓_c✓co✓ou✓un✓nt✓t,✓,s✓se✓ee✓ed✓d)✓)
des_cblock *input;
des_cblock *output;
long length;
int out_count;
des_cblock *seed;
i✓in✓nt✓t d✓de✓es✓s_✓_c✓ch✓he✓ec✓ck✓k_✓_k✓ke✓ey✓y;✓;
i✓in✓nt✓t d✓de✓es✓s_✓_e✓en✓nc✓c_✓_r✓re✓ea✓ad✓d(✓(f✓fd✓d,✓,b✓bu✓uf✓f,✓,l✓le✓en✓n,✓,s✓sc✓ch✓he✓ed✓d,✓,i✓iv✓v)✓)
int fd;
char *buf;
int len;
des_key_schedule sched;
des_cblock *iv;
i✓in✓nt✓t d✓de✓es✓s_✓_e✓en✓nc✓c_✓_w✓wr✓ri✓it✓te✓e(✓(f✓fd✓d,✓,b✓bu✓uf✓f,✓,l✓le✓en✓n,✓,s✓sc✓ch✓he✓ed✓d,✓,i✓iv✓v)✓)
int fd;
char *buf;
int len;
des_key_schedule sched;
des_cblock *iv;
e✓ex✓xt✓te✓er✓rn✓n i✓in✓nt✓t d✓de✓es✓s_✓_r✓rw✓w_✓_m✓mo✓od✓de✓e;✓;
v✓vo✓oi✓id✓d d✓de✓es✓s_✓_s✓se✓et✓t_✓_o✓od✓dd✓d_✓_p✓pa✓ar✓ri✓it✓ty✓y(✓(k✓ke✓ey✓y)✓)
des_cblock *key;
i✓in✓nt✓t d✓de✓es✓s_✓_i✓is✓s_✓_w✓we✓ea✓ak✓k_✓_k✓ke✓ey✓y(✓(k✓ke✓ey✓y)✓)
des_cblock *key;
c✓ch✓ha✓ar✓r *✓*c✓cr✓ry✓yp✓pt✓t(✓(p✓pa✓as✓ss✓sw✓wd✓d,✓,s✓sa✓al✓lt✓t)✓)
char *passwd;
char *salt;
D✓DE✓ES✓SC✓CR✓RI✓IP✓PT✓TI✓IO✓ON✓N
This library contains a fast implementation of the DES
encryption algorithm.
There are two phases to the use of DES encryption. The
first is the generation of a _✓d_✓e_✓s_✓__✓k_✓e_✓y_✓__✓s_✓c_✓h_✓e_✓d_✓u_✓l_✓e from a key,
the second is the actual encryption. A des key is of type
_✓d_✓e_✓s_✓__✓c_✓b_✓l_✓o_✓c_✓k_✓. 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 the encryption process.
_✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓p_✓a_✓s_✓s_✓w_✓o_✓r_✓d writes the string specified by prompt to
the standard output, turns off echo and reads an input
string from standard input until terminated with a new-
line. If verify is non-zero, it prompts and reads the
input again and verifies that both entered passwords are
the same. The entered string is converted into a des key
3
DES_CRYPT(3) DES_CRYPT(3)
by using the _✓d_✓e_✓s_✓__✓s_✓t_✓r_✓i_✓n_✓g_✓__✓t_✓o_✓__✓k_✓e_✓y routine. The new key is
placed in the _✓d_✓e_✓s_✓__✓c_✓b_✓l_✓o_✓c_✓k that was passed (by reference) to
the routine. If there were no errors, _✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓p_✓a_✓s_✓s_✓w_✓o_✓r_✓d
returns 0, -1 is returned if there was a terminal error
and 1 is returned for any other error.
_✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓2_✓p_✓a_✓s_✓s_✓w_✓o_✓r_✓d operates in the same way as
_✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓p_✓a_✓s_✓s_✓w_✓o_✓r_✓d except that it generates 2 keys by using
the _✓d_✓e_✓s_✓__✓s_✓t_✓r_✓i_✓n_✓g_✓__✓t_✓o_✓__✓2_✓k_✓e_✓y function.
_✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓p_✓w_✓__✓s_✓t_✓r_✓i_✓n_✓g is called by _✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓p_✓a_✓s_✓s_✓w_✓o_✓r_✓d to read
and verify a string from a terminal device. The string is
returned in _✓b_✓u_✓f_✓. The size of _✓b_✓u_✓f is passed to the routine
via the _✓l_✓e_✓n_✓g_✓t_✓h parameter.
_✓d_✓e_✓s_✓__✓s_✓t_✓r_✓i_✓n_✓g_✓__✓t_✓o_✓__✓k_✓e_✓y converts a string into a valid des key.
_✓d_✓e_✓s_✓__✓s_✓t_✓r_✓i_✓n_✓g_✓__✓t_✓o_✓__✓2_✓k_✓e_✓y converts a string into 2 valid des
keys. This routine is best suited for used to generate
keys for use with _✓d_✓e_✓s_✓__✓3_✓e_✓c_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t_✓.
_✓d_✓e_✓s_✓__✓r_✓a_✓n_✓d_✓o_✓m_✓__✓k_✓e_✓y returns a random key that is made of a com-
bination of process id, time and an increasing counter.
Before a des key can be used it is converted into a
_✓d_✓e_✓s_✓__✓k_✓e_✓y_✓__✓s_✓c_✓h_✓e_✓d_✓u_✓l_✓e via the _✓d_✓e_✓s_✓__✓s_✓e_✓t_✓__✓k_✓e_✓y routine. If the
_✓d_✓e_✓s_✓__✓c_✓h_✓e_✓c_✓k_✓__✓k_✓e_✓y flag is non-zero, _✓d_✓e_✓s_✓__✓s_✓e_✓t_✓__✓k_✓e_✓y will check
that the key passed is of odd parity and is not a week or
semi-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 gener-
ated.
_✓d_✓e_✓s_✓__✓k_✓e_✓y_✓__✓s_✓c_✓h_✓e_✓d is another name for the _✓d_✓e_✓s_✓__✓s_✓e_✓t_✓__✓k_✓e_✓y func-
tion.
The following routines mostly operate on an input and out-
put stream of _✓d_✓e_✓s_✓__✓c_✓b_✓l_✓o_✓c_✓k_✓'_✓s_✓.
_✓d_✓e_✓s_✓__✓e_✓c_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t is the basic DES encryption routine that
encrypts or decrypts a single 8-byte _✓d_✓e_✓s_✓__✓c_✓b_✓l_✓o_✓c_✓k in _✓e_✓l_✓e_✓c_✓-
_✓t_✓r_✓o_✓n_✓i_✓c _✓c_✓o_✓d_✓e _✓b_✓o_✓o_✓k mode. It always transforms the input
data, pointed to by _✓i_✓n_✓p_✓u_✓t_✓, into the output data, pointed
to by the _✓o_✓u_✓t_✓p_✓u_✓t argument. If the _✓e_✓n_✓c_✓r_✓y_✓p_✓t argument is
non-zero (DES_ENCRYPT), the _✓i_✓n_✓p_✓u_✓t (cleartext) is encrypted
in to the _✓o_✓u_✓t_✓p_✓u_✓t (ciphertext) using the key_schedule spec-
ified by the _✓s_✓c_✓h_✓e_✓d_✓u_✓l_✓e argument, previously set via
_✓d_✓e_✓s_✓__✓s_✓e_✓t_✓__✓k_✓e_✓y_✓. If _✓e_✓n_✓c_✓r_✓y_✓p_✓t is zero (DES_DECRYPT), the _✓i_✓n_✓p_✓u_✓t
(now ciphertext) is decrypted into the _✓o_✓u_✓t_✓p_✓u_✓t (now cleart-
ext). Input and output may overlap. No meaningful value
is returned.
_✓d_✓e_✓s_✓__✓3_✓e_✓c_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t encrypts/decrypts the _✓i_✓n_✓p_✓u_✓t block by
using triple ecb DES encryption. This involves encrypting
4
DES_CRYPT(3) DES_CRYPT(3)
the input with _✓k_✓s_✓1_✓, decryption with the key schedule _✓k_✓s_✓2_✓,
and then encryption with the first again. This routine
greatly reduces the chances of brute force breaking of DES
and has the advantage of if _✓k_✓s_✓1 and _✓k_✓s_✓2 are the same, it
is equivalent to just encryption using ecb mode and _✓k_✓s_✓1 as
the key.
_✓d_✓e_✓s_✓__✓c_✓b_✓c_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t encrypts/decrypts using the _✓c_✓i_✓p_✓h_✓e_✓r_✓-_✓b_✓l_✓o_✓c_✓k_✓-
_✓c_✓h_✓a_✓i_✓n_✓i_✓n_✓g mode of DES. If the _✓e_✓n_✓c_✓r_✓y_✓p_✓t argument is non-
zero, the routine cipher-block-chain encrypts the cleart-
ext data pointed to by the _✓i_✓n_✓p_✓u_✓t argument into the cipher-
text pointed to by the _✓o_✓u_✓t_✓p_✓u_✓t argument, using the key
schedule provided by the _✓s_✓c_✓h_✓e_✓d_✓u_✓l_✓e argument, and initiali-
sation vector provided by the _✓i_✓v_✓e_✓c argument. If the
_✓l_✓e_✓n_✓g_✓t_✓h argument is not an integral multiple of eight
bytes, the last block is copied to a temporary area and
zero filled. The output is always an integral multiple of
eight bytes. To make multiple cbc encrypt calls on a
large amount of data appear to be one _✓d_✓e_✓s_✓__✓c_✓b_✓c_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t
call, the _✓i_✓v_✓e_✓c of subsequent calls should be the last 8
bytes of the output.
_✓d_✓e_✓s_✓__✓3_✓c_✓b_✓c_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t encrypts/decrypts the _✓i_✓n_✓p_✓u_✓t block by
using triple cbc DES encryption. This involves encrypting
the input with key schedule _✓k_✓s_✓1_✓, decryption with the key
schedule _✓k_✓s_✓2_✓, and then encryption with the first again. 2
initialisation vectors are required, _✓i_✓v_✓e_✓c_✓1 and _✓i_✓v_✓e_✓c_✓2_✓.
Unlike _✓d_✓e_✓s_✓__✓c_✓b_✓c_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t_✓, these initialisation vectors are
modified by the subroutine. This routine greatly reduces
the chances of brute force breaking of DES and has the
advantage of if _✓k_✓s_✓1 and _✓k_✓s_✓2 are the same, it is equivalent
to just encryption using cbc mode and _✓k_✓s_✓1 as the key.
_✓d_✓e_✓s_✓__✓p_✓c_✓b_✓c_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t encrypt/decrypts using a modified block
chaining mode. It provides better error propagation char-
acteristics than cbc encryption.
_✓d_✓e_✓s_✓__✓c_✓f_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t encrypt/decrypts using cipher feedback
mode. This method takes an array of characters as input
and outputs and array of characters. It does not require
any padding to 8 character groups. Note: the ivec vari-
able is changed and the new changed value needs to be
passed to the next call to this function. Since this
function runs a complete DES ecb encryption per numbits,
this function is only suggested for use when sending small
numbers of characters.
_✓d_✓e_✓s_✓__✓o_✓f_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t encrypt using output feedback mode. This
method takes an array of characters as input and outputs
and array of characters. It does not require any padding
to 8 character groups. Note: the ivec variable is changed
and the new changed value needs to be passed to the next
call to this function. Since this function runs a com-
plete DES ecb encryption per numbits, this function is
5
DES_CRYPT(3) DES_CRYPT(3)
only suggested for use when sending small numbers of char-
acters.
_✓d_✓e_✓s_✓__✓c_✓b_✓c_✓__✓c_✓k_✓s_✓u_✓m produces 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 is
placed in _✓o_✓u_✓t_✓p_✓u_✓t_✓.
_✓d_✓e_✓s_✓__✓q_✓u_✓a_✓d_✓__✓c_✓k_✓s_✓u_✓m returns a 4 byte checksum from the input
bytes. The algorithm can be iterated over the input,
depending on _✓o_✓u_✓t_✓__✓c_✓o_✓u_✓n_✓t_✓, 1, 2, 3 or 4 times. If _✓o_✓u_✓t_✓p_✓u_✓t is
non-NULL, the 8 bytes generated by each pass are written
into _✓o_✓u_✓t_✓p_✓u_✓t_✓.
_✓d_✓e_✓s_✓__✓e_✓n_✓c_✓__✓w_✓r_✓i_✓t_✓e is used to write _✓l_✓e_✓n bytes to file descrip-
tor _✓f_✓d from buffer _✓b_✓u_✓f_✓. The data is encrypted via
_✓p_✓c_✓b_✓c_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t (default) using _✓s_✓c_✓h_✓e_✓d for the key and _✓i_✓v as a
starting vector. The actual data send down _✓f_✓d consists of
4 bytes (in network byte order) containing the length of
the following encrypted data. The encrypted data then
follows, padded with random data out to a multiple of 8
bytes.
_✓d_✓e_✓s_✓__✓e_✓n_✓c_✓__✓r_✓e_✓a_✓d is used to read _✓l_✓e_✓n bytes from file descrip-
tor _✓f_✓d into buffer _✓b_✓u_✓f_✓. The data being read from _✓f_✓d is
assumed to have come from _✓d_✓e_✓s_✓__✓e_✓n_✓c_✓__✓w_✓r_✓i_✓t_✓e and is decrypted
using _✓s_✓c_✓h_✓e_✓d for the key schedule and _✓i_✓v for the initial
vector. The _✓d_✓e_✓s_✓__✓e_✓n_✓c_✓__✓r_✓e_✓a_✓d_✓/_✓d_✓e_✓s_✓__✓e_✓n_✓c_✓__✓w_✓r_✓i_✓t_✓e pair can be used
to read/write to files, pipes and sockets. I have used
them in implementing a version of rlogin in which all data
is encrypted.
_✓d_✓e_✓s_✓__✓r_✓w_✓__✓m_✓o_✓d_✓e is used to specify the encryption mode to use
with _✓d_✓e_✓s_✓__✓e_✓n_✓c_✓__✓r_✓e_✓a_✓d and _✓d_✓e_✓s_✓__✓e_✓n_✓d_✓__✓w_✓r_✓i_✓t_✓e_✓. If set to
_✓D_✓E_✓S_✓__✓P_✓C_✓B_✓C_✓__✓M_✓O_✓D_✓E (the default), des_pcbc_encrypt is used. If
set to _✓D_✓E_✓S_✓__✓C_✓B_✓C_✓__✓M_✓O_✓D_✓E des_cbc_encrypt is used. These two
routines and the variable are not part of the normal MIT
library.
_✓d_✓e_✓s_✓__✓s_✓e_✓t_✓__✓o_✓d_✓d_✓__✓p_✓a_✓r_✓i_✓t_✓y sets the parity of the passed _✓k_✓e_✓y to
odd. This routine is not part of the standard MIT
library.
_✓d_✓e_✓s_✓__✓i_✓s_✓__✓w_✓e_✓a_✓k_✓__✓k_✓e_✓y returns 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.
_✓c_✓r_✓y_✓p_✓t is a replacement for the normal system crypt. It is
much faster than the system crypt.
F✓FI✓IL✓LE✓ES✓S
/usr/include/des.h
/usr/lib/libdes.a
6
DES_CRYPT(3) DES_CRYPT(3)
The encryption routines have been tested on 16bit, 32bit
and 64bit machines of various endian and even works under
VMS.
B✓BU✓UG✓GS✓S
If you think this manual is sparse, read the des_crypt(3)
manual from the MIT kerberos (or bones outside of the USA)
distribution.
_✓d_✓e_✓s_✓__✓c_✓f_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t and _✓d_✓e_✓s_✓__✓o_✓f_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t operates on input of 8
bits. What this means is that if you set numbits to 12,
and length to 2, the first 12 bits will come from the 1st
input byte and the low half of the second input byte. The
second 12 bits will have the low 8 bits taken from the 3rd
input byte and the top 4 bits taken from the 4th input
byte. The same holds for output. This function has been
implemented this way because most people will be using a
multiple of 8 and because once you get into pulling bytes
input bytes apart things get ugly!
_✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓p_✓w_✓__✓s_✓t_✓r_✓i_✓n_✓g is the most machine/OS dependent func-
tion and normally generates the most problems when porting
this code.
_✓d_✓e_✓s_✓__✓s_✓t_✓r_✓i_✓n_✓g_✓__✓t_✓o_✓__✓k_✓e_✓y is probably different from the MIT ver-
sion since there are lots of fun ways to implement one-way
encryption of a text string.
The routines are optimised for 32 bit machines and so are
not efficient on IBM PCs.
A✓AU✓UT✓TH✓HO✓OR✓R
Eric Young (eay@psych.psy.uq.oz.au), Psychology Depart-
ment, University of Queensland, Australia.
7