| 51 | } |
| 52 | |
| 53 | struct secret *get_encryption_key(const tal_t *ctx, const char *passphrase) |
| 54 | { |
| 55 | struct secret *secret = tal(ctx, struct secret); |
| 56 | const u8 salt[16] = "c-lightning\0\0\0\0\0"; |
| 57 | |
| 58 | /* Check bounds. */ |
| 59 | if (strlen(passphrase) < crypto_pwhash_argon2id_PASSWD_MIN) { |
| 60 | return tal_free(secret); |
| 61 | } else if (strlen(passphrase) > crypto_pwhash_argon2id_PASSWD_MAX) { |
| 62 | return tal_free(secret); |
| 63 | } |
| 64 | |
| 65 | /* Don't swap the encryption key ! */ |
| 66 | mlock_tal_memory(secret); |
| 67 | |
| 68 | /* Now derive the key. */ |
| 69 | if (crypto_pwhash(secret->data, sizeof(secret->data), passphrase, strlen(passphrase), salt, |
| 70 | /* INTERACTIVE needs 64 MiB of RAM, MODERATE needs 256, |
| 71 | * and SENSITIVE needs 1024. */ |
| 72 | crypto_pwhash_argon2id_OPSLIMIT_MODERATE, |
| 73 | crypto_pwhash_argon2id_MEMLIMIT_MODERATE, |
| 74 | crypto_pwhash_ALG_ARGON2ID13) != 0) { |
| 75 | return tal_free(secret); |
| 76 | } |
| 77 | |
| 78 | return secret; |
| 79 | } |
| 80 | |
| 81 | bool hsm_secret_needs_passphrase(const u8 *hsm_secret, size_t len) |
| 82 | { |
no test coverage detected