diff options
author | lloyd <[email protected]> | 2008-09-28 19:29:24 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 19:29:24 +0000 |
commit | 9bcfe627321ddc81691b835dffaa6324ac4684a4 (patch) | |
tree | fe5e8ae9813b853549558b59833022e87e83981b /src/mac/ssl3mac | |
parent | 9822a701516396b7de4e41339faecd48ff8dc8ff (diff) |
Move all modules into src/ directory
Diffstat (limited to 'src/mac/ssl3mac')
-rw-r--r-- | src/mac/ssl3mac/modinfo.txt | 10 | ||||
-rw-r--r-- | src/mac/ssl3mac/ssl3_mac.cpp | 88 | ||||
-rw-r--r-- | src/mac/ssl3mac/ssl3_mac.h | 34 |
3 files changed, 132 insertions, 0 deletions
diff --git a/src/mac/ssl3mac/modinfo.txt b/src/mac/ssl3mac/modinfo.txt new file mode 100644 index 000000000..d7a86e571 --- /dev/null +++ b/src/mac/ssl3mac/modinfo.txt @@ -0,0 +1,10 @@ +realname "SSLv3 MAC" + +define SSL3_MAC + +load_on auto + +<add> +ssl3_mac.cpp +ssl3_mac.h +</add> diff --git a/src/mac/ssl3mac/ssl3_mac.cpp b/src/mac/ssl3mac/ssl3_mac.cpp new file mode 100644 index 000000000..ceb04bf44 --- /dev/null +++ b/src/mac/ssl3mac/ssl3_mac.cpp @@ -0,0 +1,88 @@ +/************************************************* +* SSL3-MAC Source File * +* (C) 1999-2004 Jack Lloyd * +*************************************************/ + +#include <botan/ssl3_mac.h> +#include <botan/lookup.h> + +namespace Botan { + +/************************************************* +* Update a SSL3-MAC Calculation * +*************************************************/ +void SSL3_MAC::add_data(const byte input[], u32bit 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(const byte key[], u32bit length) + { + hash->clear(); + 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); + hash->update(i_key); + } + +/************************************************* +* Clear memory of sensitive data * +*************************************************/ +void SSL3_MAC::clear() throw() + { + hash->clear(); + i_key.clear(); + o_key.clear(); + } + +/************************************************* +* 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->name()); + } + +/************************************************* +* SSL3-MAC Constructor * +*************************************************/ +SSL3_MAC::SSL3_MAC(const std::string& hash_name) : + MessageAuthenticationCode(output_length_of(hash_name), + output_length_of(hash_name)), + hash(get_hash(hash_name)) + { + if(hash->name() != "MD5" && hash->name() != "SHA-160") + throw Invalid_Argument("SSL3-MAC cannot be used with " + hash->name()); + + const u32bit INNER_HASH_LENGTH = (hash->name() == "MD5") ? 64 : 60; + + i_key.create(INNER_HASH_LENGTH); + o_key.create(INNER_HASH_LENGTH); + } + +} diff --git a/src/mac/ssl3mac/ssl3_mac.h b/src/mac/ssl3mac/ssl3_mac.h new file mode 100644 index 000000000..8ab08c97d --- /dev/null +++ b/src/mac/ssl3mac/ssl3_mac.h @@ -0,0 +1,34 @@ +/************************************************* +* SSL3-MAC Header File * +* (C) 1999-2004 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_SSL3_MAC_H__ +#define BOTAN_SSL3_MAC_H__ + +#include <botan/base.h> + +namespace Botan { + +/************************************************* +* SSL3-MAC * +*************************************************/ +class SSL3_MAC : public MessageAuthenticationCode + { + public: + void clear() throw(); + std::string name() const; + MessageAuthenticationCode* clone() const; + SSL3_MAC(const std::string&); + ~SSL3_MAC() { delete hash; } + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + void key(const byte[], u32bit); + HashFunction* hash; + SecureVector<byte> i_key, o_key; + }; + +} + +#endif |