aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/lib/ffi/ffi.h1
-rw-r--r--src/lib/ffi/ffi_pkey_algs.cpp18
-rw-r--r--src/tests/test_ffi.cpp23
3 files changed, 35 insertions, 7 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)
diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp
index 53bd7d0e7..974909563 100644
--- a/src/tests/test_ffi.cpp
+++ b/src/tests/test_ffi.cpp
@@ -1300,13 +1300,7 @@ class FFI_Unit_Tests final : public Test
return result;
}
- Test::Result ffi_test_dsa(botan_rng_t rng)
- {
- Test::Result result("FFI DSA");
-
- botan_privkey_t priv;
-
- if(TEST_FFI_OK(botan_privkey_create, (&priv, "DSA", "dsa/jce/1024", rng)))
+ void do_dsa_test(botan_privkey_t priv, botan_rng_t rng, Test::Result &result)
{
TEST_FFI_OK(botan_privkey_check_key, (priv, rng, 0));
@@ -1404,6 +1398,21 @@ class FFI_Unit_Tests final : public Test
TEST_FFI_OK(botan_privkey_destroy, (priv));
}
+ Test::Result ffi_test_dsa(botan_rng_t rng)
+ {
+ Test::Result result("FFI DSA");
+ botan_privkey_t priv;
+
+ if(TEST_FFI_OK(botan_privkey_create, (&priv, "DSA", "dsa/jce/1024", rng)))
+ {
+ do_dsa_test(priv, rng, result);
+ }
+
+ if(TEST_FFI_OK(botan_privkey_create_dsa, (&priv, rng, 1024, 160)))
+ {
+ do_dsa_test(priv, rng, result);
+ }
+
return result;
}
Test::Result ffi_test_ecdsa(botan_rng_t rng)