aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_sm2.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-08-04 15:22:33 -0400
committerJack Lloyd <[email protected]>2017-08-04 15:22:33 -0400
commit87fcd69b587ccd60c5f248b40003cf9a0a558a53 (patch)
treec558cab7be5e591a36d74c3f8948c018a1c89bb7 /src/tests/test_sm2.cpp
parent58b1f7cc90b3e5c8a4bbff7adf2c001db0ef4d21 (diff)
Add SM2 encryption scheme
This is a contribution from Ribose Inc (@riboseinc)
Diffstat (limited to 'src/tests/test_sm2.cpp')
-rw-r--r--src/tests/test_sm2.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/tests/test_sm2.cpp b/src/tests/test_sm2.cpp
index c0d272cbd..2b647e2db 100644
--- a/src/tests/test_sm2.cpp
+++ b/src/tests/test_sm2.cpp
@@ -9,6 +9,7 @@
#if defined(BOTAN_HAS_SM2)
#include <botan/sm2.h>
+ #include <botan/sm2_enc.h>
#include "test_pubkey.h"
#endif
@@ -60,9 +61,55 @@ class SM2_Signature_KAT_Tests : public PK_Signature_Generation_Test
}
};
+BOTAN_REGISTER_TEST("sm2_sig", SM2_Signature_KAT_Tests);
+
+class SM2_Encryption_KAT_Tests : public PK_Encryption_Decryption_Test
+ {
+ public:
+ SM2_Encryption_KAT_Tests()
+ : PK_Encryption_Decryption_Test(
+ "SM2",
+ "pubkey/sm2_enc.vec",
+ "P,A,B,xG,yG,Order,Cofactor,Msg,x,Nonce,Ciphertext",
+ "") {}
+
+ virtual std::string default_padding(const VarMap& vars) const override
+ {
+ return "";
+ }
+
+ Botan::RandomNumberGenerator* test_rng(const std::vector<uint8_t>& nonce) const override
+ {
+ return new Fixed_Output_Position_RNG(nonce, 1);
+ }
+
+ std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override
+ {
+ // group params
+ const BigInt p = get_req_bn(vars, "P");
+ const BigInt a = get_req_bn(vars, "A");
+ const BigInt b = get_req_bn(vars, "B");
+ const BigInt xG = get_req_bn(vars, "xG");
+ const BigInt yG = get_req_bn(vars, "yG");
+ const BigInt order = get_req_bn(vars, "Order");
+ const BigInt cofactor = get_req_bn(vars, "Cofactor");
+ const BigInt x = get_req_bn(vars, "x");
+
+ Botan::CurveGFp curve(p, a, b);
+ Botan::PointGFp base_point(curve, xG, yG);
+ Botan::EC_Group domain(curve, base_point, order, cofactor);
+
+ Botan::Null_RNG null_rng;
+ std::unique_ptr<Botan::Private_Key> key(new Botan::SM2_Encryption_PrivateKey(null_rng, domain, x));
+ return key;
+ }
+ };
+
}
-BOTAN_REGISTER_TEST("sm2_sig", SM2_Signature_KAT_Tests);
+BOTAN_REGISTER_TEST("sm2_enc", SM2_Encryption_KAT_Tests);
+
+
#endif
}