diff options
author | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
commit | 6894dca64c04936d07048c0e8cbf7e25858548c3 (patch) | |
tree | 5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/kdf/mgf1 | |
parent | 9efa3be92442afb3d0b69890a36c7f122df18eda (diff) |
Move lib into src
Diffstat (limited to 'src/lib/kdf/mgf1')
-rw-r--r-- | src/lib/kdf/mgf1/info.txt | 5 | ||||
-rw-r--r-- | src/lib/kdf/mgf1/mgf1.cpp | 56 | ||||
-rw-r--r-- | src/lib/kdf/mgf1/mgf1.h | 36 |
3 files changed, 97 insertions, 0 deletions
diff --git a/src/lib/kdf/mgf1/info.txt b/src/lib/kdf/mgf1/info.txt new file mode 100644 index 000000000..c6254b8a0 --- /dev/null +++ b/src/lib/kdf/mgf1/info.txt @@ -0,0 +1,5 @@ +define MGF1 20131128 + +<requires> +hash +</requires> diff --git a/src/lib/kdf/mgf1/mgf1.cpp b/src/lib/kdf/mgf1/mgf1.cpp new file mode 100644 index 000000000..e0433a02f --- /dev/null +++ b/src/lib/kdf/mgf1/mgf1.cpp @@ -0,0 +1,56 @@ +/* +* 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> +#include <memory> + +namespace Botan { + +/* +* MGF1 Mask Generation Function +*/ +void MGF1::mask(const byte in[], size_t in_len, byte out[], + size_t out_len) const + { + 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; + } + } + +/* +* MGF1 Constructor +*/ +MGF1::MGF1(HashFunction* h) : hash(h) + { + if(!hash) + throw Invalid_Argument("MGF1 given null hash object"); + } + +/* +* MGF1 Destructor +*/ +MGF1::~MGF1() + { + delete hash; + } + +} diff --git a/src/lib/kdf/mgf1/mgf1.h b/src/lib/kdf/mgf1/mgf1.h new file mode 100644 index 000000000..95a2a2bc5 --- /dev/null +++ b/src/lib/kdf/mgf1/mgf1.h @@ -0,0 +1,36 @@ +/* +* MGF1 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MGF1_H__ +#define BOTAN_MGF1_H__ + +#include <botan/kdf.h> +#include <botan/hash.h> + +namespace Botan { + +/** +* MGF1 from PKCS #1 v2.0 +*/ +class BOTAN_DLL MGF1 : public MGF + { + public: + void mask(const byte[], size_t, byte[], size_t) const; + + /** + MGF1 constructor: takes ownership of hash + */ + MGF1(HashFunction* hash); + + ~MGF1(); + private: + HashFunction* hash; + }; + +} + +#endif |