Loading...
Searching...
No Matches
chacha20poly1305.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Koen Zandberg
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
26
27#include "compiler_hints.h"
28#include "crypto/poly1305.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#define CHACHA20POLY1305_KEY_BYTES (32U)
35#define CHACHA20POLY1305_NONCE_BYTES (12U)
36#define CHACHA20POLY1305_TAG_BYTES (16U)
37
41typedef union {
42 /* We need both the state matrix and the poly1305 state, but nearly not at
43 * the same time. This works as long as the first 8 members of state
44 * overlap fully or completely not with the first and second key parts
45 * from the @ref poly1305_ctx_t struct */
46 uint32_t state[16];
49
70ACCESS(read_only, 2, 3)
71ACCESS(read_only, 4, 5)
72void chacha20poly1305_encrypt(uint8_t *cipher, const uint8_t *msg,
73 size_t msglen, const uint8_t *aad, size_t aadlen,
74 const uint8_t *key, const uint8_t *nonce);
75
96ACCESS(read_only, 1, 2)
97ACCESS(read_only, 5, 6)
98int chacha20poly1305_decrypt(const uint8_t *cipher, size_t cipherlen,
99 uint8_t *msg, size_t *msglen,
100 const uint8_t *aad, size_t aadlen,
101 const uint8_t *key, const uint8_t *nonce);
102
114ACCESS(read_only, 1, 5)
115ACCESS(write_only, 2, 5)
116void chacha20_encrypt_decrypt(const uint8_t *input, uint8_t *output,
117 const uint8_t *key, const uint8_t *nonce,
118 size_t inputlen);
119
120#ifdef __cplusplus
121}
122#endif
Common macros and compiler attributes/pragmas configuration.
#define ACCESS(mode, ptr_idx, size_idx)
Emit an attribute (if supported by the compiler) that declares how a function will access its paramet...
int chacha20poly1305_decrypt(const uint8_t *cipher, size_t cipherlen, uint8_t *msg, size_t *msglen, const uint8_t *aad, size_t aadlen, const uint8_t *key, const uint8_t *nonce)
Verify the tag and decrypt a ciphertext to plaintext.
void chacha20_encrypt_decrypt(const uint8_t *input, uint8_t *output, const uint8_t *key, const uint8_t *nonce, size_t inputlen)
Encrypt a plaintext to ciphertext with the ChaCha20 algorithm.
void chacha20poly1305_encrypt(uint8_t *cipher, const uint8_t *msg, size_t msglen, const uint8_t *aad, size_t aadlen, const uint8_t *key, const uint8_t *nonce)
Encrypt a plaintext to ciphertext and append a tag to protect the ciphertext and additional data.
Poly1305 MAC interface.
Poly1305 context.
Definition poly1305.h:45
Chacha20poly1305 state struct.
uint32_t state[16]
The current state of the key stream.
poly1305_ctx_t poly
Poly1305 state for the MAC.