diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Crypto/Sha1.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,68 @@
     1.4 +// Crypto/Sha1.h
     1.5 +// This file is based on public domain
     1.6 +// Steve Reid and Wei Dai's code from Crypto++
     1.7 +
     1.8 +#ifndef __CRYPTO_SHA1_H
     1.9 +#define __CRYPTO_SHA1_H
    1.10 +
    1.11 +#include <stddef.h>
    1.12 +#include "../../Common/Types.h"
    1.13 +
    1.14 +// Sha1 implementation in RAR before version 3.60 has bug:
    1.15 +// it changes data bytes in some cases.
    1.16 +// So this class supports both versions: normal_SHA and rar3Mode
    1.17 +
    1.18 +namespace NCrypto {
    1.19 +namespace NSha1 {
    1.20 +
    1.21 +const unsigned kBlockSize = 64;
    1.22 +const unsigned kDigestSize = 20;
    1.23 +
    1.24 +const unsigned kBlockSizeInWords = (kBlockSize >> 2);
    1.25 +const unsigned kDigestSizeInWords = (kDigestSize >> 2);
    1.26 +
    1.27 +class CContextBase
    1.28 +{
    1.29 +protected:
    1.30 +  UInt32 _state[5];
    1.31 +  UInt64 _count;
    1.32 +  void UpdateBlock(UInt32 *data, bool returnRes = false)
    1.33 +  {
    1.34 +    GetBlockDigest(data, _state, returnRes);
    1.35 +    _count++;
    1.36 +  }
    1.37 +public:
    1.38 +  void Init();
    1.39 +  void GetBlockDigest(UInt32 *blockData, UInt32 *destDigest, bool returnRes = false);
    1.40 +  // PrepareBlock can be used only when size <= 13. size in Words
    1.41 +  void PrepareBlock(UInt32 *block, unsigned int size) const;
    1.42 +};
    1.43 +
    1.44 +class CContextBase2: public CContextBase
    1.45 +{
    1.46 +protected:
    1.47 +  unsigned _count2;
    1.48 +  UInt32 _buffer[kBlockSizeInWords];
    1.49 +  void UpdateBlock() { CContextBase::UpdateBlock(_buffer); }
    1.50 +public:
    1.51 +  void Init() { CContextBase::Init(); _count2 = 0; }
    1.52 +};
    1.53 +
    1.54 +class CContext: public CContextBase2
    1.55 +{
    1.56 +public:
    1.57 +  void Update(Byte *data, size_t size, bool rar350Mode = false);
    1.58 +  void Update(const Byte *data, size_t size) { Update((Byte *)data, size, false); }
    1.59 +  void Final(Byte *digest);
    1.60 +};
    1.61 +
    1.62 +class CContext32: public CContextBase2
    1.63 +{
    1.64 +public:
    1.65 +  void Update(const UInt32 *data, size_t size);
    1.66 +  void Final(UInt32 *digest);
    1.67 +};
    1.68 +
    1.69 +}}
    1.70 +
    1.71 +#endif