blob: 649749a015bd545f33b210a8917ce1e0bc6f1e2f [file] [log] [blame]
Daniel Kingb8025c52016-05-17 14:43:01 -03001/**
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002 * \file chachapoly.h
Daniel Kingb8025c52016-05-17 14:43:01 -03003 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +02004 * \brief This file contains the AEAD-ChaCha20-Poly1305 definitions and
5 * functions.
Daniel Kingb8025c52016-05-17 14:43:01 -03006 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +02007 * ChaCha20-Poly1305 is an algorithm for Authenticated Encryption
8 * with Associated Data (AEAD) that can be used to encrypt and
9 * authenticate data. It is based on ChaCha20 and Poly1305 by Daniel
10 * Bernstein and was standardized in RFC 7539.
11 *
12 * \author Daniel King <damaki.gh@gmail.com>
13 */
14
15/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
Daniel Kingb8025c52016-05-17 14:43:01 -030016 * 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 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +020030 * This file is part of Mbed TLS (https://tls.mbed.org)
Daniel Kingb8025c52016-05-17 14:43:01 -030031 */
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +020032
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020033#ifndef MBEDTLS_CHACHAPOLY_H
34#define MBEDTLS_CHACHAPOLY_H
Daniel Kingb8025c52016-05-17 14:43:01 -030035
36#if !defined(MBEDTLS_CONFIG_FILE)
37#include "config.h"
38#else
39#include MBEDTLS_CONFIG_FILE
40#endif
41
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +020042/* for shared error codes */
43#include "poly1305.h"
Manuel Pégourié-Gonnard346b8d52018-05-07 12:56:36 +020044
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +020045#define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054 /**< The requested operation is not permitted in the current state. */
46#define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056 /**< Authenticated decryption failed: data was not authentic. */
Daniel Kingb8025c52016-05-17 14:43:01 -030047
Manuel Pégourié-Gonnard823b7a02018-05-07 10:10:30 +020048#ifdef __cplusplus
49extern "C" {
50#endif
51
Daniel Kingb8025c52016-05-17 14:43:01 -030052typedef enum
53{
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +020054 MBEDTLS_CHACHAPOLY_ENCRYPT, /**< The mode value for performing encryption. */
55 MBEDTLS_CHACHAPOLY_DECRYPT /**< The mode value for performing decryption. */
Daniel Kingb8025c52016-05-17 14:43:01 -030056}
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020057mbedtls_chachapoly_mode_t;
Daniel Kingb8025c52016-05-17 14:43:01 -030058
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020059#if !defined(MBEDTLS_CHACHAPOLY_ALT)
Manuel Pégourié-Gonnard95d0bdb2018-05-07 09:58:35 +020060
61#include "chacha20.h"
Manuel Pégourié-Gonnard95d0bdb2018-05-07 09:58:35 +020062
Daniel Kingb8025c52016-05-17 14:43:01 -030063typedef struct
64{
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +020065 mbedtls_chacha20_context chacha20_ctx; /**< The ChaCha20 context. */
66 mbedtls_poly1305_context poly1305_ctx; /**< The Poly1305 context. */
67 uint64_t aad_len; /**< The length (bytes) of the Additional Authenticated Data. */
68 uint64_t ciphertext_len; /**< The length (bytes) of the ciphertext. */
69 int state; /**< The current state of the context. */
70 mbedtls_chachapoly_mode_t mode; /**< Cipher mode (encrypt or decrypt). */
Daniel Kingb8025c52016-05-17 14:43:01 -030071}
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020072mbedtls_chachapoly_context;
Daniel Kingb8025c52016-05-17 14:43:01 -030073
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020074#else /* !MBEDTLS_CHACHAPOLY_ALT */
75#include "chachapoly_alt.h"
76#endif /* !MBEDTLS_CHACHAPOLY_ALT */
Manuel Pégourié-Gonnard95d0bdb2018-05-07 09:58:35 +020077
Daniel Kingb8025c52016-05-17 14:43:01 -030078/**
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +020079 * \brief This function initializes the specified ChaCha20-Poly1305 context.
Daniel Kingb8025c52016-05-17 14:43:01 -030080 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +020081 * It must be the first API called before using
82 * the context. It must be followed by a call to
83 * \c mbedtls_chachapoly_setkey() before any operation can be
84 * done, and to \c mbedtls_chachapoly_free() once all
85 * operations with that context have been finished.
86 *
87 * In order to encrypt or decrypt full messages at once, for
88 * each message you should make a single call to
89 * \c mbedtls_chachapoly_crypt_and_tag() or
90 * \c mbedtls_chachapoly_auth_decrypt().
91 *
Manuel Pégourié-Gonnardbe78b072018-05-24 19:33:59 +020092 * In order to encrypt messages piecewise, for each
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +020093 * message you should make a call to
94 * \c mbedtls_chachapoly_starts(), then 0 or more calls to
95 * \c mbedtls_chachapoly_update_aad(), then 0 or more calls to
96 * \c mbedtls_chachapoly_update(), then one call to
97 * \c mbedtls_chachapoly_finish().
98 *
Manuel Pégourié-Gonnardbe78b072018-05-24 19:33:59 +020099 * \warning Decryption with the piecewise API is discouraged! Always
100 * use \c mbedtls_chachapoly_auth_decrypt() when possible!
101 *
102 * If however this is not possible because the data is too
103 * large to fit in memory, you need to:
104 *
105 * - call \c mbedtls_chachapoly_starts() and (if needed)
106 * \c mbedtls_chachapoly_update_aad() as above,
107 * - call \c mbedtls_chachapoly_update() multiple times and
108 * ensure its output (the plaintext) is NOT used in any other
109 * way than placing it in temporary storage at this point,
110 * - call \c mbedtls_chachapoly_finish() to compute the
111 * authentication tag and compared it in constant time to the
112 * tag received with the ciphertext.
113 *
114 * If the tags are not equal, you must immediately discard
115 * all previous outputs of \c mbedtls_chachapoly_update(),
116 * otherwise you can now safely use the plaintext.
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200117 *
118 * \param ctx The ChachaPoly context to initialize.
Daniel Kingb8025c52016-05-17 14:43:01 -0300119 */
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200120void mbedtls_chachapoly_init( mbedtls_chachapoly_context *ctx );
Daniel Kingb8025c52016-05-17 14:43:01 -0300121
122/**
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200123 * \brief This function releases and clears the specified ChaCha20-Poly1305 context.
Daniel Kingb8025c52016-05-17 14:43:01 -0300124 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200125 * \param ctx The ChachaPoly context to clear.
Daniel Kingb8025c52016-05-17 14:43:01 -0300126 */
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200127void mbedtls_chachapoly_free( mbedtls_chachapoly_context *ctx );
Daniel Kingb8025c52016-05-17 14:43:01 -0300128
129/**
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200130 * \brief This function sets the ChaCha20-Poly1305 symmetric encryption key.
Daniel Kingb8025c52016-05-17 14:43:01 -0300131 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200132 * \param ctx The ChaCha20-Poly1305 context to which the key should be
133 * bound.
134 * \param key The 256-bit (32 bytes) key.
Daniel Kingb8025c52016-05-17 14:43:01 -0300135 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200136 * \return \c 0 on success.
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200137 * \return #MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200138 * if \p ctx or \p key are NULL.
Daniel Kingb8025c52016-05-17 14:43:01 -0300139 */
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200140int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx,
141 const unsigned char key[32] );
Daniel Kingb8025c52016-05-17 14:43:01 -0300142
143/**
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200144 * \brief This function starts a ChaCha20-Poly1305 encryption or
145 * decryption operation.
Daniel Kingb8025c52016-05-17 14:43:01 -0300146 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200147 * \warning You must never use the same nonce twice with the same key.
148 * This would void any confidentiality and authenticity
149 * guarantees for the messages encrypted with the same nonce
150 * and key.
Daniel Kingb8025c52016-05-17 14:43:01 -0300151 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200152 * \note If the context is being used for AAD only (no data to
153 * encrypt or decrypt) then \p mode can be set to any value.
Daniel Kingb8025c52016-05-17 14:43:01 -0300154 *
Manuel Pégourié-Gonnardbe78b072018-05-24 19:33:59 +0200155 * \warning Decryption with the piecewise API is discouraged, see the
156 * warning on \c mbedtls_chachapoly_init().
157 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200158 * \param ctx The ChaCha20-Poly1305 context.
159 * \param nonce The nonce/IV to use for the message. Must be 12 bytes.
160 * \param mode The operation to perform: #MBEDTLS_CHACHAPOLY_ENCRYPT or
Manuel Pégourié-Gonnardbe78b072018-05-24 19:33:59 +0200161 * #MBEDTLS_CHACHAPOLY_DECRYPT (discouraged, see warning).
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200162 *
163 * \return \c 0 on success.
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200164 * \return #MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200165 * if \p ctx or \p mac are NULL.
Daniel Kingb8025c52016-05-17 14:43:01 -0300166 */
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200167int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx,
168 const unsigned char nonce[12],
169 mbedtls_chachapoly_mode_t mode );
Daniel Kingb8025c52016-05-17 14:43:01 -0300170
171/**
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200172 * \brief This function feeds additional data to be authenticated
173 * into an ongoing ChaCha20-Poly1305 operation.
Daniel Kingb8025c52016-05-17 14:43:01 -0300174 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200175 * The Additional Authenticated Data (AAD), also called
176 * Associated Data (AD) is only authenticated but not
177 * encrypted nor included in the encrypted output. It is
178 * usually transmitted separately fro mthe ciphertext or
179 * computed locally by each party.
Daniel Kingb8025c52016-05-17 14:43:01 -0300180 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200181 * \note This function is called before data is encrypted/decrypted.
182 * I.e. call this function to process the AAD before calling
183 * \c mbedtls_chachapoly_update().
Daniel Kingb8025c52016-05-17 14:43:01 -0300184 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200185 * You may call this function multiple times to process
186 * an arbitrary amount of AAD. It is permitted to call
187 * this function 0 times, if no AAD is used.
Daniel Kingb8025c52016-05-17 14:43:01 -0300188 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200189 * This function cannot be called any more if data has
190 * been processed by \c mbedtls_chachapoly_update(),
191 * or if the context has been finished.
Daniel Kingb8025c52016-05-17 14:43:01 -0300192 *
Manuel Pégourié-Gonnardbe78b072018-05-24 19:33:59 +0200193 * \warning Decryption with the piecewise API is discouraged, see the
194 * warning on \c mbedtls_chachapoly_init().
195 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200196 * \param ctx The ChaCha20-Poly1305 context to use.
197 * \param aad_len The length (in bytes) of the AAD. The length has no
198 * restrictions.
199 * \param aad Buffer containing the AAD.
200 * This pointer can be NULL if aad_len == 0.
Daniel Kingb8025c52016-05-17 14:43:01 -0300201 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200202 * \return \c 0 on success.
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200203 * \return #MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200204 * if \p ctx or \p aad are NULL.
205 * \return #MBEDTLS_ERR_CHACHAPOLY_BAD_STATE
206 * if the operations has not been started or has been
207 * finished, or if the AAD has been finished.
Daniel Kingb8025c52016-05-17 14:43:01 -0300208 */
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200209int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx,
Manuel Pégourié-Gonnard5ef92d32018-05-09 09:34:25 +0200210 const unsigned char *aad,
211 size_t aad_len );
Daniel Kingb8025c52016-05-17 14:43:01 -0300212
213/**
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200214 * \brief Thus function feeds data to be encrypted or decrypted
215 * into an on-going ChaCha20-Poly1305
216 * operation.
Daniel Kingb8025c52016-05-17 14:43:01 -0300217 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200218 * The direction (encryption or decryption) depends on the
219 * mode that was given when calling
220 * \c mbedtls_chachapoly_starts().
Daniel Kingb8025c52016-05-17 14:43:01 -0300221 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200222 * You may call this function multiple times to process
223 * an arbitrary amount of data. It is permitted to call
224 * this function 0 times, if no data is to be encrypted
225 * or decrypted.
Daniel Kingb8025c52016-05-17 14:43:01 -0300226 *
Manuel Pégourié-Gonnardbe78b072018-05-24 19:33:59 +0200227 * \warning Decryption with the piecewise API is discouraged, see the
228 * warning on \c mbedtls_chachapoly_init().
229 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200230 * \param ctx The ChaCha20-Poly1305 context to use.
231 * \param len The length (in bytes) of the data to encrypt or decrypt.
232 * \param input The buffer containing the data to encrypt or decrypt.
233 * This pointer can be NULL if len == 0.
234 * \param output The buffer to where the encrypted or decrypted data is written.
235 * Must be able to hold \p len bytes.
236 * This pointer can be NULL if len == 0.
Daniel Kingb8025c52016-05-17 14:43:01 -0300237 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200238 * \return \c 0 on success.
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200239 * \return #MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200240 * if \p ctx, \p input, or \p output are NULL.
241 * \return #MBEDTLS_ERR_CHACHAPOLY_BAD_STATE
242 * if the operation has not been started or has been
243 * finished.
Daniel Kingb8025c52016-05-17 14:43:01 -0300244 */
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200245int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
246 size_t len,
247 const unsigned char *input,
248 unsigned char *output );
Daniel Kingb8025c52016-05-17 14:43:01 -0300249
250/**
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200251 * \brief This function finished the ChaCha20-Poly1305 operation and
252 * generates the MAC (authentication tag).
Daniel Kingb8025c52016-05-17 14:43:01 -0300253 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200254 * \param ctx The ChaCha20-Poly1305 context to use.
255 * \param mac The buffer to where the 128-bit (16 bytes) MAC is written.
Daniel Kingb8025c52016-05-17 14:43:01 -0300256 *
Manuel Pégourié-Gonnardbe78b072018-05-24 19:33:59 +0200257 * \warning Decryption with the piecewise API is discouraged, see the
258 * warning on \c mbedtls_chachapoly_init().
259 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200260 * \return \c 0 on success.
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200261 * \return #MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200262 * if \p ctx or \p mac are NULL.
263 * \return #MBEDTLS_ERR_CHACHAPOLY_BAD_STATE
264 * if the operation has not been started or has been
265 * finished.
Daniel Kingb8025c52016-05-17 14:43:01 -0300266 */
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200267int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
268 unsigned char mac[16] );
Daniel Kingb8025c52016-05-17 14:43:01 -0300269
Daniel Kingb8025c52016-05-17 14:43:01 -0300270/**
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200271 * \brief This function performs a complete ChaCha20-Poly1305
Manuel Pégourié-Gonnard3dc62a02018-06-04 12:18:19 +0200272 * authenticated encryption with the previously-set key.
Daniel Kingb8025c52016-05-17 14:43:01 -0300273 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200274 * \note Before using this function, you must set the key with
275 * \c mbedtls_chachapoly_setkey().
Daniel Kingb8025c52016-05-17 14:43:01 -0300276 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200277 * \warning You must never use the same nonce twice with the same key.
278 * This would void any confidentiality and authenticity
279 * guarantees for the messages encrypted with the same nonce
280 * and key.
281 *
282 * \param ctx The ChaCha20-Poly1305 context to use (holds the key).
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200283 * \param length The length (in bytes) of the data to encrypt or decrypt.
284 * \param nonce The 96-bit (12 bytes) nonce/IV to use.
285 * \param aad The buffer containing the additional authenticated data (AAD).
286 * This pointer can be NULL if aad_len == 0.
287 * \param aad_len The length (in bytes) of the AAD data to process.
288 * \param input The buffer containing the data to encrypt or decrypt.
289 * This pointer can be NULL if ilen == 0.
290 * \param output The buffer to where the encrypted or decrypted data is written.
291 * This pointer can be NULL if ilen == 0.
292 * \param tag The buffer to where the computed 128-bit (16 bytes) MAC is written.
293 *
294 * \return \c 0 on success.
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200295 * \return #MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200296 * if one or more of the required parameters are NULL.
Daniel Kingb8025c52016-05-17 14:43:01 -0300297 */
Manuel Pégourié-Gonnard3dc62a02018-06-04 12:18:19 +0200298int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx,
299 size_t length,
300 const unsigned char nonce[12],
301 const unsigned char *aad,
302 size_t aad_len,
303 const unsigned char *input,
304 unsigned char *output,
305 unsigned char tag[16] );
Manuel Pégourié-Gonnard346b8d52018-05-07 12:56:36 +0200306
307/**
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200308 * \brief This function performs a complete ChaCha20-Poly1305
309 * authenticated decryption with the previously-set key.
Manuel Pégourié-Gonnard346b8d52018-05-07 12:56:36 +0200310 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200311 * \note Before using this function, you must set the key with
312 * \c mbedtls_chachapoly_setkey().
Manuel Pégourié-Gonnard346b8d52018-05-07 12:56:36 +0200313 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200314 * \param ctx The ChaCha20-Poly1305 context to use (holds the key).
315 * \param length The length (in bytes) of the data to decrypt.
316 * \param nonce The 96-bit (12 bytes) nonce/IV to use.
317 * \param aad The buffer containing the additional authenticated data (AAD).
318 * This pointer can be NULL if aad_len == 0.
319 * \param aad_len The length (in bytes) of the AAD data to process.
320 * \param tag The buffer holding the authentication tag.
321 * \param input The buffer containing the data to decrypt.
322 * This pointer can be NULL if ilen == 0.
323 * \param output The buffer to where the decrypted data is written.
324 * This pointer can be NULL if ilen == 0.
325 *
326 * \return \c 0 on success.
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200327 * \return #MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200328 * if one or more of the required parameters are NULL.
329 * \return #MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED
330 * if the data was not authentic.
Manuel Pégourié-Gonnard346b8d52018-05-07 12:56:36 +0200331 */
332int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx,
333 size_t length,
334 const unsigned char nonce[12],
335 const unsigned char *aad,
336 size_t aad_len,
337 const unsigned char tag[16],
338 const unsigned char *input,
339 unsigned char *output );
Daniel Kingb8025c52016-05-17 14:43:01 -0300340
Manuel Pégourié-Gonnardc22e61a2018-05-24 13:51:05 +0200341#if defined(MBEDTLS_SELF_TEST)
Daniel Kingb8025c52016-05-17 14:43:01 -0300342/**
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200343 * \brief The ChaCha20-Poly1305 checkup routine.
Daniel Kingb8025c52016-05-17 14:43:01 -0300344 *
Manuel Pégourié-Gonnardb500f8b2018-05-08 12:43:48 +0200345 * \return \c 0 on success.
346 * \return \c 1 on failure.
Daniel Kingb8025c52016-05-17 14:43:01 -0300347 */
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200348int mbedtls_chachapoly_self_test( int verbose );
Manuel Pégourié-Gonnardc22e61a2018-05-24 13:51:05 +0200349#endif /* MBEDTLS_SELF_TEST */
Daniel Kingb8025c52016-05-17 14:43:01 -0300350
Manuel Pégourié-Gonnard823b7a02018-05-07 10:10:30 +0200351#ifdef __cplusplus
352}
353#endif
354
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200355#endif /* MBEDTLS_CHACHAPOLY_H */