Initial fix for older Apple ld's non_lazy_ptr missing symbols (Issue 255)
parent
33522b39b1
commit
45323bddd8
9
3way.cpp
9
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)
|
||||
{
|
||||
|
|
|
|||
14
des.cpp
14
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<word32, BigEndian> 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)
|
||||
{
|
||||
|
|
|
|||
10
des.h
10
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 <a href="http://www.weidai.com/scan-mirror/cs.html#DES">DES</a>
|
||||
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
|
||||
{
|
||||
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>
|
||||
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>
|
||||
{
|
||||
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>
|
||||
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>
|
||||
{
|
||||
public:
|
||||
|
|
@ -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
|
||||
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>
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
7
gost.cpp
7
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);
|
||||
|
|
|
|||
6
gost.h
6
gost.h
|
|
@ -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>
|
||||
class GOST : public GOST_Info, public BlockCipherDocumentation
|
||||
{
|
||||
//! \class Base
|
||||
//! \brief GOST block cipher default operation
|
||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<GOST_Info>
|
||||
{
|
||||
public:
|
||||
|
|
@ -38,12 +40,16 @@ class GOST : public GOST_Info, public BlockCipherDocumentation
|
|||
FixedSizeSecBlock<word32, 8> 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:
|
||||
|
|
|
|||
23
idea.cpp
23
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<IDEA_KEYLEN; i++)
|
||||
{
|
||||
unsigned int j = RoundDownToMultipleOf(i,8U)-8;
|
||||
|
|
@ -170,7 +173,7 @@ void IDEA::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, b
|
|||
x1 += key[i*6+1];
|
||||
x2 += key[i*6+2];
|
||||
MUL(x3, key[i*6+3]);
|
||||
t0 = x0^x2;
|
||||
t0 = x0^x2;
|
||||
MUL(t0, key[i*6+4]);
|
||||
t1 = t0 + (x1^x3);
|
||||
MUL(t1, key[i*6+5]);
|
||||
|
|
|
|||
18
mdc.h
18
mdc.h
|
|
@ -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
|
||||
#define CRYPTOPP_MDC_H
|
||||
|
||||
/** \file
|
||||
*/
|
||||
//! \file mdc.h
|
||||
//! \brief Classes for the MDC message digest
|
||||
|
||||
#include "seckey.h"
|
||||
#include "secblock.h"
|
||||
|
|
@ -12,18 +12,24 @@
|
|||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
//! _
|
||||
//! \class MDC_Info
|
||||
//! \brief MDC_Info cipher information
|
||||
template <class T>
|
||||
struct MDC_Info : public FixedBlockSize<T::DIGESTSIZE>, public FixedKeyLength<T::BLOCKSIZE>
|
||||
{
|
||||
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>
|
||||
class MDC : public MDC_Info<T>
|
||||
{
|
||||
//! \class Enc
|
||||
//! \brief MDC cipher encryption operation
|
||||
class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<MDC_Info<T> >
|
||||
{
|
||||
typedef typename T::HashWordType HashWordType;
|
||||
|
|
|
|||
37
panama.cpp
37
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 <class B>
|
||||
void Panama<B>::Reset()
|
||||
{
|
||||
|
|
@ -385,22 +388,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);
|
||||
}
|
||||
|
||||
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<B>::TruncatedFinal(byte *hash, size_t size)
|
|||
this->ThrowIfInvalidTruncatedSize(size);
|
||||
|
||||
this->PadLastBlock(this->BLOCKSIZE, 0x01);
|
||||
|
||||
|
||||
HashEndianCorrectedBlock(this->m_data);
|
||||
|
||||
this->Iterate(32); // pull
|
||||
|
|
|
|||
24
panama.h
24
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 B>
|
||||
class CRYPTOPP_NO_VTABLE Panama
|
||||
{
|
||||
|
|
@ -33,7 +33,9 @@ protected:
|
|||
};
|
||||
|
||||
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>
|
||||
class PanamaHash : protected Panama<B>, public AlgorithmImpl<IteratedHash<word32, NativeByteOrder, 32>, PanamaHash<B> >
|
||||
{
|
||||
|
|
@ -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>
|
||||
class HermeticHashFunctionMAC : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<MessageAuthenticationCode, VariableKeyLength<32, 0, INT_MAX> > >, T_Info>
|
||||
{
|
||||
|
|
@ -108,7 +111,8 @@ protected:
|
|||
};
|
||||
|
||||
namespace Weak {
|
||||
/// Panama MAC
|
||||
//! \class PanamaMAC
|
||||
//! \brief Panama message authentication code
|
||||
template <class B = LittleEndian>
|
||||
class PanamaMAC : public HermeticHashFunctionMAC<PanamaHash<B> >
|
||||
{
|
||||
|
|
@ -119,14 +123,16 @@ public:
|
|||
};
|
||||
}
|
||||
|
||||
//! algorithm info
|
||||
//! \class PanamaCipherInfo
|
||||
//! \brief Panama stream cipher information
|
||||
template <class B>
|
||||
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 B>
|
||||
class PanamaCipherPolicy : public AdditiveCipherConcretePolicy<word32, 8>,
|
||||
public PanamaCipherInfo<B>,
|
||||
|
|
@ -142,7 +148,9 @@ protected:
|
|||
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>
|
||||
struct PanamaCipher : public PanamaCipherInfo<B>, public SymmetricCipherDocumentation
|
||||
{
|
||||
|
|
|
|||
69
salsa.cpp
69
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) \
|
||||
|
|
|
|||
10
salsa.h
10
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<word32, 16>
|
||||
{
|
||||
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 <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>
|
||||
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 <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>
|
||||
struct XSalsa20 : public XSalsa20_Info, public SymmetricCipherDocumentation
|
||||
|
|
|
|||
7
seal.cpp
7
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<B>::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<B>::OperateKeystream(KeystreamOperation operation, byte *output
|
|||
else
|
||||
{
|
||||
a += n1;
|
||||
b += n2;
|
||||
b += n2;
|
||||
c ^= n1;
|
||||
d ^= n2;
|
||||
}
|
||||
|
|
|
|||
12
seal.h
12
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 <class B = BigEndian>
|
||||
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 B = BigEndian>
|
||||
class CRYPTOPP_NO_VTABLE SEAL_Policy : public AdditiveCipherConcretePolicy<word32, 256>, public SEAL_Info<B>
|
||||
{
|
||||
|
|
@ -37,7 +42,10 @@ private:
|
|||
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>
|
||||
struct SEAL : public SEAL_Info<B>, public SymmetricCipherDocumentation
|
||||
{
|
||||
|
|
|
|||
3
seed.cpp
3
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};
|
||||
|
|
|
|||
|
|
@ -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] = {
|
||||
|
|
|
|||
6
shark.h
6
shark.h
|
|
@ -24,6 +24,8 @@ struct SHARK_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public
|
|||
/// <a href="http://www.weidai.com/scan-mirror/cs.html#SHARK-E">SHARK-E</a>
|
||||
class SHARK : public SHARK_Info, public BlockCipherDocumentation
|
||||
{
|
||||
//! \class Base
|
||||
//! \brief SHARK block cipher default operation
|
||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHARK_Info>
|
||||
{
|
||||
public:
|
||||
|
|
@ -34,6 +36,8 @@ class SHARK : public SHARK_Info, public BlockCipherDocumentation
|
|||
SecBlock<word64> 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:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "skipjack.h"
|
||||
|
||||
/*
|
||||
/*
|
||||
* Optimized implementation of SKIPJACK algorithm
|
||||
*
|
||||
* originally written by Panu Rissanen <bande@lut.fi> 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,
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ struct SKIPJACK_Info : public FixedBlockSize<8>, public FixedKeyLength<10>
|
|||
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#SKIPJACK">SKIPJACK</a>
|
||||
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>
|
||||
{
|
||||
public:
|
||||
|
|
@ -35,6 +37,8 @@ class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation
|
|||
FixedSizeSecBlock<byte, 10*256> 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:
|
||||
|
|
|
|||
21
square.cpp
21
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<ROUNDS; i+=2)
|
||||
{
|
||||
|
|
@ -163,13 +166,13 @@ void Square::Dec::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<ROUNDS; i+=2)
|
||||
{
|
||||
|
|
|
|||
15
tea.cpp
15
tea.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 = TEA::KEYLENGTH;
|
||||
|
||||
static const word32 DELTA = 0x9e3779b9;
|
||||
typedef BlockGetAndPut<word32, BigEndian> 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--)
|
||||
{
|
||||
|
|
|
|||
18
tea.h
18
tea.h
|
|
@ -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>
|
||||
class TEA : public TEA_Info, public BlockCipherDocumentation
|
||||
{
|
||||
//! \class Base
|
||||
//! \brief TEA block cipher default operation
|
||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
|
||||
{
|
||||
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 <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">XTEA</a>
|
||||
class XTEA : public XTEA_Info, public BlockCipherDocumentation
|
||||
{
|
||||
//! \class Base
|
||||
//! \brief XTEA block cipher default operation
|
||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<XTEA_Info>
|
||||
{
|
||||
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 <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">Corrected Block TEA</a>.
|
||||
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
|
||||
{
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
13
ttmac.h
13
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<word32, LittleEndian, 64, MessageAuthenticationCode>
|
||||
{
|
||||
public:
|
||||
|
|
@ -30,8 +34,11 @@ protected:
|
|||
FixedSizeSecBlock<word32, 5> m_key;
|
||||
};
|
||||
|
||||
//! <a href="http://www.weidai.com/scan-mirror/mac.html#TTMAC">Two-Track-MAC</a>
|
||||
/*! 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(), <a href="http://www.weidai.com/scan-mirror/mac.html#TTMAC">Two-Track-MAC</a>
|
||||
DOCUMENTED_TYPEDEF(MessageAuthenticationCodeFinal<TTMAC_Base>, TTMAC)
|
||||
|
||||
NAMESPACE_END
|
||||
|
|
|
|||
5
wake.cpp
5
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]= {
|
||||
|
|
|
|||
11
wake.h
11
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 <class B = BigEndian>
|
||||
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 B = BigEndian>
|
||||
class CRYPTOPP_NO_VTABLE WAKE_Policy : public AdditiveCipherConcretePolicy<word32, 1, 64>, 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 <class B = BigEndian>
|
||||
struct WAKE_OFB : public WAKE_OFB_Info<B>, public SymmetricCipherDocumentation
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue