Whitespace and spelling check-in
parent
3970a066e3
commit
79273a0f4d
26
simon.cpp
26
simon.cpp
|
|
@ -46,12 +46,18 @@ inline void SIMON_Encrypt(W c[2], const W p[2], const W k[R])
|
||||||
{
|
{
|
||||||
c[0]=p[0]; c[1]=p[1];
|
c[0]=p[0]; c[1]=p[1];
|
||||||
|
|
||||||
|
// The constexpr residue should allow the optimizer to remove unneeded statements
|
||||||
|
if (R%2 == 0)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; static_cast<int>(i) < R-1; i += 2)
|
||||||
|
R2(c[0], c[1], k[i], k[i + 1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (size_t i = 0; static_cast<int>(i) < R-1; i += 2)
|
for (size_t i = 0; static_cast<int>(i) < R-1; i += 2)
|
||||||
R2(c[0], c[1], k[i], k[i + 1]);
|
R2(c[0], c[1], k[i], k[i + 1]);
|
||||||
|
|
||||||
// The constexpr residue should allow the optimizer to remove unneeded statements
|
|
||||||
if (R%2 == 1)
|
|
||||||
{
|
|
||||||
c[1] ^= f(c[0]); c[1] ^= k[R-1];
|
c[1] ^= f(c[0]); c[1] ^= k[R-1];
|
||||||
W t = c[0]; c[0] = c[1]; c[1] = t;
|
W t = c[0]; c[0] = c[1]; c[1] = t;
|
||||||
}
|
}
|
||||||
|
|
@ -86,13 +92,13 @@ inline void SIMON_Decrypt(W p[2], const W c[2], const W k[R])
|
||||||
|
|
||||||
//! \brief Subkey generation function
|
//! \brief Subkey generation function
|
||||||
//! \details Used for SIMON-64 with 96-bit key and 42 rounds. A template was
|
//! \details Used for SIMON-64 with 96-bit key and 42 rounds. A template was
|
||||||
//! not worthwile because all instantiations would need specialization.
|
//! not worthwhile because all instantiations would need specialization.
|
||||||
//! \param key empty subkey array
|
//! \param key empty subkey array
|
||||||
//! \param k user key array
|
//! \param k user key array
|
||||||
inline void SPECK64_ExpandKey_42R3K(word32 key[42], const word32 k[3])
|
inline void SPECK64_ExpandKey_42R3K(word32 key[42], const word32 k[3])
|
||||||
{
|
{
|
||||||
const word32 c = 0xfffffffc;
|
const word32 c = 0xfffffffc;
|
||||||
word64 z = 0x7369f885192c0ef5LL;
|
word64 z = W64LIT(0x7369f885192c0ef5);
|
||||||
|
|
||||||
key[0] = k[0]; key[1] = k[1]; key[2] = k[2];
|
key[0] = k[0]; key[1] = k[1]; key[2] = k[2];
|
||||||
for (size_t i = 3; i<42; ++i)
|
for (size_t i = 3; i<42; ++i)
|
||||||
|
|
@ -104,7 +110,7 @@ inline void SPECK64_ExpandKey_42R3K(word32 key[42], const word32 k[3])
|
||||||
|
|
||||||
//! \brief Subkey generation function
|
//! \brief Subkey generation function
|
||||||
//! \details Used for SIMON-64 with 128-bit key and 44 rounds. A template was
|
//! \details Used for SIMON-64 with 128-bit key and 44 rounds. A template was
|
||||||
//! not worthwile because all instantiations would need specialization.
|
//! not worthwhile because all instantiations would need specialization.
|
||||||
//! \param key empty subkey array
|
//! \param key empty subkey array
|
||||||
//! \param k user key array
|
//! \param k user key array
|
||||||
inline void SPECK64_ExpandKey_44R4K(word32 key[44], const word32 k[4])
|
inline void SPECK64_ExpandKey_44R4K(word32 key[44], const word32 k[4])
|
||||||
|
|
@ -122,7 +128,7 @@ inline void SPECK64_ExpandKey_44R4K(word32 key[44], const word32 k[4])
|
||||||
|
|
||||||
//! \brief Subkey generation function
|
//! \brief Subkey generation function
|
||||||
//! \details Used for SIMON-128 with 128-bit key and 68 rounds. A template was
|
//! \details Used for SIMON-128 with 128-bit key and 68 rounds. A template was
|
||||||
//! not worthwile because all instantiations would need specialization.
|
//! not worthwhile because all instantiations would need specialization.
|
||||||
//! \param key empty subkey array
|
//! \param key empty subkey array
|
||||||
//! \param k user key array
|
//! \param k user key array
|
||||||
inline void SIMON128_ExpandKey_68R2K(word64 key[68], const word64 k[2])
|
inline void SIMON128_ExpandKey_68R2K(word64 key[68], const word64 k[2])
|
||||||
|
|
@ -143,7 +149,7 @@ inline void SIMON128_ExpandKey_68R2K(word64 key[68], const word64 k[2])
|
||||||
|
|
||||||
//! \brief Subkey generation function
|
//! \brief Subkey generation function
|
||||||
//! \details Used for SIMON-128 with 192-bit key and 69 rounds. A template was
|
//! \details Used for SIMON-128 with 192-bit key and 69 rounds. A template was
|
||||||
//! not worthwile because all instantiations would need specialization.
|
//! not worthwhile because all instantiations would need specialization.
|
||||||
//! \param key empty subkey array
|
//! \param key empty subkey array
|
||||||
//! \param k user key array
|
//! \param k user key array
|
||||||
inline void SIMON128_ExpandKey_69R3K(word64 key[69], const word64 k[3])
|
inline void SIMON128_ExpandKey_69R3K(word64 key[69], const word64 k[3])
|
||||||
|
|
@ -164,7 +170,7 @@ inline void SIMON128_ExpandKey_69R3K(word64 key[69], const word64 k[3])
|
||||||
|
|
||||||
//! \brief Subkey generation function
|
//! \brief Subkey generation function
|
||||||
//! \details Used for SIMON-128 with 256-bit key and 72 rounds. A template was
|
//! \details Used for SIMON-128 with 256-bit key and 72 rounds. A template was
|
||||||
//! not worthwile because all instantiations would need specialization.
|
//! not worthwhile because all instantiations would need specialization.
|
||||||
//! \param key empty subkey array
|
//! \param key empty subkey array
|
||||||
//! \param k user key array
|
//! \param k user key array
|
||||||
inline void SIMON128_ExpandKey_72R4K(word64 key[72], const word64 k[4])
|
inline void SIMON128_ExpandKey_72R4K(word64 key[72], const word64 k[4])
|
||||||
|
|
@ -191,7 +197,6 @@ ANONYMOUS_NAMESPACE_END
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
#if 1
|
|
||||||
void SIMON64::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms)
|
void SIMON64::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
CRYPTOPP_ASSERT(keyLength == 12 || keyLength == 16);
|
CRYPTOPP_ASSERT(keyLength == 12 || keyLength == 16);
|
||||||
|
|
@ -269,7 +274,6 @@ void SIMON64::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
|
||||||
typedef PutBlock<word32, BigEndian, false> OutBlock;
|
typedef PutBlock<word32, BigEndian, false> OutBlock;
|
||||||
OutBlock oblk(xorBlock, outBlock); oblk(m_wspace[2])(m_wspace[3]);
|
OutBlock oblk(xorBlock, outBlock); oblk(m_wspace[2])(m_wspace[3]);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
||||||
3
simon.h
3
simon.h
|
|
@ -52,8 +52,6 @@ struct SIMON_Base
|
||||||
unsigned int m_kwords; // number of key words
|
unsigned int m_kwords; // number of key words
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 1
|
|
||||||
|
|
||||||
//! \class SIMON64
|
//! \class SIMON64
|
||||||
//! \brief SIMON 64-bit block cipher
|
//! \brief SIMON 64-bit block cipher
|
||||||
//! \details SIMON64 provides 64-bit block size. The valid key sizes are 98-bit and 128-bit.
|
//! \details SIMON64 provides 64-bit block size. The valid key sizes are 98-bit and 128-bit.
|
||||||
|
|
@ -100,7 +98,6 @@ public:
|
||||||
typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
|
typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
|
||||||
typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
|
typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
//! \class SIMON128
|
//! \class SIMON128
|
||||||
//! \brief SIMON 128-bit block cipher
|
//! \brief SIMON 128-bit block cipher
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue