aboutsummaryrefslogtreecommitdiffstats
path: root/src/mac
diff options
context:
space:
mode:
Diffstat (limited to 'src/mac')
-rw-r--r--src/mac/ssl3mac/ssl3_mac.cpp16
-rw-r--r--src/mac/ssl3mac/ssl3_mac.h4
-rw-r--r--src/mac/x919_mac/x919_mac.cpp25
-rw-r--r--src/mac/x919_mac/x919_mac.h8
4 files changed, 35 insertions, 18 deletions
diff --git a/src/mac/ssl3mac/ssl3_mac.cpp b/src/mac/ssl3mac/ssl3_mac.cpp
index ceb04bf44..d2aec7825 100644
--- a/src/mac/ssl3mac/ssl3_mac.cpp
+++ b/src/mac/ssl3mac/ssl3_mac.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/ssl3_mac.h>
-#include <botan/lookup.h>
namespace Botan {
@@ -65,21 +64,22 @@ std::string SSL3_MAC::name() const
*************************************************/
MessageAuthenticationCode* SSL3_MAC::clone() const
{
- return new SSL3_MAC(hash->name());
+ return new SSL3_MAC(hash->clone());
}
/*************************************************
* 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))
+SSL3_MAC::SSL3_MAC(HashFunction* hash_in) :
+ MessageAuthenticationCode(hash_in->OUTPUT_LENGTH,
+ hash_in->OUTPUT_LENGTH),
+ hash(hash_in)
{
- if(hash->name() != "MD5" && hash->name() != "SHA-160")
+ if(hash->HASH_BLOCK_SIZE == 0)
throw Invalid_Argument("SSL3-MAC cannot be used with " + hash->name());
- const u32bit INNER_HASH_LENGTH = (hash->name() == "MD5") ? 64 : 60;
+ u32bit INNER_HASH_LENGTH =
+ (hash->name() == "SHA-160") ? 60 : hash->HASH_BLOCK_SIZE;
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
index 8ab08c97d..9b4be4e2f 100644
--- a/src/mac/ssl3mac/ssl3_mac.h
+++ b/src/mac/ssl3mac/ssl3_mac.h
@@ -19,12 +19,14 @@ class SSL3_MAC : public MessageAuthenticationCode
void clear() throw();
std::string name() const;
MessageAuthenticationCode* clone() const;
- SSL3_MAC(const std::string&);
+
+ SSL3_MAC(HashFunction*);
~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;
};
diff --git a/src/mac/x919_mac/x919_mac.cpp b/src/mac/x919_mac/x919_mac.cpp
index 92ec7b7b8..5e03b2e6c 100644
--- a/src/mac/x919_mac/x919_mac.cpp
+++ b/src/mac/x919_mac/x919_mac.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/x919_mac.h>
-#include <botan/lookup.h>
#include <botan/xor_buf.h>
#include <algorithm>
@@ -70,19 +69,33 @@ void ANSI_X919_MAC::clear() throw()
position = 0;
}
+std::string ANSI_X919_MAC::name() const
+ {
+ return "X9.19-MAC";
+ }
+
+MessageAuthenticationCode* ANSI_X919_MAC::clone() const
+ {
+ return new ANSI_X919_MAC(e->clone());
+ }
+
/*************************************************
* ANSI X9.19 MAC Constructor *
*************************************************/
-ANSI_X919_MAC::ANSI_X919_MAC() : MessageAuthenticationCode(8, 8, 16, 8)
+ANSI_X919_MAC::ANSI_X919_MAC(BlockCipher* e_in) :
+ MessageAuthenticationCode(e_in->BLOCK_SIZE,
+ e_in->MINIMUM_KEYLENGTH,
+ 2*e_in->MAXIMUM_KEYLENGTH,
+ 2*e_in->KEYLENGTH_MULTIPLE),
+ e(e_in), d(e->clone()), position(0)
{
- e = get_block_cipher("DES");
- d = get_block_cipher("DES");
- position = 0;
+ if(e->name() != "DES")
+ throw Invalid_Argument("ANSI X9.19 MAC only supports DES");
}
/*************************************************
* ANSI X9.19 MAC Destructor *
-*************************************************/
+le*************************************************/
ANSI_X919_MAC::~ANSI_X919_MAC()
{
delete e;
diff --git a/src/mac/x919_mac/x919_mac.h b/src/mac/x919_mac/x919_mac.h
index bedb2cf58..4909e554a 100644
--- a/src/mac/x919_mac/x919_mac.h
+++ b/src/mac/x919_mac/x919_mac.h
@@ -17,14 +17,16 @@ class BOTAN_DLL ANSI_X919_MAC : public MessageAuthenticationCode
{
public:
void clear() throw();
- std::string name() const { return "X9.19-MAC"; }
- MessageAuthenticationCode* clone() const { return new ANSI_X919_MAC; }
- ANSI_X919_MAC();
+ std::string name() const;
+ MessageAuthenticationCode* clone() const;
+
+ ANSI_X919_MAC(BlockCipher*);
~ANSI_X919_MAC();
private:
void add_data(const byte[], u32bit);
void final_result(byte[]);
void key(const byte[], u32bit);
+
BlockCipher* e;
BlockCipher* d;
SecureBuffer<byte, 8> state;