home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / man / cat3 / crypt.0 < prev    next >
Text File  |  1993-12-07  |  6KB  |  133 lines

  1.  
  2. CRYPT(3)                   UNIX Programmer's Manual                   CRYPT(3)
  3.  
  4. NNAAMMEE
  5.      ccrryypptt, sseettkkeeyy, eennccrryypptt, ddeess__sseettkkeeyy, ddeess__cciipphheerr - DES encryption
  6.  
  7. SSYYNNOOPPSSIISS
  8.      _c_h_a_r
  9.      **ccrryypptt(_c_o_n_s_t _c_h_a_r _*_k_e_y, _c_o_n_s_t _c_h_a_r _*_s_e_t_t_i_n_g)
  10.  
  11.      _i_n_t
  12.      sseettkkeeyy(_c_h_a_r _*_k_e_y)
  13.  
  14.      _i_n_t
  15.      eennccrryypptt(_c_h_a_r _*_b_l_o_c_k, _i_n_t _f_l_a_g)
  16.  
  17.      _i_n_t
  18.      ddeess__sseettkkeeyy(_c_o_n_s_t _c_h_a_r _*_k_e_y)
  19.  
  20.      _i_n_t
  21.      ddeess__cciipphheerr(_c_o_n_s_t _c_h_a_r _*_i_n, _c_h_a_r _*_o_u_t, _l_o_n_g _s_a_l_t, _i_n_t _c_o_u_n_t)
  22.  
  23. DDEESSCCRRIIPPTTIIOONN
  24.      The crypt function performs password encryption.  It is derived from the
  25.      NBS Data Encryption Standard.  Additional code has been added to deter
  26.      key search attempts.  The first argument to ccrryypptt is a NUL­terminated
  27.      string (normally a password typed by a user).  The second is a character
  28.      array, 9 bytes in length, consisting of an underscore (``_'') followed by
  29.      4 bytes of iteration count and 4 bytes of salt.  Both the iteration _c_o_u_n_t
  30.      and the _s_a_l_t are encoded with 6 bits per character, least significant
  31.      bits first.  The values 0 to 63 are encoded by the characters ``./0­9A­
  32.      Za­z'', respectively.
  33.  
  34.      The _s_a_l_t is used to induce disorder in to the DES algorithm in one of
  35.      16777216 possible ways (specifically, if bit _i of the _s_a_l_t is set then
  36.      bits _i and _i_+_2_4 are swapped in the DES ``E'' box output).  The _k_e_y is di­
  37.      vided into groups of 8 characters (a short final group is null­padded)
  38.      and the low­order 7 bits of each each character (56 bits per group) are
  39.      used to form the DES key as follows: the first group of 56 bits becomes
  40.      the initial DES key.  For each additional group, the XOR of the group
  41.      bits and the encryption of the DES key with itself becomes the next DES
  42.      key.  Then the final DES key is used to perform _c_o_u_n_t cumulative encryp­
  43.      tions of a 64­bit constant.  The value returned is a NUL­terminated
  44.      string, 20 bytes in length, consisting of the _s_e_t_t_i_n_g followed by the en­
  45.      coded 64­bit encryption.
  46.  
  47.      For compatibility with historical versions of crypt(3),  the _s_e_t_t_i_n_g may
  48.      consist of 2 bytes of salt, encoded as above, in which case an iteration
  49.      _c_o_u_n_t of 25 is used, fewer perturbations of DES are available, at most 8
  50.      characters of _k_e_y are used, and the returned value is a NUL­terminated
  51.      string 13 bytes in length.
  52.  
  53.      The functions, eennccrryypptt(), sseettkkeeyy(), ddeess__sseettkkeeyy() and ddeess__cciipphheerr() allow
  54.      limited access to the DES algorithm itself.  The _k_e_y argument to sseettkkeeyy()
  55.      is a 64 character array of binary values (numeric 0 or 1).  A 56­bit key
  56.      is derived from this array by dividing the array into groups of 8 and ig­
  57.      noring the last bit in each group.
  58.  
  59.      The eennccrryypptt() argument _b_l_o_c_k is also a 64 character array of binary val­
  60.      ues.  If the value of _f_l_a_g is 0, the argument _b_l_o_c_k is encrypted, other­
  61.      wise it is decrypted.  The encryption or decryption is returned in the
  62.      original array _b_l_o_c_k after using the key specified by sseettkkeeyy() to process
  63.      it.
  64.  
  65.  
  66.      The ddeess__sseettkkeeyy() and ddeess__cciipphheerr() functions are faster but less portable
  67.      than sseettkkeeyy() and eennccrryypptt().  The argument to ddeess__sseettkkeeyy() is a character
  68.      array of length 8.  The _l_e_a_s_t significant bit in each character is ig­
  69.      nored and the next 7 bits of each character are concatenated to yield a
  70.      56­bit key.  The function ddeess__cciipphheerr() encrypts (or decrypts if _c_o_u_n_t is
  71.      negative) the 64­bits stored in the 8 characters at _i_n using abs(3) of
  72.      _c_o_u_n_t iterations of DES and stores the 64­bit result in the 8 characters
  73.      at _o_u_t. The _s_a_l_t specifies perturbations to DES as described above.
  74.  
  75.      The function ccrryypptt() returns a pointer to the encrypted value on success
  76.      and NULL on failure.  The functions sseettkkeeyy(), eennccrryypptt(), ddeess__sseettkkeeyy(),
  77.      and ddeess__cciipphheerr() return 0 on success and 1 on failure.  Historically, the
  78.      functions sseettkkeeyy() and eennccrryypptt() did not return any value.  They have
  79.      been provided return values primarily to distinguish implementations
  80.      where hardware support is provided but not available or where the DES en­
  81.      cryption is not available due to the usual political silliness.
  82.  
  83. SSEEEE AALLSSOO
  84.      login(1),  passwd(1),  getpass(3),  passwd(5)
  85.  
  86.  
  87.      Wayne Patterson, _M_a_t_h_e_m_a_t_i_c_a_l _C_r_y_p_t_o_l_o_g_y _f_o_r _C_o_m_p_u_t_e_r _S_c_i_e_n_t_i_s_t_s _a_n_d
  88.      _M_a_t_h_e_m_a_t_i_c_i_a_n_s, ISBN 0­8476­7438­X, 1987.
  89.  
  90.      R. Morris, and Ken Thompson, "Password Security: A Case History",
  91.      _C_o_m_m_u_n_i_c_a_t_i_o_n_s _o_f _t_h_e _A_C_M, vol. 22, pp. 594­597, Nov. 1979.
  92.  
  93.      M.E. Hellman, "DES will be Totally Insecure within Ten Years", _I_E_E_E
  94.      _S_p_e_c_t_r_u_m, vol. 16, pp. 32­39, July 1979.
  95.  
  96. HHIISSTTOORRYY
  97.      A rotor­based ccrryypptt() function appeared in Version 6 AT&T UNIX.  The cur­
  98.      rent style ccrryypptt() first appeared in Version 7 AT&T UNIX.
  99.  
  100. BBUUGGSS
  101.      Dropping the _l_e_a_s_t significant bit in each character of the argument to
  102.      ddeess__sseettkkeeyy() is ridiculous.
  103.  
  104.      The ccrryypptt() function leaves its result in an internal static object and
  105.      returns a pointer to that object.  Subsequent calls to ccrryypptt() will modi­
  106.      fy the same object.
  107.  
  108. BSD Experimental                 May 21, 1991                                2
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.