|
28 | 28 | #define PASSPHRASE_HASH_LEN 32 |
29 | 29 | #define HSM_SECRET_PLAIN_SIZE 32 |
30 | 30 |
|
31 | | -void destroy_secret(struct secret *secret) |
32 | | -{ |
33 | | - sodium_munlock(secret->data, sizeof(secret->data)); |
34 | | -} |
35 | | - |
36 | 31 | /* Helper function to validate a mnemonic string */ |
37 | 32 | static bool validate_mnemonic(const char *mnemonic, enum hsm_secret_error *err) |
38 | 33 | { |
@@ -70,9 +65,7 @@ struct secret *get_encryption_key(const tal_t *ctx, const char *passphrase) |
70 | 65 | } |
71 | 66 |
|
72 | 67 | /* Don't swap the encryption key ! */ |
73 | | - if (sodium_mlock(secret->data, sizeof(secret->data)) != 0) |
74 | | - return tal_free(secret); |
75 | | - tal_add_destructor(secret, destroy_secret); |
| 68 | + mlock_tal_memory(secret); |
76 | 69 |
|
77 | 70 | /* Now derive the key. */ |
78 | 71 | if (crypto_pwhash(secret->data, sizeof(secret->data), passphrase, strlen(passphrase), salt, |
@@ -254,10 +247,6 @@ static struct hsm_secret *extract_encrypted_secret(const tal_t *ctx, |
254 | 247 | /* Attempt decryption */ |
255 | 248 | struct secret temp_secret; |
256 | 249 | decrypt_success = decrypt_hsm_secret(encryption_key, hsm_secret, &temp_secret); |
257 | | - |
258 | | - /* Clear encryption key immediately after use */ |
259 | | - destroy_secret(encryption_key); |
260 | | - |
261 | 250 | if (!decrypt_success) { |
262 | 251 | *err = HSM_SECRET_ERR_WRONG_PASSPHRASE; |
263 | 252 | return tal_free(hsms); |
@@ -389,11 +378,6 @@ bool encrypt_legacy_hsm_secret(const struct secret *encryption_key, |
389 | 378 | return true; |
390 | 379 | } |
391 | 380 |
|
392 | | -static void destroy_passphrase(char *passphrase) |
393 | | -{ |
394 | | - sodium_munlock(passphrase, tal_bytelen(passphrase)); |
395 | | -} |
396 | | - |
397 | 381 | /* Disable terminal echo if needed */ |
398 | 382 | static bool disable_echo(struct termios *saved_term) |
399 | 383 | { |
@@ -457,11 +441,7 @@ const char *read_stdin_pass(const tal_t *ctx, enum hsm_secret_error *err) |
457 | 441 | return NULL; |
458 | 442 | } |
459 | 443 |
|
460 | | - /* Memory locking is mandatory: failure means we're on an insecure system */ |
461 | | - if (sodium_mlock(input, tal_bytelen(input)) != 0) |
462 | | - abort(); |
463 | | - |
464 | | - tal_add_destructor(input, destroy_passphrase); |
| 444 | + mlock_tal_memory(input); |
465 | 445 |
|
466 | 446 | if (echo_disabled) |
467 | 447 | restore_echo(&saved_term); |
|
0 commit comments