sosemanuk.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // sosemanuk.h - originally written and placed in the public domain by Wei Dai
  2. /// \file sosemanuk.h
  3. /// \brief Classes for Sosemanuk stream cipher
  4. /// \since Crypto++ 5.5
  5. #ifndef CRYPTOPP_SOSEMANUK_H
  6. #define CRYPTOPP_SOSEMANUK_H
  7. #include "strciphr.h"
  8. #include "secblock.h"
  9. // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
  10. // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232
  11. #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM)
  12. # define CRYPTOPP_DISABLE_SOSEMANUK_ASM 1
  13. #endif
  14. NAMESPACE_BEGIN(CryptoPP)
  15. /// \brief Sosemanuk stream cipher information
  16. /// \since Crypto++ 5.5
  17. struct SosemanukInfo : public VariableKeyLength<16, 1, 32, 1, SimpleKeyingInterface::UNIQUE_IV, 16>
  18. {
  19. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Sosemanuk";}
  20. };
  21. /// \brief Sosemanuk stream cipher implementation
  22. /// \since Crypto++ 5.5
  23. class SosemanukPolicy : public AdditiveCipherConcretePolicy<word32, 20>, public SosemanukInfo
  24. {
  25. protected:
  26. std::string AlgorithmProvider() const;
  27. void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
  28. void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
  29. void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length);
  30. bool CipherIsRandomAccess() const {return false;}
  31. #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
  32. unsigned int GetAlignment() const;
  33. unsigned int GetOptimalBlockSize() const;
  34. #endif
  35. FixedSizeSecBlock<word32, 25*4> m_key;
  36. FixedSizeAlignedSecBlock<word32, 12> m_state;
  37. };
  38. /// \brief Sosemanuk stream cipher
  39. /// \details is a stream cipher developed by Come Berbain, Olivier Billet, Anne Canteaut, Nicolas Courtois,
  40. /// Henri Gilbert, Louis Goubin, Aline Gouget, Louis Granboulan, Cédric Lauradoux, Marine Minier, Thomas
  41. /// Pornin and Hervé Sibert. Sosemanuk is one of the final four Profile 1 (software) ciphers selected for
  42. /// the eSTREAM Portfolio.
  43. /// \sa <a href="http://www.cryptolounge.org/wiki/Sosemanuk">Sosemanuk</a>
  44. /// \since Crypto++ 5.5
  45. struct Sosemanuk : public SosemanukInfo, public SymmetricCipherDocumentation
  46. {
  47. typedef SymmetricCipherFinal<ConcretePolicyHolder<SosemanukPolicy, AdditiveCipherTemplate<> >, SosemanukInfo> Encryption;
  48. typedef Encryption Decryption;
  49. };
  50. NAMESPACE_END
  51. #endif