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

View File

@ -57,13 +57,13 @@ static inline word32 reverseBits(word32 a)
a0 ^= c ^ b0; \ a0 ^= c ^ b0; \
a1 ^= c ^ b1; \ a1 ^= c ^ b1; \
a2 ^= c ^ (b0 >> 16) ^ (b1 << 16); \ a2 ^= c ^ (b0 >> 16) ^ (b1 << 16); \
} }
#define rho(a0, a1, a2) \ #define rho(a0, a1, a2) \
{ \ { \
theta(a0, a1, a2); \ theta(a0, a1, a2); \
pi_gamma_pi(a0, a1, a2); \ pi_gamma_pi(a0, a1, a2); \
} }
void ThreeWay::Base::UncheckedSetKey(const byte *uk, unsigned int length, const NameValuePairs &params) void ThreeWay::Base::UncheckedSetKey(const byte *uk, unsigned int length, const NameValuePairs &params)
{ {

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

@ -11,7 +11,7 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
//! ADLER-32 checksum calculations //! ADLER-32 checksum calculations
class Adler32 : public HashTransformation class Adler32 : public HashTransformation
{ {
public: public:
@ -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:

6
arc4.h
View File

@ -23,13 +23,13 @@ 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);
void ProcessData(byte *outString, const byte *inString, size_t length); void ProcessData(byte *outString, const byte *inString, size_t length);
bool IsRandomAccess() const {return false;} bool IsRandomAccess() const {return false;}
bool IsSelfInverting() const {return true;} bool IsSelfInverting() const {return true;}
bool IsForwardTransformation() const {return true;} bool IsForwardTransformation() const {return true;}
@ -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

View File

@ -151,48 +151,48 @@ void CAST128::Base::UncheckedSetKey(const byte *userKey, unsigned int keylength,
// The following CAST-256 implementation was contributed by Leonard Janke // The following CAST-256 implementation was contributed by Leonard Janke
const word32 CAST256::Base::t_m[8][24]={ const word32 CAST256::Base::t_m[8][24]={
{ 0x5a827999, 0xd151d6a1, 0x482133a9, 0xbef090b1, 0x35bfedb9, 0xac8f4ac1, { 0x5a827999, 0xd151d6a1, 0x482133a9, 0xbef090b1, 0x35bfedb9, 0xac8f4ac1,
0x235ea7c9, 0x9a2e04d1, 0x10fd61d9, 0x87ccbee1, 0xfe9c1be9, 0x756b78f1, 0x235ea7c9, 0x9a2e04d1, 0x10fd61d9, 0x87ccbee1, 0xfe9c1be9, 0x756b78f1,
0xec3ad5f9, 0x630a3301, 0xd9d99009, 0x50a8ed11, 0xc7784a19, 0x3e47a721, 0xec3ad5f9, 0x630a3301, 0xd9d99009, 0x50a8ed11, 0xc7784a19, 0x3e47a721,
0xb5170429, 0x2be66131, 0xa2b5be39, 0x19851b41, 0x90547849, 0x0723d551}, 0xb5170429, 0x2be66131, 0xa2b5be39, 0x19851b41, 0x90547849, 0x0723d551},
{ 0xc95c653a, 0x402bc242, 0xb6fb1f4a, 0x2dca7c52, 0xa499d95a, 0x1b693662, { 0xc95c653a, 0x402bc242, 0xb6fb1f4a, 0x2dca7c52, 0xa499d95a, 0x1b693662,
0x9238936a, 0x0907f072, 0x7fd74d7a, 0xf6a6aa82, 0x6d76078a, 0xe4456492, 0x9238936a, 0x0907f072, 0x7fd74d7a, 0xf6a6aa82, 0x6d76078a, 0xe4456492,
0x5b14c19a, 0xd1e41ea2, 0x48b37baa, 0xbf82d8b2, 0x365235ba, 0xad2192c2, 0x5b14c19a, 0xd1e41ea2, 0x48b37baa, 0xbf82d8b2, 0x365235ba, 0xad2192c2,
0x23f0efca, 0x9ac04cd2, 0x118fa9da, 0x885f06e2, 0xff2e63ea, 0x75fdc0f2}, 0x23f0efca, 0x9ac04cd2, 0x118fa9da, 0x885f06e2, 0xff2e63ea, 0x75fdc0f2},
{ 0x383650db, 0xaf05ade3, 0x25d50aeb, 0x9ca467f3, 0x1373c4fb, 0x8a432203, { 0x383650db, 0xaf05ade3, 0x25d50aeb, 0x9ca467f3, 0x1373c4fb, 0x8a432203,
0x01127f0b, 0x77e1dc13, 0xeeb1391b, 0x65809623, 0xdc4ff32b, 0x531f5033, 0x01127f0b, 0x77e1dc13, 0xeeb1391b, 0x65809623, 0xdc4ff32b, 0x531f5033,
0xc9eead3b, 0x40be0a43, 0xb78d674b, 0x2e5cc453, 0xa52c215b, 0x1bfb7e63, 0xc9eead3b, 0x40be0a43, 0xb78d674b, 0x2e5cc453, 0xa52c215b, 0x1bfb7e63,
0x92cadb6b, 0x099a3873, 0x8069957b, 0xf738f283, 0x6e084f8b, 0xe4d7ac93}, 0x92cadb6b, 0x099a3873, 0x8069957b, 0xf738f283, 0x6e084f8b, 0xe4d7ac93},
{ 0xa7103c7c, 0x1ddf9984, 0x94aef68c, 0x0b7e5394, 0x824db09c, 0xf91d0da4, { 0xa7103c7c, 0x1ddf9984, 0x94aef68c, 0x0b7e5394, 0x824db09c, 0xf91d0da4,
0x6fec6aac, 0xe6bbc7b4, 0x5d8b24bc, 0xd45a81c4, 0x4b29decc, 0xc1f93bd4, 0x6fec6aac, 0xe6bbc7b4, 0x5d8b24bc, 0xd45a81c4, 0x4b29decc, 0xc1f93bd4,
0x38c898dc, 0xaf97f5e4, 0x266752ec, 0x9d36aff4, 0x14060cfc, 0x8ad56a04, 0x38c898dc, 0xaf97f5e4, 0x266752ec, 0x9d36aff4, 0x14060cfc, 0x8ad56a04,
0x01a4c70c, 0x78742414, 0xef43811c, 0x6612de24, 0xdce23b2c, 0x53b19834}, 0x01a4c70c, 0x78742414, 0xef43811c, 0x6612de24, 0xdce23b2c, 0x53b19834},
{ 0x15ea281d, 0x8cb98525, 0x0388e22d, 0x7a583f35, 0xf1279c3d, 0x67f6f945, { 0x15ea281d, 0x8cb98525, 0x0388e22d, 0x7a583f35, 0xf1279c3d, 0x67f6f945,
0xdec6564d, 0x5595b355, 0xcc65105d, 0x43346d65, 0xba03ca6d, 0x30d32775, 0xdec6564d, 0x5595b355, 0xcc65105d, 0x43346d65, 0xba03ca6d, 0x30d32775,
0xa7a2847d, 0x1e71e185, 0x95413e8d, 0x0c109b95, 0x82dff89d, 0xf9af55a5, 0xa7a2847d, 0x1e71e185, 0x95413e8d, 0x0c109b95, 0x82dff89d, 0xf9af55a5,
0x707eb2ad, 0xe74e0fb5, 0x5e1d6cbd, 0xd4ecc9c5, 0x4bbc26cd, 0xc28b83d5}, 0x707eb2ad, 0xe74e0fb5, 0x5e1d6cbd, 0xd4ecc9c5, 0x4bbc26cd, 0xc28b83d5},
{ 0x84c413be, 0xfb9370c6, 0x7262cdce, 0xe9322ad6, 0x600187de, 0xd6d0e4e6, { 0x84c413be, 0xfb9370c6, 0x7262cdce, 0xe9322ad6, 0x600187de, 0xd6d0e4e6,
0x4da041ee, 0xc46f9ef6, 0x3b3efbfe, 0xb20e5906, 0x28ddb60e, 0x9fad1316, 0x4da041ee, 0xc46f9ef6, 0x3b3efbfe, 0xb20e5906, 0x28ddb60e, 0x9fad1316,
0x167c701e, 0x8d4bcd26, 0x041b2a2e, 0x7aea8736, 0xf1b9e43e, 0x68894146, 0x167c701e, 0x8d4bcd26, 0x041b2a2e, 0x7aea8736, 0xf1b9e43e, 0x68894146,
0xdf589e4e, 0x5627fb56, 0xccf7585e, 0x43c6b566, 0xba96126e, 0x31656f76}, 0xdf589e4e, 0x5627fb56, 0xccf7585e, 0x43c6b566, 0xba96126e, 0x31656f76},
{ 0xf39dff5f, 0x6a6d5c67, 0xe13cb96f, 0x580c1677, 0xcedb737f, 0x45aad087, { 0xf39dff5f, 0x6a6d5c67, 0xe13cb96f, 0x580c1677, 0xcedb737f, 0x45aad087,
0xbc7a2d8f, 0x33498a97, 0xaa18e79f, 0x20e844a7, 0x97b7a1af, 0x0e86feb7, 0xbc7a2d8f, 0x33498a97, 0xaa18e79f, 0x20e844a7, 0x97b7a1af, 0x0e86feb7,
0x85565bbf, 0xfc25b8c7, 0x72f515cf, 0xe9c472d7, 0x6093cfdf, 0xd7632ce7, 0x85565bbf, 0xfc25b8c7, 0x72f515cf, 0xe9c472d7, 0x6093cfdf, 0xd7632ce7,
0x4e3289ef, 0xc501e6f7, 0x3bd143ff, 0xb2a0a107, 0x296ffe0f, 0xa03f5b17}, 0x4e3289ef, 0xc501e6f7, 0x3bd143ff, 0xb2a0a107, 0x296ffe0f, 0xa03f5b17},
{ 0x6277eb00, 0xd9474808, 0x5016a510, 0xc6e60218, 0x3db55f20, 0xb484bc28, { 0x6277eb00, 0xd9474808, 0x5016a510, 0xc6e60218, 0x3db55f20, 0xb484bc28,
0x2b541930, 0xa2237638, 0x18f2d340, 0x8fc23048, 0x06918d50, 0x7d60ea58, 0x2b541930, 0xa2237638, 0x18f2d340, 0x8fc23048, 0x06918d50, 0x7d60ea58,
0xf4304760, 0x6affa468, 0xe1cf0170, 0x589e5e78, 0xcf6dbb80, 0x463d1888, 0xf4304760, 0x6affa468, 0xe1cf0170, 0x589e5e78, 0xcf6dbb80, 0x463d1888,
0xbd0c7590, 0x33dbd298, 0xaaab2fa0, 0x217a8ca8, 0x9849e9b0, 0x0f1946b8} 0xbd0c7590, 0x33dbd298, 0xaaab2fa0, 0x217a8ca8, 0x9849e9b0, 0x0f1946b8}
}; };
const unsigned int CAST256::Base::t_r[8][24]={ const unsigned int CAST256::Base::t_r[8][24]={
{19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11}, {19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11},
{4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28}, {4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28},
{21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13}, {21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13},
{6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30}, {6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30},
{23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15}, {23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15},
{8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0}, {8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0},
{25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17}, {25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17},
{10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2} {10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2}
}; };
@ -262,7 +262,7 @@ void CAST256::Base::UncheckedSetKey(const byte *userKey, unsigned int keylength,
{ {
Omega(2*i,kappa); Omega(2*i,kappa);
Omega(2*i+1,kappa); Omega(2*i+1,kappa);
K[8*i]=kappa[0] & 31; K[8*i]=kappa[0] & 31;
K[8*i+1]=kappa[2] & 31; K[8*i+1]=kappa[2] & 31;
K[8*i+2]=kappa[4] & 31; K[8*i+2]=kappa[4] & 31;
@ -284,8 +284,8 @@ void CAST256::Base::UncheckedSetKey(const byte *userKey, unsigned int keylength,
assert(i1<i2); assert(i1<i2);
std::swap(K[i1],K[i2]); std::swap(K[i1],K[i2]);
std::swap(K[i1+4],K[i2+4]); std::swap(K[i1+4],K[i2+4]);
} }
} }
} }

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"

View File

@ -70,8 +70,8 @@ inline void FPERM(word32 &left, word32 &right)
} }
*/ */
// Wei Dai's modification to Richard Outerbridge's initial permutation // Wei Dai's modification to Richard Outerbridge's initial permutation
// algorithm, this one is faster if you have access to rotate instructions // algorithm, this one is faster if you have access to rotate instructions
// (like in MSVC) // (like in MSVC)
static inline void IPERM(word32 &left, word32 &right) static inline void IPERM(word32 &left, word32 &right)
{ {
@ -283,7 +283,7 @@ void RawDES::RawSetKey(CipherDir dir, const byte *key)
byte *const ks=pcr+56; byte *const ks=pcr+56;
register int i,j,l; register int i,j,l;
int m; int m;
for (j=0; j<56; j++) { /* convert pc1 to bits of key */ for (j=0; j<56; j++) { /* convert pc1 to bits of key */
l=pc1[j]-1; /* integer bit location */ l=pc1[j]-1; /* integer bit location */
m = l & 07; /* find bit */ m = l & 07; /* find bit */
@ -314,7 +314,7 @@ void RawDES::RawSetKey(CipherDir dir, const byte *key)
| ((word32)ks[5] << 8) | ((word32)ks[5] << 8)
| ((word32)ks[7]); | ((word32)ks[7]);
} }
if (dir==DECRYPTION) // reverse key schedule order if (dir==DECRYPTION) // reverse key schedule order
for (i=0; i<16; i+=2) for (i=0; i<16; i+=2)
{ {

14
des.h
View File

@ -30,17 +30,19 @@ 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
//! \brief DES block cipher //! \brief DES block cipher
//! \details The DES implementation in Crypto++ ignores the parity bits //! \details The DES implementation in Crypto++ ignores the parity bits
//! (the least significant bits of each byte) in the key. However you can use CheckKeyParityBits() //! (the least significant bits of each byte) in the key. However you can use CheckKeyParityBits()
//! and CorrectKeyParityBits() to check or correct the parity bits if you wish. //! and CorrectKeyParityBits() to check or correct the parity bits if you wish.
//! \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

@ -16,8 +16,8 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
class CRYPTOPP_NO_VTABLE ElGamalBase : public DL_KeyAgreementAlgorithm_DH<Integer, NoCofactorMultiplication>, class CRYPTOPP_NO_VTABLE ElGamalBase : public DL_KeyAgreementAlgorithm_DH<Integer, NoCofactorMultiplication>,
public DL_KeyDerivationAlgorithm<Integer>, public DL_KeyDerivationAlgorithm<Integer>,
public DL_SymmetricEncryptionAlgorithm public DL_SymmetricEncryptionAlgorithm
{ {
public: public:
@ -86,7 +86,7 @@ public:
} }
virtual const DL_GroupParameters_GFP & GetGroupParameters() const =0; virtual const DL_GroupParameters_GFP & GetGroupParameters() const =0;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~ElGamalBase() {} virtual ~ElGamalBase() {}
#endif #endif
@ -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,9 +90,9 @@ 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,
HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
byte *representative, size_t representativeBitLength) const byte *representative, size_t representativeBitLength) const

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
{ {

View File

@ -24,7 +24,7 @@ const byte GOST::Base::sBox[8][16]={
{ 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 }, { 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 },
{10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 }, {10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 },
{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 }, {15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 },
{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 }}; {14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 }};
*/ */
volatile bool GOST::Base::sTableCalculated = false; volatile bool GOST::Base::sTableCalculated = false;
@ -44,7 +44,7 @@ void GOST::Base::PrecalculateSTable()
if (!sTableCalculated) if (!sTableCalculated)
{ {
for (unsigned i = 0; i < 4; i++) for (unsigned i = 0; i < 4; i++)
for (unsigned j = 0; j < 256; j++) for (unsigned j = 0; j < 256; j++)
{ {
word32 temp = sBox[2*i][j%16] | (sBox[2*i+1][j/16] << 4); word32 temp = sBox[2*i][j%16] | (sBox[2*i+1][j/16] << 4);
sTable[i][j] = rotlMod(temp, 11+8*i); sTable[i][j] = rotlMod(temp, 11+8*i);

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:

View File

@ -42,16 +42,16 @@ void IDEA::Base::BuildLogTables()
else else
{ {
tablesBuilt = true; tablesBuilt = true;
IDEA::Word x=1; IDEA::Word x=1;
word32 i; word32 i;
for (i=0; i<0x10000; i++) for (i=0; i<0x10000; i++)
{ {
antilog[i] = (word16)x; antilog[i] = (word16)x;
DirectMUL(x, 3); DirectMUL(x, 3);
} }
for (i=0; i<0x10000; i++) for (i=0; i<0x10000; i++)
log[antilog[i]] = (word16)i; log[antilog[i]] = (word16)i;
} }
@ -82,16 +82,16 @@ inline void IDEA::Base::LookupMUL(IDEA::Word &a, IDEA::Word b)
void IDEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &) void IDEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
{ {
AssertValidKeyLength(length); AssertValidKeyLength(length);
#ifdef IDEA_LARGECACHE #ifdef IDEA_LARGECACHE
BuildLogTables(); BuildLogTables();
#endif #endif
EnKey(userKey); EnKey(userKey);
if (!IsForwardTransformation()) if (!IsForwardTransformation())
DeKey(); DeKey();
#ifdef IDEA_LARGECACHE #ifdef IDEA_LARGECACHE
LookupKeyLogs(); LookupKeyLogs();
#endif #endif
@ -100,10 +100,10 @@ void IDEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const
void IDEA::Base::EnKey (const byte *userKey) void IDEA::Base::EnKey (const byte *userKey)
{ {
unsigned int i; unsigned int i;
for (i=0; i<8; i++) for (i=0; i<8; i++)
m_key[i] = ((IDEA::Word)userKey[2*i]<<8) | userKey[2*i+1]; m_key[i] = ((IDEA::Word)userKey[2*i]<<8) | userKey[2*i+1];
for (; i<IDEA_KEYLEN; i++) for (; i<IDEA_KEYLEN; i++)
{ {
unsigned int j = RoundDownToMultipleOf(i,8U)-8; unsigned int j = RoundDownToMultipleOf(i,8U)-8;
@ -170,7 +170,7 @@ void IDEA::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, b
x1 += key[i*6+1]; x1 += key[i*6+1];
x2 += key[i*6+2]; x2 += key[i*6+2];
MUL(x3, key[i*6+3]); MUL(x3, key[i*6+3]);
t0 = x0^x2; t0 = x0^x2;
MUL(t0, key[i*6+4]); MUL(t0, key[i*6+4]);
t1 = t0 + (x1^x3); t1 = t0 + (x1^x3);
MUL(t1, key[i*6+5]); MUL(t1, key[i*6+5]);

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

14
luc.h
View File

@ -205,7 +205,7 @@ public:
{ {
return GetValueHelper<DL_GroupParameters_IntegerBased>(this, name, valueType, pValue).Assignable(); return GetValueHelper<DL_GroupParameters_IntegerBased>(this, name, valueType, pValue).Assignable();
} }
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_GroupParameters_LUC() {} virtual ~DL_GroupParameters_LUC() {}
#endif #endif
@ -219,7 +219,7 @@ class DL_GroupParameters_LUC_DefaultSafePrime : public DL_GroupParameters_LUC
{ {
public: public:
typedef NoCofactorMultiplication DefaultCofactorOption; typedef NoCofactorMultiplication DefaultCofactorOption;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_GroupParameters_LUC_DefaultSafePrime() {} virtual ~DL_GroupParameters_LUC_DefaultSafePrime() {}
#endif #endif
@ -232,14 +232,14 @@ 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;
size_t RLen(const DL_GroupParameters<Integer> &params) const size_t RLen(const DL_GroupParameters<Integer> &params) const
{return params.GetGroupOrder().ByteCount();} {return params.GetGroupOrder().ByteCount();}
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_Algorithm_LUC_HMP() {} virtual ~DL_Algorithm_LUC_HMP() {}
#endif #endif
@ -251,7 +251,7 @@ struct DL_SignatureKeys_LUC
typedef DL_GroupParameters_LUC GroupParameters; typedef DL_GroupParameters_LUC GroupParameters;
typedef DL_PublicKey_GFP<GroupParameters> PublicKey; typedef DL_PublicKey_GFP<GroupParameters> PublicKey;
typedef DL_PrivateKey_GFP<GroupParameters> PrivateKey; typedef DL_PrivateKey_GFP<GroupParameters> PrivateKey;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_SignatureKeys_LUC() {} virtual ~DL_SignatureKeys_LUC() {}
#endif #endif
@ -269,7 +269,7 @@ struct DL_CryptoKeys_LUC
typedef DL_GroupParameters_LUC_DefaultSafePrime GroupParameters; typedef DL_GroupParameters_LUC_DefaultSafePrime GroupParameters;
typedef DL_PublicKey_GFP<GroupParameters> PublicKey; typedef DL_PublicKey_GFP<GroupParameters> PublicKey;
typedef DL_PrivateKey_GFP<GroupParameters> PrivateKey; typedef DL_PrivateKey_GFP<GroupParameters> PrivateKey;
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~DL_CryptoKeys_LUC() {} virtual ~DL_CryptoKeys_LUC() {}
#endif #endif
@ -286,7 +286,7 @@ struct LUC_IES
LUC_IES<> > LUC_IES<> >
{ {
static std::string StaticAlgorithmName() {return "LUC-IES";} // non-standard name static std::string StaticAlgorithmName() {return "LUC-IES";} // non-standard name
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual ~LUC_IES() {} virtual ~LUC_IES() {}
#endif #endif

View File

@ -58,7 +58,7 @@ void MARS::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by
unsigned int i; unsigned int i;
word32 a, b, c, d, l, m, r, t; word32 a, b, c, d, l, m, r, t;
const word32 *k = m_k; const word32 *k = m_k;
Block::Get(inBlock)(a)(b)(c)(d); Block::Get(inBlock)(a)(b)(c)(d);
a += k[0]; b += k[1]; c += k[2]; d += k[3]; a += k[0]; b += k[1]; c += k[2]; d += k[3];
@ -109,7 +109,7 @@ void MARS::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by
const word32 *k = m_k; const word32 *k = m_k;
Block::Get(inBlock)(d)(c)(b)(a); Block::Get(inBlock)(d)(c)(b)(a);
d += k[36]; c += k[37]; b += k[38]; a += k[39]; d += k[36]; c += k[37]; b += k[38]; a += k[39];
for (i=0; i<8; i++) for (i=0; i<8; i++)

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";}
}; };
} }

18
mdc.h
View File

@ -1,10 +1,10 @@
// mdc.h - written and placed in the public domain by Wei Dai // mdc.h - written and placed in the public domain by Wei Dai
#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;

View File

@ -55,7 +55,7 @@ public:
{ {
#if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) && defined(IS_LITTLE_ENDIAN) #if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) && defined(IS_LITTLE_ENDIAN)
*((word32*)output) = ByteReverse(NextMersenneWord()); *((word32*)output) = ByteReverse(NextMersenneWord());
#elif defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) #elif defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS)
*((word32*)output) = NextMersenneWord(); *((word32*)output) = NextMersenneWord();
#else #else
temp = NextMersenneWord(); temp = NextMersenneWord();
@ -65,7 +65,7 @@ public:
output[0] = CRYPTOPP_GET_BYTE_AS_BYTE(temp, 3); output[0] = CRYPTOPP_GET_BYTE_AS_BYTE(temp, 3);
#endif #endif
} }
// No tail bytes // No tail bytes
if (size%4 == 0) if (size%4 == 0)
{ {
@ -73,7 +73,7 @@ public:
*((volatile word32*)&temp) = 0; *((volatile word32*)&temp) = 0;
return; return;
} }
// Handle tail bytes // Handle tail bytes
temp = NextMersenneWord(); temp = NextMersenneWord();
switch (size%4) switch (size%4)
@ -84,11 +84,11 @@ public:
default: assert(0); ;; default: assert(0); ;;
} }
// Wipe temp // Wipe temp
*((volatile word32*)&temp) = 0; *((volatile word32*)&temp) = 0;
} }
//! \brief Generate a random 32-bit word in the range min to max, inclusive //! \brief Generate a random 32-bit word in the range min to max, inclusive
//! \returns random 32-bit word in the range min to max, inclusive //! \returns random 32-bit word in the range min to max, inclusive
//! \details If the 32-bit candidate is not within the range, then it is discarded //! \details If the 32-bit candidate is not within the range, then it is discarded
@ -98,7 +98,7 @@ public:
const word32 range = max-min; const word32 range = max-min;
if (range == 0xffffffffL) if (range == 0xffffffffL)
return NextMersenneWord(); return NextMersenneWord();
const int maxBits = BitPrecision(range); const int maxBits = BitPrecision(range);
word32 value; word32 value;
@ -108,7 +108,7 @@ public:
return value+min; return value+min;
} }
//! \brief Generate and discard n bytes //! \brief Generate and discard n bytes
//! \param n the number of bytes to discard, rounded up to a <tt>word32</tt> size //! \param n the number of bytes to discard, rounded up to a <tt>word32</tt> size
//! \details If n is not a multiple of <tt>word32</tt>, then unused bytes are //! \details If n is not a multiple of <tt>word32</tt>, then unused bytes are
@ -120,7 +120,7 @@ public:
for(size_t i=0; i < RoundUpToMultipleOf(n, 4U); i++) for(size_t i=0; i < RoundUpToMultipleOf(n, 4U); i++)
NextMersenneWord(); NextMersenneWord();
} }
protected: protected:
//! \brief Returns the next 32-bit word from the state array //! \brief Returns the next 32-bit word from the state array
@ -130,19 +130,19 @@ protected:
word32 NextMersenneWord() word32 NextMersenneWord()
{ {
if (m_idx >= N) { Twist(); } if (m_idx >= N) { Twist(); }
word32 temp = m_state[m_idx++]; word32 temp = m_state[m_idx++];
temp ^= (temp >> 11); temp ^= (temp >> 11);
temp ^= (temp << 7) & 0x9D2C5680; // 0x9D2C5680 (2636928640) temp ^= (temp << 7) & 0x9D2C5680; // 0x9D2C5680 (2636928640)
temp ^= (temp << 15) & 0xEFC60000; // 0xEFC60000 (4022730752) temp ^= (temp << 15) & 0xEFC60000; // 0xEFC60000 (4022730752)
return temp ^ (temp >> 18); return temp ^ (temp >> 18);
} }
//! \brief Performs the twist operaton on the state array //! \brief Performs the twist operaton on the state array
void Twist() void Twist()
{ {
static const unsigned long magic[2]={0x0UL, K}; static const unsigned long magic[2]={0x0UL, K};
word32 kk, temp; word32 kk, temp;
@ -152,19 +152,19 @@ protected:
temp = (m_state[kk] & 0x80000000)|(m_state[kk+1] & 0x7FFFFFFF); temp = (m_state[kk] & 0x80000000)|(m_state[kk+1] & 0x7FFFFFFF);
m_state[kk] = m_state[kk+M] ^ (temp >> 1) ^ magic[temp & 0x1UL]; m_state[kk] = m_state[kk+M] ^ (temp >> 1) ^ magic[temp & 0x1UL];
} }
for (;kk<N-1;kk++) for (;kk<N-1;kk++)
{ {
temp = (m_state[kk] & 0x80000000)|(m_state[kk+1] & 0x7FFFFFFF); temp = (m_state[kk] & 0x80000000)|(m_state[kk+1] & 0x7FFFFFFF);
m_state[kk] = m_state[kk+(M-N)] ^ (temp >> 1) ^ magic[temp & 0x1UL]; m_state[kk] = m_state[kk+(M-N)] ^ (temp >> 1) ^ magic[temp & 0x1UL];
} }
temp = (m_state[N-1] & 0x80000000)|(m_state[0] & 0x7FFFFFFF); temp = (m_state[N-1] & 0x80000000)|(m_state[0] & 0x7FFFFFFF);
m_state[N-1] = m_state[M-1] ^ (temp >> 1) ^ magic[temp & 0x1UL]; m_state[N-1] = m_state[M-1] ^ (temp >> 1) ^ magic[temp & 0x1UL];
// Reset index // Reset index
m_idx = 0; m_idx = 0;
// Wipe temp // Wipe temp
*((volatile word32*)&temp) = 0; *((volatile word32*)&temp) = 0;
} }
@ -179,7 +179,7 @@ private:
unsigned int m_idx; unsigned int m_idx;
}; };
//! \brief Original MT19937 generator provided in the ACM paper. //! \brief Original MT19937 generator provided in the ACM paper.
//! \details Also see http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/mt.pdf; uses 4537 as default initial seed. //! \details Also see http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/mt.pdf; uses 4537 as default initial seed.
typedef MersenneTwister<0x9908B0DF /*2567483615*/, 397, 624, 0x10DCD /*69069*/, 4537> MT19937; typedef MersenneTwister<0x9908B0DF /*2567483615*/, 397, 624, 0x10DCD /*69069*/, 4537> MT19937;
@ -191,4 +191,4 @@ typedef MersenneTwister<0x9908B0DF /*2567483615*/, 397, 624, 0x6C078965 /*181243
NAMESPACE_END NAMESPACE_END
#endif // CRYPTOPP_MERSENNE_TWISTER_H #endif // CRYPTOPP_MERSENNE_TWISTER_H

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)

56
modes.h
View File

@ -16,8 +16,8 @@
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,
//! and the other one has a name that ends in "_ExternalCipher". //! and the other one has a name that ends in "_ExternalCipher".
@ -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:
@ -70,7 +72,7 @@ protected:
if (!(feedbackSize == 0 || feedbackSize == BlockSize())) if (!(feedbackSize == 0 || feedbackSize == BlockSize()))
throw InvalidArgument("CipherModeBase: feedback size cannot be specified for this cipher mode"); throw InvalidArgument("CipherModeBase: feedback size cannot be specified for this cipher mode");
} }
// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 // Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
virtual void ResizeBuffers(); virtual void ResizeBuffers();
@ -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:
@ -178,7 +191,7 @@ public:
protected: protected:
bool RequireAlignedInput() const {return true;} bool RequireAlignedInput() const {return true;}
// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 // Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
void ResizeBuffers(); void ResizeBuffers();
@ -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,13 +258,15 @@ 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:
void ProcessData(byte *outString, const byte *inString, size_t length); void ProcessData(byte *outString, const byte *inString, size_t length);
protected: protected:
// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 // Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
void ResizeBuffers(); void ResizeBuffers();
@ -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

@ -12,7 +12,7 @@
#include "cpu.h" #include "cpu.h"
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
#if CRYPTOPP_MSC_VERSION #if CRYPTOPP_MSC_VERSION
# pragma warning(disable: 4731) # pragma warning(disable: 4731)
#endif #endif
@ -385,22 +385,22 @@ void Panama<B>::Iterate(size_t count, const word32 *p, byte *output, const byte
UL(0); UL(1); UL(2); UL(3); UL(4); UL(5); UL(6); UL(7); UL(0); UL(1); UL(2); UL(3); UL(4); UL(5); UL(6); UL(7);
} }
GP(0); GP(0);
GP(1); GP(1);
GP(2); GP(2);
GP(3); GP(3);
GP(4); GP(4);
GP(5); GP(5);
GP(6); GP(6);
GP(7); GP(7);
GP(8); GP(8);
GP(9); GP(9);
GP(10); GP(10);
GP(11); GP(11);
GP(12); GP(12);
GP(13); GP(13);
GP(14); GP(14);
GP(15); GP(15);
GP(16); GP(16);
T(0,1); T(0,1);
@ -434,7 +434,7 @@ void PanamaHash<B>::TruncatedFinal(byte *hash, size_t size)
this->ThrowIfInvalidTruncatedSize(size); this->ThrowIfInvalidTruncatedSize(size);
this->PadLastBlock(this->BLOCKSIZE, 0x01); this->PadLastBlock(this->BLOCKSIZE, 0x01);
HashEndianCorrectedBlock(this->m_data); HashEndianCorrectedBlock(this->m_data);
this->Iterate(32); // pull this->Iterate(32); // pull

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,12 +60,12 @@ 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);}
void ComputeMessageRepresentative(RandomNumberGenerator &rng, void ComputeMessageRepresentative(RandomNumberGenerator &rng,
const byte *recoverableMessage, size_t recoverableMessageLength, const byte *recoverableMessage, size_t recoverableMessageLength,
HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
byte *representative, size_t representativeBitLength) const; byte *representative, size_t representativeBitLength) const;

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
@ -247,37 +248,37 @@ void Salsa20_Policy::OperateKeystream(KeystreamOperation operation, byte *output
AS2( pxor xmm##b, xmm5) AS2( pxor xmm##b, xmm5)
#define L01(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##A, [SSE2_WORKSPACE + d*16 + i*256]) /* y3 */ #define L01(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##A, [SSE2_WORKSPACE + d*16 + i*256]) /* y3 */
#define L02(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##C, [SSE2_WORKSPACE + a*16 + i*256]) /* y0 */ #define L02(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##C, [SSE2_WORKSPACE + a*16 + i*256]) /* y0 */
#define L03(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##C) /* y0+y3 */ #define L03(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##C) /* y0+y3 */
#define L04(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##B, xmm##A) #define L04(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##B, xmm##A)
#define L05(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 7) #define L05(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 7)
#define L06(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##B, 32-7) #define L06(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##B, 32-7)
#define L07(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, [SSE2_WORKSPACE + b*16 + i*256]) #define L07(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, [SSE2_WORKSPACE + b*16 + i*256])
#define L08(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##B) /* z1 */ #define L08(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##B) /* z1 */
#define L09(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + b*16], xmm##A) #define L09(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + b*16], xmm##A)
#define L10(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##B, xmm##A) #define L10(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##B, xmm##A)
#define L11(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##C) /* z1+y0 */ #define L11(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##C) /* z1+y0 */
#define L12(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##D, xmm##A) #define L12(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##D, xmm##A)
#define L13(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 9) #define L13(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 9)
#define L14(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##D, 32-9) #define L14(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##D, 32-9)
#define L15(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, [SSE2_WORKSPACE + c*16 + i*256]) #define L15(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, [SSE2_WORKSPACE + c*16 + i*256])
#define L16(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##D) /* z2 */ #define L16(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##D) /* z2 */
#define L17(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + c*16], xmm##A) #define L17(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + c*16], xmm##A)
#define L18(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##D, xmm##A) #define L18(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##D, xmm##A)
#define L19(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##B) /* z2+z1 */ #define L19(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##B) /* z2+z1 */
#define L20(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##B, xmm##A) #define L20(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##B, xmm##A)
#define L21(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 13) #define L21(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 13)
#define L22(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##B, 32-13) #define L22(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##B, 32-13)
#define L23(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, [SSE2_WORKSPACE + d*16 + i*256]) #define L23(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, [SSE2_WORKSPACE + d*16 + i*256])
#define L24(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##B) /* z3 */ #define L24(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##B) /* z3 */
#define L25(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + d*16], xmm##A) #define L25(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + d*16], xmm##A)
#define L26(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##D) /* z3+z2 */ #define L26(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##D) /* z3+z2 */
#define L27(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##D, xmm##A) #define L27(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##D, xmm##A)
#define L28(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 18) #define L28(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 18)
#define L29(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##D, 32-18) #define L29(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##D, 32-18)
#define L30(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##C) /* xor y0 */ #define L30(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##C) /* xor y0 */
#define L31(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##D) /* z0 */ #define L31(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##D) /* z0 */
#define L32(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + a*16], xmm##A) #define L32(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + a*16], xmm##A)
#define SSE2_QUARTER_ROUND_X8(i, a, b, c, d, e, f, g, h) \ #define SSE2_QUARTER_ROUND_X8(i, a, b, c, d, e, f, g, h) \
L01(0,1,2,3, a,b,c,d, i) L01(4,5,6,7, e,f,g,h, i) \ L01(0,1,2,3, a,b,c,d, i) L01(4,5,6,7, e,f,g,h, i) \

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

View File

@ -139,7 +139,7 @@ void SEAL_Policy<B>::OperateKeystream(KeystreamOperation operation, byte *output
p = d & 0x7fc; p = d & 0x7fc;
a += Ttab(p); a += Ttab(p);
d = rotrFixed(d, 9U); d = rotrFixed(d, 9U);
// generate 8192 bits // generate 8192 bits
for (unsigned int i=0; i<64; i++) for (unsigned int i=0; i<64; i++)
{ {
@ -197,7 +197,7 @@ void SEAL_Policy<B>::OperateKeystream(KeystreamOperation operation, byte *output
else else
{ {
a += n1; a += n1;
b += n2; b += n2;
c ^= n1; c ^= n1;
d ^= n2; d ^= n2;
} }

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,8 +52,8 @@ 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)
//! \brief Constructs a new U using variadic arguments //! \brief Constructs a new U using variadic arguments
@ -65,7 +65,7 @@ public:
//! is defined. The define is controlled by compiler versions detected in config.h. //! is defined. The define is controlled by compiler versions detected in config.h.
template<typename U, typename... Args> template<typename U, typename... Args>
void construct(U* ptr, Args&&... args) {::new ((void*)ptr) U(std::forward<Args>(args)...);} void construct(U* ptr, Args&&... args) {::new ((void*)ptr) U(std::forward<Args>(args)...);}
//! \brief Destroys an U constructed with variadic arguments //! \brief Destroys an U constructed with variadic arguments
//! \tparam U the type to be forwarded //! \tparam U the type to be forwarded
//! \details This is a C++11 feature. It is available when CRYPTOPP_CXX11_VARIADIC_TEMPLATES //! \details This is a C++11 feature. It is available when CRYPTOPP_CXX11_VARIADIC_TEMPLATES
@ -76,11 +76,11 @@ public:
#endif #endif
protected: protected:
//! \brief Verifies the allocator can satisfy a request based on size //! \brief Verifies the allocator can satisfy a request based on size
//! \param size the size of the allocation, in elements //! \param size the size of the allocation, in elements
//! \throws InvalidArgument //! \throws InvalidArgument
//! \details CheckSize verifies the number of elements requested is valid. //! \details CheckSize verifies the number of elements requested is valid.
//! \details If size is greater than max_size(), then InvalidArgument is thrown. //! \details If size is greater than max_size(), then InvalidArgument is thrown.
//! The library throws InvalidArgument if the size is too large to satisfy. //! The library throws InvalidArgument if the size is too large to satisfy.
//! \details Internally, preprocessor macros are used rather than std::numeric_limits //! \details Internally, preprocessor macros are used rather than std::numeric_limits
@ -126,7 +126,7 @@ typename A::pointer StandardReallocate(A& alloc, T *oldPtr, typename A::size_typ
{ {
typename A::pointer newPointer = alloc.allocate(newSize, NULL); typename A::pointer newPointer = alloc.allocate(newSize, NULL);
const size_t copySize = STDMIN(oldSize, newSize) * sizeof(T); const size_t copySize = STDMIN(oldSize, newSize) * sizeof(T);
if (oldPtr && newPointer) {memcpy_s(newPointer, copySize, oldPtr, copySize);} if (oldPtr && newPointer) {memcpy_s(newPointer, copySize, oldPtr, copySize);}
alloc.deallocate(oldPtr, oldSize); alloc.deallocate(oldPtr, oldSize);
return newPointer; return newPointer;
@ -140,7 +140,7 @@ typename A::pointer StandardReallocate(A& alloc, T *oldPtr, typename A::size_typ
//! \class AllocatorWithCleanup //! \class AllocatorWithCleanup
//! \brief Allocates a block of memory with cleanup //! \brief Allocates a block of memory with cleanup
//! \tparam T class or type //! \tparam T class or type
//! \tparam T_Align16 boolean that determines whether allocations should be aligned on 16-byte boundaries //! \tparam T_Align16 boolean that determines whether allocations should be aligned on 16-byte boundaries
//! \details If T_Align16 is true, then AllocatorWithCleanup calls AlignedAllocate() //! \details If T_Align16 is true, then AllocatorWithCleanup calls AlignedAllocate()
//! for memory allocations. If T_Align16 is false, then AllocatorWithCleanup() calls //! for memory allocations. If T_Align16 is false, then AllocatorWithCleanup() calls
@ -162,10 +162,10 @@ public:
//! and less than max_size(), then an attempt is made to fulfill the request using either //! and less than max_size(), then an attempt is made to fulfill the request using either
//! AlignedAllocate() or UnalignedAllocate(). //! AlignedAllocate() or UnalignedAllocate().
//! \details AlignedAllocate() is used if T_Align16 is true. //! \details AlignedAllocate() is used if T_Align16 is true.
//! UnalignedAllocate() used if T_Align16 is false. //! UnalignedAllocate() used if T_Align16 is false.
//! \details This is the C++ *Placement New* operator. ptr is not used, and the function //! \details This is the C++ *Placement New* operator. ptr is not used, and the function
//! asserts in Debug builds if ptr is non-NULL. //! asserts in Debug builds if ptr is non-NULL.
//! \sa CallNewHandler() for the methods used to recover from a failed //! \sa CallNewHandler() for the methods used to recover from a failed
//! allocation attempt. //! allocation attempt.
//! \note size is the count of elements, and not the number of bytes //! \note size is the count of elements, and not the number of bytes
pointer allocate(size_type size, const void *ptr = NULL) pointer allocate(size_type size, const void *ptr = NULL)
@ -188,10 +188,10 @@ public:
//! \param ptr the pointer for the allocation //! \param ptr the pointer for the allocation
//! \param size the size of the allocation, in elements //! \param size the size of the allocation, in elements
//! \details Internally, SecureWipeArray() is called before deallocating the memory. //! \details Internally, SecureWipeArray() is called before deallocating the memory.
//! Once the memory block is wiped or zeroized, AlignedDeallocate() or //! Once the memory block is wiped or zeroized, AlignedDeallocate() or
//! UnalignedDeallocate() is called. //! UnalignedDeallocate() is called.
//! \details AlignedDeallocate() is used if T_Align16 is true. //! \details AlignedDeallocate() is used if T_Align16 is true.
//! UnalignedDeallocate() used if T_Align16 is false. //! UnalignedDeallocate() used if T_Align16 is false.
void deallocate(void *ptr, size_type size) void deallocate(void *ptr, size_type size)
{ {
assert((ptr && size) || !(ptr || size)); assert((ptr && size) || !(ptr || size));
@ -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:
@ -446,7 +446,7 @@ public:
//! \note size is the count of elements, and not the number of bytes //! \note size is the count of elements, and not the number of bytes
explicit SecBlock(size_type size=0) explicit SecBlock(size_type size=0)
: m_size(size), m_ptr(m_alloc.allocate(size, NULL)) { } : m_size(size), m_ptr(m_alloc.allocate(size, NULL)) { }
//! \brief Copy construct a SecBlock from another SecBlock //! \brief Copy construct a SecBlock from another SecBlock
//! \param t the other SecBlock //! \param t the other SecBlock
//! \throws std::bad_alloc //! \throws std::bad_alloc
@ -460,7 +460,7 @@ public:
//! \param ptr a pointer to an array of T //! \param ptr a pointer to an array of T
//! \param len the number of elements in the memory block //! \param len the number of elements in the memory block
//! \throws std::bad_alloc //! \throws std::bad_alloc
//! \details If <tt>ptr!=NULL</tt> and <tt>len!=0</tt>, then the block is initialized from the pointer ptr. //! \details If <tt>ptr!=NULL</tt> and <tt>len!=0</tt>, then the block is initialized from the pointer ptr.
//! If <tt>ptr==NULL</tt> and <tt>len!=0</tt>, then the block is initialized to 0. //! If <tt>ptr==NULL</tt> and <tt>len!=0</tt>, then the block is initialized to 0.
//! Otherwise, the block is empty and \a not initialized. //! Otherwise, the block is empty and \a not initialized.
//! \note size is the count of elements, and not the number of bytes //! \note size is the count of elements, and not the number of bytes
@ -802,7 +802,7 @@ __stl_alloc_rebind(CryptoPP::AllocatorWithCleanup<_Tp1>& __a, const _Tp2*)
#endif #endif
NAMESPACE_END NAMESPACE_END
#if CRYPTOPP_MSC_VERSION #if CRYPTOPP_MSC_VERSION
# pragma warning(pop) # pragma warning(pop)
#endif #endif

View File

@ -66,18 +66,28 @@ public:
CRYPTOPP_CONSTANT(MIN_ROUNDS = N) CRYPTOPP_CONSTANT(MIN_ROUNDS = N)
//! \brief The maximum number of rounds for the algorithm provided as a constant. //! \brief The maximum number of rounds for the algorithm provided as a constant.
CRYPTOPP_CONSTANT(MAX_ROUNDS = M) CRYPTOPP_CONSTANT(MAX_ROUNDS = M)
//! \brief The default number of rounds for the algorithm based on key length //! \brief The default number of rounds for the algorithm based on key length
//! 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
{ {
@ -264,12 +287,12 @@ public:
//! \returns maximum key length used by the algorithm, in bytes //! \returns maximum key length used by the algorithm, in bytes
size_t MaxKeyLength() const size_t MaxKeyLength() const
{return (size_t)INFO::MAX_KEYLENGTH;} {return (size_t)INFO::MAX_KEYLENGTH;}
//! \brief The default key length used by the algorithm //! \brief The default key length used by the algorithm
//! \returns default key length used by the algorithm, in bytes //! \returns default key length used by the algorithm, in bytes
size_t DefaultKeyLength() const size_t DefaultKeyLength() const
{return INFO::DEFAULT_KEYLENGTH;} {return INFO::DEFAULT_KEYLENGTH;}
//! \brief Provides a valid key length for the algorithm //! \brief Provides a valid key length for the algorithm
//! \param keylength the size of the key, in bytes //! \param keylength the size of the key, in bytes
//! \returns the valid key lenght, in bytes //! \returns the valid key lenght, in bytes
@ -285,7 +308,7 @@ public:
//! in cryptlib.h for allowed values. //! in cryptlib.h for allowed values.
SimpleKeyingInterface::IV_Requirement IVRequirement() const SimpleKeyingInterface::IV_Requirement IVRequirement() const
{return (SimpleKeyingInterface::IV_Requirement)INFO::IV_REQUIREMENT;} {return (SimpleKeyingInterface::IV_Requirement)INFO::IV_REQUIREMENT;}
//! \brief The default initialization vector length for the algorithm //! \brief The default initialization vector length for the algorithm
//! \details IVSize is provided in bytes, not bits. The default implementation uses IV_LENGTH, which is 0. //! \details IVSize is provided in bytes, not bits. The default implementation uses IV_LENGTH, which is 0.
unsigned int IVSize() const unsigned int IVSize() const
@ -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> > >
{ {
@ -323,7 +349,7 @@ public:
//! SimpleKeyingInterface::SetKey. //! SimpleKeyingInterface::SetKey.
BlockCipherFinal(const byte *key) BlockCipherFinal(const byte *key)
{this->SetKey(key, this->DEFAULT_KEYLENGTH);} {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
//! \brief Construct a BlockCipherFinal //! \brief Construct a BlockCipherFinal
//! \param key a byte array used to key the cipher //! \param key a byte array used to key the cipher
//! \param length the length of the byte array //! \param length the length of the byte array
@ -331,7 +357,7 @@ public:
//! SimpleKeyingInterface::SetKey. //! SimpleKeyingInterface::SetKey.
BlockCipherFinal(const byte *key, size_t length) BlockCipherFinal(const byte *key, size_t length)
{this->SetKey(key, length);} {this->SetKey(key, length);}
//! \brief Construct a BlockCipherFinal //! \brief Construct a BlockCipherFinal
//! \param key a byte array used to key the cipher //! \param key a byte array used to key the cipher
//! \param length the length of the byte array //! \param length the length of the byte array
@ -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>
{ {
@ -388,7 +418,7 @@ public:
//! \brief Provides Encryption and Decryption typedefs used by derived classes to //! \brief Provides Encryption and Decryption typedefs used by derived classes to
//! implement a block cipher //! implement a block cipher
//! \details These objects usually should not be used directly. See CipherModeDocumentation //! \details These objects usually should not be used directly. See CipherModeDocumentation
//! instead. Each class derived from this one defines two types, Encryption and Decryption, //! instead. Each class derived from this one defines two types, Encryption and Decryption,
//! both of which implement the BlockCipher interface. //! both of which implement the BlockCipher interface.
struct BlockCipherDocumentation struct BlockCipherDocumentation
{ {
@ -401,7 +431,7 @@ struct BlockCipherDocumentation
//! \class SymmetricCipherDocumentation //! \class SymmetricCipherDocumentation
//! \brief Provides Encryption and Decryption typedefs used by derived classes to //! \brief Provides Encryption and Decryption typedefs used by derived classes to
//! implement a symmetric cipher //! implement a symmetric cipher
//! \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. Two types of classes derive //! both of which implement the SymmetricCipher interface. Two types of classes derive
//! from this class: stream ciphers and block cipher modes. Stream ciphers can be used //! from this class: stream ciphers and block cipher modes. Stream ciphers can be used
//! alone, cipher mode classes need to be used with a block cipher. See CipherModeDocumentation //! alone, cipher mode classes need to be used with a block cipher. See CipherModeDocumentation
@ -417,7 +447,7 @@ struct SymmetricCipherDocumentation
//! \class AuthenticatedSymmetricCipherDocumentation //! \class AuthenticatedSymmetricCipherDocumentation
//! \brief Provides Encryption and Decryption typedefs used by derived classes to //! \brief Provides Encryption and Decryption typedefs used by derived classes to
//! implement an authenticated encryption cipher //! implement an authenticated encryption cipher
//! \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 AuthenticatedSymmetricCipher interface. //! both of which implement the AuthenticatedSymmetricCipher interface.
struct AuthenticatedSymmetricCipherDocumentation struct AuthenticatedSymmetricCipherDocumentation
{ {
@ -428,7 +458,7 @@ struct AuthenticatedSymmetricCipherDocumentation
}; };
NAMESPACE_END NAMESPACE_END
#if CRYPTOPP_MSC_VERSION #if CRYPTOPP_MSC_VERSION
# pragma warning(pop) # pragma warning(pop)
#endif #endif

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

@ -52,7 +52,7 @@ typedef BlockGetAndPut<word32, LittleEndian> Block;
void Serpent::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const void Serpent::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{ {
word32 a, b, c, d, e; word32 a, b, c, d, e;
Block::Get(inBlock)(a)(b)(c)(d); Block::Get(inBlock)(a)(b)(c)(d);
const word32 *k = m_key; const word32 *k = m_key;
@ -84,14 +84,14 @@ void Serpent::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
while (true); while (true);
afterS7(KX); afterS7(KX);
Block::Put(xorBlock, outBlock)(d)(e)(b)(a); Block::Put(xorBlock, outBlock)(d)(e)(b)(a);
} }
void Serpent::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const void Serpent::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{ {
word32 a, b, c, d, e; word32 a, b, c, d, e;
Block::Get(inBlock)(a)(b)(c)(d); Block::Get(inBlock)(a)(b)(c)(d);
const word32 *k = m_key + 96; const word32 *k = m_key + 96;
@ -108,17 +108,17 @@ void Serpent::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
k -= 32; k -= 32;
beforeI7(ILT); beforeI7(ILT);
start: start:
beforeI7(I7); afterI7(KX); beforeI7(I7); afterI7(KX);
afterI7(ILT); afterI7(I6); afterI6(KX); afterI7(ILT); afterI7(I6); afterI6(KX);
afterI6(ILT); afterI6(I5); afterI5(KX); afterI6(ILT); afterI6(I5); afterI5(KX);
afterI5(ILT); afterI5(I4); afterI4(KX); afterI5(ILT); afterI5(I4); afterI4(KX);
afterI4(ILT); afterI4(I3); afterI3(KX); afterI4(ILT); afterI4(I3); afterI3(KX);
afterI3(ILT); afterI3(I2); afterI2(KX); afterI3(ILT); afterI3(I2); afterI2(KX);
afterI2(ILT); afterI2(I1); afterI1(KX); afterI2(ILT); afterI2(I1); afterI1(KX);
afterI1(ILT); afterI1(I0); afterI0(KX); afterI1(ILT); afterI1(I0); afterI0(KX);
} }
while (--i != 0); while (--i != 0);
Block::Put(xorBlock, outBlock)(a)(d)(b)(e); Block::Put(xorBlock, outBlock)(a)(d)(b)(e);
} }

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

View File

@ -15,20 +15,20 @@ NAMESPACE_BEGIN(CryptoPP)
static word64 SHARKTransform(word64 a) static word64 SHARKTransform(word64 a)
{ {
static const byte iG[8][8] = { static const byte iG[8][8] = {
0xe7, 0x30, 0x90, 0x85, 0xd0, 0x4b, 0x91, 0x41, 0xe7, 0x30, 0x90, 0x85, 0xd0, 0x4b, 0x91, 0x41,
0x53, 0x95, 0x9b, 0xa5, 0x96, 0xbc, 0xa1, 0x68, 0x53, 0x95, 0x9b, 0xa5, 0x96, 0xbc, 0xa1, 0x68,
0x02, 0x45, 0xf7, 0x65, 0x5c, 0x1f, 0xb6, 0x52, 0x02, 0x45, 0xf7, 0x65, 0x5c, 0x1f, 0xb6, 0x52,
0xa2, 0xca, 0x22, 0x94, 0x44, 0x63, 0x2a, 0xa2, 0xa2, 0xca, 0x22, 0x94, 0x44, 0x63, 0x2a, 0xa2,
0xfc, 0x67, 0x8e, 0x10, 0x29, 0x75, 0x85, 0x71, 0xfc, 0x67, 0x8e, 0x10, 0x29, 0x75, 0x85, 0x71,
0x24, 0x45, 0xa2, 0xcf, 0x2f, 0x22, 0xc1, 0x0e, 0x24, 0x45, 0xa2, 0xcf, 0x2f, 0x22, 0xc1, 0x0e,
0xa1, 0xf1, 0x71, 0x40, 0x91, 0x27, 0x18, 0xa5, 0xa1, 0xf1, 0x71, 0x40, 0x91, 0x27, 0x18, 0xa5,
0x56, 0xf4, 0xaf, 0x32, 0xd2, 0xa4, 0xdc, 0x71, 0x56, 0xf4, 0xaf, 0x32, 0xd2, 0xa4, 0xdc, 0x71,
}; };
word64 result=0; word64 result=0;
GF256 gf256(0xf5); GF256 gf256(0xf5);
for (unsigned int i=0; i<8; i++) for (unsigned int i=0; i<8; i++)
for(unsigned int j=0; j<8; j++) for(unsigned int j=0; j<8; j++)
result ^= word64(gf256.Multiply(iG[i][j], GF256::Element(a>>(56-8*j)))) << (56-8*i); result ^= word64(gf256.Multiply(iG[i][j], GF256::Element(a>>(56-8*j)))) << (56-8*i);
return result; return result;
} }
@ -100,17 +100,17 @@ inline SharkProcessAndXorBlock(const word64 *roundKeys, unsigned int rounds, con
word64 tmp = *(word64 *)(void *)inBlock ^ roundKeys[0]; word64 tmp = *(word64 *)(void *)inBlock ^ roundKeys[0];
ByteOrder order = GetNativeByteOrder(); ByteOrder order = GetNativeByteOrder();
tmp = cbox[0][GetByte(order, tmp, 0)] ^ cbox[1][GetByte(order, tmp, 1)] tmp = cbox[0][GetByte(order, tmp, 0)] ^ cbox[1][GetByte(order, tmp, 1)]
^ cbox[2][GetByte(order, tmp, 2)] ^ cbox[3][GetByte(order, tmp, 3)] ^ cbox[2][GetByte(order, tmp, 2)] ^ cbox[3][GetByte(order, tmp, 3)]
^ cbox[4][GetByte(order, tmp, 4)] ^ cbox[5][GetByte(order, tmp, 5)] ^ cbox[4][GetByte(order, tmp, 4)] ^ cbox[5][GetByte(order, tmp, 5)]
^ cbox[6][GetByte(order, tmp, 6)] ^ cbox[7][GetByte(order, tmp, 7)] ^ cbox[6][GetByte(order, tmp, 6)] ^ cbox[7][GetByte(order, tmp, 7)]
^ roundKeys[1]; ^ roundKeys[1];
for(unsigned int i=2; i<rounds; i++) for(unsigned int i=2; i<rounds; i++)
{ {
tmp = cbox[0][GETBYTE(tmp, 7)] ^ cbox[1][GETBYTE(tmp, 6)] tmp = cbox[0][GETBYTE(tmp, 7)] ^ cbox[1][GETBYTE(tmp, 6)]
^ cbox[2][GETBYTE(tmp, 5)] ^ cbox[3][GETBYTE(tmp, 4)] ^ cbox[2][GETBYTE(tmp, 5)] ^ cbox[3][GETBYTE(tmp, 4)]
^ cbox[4][GETBYTE(tmp, 3)] ^ cbox[5][GETBYTE(tmp, 2)] ^ cbox[4][GETBYTE(tmp, 3)] ^ cbox[5][GETBYTE(tmp, 2)]
^ cbox[6][GETBYTE(tmp, 1)] ^ cbox[7][GETBYTE(tmp, 0)] ^ cbox[6][GETBYTE(tmp, 1)] ^ cbox[7][GETBYTE(tmp, 0)]
^ roundKeys[i]; ^ roundKeys[i];
} }

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

@ -7,7 +7,7 @@
#include "skipjack.h" #include "skipjack.h"
/* /*
* Optimized implementation of SKIPJACK algorithm * Optimized implementation of SKIPJACK algorithm
* *
* originally written by Panu Rissanen <bande@lut.fi> 1998.06.24 * originally written by Panu Rissanen <bande@lut.fi> 1998.06.24
@ -20,7 +20,7 @@ NAMESPACE_BEGIN(CryptoPP)
/** /**
* The F-table byte permutation (see description of the G-box permutation) * The F-table byte permutation (see description of the G-box permutation)
*/ */
const byte SKIPJACK::Base::fTable[256] = { const byte SKIPJACK::Base::fTable[256] = {
0xa3,0xd7,0x09,0x83,0xf8,0x48,0xf6,0xf4,0xb3,0x21,0x15,0x78,0x99,0xb1,0xaf,0xf9, 0xa3,0xd7,0x09,0x83,0xf8,0x48,0xf6,0xf4,0xb3,0x21,0x15,0x78,0x99,0xb1,0xaf,0xf9,
0xe7,0x2d,0x4d,0x8a,0xce,0x4c,0xca,0x2e,0x52,0x95,0xd9,0x1e,0x4e,0x38,0x44,0x28, 0xe7,0x2d,0x4d,0x8a,0xce,0x4c,0xca,0x2e,0x52,0x95,0xd9,0x1e,0x4e,0x38,0x44,0x28,
0x0a,0xdf,0x02,0xa0,0x17,0xf1,0x60,0x68,0x12,0xb7,0x7a,0xc3,0xe9,0xfa,0x3d,0x53, 0x0a,0xdf,0x02,0xa0,0x17,0xf1,0x60,0x68,0x12,0xb7,0x7a,0xc3,0xe9,0xfa,0x3d,0x53,

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

@ -21,11 +21,11 @@ NAMESPACE_BEGIN(CryptoPP)
// apply theta to a roundkey // apply theta to a roundkey
static void SquareTransform (word32 in[4], word32 out[4]) static void SquareTransform (word32 in[4], word32 out[4])
{ {
static const byte G[4][4] = static const byte G[4][4] =
{ {
0x02U, 0x01U, 0x01U, 0x03U, 0x02U, 0x01U, 0x01U, 0x03U,
0x03U, 0x02U, 0x01U, 0x01U, 0x03U, 0x02U, 0x01U, 0x01U,
0x01U, 0x03U, 0x02U, 0x01U, 0x01U, 0x03U, 0x02U, 0x01U,
0x01U, 0x01U, 0x03U, 0x02U 0x01U, 0x01U, 0x03U, 0x02U
}; };
@ -62,7 +62,7 @@ void Square::Base::UncheckedSetKey(const byte *userKey, unsigned int length, con
roundkeys(i, 1) = roundkeys(i-1, 1) ^ roundkeys(i, 0); roundkeys(i, 1) = roundkeys(i-1, 1) ^ roundkeys(i, 0);
roundkeys(i, 2) = roundkeys(i-1, 2) ^ roundkeys(i, 1); roundkeys(i, 2) = roundkeys(i-1, 2) ^ roundkeys(i, 1);
roundkeys(i, 3) = roundkeys(i-1, 3) ^ roundkeys(i, 2); roundkeys(i, 3) = roundkeys(i-1, 3) ^ roundkeys(i, 2);
} }
/* produce the round keys */ /* produce the round keys */
if (IsForwardTransformation()) if (IsForwardTransformation())
@ -138,13 +138,13 @@ void Square::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
{ {
word32 text[4], temp[4]; word32 text[4], temp[4];
Block::Get(inBlock)(text[0])(text[1])(text[2])(text[3]); Block::Get(inBlock)(text[0])(text[1])(text[2])(text[3]);
/* initial key addition */ /* initial key addition */
text[0] ^= roundkeys(0, 0); text[0] ^= roundkeys(0, 0);
text[1] ^= roundkeys(0, 1); text[1] ^= roundkeys(0, 1);
text[2] ^= roundkeys(0, 2); text[2] ^= roundkeys(0, 2);
text[3] ^= roundkeys(0, 3); text[3] ^= roundkeys(0, 3);
/* ROUNDS - 1 full rounds */ /* ROUNDS - 1 full rounds */
for (int i=1; i+1<ROUNDS; i+=2) for (int i=1; i+1<ROUNDS; i+=2)
{ {
@ -163,13 +163,13 @@ void Square::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
{ {
word32 text[4], temp[4]; word32 text[4], temp[4];
Block::Get(inBlock)(text[0])(text[1])(text[2])(text[3]); Block::Get(inBlock)(text[0])(text[1])(text[2])(text[3]);
/* initial key addition */ /* initial key addition */
text[0] ^= roundkeys(0, 0); text[0] ^= roundkeys(0, 0);
text[1] ^= roundkeys(0, 1); text[1] ^= roundkeys(0, 1);
text[2] ^= roundkeys(0, 2); text[2] ^= roundkeys(0, 2);
text[3] ^= roundkeys(0, 3); text[3] ^= roundkeys(0, 3);
/* ROUNDS - 1 full rounds */ /* ROUNDS - 1 full rounds */
for (int i=1; i+1<ROUNDS; i+=2) for (int i=1; i+1<ROUNDS; i+=2)
{ {

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

12
tea.cpp
View File

@ -24,7 +24,7 @@ void TEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt
word32 sum = 0; word32 sum = 0;
while (sum != m_limit) while (sum != m_limit)
{ {
sum += DELTA; sum += DELTA;
y += ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]); y += ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
z += ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]); z += ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]);
@ -41,7 +41,7 @@ void TEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt
word32 sum = m_limit; word32 sum = m_limit;
while (sum != 0) while (sum != 0)
{ {
z -= ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]); z -= ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]);
y -= ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]); y -= ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
sum -= DELTA; sum -= DELTA;
} }
@ -70,7 +70,7 @@ void XTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by
word32 sum = 0; word32 sum = 0;
while (sum != m_limit) while (sum != m_limit)
#endif #endif
{ {
y += ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]); y += ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]);
sum += DELTA; sum += DELTA;
z += ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]); z += ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]);
@ -116,9 +116,9 @@ void BTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by
word32 y = v[0], z = v[n-1], e; word32 y = v[0], z = v[n-1], e;
word32 p, q = 6+52/n; word32 p, q = 6+52/n;
word32 sum = 0; word32 sum = 0;
while (q-- > 0) while (q-- > 0)
{ {
sum += DELTA; sum += DELTA;
e = sum>>2 & 3; e = sum>>2 & 3;
for (p = 0; p < n-1; p++) for (p = 0; p < n-1; p++)
@ -148,7 +148,7 @@ void BTEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by
word32 sum = q * DELTA; word32 sum = q * DELTA;
while (sum != 0) while (sum != 0)
{ {
e = sum>>2 & 3; e = sum>>2 & 3;
for (p = n-1; p > 0; p--) for (p = n-1; p > 0; p--)
{ {

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()

View File

@ -24,7 +24,7 @@ inline word32 WAKE_Base::M(word32 x, word32 y)
void WAKE_Base::GenKey(word32 k0, word32 k1, word32 k2, word32 k3) void WAKE_Base::GenKey(word32 k0, word32 k1, word32 k2, word32 k3)
{ {
// this code is mostly copied from David Wheeler's paper "A Bulk Data Encryption Algorithm" // this code is mostly copied from David Wheeler's paper "A Bulk Data Encryption Algorithm"
signed int x, z, p; signed int x, z, p;
// x and z were declared as "long" in Wheeler's paper, which is a signed type. I don't know if that was intentional, but it's too late to change it now. -- Wei 7/4/2010 // x and z were declared as "long" in Wheeler's paper, which is a signed type. I don't know if that was intentional, but it's too late to change it now. -- Wei 7/4/2010
CRYPTOPP_COMPILE_ASSERT(sizeof(x) == 4); CRYPTOPP_COMPILE_ASSERT(sizeof(x) == 4);
static unsigned int tt[10]= { static unsigned int tt[10]= {

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