diff options
author | Jack Lloyd <[email protected]> | 2017-03-28 11:49:17 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-03-28 11:49:17 -0400 |
commit | 5b0481cb93745c6b56d923698b164d2289559eb5 (patch) | |
tree | 58dc5291fb57c2a3eac81d88ee05e3a2344367fc /src/lib | |
parent | d4deb86738019033ede184e8d46d9e892c435f6c (diff) | |
parent | e1eb733e9cb94a3e52defa083b2c12925efc5329 (diff) |
Merge GH #944 Add check_key to C API
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/ffi/ffi.cpp | 15 | ||||
-rw-r--r-- | src/lib/ffi/ffi.h | 7 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp index 00d1433b1..9c5b837fb 100644 --- a/src/lib/ffi/ffi.cpp +++ b/src/lib/ffi/ffi.cpp @@ -954,6 +954,21 @@ int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t* out_len) return BOTAN_FFI_DO(Botan::Public_Key, key, k, { return write_str_output(out, out_len, k.algo_name()); }); } +int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags) + { + const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS); + + return BOTAN_FFI_DO(Botan::Public_Key, key, k, + { return (k.check_key(safe_get(rng), strong) == true) ? 0 : 1; }); + } + +int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags) + { + const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS); + return BOTAN_FFI_DO(Botan::Private_Key, key, k, + { return (k.check_key(safe_get(rng), strong) == true) ? 0 : 1; }); + } + int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint32_t flags) { return BOTAN_FFI_DO(Botan::Public_Key, key, k, { diff --git a/src/lib/ffi/ffi.h b/src/lib/ffi/ffi.h index 264c3d24d..8ac9f3c82 100644 --- a/src/lib/ffi/ffi.h +++ b/src/lib/ffi/ffi.h @@ -473,12 +473,15 @@ BOTAN_DLL int botan_privkey_create(botan_privkey_t* key, const char* algo_params, botan_rng_t rng); +#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS 1 + +BOTAN_DLL int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags); + BOTAN_DLL int botan_privkey_create_rsa(botan_privkey_t* key, botan_rng_t rng, size_t n_bits); BOTAN_DLL int botan_privkey_create_ecdsa(botan_privkey_t* key, botan_rng_t rng, const char* params); BOTAN_DLL int botan_privkey_create_ecdh(botan_privkey_t* key, botan_rng_t rng, const char* params); BOTAN_DLL int botan_privkey_create_mceliece(botan_privkey_t* key, botan_rng_t rng, size_t n, size_t t); - /* * Input currently assumed to be PKCS #8 structure; * Set password to NULL to indicate no encryption expected @@ -523,6 +526,8 @@ BOTAN_DLL int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out BOTAN_DLL int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t* out_len); +BOTAN_DLL int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags); + BOTAN_DLL int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t* estimate); BOTAN_DLL int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash, |