diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/build-data/oids.txt | 1 | ||||
-rw-r--r-- | src/lib/asn1/oid_maps.cpp | 3 | ||||
-rw-r--r-- | src/lib/ffi/ffi_pkey_algs.cpp | 36 | ||||
-rw-r--r-- | src/lib/pubkey/pk_algs.cpp | 22 | ||||
-rw-r--r-- | src/lib/pubkey/sm2/info.txt | 2 | ||||
-rw-r--r-- | src/lib/pubkey/sm2/sm2.cpp | 35 | ||||
-rw-r--r-- | src/lib/pubkey/sm2/sm2.h | 50 | ||||
-rw-r--r-- | src/lib/pubkey/sm2/sm2_enc.cpp | 40 | ||||
-rw-r--r-- | src/lib/pubkey/sm2/sm2_enc.h | 79 | ||||
-rw-r--r-- | src/lib/utils/types.h | 2 | ||||
-rw-r--r-- | src/tests/test_ffi.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_sm2.cpp | 24 |
12 files changed, 101 insertions, 197 deletions
diff --git a/src/build-data/oids.txt b/src/build-data/oids.txt index a918436cd..feea6ef7d 100644 --- a/src/build-data/oids.txt +++ b/src/build-data/oids.txt @@ -21,6 +21,7 @@ 1.3.132.1.12 = ECDH 1.2.156.10197.1.301.1 = SM2_Sig +1.2.156.10197.1.301.1 = SM2 1.2.156.10197.1.301.2 = SM2_Kex 1.2.156.10197.1.301.3 = SM2_Enc diff --git a/src/lib/asn1/oid_maps.cpp b/src/lib/asn1/oid_maps.cpp index e9c55706e..eb4e570db 100644 --- a/src/lib/asn1/oid_maps.cpp +++ b/src/lib/asn1/oid_maps.cpp @@ -24,7 +24,7 @@ std::unordered_map<std::string, std::string> OIDS::load_oid2str_map() { "1.2.156.10197.1.104.2", "SM4/CBC" }, { "1.2.156.10197.1.104.8", "SM4/GCM" }, { "1.2.156.10197.1.301", "sm2p256v1" }, - { "1.2.156.10197.1.301.1", "SM2_Sig" }, + { "1.2.156.10197.1.301.1", "SM2" }, { "1.2.156.10197.1.301.2", "SM2_Kex" }, { "1.2.156.10197.1.301.3", "SM2_Enc" }, { "1.2.156.10197.1.401", "SM3" }, @@ -367,6 +367,7 @@ std::unordered_map<std::string, OID> OIDS::load_str2oid_map() { "SHA-512-256", OID({2,16,840,1,101,3,4,2,6}) }, { "SHAKE-128", OID({2,16,840,1,101,3,4,2,11}) }, { "SHAKE-256", OID({2,16,840,1,101,3,4,2,12}) }, + { "SM2", OID({1,2,156,10197,1,301,1}) }, { "SM2_Enc", OID({1,2,156,10197,1,301,3}) }, { "SM2_Kex", OID({1,2,156,10197,1,301,2}) }, { "SM2_Sig", OID({1,2,156,10197,1,301,1}) }, 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 */ diff --git a/src/lib/pubkey/pk_algs.cpp b/src/lib/pubkey/pk_algs.cpp index 89ef7c708..9ea89c59f 100644 --- a/src/lib/pubkey/pk_algs.cpp +++ b/src/lib/pubkey/pk_algs.cpp @@ -71,7 +71,6 @@ #if defined(BOTAN_HAS_SM2) #include <botan/sm2.h> - #include <botan/sm2_enc.h> #endif #if defined(BOTAN_HAS_OPENSSL) @@ -152,10 +151,8 @@ load_public_key(const AlgorithmIdentifier& alg_id, #endif #if defined(BOTAN_HAS_SM2) - if(alg_name == "SM2_Sig") - return std::unique_ptr<Public_Key>(new SM2_Signature_PublicKey(alg_id, key_bits)); - if(alg_name == "SM2_Enc") - return std::unique_ptr<Public_Key>(new SM2_Encryption_PublicKey(alg_id, key_bits)); + if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") + return std::unique_ptr<Public_Key>(new SM2_PublicKey(alg_id, key_bits)); #endif #if defined(BOTAN_HAS_XMSS) @@ -230,10 +227,8 @@ load_private_key(const AlgorithmIdentifier& alg_id, #endif #if defined(BOTAN_HAS_SM2) - if(alg_name == "SM2_Sig") - return std::unique_ptr<Private_Key>(new SM2_Signature_PrivateKey(alg_id, key_bits)); - if(alg_name == "SM2_Enc") - return std::unique_ptr<Private_Key>(new SM2_Encryption_PrivateKey(alg_id, key_bits)); + if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") + return std::unique_ptr<Private_Key>(new SM2_PrivateKey(alg_id, key_bits)); #endif #if defined(BOTAN_HAS_ELGAMAL) @@ -255,7 +250,7 @@ namespace { std::string default_ec_group_for(const std::string& alg_name) { - if(alg_name == "SM2_Enc" || alg_name == "SM2_Sig") + if(alg_name == "SM2" || alg_name == "SM2_Enc" || alg_name == "SM2_Sig") return "sm2p256v1"; if(alg_name == "GOST-34.10") return "gost_256A"; @@ -341,6 +336,7 @@ create_private_key(const std::string& alg_name, alg_name == "ECDH" || alg_name == "ECKCDSA" || alg_name == "ECGDSA" || + alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc" || alg_name == "GOST-34.10") @@ -368,10 +364,8 @@ create_private_key(const std::string& alg_name, #endif #if defined(BOTAN_HAS_SM2) - if(alg_name == "SM2_Sig") - return std::unique_ptr<Private_Key>(new SM2_Signature_PrivateKey(rng, ec_group)); - if(alg_name == "SM2_Enc") - return std::unique_ptr<Private_Key>(new SM2_Encryption_PrivateKey(rng, ec_group)); + if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") + return std::unique_ptr<Private_Key>(new SM2_PrivateKey(rng, ec_group)); #endif #if defined(BOTAN_HAS_ECGDSA) diff --git a/src/lib/pubkey/sm2/info.txt b/src/lib/pubkey/sm2/info.txt index b4475525d..a3f756820 100644 --- a/src/lib/pubkey/sm2/info.txt +++ b/src/lib/pubkey/sm2/info.txt @@ -1,5 +1,5 @@ <defines> -SM2 -> 20170907 +SM2 -> 20180801 </defines> <requires> diff --git a/src/lib/pubkey/sm2/sm2.cpp b/src/lib/pubkey/sm2/sm2.cpp index 1096ea99f..c042693b3 100644 --- a/src/lib/pubkey/sm2/sm2.cpp +++ b/src/lib/pubkey/sm2/sm2.cpp @@ -15,8 +15,13 @@ namespace Botan { -bool SM2_Signature_PrivateKey::check_key(RandomNumberGenerator& rng, - bool strong) const +std::string SM2_PublicKey::algo_name() const + { + return "SM2"; + } + +bool SM2_PrivateKey::check_key(RandomNumberGenerator& rng, + bool strong) const { if(!public_point().on_the_curve()) return false; @@ -24,19 +29,19 @@ bool SM2_Signature_PrivateKey::check_key(RandomNumberGenerator& rng, if(!strong) return true; - return KeyPair::signature_consistency_check(rng, *this, "SM3"); + return KeyPair::signature_consistency_check(rng, *this, "[email protected],SM3"); } -SM2_Signature_PrivateKey::SM2_Signature_PrivateKey(const AlgorithmIdentifier& alg_id, - const secure_vector<uint8_t>& key_bits) : +SM2_PrivateKey::SM2_PrivateKey(const AlgorithmIdentifier& alg_id, + const secure_vector<uint8_t>& key_bits) : EC_PrivateKey(alg_id, key_bits) { m_da_inv = domain().inverse_mod_order(m_private_key + 1); } -SM2_Signature_PrivateKey::SM2_Signature_PrivateKey(RandomNumberGenerator& rng, - const EC_Group& domain, - const BigInt& x) : +SM2_PrivateKey::SM2_PrivateKey(RandomNumberGenerator& rng, + const EC_Group& domain, + const BigInt& x) : EC_PrivateKey(rng, domain, x) { m_da_inv = domain.inverse_mod_order(m_private_key + 1); @@ -80,7 +85,7 @@ class SM2_Signature_Operation final : public PK_Ops::Signature { public: - SM2_Signature_Operation(const SM2_Signature_PrivateKey& sm2, + SM2_Signature_Operation(const SM2_PrivateKey& sm2, const std::string& ident, const std::string& hash) : m_group(sm2.domain()), @@ -133,7 +138,7 @@ SM2_Signature_Operation::sign(RandomNumberGenerator& rng) class SM2_Verification_Operation final : public PK_Ops::Verification { public: - SM2_Verification_Operation(const SM2_Signature_PublicKey& sm2, + SM2_Verification_Operation(const SM2_PublicKey& sm2, const std::string& ident, const std::string& hash) : m_group(sm2.domain()), @@ -191,8 +196,8 @@ bool SM2_Verification_Operation::is_valid_signature(const uint8_t sig[], size_t } std::unique_ptr<PK_Ops::Verification> -SM2_Signature_PublicKey::create_verification_op(const std::string& params, - const std::string& provider) const +SM2_PublicKey::create_verification_op(const std::string& params, + const std::string& provider) const { if(provider == "base" || provider.empty()) { @@ -221,9 +226,9 @@ SM2_Signature_PublicKey::create_verification_op(const std::string& params, } std::unique_ptr<PK_Ops::Signature> -SM2_Signature_PrivateKey::create_signature_op(RandomNumberGenerator& /*rng*/, - const std::string& params, - const std::string& provider) const +SM2_PrivateKey::create_signature_op(RandomNumberGenerator& /*rng*/, + const std::string& params, + const std::string& provider) const { if(provider == "base" || provider.empty()) { diff --git a/src/lib/pubkey/sm2/sm2.h b/src/lib/pubkey/sm2/sm2.h index c6895cd6a..7b5f38858 100644 --- a/src/lib/pubkey/sm2/sm2.h +++ b/src/lib/pubkey/sm2/sm2.h @@ -13,9 +13,9 @@ namespace Botan { /** -* This class represents SM2 Signature public keys +* This class represents SM2 public keys */ -class BOTAN_PUBLIC_API(2,2) SM2_Signature_PublicKey : public virtual EC_PublicKey +class BOTAN_PUBLIC_API(2,2) SM2_PublicKey : public virtual EC_PublicKey { public: @@ -24,8 +24,8 @@ class BOTAN_PUBLIC_API(2,2) SM2_Signature_PublicKey : public virtual EC_PublicKe * @param dom_par the domain parameters associated with this key * @param public_point the public point defining this key */ - SM2_Signature_PublicKey(const EC_Group& dom_par, - const PointGFp& public_point) : + SM2_PublicKey(const EC_Group& dom_par, + const PointGFp& public_point) : EC_PublicKey(dom_par, public_point) {} /** @@ -33,15 +33,15 @@ class BOTAN_PUBLIC_API(2,2) SM2_Signature_PublicKey : public virtual EC_PublicKe * @param alg_id the X.509 algorithm identifier * @param key_bits DER encoded public key bits */ - SM2_Signature_PublicKey(const AlgorithmIdentifier& alg_id, - const std::vector<uint8_t>& key_bits) : + SM2_PublicKey(const AlgorithmIdentifier& alg_id, + const std::vector<uint8_t>& key_bits) : EC_PublicKey(alg_id, key_bits) {} /** * Get this keys algorithm name. * @result this keys algorithm name */ - std::string algo_name() const override { return "SM2_Sig"; } + std::string algo_name() const override; size_t message_parts() const override { return 2; } @@ -51,15 +51,21 @@ class BOTAN_PUBLIC_API(2,2) SM2_Signature_PublicKey : public virtual EC_PublicKe std::unique_ptr<PK_Ops::Verification> create_verification_op(const std::string& params, const std::string& provider) const override; + + std::unique_ptr<PK_Ops::Encryption> + create_encryption_op(RandomNumberGenerator& rng, + const std::string& params, + const std::string& provider) const override; + protected: - SM2_Signature_PublicKey() = default; + SM2_PublicKey() = default; }; /** -* This class represents SM2 Signature private keys +* This class represents SM2 private keys */ -class BOTAN_PUBLIC_API(2,2) SM2_Signature_PrivateKey final : - public SM2_Signature_PublicKey, public EC_PrivateKey +class BOTAN_PUBLIC_API(2,2) SM2_PrivateKey final : + public SM2_PublicKey, public EC_PrivateKey { public: @@ -68,8 +74,8 @@ class BOTAN_PUBLIC_API(2,2) SM2_Signature_PrivateKey final : * @param alg_id the X.509 algorithm identifier * @param key_bits ECPrivateKey bits */ - SM2_Signature_PrivateKey(const AlgorithmIdentifier& alg_id, - const secure_vector<uint8_t>& key_bits); + SM2_PrivateKey(const AlgorithmIdentifier& alg_id, + const secure_vector<uint8_t>& key_bits); /** * Create a private key. @@ -77,9 +83,9 @@ class BOTAN_PUBLIC_API(2,2) SM2_Signature_PrivateKey final : * @param domain parameters to used for this key * @param x the private key (if zero, generate a new random key) */ - SM2_Signature_PrivateKey(RandomNumberGenerator& rng, - const EC_Group& domain, - const BigInt& x = 0); + SM2_PrivateKey(RandomNumberGenerator& rng, + const EC_Group& domain, + const BigInt& x = 0); bool check_key(RandomNumberGenerator& rng, bool) const override; @@ -88,6 +94,11 @@ class BOTAN_PUBLIC_API(2,2) SM2_Signature_PrivateKey final : const std::string& params, const std::string& provider) const override; + std::unique_ptr<PK_Ops::Decryption> + create_decryption_op(RandomNumberGenerator& rng, + const std::string& params, + const std::string& provider) const override; + const BigInt& get_da_inv() const { return m_da_inv; } private: BigInt m_da_inv; @@ -101,6 +112,13 @@ BOTAN_PUBLIC_API(2,5) sm2_compute_za(HashFunction& hash, const EC_Group& domain, const PointGFp& pubkey); +// For compat with versions 2.2 - 2.7 +typedef SM2_PublicKey SM2_Signature_PublicKey; +typedef SM2_PublicKey SM2_Encryption_PublicKey; + +typedef SM2_PrivateKey SM2_Signature_PrivateKey; +typedef SM2_PrivateKey SM2_Encryption_PrivateKey; + } #endif diff --git a/src/lib/pubkey/sm2/sm2_enc.cpp b/src/lib/pubkey/sm2/sm2_enc.cpp index 4d27ec40b..3da4275b3 100644 --- a/src/lib/pubkey/sm2/sm2_enc.cpp +++ b/src/lib/pubkey/sm2/sm2_enc.cpp @@ -5,10 +5,9 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/sm2_enc.h> +#include <botan/sm2.h> #include <botan/internal/point_mul.h> #include <botan/pk_ops.h> -#include <botan/keypair.h> #include <botan/der_enc.h> #include <botan/ber_dec.h> #include <botan/kdf.h> @@ -16,31 +15,6 @@ namespace Botan { -bool SM2_Encryption_PrivateKey::check_key(RandomNumberGenerator& rng, - bool strong) const - { - if(!public_point().on_the_curve()) - return false; - - if(!strong) - return true; - - return KeyPair::encryption_consistency_check(rng, *this, "SM3"); - } - -SM2_Encryption_PrivateKey::SM2_Encryption_PrivateKey(const AlgorithmIdentifier& alg_id, - const secure_vector<uint8_t>& key_bits) : - EC_PrivateKey(alg_id, key_bits) - { - } - -SM2_Encryption_PrivateKey::SM2_Encryption_PrivateKey(RandomNumberGenerator& rng, - const EC_Group& domain, - const BigInt& x) : - EC_PrivateKey(rng, domain, x) - { - } - namespace { class SM2_Encryption_Operation final : public PK_Ops::Encryption @@ -233,9 +207,9 @@ class SM2_Decryption_Operation final : public PK_Ops::Decryption } std::unique_ptr<PK_Ops::Encryption> -SM2_Encryption_PublicKey::create_encryption_op(RandomNumberGenerator& rng, - const std::string& params, - const std::string& provider) const +SM2_PublicKey::create_encryption_op(RandomNumberGenerator& rng, + const std::string& params, + const std::string& provider) const { if(provider == "base" || provider.empty()) { @@ -247,9 +221,9 @@ SM2_Encryption_PublicKey::create_encryption_op(RandomNumberGenerator& rng, } std::unique_ptr<PK_Ops::Decryption> -SM2_Encryption_PrivateKey::create_decryption_op(RandomNumberGenerator& rng, - const std::string& params, - const std::string& provider) const +SM2_PrivateKey::create_decryption_op(RandomNumberGenerator& rng, + const std::string& params, + const std::string& provider) const { if(provider == "base" || provider.empty()) { diff --git a/src/lib/pubkey/sm2/sm2_enc.h b/src/lib/pubkey/sm2/sm2_enc.h index cc8d2cacb..1384d3726 100644 --- a/src/lib/pubkey/sm2/sm2_enc.h +++ b/src/lib/pubkey/sm2/sm2_enc.h @@ -8,83 +8,6 @@ #ifndef BOTAN_SM2_ENC_KEY_H_ #define BOTAN_SM2_ENC_KEY_H_ -#include <botan/ecc_key.h> - -namespace Botan { - -/** -* This class represents a public key used for SM2 encryption -*/ -class BOTAN_PUBLIC_API(2,2) SM2_Encryption_PublicKey : public virtual EC_PublicKey - { - public: - - /** - * Create a public key from a given public point. - * @param dom_par the domain parameters associated with this key - * @param public_point the public point defining this key - */ - SM2_Encryption_PublicKey(const EC_Group& dom_par, - const PointGFp& public_point) : - EC_PublicKey(dom_par, public_point) {} - - /** - * Load a public key. - * @param alg_id the X.509 algorithm identifier - * @param key_bits DER encoded public key bits - */ - SM2_Encryption_PublicKey(const AlgorithmIdentifier& alg_id, - const std::vector<uint8_t>& key_bits) : - EC_PublicKey(alg_id, key_bits) {} - - /** - * Get this keys algorithm name. - * @result this keys algorithm name - */ - std::string algo_name() const override { return "SM2_Enc"; } - - std::unique_ptr<PK_Ops::Encryption> - create_encryption_op(RandomNumberGenerator& rng, - const std::string& params, - const std::string& provider) const override; - protected: - SM2_Encryption_PublicKey() = default; - }; - -/** -* This class represents a private key used for SM2 encryption -*/ -class BOTAN_PUBLIC_API(2,2) SM2_Encryption_PrivateKey final : - public SM2_Encryption_PublicKey, public EC_PrivateKey - { - public: - - /** - * Load a private key - * @param alg_id the X.509 algorithm identifier - * @param key_bits ECPrivateKey bits - */ - SM2_Encryption_PrivateKey(const AlgorithmIdentifier& alg_id, - const secure_vector<uint8_t>& key_bits); - - /** - * Create a private key. - * @param rng a random number generator - * @param domain parameters to used for this key - * @param x the private key (if zero, generate a new random key) - */ - SM2_Encryption_PrivateKey(RandomNumberGenerator& rng, - const EC_Group& domain, - const BigInt& x = 0); - - bool check_key(RandomNumberGenerator& rng, bool) const override; - - std::unique_ptr<PK_Ops::Decryption> - create_decryption_op(RandomNumberGenerator& rng, - const std::string& params, - const std::string& provider) const override; - }; - -} +#include <botan/sm2.h> #endif diff --git a/src/lib/utils/types.h b/src/lib/utils/types.h index 51f0e3bc3..e25682a2f 100644 --- a/src/lib/utils/types.h +++ b/src/lib/utils/types.h @@ -56,7 +56,7 @@ namespace Botan { * <dt>Public Key Cryptosystems<dd> * @ref dlies.h "DLIES", @ref ecies.h "ECIES", @ref elgamal.h "ElGamal" * @ref rsa.h "RSA", @ref newhope.h "NewHope", @ref mceliece.h "McEliece" and @ref mceies.h "MCEIES", -* @ref sm2_enc.h "SM2" +* @ref sm2.h "SM2" * <dt>Public Key Signature Schemes<dd> * @ref dsa.h "DSA", @ref ecdsa.h "ECDSA", @ref ecgdsa.h "ECGDSA", @ref eckcdsa.h "ECKCDSA", * @ref gost_3410.h "GOST 34.10-2001", @ref sm2.h "SM2", @ref xmss.h "XMSS" diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index 8f3639ad4..ac21c1889 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -1723,7 +1723,7 @@ class FFI_Unit_Tests final : public Test size_t name_len = sizeof(namebuf); TEST_FFI_OK(botan_pubkey_algo_name, (pub, &namebuf[0], &name_len)); - result.test_eq(namebuf, namebuf, "SM2_Sig"); + result.test_eq(namebuf, namebuf, "SM2"); std::vector<uint8_t> message(1280), signature; TEST_FFI_OK(botan_rng_get, (rng, message.data(), message.size())); @@ -1814,7 +1814,7 @@ class FFI_Unit_Tests final : public Test size_t name_len = sizeof(namebuf); TEST_FFI_OK(botan_pubkey_algo_name, (pub, &namebuf[0], &name_len)); - result.test_eq(namebuf, namebuf, "SM2_Enc"); + result.test_eq(namebuf, namebuf, "SM2"); std::vector<uint8_t> message(32); diff --git a/src/tests/test_sm2.cpp b/src/tests/test_sm2.cpp index 0c5a62c46..24e5c640d 100644 --- a/src/tests/test_sm2.cpp +++ b/src/tests/test_sm2.cpp @@ -9,7 +9,6 @@ #if defined(BOTAN_HAS_SM2) #include <botan/sm2.h> - #include <botan/sm2_enc.h> #include "test_pubkey.h" #endif @@ -19,7 +18,6 @@ namespace Botan_Tests { namespace { -template<typename T> std::unique_ptr<Botan::Private_Key> load_sm2_private_key(const VarMap& vars) { // group params @@ -35,7 +33,7 @@ std::unique_ptr<Botan::Private_Key> load_sm2_private_key(const VarMap& vars) Botan::EC_Group domain(p, a, b, xG, yG, order, cofactor); Botan::Null_RNG null_rng; - return std::unique_ptr<Botan::Private_Key>(new T(null_rng, domain, x)); + return std::unique_ptr<Botan::Private_Key>(new Botan::SM2_PrivateKey(null_rng, domain, x)); } class SM2_Signature_KAT_Tests final : public PK_Signature_Generation_Test @@ -60,7 +58,7 @@ class SM2_Signature_KAT_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - return load_sm2_private_key<Botan::SM2_Signature_PrivateKey>(vars); + return load_sm2_private_key(vars); } }; @@ -90,7 +88,7 @@ class SM2_Encryption_KAT_Tests final : public PK_Encryption_Decryption_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - return load_sm2_private_key<Botan::SM2_Encryption_PrivateKey>(vars); + return load_sm2_private_key(vars); } }; @@ -98,6 +96,22 @@ class SM2_Encryption_KAT_Tests final : public PK_Encryption_Decryption_Test BOTAN_REGISTER_TEST("sm2_enc", SM2_Encryption_KAT_Tests); +class SM2_Keygen_Tests final : public PK_Key_Generation_Test + { + public: + std::vector<std::string> keygen_params() const override + { + return { "secp256r1", "sm2p256v1" }; + } + + std::string algo_name() const override + { + return "SM2"; + } + }; + +BOTAN_REGISTER_TEST("sm2_keygen", SM2_Keygen_Tests); + #endif |