1 // Sha256Reg.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../../C/Sha256.h"
6 
7 #include "../Common/MyCom.h"
8 
9 #include "../7zip/ICoder.h"
10 #include "../7zip/Common/RegisterCodec.h"
11 
12 class CSha256Hasher:
13   public IHasher,
14   public CMyUnknownImp
15 {
16   CSha256 _sha;
17 public:
CSha256Hasher()18   CSha256Hasher() { Init(); };
19 
20   MY_UNKNOWN_IMP
21 
22   STDMETHOD_(void, Init)();
23   STDMETHOD_(void, Update)(const void *data, UInt32 size);
24   STDMETHOD_(void, Final)(Byte *digest);
25   STDMETHOD_(UInt32, GetDigestSize)();
26 };
27 
STDMETHODIMP_(void)28 STDMETHODIMP_(void) CSha256Hasher::Init()
29 {
30   Sha256_Init(&_sha);
31 }
32 
STDMETHODIMP_(void)33 STDMETHODIMP_(void) CSha256Hasher::Update(const void *data, UInt32 size)
34 {
35   Sha256_Update(&_sha, (const Byte *)data, size);
36 }
37 
STDMETHODIMP_(void)38 STDMETHODIMP_(void) CSha256Hasher::Final(Byte *digest)
39 {
40   Sha256_Final(&_sha, digest);
41 }
42 
STDMETHODIMP_(UInt32)43 STDMETHODIMP_(UInt32) CSha256Hasher::GetDigestSize()
44 {
45   return SHA256_DIGEST_SIZE;
46 }
47 
CreateHasher()48 static IHasher *CreateHasher() { return new CSha256Hasher; }
49 
50 static CHasherInfo g_HasherInfo = { CreateHasher, 0xA, L"SHA256", SHA256_DIGEST_SIZE };
51 
52 REGISTER_HASHER(Sha256)
53