summaryrefslogtreecommitdiff
path: root/src/util/srp.h
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2015-09-30 00:38:05 +0200
committerest31 <MTest31@outlook.com>2015-09-30 09:19:40 +0200
commit0bf1984d2c9fb3a9dc73303551c18906c3c9482b (patch)
tree68e5bbcfd4914b2389c08947e2581e4c6c50f74f /src/util/srp.h
parent2a7d01b833da7b93125ad31e787f3e2145a22ec5 (diff)
downloadminetest-0bf1984d2c9fb3a9dc73303551c18906c3c9482b.tar.gz
minetest-0bf1984d2c9fb3a9dc73303551c18906c3c9482b.tar.bz2
minetest-0bf1984d2c9fb3a9dc73303551c18906c3c9482b.zip
Fix some SRP issues
-> Remove memory allocation bugs -> Merge changes from upstream, enabling customizeable memory allocation
Diffstat (limited to 'src/util/srp.h')
-rw-r--r--src/util/srp.h31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/util/srp.h b/src/util/srp.h
index 15a2b8a68..c876e70e6 100644
--- a/src/util/srp.h
+++ b/src/util/srp.h
@@ -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);