Mbed TLS v3.6.3
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 #include "mbedtls/private_access.h"
23 
24 #include "mbedtls/build_info.h"
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 
30 #define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #if !defined(MBEDTLS_CHACHA20_ALT)
37 
38 typedef struct mbedtls_chacha20_context {
39  uint32_t MBEDTLS_PRIVATE(state)[16];
40  uint8_t MBEDTLS_PRIVATE(keystream8)[64];
41  size_t MBEDTLS_PRIVATE(keystream_bytes_used);
42 }
44 
45 #else /* MBEDTLS_CHACHA20_ALT */
46 #include "chacha20_alt.h"
47 #endif /* MBEDTLS_CHACHA20_ALT */
48 
65 
76 
94  const unsigned char key[32]);
95 
116  const unsigned char nonce[12],
117  uint32_t counter);
118 
149  size_t size,
150  const unsigned char *input,
151  unsigned char *output);
152 
181 int mbedtls_chacha20_crypt(const unsigned char key[32],
182  const unsigned char nonce[12],
183  uint32_t counter,
184  size_t size,
185  const unsigned char *input,
186  unsigned char *output);
187 
188 #if defined(MBEDTLS_SELF_TEST)
189 
195 int mbedtls_chacha20_self_test(int verbose);
196 #endif /* MBEDTLS_SELF_TEST */
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif /* MBEDTLS_CHACHA20_H */
#define MBEDTLS_PRIVATE(member)
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.
int mbedtls_chacha20_self_test(int verbose)
The ChaCha20 checkup routine.
struct mbedtls_chacha20_context mbedtls_chacha20_context
Macro wrapper for struct's members.
int mbedtls_chacha20_setkey(mbedtls_chacha20_context *ctx, const unsigned char key[32])
This function sets the encryption/decryption key.
Build-time configuration info.
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.
void mbedtls_chacha20_free(mbedtls_chacha20_context *ctx)
This function releases and clears the specified ChaCha20 context.
int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx, size_t size, const unsigned char *input, unsigned char *output)
This function encrypts or decrypts data.
void mbedtls_chacha20_init(mbedtls_chacha20_context *ctx)
This function initializes the specified ChaCha20 context.