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 12Z7_CLASS_IMP_COM_2( 13 CSha256Hasher 14 , IHasher 15 , ICompressSetCoderProperties 16) 17 CAlignedBuffer1 _buf; 18public: 19 Byte _mtDummy[1 << 7]; 20 21 CSha256 *Sha() { return (CSha256 *)(void *)(Byte *)_buf; } 22public: 23 CSha256Hasher(): 24 _buf(sizeof(CSha256)) 25 { 26 Sha256_SetFunction(Sha(), 0); 27 Sha256_InitState(Sha()); 28 } 29}; 30 31Z7_COM7F_IMF2(void, CSha256Hasher::Init()) 32{ 33 Sha256_InitState(Sha()); 34} 35 36Z7_COM7F_IMF2(void, CSha256Hasher::Update(const void *data, UInt32 size)) 37{ 38 Sha256_Update(Sha(), (const Byte *)data, size); 39} 40 41Z7_COM7F_IMF2(void, CSha256Hasher::Final(Byte *digest)) 42{ 43 Sha256_Final(Sha(), digest); 44} 45 46 47Z7_COM7F_IMF(CSha256Hasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps)) 48{ 49 unsigned algo = 0; 50 for (UInt32 i = 0; i < numProps; i++) 51 { 52 if (propIDs[i] == NCoderPropID::kDefaultProp) 53 { 54 const PROPVARIANT &prop = coderProps[i]; 55 if (prop.vt != VT_UI4) 56 return E_INVALIDARG; 57 if (prop.ulVal > 2) 58 return E_NOTIMPL; 59 algo = (unsigned)prop.ulVal; 60 } 61 } 62 if (!Sha256_SetFunction(Sha(), algo)) 63 return E_NOTIMPL; 64 return S_OK; 65} 66 67REGISTER_HASHER(CSha256Hasher, 0xA, "SHA256", SHA256_DIGEST_SIZE) 68