parent
93fb412215
commit
4b3560baef
|
|
@ -14,9 +14,9 @@ Currently the library contains the following algorithms:
|
||||||
AES and AES candidates AES (Rijndael), RC6, MARS, Twofish, Serpent,
|
AES and AES candidates AES (Rijndael), RC6, MARS, Twofish, Serpent,
|
||||||
CAST-256
|
CAST-256
|
||||||
|
|
||||||
ARIA, IDEA, Triple-DES (DES-EDE2 and DES-EDE3),
|
ARIA, IDEA, Blowfish, Triple-DES (DES-EDE2 and
|
||||||
other block ciphers Camellia, SEED, Kalyna, RC5, Blowfish, TEA, XTEA,
|
other block ciphers DES-EDE3), Camellia, SEED, Kalyna, RC5, SPECK-64,
|
||||||
Threefish, Skipjack, SHACAL-2
|
SPECK-128, Threefish, Skipjack, SHACAL-2, TEA, XTEA
|
||||||
|
|
||||||
block cipher modes of operation ECB, CBC, CBC ciphertext stealing (CTS),
|
block cipher modes of operation ECB, CBC, CBC ciphertext stealing (CTS),
|
||||||
CFB, OFB, counter mode (CTR)
|
CFB, OFB, counter mode (CTR)
|
||||||
|
|
|
||||||
40
speck.cpp
40
speck.cpp
|
|
@ -18,6 +18,8 @@ using CryptoPP::rotrFixed;
|
||||||
using CryptoPP::rotlVariable;
|
using CryptoPP::rotlVariable;
|
||||||
using CryptoPP::rotrVariable;
|
using CryptoPP::rotrVariable;
|
||||||
|
|
||||||
|
//! \brief Forward round transformation
|
||||||
|
//! \tparam W word type
|
||||||
template <class W>
|
template <class W>
|
||||||
inline void TF83(W& x, W& y, const W& k)
|
inline void TF83(W& x, W& y, const W& k)
|
||||||
{
|
{
|
||||||
|
|
@ -27,19 +29,23 @@ inline void TF83(W& x, W& y, const W& k)
|
||||||
y ^= x;
|
y ^= x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief Reverse round transformation
|
||||||
|
//! \tparam W word type
|
||||||
template <class W>
|
template <class W>
|
||||||
inline void TR83(W& x, W& y, const W& k)
|
inline void TR83(W& x, W& y, const W& k)
|
||||||
{
|
{
|
||||||
y^=x;
|
y^=x;
|
||||||
y=rotrFixed(y,3);
|
y=rotrFixed(y,3);
|
||||||
x^=k;
|
x^=k; x-=y;
|
||||||
x-=y;
|
|
||||||
x=rotlFixed(x,8);
|
x=rotlFixed(x,8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// W is word type
|
//! \brief Forward transformation
|
||||||
// R is number of rounds
|
//! \tparam W word type
|
||||||
// p = plain text, k = key, c = cipher text
|
//! \tparam R number of rounds
|
||||||
|
//! \param c output array
|
||||||
|
//! \param p input array
|
||||||
|
//! \param k subkey array
|
||||||
template <class W, unsigned int R>
|
template <class W, unsigned int R>
|
||||||
inline void SPECK_Encrypt(W c[2], const W p[2], const W k[R])
|
inline void SPECK_Encrypt(W c[2], const W p[2], const W k[R])
|
||||||
{
|
{
|
||||||
|
|
@ -50,6 +56,12 @@ inline void SPECK_Encrypt(W c[2], const W p[2], const W k[R])
|
||||||
TF83(c[0], c[1], k[i]);
|
TF83(c[0], c[1], k[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief Reverse transformation
|
||||||
|
//! \tparam W word type
|
||||||
|
//! \tparam R number of rounds
|
||||||
|
//! \param p output array
|
||||||
|
//! \param c input array
|
||||||
|
//! \param k subkey array
|
||||||
template <class W, unsigned int R>
|
template <class W, unsigned int R>
|
||||||
inline void SPECK_Decrypt(W p[2], const W c[2], const W k[R])
|
inline void SPECK_Decrypt(W p[2], const W c[2], const W k[R])
|
||||||
{
|
{
|
||||||
|
|
@ -60,6 +72,12 @@ inline void SPECK_Decrypt(W p[2], const W c[2], const W k[R])
|
||||||
TR83(p[0], p[1], k[i]);
|
TR83(p[0], p[1], k[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief Subkey generation function
|
||||||
|
//! \details Used when the user key consists of 2 words
|
||||||
|
//! \tparam W word type
|
||||||
|
//! \tparam R number of rounds
|
||||||
|
//! \param key empty subkey array
|
||||||
|
//! \param k user key array
|
||||||
template <class W, unsigned int R>
|
template <class W, unsigned int R>
|
||||||
inline void SPECK_RoundKeys_2W(W key[R], const W k[2])
|
inline void SPECK_RoundKeys_2W(W key[R], const W k[2])
|
||||||
{
|
{
|
||||||
|
|
@ -74,6 +92,12 @@ inline void SPECK_RoundKeys_2W(W key[R], const W k[2])
|
||||||
key[R-1]=A;
|
key[R-1]=A;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief Subkey generation function
|
||||||
|
//! \details Used when the user key consists of 3 words
|
||||||
|
//! \tparam W word type
|
||||||
|
//! \tparam R number of rounds
|
||||||
|
//! \param key empty subkey array
|
||||||
|
//! \param k user key array
|
||||||
template <class W, unsigned int R>
|
template <class W, unsigned int R>
|
||||||
inline void SPECK_RoundKeys_3W(W key[R], const W k[3])
|
inline void SPECK_RoundKeys_3W(W key[R], const W k[3])
|
||||||
{
|
{
|
||||||
|
|
@ -95,6 +119,12 @@ inline void SPECK_RoundKeys_3W(W key[R], const W k[3])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief Subkey generation function
|
||||||
|
//! \details Used when the user key consists of 4 words
|
||||||
|
//! \tparam W word type
|
||||||
|
//! \tparam R number of rounds
|
||||||
|
//! \param key empty subkey array
|
||||||
|
//! \param k user key array
|
||||||
template <class W, unsigned int R>
|
template <class W, unsigned int R>
|
||||||
inline void SPECK_RoundKeys_4W(W key[R], const W k[4])
|
inline void SPECK_RoundKeys_4W(W key[R], const W k[4])
|
||||||
{
|
{
|
||||||
|
|
|
||||||
29
speck.h
29
speck.h
|
|
@ -21,6 +21,9 @@ NAMESPACE_BEGIN(CryptoPP)
|
||||||
//! \class SPECK_Info
|
//! \class SPECK_Info
|
||||||
//! \brief SPECK block cipher information
|
//! \brief SPECK block cipher information
|
||||||
//! \tparam BS block size of the cipher, in bytes
|
//! \tparam BS block size of the cipher, in bytes
|
||||||
|
//! \tparam D default key length, in bytes
|
||||||
|
//! \tparam N minimum key length, in bytes
|
||||||
|
//! \tparam M maximum key length, in bytes
|
||||||
//! \since Crypto++ 6.0
|
//! \since Crypto++ 6.0
|
||||||
template <unsigned int BS, unsigned int D, unsigned int N, unsigned int M>
|
template <unsigned int BS, unsigned int D, unsigned int N, unsigned int M>
|
||||||
struct SPECK_Info : public FixedBlockSize<BS>, VariableKeyLength<D, N, M>
|
struct SPECK_Info : public FixedBlockSize<BS>, VariableKeyLength<D, N, M>
|
||||||
|
|
@ -35,12 +38,14 @@ struct SPECK_Info : public FixedBlockSize<BS>, VariableKeyLength<D, N, M>
|
||||||
//! \class SPECK_Base
|
//! \class SPECK_Base
|
||||||
//! \brief SPECK block cipher base class
|
//! \brief SPECK block cipher base class
|
||||||
//! \tparam BS block size of the cipher, in bytes
|
//! \tparam BS block size of the cipher, in bytes
|
||||||
//! \details User code should use SPECK128, SPECK512, SPECK1024
|
//! \details User code should use SPECK64 or SPECK128
|
||||||
//! \sa SPECK32, SPECK48, SPECK64, SPECK96, SPECK128, <a href="http://www.cryptopp.com/wiki/SPECK">SPECK</a>
|
//! \sa SPECK64, SPECK128, <a href="http://www.cryptopp.com/wiki/SPECK">SPECK</a>
|
||||||
//! \since Crypto++ 6.0
|
//! \since Crypto++ 6.0
|
||||||
template <class W>
|
template <class W>
|
||||||
struct SPECK_Base
|
struct SPECK_Base
|
||||||
{
|
{
|
||||||
|
virtual ~SPECK_Base() {}
|
||||||
|
|
||||||
typedef SecBlock<W, AllocatorWithCleanup<W, true> > AlignedSecBlock;
|
typedef SecBlock<W, AllocatorWithCleanup<W, true> > AlignedSecBlock;
|
||||||
mutable AlignedSecBlock m_wspace; // workspace
|
mutable AlignedSecBlock m_wspace; // workspace
|
||||||
AlignedSecBlock m_rkey; // round keys
|
AlignedSecBlock m_rkey; // round keys
|
||||||
|
|
@ -51,7 +56,7 @@ struct SPECK_Base
|
||||||
//! \brief SPECK 64-bit block cipher
|
//! \brief SPECK 64-bit block cipher
|
||||||
//! \details SPECK64 provides 64-bit block size. The valid key sizes are 98-bit and 128-bit.
|
//! \details SPECK64 provides 64-bit block size. The valid key sizes are 98-bit and 128-bit.
|
||||||
//! \note Crypto++ provides a byte oriented implementation
|
//! \note Crypto++ provides a byte oriented implementation
|
||||||
//! \sa SPECK32, SPECK64, and SPECK128, <a href="http://www.cryptopp.com/wiki/SPECK">SPECK</a>
|
//! \sa SPECK64, SPECK128, <a href="http://www.cryptopp.com/wiki/SPECK">SPECK</a>
|
||||||
//! \since Crypto++ 6.0
|
//! \since Crypto++ 6.0
|
||||||
class CRYPTOPP_NO_VTABLE SPECK64 : public SPECK_Info<8, 12, 12, 16>, public BlockCipherDocumentation
|
class CRYPTOPP_NO_VTABLE SPECK64 : public SPECK_Info<8, 12, 12, 16>, public BlockCipherDocumentation
|
||||||
{
|
{
|
||||||
|
|
@ -70,12 +75,20 @@ public:
|
||||||
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms);
|
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \brief Provides implementation for encryption transformation
|
||||||
|
//! \details Enc provides implementation for encryption transformation. All key
|
||||||
|
//! sizes are supported.
|
||||||
|
//! \since Crypto++ 6.0
|
||||||
class CRYPTOPP_NO_VTABLE Enc : public Base
|
class CRYPTOPP_NO_VTABLE Enc : public Base
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \brief Provides implementation for encryption transformation
|
||||||
|
//! \details Dec provides implementation for decryption transformation. All key
|
||||||
|
//! sizes are supported.
|
||||||
|
//! \since Crypto++ 6.0
|
||||||
class CRYPTOPP_NO_VTABLE Dec : public Base
|
class CRYPTOPP_NO_VTABLE Dec : public Base
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -90,7 +103,7 @@ public:
|
||||||
//! \brief SPECK 128-bit block cipher
|
//! \brief SPECK 128-bit block cipher
|
||||||
//! \details SPECK128 provides 128-bit block size. The valid key sizes are 128-bit, 192-bit and 256-bit.
|
//! \details SPECK128 provides 128-bit block size. The valid key sizes are 128-bit, 192-bit and 256-bit.
|
||||||
//! \note Crypto++ provides a byte oriented implementation
|
//! \note Crypto++ provides a byte oriented implementation
|
||||||
//! \sa SPECK32, SPECK64, and SPECK128, <a href="http://www.cryptopp.com/wiki/SPECK">SPECK</a>
|
//! \sa SPECK64, SPECK128, <a href="http://www.cryptopp.com/wiki/SPECK">SPECK</a>
|
||||||
//! \since Crypto++ 6.0
|
//! \since Crypto++ 6.0
|
||||||
class CRYPTOPP_NO_VTABLE SPECK128 : public SPECK_Info<16, 16, 16, 32>, public BlockCipherDocumentation
|
class CRYPTOPP_NO_VTABLE SPECK128 : public SPECK_Info<16, 16, 16, 32>, public BlockCipherDocumentation
|
||||||
{
|
{
|
||||||
|
|
@ -109,12 +122,20 @@ public:
|
||||||
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms);
|
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \brief Provides implementation for encryption transformation
|
||||||
|
//! \details Enc provides implementation for encryption transformation. All key
|
||||||
|
//! sizes are supported.
|
||||||
|
//! \since Crypto++ 6.0
|
||||||
class CRYPTOPP_NO_VTABLE Enc : public Base
|
class CRYPTOPP_NO_VTABLE Enc : public Base
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \brief Provides implementation for encryption transformation
|
||||||
|
//! \details Dec provides implementation for decryption transformation. All key
|
||||||
|
//! sizes are supported.
|
||||||
|
//! \since Crypto++ 6.0
|
||||||
class CRYPTOPP_NO_VTABLE Dec : public Base
|
class CRYPTOPP_NO_VTABLE Dec : public Base
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue