| 255 | } |
| 256 | |
| 257 | static void le64_nonce(unsigned char *npub, u64 nonce) |
| 258 | { |
| 259 | /* BOLT #8: |
| 260 | * |
| 261 | * with nonce `n` encoded as 32 zero bits, followed by a |
| 262 | * *little-endian* 64-bit value. Note: this follows the Noise |
| 263 | * Protocol convention, rather than our normal endian. |
| 264 | */ |
| 265 | le64 le_nonce = cpu_to_le64(nonce); |
| 266 | const size_t zerolen = crypto_aead_chacha20poly1305_ietf_NPUBBYTES - sizeof(le_nonce); |
| 267 | |
| 268 | BUILD_ASSERT(crypto_aead_chacha20poly1305_ietf_NPUBBYTES >= sizeof(le_nonce)); |
| 269 | /* First part is 0, followed by nonce. */ |
| 270 | memset(npub, 0, zerolen); |
| 271 | memcpy(npub + zerolen, &le_nonce, sizeof(le_nonce)); |
| 272 | } |
| 273 | |
| 274 | /* BOLT #8: |
| 275 | * * `encryptWithAD(k, n, ad, plaintext)`: outputs `encrypt(k, n, ad, |
no test coverage detected