mbed TLS v3.4.0
chacha20.h
Go to the documentation of this file.
1 
15 /*
16  * Copyright The Mbed TLS Contributors
17  * SPDX-License-Identifier: Apache-2.0
18  *
19  * Licensed under the Apache License, Version 2.0 (the "License"); you may
20  * not use this file except in compliance with the License.
21  * You may obtain a copy of the License at
22  *
23  * http://www.apache.org/licenses/LICENSE-2.0
24  *
25  * Unless required by applicable law or agreed to in writing, software
26  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
27  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28  * See the License for the specific language governing permissions and
29  * limitations under the License.
30  */
31 
32 #ifndef MBEDTLS_CHACHA20_H
33 #define MBEDTLS_CHACHA20_H
34 #include "mbedtls/private_access.h"
35 
36 #include "mbedtls/build_info.h"
37 
38 #include <stdint.h>
39 #include <stddef.h>
40 
42 #define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #if !defined(MBEDTLS_CHACHA20_ALT)
49 
50 typedef struct mbedtls_chacha20_context {
51  uint32_t MBEDTLS_PRIVATE(state)[16];
52  uint8_t MBEDTLS_PRIVATE(keystream8)[64];
53  size_t MBEDTLS_PRIVATE(keystream_bytes_used);
54 }
56 
57 #else /* MBEDTLS_CHACHA20_ALT */
58 #include "chacha20_alt.h"
59 #endif /* MBEDTLS_CHACHA20_ALT */
60 
77 
88 
106  const unsigned char key[32]);
107 
128  const unsigned char nonce[12],
129  uint32_t counter);
130 
161  size_t size,
162  const unsigned char *input,
163  unsigned char *output);
164 
193 int mbedtls_chacha20_crypt(const unsigned char key[32],
194  const unsigned char nonce[12],
195  uint32_t counter,
196  size_t size,
197  const unsigned char *input,
198  unsigned char *output);
199 
200 #if defined(MBEDTLS_SELF_TEST)
201 
207 int mbedtls_chacha20_self_test(int verbose);
208 #endif /* MBEDTLS_SELF_TEST */
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 
214 #endif /* MBEDTLS_CHACHA20_H */
struct mbedtls_chacha20_context mbedtls_chacha20_context
#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.
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.