7#include <botan/sodium.h>
10#include <botan/secmem.h>
11#include <botan/stream_cipher.h>
12#include <botan/internal/ct_utils.h>
17 uint8_t ctext[],
const uint8_t ptext[],
size_t ptext_len,
const uint8_t nonce[],
const uint8_t key[]) {
27 salsa->write_keystream(auth_key.data(), auth_key.size());
29 salsa->cipher(ptext + 32, ctext + 32, ptext_len - 32);
32 poly1305->set_key(auth_key);
33 poly1305->update(ctext + 32, ptext_len - 32);
34 poly1305->final(ctext + 16);
41 uint8_t ptext[],
const uint8_t ctext[],
size_t ctext_len,
const uint8_t nonce[],
const uint8_t key[]) {
51 salsa->write_keystream(auth_key.data(), auth_key.size());
54 poly1305->set_key(auth_key);
55 poly1305->update(ctext + 32, ctext_len - 32);
62 salsa->cipher(ctext + 32, ptext + 32, ctext_len - 32);
70 const uint8_t ptext[],
72 const uint8_t nonce[],
73 const uint8_t key[]) {
79 salsa->write_keystream(auth_key.data(), auth_key.size());
81 salsa->cipher(ptext, ctext, ptext_len);
84 poly1305->set_key(auth_key);
85 poly1305->update(ctext, ptext_len);
92 const uint8_t ctext[],
95 const uint8_t nonce[],
96 const uint8_t key[]) {
102 salsa->write_keystream(auth_key.data(), auth_key.size());
105 poly1305->set_key(auth_key);
106 poly1305->update(ctext, ctext_len);
109 if(!
CT::is_equal(mac, computed_mac.data(), computed_mac.size()).as_bool()) {
113 salsa->cipher(ctext, ptext, ctext_len);
static std::unique_ptr< MessageAuthenticationCode > create_or_throw(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< StreamCipher > create_or_throw(std::string_view algo_spec, std::string_view provider="")
constexpr CT::Mask< T > is_not_equal(const T x[], const T y[], size_t len)
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
@ crypto_secretbox_KEYBYTES
@ crypto_box_curve25519xsalsa20poly1305_ZEROBYTES
@ crypto_secretbox_NONCEBYTES
int crypto_secretbox_xsalsa20poly1305_open(uint8_t ptext[], const uint8_t ctext[], size_t ctext_len, const uint8_t nonce[], const uint8_t key[])
int crypto_secretbox_open_detached(uint8_t ptext[], const uint8_t ctext[], const uint8_t mac[], size_t ctext_len, const uint8_t nonce[], const uint8_t key[])
int crypto_secretbox_xsalsa20poly1305(uint8_t ctext[], const uint8_t ptext[], size_t ptext_len, const uint8_t nonce[], const uint8_t key[])
int crypto_secretbox_detached(uint8_t ctext[], uint8_t mac[], const uint8_t ptext[], size_t ptext_len, const uint8_t nonce[], const uint8_t key[])
std::vector< T, secure_allocator< T > > secure_vector
constexpr void clear_mem(T *ptr, size_t n)