From 441b38c9eae2be8eacc8da383e47bf0f70fe8aa3 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 7 Apr 2023 21:25:14 +0930 Subject: [PATCH] hsmtool: move sodium_init() to top level. This way we always call it (we weren't for some paths!). Signed-off-by: Rusty Russell --- tools/hsmtool.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/hsmtool.c b/tools/hsmtool.c index 98299a630204..784dd87b54b0 100644 --- a/tools/hsmtool.c +++ b/tools/hsmtool.c @@ -206,10 +206,6 @@ static int decrypt_hsm(const char *hsm_secret_path) if (!passwd) errx(exit_code, "%s", err); - if (sodium_init() == -1) - errx(ERROR_LIBSODIUM, - "Could not initialize libsodium. Not enough entropy ?"); - dir = path_dirname(NULL, hsm_secret_path); backup = path_join(dir, dir, "hsm_secret.backup"); @@ -276,10 +272,6 @@ static int encrypt_hsm(const char *hsm_secret_path) dir = path_dirname(NULL, hsm_secret_path); backup = path_join(dir, dir, "hsm_secret.backup"); - if (sodium_init() == -1) - errx(ERROR_LIBSODIUM, - "Could not initialize libsodium. Not enough entropy ?"); - /* Derive the encryption key from the password provided, and try to encrypt * the seed. */ exit_code = hsm_secret_encryption_key_with_exitcode(passwd, &key, &err); @@ -630,6 +622,10 @@ int main(int argc, char *argv[]) if (!method) show_usage(argv[0]); + if (sodium_init() == -1) + errx(ERROR_LIBSODIUM, + "Could not initialize libsodium. Not enough entropy ?"); + if (streq(method, "decrypt")) { if (argc < 3) show_usage(argv[0]);