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