Botan 3.14.1
Crypto and TLS for C&
Botan::SRP6_Server_Session Class Referencefinal

#include <srp6.h>

Public Member Functions

BigInt step1 (const BigInt &v, const DL_Group &group, std::string_view hash_id, size_t b_bits, RandomNumberGenerator &rng)
BigInt step1 (const BigInt &v, std::string_view group_id, std::string_view hash_id, RandomNumberGenerator &rng)
SymmetricKey step2 (const BigInt &A)

Detailed Description

Represents a SRP-6a server session

Definition at line 102 of file srp6.h.

Member Function Documentation

◆ step1() [1/2]

BigInt Botan::SRP6_Server_Session::step1 ( const BigInt & v,
const DL_Group & group,
std::string_view hash_id,
size_t b_bits,
RandomNumberGenerator & rng )

Server side step 1 This version of step1 added in 2.11

Parameters
vthe verification value saved from client registration
groupthe SRP group
Hash Function Identificationthe SRP hash in use
Random Number Generatorsa random number generator
b_bitssize of secret exponent in bits
Returns
SRP-6 B value

Definition at line 179 of file srp6.cpp.

180 {
181 if(v.signum() <= 0 || v >= group.get_p()) {
182 throw Invalid_Argument("SRP6_Server_Session: invalid verifier");
183 }
184
185 BOTAN_ARG_CHECK(b_bits >= 160 && b_bits <= group.p_bits(), "Invalid b_bits");
186
187 BOTAN_STATE_CHECK(!m_group);
188 m_group = std::make_unique<DL_Group>(group);
189 m_b_bits = b_bits;
190
191 const BigInt& g = m_group->get_g();
192 const BigInt& p = m_group->get_p();
193
194 m_v = v;
195 m_b = BigInt(rng, m_b_bits);
196 m_hash_id = hash_id;
197
198 auto hash_fn = HashFunction::create_or_throw(hash_id);
199 if(8 * hash_fn->output_length() >= m_group->p_bits()) {
200 throw Invalid_Argument(fmt("Hash function {} too large for SRP6 with this group", hash_fn->name()));
201 }
202
203 const BigInt k = hash_seq(*hash_fn, m_group->p_bytes(), p, g);
204
205 const auto scope = CT::scoped_poison(m_v, m_b);
206 m_B = m_group->mod_p(m_v * k + m_group->power_g_p(m_b, b_bits));
207 CT::unpoison(m_B);
208
209 return m_B;
210}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:311
constexpr auto scoped_poison(const Ts &... xs)
Definition ct_utils.h:222
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:67
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References BOTAN_ARG_CHECK, BOTAN_STATE_CHECK, Botan::HashFunction::create_or_throw(), Botan::fmt(), Botan::DL_Group::get_p(), Botan::DL_Group::p_bits(), Botan::CT::scoped_poison(), Botan::BigInt::signum(), and Botan::CT::unpoison().

◆ step1() [2/2]

BigInt Botan::SRP6_Server_Session::step1 ( const BigInt & v,
std::string_view group_id,
std::string_view hash_id,
RandomNumberGenerator & rng )

Server side step 1

Parameters
vthe verification value saved from client registration
group_idthe SRP group id
Hash Function Identificationthe SRP hash in use
Random Number Generatorsa random number generator
Returns
SRP-6 B value

Definition at line 170 of file srp6.cpp.

173 {
174 const auto group = DL_Group::from_name(group_id);
175 const size_t b_bits = group.exponent_bits();
176 return this->step1(v, group, hash_id, b_bits, rng);
177}
static DL_Group from_name(std::string_view name)
Definition dl_group.cpp:266
BigInt step1(const BigInt &v, std::string_view group_id, std::string_view hash_id, RandomNumberGenerator &rng)
Definition srp6.cpp:170

References Botan::DL_Group::from_name(), and step1().

Referenced by step1().

◆ step2()

SymmetricKey Botan::SRP6_Server_Session::step2 ( const BigInt & A)

Server side step 2

Parameters
Athe client's value
Returns
shared symmetric key

Definition at line 212 of file srp6.cpp.

212 {
213 BOTAN_STATE_CHECK(m_group);
214
215 if(A <= 0 || A >= m_group->get_p()) {
216 throw Decoding_Error("Invalid SRP parameter from client");
217 }
218
219 auto hash_fn = HashFunction::create_or_throw(m_hash_id);
220 if(8 * hash_fn->output_length() >= m_group->p_bits()) {
221 throw Invalid_Argument(fmt("Hash function {} too large for SRP6 with this group", hash_fn->name()));
222 }
223
224 const BigInt u = hash_seq(*hash_fn, m_group->p_bytes(), A, m_B);
225 BOTAN_ASSERT_NOMSG(!u.is_zero());
226
227 const auto scope = CT::scoped_poison(m_v, m_b);
228
229 // The maximum length of u is fixed based on the chosen hash function
230 const size_t u_bits = hash_fn->output_length() * 8;
231 const BigInt vup = m_group->power_b_p(m_v, u, u_bits);
232
233 // The size of b is chosen by either a formula or the application; either way it is public
234 const BigInt S = m_group->power_b_p(m_group->multiply_mod_p(A, vup), m_b, m_b_bits);
235
236 // Any further secret handling of the output is up to the caller
237 CT::unpoison(S);
238
239 return SymmetricKey(S.serialize<secure_vector<uint8_t>>(m_group->p_bytes()));
240}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
OctetString SymmetricKey
Definition symkey.h:153
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128

References BOTAN_ASSERT_NOMSG, BOTAN_STATE_CHECK, Botan::HashFunction::create_or_throw(), Botan::fmt(), Botan::BigInt::is_zero(), Botan::CT::scoped_poison(), Botan::BigInt::serialize(), and Botan::CT::unpoison().


The documentation for this class was generated from the following files: