Crypto++ 8.7
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
25NAMESPACE_BEGIN(CryptoPP)
26
27/// \brief Rabbit stream cipher information
28/// \since Crypto++ 8.0
29struct 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
36struct 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
43class RabbitPolicy : public AdditiveCipherConcretePolicy<word32, 4>, public RabbitInfo
44{
45protected:
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
51private:
52 // Master and working states
53 FixedSizeSecBlock<word32, 8> m_mx, m_mc, m_wx, m_wc;
54 // Workspace
56 word32 m_mcy, m_wcy; // carry
57};
58
59/// \brief Rabbit stream cipher implementation
60/// \since Crypto++ 8.0
62{
63protected:
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
70private:
71 // Master and working states
72 FixedSizeSecBlock<word32, 8> m_mx, m_mc, m_wx, m_wc;
73 // Workspace
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
89{
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
105{
107 typedef Encryption Decryption;
108};
109
110NAMESPACE_END
111
112#endif // CRYPTOPP_RABBIT_H
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:125
Interface for retrieving values given their names.
Definition: cryptlib.h:322
Rabbit stream cipher implementation.
Definition: rabbit.h:44
Rabbit stream cipher implementation.
Definition: rabbit.h:62
Interface for algorithms that take byte strings as keys.
Definition: cryptlib.h:642
SymmetricCipher implementation.
Definition: strciphr.h:684
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:62
Crypto++ library namespace.
Classes and functions for secure memory allocations.
Classes for implementing stream ciphers.
KeystreamOperation
Keystream operation flags.
Definition: strciphr.h:88
Base class for additive stream ciphers.
Definition: strciphr.h:202
Rabbit stream cipher.
Definition: rabbit.h:89
Rabbit stream cipher information.
Definition: rabbit.h:30
Rabbit stream cipher.
Definition: rabbit.h:105
Rabbit stream cipher information.
Definition: rabbit.h:37
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher.
Definition: seckey.h:414