mbed TLS v2.16.3: chachapoly.h Source File

mbed TLS v2.16.3

chachapoly.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_CHACHAPOLY_H
34 #define MBEDTLS_CHACHAPOLY_H
35
36 #if !defined(MBEDTLS_CONFIG_FILE)
37 #include "config.h"
38 #else
39 #include MBEDTLS_CONFIG_FILE
40 #endif
41
42 /* for shared error codes */
43 #include "poly1305.h"
44
45 #define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054
46 #define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 typedef enum
53 {
54 MBEDTLS_CHACHAPOLY_ENCRYPT,
55 MBEDTLS_CHACHAPOLY_DECRYPT
56 }
57 mbedtls_chachapoly_mode_t;
58
59 #if !defined(MBEDTLS_CHACHAPOLY_ALT)
60
61 #include "chacha20.h"
62
63 typedef struct mbedtls_chachapoly_context
64 {
65 mbedtls_chacha20_context chacha20_ctx;
66 mbedtls_poly1305_context poly1305_ctx;
67 uint64_t aad_len;
68 uint64_t ciphertext_len;
69 int state;
70 mbedtls_chachapoly_mode_t mode;
71 }
72 mbedtls_chachapoly_context;
73
74 #else /* !MBEDTLS_CHACHAPOLY_ALT */
75 #include "chachapoly_alt.h"
76 #endif /* !MBEDTLS_CHACHAPOLY_ALT */
77
120 void mbedtls_chachapoly_init( mbedtls_chachapoly_context *ctx );
121
129 void mbedtls_chachapoly_free( mbedtls_chachapoly_context *ctx );
130
142 int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx,
143 const unsigned char key[32] );
144
170 int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx,
171 const unsigned char nonce[12],
172 mbedtls_chachapoly_mode_t mode );
173
213 int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx,
214 const unsigned char *aad,
215 size_t aad_len );
216
248 int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
249 size_t len,
250 const unsigned char *input,
251 unsigned char *output );
252
269 int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
270 unsigned char mac[16] );
271
301 int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx,
302 size_t length,
303 const unsigned char nonce[12],
304 const unsigned char *aad,
305 size_t aad_len,
306 const unsigned char *input,
307 unsigned char *output,
308 unsigned char tag[16] );
309
335 int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx,
336 size_t length,
337 const unsigned char nonce[12],
338 const unsigned char *aad,
339 size_t aad_len,
340 const unsigned char tag[16],
341 const unsigned char *input,
342 unsigned char *output );
343
344 #if defined(MBEDTLS_SELF_TEST)
345
351 int mbedtls_chachapoly_self_test( int verbose );
352 #endif /* MBEDTLS_SELF_TEST */
353
354 #ifdef __cplusplus
355 }
356 #endif
357
358 #endif /* MBEDTLS_CHACHAPOLY_H */
mbedtls_chachapoly_context::mode
mbedtls_chachapoly_mode_t mode
Definition: chachapoly.h:70
mbedtls_chachapoly_context
Definition: chachapoly.h:63
MBEDTLS_CHACHAPOLY_DECRYPT
Definition: chachapoly.h:55
mbedtls_chachapoly_setkey
int mbedtls_chachapoly_setkey(mbedtls_chachapoly_context *ctx, const unsigned char key[32])
This function sets the ChaCha20-Poly1305 symmetric encryption key.
chacha20.h
This file contains ChaCha20 definitions and functions.
mbedtls_chachapoly_context::chacha20_ctx
mbedtls_chacha20_context chacha20_ctx
Definition: chachapoly.h:65
poly1305.h
This file contains Poly1305 definitions and functions.
mbedtls_chachapoly_update
int mbedtls_chachapoly_update(mbedtls_chachapoly_context *ctx, size_t len, const unsigned char *input, unsigned char *output)
Thus function feeds data to be encrypted or decrypted into an on-going ChaCha20-Poly1305 operation.
mbedtls_chachapoly_context::poly1305_ctx
mbedtls_poly1305_context poly1305_ctx
Definition: chachapoly.h:66
mbedtls_chachapoly_mode_t
mbedtls_chachapoly_mode_t
Definition: chachapoly.h:52
mbedtls_chachapoly_context::state
int state
Definition: chachapoly.h:69
mbedtls_chachapoly_context::aad_len
uint64_t aad_len
Definition: chachapoly.h:67
mbedtls_chachapoly_self_test
int mbedtls_chachapoly_self_test(int verbose)
The ChaCha20-Poly1305 checkup routine.
mbedtls_chachapoly_context::ciphertext_len
uint64_t ciphertext_len
Definition: chachapoly.h:68
mbedtls_chachapoly_free
void mbedtls_chachapoly_free(mbedtls_chachapoly_context *ctx)
This function releases and clears the specified ChaCha20-Poly1305 context.
mbedtls_chachapoly_context
struct mbedtls_chachapoly_context mbedtls_chachapoly_context
mbedtls_chachapoly_encrypt_and_tag
int mbedtls_chachapoly_encrypt_and_tag(mbedtls_chachapoly_context *ctx, size_t length, const unsigned char nonce[12], const unsigned char *aad, size_t aad_len, const unsigned char *input, unsigned char *output, unsigned char tag[16])
This function performs a complete ChaCha20-Poly1305 authenticated encryption with the previously-set ...
MBEDTLS_CHACHAPOLY_ENCRYPT
Definition: chachapoly.h:54
mbedtls_chacha20_context
Definition: chacha20.h:61
config.h
Configuration options (set of defines)
mbedtls_chachapoly_update_aad
int mbedtls_chachapoly_update_aad(mbedtls_chachapoly_context *ctx, const unsigned char *aad, size_t aad_len)
This function feeds additional data to be authenticated into an ongoing ChaCha20-Poly1305 operation.
mbedtls_chachapoly_auth_decrypt
int mbedtls_chachapoly_auth_decrypt(mbedtls_chachapoly_context *ctx, size_t length, const unsigned char nonce[12], const unsigned char *aad, size_t aad_len, const unsigned char tag[16], const unsigned char *input, unsigned char *output)
This function performs a complete ChaCha20-Poly1305 authenticated decryption with the previously-set ...
mbedtls_poly1305_context
Definition: poly1305.h:61
mbedtls_chachapoly_finish
int mbedtls_chachapoly_finish(mbedtls_chachapoly_context *ctx, unsigned char mac[16])
This function finished the ChaCha20-Poly1305 operation and generates the MAC (authentication tag).
mbedtls_chachapoly_starts
int mbedtls_chachapoly_starts(mbedtls_chachapoly_context *ctx, const unsigned char nonce[12], mbedtls_chachapoly_mode_t mode)
This function starts a ChaCha20-Poly1305 encryption or decryption operation.
mbedtls_chachapoly_init
void mbedtls_chachapoly_init(mbedtls_chachapoly_context *ctx)
This function initializes the specified ChaCha20-Poly1305 context.