Skip to content

Commit 30520fe

Browse files
srodrig1Anas Nashif
authored andcommitted
ext: lib: mbedtls : Upgrading mbedTLS library
Upgrading mbedTLS to version 2.4 from 2.3 Origin: https://tls.mbed.org/download/start/mbedtls-2.4.0-apache.tgz Jira: ZEP-1292 Jira: ZEP-734 Change-Id: I32d81304f5d568810e271b8e9fc2135def1dda0a Signed-off-by: Sergio Rodriguez <[email protected]>
1 parent dca0e24 commit 30520fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2213
-416
lines changed

ext/lib/crypto/mbedtls/Kbuild

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,74 @@
11

22
include $(srctree)/ext/lib/crypto/mbedtls/Makefile.include
33

4-
obj-y += library/ssl_tls.o
5-
obj-y += library/ssl_cache.o
6-
obj-y += library/ssl_ciphersuites.o
7-
obj-y += library/ssl_cli.o
8-
obj-y += library/ssl_cookie.o
9-
obj-y += library/ssl_srv.o
10-
obj-y += library/ssl_ticket.o
11-
obj-y += library/debug.o
12-
obj-y += library/net.o
13-
obj-y += library/memory_buffer_alloc.o
14-
obj-y += library/platform.o
15-
obj-y += library/threading.o
16-
obj-y += library/timing.o
17-
obj-y += library/version.o
18-
obj-y += library/version_features.o
19-
obj-y += library/entropy.o
20-
obj-y += library/entropy_poll.o
21-
obj-y += library/error.o
22-
obj-y += library/cipher.o
23-
obj-y += library/cipher_wrap.o
24-
obj-y += library/bignum.o
254
obj-y += library/aes.o
265
obj-y += library/aesni.o
27-
obj-y += library/padlock.o
286
obj-y += library/arc4.o
297
obj-y += library/asn1parse.o
308
obj-y += library/asn1write.o
319
obj-y += library/base64.o
10+
obj-y += library/bignum.o
3211
obj-y += library/blowfish.o
3312
obj-y += library/camellia.o
3413
obj-y += library/ccm.o
14+
obj-y += library/certs.o
15+
obj-y += library/cipher.o
16+
obj-y += library/cipher_wrap.o
17+
obj-y += library/cmac.o
18+
obj-y += library/ctr_drbg.o
19+
obj-y += library/debug.o
3520
obj-y += library/des.o
3621
obj-y += library/dhm.o
3722
obj-y += library/ecdh.o
3823
obj-y += library/ecdsa.o
3924
obj-y += library/ecjpake.o
4025
obj-y += library/ecp.o
4126
obj-y += library/ecp_curves.o
42-
obj-y += library/ctr_drbg.o
27+
obj-y += library/entropy.o
28+
obj-y += library/entropy_poll.o
29+
obj-y += library/error.o
4330
obj-y += library/gcm.o
4431
obj-y += library/havege.o
4532
obj-y += library/hmac_drbg.o
33+
obj-y += library/md.o
4634
obj-y += library/md2.o
4735
obj-y += library/md4.o
4836
obj-y += library/md5.o
49-
obj-y += library/md.o
5037
obj-y += library/md_wrap.o
38+
obj-y += library/memory_buffer_alloc.o
39+
obj-y += library/net_sockets.o
5140
obj-y += library/oid.o
41+
obj-y += library/padlock.o
5242
obj-y += library/pem.o
5343
obj-y += library/pk.o
44+
obj-y += library/pk_wrap.o
45+
obj-y += library/pkcs11.o
5446
obj-y += library/pkcs12.o
5547
obj-y += library/pkcs5.o
5648
obj-y += library/pkparse.o
57-
obj-y += library/pk_wrap.o
5849
obj-y += library/pkwrite.o
50+
obj-y += library/platform.o
5951
obj-y += library/ripemd160.o
6052
obj-y += library/rsa.o
6153
obj-y += library/sha1.o
6254
obj-y += library/sha256.o
6355
obj-y += library/sha512.o
64-
obj-y += library/xtea.o
65-
obj-y += library/pkcs11.o
66-
obj-y += library/certs.o
56+
obj-y += library/ssl_cache.o
57+
obj-y += library/ssl_ciphersuites.o
58+
obj-y += library/ssl_cli.o
59+
obj-y += library/ssl_cookie.o
60+
obj-y += library/ssl_srv.o
61+
obj-y += library/ssl_ticket.o
62+
obj-y += library/ssl_tls.o
63+
obj-y += library/threading.o
64+
obj-y += library/timing.o
65+
obj-y += library/version.o
66+
obj-y += library/version_features.o
6767
obj-y += library/x509.o
6868
obj-y += library/x509_create.o
6969
obj-y += library/x509_crl.o
7070
obj-y += library/x509_crt.o
7171
obj-y += library/x509_csr.o
7272
obj-y += library/x509write_crt.o
7373
obj-y += library/x509write_csr.o
74+
obj-y += library/xtea.o

ext/lib/crypto/mbedtls/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
The mbed TLS library in Zephyr is a downstream of an externally maintained
22
open source project. The original upstream code can be found at:
33

4-
https://tls.mbed.org/download/start/mbedtls-2.3.0-apache.tgz
4+
https://tls.mbed.org/download/start/mbedtls-2.4.0-apache.tgz
55

6-
At version 2.3.0
6+
At version 2.4.0
77

88
The following is the license information for this code:
99

ext/lib/crypto/mbedtls/configs/config-ccm-psk-tls1_2.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#define MBEDTLS_NO_PLATFORM_ENTROPY
4242
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
4343
#define MBEDTLS_PLATFORM_PRINTF_ALT
44-
#define MBEDTLS_PLATFORM_TIME_TYPE_MACRO int
4544

4645
#if defined(CONFIG_MBEDTLS_TEST)
4746
#define MBEDTLS_SELF_TEST

ext/lib/crypto/mbedtls/configs/config-threadnet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#define MBEDTLS_NO_PLATFORM_ENTROPY
4444
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
4545
#define MBEDTLS_PLATFORM_PRINTF_ALT
46-
#define MBEDTLS_PLATFORM_TIME_TYPE_MACRO int
4746

4847
#if !defined(CONFIG_ARM)
4948
#define MBEDTLS_HAVE_ASM
@@ -77,6 +76,7 @@
7776
#define MBEDTLS_CCM_C
7877
#define MBEDTLS_CIPHER_C
7978
#define MBEDTLS_CTR_DRBG_C
79+
#define MBEDTLS_CMAC_C
8080
#define MBEDTLS_ECJPAKE_C
8181
#define MBEDTLS_ECP_C
8282
#define MBEDTLS_HMAC_DRBG_C

ext/lib/crypto/mbedtls/include/mbedtls/check_config.h

Lines changed: 41 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
@@ -256,6 +261,36 @@
256261
#error "MBEDTLS_PLATFORM_EXIT_MACRO and MBEDTLS_PLATFORM_STD_EXIT/MBEDTLS_PLATFORM_EXIT_ALT cannot be defined simultaneously"
257262
#endif
258263

264+
#if defined(MBEDTLS_PLATFORM_TIME_ALT) &&\
265+
( !defined(MBEDTLS_PLATFORM_C) ||\
266+
!defined(MBEDTLS_HAVE_TIME) )
267+
#error "MBEDTLS_PLATFORM_TIME_ALT defined, but not all prerequisites"
268+
#endif
269+
270+
#if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
271+
( !defined(MBEDTLS_PLATFORM_C) ||\
272+
!defined(MBEDTLS_HAVE_TIME) )
273+
#error "MBEDTLS_PLATFORM_TIME_MACRO defined, but not all prerequisites"
274+
#endif
275+
276+
#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
277+
( !defined(MBEDTLS_PLATFORM_C) ||\
278+
!defined(MBEDTLS_HAVE_TIME) )
279+
#error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO defined, but not all prerequisites"
280+
#endif
281+
282+
#if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
283+
( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
284+
defined(MBEDTLS_PLATFORM_TIME_ALT) )
285+
#error "MBEDTLS_PLATFORM_TIME_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
286+
#endif
287+
288+
#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
289+
( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
290+
defined(MBEDTLS_PLATFORM_TIME_ALT) )
291+
#error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
292+
#endif
293+
259294
#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
260295
#error "MBEDTLS_PLATFORM_FPRINTF_ALT defined, but not all prerequisites"
261296
#endif
@@ -352,6 +387,12 @@
352387
#error "MBEDTLS_PLATFORM_STD_EXIT defined, but not all prerequisites"
353388
#endif
354389

390+
#if defined(MBEDTLS_PLATFORM_STD_TIME) &&\
391+
( !defined(MBEDTLS_PLATFORM_TIME_ALT) ||\
392+
!defined(MBEDTLS_HAVE_TIME) )
393+
#error "MBEDTLS_PLATFORM_STD_TIME defined, but not all prerequisites"
394+
#endif
395+
355396
#if defined(MBEDTLS_PLATFORM_STD_FPRINTF) &&\
356397
!defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
357398
#error "MBEDTLS_PLATFORM_STD_FPRINTF defined, but not all prerequisites"

ext/lib/crypto/mbedtls/include/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
/**
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
/** Internal state of the CMAC algorithm */
48+
unsigned char state[MBEDTLS_CIPHER_BLKSIZE_MAX];
49+
50+
/** Unprocessed data - either data that was not block aligned and is still
51+
* pending to be processed, or the final block */
52+
unsigned char unprocessed_block[MBEDTLS_CIPHER_BLKSIZE_MAX];
53+
54+
/** Length of data pending to be processed */
55+
size_t unprocessed_len;
56+
};
57+
58+
/**
59+
* \brief Set the CMAC key and prepare to authenticate the input
60+
* data.
61+
* Should be called with an initialised cipher context.
62+
*
63+
* \param ctx Cipher context
64+
* \param key CMAC key
65+
* \param keybits length of the CMAC key in bits
66+
* (must be acceptable by the cipher)
67+
*
68+
* \return 0 if successful, or a cipher specific error code
69+
*/
70+
int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
71+
const unsigned char *key, size_t keybits );
72+
73+
/**
74+
* \brief Generic CMAC process buffer.
75+
* Called between mbedtls_cipher_cmac_starts() or
76+
* mbedtls_cipher_cmac_reset() and
77+
* mbedtls_cipher_cmac_finish().
78+
* May be called repeatedly.
79+
*
80+
* \param ctx CMAC context
81+
* \param input buffer holding the data
82+
* \param ilen length of the input data
83+
*
84+
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
85+
* verification fails.
86+
*/
87+
int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
88+
const unsigned char *input, size_t ilen );
89+
90+
/**
91+
* \brief Output CMAC.
92+
* Called after mbedtls_cipher_cmac_update().
93+
* Usually followed by mbedtls_cipher_cmac_reset(), then
94+
* mbedtls_cipher_cmac_starts(), or mbedtls_cipher_free().
95+
*
96+
* \param ctx CMAC context
97+
* \param output Generic CMAC checksum result
98+
*
99+
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
100+
* verification fails.
101+
*/
102+
int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
103+
unsigned char *output );
104+
105+
/**
106+
* \brief Prepare to authenticate a new message with the same key.
107+
* Called after mbedtls_cipher_cmac_finish() and before
108+
* mbedtls_cipher_cmac_update().
109+
*
110+
* \param ctx CMAC context to be reset
111+
*
112+
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
113+
* verification fails.
114+
*/
115+
int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx );
116+
117+
/**
118+
* \brief Output = Generic_CMAC( hmac key, input buffer )
119+
*
120+
* \param cipher_info message digest info
121+
* \param key CMAC key
122+
* \param keylen length of the CMAC key in bits
123+
* \param input buffer holding the data
124+
* \param ilen length of the input data
125+
* \param output Generic CMAC-result
126+
*
127+
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
128+
* verification fails.
129+
*/
130+
int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
131+
const unsigned char *key, size_t keylen,
132+
const unsigned char *input, size_t ilen,
133+
unsigned char *output );
134+
135+
#if defined(MBEDTLS_AES_C)
136+
/**
137+
* \brief AES-CMAC-128-PRF
138+
* Implementation of (AES-CMAC-PRF-128), as defined in RFC 4615
139+
*
140+
* \param key PRF key
141+
* \param key_len PRF key length in bytes
142+
* \param input buffer holding the input data
143+
* \param in_len length of the input data in bytes
144+
* \param output buffer holding the generated pseudorandom output (16 bytes)
145+
*
146+
* \return 0 if successful
147+
*/
148+
int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len,
149+
const unsigned char *input, size_t in_len,
150+
unsigned char output[16] );
151+
#endif /* MBEDTLS_AES_C */
152+
153+
#if defined(MBEDTLS_SELF_TEST) && ( defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) )
154+
/**
155+
* \brief Checkup routine
156+
*
157+
* \return 0 if successful, or 1 if the test failed
158+
*/
159+
int mbedtls_cmac_self_test( int verbose );
160+
#endif /* MBEDTLS_SELF_TEST && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
161+
162+
#ifdef __cplusplus
163+
}
164+
#endif
165+
166+
#endif /* MBEDTLS_CMAC_H */

0 commit comments

Comments
 (0)