mbed TLS v2.24.0
chachapoly.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_CHACHAPOLY_H
33 #define MBEDTLS_CHACHAPOLY_H
34 
35 #if !defined(MBEDTLS_CONFIG_FILE)
36 #include "mbedtls/config.h"
37 #else
38 #include MBEDTLS_CONFIG_FILE
39 #endif
40 
41 /* for shared error codes */
42 #include "mbedtls/poly1305.h"
43 
44 #define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054
45 #define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 typedef enum
52 {
55 }
57 
58 #if !defined(MBEDTLS_CHACHAPOLY_ALT)
59 
60 #include "mbedtls/chacha20.h"
61 
62 typedef struct mbedtls_chachapoly_context
63 {
64  mbedtls_chacha20_context chacha20_ctx;
65  mbedtls_poly1305_context poly1305_ctx;
66  uint64_t aad_len;
67  uint64_t ciphertext_len;
68  int state;
70 }
71 mbedtls_chachapoly_context;
72 
73 #else /* !MBEDTLS_CHACHAPOLY_ALT */
74 #include "chachapoly_alt.h"
75 #endif /* !MBEDTLS_CHACHAPOLY_ALT */
76 
119 void mbedtls_chachapoly_init( mbedtls_chachapoly_context *ctx );
120 
128 void mbedtls_chachapoly_free( mbedtls_chachapoly_context *ctx );
129 
141 int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx,
142  const unsigned char key[32] );
143 
169 int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx,
170  const unsigned char nonce[12],
172 
212 int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx,
213  const unsigned char *aad,
214  size_t aad_len );
215 
247 int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
248  size_t len,
249  const unsigned char *input,
250  unsigned char *output );
251 
268 int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
269  unsigned char mac[16] );
270 
300 int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx,
301  size_t length,
302  const unsigned char nonce[12],
303  const unsigned char *aad,
304  size_t aad_len,
305  const unsigned char *input,
306  unsigned char *output,
307  unsigned char tag[16] );
308 
334 int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx,
335  size_t length,
336  const unsigned char nonce[12],
337  const unsigned char *aad,
338  size_t aad_len,
339  const unsigned char tag[16],
340  const unsigned char *input,
341  unsigned char *output );
342 
343 #if defined(MBEDTLS_SELF_TEST)
344 
350 int mbedtls_chachapoly_self_test( int verbose );
351 #endif /* MBEDTLS_SELF_TEST */
352 
353 #ifdef __cplusplus
354 }
355 #endif
356 
357 #endif /* MBEDTLS_CHACHAPOLY_H */
void mbedtls_chachapoly_init(mbedtls_chachapoly_context *ctx)
This function initializes the specified ChaCha20-Poly1305 context.
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_mode_t
Definition: chachapoly.h:51
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)...
This file contains ChaCha20 definitions and functions.
Configuration options (set of defines)
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...
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 ...
int mbedtls_chachapoly_setkey(mbedtls_chachapoly_context *ctx, const unsigned char key[32])
This function sets the ChaCha20-Poly1305 symmetric encryption key.
int mbedtls_chachapoly_self_test(int verbose)
The ChaCha20-Poly1305 checkup routine.
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 ...
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.
void mbedtls_chachapoly_free(mbedtls_chachapoly_context *ctx)
This function releases and clears the specified ChaCha20-Poly1305 context.
This file contains Poly1305 definitions and functions.