mbed TLS v2.23.0

chacha20.h
Go to the documentation of this file.
1
15 /*
16 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
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 * This file is part of Mbed TLS (https://tls.mbed.org)
32 */
33
34 #ifndef MBEDTLS_CHACHA20_H
35 #define MBEDTLS_CHACHA20_H
36
37 #if !defined(MBEDTLS_CONFIG_FILE)
38 #include "mbedtls/config.h"
39 #else
40 #include MBEDTLS_CONFIG_FILE
41 #endif
42
43 #include <stdint.h>
44 #include <stddef.h>
45
46 #define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051
48 /* MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE is deprecated and should not be
49 * used. */
50 #define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053
52 /* MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED is deprecated and should not be used.
53 */
54 #define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 #if !defined(MBEDTLS_CHACHA20_ALT)
61
62 typedef struct mbedtls_chacha20_context
63 {
64 uint32_t state[16];
65 uint8_t keystream8[64];
66 size_t keystream_bytes_used;
67 }
68 mbedtls_chacha20_context;
69
70 #else /* MBEDTLS_CHACHA20_ALT */
71 #include "chacha20_alt.h"
72 #endif /* MBEDTLS_CHACHA20_ALT */
73
89 void mbedtls_chacha20_init( mbedtls_chacha20_context *ctx );
90
100 void mbedtls_chacha20_free( mbedtls_chacha20_context *ctx );
101
118 int mbedtls_chacha20_setkey( mbedtls_chacha20_context *ctx,
119 const unsigned char key[32] );
120
140 int mbedtls_chacha20_starts( mbedtls_chacha20_context* ctx,
141 const unsigned char nonce[12],
142 uint32_t counter );
143
173 int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx,
174 size_t size,
175 const unsigned char *input,
176 unsigned char *output );
177
206 int mbedtls_chacha20_crypt( const unsigned char key[32],
207 const unsigned char nonce[12],
208 uint32_t counter,
209 size_t size,
210 const unsigned char* input,
211 unsigned char* output );
212
213 #if defined(MBEDTLS_SELF_TEST)
214
220 int mbedtls_chacha20_self_test( int verbose );
221 #endif /* MBEDTLS_SELF_TEST */
222
223 #ifdef __cplusplus
224 }
225 #endif
226
227 #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:66
mbedtls_chacha20_context::keystream8
uint8_t keystream8[64]
Definition: chacha20.h:65
mbedtls_chacha20_context
Definition: chacha20.h:63
config.h
Configuration options (set of defines)
mbedtls_chacha20_context::state
uint32_t state[16]
Definition: chacha20.h:64
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.