Skip to content

Add platform error codes #1993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/mbedtls/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* CHACHA20 3 0x0051-0x0055
* POLY1305 3 0x0057-0x005B
* CHACHAPOLY 2 0x0054-0x0056
* PLATFORM 1 0x0070-0x0070
*
* High-level module nr (3 bits - 0x0...-0x7...)
* Name ID Nr of Errors
Expand Down
2 changes: 2 additions & 0 deletions include/mbedtls/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "platform_time.h"
#endif

#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware accelerator failed */

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the only error code we want to add?

How about "already in use/busy"? Or "Invalid operation"? I'd suggest out of memory, but I think we already have plans for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know what are the plans to handle the wide range of error codes that underlying platform/hardware might come across, but my guess is that each platform is most likely to end up returning their specific error codes. So I think its probably OK to just have this very generic error macro and add more as needed or see how we can integrate the platform errors with ours in some other way...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did have an "invalid operation" error code, but since I wasn't using it at the end, I didn't see a point of adding it.
We could think of many error codes to add, as the hw can fal on numerous reasons. I think that if we find ourselves in a need for other error codes, we could add. We already are low in available error values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's add the error codes when we have a need for them (not in this PR).

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
9 changes: 9 additions & 0 deletions library/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -821,6 +825,11 @@ 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_HW_ACCEL_FAILED) )
mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware accelerator 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)" );
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_errors.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
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
Expand Down