aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorKrzysztof Kwiatkowski <[email protected]>2018-01-16 23:01:17 +0000
committerKrzysztof Kwiatkowski <[email protected]>2018-01-21 23:35:27 +0000
commit45bda8b0429170036ae30ed5d3133011f9e3fe8a (patch)
treef8be7d45b7995268d9966b59b5f8a5e142f2aef8 /src/lib
parent65f375348c0773af6e9bbe3a005aef177dfd4ac3 (diff)
FFI function for DSA key generation
Adds function for DSA key generation that allows usage of 'p' and 'q' chosen by the caller.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ffi/ffi.h1
-rw-r--r--src/lib/ffi/ffi_pkey_algs.cpp18
2 files changed, 19 insertions, 0 deletions
diff --git a/src/lib/ffi/ffi.h b/src/lib/ffi/ffi.h
index 1a6014f71..77d4eb306 100644
--- a/src/lib/ffi/ffi.h
+++ b/src/lib/ffi/ffi.h
@@ -702,6 +702,7 @@ BOTAN_PUBLIC_API(2,0) int botan_privkey_create_ecdsa(botan_privkey_t* key, botan
BOTAN_PUBLIC_API(2,0) int botan_privkey_create_ecdh(botan_privkey_t* key, botan_rng_t rng, const char* params);
BOTAN_PUBLIC_API(2,0) int botan_privkey_create_mceliece(botan_privkey_t* key, botan_rng_t rng, size_t n, size_t t);
BOTAN_PUBLIC_API(2,0) int botan_privkey_create_dh(botan_privkey_t* key, botan_rng_t rng, const char* param);
+BOTAN_PUBLIC_API(2,0) int botan_privkey_create_dsa(botan_privkey_t* key, botan_rng_t rng, size_t pbits, size_t qbits);
/*
* Input currently assumed to be PKCS #8 structure;
diff --git a/src/lib/ffi/ffi_pkey_algs.cpp b/src/lib/ffi/ffi_pkey_algs.cpp
index 694edfeb3..1a2737834 100644
--- a/src/lib/ffi/ffi_pkey_algs.cpp
+++ b/src/lib/ffi/ffi_pkey_algs.cpp
@@ -333,6 +333,24 @@ int botan_pubkey_rsa_get_n(botan_mp_t n, botan_pubkey_t key)
}
/* DSA specific operations */
+int botan_privkey_create_dsa(botan_privkey_t* key, botan_rng_t rng_obj, size_t pbits, size_t qbits)
+ {
+#if defined(BOTAN_HAS_DSA)
+
+ if(rng_obj == nullptr)
+ return BOTAN_FFI_ERROR_NULL_POINTER;
+
+ return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
+ Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
+ Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
+ *key = new botan_privkey_struct(new Botan::DSA_PrivateKey(rng, group));
+ return BOTAN_FFI_SUCCESS;
+ });
+#else
+ BOTAN_UNUSED(key, rng_obj, pbits, qbits);
+ return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
+#endif
+ }
int botan_privkey_load_dsa(botan_privkey_t* key,
botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t x)