Skip to content

Commit fdc57f8

Browse files
PataterDavid Saada
authored andcommitted
crypto: Update to Mbed Crypto 1.0.0d4
1 parent dfab4de commit fdc57f8

File tree

14 files changed

+231
-84
lines changed

14 files changed

+231
-84
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mbedcrypto-1.0.0d3
1+
mbedcrypto-1.0.0d4

features/mbedtls/mbed-crypto/importer/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Set the Mbed Crypto release to import (this can/should be edited before
3131
# import)
32-
CRYPTO_RELEASE ?= mbedcrypto-1.0.0d3
32+
CRYPTO_RELEASE ?= mbedcrypto-1.0.0d4
3333
CRYPTO_REPO_URL ?= [email protected]:ARMmbed/mbed-crypto.git
3434

3535
# Translate between Mbed Crypto namespace and Mbed OS namespace

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ typedef struct psa_hash_operation_s psa_hash_operation_t;
782782
*/
783783
static psa_hash_operation_t psa_hash_operation_init(void);
784784

785-
/** Start a multipart hash operation.
785+
/** Set up a multipart hash operation.
786786
*
787787
* The sequence of operations to calculate a hash (message digest)
788788
* is as follows:
@@ -816,6 +816,9 @@ static psa_hash_operation_t psa_hash_operation_init(void);
816816
* Success.
817817
* \retval #PSA_ERROR_NOT_SUPPORTED
818818
* \p alg is not supported or is not a hash algorithm.
819+
* \retval #PSA_ERROR_BAD_STATE
820+
* The operation state is not valid (already set up and not
821+
* subsequently completed).
819822
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
820823
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
821824
* \retval #PSA_ERROR_HARDWARE_FAILURE
@@ -837,7 +840,7 @@ psa_status_t psa_hash_setup(psa_hash_operation_t *operation,
837840
* \retval #PSA_SUCCESS
838841
* Success.
839842
* \retval #PSA_ERROR_BAD_STATE
840-
* The operation state is not valid (not started, or already completed).
843+
* The operation state is not valid (not set up, or already completed).
841844
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
842845
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
843846
* \retval #PSA_ERROR_HARDWARE_FAILURE
@@ -874,7 +877,7 @@ psa_status_t psa_hash_update(psa_hash_operation_t *operation,
874877
* \retval #PSA_SUCCESS
875878
* Success.
876879
* \retval #PSA_ERROR_BAD_STATE
877-
* The operation state is not valid (not started, or already completed).
880+
* The operation state is not valid (not set up, or already completed).
878881
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
879882
* The size of the \p hash buffer is too small. You can determine a
880883
* sufficient buffer size by calling #PSA_HASH_SIZE(\c alg)
@@ -914,7 +917,7 @@ psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
914917
* The hash of the message was calculated successfully, but it
915918
* differs from the expected hash.
916919
* \retval #PSA_ERROR_BAD_STATE
917-
* The operation state is not valid (not started, or already completed).
920+
* The operation state is not valid (not set up, or already completed).
918921
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
919922
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
920923
* \retval #PSA_ERROR_HARDWARE_FAILURE
@@ -1032,7 +1035,7 @@ typedef struct psa_mac_operation_s psa_mac_operation_t;
10321035
*/
10331036
static psa_mac_operation_t psa_mac_operation_init(void);
10341037

1035-
/** Start a multipart MAC calculation operation.
1038+
/** Set up a multipart MAC calculation operation.
10361039
*
10371040
* This function sets up the calculation of the MAC
10381041
* (message authentication code) of a byte string.
@@ -1082,6 +1085,9 @@ static psa_mac_operation_t psa_mac_operation_init(void);
10821085
* \retval #PSA_ERROR_HARDWARE_FAILURE
10831086
* \retval #PSA_ERROR_TAMPERING_DETECTED
10841087
* \retval #PSA_ERROR_BAD_STATE
1088+
* The operation state is not valid (already set up and not
1089+
* subsequently completed).
1090+
* \retval #PSA_ERROR_BAD_STATE
10851091
* The library has not been previously initialized by psa_crypto_init().
10861092
* It is implementation-dependent whether a failure to initialize
10871093
* results in this error code.
@@ -1090,7 +1096,7 @@ psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation,
10901096
psa_key_handle_t handle,
10911097
psa_algorithm_t alg);
10921098

1093-
/** Start a multipart MAC verification operation.
1099+
/** Set up a multipart MAC verification operation.
10941100
*
10951101
* This function sets up the verification of the MAC
10961102
* (message authentication code) of a byte string against an expected value.
@@ -1139,6 +1145,9 @@ psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation,
11391145
* \retval #PSA_ERROR_HARDWARE_FAILURE
11401146
* \retval #PSA_ERROR_TAMPERING_DETECTED
11411147
* \retval #PSA_ERROR_BAD_STATE
1148+
* The operation state is not valid (already set up and not
1149+
* subsequently completed).
1150+
* \retval #PSA_ERROR_BAD_STATE
11421151
* The library has not been previously initialized by psa_crypto_init().
11431152
* It is implementation-dependent whether a failure to initialize
11441153
* results in this error code.
@@ -1162,7 +1171,7 @@ psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation,
11621171
* \retval #PSA_SUCCESS
11631172
* Success.
11641173
* \retval #PSA_ERROR_BAD_STATE
1165-
* The operation state is not valid (not started, or already completed).
1174+
* The operation state is not valid (not set up, or already completed).
11661175
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
11671176
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
11681177
* \retval #PSA_ERROR_HARDWARE_FAILURE
@@ -1201,7 +1210,7 @@ psa_status_t psa_mac_update(psa_mac_operation_t *operation,
12011210
* \retval #PSA_SUCCESS
12021211
* Success.
12031212
* \retval #PSA_ERROR_BAD_STATE
1204-
* The operation state is not valid (not started, or already completed).
1213+
* The operation state is not valid (not set up, or already completed).
12051214
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
12061215
* The size of the \p mac buffer is too small. You can determine a
12071216
* sufficient buffer size by calling PSA_MAC_FINAL_SIZE().
@@ -1240,7 +1249,7 @@ psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation,
12401249
* The MAC of the message was calculated successfully, but it
12411250
* differs from the expected MAC.
12421251
* \retval #PSA_ERROR_BAD_STATE
1243-
* The operation state is not valid (not started, or already completed).
1252+
* The operation state is not valid (not set up, or already completed).
12441253
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
12451254
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
12461255
* \retval #PSA_ERROR_HARDWARE_FAILURE
@@ -1384,6 +1393,9 @@ static psa_cipher_operation_t psa_cipher_operation_init(void);
13841393
* \retval #PSA_ERROR_HARDWARE_FAILURE
13851394
* \retval #PSA_ERROR_TAMPERING_DETECTED
13861395
* \retval #PSA_ERROR_BAD_STATE
1396+
* The operation state is not valid (already set up and not
1397+
* subsequently completed).
1398+
* \retval #PSA_ERROR_BAD_STATE
13871399
* The library has not been previously initialized by psa_crypto_init().
13881400
* It is implementation-dependent whether a failure to initialize
13891401
* results in this error code.
@@ -1443,6 +1455,9 @@ psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation,
14431455
* \retval #PSA_ERROR_HARDWARE_FAILURE
14441456
* \retval #PSA_ERROR_TAMPERING_DETECTED
14451457
* \retval #PSA_ERROR_BAD_STATE
1458+
* The operation state is not valid (already set up and not
1459+
* subsequently completed).
1460+
* \retval #PSA_ERROR_BAD_STATE
14461461
* The library has not been previously initialized by psa_crypto_init().
14471462
* It is implementation-dependent whether a failure to initialize
14481463
* results in this error code.
@@ -1471,7 +1486,7 @@ psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation,
14711486
* \retval #PSA_SUCCESS
14721487
* Success.
14731488
* \retval #PSA_ERROR_BAD_STATE
1474-
* The operation state is not valid (not started, or IV already set).
1489+
* The operation state is not valid (not set up, or IV already set).
14751490
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
14761491
* The size of the \p iv buffer is too small.
14771492
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -1505,7 +1520,7 @@ psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation,
15051520
* \retval #PSA_SUCCESS
15061521
* Success.
15071522
* \retval #PSA_ERROR_BAD_STATE
1508-
* The operation state is not valid (not started, or IV already set).
1523+
* The operation state is not valid (not set up, or IV already set).
15091524
* \retval #PSA_ERROR_INVALID_ARGUMENT
15101525
* The size of \p iv is not acceptable for the chosen algorithm,
15111526
* or the chosen algorithm does not use an IV.
@@ -1541,7 +1556,7 @@ psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation,
15411556
* \retval #PSA_SUCCESS
15421557
* Success.
15431558
* \retval #PSA_ERROR_BAD_STATE
1544-
* The operation state is not valid (not started, IV required but
1559+
* The operation state is not valid (not set up, IV required but
15451560
* not set, or already completed).
15461561
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
15471562
* The size of the \p output buffer is too small.
@@ -1579,7 +1594,7 @@ psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
15791594
* \retval #PSA_SUCCESS
15801595
* Success.
15811596
* \retval #PSA_ERROR_BAD_STATE
1582-
* The operation state is not valid (not started, IV required but
1597+
* The operation state is not valid (not set up, IV required but
15831598
* not set, or already completed).
15841599
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
15851600
* The size of the \p output buffer is too small.

features/mbedtls/mbed-crypto/inc/psa/crypto_platform.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,53 @@
4949
/* Integral type representing a key handle. */
5050
typedef uint16_t psa_key_handle_t;
5151

52+
/* This implementation distinguishes *application key identifiers*, which
53+
* are the key identifiers specified by the application, from
54+
* *key file identifiers*, which are the key identifiers that the library
55+
* sees internally. The two types can be different if there is a remote
56+
* call layer between the application and the library which supports
57+
* multiple client applications that do not have access to each others'
58+
* keys. The point of having different types is that the key file
59+
* identifier may encode not only the key identifier specified by the
60+
* application, but also the the identity of the application.
61+
*
62+
* Note that this is an internal concept of the library and the remote
63+
* call layer. The application itself never sees anything other than
64+
* #psa_app_key_id_t with its standard definition.
65+
*/
66+
67+
/* The application key identifier is always what the application sees as
68+
* #psa_key_id_t. */
69+
typedef uint32_t psa_app_key_id_t;
70+
71+
#if defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER)
72+
73+
#if defined(PSA_CRYPTO_SECURE)
74+
/* Building for the PSA Crypto service on a PSA platform. */
75+
/* A key owner is a PSA partition identifier. */
76+
typedef int32_t psa_key_owner_id_t;
77+
#endif
78+
79+
typedef struct
80+
{
81+
uint32_t key_id;
82+
psa_key_owner_id_t owner;
83+
} psa_key_file_id_t;
84+
#define PSA_KEY_FILE_GET_KEY_ID( file_id ) ( ( file_id ).key_id )
85+
86+
/* Since crypto.h is used as part of the PSA Cryptography API specification,
87+
* it must use standard types for things like the argument of psa_open_key().
88+
* If it wasn't for that constraint, psa_open_key() would take a
89+
* `psa_key_file_id_t` argument. As a workaround, make `psa_key_id_t` an
90+
* alias for `psa_key_file_id_t` when building for a multi-client service. */
91+
typedef psa_key_file_id_t psa_key_id_t;
92+
93+
#else /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */
94+
95+
/* By default, a key file identifier is just the application key identifier. */
96+
typedef psa_app_key_id_t psa_key_file_id_t;
97+
#define PSA_KEY_FILE_GET_KEY_ID( id ) ( id )
98+
99+
#endif /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */
100+
52101
#endif /* PSA_CRYPTO_PLATFORM_H */

features/mbedtls/mbed-crypto/inc/psa/crypto_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,14 @@ typedef uint32_t psa_key_lifetime_t;
9090

9191
/** Encoding of identifiers of persistent keys.
9292
*/
93+
/* Implementation-specific quirk: The Mbed Crypto library can be built as
94+
* part of a multi-client service that exposes the PSA Crypto API in each
95+
* client and encodes the client identity in the key id argument of functions
96+
* such as psa_open_key(). In this build configuration, we define
97+
* psa_key_id_t in crypto_platform.h instead of here. */
98+
#if !defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER)
9399
typedef uint32_t psa_key_id_t;
100+
#endif
94101

95102
/**@}*/
96103

features/mbedtls/mbed-crypto/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL/psa_crypto.c

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,8 @@
2626
#endif
2727

2828
#if defined(MBEDTLS_PSA_CRYPTO_C)
29-
/*
30-
* When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is being built for SPM
31-
* (Secure Partition Manager) integration which separates the code into two
32-
* parts: NSPE (Non-Secure Processing Environment) and SPE (Secure Processing
33-
* Environment). When building for the SPE, an additional header file should be
34-
* included.
35-
*/
36-
#if defined(MBEDTLS_PSA_CRYPTO_SPM)
37-
/*
38-
* PSA_CRYPTO_SECURE means that this file is compiled for the SPE.
39-
* Some headers will be affected by this flag.
40-
*/
41-
#define PSA_CRYPTO_SECURE 1
42-
#include "crypto_spe.h"
43-
#endif
4429

30+
#include "psa_crypto_service_integration.h"
4531
#include "psa/crypto.h"
4632

4733
#include "psa_crypto_core.h"
@@ -172,13 +158,21 @@ static psa_status_t mbedtls_to_psa_error( int ret )
172158
case MBEDTLS_ERR_ASN1_BUF_TOO_SMALL:
173159
return( PSA_ERROR_BUFFER_TOO_SMALL );
174160

161+
#if defined(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA)
175162
case MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA:
163+
#elif defined(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH)
164+
case MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH:
165+
#endif
176166
case MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH:
177167
return( PSA_ERROR_NOT_SUPPORTED );
178168
case MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED:
179169
return( PSA_ERROR_HARDWARE_FAILURE );
180170

171+
#if defined(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA)
181172
case MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA:
173+
#elif defined(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH)
174+
case MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH:
175+
#endif
182176
case MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH:
183177
return( PSA_ERROR_NOT_SUPPORTED );
184178
case MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED:
@@ -3621,6 +3615,12 @@ psa_status_t psa_generator_abort( psa_crypto_generator_t *generator )
36213615
psa_status_t psa_get_generator_capacity(const psa_crypto_generator_t *generator,
36223616
size_t *capacity)
36233617
{
3618+
if( generator->alg == 0 )
3619+
{
3620+
/* This is a blank generator. */
3621+
return PSA_ERROR_BAD_STATE;
3622+
}
3623+
36243624
*capacity = generator->capacity;
36253625
return( PSA_SUCCESS );
36263626
}
@@ -3850,6 +3850,12 @@ psa_status_t psa_generator_read( psa_crypto_generator_t *generator,
38503850
{
38513851
psa_status_t status;
38523852

3853+
if( generator->alg == 0 )
3854+
{
3855+
/* This is a blank generator. */
3856+
return PSA_ERROR_BAD_STATE;
3857+
}
3858+
38533859
if( output_length > generator->capacity )
38543860
{
38553861
generator->capacity = 0;
@@ -3858,11 +3864,10 @@ psa_status_t psa_generator_read( psa_crypto_generator_t *generator,
38583864
status = PSA_ERROR_INSUFFICIENT_DATA;
38593865
goto exit;
38603866
}
3861-
if( output_length == 0 &&
3862-
generator->capacity == 0 && generator->alg == 0 )
3867+
if( output_length == 0 && generator->capacity == 0 )
38633868
{
3864-
/* Edge case: this is a blank or finished generator, and 0
3865-
* bytes were requested. The right error in this case could
3869+
/* Edge case: this is a finished generator, and 0 bytes
3870+
* were requested. The right error in this case could
38663871
* be either INSUFFICIENT_CAPACITY or BAD_STATE. Return
38673872
* INSUFFICIENT_CAPACITY, which is right for a finished
38683873
* generator, for consistency with the case when
@@ -3911,7 +3916,13 @@ psa_status_t psa_generator_read( psa_crypto_generator_t *generator,
39113916
exit:
39123917
if( status != PSA_SUCCESS )
39133918
{
3919+
/* Preserve the algorithm upon errors, but clear all sensitive state.
3920+
* This allows us to differentiate between exhausted generators and
3921+
* blank generators, so we can return PSA_ERROR_BAD_STATE on blank
3922+
* generators. */
3923+
psa_algorithm_t alg = generator->alg;
39143924
psa_generator_abort( generator );
3925+
generator->alg = alg;
39153926
memset( output, '!', output_length );
39163927
}
39173928
return( status );

features/mbedtls/mbed-crypto/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL/psa_crypto_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef struct
4141
psa_key_type_t type;
4242
psa_key_policy_t policy;
4343
psa_key_lifetime_t lifetime;
44-
psa_key_id_t persistent_storage_id;
44+
psa_key_file_id_t persistent_storage_id;
4545
unsigned allocated : 1;
4646
union
4747
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Copyright (C) 2019, ARM Limited, All Rights Reserved
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* This file is part of mbed TLS (https://tls.mbed.org)
17+
*/
18+
19+
#ifndef PSA_CRYPTO_SERVICE_INTEGRATION_H
20+
#define PSA_CRYPTO_SERVICE_INTEGRATION_H
21+
22+
/*
23+
* When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is being built for SPM
24+
* (Secure Partition Manager) integration which separates the code into two
25+
* parts: NSPE (Non-Secure Processing Environment) and SPE (Secure Processing
26+
* Environment). When building for the SPE, an additional header file should be
27+
* included.
28+
*/
29+
#if defined(MBEDTLS_PSA_CRYPTO_SPM)
30+
/*
31+
* PSA_CRYPTO_SECURE means that the file which included this file is being
32+
* compiled for SPE. The files crypto_structs.h and crypto_types.h have
33+
* different implementations for NSPE and SPE and are compiled according to this
34+
* flag.
35+
*/
36+
#define PSA_CRYPTO_SECURE 1
37+
#include "crypto_spe.h"
38+
#endif // MBEDTLS_PSA_CRYPTO_SPM
39+
40+
#endif // PSA_CRYPTO_SERVICE_INTEGRATION_H

0 commit comments

Comments
 (0)