]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-authenticate: move one more function
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 25 Jun 2026 15:47:33 +0000 (00:47 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 27 Jun 2026 14:54:46 +0000 (23:54 +0900)
src/libsystemd/sd-journal/journal-authenticate.c

index 5e6a8f8106318f490be95aa2b46c286b89c3123e..854283f9298a318b5365c738ab67b56dfcc88ec8 100644 (file)
@@ -237,6 +237,41 @@ int journal_file_hmac_setup(JournalFile *f) {
 #endif
 }
 
+int journal_file_hmac_start(JournalFile *f) {
+#if HAVE_GCRYPT
+        int r;
+
+        assert(f);
+
+        if (!JOURNAL_HEADER_SEALED(f->header))
+                return 0;
+
+        if (f->hmac_running)
+                return 0;
+
+        /* Prepare HMAC for next cycle */
+        sym_gcry_md_reset(f->hmac);
+
+        uint8_t key[256 / 8]; /* Let's pass 256 bit from FSPRG to HMAC */
+        CLEANUP_ERASE(key);
+        r = FSPRG_GetKey(f->fsprg_state.iov_base, key, sizeof(key), 0);
+        if (r < 0)
+                return r;
+
+        gcry_error_t err = sym_gcry_md_setkey(f->hmac, key, sizeof(key));
+        if (gcry_err_code(err) != GPG_ERR_NO_ERROR)
+                return log_debug_errno(SYNTHETIC_ERRNO(EIO),
+                                       "sym_gcry_md_setkey() failed with error code: %s",
+                                       sym_gcry_strerror(err));
+
+        f->hmac_running = true;
+
+        return 0;
+#else
+        return -EOPNOTSUPP;
+#endif
+}
+
 int journal_file_append_tag(JournalFile *f) {
 #if HAVE_GCRYPT
         int r;
@@ -285,41 +320,6 @@ int journal_file_append_tag(JournalFile *f) {
 #endif
 }
 
-int journal_file_hmac_start(JournalFile *f) {
-#if HAVE_GCRYPT
-        int r;
-
-        assert(f);
-
-        if (!JOURNAL_HEADER_SEALED(f->header))
-                return 0;
-
-        if (f->hmac_running)
-                return 0;
-
-        /* Prepare HMAC for next cycle */
-        sym_gcry_md_reset(f->hmac);
-
-        uint8_t key[256 / 8]; /* Let's pass 256 bit from FSPRG to HMAC */
-        CLEANUP_ERASE(key);
-        r = FSPRG_GetKey(f->fsprg_state.iov_base, key, sizeof(key), 0);
-        if (r < 0)
-                return r;
-
-        gcry_error_t err = sym_gcry_md_setkey(f->hmac, key, sizeof(key));
-        if (gcry_err_code(err) != GPG_ERR_NO_ERROR)
-                return log_debug_errno(SYNTHETIC_ERRNO(EIO),
-                                       "sym_gcry_md_setkey() failed with error code: %s",
-                                       sym_gcry_strerror(err));
-
-        f->hmac_running = true;
-
-        return 0;
-#else
-        return -EOPNOTSUPP;
-#endif
-}
-
 static int journal_file_get_epoch(JournalFile *f, uint64_t realtime, uint64_t *epoch) {
         uint64_t t;