Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:08

0001 // seal.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file seal.h

0004 /// \brief Classes for SEAL stream cipher

0005 /// \since Crypto++ 2.2

0006 
0007 #ifndef CRYPTOPP_SEAL_H
0008 #define CRYPTOPP_SEAL_H
0009 
0010 #include "strciphr.h"
0011 #include "secblock.h"
0012 
0013 NAMESPACE_BEGIN(CryptoPP)
0014 
0015 /// \brief SEAL stream cipher information

0016 /// \tparam B Endianness of the stream cipher

0017 /// \since Crypto++ 2.2

0018 template <class B = BigEndian>
0019 struct SEAL_Info : public FixedKeyLength<20, SimpleKeyingInterface::INTERNALLY_GENERATED_IV, 4>
0020 {
0021     CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "SEAL-3.0-LE" : "SEAL-3.0-BE";}
0022 };
0023 
0024 /// \brief SEAL stream cipher operation

0025 /// \tparam B Endianness of the stream cipher

0026 /// \since Crypto++ 2.2

0027 template <class B = BigEndian>
0028 class CRYPTOPP_NO_VTABLE SEAL_Policy : public AdditiveCipherConcretePolicy<word32, 256>, public SEAL_Info<B>
0029 {
0030 protected:
0031     void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
0032     void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
0033     void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
0034     bool CipherIsRandomAccess() const {return true;}
0035     void SeekToIteration(lword iterationCount);
0036 
0037 private:
0038     FixedSizeSecBlock<word32, 512> m_T;
0039     FixedSizeSecBlock<word32, 256> m_S;
0040     SecBlock<word32> m_R;
0041 
0042     word32 m_startCount, m_iterationsPerCount;
0043     word32 m_outsideCounter, m_insideCounter;
0044 };
0045 
0046 /// \brief SEAL stream cipher

0047 /// \tparam B Endianness of the stream cipher

0048 /// \sa <a href="http://www.cryptopp.com/wiki/SEAL-3.0-BE">SEAL</a>

0049 /// \since Crypto++ 2.2

0050 template <class B = BigEndian>
0051 struct SEAL : public SEAL_Info<B>, public SymmetricCipherDocumentation
0052 {
0053     typedef SymmetricCipherFinal<ConcretePolicyHolder<SEAL_Policy<B>, AdditiveCipherTemplate<> >, SEAL_Info<B> > Encryption;
0054     typedef Encryption Decryption;
0055 };
0056 
0057 NAMESPACE_END
0058 
0059 #endif