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

Function decrypt_scb

plugins/chanbackup.c:257–290  ·  view source on GitHub ↗

Returns decrypted SCB in form of a u8 array */

Source from the content-addressed store, hash-verified

255
256/* Returns decrypted SCB in form of a u8 array */
257static u8 *decrypt_scb(struct plugin *p)
258{
259 const struct chanbackup *cb = chanbackup(p);
260 u8 *filedata = get_file_data(tmpctx, p);
261
262 crypto_secretstream_xchacha20poly1305_state crypto_state;
263
264 if (tal_bytelen(filedata) < ABYTES +
265 HEADER_LEN)
266 plugin_err(p, "SCB file is corrupted!");
267
268 u8 *decrypt_scb = tal_arr(tmpctx, u8, tal_bytelen(filedata) -
269 ABYTES -
270 HEADER_LEN);
271
272 /* The header part */
273 if (crypto_secretstream_xchacha20poly1305_init_pull(&crypto_state,
274 filedata,
275 cb->secret.data) != 0)
276 {
277 plugin_err(p, "SCB file is corrupted!");
278 }
279
280 if (crypto_secretstream_xchacha20poly1305_pull(&crypto_state, decrypt_scb,
281 NULL, 0,
282 filedata +
283 HEADER_LEN,
284 tal_bytelen(filedata)-
285 HEADER_LEN,
286 NULL, 0) != 0) {
287 plugin_err(p, "SCB file is corrupted!");
288 }
289 return decrypt_scb;
290}
291
292static struct command_result *after_recover_rpc(struct command *cmd,
293 const char *method,

Callers 2

json_emergencyrecoverFunction · 0.85

Calls 4

get_file_dataFunction · 0.85
tal_bytelenFunction · 0.85
chanbackupFunction · 0.70
plugin_errFunction · 0.70

Tested by

no test coverage detected