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