| 149 | } |
| 150 | |
| 151 | static u8 *decrypt_encmsg_raw(const tal_t *ctx, |
| 152 | const struct pubkey *blinding, |
| 153 | const struct secret *ss, |
| 154 | const u8 *enctlv) |
| 155 | { |
| 156 | struct secret rho; |
| 157 | u8 *dec; |
| 158 | /* All-zero npub */ |
| 159 | static const unsigned char npub[crypto_aead_chacha20poly1305_ietf_NPUBBYTES]; |
| 160 | |
| 161 | /* We need this to decrypt enctlv */ |
| 162 | subkey_from_hmac("rho", ss, &rho); |
| 163 | |
| 164 | /* BOLT-onion-message #4: |
| 165 | * - if `enctlv` is not present, or does not decrypt with the |
| 166 | * shared secret from the given `blinding` parameter: |
| 167 | * - MUST drop the message. |
| 168 | */ |
| 169 | /* Too short? */ |
| 170 | if (tal_bytelen(enctlv) < crypto_aead_chacha20poly1305_ietf_ABYTES) |
| 171 | return NULL; |
| 172 | |
| 173 | dec = tal_arr(ctx, u8, tal_bytelen(enctlv) |
| 174 | - crypto_aead_chacha20poly1305_ietf_ABYTES); |
| 175 | if (crypto_aead_chacha20poly1305_ietf_decrypt(dec, NULL, |
| 176 | NULL, |
| 177 | enctlv, tal_bytelen(enctlv), |
| 178 | NULL, 0, |
| 179 | npub, |
| 180 | rho.data) != 0) |
| 181 | return tal_free(dec); |
| 182 | |
| 183 | return dec; |
| 184 | } |
| 185 | |
| 186 | static struct tlv_encrypted_data_tlv *decrypt_encmsg(const tal_t *ctx, |
| 187 | const struct pubkey *blinding, |
no test coverage detected