Skip to content

Commit d27a884

Browse files
committed
Merge branch 'development' into development-restricted
2 parents ba9fff2 + a337167 commit d27a884

Some content is hidden

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

85 files changed

+1675
-780
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Mbed Crypto is distributed under the Apache License, version 2.0. See the [LICEN
66

77
## PSA cryptography API
88

9-
Arm's Platform Security Architecture (PSA) is a holistic set of threat models, security analyses, hardware and firmware architecture specifications, and an open source firmware reference implementation. PSA provides a recipe, based on industry best practice, that allows security to be consistently designed in, at both a hardware and firmware level.
9+
Arm's [Platform Security Architecture (PSA)](https://developer.arm.com/architectures/security-architectures/platform-security-architecture) is a holistic set of threat models, security analyses, hardware and firmware architecture specifications, and an open source firmware reference implementation. PSA provides a recipe, based on industry best practice, that allows security to be consistently designed in, at both a hardware and firmware level.
1010

11-
The PSA cryptography API provides access to a set of cryptographic primitives. It has a dual purpose. First, it can be used in a PSA-compliant platform to build services, such as secure boot, secure storage and secure communication. Second, it can also be used independently of other PSA components on any platform.
11+
The [PSA cryptography API](https://armmbed.github.io/mbed-crypto/psa/#application-programming-interface) provides access to a set of cryptographic primitives. It has a dual purpose. First, it can be used in a PSA-compliant platform to build services, such as secure boot, secure storage and secure communication. Second, it can also be used independently of other PSA components on any platform.
1212

1313
The design goals of the PSA cryptography API include:
1414

@@ -24,17 +24,17 @@ Mbed Crypto is a reference implementation of the PSA cryptography API. It is wri
2424

2525
## Documentation
2626

27-
The Mbed Crypto library is a reference implementation of the PSA cryptography API. Please refer to the PSA Cryptography API documents for an overview of the library's interfaces and a detailed description of the types, macros and functions that it provides.
27+
The Mbed Crypto library implements both the legacy Mbed TLS interfaces to cryptographic primitives (`mbedtls_xxx`) and the new PSA Cryptography interfaces (`psa_xxx`).
2828

29-
There are currently a few deviations where the library does not yet implement the latest version of the specification. Please refer to the [compliance issues on Github](https://github.com/ARMmbed/mbed-crypto/labels/compliance) for an up-to-date list.
29+
Documentation for the Mbed TLS interfaces in the default library configuration is available as part of the [Mbed TLS documentation](https://tls.mbed.org/api/).
3030

31-
### PSA Cryptography API
31+
For the PSA interfaces, please refer to the PSA Cryptography API documents linked from the [PSA cryptography interfaces documentation portal](https://armmbed.github.io/mbed-crypto/psa/#application-programming-interface) for an overview of the library's interfaces and a detailed description of the types, macros and functions that it provides. The API reference is available in [PDF](https://armmbed.github.io/mbed-crypto/PSA_Cryptography_API_Specification.pdf) and [HTML](https://armmbed.github.io/mbed-crypto/html/index.html) formats.
3232

33-
You can read the [complete PSA cryptography API specification as a PDF document](https://github.com/ARMmbed/mbed-crypto/raw/psa-crypto-api/docs/PSA_Cryptography_API_Specification.pdf). The API reference is also available in [HTML format](https://armmbed.github.io/mbed-crypto/html/index.html).
33+
There are currently a few deviations where the library does not yet implement the latest version of the specification. Please refer to the [compliance issues on Github](https://github.com/ARMmbed/mbed-crypto/labels/compliance) for an up-to-date list.
3434

3535
### Browsable library documentation
3636

37-
To generate a local copy of the library documentation in HTML format:
37+
To generate a local copy of the library documentation in HTML format, tailored to your compile-time configuration:
3838

3939
1. Make sure that [Doxygen](http://www.doxygen.nl/) is installed. We use version 1.8.11 but slightly older or more recent versions should work.
4040
1. Run `make apidoc`.

docs/getting_started.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ Mbed Crypto supports encrypting, decrypting, signing and verifying messages usin
119119
**Prerequisites to performing asymmetric signature operations:**
120120
* Initialize the library with a successful call to `psa_crypto_init()`.
121121
* Have a valid key with appropriate attributes set:
122-
* Usage flag `PSA_KEY_USAGE_SIGN` to allow signing.
123-
* Usage flag `PSA_KEY_USAGE_VERIFY` to allow signature verification.
122+
* Usage flag `PSA_KEY_USAGE_SIGN_HASH` to allow signing.
123+
* Usage flag `PSA_KEY_USAGE_VERIFY_HASH` to allow signature verification.
124124
* Algorithm set to the desired signature algorithm.
125125
126126
This example shows how to sign a hash that has already been calculated:
@@ -133,7 +133,7 @@ void sign_a_message_using_rsa(const uint8_t *key, size_t key_len)
133133
0x60, 0x41, 0x8a, 0xaf, 0x0c, 0xc5, 0xab, 0x58,
134134
0x7f, 0x42, 0xc2, 0x57, 0x0a, 0x88, 0x40, 0x95,
135135
0xa9, 0xe8, 0xcc, 0xac, 0xd0, 0xf6, 0x54, 0x5c};
136-
uint8_t signature[PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE] = {0};
136+
uint8_t signature[PSA_SIGNATURE_MAX_SIZE] = {0};
137137
size_t signature_length;
138138
psa_key_handle_t handle;
139139
@@ -148,7 +148,7 @@ void sign_a_message_using_rsa(const uint8_t *key, size_t key_len)
148148
}
149149
150150
/* Set key attributes */
151-
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN);
151+
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
152152
psa_set_key_algorithm(&attributes, PSA_ALG_RSA_PKCS1V15_SIGN_RAW);
153153
psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_KEY_PAIR);
154154
psa_set_key_bits(&attributes, 1024);
@@ -161,10 +161,10 @@ void sign_a_message_using_rsa(const uint8_t *key, size_t key_len)
161161
}
162162
163163
/* Sign message using the key */
164-
status = psa_asymmetric_sign(handle, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
165-
hash, sizeof(hash),
166-
signature, sizeof(signature),
167-
&signature_length);
164+
status = psa_sign_hash(handle, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
165+
hash, sizeof(hash),
166+
signature, sizeof(signature),
167+
&signature_length);
168168
if (status != PSA_SUCCESS) {
169169
printf("Failed to sign\n");
170170
return;
@@ -861,7 +861,7 @@ Mbed Crypto provides a simple way to generate a key or key pair.
861861
}
862862

863863
/* Generate a key */
864-
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN);
864+
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH);
865865
psa_set_key_algorithm(&attributes,
866866
PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256));
867867
psa_set_key_type(&attributes,

include/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,

include/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.

include/mbedtls/ctr_drbg.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ typedef struct mbedtls_ctr_drbg_context
177177
* minus one.
178178
* Before the initial seeding, this field
179179
* contains the amount of entropy in bytes
180-
* to use as a nonce for the initial seeding.
180+
* to use as a nonce for the initial seeding,
181+
* or -1 if no nonce length has been explicitly
182+
* set (see mbedtls_ctr_drbg_set_nonce_len()).
181183
*/
182184
int prediction_resistance; /*!< This determines whether prediction
183185
resistance is enabled, that is

include/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

include/mbedtls/pk.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ typedef struct mbedtls_pk_rsassa_pss_options
134134
#endif
135135

136136
#if defined(MBEDTLS_USE_PSA_CRYPTO)
137-
#if PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
138-
/* PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE is the maximum size of a signature made
137+
#if PSA_SIGNATURE_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
138+
/* PSA_SIGNATURE_MAX_SIZE is the maximum size of a signature made
139139
* through the PSA API in the PSA representation. */
140140
#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
141-
#define MBEDTLS_PK_SIGNATURE_MAX_SIZE PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE
141+
#define MBEDTLS_PK_SIGNATURE_MAX_SIZE PSA_SIGNATURE_MAX_SIZE
142142
#endif
143143

144144
#if PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 > MBEDTLS_PK_SIGNATURE_MAX_SIZE

include/mbedtls/psa_util.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -378,24 +378,6 @@ static inline psa_ecc_curve_t mbedtls_psa_translate_ecc_group( mbedtls_ecp_group
378378
}
379379
}
380380

381-
382-
#define MBEDTLS_PSA_ECC_KEY_BITS_OF_CURVE( curve ) \
383-
( curve == PSA_ECC_CURVE_SECP192R1 ? 192 : \
384-
curve == PSA_ECC_CURVE_SECP224R1 ? 224 : \
385-
curve == PSA_ECC_CURVE_SECP256R1 ? 256 : \
386-
curve == PSA_ECC_CURVE_SECP384R1 ? 384 : \
387-
curve == PSA_ECC_CURVE_SECP521R1 ? 521 : \
388-
curve == PSA_ECC_CURVE_SECP192K1 ? 192 : \
389-
curve == PSA_ECC_CURVE_SECP224K1 ? 224 : \
390-
curve == PSA_ECC_CURVE_SECP256K1 ? 256 : \
391-
curve == PSA_ECC_CURVE_BRAINPOOL_P256R1 ? 256 : \
392-
curve == PSA_ECC_CURVE_BRAINPOOL_P384R1 ? 384 : \
393-
curve == PSA_ECC_CURVE_BRAINPOOL_P512R1 ? 512 : \
394-
0 )
395-
396-
#define MBEDTLS_PSA_ECC_KEY_BYTES_OF_CURVE( curve ) \
397-
( ( MBEDTLS_PSA_ECC_KEY_BITS_OF_CURVE( curve ) + 7 ) / 8 )
398-
399381
/* Translations for PK layer */
400382

401383
static inline int mbedtls_psa_err_translate_pk( psa_status_t status )

include/psa/crypto.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,7 +2879,7 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation);
28792879
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
28802880
* The size of the \p signature buffer is too small. You can
28812881
* determine a sufficient buffer size by calling
2882-
* #PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
2882+
* #PSA_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
28832883
* where \c key_type and \c key_bits are the type and bit-size
28842884
* respectively of \p handle.
28852885
* \retval #PSA_ERROR_NOT_SUPPORTED
@@ -2895,13 +2895,13 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation);
28952895
* It is implementation-dependent whether a failure to initialize
28962896
* results in this error code.
28972897
*/
2898-
psa_status_t psa_asymmetric_sign(psa_key_handle_t handle,
2899-
psa_algorithm_t alg,
2900-
const uint8_t *hash,
2901-
size_t hash_length,
2902-
uint8_t *signature,
2903-
size_t signature_size,
2904-
size_t *signature_length);
2898+
psa_status_t psa_sign_hash(psa_key_handle_t handle,
2899+
psa_algorithm_t alg,
2900+
const uint8_t *hash,
2901+
size_t hash_length,
2902+
uint8_t *signature,
2903+
size_t signature_size,
2904+
size_t *signature_length);
29052905

29062906
/**
29072907
* \brief Verify the signature a hash or short message using a public key.
@@ -2941,12 +2941,12 @@ psa_status_t psa_asymmetric_sign(psa_key_handle_t handle,
29412941
* It is implementation-dependent whether a failure to initialize
29422942
* results in this error code.
29432943
*/
2944-
psa_status_t psa_asymmetric_verify(psa_key_handle_t handle,
2945-
psa_algorithm_t alg,
2946-
const uint8_t *hash,
2947-
size_t hash_length,
2948-
const uint8_t *signature,
2949-
size_t signature_length);
2944+
psa_status_t psa_verify_hash(psa_key_handle_t handle,
2945+
psa_algorithm_t alg,
2946+
const uint8_t *hash,
2947+
size_t hash_length,
2948+
const uint8_t *signature,
2949+
size_t signature_length);
29502950

29512951
/**
29522952
* \brief Encrypt a short message with a public key.

0 commit comments

Comments
 (0)