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

randombit / botan / 21892189369

11 Feb 2026 12:53AM UTC coverage: 90.069% (-1.6%) from 91.638%
21892189369

push

github

web-flow
Merge pull request #5302 from randombit/jack/header-patrol-4

Cleanup various header inclusions

102230 of 113502 relevant lines covered (90.07%)

11577018.64 hits per line

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

91.67
/src/lib/ffi/ffi_srp6.cpp
1
/*
2
* (C) 2022 Rostyslav Khudolii
3
*     2023 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/ffi.h>
9

10
#include <botan/assert.h>
11
#include <botan/internal/ffi_rng.h>
12
#include <botan/internal/ffi_util.h>
13

14
#if defined(BOTAN_HAS_SRP6)
15
   #include <botan/bigint.h>
16
   #include <botan/dl_group.h>
17
   #include <botan/rng.h>
18
   #include <botan/srp6.h>
19
   #include <botan/symkey.h>
20
#endif
21

22
extern "C" {
23

24
using namespace Botan_FFI;
25

26
#if defined(BOTAN_HAS_SRP6)
27
BOTAN_FFI_DECLARE_STRUCT(botan_srp6_server_session_struct, Botan::SRP6_Server_Session, 0x44F7425F);
2✔
28
#else
29
BOTAN_FFI_DECLARE_DUMMY_STRUCT(botan_srp6_server_session_struct, 0x44F7425F);
30
#endif
31

32
int botan_srp6_server_session_init(botan_srp6_server_session_t* srp6) {
2✔
33
#if defined(BOTAN_HAS_SRP6)
34
   return ffi_guard_thunk(
2✔
35
      __func__, [=]() -> int { return ffi_new_object(srp6, std::make_unique<Botan::SRP6_Server_Session>()); });
2✔
36
#else
37
   BOTAN_UNUSED(srp6);
38
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
39
#endif
40
}
41

42
int botan_srp6_server_session_destroy(botan_srp6_server_session_t srp6) {
2✔
43
   return BOTAN_FFI_CHECKED_DELETE(srp6);
2✔
44
}
45

46
int botan_srp6_group_size(const char* group_id, size_t* group_p_bytes) {
4✔
47
#if defined(BOTAN_HAS_SRP6)
48
   if(any_null_pointers(group_id, group_p_bytes)) {
4✔
49
      return BOTAN_FFI_ERROR_NULL_POINTER;
50
   }
51

52
   return ffi_guard_thunk(__func__, [=]() -> int {
4✔
53
      const auto group = Botan::DL_Group::from_name(group_id);
4✔
54
      *group_p_bytes = group.p_bytes();
4✔
55
      return BOTAN_FFI_SUCCESS;
4✔
56
   });
8✔
57
#else
58
   BOTAN_UNUSED(group_id, group_p_bytes);
59
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
60
#endif
61
}
62

63
int botan_srp6_server_session_step1(botan_srp6_server_session_t srp6,
3✔
64
                                    const uint8_t* verifier,
65
                                    size_t verifier_len,
66
                                    const char* group_id,
67
                                    const char* hash_id,
68
                                    botan_rng_t rng_obj,
69
                                    uint8_t b_pub[],
70
                                    size_t* b_pub_len) {
71
#if defined(BOTAN_HAS_SRP6)
72
   return BOTAN_FFI_VISIT(srp6, [=](auto& s) -> int {
11✔
73
      if(any_null_pointers(verifier, group_id, hash_id, rng_obj)) {
74
         return BOTAN_FFI_ERROR_NULL_POINTER;
75
      }
76
      try {
77
         const auto group = Botan::DL_Group::from_name(group_id);
78
         const auto rc = check_and_prepare_output_space(b_pub, b_pub_len, group.p_bytes());
79
         if(rc != BOTAN_FFI_SUCCESS) {
80
            return rc;
81
         }
82

83
         Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
84
         auto v_bn = Botan::BigInt::from_bytes(std::span{verifier, verifier_len});
85
         auto b_pub_bn = s.step1(v_bn, group, hash_id, group.exponent_bits(), rng);
86
         return write_vec_output(b_pub, b_pub_len, b_pub_bn.serialize(group.p_bytes()));
87
      } catch(Botan::Decoding_Error&) {
88
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
89
      } catch(Botan::Lookup_Error&) {
90
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
91
      }
92
   });
93
#else
94
   BOTAN_UNUSED(srp6, verifier, verifier_len, group_id, hash_id, rng_obj, b_pub, b_pub_len);
95
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
96
#endif
97
}
98

99
int botan_srp6_server_session_step2(
3✔
100
   botan_srp6_server_session_t srp6, const uint8_t a[], size_t a_len, uint8_t key[], size_t* key_len) {
101
#if defined(BOTAN_HAS_SRP6)
102
   return BOTAN_FFI_VISIT(srp6, [=](auto& s) -> int {
15✔
103
      if(!a) {
104
         return BOTAN_FFI_ERROR_NULL_POINTER;
105
      }
106
      try {
107
         const Botan::BigInt a_bn = Botan::BigInt::from_bytes({a, a_len});
108
         auto key_sk = s.step2(a_bn);
109
         return write_vec_output(key, key_len, key_sk.bits_of());
110
      } catch(Botan::Decoding_Error&) {
111
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
112
      }
113
   });
114
#else
115
   BOTAN_UNUSED(srp6, a, a_len, key, key_len);
116
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
117
#endif
118
}
119

120
int botan_srp6_generate_verifier(const char* username,
3✔
121
                                 const char* password,
122
                                 const uint8_t salt[],
123
                                 size_t salt_len,
124
                                 const char* group_id,
125
                                 const char* hash_id,
126
                                 uint8_t verifier[],
127
                                 size_t* verifier_len) {
128
#if defined(BOTAN_HAS_SRP6)
129
   return ffi_guard_thunk(__func__, [=]() -> int {
3✔
130
      if(any_null_pointers(username, password, salt, group_id, hash_id)) {
6✔
131
         return BOTAN_FFI_ERROR_NULL_POINTER;
132
      }
133
      try {
3✔
134
         const std::vector<uint8_t> salt_vec(salt, salt + salt_len);
3✔
135
         const auto group = Botan::DL_Group::from_name(group_id);
3✔
136
         const size_t p_bytes = group.p_bytes();
3✔
137
         auto verifier_bn = Botan::srp6_generate_verifier(username, password, salt_vec, group, hash_id);
3✔
138
         return write_vec_output(verifier, verifier_len, verifier_bn.serialize(p_bytes));
3✔
139
      } catch(Botan::Lookup_Error&) {
9✔
140
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
×
141
      }
×
142
   });
3✔
143
#else
144
   BOTAN_UNUSED(username, password, group_id, hash_id);
145
   BOTAN_UNUSED(salt, salt_len, verifier, verifier_len);
146
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
147
#endif
148
}
149

150
int botan_srp6_client_agree(const char* identity,
3✔
151
                            const char* password,
152
                            const char* group_id,
153
                            const char* hash_id,
154
                            const uint8_t salt[],
155
                            size_t salt_len,
156
                            const uint8_t b[],
157
                            size_t b_len,
158
                            botan_rng_t rng_obj,
159
                            uint8_t A[],
160
                            size_t* A_len,
161
                            uint8_t K[],
162
                            size_t* K_len) {
163
#if defined(BOTAN_HAS_SRP6)
164
   return ffi_guard_thunk(__func__, [=]() -> int {
3✔
165
      if(any_null_pointers(identity, password, salt, group_id, hash_id, b, rng_obj)) {
6✔
166
         return BOTAN_FFI_ERROR_NULL_POINTER;
167
      }
168
      try {
3✔
169
         const std::vector<uint8_t> saltv(salt, salt + salt_len);
3✔
170
         Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
3✔
171
         auto b_bn = Botan::BigInt::from_bytes({b, b_len});
3✔
172
         const auto group = Botan::DL_Group::from_name(group_id);
3✔
173
         const size_t a_bits = group.exponent_bits();
3✔
174
         auto [A_bn, K_sk] = Botan::srp6_client_agree(identity, password, group, hash_id, saltv, b_bn, a_bits, rng);
3✔
175
         auto ret_a = write_vec_output(A, A_len, A_bn.serialize(group.p_bytes()));
3✔
176
         auto ret_k = write_vec_output(K, K_len, K_sk.bits_of());
3✔
177
         if(ret_a != BOTAN_FFI_SUCCESS) {
3✔
178
            return ret_a;
1✔
179
         }
180
         if(ret_k != BOTAN_FFI_SUCCESS) {
181
            return ret_k;
182
         }
183
         return BOTAN_FFI_SUCCESS;
184
      } catch(Botan::Lookup_Error&) {
9✔
185
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
×
186
      }
×
187
   });
3✔
188
#else
189
   BOTAN_UNUSED(identity, password, group_id, hash_id, rng_obj);
190
   BOTAN_UNUSED(salt, salt_len, b, b_len, A, A_len, K, K_len);
191
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
192
#endif
193
}
194
}
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

© 2026 Coveralls, Inc