From 0ff4e0b8242e05d32be20145c4b4baa94864bb19 Mon Sep 17 00:00:00 2001 From: Ron Eldor Date: Wed, 29 Aug 2018 18:53:20 +0300 Subject: [PATCH] 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 6b82d4fbbe..95415dc722 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 a40a64f9c6..a1cd689f39 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 774244b454..f34a6effa2 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 ac171ed4a2..0c1f7e16ec 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