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

Function json_decryptencrypteddata

lightningd/onion_message.c:213–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211AUTODATA(json_command, &injectonionmessage_command);
212
213static struct command_result *json_decryptencrypteddata(struct command *cmd,
214 const char *buffer,
215 const jsmntok_t *obj UNNEEDED,
216 const jsmntok_t *params)
217{
218 u8 *encdata, *decrypted;
219 struct pubkey *path_key, next_path_key;
220 struct secret ss;
221 struct sha256 h;
222 struct json_stream *response;
223
224 if (!param_check(cmd, buffer, params,
225 p_req("encrypted_data", param_bin_from_hex, &encdata),
226 p_req("path_key", param_pubkey, &path_key),
227 NULL))
228 return command_param_failed();
229
230 /* BOLT #4:
231 *
232 * - MUST compute:
233 * - $`ss_i = SHA256(k_i * E_i)`$ (standard ECDH)
234 *...
235 * - $`rho_i = HMAC256(\text{"rho"}, ss_i)`$
236 * - MUST decrypt the `encrypted_recipient_data` field using $`rho_i`$
237 */
238 ecdh(path_key, &ss);
239
240 decrypted = decrypt_encmsg_raw(cmd, &ss, encdata);
241 if (!decrypted)
242 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
243 "Decryption failed!");
244
245 if (command_check_only(cmd))
246 return command_check_done(cmd);
247
248 /* BOLT #4:
249 *
250 * - $`E_{i+1} = SHA256(E_i || ss_i) * E_i`$
251 */
252 blinding_hash_e_and_ss(path_key, &ss, &h);
253 blinding_next_path_key(path_key, &h, &next_path_key);
254
255 response = json_stream_success(cmd);
256 json_object_start(response, "decryptencrypteddata");
257 json_add_hex_talarr(response, "decrypted", decrypted);
258 json_add_pubkey(response, "next_path_key", &next_path_key);
259 json_object_end(response);
260 return command_success(cmd, response);
261}
262
263static const struct json_command decryptencrypteddata_command = {
264 "decryptencrypteddata",

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
decrypt_encmsg_rawFunction · 0.85
blinding_hash_e_and_ssFunction · 0.85
blinding_next_path_keyFunction · 0.85
json_object_startFunction · 0.85
json_add_hex_talarrFunction · 0.85
json_add_pubkeyFunction · 0.85
json_object_endFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70

Tested by

no test coverage detected