]> git.lizzy.rs Git - minetest.git/blobdiff - src/util/srp.cpp
numeric: Fix clang, broken since d5456da
[minetest.git] / src / util / srp.cpp
index 0d3c938a3a593bb6a244e57ba429153e8e1f2937..f4d369d687ce68a80cefb395c46df495a12fb64d 100644 (file)
  */
 
 // clang-format off
+
+#include <cstddef>
+
 #ifdef WIN32
        #include <windows.h>
        #include <wincrypt.h>
 #else
-       #include <time.h>
+       #include <ctime>
+
 #endif
 // clang-format on
 
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
+#include <cstdlib>
+#include <cstring>
+#include <cstdio>
+#include <cstdint>
 
 #include <config.h>
 
-#if USE_SYSTEM_GMP || defined (__ANDROID__) || defined (ANDROID)
+#if USE_SYSTEM_GMP
        #include <gmp.h>
 #else
-       #include <gmp/mini-gmp.h>
+       #include <mini-gmp.h>
 #endif
 
 #include <util/sha2.h>
@@ -417,7 +422,7 @@ static SRP_Result H_nn(
 }
 
 static SRP_Result H_ns(mpz_t result, SRP_HashAlgorithm alg, const unsigned char *n,
-       size_t len_n, const unsigned char *bytes, size_t len_bytes)
+       size_t len_n, const unsigned char *bytes, uint32_t len_bytes)
 {
        unsigned char buff[SHA512_DIGEST_LENGTH];
        size_t nbytes = len_n + len_bytes;
@@ -542,7 +547,7 @@ static SRP_Result fill_buff()
 
        if (!fp) return SRP_ERR;
 
-       if (fread(g_rand_buff, sizeof(g_rand_buff), 1, fp) != 1) return SRP_ERR;
+       if (fread(g_rand_buff, sizeof(g_rand_buff), 1, fp) != 1) { fclose(fp); return SRP_ERR; }
        if (fclose(fp)) return SRP_ERR;
 #endif
        return SRP_OK;
@@ -611,7 +616,7 @@ SRP_Result srp_create_salted_verification_key( SRP_HashAlgorithm alg,
                        if (fill_buff() != SRP_OK) goto error_and_exit;
                *bytes_s = (unsigned char *)srp_alloc(size_to_fill);
                if (!*bytes_s) goto error_and_exit;
-               memcpy(*bytes_s, &g_rand_buff + g_rand_idx, size_to_fill);
+               memcpy(*bytes_s, &g_rand_buff[g_rand_idx], size_to_fill);
                g_rand_idx += size_to_fill;
        }
 
@@ -696,7 +701,7 @@ struct SRPVerifier *srp_verifier_new(SRP_HashAlgorithm alg,
                goto cleanup_and_exit;
        }
 
-       memcpy((char *)ver->username, username, ulen);
+       memcpy(ver->username, username, ulen);
 
        ver->authenticated = 0;
 
@@ -861,7 +866,7 @@ struct SRPUser *srp_user_new(SRP_HashAlgorithm alg, SRP_NGType ng_type,
                mpz_clear(usr->a);
                mpz_clear(usr->A);
                mpz_clear(usr->S);
-               if (usr->ng) delete_ng(usr->ng);
+               delete_ng(usr->ng);
                srp_free(usr->username);
                srp_free(usr->username_verifier);
                if (usr->password) {