aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/examples/cipher.py
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-02-16 20:12:38 +0000
committerlloyd <[email protected]>2015-02-16 20:12:38 +0000
commit3b9a0c1535e40f8f9fc4cfbc734144ee229df65d (patch)
tree30c1d4363b4c85561204d26344f40de3e78f6d9d /src/scripts/examples/cipher.py
parent85caef829c9eeb7c224ad3b2e3ffbcfe981c2428 (diff)
Add new module `ffi` which provides a plain C interface, plus a new
ctypes Python wrapper that uses it. The API is intentionally designed to have a very simple ABI (extern "C", all structs are opaque, no memory ownership passing the FFI boundary, limited set of simple types as args) so the ctypes wrapper is quite simple. Currently ffi provides ciphers, hashes, MACs, RNGs, PBKDF, KDF, bcrypt, and most public key operations. Remove the old boost.python wrapper and all the build code for it.
Diffstat (limited to 'src/scripts/examples/cipher.py')
-rwxr-xr-xsrc/scripts/examples/cipher.py44
1 files changed, 0 insertions, 44 deletions
diff --git a/src/scripts/examples/cipher.py b/src/scripts/examples/cipher.py
deleted file mode 100755
index 1be2759ae..000000000
--- a/src/scripts/examples/cipher.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/usr/bin/python
-
-import botan
-import sys
-
-def encrypt(input, passphrase):
- rng = botan.RandomNumberGenerator()
-
- # Use as both EAX IV and PBKDF2 salt
- salt = rng.gen_random(10)
-
- iterations = 10000
- output_size = 16
-
- key = botan.pbkdf2(passphrase, salt, iterations, output_size, "SHA-1")
-
- encryptor = botan.Cipher("AES-128/EAX", "encrypt", key)
-
- ciphertext = encryptor.cipher(input, salt)
- return (ciphertext, salt)
-
-def decrypt(input, salt, passphrase):
- iterations = 10000
- output_size = 16
-
- key = botan.pbkdf2(passphrase, salt, iterations, output_size, "SHA-1")
-
- decryptor = botan.Cipher("AES-128/EAX", "decrypt", key)
-
- return decryptor.cipher(input, salt)
-
-def main(args = None):
- if args is None:
- args = sys.argv
-
- passphrase = args[1]
- input = ''.join(open(args[2]).readlines())
-
- (ciphertext, salt) = encrypt(input, passphrase)
-
- print decrypt(ciphertext, salt, passphrase)
-
-if __name__ == '__main__':
- sys.exit(main())