diff options
author | lloyd <[email protected]> | 2009-10-09 18:48:11 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-10-09 18:48:11 +0000 |
commit | ebfa4f1f5d07857b1c000f36c8f8cea0984db121 (patch) | |
tree | c390ac5204d1e1238ede6c2d6e5437e6a0992fb0 | |
parent | 43d6a9673f7bbf962ef6075e4268caa44f03a798 (diff) |
Fix python install target. Add CryptoBox wrapper plus an example
-rw-r--r-- | doc/log.txt | 1 | ||||
-rwxr-xr-x | doc/python/cryptobox.py | 34 | ||||
-rw-r--r-- | src/build-data/makefile/python.in | 2 | ||||
-rw-r--r-- | src/wrap/python/core.cpp | 24 |
4 files changed, 60 insertions, 1 deletions
diff --git a/doc/log.txt b/doc/log.txt index 883c3dabe..3dac507ca 100644 --- a/doc/log.txt +++ b/doc/log.txt @@ -1,5 +1,6 @@ * 1.9.1-pre, 2009-??-?? + - Better support for Python and Perl wrappers - Add an implementation of Blue Midnight Wish (Round 2 tweak version) - Add threshold secret sharing (draft-mcgrew-tss-02) - Add runtime cpu feature detection for x86/x86-64 diff --git a/doc/python/cryptobox.py b/doc/python/cryptobox.py new file mode 100755 index 000000000..1968b40e1 --- /dev/null +++ b/doc/python/cryptobox.py @@ -0,0 +1,34 @@ +#!/usr/bin/python + +import sys +import botan + +def main(args = None): + if args is None: + args = sys.argv + + if len(args) != 3: + raise Exception("Bad usage") + + password = args[1] + input = ''.join(open(args[2]).readlines()) + + rng = botan.RandomNumberGenerator() + + ciphertext = botan.cryptobox_encrypt(input, password, rng) + + print ciphertext + + plaintext = '' + + try: + plaintext = botan.cryptobox_decrypt(ciphertext, password + 'FAIL') + except Exception, e: + print "Oops -- ", e + + plaintext = botan.cryptobox_decrypt(ciphertext, password) + + print plaintext + +if __name__ == '__main__': + sys.exit(main()) diff --git a/src/build-data/makefile/python.in b/src/build-data/makefile/python.in index ee95f8d78..9658c70ce 100644 --- a/src/build-data/makefile/python.in +++ b/src/build-data/makefile/python.in @@ -2,7 +2,7 @@ CXX = g++ PYTHON_ROOT = /usr/lib/python%{python_version}/config PYTHON_INC = -I/usr/include/python%{python_version} -PYTHON_SITE_PACKAGE_DIR = /tmp/usr/lib/python%{python_version}/site-packages/ +PYTHON_SITE_PACKAGE_DIR = /usr/lib/python%{python_version}/site-packages/ PYTHON_FLAGS = -Isrc/wrap/python -Os -fPIC -ftemplate-depth-255 -Wall -Wno-unused $(PYTHON_INC) diff --git a/src/wrap/python/core.cpp b/src/wrap/python/core.cpp index 1992e3d61..59df863de 100644 --- a/src/wrap/python/core.cpp +++ b/src/wrap/python/core.cpp @@ -6,6 +6,7 @@ #include <botan/init.h> #include <botan/pipe.h> #include <botan/lookup.h> +#include <botan/cryptobox.h> using namespace Botan; #include "python_botan.h" @@ -33,6 +34,7 @@ class Python_RandomNumberGenerator void add_entropy(const std::string& in) { rng->add_entropy(reinterpret_cast<const byte*>(in.c_str()), in.length()); } + RandomNumberGenerator& get_underlying_rng() { return *rng; } private: RandomNumberGenerator* rng; }; @@ -163,6 +165,25 @@ class Py_MAC MessageAuthenticationCode* mac; }; +std::string cryptobox_encrypt(const std::string& in, + const std::string& passphrase, + Python_RandomNumberGenerator& rng) + { + const byte* in_bytes = reinterpret_cast<const byte*>(in.data()); + + return CryptoBox::encrypt(in_bytes, in.size(), + passphrase, rng.get_underlying_rng()); + } + +std::string cryptobox_decrypt(const std::string& in, + const std::string& passphrase) + { + const byte* in_bytes = reinterpret_cast<const byte*>(in.data()); + + return CryptoBox::decrypt(in_bytes, in.size(), + passphrase); + } + BOOST_PYTHON_MODULE(_botan) { python::class_<LibraryInitializer>("LibraryInitializer") @@ -197,6 +218,9 @@ BOOST_PYTHON_MODULE(_botan) .def("name", &Py_MAC::name) .def("output_length", &Py_MAC::output_length); + python::def("cryptobox_encrypt", cryptobox_encrypt); + python::def("cryptobox_decrypt", cryptobox_decrypt); + export_filters(); export_pk(); export_x509(); |