]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libcrypt-util: drop unused hash_passwrod_full()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Nov 2025 00:52:37 +0000 (09:52 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Jan 2026 03:54:00 +0000 (12:54 +0900)
It is only used by test cases. Not necessary to keep it.

src/shared/libcrypt-util.c
src/shared/libcrypt-util.h
src/test/test-libcrypt-util.c

index f981c1b9973fc1bc862f56a6d8d9e29a6065eed1..cff3f586cfd283ff3fd7acc13c7e3db5dbcb0e54 100644 (file)
@@ -119,20 +119,18 @@ static char* systemd_crypt_ra(const char *phrase, const char *setting, void **da
 
 #endif
 
-int hash_password_full(const char *password, void **cd_data, int *cd_size, char **ret) {
+int hash_password(const char *password, char **ret) {
         _cleanup_free_ char *salt = NULL;
-        _cleanup_(erase_and_freep) void *_cd_data = NULL;
+        _cleanup_(erase_and_freep) void *cd_data = NULL;
         const char *p;
-        int r, _cd_size = 0;
-
-        assert(!!cd_data == !!cd_size);
+        int r, cd_size = 0;
 
         r = make_salt(&salt);
         if (r < 0)
                 return log_debug_errno(r, "Failed to generate salt: %m");
 
         errno = 0;
-        p = crypt_ra(password, salt, cd_data ?: &_cd_data, cd_size ?: &_cd_size);
+        p = crypt_ra(password, salt, &cd_data, &cd_size);
         if (!p)
                 return log_debug_errno(errno_or_else(SYNTHETIC_ERRNO(EINVAL)),
                                        CRYPT_RA_NAME "() failed: %m");
index ed2993f82ceadd83666ca8489822d3dc98f9a49e..e80cfcaf4e21f26aec8cb3d16047e36e7fe75f51 100644 (file)
@@ -4,10 +4,7 @@
 #include "shared-forward.h"
 
 int make_salt(char **ret);
-int hash_password_full(const char *password, void **cd_data, int *cd_size, char **ret);
-static inline int hash_password(const char *password, char **ret) {
-        return hash_password_full(password, NULL, NULL, ret);
-}
+int hash_password(const char *password, char **ret);
 int test_password_one(const char *hashed_password, const char *password);
 int test_password_many(char **hashed_password, const char *password);
 bool looks_like_hashed_password(const char *s);
index 92eda2e1a7cc1d14f4305194d1ab63d45ebc4fa0..f4968d91deff69b16b84bbf5319e12a70410afb2 100644 (file)
@@ -62,45 +62,37 @@ static int test_hash_password(void) {
 static void test_hash_password_full(void) {
         log_info("/* %s */", __func__);
 
-        _cleanup_free_ void *cd_data = NULL;
-        int cd_size = 0;
-
         log_info("sizeof(struct crypt_data): %zu bytes", sizeof(struct crypt_data));
 
-        for (unsigned c = 0; c < 2; c++)
-                FOREACH_STRING(i, "abc123", "h⸿sło") {
-                        _cleanup_free_ char *hashed;
-
-                        if (c == 0)
-                                assert_se(hash_password_full(i, &cd_data, &cd_size, &hashed) == 0);
-                        else
-                                assert_se(hash_password_full(i, NULL, NULL, &hashed) == 0);
-                        log_debug("\"%s\" → \"%s\"", i, hashed);
-                        log_info("crypt_r[a] buffer size: %i bytes", cd_size);
-
-                        assert_se(test_password_one(hashed, i) == true);
-                        assert_se(test_password_one(i, hashed) <= 0); /* We get an error for non-utf8 */
-                        assert_se(test_password_one(hashed, "foobar") == false);
-                        assert_se(test_password_many(STRV_MAKE(hashed), i) == true);
-                        assert_se(test_password_many(STRV_MAKE(hashed), "foobar") == false);
-                        assert_se(test_password_many(STRV_MAKE(hashed, hashed, hashed), "foobar") == false);
-                        assert_se(test_password_many(STRV_MAKE("$y$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH",
-                                                               hashed,
-                                                               "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
-                                                     i) == true);
-                        assert_se(test_password_many(STRV_MAKE("$W$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", /* no such method exists... */
-                                                               hashed,
-                                                               "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
-                                                     i) == true);
-                        assert_se(test_password_many(STRV_MAKE("$y$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH",
-                                                               hashed,
-                                                               "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
-                                                     "") == false);
-                        assert_se(test_password_many(STRV_MAKE("$W$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", /* no such method exists... */
-                                                               hashed,
-                                                               "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
-                                                     "") == false);
-                }
+        FOREACH_STRING(i, "abc123", "h⸿sło") {
+                _cleanup_free_ char *hashed;
+
+                assert_se(hash_password(i, &hashed) == 0);
+                log_debug("\"%s\" → \"%s\"", i, hashed);
+
+                assert_se(test_password_one(hashed, i) == true);
+                assert_se(test_password_one(i, hashed) <= 0); /* We get an error for non-utf8 */
+                assert_se(test_password_one(hashed, "foobar") == false);
+                assert_se(test_password_many(STRV_MAKE(hashed), i) == true);
+                assert_se(test_password_many(STRV_MAKE(hashed), "foobar") == false);
+                assert_se(test_password_many(STRV_MAKE(hashed, hashed, hashed), "foobar") == false);
+                assert_se(test_password_many(STRV_MAKE("$y$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH",
+                                                       hashed,
+                                                       "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
+                                             i) == true);
+                assert_se(test_password_many(STRV_MAKE("$W$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", /* no such method exists... */
+                                                       hashed,
+                                                       "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
+                                             i) == true);
+                assert_se(test_password_many(STRV_MAKE("$y$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH",
+                                                       hashed,
+                                                       "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
+                                             "") == false);
+                assert_se(test_password_many(STRV_MAKE("$W$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", /* no such method exists... */
+                                                       hashed,
+                                                       "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
+                                             "") == false);
+        }
 }
 
 int main(int argc, char *argv[]) {