diff options
Diffstat (limited to 'src/lib/pk_pad/mgf1/mgf1.cpp')
-rw-r--r-- | src/lib/pk_pad/mgf1/mgf1.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/lib/pk_pad/mgf1/mgf1.cpp b/src/lib/pk_pad/mgf1/mgf1.cpp new file mode 100644 index 000000000..eae2fed59 --- /dev/null +++ b/src/lib/pk_pad/mgf1/mgf1.cpp @@ -0,0 +1,36 @@ +/* +* MGF1 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/mgf1.h> +#include <botan/exceptn.h> +#include <botan/internal/xor_buf.h> +#include <algorithm> + +namespace Botan { + +void mgf1_mask(HashFunction& hash, + const byte in[], size_t in_len, + byte out[], size_t out_len) + { + u32bit counter = 0; + + while(out_len) + { + hash.update(in, in_len); + hash.update_be(counter); + secure_vector<byte> buffer = hash.final(); + + size_t xored = std::min<size_t>(buffer.size(), out_len); + xor_buf(out, &buffer[0], xored); + out += xored; + out_len -= xored; + + ++counter; + } + } + +} |