Botan 3.4.0
Crypto and TLS for C&
Functions
ffi_srp6.cpp File Reference
#include <botan/ffi.h>
#include <botan/internal/ffi_rng.h>
#include <botan/internal/ffi_util.h>

Go to the source code of this file.

Functions

 BOTAN_FFI_DECLARE_DUMMY_STRUCT (botan_srp6_server_session_struct, 0x44F7425F)
 
int botan_srp6_client_agree (const char *identity, const char *password, const char *group_id, const char *hash_id, const uint8_t salt[], size_t salt_len, const uint8_t b[], size_t b_len, botan_rng_t rng_obj, uint8_t A[], size_t *A_len, uint8_t K[], size_t *K_len)
 
int botan_srp6_generate_verifier (const char *username, const char *password, const uint8_t salt[], size_t salt_len, const char *group_id, const char *hash_id, uint8_t verifier[], size_t *verifier_len)
 
int botan_srp6_group_size (const char *group_id, size_t *group_p_bytes)
 
int botan_srp6_server_session_destroy (botan_srp6_server_session_t srp6)
 
int botan_srp6_server_session_init (botan_srp6_server_session_t *srp6)
 
int botan_srp6_server_session_step1 (botan_srp6_server_session_t srp6, const uint8_t *verifier, size_t verifier_len, const char *group_id, const char *hash_id, botan_rng_t rng_obj, uint8_t b_pub[], size_t *b_pub_len)
 
int botan_srp6_server_session_step2 (botan_srp6_server_session_t srp6, const uint8_t a[], size_t a_len, uint8_t key[], size_t *key_len)
 

Function Documentation

◆ BOTAN_FFI_DECLARE_DUMMY_STRUCT()

BOTAN_FFI_DECLARE_DUMMY_STRUCT ( botan_srp6_server_session_struct ,
0x44F7425F  )

◆ botan_srp6_client_agree()

int botan_srp6_client_agree ( const char * username,
const char * password,
const char * group_id,
const char * hash_id,
const uint8_t salt[],
size_t salt_len,
const uint8_t B[],
size_t B_len,
botan_rng_t rng_obj,
uint8_t A[],
size_t * A_len,
uint8_t K[],
size_t * K_len )

SRP6a Client side

Parameters
usernamethe username we are attempting login for
passwordthe password we are attempting to use
group_idspecifies the shared SRP group
hash_idspecifies a secure hash function
saltis the salt value sent by the server
salt_lenthe length of salt
Bis the server's public value
B_lenis the server's public value length
rng_objis a random number generator object
Aout buffer to store the SRP-6 A value
A_lenSRP-6 A verifier value length
Kout buffer to store the symmetric value
K_lensymmetric key length
Returns
0 on success, negative on failure

Definition at line 143 of file ffi_srp6.cpp.

155 {
156#if defined(BOTAN_HAS_SRP6)
157 return ffi_guard_thunk(__func__, [=]() -> int {
158 if(!identity || !password || !salt || !group_id || !hash_id || !b || !rng_obj) {
160 }
161 try {
162 std::vector<uint8_t> saltv(salt, salt + salt_len);
164 auto b_bn = Botan::BigInt::decode(b, b_len);
165 auto [A_bn, K_sk] = Botan::srp6_client_agree(identity, password, group_id, hash_id, saltv, b_bn, rng);
166 auto ret_a = write_vec_output(A, A_len, Botan::BigInt::encode(A_bn));
167 auto ret_k = write_vec_output(K, K_len, K_sk.bits_of());
168 if(ret_a != BOTAN_FFI_SUCCESS) {
169 return ret_a;
170 }
171 if(ret_k != BOTAN_FFI_SUCCESS) {
172 return ret_k;
173 }
174 return BOTAN_FFI_SUCCESS;
175 } catch(Botan::Lookup_Error&) {
177 }
178 });
179#else
180 BOTAN_UNUSED(identity, password, group_id, hash_id, rng_obj);
181 BOTAN_UNUSED(salt, salt_len, b, b_len, A, A_len, K, K_len);
183#endif
184}
#define BOTAN_UNUSED
Definition assert.h:118
static BigInt decode(const uint8_t buf[], size_t length)
Definition bigint.h:773
static std::vector< uint8_t > encode(const BigInt &n)
Definition bigint.h:750
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:124
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:118
@ BOTAN_FFI_SUCCESS
Definition ffi.h:103
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:119
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:63
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition ffi.cpp:116
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition ffi_util.h:201
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)
Definition srp6.cpp:65

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan::BigInt::decode(), Botan::BigInt::encode(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), Botan::srp6_client_agree(), and Botan_FFI::write_vec_output().

◆ botan_srp6_generate_verifier()

int botan_srp6_generate_verifier ( const char * identifier,
const char * password,
const uint8_t salt[],
size_t salt_len,
const char * group_id,
const char * hash_id,
uint8_t verifier[],
size_t * verifier_len )

Generate a new SRP-6 verifier

Parameters
identifiera username or other client identifier
passwordthe secret used to authenticate user
salta randomly chosen value, at least 128 bits long
salt_lenthe length of salt
group_idspecifies the shared SRP group
hash_idspecifies a secure hash function
verifierout buffer to store the SRP-6 verifier value
verifier_lenSRP-6 verifier value length
Returns
0 on success, negative on failure

Definition at line 115 of file ffi_srp6.cpp.

122 {
123#if defined(BOTAN_HAS_SRP6)
124 return ffi_guard_thunk(__func__, [=]() -> int {
125 if(!username || !password || !salt || !group_id || !hash_id) {
127 }
128 try {
129 std::vector<uint8_t> salt_vec(salt, salt + salt_len);
130 auto verifier_bn = Botan::srp6_generate_verifier(username, password, salt_vec, group_id, hash_id);
131 return write_vec_output(verifier, verifier_len, Botan::BigInt::encode(verifier_bn));
132 } catch(Botan::Lookup_Error&) {
134 }
135 });
136#else
137 BOTAN_UNUSED(username, password, group_id, hash_id);
138 BOTAN_UNUSED(salt, salt_len, verifier, verifier_len);
140#endif
141}
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)
Definition srp6.cpp:128

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan::BigInt::encode(), Botan_FFI::ffi_guard_thunk(), Botan::srp6_generate_verifier(), and Botan_FFI::write_vec_output().

◆ botan_srp6_group_size()

int botan_srp6_group_size ( const char * group_id,
size_t * group_p_bytes )

Return the size, in bytes, of the prime associated with group_id

Definition at line 47 of file ffi_srp6.cpp.

47 {
48#if defined(BOTAN_HAS_SRP6)
49 if(group_id == nullptr || group_p_bytes == nullptr) {
51 }
52
53 return ffi_guard_thunk(__func__, [=]() -> int {
54 Botan::DL_Group group(group_id);
55 *group_p_bytes = group.p_bytes();
56 return BOTAN_FFI_SUCCESS;
57 });
58#else
59 BOTAN_UNUSED(group_id, group_p_bytes);
61#endif
62}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan::DL_Group::p_bytes().

◆ botan_srp6_server_session_destroy()

int botan_srp6_server_session_destroy ( botan_srp6_server_session_t srp6)

Frees all resources of the SRP-6 server session object

Parameters
srp6SRP-6 server session object
Returns
0 if success, error if invalid object handle

Definition at line 43 of file ffi_srp6.cpp.

43 {
44 return BOTAN_FFI_CHECKED_DELETE(srp6);
45}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:143

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_srp6_server_session_init()

int botan_srp6_server_session_init ( botan_srp6_server_session_t * srp6)

Initialize an SRP-6 server session object

Parameters
srp6SRP-6 server session object

Definition at line 31 of file ffi_srp6.cpp.

31 {
32#if defined(BOTAN_HAS_SRP6)
33 return ffi_guard_thunk(__func__, [=]() -> int {
34 *srp6 = new botan_srp6_server_session_struct(std::make_unique<Botan::SRP6_Server_Session>());
35 return BOTAN_FFI_SUCCESS;
36 });
37#else
38 BOTAN_UNUSED(srp6);
40#endif
41}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_srp6_server_session_step1()

int botan_srp6_server_session_step1 ( botan_srp6_server_session_t srp6,
const uint8_t * verifier,
size_t verifier_len,
const char * group_id,
const char * hash_id,
botan_rng_t rng_obj,
uint8_t b_pub[],
size_t * b_pub_len )

Definition at line 64 of file ffi_srp6.cpp.

71 {
72#if defined(BOTAN_HAS_SRP6)
73 return BOTAN_FFI_VISIT(srp6, [=](auto& s) -> int {
74 if(!verifier || !group_id || !hash_id || !rng_obj) {
76 }
77 try {
79 auto v_bn = Botan::BigInt::decode(verifier, verifier_len);
80 auto b_pub_bn = s.step1(v_bn, group_id, hash_id, rng);
81 return write_vec_output(b_pub, b_pub_len, Botan::BigInt::encode(b_pub_bn));
82 } catch(Botan::Decoding_Error&) {
84 } catch(Botan::Lookup_Error&) {
86 }
87 });
88#else
89 BOTAN_UNUSED(srp6, verifier, verifier_len, group_id, hash_id, rng_obj, b_pub, b_pub_len);
91#endif
92}
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:124

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::BigInt::decode(), Botan::BigInt::encode(), Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

◆ botan_srp6_server_session_step2()

int botan_srp6_server_session_step2 ( botan_srp6_server_session_t srp6,
const uint8_t A[],
size_t A_len,
uint8_t key[],
size_t * key_len )

SRP-6 Server side step 2

Parameters
srp6SRP-6 server session object
Athe client's value
A_lenthe client's value length
keyout buffer to store the symmetric key value
key_lensymmetric key length
Returns
0 on success, negative on failure

Definition at line 94 of file ffi_srp6.cpp.

95 {
96#if defined(BOTAN_HAS_SRP6)
97 return BOTAN_FFI_VISIT(srp6, [=](auto& s) -> int {
98 if(!a) {
100 }
101 try {
102 Botan::BigInt a_bn = Botan::BigInt::decode(a, a_len);
103 auto key_sk = s.step2(a_bn);
104 return write_vec_output(key, key_len, key_sk.bits_of());
105 } catch(Botan::Decoding_Error&) {
107 }
108 });
109#else
110 BOTAN_UNUSED(srp6, a, a_len, key, key_len);
112#endif
113}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::BigInt::decode(), and Botan_FFI::write_vec_output().