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