Skip to content

Commit deb4995

Browse files
authored
Merge pull request #12150 from Patater/update-tls-crypto-20191220
Update Mbed TLS and Mbed Crypto to latest as of 2019-12-20
2 parents f880838 + 689274b commit deb4995

Some content is hidden

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

86 files changed

+1325
-888
lines changed

TESTS/mbed-crypto/sanity/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ void test_crypto_asymmetric_sign_verify(void)
262262
psa_set_key_algorithm(&attributes, alg);
263263
psa_set_key_type(&attributes, key_type);
264264
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_import_key(&attributes, key, sizeof(key), &key_handle));
265-
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_sign(key_handle, alg, input, sizeof(input),
266-
signature, sizeof(signature), &signature_len));
265+
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_sign_hash(key_handle, alg, input, sizeof(input),
266+
signature, sizeof(signature), &signature_len));
267267
TEST_ASSERT_EQUAL(sizeof(signature), signature_len);
268268
TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_signature, signature, signature_len);
269269

270-
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_verify(key_handle, alg, input, sizeof(input),
271-
signature, signature_len));
270+
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_verify_hash(key_handle, alg, input, sizeof(input),
271+
signature, signature_len));
272272
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
273273
}
274274

TESTS/psa/crypto_access_control/COMPONENT_NSPE/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,12 @@ void test_use_other_partition_key_asymmetric_sign_verify(void)
373373
TEST_ASSERT_NOT_EQUAL(0, key_handle);
374374

375375
/* try to asymmetric sign using the key that was created by the test partition */
376-
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_asymmetric_sign(key_handle, key_alg, input, sizeof(input),
377-
signature, sizeof(signature), &len));
376+
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_sign_hash(key_handle, key_alg, input, sizeof(input),
377+
signature, sizeof(signature), &len));
378378

379379
/* try to asymmetric verify using the key that was created by the test partition */
380-
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_asymmetric_verify(key_handle, key_alg, input, sizeof(input),
381-
signature, sizeof(signature)));
380+
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_verify_hash(key_handle, key_alg, input, sizeof(input),
381+
signature, sizeof(signature)));
382382

383383
/* via test partition - destroy the key created by the test partition */
384384
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_destroy_key(key_handle));

components/TARGET_PSA/services/attestation/COMPONENT_PSA_SRV_IMPL/attest_crypto.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ t_cose_crypto_pub_key_sign(int32_t cose_alg_id,
5858
return T_COSE_ERR_NO_KID;
5959
}
6060

61-
crypto_ret = psa_asymmetric_sign(handle,
62-
PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256),
63-
hash_to_sign.ptr,
64-
hash_to_sign.len,
65-
signature_buffer.ptr,
66-
signature_buffer.len,
67-
&(signature->len));
61+
crypto_ret = psa_sign_hash(handle,
62+
PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256),
63+
hash_to_sign.ptr,
64+
hash_to_sign.len,
65+
signature_buffer.ptr,
66+
signature_buffer.len,
67+
&(signature->len));
6868

6969

7070
if (crypto_ret != PSA_SUCCESS)

components/TARGET_PSA/services/attestation/COMPONENT_PSA_SRV_IMPL/tfm_impl/attestation_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ attest_create_token(struct useful_buf_c *challenge,
942942

943943
/* Limitations of the current implementation:
944944
* - Token is not signed yet properly, just a fake signature is added to the
945-
* token due to lack of psa_asymmetric_sign() implementation in crypto
945+
* token due to lack of psa_sign_hash() implementation in crypto
946946
* service.
947947
*/
948948
enum psa_attest_err_t

components/TARGET_PSA/services/crypto/COMPONENT_PSA_SRV_IPC/crypto_platform_spe.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ typedef enum psa_sec_function_s {
8787
PSA_AEAD_FINISH,
8888
PSA_AEAD_VERIFY,
8989
PSA_AEAD_ABORT,
90-
PSA_ASYMMETRIC_SIGN,
91-
PSA_ASYMMETRIC_VERIFY,
90+
PSA_SIGN_HASH,
91+
PSA_VERIFY_HASH,
9292
PSA_ASYMMETRIC_ENCRYPT,
9393
PSA_ASYMMETRIC_DECRYPT,
9494
PSA_KEY_DERIVATION_SETUP,

components/TARGET_PSA/services/crypto/COMPONENT_PSA_SRV_IPC/psa_crypto_spm.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,16 +1216,16 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation)
12161216
return ipc_call(&operation->handle, &in_vec, 1, NULL, 0, true);
12171217
}
12181218

1219-
psa_status_t psa_asymmetric_sign(psa_key_handle_t handle,
1220-
psa_algorithm_t alg,
1221-
const uint8_t *hash,
1222-
size_t hash_length,
1223-
uint8_t *signature,
1224-
size_t signature_size,
1225-
size_t *signature_length)
1219+
psa_status_t psa_sign_hash(psa_key_handle_t handle,
1220+
psa_algorithm_t alg,
1221+
const uint8_t *hash,
1222+
size_t hash_length,
1223+
uint8_t *signature,
1224+
size_t signature_size,
1225+
size_t *signature_length)
12261226
{
12271227
psa_crypto_ipc_asymmetric_t psa_crypto_ipc = {
1228-
.func = PSA_ASYMMETRIC_SIGN,
1228+
.func = PSA_SIGN_HASH,
12291229
.handle = handle,
12301230
.alg = alg,
12311231
.input_length = 0,
@@ -1246,15 +1246,15 @@ psa_status_t psa_asymmetric_sign(psa_key_handle_t handle,
12461246
return (status);
12471247
}
12481248

1249-
psa_status_t psa_asymmetric_verify(psa_key_handle_t handle,
1250-
psa_algorithm_t alg,
1251-
const uint8_t *hash,
1252-
size_t hash_length,
1253-
const uint8_t *signature,
1254-
size_t signature_size)
1249+
psa_status_t psa_verify_hash(psa_key_handle_t handle,
1250+
psa_algorithm_t alg,
1251+
const uint8_t *hash,
1252+
size_t hash_length,
1253+
const uint8_t *signature,
1254+
size_t signature_size)
12551255
{
12561256
psa_crypto_ipc_asymmetric_t psa_crypto_ipc = {
1257-
.func = PSA_ASYMMETRIC_VERIFY,
1257+
.func = PSA_VERIFY_HASH,
12581258
.handle = handle,
12591259
.alg = alg,
12601260
.input_length = 0,

components/TARGET_PSA/services/crypto/COMPONENT_SPE/crypto_spe.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ extern "C" {
5959
#define psa_aead_finish psa_sec_aead_finish
6060
#define psa_aead_verify psa_sec_aead_verify
6161
#define psa_aead_abort psa_sec_aead_abort
62-
#define psa_asymmetric_sign psa_sec_asymmetric_sign
63-
#define psa_asymmetric_verify psa_sec_asymmetric_verify
62+
#define psa_sign_hash psa_sec_sign_hash
63+
#define psa_verify_hash psa_sec_verify_hash
6464
#define psa_asymmetric_encrypt psa_sec_asymmetric_encrypt
6565
#define psa_asymmetric_decrypt psa_sec_asymmetric_decrypt
6666
#define psa_key_derivation_setup psa_sec_key_derivation_setup

components/TARGET_PSA/services/crypto/COMPONENT_SPE/psa_crypto_partition.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ static void psa_asymmetric_operation(void)
989989
}
990990

991991
switch (psa_crypto.func) {
992-
case PSA_ASYMMETRIC_SIGN: {
992+
case PSA_SIGN_HASH: {
993993
uint8_t *signature = NULL;
994994
uint8_t *hash = NULL;
995995
size_t signature_length = 0,
@@ -1015,9 +1015,9 @@ static void psa_asymmetric_operation(void)
10151015
}
10161016

10171017
if (status == PSA_SUCCESS) {
1018-
status = psa_asymmetric_sign(psa_crypto.handle, psa_crypto.alg,
1019-
hash, hash_size,
1020-
signature, signature_size, &signature_length);
1018+
status = psa_sign_hash(psa_crypto.handle, psa_crypto.alg,
1019+
hash, hash_size,
1020+
signature, signature_size, &signature_length);
10211021

10221022
if (status == PSA_SUCCESS) {
10231023
psa_write(msg.handle, 0, signature, signature_length);
@@ -1030,7 +1030,7 @@ static void psa_asymmetric_operation(void)
10301030
break;
10311031
}
10321032

1033-
case PSA_ASYMMETRIC_VERIFY: {
1033+
case PSA_VERIFY_HASH: {
10341034
uint8_t *signature = NULL;
10351035
uint8_t *hash = NULL;
10361036
size_t signature_size = msg.in_size[1],
@@ -1060,9 +1060,9 @@ static void psa_asymmetric_operation(void)
10601060
}
10611061

10621062
if (status == PSA_SUCCESS) {
1063-
status = psa_asymmetric_verify(psa_crypto.handle, psa_crypto.alg,
1064-
hash, hash_size,
1065-
signature, signature_size);
1063+
status = psa_verify_hash(psa_crypto.handle, psa_crypto.alg,
1064+
hash, hash_size,
1065+
signature, signature_size);
10661066
}
10671067

10681068
mbedtls_free(signature);

features/mbedtls/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mbedtls-2.20.0d0
1+
mbedtls-2.20.0d1

features/mbedtls/importer/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#
2828

2929
# Set the mbed TLS release to import (this can/should be edited before import)
30-
MBED_TLS_RELEASE ?= mbedtls-2.20.0d0
31-
MBED_TLS_REPO_URL ?= [email protected]:ARMmbed/mbedtls-restricted.git
30+
MBED_TLS_RELEASE ?= mbedtls-2.20.0d1
31+
MBED_TLS_REPO_URL ?= [email protected]:ARMmbed/mbedtls.git
3232

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

features/mbedtls/inc/mbedtls/error.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@
5252
* For historical reasons, low-level error codes are divided in even and odd,
5353
* even codes were assigned first, and -1 is reserved for other errors.
5454
*
55-
* Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
55+
* Low-level module errors (0x0002-0x007E, 0x0001-0x007F)
5656
*
5757
* Module Nr Codes assigned
58+
* ERROR 2 0x006E 0x0001
5859
* MPI 7 0x0002-0x0010
5960
* GCM 3 0x0012-0x0014 0x0013-0x0013
6061
* BLOWFISH 3 0x0016-0x0018 0x0017-0x0017
@@ -86,7 +87,7 @@
8687
* CHACHA20 3 0x0051-0x0055
8788
* POLY1305 3 0x0057-0x005B
8889
* CHACHAPOLY 2 0x0054-0x0056
89-
* PLATFORM 1 0x0070-0x0072
90+
* PLATFORM 2 0x0070-0x0072
9091
*
9192
* High-level module nr (3 bits - 0x0...-0x7...)
9293
* Name ID Nr of Errors
@@ -112,6 +113,9 @@
112113
extern "C" {
113114
#endif
114115

116+
#define MBEDTLS_ERR_ERROR_GENERIC_ERROR -0x0001 /**< Generic error */
117+
#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E /**< This is a bug in the library */
118+
115119
/**
116120
* \brief Translate a mbed TLS error code into a string representation,
117121
* Result is truncated if necessary and always includes a terminating
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mbedcrypto-2.1.0d0
1+
mbedcrypto-3.0.0d0

features/mbedtls/mbed-crypto/importer/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
# Set the Mbed Crypto release to import (this can/should be edited before
3131
# import)
32-
CRYPTO_RELEASE ?= mbedcrypto-2.1.0d0
33-
CRYPTO_REPO_URL ?= [email protected]:ARMmbed/mbedtls-psa.git
32+
CRYPTO_RELEASE ?= mbedcrypto-3.0.0d0
33+
CRYPTO_REPO_URL ?= [email protected]:ARMmbed/mbed-crypto.git
3434

3535
# Translate between Mbed Crypto namespace and Mbed OS namespace
3636
TARGET_PREFIX:=..

features/mbedtls/mbed-crypto/inc/mbedtls/asn1.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#define MBEDTLS_ASN1_OCTET_STRING 0x04
7676
#define MBEDTLS_ASN1_NULL 0x05
7777
#define MBEDTLS_ASN1_OID 0x06
78+
#define MBEDTLS_ASN1_ENUMERATED 0x0A
7879
#define MBEDTLS_ASN1_UTF8_STRING 0x0C
7980
#define MBEDTLS_ASN1_SEQUENCE 0x10
8081
#define MBEDTLS_ASN1_SET 0x11
@@ -254,13 +255,32 @@ int mbedtls_asn1_get_bool( unsigned char **p,
254255
* a valid ASN.1 INTEGER.
255256
* \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does
256257
* not fit in an \c int.
257-
* \return An ASN.1 error code if the input does not start with
258-
* a valid ASN.1 INTEGER.
259258
*/
260259
int mbedtls_asn1_get_int( unsigned char **p,
261260
const unsigned char *end,
262261
int *val );
263262

263+
/**
264+
* \brief Retrieve an enumerated ASN.1 tag and its value.
265+
* Updates the pointer to immediately behind the full tag.
266+
*
267+
* \param p On entry, \c *p points to the start of the ASN.1 element.
268+
* On successful completion, \c *p points to the first byte
269+
* beyond the ASN.1 element.
270+
* On error, the value of \c *p is undefined.
271+
* \param end End of data.
272+
* \param val On success, the parsed value.
273+
*
274+
* \return 0 if successful.
275+
* \return An ASN.1 error code if the input does not start with
276+
* a valid ASN.1 ENUMERATED.
277+
* \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does
278+
* not fit in an \c int.
279+
*/
280+
int mbedtls_asn1_get_enum( unsigned char **p,
281+
const unsigned char *end,
282+
int *val );
283+
264284
/**
265285
* \brief Retrieve a bitstring ASN.1 tag and its value.
266286
* Updates the pointer to immediately behind the full tag.
@@ -367,8 +387,6 @@ int mbedtls_asn1_get_sequence_of( unsigned char **p,
367387
* \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does
368388
* not fit in an \c int.
369389
* \return An MPI error code if the parsed value is too large.
370-
* \return An ASN.1 error code if the input does not start with
371-
* a valid ASN.1 INTEGER.
372390
*/
373391
int mbedtls_asn1_get_mpi( unsigned char **p,
374392
const unsigned char *end,

features/mbedtls/mbed-crypto/inc/mbedtls/asn1write.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start,
192192
*/
193193
int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val );
194194

195+
/**
196+
* \brief Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value
197+
* in ASN.1 format.
198+
*
199+
* \note This function works backwards in data buffer.
200+
*
201+
* \param p The reference to the current position pointer.
202+
* \param start The start of the buffer, for bounds-checking.
203+
* \param val The integer value to write.
204+
*
205+
* \return The number of bytes written to \p p on success.
206+
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
207+
*/
208+
int mbedtls_asn1_write_enum( unsigned char **p, unsigned char *start, int val );
209+
195210
/**
196211
* \brief Write a string in ASN.1 format using a specific
197212
* string encoding tag.

0 commit comments

Comments
 (0)