wake.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // wake.h - originally written and placed in the public domain by Wei Dai
  2. /// \file wake.h
  3. /// \brief Classes for WAKE stream cipher
  4. #ifndef CRYPTOPP_WAKE_H
  5. #define CRYPTOPP_WAKE_H
  6. #include "seckey.h"
  7. #include "secblock.h"
  8. #include "strciphr.h"
  9. NAMESPACE_BEGIN(CryptoPP)
  10. /// \brief WAKE stream cipher information
  11. /// \tparam B Endianness of the stream cipher
  12. /// \since Crypto++ 1.0
  13. template <class B = BigEndian>
  14. struct WAKE_OFB_Info : public FixedKeyLength<32>
  15. {
  16. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "WAKE-OFB-LE" : "WAKE-OFB-BE";}
  17. };
  18. class CRYPTOPP_NO_VTABLE WAKE_Base
  19. {
  20. protected:
  21. word32 M(word32 x, word32 y);
  22. void GenKey(word32 k0, word32 k1, word32 k2, word32 k3);
  23. word32 t[257];
  24. word32 r3, r4, r5, r6;
  25. };
  26. /// \brief WAKE stream cipher operation
  27. /// \tparam B Endianness of the stream cipher
  28. /// \since Crypto++ 1.0
  29. template <class B = BigEndian>
  30. class CRYPTOPP_NO_VTABLE WAKE_Policy : public AdditiveCipherConcretePolicy<word32, 1, 64>, protected WAKE_Base
  31. {
  32. protected:
  33. void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
  34. // OFB
  35. void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
  36. bool CipherIsRandomAccess() const {return false;}
  37. };
  38. /// \brief WAKE stream cipher
  39. /// \tparam B Endianness of the stream cipher
  40. /// \since Crypto++ 1.0
  41. template <class B = BigEndian>
  42. struct WAKE_OFB : public WAKE_OFB_Info<B>, public SymmetricCipherDocumentation
  43. {
  44. typedef SymmetricCipherFinal<ConcretePolicyHolder<WAKE_Policy<B>, AdditiveCipherTemplate<> >, WAKE_OFB_Info<B> > Encryption;
  45. typedef Encryption Decryption;
  46. };
  47. NAMESPACE_END
  48. #endif