aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/CksumReg.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Common/CksumReg.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/CPP/Common/CksumReg.cpp b/CPP/Common/CksumReg.cpp
new file mode 100644
index 0000000..29d9f82
--- /dev/null
+++ b/CPP/Common/CksumReg.cpp
@@ -0,0 +1,60 @@
1// CksumReg.cpp
2
3#include "StdAfx.h"
4
5#include "../../C/CpuArch.h"
6
7#include "../Common/MyCom.h"
8
9#include "../7zip/Common/RegisterCodec.h"
10
11#include "../7zip/Compress/BZip2Crc.h"
12
13class CCksumHasher:
14 public IHasher,
15 public CMyUnknownImp
16{
17 CBZip2Crc _crc;
18 UInt64 _size;
19 Byte mtDummy[1 << 7];
20
21public:
22 CCksumHasher()
23 {
24 _crc.Init(0);
25 _size = 0;
26 }
27
28 MY_UNKNOWN_IMP1(IHasher)
29 INTERFACE_IHasher(;)
30};
31
32STDMETHODIMP_(void) CCksumHasher::Init() throw()
33{
34 _crc.Init(0);
35 _size = 0;
36}
37
38STDMETHODIMP_(void) CCksumHasher::Update(const void *data, UInt32 size) throw()
39{
40 _size += size;
41 CBZip2Crc crc = _crc;
42 for (UInt32 i = 0; i < size; i++)
43 crc.UpdateByte(((const Byte *)data)[i]);
44 _crc = crc;
45}
46
47STDMETHODIMP_(void) CCksumHasher::Final(Byte *digest) throw()
48{
49 UInt64 size = _size;
50 CBZip2Crc crc = _crc;
51 while (size)
52 {
53 crc.UpdateByte((Byte)size);
54 size >>= 8;
55 }
56 const UInt32 val = crc.GetDigest();
57 SetUi32(digest, val);
58}
59
60REGISTER_HASHER(CCksumHasher, 0x203, "CKSUM", 4)