Merge 'master' into 'hmqv'

pull/263/head
Jeffrey Walton 2016-09-08 01:30:29 -04:00
commit 01b40aab31
76 changed files with 921 additions and 411 deletions

2
3way.h
View File

@ -16,7 +16,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \brief ThreeWay block cipher information //! \brief ThreeWay block cipher information
struct ThreeWay_Info : public FixedBlockSize<12>, public FixedKeyLength<12>, public VariableRounds<11> struct ThreeWay_Info : public FixedBlockSize<12>, public FixedKeyLength<12>, public VariableRounds<11>
{ {
static const char *StaticAlgorithmName() {return "3-Way";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "3-Way";}
}; };
//! \class ThreeWay //! \class ThreeWay

View File

@ -20,7 +20,7 @@ public:
void Update(const byte *input, size_t length); void Update(const byte *input, size_t length);
void TruncatedFinal(byte *hash, size_t size); void TruncatedFinal(byte *hash, size_t size);
unsigned int DigestSize() const {return DIGESTSIZE;} unsigned int DigestSize() const {return DIGESTSIZE;}
static const char * StaticAlgorithmName() {return "Adler32";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Adler32";}
std::string AlgorithmName() const {return StaticAlgorithmName();} std::string AlgorithmName() const {return StaticAlgorithmName();}
private: private:

4
arc4.h
View File

@ -23,7 +23,7 @@ class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, publi
public: public:
~ARC4_Base(); ~ARC4_Base();
static const char *StaticAlgorithmName() {return "ARC4";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "ARC4";}
void GenerateBlock(byte *output, size_t size); void GenerateBlock(byte *output, size_t size);
void DiscardBytes(size_t n); void DiscardBytes(size_t n);
@ -55,7 +55,7 @@ DOCUMENTED_TYPEDEF(SymmetricCipherFinal<ARC4_Base>, ARC4)
class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
{ {
public: public:
static const char *StaticAlgorithmName() {return "MARC4";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "MARC4";}
typedef SymmetricCipherFinal<MARC4_Base> Encryption; typedef SymmetricCipherFinal<MARC4_Base> Encryption;
typedef SymmetricCipherFinal<MARC4_Base> Decryption; typedef SymmetricCipherFinal<MARC4_Base> Decryption;

View File

@ -39,7 +39,7 @@ struct BLAKE2_Info : public VariableKeyLength<(T_64bit ? 64 : 32),0,(T_64bit ? 6
CRYPTOPP_CONSTANT(SALTSIZE = (T_64bit ? 16 : 8)) CRYPTOPP_CONSTANT(SALTSIZE = (T_64bit ? 16 : 8))
CRYPTOPP_CONSTANT(PERSONALIZATIONSIZE = (T_64bit ? 16 : 8)) CRYPTOPP_CONSTANT(PERSONALIZATIONSIZE = (T_64bit ? 16 : 8))
static const char *StaticAlgorithmName() {return (T_64bit ? "BLAKE2b" : "BLAKE2s");} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return (T_64bit ? "BLAKE2b" : "BLAKE2s");}
}; };
//! \class BLAKE2_ParameterBlock //! \class BLAKE2_ParameterBlock
@ -175,7 +175,7 @@ public:
//! \brief Retrieve the static algorithm name //! \brief Retrieve the static algorithm name
//! \returns the algorithm name (BLAKE2s or BLAKE2b) //! \returns the algorithm name (BLAKE2s or BLAKE2b)
static const char *StaticAlgorithmName() {return BLAKE2_Info<T_64bit>::StaticAlgorithmName();} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return BLAKE2_Info<T_64bit>::StaticAlgorithmName();}
//! \brief Retrieve the object's name //! \brief Retrieve the object's name
//! \returns the object's algorithm name following RFC 7693 //! \returns the object's algorithm name following RFC 7693

View File

@ -15,7 +15,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \brief Blowfish block cipher information //! \brief Blowfish block cipher information
struct Blowfish_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 4, 56>, public FixedRounds<16> struct Blowfish_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 4, 56>, public FixedRounds<16>
{ {
static const char *StaticAlgorithmName() {return "Blowfish";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Blowfish";}
}; };
// <a href="http://www.weidai.com/scan-mirror/cs.html#Blowfish">Blowfish</a> // <a href="http://www.weidai.com/scan-mirror/cs.html#Blowfish">Blowfish</a>

View File

@ -16,7 +16,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \brief Camellia block cipher information //! \brief Camellia block cipher information
struct Camellia_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8> struct Camellia_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>
{ {
static const char *StaticAlgorithmName() {return "Camellia";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Camellia";}
}; };
//! \class Camellia //! \class Camellia

16
cast.h
View File

@ -11,6 +11,8 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
//! \class CAST
//! \brief CAST block cipher base
class CAST class CAST
{ {
protected: protected:
@ -21,7 +23,7 @@ protected:
//! \brief CAST128 block cipher information //! \brief CAST128 block cipher information
struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5, 16> struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5, 16>
{ {
static const char *StaticAlgorithmName() {return "CAST-128";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "CAST-128";}
}; };
//! \class CAST128 //! \class CAST128
@ -29,6 +31,8 @@ struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5,
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-128">CAST-128</a> //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-128">CAST-128</a>
class CAST128 : public CAST128_Info, public BlockCipherDocumentation class CAST128 : public CAST128_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief CAST128 block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info> class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
{ {
public: public:
@ -39,12 +43,16 @@ class CAST128 : public CAST128_Info, public BlockCipherDocumentation
FixedSizeSecBlock<word32, 32> K; FixedSizeSecBlock<word32, 32> K;
}; };
//! \class Enc
//! \brief CAST128 block cipher encryption operation
class CRYPTOPP_NO_VTABLE Enc : public Base class CRYPTOPP_NO_VTABLE Enc : public Base
{ {
public: public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
}; };
//! \class Dec
//! \brief CAST128 block cipher decryption operation
class CRYPTOPP_NO_VTABLE Dec : public Base class CRYPTOPP_NO_VTABLE Dec : public Base
{ {
public: public:
@ -58,9 +66,9 @@ public:
//! \class CAST256_Info //! \class CAST256_Info
//! \brief CAST256 block cipher information //! \brief CAST256 block cipher information
struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32> struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 4>
{ {
static const char *StaticAlgorithmName() {return "CAST-256";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "CAST-256";}
}; };
//! \class CAST256 //! \class CAST256
@ -68,6 +76,8 @@ struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-256">CAST-256</a> //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-256">CAST-256</a>
class CAST256 : public CAST256_Info, public BlockCipherDocumentation class CAST256 : public CAST256_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief CAST256 block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info> class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
{ {
public: public:

View File

@ -19,7 +19,9 @@ NAMESPACE_BEGIN(CryptoPP)
template <unsigned int R> template <unsigned int R>
struct ChaCha_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>, public FixedRounds<R> struct ChaCha_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>, public FixedRounds<R>
{ {
static const char *StaticAlgorithmName() {static const std::string name = "ChaCha" + IntToString(R); return name.c_str();} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {
return (R==8?"ChaCha8":(R==12?"ChaCha12":(R==20?"ChaCha20":"ChaCha")));
}
}; };
//! \class ChaCha_Policy //! \class ChaCha_Policy

View File

@ -544,7 +544,8 @@ NAMESPACE_END
# define CRYPTOPP_NOINLINE # define CRYPTOPP_NOINLINE
#endif #endif
// how to declare class constants // How to declare class constants
// Use enum for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__) #if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__)
# define CRYPTOPP_CONSTANT(x) enum {x}; # define CRYPTOPP_CONSTANT(x) enum {x};
#else #else
@ -901,6 +902,12 @@ NAMESPACE_END
# define CRYPTOPP_ALIGN_DATA(x) alignas(x) # define CRYPTOPP_ALIGN_DATA(x) alignas(x)
#endif // CRYPTOPP_CXX11_ALIGNAS #endif // CRYPTOPP_CXX11_ALIGNAS
// Hack... CRYPTOPP_CONSTANT is defined earlier, before C++11 constexpr availability is determined
#if defined(CRYPTOPP_CXX11_CONSTEXPR)
# undef CRYPTOPP_CONSTANT
# define CRYPTOPP_CONSTANT(x) constexpr static int x;
#endif
// OK to comment the following out, but please report it so we can fix it. // OK to comment the following out, but please report it so we can fix it.
// C++17 value taken from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4567.pdf. // C++17 value taken from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4567.pdf.
#if (defined(__cplusplus) && (__cplusplus >= 199711L) && (__cplusplus < 201402L)) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE) #if (defined(__cplusplus) && (__cplusplus >= 199711L) && (__cplusplus < 201402L)) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE)

View File

@ -544,7 +544,8 @@ NAMESPACE_END
# define CRYPTOPP_NOINLINE # define CRYPTOPP_NOINLINE
#endif #endif
// how to declare class constants // How to declare class constants
// Use enum for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__) #if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__)
# define CRYPTOPP_CONSTANT(x) enum {x}; # define CRYPTOPP_CONSTANT(x) enum {x};
#else #else
@ -901,6 +902,12 @@ NAMESPACE_END
# define CRYPTOPP_ALIGN_DATA(x) alignas(x) # define CRYPTOPP_ALIGN_DATA(x) alignas(x)
#endif // CRYPTOPP_CXX11_ALIGNAS #endif // CRYPTOPP_CXX11_ALIGNAS
// Hack... CRYPTOPP_CONSTANT is defined earlier, before C++11 constexpr availability is determined
#if defined(CRYPTOPP_CXX11_CONSTEXPR)
# undef CRYPTOPP_CONSTANT
# define CRYPTOPP_CONSTANT(x) constexpr static int x;
#endif
// OK to comment the following out, but please report it so we can fix it. // OK to comment the following out, but please report it so we can fix it.
// C++17 value taken from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4567.pdf. // C++17 value taken from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4567.pdf.
#if (defined(__cplusplus) && (__cplusplus >= 199711L) && (__cplusplus < 201402L)) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE) #if (defined(__cplusplus) && (__cplusplus >= 199711L) && (__cplusplus < 201402L)) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE)

4
crc.h
View File

@ -31,7 +31,7 @@ public:
void Update(const byte *input, size_t length); void Update(const byte *input, size_t length);
void TruncatedFinal(byte *hash, size_t size); void TruncatedFinal(byte *hash, size_t size);
unsigned int DigestSize() const {return DIGESTSIZE;} unsigned int DigestSize() const {return DIGESTSIZE;}
static const char * StaticAlgorithmName() {return "CRC32";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "CRC32";}
std::string AlgorithmName() const {return StaticAlgorithmName();} std::string AlgorithmName() const {return StaticAlgorithmName();}
void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
@ -55,7 +55,7 @@ public:
void Update(const byte *input, size_t length); void Update(const byte *input, size_t length);
void TruncatedFinal(byte *hash, size_t size); void TruncatedFinal(byte *hash, size_t size);
unsigned int DigestSize() const {return DIGESTSIZE;} unsigned int DigestSize() const {return DIGESTSIZE;}
static const char * StaticAlgorithmName() {return "CRC32C";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "CRC32C";}
std::string AlgorithmName() const {return StaticAlgorithmName();} std::string AlgorithmName() const {return StaticAlgorithmName();}
void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}

View File

@ -45,7 +45,7 @@ RM = del.exe
# To test Surface RT (ARM tablet), use the following CXXFLAGS: # To test Surface RT (ARM tablet), use the following CXXFLAGS:
# - /D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1 /DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP # - /D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1 /DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP
CXXFLAGS = /nologo /W4 /D_MBCS /Zi /TP /EHsc /MD /FI sdkddkver.h /FI winapifamily.h CXXFLAGS = /nologo /W4 /wd4511 /D_MBCS /Zi /TP /EHsc /MD /FI sdkddkver.h /FI winapifamily.h
LDFLAGS = /nologo /SUBSYSTEM:CONSOLE LDFLAGS = /nologo /SUBSYSTEM:CONSOLE
ARFLAGS = /nologo ARFLAGS = /nologo
LDLIBS = LDLIBS =
@ -53,7 +53,7 @@ LDLIBS =
!IF "$(PLATFORM)" == "" !IF "$(PLATFORM)" == ""
!IF "$(PROCESSOR_ARCHITECTURE)" == "x86" !IF "$(PROCESSOR_ARCHITECTURE)" == "x86"
PLATFORM = x86 PLATFORM = x86
!ELSEIF "$(PROCESSOR_ARCHITECTURE)" == "x64" !ELSEIF "$(PROCESSOR_ARCHITECTURE)" == "x64" || "$(PROCESSOR_ARCHITECTURE)" == "AMD64"
PLATFORM = x64 PLATFORM = x64
!ELSE !ELSE
!ERROR "Unknown platform" !ERROR "Unknown platform"

12
des.h
View File

@ -30,7 +30,7 @@ protected:
struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8> struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
{ {
// disable DES in DLL version by not exporting this function // disable DES in DLL version by not exporting this function
static const char * StaticAlgorithmName() {return "DES";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "DES";}
}; };
//! \class DES //! \class DES
@ -41,6 +41,8 @@ struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#DES">DES</a> //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#DES">DES</a>
class DES : public DES_Info, public BlockCipherDocumentation class DES : public DES_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief DES block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES
{ {
public: public:
@ -70,6 +72,8 @@ struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
/// \sa <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE2</a> /// \sa <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE2</a>
class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief DES_EDE2 block cipher default operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE2_Info> class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE2_Info>
{ {
public: public:
@ -97,6 +101,8 @@ struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE3</a> //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE3</a>
class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief DES_EDE3 block cipher default operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE3_Info> class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE3_Info>
{ {
public: public:
@ -116,7 +122,7 @@ public:
//! \brief DESX block cipher information //! \brief DESX block cipher information
struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24> struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
{ {
static const char *StaticAlgorithmName() {return "DES-XEX3";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "DES-XEX3";}
}; };
//! \class DES_XEX3 //! \class DES_XEX3
@ -124,6 +130,8 @@ struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#DESX">DES-XEX3</a>, AKA DESX //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#DESX">DES-XEX3</a>, AKA DESX
class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief DES_XEX3 block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info> class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info>
{ {
public: public:

View File

@ -284,7 +284,7 @@ template <class EC>
class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA<typename EC::Point> class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA<typename EC::Point>
{ {
public: public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECDSA";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECDSA";}
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_Algorithm_ECDSA() {} virtual ~DL_Algorithm_ECDSA() {}
@ -296,7 +296,7 @@ template <class EC>
class DL_Algorithm_ECNR : public DL_Algorithm_NR<typename EC::Point> class DL_Algorithm_ECNR : public DL_Algorithm_NR<typename EC::Point>
{ {
public: public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECNR";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECNR";}
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_Algorithm_ECNR() {} virtual ~DL_Algorithm_ECNR() {}

View File

@ -127,7 +127,7 @@ struct ElGamal
{ {
typedef DL_CryptoSchemeOptions<ElGamal, ElGamalKeys, int, int, int> SchemeOptions; typedef DL_CryptoSchemeOptions<ElGamal, ElGamalKeys, int, int, int> SchemeOptions;
static const char * StaticAlgorithmName() {return "ElgamalEnc/Crypto++Padding";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "ElgamalEnc/Crypto++Padding";}
typedef SchemeOptions::GroupParameters GroupParameters; typedef SchemeOptions::GroupParameters GroupParameters;
//! implements PK_Encryptor interface //! implements PK_Encryptor interface

View File

@ -61,7 +61,7 @@ CRYPTOPP_DLL_TEMPLATE_CLASS EMSA2HashId<SHA512>;
class CRYPTOPP_DLL EMSA2Pad : public EMSA2HashIdLookup<PK_DeterministicSignatureMessageEncodingMethod> class CRYPTOPP_DLL EMSA2Pad : public EMSA2HashIdLookup<PK_DeterministicSignatureMessageEncodingMethod>
{ {
public: public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA2";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA2";}
size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const
{CRYPTOPP_UNUSED(hashIdentifierLength); return 8*digestLength + 31;} {CRYPTOPP_UNUSED(hashIdentifierLength); return 8*digestLength + 31;}

View File

@ -90,7 +90,7 @@ template <class T>
class EMSA5Pad : public PK_DeterministicSignatureMessageEncodingMethod class EMSA5Pad : public PK_DeterministicSignatureMessageEncodingMethod
{ {
public: public:
static const char *StaticAlgorithmName() {return "EMSA5";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "EMSA5";}
void ComputeMessageRepresentative(RandomNumberGenerator &rng, void ComputeMessageRepresentative(RandomNumberGenerator &rng,
const byte *recoverableMessage, size_t recoverableMessageLength, const byte *recoverableMessage, size_t recoverableMessageLength,

View File

@ -185,7 +185,7 @@ template <class T>
class DL_Algorithm_GDSA : public DL_ElgamalLikeSignatureAlgorithm<T> class DL_Algorithm_GDSA : public DL_ElgamalLikeSignatureAlgorithm<T>
{ {
public: public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "DSA-1363";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "DSA-1363";}
void Sign(const DL_GroupParameters<T> &params, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const void Sign(const DL_GroupParameters<T> &params, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const
{ {
@ -221,7 +221,7 @@ template <class T>
class DL_Algorithm_NR : public DL_ElgamalLikeSignatureAlgorithm<T> class DL_Algorithm_NR : public DL_ElgamalLikeSignatureAlgorithm<T>
{ {
public: public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "NR";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "NR";}
void Sign(const DL_GroupParameters<T> &params, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const void Sign(const DL_GroupParameters<T> &params, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const
{ {

8
gost.h
View File

@ -15,7 +15,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \brief GOST block cipher information //! \brief GOST block cipher information
struct GOST_Info : public FixedBlockSize<8>, public FixedKeyLength<32> struct GOST_Info : public FixedBlockSize<8>, public FixedKeyLength<32>
{ {
static const char *StaticAlgorithmName() {return "GOST";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "GOST";}
}; };
//! \class GOST //! \class GOST
@ -23,6 +23,8 @@ struct GOST_Info : public FixedBlockSize<8>, public FixedKeyLength<32>
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#GOST">GOST</a> //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#GOST">GOST</a>
class GOST : public GOST_Info, public BlockCipherDocumentation class GOST : public GOST_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief GOST block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<GOST_Info> class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<GOST_Info>
{ {
public: public:
@ -38,12 +40,16 @@ class GOST : public GOST_Info, public BlockCipherDocumentation
FixedSizeSecBlock<word32, 8> key; FixedSizeSecBlock<word32, 8> key;
}; };
//! \class Enc
//! \brief GOST block cipher encryption operation
class CRYPTOPP_NO_VTABLE Enc : public Base class CRYPTOPP_NO_VTABLE Enc : public Base
{ {
public: public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
}; };
//! \class Dec
//! \brief GOST block cipher decryption operation
class CRYPTOPP_NO_VTABLE Dec : public Base class CRYPTOPP_NO_VTABLE Dec : public Base
{ {
public: public:

2
idea.h
View File

@ -15,7 +15,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \brief IDEA block cipher information //! \brief IDEA block cipher information
struct IDEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public FixedRounds<8> struct IDEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public FixedRounds<8>
{ {
static const char *StaticAlgorithmName() {return "IDEA";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "IDEA";}
}; };
//! \class IDEA //! \class IDEA

2
luc.h
View File

@ -232,7 +232,7 @@ protected:
class DL_Algorithm_LUC_HMP : public DL_ElgamalLikeSignatureAlgorithm<Integer> class DL_Algorithm_LUC_HMP : public DL_ElgamalLikeSignatureAlgorithm<Integer>
{ {
public: public:
static const char * StaticAlgorithmName() {return "LUC-HMP";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "LUC-HMP";}
void Sign(const DL_GroupParameters<Integer> &params, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const; void Sign(const DL_GroupParameters<Integer> &params, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const;
bool Verify(const DL_GroupParameters<Integer> &params, const DL_PublicKey<Integer> &publicKey, const Integer &e, const Integer &r, const Integer &s) const; bool Verify(const DL_GroupParameters<Integer> &params, const DL_PublicKey<Integer> &publicKey, const Integer &e, const Integer &r, const Integer &s) const;

4
mars.h
View File

@ -13,9 +13,9 @@ NAMESPACE_BEGIN(CryptoPP)
//! \class MARS_Info //! \class MARS_Info
//! \brief MARS block cipher information //! \brief MARS block cipher information
struct MARS_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 56, 4> struct MARS_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>
{ {
static const char *StaticAlgorithmName() {return "MARS";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "MARS";}
}; };
//! \class MARS //! \class MARS

2
md2.h
View File

@ -17,7 +17,7 @@ public:
void TruncatedFinal(byte *hash, size_t size); void TruncatedFinal(byte *hash, size_t size);
unsigned int DigestSize() const {return DIGESTSIZE;} unsigned int DigestSize() const {return DIGESTSIZE;}
unsigned int BlockSize() const {return BLOCKSIZE;} unsigned int BlockSize() const {return BLOCKSIZE;}
static const char * StaticAlgorithmName() {return "MD2";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "MD2";}
CRYPTOPP_CONSTANT(DIGESTSIZE = 16) CRYPTOPP_CONSTANT(DIGESTSIZE = 16)
CRYPTOPP_CONSTANT(BLOCKSIZE = 16) CRYPTOPP_CONSTANT(BLOCKSIZE = 16)

2
md4.h
View File

@ -15,7 +15,7 @@ class MD4 : public IteratedHashWithStaticTransform<word32, LittleEndian, 64, 16,
public: public:
static void InitState(HashWordType *state); static void InitState(HashWordType *state);
static void Transform(word32 *digest, const word32 *data); static void Transform(word32 *digest, const word32 *data);
static const char *StaticAlgorithmName() {return "MD4";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "MD4";}
}; };
} }

2
md5.h
View File

@ -13,7 +13,7 @@ class MD5 : public IteratedHashWithStaticTransform<word32, LittleEndian, 64, 16,
public: public:
static void InitState(HashWordType *state); static void InitState(HashWordType *state);
static void Transform(word32 *digest, const word32 *data); static void Transform(word32 *digest, const word32 *data);
static const char * StaticAlgorithmName() {return "MD5";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "MD5";}
}; };
} }

16
mdc.h
View File

@ -3,8 +3,8 @@
#ifndef CRYPTOPP_MDC_H #ifndef CRYPTOPP_MDC_H
#define CRYPTOPP_MDC_H #define CRYPTOPP_MDC_H
/** \file //! \file mdc.h
*/ //! \brief Classes for the MDC message digest
#include "seckey.h" #include "seckey.h"
#include "secblock.h" #include "secblock.h"
@ -12,18 +12,24 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
//! _ //! \class MDC_Info
//! \brief MDC_Info cipher information
template <class T> template <class T>
struct MDC_Info : public FixedBlockSize<T::DIGESTSIZE>, public FixedKeyLength<T::BLOCKSIZE> struct MDC_Info : public FixedBlockSize<T::DIGESTSIZE>, public FixedKeyLength<T::BLOCKSIZE>
{ {
static std::string StaticAlgorithmName() {return std::string("MDC/")+T::StaticAlgorithmName();} static std::string StaticAlgorithmName() {return std::string("MDC/")+T::StaticAlgorithmName();}
}; };
//! <a href="http://www.weidai.com/scan-mirror/cs.html#MDC">MDC</a>
/*! a construction by Peter Gutmann to turn an iterated hash function into a PRF */ //! \class MDC
//! \brief MDC cipher
//! \details MDC() is a construction by Peter Gutmann to turn an iterated hash function into a PRF
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#MDC">MDC</a>
template <class T> template <class T>
class MDC : public MDC_Info<T> class MDC : public MDC_Info<T>
{ {
//! \class Enc
//! \brief MDC cipher encryption operation
class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<MDC_Info<T> > class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<MDC_Info<T> >
{ {
typedef typename T::HashWordType HashWordType; typedef typename T::HashWordType HashWordType;

18
misc.h
View File

@ -1293,6 +1293,7 @@ CRYPTOPP_DLL void CRYPTOPP_API UnalignedDeallocate(void *ptr);
// ************** rotate functions *************** // ************** rotate functions ***************
//! \brief Performs a left rotate //! \brief Performs a left rotate
//! \tparam T the word type
//! \param x the value to rotate //! \param x the value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits. //! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
@ -1314,6 +1315,7 @@ template <class T> inline T rotlFixed(T x, unsigned int y)
} }
//! \brief Performs a right rotate //! \brief Performs a right rotate
//! \tparam T the word type
//! \param x the value to rotate //! \param x the value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits. //! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
@ -1335,6 +1337,7 @@ template <class T> inline T rotrFixed(T x, unsigned int y)
} }
//! \brief Performs a left rotate //! \brief Performs a left rotate
//! \tparam T the word type
//! \param x the value to rotate //! \param x the value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits. //! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
@ -1352,6 +1355,7 @@ template <class T> inline T rotlVariable(T x, unsigned int y)
} }
//! \brief Performs a right rotate //! \brief Performs a right rotate
//! \tparam T the word type
//! \param x the value to rotate //! \param x the value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits. //! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
@ -1369,6 +1373,7 @@ template <class T> inline T rotrVariable(T x, unsigned int y)
} }
//! \brief Performs a left rotate //! \brief Performs a left rotate
//! \tparam T the word type
//! \param x the value to rotate //! \param x the value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits. //! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
@ -1382,6 +1387,7 @@ template <class T> inline T rotlMod(T x, unsigned int y)
} }
//! \brief Performs a right rotate //! \brief Performs a right rotate
//! \tparam T the word type
//! \param x the value to rotate //! \param x the value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits. //! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
@ -1397,6 +1403,7 @@ template <class T> inline T rotrMod(T x, unsigned int y)
#ifdef _MSC_VER #ifdef _MSC_VER
//! \brief Performs a left rotate //! \brief Performs a left rotate
//! \tparam T the word type
//! \param x the 32-bit value to rotate //! \param x the 32-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by
@ -1411,6 +1418,7 @@ template<> inline word32 rotlFixed<word32>(word32 x, unsigned int y)
} }
//! \brief Performs a right rotate //! \brief Performs a right rotate
//! \tparam T the word type
//! \param x the 32-bit value to rotate //! \param x the 32-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by
@ -1425,6 +1433,7 @@ template<> inline word32 rotrFixed<word32>(word32 x, unsigned int y)
} }
//! \brief Performs a left rotate //! \brief Performs a left rotate
//! \tparam T the word type
//! \param x the 32-bit value to rotate //! \param x the 32-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by
@ -1438,6 +1447,7 @@ template<> inline word32 rotlVariable<word32>(word32 x, unsigned int y)
} }
//! \brief Performs a right rotate //! \brief Performs a right rotate
//! \tparam T the word type
//! \param x the 32-bit value to rotate //! \param x the 32-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by
@ -1451,6 +1461,7 @@ template<> inline word32 rotrVariable<word32>(word32 x, unsigned int y)
} }
//! \brief Performs a left rotate //! \brief Performs a left rotate
//! \tparam T the word type
//! \param x the 32-bit value to rotate //! \param x the 32-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by
@ -1463,6 +1474,7 @@ template<> inline word32 rotlMod<word32>(word32 x, unsigned int y)
} }
//! \brief Performs a right rotate //! \brief Performs a right rotate
//! \tparam T the word type
//! \param x the 32-bit value to rotate //! \param x the 32-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by
@ -1480,6 +1492,7 @@ template<> inline word32 rotrMod<word32>(word32 x, unsigned int y)
// Intel C++ Compiler 10.0 calls a function instead of using the rotate instruction when using these instructions // Intel C++ Compiler 10.0 calls a function instead of using the rotate instruction when using these instructions
//! \brief Performs a left rotate //! \brief Performs a left rotate
//! \tparam T the word type
//! \param x the 64-bit value to rotate //! \param x the 64-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by
@ -1494,6 +1507,7 @@ template<> inline word64 rotlFixed<word64>(word64 x, unsigned int y)
} }
//! \brief Performs a right rotate //! \brief Performs a right rotate
//! \tparam T the word type
//! \param x the 64-bit value to rotate //! \param x the 64-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by
@ -1508,6 +1522,7 @@ template<> inline word64 rotrFixed<word64>(word64 x, unsigned int y)
} }
//! \brief Performs a left rotate //! \brief Performs a left rotate
//! \tparam T the word type
//! \param x the 64-bit value to rotate //! \param x the 64-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by
@ -1521,6 +1536,7 @@ template<> inline word64 rotlVariable<word64>(word64 x, unsigned int y)
} }
//! \brief Performs a right rotate //! \brief Performs a right rotate
//! \tparam T the word type
//! \param x the 64-bit value to rotate //! \param x the 64-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by
@ -1534,6 +1550,7 @@ template<> inline word64 rotrVariable<word64>(word64 x, unsigned int y)
} }
//! \brief Performs a left rotate //! \brief Performs a left rotate
//! \tparam T the word type
//! \param x the 64-bit value to rotate //! \param x the 64-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotl</tt> provided by
@ -1546,6 +1563,7 @@ template<> inline word64 rotlMod<word64>(word64 x, unsigned int y)
} }
//! \brief Performs a right rotate //! \brief Performs a right rotate
//! \tparam T the word type
//! \param x the 64-bit value to rotate //! \param x the 64-bit value to rotate
//! \param y the number of bit positions to rotate the value //! \param y the number of bit positions to rotate the value
//! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by //! \details This is a Microsoft specific implementation using <tt>_lrotr</tt> provided by

View File

@ -7,9 +7,9 @@
#include "modes.h" #include "modes.h"
#include "misc.h" #include "misc.h"
#ifndef NDEBUG //#ifndef NDEBUG
#include "des.h" #include "des.h"
#endif //#endif
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)

46
modes.h
View File

@ -16,7 +16,7 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
//! \class CipherModeDocumentation //! \class CipherModeDocumentation
//! \brief Classes for operating block cipher modes of operation //! \brief Block cipher mode of operation information
//! \details Each class derived from this one defines two types, Encryption and Decryption, //! \details Each class derived from this one defines two types, Encryption and Decryption,
//! both of which implement the SymmetricCipher interface. //! both of which implement the SymmetricCipher interface.
//! For each mode there are two classes, one of which is a template class, //! For each mode there are two classes, one of which is a template class,
@ -31,6 +31,8 @@ struct CipherModeDocumentation : public SymmetricCipherDocumentation
{ {
}; };
//! \class CipherModeBase
//! \brief Block cipher mode of operation information
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher
{ {
public: public:
@ -85,6 +87,9 @@ protected:
AlignedSecByteBlock m_register; AlignedSecByteBlock m_register;
}; };
//! \class ModePolicyCommonTemplate
//! \brief Block cipher mode of operation common operations
//! \tparam POLICY_INTERFACE common operations
template <class POLICY_INTERFACE> template <class POLICY_INTERFACE>
class CRYPTOPP_NO_VTABLE ModePolicyCommonTemplate : public CipherModeBase, public POLICY_INTERFACE class CRYPTOPP_NO_VTABLE ModePolicyCommonTemplate : public CipherModeBase, public POLICY_INTERFACE
{ {
@ -101,11 +106,13 @@ void ModePolicyCommonTemplate<POLICY_INTERFACE>::CipherSetKey(const NameValuePai
SetFeedbackSize(feedbackSize); SetFeedbackSize(feedbackSize);
} }
//! \class CFB_ModePolicy
//! \brief CFB block cipher mode of operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : public ModePolicyCommonTemplate<CFB_CipherAbstractPolicy> class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : public ModePolicyCommonTemplate<CFB_CipherAbstractPolicy>
{ {
public: public:
IV_Requirement IVRequirement() const {return RANDOM_IV;} IV_Requirement IVRequirement() const {return RANDOM_IV;}
static const char * CRYPTOPP_API StaticAlgorithmName() {return "CFB";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "CFB";}
protected: protected:
unsigned int GetBytesPerIteration() const {return m_feedbackSize;} unsigned int GetBytesPerIteration() const {return m_feedbackSize;}
@ -129,12 +136,14 @@ inline void CopyOrZero(void *dest, const void *src, size_t s)
memset(dest, 0, s); memset(dest, 0, s);
} }
//! \class OFB_ModePolicy
//! \brief OFB block cipher mode of operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy> class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>
{ {
public: public:
bool CipherIsRandomAccess() const {return false;} bool CipherIsRandomAccess() const {return false;}
IV_Requirement IVRequirement() const {return UNIQUE_IV;} IV_Requirement IVRequirement() const {return UNIQUE_IV;}
static const char * CRYPTOPP_API StaticAlgorithmName() {return "OFB";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "OFB";}
private: private:
unsigned int GetBytesPerIteration() const {return BlockSize();} unsigned int GetBytesPerIteration() const {return BlockSize();}
@ -143,12 +152,14 @@ private:
void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length); void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length);
}; };
//! \class CTR_ModePolicy
//! \brief CTR block cipher mode of operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy> class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>
{ {
public: public:
bool CipherIsRandomAccess() const {return true;} bool CipherIsRandomAccess() const {return true;}
IV_Requirement IVRequirement() const {return RANDOM_IV;} IV_Requirement IVRequirement() const {return RANDOM_IV;}
static const char * CRYPTOPP_API StaticAlgorithmName() {return "CTR";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "CTR";}
protected: protected:
virtual void IncrementCounterBy256(); virtual void IncrementCounterBy256();
@ -166,6 +177,8 @@ protected:
AlignedSecByteBlock m_counterArray; AlignedSecByteBlock m_counterArray;
}; };
//! \class BlockOrientedCipherModeBase
//! \brief Block cipher mode of operation default implementation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase
{ {
public: public:
@ -193,6 +206,8 @@ protected:
SecByteBlock m_buffer; SecByteBlock m_buffer;
}; };
//! \class ECB_OneWay
//! \brief ECB block cipher mode of operation default implementation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherModeBase class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherModeBase
{ {
public: public:
@ -201,31 +216,37 @@ public:
IV_Requirement IVRequirement() const {return NOT_RESYNCHRONIZABLE;} IV_Requirement IVRequirement() const {return NOT_RESYNCHRONIZABLE;}
unsigned int OptimalBlockSize() const {return BlockSize() * m_cipher->OptimalNumberOfParallelBlocks();} unsigned int OptimalBlockSize() const {return BlockSize() * m_cipher->OptimalNumberOfParallelBlocks();}
void ProcessData(byte *outString, const byte *inString, size_t length); void ProcessData(byte *outString, const byte *inString, size_t length);
static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECB";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECB";}
}; };
//! \class CBC_ModeBase
//! \brief CBC block cipher mode of operation default implementation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherModeBase class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherModeBase
{ {
public: public:
IV_Requirement IVRequirement() const {return UNPREDICTABLE_RANDOM_IV;} IV_Requirement IVRequirement() const {return UNPREDICTABLE_RANDOM_IV;}
bool RequireAlignedInput() const {return false;} bool RequireAlignedInput() const {return false;}
unsigned int MinLastBlockSize() const {return 0;} unsigned int MinLastBlockSize() const {return 0;}
static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC";}
}; };
//! \class CBC_Encryption
//! \brief CBC block cipher mode of operation encryption operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Encryption : public CBC_ModeBase class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Encryption : public CBC_ModeBase
{ {
public: public:
void ProcessData(byte *outString, const byte *inString, size_t length); void ProcessData(byte *outString, const byte *inString, size_t length);
}; };
//! \class CBC_CTS_Encryption
//! \brief CBC-CTS block cipher mode of operation encryption operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption
{ {
public: public:
void SetStolenIV(byte *iv) {m_stolenIV = iv;} void SetStolenIV(byte *iv) {m_stolenIV = iv;}
unsigned int MinLastBlockSize() const {return BlockSize()+1;} unsigned int MinLastBlockSize() const {return BlockSize()+1;}
void ProcessLastBlock(byte *outString, const byte *inString, size_t length); void ProcessLastBlock(byte *outString, const byte *inString, size_t length);
static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";}
protected: protected:
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params) void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
@ -237,6 +258,8 @@ protected:
byte *m_stolenIV; byte *m_stolenIV;
}; };
//! \class CBC_Decryption
//! \brief CBC block cipher mode of operation decryption operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Decryption : public CBC_ModeBase class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Decryption : public CBC_ModeBase
{ {
public: public:
@ -258,6 +281,8 @@ protected:
AlignedSecByteBlock m_temp; AlignedSecByteBlock m_temp;
}; };
//! \class CBC_CTS_Decryption
//! \brief CBC-CTS block cipher mode of operation decryption operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Decryption : public CBC_Decryption class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Decryption : public CBC_Decryption
{ {
public: public:
@ -265,7 +290,8 @@ public:
void ProcessLastBlock(byte *outString, const byte *inString, size_t length); void ProcessLastBlock(byte *outString, const byte *inString, size_t length);
}; };
//! _ //! \class CipherModeFinalTemplate_CipherHolder
//! \brief Block cipher mode of operation aggregate
template <class CIPHER, class BASE> template <class CIPHER, class BASE>
class CipherModeFinalTemplate_CipherHolder : protected ObjectHolder<CIPHER>, public AlgorithmImpl<BASE, CipherModeFinalTemplate_CipherHolder<CIPHER, BASE> > class CipherModeFinalTemplate_CipherHolder : protected ObjectHolder<CIPHER>, public AlgorithmImpl<BASE, CipherModeFinalTemplate_CipherHolder<CIPHER, BASE> >
{ {
@ -296,8 +322,8 @@ public:
}; };
//! \class CipherModeFinalTemplate_ExternalCipher //! \class CipherModeFinalTemplate_ExternalCipher
//! \tparam BASE CipherModeFinalTemplate_CipherHolder class //! \tparam BASE CipherModeFinalTemplate_CipherHolder base class
//! \brief OFB block cipher mode of operation. //! \details
template <class BASE> template <class BASE>
class CipherModeFinalTemplate_ExternalCipher : public BASE class CipherModeFinalTemplate_ExternalCipher : public BASE
{ {

View File

@ -1,7 +1,7 @@
// panama.h - written and placed in the public domain by Wei Dai // panama.h - written and placed in the public domain by Wei Dai
//! \file panama.h //! \file panama.h
//! \brief Classes for Panama stream cipher //! \brief Classes for Panama hash and stream cipher
#ifndef CRYPTOPP_PANAMA_H #ifndef CRYPTOPP_PANAMA_H
#define CRYPTOPP_PANAMA_H #define CRYPTOPP_PANAMA_H
@ -17,7 +17,7 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
/// base class, do not use directly // Base class, do not use directly
template <class B> template <class B>
class CRYPTOPP_NO_VTABLE Panama class CRYPTOPP_NO_VTABLE Panama
{ {
@ -33,7 +33,9 @@ protected:
}; };
namespace Weak { namespace Weak {
/// <a href="http://www.weidai.com/scan-mirror/md.html#Panama">Panama Hash</a> //! \class PanamaHash
//! \brief Panama hash
//! \sa <a href="http://www.weidai.com/scan-mirror/md.html#Panama">Panama Hash</a>
template <class B = LittleEndian> template <class B = LittleEndian>
class PanamaHash : protected Panama<B>, public AlgorithmImpl<IteratedHash<word32, NativeByteOrder, 32>, PanamaHash<B> > class PanamaHash : protected Panama<B>, public AlgorithmImpl<IteratedHash<word32, NativeByteOrder, 32>, PanamaHash<B> >
{ {
@ -42,7 +44,7 @@ public:
PanamaHash() {Panama<B>::Reset();} PanamaHash() {Panama<B>::Reset();}
unsigned int DigestSize() const {return DIGESTSIZE;} unsigned int DigestSize() const {return DIGESTSIZE;}
void TruncatedFinal(byte *hash, size_t size); void TruncatedFinal(byte *hash, size_t size);
static const char * StaticAlgorithmName() {return B::ToEnum() == BIG_ENDIAN_ORDER ? "Panama-BE" : "Panama-LE";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return B::ToEnum() == BIG_ENDIAN_ORDER ? "Panama-BE" : "Panama-LE";}
protected: protected:
void Init() {Panama<B>::Reset();} void Init() {Panama<B>::Reset();}
@ -52,7 +54,8 @@ protected:
}; };
} }
//! MAC construction using a hermetic hash function //! \class HermeticHashFunctionMAC
//! \brief MAC construction using a hermetic hash function
template <class T_Hash, class T_Info = T_Hash> template <class T_Hash, class T_Info = T_Hash>
class HermeticHashFunctionMAC : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<MessageAuthenticationCode, VariableKeyLength<32, 0, INT_MAX> > >, T_Info> class HermeticHashFunctionMAC : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<MessageAuthenticationCode, VariableKeyLength<32, 0, INT_MAX> > >, T_Info>
{ {
@ -108,7 +111,8 @@ protected:
}; };
namespace Weak { namespace Weak {
/// Panama MAC //! \class PanamaMAC
//! \brief Panama message authentication code
template <class B = LittleEndian> template <class B = LittleEndian>
class PanamaMAC : public HermeticHashFunctionMAC<PanamaHash<B> > class PanamaMAC : public HermeticHashFunctionMAC<PanamaHash<B> >
{ {
@ -119,14 +123,16 @@ public:
}; };
} }
//! algorithm info //! \class PanamaCipherInfo
//! \brief Panama stream cipher information
template <class B> template <class B>
struct PanamaCipherInfo : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 32> struct PanamaCipherInfo : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 32>
{ {
static const char * StaticAlgorithmName() {return B::ToEnum() == BIG_ENDIAN_ORDER ? "Panama-BE" : "Panama-LE";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return B::ToEnum() == BIG_ENDIAN_ORDER ? "Panama-BE" : "Panama-LE";}
}; };
//! _ //! \class PanamaCipherPolicy
//! \brief Panama stream cipher operation
template <class B> template <class B>
class PanamaCipherPolicy : public AdditiveCipherConcretePolicy<word32, 8>, class PanamaCipherPolicy : public AdditiveCipherConcretePolicy<word32, 8>,
public PanamaCipherInfo<B>, public PanamaCipherInfo<B>,
@ -142,7 +148,9 @@ protected:
FixedSizeSecBlock<word32, 8> m_key; FixedSizeSecBlock<word32, 8> m_key;
}; };
//! <a href="http://www.cryptolounge.org/wiki/PANAMA">Panama Stream Cipher</a> //! \class PanamaCipher
//! \brief Panama stream cipher
//! \sa <a href="http://www.cryptolounge.org/wiki/PANAMA">Panama Stream Cipher</a>
template <class B = LittleEndian> template <class B = LittleEndian>
struct PanamaCipher : public PanamaCipherInfo<B>, public SymmetricCipherDocumentation struct PanamaCipher : public PanamaCipherInfo<B>, public SymmetricCipherDocumentation
{ {

View File

@ -19,7 +19,7 @@ NAMESPACE_BEGIN(CryptoPP)
class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod class PKCS_EncryptionPaddingScheme : public PK_EncryptionMessageEncodingMethod
{ {
public: public:
static const char * StaticAlgorithmName() {return "EME-PKCS1-v1_5";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "EME-PKCS1-v1_5";}
size_t MaxUnpaddedLength(size_t paddedLength) const; size_t MaxUnpaddedLength(size_t paddedLength) const;
void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs &parameters) const; void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs &parameters) const;
@ -60,7 +60,7 @@ CRYPTOPP_DLL_TEMPLATE_CLASS PKCS_DigestDecoration<SHA512>;
class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod class CRYPTOPP_DLL PKCS1v15_SignatureMessageEncodingMethod : public PK_DeterministicSignatureMessageEncodingMethod
{ {
public: public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "EMSA-PKCS1-v1_5";}
size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const size_t MinRepresentativeBitLength(size_t hashIdentifierSize, size_t digestSize) const
{return 8 * (digestSize + hashIdentifierSize + 10);} {return 8 * (digestSize + hashIdentifierSize + 10);}

View File

@ -712,7 +712,7 @@ CRYPTOPP_DLL void CRYPTOPP_API P1363_MGF1KDF2_Common(HashTransformation &hash, b
class P1363_MGF1 : public MaskGeneratingFunction class P1363_MGF1 : public MaskGeneratingFunction
{ {
public: public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "MGF1";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "MGF1";}
void GenerateAndMask(HashTransformation &hash, byte *output, size_t outputLength, const byte *input, size_t inputLength, bool mask = true) const void GenerateAndMask(HashTransformation &hash, byte *output, size_t outputLength, const byte *input, size_t inputLength, bool mask = true) const
{ {
P1363_MGF1KDF2_Common(hash, output, outputLength, input, inputLength, NULL, 0, mask, 0); P1363_MGF1KDF2_Common(hash, output, outputLength, input, inputLength, NULL, 0, mask, 0);
@ -1978,7 +1978,7 @@ public:
virtual ~DL_KeyAgreementAlgorithm_DH() {} virtual ~DL_KeyAgreementAlgorithm_DH() {}
#endif #endif
static const char * CRYPTOPP_API StaticAlgorithmName() CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName()
{return COFACTOR_OPTION::ToEnum() == INCOMPATIBLE_COFACTOR_MULTIPLICTION ? "DHC" : "DH";} {return COFACTOR_OPTION::ToEnum() == INCOMPATIBLE_COFACTOR_MULTIPLICTION ? "DHC" : "DH";}
Element AgreeWithEphemeralPrivateKey(const DL_GroupParameters<Element> &params, const DL_FixedBasePrecomputation<Element> &publicPrecomputation, const Integer &privateExponent) const Element AgreeWithEphemeralPrivateKey(const DL_GroupParameters<Element> &params, const DL_FixedBasePrecomputation<Element> &publicPrecomputation, const Integer &privateExponent) const

2
rc2.h
View File

@ -18,7 +18,7 @@ struct RC2_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 128>
{ {
CRYPTOPP_CONSTANT(DEFAULT_EFFECTIVE_KEYLENGTH = 1024) CRYPTOPP_CONSTANT(DEFAULT_EFFECTIVE_KEYLENGTH = 1024)
CRYPTOPP_CONSTANT(MAX_EFFECTIVE_KEYLENGTH = 1024) CRYPTOPP_CONSTANT(MAX_EFFECTIVE_KEYLENGTH = 1024)
static const char *StaticAlgorithmName() {return "RC2";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "RC2";}
}; };
//! \class RC2 //! \class RC2

2
rc5.h
View File

@ -15,7 +15,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \brief RC5 block cipher information //! \brief RC5 block cipher information
struct RC5_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 0, 255>, public VariableRounds<16> struct RC5_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 0, 255>, public VariableRounds<16>
{ {
static const char *StaticAlgorithmName() {return "RC5";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "RC5";}
typedef word32 RC5_WORD; typedef word32 RC5_WORD;
}; };

4
rc6.h
View File

@ -13,9 +13,9 @@ NAMESPACE_BEGIN(CryptoPP)
//! \class RC6_Info //! \class RC6_Info
//! \brief RC6 block cipher information //! \brief RC6 block cipher information
struct RC6_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 0, 255>, public VariableRounds<20> struct RC6_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>, public VariableRounds<20>
{ {
static const char *StaticAlgorithmName() {return "RC6";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "RC6";}
typedef word32 RC6_WORD; typedef word32 RC6_WORD;
}; };

View File

@ -175,7 +175,8 @@ static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
if (_rdrand32_step((word32*)output)) if (_rdrand32_step((word32*)output))
#else #else
if (_rdrand64_step((word64*)output)) // Cast due to GCC, http://github.com/weidai11/cryptopp/issues/236
if (_rdrand64_step(reinterpret_cast<unsigned long long*>(output)))
#endif #endif
{ {
output += sizeof(val); output += sizeof(val);
@ -196,7 +197,8 @@ static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
if (_rdrand32_step(&val)) if (_rdrand32_step(&val))
#else #else
if (_rdrand64_step(&val)) // Cast due to GCC, http://github.com/weidai11/cryptopp/issues/236
if (_rdrand64_step(reinterpret_cast<unsigned long long*>(&val)))
#endif #endif
{ {
memcpy(output, &val, size); memcpy(output, &val, size);
@ -348,7 +350,8 @@ static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
if (_rdseed32_step((word32*)output)) if (_rdseed32_step((word32*)output))
#else #else
if (_rdseed64_step((word64*)output)) // Cast due to GCC, http://github.com/weidai11/cryptopp/issues/236
if (_rdseed64_step(reinterpret_cast<unsigned long long*>(output)))
#endif #endif
{ {
output += sizeof(val); output += sizeof(val);
@ -369,7 +372,8 @@ static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
if (_rdseed32_step(&val)) if (_rdseed32_step(&val))
#else #else
if (_rdseed64_step(&val)) // Cast due to GCC, http://github.com/weidai11/cryptopp/issues/236
if (_rdseed64_step(reinterpret_cast<unsigned long long*>(&val)))
#endif #endif
{ {
memcpy(output, &val, size); memcpy(output, &val, size);

View File

@ -17,7 +17,7 @@ class RIPEMD160 : public IteratedHashWithStaticTransform<word32, LittleEndian, 6
public: public:
static void InitState(HashWordType *state); static void InitState(HashWordType *state);
static void Transform(word32 *digest, const word32 *data); static void Transform(word32 *digest, const word32 *data);
static const char * StaticAlgorithmName() {return "RIPEMD-160";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "RIPEMD-160";}
}; };
/*! Digest Length = 320 bits, Security is similar to RIPEMD-160 */ /*! Digest Length = 320 bits, Security is similar to RIPEMD-160 */
@ -26,7 +26,7 @@ class RIPEMD320 : public IteratedHashWithStaticTransform<word32, LittleEndian, 6
public: public:
static void InitState(HashWordType *state); static void InitState(HashWordType *state);
static void Transform(word32 *digest, const word32 *data); static void Transform(word32 *digest, const word32 *data);
static const char * StaticAlgorithmName() {return "RIPEMD-320";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "RIPEMD-320";}
}; };
/*! \warning RIPEMD-128 is considered insecure, and should not be used /*! \warning RIPEMD-128 is considered insecure, and should not be used
@ -36,7 +36,7 @@ class RIPEMD128 : public IteratedHashWithStaticTransform<word32, LittleEndian, 6
public: public:
static void InitState(HashWordType *state); static void InitState(HashWordType *state);
static void Transform(word32 *digest, const word32 *data); static void Transform(word32 *digest, const word32 *data);
static const char * StaticAlgorithmName() {return "RIPEMD-128";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "RIPEMD-128";}
}; };
/*! \warning RIPEMD-256 is considered insecure, and should not be used /*! \warning RIPEMD-256 is considered insecure, and should not be used
@ -46,7 +46,7 @@ class RIPEMD256 : public IteratedHashWithStaticTransform<word32, LittleEndian, 6
public: public:
static void InitState(HashWordType *state); static void InitState(HashWordType *state);
static void Transform(word32 *digest, const word32 *data); static void Transform(word32 *digest, const word32 *data);
static const char * StaticAlgorithmName() {return "RIPEMD-256";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "RIPEMD-256";}
}; };
NAMESPACE_END NAMESPACE_END

4
rsa.h
View File

@ -152,7 +152,7 @@ public:
//! \brief RSA algorithm //! \brief RSA algorithm
struct CRYPTOPP_DLL RSA struct CRYPTOPP_DLL RSA
{ {
static const char * CRYPTOPP_API StaticAlgorithmName() {return "RSA";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "RSA";}
typedef RSAFunction PublicKey; typedef RSAFunction PublicKey;
typedef InvertibleRSAFunction PrivateKey; typedef InvertibleRSAFunction PrivateKey;
}; };
@ -181,7 +181,7 @@ struct RSASS : public TF_SS<STANDARD, H, RSA>
//! \brief RSA algorithm //! \brief RSA algorithm
struct CRYPTOPP_DLL RSA_ISO struct CRYPTOPP_DLL RSA_ISO
{ {
static const char * CRYPTOPP_API StaticAlgorithmName() {return "RSA-ISO";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "RSA-ISO";}
typedef RSAFunction_ISO PublicKey; typedef RSAFunction_ISO PublicKey;
typedef InvertibleRSAFunction_ISO PrivateKey; typedef InvertibleRSAFunction_ISO PrivateKey;
}; };

2
rw.cpp
View File

@ -207,7 +207,7 @@ Integer InvertibleRWFunction::CalculateInverse(RandomNumberGenerator &rng, const
Integer re = modn.Square(r); Integer re = modn.Square(r);
re = modn.Multiply(re, x); // blind re = modn.Multiply(re, x); // blind
const Integer &h = re, &p = m_p, &q = m_q, &n = m_n; const Integer &h = re, &p = m_p, &q = m_q;
Integer e, f; Integer e, f;
const Integer U = modq.Exponentiate(h, (q+1)/8); const Integer U = modq.Exponentiate(h, (q+1)/8);

20
safer.h
View File

@ -1,7 +1,7 @@
// safer.h - written and placed in the public domain by Wei Dai // safer.h - written and placed in the public domain by Wei Dai
//! \file safer.h //! \file safer.h
//! \brief Classes for the SAFER block cipher //! \brief Classes for the SAFER and SAFER-K block ciphers
#ifndef CRYPTOPP_SAFER_H #ifndef CRYPTOPP_SAFER_H
#define CRYPTOPP_SAFER_H #define CRYPTOPP_SAFER_H
@ -12,10 +12,12 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
//! \class SAFER //! \class SAFER
//! \brief SAFER base class //! \brief SAFER block cipher
class SAFER class SAFER
{ {
public: public:
//! \class Base
//! \brief SAFER block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public BlockCipher class CRYPTOPP_NO_VTABLE Base : public BlockCipher
{ {
public: public:
@ -30,12 +32,16 @@ public:
static const byte log_tab[256]; static const byte log_tab[256];
}; };
//! \class Enc
//! \brief SAFER block cipher encryption operation
class CRYPTOPP_NO_VTABLE Enc : public Base class CRYPTOPP_NO_VTABLE Enc : public Base
{ {
public: public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
}; };
//! \class Dec
//! \brief SAFER block cipher decryption operation
class CRYPTOPP_NO_VTABLE Dec : public Base class CRYPTOPP_NO_VTABLE Dec : public Base
{ {
public: public:
@ -43,6 +49,12 @@ public:
}; };
}; };
//! \class SAFER_Impl
//! \brief SAFER block cipher default implementation
//! \tparam BASE SAFER::Enc or SAFER::Dec derived base class
//! \tparam INFO SAFER_Info derived class
//! \tparam STR flag indicating a strengthened implementation
//! \details SAFER-K is not strengthened; while SAFER-SK is strengthened.
template <class BASE, class INFO, bool STR> template <class BASE, class INFO, bool STR>
class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl<INFO, BASE> class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl<INFO, BASE>
{ {
@ -54,7 +66,7 @@ protected:
//! \brief SAFER-K block cipher information //! \brief SAFER-K block cipher information
struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13> struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
{ {
static const char *StaticAlgorithmName() {return "SAFER-K";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SAFER-K";}
}; };
//! \class SAFER_K //! \class SAFER_K
@ -71,7 +83,7 @@ public:
//! \brief SAFER-SK block cipher information //! \brief SAFER-SK block cipher information
struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13> struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
{ {
static const char *StaticAlgorithmName() {return "SAFER-SK";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SAFER-SK";}
}; };
//! \class SAFER_SK //! \class SAFER_SK

View File

@ -35,7 +35,8 @@ NAMESPACE_BEGIN(CryptoPP)
#if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) #if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void Salsa20_TestInstantiations() void Salsa20_TestInstantiations()
{ {
Salsa20::Encryption x; Salsa20::Encryption x1;
XSalsa20::Encryption x2;
} }
#endif #endif

14
salsa.h
View File

@ -19,12 +19,14 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
//! \class Salsa20_Info //! \class Salsa20_Info
//! \brief Salsa stream cipher information //! \brief Salsa20 stream cipher information
struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8> struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>
{ {
static const char *StaticAlgorithmName() {return "Salsa20";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Salsa20";}
}; };
//! \class Salsa20_Policy
//! \brief Salsa20 stream cipher operation
class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy<word32, 16> class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy<word32, 16>
{ {
protected: protected:
@ -43,7 +45,7 @@ protected:
}; };
//! \class Salsa20 //! \class Salsa20
//! \brief Salsa20 stream cipher information //! \brief Salsa20 stream cipher
//! \details Salsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20. //! \details Salsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20.
//! \sa <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a> //! \sa <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>
struct Salsa20 : public Salsa20_Info, public SymmetricCipherDocumentation struct Salsa20 : public Salsa20_Info, public SymmetricCipherDocumentation
@ -56,9 +58,11 @@ struct Salsa20 : public Salsa20_Info, public SymmetricCipherDocumentation
//! \brief XSalsa20 stream cipher information //! \brief XSalsa20 stream cipher information
struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24> struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24>
{ {
static const char *StaticAlgorithmName() {return "XSalsa20";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "XSalsa20";}
}; };
//! \class XSalsa20_Policy
//! \brief XSalsa20 stream cipher operation
class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy
{ {
public: public:
@ -70,7 +74,7 @@ protected:
}; };
//! \class XSalsa20 //! \class XSalsa20
//! \brief XSalsa20 stream cipher information //! \brief XSalsa20 stream cipher
//! \details XSalsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20. //! \details XSalsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20.
//! \sa <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a> //! \sa <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>
struct XSalsa20 : public XSalsa20_Info, public SymmetricCipherDocumentation struct XSalsa20 : public XSalsa20_Info, public SymmetricCipherDocumentation

14
seal.h
View File

@ -11,13 +11,18 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
//! _ //! \class SEAL_Info
//! \brief SEAL stream cipher information
//! \tparam B Endianess of the stream cipher
template <class B = BigEndian> template <class B = BigEndian>
struct SEAL_Info : public FixedKeyLength<20, SimpleKeyingInterface::INTERNALLY_GENERATED_IV, 4> struct SEAL_Info : public FixedKeyLength<20, SimpleKeyingInterface::INTERNALLY_GENERATED_IV, 4>
{ {
static const char *StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "SEAL-3.0-LE" : "SEAL-3.0-BE";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "SEAL-3.0-LE" : "SEAL-3.0-BE";}
}; };
//! \class SEAL_Policy
//! \brief SEAL stream cipher operation
//! \tparam B Endianess of the stream cipher
template <class B = BigEndian> template <class B = BigEndian>
class CRYPTOPP_NO_VTABLE SEAL_Policy : public AdditiveCipherConcretePolicy<word32, 256>, public SEAL_Info<B> class CRYPTOPP_NO_VTABLE SEAL_Policy : public AdditiveCipherConcretePolicy<word32, 256>, public SEAL_Info<B>
{ {
@ -37,7 +42,10 @@ private:
word32 m_outsideCounter, m_insideCounter; word32 m_outsideCounter, m_insideCounter;
}; };
//! <a href="http://www.weidai.com/scan-mirror/cs.html#SEAL-3.0-BE">SEAL</a> //! \class SEAL
//! \brief SEAL stream cipher
//! \tparam B Endianess of the stream cipher
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#SEAL-3.0-BE">SEAL</a>
template <class B = BigEndian> template <class B = BigEndian>
struct SEAL : public SEAL_Info<B>, public SymmetricCipherDocumentation struct SEAL : public SEAL_Info<B>, public SymmetricCipherDocumentation
{ {

View File

@ -52,7 +52,7 @@ public:
//! because the latter is \a not a \a constexpr. Some compilers, like Clang, do not //! because the latter is \a not a \a constexpr. Some compilers, like Clang, do not
//! optimize it well under all circumstances. Compilers like GCC, ICC and MSVC appear //! optimize it well under all circumstances. Compilers like GCC, ICC and MSVC appear
//! to optimize it well in either form. //! to optimize it well in either form.
size_type max_size() const {return (SIZE_MAX/sizeof(T));} CRYPTOPP_CONSTEXPR size_type max_size() const {return (SIZE_MAX/sizeof(T));}
#if defined(CRYPTOPP_CXX11_VARIADIC_TEMPLATES) || defined(CRYPTOPP_DOXYGEN_PROCESSING) #if defined(CRYPTOPP_CXX11_VARIADIC_TEMPLATES) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
@ -278,7 +278,7 @@ public:
assert(false); assert(false);
} }
size_type max_size() const {return 0;} CRYPTOPP_CONSTEXPR size_type max_size() const {return 0;}
//LCOV_EXCL_STOP //LCOV_EXCL_STOP
}; };
@ -410,7 +410,7 @@ public:
return newPointer; return newPointer;
} }
size_type max_size() const {return STDMAX(m_fallbackAllocator.max_size(), S);} CRYPTOPP_CONSTEXPR size_type max_size() const {return STDMAX(m_fallbackAllocator.max_size(), S);}
private: private:

View File

@ -70,14 +70,24 @@ public:
//! provided by a static function. //! provided by a static function.
//! \param keylength the size of the key, in bytes //! \param keylength the size of the key, in bytes
//! \details keylength is unused in the default implementation. //! \details keylength is unused in the default implementation.
static unsigned int StaticGetDefaultRounds(size_t keylength) CRYPTOPP_CONSTEXPR static unsigned int StaticGetDefaultRounds(size_t keylength)
{CRYPTOPP_UNUSED(keylength); return DEFAULT_ROUNDS;} {
// Comma operator breaks Debug builds with GCC 4.0 - 4.6.
// Also see http://github.com/weidai11/cryptopp/issues/255
#if defined(CRYPTOPP_CXX11_CONSTEXPR)
return CRYPTOPP_UNUSED(keylength), static_cast<unsigned int>(DEFAULT_ROUNDS);
#else
CRYPTOPP_UNUSED(keylength);
return static_cast<unsigned int>(DEFAULT_ROUNDS);
#endif
}
protected: protected:
//! \brief Validates the number of rounds for an algorithm. //! \brief Validates the number of rounds for an algorithm.
//! \param rounds the canddiate number of rounds //! \param rounds the candidate number of rounds
//! \param alg an Algorithm object used if the number of rounds are invalid //! \param alg an Algorithm object used if the number of rounds are invalid
//! \throws InvalidRounds if the number of rounds are invalid //! \throws InvalidRounds if the number of rounds are invalid
//! \details ThrowIfInvalidRounds() validates the number of rounds and throws if invalid.
inline void ThrowIfInvalidRounds(int rounds, const Algorithm *alg) inline void ThrowIfInvalidRounds(int rounds, const Algorithm *alg)
{ {
if (M == INT_MAX) // Coverity and result_independent_of_operands if (M == INT_MAX) // Coverity and result_independent_of_operands
@ -93,10 +103,11 @@ protected:
} }
//! \brief Validates the number of rounds for an algorithm //! \brief Validates the number of rounds for an algorithm
//! \param param the canddiate number of rounds //! \param param the candidate number of rounds
//! \param alg an Algorithm object used if the number of rounds are invalid //! \param alg an Algorithm object used if the number of rounds are invalid
//! \returns the number of rounds for the algorithm //! \returns the number of rounds for the algorithm
//! \throws InvalidRounds if the number of rounds are invalid //! \throws InvalidRounds if the number of rounds are invalid
//! \details GetRoundsAndThrowIfInvalid() validates the number of rounds and throws if invalid.
inline unsigned int GetRoundsAndThrowIfInvalid(const NameValuePairs &param, const Algorithm *alg) inline unsigned int GetRoundsAndThrowIfInvalid(const NameValuePairs &param, const Algorithm *alg)
{ {
int rounds = param.GetIntValueWithDefault("Rounds", DEFAULT_ROUNDS); int rounds = param.GetIntValueWithDefault("Rounds", DEFAULT_ROUNDS);
@ -140,8 +151,17 @@ public:
//! \param keylength the size of the key, in bytes //! \param keylength the size of the key, in bytes
//! \details The default implementation returns KEYLENGTH. keylength is unused //! \details The default implementation returns KEYLENGTH. keylength is unused
//! in the default implementation. //! in the default implementation.
static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) CRYPTOPP_CONSTEXPR static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength)
{CRYPTOPP_UNUSED(keylength); return KEYLENGTH;} {
// Comma operator breaks Debug builds with GCC 4.0 - 4.6.
// Also see http://github.com/weidai11/cryptopp/issues/255
#if defined(CRYPTOPP_CXX11_CONSTEXPR)
return CRYPTOPP_UNUSED(keylength), static_cast<size_t>(KEYLENGTH);
#else
CRYPTOPP_UNUSED(keylength);
return static_cast<size_t>(KEYLENGTH);
#endif
}
}; };
//! \class VariableKeyLength //! \class VariableKeyLength
@ -192,6 +212,7 @@ public:
//! then keylength is returned. Otherwise, the function returns keylength rounded //! then keylength is returned. Otherwise, the function returns keylength rounded
//! \a down to the next smaller multiple of KEYLENGTH_MULTIPLE. //! \a down to the next smaller multiple of KEYLENGTH_MULTIPLE.
//! \details keylength is provided in bytes, not bits. //! \details keylength is provided in bytes, not bits.
// TODO: Figure out how to make this CRYPTOPP_CONSTEXPR
static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength)
{ {
if (keylength < (size_t)MIN_KEYLENGTH) if (keylength < (size_t)MIN_KEYLENGTH)
@ -240,7 +261,7 @@ public:
//! then keylength is returned. Otherwise, the function returns keylength rounded //! then keylength is returned. Otherwise, the function returns keylength rounded
//! \a down to the next smaller multiple of KEYLENGTH_MULTIPLE. //! \a down to the next smaller multiple of KEYLENGTH_MULTIPLE.
//! \details keylength is provided in bytes, not bits. //! \details keylength is provided in bytes, not bits.
static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) CRYPTOPP_CONSTEXPR static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength)
{return T::StaticGetValidKeyLength(keylength);} {return T::StaticGetValidKeyLength(keylength);}
}; };
@ -250,7 +271,9 @@ public:
//! \brief Provides a base implementation of SimpleKeyingInterface //! \brief Provides a base implementation of SimpleKeyingInterface
//! \tparam BASE a SimpleKeyingInterface derived class //! \tparam BASE a SimpleKeyingInterface derived class
//! \tparam INFO a SimpleKeyingInterface derived class //! \tparam INFO a SimpleKeyingInterface derived class
//! \sa SimpleKeyingInterface //! \details SimpleKeyingInterfaceImpl() provides a default implementation for ciphers providing a keying interface.
//! Functions are virtual and not eligible for C++11 <tt>constexpr</tt>-ness.
//! \sa Algorithm(), SimpleKeyingInterface()
template <class BASE, class INFO = BASE> template <class BASE, class INFO = BASE>
class CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE class CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE
{ {
@ -296,6 +319,9 @@ public:
//! \brief Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers //! \brief Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers
//! \tparam INFO a SimpleKeyingInterface derived class //! \tparam INFO a SimpleKeyingInterface derived class
//! \tparam BASE a SimpleKeyingInterface derived class //! \tparam BASE a SimpleKeyingInterface derived class
//! \details BlockCipherImpl() provides a default implementation for block ciphers using AlgorithmImpl()
//! and SimpleKeyingInterfaceImpl(). Functions are virtual and not eligible for C++11 <tt>constexpr</tt>-ness.
//! \sa Algorithm(), SimpleKeyingInterface(), AlgorithmImpl(), SimpleKeyingInterfaceImpl()
template <class INFO, class BASE = BlockCipher> template <class INFO, class BASE = BlockCipher>
class CRYPTOPP_NO_VTABLE BlockCipherImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<BASE, INFO> > > class CRYPTOPP_NO_VTABLE BlockCipherImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<BASE, INFO> > >
{ {
@ -351,6 +377,10 @@ public:
//! \brief Provides a base implementation of Algorithm and SimpleKeyingInterface for message authentication codes //! \brief Provides a base implementation of Algorithm and SimpleKeyingInterface for message authentication codes
//! \tparam INFO a SimpleKeyingInterface derived class //! \tparam INFO a SimpleKeyingInterface derived class
//! \tparam BASE a SimpleKeyingInterface derived class //! \tparam BASE a SimpleKeyingInterface derived class
//! \details MessageAuthenticationCodeImpl() provides a default implementation for message authentication codes
//! using AlgorithmImpl() and SimpleKeyingInterfaceImpl(). Functions are virtual and not subject to C++11
//! <tt>constexpr</tt>.
//! \sa Algorithm(), SimpleKeyingInterface(), AlgorithmImpl(), SimpleKeyingInterfaceImpl()
template <class BASE, class INFO = BASE> template <class BASE, class INFO = BASE>
class MessageAuthenticationCodeImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE, INFO>, INFO> class MessageAuthenticationCodeImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE, INFO>, INFO>
{ {

2
seed.h
View File

@ -15,7 +15,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \brief SEED block cipher information //! \brief SEED block cipher information
struct SEED_Info : public FixedBlockSize<16>, public FixedKeyLength<16>, public FixedRounds<16> struct SEED_Info : public FixedBlockSize<16>, public FixedKeyLength<16>, public FixedRounds<16>
{ {
static const char *StaticAlgorithmName() {return "SEED";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SEED";}
}; };
//! \class SEED //! \class SEED

View File

@ -13,9 +13,9 @@ NAMESPACE_BEGIN(CryptoPP)
//! \class Serpent_Info //! \class Serpent_Info
//! \brief Serpent block cipher information //! \brief Serpent block cipher information
struct Serpent_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 0, 32>, public FixedRounds<32> struct Serpent_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>, public FixedRounds<32>
{ {
static const char *StaticAlgorithmName() {return "Serpent";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Serpent";}
}; };
//! \class Serpent //! \class Serpent

10
sha.h
View File

@ -23,7 +23,7 @@ class CRYPTOPP_DLL SHA1 : public IteratedHashWithStaticTransform<word32, BigEndi
public: public:
static void CRYPTOPP_API InitState(HashWordType *state); static void CRYPTOPP_API InitState(HashWordType *state);
static void CRYPTOPP_API Transform(word32 *digest, const word32 *data); static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";}
}; };
typedef SHA1 SHA; // for backwards compatibility typedef SHA1 SHA; // for backwards compatibility
@ -37,7 +37,7 @@ public:
#endif #endif
static void CRYPTOPP_API InitState(HashWordType *state); static void CRYPTOPP_API InitState(HashWordType *state);
static void CRYPTOPP_API Transform(word32 *digest, const word32 *data); static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";}
}; };
//! implements the SHA-224 standard //! implements the SHA-224 standard
@ -49,7 +49,7 @@ public:
#endif #endif
static void CRYPTOPP_API InitState(HashWordType *state); static void CRYPTOPP_API InitState(HashWordType *state);
static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);} static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);}
static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";}
}; };
//! implements the SHA-512 standard //! implements the SHA-512 standard
@ -58,7 +58,7 @@ class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform<word64, BigEn
public: public:
static void CRYPTOPP_API InitState(HashWordType *state); static void CRYPTOPP_API InitState(HashWordType *state);
static void CRYPTOPP_API Transform(word64 *digest, const word64 *data); static void CRYPTOPP_API Transform(word64 *digest, const word64 *data);
static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";}
}; };
//! implements the SHA-384 standard //! implements the SHA-384 standard
@ -67,7 +67,7 @@ class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform<word64, BigEn
public: public:
static void CRYPTOPP_API InitState(HashWordType *state); static void CRYPTOPP_API InitState(HashWordType *state);
static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);} static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);}
static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";} CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";}
}; };
NAMESPACE_END NAMESPACE_END

8
sha3.h
View File

@ -52,7 +52,7 @@ public:
//! \brief Construct a SHA3-224 message digest //! \brief Construct a SHA3-224 message digest
SHA3_224() : SHA3(DIGESTSIZE) {} SHA3_224() : SHA3(DIGESTSIZE) {}
static const char * StaticAlgorithmName() {return "SHA-3-224";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA-3-224";}
} CRYPTOPP_DEPRECATED("SHA-3 will be changing in the future due to FIPS 202 finalization"); } CRYPTOPP_DEPRECATED("SHA-3 will be changing in the future due to FIPS 202 finalization");
//! \class SHA3_256 //! \class SHA3_256
@ -64,7 +64,7 @@ public:
//! \brief Construct a SHA3-256 message digest //! \brief Construct a SHA3-256 message digest
SHA3_256() : SHA3(DIGESTSIZE) {} SHA3_256() : SHA3(DIGESTSIZE) {}
static const char * StaticAlgorithmName() {return "SHA-3-256";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA-3-256";}
} CRYPTOPP_DEPRECATED("SHA-3 will be changing in the future due to FIPS 202 finalization"); } CRYPTOPP_DEPRECATED("SHA-3 will be changing in the future due to FIPS 202 finalization");
//! \class SHA3_384 //! \class SHA3_384
@ -76,7 +76,7 @@ public:
//! \brief Construct a SHA3-384 message digest //! \brief Construct a SHA3-384 message digest
SHA3_384() : SHA3(DIGESTSIZE) {} SHA3_384() : SHA3(DIGESTSIZE) {}
static const char * StaticAlgorithmName() {return "SHA-3-384";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA-3-384";}
} CRYPTOPP_DEPRECATED("SHA-3 will be changing in the future due to FIPS 202 finalization"); } CRYPTOPP_DEPRECATED("SHA-3 will be changing in the future due to FIPS 202 finalization");
//! \class SHA3_512 //! \class SHA3_512
@ -88,7 +88,7 @@ public:
//! \brief Construct a SHA3-512 message digest //! \brief Construct a SHA3-512 message digest
SHA3_512() : SHA3(DIGESTSIZE) {} SHA3_512() : SHA3(DIGESTSIZE) {}
static const char * StaticAlgorithmName() {return "SHA-3-512";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA-3-512";}
} CRYPTOPP_DEPRECATED("SHA-3 will be changing in the future due to FIPS 202 finalization"); } CRYPTOPP_DEPRECATED("SHA-3 will be changing in the future due to FIPS 202 finalization");
NAMESPACE_END NAMESPACE_END

View File

@ -15,7 +15,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \brief SHACAL2 block cipher information //! \brief SHACAL2 block cipher information
struct SHACAL2_Info : public FixedBlockSize<32>, public VariableKeyLength<16, 16, 64> struct SHACAL2_Info : public FixedBlockSize<32>, public VariableKeyLength<16, 16, 64>
{ {
static const char *StaticAlgorithmName() {return "SHACAL-2";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHACAL-2";}
}; };
//! \class SHACAL2 //! \class SHACAL2

10
shark.h
View File

@ -14,9 +14,9 @@ NAMESPACE_BEGIN(CryptoPP)
//! \class SHARK_Info //! \class SHARK_Info
//! \brief SHARK block cipher information //! \brief SHARK block cipher information
struct SHARK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 16>, public VariableRounds<6, 2> struct SHARK_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<6, 2>
{ {
static const char *StaticAlgorithmName() {return "SHARK-E";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHARK-E";}
}; };
//! \class SHARK //! \class SHARK
@ -24,6 +24,8 @@ struct SHARK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 16
/// <a href="http://www.weidai.com/scan-mirror/cs.html#SHARK-E">SHARK-E</a> /// <a href="http://www.weidai.com/scan-mirror/cs.html#SHARK-E">SHARK-E</a>
class SHARK : public SHARK_Info, public BlockCipherDocumentation class SHARK : public SHARK_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief SHARK block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHARK_Info> class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHARK_Info>
{ {
public: public:
@ -34,6 +36,8 @@ class SHARK : public SHARK_Info, public BlockCipherDocumentation
SecBlock<word64> m_roundKeys; SecBlock<word64> m_roundKeys;
}; };
//! \class Enc
//! \brief SHARK block cipher encryption operation
class CRYPTOPP_NO_VTABLE Enc : public Base class CRYPTOPP_NO_VTABLE Enc : public Base
{ {
public: public:
@ -47,6 +51,8 @@ class SHARK : public SHARK_Info, public BlockCipherDocumentation
static const word64 cbox[8][256]; static const word64 cbox[8][256];
}; };
//! \class Dec
//! \brief SHARK block cipher decryption operation
class CRYPTOPP_NO_VTABLE Dec : public Base class CRYPTOPP_NO_VTABLE Dec : public Base
{ {
public: public:

View File

@ -19,10 +19,12 @@ struct SKIPJACK_Info : public FixedBlockSize<8>, public FixedKeyLength<10>
}; };
//! \class SKIPJACK //! \class SKIPJACK
//! \brief SKIPJACK block cipher information //! \brief SKIPJACK block cipher
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#SKIPJACK">SKIPJACK</a> //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#SKIPJACK">SKIPJACK</a>
class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief SKIPJACK block cipher default operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SKIPJACK_Info> class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SKIPJACK_Info>
{ {
public: public:
@ -35,6 +37,8 @@ class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation
FixedSizeSecBlock<byte, 10*256> tab; FixedSizeSecBlock<byte, 10*256> tab;
}; };
//! \class Enc
//! \brief SKIPJACK block cipher encryption operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Enc : public Base class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Enc : public Base
{ {
public: public:
@ -44,6 +48,8 @@ class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation
static const word32 Te[4][256]; static const word32 Te[4][256];
}; };
//! \class Dec
//! \brief SKIPJACK block cipher decryption operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Dec : public Base class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Dec : public Base
{ {
public: public:

View File

@ -20,7 +20,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! algorithm info //! algorithm info
struct SosemanukInfo : public VariableKeyLength<16, 1, 32, 1, SimpleKeyingInterface::UNIQUE_IV, 16> struct SosemanukInfo : public VariableKeyLength<16, 1, 32, 1, SimpleKeyingInterface::UNIQUE_IV, 16>
{ {
static const char * StaticAlgorithmName() {return "Sosemanuk";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Sosemanuk";}
}; };
//! _ //! _

View File

@ -15,7 +15,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \brief Square block cipher information //! \brief Square block cipher information
struct Square_Info : public FixedBlockSize<16>, public FixedKeyLength<16>, FixedRounds<8> struct Square_Info : public FixedBlockSize<16>, public FixedKeyLength<16>, FixedRounds<8>
{ {
static const char *StaticAlgorithmName() {return "Square";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Square";}
}; };
//! \class Square //! \class Square

24
tea.h
View File

@ -16,7 +16,7 @@ NAMESPACE_BEGIN(CryptoPP)
//! \brief TEA block cipher information //! \brief TEA block cipher information
struct TEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32> struct TEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
{ {
static const char *StaticAlgorithmName() {return "TEA";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "TEA";}
}; };
//! \class TEA //! \class TEA
@ -24,6 +24,8 @@ struct TEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public Va
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">TEA</a> //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">TEA</a>
class TEA : public TEA_Info, public BlockCipherDocumentation class TEA : public TEA_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief TEA block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info> class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
{ {
public: public:
@ -34,12 +36,16 @@ class TEA : public TEA_Info, public BlockCipherDocumentation
word32 m_limit; word32 m_limit;
}; };
//! \class Enc
//! \brief TEA block cipher encryption operation
class CRYPTOPP_NO_VTABLE Enc : public Base class CRYPTOPP_NO_VTABLE Enc : public Base
{ {
public: public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
}; };
//! \class Dec
//! \brief TEA block cipher decryption operation
class CRYPTOPP_NO_VTABLE Dec : public Base class CRYPTOPP_NO_VTABLE Dec : public Base
{ {
public: public:
@ -58,7 +64,7 @@ typedef TEA::Decryption TEADecryption;
//! \brief XTEA block cipher information //! \brief XTEA block cipher information
struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32> struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
{ {
static const char *StaticAlgorithmName() {return "XTEA";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "XTEA";}
}; };
//! \class XTEA //! \class XTEA
@ -66,6 +72,8 @@ struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public V
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">XTEA</a> //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">XTEA</a>
class XTEA : public XTEA_Info, public BlockCipherDocumentation class XTEA : public XTEA_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief XTEA block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<XTEA_Info> class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<XTEA_Info>
{ {
public: public:
@ -76,12 +84,16 @@ class XTEA : public XTEA_Info, public BlockCipherDocumentation
word32 m_limit; word32 m_limit;
}; };
//! \class Enc
//! \brief XTEA block cipher encryption operation
class CRYPTOPP_NO_VTABLE Enc : public Base class CRYPTOPP_NO_VTABLE Enc : public Base
{ {
public: public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
}; };
//! \class Dec
//! \brief XTEA block cipher decryption operation
class CRYPTOPP_NO_VTABLE Dec : public Base class CRYPTOPP_NO_VTABLE Dec : public Base
{ {
public: public:
@ -97,7 +109,7 @@ public:
//! \brief BTEA block cipher information //! \brief BTEA block cipher information
struct BTEA_Info : public FixedKeyLength<16> struct BTEA_Info : public FixedKeyLength<16>
{ {
static const char *StaticAlgorithmName() {return "BTEA";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "BTEA";}
}; };
//! \class BTEA //! \class BTEA
@ -106,6 +118,8 @@ struct BTEA_Info : public FixedKeyLength<16>
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">Corrected Block TEA</a>. //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">Corrected Block TEA</a>.
class BTEA : public BTEA_Info, public BlockCipherDocumentation class BTEA : public BTEA_Info, public BlockCipherDocumentation
{ {
//! \class Base
//! \brief BTEA block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>, public BTEA_Info class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>, public BTEA_Info
{ {
public: public:
@ -123,12 +137,16 @@ class BTEA : public BTEA_Info, public BlockCipherDocumentation
unsigned int m_blockSize; unsigned int m_blockSize;
}; };
//! \class Enc
//! \brief BTEA block cipher encryption operation
class CRYPTOPP_NO_VTABLE Enc : public Base class CRYPTOPP_NO_VTABLE Enc : public Base
{ {
public: public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
}; };
//! \class Dec
//! \brief BTEA block cipher decryption operation
class CRYPTOPP_NO_VTABLE Dec : public Base class CRYPTOPP_NO_VTABLE Dec : public Base
{ {
public: public:

View File

@ -13,7 +13,7 @@ public:
static void InitState(HashWordType *state); static void InitState(HashWordType *state);
static void Transform(word64 *digest, const word64 *data); static void Transform(word64 *digest, const word64 *data);
void TruncatedFinal(byte *hash, size_t size); void TruncatedFinal(byte *hash, size_t size);
static const char * StaticAlgorithmName() {return "Tiger";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Tiger";}
protected: protected:
static const word64 table[4*256+3]; static const word64 table[4*256+3];

13
ttmac.h
View File

@ -1,5 +1,8 @@
// ttmac.h - written and placed in the public domain by Kevin Springle // ttmac.h - written and placed in the public domain by Kevin Springle
//! \file ttmac.h
//! \brief Classes for the TTMAC message authentication code
#ifndef CRYPTOPP_TTMAC_H #ifndef CRYPTOPP_TTMAC_H
#define CRYPTOPP_TTMAC_H #define CRYPTOPP_TTMAC_H
@ -9,7 +12,8 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
//! _ //! \class TTMAC_Base
//! \brief TTMAC message authentication code information
class CRYPTOPP_NO_VTABLE TTMAC_Base : public FixedKeyLength<20>, public IteratedHash<word32, LittleEndian, 64, MessageAuthenticationCode> class CRYPTOPP_NO_VTABLE TTMAC_Base : public FixedKeyLength<20>, public IteratedHash<word32, LittleEndian, 64, MessageAuthenticationCode>
{ {
public: public:
@ -30,8 +34,11 @@ protected:
FixedSizeSecBlock<word32, 5> m_key; FixedSizeSecBlock<word32, 5> m_key;
}; };
//! <a href="http://www.weidai.com/scan-mirror/mac.html#TTMAC">Two-Track-MAC</a> //! \class TTMAC
/*! 160 Bit MAC with 160 Bit Key */ //! \brief Two-Track-MAC message authentication code
//! \tparam T HashTransformation class
//! \details 160-bit MAC with 160-bit key
//! \sa MessageAuthenticationCode(), <a href="http://www.weidai.com/scan-mirror/mac.html#TTMAC">Two-Track-MAC</a>
DOCUMENTED_TYPEDEF(MessageAuthenticationCodeFinal<TTMAC_Base>, TTMAC) DOCUMENTED_TYPEDEF(MessageAuthenticationCodeFinal<TTMAC_Base>, TTMAC)
NAMESPACE_END NAMESPACE_END

View File

@ -13,9 +13,9 @@ NAMESPACE_BEGIN(CryptoPP)
//! \class Twofish_Info //! \class Twofish_Info
//! \brief Twofish block cipher information //! \brief Twofish block cipher information
struct Twofish_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 0, 32>, FixedRounds<16> struct Twofish_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 8>, FixedRounds<16>
{ {
static const char *StaticAlgorithmName() {return "Twofish";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Twofish";}
}; };
//! \class Twofish //! \class Twofish

View File

@ -2435,93 +2435,240 @@ bool ValidateARC4()
bool ValidateRC5() bool ValidateRC5()
{ {
cout << "\nRC5 validation suite running...\n\n"; cout << "\nRC5 validation suite running...\n\n";
bool pass1 = true, pass2 = true;
RC5Encryption enc; // 0 to 2040-bits (255-bytes)
pass1 = RC5Encryption::DEFAULT_KEYLENGTH == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(0) == 0 && pass1;
pass1 = enc.StaticGetValidKeyLength(254) == 254 && pass1;
pass1 = enc.StaticGetValidKeyLength(255) == 255 && pass1;
pass1 = enc.StaticGetValidKeyLength(256) == 255 && pass1;
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
RC5Decryption dec;
pass2 = RC5Decryption::DEFAULT_KEYLENGTH == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(0) == 0 && pass2;
pass2 = dec.StaticGetValidKeyLength(254) == 254 && pass2;
pass2 = dec.StaticGetValidKeyLength(255) == 255 && pass2;
pass2 = dec.StaticGetValidKeyLength(256) == 255 && pass2;
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc5val.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc5val.dat", true, new HexDecoder);
return BlockTransformationTest(VariableRoundsCipherFactory<RC5Encryption, RC5Decryption>(16, 12), valdata); return BlockTransformationTest(VariableRoundsCipherFactory<RC5Encryption, RC5Decryption>(16, 12), valdata) && pass1 && pass2;
} }
bool ValidateRC6() bool ValidateRC6()
{ {
cout << "\nRC6 validation suite running...\n\n"; cout << "\nRC6 validation suite running...\n\n";
bool pass1 = true, pass2 = true, pass3 = true;
RC6Encryption enc;
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(24) == 24 && pass1;
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(128) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
RC6Decryption dec;
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(24) == 24 && pass2;
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc6val.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc6val.dat", true, new HexDecoder);
bool pass = true; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(16), valdata, 2) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(16), valdata, 2) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(24), valdata, 2) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(24), valdata, 2) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(32), valdata, 2) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(32), valdata, 2) && pass; return pass1 && pass2 && pass3;
return pass;
} }
bool ValidateMARS() bool ValidateMARS()
{ {
cout << "\nMARS validation suite running...\n\n"; cout << "\nMARS validation suite running...\n\n";
bool pass1 = true, pass2 = true, pass3 = true;
MARSEncryption enc;
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(24) == 24 && pass1;
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(128) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
MARSDecryption dec;
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(24) == 24 && pass2;
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/marsval.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/marsval.dat", true, new HexDecoder);
bool pass = true; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(16), valdata, 4) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(16), valdata, 4) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(24), valdata, 3) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(24), valdata, 3) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(32), valdata, 2) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(32), valdata, 2) && pass; return pass1 && pass2 && pass3;
return pass;
} }
bool ValidateRijndael() bool ValidateRijndael()
{ {
cout << "\nRijndael (AES) validation suite running...\n\n"; cout << "\nRijndael (AES) validation suite running...\n\n";
bool pass1 = true, pass2 = true, pass3 = true;
RijndaelEncryption enc;
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(24) == 24 && pass1;
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(128) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
RijndaelDecryption dec;
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(24) == 24 && pass2;
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rijndael.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rijndael.dat", true, new HexDecoder);
bool pass = true; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(16), valdata, 4) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(16), valdata, 4) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(24), valdata, 3) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(24), valdata, 3) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(32), valdata, 2) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(32), valdata, 2) && pass; pass3 = RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/aes.txt") && pass3;
pass = RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/aes.txt") && pass; return pass1 && pass2 && pass3;
return pass;
} }
bool ValidateTwofish() bool ValidateTwofish()
{ {
cout << "\nTwofish validation suite running...\n\n"; cout << "\nTwofish validation suite running...\n\n";
bool pass1 = true, pass2 = true, pass3 = true;
TwofishEncryption enc;
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(24) == 24 && pass1;
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(128) == 32 && pass1;
TwofishDecryption dec;
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(24) == 24 && pass2;
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/twofishv.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/twofishv.dat", true, new HexDecoder);
bool pass = true; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(16), valdata, 4) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(16), valdata, 4) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(24), valdata, 3) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(24), valdata, 3) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(32), valdata, 2) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(32), valdata, 2) && pass; return pass1 && pass2 && pass3;
return pass;
} }
bool ValidateSerpent() bool ValidateSerpent()
{ {
cout << "\nSerpent validation suite running...\n\n"; cout << "\nSerpent validation suite running...\n\n";
bool pass1 = true, pass2 = true, pass3 = true;
SerpentEncryption enc;
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(24) == 24 && pass1;
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(128) == 32 && pass1;
SerpentDecryption dec;
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(24) == 24 && pass2;
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/serpentv.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/serpentv.dat", true, new HexDecoder);
bool pass = true; bool pass = true;
pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(16), valdata, 5) && pass; pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(16), valdata, 5) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(24), valdata, 4) && pass; pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(24), valdata, 4) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(32), valdata, 3) && pass; pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(32), valdata, 3) && pass;
return pass; return pass1 && pass2 && pass3;
} }
bool ValidateBlowfish() bool ValidateBlowfish()
{ {
cout << "\nBlowfish validation suite running...\n\n"; cout << "\nBlowfish validation suite running...\n\n";
bool pass1 = true, pass2 = true, pass3 = true, fail;
BlowfishEncryption enc1; // 32 to 448-bits (4 to 56-bytes)
pass1 = enc1.StaticGetValidKeyLength(3) == 4 && pass1;
pass1 = enc1.StaticGetValidKeyLength(4) == 4 && pass1;
pass1 = enc1.StaticGetValidKeyLength(5) == 5 && pass1;
pass1 = enc1.StaticGetValidKeyLength(8) == 8 && pass1;
pass1 = enc1.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc1.StaticGetValidKeyLength(24) == 24 && pass1;
pass1 = enc1.StaticGetValidKeyLength(32) == 32 && pass1;
pass1 = enc1.StaticGetValidKeyLength(56) == 56 && pass1;
pass1 = enc1.StaticGetValidKeyLength(57) == 56 && pass1;
pass1 = enc1.StaticGetValidKeyLength(60) == 56 && pass1;
pass1 = enc1.StaticGetValidKeyLength(64) == 56 && pass1;
pass1 = enc1.StaticGetValidKeyLength(128) == 56 && pass1;
BlowfishDecryption dec1; // 32 to 448-bits (4 to 56-bytes)
pass2 = dec1.StaticGetValidKeyLength(3) == 4 && pass2;
pass2 = dec1.StaticGetValidKeyLength(4) == 4 && pass2;
pass2 = dec1.StaticGetValidKeyLength(5) == 5 && pass2;
pass2 = dec1.StaticGetValidKeyLength(8) == 8 && pass2;
pass2 = dec1.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec1.StaticGetValidKeyLength(24) == 24 && pass2;
pass2 = dec1.StaticGetValidKeyLength(32) == 32 && pass2;
pass2 = dec1.StaticGetValidKeyLength(56) == 56 && pass2;
pass2 = dec1.StaticGetValidKeyLength(57) == 56 && pass2;
pass2 = dec1.StaticGetValidKeyLength(60) == 56 && pass2;
pass2 = dec1.StaticGetValidKeyLength(64) == 56 && pass2;
pass2 = dec1.StaticGetValidKeyLength(128) == 56 && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
HexEncoder output(new FileSink(cout)); HexEncoder output(new FileSink(cout));
const char *key[]={"abcdefghijklmnopqrstuvwxyz", "Who is John Galt?"}; const char *key[]={"abcdefghijklmnopqrstuvwxyz", "Who is John Galt?"};
byte *plain[]={(byte *)"BLOWFISH", (byte *)"\xfe\xdc\xba\x98\x76\x54\x32\x10"}; byte *plain[]={(byte *)"BLOWFISH", (byte *)"\xfe\xdc\xba\x98\x76\x54\x32\x10"};
byte *cipher[]={(byte *)"\x32\x4e\xd0\xfe\xf4\x13\xa2\x03", (byte *)"\xcc\x91\x73\x2b\x80\x22\xf6\x84"}; byte *cipher[]={(byte *)"\x32\x4e\xd0\xfe\xf4\x13\xa2\x03", (byte *)"\xcc\x91\x73\x2b\x80\x22\xf6\x84"};
byte out[8], outplain[8]; byte out[8], outplain[8];
bool pass=true, fail;
for (int i=0; i<2; i++) for (int i=0; i<2; i++)
{ {
ECB_Mode<Blowfish>::Encryption enc((byte *)key[i], strlen(key[i])); ECB_Mode<Blowfish>::Encryption enc2((byte *)key[i], strlen(key[i]));
enc.ProcessData(out, plain[i], 8); enc2.ProcessData(out, plain[i], 8);
fail = memcmp(out, cipher[i], 8) != 0; fail = memcmp(out, cipher[i], 8) != 0;
ECB_Mode<Blowfish>::Decryption dec((byte *)key[i], strlen(key[i])); ECB_Mode<Blowfish>::Decryption dec2((byte *)key[i], strlen(key[i]));
dec.ProcessData(outplain, cipher[i], 8); dec2.ProcessData(outplain, cipher[i], 8);
fail = fail || memcmp(outplain, plain[i], 8); fail = fail || memcmp(outplain, plain[i], 8);
pass = pass && !fail; pass3 = pass3 && !fail;
cout << (fail ? "FAILED " : "passed "); cout << (fail ? "FAILED " : "passed ");
cout << '\"' << key[i] << '\"'; cout << '\"' << key[i] << '\"';
@ -2532,76 +2679,196 @@ bool ValidateBlowfish()
output.Put(out, 8); output.Put(out, 8);
cout << endl; cout << endl;
} }
return pass; return pass1 && pass2 && pass3;
} }
bool ValidateThreeWay() bool ValidateThreeWay()
{ {
cout << "\n3-WAY validation suite running...\n\n"; cout << "\n3-WAY validation suite running...\n\n";
bool pass1 = true, pass2 = true;
ThreeWayEncryption enc; // 96-bit only
pass1 = ThreeWayEncryption::KEYLENGTH == 12 && pass1;
pass1 = enc.StaticGetValidKeyLength(8) == 12 && pass1;
pass1 = enc.StaticGetValidKeyLength(12) == 12 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 12 && pass1;
ThreeWayDecryption dec; // 96-bit only
pass2 = ThreeWayDecryption::KEYLENGTH == 12 && pass2;
pass2 = dec.StaticGetValidKeyLength(8) == 12 && pass2;
pass2 = dec.StaticGetValidKeyLength(12) == 12 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 12 && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/3wayval.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/3wayval.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<ThreeWayEncryption, ThreeWayDecryption>(), valdata); return BlockTransformationTest(FixedRoundsCipherFactory<ThreeWayEncryption, ThreeWayDecryption>(), valdata) && pass1 && pass2;
} }
bool ValidateGOST() bool ValidateGOST()
{ {
cout << "\nGOST validation suite running...\n\n"; cout << "\nGOST validation suite running...\n\n";
bool pass1 = true, pass2 = true;
GOSTEncryption enc; // 256-bit only
pass1 = GOSTEncryption::KEYLENGTH == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(24) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(40) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
GOSTDecryption dec; // 256-bit only
pass2 = GOSTDecryption::KEYLENGTH == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(24) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(40) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/gostval.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/gostval.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<GOSTEncryption, GOSTDecryption>(), valdata); return BlockTransformationTest(FixedRoundsCipherFactory<GOSTEncryption, GOSTDecryption>(), valdata) && pass1 && pass2;
} }
bool ValidateSHARK() bool ValidateSHARK()
{ {
cout << "\nSHARK validation suite running...\n\n"; cout << "\nSHARK validation suite running...\n\n";
bool pass1 = true, pass2 = true;
SHARKEncryption enc; // 128-bit only
pass1 = SHARKEncryption::KEYLENGTH == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(15) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(17) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(32) == 16 && pass1;
SHARKDecryption dec; // 128-bit only
pass2 = SHARKDecryption::KEYLENGTH == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(15) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(17) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(32) == 16 && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/sharkval.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/sharkval.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<SHARKEncryption, SHARKDecryption>(), valdata); return BlockTransformationTest(FixedRoundsCipherFactory<SHARKEncryption, SHARKDecryption>(), valdata) && pass1 && pass2;
} }
bool ValidateCAST() bool ValidateCAST()
{ {
bool pass = true;
cout << "\nCAST-128 validation suite running...\n\n"; cout << "\nCAST-128 validation suite running...\n\n";
bool pass1 = true, pass2 = true, pass3 = true;
CAST128Encryption enc1; // 40 to 128-bits (5 to 16-bytes)
pass1 = CAST128Encryption::DEFAULT_KEYLENGTH == 16 && pass1;
pass1 = enc1.StaticGetValidKeyLength(4) == 5 && pass1;
pass1 = enc1.StaticGetValidKeyLength(5) == 5 && pass1;
pass1 = enc1.StaticGetValidKeyLength(15) == 15 && pass1;
pass1 = enc1.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc1.StaticGetValidKeyLength(17) == 16 && pass1;
CAST128Decryption dec1; // 40 to 128-bits (5 to 16-bytes)
pass2 = CAST128Decryption::DEFAULT_KEYLENGTH == 16 && pass2;
pass2 = dec1.StaticGetValidKeyLength(4) == 5 && pass2;
pass2 = dec1.StaticGetValidKeyLength(5) == 5 && pass2;
pass2 = dec1.StaticGetValidKeyLength(15) == 15 && pass2;
pass2 = dec1.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec1.StaticGetValidKeyLength(17) == 16 && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource val128(CRYPTOPP_DATA_DIR "TestData/cast128v.dat", true, new HexDecoder); FileSource val128(CRYPTOPP_DATA_DIR "TestData/cast128v.dat", true, new HexDecoder);
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(16), val128, 1) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(16), val128, 1) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(10), val128, 1) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(10), val128, 1) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(5), val128, 1) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(5), val128, 1) && pass3;
cout << "\nCAST-256 validation suite running...\n\n"; cout << "\nCAST-256 validation suite running...\n\n";
bool pass4 = true, pass5 = true, pass6 = true;
CAST256Encryption enc2; // 128, 160, 192, 224, or 256-bits (16 to 32-bytes, step 4)
pass1 = CAST128Encryption::DEFAULT_KEYLENGTH == 16 && pass1;
pass4 = enc2.StaticGetValidKeyLength(15) == 16 && pass4;
pass4 = enc2.StaticGetValidKeyLength(16) == 16 && pass4;
pass4 = enc2.StaticGetValidKeyLength(17) == 20 && pass4;
pass4 = enc2.StaticGetValidKeyLength(20) == 20 && pass4;
pass4 = enc2.StaticGetValidKeyLength(24) == 24 && pass4;
pass4 = enc2.StaticGetValidKeyLength(28) == 28 && pass4;
pass4 = enc2.StaticGetValidKeyLength(31) == 32 && pass4;
pass4 = enc2.StaticGetValidKeyLength(32) == 32 && pass4;
pass4 = enc2.StaticGetValidKeyLength(33) == 32 && pass4;
CAST256Decryption dec2; // 128, 160, 192, 224, or 256-bits (16 to 32-bytes, step 4)
pass2 = CAST256Decryption::DEFAULT_KEYLENGTH == 16 && pass2;
pass5 = dec2.StaticGetValidKeyLength(15) == 16 && pass5;
pass5 = dec2.StaticGetValidKeyLength(16) == 16 && pass5;
pass5 = dec2.StaticGetValidKeyLength(17) == 20 && pass5;
pass5 = dec2.StaticGetValidKeyLength(20) == 20 && pass5;
pass5 = dec2.StaticGetValidKeyLength(24) == 24 && pass5;
pass5 = dec2.StaticGetValidKeyLength(28) == 28 && pass5;
pass5 = dec2.StaticGetValidKeyLength(31) == 32 && pass5;
pass5 = dec2.StaticGetValidKeyLength(32) == 32 && pass5;
pass5 = dec2.StaticGetValidKeyLength(33) == 32 && pass5;
cout << (pass4 && pass5 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource val256(CRYPTOPP_DATA_DIR "TestData/cast256v.dat", true, new HexDecoder); FileSource val256(CRYPTOPP_DATA_DIR "TestData/cast256v.dat", true, new HexDecoder);
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(16), val256, 1) && pass; pass6 = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(16), val256, 1) && pass6;
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(24), val256, 1) && pass; pass6 = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(24), val256, 1) && pass6;
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(32), val256, 1) && pass; pass6 = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(32), val256, 1) && pass6;
return pass; return pass1 && pass2 && pass3 && pass4 && pass5 && pass6;
} }
bool ValidateSquare() bool ValidateSquare()
{ {
cout << "\nSquare validation suite running...\n\n"; cout << "\nSquare validation suite running...\n\n";
bool pass1 = true, pass2 = true;
SquareEncryption enc; // 128-bits only
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(15) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(17) == 16 && pass1;
SquareDecryption dec; // 128-bits only
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(15) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(17) == 16 && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/squareva.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/squareva.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<SquareEncryption, SquareDecryption>(), valdata); return BlockTransformationTest(FixedRoundsCipherFactory<SquareEncryption, SquareDecryption>(), valdata) && pass1 && pass2;
} }
bool ValidateSKIPJACK() bool ValidateSKIPJACK()
{ {
cout << "\nSKIPJACK validation suite running...\n\n"; cout << "\nSKIPJACK validation suite running...\n\n";
bool pass1 = true, pass2 = true;
SKIPJACKEncryption enc; // 80-bits only
pass1 = enc.StaticGetValidKeyLength(8) == 10 && pass1;
pass1 = enc.StaticGetValidKeyLength(9) == 10 && pass1;
pass1 = enc.StaticGetValidKeyLength(10) == 10 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 10 && pass1;
SKIPJACKDecryption dec; // 80-bits only
pass2 = dec.StaticGetValidKeyLength(8) == 10 && pass2;
pass2 = dec.StaticGetValidKeyLength(9) == 10 && pass2;
pass2 = dec.StaticGetValidKeyLength(10) == 10 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 10 && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/skipjack.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/skipjack.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<SKIPJACKEncryption, SKIPJACKDecryption>(), valdata); return BlockTransformationTest(FixedRoundsCipherFactory<SKIPJACKEncryption, SKIPJACKDecryption>(), valdata) && pass1 && pass2;
} }
bool ValidateSEAL() bool ValidateSEAL()
{ {
byte input[] = {0x37,0xa0,0x05,0x95,0x9b,0x84,0xc4,0x9c,0xa4,0xbe,0x1e,0x05,0x06,0x73,0x53,0x0f,0x5f,0xb0,0x97,0xfd,0xf6,0xa1,0x3f,0xbd,0x6c,0x2c,0xde,0xcd,0x81,0xfd,0xee,0x7c}; static const byte input[] = {0x37,0xa0,0x05,0x95,0x9b,0x84,0xc4,0x9c,0xa4,0xbe,0x1e,0x05,0x06,0x73,0x53,0x0f,0x5f,0xb0,0x97,0xfd,0xf6,0xa1,0x3f,0xbd,0x6c,0x2c,0xde,0xcd,0x81,0xfd,0xee,0x7c};
static const byte key[] = {0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0};
static const byte iv[] = {0x01, 0x35, 0x77, 0xaf};
byte output[32]; byte output[32];
byte key[] = {0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0};
byte iv[] = {0x01, 0x35, 0x77, 0xaf};
cout << "\nSEAL validation suite running...\n\n"; cout << "\nSEAL validation suite running...\n\n";
@ -2694,24 +2961,66 @@ bool ValidateBaseCode()
bool ValidateSHACAL2() bool ValidateSHACAL2()
{ {
cout << "\nSHACAL-2 validation suite running...\n\n"; cout << "\nSHACAL-2 validation suite running...\n\n";
bool pass1 = true, pass2 = true, pass3 = true;
SHACAL2Encryption enc; // 128 to 512-bits (16 to 64-bytes)
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(15) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(64) == 64 && pass1;
pass1 = enc.StaticGetValidKeyLength(65) == 64 && pass1;
pass1 = enc.StaticGetValidKeyLength(128) == 64 && pass1;
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
SHACAL2Decryption dec; // 128 to 512-bits (16 to 64-bytes)
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(15) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(64) == 64 && pass2;
pass2 = dec.StaticGetValidKeyLength(65) == 64 && pass2;
pass2 = dec.StaticGetValidKeyLength(128) == 64 && pass2;
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
bool pass = true;
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/shacal2v.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/shacal2v.dat", true, new HexDecoder);
pass = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(16), valdata, 4) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(16), valdata, 4) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(64), valdata, 10) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(64), valdata, 10) && pass3;
return pass; return pass1 && pass2 && pass3;
} }
bool ValidateCamellia() bool ValidateCamellia()
{ {
cout << "\nCamellia validation suite running...\n\n"; cout << "\nCamellia validation suite running...\n\n";
bool pass1 = true, pass2 = true, pass3 = true;
CamelliaEncryption enc;
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
pass1 = enc.StaticGetValidKeyLength(24) == 24 && pass1;
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(128) == 32 && pass1;
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
CamelliaDecryption dec;
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
pass2 = dec.StaticGetValidKeyLength(24) == 24 && pass2;
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
bool pass = true;
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/camellia.dat", true, new HexDecoder); FileSource valdata(CRYPTOPP_DATA_DIR "TestData/camellia.dat", true, new HexDecoder);
pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(16), valdata, 15) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(16), valdata, 15) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(24), valdata, 15) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(24), valdata, 15) && pass3;
pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(32), valdata, 15) && pass; pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(32), valdata, 15) && pass3;
return pass; return pass1 && pass2 && pass3;
} }
bool ValidateSalsa() bool ValidateSalsa()

13
wake.h
View File

@ -12,11 +12,13 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
//! _ //! \class WAKE_OFB_Info
//! \brief WAKE stream cipher information
//! \tparam B Endianess of the stream cipher
template <class B = BigEndian> template <class B = BigEndian>
struct WAKE_OFB_Info : public FixedKeyLength<32> struct WAKE_OFB_Info : public FixedKeyLength<32>
{ {
static const char *StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "WAKE-OFB-LE" : "WAKE-OFB-BE";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "WAKE-OFB-LE" : "WAKE-OFB-BE";}
}; };
class CRYPTOPP_NO_VTABLE WAKE_Base class CRYPTOPP_NO_VTABLE WAKE_Base
@ -29,6 +31,9 @@ protected:
word32 r3, r4, r5, r6; word32 r3, r4, r5, r6;
}; };
//! \class WAKE_Policy
//! \brief WAKE stream cipher operation
//! \tparam B Endianess of the stream cipher
template <class B = BigEndian> template <class B = BigEndian>
class CRYPTOPP_NO_VTABLE WAKE_Policy : public AdditiveCipherConcretePolicy<word32, 1, 64>, protected WAKE_Base class CRYPTOPP_NO_VTABLE WAKE_Policy : public AdditiveCipherConcretePolicy<word32, 1, 64>, protected WAKE_Base
{ {
@ -39,7 +44,9 @@ protected:
bool CipherIsRandomAccess() const {return false;} bool CipherIsRandomAccess() const {return false;}
}; };
//! WAKE-OFB //! \class WAKE_OFB
//! \brief WAKE stream cipher
//! \tparam B Endianess of the stream cipher
template <class B = BigEndian> template <class B = BigEndian>
struct WAKE_OFB : public WAKE_OFB_Info<B>, public SymmetricCipherDocumentation struct WAKE_OFB : public WAKE_OFB_Info<B>, public SymmetricCipherDocumentation
{ {

View File

@ -13,7 +13,7 @@ public:
static void InitState(HashWordType *state); static void InitState(HashWordType *state);
static void Transform(word64 *digest, const word64 *data); static void Transform(word64 *digest, const word64 *data);
void TruncatedFinal(byte *hash, size_t size); void TruncatedFinal(byte *hash, size_t size);
static const char * StaticAlgorithmName() {return "Whirlpool";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Whirlpool";}
}; };
NAMESPACE_END NAMESPACE_END