Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 1 | /* |
| 2 | * NIST SP800-38C compliant CCM implementation |
| 3 | * |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 4 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame^] | 5 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Definition of CCM: |
| 10 | * http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf |
| 11 | * RFC 3610 "Counter with CBC-MAC (CCM)" |
| 12 | * |
| 13 | * Related: |
| 14 | * RFC 5116 "An Interface and Algorithms for Authenticated Encryption" |
| 15 | */ |
| 16 | |
Gilles Peskine | db09ef6 | 2020-06-03 01:43:33 +0200 | [diff] [blame] | 17 | #include "common.h" |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 18 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 19 | #if defined(MBEDTLS_CCM_C) |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 20 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 21 | #include "mbedtls/ccm.h" |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 22 | #include "mbedtls/platform_util.h" |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 23 | #include "mbedtls/error.h" |
Dave Rodgman | c280520 | 2023-09-11 18:25:16 +0100 | [diff] [blame] | 24 | #include "mbedtls/constant_time.h" |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 25 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 26 | #include <string.h> |
| 27 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 28 | #include "mbedtls/platform.h" |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 29 | |
Steven Cooreman | 222e2ff | 2017-04-04 11:37:15 +0200 | [diff] [blame] | 30 | #if !defined(MBEDTLS_CCM_ALT) |
| 31 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 32 | #define CCM_VALIDATE_RET(cond) \ |
| 33 | MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_CCM_BAD_INPUT) |
| 34 | #define CCM_VALIDATE(cond) \ |
| 35 | MBEDTLS_INTERNAL_VALIDATE(cond) |
k-stachowiak | 26d365e | 2018-12-11 12:22:16 +0100 | [diff] [blame] | 36 | |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 37 | #define CCM_ENCRYPT 0 |
| 38 | #define CCM_DECRYPT 1 |
| 39 | |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 40 | /* |
| 41 | * Initialize context |
| 42 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 43 | void mbedtls_ccm_init(mbedtls_ccm_context *ctx) |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 44 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 45 | CCM_VALIDATE(ctx != NULL); |
| 46 | memset(ctx, 0, sizeof(mbedtls_ccm_context)); |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 49 | int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx, |
| 50 | mbedtls_cipher_id_t cipher, |
| 51 | const unsigned char *key, |
| 52 | unsigned int keybits) |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 53 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 54 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 55 | const mbedtls_cipher_info_t *cipher_info; |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 56 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 57 | CCM_VALIDATE_RET(ctx != NULL); |
| 58 | CCM_VALIDATE_RET(key != NULL); |
k-stachowiak | 26d365e | 2018-12-11 12:22:16 +0100 | [diff] [blame] | 59 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 60 | cipher_info = mbedtls_cipher_info_from_values(cipher, keybits, |
| 61 | MBEDTLS_MODE_ECB); |
| 62 | if (cipher_info == NULL) { |
| 63 | return MBEDTLS_ERR_CCM_BAD_INPUT; |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 64 | } |
| 65 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 66 | if (cipher_info->block_size != 16) { |
| 67 | return MBEDTLS_ERR_CCM_BAD_INPUT; |
| 68 | } |
| 69 | |
| 70 | mbedtls_cipher_free(&ctx->cipher_ctx); |
| 71 | |
| 72 | if ((ret = mbedtls_cipher_setup(&ctx->cipher_ctx, cipher_info)) != 0) { |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | if ((ret = mbedtls_cipher_setkey(&ctx->cipher_ctx, key, keybits, |
| 77 | MBEDTLS_ENCRYPT)) != 0) { |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | return 0; |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /* |
| 85 | * Free context |
| 86 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 87 | void mbedtls_ccm_free(mbedtls_ccm_context *ctx) |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 88 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 89 | if (ctx == NULL) { |
k-stachowiak | fd42d53 | 2018-12-11 14:37:51 +0100 | [diff] [blame] | 90 | return; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 91 | } |
| 92 | mbedtls_cipher_free(&ctx->cipher_ctx); |
| 93 | mbedtls_platform_zeroize(ctx, sizeof(mbedtls_ccm_context)); |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 96 | /* |
| 97 | * Macros for common operations. |
| 98 | * Results in smaller compiled code than static inline functions. |
| 99 | */ |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 100 | |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 101 | /* |
| 102 | * Update the CBC-MAC state in y using a block in b |
| 103 | * (Always using b as the source helps the compiler optimise a bit better.) |
| 104 | */ |
| 105 | #define UPDATE_CBC_MAC \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 106 | for (i = 0; i < 16; i++) \ |
| 107 | y[i] ^= b[i]; \ |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 108 | \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 109 | if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, y, 16, y, &olen)) != 0) \ |
| 110 | return ret; |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 111 | |
| 112 | /* |
| 113 | * Encrypt or decrypt a partial block with CTR |
| 114 | * Warning: using b for temporary storage! src and dst must not be b! |
Manuel Pégourié-Gonnard | 0f6b66d | 2014-05-07 14:43:46 +0200 | [diff] [blame] | 115 | * This avoids allocating one more 16 bytes buffer while allowing src == dst. |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 116 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 117 | #define CTR_CRYPT(dst, src, len) \ |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 118 | do \ |
| 119 | { \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 120 | if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctr, \ |
| 121 | 16, b, &olen)) != 0) \ |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 122 | { \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 123 | return ret; \ |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 124 | } \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 125 | \ |
| 126 | for (i = 0; i < (len); i++) \ |
| 127 | (dst)[i] = (src)[i] ^ b[i]; \ |
| 128 | } while (0) |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 129 | |
| 130 | /* |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 131 | * Authenticated encryption or decryption |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 132 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 133 | static int ccm_auth_crypt(mbedtls_ccm_context *ctx, int mode, size_t length, |
| 134 | const unsigned char *iv, size_t iv_len, |
| 135 | const unsigned char *add, size_t add_len, |
| 136 | const unsigned char *input, unsigned char *output, |
| 137 | unsigned char *tag, size_t tag_len) |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 138 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 139 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 140 | unsigned char i; |
Manuel Pégourié-Gonnard | 9de64f5 | 2015-07-01 15:51:43 +0200 | [diff] [blame] | 141 | unsigned char q; |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 142 | size_t len_left, olen; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 143 | unsigned char b[16]; |
| 144 | unsigned char y[16]; |
| 145 | unsigned char ctr[16]; |
| 146 | const unsigned char *src; |
| 147 | unsigned char *dst; |
| 148 | |
| 149 | /* |
| 150 | * Check length requirements: SP800-38C A.1 |
| 151 | * Additional requirement: a < 2^16 - 2^8 to simplify the code. |
| 152 | * 'length' checked later (when writing it to the first block) |
Janos Follath | 997e85c | 2018-05-29 11:33:45 +0100 | [diff] [blame] | 153 | * |
| 154 | * Also, loosen the requirements to enable support for CCM* (IEEE 802.15.4). |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 155 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 156 | if (tag_len == 2 || tag_len > 16 || tag_len % 2 != 0) { |
| 157 | return MBEDTLS_ERR_CCM_BAD_INPUT; |
| 158 | } |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 159 | |
| 160 | /* Also implies q is within bounds */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 161 | if (iv_len < 7 || iv_len > 13) { |
| 162 | return MBEDTLS_ERR_CCM_BAD_INPUT; |
| 163 | } |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 164 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 165 | if (add_len >= 0xFF00) { |
| 166 | return MBEDTLS_ERR_CCM_BAD_INPUT; |
| 167 | } |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 168 | |
Manuel Pégourié-Gonnard | 9de64f5 | 2015-07-01 15:51:43 +0200 | [diff] [blame] | 169 | q = 16 - 1 - (unsigned char) iv_len; |
| 170 | |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 171 | /* |
| 172 | * First block B_0: |
| 173 | * 0 .. 0 flags |
| 174 | * 1 .. iv_len nonce (aka iv) |
| 175 | * iv_len+1 .. 15 length |
| 176 | * |
| 177 | * With flags as (bits): |
| 178 | * 7 0 |
| 179 | * 6 add present? |
| 180 | * 5 .. 3 (t - 2) / 2 |
| 181 | * 2 .. 0 q - 1 |
| 182 | */ |
| 183 | b[0] = 0; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 184 | b[0] |= (add_len > 0) << 6; |
| 185 | b[0] |= ((tag_len - 2) / 2) << 3; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 186 | b[0] |= q - 1; |
| 187 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 188 | memcpy(b + 1, iv, iv_len); |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 189 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 190 | for (i = 0, len_left = length; i < q; i++, len_left >>= 8) { |
| 191 | b[15-i] = MBEDTLS_BYTE_0(len_left); |
| 192 | } |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 193 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 194 | if (len_left > 0) { |
| 195 | return MBEDTLS_ERR_CCM_BAD_INPUT; |
| 196 | } |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 197 | |
| 198 | |
| 199 | /* Start CBC-MAC with first block */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 200 | memset(y, 0, 16); |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 201 | UPDATE_CBC_MAC; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * If there is additional data, update CBC-MAC with |
| 205 | * add_len, add, 0 (padding to a block boundary) |
| 206 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 207 | if (add_len > 0) { |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 208 | size_t use_len; |
| 209 | len_left = add_len; |
| 210 | src = add; |
| 211 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 212 | memset(b, 0, 16); |
| 213 | MBEDTLS_PUT_UINT16_BE(add_len, b, 0); |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 214 | |
| 215 | use_len = len_left < 16 - 2 ? len_left : 16 - 2; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 216 | memcpy(b + 2, src, use_len); |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 217 | len_left -= use_len; |
| 218 | src += use_len; |
| 219 | |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 220 | UPDATE_CBC_MAC; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 221 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 222 | while (len_left > 0) { |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 223 | use_len = len_left > 16 ? 16 : len_left; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 224 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 225 | memset(b, 0, 16); |
| 226 | memcpy(b, src, use_len); |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 227 | UPDATE_CBC_MAC; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 228 | |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 229 | len_left -= use_len; |
| 230 | src += use_len; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
| 234 | /* |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 235 | * Prepare counter block for encryption: |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 236 | * 0 .. 0 flags |
| 237 | * 1 .. iv_len nonce (aka iv) |
| 238 | * iv_len+1 .. 15 counter (initially 1) |
| 239 | * |
| 240 | * With flags as (bits): |
| 241 | * 7 .. 3 0 |
| 242 | * 2 .. 0 q - 1 |
| 243 | */ |
| 244 | ctr[0] = q - 1; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 245 | memcpy(ctr + 1, iv, iv_len); |
| 246 | memset(ctr + 1 + iv_len, 0, q); |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 247 | ctr[15] = 1; |
| 248 | |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 249 | /* |
| 250 | * Authenticate and {en,de}crypt the message. |
| 251 | * |
| 252 | * The only difference between encryption and decryption is |
| 253 | * the respective order of authentication and {en,de}cryption. |
| 254 | */ |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 255 | len_left = length; |
| 256 | src = input; |
| 257 | dst = output; |
| 258 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 259 | while (len_left > 0) { |
Manuel Pégourié-Gonnard | 9de64f5 | 2015-07-01 15:51:43 +0200 | [diff] [blame] | 260 | size_t use_len = len_left > 16 ? 16 : len_left; |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 261 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 262 | if (mode == CCM_ENCRYPT) { |
| 263 | memset(b, 0, 16); |
| 264 | memcpy(b, src, use_len); |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 265 | UPDATE_CBC_MAC; |
Manuel Pégourié-Gonnard | ce77d55 | 2014-05-06 18:06:52 +0200 | [diff] [blame] | 266 | } |
| 267 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 268 | CTR_CRYPT(dst, src, use_len); |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 269 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 270 | if (mode == CCM_DECRYPT) { |
| 271 | memset(b, 0, 16); |
| 272 | memcpy(b, dst, use_len); |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 273 | UPDATE_CBC_MAC; |
Manuel Pégourié-Gonnard | ce77d55 | 2014-05-06 18:06:52 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 276 | dst += use_len; |
| 277 | src += use_len; |
| 278 | len_left -= use_len; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 279 | |
Manuel Pégourié-Gonnard | ce77d55 | 2014-05-06 18:06:52 +0200 | [diff] [blame] | 280 | /* |
| 281 | * Increment counter. |
| 282 | * No need to check for overflow thanks to the length check above. |
| 283 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 284 | for (i = 0; i < q; i++) { |
| 285 | if (++ctr[15-i] != 0) { |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 286 | break; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 287 | } |
| 288 | } |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 291 | /* |
Manuel Pégourié-Gonnard | aed6065 | 2014-05-07 13:14:42 +0200 | [diff] [blame] | 292 | * Authentication: reset counter and crypt/mask internal tag |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 293 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 294 | for (i = 0; i < q; i++) { |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 295 | ctr[15-i] = 0; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 296 | } |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 297 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 298 | CTR_CRYPT(y, y, 16); |
| 299 | memcpy(tag, y, tag_len); |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 300 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 301 | return 0; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 302 | } |
| 303 | |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 304 | /* |
| 305 | * Authenticated encryption |
| 306 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 307 | int mbedtls_ccm_star_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length, |
| 308 | const unsigned char *iv, size_t iv_len, |
| 309 | const unsigned char *add, size_t add_len, |
| 310 | const unsigned char *input, unsigned char *output, |
| 311 | unsigned char *tag, size_t tag_len) |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 312 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 313 | CCM_VALIDATE_RET(ctx != NULL); |
| 314 | CCM_VALIDATE_RET(iv != NULL); |
| 315 | CCM_VALIDATE_RET(add_len == 0 || add != NULL); |
| 316 | CCM_VALIDATE_RET(length == 0 || input != NULL); |
| 317 | CCM_VALIDATE_RET(length == 0 || output != NULL); |
| 318 | CCM_VALIDATE_RET(tag_len == 0 || tag != NULL); |
| 319 | return ccm_auth_crypt(ctx, CCM_ENCRYPT, length, iv, iv_len, |
| 320 | add, add_len, input, output, tag, tag_len); |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 323 | int mbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length, |
| 324 | const unsigned char *iv, size_t iv_len, |
| 325 | const unsigned char *add, size_t add_len, |
| 326 | const unsigned char *input, unsigned char *output, |
| 327 | unsigned char *tag, size_t tag_len) |
Janos Follath | b5734a2 | 2018-05-14 14:31:49 +0100 | [diff] [blame] | 328 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 329 | CCM_VALIDATE_RET(ctx != NULL); |
| 330 | CCM_VALIDATE_RET(iv != NULL); |
| 331 | CCM_VALIDATE_RET(add_len == 0 || add != NULL); |
| 332 | CCM_VALIDATE_RET(length == 0 || input != NULL); |
| 333 | CCM_VALIDATE_RET(length == 0 || output != NULL); |
| 334 | CCM_VALIDATE_RET(tag_len == 0 || tag != NULL); |
| 335 | if (tag_len == 0) { |
| 336 | return MBEDTLS_ERR_CCM_BAD_INPUT; |
| 337 | } |
Janos Follath | b5734a2 | 2018-05-14 14:31:49 +0100 | [diff] [blame] | 338 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 339 | return mbedtls_ccm_star_encrypt_and_tag(ctx, length, iv, iv_len, add, |
| 340 | add_len, input, output, tag, tag_len); |
Janos Follath | b5734a2 | 2018-05-14 14:31:49 +0100 | [diff] [blame] | 341 | } |
| 342 | |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 343 | /* |
| 344 | * Authenticated decryption |
| 345 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 346 | int mbedtls_ccm_star_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, |
| 347 | const unsigned char *iv, size_t iv_len, |
| 348 | const unsigned char *add, size_t add_len, |
| 349 | const unsigned char *input, unsigned char *output, |
| 350 | const unsigned char *tag, size_t tag_len) |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 351 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 352 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 353 | unsigned char check_tag[16]; |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 354 | int diff; |
| 355 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 356 | CCM_VALIDATE_RET(ctx != NULL); |
| 357 | CCM_VALIDATE_RET(iv != NULL); |
| 358 | CCM_VALIDATE_RET(add_len == 0 || add != NULL); |
| 359 | CCM_VALIDATE_RET(length == 0 || input != NULL); |
| 360 | CCM_VALIDATE_RET(length == 0 || output != NULL); |
| 361 | CCM_VALIDATE_RET(tag_len == 0 || tag != NULL); |
k-stachowiak | 26d365e | 2018-12-11 12:22:16 +0100 | [diff] [blame] | 362 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 363 | if ((ret = ccm_auth_crypt(ctx, CCM_DECRYPT, length, |
| 364 | iv, iv_len, add, add_len, |
| 365 | input, output, check_tag, tag_len)) != 0) { |
| 366 | return ret; |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /* Check tag in "constant-time" */ |
Dave Rodgman | c280520 | 2023-09-11 18:25:16 +0100 | [diff] [blame] | 370 | diff = mbedtls_ct_memcmp(tag, check_tag, tag_len); |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 371 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 372 | if (diff != 0) { |
| 373 | mbedtls_platform_zeroize(output, length); |
| 374 | return MBEDTLS_ERR_CCM_AUTH_FAILED; |
| 375 | } |
| 376 | |
| 377 | return 0; |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 378 | } |
| 379 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 380 | int mbedtls_ccm_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, |
| 381 | const unsigned char *iv, size_t iv_len, |
| 382 | const unsigned char *add, size_t add_len, |
| 383 | const unsigned char *input, unsigned char *output, |
| 384 | const unsigned char *tag, size_t tag_len) |
Janos Follath | b5734a2 | 2018-05-14 14:31:49 +0100 | [diff] [blame] | 385 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 386 | CCM_VALIDATE_RET(ctx != NULL); |
| 387 | CCM_VALIDATE_RET(iv != NULL); |
| 388 | CCM_VALIDATE_RET(add_len == 0 || add != NULL); |
| 389 | CCM_VALIDATE_RET(length == 0 || input != NULL); |
| 390 | CCM_VALIDATE_RET(length == 0 || output != NULL); |
| 391 | CCM_VALIDATE_RET(tag_len == 0 || tag != NULL); |
k-stachowiak | f712534 | 2018-12-11 15:57:19 +0100 | [diff] [blame] | 392 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 393 | if (tag_len == 0) { |
| 394 | return MBEDTLS_ERR_CCM_BAD_INPUT; |
| 395 | } |
Janos Follath | b5734a2 | 2018-05-14 14:31:49 +0100 | [diff] [blame] | 396 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 397 | return mbedtls_ccm_star_auth_decrypt(ctx, length, iv, iv_len, add, |
| 398 | add_len, input, output, tag, tag_len); |
Janos Follath | b5734a2 | 2018-05-14 14:31:49 +0100 | [diff] [blame] | 399 | } |
Steven Cooreman | 222e2ff | 2017-04-04 11:37:15 +0200 | [diff] [blame] | 400 | #endif /* !MBEDTLS_CCM_ALT */ |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 401 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 402 | #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 403 | /* |
| 404 | * Examples 1 to 3 from SP800-38C Appendix C |
| 405 | */ |
| 406 | |
| 407 | #define NB_TESTS 3 |
Ron Eldor | 1b9b217 | 2018-04-26 14:15:01 +0300 | [diff] [blame] | 408 | #define CCM_SELFTEST_PT_MAX_LEN 24 |
| 409 | #define CCM_SELFTEST_CT_MAX_LEN 32 |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 410 | /* |
| 411 | * The data is the same for all tests, only the used length changes |
| 412 | */ |
Michał Janiszewski | c79e92b | 2018-10-31 20:43:05 +0100 | [diff] [blame] | 413 | static const unsigned char key_test_data[] = { |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 414 | 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, |
| 415 | 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f |
| 416 | }; |
| 417 | |
Michał Janiszewski | c79e92b | 2018-10-31 20:43:05 +0100 | [diff] [blame] | 418 | static const unsigned char iv_test_data[] = { |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 419 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 420 | 0x18, 0x19, 0x1a, 0x1b |
| 421 | }; |
| 422 | |
Michał Janiszewski | c79e92b | 2018-10-31 20:43:05 +0100 | [diff] [blame] | 423 | static const unsigned char ad_test_data[] = { |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 424 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 425 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 426 | 0x10, 0x11, 0x12, 0x13 |
| 427 | }; |
| 428 | |
Michał Janiszewski | c79e92b | 2018-10-31 20:43:05 +0100 | [diff] [blame] | 429 | static const unsigned char msg_test_data[CCM_SELFTEST_PT_MAX_LEN] = { |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 430 | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, |
| 431 | 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, |
| 432 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, |
| 433 | }; |
| 434 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 435 | static const size_t iv_len_test_data[NB_TESTS] = { 7, 8, 12 }; |
Michał Janiszewski | 9aeea93 | 2018-10-30 23:00:15 +0100 | [diff] [blame] | 436 | static const size_t add_len_test_data[NB_TESTS] = { 8, 16, 20 }; |
| 437 | static const size_t msg_len_test_data[NB_TESTS] = { 4, 16, 24 }; |
| 438 | static const size_t tag_len_test_data[NB_TESTS] = { 4, 6, 8 }; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 439 | |
Michał Janiszewski | c79e92b | 2018-10-31 20:43:05 +0100 | [diff] [blame] | 440 | static const unsigned char res_test_data[NB_TESTS][CCM_SELFTEST_CT_MAX_LEN] = { |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 441 | { 0x71, 0x62, 0x01, 0x5b, 0x4d, 0xac, 0x25, 0x5d }, |
| 442 | { 0xd2, 0xa1, 0xf0, 0xe0, 0x51, 0xea, 0x5f, 0x62, |
| 443 | 0x08, 0x1a, 0x77, 0x92, 0x07, 0x3d, 0x59, 0x3d, |
| 444 | 0x1f, 0xc6, 0x4f, 0xbf, 0xac, 0xcd }, |
| 445 | { 0xe3, 0xb2, 0x01, 0xa9, 0xf5, 0xb7, 0x1a, 0x7a, |
| 446 | 0x9b, 0x1c, 0xea, 0xec, 0xcd, 0x97, 0xe7, 0x0b, |
| 447 | 0x61, 0x76, 0xaa, 0xd9, 0xa4, 0x42, 0x8a, 0xa5, |
| 448 | 0x48, 0x43, 0x92, 0xfb, 0xc1, 0xb0, 0x99, 0x51 } |
| 449 | }; |
| 450 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 451 | int mbedtls_ccm_self_test(int verbose) |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 452 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 453 | mbedtls_ccm_context ctx; |
Ron Eldor | 1b9b217 | 2018-04-26 14:15:01 +0300 | [diff] [blame] | 454 | /* |
| 455 | * Some hardware accelerators require the input and output buffers |
| 456 | * would be in RAM, because the flash is not accessible. |
| 457 | * Use buffers on the stack to hold the test vectors data. |
| 458 | */ |
| 459 | unsigned char plaintext[CCM_SELFTEST_PT_MAX_LEN]; |
| 460 | unsigned char ciphertext[CCM_SELFTEST_CT_MAX_LEN]; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 461 | size_t i; |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 462 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 463 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 464 | mbedtls_ccm_init(&ctx); |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 465 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 466 | if (mbedtls_ccm_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, key_test_data, |
Dave Rodgman | 1868870 | 2023-02-02 12:40:50 +0000 | [diff] [blame] | 467 | 8 * sizeof(key_test_data)) != 0) { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 468 | if (verbose != 0) { |
| 469 | mbedtls_printf(" CCM: setup failed"); |
Manuel Pégourié-Gonnard | ce77d55 | 2014-05-06 18:06:52 +0200 | [diff] [blame] | 470 | } |
| 471 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 472 | return 1; |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 475 | for (i = 0; i < NB_TESTS; i++) { |
| 476 | if (verbose != 0) { |
| 477 | mbedtls_printf(" CCM-AES #%u: ", (unsigned int) i + 1); |
| 478 | } |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 479 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 480 | memset(plaintext, 0, CCM_SELFTEST_PT_MAX_LEN); |
| 481 | memset(ciphertext, 0, CCM_SELFTEST_CT_MAX_LEN); |
| 482 | memcpy(plaintext, msg_test_data, msg_len_test_data[i]); |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 483 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 484 | ret = mbedtls_ccm_encrypt_and_tag(&ctx, msg_len_test_data[i], |
| 485 | iv_test_data, iv_len_test_data[i], |
| 486 | ad_test_data, add_len_test_data[i], |
| 487 | plaintext, ciphertext, |
| 488 | ciphertext + msg_len_test_data[i], |
| 489 | tag_len_test_data[i]); |
| 490 | |
| 491 | if (ret != 0 || |
| 492 | memcmp(ciphertext, res_test_data[i], |
| 493 | msg_len_test_data[i] + tag_len_test_data[i]) != 0) { |
| 494 | if (verbose != 0) { |
| 495 | mbedtls_printf("failed\n"); |
| 496 | } |
| 497 | |
| 498 | return 1; |
| 499 | } |
| 500 | memset(plaintext, 0, CCM_SELFTEST_PT_MAX_LEN); |
| 501 | |
| 502 | ret = mbedtls_ccm_auth_decrypt(&ctx, msg_len_test_data[i], |
| 503 | iv_test_data, iv_len_test_data[i], |
| 504 | ad_test_data, add_len_test_data[i], |
| 505 | ciphertext, plaintext, |
| 506 | ciphertext + msg_len_test_data[i], |
| 507 | tag_len_test_data[i]); |
| 508 | |
| 509 | if (ret != 0 || |
| 510 | memcmp(plaintext, msg_test_data, msg_len_test_data[i]) != 0) { |
| 511 | if (verbose != 0) { |
| 512 | mbedtls_printf("failed\n"); |
| 513 | } |
| 514 | |
| 515 | return 1; |
| 516 | } |
| 517 | |
| 518 | if (verbose != 0) { |
| 519 | mbedtls_printf("passed\n"); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | mbedtls_ccm_free(&ctx); |
| 524 | |
| 525 | if (verbose != 0) { |
| 526 | mbedtls_printf("\n"); |
| 527 | } |
| 528 | |
| 529 | return 0; |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 532 | #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 533 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 534 | #endif /* MBEDTLS_CCM_C */ |