(this)->AccessSymmetricCipher();};
+
+ virtual SymmetricCipher & AccessSymmetricCipher() =0;
+ virtual bool AuthenticationIsOnPlaintext() const =0;
+ virtual unsigned int AuthenticationBlockSize() const =0;
+ virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) =0;
+ virtual void Resync(const byte *iv, size_t len) =0;
+ virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0;
+ virtual void AuthenticateLastHeaderBlock() =0;
+ virtual void AuthenticateLastConfidentialBlock() {}
+ virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0;
+
+ // State_AuthUntransformed: authentication is applied to plain text (Authenticate-then-Encrypt)
+ // State_AuthTransformed: authentication is applied to cipher text (Encrypt-then-Authenticate)
+ enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter};
+
+ AlignedSecByteBlock m_buffer;
+ lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength;
+ unsigned int m_bufferedDataLength;
+ State m_state;
+};
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/base32.h b/linux/include/cryptopp/base32.h
new file mode 100644
index 000000000..4eeae43ce
--- /dev/null
+++ b/linux/include/cryptopp/base32.h
@@ -0,0 +1,158 @@
+// base32.h - written and placed in the public domain by Frank Palazzolo, based on hex.cpp by Wei Dai
+// extended hex alphabet added by JW in November, 2017.
+
+/// \file base32.h
+/// \brief Classes for Base32Encoder, Base32Decoder, Base32HexEncoder and Base32HexDecoder
+
+#ifndef CRYPTOPP_BASE32_H
+#define CRYPTOPP_BASE32_H
+
+#include "cryptlib.h"
+#include "basecode.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief Base32 encodes data using DUDE encoding
+/// \details Converts data to base32 using DUDE encoding. The default code is based on Differential Unicode Domain Encoding (DUDE) (draft-ietf-idn-dude-02.txt).
+/// \sa Base32Encoder, Base32Decoder, Base32HexEncoder and Base32HexDecoder
+class Base32Encoder : public SimpleProxyFilter
+{
+public:
+ /// \brief Construct a Base32Encoder
+ /// \param attachment a BufferedTrasformation to attach to this object
+ /// \param uppercase a flag indicating uppercase output
+ /// \param groupSize the size of the grouping
+ /// \param separator the separator to use between groups
+ /// \param terminator the terminator appeand after processing
+ /// \details Base32Encoder() constructs a default encoder. The constructor lacks fields for padding and
+ /// line breaks. You must use IsolatedInitialize() to change the default padding character or suppress it.
+ /// \sa Base32Encoder, Base32Decoder, Base32HexEncoder and Base32HexDecoder
+ Base32Encoder(BufferedTransformation *attachment = NULLPTR, bool uppercase = true, int groupSize = 0, const std::string &separator = ":", const std::string &terminator = "")
+ : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment)
+ {
+ IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), groupSize)(Name::Separator(), ConstByteArrayParameter(separator))(Name::Terminator(), ConstByteArrayParameter(terminator)));
+ }
+
+ /// \brief Initialize or reinitialize this object, without signal propagation
+ /// \param parameters a set of NameValuePairs used to initialize this object
+ /// \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable
+ /// number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on attached
+ /// transformations. If initialization should be propagated, then use the Initialize() function.
+ /// \details The following code modifies the padding and line break parameters for an encoder:
+ ///
+ /// Base32Encoder encoder;
+ /// AlgorithmParameters params = MakeParameters(Pad(), false)(InsertLineBreaks(), false);
+ /// encoder.IsolatedInitialize(params);
+ /// \details You can change the encoding to RFC 4648, Base
+ /// 32 Encoding with Extended Hex Alphabet by performing the following:
+ ///
+ /// Base32Encoder encoder;
+ /// const byte ALPHABET[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
+ /// AlgorithmParameters params = MakeParameters(Name::EncodingLookupArray(),(const byte *)ALPHABET);
+ /// encoder.IsolatedInitialize(params);
+ /// \details If you change the encoding alphabet, then you will need to change the decoding alphabet \a and
+ /// the decoder's lookup table.
+ /// \sa Base32Encoder, Base32Decoder, Base32HexEncoder and Base32HexDecoder
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+};
+
+/// \brief Base32 decodes data using DUDE encoding
+/// \details Converts data from base32 using DUDE encoding. The default code is based on Differential Unicode Domain Encoding (DUDE) (draft-ietf-idn-dude-02.txt).
+/// \sa Base32Encoder, Base32Decoder, Base32HexEncoder and Base32HexDecoder
+class Base32Decoder : public BaseN_Decoder
+{
+public:
+ /// \brief Construct a Base32Decoder
+ /// \param attachment a BufferedTrasformation to attach to this object
+ /// \sa IsolatedInitialize() for an example of modifying a Base32Decoder after construction.
+ Base32Decoder(BufferedTransformation *attachment = NULLPTR)
+ : BaseN_Decoder(GetDefaultDecodingLookupArray(), 5, attachment) {}
+
+ /// \brief Initialize or reinitialize this object, without signal propagation
+ /// \param parameters a set of NameValuePairs used to initialize this object
+ /// \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable
+ /// number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on attached
+ /// transformations. If initialization should be propagated, then use the Initialize() function.
+ /// \details You can change the encoding to RFC 4648, Base
+ /// 32 Encoding with Extended Hex Alphabet by performing the following:
+ ///
+ /// int lookup[256];
+ /// const byte ALPHABET[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
+ /// Base32Decoder::InitializeDecodingLookupArray(lookup, ALPHABET, 32, true /*insensitive*/);
+ ///
+ /// Base32Decoder decoder;
+ /// AlgorithmParameters params = MakeParameters(Name::DecodingLookupArray(),(const int *)lookup);
+ /// decoder.IsolatedInitialize(params);
+ /// \sa Base32Encoder, Base32Decoder, Base32HexEncoder and Base32HexDecoder
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+
+private:
+ /// \brief Provides the default decoding lookup table
+ /// \return default decoding lookup table
+ static const int * CRYPTOPP_API GetDefaultDecodingLookupArray();
+};
+
+/// \brief Base32 encodes data using extended hex
+/// \details Converts data to base32 using extended hex alphabet. The alphabet is different than Base32Encoder.
+/// \sa Base32Encoder, Base32Decoder, Base32HexEncoder and Base32HexDecoder, RFC 4648, Base 32 Encoding with Extended Hex Alphabet.
+/// \since Crypto++ 6.0
+class Base32HexEncoder : public SimpleProxyFilter
+{
+public:
+ /// \brief Construct a Base32HexEncoder
+ /// \param attachment a BufferedTrasformation to attach to this object
+ /// \param uppercase a flag indicating uppercase output
+ /// \param groupSize the size of the grouping
+ /// \param separator the separator to use between groups
+ /// \param terminator the terminator appeand after processing
+ /// \details Base32HexEncoder() constructs a default encoder. The constructor lacks fields for padding and
+ /// line breaks. You must use IsolatedInitialize() to change the default padding character or suppress it.
+ /// \sa Base32Encoder, Base32Decoder, Base32HexEncoder and Base32HexDecoder
+ Base32HexEncoder(BufferedTransformation *attachment = NULLPTR, bool uppercase = true, int groupSize = 0, const std::string &separator = ":", const std::string &terminator = "")
+ : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment)
+ {
+ IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), groupSize)(Name::Separator(), ConstByteArrayParameter(separator))(Name::Terminator(), ConstByteArrayParameter(terminator)));
+ }
+
+ /// \brief Initialize or reinitialize this object, without signal propagation
+ /// \param parameters a set of NameValuePairs used to initialize this object
+ /// \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable
+ /// number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on attached
+ /// transformations. If initialization should be propagated, then use the Initialize() function.
+ /// \details The following code modifies the padding and line break parameters for an encoder:
+ ///
+ /// Base32HexEncoder encoder;
+ /// AlgorithmParameters params = MakeParameters(Pad(), false)(InsertLineBreaks(), false);
+ /// encoder.IsolatedInitialize(params);
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+};
+
+/// \brief Base32 decodes data using extended hex
+/// \details Converts data from base32 using extended hex alphabet. The alphabet is different than Base32Decoder.
+/// \sa Base32Encoder, Base32Decoder, Base32HexEncoder and Base32HexDecoder, RFC 4648, Base 32 Encoding with Extended Hex Alphabet.
+/// \since Crypto++ 6.0
+class Base32HexDecoder : public BaseN_Decoder
+{
+public:
+ /// \brief Construct a Base32HexDecoder
+ /// \param attachment a BufferedTrasformation to attach to this object
+ /// \sa Base32Encoder, Base32Decoder, Base32HexEncoder and Base32HexDecoder
+ Base32HexDecoder(BufferedTransformation *attachment = NULLPTR)
+ : BaseN_Decoder(GetDefaultDecodingLookupArray(), 5, attachment) {}
+
+ /// \brief Initialize or reinitialize this object, without signal propagation
+ /// \param parameters a set of NameValuePairs used to initialize this object
+ /// \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable
+ /// number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on attached
+ /// transformations. If initialization should be propagated, then use the Initialize() function.
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+
+private:
+ /// \brief Provides the default decoding lookup table
+ /// \return default decoding lookup table
+ static const int * CRYPTOPP_API GetDefaultDecodingLookupArray();
+};
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/base64.h b/linux/include/cryptopp/base64.h
new file mode 100644
index 000000000..5defc3740
--- /dev/null
+++ b/linux/include/cryptopp/base64.h
@@ -0,0 +1,158 @@
+// base64.h - originally written and placed in the public domain by Wei Dai
+
+/// \file base64.h
+/// \brief Classes for the Base64Encoder, Base64Decoder, Base64URLEncoder and Base64URLDecoder
+
+#ifndef CRYPTOPP_BASE64_H
+#define CRYPTOPP_BASE64_H
+
+#include "cryptlib.h"
+#include "basecode.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief Base64 encodes data using DUDE
+/// \details Base64 encodes data per RFC 4648, Base 64 Encoding.
+class Base64Encoder : public SimpleProxyFilter
+{
+public:
+ /// \brief Construct a Base64Encoder
+ /// \param attachment a BufferedTrasformation to attach to this object
+ /// \param insertLineBreaks a BufferedTrasformation to attach to this object
+ /// \param maxLineLength the length of a line if line breaks are used
+ /// \details Base64Encoder constructs a default encoder. The constructor lacks a parameter for padding, and you must
+ /// use IsolatedInitialize() to modify the Base64Encoder after construction.
+ /// \sa IsolatedInitialize() for an example of modifying an encoder after construction.
+ Base64Encoder(BufferedTransformation *attachment = NULLPTR, bool insertLineBreaks = true, int maxLineLength = 72)
+ : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment)
+ {
+ IsolatedInitialize(MakeParameters(Name::InsertLineBreaks(), insertLineBreaks)(Name::MaxLineLength(), maxLineLength));
+ }
+
+ /// \brief Initialize or reinitialize this object, without signal propagation
+ /// \param parameters a set of NameValuePairs used to initialize this object
+ /// \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable
+ /// number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on attached
+ /// transformations. If initialization should be propagated, then use the Initialize() function.
+ /// \details The following code modifies the padding and line break parameters for an encoder:
+ ///
+ /// Base64Encoder encoder;
+ /// AlgorithmParameters params = MakeParameters(Pad(), false)(InsertLineBreaks(), false);
+ /// encoder.IsolatedInitialize(params);
+ /// \details You can change the encoding to RFC 4648 web safe alphabet by performing the following:
+ ///
+ /// Base64Encoder encoder;
+ /// const byte ALPHABET[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+ /// AlgorithmParameters params = MakeParameters(Name::EncodingLookupArray(),(const byte *)ALPHABET);
+ /// encoder.IsolatedInitialize(params);
+ /// \details If you change the encoding alphabet, then you will need to change the decoding alphabet \a and
+ /// the decoder's lookup table.
+ /// \sa Base64URLEncoder for an encoder that provides the web safe alphabet, and Base64Decoder::IsolatedInitialize()
+ /// for an example of modifying a decoder's lookup table after construction.
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+};
+
+/// \brief Base64 decodes data using DUDE
+/// \details Base64 encodes data per RFC 4648, Base 64 Encoding.
+class Base64Decoder : public BaseN_Decoder
+{
+public:
+ /// \brief Construct a Base64Decoder
+ /// \param attachment a BufferedTrasformation to attach to this object
+ /// \sa IsolatedInitialize() for an example of modifying an encoder after construction.
+ Base64Decoder(BufferedTransformation *attachment = NULLPTR)
+ : BaseN_Decoder(GetDecodingLookupArray(), 6, attachment) {}
+
+ /// \brief Initialize or reinitialize this object, without signal propagation
+ /// \param parameters a set of NameValuePairs used to initialize this object
+ /// \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable
+ /// number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on attached
+ /// transformations. If initialization should be propagated, then use the Initialize() function.
+ /// \details The default decoding alpahbet is RFC 4868. You can change the to RFC 4868 web safe alphabet
+ /// by performing the following:
+ ///
+ /// int lookup[256];
+ /// const byte ALPHABET[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+ /// Base64Decoder::InitializeDecodingLookupArray(lookup, ALPHABET, 64, false);
+ ///
+ /// Base64Decoder decoder;
+ /// AlgorithmParameters params = MakeParameters(Name::DecodingLookupArray(),(const int *)lookup);
+ /// decoder.IsolatedInitialize(params);
+ /// \sa Base64URLDecoder for a decoder that provides the web safe alphabet, and Base64Encoder::IsolatedInitialize()
+ /// for an example of modifying an encoder's alphabet after construction.
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+
+private:
+ /// \brief Provides the default decoding lookup table
+ /// \return default decoding lookup table
+ static const int * CRYPTOPP_API GetDecodingLookupArray();
+};
+
+/// \brief Base64 encodes data using a web safe alphabet
+/// \details Base64 encodes data per RFC 4648, Base 64 Encoding
+/// with URL and Filename Safe Alphabet.
+class Base64URLEncoder : public SimpleProxyFilter
+{
+public:
+ /// \brief Construct a Base64URLEncoder
+ /// \param attachment a BufferedTrasformation to attach to this object
+ /// \param insertLineBreaks a BufferedTrasformation to attach to this object
+ /// \param maxLineLength the length of a line if line breaks are used
+ /// \details Base64URLEncoder() constructs a default encoder using a web safe alphabet. The constructor ignores
+ /// insertLineBreaks and maxLineLength because the web and URL safe specifications don't use them. They are
+ /// present in the constructor for API compatibility with Base64Encoder so it is a drop-in replacement. The
+ /// constructor also disables padding on the encoder for the same reason.
+ /// \details If you need line breaks or padding, then you must use IsolatedInitialize() to set them
+ /// after constructing a Base64URLEncoder.
+ /// \sa Base64Encoder for an encoder that provides a classic alphabet, and Base64URLEncoder::IsolatedInitialize
+ /// for an example of modifying an encoder after construction.
+ Base64URLEncoder(BufferedTransformation *attachment = NULLPTR, bool insertLineBreaks = false, int maxLineLength = -1)
+ : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment)
+ {
+ CRYPTOPP_UNUSED(insertLineBreaks), CRYPTOPP_UNUSED(maxLineLength);
+ IsolatedInitialize(MakeParameters(Name::InsertLineBreaks(), false)(Name::MaxLineLength(), -1)(Name::Pad(),false));
+ }
+
+ /// \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable
+ /// number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on attached
+ /// transformations. If initialization should be propagated, then use the Initialize() function.
+ /// \details The following code modifies the padding and line break parameters for an encoder:
+ ///
+ /// Base64URLEncoder encoder;
+ /// AlgorithmParameters params = MakeParameters(Name::Pad(), true)(Name::InsertLineBreaks(), true);
+ /// encoder.IsolatedInitialize(params);
+ /// \sa Base64Encoder for an encoder that provides a classic alphabet.
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+};
+
+/// \brief Base64 decodes data using a web safe alphabet
+/// \details Base64 encodes data per RFC 4648, Base 64 Encoding
+/// with URL and Filename Safe Alphabet.
+class Base64URLDecoder : public BaseN_Decoder
+{
+public:
+ /// \brief Construct a Base64URLDecoder
+ /// \param attachment a BufferedTrasformation to attach to this object
+ /// \details Base64URLDecoder() constructs a default decoder using a web safe alphabet.
+ /// \sa Base64Decoder for a decoder that provides a classic alphabet.
+ Base64URLDecoder(BufferedTransformation *attachment = NULLPTR)
+ : BaseN_Decoder(GetDecodingLookupArray(), 6, attachment) {}
+
+ /// \brief Initialize or reinitialize this object, without signal propagation
+ /// \param parameters a set of NameValuePairs used to initialize this object
+ /// \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable
+ /// number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on
+ /// attached transformations. If initialization should be propagated, then use the Initialize() function.
+ /// \sa Base64Decoder for a decoder that provides a classic alphabet, and Base64URLEncoder::IsolatedInitialize
+ /// for an example of modifying an encoder after construction.
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+
+private:
+ /// \brief Provides the default decoding lookup table
+ /// \return default decoding lookup table
+ static const int * CRYPTOPP_API GetDecodingLookupArray();
+};
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/basecode.h b/linux/include/cryptopp/basecode.h
new file mode 100644
index 000000000..1bfe68d11
--- /dev/null
+++ b/linux/include/cryptopp/basecode.h
@@ -0,0 +1,139 @@
+// basecode.h - originally written and placed in the public domain by Wei Dai
+
+/// \file
+/// \brief Base classes for working with encoders and decoders.
+
+#ifndef CRYPTOPP_BASECODE_H
+#define CRYPTOPP_BASECODE_H
+
+#include "cryptlib.h"
+#include "filters.h"
+#include "algparam.h"
+#include "argnames.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief Encoder for bases that are a power of 2
+class CRYPTOPP_DLL BaseN_Encoder : public Unflushable
+{
+public:
+ /// \brief Construct a BaseN_Encoder
+ /// \param attachment a BufferedTransformation to attach to this object
+ BaseN_Encoder(BufferedTransformation *attachment=NULLPTR)
+ : m_alphabet(NULLPTR), m_padding(0), m_bitsPerChar(0)
+ , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
+ {Detach(attachment);}
+
+ /// \brief Construct a BaseN_Encoder
+ /// \param alphabet table of ASCII characters to use as the alphabet
+ /// \param log2base the log2base
+ /// \param attachment a BufferedTransformation to attach to this object
+ /// \param padding the character to use as padding
+ /// \pre log2base must be between 1 and 7 inclusive
+ /// \throws InvalidArgument if log2base is not between 1 and 7
+ BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULLPTR, int padding=-1)
+ : m_alphabet(NULLPTR), m_padding(0), m_bitsPerChar(0)
+ , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
+ {
+ Detach(attachment);
+ IsolatedInitialize(MakeParameters(Name::EncodingLookupArray(), alphabet)
+ (Name::Log2Base(), log2base)
+ (Name::Pad(), padding != -1)
+ (Name::PaddingByte(), byte(padding)));
+ }
+
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+ size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
+
+private:
+ const byte *m_alphabet;
+ int m_padding, m_bitsPerChar, m_outputBlockSize;
+ int m_bytePos, m_bitPos;
+ SecByteBlock m_outBuf;
+};
+
+/// \brief Decoder for bases that are a power of 2
+class CRYPTOPP_DLL BaseN_Decoder : public Unflushable
+{
+public:
+ /// \brief Construct a BaseN_Decoder
+ /// \param attachment a BufferedTransformation to attach to this object
+ /// \details padding is set to -1, which means use default padding. If not
+ /// required, then the value must be set via IsolatedInitialize().
+ BaseN_Decoder(BufferedTransformation *attachment=NULLPTR)
+ : m_lookup(NULLPTR), m_padding(0), m_bitsPerChar(0)
+ , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
+ {Detach(attachment);}
+
+ /// \brief Construct a BaseN_Decoder
+ /// \param lookup table of values
+ /// \param log2base the log2base
+ /// \param attachment a BufferedTransformation to attach to this object
+ /// \details log2base is the exponent (like 5 in 25), and not
+ /// the number of elements (like 32).
+ /// \details padding is set to -1, which means use default padding. If not
+ /// required, then the value must be set via IsolatedInitialize().
+ BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULLPTR)
+ : m_lookup(NULLPTR), m_padding(0), m_bitsPerChar(0)
+ , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
+ {
+ Detach(attachment);
+ IsolatedInitialize(MakeParameters(Name::DecodingLookupArray(), lookup)(Name::Log2Base(), log2base));
+ }
+
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+ size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
+
+ /// \brief Initializes BaseN lookup array
+ /// \param lookup table of values
+ /// \param alphabet table of ASCII characters
+ /// \param base the base for the encoder
+ /// \param caseInsensitive flag indicating whether the alphabet is case sensitivie
+ /// \pre COUNTOF(lookup) == 256
+ /// \pre COUNTOF(alphabet) == base
+ /// \details Internally, the function sets the first 256 elements in the lookup table to
+ /// their value from the alphabet array or -1. base is the number of element (like 32),
+ /// and not an exponent (like 5 in 25)
+ static void CRYPTOPP_API InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);
+
+private:
+ const int *m_lookup;
+ int m_padding, m_bitsPerChar, m_outputBlockSize;
+ int m_bytePos, m_bitPos;
+ SecByteBlock m_outBuf;
+};
+
+/// \brief Filter that breaks input stream into groups of fixed size
+class CRYPTOPP_DLL Grouper : public Bufferless
+{
+public:
+ /// \brief Construct a Grouper
+ /// \param attachment a BufferedTransformation to attach to this object
+ Grouper(BufferedTransformation *attachment=NULLPTR)
+ : m_groupSize(0), m_counter(0) {Detach(attachment);}
+
+ /// \brief Construct a Grouper
+ /// \param groupSize the size of the grouping
+ /// \param separator the separator to use between groups
+ /// \param terminator the terminator appeand after processing
+ /// \param attachment a BufferedTransformation to attach to this object
+ Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULLPTR)
+ : m_groupSize(0), m_counter(0)
+ {
+ Detach(attachment);
+ IsolatedInitialize(MakeParameters(Name::GroupSize(), groupSize)
+ (Name::Separator(), ConstByteArrayParameter(separator))
+ (Name::Terminator(), ConstByteArrayParameter(terminator)));
+ }
+
+ void IsolatedInitialize(const NameValuePairs ¶meters);
+ size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
+
+private:
+ SecByteBlock m_separator, m_terminator;
+ size_t m_groupSize, m_counter;
+};
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/bench.h b/linux/include/cryptopp/bench.h
new file mode 100644
index 000000000..59bfbf2ca
--- /dev/null
+++ b/linux/include/cryptopp/bench.h
@@ -0,0 +1,57 @@
+// bench.h - originally written and placed in the public domain by Wei Dai
+// CryptoPP::Test namespace added by JW in February 2017
+
+#ifndef CRYPTOPP_BENCH_H
+#define CRYPTOPP_BENCH_H
+
+#include "cryptlib.h"
+
+#include
+#include
+#include
+#include
+
+NAMESPACE_BEGIN(CryptoPP)
+NAMESPACE_BEGIN(Test)
+
+// More granular control over benchmarks
+enum TestClass {
+ UnkeyedRNG=(1<<0),UnkeyedHash=(1<<1),UnkeyedOther=(1<<2),
+ SharedKeyMAC=(1<<3),SharedKeyStream=(1<<4),SharedKeyBlock=(1<<5),SharedKeyOther=(1<<6),
+ PublicKeyAgreement=(1<<7),PublicKeyEncryption=(1<<8),PublicKeySignature=(1<<9),PublicKeyOther=(1<<10),
+ Unkeyed=UnkeyedRNG|UnkeyedHash|UnkeyedOther,
+ SharedKey=SharedKeyMAC|SharedKeyStream|SharedKeyBlock|SharedKeyOther,
+ PublicKey=PublicKeyAgreement|PublicKeyEncryption|PublicKeySignature|PublicKeyOther,
+ All=Unkeyed|SharedKey|PublicKey,
+ TestFirst=(0), TestLast=(1<<11)
+};
+
+extern const double CLOCK_TICKS_PER_SECOND;
+extern double g_allocatedTime;
+extern double g_hertz;
+extern double g_logTotal;
+extern unsigned int g_logCount;
+extern const byte defaultKey[];
+
+// Test book keeping
+extern time_t g_testBegin;
+extern time_t g_testEnd;
+
+// Command handler
+void BenchmarkWithCommand(int argc, const char* const argv[]);
+// Top level, prints preamble and postamble
+void Benchmark(Test::TestClass suites, double t, double hertz);
+// Unkeyed systems
+void Benchmark1(double t, double hertz);
+// Shared key systems
+void Benchmark2(double t, double hertz);
+// Public key systems
+void Benchmark3(double t, double hertz);
+
+void OutputResultBytes(const char *name, double length, double timeTaken);
+void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken);
+
+NAMESPACE_END // Test
+NAMESPACE_END // CryptoPP
+
+#endif
diff --git a/linux/include/cryptopp/blake2.h b/linux/include/cryptopp/blake2.h
new file mode 100644
index 000000000..fe3c9695a
--- /dev/null
+++ b/linux/include/cryptopp/blake2.h
@@ -0,0 +1,309 @@
+// blake2.h - written and placed in the public domain by Jeffrey Walton and Zooko
+// Wilcox-O'Hearn. Based on Aumasson, Neves, Wilcox-O'Hearn and Winnerlein's
+// reference BLAKE2 implementation at http://github.com/BLAKE2/BLAKE2.
+
+/// \file blake2.h
+/// \brief Classes for BLAKE2b and BLAKE2s message digests and keyed message digests
+/// \details This implementation follows Aumasson, Neves, Wilcox-O'Hearn and Winnerlein's
+/// BLAKE2: simpler, smaller, fast as MD5 (2013.01.29).
+/// Static algorithm name return either "BLAKE2b" or "BLAKE2s". An object algorithm name follows
+/// the naming described in RFC 7693, The
+/// BLAKE2 Cryptographic Hash and Message Authentication Code (MAC).
+/// \details The library provides specialized SSE2, SSE4 and NEON version of the BLAKE2 compression
+/// function. For best results under ARM NEON, specify both an architecture and cpu. For example:
+/// CXXFLAGS="-DNDEBUG -march=armv8-a+crc -mcpu=cortex-a53 ..."
+/// \since Crypto++ 5.6.4
+
+#ifndef CRYPTOPP_BLAKE2_H
+#define CRYPTOPP_BLAKE2_H
+
+#include "cryptlib.h"
+#include "secblock.h"
+#include "seckey.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief BLAKE2 hash information
+/// \tparam T_64bit flag indicating 64-bit
+/// \since Crypto++ 5.6.4
+template
+struct BLAKE2_Info : public VariableKeyLength<(T_64bit ? 64 : 32),0,(T_64bit ? 64 : 32),1,SimpleKeyingInterface::NOT_RESYNCHRONIZABLE>
+{
+ typedef VariableKeyLength<(T_64bit ? 64 : 32),0,(T_64bit ? 64 : 32),1,SimpleKeyingInterface::NOT_RESYNCHRONIZABLE> KeyBase;
+ CRYPTOPP_CONSTANT(MIN_KEYLENGTH = KeyBase::MIN_KEYLENGTH)
+ CRYPTOPP_CONSTANT(MAX_KEYLENGTH = KeyBase::MAX_KEYLENGTH)
+ CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH = KeyBase::DEFAULT_KEYLENGTH)
+
+ CRYPTOPP_CONSTANT(BLOCKSIZE = (T_64bit ? 128 : 64))
+ CRYPTOPP_CONSTANT(DIGESTSIZE = (T_64bit ? 64 : 32))
+ CRYPTOPP_CONSTANT(SALTSIZE = (T_64bit ? 16 : 8))
+ CRYPTOPP_CONSTANT(PERSONALIZATIONSIZE = (T_64bit ? 16 : 8))
+
+ CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return (T_64bit ? "BLAKE2b" : "BLAKE2s");}
+};
+
+/// \brief BLAKE2 parameter block
+/// \tparam T_64bit flag indicating 64-bit
+/// \details BLAKE2b uses BLAKE2_ParameterBlock, while BLAKE2s
+/// uses BLAKE2_ParameterBlock.
+/// \since Crypto++ 5.6.4
+template
+struct CRYPTOPP_NO_VTABLE BLAKE2_ParameterBlock
+{
+};
+
+/// \brief BLAKE2b parameter block specialization
+template<>
+struct CRYPTOPP_NO_VTABLE BLAKE2_ParameterBlock
+{
+ CRYPTOPP_CONSTANT(SALTSIZE = BLAKE2_Info::SALTSIZE)
+ CRYPTOPP_CONSTANT(DIGESTSIZE = BLAKE2_Info::DIGESTSIZE)
+ CRYPTOPP_CONSTANT(PERSONALIZATIONSIZE = BLAKE2_Info::PERSONALIZATIONSIZE)
+
+ BLAKE2_ParameterBlock()
+ {
+ memset(this, 0x00, sizeof(*this));
+ digestLength = DIGESTSIZE;
+ fanout = depth = 1;
+ }
+
+ BLAKE2_ParameterBlock(size_t digestSize)
+ {
+ CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE);
+ memset(this, 0x00, sizeof(*this));
+ digestLength = (byte)digestSize;
+ fanout = depth = 1;
+ }
+
+ BLAKE2_ParameterBlock(size_t digestSize, size_t keyLength, const byte* salt, size_t saltLength,
+ const byte* personalization, size_t personalizationLength);
+
+ byte digestLength;
+ byte keyLength, fanout, depth;
+ byte leafLength[4];
+ byte nodeOffset[8];
+ byte nodeDepth, innerLength, rfu[14];
+ byte salt[SALTSIZE];
+ byte personalization[PERSONALIZATIONSIZE];
+};
+
+/// \brief BLAKE2s parameter block specialization
+template<>
+struct CRYPTOPP_NO_VTABLE BLAKE2_ParameterBlock
+{
+ CRYPTOPP_CONSTANT(SALTSIZE = BLAKE2_Info::SALTSIZE)
+ CRYPTOPP_CONSTANT(DIGESTSIZE = BLAKE2_Info::DIGESTSIZE)
+ CRYPTOPP_CONSTANT(PERSONALIZATIONSIZE = BLAKE2_Info::PERSONALIZATIONSIZE)
+
+ BLAKE2_ParameterBlock()
+ {
+ memset(this, 0x00, sizeof(*this));
+ digestLength = DIGESTSIZE;
+ fanout = depth = 1;
+ }
+
+ BLAKE2_ParameterBlock(size_t digestSize)
+ {
+ CRYPTOPP_ASSERT(digestSize <= DIGESTSIZE);
+ memset(this, 0x00, sizeof(*this));
+ digestLength = (byte)digestSize;
+ fanout = depth = 1;
+ }
+
+ BLAKE2_ParameterBlock(size_t digestSize, size_t keyLength, const byte* salt, size_t saltLength,
+ const byte* personalization, size_t personalizationLength);
+
+ byte digestLength;
+ byte keyLength, fanout, depth;
+ byte leafLength[4];
+ byte nodeOffset[6];
+ byte nodeDepth, innerLength;
+ byte salt[SALTSIZE];
+ byte personalization[PERSONALIZATIONSIZE];
+};
+
+/// \brief BLAKE2 state information
+/// \tparam W word type
+/// \tparam T_64bit flag indicating 64-bit
+/// \details BLAKE2b uses BLAKE2_State, while BLAKE2s
+/// uses BLAKE2_State.
+/// \since Crypto++ 5.6.4
+template
+struct CRYPTOPP_NO_VTABLE BLAKE2_State
+{
+ CRYPTOPP_CONSTANT(BLOCKSIZE = BLAKE2_Info::BLOCKSIZE)
+
+ BLAKE2_State()
+ {
+ // Set all members except scratch buffer[]
+ h[0]=h[1]=h[2]=h[3]=h[4]=h[5]=h[6]=h[7] = 0;
+ t[0]=t[1]=f[0]=f[1] = 0;
+ length = 0;
+ }
+
+ // SSE2, SSE4 and NEON depend upon t[] and f[] being side-by-side
+ W h[8], t[2], f[2];
+ byte buffer[BLOCKSIZE];
+ size_t length;
+};
+
+/// \brief BLAKE2 hash implementation
+/// \tparam W word type
+/// \tparam T_64bit flag indicating 64-bit
+/// \details BLAKE2b uses BLAKE2_Base, while BLAKE2s
+/// uses BLAKE2_Base.
+/// \since Crypto++ 5.6.4
+template
+class BLAKE2_Base : public SimpleKeyingInterfaceImpl >
+{
+public:
+ CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH = BLAKE2_Info::DEFAULT_KEYLENGTH)
+ CRYPTOPP_CONSTANT(MIN_KEYLENGTH = BLAKE2_Info::MIN_KEYLENGTH)
+ CRYPTOPP_CONSTANT(MAX_KEYLENGTH = BLAKE2_Info::MAX_KEYLENGTH)
+
+ CRYPTOPP_CONSTANT(DIGESTSIZE = BLAKE2_Info::DIGESTSIZE)
+ CRYPTOPP_CONSTANT(BLOCKSIZE = BLAKE2_Info::BLOCKSIZE)
+ CRYPTOPP_CONSTANT(SALTSIZE = BLAKE2_Info::SALTSIZE)
+ CRYPTOPP_CONSTANT(PERSONALIZATIONSIZE = BLAKE2_Info::PERSONALIZATIONSIZE)
+
+ typedef BLAKE2_State State;
+ typedef BLAKE2_ParameterBlock ParameterBlock;
+ typedef SecBlock > AlignedState;
+ typedef SecBlock > AlignedParameterBlock;
+
+ virtual ~BLAKE2_Base() {}
+
+ /// \brief Retrieve the static algorithm name
+ /// \returns the algorithm name (BLAKE2s or BLAKE2b)
+ CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return BLAKE2_Info::StaticAlgorithmName();}
+
+ /// \brief Retrieve the object's name
+ /// \returns the object's algorithm name following RFC 7693
+ /// \details Object algorithm name follows the naming described in
+ /// RFC 7693, The BLAKE2 Cryptographic Hash and
+ /// Message Authentication Code (MAC). For example, "BLAKE2b-512" and "BLAKE2s-256".
+ std::string AlgorithmName() const {return std::string(StaticAlgorithmName()) + "-" + IntToString(this->DigestSize()*8);}
+
+ unsigned int DigestSize() const {return m_digestSize;}
+ unsigned int OptimalDataAlignment() const {return (CRYPTOPP_BOOL_ALIGN16 ? 16 : GetAlignmentOf());}
+
+ void Update(const byte *input, size_t length);
+ void Restart();
+
+ /// \brief Restart a hash with parameter block and counter
+ /// \param block parameter block
+ /// \param counter counter array
+ /// \details Parameter block is persisted across calls to Restart().
+ void Restart(const BLAKE2_ParameterBlock& block, const W counter[2]);
+
+ /// \brief Set tree mode
+ /// \param mode the new tree mode
+ /// \details BLAKE2 has two finalization flags, called State::f[0] and State::f[1].
+ /// If treeMode=false (default), then State::f[1] is never set. If
+ /// treeMode=true, then State::f[1] is set when State::f[0] is set.
+ /// Tree mode is persisted across calls to Restart().
+ void SetTreeMode(bool mode) {m_treeMode=mode;}
+
+ /// \brief Get tree mode
+ /// \returns the current tree mode
+ /// \details Tree mode is persisted across calls to Restart().
+ bool GetTreeMode() const {return m_treeMode;}
+
+ void TruncatedFinal(byte *hash, size_t size);
+
+protected:
+ BLAKE2_Base();
+ BLAKE2_Base(bool treeMode, unsigned int digestSize);
+ BLAKE2_Base(const byte *key, size_t keyLength, const byte* salt, size_t saltLength,
+ const byte* personalization, size_t personalizationLength,
+ bool treeMode, unsigned int digestSize);
+
+ // Operates on state buffer and/or input. Must be BLOCKSIZE, final block will pad with 0's.
+ void Compress(const byte *input);
+ inline void IncrementCounter(size_t count=BLOCKSIZE);
+
+ void UncheckedSetKey(const byte* key, unsigned int length, const CryptoPP::NameValuePairs& params);
+
+private:
+ AlignedState m_state;
+ AlignedParameterBlock m_block;
+ AlignedSecByteBlock m_key;
+ word32 m_digestSize;
+ bool m_treeMode;
+};
+
+/// \brief The BLAKE2b cryptographic hash function
+/// \details BLAKE2b can function as both a hash and keyed hash. If you want only the hash,
+/// then use the BLAKE2b constructor that accepts no parameters or digest size. If you
+/// want a keyed hash, then use the constructor that accpts the key as a parameter.
+/// Once a key and digest size are selected, its effectively immutable. The Restart()
+/// method that accepts a ParameterBlock does not allow you to change it.
+/// \sa Aumasson, Neves, Wilcox-O'Hearn and Winnerlein's
+/// BLAKE2: simpler, smaller, fast as MD5 (2013.01.29).
+/// \since Crypto++ 5.6.4
+class BLAKE2b : public BLAKE2_Base
+{
+public:
+ typedef BLAKE2_Base ThisBase; // Early Visual Studio workaround
+ typedef BLAKE2_ParameterBlock ParameterBlock;
+ CRYPTOPP_COMPILE_ASSERT(sizeof(ParameterBlock) == 64);
+
+ /// \brief Construct a BLAKE2b hash
+ /// \param digestSize the digest size, in bytes
+ /// \param treeMode flag indicating tree mode
+ BLAKE2b(bool treeMode=false, unsigned int digestSize = DIGESTSIZE) : ThisBase(treeMode, digestSize) {}
+
+ /// \brief Construct a BLAKE2b hash
+ /// \param key a byte array used to key the cipher
+ /// \param keyLength the size of the byte array
+ /// \param salt a byte array used as salt
+ /// \param saltLength the size of the byte array
+ /// \param personalization a byte array used as prsonalization string
+ /// \param personalizationLength the size of the byte array
+ /// \param treeMode flag indicating tree mode
+ /// \param digestSize the digest size, in bytes
+ BLAKE2b(const byte *key, size_t keyLength, const byte* salt = NULLPTR, size_t saltLength = 0,
+ const byte* personalization = NULLPTR, size_t personalizationLength = 0,
+ bool treeMode=false, unsigned int digestSize = DIGESTSIZE)
+ : ThisBase(key, keyLength, salt, saltLength, personalization, personalizationLength, treeMode, digestSize) {}
+};
+
+/// \brief The BLAKE2s cryptographic hash function
+/// \details BLAKE2s can function as both a hash and keyed hash. If you want only the hash,
+/// then use the BLAKE2s constructor that accepts no parameters or digest size. If you
+/// want a keyed hash, then use the constructor that accpts the key as a parameter.
+/// Once a key and digest size are selected, its effectively immutable. The Restart()
+/// method that accepts a ParameterBlock does not allow you to change it.
+/// \sa Aumasson, Neves, Wilcox-O'Hearn and Winnerlein's
+/// BLAKE2: simpler, smaller, fast as MD5 (2013.01.29).
+/// \since Crypto++ 5.6.4
+class BLAKE2s : public BLAKE2_Base
+{
+public:
+ typedef BLAKE2_Base ThisBase; // Early Visual Studio workaround
+ typedef BLAKE2_ParameterBlock ParameterBlock;
+ CRYPTOPP_COMPILE_ASSERT(sizeof(ParameterBlock) == 32);
+
+ /// \brief Construct a BLAKE2s hash
+ /// \param digestSize the digest size, in bytes
+ /// \param treeMode flag indicating tree mode
+ BLAKE2s(bool treeMode=false, unsigned int digestSize = DIGESTSIZE) : ThisBase(treeMode, digestSize) {}
+
+ /// \brief Construct a BLAKE2s hash
+ /// \param key a byte array used to key the cipher
+ /// \param keyLength the size of the byte array
+ /// \param salt a byte array used as salt
+ /// \param saltLength the size of the byte array
+ /// \param personalization a byte array used as prsonalization string
+ /// \param personalizationLength the size of the byte array
+ /// \param treeMode flag indicating tree mode
+ /// \param digestSize the digest size, in bytes
+ BLAKE2s(const byte *key, size_t keyLength, const byte* salt = NULLPTR, size_t saltLength = 0,
+ const byte* personalization = NULLPTR, size_t personalizationLength = 0,
+ bool treeMode=false, unsigned int digestSize = DIGESTSIZE)
+ : ThisBase(key, keyLength, salt, saltLength, personalization, personalizationLength, treeMode, digestSize) {}
+};
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/blowfish.h b/linux/include/cryptopp/blowfish.h
new file mode 100644
index 000000000..5f34609f6
--- /dev/null
+++ b/linux/include/cryptopp/blowfish.h
@@ -0,0 +1,54 @@
+// blowfish.h - originally written and placed in the public domain by Wei Dai
+
+/// \file blowfish.h
+/// \brief Classes for the Blowfish block cipher
+
+#ifndef CRYPTOPP_BLOWFISH_H
+#define CRYPTOPP_BLOWFISH_H
+
+#include "seckey.h"
+#include "secblock.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief Blowfish block cipher information
+struct Blowfish_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 4, 56>, public FixedRounds<16>
+{
+ CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Blowfish";}
+};
+
+// Blowfish
+
+/// \brief Blowfish block cipher
+/// \since Crypto++ 1.0
+class Blowfish : public Blowfish_Info, public BlockCipherDocumentation
+{
+ /// \brief Class specific implementation and overrides used to operate the cipher.
+ /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
+ class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl
+ {
+ public:
+ void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
+ void UncheckedSetKey(const byte *key_string, unsigned int keylength, const NameValuePairs ¶ms);
+
+ private:
+ void crypt_block(const word32 in[2], word32 out[2]) const;
+
+ static const word32 p_init[ROUNDS+2];
+ static const word32 s_init[4*256];
+
+ FixedSizeSecBlock pbox;
+ FixedSizeSecBlock sbox;
+ };
+
+public:
+ typedef BlockCipherFinal Encryption;
+ typedef BlockCipherFinal Decryption;
+};
+
+typedef Blowfish::Encryption BlowfishEncryption;
+typedef Blowfish::Decryption BlowfishDecryption;
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/blumshub.h b/linux/include/cryptopp/blumshub.h
new file mode 100644
index 000000000..9297c9425
--- /dev/null
+++ b/linux/include/cryptopp/blumshub.h
@@ -0,0 +1,58 @@
+// blumshub.h - originally written and placed in the public domain by Wei Dai
+
+/// \file blumshub.h
+/// \brief Classes for Blum Blum Shub generator
+
+#ifndef CRYPTOPP_BLUMSHUB_H
+#define CRYPTOPP_BLUMSHUB_H
+
+#include "cryptlib.h"
+#include "modarith.h"
+#include "integer.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// BlumBlumShub without factorization of the modulus
+class PublicBlumBlumShub : public RandomNumberGenerator,
+ public StreamTransformation
+{
+public:
+ virtual ~PublicBlumBlumShub() {}
+
+ PublicBlumBlumShub(const Integer &n, const Integer &seed);
+
+ unsigned int GenerateBit();
+ byte GenerateByte();
+ void GenerateBlock(byte *output, size_t size);
+ void ProcessData(byte *outString, const byte *inString, size_t length);
+
+ bool IsSelfInverting() const {return true;}
+ bool IsForwardTransformation() const {return true;}
+
+protected:
+ ModularArithmetic modn;
+ Integer current;
+ word maxBits, bitsLeft;
+};
+
+/// BlumBlumShub with factorization of the modulus
+class BlumBlumShub : public PublicBlumBlumShub
+{
+public:
+ virtual ~BlumBlumShub() {}
+
+ // Make sure p and q are both primes congruent to 3 mod 4 and at least 512 bits long,
+ // seed is the secret key and should be about as big as p*q
+ BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed);
+
+ bool IsRandomAccess() const {return true;}
+ void Seek(lword index);
+
+protected:
+ const Integer p, q;
+ const Integer x0;
+};
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/camellia.h b/linux/include/cryptopp/camellia.h
new file mode 100644
index 000000000..e83a20608
--- /dev/null
+++ b/linux/include/cryptopp/camellia.h
@@ -0,0 +1,49 @@
+// camellia.h - originally written and placed in the public domain by Wei Dai
+
+/// \file camellia.h
+/// \brief Classes for the Camellia block cipher
+
+#ifndef CRYPTOPP_CAMELLIA_H
+#define CRYPTOPP_CAMELLIA_H
+
+#include "config.h"
+#include "seckey.h"
+#include "secblock.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief Camellia block cipher information
+struct Camellia_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>
+{
+ CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Camellia";}
+};
+
+/// \brief Camellia block cipher
+/// \sa Camellia
+class Camellia : public Camellia_Info, public BlockCipherDocumentation
+{
+ class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl
+ {
+ public:
+ void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs ¶ms);
+ void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
+
+ protected:
+ CRYPTOPP_ALIGN_DATA(4) static const byte s1[256];
+ static const word32 SP[4][256];
+
+ unsigned int m_rounds;
+ SecBlock m_key;
+ };
+
+public:
+ typedef BlockCipherFinal Encryption;
+ typedef BlockCipherFinal Decryption;
+};
+
+typedef Camellia::Encryption CamelliaEncryption;
+typedef Camellia::Decryption CamelliaDecryption;
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/cast.h b/linux/include/cryptopp/cast.h
new file mode 100644
index 000000000..08ac2951b
--- /dev/null
+++ b/linux/include/cryptopp/cast.h
@@ -0,0 +1,106 @@
+// cast.h - originally written and placed in the public domain by Wei Dai
+
+/// \file cast.h
+/// \brief Classes for the CAST-128 and CAST-256 block ciphers
+/// \since Crypto++ 2.2
+
+#ifndef CRYPTOPP_CAST_H
+#define CRYPTOPP_CAST_H
+
+#include "seckey.h"
+#include "secblock.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief CAST block cipher base
+/// \since Crypto++ 2.2
+class CAST
+{
+protected:
+ static const word32 S[8][256];
+};
+
+/// \brief CAST128 block cipher information
+/// \since Crypto++ 2.2
+struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5, 16>
+{
+ CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "CAST-128";}
+};
+
+/// \brief CAST128 block cipher
+/// \sa CAST-128
+/// \since Crypto++ 2.2
+class CAST128 : public CAST128_Info, public BlockCipherDocumentation
+{
+ /// \brief CAST128 block cipher default operation
+ class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl
+ {
+ public:
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
+
+ protected:
+ bool reduced;
+ FixedSizeSecBlock K;
+ };
+
+ /// \brief CAST128 block cipher encryption operation
+ class CRYPTOPP_NO_VTABLE Enc : public Base
+ {
+ public:
+ void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
+ };
+
+ /// \brief CAST128 block cipher decryption operation
+ class CRYPTOPP_NO_VTABLE Dec : public Base
+ {
+ public:
+ void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
+ };
+
+public:
+ typedef BlockCipherFinal Encryption;
+ typedef BlockCipherFinal Decryption;
+};
+
+/// \brief CAST256 block cipher information
+/// \since Crypto++ 4.0
+struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 4>
+{
+ CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "CAST-256";}
+};
+
+/// \brief CAST256 block cipher
+/// \sa CAST-256
+/// \since Crypto++ 4.0
+class CAST256 : public CAST256_Info, public BlockCipherDocumentation
+{
+ /// \brief CAST256 block cipher default operation
+ class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl
+ {
+ public:
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
+ void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
+
+ protected:
+ static const word32 t_m[8][24];
+ static const unsigned int t_r[8][24];
+
+ static void Omega(int i, word32 kappa[8]);
+
+ FixedSizeSecBlock K;
+ };
+
+public:
+ typedef BlockCipherFinal Encryption;
+ typedef BlockCipherFinal Decryption;
+};
+
+typedef CAST128::Encryption CAST128Encryption;
+typedef CAST128::Decryption CAST128Decryption;
+
+typedef CAST256::Encryption CAST256Encryption;
+typedef CAST256::Decryption CAST256Decryption;
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/cbcmac.h b/linux/include/cryptopp/cbcmac.h
new file mode 100644
index 000000000..8ad81b52a
--- /dev/null
+++ b/linux/include/cryptopp/cbcmac.h
@@ -0,0 +1,59 @@
+// cbcmac.h - originally written and placed in the public domain by Wei Dai
+
+/// \file
+/// \brief Classes for CBC MAC
+/// \since Crypto++ 3.1
+
+#ifndef CRYPTOPP_CBCMAC_H
+#define CRYPTOPP_CBCMAC_H
+
+#include "seckey.h"
+#include "secblock.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief CBC-MAC base class
+/// \since Crypto++ 3.1
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode
+{
+public:
+ CBC_MAC_Base() : m_counter(0) {}
+
+ void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
+ void Update(const byte *input, size_t length);
+ void TruncatedFinal(byte *mac, size_t size);
+ unsigned int DigestSize() const {return const_cast(this)->AccessCipher().BlockSize();}
+
+protected:
+ virtual BlockCipher & AccessCipher() =0;
+
+private:
+ void ProcessBuf();
+ SecByteBlock m_reg;
+ unsigned int m_counter;
+};
+
+/// \brief CBC-MAC
+/// \tparam T BlockCipherDocumentation derived class
+/// \details CBC-MAC is compatible with FIPS 113. The MAC is secure only for fixed
+/// length messages. For variable length messages use CMAC or DMAC.
+/// \sa CBC-MAC
+/// \since Crypto++ 3.1
+template
+class CBC_MAC : public MessageAuthenticationCodeImpl >, public SameKeyLengthAs
+{
+public:
+ CBC_MAC() {}
+ CBC_MAC(const byte *key, size_t length=SameKeyLengthAs::DEFAULT_KEYLENGTH)
+ {this->SetKey(key, length);}
+
+ static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";}
+
+private:
+ BlockCipher & AccessCipher() {return m_cipher;}
+ typename T::Encryption m_cipher;
+};
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/ccm.h b/linux/include/cryptopp/ccm.h
new file mode 100644
index 000000000..c381150e6
--- /dev/null
+++ b/linux/include/cryptopp/ccm.h
@@ -0,0 +1,121 @@
+// ccm.h - originally written and placed in the public domain by Wei Dai
+
+/// \file ccm.h
+/// \brief CCM block cipher mode of operation
+/// \since Crypto++ 5.6.0
+
+#ifndef CRYPTOPP_CCM_H
+#define CRYPTOPP_CCM_H
+
+#include "authenc.h"
+#include "modes.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief CCM block cipher base implementation
+/// \details Base implementation of the AuthenticatedSymmetricCipher interface
+/// \since Crypto++ 5.6.0
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CCM_Base : public AuthenticatedSymmetricCipherBase
+{
+public:
+ CCM_Base()
+ : m_digestSize(0), m_L(0), m_messageLength(0), m_aadLength(0) {}
+
+ // AuthenticatedSymmetricCipher
+ std::string AlgorithmName() const
+ {return GetBlockCipher().AlgorithmName() + std::string("/CCM");}
+ size_t MinKeyLength() const
+ {return GetBlockCipher().MinKeyLength();}
+ size_t MaxKeyLength() const
+ {return GetBlockCipher().MaxKeyLength();}
+ size_t DefaultKeyLength() const
+ {return GetBlockCipher().DefaultKeyLength();}
+ size_t GetValidKeyLength(size_t keylength) const
+ {return GetBlockCipher().GetValidKeyLength(keylength);}
+ bool IsValidKeyLength(size_t keylength) const
+ {return GetBlockCipher().IsValidKeyLength(keylength);}
+ unsigned int OptimalDataAlignment() const
+ {return GetBlockCipher().OptimalDataAlignment();}
+ IV_Requirement IVRequirement() const
+ {return UNIQUE_IV;}
+ unsigned int IVSize() const
+ {return 8;}
+ unsigned int MinIVLength() const
+ {return 7;}
+ unsigned int MaxIVLength() const
+ {return 13;}
+ unsigned int DigestSize() const
+ {return m_digestSize;}
+ lword MaxHeaderLength() const
+ {return W64LIT(0)-1;}
+ lword MaxMessageLength() const
+ {return m_L<8 ? (W64LIT(1)<<(8*m_L))-1 : W64LIT(0)-1;}
+ bool NeedsPrespecifiedDataLengths() const
+ {return true;}
+ void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength);
+
+protected:
+ // AuthenticatedSymmetricCipherBase
+ bool AuthenticationIsOnPlaintext() const
+ {return true;}
+ unsigned int AuthenticationBlockSize() const
+ {return GetBlockCipher().BlockSize();}
+ void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms);
+ void Resync(const byte *iv, size_t len);
+ size_t AuthenticateBlocks(const byte *data, size_t len);
+ void AuthenticateLastHeaderBlock();
+ void AuthenticateLastConfidentialBlock();
+ void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
+ SymmetricCipher & AccessSymmetricCipher() {return m_ctr;}
+
+ virtual BlockCipher & AccessBlockCipher() =0;
+ virtual int DefaultDigestSize() const =0;
+
+ const BlockCipher & GetBlockCipher() const {return const_cast(this)->AccessBlockCipher();};
+ byte *CBC_Buffer() {return m_buffer+REQUIRED_BLOCKSIZE;}
+
+ enum {REQUIRED_BLOCKSIZE = 16};
+ int m_digestSize, m_L;
+ word64 m_messageLength, m_aadLength;
+ CTR_Mode_ExternalCipher::Encryption m_ctr;
+};
+
+/// \brief CCM block cipher final implementation
+/// \tparam T_BlockCipher block cipher
+/// \tparam T_DefaultDigestSize default digest size, in bytes
+/// \tparam T_IsEncryption direction in which to operate the cipher
+/// \since Crypto++ 5.6.0
+template
+class CCM_Final : public CCM_Base
+{
+public:
+ static std::string StaticAlgorithmName()
+ {return T_BlockCipher::StaticAlgorithmName() + std::string("/CCM");}
+ bool IsForwardTransformation() const
+ {return T_IsEncryption;}
+
+private:
+ BlockCipher & AccessBlockCipher() {return m_cipher;}
+ int DefaultDigestSize() const {return T_DefaultDigestSize;}
+ typename T_BlockCipher::Encryption m_cipher;
+};
+
+/// \brief CCM block cipher mode of operation
+/// \tparam T_BlockCipher block cipher
+/// \tparam T_DefaultDigestSize default digest size, in bytes
+/// \details \p CCM provides the \p Encryption and \p Decryption typedef. See GCM_Base
+/// and GCM_Final for the AuthenticatedSymmetricCipher implementation.
+/// \sa CCM Mode and
+/// Modes of Operation
+/// on the Crypto++ wiki.
+/// \since Crypto++ 5.6.0
+template
+struct CCM : public AuthenticatedSymmetricCipherDocumentation
+{
+ typedef CCM_Final Encryption;
+ typedef CCM_Final Decryption;
+};
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/chacha.h b/linux/include/cryptopp/chacha.h
new file mode 100644
index 000000000..81c9f8ea1
--- /dev/null
+++ b/linux/include/cryptopp/chacha.h
@@ -0,0 +1,85 @@
+// chacha.h - written and placed in the public domain by Jeffrey Walton.
+// Based on Wei Dai's Salsa20 and Bernstein's reference ChaCha
+// family implementation at http://cr.yp.to/chacha.html.
+
+/// \file chacha.h
+/// \brief Classes for ChaCha8, ChaCha12 and ChaCha20 stream ciphers
+/// \details Crypto++ provides Bernstein and ECRYPT's ChaCha from ChaCha,
+/// a variant of Salsa20 (2008.01.28). Bernstein's implementation is _slightly_ different from the TLS working group's
+/// implementation for cipher suites TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
+/// TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, and TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256.
+/// \since Crypto++ 5.6.4
+
+#ifndef CRYPTOPP_CHACHA_H
+#define CRYPTOPP_CHACHA_H
+
+#include "strciphr.h"
+#include "secblock.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief ChaCha stream cipher information
+/// \since Crypto++ 5.6.4
+template
+struct ChaCha_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>, public FixedRounds
+{
+ CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {
+ return (R==8?"ChaCha8":(R==12?"ChaCha12":(R==20?"ChaCha20":"ChaCha")));
+ }
+};
+
+/// \brief ChaCha stream cipher implementation
+/// \since Crypto++ 5.6.4
+template
+class CRYPTOPP_NO_VTABLE ChaCha_Policy : public AdditiveCipherConcretePolicy
+{
+protected:
+ CRYPTOPP_CONSTANT(ROUNDS=FixedRounds::ROUNDS)
+
+ void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length);
+ void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
+ void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
+ bool CipherIsRandomAccess() const {return false;} // TODO
+ void SeekToIteration(lword iterationCount);
+ unsigned int GetAlignment() const;
+ unsigned int GetOptimalBlockSize() const;
+
+ FixedSizeAlignedSecBlock m_state;
+};
+
+/// \brief ChaCha8 stream cipher
+/// \sa ChaCha, a variant of Salsa20 (2008.01.28).
+/// \since Crypto++ 5.6.4
+struct ChaCha8 : public ChaCha_Info<8>, public SymmetricCipherDocumentation
+{
+ typedef SymmetricCipherFinal, AdditiveCipherTemplate<> >, ChaCha_Info<8> > Encryption;
+ typedef Encryption Decryption;
+};
+
+/// \brief ChaCha12 stream cipher
+/// \details Bernstein and ECRYPT's ChaCha is _slightly_ different from the TLS working group's implementation for
+/// cipher suites TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
+/// TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, and TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256.
+/// \sa ChaCha, a variant of Salsa20 (2008.01.28).
+/// \since Crypto++ 5.6.4
+struct ChaCha12 : public ChaCha_Info<12>, public SymmetricCipherDocumentation
+{
+ typedef SymmetricCipherFinal, AdditiveCipherTemplate<> >, ChaCha_Info<12> > Encryption;
+ typedef Encryption Decryption;
+};
+
+/// \brief ChaCha20 stream cipher
+/// \sa ChaCha, a variant of Salsa20 (2008.01.28).
+/// \details Bernstein and ECRYPT's ChaCha is _slightly_ different from the TLS working group's implementation for
+/// cipher suites TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
+/// TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, and TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256.
+/// \since Crypto++ 5.6.4
+struct ChaCha20 : public ChaCha_Info<20>, public SymmetricCipherDocumentation
+{
+ typedef SymmetricCipherFinal, AdditiveCipherTemplate<> >, ChaCha_Info<20> > Encryption;
+ typedef Encryption Decryption;
+};
+
+NAMESPACE_END
+
+#endif // CRYPTOPP_CHACHA_H
diff --git a/linux/include/cryptopp/channels.h b/linux/include/cryptopp/channels.h
new file mode 100644
index 000000000..da470a2b1
--- /dev/null
+++ b/linux/include/cryptopp/channels.h
@@ -0,0 +1,142 @@
+// channels.h - originally written and placed in the public domain by Wei Dai
+
+/// \file channels.h
+/// \brief Classes for multiple named channels
+
+#ifndef CRYPTOPP_CHANNELS_H
+#define CRYPTOPP_CHANNELS_H
+
+#include "cryptlib.h"
+#include "simple.h"
+#include "smartptr.h"
+#include "stdcpp.h"
+
+#if CRYPTOPP_MSC_VERSION
+# pragma warning(push)
+# pragma warning(disable: 4355)
+#endif
+
+NAMESPACE_BEGIN(CryptoPP)
+
+#if 0
+/// Route input on default channel to different and/or multiple channels based on message sequence number
+class MessageSwitch : public Sink
+{
+public:
+ void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel);
+ void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel);
+
+ void Put(byte inByte);
+ void Put(const byte *inString, unsigned int length);
+
+ void Flush(bool completeFlush, int propagation=-1);
+ void MessageEnd(int propagation=-1);
+ void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);
+ void MessageSeriesEnd(int propagation=-1);
+
+private:
+ typedef std::pair Route;
+ struct RangeRoute
+ {
+ RangeRoute(unsigned int begin, unsigned int end, const Route &route)
+ : begin(begin), end(end), route(route) {}
+ bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;}
+ unsigned int begin, end;
+ Route route;
+ };
+
+ typedef std::list RouteList;
+ typedef std::list DefaultRouteList;
+
+ RouteList m_routes;
+ DefaultRouteList m_defaultRoutes;
+ unsigned int m_nCurrentMessage;
+};
+#endif
+
+class ChannelSwitchTypedefs
+{
+public:
+ typedef std::pair Route;
+ typedef std::multimap RouteMap;
+
+ typedef std::pair > DefaultRoute;
+ typedef std::list DefaultRouteList;
+
+ // SunCC workaround: can't use const_iterator here
+ typedef RouteMap::iterator MapIterator;
+ typedef DefaultRouteList::iterator ListIterator;
+};
+
+class ChannelSwitch;
+
+class ChannelRouteIterator : public ChannelSwitchTypedefs
+{
+public:
+ ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs), m_useDefault(false) {}
+
+ void Reset(const std::string &channel);
+ bool End() const;
+ void Next();
+ BufferedTransformation & Destination();
+ const std::string & Channel();
+
+ ChannelSwitch& m_cs;
+ std::string m_channel;
+ bool m_useDefault;
+ MapIterator m_itMapCurrent, m_itMapEnd;
+ ListIterator m_itListCurrent, m_itListEnd;
+
+protected:
+ // Hide this to see if we break something...
+ ChannelRouteIterator();
+};
+
+/// Route input to different and/or multiple channels based on channel ID
+class CRYPTOPP_DLL ChannelSwitch : public Multichannel, public ChannelSwitchTypedefs
+{
+public:
+ ChannelSwitch() : m_it(*this), m_blocked(false) {}
+ ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false)
+ {
+ AddDefaultRoute(destination);
+ }
+ ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false)
+ {
+ AddDefaultRoute(destination, outChannel);
+ }
+
+ void IsolatedInitialize(const NameValuePairs ¶meters=g_nullNameValuePairs);
+
+ size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
+ size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking);
+
+ bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
+ bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
+
+ byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
+
+ void AddDefaultRoute(BufferedTransformation &destination);
+ void RemoveDefaultRoute(BufferedTransformation &destination);
+ void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
+ void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
+ void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
+ void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
+
+private:
+ RouteMap m_routeMap;
+ DefaultRouteList m_defaultRoutes;
+
+ ChannelRouteIterator m_it;
+ bool m_blocked;
+
+ friend class ChannelRouteIterator;
+};
+
+NAMESPACE_END
+
+#if CRYPTOPP_MSC_VERSION
+# pragma warning(pop)
+#endif
+
+#endif
diff --git a/linux/include/cryptopp/cmac.h b/linux/include/cryptopp/cmac.h
new file mode 100644
index 000000000..98afd007f
--- /dev/null
+++ b/linux/include/cryptopp/cmac.h
@@ -0,0 +1,66 @@
+// cmac.h - originally written and placed in the public domain by Wei Dai
+
+/// \file cmac.h
+/// \brief Classes for CMAC message authentication code
+/// \since Crypto++ 5.6.0
+
+#ifndef CRYPTOPP_CMAC_H
+#define CRYPTOPP_CMAC_H
+
+#include "seckey.h"
+#include "secblock.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+/// \brief CMAC base implementation
+/// \since Crypto++ 5.6.0
+class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode
+{
+public:
+ CMAC_Base() : m_counter(0) {}
+
+ void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
+ void Update(const byte *input, size_t length);
+ void TruncatedFinal(byte *mac, size_t size);
+ unsigned int DigestSize() const {return GetCipher().BlockSize();}
+ unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();}
+ unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();}
+
+protected:
+ friend class EAX_Base;
+
+ const BlockCipher & GetCipher() const {return const_cast(this)->AccessCipher();}
+ virtual BlockCipher & AccessCipher() =0;
+
+ void ProcessBuf();
+ SecByteBlock m_reg;
+ unsigned int m_counter;
+};
+
+/// \brief CMAC message authentication code
+/// \tparam T block cipher
+/// \details Template parameter T should be a class derived from BlockCipherDocumentation, for example AES, with a block size of 8, 16, or 32.
+/// \sa CMAC
+/// \since Crypto++ 5.6.0
+template
+class CMAC : public MessageAuthenticationCodeImpl >, public SameKeyLengthAs
+{
+public:
+ /// \brief Construct a CMAC
+ CMAC() {}
+ /// \brief Construct a CMAC
+ /// \param key the MAC key
+ /// \param length the key size, in bytes
+ CMAC(const byte *key, size_t length=SameKeyLengthAs::DEFAULT_KEYLENGTH)
+ {this->SetKey(key, length);}
+
+ static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";}
+
+private:
+ BlockCipher & AccessCipher() {return m_cipher;}
+ typename T::Encryption m_cipher;
+};
+
+NAMESPACE_END
+
+#endif
diff --git a/linux/include/cryptopp/config.h b/linux/include/cryptopp/config.h
new file mode 100644
index 000000000..b96b7aa63
--- /dev/null
+++ b/linux/include/cryptopp/config.h
@@ -0,0 +1,1153 @@
+// config.h - originally written and placed in the public domain by Wei Dai
+
+/// \file config.h
+/// \brief Library configuration file
+
+#ifndef CRYPTOPP_CONFIG_H
+#define CRYPTOPP_CONFIG_H
+
+// ***************** Important Settings ********************
+
+// define this if running on a big-endian CPU
+#if !defined(CRYPTOPP_LITTLE_ENDIAN) && !defined(CRYPTOPP_BIG_ENDIAN) && (defined(__BIG_ENDIAN__) || (defined(__s390__) || defined(__s390x__) || defined(__zarch__)) || (defined(__m68k__) || defined(__MC68K__)) || defined(__sparc) || defined(__sparc__) || defined(__hppa__) || defined(__MIPSEB__) || defined(__ARMEB__) || (defined(__MWERKS__) && !defined(__INTEL__)))
+# define CRYPTOPP_BIG_ENDIAN 1
+#endif
+
+// define this if running on a little-endian CPU
+// big endian will be assumed if CRYPTOPP_LITTLE_ENDIAN is not defined
+#if !defined(CRYPTOPP_BIG_ENDIAN) && !defined(CRYPTOPP_LITTLE_ENDIAN)
+# define CRYPTOPP_LITTLE_ENDIAN 1
+#endif
+
+// Sanity checks. Some processors have more than big, little and bi-endian modes. PDP mode, where order results in "4312", should
+// raise red flags immediately. Additionally, mis-classified machines, like (previosuly) S/390, should raise red flags immediately.
+#if defined(CRYPTOPP_BIG_ENDIAN) && defined(__GNUC__) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__)
+# error "CRYPTOPP_BIG_ENDIAN is set, but __BYTE_ORDER__ is not __ORDER_BIG_ENDIAN__"
+#endif
+#if defined(CRYPTOPP_LITTLE_ENDIAN) && defined(__GNUC__) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__)
+# error "CRYPTOPP_LITTLE_ENDIAN is set, but __BYTE_ORDER__ is not __ORDER_LITTLE_ENDIAN__"
+#endif
+
+// Define this if you want to disable all OS-dependent features,
+// such as sockets and OS-provided random number generators
+// #define NO_OS_DEPENDENCE
+
+// Define this to use features provided by Microsoft's CryptoAPI.
+// Currently the only feature used is Windows random number generation.
+// This macro will be ignored if NO_OS_DEPENDENCE is defined.
+// #define USE_MS_CRYPTOAPI
+
+// Define this to use features provided by Microsoft's CryptoNG API.
+// CryptoNG API is available in Vista and above and its cross platform,
+// including desktop apps and store apps. Currently the only feature
+// used is Windows random number generation.
+// This macro will be ignored if NO_OS_DEPENDENCE is defined.
+// #define USE_MS_CNGAPI
+
+// If the user did not make a choice, then select CryptoNG if
+// targeting Windows 8 or above.
+#if !defined(USE_MS_CRYPTOAPI) && !defined(USE_MS_CNGAPI)
+# if !defined(_USING_V110_SDK71_) && ((WINVER >= 0x0602 /*_WIN32_WINNT_WIN8*/) || (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/))
+# define USE_MS_CNGAPI
+# else
+# define USE_MS_CRYPTOAPI
+# endif
+#endif
+
+// Define this to disable ASM, intrinsics and built-ins. The code will be
+// compiled using C++ only. The library code will not include SSE2 (and
+// above), NEON, Aarch32, Aarch64, Power4, Power7 or Power8.
+// #define CRYPTOPP_DISABLE_ASM 1
+
+// Define CRYPTOPP_NO_CXX11 to avoid C++11 related features shown at the
+// end of this file. Some compilers and standard C++ headers advertise C++11
+// but they are really just C++03 with some additional C++11 headers and
+// non-conforming classes. You might also consider `-std=c++03` or
+// `-std=gnu++03`, but they are required options when building the library
+// and all programs. CRYPTOPP_NO_CXX11 is probably easier to manage but it may
+// cause -Wterminate warnings under GCC. MSVC++ has a similar warning.
+// Also see https://github.com/weidai11/cryptopp/issues/529
+// #define CRYPTOPP_NO_CXX11 1
+
+// Define this to allow unaligned data access. If you experience a break with
+// GCC at -O3, you should immediately suspect unaligned data accesses.
+// #define CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS 1
+
+// ***************** Less Important Settings ***************
+
+// Library version macro. Since this macro is in a header, it reflects
+// the version of the library the headers came from. It is not
+// necessarily the version of the library built as a shared object if
+// versions are inadvertently mixed and matched.
+#define CRYPTOPP_VERSION 610
+
+// Define this if you want to set a prefix for TestData/ and TestVectors/
+// Be mindful of the trailing slash since its simple concatenation.
+// g++ ... -DCRYPTOPP_DATA_DIR='"/tmp/cryptopp_test/share/"'
+#ifndef CRYPTOPP_DATA_DIR
+# define CRYPTOPP_DATA_DIR ""
+#endif
+
+// Define this if you want or need the library's memcpy_s and memmove_s.
+// See http://github.com/weidai11/cryptopp/issues/28.
+// #if !defined(CRYPTOPP_WANT_SECURE_LIB)
+// # define CRYPTOPP_WANT_SECURE_LIB
+// #endif
+
+// File system code to write to GZIP archive.
+// http://www.gzip.org/format.txt
+#if !defined(GZIP_OS_CODE)
+# if defined(__macintosh__)
+# define GZIP_OS_CODE 7
+# elif defined(__unix__) || defined(__linux__)
+# define GZIP_OS_CODE 3
+# else
+# define GZIP_OS_CODE 0
+# endif
+#endif
+
+// Try this if your CPU has 256K internal cache or a slow multiply instruction
+// and you want a (possibly) faster IDEA implementation using log tables
+// #define IDEA_LARGECACHE
+
+// Define this if, for the linear congruential RNG, you want to use
+// the original constants as specified in S.K. Park and K.W. Miller's
+// CACM paper.
+// #define LCRNG_ORIGINAL_NUMBERS
+
+// Define this if you want Integer's operator<< to honor std::showbase (and
+// std::noshowbase). If defined, Integer will use a suffix of 'b', 'o', 'h'
+// or '.' (the last for decimal) when std::showbase is in effect. If
+// std::noshowbase is set, then the suffix is not added to the Integer. If
+// not defined, existing behavior is preserved and Integer will use a suffix
+// of 'b', 'o', 'h' or '.' (the last for decimal).
+// #define CRYPTOPP_USE_STD_SHOWBASE
+
+// Define this if ARMv8 shifts are slow. ARM Cortex-A53 and Cortex-A57 shift
+// operation perform poorly, so NEON and ASIMD code that relies on shifts
+// or rotates often performs worse than C/C++ code. Also see
+// http://github.com/weidai11/cryptopp/issues/367.
+#define CRYPTOPP_SLOW_ARMV8_SHIFT 1
+
+// Define this if you want to decouple AlgorithmParameters and Integer
+// The decoupling should make it easier for the linker to remove Integer
+// related code for those who do not need Integer, and avoid a potential
+// race during AssignIntToInteger pointer initialization. Also
+// see http://github.com/weidai11/cryptopp/issues/389.
+// #define CRYPTOPP_NO_ASSIGN_TO_INTEGER
+
+// choose which style of sockets to wrap (mostly useful for MinGW which has both)
+#if !defined(NO_BERKELEY_STYLE_SOCKETS) && !defined(PREFER_BERKELEY_STYLE_SOCKETS)
+# define PREFER_BERKELEY_STYLE_SOCKETS
+#endif
+
+// #if !defined(NO_WINDOWS_STYLE_SOCKETS) && !defined(PREFER_WINDOWS_STYLE_SOCKETS)
+// # define PREFER_WINDOWS_STYLE_SOCKETS
+// #endif
+
+// set the name of Rijndael cipher, was "Rijndael" before version 5.3
+#define CRYPTOPP_RIJNDAEL_NAME "AES"
+
+// CRYPTOPP_DEBUG enables the library's CRYPTOPP_ASSERT. CRYPTOPP_ASSERT
+// raises a SIGTRAP (Unix) or calls DebugBreak() (Windows). CRYPTOPP_ASSERT
+// is only in effect when CRYPTOPP_DEBUG, DEBUG or _DEBUG is defined. Unlike
+// Posix assert, CRYPTOPP_ASSERT is not affected by NDEBUG (or failure to
+// define it).
+// Also see http://github.com/weidai11/cryptopp/issues/277, CVE-2016-7420
+#if (defined(DEBUG) || defined(_DEBUG)) && !defined(CRYPTOPP_DEBUG)
+# define CRYPTOPP_DEBUG 1
+#endif
+
+// ***************** Important Settings Again ********************
+// But the defaults should be ok.
+
+// namespace support is now required
+#ifdef NO_NAMESPACE
+# error namespace support is now required
+#endif
+
+#ifdef CRYPTOPP_DOXYGEN_PROCESSING
+// Document the namespce exists. Put it here before CryptoPP is undefined below.
+/// \namespace CryptoPP
+/// \brief Crypto++ library namespace
+/// \details Nearly all classes are located in the CryptoPP namespace. Within
+/// the namespace, there are two additional namespaces.
+///