10#include <botan/assert.h>
11#include <botan/dl_group.h>
12#include <botan/exceptn.h>
13#include <botan/hash.h>
14#include <botan/internal/ct_utils.h>
15#include <botan/internal/fmt.h>
16#include <botan/internal/mp_core.h>
23 hash_fn.update(in1.serialize(p_bytes));
24 hash_fn.update(in2.serialize(p_bytes));
30 std::string_view identifier,
31 std::string_view password,
32 const std::vector<uint8_t>& salt) {
33 hash_fn.update(identifier);
35 hash_fn.update(password);
40 hash_fn.update(inner_h);
55 const std::string group_name =
"modp/srp/" + std::to_string(N.
bits());
59 if(group.get_p() == N && group.get_g() == g) {
69 std::string_view password,
70 std::string_view group_id,
71 std::string_view hash_id,
72 const std::vector<uint8_t>& salt,
76 const size_t a_bits = group.exponent_bits();
78 return srp6_client_agree(identifier, password, group, hash_id, salt, B, a_bits, rng);
82 std::string_view password,
84 std::string_view hash_id,
85 const std::vector<uint8_t>& salt,
94 const size_t p_bytes = group.
p_bytes();
96 if(B <= 0 || B >= p) {
101 if(8 * hash_fn->output_length() >= group.
p_bits()) {
102 throw Invalid_Argument(
fmt(
"Hash function {} too large for SRP6 with this group", hash_fn->name()));
105 const BigInt k = hash_seq(*hash_fn, p_bytes, p, g);
107 const BigInt a(rng, a_bits);
113 const BigInt u = hash_seq(*hash_fn, p_bytes, A, B);
116 const BigInt x = compute_x(*hash_fn, identifier, password, salt);
133 const size_t max_aux_bits = std::max<size_t>(a_bits, 2 * 8 * hash_fn->output_length()) + 1;
143 return std::make_pair(A, Sk);
147 std::string_view password,
148 const std::vector<uint8_t>& salt,
149 std::string_view group_id,
150 std::string_view hash_id) {
156 std::string_view password,
157 const std::vector<uint8_t>& salt,
159 std::string_view hash_id) {
161 if(8 * hash_fn->output_length() >= group.
p_bits()) {
162 throw Invalid_Argument(
fmt(
"Hash function {} too large for SRP6 with this group", hash_fn->name()));
165 const BigInt x = compute_x(*hash_fn, identifier, password, salt);
171 std::string_view group_id,
172 std::string_view hash_id,
175 const size_t b_bits = group.exponent_bits();
176 return this->
step1(v, group, hash_id, b_bits, rng);
188 m_group = std::make_unique<DL_Group>(group);
191 const BigInt& g = m_group->get_g();
192 const BigInt& p = m_group->get_p();
195 m_b =
BigInt(rng, m_b_bits);
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()));
203 const BigInt k = hash_seq(*hash_fn, m_group->p_bytes(), p, g);
206 m_B = m_group->mod_p(m_v * k + m_group->power_g_p(m_b, b_bits));
215 if(A <= 0 || A >= m_group->get_p()) {
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()));
224 const BigInt u = hash_seq(*hash_fn, m_group->p_bytes(), A, m_B);
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);
234 const BigInt S = m_group->power_b_p(m_group->multiply_mod_p(A, vup), m_b, m_b_bits);
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_STATE_CHECK(expr)
#define BOTAN_ARG_CHECK(expr, msg)
static BigInt _from_words(secure_vector< word > &words)
static BigInt from_bytes(std::span< const uint8_t > bytes)
const word * _data() const
T serialize(size_t len) const
BigInt power_g_p(const BigInt &x) const
BigInt mod_p(const BigInt &x) const
BigInt multiply_mod_p(const BigInt &x, const BigInt &y) const
const BigInt & get_p() const
static DL_Group from_name(std::string_view name)
BigInt power_b_p(const BigInt &b, const BigInt &x, size_t max_x_bits) const
const BigInt & get_g() const
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
BigInt step1(const BigInt &v, std::string_view group_id, std::string_view hash_id, RandomNumberGenerator &rng)
SymmetricKey step2(const BigInt &A)
constexpr decltype(auto) driveby_unpoison(T &&v)
constexpr auto scoped_poison(const Ts &... xs)
constexpr void unpoison_all(const Ts &... ts)
constexpr void unpoison(const T *p, size_t n)
constexpr void poison(const T *p, size_t n)
constexpr auto bigint_add2(W x[], size_t x_size, const W y[], size_t y_size) -> W
std::string fmt(std::string_view format, const T &... args)
void bigint_mul(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word y[], size_t y_size, size_t y_sw, word workspace[], size_t ws_size)
std::pair< BigInt, SymmetricKey > srp6_client_agree(std::string_view identifier, std::string_view password, std::string_view group_id, std::string_view hash_id, const std::vector< uint8_t > &salt, const BigInt &B, RandomNumberGenerator &rng)
BigInt srp6_generate_verifier(std::string_view identifier, std::string_view password, const std::vector< uint8_t > &salt, std::string_view group_id, std::string_view hash_id)
std::string srp6_group_identifier(const BigInt &N, const BigInt &g)
std::vector< T, secure_allocator< T > > secure_vector
std::conditional_t< HasNative64BitRegisters, std::uint64_t, uint32_t > word
The native machine word, used as the limb type for multiprecision integers.