Update documentation

Whitespace check-in
pull/548/head
Jeffrey Walton 2017-11-20 08:33:33 -05:00
parent 93fb412215
commit 4b3560baef
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
3 changed files with 268 additions and 217 deletions

View File

@ -14,9 +14,9 @@ Currently the library contains the following algorithms:
AES and AES candidates AES (Rijndael), RC6, MARS, Twofish, Serpent,
CAST-256
ARIA, IDEA, Triple-DES (DES-EDE2 and DES-EDE3),
other block ciphers Camellia, SEED, Kalyna, RC5, Blowfish, TEA, XTEA,
Threefish, Skipjack, SHACAL-2
ARIA, IDEA, Blowfish, Triple-DES (DES-EDE2 and
other block ciphers DES-EDE3), Camellia, SEED, Kalyna, RC5, SPECK-64,
SPECK-128, Threefish, Skipjack, SHACAL-2, TEA, XTEA
block cipher modes of operation ECB, CBC, CBC ciphertext stealing (CTS),
CFB, OFB, counter mode (CTR)

View File

@ -18,6 +18,8 @@ using CryptoPP::rotrFixed;
using CryptoPP::rotlVariable;
using CryptoPP::rotrVariable;
//! \brief Forward round transformation
//! \tparam W word type
template <class W>
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;
}
//! \brief Reverse round transformation
//! \tparam W word type
template <class W>
inline void TR83(W& x, W& y, const W& k)
{
y^=x;
y=rotrFixed(y,3);
x^=k;
x-=y;
x^=k; x-=y;
x=rotlFixed(x,8);
}
// W is word type
// R is number of rounds
// p = plain text, k = key, c = cipher text
//! \brief Forward transformation
//! \tparam W word type
//! \tparam R number of rounds
//! \param c output array
//! \param p input array
//! \param k subkey array
template <class W, unsigned int 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]);
}
//! \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>
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]);
}
//! \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>
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;
}
//! \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>
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>
inline void SPECK_RoundKeys_4W(W key[R], const W k[4])
{

29
speck.h
View File

@ -21,6 +21,9 @@ NAMESPACE_BEGIN(CryptoPP)
//! \class SPECK_Info
//! \brief SPECK block cipher information
//! \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
template <unsigned int BS, unsigned int D, unsigned int N, unsigned int 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
//! \brief SPECK block cipher base class
//! \tparam BS block size of the cipher, in bytes
//! \details User code should use SPECK128, SPECK512, SPECK1024
//! \sa SPECK32, SPECK48, SPECK64, SPECK96, SPECK128, <a href="http://www.cryptopp.com/wiki/SPECK">SPECK</a>
//! \details User code should use SPECK64 or SPECK128
//! \sa SPECK64, SPECK128, <a href="http://www.cryptopp.com/wiki/SPECK">SPECK</a>
//! \since Crypto++ 6.0
template <class W>
struct SPECK_Base
{
virtual ~SPECK_Base() {}
typedef SecBlock<W, AllocatorWithCleanup<W, true> > AlignedSecBlock;
mutable AlignedSecBlock m_wspace; // workspace
AlignedSecBlock m_rkey; // round keys
@ -51,7 +56,7 @@ struct SPECK_Base
//! \brief SPECK 64-bit block cipher
//! \details SPECK64 provides 64-bit block size. The valid key sizes are 98-bit and 128-bit.
//! \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
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 &params);
};
//! \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
{
protected:
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
{
protected:
@ -90,7 +103,7 @@ public:
//! \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.
//! \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
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 &params);
};
//! \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
{
protected:
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
{
protected: