Loading...
Searching...
No Matches
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
9#pragma once
10
29
30#include "crypto/poly1305.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36#define CHACHA20POLY1305_KEY_BYTES (32U)
37#define CHACHA20POLY1305_NONCE_BYTES (12U)
38#define CHACHA20POLY1305_TAG_BYTES (16U)
39
43typedef union {
44 /* We need both the state matrix and the poly1305 state, but nearly not at
45 * the same time. This works as long as the first 8 members of state
46 * overlap fully or completely not with the first and second key parts
47 * from the @ref poly1305_ctx_t struct */
48 uint32_t state[16];
51
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
93int chacha20poly1305_decrypt(const uint8_t *cipher, size_t cipherlen,
94 uint8_t *msg, size_t *msglen,
95 const uint8_t *aad, size_t aadlen,
96 const uint8_t *key, const uint8_t *nonce);
97
109void chacha20_encrypt_decrypt(const uint8_t *input, uint8_t *output,
110 const uint8_t *key, const uint8_t *nonce,
111 size_t inputlen);
112
113#ifdef __cplusplus
114}
115#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:46
Chacha20poly1305 state struct.
uint32_t state[16]
The current state of the key stream.
poly1305_ctx_t poly
Poly1305 state for the MAC.