1 // XzCrc64Reg.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../../C/CpuArch.h"
6 #include "../../C/XzCrc64.h"
7 
8 #include "../Common/MyCom.h"
9 
10 #include "../7zip/ICoder.h"
11 #include "../7zip/Common/RegisterCodec.h"
12 
13 class CXzCrc64Hasher:
14   public IHasher,
15   public CMyUnknownImp
16 {
17   UInt64 _crc;
18 public:
CXzCrc64Hasher()19   CXzCrc64Hasher(): _crc(CRC64_INIT_VAL) {}
20 
21   MY_UNKNOWN_IMP
22 
23   STDMETHOD_(void, Init)();
24   STDMETHOD_(void, Update)(const void *data, UInt32 size);
25   STDMETHOD_(void, Final)(Byte *digest);
26   STDMETHOD_(UInt32, GetDigestSize)();
27 };
28 
STDMETHODIMP_(void)29 STDMETHODIMP_(void) CXzCrc64Hasher::Init()
30 {
31   _crc = CRC64_INIT_VAL;
32 }
33 
STDMETHODIMP_(void)34 STDMETHODIMP_(void) CXzCrc64Hasher::Update(const void *data, UInt32 size)
35 {
36   _crc = Crc64Update(_crc, data, size);
37 }
38 
STDMETHODIMP_(void)39 STDMETHODIMP_(void) CXzCrc64Hasher::Final(Byte *digest)
40 {
41   UInt64 val = CRC64_GET_DIGEST(_crc);
42   SetUi64(digest, val);
43 }
44 
STDMETHODIMP_(UInt32)45 STDMETHODIMP_(UInt32) CXzCrc64Hasher::GetDigestSize()
46 {
47   return 8;
48 }
49 
CreateHasher()50 static IHasher *CreateHasher() { return new CXzCrc64Hasher; }
51 
52 static CHasherInfo g_HasherInfo = { CreateHasher, 0x4, L"CRC64", 8 };
53 
54 REGISTER_HASHER(Crc64)
55