diff options
Diffstat (limited to 'src/mac')
-rw-r--r-- | src/mac/cbc_mac/cbc_mac.h | 2 | ||||
-rw-r--r-- | src/mac/cmac/cmac.cpp | 8 | ||||
-rw-r--r-- | src/mac/cmac/cmac.h | 6 | ||||
-rw-r--r-- | src/mac/hmac/hmac.cpp | 13 | ||||
-rw-r--r-- | src/mac/hmac/hmac.h | 4 | ||||
-rw-r--r-- | src/mac/mac.cpp | 2 | ||||
-rw-r--r-- | src/mac/ssl3mac/ssl3_mac.cpp | 24 | ||||
-rw-r--r-- | src/mac/ssl3mac/ssl3_mac.h | 2 | ||||
-rw-r--r-- | src/mac/x919_mac/x919_mac.cpp | 2 | ||||
-rw-r--r-- | src/mac/x919_mac/x919_mac.h | 2 |
10 files changed, 34 insertions, 31 deletions
diff --git a/src/mac/cbc_mac/cbc_mac.h b/src/mac/cbc_mac/cbc_mac.h index 5cc8adc67..be25718d9 100644 --- a/src/mac/cbc_mac/cbc_mac.h +++ b/src/mac/cbc_mac/cbc_mac.h @@ -40,7 +40,7 @@ class BOTAN_DLL CBC_MAC : public MessageAuthenticationCode void key_schedule(const byte[], size_t); BlockCipher* e; - SecureVector<byte> state; + secure_vector<byte> state; size_t position; }; diff --git a/src/mac/cmac/cmac.cpp b/src/mac/cmac/cmac.cpp index baf22f4e8..00120cf14 100644 --- a/src/mac/cmac/cmac.cpp +++ b/src/mac/cmac/cmac.cpp @@ -13,12 +13,12 @@ namespace Botan { /* * Perform CMAC's multiplication in GF(2^n) */ -SecureVector<byte> CMAC::poly_double(const MemoryRegion<byte>& in, +secure_vector<byte> CMAC::poly_double(const secure_vector<byte>& in, byte polynomial) { const byte poly_xor = (in[0] & 0x80) ? polynomial : 0; - SecureVector<byte> out = in; + secure_vector<byte> out = in; byte carry = 0; for(size_t i = out.size(); i != 0; --i) @@ -38,7 +38,7 @@ SecureVector<byte> CMAC::poly_double(const MemoryRegion<byte>& in, */ void CMAC::add_data(const byte input[], size_t length) { - buffer.copy(position, input, length); + buffer_insert(buffer, position, input, length); if(position + length > output_length()) { xor_buf(state, buffer, output_length()); @@ -52,7 +52,7 @@ void CMAC::add_data(const byte input[], size_t length) input += output_length(); length -= output_length(); } - buffer.copy(input, length); + copy_mem(&buffer[0], input, length); position = 0; } position += length; diff --git a/src/mac/cmac/cmac.h b/src/mac/cmac/cmac.h index 98634bdb7..b398f2563 100644 --- a/src/mac/cmac/cmac.h +++ b/src/mac/cmac/cmac.h @@ -35,8 +35,8 @@ class BOTAN_DLL CMAC : public MessageAuthenticationCode * @param in the input * @param polynomial the byte value of the polynomial */ - static SecureVector<byte> poly_double(const MemoryRegion<byte>& in, - byte polynomial); + static secure_vector<byte> poly_double(const secure_vector<byte>& in, + byte polynomial); /** * @param cipher the underlying block cipher to use @@ -49,7 +49,7 @@ class BOTAN_DLL CMAC : public MessageAuthenticationCode void key_schedule(const byte[], size_t); BlockCipher* e; - SecureVector<byte> buffer, state, B, P; + secure_vector<byte> buffer, state, B, P; size_t position; byte polynomial; }; diff --git a/src/mac/hmac/hmac.cpp b/src/mac/hmac/hmac.cpp index fc35e26ea..4b4ed2f70 100644 --- a/src/mac/hmac/hmac.cpp +++ b/src/mac/hmac/hmac.cpp @@ -37,12 +37,16 @@ void HMAC::final_result(byte mac[]) void HMAC::key_schedule(const byte key[], size_t length) { hash->clear(); + + i_key.resize(hash->hash_block_size()); + o_key.resize(hash->hash_block_size()); + std::fill(i_key.begin(), i_key.end(), 0x36); std::fill(o_key.begin(), o_key.end(), 0x5C); if(length > hash->hash_block_size()) { - SecureVector<byte> hmac_key = hash->process(key, length); + secure_vector<byte> hmac_key = hash->process(key, length); xor_buf(i_key, hmac_key, hmac_key.size()); xor_buf(o_key, hmac_key, hmac_key.size()); } @@ -61,8 +65,8 @@ void HMAC::key_schedule(const byte key[], size_t length) void HMAC::clear() { hash->clear(); - zeroise(i_key); - zeroise(o_key); + i_key.clear(); + o_key.clear(); } /* @@ -88,9 +92,6 @@ HMAC::HMAC(HashFunction* hash_in) : hash(hash_in) { if(hash->hash_block_size() == 0) throw Invalid_Argument("HMAC cannot be used with " + hash->name()); - - i_key.resize(hash->hash_block_size()); - o_key.resize(hash->hash_block_size()); } } diff --git a/src/mac/hmac/hmac.h b/src/mac/hmac/hmac.h index b76a058f4..cb5bd6917 100644 --- a/src/mac/hmac/hmac.h +++ b/src/mac/hmac/hmac.h @@ -27,7 +27,7 @@ class BOTAN_DLL HMAC : public MessageAuthenticationCode Key_Length_Specification key_spec() const { - return Key_Length_Specification(0, 2*hash->hash_block_size()); + return Key_Length_Specification(0, 512); } /** @@ -41,7 +41,7 @@ class BOTAN_DLL HMAC : public MessageAuthenticationCode void key_schedule(const byte[], size_t); HashFunction* hash; - SecureVector<byte> i_key, o_key; + secure_vector<byte> i_key, o_key; }; } diff --git a/src/mac/mac.cpp b/src/mac/mac.cpp index 2ef4ab64c..094aa1b4a 100644 --- a/src/mac/mac.cpp +++ b/src/mac/mac.cpp @@ -15,7 +15,7 @@ namespace Botan { */ bool MessageAuthenticationCode::verify_mac(const byte mac[], size_t length) { - SecureVector<byte> our_mac = final(); + secure_vector<byte> our_mac = final(); if(our_mac.size() != length) return false; diff --git a/src/mac/ssl3mac/ssl3_mac.cpp b/src/mac/ssl3mac/ssl3_mac.cpp index a07622eb3..8979d1291 100644 --- a/src/mac/ssl3mac/ssl3_mac.cpp +++ b/src/mac/ssl3mac/ssl3_mac.cpp @@ -35,11 +35,20 @@ void SSL3_MAC::final_result(byte mac[]) void SSL3_MAC::key_schedule(const byte key[], size_t length) { hash->clear(); + + // Quirk to deal with specification bug + const size_t inner_hash_length = + (hash->name() == "SHA-160") ? 60 : hash->hash_block_size(); + + i_key.resize(inner_hash_length); + o_key.resize(inner_hash_length); + std::fill(i_key.begin(), i_key.end(), 0x36); std::fill(o_key.begin(), o_key.end(), 0x5C); - i_key.copy(key, length); - o_key.copy(key, length); + copy_mem(&i_key[0], key, length); + copy_mem(&o_key[0], key, length); + hash->update(i_key); } @@ -49,8 +58,8 @@ void SSL3_MAC::key_schedule(const byte key[], size_t length) void SSL3_MAC::clear() { hash->clear(); - zeroise(i_key); - zeroise(o_key); + i_key.clear(); + o_key.clear(); } /* @@ -76,13 +85,6 @@ SSL3_MAC::SSL3_MAC(HashFunction* hash_in) : hash(hash_in) { if(hash->hash_block_size() == 0) throw Invalid_Argument("SSL3-MAC cannot be used with " + hash->name()); - - // Quirk to deal with specification bug - const size_t INNER_HASH_LENGTH = - (hash->name() == "SHA-160") ? 60 : hash->hash_block_size(); - - i_key.resize(INNER_HASH_LENGTH); - o_key.resize(INNER_HASH_LENGTH); } } diff --git a/src/mac/ssl3mac/ssl3_mac.h b/src/mac/ssl3mac/ssl3_mac.h index a85a78263..d23ac023c 100644 --- a/src/mac/ssl3mac/ssl3_mac.h +++ b/src/mac/ssl3mac/ssl3_mac.h @@ -41,7 +41,7 @@ class BOTAN_DLL SSL3_MAC : public MessageAuthenticationCode void key_schedule(const byte[], size_t); HashFunction* hash; - SecureVector<byte> i_key, o_key; + secure_vector<byte> i_key, o_key; }; } diff --git a/src/mac/x919_mac/x919_mac.cpp b/src/mac/x919_mac/x919_mac.cpp index fcbe77537..faf6138ef 100644 --- a/src/mac/x919_mac/x919_mac.cpp +++ b/src/mac/x919_mac/x919_mac.cpp @@ -44,7 +44,7 @@ void ANSI_X919_MAC::final_result(byte mac[]) { if(position) e->encrypt(state); - d->decrypt(state, mac); + d->decrypt(&state[0], mac); e->encrypt(mac); zeroise(state); position = 0; diff --git a/src/mac/x919_mac/x919_mac.h b/src/mac/x919_mac/x919_mac.h index 58a005e0b..4b5e63b33 100644 --- a/src/mac/x919_mac/x919_mac.h +++ b/src/mac/x919_mac/x919_mac.h @@ -41,7 +41,7 @@ class BOTAN_DLL ANSI_X919_MAC : public MessageAuthenticationCode BlockCipher* e; BlockCipher* d; - SecureVector<byte> state; + secure_vector<byte> state; size_t position; }; |