MCPcopy Create free account
hub / github.com/ElementsProject/lightning / get_encryption_key

Function get_encryption_key

common/hsm_secret.c:53–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53struct 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
81bool hsm_secret_needs_passphrase(const u8 *hsm_secret, size_t len)
82{

Callers 3

encrypt_hsmFunction · 0.85
runFunction · 0.85
extract_encrypted_secretFunction · 0.85

Calls 2

tal_freeFunction · 0.85
mlock_tal_memoryFunction · 0.85

Tested by

no test coverage detected