Source code of Windows XP (NT5)
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.

78 lines
1.8 KiB

  1. #pragma once
  2. #include "stdinc.h"
  3. #include "fusionarray.h"
  4. #include "wincrypt.h"
  5. #include "fusionhandle.h"
  6. #define A_SHA_DIGEST_LEN 20
  7. #ifndef INVALID_CRYPT_HASH
  8. #define INVALID_CRYPT_HASH (static_cast<HCRYPTHASH>(NULL))
  9. #endif
  10. #define PRIVATIZE_COPY_CONSTRUCTORS( obj ) obj( const obj& ); obj& operator=(const obj&);
  11. class CSha1Context
  12. {
  13. PRIVATIZE_COPY_CONSTRUCTORS(CSha1Context);
  14. unsigned char m_workspace[64];
  15. unsigned long state[5];
  16. SIZE_T count[2];
  17. unsigned char buffer[64];
  18. BOOL Transform( const unsigned char* buffer );
  19. public:
  20. CSha1Context() { }
  21. BOOL Update( const unsigned char* data, SIZE_T len );
  22. BOOL GetDigest( unsigned char* digest, PSIZE_T len );
  23. BOOL Initialize();
  24. };
  25. /*
  26. void A_SHATransform(CSha1Context* context, const unsigned char buffer);
  27. void A_SHAInit(CSha1Context* context);
  28. void A_SHAUpdate(CSha1Context* context, const unsigned char* data, const ULONG len);
  29. BOOL A_SHAFinal(CSha1Context* context, unsigned char* digest, ULONG *len);
  30. */
  31. class CFusionHash
  32. {
  33. private:
  34. PRIVATIZE_COPY_CONSTRUCTORS(CFusionHash);
  35. protected:
  36. CSha1Context m_Sha1Context;
  37. CCryptHash m_hCryptHash;
  38. ALG_ID m_aid;
  39. BOOL m_fInitialized;
  40. BOOL GetIsValid();
  41. public:
  42. CFusionHash()
  43. : m_fInitialized(FALSE), m_aid(0), m_hCryptHash(INVALID_CRYPT_HASH)
  44. { }
  45. BOOL Win32Initialize( ALG_ID aid );
  46. BOOL Win32HashData(const BYTE *pbBuffer, SIZE_T cbSize);
  47. BOOL Win32GetValue(OUT CFusionArray<BYTE> &out);
  48. };
  49. //
  50. // There's no "real" invalid value defined anywhere, but by inspecting the
  51. // codebase, NULL is the accepted "invalid" value - check the logon service
  52. // code, they do the same thing.
  53. //
  54. #define INVALID_CRYPT_HANDLE (static_cast<HCRYPTPROV>(NULL))
  55. //
  56. // Global crypto context stuff
  57. //
  58. BOOL SxspAcquireGlobalCryptContext( HCRYPTPROV *pContext );
  59. BOOL SxspReleaseGlobalCryptContext();