Team Fortress 2 Source Code as on 22/4/2020
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.6 KiB

  1. //========= Copyright 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. #define MD5_BIT_LENGTH ( MD5_DIGEST_LENGTH * sizeof(unsigned char) )
  14. struct MD5Value_t
  15. {
  16. unsigned char bits[MD5_DIGEST_LENGTH];
  17. void Zero();
  18. bool IsZero() const;
  19. bool operator==( const MD5Value_t &src ) const;
  20. bool operator!=( const MD5Value_t &src ) const;
  21. };
  22. // MD5 Hash
  23. typedef struct
  24. {
  25. unsigned int buf[4];
  26. unsigned int bits[2];
  27. unsigned char in[64];
  28. } MD5Context_t;
  29. void MD5Init( MD5Context_t *context );
  30. void MD5Update( MD5Context_t *context, unsigned char const *buf, unsigned int len );
  31. void MD5Final( unsigned char digest[ MD5_DIGEST_LENGTH ], MD5Context_t *context );
  32. char *MD5_Print(unsigned char *digest, int hashlen );
  33. /// Convenience wrapper to calculate the MD5 for a buffer, all in one step, without
  34. /// bothering with the context object.
  35. void MD5_ProcessSingleBuffer( const void *p, int len, MD5Value_t &md5Result );
  36. unsigned int MD5_PseudoRandom(unsigned int nSeed);
  37. /// Returns true if the values match.
  38. bool MD5_Compare( const MD5Value_t &data, const MD5Value_t &compare );
  39. inline bool MD5Value_t::operator==( const MD5Value_t &src ) const
  40. {
  41. return MD5_Compare( *this, src );
  42. }
  43. inline bool MD5Value_t::operator!=( const MD5Value_t &src ) const
  44. {
  45. return !MD5_Compare( *this, src );
  46. }
  47. #endif // CHECKSUM_MD5_H