diff src/win32/7zip/7z/CPP/7zip/Crypto/7zAes.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/7zAes.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,117 @@
     1.4 +// 7zAes.h
     1.5 +
     1.6 +#ifndef __CRYPTO_7Z_AES_H
     1.7 +#define __CRYPTO_7Z_AES_H
     1.8 +
     1.9 +#include "Common/Buffer.h"
    1.10 +#include "Common/MyCom.h"
    1.11 +#include "Common/MyVector.h"
    1.12 +
    1.13 +#include "../ICoder.h"
    1.14 +#include "../IPassword.h"
    1.15 +
    1.16 +namespace NCrypto {
    1.17 +namespace NSevenZ {
    1.18 +
    1.19 +const int kKeySize = 32;
    1.20 +
    1.21 +class CKeyInfo
    1.22 +{
    1.23 +public:
    1.24 +  int NumCyclesPower;
    1.25 +  UInt32 SaltSize;
    1.26 +  Byte Salt[16];
    1.27 +  CByteBuffer Password;
    1.28 +  Byte Key[kKeySize];
    1.29 +
    1.30 +  bool IsEqualTo(const CKeyInfo &a) const;
    1.31 +  void CalculateDigest();
    1.32 +
    1.33 +  CKeyInfo() { Init(); }
    1.34 +  void Init()
    1.35 +  {
    1.36 +    NumCyclesPower = 0;
    1.37 +    SaltSize = 0;
    1.38 +    for (int i = 0; i < sizeof(Salt); i++)
    1.39 +      Salt[i] = 0;
    1.40 +  }
    1.41 +};
    1.42 +
    1.43 +class CKeyInfoCache
    1.44 +{
    1.45 +  int Size;
    1.46 +  CObjectVector<CKeyInfo> Keys;
    1.47 +public:
    1.48 +  CKeyInfoCache(int size): Size(size) {}
    1.49 +  bool Find(CKeyInfo &key);
    1.50 +  // HRESULT Calculate(CKeyInfo &key);
    1.51 +  void Add(CKeyInfo &key);
    1.52 +};
    1.53 +
    1.54 +class CBase
    1.55 +{
    1.56 +  CKeyInfoCache _cachedKeys;
    1.57 +protected:
    1.58 +  CKeyInfo _key;
    1.59 +  Byte _iv[16];
    1.60 +  UInt32 _ivSize;
    1.61 +  void CalculateDigest();
    1.62 +  CBase();
    1.63 +};
    1.64 +
    1.65 +class CBaseCoder:
    1.66 +  public ICompressFilter,
    1.67 +  public ICryptoSetPassword,
    1.68 +  public CMyUnknownImp,
    1.69 +  public CBase
    1.70 +{
    1.71 +protected:
    1.72 +  CMyComPtr<ICompressFilter> _aesFilter;
    1.73 +
    1.74 +  virtual HRESULT CreateFilter() = 0;
    1.75 +  #ifndef CRYPTO_AES
    1.76 +  HRESULT CreateFilterFromDLL(REFCLSID clsID);
    1.77 +  #endif
    1.78 +public:
    1.79 +  STDMETHOD(Init)();
    1.80 +  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
    1.81 +  
    1.82 +  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
    1.83 +};
    1.84 +
    1.85 +#ifndef EXTRACT_ONLY
    1.86 +
    1.87 +class CEncoder:
    1.88 +  public CBaseCoder,
    1.89 +  public ICompressWriteCoderProperties,
    1.90 +  // public ICryptoResetSalt,
    1.91 +  public ICryptoResetInitVector
    1.92 +{
    1.93 +  virtual HRESULT CreateFilter();
    1.94 +public:
    1.95 +  MY_UNKNOWN_IMP3(
    1.96 +      ICryptoSetPassword,
    1.97 +      ICompressWriteCoderProperties,
    1.98 +      // ICryptoResetSalt,
    1.99 +      ICryptoResetInitVector)
   1.100 +  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
   1.101 +  // STDMETHOD(ResetSalt)();
   1.102 +  STDMETHOD(ResetInitVector)();
   1.103 +};
   1.104 +#endif
   1.105 +
   1.106 +class CDecoder:
   1.107 +  public CBaseCoder,
   1.108 +  public ICompressSetDecoderProperties2
   1.109 +{
   1.110 +  virtual HRESULT CreateFilter();
   1.111 +public:
   1.112 +  MY_UNKNOWN_IMP2(
   1.113 +      ICryptoSetPassword,
   1.114 +      ICompressSetDecoderProperties2)
   1.115 +  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
   1.116 +};
   1.117 +
   1.118 +}}
   1.119 +
   1.120 +#endif