diff options
Diffstat (limited to '')
| -rw-r--r-- | CPP/Common/Sha256Reg.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/CPP/Common/Sha256Reg.cpp b/CPP/Common/Sha256Reg.cpp new file mode 100644 index 0000000..5f3a35b --- /dev/null +++ b/CPP/Common/Sha256Reg.cpp | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | // Sha256Reg.cpp | ||
| 2 | |||
| 3 | #include "StdAfx.h" | ||
| 4 | |||
| 5 | #include "../../C/Sha256.h" | ||
| 6 | |||
| 7 | #include "../Common/MyBuffer2.h" | ||
| 8 | #include "../Common/MyCom.h" | ||
| 9 | |||
| 10 | #include "../7zip/Common/RegisterCodec.h" | ||
| 11 | |||
| 12 | class CSha256Hasher: | ||
| 13 | public IHasher, | ||
| 14 | public ICompressSetCoderProperties, | ||
| 15 | public CMyUnknownImp | ||
| 16 | { | ||
| 17 | CAlignedBuffer _buf; | ||
| 18 | Byte mtDummy[1 << 7]; | ||
| 19 | |||
| 20 | CSha256 *Sha() { return (CSha256 *)(void *)(Byte *)_buf; } | ||
| 21 | public: | ||
| 22 | CSha256Hasher(): | ||
| 23 | _buf(sizeof(CSha256)) | ||
| 24 | { | ||
| 25 | Sha256_SetFunction(Sha(), 0); | ||
| 26 | Sha256_InitState(Sha()); | ||
| 27 | } | ||
| 28 | |||
| 29 | MY_UNKNOWN_IMP2(IHasher, ICompressSetCoderProperties) | ||
| 30 | INTERFACE_IHasher(;) | ||
| 31 | STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); | ||
| 32 | }; | ||
| 33 | |||
| 34 | STDMETHODIMP_(void) CSha256Hasher::Init() throw() | ||
| 35 | { | ||
| 36 | Sha256_InitState(Sha()); | ||
| 37 | } | ||
| 38 | |||
| 39 | STDMETHODIMP_(void) CSha256Hasher::Update(const void *data, UInt32 size) throw() | ||
| 40 | { | ||
| 41 | Sha256_Update(Sha(), (const Byte *)data, size); | ||
| 42 | } | ||
| 43 | |||
| 44 | STDMETHODIMP_(void) CSha256Hasher::Final(Byte *digest) throw() | ||
| 45 | { | ||
| 46 | Sha256_Final(Sha(), digest); | ||
| 47 | } | ||
| 48 | |||
| 49 | |||
| 50 | STDMETHODIMP CSha256Hasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps) | ||
| 51 | { | ||
| 52 | unsigned algo = 0; | ||
| 53 | for (UInt32 i = 0; i < numProps; i++) | ||
| 54 | { | ||
| 55 | const PROPVARIANT &prop = coderProps[i]; | ||
| 56 | if (propIDs[i] == NCoderPropID::kDefaultProp) | ||
| 57 | { | ||
| 58 | if (prop.vt != VT_UI4) | ||
| 59 | return E_INVALIDARG; | ||
| 60 | if (prop.ulVal > 2) | ||
| 61 | return E_NOTIMPL; | ||
| 62 | algo = (unsigned)prop.ulVal; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | if (!Sha256_SetFunction(Sha(), algo)) | ||
| 66 | return E_NOTIMPL; | ||
| 67 | return S_OK; | ||
| 68 | } | ||
| 69 | |||
| 70 | REGISTER_HASHER(CSha256Hasher, 0xA, "SHA256", SHA256_DIGEST_SIZE) | ||
