diff options
author | lloyd <[email protected]> | 2015-02-24 00:20:57 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-02-24 00:20:57 +0000 |
commit | 2cfcd2ebddcb19647938fffc412fb468608ea89d (patch) | |
tree | 7fc5e956485566977d71f77525f8c1beafe91f9a | |
parent | b5f4a08f22806a738332fe1d8ee984686b883b98 (diff) |
FFI header cleanup, small Python additions
-rw-r--r-- | src/lib/ffi/ffi.h | 26 | ||||
-rwxr-xr-x | src/python/botan.py | 22 |
2 files changed, 35 insertions, 13 deletions
diff --git a/src/lib/ffi/ffi.h b/src/lib/ffi/ffi.h index 4b4d5904d..9ba02f02c 100644 --- a/src/lib/ffi/ffi.h +++ b/src/lib/ffi/ffi.h @@ -166,7 +166,6 @@ BOTAN_DLL int botan_bcrypt_is_valid(const char* pass, const char* hash); /* * Public/private key creation, import, ... */ -typedef struct botan_pubkey_struct* botan_pubkey_t; typedef struct botan_privkey_struct* botan_privkey_t; BOTAN_DLL int botan_privkey_create_rsa(botan_privkey_t* key, botan_rng_t rng, size_t n_bits); @@ -178,17 +177,12 @@ BOTAN_DLL int botan_privkey_create_ecdh(botan_privkey_t* key, botan_rng_t rng, c /* * Input currently assumed to be PKCS #8 structure; +* Set password to NULL to indicate no encryption expected */ BOTAN_DLL int botan_privkey_load(botan_privkey_t* key, botan_rng_t rng, const uint8_t bits[], size_t len, const char* password); -BOTAN_DLL int botan_pubkey_load(botan_privkey_t* key, - const uint8_t bits[], size_t len, - const char* password); - -BOTAN_DLL int botan_privkey_export_pubkey(botan_pubkey_t* out, botan_privkey_t in); -BOTAN_DLL int botan_pubkey_destroy(botan_privkey_t key); BOTAN_DLL int botan_privkey_destroy(botan_privkey_t key); #define BOTAN_PRIVKEY_EXPORT_FLAG_DER 0 @@ -201,11 +195,12 @@ BOTAN_DLL int botan_privkey_destroy(botan_privkey_t key); * Returns 0 on success and sets * If some other error occurs a negative integer is returned. */ -BOTAN_DLL int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint32_t flags); -BOTAN_DLL int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t* out_len, uint32_t flags); +BOTAN_DLL int botan_privkey_export(botan_privkey_t key, + uint8_t out[], size_t* out_len, + uint32_t flags); /* -* Set encryption_algo to NULL to have the library choose a default (recommended) +* Set encryption_algo to NULL or "" to have the library choose a default (recommended) */ BOTAN_DLL int botan_privkey_export_encrypted(botan_privkey_t key, uint8_t out[], size_t* out_len, @@ -214,6 +209,14 @@ BOTAN_DLL int botan_privkey_export_encrypted(botan_privkey_t key, const char* encryption_algo, uint32_t flags); +typedef struct botan_pubkey_struct* botan_pubkey_t; + +BOTAN_DLL int botan_pubkey_load(botan_pubkey_t* key, const uint8_t bits[], size_t len); + +BOTAN_DLL int botan_privkey_export_pubkey(botan_pubkey_t* out, botan_privkey_t in); + +BOTAN_DLL int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint32_t flags); + BOTAN_DLL int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t* out_len); BOTAN_DLL int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t* estimate); @@ -221,6 +224,9 @@ BOTAN_DLL int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t* estima BOTAN_DLL int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash, uint8_t out[], size_t* out_len); +BOTAN_DLL int botan_pubkey_destroy(botan_privkey_t key); + + /* * Public Key Encryption */ diff --git a/src/python/botan.py b/src/python/botan.py index 815d86a87..919a426b7 100755 --- a/src/python/botan.py +++ b/src/python/botan.py @@ -287,6 +287,21 @@ class public_key(object): botan.botan_pubkey_destroy.argtypes = [c_void_p] botan.botan_pubkey_destroy(self.pubkey) + def estimated_strength(self): + botan.botan_pubkey_estimated_strength.argtypes = [c_void_p, POINTER(c_size_t)] + r = c_size_t(0) + botan.botan_pubkey_estimated_strength(self.pubkey, byref(r)) + return r.value + + def algo_name(self): + botan.botan_pubkey_algo_name.argtypes = [c_void_p, POINTER(c_char), POINTER(c_size_t)] + + buf = create_string_buffer(64) + buf_len = c_size_t(len(buf)) + botan.botan_pubkey_algo_name(self.pubkey, buf, byref(buf_len)) + assert buf_len.value <= len(buf) + return buf.raw[0:buf_len.value] + def fingerprint(self, hash = 'SHA-256'): botan.botan_pubkey_fingerprint.argtypes = [c_void_p, c_char_p, POINTER(c_char), POINTER(c_size_t)] @@ -485,13 +500,13 @@ def test(): print kdf('KDF2(SHA-1)', '701F3480DFE95F57941F804B1B2413EF'.decode('hex'), 7, '55A4E9DD5F4CA2EF82'.decode('hex')).encode('hex') - print pbkdf('PBKDF2(SHA-1)', '', 32, 10000, '0001020304050607'.decode('hex')).encode('hex').upper() + print pbkdf('PBKDF2(SHA-1)', '', 32, 10000, '0001020304050607'.decode('hex'))[2].encode('hex').upper() print '59B2B1143B4CB1059EC58D9722FB1C72471E0D85C6F7543BA5228526375B0127' - (salt,iterations,psk) = pbkdf_timed('PBKDF2(SHA-256)', 'xyz', 32, r, 200, 12) + (salt,iterations,psk) = pbkdf_timed('PBKDF2(SHA-256)', 'xyz', 32, 200) print salt.encode('hex'), iterations print 'x', psk.encode('hex') - print 'y', pbkdf('PBKDF2(SHA-256)', 'xyz', 32, iterations, salt).encode('hex') + print 'y', pbkdf('PBKDF2(SHA-256)', 'xyz', 32, iterations, salt)[2].encode('hex') print r.get(42).encode('hex'), r.get(13).encode('hex'), r.get(9).encode('hex') @@ -514,6 +529,7 @@ def test(): rsapub = rsapriv.get_public_key() print rsapub.fingerprint("SHA-1") + print rsapub.algo_name(), rsapub.estimated_strength() enc = pk_op_encrypt(rsapub, "EME1(SHA-256)") |