diff options
author | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
commit | 6894dca64c04936d07048c0e8cbf7e25858548c3 (patch) | |
tree | 5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/mac/ssl3mac | |
parent | 9efa3be92442afb3d0b69890a36c7f122df18eda (diff) |
Move lib into src
Diffstat (limited to 'src/lib/mac/ssl3mac')
-rw-r--r-- | src/lib/mac/ssl3mac/info.txt | 5 | ||||
-rw-r--r-- | src/lib/mac/ssl3mac/ssl3_mac.cpp | 90 | ||||
-rw-r--r-- | src/lib/mac/ssl3mac/ssl3_mac.h | 49 |
3 files changed, 144 insertions, 0 deletions
diff --git a/src/lib/mac/ssl3mac/info.txt b/src/lib/mac/ssl3mac/info.txt new file mode 100644 index 000000000..5e69b0ae8 --- /dev/null +++ b/src/lib/mac/ssl3mac/info.txt @@ -0,0 +1,5 @@ +define SSL3_MAC 20131128 + +<requires> +hash +</requires> diff --git a/src/lib/mac/ssl3mac/ssl3_mac.cpp b/src/lib/mac/ssl3mac/ssl3_mac.cpp new file mode 100644 index 000000000..64f3103ef --- /dev/null +++ b/src/lib/mac/ssl3mac/ssl3_mac.cpp @@ -0,0 +1,90 @@ +/* +* SSL3-MAC +* (C) 1999-2004 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/ssl3_mac.h> + +namespace Botan { + +/* +* Update a SSL3-MAC Calculation +*/ +void SSL3_MAC::add_data(const byte input[], size_t length) + { + hash->update(input, length); + } + +/* +* Finalize a SSL3-MAC Calculation +*/ +void SSL3_MAC::final_result(byte mac[]) + { + hash->final(mac); + hash->update(o_key); + hash->update(mac, output_length()); + hash->final(mac); + hash->update(i_key); + } + +/* +* SSL3-MAC Key Schedule +*/ +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); + + copy_mem(&i_key[0], key, length); + copy_mem(&o_key[0], key, length); + + hash->update(i_key); + } + +/* +* Clear memory of sensitive data +*/ +void SSL3_MAC::clear() + { + hash->clear(); + zap(i_key); + zap(o_key); + } + +/* +* Return the name of this type +*/ +std::string SSL3_MAC::name() const + { + return "SSL3-MAC(" + hash->name() + ")"; + } + +/* +* Return a clone of this object +*/ +MessageAuthenticationCode* SSL3_MAC::clone() const + { + return new SSL3_MAC(hash->clone()); + } + +/* +* SSL3-MAC Constructor +*/ +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()); + } + +} diff --git a/src/lib/mac/ssl3mac/ssl3_mac.h b/src/lib/mac/ssl3mac/ssl3_mac.h new file mode 100644 index 000000000..d23ac023c --- /dev/null +++ b/src/lib/mac/ssl3mac/ssl3_mac.h @@ -0,0 +1,49 @@ +/* +* SSL3-MAC +* (C) 1999-2004 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SSL3_MAC_H__ +#define BOTAN_SSL3_MAC_H__ + +#include <botan/hash.h> +#include <botan/mac.h> + +namespace Botan { + +/** +* A MAC only used in SSLv3. Do not use elsewhere! Use HMAC instead. +*/ +class BOTAN_DLL SSL3_MAC : public MessageAuthenticationCode + { + public: + std::string name() const; + size_t output_length() const { return hash->output_length(); } + MessageAuthenticationCode* clone() const; + + void clear(); + + Key_Length_Specification key_spec() const + { + return Key_Length_Specification(hash->output_length()); + } + + /** + * @param hash the underlying hash to use + */ + SSL3_MAC(HashFunction* hash); + ~SSL3_MAC() { delete hash; } + private: + void add_data(const byte[], size_t); + void final_result(byte[]); + void key_schedule(const byte[], size_t); + + HashFunction* hash; + secure_vector<byte> i_key, o_key; + }; + +} + +#endif |