diff options
author | lloyd <[email protected]> | 2008-09-14 03:42:57 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-14 03:42:57 +0000 |
commit | 9154d2e93c7fd4986c38bf62e12241db550dc420 (patch) | |
tree | 3b16e193e5bfc055c43105184d4590c761020604 /src | |
parent | de02c2fe44ad7ce5ead3967c22aa689da508eaa0 (diff) |
Pass a pointer to a HashFunction to the MGF1 constructor, and have that
pointer used over and over again in MGF1::mask.
Diffstat (limited to 'src')
-rw-r--r-- | src/get_enc.cpp | 2 | ||||
-rw-r--r-- | src/mgf1.cpp | 17 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/get_enc.cpp b/src/get_enc.cpp index 17e28e9d9..29a166b2c 100644 --- a/src/get_enc.cpp +++ b/src/get_enc.cpp @@ -123,7 +123,7 @@ MGF* get_mgf(const std::string& algo_spec) if(mgf_name == "MGF1") { if(name.size() == 2) - return new MGF1(name[1]); + return new MGF1(get_hash(name[1])); } else throw Algorithm_Not_Found(algo_spec); diff --git a/src/mgf1.cpp b/src/mgf1.cpp index 70f5a50a0..c2cda7f4c 100644 --- a/src/mgf1.cpp +++ b/src/mgf1.cpp @@ -4,7 +4,6 @@ *************************************************/ #include <botan/mgf1.h> -#include <botan/lookup.h> #include <botan/loadstor.h> #include <botan/xor_buf.h> #include <algorithm> @@ -20,8 +19,6 @@ void MGF1::mask(const byte in[], u32bit in_len, byte out[], { u32bit counter = 0; - std::auto_ptr<HashFunction> hash(get_hash(hash_name)); - while(out_len) { hash->update(in, in_len); @@ -41,10 +38,18 @@ void MGF1::mask(const byte in[], u32bit in_len, byte out[], /************************************************* * MGF1 Constructor * *************************************************/ -MGF1::MGF1(const std::string& h_name) : hash_name(h_name) +MGF1::MGF1(HashFunction* h) : hash(h) + { + if(!hash) + throw Invalid_Argument("MGF1 given null hash object"); + } + +/************************************************* +* MGF1 Destructor * +*************************************************/ +MGF1::~MGF1() { - if(!have_hash(hash_name)) - throw Algorithm_Not_Found(hash_name); + delete hash; } } |