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

Function extract_encrypted_secret

common/hsm_secret.c:227–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225}
226
227static struct hsm_secret *extract_encrypted_secret(const tal_t *ctx,
228 const u8 *hsm_secret,
229 size_t len,
230 const char *passphrase,
231 enum hsm_secret_error *err)
232{
233 struct hsm_secret *hsms = tal(ctx, struct hsm_secret);
234 struct secret *encryption_key;
235 bool decrypt_success;
236
237 if (!passphrase) {
238 *err = HSM_SECRET_ERR_PASSPHRASE_REQUIRED;
239 return tal_free(hsms);
240 }
241 encryption_key = get_encryption_key(tmpctx, passphrase);
242 if (!encryption_key) {
243 *err = HSM_SECRET_ERR_WRONG_PASSPHRASE;
244 return tal_free(hsms);
245 }
246
247 /* Attempt decryption */
248 struct secret temp_secret;
249 decrypt_success = decrypt_hsm_secret(encryption_key, hsm_secret, &temp_secret);
250 if (!decrypt_success) {
251 *err = HSM_SECRET_ERR_WRONG_PASSPHRASE;
252 return tal_free(hsms);
253 }
254
255 /* Duplicate decrypted secret data */
256 hsms->secret_data = tal_dup_arr(hsms, u8, temp_secret.data, HSM_SECRET_PLAIN_SIZE, 0);
257
258 hsms->type = HSM_SECRET_ENCRYPTED;
259 hsms->mnemonic = NULL;
260
261 *err = HSM_SECRET_OK;
262 return hsms;
263}
264
265static struct hsm_secret *extract_mnemonic_secret(const tal_t *ctx,
266 const u8 *hsm_secret,

Callers 1

extract_hsm_secretFunction · 0.85

Calls 3

tal_freeFunction · 0.85
get_encryption_keyFunction · 0.85
decrypt_hsm_secretFunction · 0.85

Tested by

no test coverage detected