mbed TLS v2.16.3: chacha20.h Source File

mbed TLS v2.16.3

chacha20.h
Go to the documentation of this file.
1
15 /* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
16 * SPDX-License-Identifier: Apache-2.0
17 *
18 * Licensed under the Apache License, Version 2.0 (the "License"); you may
19 * not use this file except in compliance with the License.
20 * You may obtain a copy of the License at
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Unless required by applicable law or agreed to in writing, software
25 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 * See the License for the specific language governing permissions and
28 * limitations under the License.
29 *
30 * This file is part of Mbed TLS (https://tls.mbed.org)
31 */
32
33 #ifndef MBEDTLS_CHACHA20_H
34 #define MBEDTLS_CHACHA20_H
35
36 #if !defined(MBEDTLS_CONFIG_FILE)
37 #include "config.h"
38 #else
39 #include MBEDTLS_CONFIG_FILE
40 #endif
41
42 #include <stdint.h>
43 #include <stddef.h>
44
45 #define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051
47 /* MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE is deprecated and should not be
48 * used. */
49 #define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053
51 /* MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED is deprecated and should not be used.
52 */
53 #define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 #if !defined(MBEDTLS_CHACHA20_ALT)
60
61 typedef struct mbedtls_chacha20_context
62 {
63 uint32_t state[16];
64 uint8_t keystream8[64];
65 size_t keystream_bytes_used;
66 }
67 mbedtls_chacha20_context;
68
69 #else /* MBEDTLS_CHACHA20_ALT */
70 #include "chacha20_alt.h"
71 #endif /* MBEDTLS_CHACHA20_ALT */
72
88 void mbedtls_chacha20_init( mbedtls_chacha20_context *ctx );
89
99 void mbedtls_chacha20_free( mbedtls_chacha20_context *ctx );
100
117 int mbedtls_chacha20_setkey( mbedtls_chacha20_context *ctx,
118 const unsigned char key[32] );
119
139 int mbedtls_chacha20_starts( mbedtls_chacha20_context* ctx,
140 const unsigned char nonce[12],
141 uint32_t counter );
142
172 int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx,
173 size_t size,
174 const unsigned char *input,
175 unsigned char *output );
176
205 int mbedtls_chacha20_crypt( const unsigned char key[32],
206 const unsigned char nonce[12],
207 uint32_t counter,
208 size_t size,
209 const unsigned char* input,
210 unsigned char* output );
211
212 #if defined(MBEDTLS_SELF_TEST)
213
219 int mbedtls_chacha20_self_test( int verbose );
220 #endif /* MBEDTLS_SELF_TEST */
221
222 #ifdef __cplusplus
223 }
224 #endif
225
226 #endif /* MBEDTLS_CHACHA20_H */
mbedtls_chacha20_self_test
int mbedtls_chacha20_self_test(int verbose)
The ChaCha20 checkup routine.
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:65
mbedtls_chacha20_context::keystream8
uint8_t keystream8[64]
Definition: chacha20.h:64
mbedtls_chacha20_context
Definition: chacha20.h:61
config.h
Configuration options (set of defines)
mbedtls_chacha20_context::state
uint32_t state[16]
Definition: chacha20.h:63
mbedtls_chacha20_context
struct mbedtls_chacha20_context mbedtls_chacha20_context
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.