Crypto++ 8.1 Free C++ class library of cryptographic schemes

rabbit.h
Go to the documentation of this file.
1 // rabbit.h - written and placed in the public domain by Jeffrey Walton
2 // based on public domain code by Martin Boesgaard, Mette Vesterager,
3 // Thomas Pedersen, Jesper Christiansen and Ove Scavenius.
4 //
5 // The reference materials and source files are available at
6 // The eSTREAM Project, http://www.ecrypt.eu.org/stream/e2-rabbit.html.
7
8 /// \file rabbit.h
9 /// \brief Classes for Rabbit stream cipher
10 /// \sa <A HREF="http://www.ecrypt.eu.org/stream/e2-rabbit.html">The
11 /// eSTREAM Project | Rabbit</A> and
12 /// <A HREF="https://www.cryptopp.com/wiki/Rabbit">Crypto++ Wiki | Rabbit</A>.
13 /// \since Crypto++ 8.0
14
15 #ifndef CRYPTOPP_RABBIT_H
16 #define CRYPTOPP_RABBIT_H
17
18 #include "strciphr.h"
19 #include "secblock.h"
20
21 // The library does not have a way to describe an optional IV. Rabbit takes
22 // an optional IV so two classes are offered to bridge the gap. One provides
23 // Rabbit without an IV and the second provides Rabbit with an IV.
24
25 NAMESPACE_BEGIN(CryptoPP)
26
27 /// \brief Rabbit stream cipher information
28 /// \since Crypto++ 8.0
29 struct RabbitInfo : public FixedKeyLength<16, SimpleKeyingInterface::NOT_RESYNCHRONIZABLE>
30 {
31 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "Rabbit"; }
32 };
33
34 /// \brief Rabbit stream cipher information
35 /// \since Crypto++ 8.0
36 struct RabbitWithIVInfo : public FixedKeyLength<16, SimpleKeyingInterface::UNIQUE_IV, 8>
37 {
38 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "RabbitWithIV"; }
39 };
40
41 /// \brief Rabbit stream cipher implementation
42 /// \since Crypto++ 8.0
43 class RabbitPolicy : public AdditiveCipherConcretePolicy<word32, 4>, public RabbitInfo
44 {
45 protected:
46 void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
47 void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
48 bool CanOperateKeystream() const { return true; }
49 bool CipherIsRandomAccess() const { return false; }
50
51 private:
52 // Master and working states
53 FixedSizeSecBlock<word32, 8> m_mx, m_mc, m_wx, m_wc;
54 // Workspace
55 FixedSizeSecBlock<word32, 12> m_t;
56 word32 m_mcy, m_wcy; // carry
57 };
58
59 /// \brief Rabbit stream cipher implementation
60 /// \since Crypto++ 8.0
61 class RabbitWithIVPolicy : public AdditiveCipherConcretePolicy<word32, 4>, public RabbitWithIVInfo
62 {
63 protected:
64 void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
65 void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
66 void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length);
67 bool CanOperateKeystream() const { return true; }
68 bool CipherIsRandomAccess() const { return false; }
69
70 private:
71 // Master and working states
72 FixedSizeSecBlock<word32, 8> m_mx, m_mc, m_wx, m_wc;
73 // Workspace
74 FixedSizeSecBlock<word32, 12> m_t;
75 word32 m_mcy, m_wcy; // carry
76 };
77
78 /// \brief Rabbit stream cipher
79 /// \details Rabbit is a stream cipher developed by Martin Boesgaard, Mette Vesterager,
80 /// Thomas Pedersen, Jesper Christiansen and Ove Scavenius. Rabbit is one of the final four
81 /// Profile 1 (software) ciphers selected for the eSTREAM portfolio.
82 /// \details Crypto++ provides Rabbit and RabbitWithIV classes. Two classes are necessary
83 /// because the library lacks the means to describe and manage optional IVs.
84 /// \sa RabbitWithIV, <A HREF="http://www.ecrypt.eu.org/stream/e2-rabbit.html">The
85 /// eSTREAM Project | Rabbit</A> and
86 /// <A HREF="https://www.cryptopp.com/wiki/Rabbit">Crypto++ Wiki | Rabbit</A>.
87 /// \since Crypto++ 8.0
88 struct Rabbit : public RabbitInfo, public SymmetricCipherDocumentation
89 {
90 typedef SymmetricCipherFinal<ConcretePolicyHolder<RabbitPolicy, AdditiveCipherTemplate<> >, RabbitInfo> Encryption;
91 typedef Encryption Decryption;
92 };
93
94 /// \brief Rabbit stream cipher
95 /// \details Rabbit is a stream cipher developed by Martin Boesgaard, Mette Vesterager,
96 /// Thomas Pedersen, Jesper Christiansen and Ove Scavenius. Rabbit is one of the final four
97 /// Profile 1 (software) ciphers selected for the eSTREAM portfolio.
98 /// \details Crypto++ provides Rabbit and RabbitWithIV classes. Two classes are necessary
99 /// because the library lacks the means to describe and manage optional IVs.
100 /// \sa Rabbit, <A HREF="http://www.ecrypt.eu.org/stream/e2-rabbit.html">The
101 /// eSTREAM Project | Rabbit</A> and
102 /// <A HREF="https://www.cryptopp.com/wiki/Rabbit">Crypto++ Wiki | Rabbit</A>.
103 /// \since Crypto++ 8.0
104 struct RabbitWithIV : public RabbitWithIVInfo, public SymmetricCipherDocumentation
105 {
106 typedef SymmetricCipherFinal<ConcretePolicyHolder<RabbitWithIVPolicy, AdditiveCipherTemplate<> >, RabbitWithIVInfo> Encryption;
107 typedef Encryption Decryption;
108 };
109
110 NAMESPACE_END
111
112 #endif // CRYPTOPP_RABBIT_H
FixedKeyLength
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:124
RabbitWithIVInfo
Rabbit stream cipher information.
Definition: rabbit.h:36
AdditiveCipherConcretePolicy
Base class for additive stream ciphers.
Definition: strciphr.h:201
RabbitWithIVPolicy
Rabbit stream cipher implementation.
Definition: rabbit.h:61
RabbitPolicy
Rabbit stream cipher implementation.
Definition: rabbit.h:43
secblock.h
Classes and functions for secure memory allocations.
SimpleKeyingInterface
Interface for algorithms that take byte strings as keys.
Definition: cryptlib.h:613
FixedSizeSecBlock< word32, 8 >
strciphr.h
Classes for implementing stream ciphers.
SymmetricCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
Definition: seckey.h:413
KeystreamOperation
KeystreamOperation
Keystream operation flags.
Definition: strciphr.h:88
CryptoPP
Crypto++ library namespace.
SymmetricCipherFinal
SymmetricCipher implementation.
Definition: strciphr.h:673
Rabbit
Rabbit stream cipher.
Definition: rabbit.h:88
RabbitWithIV
Rabbit stream cipher.
Definition: rabbit.h:104
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:293
RabbitInfo
Rabbit stream cipher information.
Definition: rabbit.h:29