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

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 hits per line

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

91.11
/src/tests/test_dsa.cpp
1
/*
2
* (C) 2014,2015 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_DSA)
10
   #include "test_pubkey.h"
11
   #include <botan/bigint.h>
12
   #include <botan/dl_group.h>
13
   #include <botan/dsa.h>
14
#endif
15

16
namespace Botan_Tests {
17

18
namespace {
19

20
#if defined(BOTAN_HAS_DSA)
21

22
class DSA_KAT_Tests final : public PK_Signature_Generation_Test {
×
23
   public:
24
      DSA_KAT_Tests() :
1✔
25
            PK_Signature_Generation_Test("DSA",
26
   #if defined(BOTAN_HAS_RFC6979_GENERATOR)
27
                                         "pubkey/dsa_rfc6979.vec",
28
                                         "P,Q,G,X,Hash,Msg,Signature",
29
   #else
30
                                         "pubkey/dsa_prob.vec",
31
                                         "P,Q,G,X,Hash,Msg,Nonce,Signature",
32
   #endif
33
                                         "") {
4✔
34
      }
1✔
35

36
      bool clear_between_callbacks() const override { return false; }
21✔
37

38
      std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override {
21✔
39
         const Botan::BigInt p = vars.get_req_bn("P");
21✔
40
         const Botan::BigInt q = vars.get_req_bn("Q");
21✔
41
         const Botan::BigInt g = vars.get_req_bn("G");
21✔
42
         const Botan::BigInt x = vars.get_req_bn("X");
21✔
43

44
         const Botan::DL_Group group(p, q, g);
21✔
45

46
         return std::make_unique<Botan::DSA_PrivateKey>(group, x);
42✔
47
      }
105✔
48

49
      std::string default_padding(const VarMap& vars) const override { return vars.get_req_str("Hash"); }
42✔
50
};
51

52
class DSA_KAT_Verification_Tests final : public PK_Signature_Verification_Test {
×
53
   public:
54
      DSA_KAT_Verification_Tests() :
1✔
55
            PK_Signature_Verification_Test("DSA",
56
   #if !defined(BOTAN_HAS_RFC6979_GENERATOR)
57
                                           "pubkey/dsa_rfc6979.vec",
58
                                           "P,Q,G,X,Hash,Msg,Signature",
59
   #else
60
                                           "pubkey/dsa_prob.vec",
61
                                           "P,Q,G,X,Hash,Msg,Nonce,Signature",
62
   #endif
63
                                           "") {
4✔
64
      }
1✔
65

66
      bool clear_between_callbacks() const override { return false; }
302✔
67

68
      std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override {
302✔
69
         const Botan::BigInt p = vars.get_req_bn("P");
302✔
70
         const Botan::BigInt q = vars.get_req_bn("Q");
302✔
71
         const Botan::BigInt g = vars.get_req_bn("G");
302✔
72
         const Botan::BigInt x = vars.get_req_bn("X");
302✔
73

74
         const Botan::DL_Group grp(p, q, g);
302✔
75

76
         const Botan::DSA_PrivateKey priv_key(grp, x);
302✔
77

78
         return priv_key.public_key();
302✔
79
      }
1,812✔
80

81
      std::string default_padding(const VarMap& vars) const override { return vars.get_req_str("Hash"); }
604✔
82
};
83

84
class DSA_Verification_Tests final : public PK_Signature_Verification_Test {
×
85
   public:
86
      DSA_Verification_Tests() :
1✔
87
            PK_Signature_Verification_Test("DSA", "pubkey/dsa_verify.vec", "P,Q,G,Y,Msg,Signature") {}
4✔
88

89
      bool clear_between_callbacks() const override { return false; }
2✔
90

91
      std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override {
2✔
92
         const Botan::BigInt p = vars.get_req_bn("P");
2✔
93
         const Botan::BigInt q = vars.get_req_bn("Q");
2✔
94
         const Botan::BigInt g = vars.get_req_bn("G");
2✔
95
         const Botan::BigInt y = vars.get_req_bn("Y");
2✔
96

97
         const Botan::DL_Group group(p, q, g);
2✔
98

99
         return std::make_unique<Botan::DSA_PublicKey>(group, y);
4✔
100
      }
10✔
101

102
      std::string default_padding(const VarMap& /*unused*/) const override { return "Raw"; }
2✔
103
};
104

105
class DSA_Keygen_Tests final : public PK_Key_Generation_Test {
×
106
   public:
107
      std::vector<std::string> keygen_params() const override { return {"dsa/jce/1024"}; }
2✔
108

109
      std::string algo_name() const override { return "DSA"; }
3✔
110
};
111

112
BOTAN_REGISTER_TEST("pubkey", "dsa_kat_sign", DSA_KAT_Tests);
113
BOTAN_REGISTER_TEST("pubkey", "dsa_kat_verify", DSA_KAT_Verification_Tests);
114
BOTAN_REGISTER_TEST("pubkey", "dsa_misc_verify", DSA_Verification_Tests);
115
BOTAN_REGISTER_TEST("pubkey", "dsa_keygen", DSA_Keygen_Tests);
116

117
#endif
118

119
}  // namespace
120

121
}  // namespace Botan_Tests
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