Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 1 | /** |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 2 | * \file chachapoly.c |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 3 | * |
| 4 | * \brief ChaCha20-Poly1305 AEAD construction based on RFC 7539. |
| 5 | * |
| 6 | * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 7 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 8 | * |
| 9 | * This file is provided under the Apache License 2.0, or the |
| 10 | * GNU General Public License v2.0 or later. |
| 11 | * |
| 12 | * ********** |
| 13 | * Apache License 2.0: |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 14 | * |
| 15 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 16 | * not use this file except in compliance with the License. |
| 17 | * You may obtain a copy of the License at |
| 18 | * |
| 19 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 20 | * |
| 21 | * Unless required by applicable law or agreed to in writing, software |
| 22 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 23 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 24 | * See the License for the specific language governing permissions and |
| 25 | * limitations under the License. |
| 26 | * |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 27 | * ********** |
| 28 | * |
| 29 | * ********** |
| 30 | * GNU General Public License v2.0 or later: |
| 31 | * |
| 32 | * This program is free software; you can redistribute it and/or modify |
| 33 | * it under the terms of the GNU General Public License as published by |
| 34 | * the Free Software Foundation; either version 2 of the License, or |
| 35 | * (at your option) any later version. |
| 36 | * |
| 37 | * This program is distributed in the hope that it will be useful, |
| 38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 40 | * GNU General Public License for more details. |
| 41 | * |
| 42 | * You should have received a copy of the GNU General Public License along |
| 43 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 44 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 45 | * |
| 46 | * ********** |
| 47 | * |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 48 | * This file is part of mbed TLS (https://tls.mbed.org) |
| 49 | */ |
| 50 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 51 | #include "mbedtls/config.h" |
| 52 | #else |
| 53 | #include MBEDTLS_CONFIG_FILE |
| 54 | #endif |
| 55 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 56 | #if defined(MBEDTLS_CHACHAPOLY_C) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 57 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 58 | #include "mbedtls/chachapoly.h" |
Manuel Pégourié-Gonnard | fb78c90 | 2018-05-24 13:46:15 +0200 | [diff] [blame] | 59 | #include "mbedtls/platform_util.h" |
| 60 | |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 61 | #include <string.h> |
| 62 | |
| 63 | #if defined(MBEDTLS_SELF_TEST) |
| 64 | #if defined(MBEDTLS_PLATFORM_C) |
| 65 | #include "mbedtls/platform.h" |
| 66 | #else |
| 67 | #include <stdio.h> |
| 68 | #define mbedtls_printf printf |
| 69 | #endif /* MBEDTLS_PLATFORM_C */ |
| 70 | #endif /* MBEDTLS_SELF_TEST */ |
| 71 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 72 | #if !defined(MBEDTLS_CHACHAPOLY_ALT) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 73 | |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 74 | /* Parameter validation macros */ |
| 75 | #define CHACHAPOLY_VALIDATE_RET( cond ) \ |
| 76 | MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA ) |
| 77 | #define CHACHAPOLY_VALIDATE( cond ) \ |
| 78 | MBEDTLS_INTERNAL_VALIDATE( cond ) |
| 79 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 80 | #define CHACHAPOLY_STATE_INIT ( 0 ) |
| 81 | #define CHACHAPOLY_STATE_AAD ( 1 ) |
| 82 | #define CHACHAPOLY_STATE_CIPHERTEXT ( 2 ) /* Encrypting or decrypting */ |
| 83 | #define CHACHAPOLY_STATE_FINISHED ( 3 ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 84 | |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 85 | /** |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 86 | * \brief Adds nul bytes to pad the AAD for Poly1305. |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 87 | * |
| 88 | * \param ctx The ChaCha20-Poly1305 context. |
| 89 | */ |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 90 | static int chachapoly_pad_aad( mbedtls_chachapoly_context *ctx ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 91 | { |
Daniel King | e6e7968 | 2016-05-24 11:16:17 -0300 | [diff] [blame] | 92 | uint32_t partial_block_len = (uint32_t) ( ctx->aad_len % 16U ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 93 | unsigned char zeroes[15]; |
| 94 | |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 95 | if( partial_block_len == 0U ) |
| 96 | return( 0 ); |
| 97 | |
| 98 | memset( zeroes, 0, sizeof( zeroes ) ); |
| 99 | |
| 100 | return( mbedtls_poly1305_update( &ctx->poly1305_ctx, |
| 101 | zeroes, |
| 102 | 16U - partial_block_len ) ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 106 | * \brief Adds nul bytes to pad the ciphertext for Poly1305. |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 107 | * |
| 108 | * \param ctx The ChaCha20-Poly1305 context. |
| 109 | */ |
Manuel Pégourié-Gonnard | 26c3b0a | 2018-06-04 12:06:23 +0200 | [diff] [blame] | 110 | static int chachapoly_pad_ciphertext( mbedtls_chachapoly_context *ctx ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 111 | { |
Daniel King | e6e7968 | 2016-05-24 11:16:17 -0300 | [diff] [blame] | 112 | uint32_t partial_block_len = (uint32_t) ( ctx->ciphertext_len % 16U ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 113 | unsigned char zeroes[15]; |
| 114 | |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 115 | if( partial_block_len == 0U ) |
| 116 | return( 0 ); |
| 117 | |
| 118 | memset( zeroes, 0, sizeof( zeroes ) ); |
| 119 | return( mbedtls_poly1305_update( &ctx->poly1305_ctx, |
| 120 | zeroes, |
| 121 | 16U - partial_block_len ) ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 122 | } |
| 123 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 124 | void mbedtls_chachapoly_init( mbedtls_chachapoly_context *ctx ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 125 | { |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 126 | CHACHAPOLY_VALIDATE( ctx != NULL ); |
| 127 | |
| 128 | mbedtls_chacha20_init( &ctx->chacha20_ctx ); |
| 129 | mbedtls_poly1305_init( &ctx->poly1305_ctx ); |
| 130 | ctx->aad_len = 0U; |
| 131 | ctx->ciphertext_len = 0U; |
| 132 | ctx->state = CHACHAPOLY_STATE_INIT; |
| 133 | ctx->mode = MBEDTLS_CHACHAPOLY_ENCRYPT; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 134 | } |
| 135 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 136 | void mbedtls_chachapoly_free( mbedtls_chachapoly_context *ctx ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 137 | { |
Hanno Becker | 236ea16 | 2018-12-12 14:00:34 +0000 | [diff] [blame] | 138 | if( ctx == NULL ) |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 139 | return; |
| 140 | |
| 141 | mbedtls_chacha20_free( &ctx->chacha20_ctx ); |
| 142 | mbedtls_poly1305_free( &ctx->poly1305_ctx ); |
| 143 | ctx->aad_len = 0U; |
| 144 | ctx->ciphertext_len = 0U; |
| 145 | ctx->state = CHACHAPOLY_STATE_INIT; |
| 146 | ctx->mode = MBEDTLS_CHACHAPOLY_ENCRYPT; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 147 | } |
| 148 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 149 | int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx, |
| 150 | const unsigned char key[32] ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 151 | { |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 152 | int ret; |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 153 | CHACHAPOLY_VALIDATE_RET( ctx != NULL ); |
| 154 | CHACHAPOLY_VALIDATE_RET( key != NULL ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 155 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 156 | ret = mbedtls_chacha20_setkey( &ctx->chacha20_ctx, key ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 157 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 158 | return( ret ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 159 | } |
| 160 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 161 | int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx, |
| 162 | const unsigned char nonce[12], |
| 163 | mbedtls_chachapoly_mode_t mode ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 164 | { |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 165 | int ret; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 166 | unsigned char poly1305_key[64]; |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 167 | CHACHAPOLY_VALIDATE_RET( ctx != NULL ); |
| 168 | CHACHAPOLY_VALIDATE_RET( nonce != NULL ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 169 | |
Manuel Pégourié-Gonnard | 56206c4 | 2018-05-07 12:18:34 +0200 | [diff] [blame] | 170 | /* Set counter = 0, will be update to 1 when generating Poly1305 key */ |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 171 | ret = mbedtls_chacha20_starts( &ctx->chacha20_ctx, nonce, 0U ); |
| 172 | if( ret != 0 ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 173 | goto cleanup; |
| 174 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 175 | /* Generate the Poly1305 key by getting the ChaCha20 keystream output with |
| 176 | * counter = 0. This is the same as encrypting a buffer of zeroes. |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 177 | * Only the first 256-bits (32 bytes) of the key is used for Poly1305. |
| 178 | * The other 256 bits are discarded. |
| 179 | */ |
Manuel Pégourié-Gonnard | 56206c4 | 2018-05-07 12:18:34 +0200 | [diff] [blame] | 180 | memset( poly1305_key, 0, sizeof( poly1305_key ) ); |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 181 | ret = mbedtls_chacha20_update( &ctx->chacha20_ctx, sizeof( poly1305_key ), |
Manuel Pégourié-Gonnard | 56206c4 | 2018-05-07 12:18:34 +0200 | [diff] [blame] | 182 | poly1305_key, poly1305_key ); |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 183 | if( ret != 0 ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 184 | goto cleanup; |
| 185 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 186 | ret = mbedtls_poly1305_starts( &ctx->poly1305_ctx, poly1305_key ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 187 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 188 | if( ret == 0 ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 189 | { |
| 190 | ctx->aad_len = 0U; |
| 191 | ctx->ciphertext_len = 0U; |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 192 | ctx->state = CHACHAPOLY_STATE_AAD; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 193 | ctx->mode = mode; |
| 194 | } |
| 195 | |
| 196 | cleanup: |
Manuel Pégourié-Gonnard | fb78c90 | 2018-05-24 13:46:15 +0200 | [diff] [blame] | 197 | mbedtls_platform_zeroize( poly1305_key, 64U ); |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 198 | return( ret ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 199 | } |
| 200 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 201 | int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx, |
Manuel Pégourié-Gonnard | 5ef92d3 | 2018-05-09 09:34:25 +0200 | [diff] [blame] | 202 | const unsigned char *aad, |
| 203 | size_t aad_len ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 204 | { |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 205 | CHACHAPOLY_VALIDATE_RET( ctx != NULL ); |
| 206 | CHACHAPOLY_VALIDATE_RET( aad_len == 0 || aad != NULL ); |
| 207 | |
| 208 | if( ctx->state != CHACHAPOLY_STATE_AAD ) |
Manuel Pégourié-Gonnard | c7bc9e1 | 2018-06-18 10:30:30 +0200 | [diff] [blame] | 209 | return( MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 210 | |
| 211 | ctx->aad_len += aad_len; |
| 212 | |
Manuel Pégourié-Gonnard | b1ac5e7 | 2018-05-09 09:25:00 +0200 | [diff] [blame] | 213 | return( mbedtls_poly1305_update( &ctx->poly1305_ctx, aad, aad_len ) ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 214 | } |
| 215 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 216 | int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx, |
| 217 | size_t len, |
| 218 | const unsigned char *input, |
| 219 | unsigned char *output ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 220 | { |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 221 | int ret; |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 222 | CHACHAPOLY_VALIDATE_RET( ctx != NULL ); |
| 223 | CHACHAPOLY_VALIDATE_RET( len == 0 || input != NULL ); |
| 224 | CHACHAPOLY_VALIDATE_RET( len == 0 || output != NULL ); |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 225 | |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 226 | if( ( ctx->state != CHACHAPOLY_STATE_AAD ) && |
| 227 | ( ctx->state != CHACHAPOLY_STATE_CIPHERTEXT ) ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 228 | { |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 229 | return( MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 230 | } |
| 231 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 232 | if( ctx->state == CHACHAPOLY_STATE_AAD ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 233 | { |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 234 | ctx->state = CHACHAPOLY_STATE_CIPHERTEXT; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 235 | |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 236 | ret = chachapoly_pad_aad( ctx ); |
| 237 | if( ret != 0 ) |
| 238 | return( ret ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | ctx->ciphertext_len += len; |
| 242 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 243 | if( ctx->mode == MBEDTLS_CHACHAPOLY_ENCRYPT ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 244 | { |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 245 | ret = mbedtls_chacha20_update( &ctx->chacha20_ctx, len, input, output ); |
| 246 | if( ret != 0 ) |
| 247 | return( ret ); |
| 248 | |
| 249 | ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, output, len ); |
| 250 | if( ret != 0 ) |
| 251 | return( ret ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 252 | } |
| 253 | else /* DECRYPT */ |
| 254 | { |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 255 | ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, input, len ); |
| 256 | if( ret != 0 ) |
| 257 | return( ret ); |
| 258 | |
| 259 | ret = mbedtls_chacha20_update( &ctx->chacha20_ctx, len, input, output ); |
| 260 | if( ret != 0 ) |
| 261 | return( ret ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | return( 0 ); |
| 265 | } |
| 266 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 267 | int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx, |
| 268 | unsigned char mac[16] ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 269 | { |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 270 | int ret; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 271 | unsigned char len_block[16]; |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 272 | CHACHAPOLY_VALIDATE_RET( ctx != NULL ); |
| 273 | CHACHAPOLY_VALIDATE_RET( mac != NULL ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 274 | |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 275 | if( ctx->state == CHACHAPOLY_STATE_INIT ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 276 | { |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 277 | return( MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 278 | } |
| 279 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 280 | if( ctx->state == CHACHAPOLY_STATE_AAD ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 281 | { |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 282 | ret = chachapoly_pad_aad( ctx ); |
| 283 | if( ret != 0 ) |
| 284 | return( ret ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 285 | } |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 286 | else if( ctx->state == CHACHAPOLY_STATE_CIPHERTEXT ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 287 | { |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 288 | ret = chachapoly_pad_ciphertext( ctx ); |
| 289 | if( ret != 0 ) |
| 290 | return( ret ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 291 | } |
| 292 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 293 | ctx->state = CHACHAPOLY_STATE_FINISHED; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 294 | |
| 295 | /* The lengths of the AAD and ciphertext are processed by |
| 296 | * Poly1305 as the final 128-bit block, encoded as little-endian integers. |
| 297 | */ |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 298 | len_block[ 0] = (unsigned char)( ctx->aad_len ); |
| 299 | len_block[ 1] = (unsigned char)( ctx->aad_len >> 8 ); |
| 300 | len_block[ 2] = (unsigned char)( ctx->aad_len >> 16 ); |
| 301 | len_block[ 3] = (unsigned char)( ctx->aad_len >> 24 ); |
| 302 | len_block[ 4] = (unsigned char)( ctx->aad_len >> 32 ); |
| 303 | len_block[ 5] = (unsigned char)( ctx->aad_len >> 40 ); |
| 304 | len_block[ 6] = (unsigned char)( ctx->aad_len >> 48 ); |
| 305 | len_block[ 7] = (unsigned char)( ctx->aad_len >> 56 ); |
| 306 | len_block[ 8] = (unsigned char)( ctx->ciphertext_len ); |
| 307 | len_block[ 9] = (unsigned char)( ctx->ciphertext_len >> 8 ); |
| 308 | len_block[10] = (unsigned char)( ctx->ciphertext_len >> 16 ); |
| 309 | len_block[11] = (unsigned char)( ctx->ciphertext_len >> 24 ); |
| 310 | len_block[12] = (unsigned char)( ctx->ciphertext_len >> 32 ); |
| 311 | len_block[13] = (unsigned char)( ctx->ciphertext_len >> 40 ); |
| 312 | len_block[14] = (unsigned char)( ctx->ciphertext_len >> 48 ); |
| 313 | len_block[15] = (unsigned char)( ctx->ciphertext_len >> 56 ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 314 | |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 315 | ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, len_block, 16U ); |
| 316 | if( ret != 0 ) |
| 317 | return( ret ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 318 | |
Manuel Pégourié-Gonnard | f4f01b6 | 2018-05-24 18:43:42 +0200 | [diff] [blame] | 319 | ret = mbedtls_poly1305_finish( &ctx->poly1305_ctx, mac ); |
| 320 | |
| 321 | return( ret ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 322 | } |
| 323 | |
Manuel Pégourié-Gonnard | 3dc62a0 | 2018-06-04 12:18:19 +0200 | [diff] [blame] | 324 | static int chachapoly_crypt_and_tag( mbedtls_chachapoly_context *ctx, |
| 325 | mbedtls_chachapoly_mode_t mode, |
| 326 | size_t length, |
| 327 | const unsigned char nonce[12], |
| 328 | const unsigned char *aad, |
| 329 | size_t aad_len, |
| 330 | const unsigned char *input, |
| 331 | unsigned char *output, |
| 332 | unsigned char tag[16] ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 333 | { |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 334 | int ret; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 335 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 336 | ret = mbedtls_chachapoly_starts( ctx, nonce, mode ); |
| 337 | if( ret != 0 ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 338 | goto cleanup; |
| 339 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 340 | ret = mbedtls_chachapoly_update_aad( ctx, aad, aad_len ); |
| 341 | if( ret != 0 ) |
| 342 | goto cleanup; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 343 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 344 | ret = mbedtls_chachapoly_update( ctx, length, input, output ); |
| 345 | if( ret != 0 ) |
| 346 | goto cleanup; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 347 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 348 | ret = mbedtls_chachapoly_finish( ctx, tag ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 349 | |
| 350 | cleanup: |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 351 | return( ret ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 352 | } |
| 353 | |
Manuel Pégourié-Gonnard | 3dc62a0 | 2018-06-04 12:18:19 +0200 | [diff] [blame] | 354 | int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx, |
| 355 | size_t length, |
| 356 | const unsigned char nonce[12], |
| 357 | const unsigned char *aad, |
| 358 | size_t aad_len, |
| 359 | const unsigned char *input, |
| 360 | unsigned char *output, |
| 361 | unsigned char tag[16] ) |
| 362 | { |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 363 | CHACHAPOLY_VALIDATE_RET( ctx != NULL ); |
| 364 | CHACHAPOLY_VALIDATE_RET( nonce != NULL ); |
| 365 | CHACHAPOLY_VALIDATE_RET( tag != NULL ); |
| 366 | CHACHAPOLY_VALIDATE_RET( aad_len == 0 || aad != NULL ); |
| 367 | CHACHAPOLY_VALIDATE_RET( length == 0 || input != NULL ); |
| 368 | CHACHAPOLY_VALIDATE_RET( length == 0 || output != NULL ); |
| 369 | |
Manuel Pégourié-Gonnard | 3dc62a0 | 2018-06-04 12:18:19 +0200 | [diff] [blame] | 370 | return( chachapoly_crypt_and_tag( ctx, MBEDTLS_CHACHAPOLY_ENCRYPT, |
| 371 | length, nonce, aad, aad_len, |
| 372 | input, output, tag ) ); |
| 373 | } |
| 374 | |
Manuel Pégourié-Gonnard | 346b8d5 | 2018-05-07 12:56:36 +0200 | [diff] [blame] | 375 | int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx, |
| 376 | size_t length, |
| 377 | const unsigned char nonce[12], |
| 378 | const unsigned char *aad, |
| 379 | size_t aad_len, |
| 380 | const unsigned char tag[16], |
| 381 | const unsigned char *input, |
| 382 | unsigned char *output ) |
| 383 | { |
| 384 | int ret; |
| 385 | unsigned char check_tag[16]; |
| 386 | size_t i; |
| 387 | int diff; |
Hanno Becker | 305e4e4 | 2018-12-11 15:03:16 +0000 | [diff] [blame] | 388 | CHACHAPOLY_VALIDATE_RET( ctx != NULL ); |
| 389 | CHACHAPOLY_VALIDATE_RET( nonce != NULL ); |
| 390 | CHACHAPOLY_VALIDATE_RET( tag != NULL ); |
| 391 | CHACHAPOLY_VALIDATE_RET( aad_len == 0 || aad != NULL ); |
| 392 | CHACHAPOLY_VALIDATE_RET( length == 0 || input != NULL ); |
| 393 | CHACHAPOLY_VALIDATE_RET( length == 0 || output != NULL ); |
Manuel Pégourié-Gonnard | 59d2c30 | 2018-05-10 10:39:32 +0200 | [diff] [blame] | 394 | |
Manuel Pégourié-Gonnard | 3dc62a0 | 2018-06-04 12:18:19 +0200 | [diff] [blame] | 395 | if( ( ret = chachapoly_crypt_and_tag( ctx, |
Manuel Pégourié-Gonnard | 346b8d5 | 2018-05-07 12:56:36 +0200 | [diff] [blame] | 396 | MBEDTLS_CHACHAPOLY_DECRYPT, length, nonce, |
| 397 | aad, aad_len, input, output, check_tag ) ) != 0 ) |
| 398 | { |
| 399 | return( ret ); |
| 400 | } |
| 401 | |
| 402 | /* Check tag in "constant-time" */ |
| 403 | for( diff = 0, i = 0; i < sizeof( check_tag ); i++ ) |
| 404 | diff |= tag[i] ^ check_tag[i]; |
| 405 | |
| 406 | if( diff != 0 ) |
| 407 | { |
Manuel Pégourié-Gonnard | fb78c90 | 2018-05-24 13:46:15 +0200 | [diff] [blame] | 408 | mbedtls_platform_zeroize( output, length ); |
Manuel Pégourié-Gonnard | 346b8d5 | 2018-05-07 12:56:36 +0200 | [diff] [blame] | 409 | return( MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED ); |
| 410 | } |
| 411 | |
| 412 | return( 0 ); |
| 413 | } |
| 414 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 415 | #endif /* MBEDTLS_CHACHAPOLY_ALT */ |
Manuel Pégourié-Gonnard | 95d0bdb | 2018-05-07 09:58:35 +0200 | [diff] [blame] | 416 | |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 417 | #if defined(MBEDTLS_SELF_TEST) |
| 418 | |
| 419 | static const unsigned char test_key[1][32] = |
| 420 | { |
| 421 | { |
| 422 | 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 423 | 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, |
| 424 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, |
| 425 | 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f |
| 426 | } |
| 427 | }; |
| 428 | |
| 429 | static const unsigned char test_nonce[1][12] = |
| 430 | { |
| 431 | { |
| 432 | 0x07, 0x00, 0x00, 0x00, /* 32-bit common part */ |
| 433 | 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 /* 64-bit IV */ |
| 434 | } |
| 435 | }; |
| 436 | |
| 437 | static const unsigned char test_aad[1][12] = |
| 438 | { |
| 439 | { |
| 440 | 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, |
| 441 | 0xc4, 0xc5, 0xc6, 0xc7 |
| 442 | } |
| 443 | }; |
| 444 | |
| 445 | static const size_t test_aad_len[1] = |
| 446 | { |
| 447 | 12U |
| 448 | }; |
| 449 | |
| 450 | static const unsigned char test_input[1][114] = |
| 451 | { |
| 452 | { |
| 453 | 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, |
| 454 | 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, |
| 455 | 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, |
| 456 | 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, |
| 457 | 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, |
| 458 | 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, |
| 459 | 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, |
| 460 | 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, |
| 461 | 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, |
| 462 | 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, |
| 463 | 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, |
| 464 | 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, |
| 465 | 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, |
| 466 | 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, |
| 467 | 0x74, 0x2e |
| 468 | } |
| 469 | }; |
| 470 | |
| 471 | static const unsigned char test_output[1][114] = |
| 472 | { |
| 473 | { |
| 474 | 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb, |
| 475 | 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2, |
| 476 | 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe, |
| 477 | 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6, |
| 478 | 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12, |
| 479 | 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b, |
| 480 | 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29, |
| 481 | 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36, |
| 482 | 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c, |
| 483 | 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58, |
| 484 | 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94, |
| 485 | 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc, |
| 486 | 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d, |
| 487 | 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b, |
| 488 | 0x61, 0x16 |
| 489 | } |
| 490 | }; |
| 491 | |
| 492 | static const size_t test_input_len[1] = |
| 493 | { |
| 494 | 114U |
| 495 | }; |
| 496 | |
| 497 | static const unsigned char test_mac[1][16] = |
| 498 | { |
| 499 | { |
| 500 | 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a, |
| 501 | 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91 |
| 502 | } |
| 503 | }; |
| 504 | |
Manuel Pégourié-Gonnard | c0dfcd4 | 2018-05-10 11:42:07 +0200 | [diff] [blame] | 505 | #define ASSERT( cond, args ) \ |
| 506 | do \ |
| 507 | { \ |
| 508 | if( ! ( cond ) ) \ |
| 509 | { \ |
| 510 | if( verbose != 0 ) \ |
| 511 | mbedtls_printf args; \ |
| 512 | \ |
| 513 | return( -1 ); \ |
| 514 | } \ |
| 515 | } \ |
| 516 | while( 0 ) |
| 517 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 518 | int mbedtls_chachapoly_self_test( int verbose ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 519 | { |
Manuel Pégourié-Gonnard | 346b8d5 | 2018-05-07 12:56:36 +0200 | [diff] [blame] | 520 | mbedtls_chachapoly_context ctx; |
Manuel Pégourié-Gonnard | b7e9900 | 2018-05-07 10:14:18 +0200 | [diff] [blame] | 521 | unsigned i; |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 522 | int ret; |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 523 | unsigned char output[200]; |
| 524 | unsigned char mac[16]; |
| 525 | |
Manuel Pégourié-Gonnard | c0dfcd4 | 2018-05-10 11:42:07 +0200 | [diff] [blame] | 526 | for( i = 0U; i < 1U; i++ ) |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 527 | { |
Manuel Pégourié-Gonnard | c0dfcd4 | 2018-05-10 11:42:07 +0200 | [diff] [blame] | 528 | if( verbose != 0 ) |
Manuel Pégourié-Gonnard | b7e9900 | 2018-05-07 10:14:18 +0200 | [diff] [blame] | 529 | mbedtls_printf( " ChaCha20-Poly1305 test %u ", i ); |
Daniel King | dedf4a3 | 2016-05-18 10:07:53 -0300 | [diff] [blame] | 530 | |
Manuel Pégourié-Gonnard | 346b8d5 | 2018-05-07 12:56:36 +0200 | [diff] [blame] | 531 | mbedtls_chachapoly_init( &ctx ); |
| 532 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 533 | ret = mbedtls_chachapoly_setkey( &ctx, test_key[i] ); |
| 534 | ASSERT( 0 == ret, ( "setkey() error code: %i\n", ret ) ); |
Manuel Pégourié-Gonnard | 346b8d5 | 2018-05-07 12:56:36 +0200 | [diff] [blame] | 535 | |
Manuel Pégourié-Gonnard | 3dc62a0 | 2018-06-04 12:18:19 +0200 | [diff] [blame] | 536 | ret = mbedtls_chachapoly_encrypt_and_tag( &ctx, |
| 537 | test_input_len[i], |
| 538 | test_nonce[i], |
| 539 | test_aad[i], |
| 540 | test_aad_len[i], |
| 541 | test_input[i], |
| 542 | output, |
| 543 | mac ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 544 | |
Manuel Pégourié-Gonnard | 1729789 | 2018-05-24 17:53:41 +0200 | [diff] [blame] | 545 | ASSERT( 0 == ret, ( "crypt_and_tag() error code: %i\n", ret ) ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 546 | |
Manuel Pégourié-Gonnard | c0dfcd4 | 2018-05-10 11:42:07 +0200 | [diff] [blame] | 547 | ASSERT( 0 == memcmp( output, test_output[i], test_input_len[i] ), |
| 548 | ( "failure (wrong output)\n" ) ); |
| 549 | |
| 550 | ASSERT( 0 == memcmp( mac, test_mac[i], 16U ), |
| 551 | ( "failure (wrong MAC)\n" ) ); |
Daniel King | dedf4a3 | 2016-05-18 10:07:53 -0300 | [diff] [blame] | 552 | |
Manuel Pégourié-Gonnard | 346b8d5 | 2018-05-07 12:56:36 +0200 | [diff] [blame] | 553 | mbedtls_chachapoly_free( &ctx ); |
| 554 | |
Manuel Pégourié-Gonnard | c0dfcd4 | 2018-05-10 11:42:07 +0200 | [diff] [blame] | 555 | if( verbose != 0 ) |
Daniel King | dedf4a3 | 2016-05-18 10:07:53 -0300 | [diff] [blame] | 556 | mbedtls_printf( "passed\n" ); |
Daniel King | dedf4a3 | 2016-05-18 10:07:53 -0300 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | if( verbose != 0 ) |
Daniel King | dedf4a3 | 2016-05-18 10:07:53 -0300 | [diff] [blame] | 560 | mbedtls_printf( "\n" ); |
Daniel King | b8025c5 | 2016-05-17 14:43:01 -0300 | [diff] [blame] | 561 | |
| 562 | return( 0 ); |
| 563 | } |
| 564 | |
| 565 | #endif /* MBEDTLS_SELF_TEST */ |
| 566 | |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 567 | #endif /* MBEDTLS_CHACHAPOLY_C */ |