home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume29 / libdes / part01 / quad_cksum.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-04  |  1.5 KB  |  70 lines

  1. /* quad_cksum.c */
  2. /* Copyright (C) 1992 Eric Young - see COPYING for more details */
  3. /* From "Message Authentication"  R.R. Jueneman, S.M. Matyas, C.H. Meyer
  4.  * IEEE Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40
  5.  * This module in only based on the code in this paper and is
  6.  * almost definitely not the same as the MIT implementation.
  7.  */
  8. #include "des_local.h"
  9.  
  10. /* bug fix for dos - 7/6/91 - Larry hughes@logos.ucs.indiana.edu */
  11. #define B0(a)    (((ulong)(a)))
  12. #define B1(a)    (((ulong)(a))<<8)
  13. #define B2(a)    (((ulong)(a))<<16)
  14. #define B3(a)    (((ulong)(a))<<24)
  15.  
  16. /* used to scramble things a bit */
  17. /* Got the value MIT uses via brute force :-) 2/10/90 eay */
  18. #define NOISE    (83653421)
  19.  
  20. unsigned long des_quad_cksum(input,output,length,out_count,seed)
  21. des_cblock *input;
  22. des_cblock *output;
  23. long length;
  24. int out_count;
  25. des_cblock *seed;
  26.     {
  27.     ulong z0,z1,t0,t1;
  28.     int i;
  29.     long l=0;
  30.     uchar *cp;
  31.     uchar *lp;
  32.  
  33.     lp=(uchar *)output;
  34.  
  35.     z0=B0((*seed)[0])|B1((*seed)[1])|B2((*seed)[2])|B3((*seed)[3]);
  36.     z1=B0((*seed)[4])|B1((*seed)[5])|B2((*seed)[6])|B3((*seed)[7]);
  37.  
  38.     for (i=0; ((i<4)&&(i<out_count)); i++)
  39.         {
  40.         cp=(uchar *)input;
  41.         l=length;
  42.         while (l > 0)
  43.             {
  44.             if (l > 1)
  45.                 {
  46.                 t0= (ulong)*cp++;
  47.                 t0|=(ulong)B1(*cp++);
  48.                 l--;
  49.                 }
  50.             else
  51.                 t0= (ulong)*cp++;
  52.             l--;
  53.  
  54.             /* add */
  55.             t0+=z0;
  56.             t1=z1;
  57.             /* square, well sort of square */
  58.             z0=((t0*t0)+(t1*t1))  %0x7fffffff; 
  59.             z1=(t0*(t1+NOISE))%0x7fffffff;
  60.             }
  61.         if (lp != NULL)
  62.             {
  63.             l2c(z0,lp);
  64.             l2c(z1,lp);
  65.             }
  66.         }
  67.     return(z0);
  68.     }
  69.  
  70.