10#include <botan/dl_group.h>
11#include <botan/numthry.h>
17BigInt hash_seq(
const std::string& hash_id,
30BigInt compute_x(
const std::string& hash_id,
31 const std::string& identifier,
32 const std::string& password,
33 const std::vector<uint8_t>& salt)
37 hash_fn->update(identifier);
39 hash_fn->update(password);
41 secure_vector<uint8_t> inner_h = hash_fn->final();
43 hash_fn->update(salt);
44 hash_fn->update(inner_h);
46 secure_vector<uint8_t> outer_h = hash_fn->final();
76std::pair<BigInt, SymmetricKey>
78 const std::string& password,
79 const std::string& group_id,
80 const std::string& hash_id,
81 const std::vector<uint8_t>& salt,
88 return srp6_client_agree(identifier, password, group, hash_id, salt, B, a_bits, rng);
91std::pair<BigInt, SymmetricKey>
93 const std::string& password,
95 const std::string& hash_id,
96 const std::vector<uint8_t>& salt,
104 const size_t p_bytes = group.
p_bytes();
109 const BigInt k = hash_seq(hash_id, p_bytes, p, g);
111 const BigInt a(rng, a_bits);
115 const BigInt u = hash_seq(hash_id, p_bytes, A, B);
117 const BigInt x = compute_x(hash_id, identifier, password, salt);
120 group.
mod_p(a + (u * x)), p);
124 return std::make_pair(A, Sk);
128 const std::string& password,
129 const std::vector<uint8_t>& salt,
130 const std::string& group_id,
131 const std::string& hash_id)
138 const std::string& password,
139 const std::vector<uint8_t>& salt,
141 const std::string& hash_id)
143 const BigInt x = compute_x(hash_id, identifier, password, salt);
149 const std::string& group_id,
150 const std::string& hash_id,
156 return this->
step1(v, group, hash_id, b_bits, rng);
161 const std::string& hash_id,
168 m_p_bytes = p.
bytes();
170 m_b =
BigInt(rng, b_bits);
174 const BigInt k = hash_seq(hash_id, m_p_bytes, p, g);
183 if(A <= 0 || A >= m_p)
186 const BigInt u = hash_seq(m_hash_id, m_p_bytes, A, m_B);
static BigInt decode(const uint8_t buf[], size_t length)
static secure_vector< uint8_t > encode_1363(const BigInt &n, size_t bytes)
BigInt power_g_p(const BigInt &x) const
BigInt mod_p(const BigInt &x) const
const BigInt & get_p() const
size_t exponent_bits() const
const BigInt & get_g() const
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
BigInt step1(const BigInt &v, const std::string &group_id, const std::string &hash_id, RandomNumberGenerator &rng)
SymmetricKey step2(const BigInt &A)
std::string to_string(const BER_Object &obj)
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
BigInt generate_srp6_verifier(const std::string &identifier, const std::string &password, const std::vector< uint8_t > &salt, const std::string &group_id, const std::string &hash_id)
std::pair< BigInt, SymmetricKey > srp6_client_agree(const std::string &identifier, const std::string &password, const std::string &group_id, const std::string &hash_id, const std::vector< uint8_t > &salt, const BigInt &B, RandomNumberGenerator &rng)
std::string srp6_group_identifier(const BigInt &N, const BigInt &g)