| 28 | #endif // TIMINGSAFE_BCMP |
| 29 | |
| 30 | ChaCha20Poly1305AEAD::ChaCha20Poly1305AEAD(const unsigned char* K_1, size_t K_1_len, const unsigned char* K_2, size_t K_2_len) |
| 31 | { |
| 32 | assert(K_1_len == CHACHA20_POLY1305_AEAD_KEY_LEN); |
| 33 | assert(K_2_len == CHACHA20_POLY1305_AEAD_KEY_LEN); |
| 34 | |
| 35 | m_chacha_header.SetKey(K_1, CHACHA20_POLY1305_AEAD_KEY_LEN); |
| 36 | m_chacha_main.SetKey(K_2, CHACHA20_POLY1305_AEAD_KEY_LEN); |
| 37 | |
| 38 | // set the cached sequence number to uint64 max which hints for an unset cache. |
| 39 | // we can't hit uint64 max since the rekey rule (which resets the sequence number) is 1GB |
| 40 | m_cached_aad_seqnr = std::numeric_limits<uint64_t>::max(); |
| 41 | } |
| 42 | |
| 43 | bool ChaCha20Poly1305AEAD::Crypt(uint64_t seqnr_payload, uint64_t seqnr_aad, int aad_pos, unsigned char* dest, size_t dest_len /* length of the output buffer for sanity checks */, const unsigned char* src, size_t src_len, bool is_encrypt) |
| 44 | { |