From f87c490937dcd6a2e9affc72d4121e7d5daa5eee Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 9 Oct 2009 22:38:46 +0000 Subject: Add PBKDF2 wrapper --- src/wrap/python/core.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/wrap/python/core.cpp') diff --git a/src/wrap/python/core.cpp b/src/wrap/python/core.cpp index 40af71ecf..fe26e16ee 100644 --- a/src/wrap/python/core.cpp +++ b/src/wrap/python/core.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include using namespace Botan; #include "python_botan.h" @@ -156,6 +158,20 @@ std::string cryptobox_decrypt(const std::string& in, passphrase); } +std::string python_pbkdf2(const std::string& passphrase, + const std::string& salt, + u32bit iterations, + u32bit output_size, + const std::string& hash_fn) + { + PKCS5_PBKDF2 pbkdf2(new HMAC(get_hash(hash_fn))); + + pbkdf2.set_iterations(iterations); + pbkdf2.change_salt(reinterpret_cast(salt.data()), salt.size()); + + return make_string(pbkdf2.derive_key(output_size, passphrase).bits_of()); + } + BOOST_PYTHON_MODULE(_botan) { python::class_("LibraryInitializer") @@ -192,6 +208,7 @@ BOOST_PYTHON_MODULE(_botan) python::def("cryptobox_encrypt", cryptobox_encrypt); python::def("cryptobox_decrypt", cryptobox_decrypt); + python::def("pbkdf2", python_pbkdf2); export_filters(); export_rsa(); -- cgit v1.2.3