aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ffi/ffi.cpp
diff options
context:
space:
mode:
authorKrzysztof Kwiatkowski <[email protected]>2017-04-14 22:23:34 +0100
committerKrzysztof Kwiatkowski <[email protected]>2017-04-14 22:25:38 +0100
commit70f24fcccb832de6a0d2563306a82f306370033a (patch)
treeebff0c12f6b4051ce7bf6cc32540f1d3e5a3bd10 /src/lib/ffi/ffi.cpp
parentd0e4ce08973dbbc1ed28c85b67371e720e425922 (diff)
Support for ElGamal in FFI interface
* Adds `botan_pubkey_load_elgamal' and `botan_privkey_load_elgamal' functions to FFI interface. * Adds test `ffi_test_elgamal'
Diffstat (limited to 'src/lib/ffi/ffi.cpp')
-rw-r--r--src/lib/ffi/ffi.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp
index 7cf69efb3..8e341d83d 100644
--- a/src/lib/ffi/ffi.cpp
+++ b/src/lib/ffi/ffi.cpp
@@ -26,6 +26,7 @@
#include <botan/reducer.h>
#include <botan/numthry.h>
#include <botan/divide.h>
+#include <botan/elgamal.h>
#include <cstring>
#include <memory>
@@ -1422,6 +1423,57 @@ int botan_pubkey_load_dsa(botan_pubkey_t* key,
#endif
}
+int botan_pubkey_load_elgamal(botan_pubkey_t* key,
+ botan_mp_t p, botan_mp_t g, botan_mp_t y)
+ {
+#if defined(BOTAN_HAS_ELGAMAL)
+ *key = nullptr;
+ try
+ {
+ Botan::DL_Group group(safe_get(p), safe_get(g));
+ *key = new botan_pubkey_struct(new Botan::ElGamal_PublicKey(group, safe_get(y)));
+ return 0;
+ }
+ catch(std::exception& exn)
+ {
+ log_exception(BOTAN_CURRENT_FUNCTION, exn.what());
+ }
+
+ return -1;
+#else
+ BOTAN_UNUSED(p);
+ BOTAN_UNUSED(q);
+ BOTAN_UNUSED(g);
+ BOTAN_UNUSED(x);
+ return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
+#endif
+ }
+
+int botan_privkey_load_elgamal(botan_privkey_t* key,
+ botan_mp_t p, botan_mp_t g, botan_mp_t x)
+ {
+#if defined(BOTAN_HAS_ELGAMAL)
+ *key = nullptr;
+ try
+ {
+ Botan::Null_RNG null_rng;
+ Botan::DL_Group group(safe_get(p), safe_get(g));
+ *key = new botan_privkey_struct(new Botan::ElGamal_PrivateKey(null_rng, group, safe_get(x)));
+ return 0;
+ }
+ catch(std::exception& e)
+ {
+ log_exception(BOTAN_CURRENT_FUNCTION, e.what());
+ }
+ return -1;
+#else
+ BOTAN_UNUSED(p);
+ BOTAN_UNUSED(g);
+ BOTAN_UNUSED(x);
+ return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
+#endif
+ }
+
namespace {
Botan::BigInt botan_pubkey_do_get_field(const Botan::Public_Key& key,