diff options
Diffstat (limited to 'src/block/safer/safer_sk.cpp')
-rw-r--r-- | src/block/safer/safer_sk.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp index 84ad9523b..5edd9245b 100644 --- a/src/block/safer/safer_sk.cpp +++ b/src/block/safer/safer_sk.cpp @@ -15,14 +15,14 @@ namespace Botan { /* * SAFER-SK Encryption */ -void SAFER_SK::encrypt_n(const byte in[], byte out[], u32bit blocks) const +void SAFER_SK::encrypt_n(const byte in[], byte out[], size_t blocks) const { - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { byte A = in[0], B = in[1], C = in[2], D = in[3], E = in[4], F = in[5], G = in[6], H = in[7], X, Y; - for(u32bit j = 0; j != 16*ROUNDS; j += 16) + for(size_t j = 0; j != 16*ROUNDS; j += 16) { A = EXP[A ^ EK[j ]]; B = LOG[B + EK[j+1]]; C = LOG[C + EK[j+2]]; D = EXP[D ^ EK[j+3]]; @@ -43,17 +43,17 @@ void SAFER_SK::encrypt_n(const byte in[], byte out[], u32bit blocks) const out[4] = E ^ EK[16*ROUNDS+4]; out[5] = F + EK[16*ROUNDS+5]; out[6] = G + EK[16*ROUNDS+6]; out[7] = H ^ EK[16*ROUNDS+7]; - in += BLOCK_SIZE; - out += BLOCK_SIZE; + in += block_size(); + out += block_size(); } } /* * SAFER-SK Decryption */ -void SAFER_SK::decrypt_n(const byte in[], byte out[], u32bit blocks) const +void SAFER_SK::decrypt_n(const byte in[], byte out[], size_t blocks) const { - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { byte A = in[0], B = in[1], C = in[2], D = in[3], E = in[4], F = in[5], G = in[6], H = in[7]; @@ -81,29 +81,30 @@ void SAFER_SK::decrypt_n(const byte in[], byte out[], u32bit blocks) const out[0] = A; out[1] = B; out[2] = C; out[3] = D; out[4] = E; out[5] = F; out[6] = G; out[7] = H; - in += BLOCK_SIZE; - out += BLOCK_SIZE; + in += block_size(); + out += block_size(); } } /* * SAFER-SK Key Schedule */ -void SAFER_SK::key_schedule(const byte key[], u32bit) +void SAFER_SK::key_schedule(const byte key[], size_t) { - SecureVector<byte, 18> KB; + SecureVector<byte> KB(18); - for(u32bit j = 0; j != 8; ++j) + for(size_t i = 0; i != 8; ++i) { - KB[ 8] ^= KB[j] = rotate_left(key[j], 5); - KB[17] ^= KB[j+9] = EK[j] = key[j+8]; + KB[ 8] ^= KB[i] = rotate_left(key[i], 5); + KB[17] ^= KB[i+9] = EK[i] = key[i+8]; } - for(u32bit j = 0; j != ROUNDS; ++j) + + for(size_t i = 0; i != ROUNDS; ++i) { - for(u32bit k = 0; k != 18; ++k) - KB[k] = rotate_left(KB[k], 6); - for(u32bit k = 0; k != 16; ++k) - EK[16*j+k+8] = KB[KEY_INDEX[16*j+k]] + BIAS[16*j+k]; + for(size_t j = 0; j != 18; ++j) + KB[j] = rotate_left(KB[j], 6); + for(size_t j = 0; j != 16; ++j) + EK[16*i+j+8] = KB[KEY_INDEX[16*i+j]] + BIAS[16*i+j]; } } @@ -126,7 +127,7 @@ BlockCipher* SAFER_SK::clone() const /* * SAFER-SK Constructor */ -SAFER_SK::SAFER_SK(u32bit rounds) : BlockCipher(8, 16), +SAFER_SK::SAFER_SK(size_t rounds) : BlockCipher(8, 16), EK(16 * rounds + 8), ROUNDS(rounds) { if(ROUNDS > 13 || ROUNDS == 0) |