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 
27 #include "crypto/poly1305.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #define CHACHA20POLY1305_KEY_BYTES (32U)
34 #define CHACHA20POLY1305_NONCE_BYTES (12U)
35 #define CHACHA20POLY1305_TAG_BYTES (16U)
40 typedef union {
41  /* We need both the state matrix and the poly1305 state, but nearly not at
42  * the same time. This works as long as the first 8 members of state
43  * overlap fully or completely not with the first and second key parts
44  * from the @ref poly1305_ctx_t struct */
45  uint32_t state[16];
48 
69 void chacha20poly1305_encrypt(uint8_t *cipher, const uint8_t *msg,
70  size_t msglen, const uint8_t *aad, size_t aadlen,
71  const uint8_t *key, const uint8_t *nonce);
72 
90 int chacha20poly1305_decrypt(const uint8_t *cipher, size_t cipherlen,
91  uint8_t *msg, size_t *msglen,
92  const uint8_t *aad, size_t aadlen,
93  const uint8_t *key, const uint8_t *nonce);
94 
106 void chacha20_encrypt_decrypt(const uint8_t *input, uint8_t *output,
107  const uint8_t *key, const uint8_t *nonce,
108  size_t inputlen);
109 
110 #ifdef __cplusplus
111 }
112 #endif
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:43
Chacha20poly1305 state struct.
poly1305_ctx_t poly
Poly1305 state for the MAC.