home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / des16 / des16.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-01  |  4.4 KB  |  85 lines

  1. #ifndef _DES16_H_
  2. #define _DES16_H_
  3.  
  4. /*
  5.  *             des16 - NBS Data Encryption Standard Library
  6.  *
  7.  *         Copyright (c) 1992,93,94 by SWS. All Rights Reserved.
  8.  *       Stefan Wolf Software; Gartenstr 22; D-61449 Steinbach/Ts.
  9.  *           FAX: +49 (0) 6171 980483; CI$ Email: 100111,140
  10.  *
  11.  *  DES in ECB mode handles data blocks of 64 bits at one time. DES is 
  12.  *  basically a bit permutation, substitution, and recombination function 
  13.  *  performed on blocks of 64 bits of data and 56 bits of key (eight 7-bit 
  14.  *  characters).
  15.  *
  16.  *  First, the 64 bit inputblock is subjected to a fixed initial permutation
  17.  *  IP and split into two 32 bit blocks L_0_ and R_0_. Then each block is 
  18.  *  hacked apart in 16 iterations. The resulting 32 bit blocks L_16_ and 
  19.  *  R_16_ are then permuted back to a 64 bit block by a permutation table IP' 
  20.  *  which is the inverse of IP. The resulting 64 bit encrypted block is then 
  21.  *  written to the output block.
  22.  *
  23.  *  [technical stuff on]
  24.  *  In each iteration I_i_ the block L_i-1_ is coupled with the 32 bit 
  25.  *  output of the function f(R_i-1_,k_i_) by an XOR operation. The 
  26.  *  iteration I_16_ is an exception, here the blocks are swapped. The 
  27.  *  function f() receives the block R_i-1_ and the 48 bit output of the 
  28.  *  function K(i) as its arguments. f() permutes the 32 bits of R_i-1_ 
  29.  *  into 48 bits by using the permutation table E. The result is exclusive
  30.  *  ORed with the 48 bit output from the function K(i). The 48 bit result 
  31.  *  is then split into eight 6 bit values. Then the function S realizes 
  32.  *  a 4 bit value for each 6 bit value by an nonlineare substitution. The 
  33.  *  eight 4 bit values are then combined to a 32 bit value, which is then 
  34.  *  coupled with the permutation table P. The resulting 32 bit is the 
  35.  *  output of f(). The function S composed of eight substitution modules 
  36.  *  s1,s2,...,s8 (the mysterious S-boxes) which are used on the eight 6 
  37.  *  bit values from above. In this 16x4 matrix each of the 64 elements 
  38.  *  has a value between 0 and 15, a 4 bit value which substitutes a 6 bit 
  39.  *  value. The matrix coordinates of a 6 bit value are obtained in the 
  40.  *  following manner: bits 1 and 6 as binary give column 0..3, with 
  41.  *  bits 2 through 5 the row  0..15 is calculated. The function S returns 
  42.  *  the 4 bit value of the so addressed matrix element. The function K(i)
  43.  *  returns the 48 bit value k_i_ based on the key. There are two further 
  44.  *  permutation tables for the key. In the first iteration the key is 
  45.  *  permuted with the first table and then split into two halves. Each of 
  46.  *  these halves is shifted to the left once (_i_ = 1,2,9,16) or twice 
  47.  *  depending on the iteration number _i_. Each subsequent iteration I_i_ 
  48.  *  after the first uses the shifted value of the preceding iteration as 
  49.  *  input, shifts the value again and finally permutes it with the second 
  50.  *  permutation table. The decryption process uses the same algorithm, 
  51.  *  except that the decryption reverses the half exchanges during the 
  52.  *  iterations and uses the permuted key values returned by K(i) in 
  53.  *  the reverse order.
  54.  *  [technical stuff off]
  55.  *
  56.  *  It can be shown that after a few iteration steps each bit in the output 
  57.  *  block is dependent upon every bit of the input block and the key. 
  58.  *  A minimal change in the input block or in the key causes more than half 
  59.  *  of the bits in the output block to change, this is the so-called avalanche 
  60.  *  effect. To crack the output block a frequency analysis is no use and a 
  61.  *  potential hacker can only use brute-force methods for key search. This 
  62.  *  means that theoretically 72 quadrillion keys have to be tried.
  63.  *
  64.  *
  65.  *    Synopsis:    desinit(key)
  66.  * Description: intializes all DES arrays and permutation tables
  67.  *       Input: key - 64-bit DES key
  68.  *      Output: none
  69.  *
  70.  *    Synopsis: des_xx_code(inblock,outblock)
  71.  * Description: encrypts (_xx_=en) or decrypts (_xx_=de) 
  72.  *              64-bit inblock to 64-bit outblock
  73.  *     Input: inblock - pointer to 64-bit buffer of input data
  74.  *              outblock - pointer to 64-bit buffer for output data
  75.  *      Output: none        
  76.  *                 
  77.  */
  78.  
  79. typedef unsigned char uchar;
  80.  
  81. extern void far pascal desinit(uchar far *key);
  82. extern void far pascal desencode(uchar far *inblock, uchar far *outblock);
  83. extern void far pascal desdecode(uchar far *inblock, uchar far *outblock);
  84.  
  85. #endif