Skip to content

Commit a80a874

Browse files
committed
crypto/mbedtls: Upgrade to v3.6.2
This upgrades mbedtls version to v3.6.2: 1. mbedtls repository changed to version v3.6.2 2. Removed tests that are no longer supported 3. Updated/modified gcm_mynewt API: a) Function mbedtls_gcm_update_add is removed, because now function mbedtls_gcm_update_ad from mbedtls upstream provides the same functionality. b) Due to internal mbedtls API changes mbedtls_gcm_setkey_noalloc function now needs one argument more, which is keybits. This argument specifies length of key in bits and should be set to 128, 192 or 256. Other values won't be accepted. In earlier version this could be extracted from mbedtls_cipher_info_t key_bitlen field, which is no longer the case - now it's 4 bit bitfield later processed by internal mbedtls macros. It probably would be possible to not break this APIs, but since a lot of mbedtls APIs where changed in new version it was assumed that migration changes in projects using mbedtls would be necessary anyway.
1 parent be32386 commit a80a874

File tree

13 files changed

+130
-386
lines changed

13 files changed

+130
-386
lines changed

crypto/mbedtls/include/mbedtls/config_mynewt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ extern "C" {
501501
#undef MBEDTLS_PSA_CRYPTO_SE_C
502502
#undef MBEDTLS_PSA_CRYPTO_STORAGE_C
503503
#undef MBEDTLS_PSA_ITS_FILE_C
504+
#undef MBEDTLS_LMS_C
504505

505506
#ifdef __cplusplus
506507
}

crypto/mbedtls/include/mbedtls/gcm_mynewt.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,16 @@
2020
#ifndef _GCM_MYNEWT_H_
2121
#define _GCM_MYNEWT_H_
2222

23+
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
2324
#include <mbedtls/gcm.h>
2425

25-
/**
26-
* \brief This function feeds an input buffer into an ongoing GCM
27-
* encryption or decryption operation as additional data.
28-
* This needs to be called before starting enc/dec
29-
* operations.
30-
*
31-
* ` The function expects input to be a multiple of 16
32-
* Bytes. Only the last call before mbedtls_gcm_update() or
33-
* mbedtls_gcm_finish() can be less than 16 Bytes.
34-
*
35-
*
36-
* \param ctx The GCM context.
37-
* \param length The length of the input data. This must be a multiple of
38-
* 16 except in the last call before mbedtls_gcm_finish().
39-
* \param input The buffer holding the input ADD.
40-
*
41-
* \return \c 0 on success.
42-
* \return #MBEDTLS_ERR_GCM_BAD_INPUT on failure.
43-
*/
44-
int mbedtls_gcm_update_add( mbedtls_gcm_context *ctx,
45-
size_t length,
46-
const unsigned char *input );
47-
48-
4926
/**
5027
* Same as mbedtls_gcm_setkey, but with preallocated memory for cipher algorithm context
5128
*/
5229
int mbedtls_gcm_setkey_noalloc( mbedtls_gcm_context *ctx,
5330
const mbedtls_cipher_info_t *cipher_info,
5431
const unsigned char *key,
32+
unsigned int keybits,
5533
void *cipher_ctx);
5634

5735

crypto/mbedtls/pkg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pkg.src_dirs:
4747

4848
repository.mbedtls:
4949
type: github
50-
vers: v2.28.9-commit
50+
vers: v3.6.2-commit
5151
branch: master
5252
user: Mbed-TLS
5353
repo: mbedtls

crypto/mbedtls/selftest/src/mbedtls_test.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "mbedtls/sha256.h"
2828
#include "mbedtls/sha512.h"
2929
#include "mbedtls/aes.h"
30-
#include "mbedtls/arc4.h"
3130
#include "mbedtls/bignum.h"
3231
#include "mbedtls/ccm.h"
3332
#include "mbedtls/dhm.h"
@@ -41,7 +40,6 @@
4140
#include "mbedtls/ripemd160.h"
4241
#include "mbedtls/rsa.h"
4342
#include "mbedtls/x509.h"
44-
#include "mbedtls/xtea.h"
4543
#include "mbedtls/poly1305.h"
4644
#include "mbedtls/chacha20.h"
4745
#include "mbedtls/chachapoly.h"
@@ -53,7 +51,6 @@
5351
#include "mbedtls/timing.h"
5452

5553
TEST_CASE_DECL(aes_test)
56-
TEST_CASE_DECL(arc4_test)
5754
TEST_CASE_DECL(aria_test)
5855
TEST_CASE_DECL(base64_test)
5956
TEST_CASE_DECL(bignum_test)
@@ -70,8 +67,6 @@ TEST_CASE_DECL(ecp_test)
7067
TEST_CASE_DECL(entropy_test)
7168
TEST_CASE_DECL(gcm_test)
7269
TEST_CASE_DECL(hmac_drbg_test)
73-
TEST_CASE_DECL(md2_test)
74-
TEST_CASE_DECL(md4_test)
7570
TEST_CASE_DECL(md5_test)
7671
TEST_CASE_DECL(memory_buffer_alloc_test)
7772
TEST_CASE_DECL(nist_kw_test)
@@ -82,15 +77,11 @@ TEST_CASE_DECL(rsa_test)
8277
TEST_CASE_DECL(sha1_test)
8378
TEST_CASE_DECL(sha256_test)
8479
TEST_CASE_DECL(sha512_test)
85-
TEST_CASE_DECL(timing_test)
86-
TEST_CASE_DECL(x509_test)
87-
TEST_CASE_DECL(xtea_test)
8880
TEST_CASE_DECL(gcm_mynewt_test)
8981

9082
TEST_SUITE(mbedtls_test_all)
9183
{
9284
aes_test();
93-
arc4_test();
9485
aria_test();
9586
base64_test();
9687
bignum_test();
@@ -107,8 +98,6 @@ TEST_SUITE(mbedtls_test_all)
10798
entropy_test();
10899
gcm_test();
109100
hmac_drbg_test();
110-
md2_test();
111-
md4_test();
112101
md5_test();
113102
nist_kw_test();
114103
pkcs5_test();
@@ -118,9 +107,6 @@ TEST_SUITE(mbedtls_test_all)
118107
sha1_test();
119108
sha256_test();
120109
sha512_test();
121-
timing_test();
122-
x509_test();
123-
xtea_test();
124110
gcm_mynewt_test();
125111
}
126112

crypto/mbedtls/selftest/src/mbedtls_test.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "testutil/testutil.h"
2626

2727
#include "mbedtls/aes.h"
28-
#include "mbedtls/arc4.h"
2928
#include "mbedtls/aria.h"
3029
#include "mbedtls/base64.h"
3130
#include "mbedtls/bignum.h"
@@ -42,8 +41,6 @@
4241
#include "mbedtls/entropy.h"
4342
#include "mbedtls/gcm.h"
4443
#include "mbedtls/hmac_drbg.h"
45-
#include "mbedtls/md2.h"
46-
#include "mbedtls/md4.h"
4744
#include "mbedtls/md5.h"
4845
#include "mbedtls/nist_kw.h"
4946
#include "mbedtls/pkcs5.h"
@@ -53,9 +50,6 @@
5350
#include "mbedtls/sha1.h"
5451
#include "mbedtls/sha256.h"
5552
#include "mbedtls/sha512.h"
56-
#include "mbedtls/timing.h"
57-
#include "mbedtls/x509.h"
58-
#include "mbedtls/xtea.h"
5953
#include "gcm_mynewt.h"
6054

6155
#ifdef __cplusplus

crypto/mbedtls/selftest/src/testcases/arc4_test.c

Lines changed: 0 additions & 27 deletions
This file was deleted.

crypto/mbedtls/selftest/src/testcases/gcm_mynewt_test.c

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,32 @@ static const mbedtls_cipher_info_t *rsm_ucast_cipher;
2424

2525
/* This contains both ADD and plaintext for encryption */
2626
static const uint8_t initial_data[110] = {
27-
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x11,
28-
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x21, 0x22,
29-
0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x31, 0x32, 0x33,
30-
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x41, 0x42, 0x43, 0x44,
31-
0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x51, 0x52, 0x53, 0x54, 0x55,
32-
0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
33-
0x67, 0x68, 0x69, 0x6A, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
34-
0x78, 0x79, 0x7A, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
35-
0x89, 0x8A, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
36-
0x9A, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA
27+
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
28+
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
29+
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,
30+
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
31+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A,
32+
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,
33+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A,
34+
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A,
35+
0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A,
36+
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A,
37+
0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA
3738
};
38-
39-
static const uint8_t key[32] = { 0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0,
40-
0x1A, 0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA,
41-
0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A, 0xC0,
42-
0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A,
43-
0xC0, 0xCA, 0xC0, 0x1A };
44-
45-
static const uint8_t iv[12] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5,
46-
0x6, 0x7, 0x8, 0x9, 0xA, 0xB };
47-
48-
static const uint8_t expected_tag[16] = { 0x05, 0x5D, 0x8E, 0xD4, 0xF9, 0x2A,
49-
0x87, 0x87, 0x6F, 0x23, 0xF2, 0xE6,
50-
0xF0, 0x1D, 0x6D, 0x5C };
39+
static const uint8_t key[32] = {
40+
0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A,
41+
0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A,
42+
0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A,
43+
0xC0, 0xCA, 0xC0, 0x1A, 0xC0, 0xCA, 0xC0, 0x1A
44+
};
45+
static const uint8_t iv[12] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB };
46+
static const uint8_t expected_tag[16] = { 0x05, 0x5D, 0x8E, 0xD4, 0xF9, 0x2A, 0x87, 0x87,
47+
0x6F, 0x23, 0xF2, 0xE6, 0xF0, 0x1D, 0x6D, 0x5C };
5148

5249
static uint8_t test_tag[16];
5350
static uint8_t test_buf[110];
5451

55-
static int
56-
mbedtls_gcm_mynewt_test_crypt(uint8_t enc)
52+
static int mbedtls_gcm_mynewt_test_crypt(uint8_t enc)
5753
{
5854
int add_len = 40;
5955
mbedtls_gcm_context ctx;
@@ -63,22 +59,25 @@ mbedtls_gcm_mynewt_test_crypt(uint8_t enc)
6359
uint16_t off;
6460
uint16_t blklen;
6561
uint16_t totlen;
62+
size_t len_check;
6663
int rc;
6764

6865
if (rsm_ucast_cipher == NULL) {
69-
rsm_ucast_cipher = mbedtls_cipher_info_from_values(MBEDTLS_CIPHER_ID_AES,
70-
256, MBEDTLS_MODE_ECB);
66+
rsm_ucast_cipher =
67+
mbedtls_cipher_info_from_values(MBEDTLS_CIPHER_ID_AES, 256,
68+
MBEDTLS_MODE_ECB);
7169
}
7270

7371
memset(&ctx, 0, sizeof(ctx));
7472
mbedtls_aes_init(&aes_ctx);
75-
rc = mbedtls_gcm_setkey_noalloc(&ctx, rsm_ucast_cipher, key, &aes_ctx);
73+
rc = mbedtls_gcm_setkey_noalloc(&ctx, rsm_ucast_cipher, key, 256, &aes_ctx);
7674
if (rc) {
7775
goto out;
7876
}
7977

80-
rc = mbedtls_gcm_starts(&ctx, enc == 1 ? MBEDTLS_GCM_ENCRYPT : MBEDTLS_GCM_DECRYPT,
81-
iv, sizeof(iv), NULL, 0);
78+
rc = mbedtls_gcm_starts(&ctx,
79+
enc == 1 ? MBEDTLS_GCM_ENCRYPT : MBEDTLS_GCM_DECRYPT,
80+
iv, sizeof(iv));
8281
if (rc) {
8382
goto out;
8483
}
@@ -105,18 +104,26 @@ mbedtls_gcm_mynewt_test_crypt(uint8_t enc)
105104
}
106105

107106
if (off < add_len) {
108-
mbedtls_gcm_update_add(&ctx, blklen, ptr);
107+
mbedtls_gcm_update_ad(&ctx, ptr, blklen);
109108
} else {
110-
rc = mbedtls_gcm_update(&ctx, blklen, ptr, ptr);
109+
rc = mbedtls_gcm_update(&ctx, ptr, blklen, ptr, blklen, &len_check);
111110
if (rc) {
112111
goto out;
113112
}
113+
if (len_check != blklen) {
114+
rc = 1;
115+
goto out;
116+
}
114117
}
115118

116119
off += blklen;
117120
}
118121

119-
rc = mbedtls_gcm_finish(&ctx, test_tag, sizeof(test_tag));
122+
rc = mbedtls_gcm_finish(&ctx, NULL, 0, &len_check, test_tag, sizeof(test_tag));
123+
if (len_check != 0) {
124+
rc = 1;
125+
goto out;
126+
}
120127
out:
121128
memset(&ctx, 0, sizeof(ctx));
122129
mbedtls_aes_free(&aes_ctx);
@@ -138,5 +145,5 @@ TEST_CASE_SELF(gcm_mynewt_test)
138145
rc = mbedtls_gcm_mynewt_test_crypt(0);
139146
TEST_ASSERT(rc == 0);
140147
TEST_ASSERT(memcmp(test_tag, expected_tag, sizeof(test_tag)) == 0);
141-
TEST_ASSERT(memcmp(test_buf, initial_data, sizeof(test_buf)) == 0);
148+
TEST_ASSERT(memcmp(test_buf, initial_data, sizeof(initial_data)) == 0);
142149
}

crypto/mbedtls/selftest/src/testcases/md2_test.c

Lines changed: 0 additions & 27 deletions
This file was deleted.

crypto/mbedtls/selftest/src/testcases/md4_test.c

Lines changed: 0 additions & 27 deletions
This file was deleted.

crypto/mbedtls/selftest/src/testcases/timing_test.c

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)