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.

62 lines
2.3 KiB

  1. #pragma once
  2. #include "sha.h"
  3. #include "sha2.h"
  4. #include "bcl_common.h"
  5. #include "environment.h"
  6. class CHashObject
  7. {
  8. protected:
  9. template <typename T> static T* CreateDerived();
  10. void * operator new(size_t cb);
  11. void operator delete(void *p);
  12. private:
  13. typedef struct {
  14. const CEnv::CConstantByteRegion &Oid;
  15. const CEnv::CConstantUnicodeStringPair &Name;
  16. CHashObject* (*pfnCreator)();
  17. } CHashObjectFactoryMember;
  18. static CHashObjectFactoryMember s_FactoryItems[];
  19. typedef CHashObject* (*pfnCreator)();
  20. public:
  21. virtual ~CHashObject() { }
  22. virtual CEnv::StatusCode Initialize() = 0;
  23. virtual CEnv::StatusCode Hash(const CEnv::CConstantByteRegion&) = 0;
  24. virtual CEnv::StatusCode Finalize() = 0;
  25. virtual CEnv::StatusCode GetValue(CEnv::CConstantByteRegion &pBytes) const = 0;
  26. virtual const CEnv::CConstantByteRegion &GetOid() const = 0;
  27. virtual const CEnv::CConstantUnicodeStringPair &GetAlgName() const = 0;
  28. static CHashObject *HashObjectFromName(const CEnv::CConstantUnicodeStringPair &TextName);
  29. static CHashObject *HashObjectFromOid(const CEnv::CConstantByteRegion &Oid);
  30. };
  31. class CSha1HashObject : public CHashObject, A_SHA_CTX
  32. {
  33. unsigned char FinalResult[A_SHA_DIGEST_LEN];
  34. bool Finalized;
  35. static const CEnv::CConstantByteRegion s_Sha1Oid;
  36. static const CEnv::CConstantUnicodeStringPair s_Sha1AlgName;
  37. CSha1HashObject(const CSha1HashObject&);
  38. void operator=(const CSha1HashObject&);
  39. public:
  40. CSha1HashObject();
  41. virtual ~CSha1HashObject();
  42. virtual CEnv::StatusCode Initialize();
  43. virtual CEnv::StatusCode Hash(const CEnv::CConstantByteRegion&);
  44. virtual CEnv::StatusCode Finalize();
  45. virtual CEnv::StatusCode GetValue(CEnv::CConstantByteRegion &pBytes) const;
  46. static const CEnv::CConstantByteRegion &Oid() { return s_Sha1Oid; }
  47. static const CEnv::CConstantUnicodeStringPair &AlgName() { return s_Sha1AlgName; }
  48. virtual const CEnv::CConstantByteRegion &GetOid() const { return CSha1HashObject::Oid(); }
  49. virtual const CEnv::CConstantUnicodeStringPair &GetAlgName() const { return CSha1HashObject::AlgName(); }
  50. static CHashObject* CreateSelf() { return CHashObject::CreateDerived<CSha1HashObject>(); }
  51. };