mbed TLS v2.16.7
chachapoly.h
Go to the documentation of this file.
1 
15 /*
16  * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
17  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
18  *
19  * This file is provided under the Apache License 2.0, or the
20  * GNU General Public License v2.0 or later.
21  *
22  * **********
23  * Apache License 2.0:
24  *
25  * Licensed under the Apache License, Version 2.0 (the "License"); you may
26  * not use this file except in compliance with the License.
27  * You may obtain a copy of the License at
28  *
29  * http://www.apache.org/licenses/LICENSE-2.0
30  *
31  * Unless required by applicable law or agreed to in writing, software
32  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
33  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34  * See the License for the specific language governing permissions and
35  * limitations under the License.
36  *
37  * **********
38  *
39  * **********
40  * GNU General Public License v2.0 or later:
41  *
42  * This program is free software; you can redistribute it and/or modify
43  * it under the terms of the GNU General Public License as published by
44  * the Free Software Foundation; either version 2 of the License, or
45  * (at your option) any later version.
46  *
47  * This program is distributed in the hope that it will be useful,
48  * but WITHOUT ANY WARRANTY; without even the implied warranty of
49  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50  * GNU General Public License for more details.
51  *
52  * You should have received a copy of the GNU General Public License along
53  * with this program; if not, write to the Free Software Foundation, Inc.,
54  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
55  *
56  * **********
57  *
58  * This file is part of Mbed TLS (https://tls.mbed.org)
59  */
60 
61 #ifndef MBEDTLS_CHACHAPOLY_H
62 #define MBEDTLS_CHACHAPOLY_H
63 
64 #if !defined(MBEDTLS_CONFIG_FILE)
65 #include "config.h"
66 #else
67 #include MBEDTLS_CONFIG_FILE
68 #endif
69 
70 /* for shared error codes */
71 #include "poly1305.h"
72 
73 #define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054
74 #define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
80 typedef enum
81 {
84 }
86 
87 #if !defined(MBEDTLS_CHACHAPOLY_ALT)
88 
89 #include "chacha20.h"
90 
92 {
95  uint64_t aad_len;
96  uint64_t ciphertext_len;
97  int state;
99 }
101 
102 #else /* !MBEDTLS_CHACHAPOLY_ALT */
103 #include "chachapoly_alt.h"
104 #endif /* !MBEDTLS_CHACHAPOLY_ALT */
105 
149 
158 
171  const unsigned char key[32] );
172 
199  const unsigned char nonce[12],
201 
242  const unsigned char *aad,
243  size_t aad_len );
244 
277  size_t len,
278  const unsigned char *input,
279  unsigned char *output );
280 
298  unsigned char mac[16] );
299 
330  size_t length,
331  const unsigned char nonce[12],
332  const unsigned char *aad,
333  size_t aad_len,
334  const unsigned char *input,
335  unsigned char *output,
336  unsigned char tag[16] );
337 
364  size_t length,
365  const unsigned char nonce[12],
366  const unsigned char *aad,
367  size_t aad_len,
368  const unsigned char tag[16],
369  const unsigned char *input,
370  unsigned char *output );
371 
372 #if defined(MBEDTLS_SELF_TEST)
373 
379 int mbedtls_chachapoly_self_test( int verbose );
380 #endif /* MBEDTLS_SELF_TEST */
381 
382 #ifdef __cplusplus
383 }
384 #endif
385 
386 #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 mode
Definition: chachapoly.h:98
mbedtls_chachapoly_mode_t
Definition: chachapoly.h:80
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)...
struct mbedtls_chachapoly_context mbedtls_chachapoly_context
This file contains ChaCha20 definitions and functions.
Configuration options (set of defines)
mbedtls_chacha20_context chacha20_ctx
Definition: chachapoly.h:93
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.
mbedtls_poly1305_context poly1305_ctx
Definition: chachapoly.h:94
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.