From 0ff4e0b8242e05d32be20145c4b4baa94864bb19 Mon Sep 17 00:00:00 2001 From: Ron Eldor Date: Wed, 29 Aug 2018 18:53:20 +0300 Subject: [PATCH 1/5] Add platform error codes Add error codes for the platform module, to be used by the setup \ terminate API. --- include/mbedtls/error.h | 1 + include/mbedtls/platform.h | 3 +++ library/error.c | 11 +++++++++++ scripts/generate_errors.pl | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index 6b82d4fbb..95415dc72 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -80,6 +80,7 @@ * CHACHA20 3 0x0051-0x0055 * POLY1305 3 0x0057-0x005B * CHACHAPOLY 2 0x0054-0x0056 + * PLATFORM 2 0x0080-0x0082 * * High-level module nr (3 bits - 0x0...-0x7...) * Name ID Nr of Errors diff --git a/include/mbedtls/platform.h b/include/mbedtls/platform.h index a40a64f9c..a1cd689f3 100644 --- a/include/mbedtls/platform.h +++ b/include/mbedtls/platform.h @@ -43,6 +43,9 @@ #include "platform_time.h" #endif +#define MBEDTLS_ERR_PLATFORM_INVALID_DATA -0x0080 /**< Bad input parameters to the platform function. */ +#define MBEDTLS_ERR_PLATFORM_HW_FAILED -0x0082 /**< Hardware platform function failed. */ + #ifdef __cplusplus extern "C" { #endif diff --git a/library/error.c b/library/error.c index 774244b45..f34a6effa 100644 --- a/library/error.c +++ b/library/error.c @@ -165,6 +165,10 @@ #include "mbedtls/pkcs5.h" #endif +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#endif + #if defined(MBEDTLS_POLY1305_C) #include "mbedtls/poly1305.h" #endif @@ -821,6 +825,13 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" ); #endif /* MBEDTLS_PADLOCK_C */ +#if defined(MBEDTLS_PLATFORM_C) + if( use_ret == -(MBEDTLS_ERR_PLATFORM_INVALID_DATA) ) + mbedtls_snprintf( buf, buflen, "PLATFORM - Bad input parameters to the platform function" ); + if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_FAILED) ) + mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware platform function failed" ); +#endif /* MBEDTLS_PLATFORM_C */ + #if defined(MBEDTLS_POLY1305_C) if( use_ret == -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA) ) mbedtls_snprintf( buf, buflen, "POLY1305 - Invalid input parameter(s)" ); diff --git a/scripts/generate_errors.pl b/scripts/generate_errors.pl index ac171ed4a..0c1f7e16e 100755 --- a/scripts/generate_errors.pl +++ b/scripts/generate_errors.pl @@ -32,7 +32,7 @@ my $error_format_file = $data_dir.'/error.fmt'; my @low_level_modules = qw( AES ARC4 ARIA ASN1 BASE64 BIGNUM BLOWFISH CAMELLIA CCM CHACHA20 CHACHAPOLY CMAC CTR_DRBG DES ENTROPY GCM HKDF HMAC_DRBG MD2 MD4 MD5 - NET OID PADLOCK PBKDF2 POLY1305 RIPEMD160 + NET OID PADLOCK PBKDF2 PLATFORM POLY1305 RIPEMD160 SHA1 SHA256 SHA512 THREADING XTEA ); my @high_level_modules = qw( CIPHER DHM ECP MD PEM PK PKCS12 PKCS5 From b0ad58152671312854a7a80e3c52a80162382b32 Mon Sep 17 00:00:00 2001 From: Ron Eldor Date: Wed, 29 Aug 2018 19:06:14 +0300 Subject: [PATCH 2/5] Remove the invalid input for platform module Remove the invalid input for the platform module, as it's not currently used in the Mbed OS platform setup \ termination code. --- include/mbedtls/error.h | 2 +- include/mbedtls/platform.h | 3 +-- library/error.c | 2 -- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index 95415dc72..2b83c2d9b 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -80,7 +80,7 @@ * CHACHA20 3 0x0051-0x0055 * POLY1305 3 0x0057-0x005B * CHACHAPOLY 2 0x0054-0x0056 - * PLATFORM 2 0x0080-0x0082 + * PLATFORM 1 0x0080-0x0080 * * High-level module nr (3 bits - 0x0...-0x7...) * Name ID Nr of Errors diff --git a/include/mbedtls/platform.h b/include/mbedtls/platform.h index a1cd689f3..cb21d2ac0 100644 --- a/include/mbedtls/platform.h +++ b/include/mbedtls/platform.h @@ -43,8 +43,7 @@ #include "platform_time.h" #endif -#define MBEDTLS_ERR_PLATFORM_INVALID_DATA -0x0080 /**< Bad input parameters to the platform function. */ -#define MBEDTLS_ERR_PLATFORM_HW_FAILED -0x0082 /**< Hardware platform function failed. */ +#define MBEDTLS_ERR_PLATFORM_HW_FAILED -0x0080 /**< Hardware platform function failed. */ #ifdef __cplusplus extern "C" { diff --git a/library/error.c b/library/error.c index f34a6effa..d3b155b62 100644 --- a/library/error.c +++ b/library/error.c @@ -826,8 +826,6 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #endif /* MBEDTLS_PADLOCK_C */ #if defined(MBEDTLS_PLATFORM_C) - if( use_ret == -(MBEDTLS_ERR_PLATFORM_INVALID_DATA) ) - mbedtls_snprintf( buf, buflen, "PLATFORM - Bad input parameters to the platform function" ); if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_FAILED) ) mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware platform function failed" ); #endif /* MBEDTLS_PLATFORM_C */ From 54a7c620bbd7222950594b27f70814e10f877af4 Mon Sep 17 00:00:00 2001 From: Ron Eldor Date: Wed, 12 Sep 2018 14:43:44 +0300 Subject: [PATCH 3/5] Minor style changes 1. Rephrase error description. 2. fix alignment of error list. --- include/mbedtls/error.h | 2 +- include/mbedtls/platform.h | 2 +- library/error.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index 2b83c2d9b..c9a825035 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -80,7 +80,7 @@ * CHACHA20 3 0x0051-0x0055 * POLY1305 3 0x0057-0x005B * CHACHAPOLY 2 0x0054-0x0056 - * PLATFORM 1 0x0080-0x0080 + * PLATFORM 1 0x0080-0x0080 * * High-level module nr (3 bits - 0x0...-0x7...) * Name ID Nr of Errors diff --git a/include/mbedtls/platform.h b/include/mbedtls/platform.h index cb21d2ac0..5f5b982a4 100644 --- a/include/mbedtls/platform.h +++ b/include/mbedtls/platform.h @@ -43,7 +43,7 @@ #include "platform_time.h" #endif -#define MBEDTLS_ERR_PLATFORM_HW_FAILED -0x0080 /**< Hardware platform function failed. */ +#define MBEDTLS_ERR_PLATFORM_HW_FAILED -0x0080 /**< Hardware failed platform operation. */ #ifdef __cplusplus extern "C" { diff --git a/library/error.c b/library/error.c index d3b155b62..c6292171b 100644 --- a/library/error.c +++ b/library/error.c @@ -827,7 +827,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #if defined(MBEDTLS_PLATFORM_C) if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_FAILED) ) - mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware platform function failed" ); + mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware failed platform operation" ); #endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_POLY1305_C) From a27190b774e7e89860c2e3b1874ea316629e189b Mon Sep 17 00:00:00 2001 From: Ron Eldor Date: Mon, 15 Oct 2018 16:33:43 +0300 Subject: [PATCH 4/5] Rename platform error code and value Rename the PLATFORM HW error, to avoid ABI breakage with Mbed OS. The value changed as well, as previous value was not in the range of Mbed TLS low level error codes. --- include/mbedtls/platform.h | 2 +- library/error.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mbedtls/platform.h b/include/mbedtls/platform.h index 5f5b982a4..e30edc2e0 100644 --- a/include/mbedtls/platform.h +++ b/include/mbedtls/platform.h @@ -43,7 +43,7 @@ #include "platform_time.h" #endif -#define MBEDTLS_ERR_PLATFORM_HW_FAILED -0x0080 /**< Hardware failed platform operation. */ +#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware failed platform operation. */ #ifdef __cplusplus extern "C" { diff --git a/library/error.c b/library/error.c index c6292171b..0a1c79462 100644 --- a/library/error.c +++ b/library/error.c @@ -826,7 +826,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #endif /* MBEDTLS_PADLOCK_C */ #if defined(MBEDTLS_PLATFORM_C) - if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_FAILED) ) + if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED) ) mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware failed platform operation" ); #endif /* MBEDTLS_PLATFORM_C */ From 5267b62248c53f0f1c6d99efe081c6fa12f15eda Mon Sep 17 00:00:00 2001 From: Ron Eldor Date: Mon, 15 Oct 2018 18:44:42 +0300 Subject: [PATCH 5/5] Change error description 1. Change error description to a clearer one. 2. Change value in the error codes ranges description. --- include/mbedtls/error.h | 2 +- include/mbedtls/platform.h | 2 +- library/error.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index c9a825035..6c69a9b4a 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -80,7 +80,7 @@ * CHACHA20 3 0x0051-0x0055 * POLY1305 3 0x0057-0x005B * CHACHAPOLY 2 0x0054-0x0056 - * PLATFORM 1 0x0080-0x0080 + * PLATFORM 1 0x0070-0x0070 * * High-level module nr (3 bits - 0x0...-0x7...) * Name ID Nr of Errors diff --git a/include/mbedtls/platform.h b/include/mbedtls/platform.h index e30edc2e0..5cd143ce5 100644 --- a/include/mbedtls/platform.h +++ b/include/mbedtls/platform.h @@ -43,7 +43,7 @@ #include "platform_time.h" #endif -#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware failed platform operation. */ +#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware accelerator failed */ #ifdef __cplusplus extern "C" { diff --git a/library/error.c b/library/error.c index 0a1c79462..12902e305 100644 --- a/library/error.c +++ b/library/error.c @@ -827,7 +827,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #if defined(MBEDTLS_PLATFORM_C) if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED) ) - mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware failed platform operation" ); + mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware accelerator failed" ); #endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_POLY1305_C)