Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * NIST SP800-38B compliant CMAC implementation |
| 3 | * |
| 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | * not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * |
| 19 | * This file is part of mbed TLS (https://tls.mbed.org) |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * Definition of CMAC: |
| 24 | * http://csrc.nist.gov/publications/nistpubs/800-38B/SP_800-38B.pdf |
| 25 | * RFC 4493 "The AES-CMAC Algorithm" |
| 26 | */ |
| 27 | |
| 28 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 29 | #include "mbedtls/config.h" |
| 30 | #else |
| 31 | #include MBEDTLS_CONFIG_FILE |
| 32 | #endif |
| 33 | |
| 34 | #if defined(MBEDTLS_CMAC_C) |
| 35 | |
| 36 | #include "mbedtls/cmac.h" |
| 37 | |
| 38 | #include <string.h> |
| 39 | |
| 40 | #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) |
| 41 | #if defined(MBEDTLS_PLATFORM_C) |
| 42 | #include "mbedtls/platform.h" |
| 43 | #else |
| 44 | #include <stdio.h> |
| 45 | #define mbedtls_printf printf |
| 46 | #endif /* MBEDTLS_PLATFORM_C */ |
| 47 | #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ |
| 48 | |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 49 | /* Implementation that should never be optimized out by the compiler */ |
| 50 | static void mbedtls_zeroize( void *v, size_t n ) { |
| 51 | volatile unsigned char *p = v; while( n-- ) *p++ = 0; |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * Initialize context |
| 56 | */ |
| 57 | void mbedtls_cmac_init( mbedtls_cmac_context *ctx ) |
| 58 | { |
| 59 | memset( ctx, 0, sizeof( mbedtls_cmac_context ) ); |
| 60 | } |
| 61 | |
| 62 | /* |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 63 | * Multiplication by u in the Galois field of GF(2^n) |
Manuel Pégourié-Gonnard | a610b4c | 2016-01-13 11:28:16 +0000 | [diff] [blame] | 64 | * |
Brian Murray | 87e4040 | 2016-05-19 19:05:57 -0700 | [diff] [blame] | 65 | * As explained in the paper, this can be computed: |
Manuel Pégourié-Gonnard | a610b4c | 2016-01-13 11:28:16 +0000 | [diff] [blame] | 66 | * If MSB(p) = 0, then p = (p << 1) |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 67 | * If MSB(p) = 1, then p = (p << 1) ^ R_n |
| 68 | * with R_64 = 0x1B and R_128 = 0x87 |
Manuel Pégourié-Gonnard | a610b4c | 2016-01-13 11:28:16 +0000 | [diff] [blame] | 69 | * |
| 70 | * Input and output MUST not point to the same buffer |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 71 | * Block size must be 8 byes or 16 bytes. |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 72 | */ |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 73 | static int cmac_multiply_by_u( unsigned char *output, |
| 74 | const unsigned char *input, |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 75 | size_t blocksize ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 76 | { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 77 | const unsigned char R_128 = 0x87; |
| 78 | const unsigned char R_64 = 0x1B; |
| 79 | unsigned char R_n, mask; |
| 80 | unsigned char overflow = 0x00; |
| 81 | int i, starting_index; |
| 82 | |
| 83 | starting_index = blocksize -1; |
| 84 | |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 85 | if( blocksize == 16 ){ |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 86 | R_n = R_128; |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 87 | } else if( blocksize == 8 ) { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 88 | R_n = R_64; |
| 89 | } else { |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 90 | return( MBEDTLS_ERR_CMAC_BAD_INPUT ); |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 93 | for( i = starting_index; i >= 0; i-- ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 94 | { |
Manuel Pégourié-Gonnard | a610b4c | 2016-01-13 11:28:16 +0000 | [diff] [blame] | 95 | output[i] = input[i] << 1 | overflow; |
| 96 | overflow = input[i] >> 7; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 97 | } |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 98 | |
Manuel Pégourié-Gonnard | 475f06f | 2016-01-13 13:05:03 +0000 | [diff] [blame] | 99 | /* mask = ( input[0] >> 7 ) ? 0xff : 0x00 |
| 100 | * using bit operations to avoid branches */ |
| 101 | /* MSVC has a warning about unary minus on unsigned, but this is |
| 102 | * well-defined and precisely what we want to do here */ |
| 103 | #if defined(_MSC_VER) |
| 104 | #pragma warning( push ) |
| 105 | #pragma warning( disable : 4146 ) |
| 106 | #endif |
| 107 | mask = - ( input[0] >> 7 ); |
| 108 | #if defined(_MSC_VER) |
| 109 | #pragma warning( pop ) |
| 110 | #endif |
| 111 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 112 | output[starting_index] ^= R_n & mask; |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 113 | return( 0 ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* |
| 117 | * Generate subkeys |
| 118 | */ |
Manuel Pégourié-Gonnard | 7b555f2 | 2016-01-13 15:09:09 +0000 | [diff] [blame] | 119 | static int cmac_generate_subkeys( mbedtls_cmac_context *ctx ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 120 | { |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 121 | int ret; |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 122 | unsigned char *L; |
| 123 | size_t olen, block_size; |
| 124 | |
| 125 | ret = 0; |
| 126 | block_size = ctx->cipher_ctx.cipher_info->block_size; |
| 127 | |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 128 | L = mbedtls_calloc( block_size, sizeof( unsigned char ) ); |
Brian Murray | 4b64ab6 | 2016-05-20 06:33:01 -0700 | [diff] [blame^] | 129 | if( L == NULL ) |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 130 | { |
| 131 | ret = MBEDTLS_ERR_CMAC_ALLOC_FAILED; |
| 132 | goto exit; |
| 133 | } |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 134 | /* Calculate Ek(0) */ |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 135 | if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 136 | L, block_size, L, &olen ) ) != 0 ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 137 | { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 138 | goto exit; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 141 | /* |
Manuel Pégourié-Gonnard | a610b4c | 2016-01-13 11:28:16 +0000 | [diff] [blame] | 142 | * Generate K1 and K2 |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 143 | */ |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 144 | if( ( ret = cmac_multiply_by_u( ctx->K1, L , block_size ) ) != 0 ) |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 145 | goto exit; |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 146 | if( ( cmac_multiply_by_u( ctx->K2, ctx->K1 , block_size ) ) != 0 ) |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 147 | goto exit; |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 148 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 149 | exit: |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 150 | if( L != NULL ) |
| 151 | mbedtls_zeroize( L, sizeof( L ) ); |
Brian Murray | 4b64ab6 | 2016-05-20 06:33:01 -0700 | [diff] [blame^] | 152 | mbedtls_free( L ); |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 153 | return( ret ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Manuel Pégourié-Gonnard | 7b555f2 | 2016-01-13 15:09:09 +0000 | [diff] [blame] | 156 | /* |
| 157 | * Set key and prepare context for use |
| 158 | */ |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 159 | int mbedtls_cmac_setkey( mbedtls_cmac_context *ctx, |
| 160 | mbedtls_cipher_id_t cipher, |
| 161 | const unsigned char *key, |
| 162 | unsigned int keybits ) |
| 163 | { |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 164 | int ret; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 165 | const mbedtls_cipher_info_t *cipher_info; |
| 166 | |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 167 | cipher_info = mbedtls_cipher_info_from_values( cipher, keybits, |
| 168 | MBEDTLS_MODE_ECB ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 169 | if( cipher_info == NULL ) |
| 170 | return( MBEDTLS_ERR_CMAC_BAD_INPUT ); |
| 171 | |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 172 | mbedtls_cipher_free( &ctx->cipher_ctx ); |
| 173 | |
| 174 | if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) |
| 175 | return( ret ); |
| 176 | |
| 177 | if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keybits, |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 178 | MBEDTLS_ENCRYPT ) ) != 0 ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 179 | { |
| 180 | return( ret ); |
| 181 | } |
| 182 | |
Brian Murray | 2cfa507 | 2016-05-23 20:17:04 -0700 | [diff] [blame] | 183 | ctx->K1 = mbedtls_calloc( cipher_info->block_size, sizeof( unsigned char ) ); |
| 184 | ctx->K2 = mbedtls_calloc( cipher_info->block_size, sizeof( unsigned char ) ); |
| 185 | |
| 186 | if( ctx->K1 == NULL || ctx->K2 == NULL ) |
| 187 | { |
| 188 | mbedtls_free(ctx->K1); |
| 189 | mbedtls_free(ctx->K2); |
| 190 | return( MBEDTLS_ERR_CMAC_ALLOC_FAILED ); |
| 191 | } |
| 192 | |
Manuel Pégourié-Gonnard | 7b555f2 | 2016-01-13 15:09:09 +0000 | [diff] [blame] | 193 | return( cmac_generate_subkeys( ctx ) ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Free context |
| 198 | */ |
| 199 | void mbedtls_cmac_free( mbedtls_cmac_context *ctx ) |
| 200 | { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 201 | int block_size; |
| 202 | block_size = ctx->cipher_ctx.cipher_info->block_size; |
| 203 | |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 204 | mbedtls_cipher_free( &ctx->cipher_ctx ); |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 205 | |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 206 | mbedtls_zeroize( ctx->K1, block_size * sizeof( unsigned char ) ); |
| 207 | mbedtls_zeroize( ctx->K2, block_size * sizeof( unsigned char ) ); |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 208 | mbedtls_free( ctx->K1 ); |
| 209 | mbedtls_free( ctx->K2 ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Manuel Pégourié-Gonnard | d2c3d3e | 2016-01-13 13:14:04 +0000 | [diff] [blame] | 212 | /* |
| 213 | * Create padded last block from (partial) last block. |
| 214 | * |
| 215 | * We can't use the padding option from the cipher layer, as it only works for |
| 216 | * CBC and we use ECB mode, and anyway we need to XOR K1 or K2 in addition. |
| 217 | */ |
Manuel Pégourié-Gonnard | 7b555f2 | 2016-01-13 15:09:09 +0000 | [diff] [blame] | 218 | static void cmac_pad( unsigned char padded_block[16], |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 219 | size_t padded_block_len, |
Manuel Pégourié-Gonnard | 7b555f2 | 2016-01-13 15:09:09 +0000 | [diff] [blame] | 220 | const unsigned char *last_block, |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 221 | size_t last_block_len ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 222 | { |
| 223 | size_t j; |
| 224 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 225 | for( j = 0; j < padded_block_len; j++ ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 226 | { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 227 | if( j < last_block_len ) |
Manuel Pégourié-Gonnard | d2c3d3e | 2016-01-13 13:14:04 +0000 | [diff] [blame] | 228 | padded_block[j] = last_block[j]; |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 229 | else if( j == last_block_len ) |
Manuel Pégourié-Gonnard | d2c3d3e | 2016-01-13 13:14:04 +0000 | [diff] [blame] | 230 | padded_block[j] = 0x80; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 231 | else |
Manuel Pégourié-Gonnard | d2c3d3e | 2016-01-13 13:14:04 +0000 | [diff] [blame] | 232 | padded_block[j] = 0x00; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | /* |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 237 | * XOR Block |
Manuel Pégourié-Gonnard | d18c707 | 2016-01-13 15:03:05 +0000 | [diff] [blame] | 238 | * Here, macro results in smaller compiled code than static inline function |
| 239 | */ |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 240 | #define XOR_BLOCK( o, i1, i2 ) \ |
| 241 | for( i = 0; i < block_size; i++ ) \ |
Manuel Pégourié-Gonnard | d18c707 | 2016-01-13 15:03:05 +0000 | [diff] [blame] | 242 | ( o )[i] = ( i1 )[i] ^ ( i2 )[i]; |
| 243 | |
| 244 | /* |
Brian Murray | 87e4040 | 2016-05-19 19:05:57 -0700 | [diff] [blame] | 245 | * Update the CMAC state using an input block |
Manuel Pégourié-Gonnard | d18c707 | 2016-01-13 15:03:05 +0000 | [diff] [blame] | 246 | */ |
| 247 | #define UPDATE_CMAC( x ) \ |
| 248 | do { \ |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 249 | XOR_BLOCK( state, ( x ), state ); \ |
Manuel Pégourié-Gonnard | d18c707 | 2016-01-13 15:03:05 +0000 | [diff] [blame] | 250 | if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, \ |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 251 | state, block_size, \ |
| 252 | state, &olen ) ) != 0 ) \ |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 253 | { \ |
| 254 | goto exit; \ |
| 255 | } \ |
Manuel Pégourié-Gonnard | d18c707 | 2016-01-13 15:03:05 +0000 | [diff] [blame] | 256 | } while( 0 ) |
| 257 | |
| 258 | /* |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 259 | * Generate tag on complete message |
| 260 | */ |
Manuel Pégourié-Gonnard | ab9c5fd | 2016-01-13 15:05:57 +0000 | [diff] [blame] | 261 | int mbedtls_cmac_generate( mbedtls_cmac_context *ctx, |
| 262 | const unsigned char *input, size_t in_len, |
| 263 | unsigned char *tag, size_t tag_len ) |
| 264 | |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 265 | { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 266 | unsigned char *state; |
| 267 | unsigned char *M_last; |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 268 | int n, j, ret, needs_padding; |
| 269 | size_t olen, block_size, i; |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 270 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 271 | ret = 0; |
| 272 | block_size = ctx->cipher_ctx.cipher_info->block_size; |
| 273 | |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 274 | state = mbedtls_calloc( block_size, sizeof( unsigned char ) ); |
| 275 | M_last = mbedtls_calloc( block_size, sizeof( unsigned char ) ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 276 | |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 277 | if( state == NULL || M_last == NULL ) |
| 278 | { |
| 279 | ret = MBEDTLS_ERR_CMAC_ALLOC_FAILED; |
| 280 | goto exit; |
| 281 | } |
| 282 | |
Brian Murray | 87e4040 | 2016-05-19 19:05:57 -0700 | [diff] [blame] | 283 | if( tag_len < 2 || tag_len > block_size || tag_len % 2 != 0 ) |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 284 | { |
| 285 | ret = MBEDTLS_ERR_CMAC_BAD_INPUT; |
| 286 | goto exit; |
| 287 | } |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 288 | |
Manuel Pégourié-Gonnard | 2c06306 | 2016-01-13 14:27:55 +0000 | [diff] [blame] | 289 | if( in_len == 0 ) |
| 290 | needs_padding = 1; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 291 | else |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 292 | needs_padding = in_len % block_size != 0; |
Manuel Pégourié-Gonnard | 2c06306 | 2016-01-13 14:27:55 +0000 | [diff] [blame] | 293 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 294 | n = in_len / block_size + needs_padding; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 295 | |
| 296 | /* Calculate last block */ |
Manuel Pégourié-Gonnard | 2c06306 | 2016-01-13 14:27:55 +0000 | [diff] [blame] | 297 | if( needs_padding ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 298 | { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 299 | cmac_pad( M_last, block_size, input + block_size * ( n - 1 ), in_len % block_size ); |
| 300 | XOR_BLOCK( M_last, M_last, ctx->K2 ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 301 | } |
| 302 | else |
| 303 | { |
Manuel Pégourié-Gonnard | 2c06306 | 2016-01-13 14:27:55 +0000 | [diff] [blame] | 304 | /* Last block is complete block */ |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 305 | XOR_BLOCK( M_last, input + block_size * ( n - 1 ), ctx->K1 ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 308 | for( j = 0; j < n - 1; j++ ) |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 309 | UPDATE_CMAC( input + block_size * j ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 310 | |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 311 | UPDATE_CMAC( M_last ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 312 | |
Brian Murray | 00dc5f0 | 2016-05-19 14:23:50 -0700 | [diff] [blame] | 313 | memcpy( tag, state, tag_len ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 314 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 315 | exit: |
Brian Murray | 4b64ab6 | 2016-05-20 06:33:01 -0700 | [diff] [blame^] | 316 | mbedtls_free( state ); |
| 317 | mbedtls_free( M_last ); |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 318 | return( ret ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 321 | #undef XOR_BLOCK |
Manuel Pégourié-Gonnard | d18c707 | 2016-01-13 15:03:05 +0000 | [diff] [blame] | 322 | #undef UPDATE_CMAC |
| 323 | |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 324 | /* |
Manuel Pégourié-Gonnard | 7b555f2 | 2016-01-13 15:09:09 +0000 | [diff] [blame] | 325 | * Verify tag on complete message |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 326 | */ |
Manuel Pégourié-Gonnard | 690083c | 2016-01-13 10:48:02 +0000 | [diff] [blame] | 327 | int mbedtls_cmac_verify( mbedtls_cmac_context *ctx, |
| 328 | const unsigned char *input, size_t in_len, |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 329 | const unsigned char *tag, size_t tag_len ) |
| 330 | { |
| 331 | int ret; |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 332 | unsigned char *check_tag; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 333 | unsigned char i; |
| 334 | int diff; |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 335 | |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 336 | check_tag = mbedtls_calloc( ctx->cipher_ctx.cipher_info->block_size, |
| 337 | sizeof( unsigned char ) ); |
Brian Murray | 4b64ab6 | 2016-05-20 06:33:01 -0700 | [diff] [blame^] | 338 | if( check_tag == NULL ) |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 339 | { |
| 340 | ret = MBEDTLS_ERR_CMAC_ALLOC_FAILED; |
| 341 | goto exit; |
| 342 | } |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 343 | |
Manuel Pégourié-Gonnard | ab9c5fd | 2016-01-13 15:05:57 +0000 | [diff] [blame] | 344 | if( ( ret = mbedtls_cmac_generate( ctx, input, in_len, |
| 345 | check_tag, tag_len ) ) != 0 ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 346 | { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 347 | goto exit; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* Check tag in "constant-time" */ |
| 351 | for( diff = 0, i = 0; i < tag_len; i++ ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 352 | diff |= tag[i] ^ check_tag[i]; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 353 | |
| 354 | if( diff != 0 ) |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 355 | ret = MBEDTLS_ERR_CMAC_VERIFY_FAILED; |
| 356 | goto exit; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 357 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 358 | exit: |
Brian Murray | 4b64ab6 | 2016-05-20 06:33:01 -0700 | [diff] [blame^] | 359 | mbedtls_free( check_tag ); |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 360 | return( ret ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 363 | #ifdef MBEDTLS_AES_C |
Manuel Pégourié-Gonnard | 7b555f2 | 2016-01-13 15:09:09 +0000 | [diff] [blame] | 364 | /* |
| 365 | * PRF based on CMAC with AES-128 |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 366 | * See RFC 4615 |
Manuel Pégourié-Gonnard | 7b555f2 | 2016-01-13 15:09:09 +0000 | [diff] [blame] | 367 | */ |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 368 | int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_length, |
Manuel Pégourié-Gonnard | 690083c | 2016-01-13 10:48:02 +0000 | [diff] [blame] | 369 | const unsigned char *input, size_t in_len, |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 370 | unsigned char tag[16] ) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 371 | { |
| 372 | int ret; |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 373 | mbedtls_cmac_context ctx; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 374 | unsigned char zero_key[16]; |
| 375 | unsigned char int_key[16]; |
| 376 | |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 377 | mbedtls_cmac_init(&ctx ); |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 378 | |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 379 | if( key_length == 16 ) |
| 380 | { |
| 381 | /* Use key as is */ |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 382 | memcpy( int_key, key, 16 ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 383 | } |
| 384 | else |
| 385 | { |
| 386 | mbedtls_cmac_context zero_ctx; |
| 387 | |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 388 | /* Key is AES_CMAC( 0, key ) */ |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 389 | mbedtls_cmac_init( &zero_ctx ); |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 390 | memset( zero_key, 0, 16 ); |
| 391 | ret = mbedtls_cmac_setkey( &zero_ctx, MBEDTLS_CIPHER_ID_AES, |
| 392 | zero_key, 8 * sizeof zero_key ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 393 | if( ret != 0 ) |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 394 | goto exit; |
Manuel Pégourié-Gonnard | 7b555f2 | 2016-01-13 15:09:09 +0000 | [diff] [blame] | 395 | |
Manuel Pégourié-Gonnard | 690083c | 2016-01-13 10:48:02 +0000 | [diff] [blame] | 396 | ret = mbedtls_cmac_generate( &zero_ctx, key, key_length, int_key, 16 ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 397 | if( ret != 0 ) |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 398 | goto exit; |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 401 | ret = mbedtls_cmac_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 402 | int_key, 8 * sizeof int_key ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 403 | if( ret != 0 ) |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 404 | goto exit; |
Manuel Pégourié-Gonnard | d6cf754 | 2016-01-13 11:30:00 +0000 | [diff] [blame] | 405 | |
| 406 | mbedtls_zeroize( int_key, sizeof( int_key ) ); |
| 407 | |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 408 | ret = mbedtls_cmac_generate( &ctx, input, in_len, tag, 16 ); |
| 409 | |
| 410 | exit: |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 411 | mbedtls_cmac_free( &ctx ); |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 412 | return( ret ); |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 413 | } |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 414 | #endif /* MBEDTLS_AES_C */ |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 415 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 416 | #ifdef MBEDTLS_SELF_TEST |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 417 | /* |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 418 | * CMAC test data from SP800-38B Appendix D.1 (corrected) |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 419 | * http://csrc.nist.gov/publications/nistpubs/800-38B/Updated_CMAC_Examples.pdf |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 420 | * |
| 421 | * AES-CMAC-PRF-128 test data from RFC 4615 |
| 422 | * https://tools.ietf.org/html/rfc4615#page-4 |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 423 | */ |
| 424 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 425 | #define NB_CMAC_TESTS_PER_KEY 4 |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 426 | #define NB_PRF_TESTS 3 |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 427 | #define AES_BLOCK_SIZE 16 |
| 428 | #define DES3_BLOCK_SIZE 8 |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 429 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 430 | #if defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) |
| 431 | /* All CMAC test inputs are truncated from the same 64 byte buffer. */ |
| 432 | static const unsigned char test_message[] = { |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 433 | 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, |
| 434 | 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, |
| 435 | 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, |
| 436 | 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, |
| 437 | 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, |
| 438 | 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, |
| 439 | 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, |
| 440 | 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 |
| 441 | }; |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 442 | #endif /* defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) */ |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 443 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 444 | #ifdef MBEDTLS_AES_C |
| 445 | /* Truncation point of message for AES CMAC tests */ |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 446 | static const unsigned int aes_message_lengths[NB_CMAC_TESTS_PER_KEY] = { |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 447 | 0, |
| 448 | 16, |
| 449 | 40, |
| 450 | 64 |
| 451 | }; |
| 452 | |
| 453 | /* AES 128 CMAC Test Data */ |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 454 | static const unsigned char aes_128_key[16] = { |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 455 | 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, |
| 456 | 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c |
| 457 | }; |
| 458 | static const unsigned char aes_128_subkeys[2][AES_BLOCK_SIZE] = { |
| 459 | { |
| 460 | 0xfb, 0xee, 0xd6, 0x18, 0x35, 0x71, 0x33, 0x66, |
| 461 | 0x7c, 0x85, 0xe0, 0x8f, 0x72, 0x36, 0xa8, 0xde |
| 462 | }, |
| 463 | { |
| 464 | 0xf7, 0xdd, 0xac, 0x30, 0x6a, 0xe2, 0x66, 0xcc, |
| 465 | 0xf9, 0x0b, 0xc1, 0x1e, 0xe4, 0x6d, 0x51, 0x3b |
| 466 | } |
| 467 | }; |
| 468 | static const unsigned char aes_128_expected_result[NB_CMAC_TESTS_PER_KEY][AES_BLOCK_SIZE] = { |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 469 | { |
| 470 | 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28, |
| 471 | 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46 |
| 472 | }, |
| 473 | { |
| 474 | 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44, |
| 475 | 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c |
| 476 | }, |
| 477 | { |
| 478 | 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30, |
| 479 | 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27 |
| 480 | }, |
| 481 | { |
| 482 | 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92, |
| 483 | 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe |
| 484 | } |
| 485 | }; |
| 486 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 487 | /* AES 192 CMAC Test Data */ |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 488 | static const unsigned char aes_192_key[24] = { |
Brian Murray | 87e4040 | 2016-05-19 19:05:57 -0700 | [diff] [blame] | 489 | 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, |
| 490 | 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, |
| 491 | 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 492 | }; |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 493 | static const unsigned char aes_192_subkeys[2][AES_BLOCK_SIZE] = { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 494 | { |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 495 | 0x44, 0x8a, 0x5b, 0x1c, 0x93, 0x51, 0x4b, 0x27, |
| 496 | 0x3e, 0xe6, 0x43, 0x9d, 0xd4, 0xda, 0xa2, 0x96 |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 497 | }, |
| 498 | { |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 499 | 0x89, 0x14, 0xb6, 0x39, 0x26, 0xa2, 0x96, 0x4e, |
| 500 | 0x7d, 0xcc, 0x87, 0x3b, 0xa9, 0xb5, 0x45, 0x2c |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 501 | } |
| 502 | }; |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 503 | static const unsigned char aes_192_expected_result[NB_CMAC_TESTS_PER_KEY][AES_BLOCK_SIZE] = { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 504 | { |
| 505 | 0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5, |
| 506 | 0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67 |
| 507 | }, |
| 508 | { |
| 509 | 0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90, |
| 510 | 0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84 |
| 511 | }, |
| 512 | { |
| 513 | 0x8a, 0x1d, 0xe5, 0xbe, 0x2e, 0xb3, 0x1a, 0xad, |
| 514 | 0x08, 0x9a, 0x82, 0xe6, 0xee, 0x90, 0x8b, 0x0e |
| 515 | }, |
| 516 | { |
| 517 | 0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79, |
| 518 | 0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11 |
| 519 | } |
| 520 | }; |
| 521 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 522 | /* AES 256 CMAC Test Data */ |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 523 | static const unsigned char aes_256_key[32] = { |
Brian Murray | 87e4040 | 2016-05-19 19:05:57 -0700 | [diff] [blame] | 524 | 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, |
| 525 | 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, |
| 526 | 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, |
| 527 | 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 528 | }; |
| 529 | static const unsigned char aes_256_subkeys[2][AES_BLOCK_SIZE] = { |
| 530 | { |
| 531 | 0xca, 0xd1, 0xed, 0x03, 0x29, 0x9e, 0xed, 0xac, |
| 532 | 0x2e, 0x9a, 0x99, 0x80, 0x86, 0x21, 0x50, 0x2f |
| 533 | }, |
| 534 | { |
| 535 | 0x95, 0xa3, 0xda, 0x06, 0x53, 0x3d, 0xdb, 0x58, |
| 536 | 0x5d, 0x35, 0x33, 0x01, 0x0c, 0x42, 0xa0, 0xd9 |
| 537 | } |
| 538 | }; |
| 539 | static const unsigned char aes_256_expected_result[NB_CMAC_TESTS_PER_KEY][AES_BLOCK_SIZE] = { |
| 540 | { |
| 541 | 0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e, |
| 542 | 0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83 |
| 543 | }, |
| 544 | { |
| 545 | 0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82, |
| 546 | 0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c |
| 547 | }, |
| 548 | { |
| 549 | 0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2, |
| 550 | 0x32, 0xf5, 0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6 |
| 551 | }, |
| 552 | { |
| 553 | 0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5, |
| 554 | 0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10 |
| 555 | } |
| 556 | }; |
| 557 | #endif /* MBEDTLS_AES_C */ |
| 558 | |
| 559 | #ifdef MBEDTLS_DES_C |
| 560 | /* Truncation point of message for 3DES CMAC tests */ |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 561 | static const unsigned int des3_message_lengths[NB_CMAC_TESTS_PER_KEY] = { |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 562 | 0, |
| 563 | 8, |
| 564 | 20, |
| 565 | 32 |
| 566 | }; |
| 567 | |
| 568 | /* 3DES 2 Key CMAC Test Data */ |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 569 | static const unsigned char des3_2key_key[24] = { |
Brian Murray | 87e4040 | 2016-05-19 19:05:57 -0700 | [diff] [blame] | 570 | 0x4c, 0xf1, 0x51, 0x34, 0xa2, 0x85, 0x0d, 0xd5, |
| 571 | 0x8a, 0x3d, 0x10, 0xba, 0x80, 0x57, 0x0d, 0x38, |
| 572 | 0x4c, 0xf1, 0x51, 0x34, 0xa2, 0x85, 0x0d, 0xd5 |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 573 | }; |
| 574 | static const unsigned char des3_2key_subkeys[2][8] = { |
| 575 | { |
| 576 | 0x8e, 0xcf, 0x37, 0x3e, 0xd7, 0x1a, 0xfa, 0xef |
| 577 | }, |
| 578 | { |
| 579 | 0x1d, 0x9e, 0x6e, 0x7d, 0xae, 0x35, 0xf5, 0xc5 |
| 580 | } |
| 581 | }; |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 582 | static const unsigned char des3_2key_expected_result[NB_CMAC_TESTS_PER_KEY][DES3_BLOCK_SIZE] = { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 583 | { |
| 584 | 0xbd, 0x2e, 0xbf, 0x9a, 0x3b, 0xa0, 0x03, 0x61 |
| 585 | }, |
| 586 | { |
| 587 | 0x4f, 0xf2, 0xab, 0x81, 0x3c, 0x53, 0xce, 0x83 |
| 588 | }, |
| 589 | { |
| 590 | 0x62, 0xdd, 0x1b, 0x47, 0x19, 0x02, 0xbd, 0x4e |
| 591 | }, |
| 592 | { |
| 593 | 0x31, 0xb1, 0xe4, 0x31, 0xda, 0xbc, 0x4e, 0xb8 |
| 594 | } |
| 595 | }; |
| 596 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 597 | /* 3DES 3 Key CMAC Test Data */ |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 598 | static const unsigned char des3_3key_key[24] = { |
Brian Murray | 87e4040 | 2016-05-19 19:05:57 -0700 | [diff] [blame] | 599 | 0x8a, 0xa8, 0x3b, 0xf8, 0xcb, 0xda, 0x10, 0x62, |
| 600 | 0x0b, 0xc1, 0xbf, 0x19, 0xfb, 0xb6, 0xcd, 0x58, |
| 601 | 0xbc, 0x31, 0x3d, 0x4a, 0x37, 0x1c, 0xa8, 0xb5 |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 602 | }; |
| 603 | static const unsigned char des3_3key_subkeys[2][8] = { |
| 604 | { |
| 605 | 0x91, 0x98, 0xe9, 0xd3, 0x14, 0xe6, 0x53, 0x5f |
| 606 | }, |
| 607 | { |
| 608 | 0x23, 0x31, 0xd3, 0xa6, 0x29, 0xcc, 0xa6, 0xa5 |
| 609 | } |
| 610 | }; |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 611 | static const unsigned char des3_3key_expected_result[NB_CMAC_TESTS_PER_KEY][DES3_BLOCK_SIZE] = { |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 612 | { |
| 613 | 0xb7, 0xa6, 0x88, 0xe1, 0x22, 0xff, 0xaf, 0x95 |
| 614 | }, |
| 615 | { |
| 616 | 0x8e, 0x8f, 0x29, 0x31, 0x36, 0x28, 0x37, 0x97 |
| 617 | }, |
| 618 | { |
| 619 | 0x74, 0x3d, 0xdb, 0xe0, 0xce, 0x2d, 0xc2, 0xed |
| 620 | }, |
| 621 | { |
| 622 | 0x33, 0xe6, 0xb1, 0x09, 0x24, 0x00, 0xea, 0xe5 |
| 623 | } |
| 624 | }; |
| 625 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 626 | #endif /* MBEDTLS_DES_C */ |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 627 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 628 | #ifdef MBEDTLS_AES_C |
| 629 | /* AES AES-CMAC-PRF-128 Test Data */ |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 630 | static const unsigned char PRFK[] = { |
| 631 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 632 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 633 | 0xed, 0xcb |
| 634 | }; |
| 635 | |
| 636 | /* Sizes in bytes */ |
| 637 | static const size_t PRFKlen[NB_PRF_TESTS] = { |
| 638 | 18, |
| 639 | 16, |
| 640 | 10 |
| 641 | }; |
| 642 | |
| 643 | /* PRF M */ |
| 644 | static const unsigned char PRFM[] = { |
| 645 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 646 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
Manuel Pégourié-Gonnard | 3da5402 | 2016-01-13 11:00:47 +0000 | [diff] [blame] | 647 | 0x10, 0x11, 0x12, 0x13 |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 648 | }; |
| 649 | |
| 650 | static const unsigned char PRFT[NB_PRF_TESTS][16] = { |
| 651 | { |
| 652 | 0x84, 0xa3, 0x48, 0xa4, 0xa4, 0x5d, 0x23, 0x5b, |
| 653 | 0xab, 0xff, 0xfc, 0x0d, 0x2b, 0x4d, 0xa0, 0x9a |
| 654 | }, |
| 655 | { |
| 656 | 0x98, 0x0a, 0xe8, 0x7b, 0x5f, 0x4c, 0x9c, 0x52, |
| 657 | 0x14, 0xf5, 0xb6, 0xa8, 0x45, 0x5e, 0x4c, 0x2d |
| 658 | }, |
| 659 | { |
| 660 | 0x29, 0x0d, 0x9e, 0x11, 0x2e, 0xdb, 0x09, 0xee, |
| 661 | 0x14, 0x1f, 0xcf, 0x64, 0xc0, 0xb7, 0x2f, 0x3d |
| 662 | } |
| 663 | }; |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 664 | #endif /* MBEDTLS_AES_C */ |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 665 | |
Brian Murray | b439d45 | 2016-05-19 16:02:42 -0700 | [diff] [blame] | 666 | int test_cmac_with_cipher( int verbose, |
Brian Murray | 87e4040 | 2016-05-19 19:05:57 -0700 | [diff] [blame] | 667 | char* testname, |
| 668 | const unsigned char* key, |
| 669 | int keybits, |
| 670 | const unsigned char* messages, |
| 671 | const unsigned int message_lengths[4], |
| 672 | const unsigned char* subkeys, |
| 673 | const unsigned char* expected_result, |
| 674 | mbedtls_cipher_id_t cipher_id, |
| 675 | int block_size ) |
Brian Murray | 00dc5f0 | 2016-05-19 14:23:50 -0700 | [diff] [blame] | 676 | { |
Brian Murray | 87e4040 | 2016-05-19 19:05:57 -0700 | [diff] [blame] | 677 | const int num_tests = 4; |
| 678 | mbedtls_cmac_context ctx; |
Brian Murray | 00dc5f0 | 2016-05-19 14:23:50 -0700 | [diff] [blame] | 679 | int i, ret; |
| 680 | unsigned char* tag; |
| 681 | |
| 682 | tag = mbedtls_calloc( block_size, sizeof( unsigned char ) ); |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 683 | if( tag == NULL ){ |
| 684 | ret = MBEDTLS_ERR_CMAC_ALLOC_FAILED; |
| 685 | goto exit; |
| 686 | } |
| 687 | |
Brian Murray | 00dc5f0 | 2016-05-19 14:23:50 -0700 | [diff] [blame] | 688 | mbedtls_cmac_init( &ctx ); |
| 689 | |
| 690 | if( ( ret = mbedtls_cmac_setkey( &ctx, cipher_id, key, keybits ) ) != 0 ) |
| 691 | { |
| 692 | if( verbose != 0 ) |
| 693 | mbedtls_printf( " CMAC: setup failed\n" ); |
| 694 | goto exit; |
| 695 | } |
| 696 | |
| 697 | if( ( ret = memcmp( ctx.K1, subkeys, block_size ) != 0 ) || |
| 698 | ( ret = memcmp( ctx.K2, &subkeys[block_size], block_size ) != 0 ) ) |
| 699 | { |
| 700 | if( verbose != 0 ) |
| 701 | mbedtls_printf( " CMAC: subkey generation failed\n" ); |
| 702 | goto exit; |
| 703 | } |
| 704 | |
| 705 | for( i = 0; i < num_tests; i++ ) |
| 706 | { |
| 707 | if( verbose != 0 ) |
| 708 | mbedtls_printf( " %s CMAC #%u: ", testname, i +1 ); |
| 709 | |
| 710 | if( ( ret = mbedtls_cmac_generate( &ctx, messages, message_lengths[i], tag, block_size ) ) != 0 ) |
| 711 | { |
| 712 | if( verbose != 0 ) |
| 713 | mbedtls_printf( "failed\n" ); |
| 714 | goto exit; |
| 715 | } |
| 716 | if( ( ret = memcmp( tag, &expected_result[i * block_size], block_size ) ) != 0 ) |
| 717 | { |
| 718 | if( verbose != 0 ) |
| 719 | mbedtls_printf( "failed\n" ); |
| 720 | goto exit; |
| 721 | } |
| 722 | |
| 723 | if( ( ret = mbedtls_cmac_verify( &ctx, messages, message_lengths[i], &expected_result[i * block_size], block_size ) != 0 ) ) |
| 724 | { |
Brian Murray | 4b64ab6 | 2016-05-20 06:33:01 -0700 | [diff] [blame^] | 725 | if( verbose != 0 ) |
| 726 | mbedtls_printf( "failed\n" ); |
| 727 | goto exit; |
Brian Murray | 00dc5f0 | 2016-05-19 14:23:50 -0700 | [diff] [blame] | 728 | } |
| 729 | mbedtls_printf( "passed\n" ); |
| 730 | } |
| 731 | exit: |
Brian Murray | 4b64ab6 | 2016-05-20 06:33:01 -0700 | [diff] [blame^] | 732 | mbedtls_free( tag ); |
Brian Murray | 00dc5f0 | 2016-05-19 14:23:50 -0700 | [diff] [blame] | 733 | mbedtls_cmac_free( &ctx ); |
| 734 | return( ret ); |
| 735 | } |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 736 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 737 | #ifdef MBEDTLS_AES_C |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 738 | int test_aes128_cmac_prf( int verbose ) { |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 739 | int i; |
| 740 | int ret; |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 741 | unsigned char tag[16]; |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 742 | for( i = 0; i < NB_PRF_TESTS; i++ ) |
| 743 | { |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 744 | mbedtls_printf( " AES CMAC 128 PRF #%u: ", i ); |
| 745 | ret = mbedtls_aes_cmac_prf_128( PRFK, PRFKlen[i], PRFM, 20, tag ); |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 746 | if( ret != 0 || |
| 747 | memcmp( tag, PRFT[i], 16 ) != 0 ) |
| 748 | { |
| 749 | if( verbose != 0 ) |
| 750 | mbedtls_printf( "failed\n" ); |
| 751 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 752 | return( ret ); |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 753 | } else if( verbose != 0 ) |
| 754 | { |
| 755 | mbedtls_printf( "passed\n" ); |
| 756 | } |
| 757 | } |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 758 | return( ret ); |
| 759 | } |
| 760 | #endif /* MBEDTLS_AES_C */ |
| 761 | |
| 762 | int mbedtls_cmac_self_test( int verbose ) |
| 763 | { |
| 764 | int ret; |
| 765 | |
| 766 | #ifdef MBEDTLS_AES_C |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 767 | if( ( ret = test_cmac_with_cipher( verbose, |
| 768 | "AES 128", |
| 769 | aes_128_key, |
| 770 | 128, |
| 771 | test_message, |
| 772 | aes_message_lengths, |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 773 | (const unsigned char*) aes_128_subkeys, |
| 774 | (const unsigned char*) aes_128_expected_result, |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 775 | MBEDTLS_CIPHER_ID_AES, |
| 776 | AES_BLOCK_SIZE ) !=0 ) ) |
| 777 | { |
| 778 | return( ret ); |
| 779 | } |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 780 | |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 781 | if( ( ret = test_cmac_with_cipher( verbose, |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 782 | "AES 192", |
| 783 | aes_192_key, |
| 784 | 192, |
| 785 | test_message, |
| 786 | aes_message_lengths, |
| 787 | (const unsigned char*) aes_192_subkeys, |
| 788 | (const unsigned char*) aes_192_expected_result, |
| 789 | MBEDTLS_CIPHER_ID_AES, |
| 790 | AES_BLOCK_SIZE ) !=0 ) ) |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 791 | { |
| 792 | return( ret ); |
| 793 | } |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 794 | |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 795 | if( ( ret = test_cmac_with_cipher ( verbose, |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 796 | "AES 256", |
| 797 | aes_256_key, |
| 798 | 256, |
| 799 | test_message, |
| 800 | aes_message_lengths, |
| 801 | (const unsigned char*) aes_256_subkeys, |
| 802 | (const unsigned char*) aes_256_expected_result, |
| 803 | MBEDTLS_CIPHER_ID_AES, |
| 804 | AES_BLOCK_SIZE ) !=0 ) ) |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 805 | { |
| 806 | return( ret ); |
| 807 | } |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 808 | #endif /* MBEDTLS_AES_C */ |
| 809 | |
| 810 | #ifdef MBEDTLS_DES_C |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 811 | if( ( ret = test_cmac_with_cipher( verbose, |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 812 | "3DES 2 key", |
| 813 | des3_2key_key, |
| 814 | 192, |
| 815 | test_message, |
| 816 | des3_message_lengths, |
| 817 | (const unsigned char*) des3_2key_subkeys, |
| 818 | (const unsigned char*) des3_2key_expected_result, |
| 819 | MBEDTLS_CIPHER_ID_3DES, |
| 820 | DES3_BLOCK_SIZE ) !=0 ) ) |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 821 | { |
| 822 | return( ret ); |
| 823 | } |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 824 | |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 825 | if( ( ret = test_cmac_with_cipher( verbose, |
Brian Murray | 57863ad | 2016-05-19 16:38:36 -0700 | [diff] [blame] | 826 | "3DES 3 key", |
| 827 | des3_3key_key, |
| 828 | 192, |
| 829 | test_message, |
| 830 | des3_message_lengths, |
| 831 | (const unsigned char*) des3_3key_subkeys, |
| 832 | (const unsigned char*) des3_3key_expected_result, |
| 833 | MBEDTLS_CIPHER_ID_3DES, |
| 834 | DES3_BLOCK_SIZE ) !=0 ) ) |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 835 | { |
| 836 | return( ret ); |
| 837 | } |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 838 | #endif /* MBEDTLS_DES_C */ |
| 839 | |
| 840 | #ifdef MBEDTLS_AES_C |
Brian Murray | 9044b02 | 2016-05-19 16:36:56 -0700 | [diff] [blame] | 841 | if( ( ret = test_aes128_cmac_prf( verbose ) != 0 ) ) |
| 842 | return( ret ); |
| 843 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 844 | #endif /* MBEDTLS_AES_C */ |
Brian Murray | b0c3c43 | 2016-05-18 14:29:51 -0700 | [diff] [blame] | 845 | |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 846 | if( verbose != 0 ) |
| 847 | mbedtls_printf( "\n" ); |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 848 | |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 849 | return( 0 ); |
| 850 | } |
| 851 | |
Brian Murray | 0f6af73 | 2016-05-19 15:59:23 -0700 | [diff] [blame] | 852 | #endif /* MBEDTLS_SELF_TEST */ |
Robert Cragie | 3d23b1d | 2015-12-15 07:38:11 +0000 | [diff] [blame] | 853 | |
| 854 | #endif /* MBEDTLS_CMAC_C */ |