4
* Botan is released under the Simplified BSD License (see license.txt)
10
#if defined(BOTAN_HAS_SM2)
11
#include <botan/sm2.h>
12
#include <botan/sm2_enc.h>
13
#include "test_pubkey.h"
16
namespace Botan_Tests {
18
#if defined(BOTAN_HAS_SM2)
22
class SM2_Signature_KAT_Tests final : public PK_Signature_Generation_Test
25
SM2_Signature_KAT_Tests()
26
: PK_Signature_Generation_Test(
29
"P,A,B,xG,yG,Order,Cofactor,Ident,Msg,x,Nonce,Signature",
32
std::string default_padding(const VarMap& vars) const override
34
return get_req_str(vars, "Ident") + "," + get_opt_str(vars, "Hash", "SM3");
37
Botan::RandomNumberGenerator* test_rng(const std::vector<uint8_t>& nonce) const override
39
return new Fixed_Output_Position_RNG(nonce, 1);
42
std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override
45
const BigInt p = get_req_bn(vars, "P");
46
const BigInt a = get_req_bn(vars, "A");
47
const BigInt b = get_req_bn(vars, "B");
48
const BigInt xG = get_req_bn(vars, "xG");
49
const BigInt yG = get_req_bn(vars, "yG");
50
const BigInt order = get_req_bn(vars, "Order");
51
const BigInt cofactor = get_req_bn(vars, "Cofactor");
52
const BigInt x = get_req_bn(vars, "x");
54
Botan::CurveGFp curve(p, a, b);
55
Botan::PointGFp base_point(curve, xG, yG);
56
Botan::EC_Group domain(curve, base_point, order, cofactor);
58
Botan::Null_RNG null_rng;
59
std::unique_ptr<Botan::Private_Key> key(new Botan::SM2_Signature_PrivateKey(null_rng, domain, x));
64
BOTAN_REGISTER_TEST("sm2_sig", SM2_Signature_KAT_Tests);
66
class SM2_Encryption_KAT_Tests final : public PK_Encryption_Decryption_Test
69
SM2_Encryption_KAT_Tests()
70
: PK_Encryption_Decryption_Test(
73
"P,A,B,xG,yG,Order,Cofactor,Msg,x,Nonce,Ciphertext",
76
std::string default_padding(const VarMap& vars) const override
78
return get_opt_str(vars, "Hash", "SM3");
81
bool clear_between_callbacks() const override { return false; }
83
Botan::RandomNumberGenerator* test_rng(const std::vector<uint8_t>& nonce) const override
85
return new Fixed_Output_Position_RNG(nonce, 1);
88
std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override
91
const BigInt p = get_req_bn(vars, "P");
92
const BigInt a = get_req_bn(vars, "A");
93
const BigInt b = get_req_bn(vars, "B");
94
const BigInt xG = get_req_bn(vars, "xG");
95
const BigInt yG = get_req_bn(vars, "yG");
96
const BigInt order = get_req_bn(vars, "Order");
97
const BigInt cofactor = get_req_bn(vars, "Cofactor");
98
const BigInt x = get_req_bn(vars, "x");
100
Botan::CurveGFp curve(p, a, b);
101
Botan::PointGFp base_point(curve, xG, yG);
102
Botan::EC_Group domain(curve, base_point, order, cofactor);
104
Botan::Null_RNG null_rng;
105
std::unique_ptr<Botan::Private_Key> key(new Botan::SM2_Encryption_PrivateKey(null_rng, domain, x));
112
BOTAN_REGISTER_TEST("sm2_enc", SM2_Encryption_KAT_Tests);