Skip to content

Commit 39c95e0

Browse files
author
Andres AG
committed
Sync mbed TLS with development HEAD
Update the current version of mbed TLS with the development HEAD of the mbed TLS project repository. This mostly includes the latest CMAC feature. Also, update the version in the importer Makefile and VERSION.txt with the hash of the mbed TLS commit that was sync'ed.
1 parent 916ce43 commit 39c95e0

File tree

11 files changed

+1271
-10
lines changed

11 files changed

+1271
-10
lines changed

features/mbedtls/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mbedtls-2.3.0
1+
a592dcc1c6277bb191269e709cdd3d5593e593ed

features/mbedtls/importer/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#
2828

2929
# Set the mbed TLS release to import (this can/should be edited before import)
30-
MBED_TLS_RELEASE ?= mbedtls-2.3.0
30+
MBED_TLS_RELEASE ?= a592dcc1c6277bb191269e709cdd3d5593e593ed
3131

3232
# Translate between mbed TLS namespace and mbed namespace
3333
TARGET_PREFIX:=../

features/mbedtls/inc/mbedtls/check_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
#error "MBEDTLS_DHM_C defined, but not all prerequisites"
7878
#endif
7979

80+
#if defined(MBEDTLS_CMAC_C) && \
81+
!defined(MBEDTLS_AES_C) && !defined(MBEDTLS_DES_C)
82+
#error "MBEDTLS_CMAC_C defined, but not all prerequisites"
83+
#endif
84+
8085
#if defined(MBEDTLS_ECDH_C) && !defined(MBEDTLS_ECP_C)
8186
#error "MBEDTLS_ECDH_C defined, but not all prerequisites"
8287
#endif

features/mbedtls/inc/mbedtls/cipher.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ enum {
176176
*/
177177
typedef struct mbedtls_cipher_base_t mbedtls_cipher_base_t;
178178

179+
/**
180+
* CMAC context (opaque struct).
181+
*/
182+
typedef struct mbedtls_cmac_context_t mbedtls_cmac_context_t;
183+
179184
/**
180185
* Cipher information. Allows cipher functions to be called in a generic way.
181186
*/
@@ -241,6 +246,11 @@ typedef struct {
241246

242247
/** Cipher-specific context */
243248
void *cipher_ctx;
249+
250+
#if defined(MBEDTLS_CMAC_C)
251+
/** CMAC Specific context */
252+
mbedtls_cmac_context_t *cmac_ctx;
253+
#endif
244254
} mbedtls_cipher_context_t;
245255

246256
/**

features/mbedtls/inc/mbedtls/cmac.h

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/**
2+
* \file cmac.h
3+
*
4+
* \brief Cipher-based Message Authentication Code (CMAC) Mode for
5+
* Authentication
6+
*
7+
* Copyright (C) 2015-2016, ARM Limited, All Rights Reserved
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
11+
* not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*
22+
* This file is part of mbed TLS (https://tls.mbed.org)
23+
*/
24+
#ifndef MBEDTLS_CMAC_H
25+
#define MBEDTLS_CMAC_H
26+
27+
#include "mbedtls/cipher.h"
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
#define MBEDTLS_AES_BLOCK_SIZE 16
34+
#define MBEDTLS_DES3_BLOCK_SIZE 8
35+
36+
#if defined(MBEDTLS_AES_C)
37+
#define MBEDTLS_CIPHER_BLKSIZE_MAX 16 /* longest used by CMAC is AES */
38+
#else
39+
#define MBEDTLS_CIPHER_BLKSIZE_MAX 8 /* longest used by CMAC is 3DES */
40+
#endif
41+
42+
/**
43+
* CMAC context structure - Contains internal state information only
44+
*/
45+
struct mbedtls_cmac_context_t
46+
{
47+
48+
/** Internal state of the CMAC algorithm */
49+
unsigned char state[MBEDTLS_CIPHER_BLKSIZE_MAX];
50+
51+
/** Unprocessed data - either data that was not block aligned and is still
52+
* pending to be processed, or the final block */
53+
unsigned char unprocessed_block[MBEDTLS_CIPHER_BLKSIZE_MAX];
54+
55+
/** Length of data pending to be processed */
56+
size_t unprocessed_len;
57+
58+
/** Flag to indicate if the last block needs padding */
59+
int padding_flag;
60+
};
61+
62+
/**
63+
* \brief Set the CMAC key and prepare to authenticate the input
64+
* data.
65+
* Should be called with an initialised cipher context.
66+
*
67+
* \param ctx Cipher context
68+
* \param key CMAC key
69+
* \param keybits length of the CMAC key in bits
70+
* (must be acceptable by the cipher)
71+
*
72+
* \return 0 if successful, or a cipher specific error code
73+
*/
74+
int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
75+
const unsigned char *key, size_t keybits );
76+
77+
/**
78+
* \brief Generic CMAC process buffer.
79+
* Called between mbedtls_cipher_cmac_starts() or
80+
* mbedtls_cipher_cmac_reset() and
81+
* mbedtls_cipher_cmac_finish().
82+
* May be called repeatedly.
83+
*
84+
* \param ctx CMAC context
85+
* \param input buffer holding the data
86+
* \param ilen length of the input data
87+
*
88+
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
89+
* verification fails.
90+
*/
91+
int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
92+
const unsigned char *input, size_t ilen );
93+
94+
/**
95+
* \brief Output CMAC.
96+
* Called after mbedtls_cipher_cmac_update().
97+
* Usually followed by mbedtls_cipher_cmac_reset(), then
98+
* mbedtls_cipher_cmac_starts(), or mbedtls_cipher_free().
99+
*
100+
* \param ctx CMAC context
101+
* \param output Generic CMAC checksum result
102+
*
103+
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
104+
* verification fails.
105+
*/
106+
int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
107+
unsigned char *output );
108+
109+
/**
110+
* \brief Prepare to authenticate a new message with the same key.
111+
* Called after mbedtls_cipher_cmac_finish() and before
112+
* mbedtls_cipher_cmac_update().
113+
*
114+
* \param ctx CMAC context to be reset
115+
*
116+
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
117+
* verification fails.
118+
*/
119+
int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx );
120+
121+
/**
122+
* \brief Output = Generic_CMAC( hmac key, input buffer )
123+
*
124+
* \param cipher_info message digest info
125+
* \param key CMAC key
126+
* \param keylen length of the CMAC key in bits
127+
* \param input buffer holding the data
128+
* \param ilen length of the input data
129+
* \param output Generic CMAC-result
130+
*
131+
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
132+
* verification fails.
133+
*/
134+
int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
135+
const unsigned char *key, size_t keylen,
136+
const unsigned char *input, size_t ilen,
137+
unsigned char *output );
138+
139+
#if defined(MBEDTLS_AES_C)
140+
/**
141+
* \brief AES-CMAC-128-PRF
142+
* Implementation of (AES-CMAC-PRF-128), as defined in RFC 4615
143+
*
144+
* \param key PRF key
145+
* \param key_len PRF key length in bytes
146+
* \param input buffer holding the input data
147+
* \param in_len length of the input data in bytes
148+
* \param output buffer holding the generated pseudorandom output (16 bytes)
149+
*
150+
* \return 0 if successful
151+
*/
152+
int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len,
153+
const unsigned char *input, size_t in_len,
154+
unsigned char output[16] );
155+
#endif /* MBEDTLS_AES_C */
156+
157+
#if defined(MBEDTLS_SELF_TEST) && ( defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) )
158+
/**
159+
* \brief Checkup routine
160+
*
161+
* \return 0 if successful, or 1 if the test failed
162+
*/
163+
int mbedtls_cmac_self_test( int verbose );
164+
#endif /* MBEDTLS_SELF_TEST && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
165+
166+
#ifdef __cplusplus
167+
}
168+
#endif
169+
170+
#endif /* MBEDTLS_CMAC_H */

features/mbedtls/inc/mbedtls/config.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@
3333
* Only use features that do not require an entropy source when
3434
* DEVICE_ENTROPY_SOURCE is not defined in mbed OS.
3535
*/
36-
#if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
36+
#if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT) && !defined(MBEDTLS_TEST_NULL_ENTROPY)
3737
#include "mbedtls/config-no-entropy.h"
38+
39+
#if defined(MBEDTLS_USER_CONFIG_FILE)
40+
#include MBEDTLS_USER_CONFIG_FILE
41+
#endif
42+
3843
#else
3944
#define MBEDTLS_CONFIG_H
4045

@@ -1681,6 +1686,19 @@
16811686
*/
16821687
#define MBEDTLS_CIPHER_C
16831688

1689+
/**
1690+
* \def MBEDTLS_CMAC_C
1691+
*
1692+
* Enable the CMAC (Cipher-based Message Authentication Code) mode for block
1693+
* ciphers.
1694+
*
1695+
* Module: library/cmac.c
1696+
*
1697+
* Requires: MBEDTLS_AES_C or MBEDTLS_DES_C
1698+
*
1699+
*/
1700+
//#define MBEDTLS_CMAC_C
1701+
16841702
/**
16851703
* \def MBEDTLS_CTR_DRBG_C
16861704
*
@@ -2606,5 +2624,5 @@
26062624

26072625
#include "check_config.h"
26082626

2609-
#endif /* !MBEDTLS_ENTROPY_HARDWARE_ALT */
2627+
#endif /* !MBEDTLS_ENTROPY_HARDWARE_ALT && !MBEDTLS_TEST_NULL_ENTROPY */
26102628
#endif /* MBEDTLS_CONFIG_H */

features/mbedtls/inc/mbedtls/md.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *inpu
304304
/**
305305
* \brief Output HMAC.
306306
* Called after mbedtls_md_hmac_update().
307-
* Usually followed my mbedtls_md_hmac_reset(), mbedtls_md_hmac_starts(),
308-
* or mbedtls_md_free().
307+
* Usually followed by mbedtls_md_hmac_reset(),
308+
* mbedtls_md_hmac_starts(), or mbedtls_md_free().
309309
*
310310
* \param ctx HMAC context
311311
* \param output Generic HMAC checksum result
@@ -317,7 +317,8 @@ int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
317317

318318
/**
319319
* \brief Prepare to authenticate a new message with the same key.
320-
* Called after mbedtls_md_hmac_finish() and before mbedtls_md_hmac_update().
320+
* Called after mbedtls_md_hmac_finish() and before
321+
* mbedtls_md_hmac_update().
321322
*
322323
* \param ctx HMAC context to be reset
323324
*

features/mbedtls/src/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ OBJS_CRYPTO= aes.o aesni.o arc4.o \
4848
asn1parse.o asn1write.o base64.o \
4949
bignum.o blowfish.o camellia.o \
5050
ccm.o cipher.o cipher_wrap.o \
51-
ctr_drbg.o des.o dhm.o \
52-
ecdh.o ecdsa.o ecjpake.o \
53-
ecp.o \
51+
cmac.o ctr_drbg.o des.o \
52+
dhm.o ecdh.o ecdsa.o \
53+
ecjpake.o ecp.o \
5454
ecp_curves.o entropy.o entropy_poll.o \
5555
error.o gcm.o havege.o \
5656
hmac_drbg.o md.o md2.o \

features/mbedtls/src/cipher.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@
4545
#include "mbedtls/ccm.h"
4646
#endif
4747

48+
#if defined(MBEDTLS_CMAC_C)
49+
#include "mbedtls/cmac.h"
50+
#endif
51+
52+
#if defined(MBEDTLS_PLATFORM_C)
53+
#include "mbedtls/platform.h"
54+
#else
55+
#define mbedtls_calloc calloc
56+
#define mbedtls_free free
57+
#endif
58+
4859
#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER)
4960
#define MBEDTLS_CIPHER_MODE_STREAM
5061
#endif
@@ -127,6 +138,14 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx )
127138
if( ctx == NULL )
128139
return;
129140

141+
#if defined(MBEDTLS_CMAC_C)
142+
if( ctx->cmac_ctx )
143+
{
144+
mbedtls_zeroize( ctx->cmac_ctx, sizeof( mbedtls_cmac_context_t ) );
145+
mbedtls_free( ctx->cmac_ctx );
146+
}
147+
#endif
148+
130149
if( ctx->cipher_ctx )
131150
ctx->cipher_info->base->ctx_free_func( ctx->cipher_ctx );
132151

0 commit comments

Comments
 (0)