diff options
Diffstat (limited to 'src/lib/block/rc5/rc5.cpp')
-rw-r--r-- | src/lib/block/rc5/rc5.cpp | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/lib/block/rc5/rc5.cpp b/src/lib/block/rc5/rc5.cpp index a32efd775..a02a45e9f 100644 --- a/src/lib/block/rc5/rc5.cpp +++ b/src/lib/block/rc5/rc5.cpp @@ -21,20 +21,20 @@ void RC5::encrypt_n(const byte in[], byte out[], size_t blocks) const u32bit A = load_le<u32bit>(in, 0); u32bit B = load_le<u32bit>(in, 1); - A += S[0]; B += S[1]; - for(size_t j = 0; j != rounds; j += 4) + A += m_S[0]; B += m_S[1]; + for(size_t j = 0; j != m_rounds; j += 4) { - A = rotate_left(A ^ B, B % 32) + S[2*j+2]; - B = rotate_left(B ^ A, A % 32) + S[2*j+3]; + A = rotate_left(A ^ B, B % 32) + m_S[2*j+2]; + B = rotate_left(B ^ A, A % 32) + m_S[2*j+3]; - A = rotate_left(A ^ B, B % 32) + S[2*j+4]; - B = rotate_left(B ^ A, A % 32) + S[2*j+5]; + A = rotate_left(A ^ B, B % 32) + m_S[2*j+4]; + B = rotate_left(B ^ A, A % 32) + m_S[2*j+5]; - A = rotate_left(A ^ B, B % 32) + S[2*j+6]; - B = rotate_left(B ^ A, A % 32) + S[2*j+7]; + A = rotate_left(A ^ B, B % 32) + m_S[2*j+6]; + B = rotate_left(B ^ A, A % 32) + m_S[2*j+7]; - A = rotate_left(A ^ B, B % 32) + S[2*j+8]; - B = rotate_left(B ^ A, A % 32) + S[2*j+9]; + A = rotate_left(A ^ B, B % 32) + m_S[2*j+8]; + B = rotate_left(B ^ A, A % 32) + m_S[2*j+9]; } store_le(out, A, B); @@ -54,21 +54,21 @@ void RC5::decrypt_n(const byte in[], byte out[], size_t blocks) const u32bit A = load_le<u32bit>(in, 0); u32bit B = load_le<u32bit>(in, 1); - for(size_t j = rounds; j != 0; j -= 4) + for(size_t j = m_rounds; j != 0; j -= 4) { - B = rotate_right(B - S[2*j+1], A % 32) ^ A; - A = rotate_right(A - S[2*j ], B % 32) ^ B; + B = rotate_right(B - m_S[2*j+1], A % 32) ^ A; + A = rotate_right(A - m_S[2*j ], B % 32) ^ B; - B = rotate_right(B - S[2*j-1], A % 32) ^ A; - A = rotate_right(A - S[2*j-2], B % 32) ^ B; + B = rotate_right(B - m_S[2*j-1], A % 32) ^ A; + A = rotate_right(A - m_S[2*j-2], B % 32) ^ B; - B = rotate_right(B - S[2*j-3], A % 32) ^ A; - A = rotate_right(A - S[2*j-4], B % 32) ^ B; + B = rotate_right(B - m_S[2*j-3], A % 32) ^ A; + A = rotate_right(A - m_S[2*j-4], B % 32) ^ B; - B = rotate_right(B - S[2*j-5], A % 32) ^ A; - A = rotate_right(A - S[2*j-6], B % 32) ^ B; + B = rotate_right(B - m_S[2*j-5], A % 32) ^ A; + A = rotate_right(A - m_S[2*j-6], B % 32) ^ B; } - B -= S[1]; A -= S[0]; + B -= m_S[1]; A -= m_S[0]; store_le(out, A, B); @@ -82,14 +82,14 @@ void RC5::decrypt_n(const byte in[], byte out[], size_t blocks) const */ void RC5::key_schedule(const byte key[], size_t length) { - S.resize(2*rounds + 2); + m_S.resize(2*m_rounds + 2); const size_t WORD_KEYLENGTH = (((length - 1) / 4) + 1); - const size_t MIX_ROUNDS = 3 * std::max(WORD_KEYLENGTH, S.size()); + const size_t MIX_ROUNDS = 3 * std::max(WORD_KEYLENGTH, m_S.size()); - S[0] = 0xB7E15163; - for(size_t i = 1; i != S.size(); ++i) - S[i] = S[i-1] + 0x9E3779B9; + m_S[0] = 0xB7E15163; + for(size_t i = 1; i != m_S.size(); ++i) + m_S[i] = m_S[i-1] + 0x9E3779B9; secure_vector<u32bit> K(8); @@ -100,16 +100,16 @@ void RC5::key_schedule(const byte key[], size_t length) for(size_t i = 0; i != MIX_ROUNDS; ++i) { - A = rotate_left(S[i % S.size()] + A + B, 3); + A = rotate_left(m_S[i % m_S.size()] + A + B, 3); B = rotate_left(K[i % WORD_KEYLENGTH] + A + B, (A + B) % 32); - S[i % S.size()] = A; + m_S[i % m_S.size()] = A; K[i % WORD_KEYLENGTH] = B; } } void RC5::clear() { - zap(S); + zap(m_S); } /* @@ -117,17 +117,17 @@ void RC5::clear() */ std::string RC5::name() const { - return "RC5(" + std::to_string(rounds) + ")"; + return "RC5(" + std::to_string(m_rounds) + ")"; } /* * RC5 Constructor */ -RC5::RC5(size_t r) : rounds(r) +RC5::RC5(size_t r) : m_rounds(r) { - if(rounds < 8 || rounds > 32 || (rounds % 4 != 0)) + if(m_rounds < 8 || m_rounds > 32 || (m_rounds % 4 != 0)) throw Invalid_Argument("RC5: Invalid number of rounds " + - std::to_string(rounds)); + std::to_string(m_rounds)); } } |