| 157 | } |
| 158 | |
| 159 | u8 *decrypt_encmsg_raw(const tal_t *ctx, |
| 160 | const struct secret *ss, |
| 161 | const u8 *enctlv) |
| 162 | { |
| 163 | struct secret rho; |
| 164 | u8 *dec; |
| 165 | /* All-zero npub */ |
| 166 | static const unsigned char npub[crypto_aead_chacha20poly1305_ietf_NPUBBYTES]; |
| 167 | |
| 168 | /* BOLT #4: |
| 169 | * The reader of the `encrypted_recipient_data`: |
| 170 | *... |
| 171 | *- $`rho_i = HMAC256(\text{"rho"}, ss_i)`$ |
| 172 | *- MUST decrypt the `encrypted_recipient_data` field using $`rho_i`$ |
| 173 | * as a key using ChaCha20-Poly1305 and an all-zero nonce key. |
| 174 | */ |
| 175 | subkey_from_hmac("rho", ss, &rho); |
| 176 | |
| 177 | /* BOLT #4: |
| 178 | * - If the `encrypted_recipient_data` field is missing, cannot be |
| 179 | * decrypted into an `encrypted_data_tlv` or contains unknown even |
| 180 | * fields: |
| 181 | * - MUST return an error |
| 182 | */ |
| 183 | /* Too short? */ |
| 184 | if (tal_bytelen(enctlv) < crypto_aead_chacha20poly1305_ietf_ABYTES) |
| 185 | return NULL; |
| 186 | |
| 187 | dec = tal_arr(ctx, u8, tal_bytelen(enctlv) |
| 188 | - crypto_aead_chacha20poly1305_ietf_ABYTES); |
| 189 | if (crypto_aead_chacha20poly1305_ietf_decrypt(dec, NULL, |
| 190 | NULL, |
| 191 | enctlv, tal_bytelen(enctlv), |
| 192 | NULL, 0, |
| 193 | npub, |
| 194 | rho.data) != 0) |
| 195 | return tal_free(dec); |
| 196 | |
| 197 | return dec; |
| 198 | } |
| 199 | |
| 200 | struct tlv_encrypted_data_tlv *decrypt_encrypted_data(const tal_t *ctx, |
| 201 | const struct secret *ss, |
no test coverage detected