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 >
Text File  |  1993-11-10  |  20KB  |  463 lines

  1.  
  2.  
  3.  
  4. DES_CRYPT(3)                                         DES_CRYPT(3)
  5.  
  6.  
  7. N✓NA✓AM✓ME✓E
  8.        des_read_password,  des_read_2password, des_string_to_key,
  9.        des_string_to_2key,  des_read_pw_string,   des_random_key,
  10.        des_set_key,        des_key_sched,        des_ecb_encrypt,
  11.        des_3ecb_encrypt,    des_cbc_encrypt,    des_3cbc_encrypt,
  12.        des_pcbc_encrypt,     des_cfb_encrypt,    des_ofb_encrypt,
  13.        des_cbc_cksum,        des_quad_cksum,        des_enc_read,
  14.        des_enc_write,  des_set_odd_parity, des_is_weak_key, crypt
  15.        - (non USA) DES encryption
  16.  
  17. S✓SY✓YN✓NO✓OP✓PS✓SI✓IS✓S
  18.        #✓#i✓in✓nc✓cl✓lu✓ud✓de✓e <✓<d✓de✓es✓s.✓.h✓h>✓>
  19.  
  20.        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)✓)
  21.        des_cblock *key;
  22.        char *prompt;
  23.        int verify;
  24.  
  25.        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)✓)
  26.        des_cblock *key1,*key2;
  27.        char *prompt;
  28.        int verify;
  29.  
  30.        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)✓)
  31.        char *str;
  32.        des_cblock *key;
  33.  
  34.        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)✓)
  35.        char *str;
  36.        des_cblock *key1,*key2;
  37.  
  38.        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)✓)
  39.        char *buf;
  40.        int length;
  41.        char *prompt;
  42.        int verify;
  43.  
  44.        i✓in✓nt✓t d✓de✓es✓s_✓_r✓ra✓an✓nd✓do✓om✓m_✓_k✓ke✓ey✓y(✓(k✓ke✓ey✓y)✓)
  45.        des_cblock *key;
  46.  
  47.        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)✓)
  48.        des_cblock *key;
  49.        des_key_schedule schedule;
  50.  
  51.        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)✓)
  52.        des_cblock *key;
  53.        des_key_schedule schedule;
  54.  
  55.        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)✓)
  56.        des_cblock *input;
  57.        des_cblock *output;
  58.        des_key_schedule schedule;
  59.        int encrypt;
  60.  
  61.  
  62.  
  63.  
  64.                                                                 1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. DES_CRYPT(3)                                         DES_CRYPT(3)
  71.  
  72.  
  73.        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)✓)
  74.        des_cblock *input;
  75.        des_cblock *output;
  76.        des_key_schedule ks1,ks2;
  77.        int encrypt;
  78.  
  79.        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)✓)
  80.        des_cblock *input;
  81.        des_cblock *output;
  82.        long length;
  83.        des_key_schedule schedule;
  84.        des_cblock *ivec;
  85.        int encrypt;
  86.  
  87.        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)✓)
  88.        des_cblock *input;
  89.        des_cblock *output;
  90.        long length;
  91.        des_key_schedule sk1;
  92.        des_key_schedule sk2;
  93.        des_cblock *ivec1;
  94.        des_cblock *ivec2;
  95.        int encrypt;
  96.  
  97.        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)✓)
  98.        des_cblock *input;
  99.        des_cblock *output;
  100.        long length;
  101.        des_key_schedule schedule;
  102.        des_cblock *ivec;
  103.        int encrypt;
  104.  
  105.        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)✓)
  106.        unsigned char *input;
  107.        unsigned char *output;
  108.        int numbits;
  109.        long length;
  110.        des_key_schedule schedule;
  111.        des_cblock *ivec;
  112.        int encrypt;
  113.  
  114.        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)✓)
  115.        unsigned char *input,*output;
  116.        int numbits;
  117.        long length;
  118.        des_key_schedule schedule;
  119.        des_cblock *ivec;
  120.  
  121.        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)✓)
  122.        des_cblock *input;
  123.        des_cblock *output;
  124.        long length;
  125.        des_key_schedule schedule;
  126.        des_cblock *ivec;
  127.  
  128.  
  129.  
  130.                                                                 2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. DES_CRYPT(3)                                         DES_CRYPT(3)
  137.  
  138.  
  139.        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)✓)
  140.        des_cblock *input;
  141.        des_cblock *output;
  142.        long length;
  143.        int out_count;
  144.        des_cblock *seed;
  145.  
  146.        i✓in✓nt✓t d✓de✓es✓s_✓_c✓ch✓he✓ec✓ck✓k_✓_k✓ke✓ey✓y;✓;
  147.  
  148.        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)✓)
  149.        int fd;
  150.        char *buf;
  151.        int len;
  152.        des_key_schedule sched;
  153.        des_cblock *iv;
  154.  
  155.        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)✓)
  156.        int fd;
  157.        char *buf;
  158.        int len;
  159.        des_key_schedule sched;
  160.        des_cblock *iv;
  161.  
  162.        e✓ex✓xt✓te✓er✓rn✓n i✓in✓nt✓t d✓de✓es✓s_✓_r✓rw✓w_✓_m✓mo✓od✓de✓e;✓;
  163.  
  164.        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)✓)
  165.        des_cblock *key;
  166.  
  167.        i✓in✓nt✓t d✓de✓es✓s_✓_i✓is✓s_✓_w✓we✓ea✓ak✓k_✓_k✓ke✓ey✓y(✓(k✓ke✓ey✓y)✓)
  168.        des_cblock *key;
  169.  
  170.        c✓ch✓ha✓ar✓r *✓*c✓cr✓ry✓yp✓pt✓t(✓(p✓pa✓as✓ss✓sw✓wd✓d,✓,s✓sa✓al✓lt✓t)✓)
  171.        char *passwd;
  172.        char *salt;
  173.  
  174.  
  175. D✓DE✓ES✓SC✓CR✓RI✓IP✓PT✓TI✓IO✓ON✓N
  176.        This library contains a fast  implementation  of  the  DES
  177.        encryption algorithm.
  178.  
  179.        There  are  two  phases to the use of DES encryption.  The
  180.        first is the generation of a _✓d_✓e_✓s_✓__✓k_✓e_✓y_✓__✓s_✓c_✓h_✓e_✓d_✓u_✓l_✓e from a  key,
  181.        the second is the actual encryption.  A des key is of type
  182.        _✓d_✓e_✓s_✓__✓c_✓b_✓l_✓o_✓c_✓k_✓.  This type is made from 8 characters with  odd
  183.        parity.  The least significant bit in the character is the
  184.        parity bit.  The key schedule is an expanded form  of  the
  185.        key; it is used to speed the encryption process.
  186.  
  187.        _✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓p_✓a_✓s_✓s_✓w_✓o_✓r_✓d writes the string specified by prompt to
  188.        the standard output, turns off echo  and  reads  an  input
  189.        string  from  standard  input until terminated with a new-
  190.        line.  If verify is non-zero, it  prompts  and  reads  the
  191.        input  again  and verifies that both entered passwords are
  192.        the same.  The entered string is converted into a des  key
  193.  
  194.  
  195.  
  196.                                                                 3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. DES_CRYPT(3)                                         DES_CRYPT(3)
  203.  
  204.  
  205.        by  using  the  _✓d_✓e_✓s_✓__✓s_✓t_✓r_✓i_✓n_✓g_✓__✓t_✓o_✓__✓k_✓e_✓y routine.  The new key is
  206.        placed in the _✓d_✓e_✓s_✓__✓c_✓b_✓l_✓o_✓c_✓k that was passed (by reference) to
  207.        the  routine.   If there were no errors, _✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓p_✓a_✓s_✓s_✓w_✓o_✓r_✓d
  208.        returns 0, -1 is returned if there was  a  terminal  error
  209.        and 1 is returned for any other error.
  210.  
  211.        _✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓2_✓p_✓a_✓s_✓s_✓w_✓o_✓r_✓d   operates   in   the   same   way   as
  212.        _✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓p_✓a_✓s_✓s_✓w_✓o_✓r_✓d except that it generates 2 keys by using
  213.        the _✓d_✓e_✓s_✓__✓s_✓t_✓r_✓i_✓n_✓g_✓__✓t_✓o_✓__✓2_✓k_✓e_✓y function.
  214.  
  215.        _✓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
  216.        and verify a string from a terminal device.  The string is
  217.        returned in _✓b_✓u_✓f_✓.  The size of _✓b_✓u_✓f is passed to the routine
  218.        via the _✓l_✓e_✓n_✓g_✓t_✓h parameter.
  219.  
  220.        _✓d_✓e_✓s_✓__✓s_✓t_✓r_✓i_✓n_✓g_✓__✓t_✓o_✓__✓k_✓e_✓y converts a string into a valid des  key.
  221.  
  222.        _✓d_✓e_✓s_✓__✓s_✓t_✓r_✓i_✓n_✓g_✓__✓t_✓o_✓__✓2_✓k_✓e_✓y  converts  a  string  into  2 valid des
  223.        keys.  This routine is best suited for  used  to  generate
  224.        keys for use with _✓d_✓e_✓s_✓__✓3_✓e_✓c_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t_✓.
  225.  
  226.        _✓d_✓e_✓s_✓__✓r_✓a_✓n_✓d_✓o_✓m_✓__✓k_✓e_✓y returns a random key that is made of a com-
  227.        bination of process id, time and an increasing counter.
  228.  
  229.        Before a des key can  be  used  it  is  converted  into  a
  230.        _✓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
  231.        _✓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
  232.        that  the key passed is of odd parity and is not a week or
  233.        semi-weak key.   If  the  parity  is  wrong,  then  -1  is
  234.        returned.   If the key is a weak key, then -2 is returned.
  235.        If an error is returned, the key schedule  is  not  gener-
  236.        ated.
  237.  
  238.        _✓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-
  239.        tion.
  240.  
  241.        The following routines mostly operate on an input and out-
  242.        put stream of _✓d_✓e_✓s_✓__✓c_✓b_✓l_✓o_✓c_✓k_✓'_✓s_✓.
  243.  
  244.        _✓d_✓e_✓s_✓__✓e_✓c_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t  is  the basic DES encryption routine that
  245.        encrypts or decrypts a single 8-byte _✓d_✓e_✓s_✓__✓c_✓b_✓l_✓o_✓c_✓k  in  _✓e_✓l_✓e_✓c_✓-
  246.        _✓t_✓r_✓o_✓n_✓i_✓c  _✓c_✓o_✓d_✓e  _✓b_✓o_✓o_✓k  mode.   It always transforms the input
  247.        data, pointed to by _✓i_✓n_✓p_✓u_✓t_✓, into the output  data,  pointed
  248.        to  by  the  _✓o_✓u_✓t_✓p_✓u_✓t  argument.  If the _✓e_✓n_✓c_✓r_✓y_✓p_✓t argument is
  249.        non-zero (DES_ENCRYPT), the _✓i_✓n_✓p_✓u_✓t (cleartext) is encrypted
  250.        in to the _✓o_✓u_✓t_✓p_✓u_✓t (ciphertext) using the key_schedule spec-
  251.        ified  by  the  _✓s_✓c_✓h_✓e_✓d_✓u_✓l_✓e  argument,  previously  set   via
  252.        _✓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
  253.        (now ciphertext) is decrypted into the _✓o_✓u_✓t_✓p_✓u_✓t (now cleart-
  254.        ext).   Input and output may overlap.  No meaningful value
  255.        is returned.
  256.  
  257.        _✓d_✓e_✓s_✓__✓3_✓e_✓c_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t  encrypts/decrypts  the  _✓i_✓n_✓p_✓u_✓t  block  by
  258.        using triple ecb DES encryption.  This involves encrypting
  259.  
  260.  
  261.  
  262.                                                                 4
  263.  
  264.  
  265.  
  266.  
  267.  
  268. DES_CRYPT(3)                                         DES_CRYPT(3)
  269.  
  270.  
  271.        the input with _✓k_✓s_✓1_✓, decryption with the key schedule  _✓k_✓s_✓2_✓,
  272.        and  then  encryption  with the first again.  This routine
  273.        greatly reduces the chances of brute force breaking of DES
  274.        and  has  the advantage of if _✓k_✓s_✓1 and _✓k_✓s_✓2 are the same, it
  275.        is equivalent to just encryption using ecb mode and _✓k_✓s_✓1 as
  276.        the key.
  277.  
  278.        _✓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_✓-
  279.        _✓c_✓h_✓a_✓i_✓n_✓i_✓n_✓g mode of DES.  If the  _✓e_✓n_✓c_✓r_✓y_✓p_✓t  argument  is  non-
  280.        zero,  the routine cipher-block-chain encrypts the cleart-
  281.        ext data pointed to by the _✓i_✓n_✓p_✓u_✓t argument into the cipher-
  282.        text  pointed  to  by  the  _✓o_✓u_✓t_✓p_✓u_✓t argument, using the key
  283.        schedule provided by the _✓s_✓c_✓h_✓e_✓d_✓u_✓l_✓e argument, and  initiali-
  284.        sation  vector  provided  by  the  _✓i_✓v_✓e_✓c  argument.  If the
  285.        _✓l_✓e_✓n_✓g_✓t_✓h argument is  not  an  integral  multiple  of  eight
  286.        bytes,  the  last  block is copied to a temporary area and
  287.        zero filled.  The output is always an integral multiple of
  288.        eight  bytes.   To  make  multiple  cbc encrypt calls on a
  289.        large amount of data  appear  to  be  one  _✓d_✓e_✓s_✓__✓c_✓b_✓c_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t
  290.        call,  the  _✓i_✓v_✓e_✓c  of subsequent calls should be the last 8
  291.        bytes of the output.
  292.  
  293.        _✓d_✓e_✓s_✓__✓3_✓c_✓b_✓c_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t  encrypts/decrypts  the  _✓i_✓n_✓p_✓u_✓t  block  by
  294.        using triple cbc DES encryption.  This involves encrypting
  295.        the input with key schedule _✓k_✓s_✓1_✓, decryption with  the  key
  296.        schedule _✓k_✓s_✓2_✓, and then encryption with the first again.  2
  297.        initialisation vectors  are  required,  _✓i_✓v_✓e_✓c_✓1  and  _✓i_✓v_✓e_✓c_✓2_✓.
  298.        Unlike  _✓d_✓e_✓s_✓__✓c_✓b_✓c_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t_✓,  these initialisation vectors are
  299.        modified by the subroutine.  This routine greatly  reduces
  300.        the  chances  of  brute  force breaking of DES and has the
  301.        advantage of if _✓k_✓s_✓1 and _✓k_✓s_✓2 are the same, it is equivalent
  302.        to just encryption using cbc mode and _✓k_✓s_✓1 as the key.
  303.  
  304.        _✓d_✓e_✓s_✓__✓p_✓c_✓b_✓c_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t  encrypt/decrypts  using a modified block
  305.        chaining mode.  It provides better error propagation char-
  306.        acteristics than cbc encryption.
  307.  
  308.        _✓d_✓e_✓s_✓__✓c_✓f_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t  encrypt/decrypts  using  cipher  feedback
  309.        mode.  This method takes an array of characters  as  input
  310.        and  outputs and array of characters.  It does not require
  311.        any padding to 8 character groups.  Note: the  ivec  vari-
  312.        able  is  changed  and  the  new changed value needs to be
  313.        passed to the next call  to  this  function.   Since  this
  314.        function  runs  a complete DES ecb encryption per numbits,
  315.        this function is only suggested for use when sending small
  316.        numbers of characters.
  317.  
  318.        _✓d_✓e_✓s_✓__✓o_✓f_✓b_✓__✓e_✓n_✓c_✓r_✓y_✓p_✓t  encrypt using output feedback mode.  This
  319.        method takes an array of characters as input  and  outputs
  320.        and  array of characters.  It does not require any padding
  321.        to 8 character groups.  Note: the ivec variable is changed
  322.        and  the  new changed value needs to be passed to the next
  323.        call to this function.  Since this function  runs  a  com-
  324.        plete  DES  ecb  encryption  per numbits, this function is
  325.  
  326.  
  327.  
  328.                                                                 5
  329.  
  330.  
  331.  
  332.  
  333.  
  334. DES_CRYPT(3)                                         DES_CRYPT(3)
  335.  
  336.  
  337.        only suggested for use when sending small numbers of char-
  338.        acters.
  339.  
  340.        _✓d_✓e_✓s_✓__✓c_✓b_✓c_✓__✓c_✓k_✓s_✓u_✓m  produces  an  8  byte checksum based on the
  341.        input stream (via cbc encryption).  The last  4  bytes  of
  342.        the  checksum  is  returned  and  the  complete 8 bytes is
  343.        placed in _✓o_✓u_✓t_✓p_✓u_✓t_✓.
  344.  
  345.        _✓d_✓e_✓s_✓__✓q_✓u_✓a_✓d_✓__✓c_✓k_✓s_✓u_✓m returns a 4 byte checksum  from  the  input
  346.        bytes.   The  algorithm  can  be  iterated over the input,
  347.        depending on _✓o_✓u_✓t_✓__✓c_✓o_✓u_✓n_✓t_✓, 1, 2, 3 or 4 times.  If _✓o_✓u_✓t_✓p_✓u_✓t  is
  348.        non-NULL,  the  8 bytes generated by each pass are written
  349.        into _✓o_✓u_✓t_✓p_✓u_✓t_✓.
  350.  
  351.        _✓d_✓e_✓s_✓__✓e_✓n_✓c_✓__✓w_✓r_✓i_✓t_✓e is used to write _✓l_✓e_✓n bytes to file  descrip-
  352.        tor  _✓f_✓d  from  buffer  _✓b_✓u_✓f_✓.   The  data  is  encrypted via
  353.        _✓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
  354.        starting vector.  The actual data send down _✓f_✓d consists of
  355.        4 bytes (in network byte order) containing the  length  of
  356.        the  following  encrypted  data.   The encrypted data then
  357.        follows, padded with random data out to a  multiple  of  8
  358.        bytes.
  359.  
  360.        _✓d_✓e_✓s_✓__✓e_✓n_✓c_✓__✓r_✓e_✓a_✓d  is used to read _✓l_✓e_✓n bytes from file descrip-
  361.        tor _✓f_✓d into buffer _✓b_✓u_✓f_✓.  The data being read  from  _✓f_✓d  is
  362.        assumed  to  have come from _✓d_✓e_✓s_✓__✓e_✓n_✓c_✓__✓w_✓r_✓i_✓t_✓e and is decrypted
  363.        using _✓s_✓c_✓h_✓e_✓d for the key schedule and _✓i_✓v  for  the  initial
  364.        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
  365.        to read/write to files, pipes and sockets.   I  have  used
  366.        them in implementing a version of rlogin in which all data
  367.        is encrypted.
  368.  
  369.        _✓d_✓e_✓s_✓__✓r_✓w_✓__✓m_✓o_✓d_✓e is used to specify the encryption mode to  use
  370.        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
  371.        _✓D_✓E_✓S_✓__✓P_✓C_✓B_✓C_✓__✓M_✓O_✓D_✓E (the default), des_pcbc_encrypt is used.  If
  372.        set  to  _✓D_✓E_✓S_✓__✓C_✓B_✓C_✓__✓M_✓O_✓D_✓E  des_cbc_encrypt is used.  These two
  373.        routines and the variable are not part of the  normal  MIT
  374.        library.
  375.  
  376.        _✓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
  377.        odd.  This  routine  is  not  part  of  the  standard  MIT
  378.        library.
  379.  
  380.        _✓d_✓e_✓s_✓__✓i_✓s_✓__✓w_✓e_✓a_✓k_✓__✓k_✓e_✓y  returns 1 is the passed key is a weak key
  381.        (pick again :-), 0 if it is ok.  This routine is not  part
  382.        of the standard MIT library.
  383.  
  384.        _✓c_✓r_✓y_✓p_✓t is a replacement for the normal system crypt.  It is
  385.        much faster than the system crypt.
  386.  
  387.  
  388. F✓FI✓IL✓LE✓ES✓S
  389.        /usr/include/des.h
  390.        /usr/lib/libdes.a
  391.  
  392.  
  393.  
  394.                                                                 6
  395.  
  396.  
  397.  
  398.  
  399.  
  400. DES_CRYPT(3)                                         DES_CRYPT(3)
  401.  
  402.  
  403.        The encryption routines have been tested on  16bit,  32bit
  404.        and  64bit machines of various endian and even works under
  405.        VMS.
  406.  
  407.  
  408. B✓BU✓UG✓GS✓S
  409.        If you think this manual is sparse, read the  des_crypt(3)
  410.        manual from the MIT kerberos (or bones outside of the USA)
  411.        distribution.
  412.  
  413.        _✓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
  414.        bits.   What  this means is that if you set numbits to 12,
  415.        and length to 2, the first 12 bits will come from the  1st
  416.        input byte and the low half of the second input byte.  The
  417.        second 12 bits will have the low 8 bits taken from the 3rd
  418.        input  byte  and  the  top 4 bits taken from the 4th input
  419.        byte.  The same holds for output.  This function has  been
  420.        implemented  this  way because most people will be using a
  421.        multiple of 8 and because once you get into pulling  bytes
  422.        input bytes apart things get ugly!
  423.  
  424.        _✓d_✓e_✓s_✓__✓r_✓e_✓a_✓d_✓__✓p_✓w_✓__✓s_✓t_✓r_✓i_✓n_✓g  is the most machine/OS dependent func-
  425.        tion and normally generates the most problems when porting
  426.        this code.
  427.  
  428.        _✓d_✓e_✓s_✓__✓s_✓t_✓r_✓i_✓n_✓g_✓__✓t_✓o_✓__✓k_✓e_✓y  is probably different from the MIT ver-
  429.        sion since there are lots of fun ways to implement one-way
  430.        encryption of a text string.
  431.  
  432.        The  routines are optimised for 32 bit machines and so are
  433.        not efficient on IBM PCs.
  434.  
  435. A✓AU✓UT✓TH✓HO✓OR✓R
  436.        Eric Young  (eay@psych.psy.uq.oz.au),  Psychology  Depart-
  437.        ment, University of Queensland, Australia.
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.                                                                 7
  461.  
  462.  
  463.