aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/Sha256Reg.cpp
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2021-12-27 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2022-03-18 15:35:13 +0500
commitf19f813537c7aea1c20749c914e756b54a9c3cf5 (patch)
tree816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Common/Sha256Reg.cpp
parent98e06a519b63b81986abe76d28887f6984a7732b (diff)
download7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.tar.gz
7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.tar.bz2
7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.zip
'21.07'21.07
Diffstat (limited to 'CPP/Common/Sha256Reg.cpp')
-rw-r--r--CPP/Common/Sha256Reg.cpp70
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
12class 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; }
21public:
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
34STDMETHODIMP_(void) CSha256Hasher::Init() throw()
35{
36 Sha256_InitState(Sha());
37}
38
39STDMETHODIMP_(void) CSha256Hasher::Update(const void *data, UInt32 size) throw()
40{
41 Sha256_Update(Sha(), (const Byte *)data, size);
42}
43
44STDMETHODIMP_(void) CSha256Hasher::Final(Byte *digest) throw()
45{
46 Sha256_Final(Sha(), digest);
47}
48
49
50STDMETHODIMP 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
70REGISTER_HASHER(CSha256Hasher, 0xA, "SHA256", SHA256_DIGEST_SIZE)