From 45323bddd83982a183714d91167194f73bab1440 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Tue, 6 Sep 2016 02:51:16 -0400 Subject: [PATCH] Initial fix for older Apple ld's non_lazy_ptr missing symbols (Issue 255) --- 3way.cpp | 9 +++++-- des.cpp | 14 ++++++++--- des.h | 10 +++++++- gost.cpp | 7 ++++-- gost.h | 6 +++++ idea.cpp | 23 ++++++++++-------- mdc.h | 18 +++++++++----- panama.cpp | 37 +++++++++++++++------------- panama.h | 24 ++++++++++++------ salsa.cpp | 69 ++++++++++++++++++++++++++++------------------------ salsa.h | 10 +++++--- seal.cpp | 7 ++++-- seal.h | 12 +++++++-- seed.cpp | 3 +++ shark.cpp | 3 +++ shark.h | 6 +++++ skipjack.cpp | 7 ++++-- skipjack.h | 6 +++++ square.cpp | 21 +++++++++------- tea.cpp | 15 +++++++----- tea.h | 18 ++++++++++++++ ttmac.cpp | 3 +++ ttmac.h | 13 +++++++--- wake.cpp | 5 +++- wake.h | 11 +++++++-- 25 files changed, 245 insertions(+), 112 deletions(-) diff --git a/3way.cpp b/3way.cpp index ad57edf5..c6784ee8 100644 --- a/3way.cpp +++ b/3way.cpp @@ -15,6 +15,11 @@ void ThreeWay_TestInstantiations() } #endif +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused1 = ThreeWay::KEYLENGTH; +static const size_t s_unused2 = ThreeWayEncryption::KEYLENGTH; +static const size_t s_unused3 = ThreeWayDecryption::KEYLENGTH; + static const word32 START_E = 0x0b0b; // round constant of first encryption round static const word32 START_D = 0xb1b1; // round constant of first decryption round #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 @@ -57,13 +62,13 @@ static inline word32 reverseBits(word32 a) a0 ^= c ^ b0; \ a1 ^= c ^ b1; \ a2 ^= c ^ (b0 >> 16) ^ (b1 << 16); \ -} +} #define rho(a0, a1, a2) \ { \ theta(a0, a1, a2); \ pi_gamma_pi(a0, a1, a2); \ -} +} void ThreeWay::Base::UncheckedSetKey(const byte *uk, unsigned int length, const NameValuePairs ¶ms) { diff --git a/des.cpp b/des.cpp index 7e6e45fa..c468403c 100644 --- a/des.cpp +++ b/des.cpp @@ -20,6 +20,12 @@ NAMESPACE_BEGIN(CryptoPP) +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused1 = DES::KEYLENGTH; +static const size_t s_unused2 = DES_EDE2::KEYLENGTH; +static const size_t s_unused3 = DES_EDE3::KEYLENGTH; +static const size_t s_unused4 = DES_XEX3::KEYLENGTH; + typedef BlockGetAndPut Block; // Richard Outerbridge's initial permutation algorithm @@ -70,8 +76,8 @@ inline void FPERM(word32 &left, word32 &right) } */ -// Wei Dai's modification to Richard Outerbridge's initial permutation -// algorithm, this one is faster if you have access to rotate instructions +// Wei Dai's modification to Richard Outerbridge's initial permutation +// algorithm, this one is faster if you have access to rotate instructions // (like in MSVC) static inline void IPERM(word32 &left, word32 &right) { @@ -283,7 +289,7 @@ void RawDES::RawSetKey(CipherDir dir, const byte *key) byte *const ks=pcr+56; register int i,j,l; int m; - + for (j=0; j<56; j++) { /* convert pc1 to bits of key */ l=pc1[j]-1; /* integer bit location */ m = l & 07; /* find bit */ @@ -314,7 +320,7 @@ void RawDES::RawSetKey(CipherDir dir, const byte *key) | ((word32)ks[5] << 8) | ((word32)ks[7]); } - + if (dir==DECRYPTION) // reverse key schedule order for (i=0; i<16; i+=2) { diff --git a/des.h b/des.h index 429d2e49..5ada3513 100644 --- a/des.h +++ b/des.h @@ -35,12 +35,14 @@ struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8> //! \class DES //! \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() //! and CorrectKeyParityBits() to check or correct the parity bits if you wish. //! \sa DES class DES : public DES_Info, public BlockCipherDocumentation { + //! \class Base + //! \brief DES block cipher default operation class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl, public RawDES { public: @@ -70,6 +72,8 @@ struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16> /// \sa DES-EDE2 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 { public: @@ -97,6 +101,8 @@ struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24> //! \sa DES-EDE3 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 { public: @@ -124,6 +130,8 @@ struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24> //! \sa DES-XEX3, AKA DESX 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 { public: diff --git a/gost.cpp b/gost.cpp index f502f8a1..f60cf031 100644 --- a/gost.cpp +++ b/gost.cpp @@ -4,6 +4,9 @@ NAMESPACE_BEGIN(CryptoPP) +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused = GOST::KEYLENGTH; + // these are the S-boxes given in Applied Cryptography 2nd Ed., p. 333 const byte GOST::Base::sBox[8][16]={ {4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3}, @@ -24,7 +27,7 @@ const byte GOST::Base::sBox[8][16]={ { 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 }, {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; @@ -44,7 +47,7 @@ void GOST::Base::PrecalculateSTable() if (!sTableCalculated) { 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); sTable[i][j] = rotlMod(temp, 11+8*i); diff --git a/gost.h b/gost.h index 12dbb344..116e3710 100644 --- a/gost.h +++ b/gost.h @@ -23,6 +23,8 @@ struct GOST_Info : public FixedBlockSize<8>, public FixedKeyLength<32> //! \sa GOST class GOST : public GOST_Info, public BlockCipherDocumentation { + //! \class Base + //! \brief GOST block cipher default operation class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl { public: @@ -38,12 +40,16 @@ class GOST : public GOST_Info, public BlockCipherDocumentation FixedSizeSecBlock key; }; + //! \class Enc + //! \brief GOST block cipher encryption operation class CRYPTOPP_NO_VTABLE Enc : public Base { public: 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 { public: diff --git a/idea.cpp b/idea.cpp index fe961743..96f946af 100644 --- a/idea.cpp +++ b/idea.cpp @@ -7,6 +7,9 @@ NAMESPACE_BEGIN(CryptoPP) +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused = IDEA::KEYLENGTH; + static const int IDEA_KEYLEN=(6*IDEA::ROUNDS+4); // key schedule length in # of word16s #define low16(x) ((x)&0xffff) // compiler should be able to optimize this away if word is 16 bits @@ -42,16 +45,16 @@ void IDEA::Base::BuildLogTables() else { tablesBuilt = true; - + IDEA::Word x=1; word32 i; - + for (i=0; i<0x10000; i++) { antilog[i] = (word16)x; DirectMUL(x, 3); } - + for (i=0; i<0x10000; i++) log[antilog[i]] = (word16)i; } @@ -82,16 +85,16 @@ inline void IDEA::Base::LookupMUL(IDEA::Word &a, IDEA::Word b) void IDEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &) { AssertValidKeyLength(length); - + #ifdef IDEA_LARGECACHE BuildLogTables(); #endif - + EnKey(userKey); - + if (!IsForwardTransformation()) DeKey(); - + #ifdef IDEA_LARGECACHE LookupKeyLogs(); #endif @@ -100,10 +103,10 @@ void IDEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const void IDEA::Base::EnKey (const byte *userKey) { unsigned int i; - + for (i=0; i<8; i++) m_key[i] = ((IDEA::Word)userKey[2*i]<<8) | userKey[2*i+1]; - + for (; i struct MDC_Info : public FixedBlockSize, public FixedKeyLength { static std::string StaticAlgorithmName() {return std::string("MDC/")+T::StaticAlgorithmName();} }; -//! MDC -/*! 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 MDC template class MDC : public MDC_Info { + //! \class Enc + //! \brief MDC cipher encryption operation class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl > { typedef typename T::HashWordType HashWordType; diff --git a/panama.cpp b/panama.cpp index 1631e02c..2c76c934 100644 --- a/panama.cpp +++ b/panama.cpp @@ -12,11 +12,14 @@ #include "cpu.h" NAMESPACE_BEGIN(CryptoPP) - + #if CRYPTOPP_MSC_VERSION # pragma warning(disable: 4731) #endif +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused = PanamaCipher<>::KEYLENGTH; + template void Panama::Reset() { @@ -385,22 +388,22 @@ void Panama::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); } - GP(0); - GP(1); - GP(2); - GP(3); - GP(4); - GP(5); - GP(6); + GP(0); + GP(1); + GP(2); + GP(3); + GP(4); + GP(5); + GP(6); GP(7); - GP(8); - GP(9); - GP(10); - GP(11); - GP(12); - GP(13); - GP(14); - GP(15); + GP(8); + GP(9); + GP(10); + GP(11); + GP(12); + GP(13); + GP(14); + GP(15); GP(16); T(0,1); @@ -434,7 +437,7 @@ void PanamaHash::TruncatedFinal(byte *hash, size_t size) this->ThrowIfInvalidTruncatedSize(size); this->PadLastBlock(this->BLOCKSIZE, 0x01); - + HashEndianCorrectedBlock(this->m_data); this->Iterate(32); // pull diff --git a/panama.h b/panama.h index 18e60338..b1a41e61 100644 --- a/panama.h +++ b/panama.h @@ -1,7 +1,7 @@ // panama.h - written and placed in the public domain by Wei Dai //! \file panama.h -//! \brief Classes for Panama stream cipher +//! \brief Classes for Panama hash and stream cipher #ifndef CRYPTOPP_PANAMA_H #define CRYPTOPP_PANAMA_H @@ -17,7 +17,7 @@ NAMESPACE_BEGIN(CryptoPP) -/// base class, do not use directly +// Base class, do not use directly template class CRYPTOPP_NO_VTABLE Panama { @@ -33,7 +33,9 @@ protected: }; namespace Weak { -/// Panama Hash +//! \class PanamaHash +//! \brief Panama hash +//! \sa Panama Hash template class PanamaHash : protected Panama, public AlgorithmImpl, PanamaHash > { @@ -52,7 +54,8 @@ protected: }; } -//! MAC construction using a hermetic hash function +//! \class HermeticHashFunctionMAC +//! \brief MAC construction using a hermetic hash function template class HermeticHashFunctionMAC : public AlgorithmImpl > >, T_Info> { @@ -108,7 +111,8 @@ protected: }; namespace Weak { -/// Panama MAC +//! \class PanamaMAC +//! \brief Panama message authentication code template class PanamaMAC : public HermeticHashFunctionMAC > { @@ -119,14 +123,16 @@ public: }; } -//! algorithm info +//! \class PanamaCipherInfo +//! \brief Panama stream cipher information template struct PanamaCipherInfo : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 32> { static const char * StaticAlgorithmName() {return B::ToEnum() == BIG_ENDIAN_ORDER ? "Panama-BE" : "Panama-LE";} }; -//! _ +//! \class PanamaCipherPolicy +//! \brief Panama stream cipher operation template class PanamaCipherPolicy : public AdditiveCipherConcretePolicy, public PanamaCipherInfo, @@ -142,7 +148,9 @@ protected: FixedSizeSecBlock m_key; }; -//! Panama Stream Cipher +//! \class PanamaCipher +//! \brief Panama stream cipher +//! \sa Panama Stream Cipher template struct PanamaCipher : public PanamaCipherInfo, public SymmetricCipherDocumentation { diff --git a/salsa.cpp b/salsa.cpp index d13e4e4d..603ae521 100644 --- a/salsa.cpp +++ b/salsa.cpp @@ -35,10 +35,15 @@ NAMESPACE_BEGIN(CryptoPP) #if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) void Salsa20_TestInstantiations() { - Salsa20::Encryption x; + Salsa20::Encryption x1; + XSalsa20::Encryption x2; } #endif +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +// static const size_t s_unused1 = Salsa20::KEYLENGTH; +static const size_t s_unused2 = XSalsa20::KEYLENGTH; + void Salsa20_Policy::CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) { m_rounds = params.GetIntValueWithDefault(Name::Rounds(), 20); @@ -247,37 +252,37 @@ void Salsa20_Policy::OperateKeystream(KeystreamOperation operation, byte *output 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 L32(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + a*16], xmm##A) +#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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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) \ L01(0,1,2,3, a,b,c,d, i) L01(4,5,6,7, e,f,g,h, i) \ diff --git a/salsa.h b/salsa.h index 54d1ec69..6a70af6e 100644 --- a/salsa.h +++ b/salsa.h @@ -19,12 +19,14 @@ NAMESPACE_BEGIN(CryptoPP) //! \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> { static const char *StaticAlgorithmName() {return "Salsa20";} }; +//! \class Salsa20_Policy +//! \brief Salsa20 stream cipher operation class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy { protected: @@ -43,7 +45,7 @@ protected: }; //! \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. //! \sa XSalsa20 struct Salsa20 : public Salsa20_Info, public SymmetricCipherDocumentation @@ -59,6 +61,8 @@ struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_I static const char *StaticAlgorithmName() {return "XSalsa20";} }; +//! \class XSalsa20_Policy +//! \brief XSalsa20 stream cipher operation class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy { public: @@ -70,7 +74,7 @@ protected: }; //! \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. //! \sa XSalsa20 struct XSalsa20 : public XSalsa20_Info, public SymmetricCipherDocumentation diff --git a/seal.cpp b/seal.cpp index 15392ac0..641a3207 100644 --- a/seal.cpp +++ b/seal.cpp @@ -17,6 +17,9 @@ void SEAL_TestInstantiations() } #endif +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused = SEAL<>::KEYLENGTH; + struct SEAL_Gamma { SEAL_Gamma(const byte *key) @@ -139,7 +142,7 @@ void SEAL_Policy::OperateKeystream(KeystreamOperation operation, byte *output p = d & 0x7fc; a += Ttab(p); d = rotrFixed(d, 9U); - + // generate 8192 bits for (unsigned int i=0; i<64; i++) { @@ -197,7 +200,7 @@ void SEAL_Policy::OperateKeystream(KeystreamOperation operation, byte *output else { a += n1; - b += n2; + b += n2; c ^= n1; d ^= n2; } diff --git a/seal.h b/seal.h index cbf5edb1..9c898e52 100644 --- a/seal.h +++ b/seal.h @@ -11,13 +11,18 @@ NAMESPACE_BEGIN(CryptoPP) -//! _ +//! \class SEAL_Info +//! \brief SEAL stream cipher information +//! \tparam B Endianess of the stream cipher template 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";} }; +//! \class SEAL_Policy +//! \brief SEAL stream cipher operation +//! \tparam B Endianess of the stream cipher template class CRYPTOPP_NO_VTABLE SEAL_Policy : public AdditiveCipherConcretePolicy, public SEAL_Info { @@ -37,7 +42,10 @@ private: word32 m_outsideCounter, m_insideCounter; }; -//! SEAL +//! \class SEAL +//! \brief SEAL stream cipher +//! \tparam B Endianess of the stream cipher +//! \sa SEAL template struct SEAL : public SEAL_Info, public SymmetricCipherDocumentation { diff --git a/seed.cpp b/seed.cpp index f6a9690f..58905fe3 100644 --- a/seed.cpp +++ b/seed.cpp @@ -6,6 +6,9 @@ NAMESPACE_BEGIN(CryptoPP) +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused = SEED::KEYLENGTH; + static const word32 s_kc[16] = { 0x9e3779b9, 0x3c6ef373, 0x78dde6e6, 0xf1bbcdcc, 0xe3779b99, 0xc6ef3733, 0x8dde6e67, 0x1bbcdccf, 0x3779b99e, 0x6ef3733c, 0xdde6e678, 0xbbcdccf1, 0x779b99e3, 0xef3733c6, 0xde6e678d, 0xbcdccf1b}; diff --git a/shark.cpp b/shark.cpp index 99d63d21..503d00b6 100644 --- a/shark.cpp +++ b/shark.cpp @@ -12,6 +12,9 @@ NAMESPACE_BEGIN(CryptoPP) +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused = SHARK::KEYLENGTH; + static word64 SHARKTransform(word64 a) { static const byte iG[8][8] = { diff --git a/shark.h b/shark.h index 0998011a..bf413c92 100644 --- a/shark.h +++ b/shark.h @@ -24,6 +24,8 @@ struct SHARK_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public /// SHARK-E class SHARK : public SHARK_Info, public BlockCipherDocumentation { + //! \class Base + //! \brief SHARK block cipher default operation class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl { public: @@ -34,6 +36,8 @@ class SHARK : public SHARK_Info, public BlockCipherDocumentation SecBlock m_roundKeys; }; + //! \class Enc + //! \brief SHARK block cipher encryption operation class CRYPTOPP_NO_VTABLE Enc : public Base { public: @@ -47,6 +51,8 @@ class SHARK : public SHARK_Info, public BlockCipherDocumentation static const word64 cbox[8][256]; }; + //! \class Dec + //! \brief SHARK block cipher decryption operation class CRYPTOPP_NO_VTABLE Dec : public Base { public: diff --git a/skipjack.cpp b/skipjack.cpp index 7b3afdfa..c52baf49 100644 --- a/skipjack.cpp +++ b/skipjack.cpp @@ -7,7 +7,7 @@ #include "skipjack.h" -/* +/* * Optimized implementation of SKIPJACK algorithm * * originally written by Panu Rissanen 1998.06.24 @@ -17,10 +17,13 @@ NAMESPACE_BEGIN(CryptoPP) +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused = SKIPJACK::KEYLENGTH; + /** * 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, 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, diff --git a/skipjack.h b/skipjack.h index 1e214c26..c2142ef5 100644 --- a/skipjack.h +++ b/skipjack.h @@ -23,6 +23,8 @@ struct SKIPJACK_Info : public FixedBlockSize<8>, public FixedKeyLength<10> //! \sa SKIPJACK class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation { + //! \class Base + //! \brief SKIPJACK block cipher default operation class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl { public: @@ -35,6 +37,8 @@ class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation FixedSizeSecBlock tab; }; + //! \class Enc + //! \brief SKIPJACK block cipher encryption operation class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Enc : public Base { public: @@ -44,6 +48,8 @@ class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation static const word32 Te[4][256]; }; + //! \class Dec + //! \brief SKIPJACK block cipher decryption operation class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Dec : public Base { public: diff --git a/square.cpp b/square.cpp index c976cb38..b868200a 100644 --- a/square.cpp +++ b/square.cpp @@ -18,14 +18,17 @@ NAMESPACE_BEGIN(CryptoPP) +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused = Square::KEYLENGTH; + // apply theta to a roundkey 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, - 0x03U, 0x02U, 0x01U, 0x01U, - 0x01U, 0x03U, 0x02U, 0x01U, + 0x02U, 0x01U, 0x01U, 0x03U, + 0x03U, 0x02U, 0x01U, 0x01U, + 0x01U, 0x03U, 0x02U, 0x01U, 0x01U, 0x01U, 0x03U, 0x02U }; @@ -62,7 +65,7 @@ void Square::Base::UncheckedSetKey(const byte *userKey, unsigned int length, con roundkeys(i, 1) = roundkeys(i-1, 1) ^ roundkeys(i, 0); roundkeys(i, 2) = roundkeys(i-1, 2) ^ roundkeys(i, 1); roundkeys(i, 3) = roundkeys(i-1, 3) ^ roundkeys(i, 2); - } + } /* produce the round keys */ if (IsForwardTransformation()) @@ -138,13 +141,13 @@ void Square::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, { word32 text[4], temp[4]; Block::Get(inBlock)(text[0])(text[1])(text[2])(text[3]); - + /* initial key addition */ text[0] ^= roundkeys(0, 0); text[1] ^= roundkeys(0, 1); text[2] ^= roundkeys(0, 2); text[3] ^= roundkeys(0, 3); - + /* ROUNDS - 1 full rounds */ for (int i=1; i+1 Block; @@ -24,7 +27,7 @@ void TEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt word32 sum = 0; while (sum != m_limit) - { + { sum += DELTA; 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]); @@ -41,7 +44,7 @@ void TEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt word32 sum = m_limit; 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]); sum -= DELTA; } @@ -70,7 +73,7 @@ void XTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by word32 sum = 0; while (sum != m_limit) #endif - { + { y += ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]); sum += DELTA; z += ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]); @@ -116,9 +119,9 @@ void BTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by word32 y = v[0], z = v[n-1], e; word32 p, q = 6+52/n; word32 sum = 0; - + while (q-- > 0) - { + { sum += DELTA; e = sum>>2 & 3; for (p = 0; p < n-1; p++) @@ -148,7 +151,7 @@ void BTEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by word32 sum = q * DELTA; while (sum != 0) - { + { e = sum>>2 & 3; for (p = n-1; p > 0; p--) { diff --git a/tea.h b/tea.h index 6c933b7e..e1d0da87 100644 --- a/tea.h +++ b/tea.h @@ -24,6 +24,8 @@ struct TEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public Va //! \sa TEA class TEA : public TEA_Info, public BlockCipherDocumentation { + //! \class Base + //! \brief TEA block cipher default operation class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl { public: @@ -34,12 +36,16 @@ class TEA : public TEA_Info, public BlockCipherDocumentation word32 m_limit; }; + //! \class Enc + //! \brief TEA block cipher encryption operation class CRYPTOPP_NO_VTABLE Enc : public Base { public: 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 { public: @@ -66,6 +72,8 @@ struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public V //! \sa XTEA class XTEA : public XTEA_Info, public BlockCipherDocumentation { + //! \class Base + //! \brief XTEA block cipher default operation class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl { public: @@ -76,12 +84,16 @@ class XTEA : public XTEA_Info, public BlockCipherDocumentation word32 m_limit; }; + //! \class Enc + //! \brief XTEA block cipher encryption operation class CRYPTOPP_NO_VTABLE Enc : public Base { public: 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 { public: @@ -106,6 +118,8 @@ struct BTEA_Info : public FixedKeyLength<16> //! \sa Corrected Block TEA. class BTEA : public BTEA_Info, public BlockCipherDocumentation { + //! \class Base + //! \brief BTEA block cipher default operation class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl, BTEA_Info>, public BTEA_Info { public: @@ -123,12 +137,16 @@ class BTEA : public BTEA_Info, public BlockCipherDocumentation unsigned int m_blockSize; }; + //! \class Enc + //! \brief BTEA block cipher encryption operation class CRYPTOPP_NO_VTABLE Enc : public Base { public: 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 { public: diff --git a/ttmac.cpp b/ttmac.cpp index 98954370..b7513e8b 100644 --- a/ttmac.cpp +++ b/ttmac.cpp @@ -6,6 +6,9 @@ NAMESPACE_BEGIN(CryptoPP) +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused = TTMAC::KEYLENGTH; + void TTMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &) { AssertValidKeyLength(keylength); diff --git a/ttmac.h b/ttmac.h index 206ee293..47b32ca2 100644 --- a/ttmac.h +++ b/ttmac.h @@ -1,5 +1,8 @@ // 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 #define CRYPTOPP_TTMAC_H @@ -9,7 +12,8 @@ NAMESPACE_BEGIN(CryptoPP) -//! _ +//! \class TTMAC_Base +//! \brief TTMAC message authentication code information class CRYPTOPP_NO_VTABLE TTMAC_Base : public FixedKeyLength<20>, public IteratedHash { public: @@ -30,8 +34,11 @@ protected: FixedSizeSecBlock m_key; }; -//! Two-Track-MAC -/*! 160 Bit MAC with 160 Bit Key */ +//! \class TTMAC +//! \brief Two-Track-MAC message authentication code +//! \tparam T HashTransformation class +//! \details 160-bit MAC with 160-bit key +//! \sa MessageAuthenticationCode(), Two-Track-MAC DOCUMENTED_TYPEDEF(MessageAuthenticationCodeFinal, TTMAC) NAMESPACE_END diff --git a/wake.cpp b/wake.cpp index 4a9bc340..4725947f 100644 --- a/wake.cpp +++ b/wake.cpp @@ -15,6 +15,9 @@ void WAKE_TestInstantiations() } #endif +// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 +static const size_t s_unused = WAKE_OFB<>::KEYLENGTH; + inline word32 WAKE_Base::M(word32 x, word32 y) { word32 w = x+y; @@ -24,7 +27,7 @@ inline word32 WAKE_Base::M(word32 x, word32 y) 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" - 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 CRYPTOPP_COMPILE_ASSERT(sizeof(x) == 4); static unsigned int tt[10]= { diff --git a/wake.h b/wake.h index 28c00e02..9629e9f9 100644 --- a/wake.h +++ b/wake.h @@ -12,7 +12,9 @@ NAMESPACE_BEGIN(CryptoPP) -//! _ +//! \class WAKE_OFB_Info +//! \brief WAKE stream cipher information +//! \tparam B Endianess of the stream cipher template struct WAKE_OFB_Info : public FixedKeyLength<32> { @@ -29,6 +31,9 @@ protected: word32 r3, r4, r5, r6; }; +//! \class WAKE_Policy +//! \brief WAKE stream cipher operation +//! \tparam B Endianess of the stream cipher template class CRYPTOPP_NO_VTABLE WAKE_Policy : public AdditiveCipherConcretePolicy, protected WAKE_Base { @@ -39,7 +44,9 @@ protected: bool CipherIsRandomAccess() const {return false;} }; -//! WAKE-OFB +//! \class WAKE_OFB +//! \brief WAKE stream cipher +//! \tparam B Endianess of the stream cipher template struct WAKE_OFB : public WAKE_OFB_Info, public SymmetricCipherDocumentation {