home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume29 / libdes / part01 / cbc_cksum.c next >
Encoding:
C/C++ Source or Header  |  1992-04-04  |  901 b   |  47 lines

  1. /* cbc_cksum.c */
  2. /* Copyright (C) 1992 Eric Young - see COPYING for more details */
  3. #include "des_local.h"
  4.  
  5. ulong des_cbc_cksum(input,output,length,schedule,ivec)
  6. des_cblock *input;
  7. des_cblock *output;
  8. long length;
  9. des_key_schedule schedule;
  10. des_cblock *ivec;
  11.     {
  12.     register ulong tout0,tout1,tin0,tin1;
  13.     register long l=length;
  14.     ulong tin[2],tout[2];
  15.     uchar *in,*out,*iv;
  16.  
  17.     in=(uchar *)input;
  18.     out=(uchar *)output;
  19.     iv=(uchar *)ivec;
  20.  
  21.     c2l(iv,tout0);
  22.     c2l(iv,tout1);
  23.     for (; l>0; l-=8)
  24.         {
  25.         if (l >= 8)
  26.             {
  27.             c2l(in,tin0);
  28.             c2l(in,tin1);
  29.             }
  30.         else
  31.             c2ln(in,tin0,tin1,l);
  32.             
  33.         tin0^=tout0;
  34.         tin1^=tout1;
  35.         tin[0]=tin0;
  36.         tin[1]=tin1;
  37.         des_encrypt((ulong *)tin,(ulong *)tout,schedule,DES_ENCRYPT);
  38.         /* fix 15/10/91 eay - thanks to keithr@sco.COM */
  39.         tout0=tout[0];
  40.         tout1=tout[1];
  41.         }
  42.     l2c(tout0,out);
  43.     l2c(tout1,out);
  44.     tout0=tin0=tin1=tin[0]=tin[1]=tout[0]=tout[1]=0;
  45.     return(tout1);
  46.     }
  47.