checksum.cc 960 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "arch.hh"
  9. w32 i4_check_sum32(void *buf, w32 buf_len)
  10. {
  11. w8 c1=0,c2=0,c3=0,c4=0;
  12. while (buf_len)
  13. {
  14. c1+=*((w8 *)buf);
  15. c2+=c1;
  16. buf=(void *)(((w8 *)buf)+1);
  17. c3+=c2;
  18. c4+=c3;
  19. buf_len--;
  20. }
  21. return (c1|(c2<<8)|(c3<<16)|(c4<<24));
  22. }
  23. w16 i4_check_sum16(void *buf, w32 buf_len)
  24. {
  25. w8 c1=0,c2=0;
  26. while (buf_len)
  27. {
  28. c1+=*((w8 *)buf);
  29. buf=(void *)(((w8 *)buf)+1);
  30. c2+=c1;
  31. }
  32. return (c1|(c2<<8));
  33. }