| 225 | } |
| 226 | |
| 227 | static 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 | |
| 265 | static struct hsm_secret *extract_mnemonic_secret(const tal_t *ctx, |
| 266 | const u8 *hsm_secret, |
no test coverage detected