mbed TLS v2.12.0
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
46 #define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053
47 #define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 #if !defined(MBEDTLS_CHACHA20_ALT)
54 
55 typedef struct
56 {
57  uint32_t state[16];
58  uint8_t keystream8[64];
60 }
62 
63 #else /* MBEDTLS_CHACHA20_ALT */
64 #include "chacha20_alt.h"
65 #endif /* MBEDTLS_CHACHA20_ALT */
66 
82 
89 
105  const unsigned char key[32] );
106 
126  const unsigned char nonce[12],
127  uint32_t counter );
128 
159  size_t size,
160  const unsigned char *input,
161  unsigned char *output );
162 
191 int mbedtls_chacha20_crypt( const unsigned char key[32],
192  const unsigned char nonce[12],
193  uint32_t counter,
194  size_t size,
195  const unsigned char* input,
196  unsigned char* output );
197 
198 #if defined(MBEDTLS_SELF_TEST)
199 
205 int mbedtls_chacha20_self_test( int verbose );
206 #endif /* MBEDTLS_SELF_TEST */
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif /* MBEDTLS_CHACHA20_H */
Configuration options (set of defines)
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.
int mbedtls_chacha20_setkey(mbedtls_chacha20_context *ctx, const unsigned char key[32])
This function sets the encryption/decryption key.
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.