aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ffi/ffi_pkey_algs.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-08-01 20:19:38 -0400
committerJack Lloyd <[email protected]>2018-08-01 20:19:38 -0400
commitd17dbed547765739e1885bde33b0165795bcbd72 (patch)
tree4541ace57656daffcc1f17f04cd6656a9ded67e9 /src/lib/ffi/ffi_pkey_algs.cpp
parent2504351f6df8ff07df131dcee3248f4b9595e2d7 (diff)
Combine SM2 key types for signatures and encryption
It seems in practice the same key may be end up used for both operations, so maintaining a distinction at the type level just complicates things.
Diffstat (limited to 'src/lib/ffi/ffi_pkey_algs.cpp')
-rw-r--r--src/lib/ffi/ffi_pkey_algs.cpp36
1 files changed, 5 insertions, 31 deletions
diff --git a/src/lib/ffi/ffi_pkey_algs.cpp b/src/lib/ffi/ffi_pkey_algs.cpp
index d9388afee..622da7a14 100644
--- a/src/lib/ffi/ffi_pkey_algs.cpp
+++ b/src/lib/ffi/ffi_pkey_algs.cpp
@@ -40,7 +40,6 @@
#if defined(BOTAN_HAS_SM2)
#include <botan/sm2.h>
- #include <botan/sm2_enc.h>
#endif
#if defined(BOTAN_HAS_ECDH)
@@ -690,7 +689,7 @@ int botan_pubkey_sm2_compute_za(uint8_t out[],
if(ec_key == nullptr)
return BOTAN_FFI_ERROR_BAD_PARAMETER;
- if(ec_key->algo_name() != "SM2_Sig" && ec_key->algo_name() != "SM2_Enc")
+ if(ec_key->algo_name() != "SM2")
return BOTAN_FFI_ERROR_BAD_PARAMETER;
const std::string ident_str(ident);
@@ -714,7 +713,7 @@ int botan_pubkey_load_sm2(botan_pubkey_t* key,
{
#if defined(BOTAN_HAS_SM2)
return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
- std::unique_ptr<Botan::SM2_Signature_PublicKey> p_key;
+ std::unique_ptr<Botan::SM2_PublicKey> p_key;
if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
{
*key = new botan_pubkey_struct(p_key.release());
@@ -734,7 +733,7 @@ int botan_privkey_load_sm2(botan_privkey_t* key,
{
#if defined(BOTAN_HAS_SM2)
return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
- std::unique_ptr<Botan::SM2_Signature_PrivateKey> p_key;
+ std::unique_ptr<Botan::SM2_PrivateKey> p_key;
int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
if(rc == BOTAN_FFI_SUCCESS)
@@ -752,39 +751,14 @@ int botan_pubkey_load_sm2_enc(botan_pubkey_t* key,
const botan_mp_t public_y,
const char* curve_name)
{
-#if defined(BOTAN_HAS_SM2)
- return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
- std::unique_ptr<Botan::SM2_Encryption_PublicKey> p_key;
- if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
- {
- *key = new botan_pubkey_struct(p_key.release());
- return BOTAN_FFI_SUCCESS;
- }
- return BOTAN_FFI_ERROR_UNKNOWN_ERROR;
- });
-#else
- BOTAN_UNUSED(key, public_x, public_y, curve_name);
- return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
-#endif
+ return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
}
int botan_privkey_load_sm2_enc(botan_privkey_t* key,
const botan_mp_t scalar,
const char* curve_name)
{
-#if defined(BOTAN_HAS_SM2)
- return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
- std::unique_ptr<Botan::SM2_Encryption_PrivateKey> p_key;
- int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
-
- if(rc == BOTAN_FFI_SUCCESS)
- *key = new botan_privkey_struct(p_key.release());
- return rc;
- });
-#else
- BOTAN_UNUSED(key, scalar, curve_name);
- return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
-#endif
+ return botan_privkey_load_sm2(key, scalar, curve_name);
}
/* Ed25519 specific operations */