Mbed TLS v2.28.8
chacha20.h
Go to the documentation of this file.
1 
15 /*
16  * Copyright The Mbed TLS Contributors
17  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
18  */
19 
20 #ifndef MBEDTLS_CHACHA20_H
21 #define MBEDTLS_CHACHA20_H
22 
23 #if !defined(MBEDTLS_CONFIG_FILE)
24 #include "mbedtls/config.h"
25 #else
26 #include MBEDTLS_CONFIG_FILE
27 #endif
28 
29 #include <stdint.h>
30 #include <stddef.h>
31 
33 #define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051
34 
35 /* MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE is deprecated and should not be
36  * used. */
38 #define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053
39 
40 /* MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED is deprecated and should not be used.
41  */
43 #define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #if !defined(MBEDTLS_CHACHA20_ALT)
50 
51 typedef struct mbedtls_chacha20_context {
52  uint32_t state[16];
53  uint8_t keystream8[64];
55 }
57 
58 #else /* MBEDTLS_CHACHA20_ALT */
59 #include "chacha20_alt.h"
60 #endif /* MBEDTLS_CHACHA20_ALT */
61 
78 
89 
107  const unsigned char key[32]);
108 
129  const unsigned char nonce[12],
130  uint32_t counter);
131 
162  size_t size,
163  const unsigned char *input,
164  unsigned char *output);
165 
194 int mbedtls_chacha20_crypt(const unsigned char key[32],
195  const unsigned char nonce[12],
196  uint32_t counter,
197  size_t size,
198  const unsigned char *input,
199  unsigned char *output);
200 
201 #if defined(MBEDTLS_SELF_TEST)
202 
208 int mbedtls_chacha20_self_test(int verbose);
209 #endif /* MBEDTLS_SELF_TEST */
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 
215 #endif /* MBEDTLS_CHACHA20_H */
mbedtls_chacha20_self_test
int mbedtls_chacha20_self_test(int verbose)
The ChaCha20 checkup routine.
mbedtls_chacha20_context
struct mbedtls_chacha20_context mbedtls_chacha20_context
mbedtls_chacha20_setkey
int mbedtls_chacha20_setkey(mbedtls_chacha20_context *ctx, const unsigned char key[32])
This function sets the encryption/decryption key.
mbedtls_chacha20_crypt
int mbedtls_chacha20_crypt(const unsigned char key[32], const unsigned char nonce[12], uint32_t counter, size_t size, const unsigned char *input, unsigned char *output)
This function encrypts or decrypts data with ChaCha20 and the given key and nonce.
mbedtls_chacha20_starts
int mbedtls_chacha20_starts(mbedtls_chacha20_context *ctx, const unsigned char nonce[12], uint32_t counter)
This function sets the nonce and initial counter value.
mbedtls_chacha20_context::keystream_bytes_used
size_t keystream_bytes_used
Definition: chacha20.h:54
mbedtls_chacha20_context::keystream8
uint8_t keystream8[64]
Definition: chacha20.h:53
mbedtls_chacha20_context
Definition: chacha20.h:51
config.h
Configuration options (set of defines)
mbedtls_chacha20_context::state
uint32_t state[16]
Definition: chacha20.h:52
mbedtls_chacha20_free
void mbedtls_chacha20_free(mbedtls_chacha20_context *ctx)
This function releases and clears the specified ChaCha20 context.
mbedtls_chacha20_update
int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx, size_t size, const unsigned char *input, unsigned char *output)
This function encrypts or decrypts data.
mbedtls_chacha20_init
void mbedtls_chacha20_init(mbedtls_chacha20_context *ctx)
This function initializes the specified ChaCha20 context.