Skip to content

Commit

Permalink
hsmtool: move sodium_init() to top level.
Browse files Browse the repository at this point in the history
This way we always call it (we weren't for some paths!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and ShahanaFarooqui committed Apr 11, 2023
1 parent e5c76f8 commit 441b38c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions tools/hsmtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 441b38c

Please sign in to comment.