diff options
author | lloyd <[email protected]> | 2010-10-13 01:34:15 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-13 01:34:15 +0000 |
commit | fe4119c74b5e81a354a5313e4d2efbf9a135aa81 (patch) | |
tree | 5c5254cc3a4e5713169ef1d52a83db19c8c4ed65 /src/block/aes | |
parent | 60fb91d8cb1710d07041f76050d24229ce91131b (diff) |
Use size_t rather than u32bit in SymmetricAlgorithm
Diffstat (limited to 'src/block/aes')
-rw-r--r-- | src/block/aes/aes.cpp | 46 | ||||
-rw-r--r-- | src/block/aes/aes.h | 7 |
2 files changed, 27 insertions, 26 deletions
diff --git a/src/block/aes/aes.cpp b/src/block/aes/aes.cpp index 66f9c5eb1..cfd490e1d 100644 --- a/src/block/aes/aes.cpp +++ b/src/block/aes/aes.cpp @@ -619,7 +619,7 @@ void AES::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * AES Key Schedule */ -void AES::key_schedule(const byte key[], u32bit length) +void AES::key_schedule(const byte key[], size_t length) { static const u32bit RC[10] = { 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, @@ -629,40 +629,40 @@ void AES::key_schedule(const byte key[], u32bit length) SecureVector<u32bit> XEK(64), XDK(64); - const u32bit X = length / 4; - for(u32bit j = 0; j != X; ++j) - XEK[j] = load_be<u32bit>(key, j); + const size_t X = length / 4; + for(size_t i = 0; i != X; ++i) + XEK[i] = load_be<u32bit>(key, i); - for(u32bit j = X; j < 4*(ROUNDS+1); j += X) + for(size_t i = X; i < 4*(ROUNDS+1); i += X) { - XEK[j] = XEK[j-X] ^ S(rotate_left(XEK[j-1], 8)) ^ RC[(j-X)/X]; - for(u32bit k = 1; k != X; ++k) + XEK[i] = XEK[i-X] ^ S(rotate_left(XEK[i-1], 8)) ^ RC[(i-X)/X]; + for(size_t j = 1; j != X; ++j) { - if(X == 8 && k == 4) - XEK[j+k] = XEK[j+k-X] ^ S(XEK[j+k-1]); + if(X == 8 && j == 4) + XEK[i+j] = XEK[i+j-X] ^ S(XEK[i+j-1]); else - XEK[j+k] = XEK[j+k-X] ^ XEK[j+k-1]; + XEK[i+j] = XEK[i+j-X] ^ XEK[i+j-1]; } } - for(u32bit j = 0; j != 4*(ROUNDS+1); j += 4) + for(size_t i = 0; i != 4*(ROUNDS+1); i += 4) { - XDK[j ] = XEK[4*ROUNDS-j ]; - XDK[j+1] = XEK[4*ROUNDS-j+1]; - XDK[j+2] = XEK[4*ROUNDS-j+2]; - XDK[j+3] = XEK[4*ROUNDS-j+3]; + XDK[i ] = XEK[4*ROUNDS-i ]; + XDK[i+1] = XEK[4*ROUNDS-i+1]; + XDK[i+2] = XEK[4*ROUNDS-i+2]; + XDK[i+3] = XEK[4*ROUNDS-i+3]; } - for(u32bit j = 4; j != length + 24; ++j) - XDK[j] = TD[SE[get_byte(0, XDK[j])] + 0] ^ - TD[SE[get_byte(1, XDK[j])] + 256] ^ - TD[SE[get_byte(2, XDK[j])] + 512] ^ - TD[SE[get_byte(3, XDK[j])] + 768]; + for(size_t i = 4; i != length + 24; ++i) + XDK[i] = TD[SE[get_byte(0, XDK[i])] + 0] ^ + TD[SE[get_byte(1, XDK[i])] + 256] ^ + TD[SE[get_byte(2, XDK[i])] + 512] ^ + TD[SE[get_byte(3, XDK[i])] + 768]; - for(u32bit j = 0; j != 4; ++j) + for(size_t i = 0; i != 4; ++i) { - store_be(XEK[j+4*ROUNDS], &ME[4*j]); - store_be(XEK[j], &MD[4*j]); + store_be(XEK[i+4*ROUNDS], &ME[4*i]); + store_be(XEK[i], &MD[4*i]); } EK.copy(&XEK[0], length + 24); diff --git a/src/block/aes/aes.h b/src/block/aes/aes.h index 6bc1f44b4..d62413f5b 100644 --- a/src/block/aes/aes.h +++ b/src/block/aes/aes.h @@ -25,7 +25,8 @@ class BOTAN_DLL AES : public BlockCipher std::string name() const { return "AES"; } BlockCipher* clone() const { return new AES; } - AES() : BlockCipher(16, 16, 32, 8), EK(56), ME(16), DK(56), MD(16) { ROUNDS = 14; } + AES() : BlockCipher(16, 16, 32, 8), EK(56), ME(16), DK(56), MD(16) + { ROUNDS = 14; } /** * AES fixed to a particular key_size (16, 24, or 32 bytes) @@ -33,7 +34,7 @@ class BOTAN_DLL AES : public BlockCipher */ AES(u32bit key_size); private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); static u32bit S(u32bit); u32bit ROUNDS; @@ -41,7 +42,7 @@ class BOTAN_DLL AES : public BlockCipher SecureVector<u32bit> EK; SecureVector<byte> ME; - SecureVector<u32bit> DK; + SecureVector<u32bit > DK; SecureVector<byte> MD; }; |