view src/win32/7zip/7z/CPP/7zip/Crypto/Sha1.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line source
1 // Crypto/Sha1.h
2 // This file is based on public domain
3 // Steve Reid and Wei Dai's code from Crypto++
5 #ifndef __CRYPTO_SHA1_H
6 #define __CRYPTO_SHA1_H
8 #include <stddef.h>
9 #include "../../Common/Types.h"
11 // Sha1 implementation in RAR before version 3.60 has bug:
12 // it changes data bytes in some cases.
13 // So this class supports both versions: normal_SHA and rar3Mode
15 namespace NCrypto {
16 namespace NSha1 {
18 const unsigned kBlockSize = 64;
19 const unsigned kDigestSize = 20;
21 const unsigned kBlockSizeInWords = (kBlockSize >> 2);
22 const unsigned kDigestSizeInWords = (kDigestSize >> 2);
24 class CContextBase
25 {
26 protected:
27 UInt32 _state[5];
28 UInt64 _count;
29 void UpdateBlock(UInt32 *data, bool returnRes = false)
30 {
31 GetBlockDigest(data, _state, returnRes);
32 _count++;
33 }
34 public:
35 void Init();
36 void GetBlockDigest(UInt32 *blockData, UInt32 *destDigest, bool returnRes = false);
37 // PrepareBlock can be used only when size <= 13. size in Words
38 void PrepareBlock(UInt32 *block, unsigned int size) const;
39 };
41 class CContextBase2: public CContextBase
42 {
43 protected:
44 unsigned _count2;
45 UInt32 _buffer[kBlockSizeInWords];
46 void UpdateBlock() { CContextBase::UpdateBlock(_buffer); }
47 public:
48 void Init() { CContextBase::Init(); _count2 = 0; }
49 };
51 class CContext: public CContextBase2
52 {
53 public:
54 void Update(Byte *data, size_t size, bool rar350Mode = false);
55 void Update(const Byte *data, size_t size) { Update((Byte *)data, size, false); }
56 void Final(Byte *digest);
57 };
59 class CContext32: public CContextBase2
60 {
61 public:
62 void Update(const UInt32 *data, size_t size);
63 void Final(UInt32 *digest);
64 };
66 }}
68 #endif