diff options
author | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
commit | a2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch) | |
tree | ad3d6c4fcc8dd0f403f8105598943616246fe172 /src/mgf1.cpp |
Initial checkin1.5.6
Diffstat (limited to 'src/mgf1.cpp')
-rw-r--r-- | src/mgf1.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/mgf1.cpp b/src/mgf1.cpp new file mode 100644 index 000000000..b922c8987 --- /dev/null +++ b/src/mgf1.cpp @@ -0,0 +1,49 @@ +/************************************************* +* MGF1 Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include <botan/mgf1.h> +#include <botan/lookup.h> +#include <botan/bit_ops.h> +#include <algorithm> +#include <memory> + +namespace Botan { + +/************************************************* +* MGF1 Mask Generation Function * +*************************************************/ +void MGF1::mask(const byte in[], u32bit in_len, byte out[], + u32bit out_len) const + { + u32bit counter = 0; + + std::auto_ptr<HashFunction> hash(get_hash(hash_name)); + + while(out_len) + { + hash->update(in, in_len); + for(u32bit j = 0; j != 4; ++j) + hash->update(get_byte(j, counter)); + SecureVector<byte> buffer = hash->final(); + + u32bit xored = std::min(buffer.size(), out_len); + xor_buf(out, buffer.begin(), xored); + out += xored; + out_len -= xored; + + ++counter; + } + } + +/************************************************* +* MGF1 Constructor * +*************************************************/ +MGF1::MGF1(const std::string& h_name) : hash_name(h_name) + { + if(!have_hash(hash_name)) + throw Algorithm_Not_Found(hash_name); + } + +} |