Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Generic MD5 hashing algo
  4. //
  5. //=============================================================================//
  6. #ifndef CHECKSUM_MD5_H
  7. #define CHECKSUM_MD5_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. // 16 bytes == 128 bit digest
  12. #define MD5_DIGEST_LENGTH 16
  13. struct MD5Value_t
  14. {
  15. unsigned char bits[MD5_DIGEST_LENGTH];
  16. void Zero();
  17. bool IsZero() const;
  18. bool operator==( const MD5Value_t &src ) const;
  19. bool operator!=( const MD5Value_t &src ) const;
  20. };
  21. // MD5 Hash
  22. typedef struct
  23. {
  24. unsigned int buf[4];
  25. unsigned int bits[2];
  26. unsigned char in[64];
  27. } MD5Context_t;
  28. void MD5Init( MD5Context_t *context );
  29. void MD5Update( MD5Context_t *context, unsigned char const *buf, unsigned int len );
  30. void MD5Final( unsigned char digest[ MD5_DIGEST_LENGTH ], MD5Context_t *context );
  31. char *MD5_Print(unsigned char *digest, int hashlen );
  32. /// Convenience wrapper to calculate the MD5 for a buffer, all in one step, without
  33. /// bothering with the context object.
  34. void MD5_ProcessSingleBuffer( const void *p, int len, MD5Value_t &md5Result );
  35. unsigned int MD5_PseudoRandom(unsigned int nSeed);
  36. /// Returns true if the values match.
  37. bool MD5_Compare( const MD5Value_t &data, const MD5Value_t &compare );
  38. inline bool MD5Value_t::operator==( const MD5Value_t &src ) const
  39. {
  40. return MD5_Compare( *this, src );
  41. }
  42. inline bool MD5Value_t::operator!=( const MD5Value_t &src ) const
  43. {
  44. return !MD5_Compare( *this, src );
  45. }
  46. #endif // CHECKSUM_MD5_H