mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-12 16:58:39 +00:00
Fix some SRP issues
-> Remove memory allocation bugs -> Merge changes from upstream, enabling customizeable memory allocation
This commit is contained in:
parent
2a7d01b833
commit
0bf1984d2c
4 changed files with 153 additions and 82 deletions
|
@ -78,6 +78,22 @@ typedef enum
|
|||
SRP_SHA512*/
|
||||
} SRP_HashAlgorithm;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SRP_OK,
|
||||
SRP_ERR,
|
||||
} SRP_Result;
|
||||
|
||||
/* Sets the memory functions used by srp.
|
||||
* Note: this doesn't set the memory functions used by gmp,
|
||||
* but it is supported to have different functions for srp and gmp.
|
||||
* Don't call this after you have already allocated srp structures.
|
||||
*/
|
||||
void srp_set_memory_functions(
|
||||
void *(*new_srp_alloc) (size_t),
|
||||
void *(*new_srp_realloc) (void *, size_t),
|
||||
void (*new_srp_free) (void *));
|
||||
|
||||
/* Out: bytes_v, len_v
|
||||
*
|
||||
* The caller is responsible for freeing the memory allocated for bytes_v
|
||||
|
@ -86,8 +102,11 @@ typedef enum
|
|||
* If provided, they must contain ASCII text of the hexidecimal notation.
|
||||
*
|
||||
* If bytes_s == NULL, it is filled with random data. The caller is responsible for freeing.
|
||||
*
|
||||
* Returns SRP_OK on success, and SRP_ERR on error.
|
||||
* bytes_s might be in this case invalid, don't free it.
|
||||
*/
|
||||
void srp_create_salted_verification_key( SRP_HashAlgorithm alg,
|
||||
SRP_Result srp_create_salted_verification_key( SRP_HashAlgorithm alg,
|
||||
SRP_NGType ng_type, const char *username_for_verifier,
|
||||
const unsigned char *password, size_t len_password,
|
||||
unsigned char **bytes_s, size_t *len_s,
|
||||
|
@ -101,6 +120,8 @@ void srp_create_salted_verification_key( SRP_HashAlgorithm alg,
|
|||
* The n_hex and g_hex parameters should be 0 unless SRP_NG_CUSTOM is used for ng_type
|
||||
*
|
||||
* If bytes_b == NULL, random data is used for b.
|
||||
*
|
||||
* Returns pointer to SRPVerifier on success, and NULL on error.
|
||||
*/
|
||||
struct SRPVerifier* srp_verifier_new(SRP_HashAlgorithm alg, SRP_NGType ng_type,
|
||||
const char *username,
|
||||
|
@ -114,7 +135,7 @@ struct SRPVerifier* srp_verifier_new(SRP_HashAlgorithm alg, SRP_NGType ng_type,
|
|||
|
||||
void srp_verifier_delete( struct SRPVerifier* ver );
|
||||
|
||||
|
||||
// srp_verifier_verify_session must have been called before
|
||||
int srp_verifier_is_authenticated( struct SRPVerifier* ver );
|
||||
|
||||
|
||||
|
@ -128,7 +149,9 @@ const unsigned char* srp_verifier_get_session_key( struct SRPVerifier* ver,
|
|||
size_t srp_verifier_get_session_key_length(struct SRPVerifier* ver);
|
||||
|
||||
|
||||
/* user_M must be exactly srp_verifier_get_session_key_length() bytes in size */
|
||||
/* Verifies session, on success, it writes bytes_HAMK.
|
||||
* user_M must be exactly srp_verifier_get_session_key_length() bytes in size
|
||||
*/
|
||||
void srp_verifier_verify_session( struct SRPVerifier* ver,
|
||||
const unsigned char* user_M, unsigned char** bytes_HAMK );
|
||||
|
||||
|
@ -154,7 +177,7 @@ size_t srp_user_get_session_key_length(struct SRPUser* usr);
|
|||
|
||||
/* Output: username, bytes_A, len_A. If you don't want it get written, set username to NULL.
|
||||
* If bytes_a == NULL, random data is used for a. */
|
||||
void srp_user_start_authentication(struct SRPUser* usr, char** username,
|
||||
SRP_Result srp_user_start_authentication(struct SRPUser* usr, char** username,
|
||||
const unsigned char* bytes_a, size_t len_a,
|
||||
unsigned char** bytes_A, size_t* len_A);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue