Skip to content

Commit c1d8d81

Browse files
committed
Update CHAM64 and CHAM128 key setup
1 parent f51dc25 commit c1d8d81

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

cham.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,26 @@ extern size_t CHAM128_Dec_AdvancedProcessBlocks_SSSE3(const word32* subKeys, siz
112112
# endif // CRYPTOPP_SSSE3_AVAILABLE
113113
#endif // CRYPTOPP_CHAM128_ADVANCED_PROCESS_BLOCKS
114114

115-
std::string CHAM64::Base::AlgorithmProvider() const
116-
{
117-
return "C++";
118-
}
119-
120115
void CHAM64::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
121116
{
122117
CRYPTOPP_UNUSED(params);
123118
m_kw = keyLength/sizeof(word16);
124119
m_rk.New(2*m_kw);
125120

126-
for (size_t i = 0; i < m_kw; ++i, userKey += sizeof(word16))
121+
for (size_t i = 0; i < m_kw; userKey += sizeof(word32))
127122
{
128123
// Do not cast the buffer. It will SIGBUS on some ARM and SPARC.
129-
const word16 rk = GetWord<word16>(false, BIG_ENDIAN_ORDER, userKey);
130-
m_rk[i] = rk ^ rotlConstant<1>(rk) ^ rotlConstant<8>(rk);
131-
m_rk[(i + m_kw) ^ 1] = rk ^ rotlConstant<1>(rk) ^ rotlConstant<11>(rk);
124+
const word32 rk = GetWord<word32>(false, BIG_ENDIAN_ORDER, userKey);
125+
126+
const word16 rk1 = rk >> 16;
127+
m_rk[i] = rk1 ^ rotlConstant<1>(rk1) ^ rotlConstant<8>(rk1);
128+
m_rk[(i + m_kw) ^ 1] = rk1 ^ rotlConstant<1>(rk1) ^ rotlConstant<11>(rk1);
129+
i++;
130+
131+
const word16 rk2 = rk & 0xffff;
132+
m_rk[i] = rk2 ^ rotlConstant<1>(rk2) ^ rotlConstant<8>(rk2);
133+
m_rk[(i + m_kw) ^ 1] = rk2 ^ rotlConstant<1>(rk2) ^ rotlConstant<11>(rk2);
134+
i++;
132135
}
133136
}
134137

@@ -209,12 +212,13 @@ void CHAM128::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength,
209212
m_kw = keyLength/sizeof(word32);
210213
m_rk.New(2*m_kw);
211214

212-
for (size_t i = 0; i < m_kw; ++i, userKey += sizeof(word32))
215+
for (size_t i = 0; i < m_kw; userKey += sizeof(word32))
213216
{
214217
// Do not cast the buffer. It will SIGBUS on some ARM and SPARC.
215218
const word32 rk = GetWord<word32>(false, BIG_ENDIAN_ORDER, userKey);
216219
m_rk[i] = rk ^ rotlConstant<1>(rk) ^ rotlConstant<8>(rk);
217220
m_rk[(i + m_kw) ^ 1] = rk ^ rotlConstant<1>(rk) ^ rotlConstant<11>(rk);
221+
i++;
218222
}
219223
}
220224

cham.h

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class CRYPTOPP_NO_VTABLE CHAM64 : public CHAM64_Info, public BlockCipherDocument
7474
{
7575
protected:
7676
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
77-
std::string AlgorithmProvider() const;
7877

7978
SecBlock<word16> m_rk;
8079
mutable FixedSizeSecBlock<word16, 4> m_x;

0 commit comments

Comments
 (0)