]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/libcrypt-util.c
Simplify random number selection
[thirdparty/systemd.git] / src / shared / libcrypt-util.c
index c5d98671bd6d672f49c1fd9398e245fae4c9f254..81e6f1754c4f8973fb3d5cc99f0a29dbe7d151e6 100644 (file)
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #if HAVE_CRYPT_H
 /* libxcrypt is a replacement for glibc's libcrypt, and libcrypt might be
@@ -40,7 +40,11 @@ int make_salt(char **ret) {
 
         e = secure_getenv("SYSTEMD_CRYPT_PREFIX");
         if (!e)
+#if HAVE_CRYPT_PREFERRED_METHOD
                 e = crypt_preferred_method();
+#else
+                e = "$6$";
+#endif
 
         log_debug("Generating salt for hash prefix: %s", e);
 
@@ -72,7 +76,7 @@ int make_salt(char **ret) {
         log_debug("Generating fallback salt for hash prefix: $6$");
 
         /* Insist on the best randomness by setting RANDOM_BLOCK, this is about keeping passwords secret after all. */
-        r = genuine_random_bytes(raw, sizeof(raw), RANDOM_BLOCK);
+        r = crypto_random_bytes(raw, sizeof(raw));
         if (r < 0)
                 return r;
 
@@ -193,7 +197,6 @@ int test_password_one(const char *hashed_password, const char *password) {
 }
 
 int test_password_many(char **hashed_password, const char *password) {
-        char **hpw;
         int r;
 
         STRV_FOREACH(hpw, hashed_password) {