aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/CksumReg.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/CksumReg.cpp
parent98e06a519b63b81986abe76d28887f6984a7732b (diff)
download7zip-21.07.tar.gz
7zip-21.07.tar.bz2
7zip-21.07.zip
'21.07'21.07
Diffstat (limited to 'CPP/Common/CksumReg.cpp')
-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)