diff options
author | Philipp Weber <[email protected]> | 2016-04-27 15:22:08 +0200 |
---|---|---|
committer | Philipp Weber <[email protected]> | 2016-04-27 15:40:22 +0200 |
commit | f15cdfc6d954fd3d835a6d1b56632f0b3746b368 (patch) | |
tree | ca95e69c75299cbba76d7e5302f5c13c88c37037 /src/lib/kdf/kdf1_iso18033/kdf1_iso18033.cpp | |
parent | 4ad555977b03cb92dfac0b87a00febe4d8e7ff5e (diff) |
add kdf1 implementation according to iso-18033 (preparation for ecies)
Diffstat (limited to 'src/lib/kdf/kdf1_iso18033/kdf1_iso18033.cpp')
-rw-r--r-- | src/lib/kdf/kdf1_iso18033/kdf1_iso18033.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lib/kdf/kdf1_iso18033/kdf1_iso18033.cpp b/src/lib/kdf/kdf1_iso18033/kdf1_iso18033.cpp new file mode 100644 index 000000000..3ff717993 --- /dev/null +++ b/src/lib/kdf/kdf1_iso18033/kdf1_iso18033.cpp @@ -0,0 +1,35 @@ +/* +* KDF1 from ISO 18033 +* (C) 2016 Philipp Weber +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include <botan/kdf1_iso18033.h> + +namespace Botan { + +size_t KDF1_18033::kdf(byte key[], size_t key_len, + const byte secret[], size_t secret_len, + const byte salt[], size_t salt_len) const + { + u32bit counter = 0; + secure_vector<byte> h; + + size_t offset = 0; + while(offset != key_len && counter != 0xFFFFFFFF) + { + m_hash->update(secret, secret_len); + m_hash->update_be(counter++); + m_hash->update(salt, salt_len); + m_hash->final(h); + + const size_t added = std::min(h.size(), key_len - offset); + copy_mem(&key[offset], h.data(), added); + offset += added; + } + + return offset; + } + +} |