mbed TLS v3.1.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 #include "mbedtls/private_access.h"
35 
36 #include "mbedtls/build_info.h"
37 
38 /* for shared error codes */
39 #include "mbedtls/poly1305.h"
40 
42 #define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054
43 
44 #define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 typedef enum
51 {
54 }
56 
57 #if !defined(MBEDTLS_CHACHAPOLY_ALT)
58 
59 #include "mbedtls/chacha20.h"
60 
61 typedef struct mbedtls_chachapoly_context
62 {
63  mbedtls_chacha20_context MBEDTLS_PRIVATE(chacha20_ctx);
64  mbedtls_poly1305_context MBEDTLS_PRIVATE(poly1305_ctx);
65  uint64_t MBEDTLS_PRIVATE(aad_len);
66  uint64_t MBEDTLS_PRIVATE(ciphertext_len);
67  int MBEDTLS_PRIVATE(state);
69 }
70 mbedtls_chachapoly_context;
71 
72 #else /* !MBEDTLS_CHACHAPOLY_ALT */
73 #include "chachapoly_alt.h"
74 #endif /* !MBEDTLS_CHACHAPOLY_ALT */
75 
118 void mbedtls_chachapoly_init( mbedtls_chachapoly_context *ctx );
119 
127 void mbedtls_chachapoly_free( mbedtls_chachapoly_context *ctx );
128 
140 int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx,
141  const unsigned char key[32] );
142 
168 int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx,
169  const unsigned char nonce[12],
171 
211 int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx,
212  const unsigned char *aad,
213  size_t aad_len );
214 
246 int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
247  size_t len,
248  const unsigned char *input,
249  unsigned char *output );
250 
267 int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
268  unsigned char mac[16] );
269 
299 int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx,
300  size_t length,
301  const unsigned char nonce[12],
302  const unsigned char *aad,
303  size_t aad_len,
304  const unsigned char *input,
305  unsigned char *output,
306  unsigned char tag[16] );
307 
333 int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx,
334  size_t length,
335  const unsigned char nonce[12],
336  const unsigned char *aad,
337  size_t aad_len,
338  const unsigned char tag[16],
339  const unsigned char *input,
340  unsigned char *output );
341 
342 #if defined(MBEDTLS_SELF_TEST)
343 
349 int mbedtls_chachapoly_self_test( int verbose );
350 #endif /* MBEDTLS_SELF_TEST */
351 
352 #ifdef __cplusplus
353 }
354 #endif
355 
356 #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:50
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)...
#define MBEDTLS_PRIVATE(member)
This file contains ChaCha20 definitions and functions.
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.
Macro wrapper for struct's memebrs.
int mbedtls_chachapoly_self_test(int verbose)
The ChaCha20-Poly1305 checkup routine.
Build-time configuration info.
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.