]> git.lizzy.rs Git - minetest.git/blobdiff - src/util/srp.cpp
Increase `ftos` precision (#13141)
[minetest.git] / src / util / srp.cpp
index e0ddb9020125de6c6d164a2ef27bc0c7bdbe47ed..daa7f332bd70ab94b21e6404c4b8c8e56ac6d951 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 <mini-gmp.h>
@@ -349,7 +354,7 @@ static size_t hash_length(SRP_HashAlgorithm alg)
                case SRP_SHA384: return SHA384_DIGEST_LENGTH;
                case SRP_SHA512: return SHA512_DIGEST_LENGTH;
                */
-               default: return -1;
+               default: return 0;
        };
 }
 // clang-format on
@@ -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;
 
@@ -1010,10 +1015,10 @@ void  srp_user_process_challenge(struct SRPUser *usr,
                        goto cleanup_and_exit;
 
                *bytes_M = usr->M;
-               if (len_M) *len_M = hash_length(usr->hash_alg);
+               *len_M = hash_length(usr->hash_alg);
        } else {
                *bytes_M = NULL;
-               if (len_M) *len_M = 0;
+               *len_M = 0;
        }
 
 cleanup_and_exit: