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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 hits per line

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

88.89
/src/tests/test_srp6.cpp
1
/*
2
* (C) 2015,2019 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_SRP6)
10
   #include "test_rng.h"
11
   #include <botan/dl_group.h>
12
   #include <botan/hash.h>
13
   #include <botan/srp6.h>
14
#endif
15

16
namespace Botan_Tests {
17

18
namespace {
19

20
#if defined(BOTAN_HAS_SRP6)
21

22
class SRP6_KAT_Tests final : public Text_Based_Test {
×
23
   public:
24
      SRP6_KAT_Tests() : Text_Based_Test("srp6a.vec", "Hash,N,g,I,P,s,v,a,b,A,B,S") {}
3✔
25

26
      bool clear_between_callbacks() const override { return false; }
50✔
27

28
      Test::Result run_one_test(const std::string& /*header*/, const VarMap& vars) override {
50✔
29
         const std::string hash = vars.get_req_str("Hash");
50✔
30
         const std::string username = vars.get_req_str("I");
50✔
31
         const std::string password = vars.get_req_str("P");
50✔
32
         const std::vector<uint8_t> salt = vars.get_req_bin("s");
50✔
33
         const BigInt N = vars.get_req_bn("N");
50✔
34
         const BigInt g = vars.get_req_bn("g");
50✔
35
         const BigInt exp_v = vars.get_req_bn("v");
50✔
36
         const std::vector<uint8_t> a = vars.get_req_bin("a");
50✔
37
         const std::vector<uint8_t> b = vars.get_req_bin("b");
50✔
38
         const BigInt exp_A = vars.get_req_bn("A");
50✔
39
         const BigInt exp_B = vars.get_req_bn("B");
50✔
40
         const auto exp_S = Botan::SymmetricKey(vars.get_req_bin("S"));
100✔
41

42
         const std::string group_id = Botan::srp6_group_identifier(N, g);
50✔
43
         if(group_id.empty()) {
50✔
44
            throw Test_Error("Unknown SRP group used in test data");
×
45
         }
46

47
         Test::Result result("SRP6a " + group_id);
50✔
48

49
         if(Botan::HashFunction::create(hash) == nullptr) {
100✔
50
            result.test_note("Skipping test as hash function not available");
×
51
            return result;
×
52
         }
53

54
         if(N.bits() >= 4096 && !Test::run_long_tests()) {
50✔
55
            result.test_note("Skipping test with long SRP modulus");
×
56
            return result;
×
57
         }
58

59
         Botan::DL_Group group(group_id);
50✔
60

61
         const Botan::BigInt v = Botan::srp6_generate_verifier(username, password, salt, group_id, hash);
50✔
62
         result.test_eq("SRP verifier", v, exp_v);
50✔
63

64
         Botan::SRP6_Server_Session server;
50✔
65

66
         const size_t b_bits = Botan::BigInt(b).bits();
50✔
67
         Fixed_Output_RNG b_rng(b);
50✔
68
         const Botan::BigInt B = server.step1(v, group, hash, b_bits, b_rng);
50✔
69
         result.test_eq("SRP B", B, exp_B);
50✔
70

71
         const size_t a_bits = Botan::BigInt(a).bits();
50✔
72
         Fixed_Output_RNG a_rng(a);
50✔
73
         const auto srp_resp = Botan::srp6_client_agree(username, password, group, hash, salt, B, a_bits, a_rng);
50✔
74
         result.test_eq("SRP A", srp_resp.first, exp_A);
50✔
75

76
         const auto S = server.step2(srp_resp.first);
50✔
77

78
         result.test_eq("SRP client S", srp_resp.second, exp_S);
50✔
79
         result.test_eq("SRP server S", S, exp_S);
50✔
80

81
         return result;
50✔
82
      }
650✔
83
};
84

85
BOTAN_REGISTER_TEST("pake", "srp6_kat", SRP6_KAT_Tests);
86

87
   #if defined(BOTAN_HAS_SHA2_32)
88

89
class SRP6_RT_Tests final : public Test {
×
90
   public:
91
      std::vector<Test::Result> run() override {
1✔
92
         std::vector<Test::Result> results;
1✔
93

94
         const std::string username = "user";
1✔
95
         const std::string password = "Awellchosen1_to_be_sure_";
1✔
96
         const std::string hash_id = "SHA-256";
1✔
97

98
         for(size_t b : {1024, 1536, 2048, 3072, 4096, 6144, 8192}) {
8✔
99
            if(b >= 4096 && !Test::run_long_tests()) {
7✔
100
               continue;
×
101
            }
102

103
            const std::string group_id = "modp/srp/" + std::to_string(b);
7✔
104
            Test::Result result("SRP6 " + group_id);
7✔
105

106
            result.start_timer();
7✔
107

108
            const size_t trials = 8192 / b;
7✔
109

110
            for(size_t t = 0; t != trials; ++t) {
30✔
111
               std::vector<uint8_t> salt;
23✔
112
               Test::rng().random_vec(salt, 16);
23✔
113

114
               const Botan::BigInt verifier =
23✔
115
                  Botan::srp6_generate_verifier(username, password, salt, group_id, hash_id);
23✔
116

117
               Botan::SRP6_Server_Session server;
23✔
118

119
               const Botan::BigInt B = server.step1(verifier, group_id, hash_id, Test::rng());
23✔
120

121
               auto client = srp6_client_agree(username, password, group_id, hash_id, salt, B, Test::rng());
23✔
122

123
               const Botan::SymmetricKey server_K = server.step2(client.first);
23✔
124

125
               result.test_eq("computed same keys", client.second.bits_of(), server_K.bits_of());
92✔
126
            }
92✔
127
            result.end_timer();
7✔
128
            results.push_back(result);
7✔
129
         }
7✔
130

131
         return results;
1✔
132
      }
2✔
133
};
134

135
BOTAN_REGISTER_TEST("pake", "srp6_rt", SRP6_RT_Tests);
136

137
   #endif
138

139
#endif
140

141
}  // namespace
142

143
}  // 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