• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
You are now the owner of this repo.

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

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
         Test::Result result("SRP6a " + group_id);
50✔
47

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

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

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

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

63
         Botan::SRP6_Server_Session server;
50✔
64

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

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

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

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

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

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

86
   #if defined(BOTAN_HAS_SHA2_32)
87

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

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

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

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

105
            result.start_timer();
7✔
106

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

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

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

116
               Botan::SRP6_Server_Session server;
23✔
117

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

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

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

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

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

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

136
   #endif
137

138
#endif
139

140
}
141

142
}
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