aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ffi
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-03-01 16:47:44 +0000
committerlloyd <[email protected]>2015-03-01 16:47:44 +0000
commit38cc1747b615081539893aa6c8bc02e6e1960d25 (patch)
treec504fc297905f434a5c1dd5a359412b5e8d4bf1b /src/lib/ffi
parenta9aebb6c08eb7d78a62283c33ece17b73e7c2f8c (diff)
Fix decrypt in FFI/Python. Github issue 53
Diffstat (limited to 'src/lib/ffi')
-rw-r--r--src/lib/ffi/ffi.cpp4
-rw-r--r--src/lib/ffi/ffi.h4
2 files changed, 7 insertions, 1 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp
index 6c29a6f7e..c5a862200 100644
--- a/src/lib/ffi/ffi.cpp
+++ b/src/lib/ffi/ffi.cpp
@@ -393,7 +393,8 @@ int botan_cipher_init(botan_cipher_t* cipher, const char* cipher_name, uint32_t
{
try
{
- Botan::Cipher_Dir dir = (flags & 0) ? Botan::DECRYPTION : Botan::ENCRYPTION;
+ const bool encrypt_p = ((flags & BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION) == BOTAN_CIPHER_INIT_FLAG_ENCRYPT);
+ const Botan::Cipher_Dir dir = encrypt_p ? Botan::ENCRYPTION : Botan::DECRYPTION;
std::unique_ptr<Botan::Cipher_Mode> mode(Botan::get_cipher_mode(cipher_name, dir));
if(!mode)
return -1;
@@ -469,6 +470,7 @@ int botan_cipher_update(botan_cipher_t cipher_obj,
{
mbuf.assign(input, input + input_size);
*input_consumed = input_size;
+ *output_written = 0;
try
{
diff --git a/src/lib/ffi/ffi.h b/src/lib/ffi/ffi.h
index 9ba02f02c..b4e99defd 100644
--- a/src/lib/ffi/ffi.h
+++ b/src/lib/ffi/ffi.h
@@ -90,6 +90,10 @@ BOTAN_DLL int botan_mac_destroy(botan_mac_t mac);
*/
typedef struct botan_cipher_struct* botan_cipher_t;
+#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION 1
+#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT 0
+#define BOTAN_CIPHER_INIT_FLAG_DECRYPT 1
+
BOTAN_DLL int botan_cipher_init(botan_cipher_t* cipher, const char* name, uint32_t flags);
BOTAN_DLL int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl);