• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.43
/src/tests/test_sm2.cpp
1
/*
2
* (C) 2017 Ribose Inc
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "test_rng.h"
8
#include "tests.h"
9

10
#if defined(BOTAN_HAS_SM2)
11
   #include "test_pubkey.h"
12
   #include <botan/sm2.h>
13
#endif
14

15
namespace Botan_Tests {
16

17
#if defined(BOTAN_HAS_SM2)
18

19
namespace {
20

21
std::unique_ptr<Botan::Private_Key> load_sm2_private_key(const VarMap& vars) {
12✔
22
   // group params
23
   const BigInt p = vars.get_req_bn("P");
12✔
24
   const BigInt a = vars.get_req_bn("A");
12✔
25
   const BigInt b = vars.get_req_bn("B");
12✔
26
   const BigInt xG = vars.get_req_bn("xG");
12✔
27
   const BigInt yG = vars.get_req_bn("yG");
12✔
28
   const BigInt order = vars.get_req_bn("Order");
12✔
29
   const BigInt cofactor = vars.get_req_bn("Cofactor");
12✔
30
   const BigInt x = vars.get_req_bn("x");
12✔
31

32
   Botan::EC_Group domain(p, a, b, xG, yG, order, cofactor);
12✔
33

34
   Botan::Null_RNG null_rng;
12✔
35
   return std::make_unique<Botan::SM2_PrivateKey>(null_rng, domain, x);
24✔
36
}
108✔
37

38
class SM2_Signature_KAT_Tests final : public PK_Signature_Generation_Test {
×
39
   public:
40
      SM2_Signature_KAT_Tests() :
1✔
41
            PK_Signature_Generation_Test(
42
               "SM2", "pubkey/sm2_sig.vec", "P,A,B,xG,yG,Order,Cofactor,Ident,Msg,x,Nonce,Signature", "Hash") {}
4✔
43

44
      bool clear_between_callbacks() const override { return false; }
7✔
45

46
      std::string default_padding(const VarMap& vars) const override {
7✔
47
         return vars.get_req_str("Ident") + "," + vars.get_opt_str("Hash", "SM3");
14✔
48
      }
49

50
      std::unique_ptr<Botan::RandomNumberGenerator> test_rng(const std::vector<uint8_t>& nonce) const override {
7✔
51
         return std::make_unique<Fixed_Output_Position_RNG>(nonce, 1);
7✔
52
      }
53

54
      std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override {
7✔
55
         return load_sm2_private_key(vars);
7✔
56
      }
57
};
58

59
BOTAN_REGISTER_TEST("pubkey", "sm2_sig", SM2_Signature_KAT_Tests);
60

61
class SM2_Encryption_KAT_Tests final : public PK_Encryption_Decryption_Test {
×
62
   public:
63
      SM2_Encryption_KAT_Tests() :
1✔
64
            PK_Encryption_Decryption_Test(
65
               "SM2", "pubkey/sm2_enc.vec", "P,A,B,xG,yG,Order,Cofactor,Msg,x,Nonce,Ciphertext", "Hash") {}
4✔
66

67
      std::string default_padding(const VarMap& vars) const override { return vars.get_opt_str("Hash", "SM3"); }
10✔
68

69
      bool clear_between_callbacks() const override { return false; }
5✔
70

71
      std::unique_ptr<Botan::RandomNumberGenerator> test_rng(const std::vector<uint8_t>& nonce) const override {
5✔
72
         return std::make_unique<Fixed_Output_Position_RNG>(nonce, 1);
5✔
73
      }
74

75
      std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override {
5✔
76
         return load_sm2_private_key(vars);
5✔
77
      }
78
};
79

80
}
81

82
BOTAN_REGISTER_TEST("pubkey", "sm2_enc", SM2_Encryption_KAT_Tests);
83

84
class SM2_Keygen_Tests final : public PK_Key_Generation_Test {
×
85
   public:
86
      std::vector<std::string> keygen_params() const override { return {"secp256r1", "sm2p256v1"}; }
3✔
87

88
      std::string algo_name() const override { return "SM2"; }
6✔
89
};
90

91
BOTAN_REGISTER_TEST("pubkey", "sm2_keygen", SM2_Keygen_Tests);
92

93
#endif
94

95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc