chacha20poly1305.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Koen Zandberg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
28 #ifndef CRYPTO_CHACHA20POLY1305_H
29 #define CRYPTO_CHACHA20POLY1305_H
30 
31 #include "crypto/poly1305.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define CHACHA20POLY1305_KEY_BYTES (32U)
38 #define CHACHA20POLY1305_NONCE_BYTES (12U)
39 #define CHACHA20POLY1305_TAG_BYTES (16U)
44 typedef union {
45  /* We need both the state matrix and the poly1305 state, but nearly not at
46  * the same time. This works as long as the first 8 members of state
47  * overlap fully or completely not with the first and second key parts
48  * from the @ref poly1305_ctx_t struct */
49  uint32_t state[16];
52 
73 void chacha20poly1305_encrypt(uint8_t *cipher, const uint8_t *msg,
74  size_t msglen, const uint8_t *aad, size_t aadlen,
75  const uint8_t *key, const uint8_t *nonce);
76 
94 int chacha20poly1305_decrypt(const uint8_t *cipher, size_t cipherlen,
95  uint8_t *msg, size_t *msglen,
96  const uint8_t *aad, size_t aadlen,
97  const uint8_t *key, const uint8_t *nonce);
98 
99 #ifdef __cplusplus
100 }
101 #endif
102 #endif /* CRYPTO_CHACHA20POLY1305_H */
103 
chacha20poly1305_ctx_t::poly
poly1305_ctx_t poly
Poly1305 state for the MAC.
Definition: chacha20poly1305.h:50
chacha20poly1305_ctx_t
Chacha20poly1305 state struct.
Definition: chacha20poly1305.h:44
poly1305.h
Poly1305 MAC interface.
chacha20poly1305_decrypt
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.
chacha20poly1305_encrypt
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_ctx_t
Poly1305 context.
Definition: poly1305.h:46