Leaked source code of windows server 2003
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.

63 lines
1.5 KiB

  1. #include "nt.h"
  2. #include "ntrtl.h"
  3. #include "nturtl.h"
  4. #include "hashers.h"
  5. #include "sha.h"
  6. #include "sha2.h"
  7. CSha1HashObject::CSha1HashObject() : Finalized(false) { }
  8. CSha1HashObject::~CSha1HashObject() { }
  9. CEnv::StatusCode CSha1HashObject::Initialize()
  10. {
  11. Finalized = false;
  12. ZeroMemory(FinalResult, sizeof(FinalResult));
  13. A_SHAInit(this);
  14. return CEnv::SuccessCode;
  15. }
  16. CEnv::StatusCode
  17. CSha1HashObject::Hash(const CEnv::CConstantByteRegion& region)
  18. {
  19. if (Finalized)
  20. return CEnv::InvalidParameter;
  21. A_SHAUpdate(this, const_cast<unsigned char*>(region.GetPointer()), region.GetCount());
  22. return CEnv::SuccessCode;
  23. }
  24. CEnv::StatusCode CSha1HashObject::Finalize()
  25. {
  26. if (!Finalized)
  27. {
  28. A_SHAFinal(this, FinalResult);
  29. Finalized = true;
  30. }
  31. return CEnv::SuccessCode;
  32. }
  33. CEnv::StatusCode
  34. CSha1HashObject::GetValue(CEnv::CConstantByteRegion &pBytes) const
  35. {
  36. pBytes.SetPointerAndCount(NULL, 0);
  37. if (!Finalized)
  38. return CEnv::InvalidParameter;
  39. pBytes.SetPointerAndCount(FinalResult, sizeof(FinalResult));
  40. return CEnv::SuccessCode;
  41. }
  42. const CEnv::CConstantByteRegion CSha1HashObject::s_Sha1Oid = CEnv::CConstantByteRegion(NULL, 0);
  43. const CEnv::CConstantUnicodeStringPair CSha1HashObject::s_Sha1AlgName = CEnv::CConstantUnicodeStringPair(L"SHA1", 4);
  44. void *CHashObject::operator new(size_t cb)
  45. {
  46. return HeapAlloc(GetProcessHeap(), 0, cb);
  47. }
  48. void CHashObject::operator delete(void *p)
  49. {
  50. HeapFree(GetProcessHeap(), 0, p);
  51. }