Skip to content

Error codes for hardware accelerator failures #1303

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 2 commits into from
Jan 29, 2018

Conversation

gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Jan 24, 2018

Add MBEDTLS_ERR_XXX_HW_ACCEL_FAILED error codes for all cryptography
modules where the software implementation can be replaced by a hardware
implementation.

This does not include the individual message digest modules since they
currently have no way to return error codes. That part is done in #1294

This does include the higher-level md, cipher and pk modules since
alternative implementations and even algorithms can be plugged in at
runtime.

[added by mpg]: no backports required, hardware acceleration is a new feature

Internal reference: IOTSSL-2039

@gilles-peskine-arm gilles-peskine-arm added enhancement mbed TLS team needs-review Every commit must be reviewed by at least two team members, labels Jan 24, 2018
@RonEld
Copy link
Contributor

RonEld commented Jan 24, 2018

While we are working on this, I would also think adding MBEDTLS_ERR_XXX_FEATURE_UNAVAILABLE, for features the HW acceleration doesn't support, such as key size, unsupported curves, etc..
We have suce an error for AES

@gilles-peskine-arm gilles-peskine-arm mentioned this pull request Jan 24, 2018
4 tasks
@gilles-peskine-arm
Copy link
Contributor Author

@RonEld Shouldn't this be a job for the higher-level modules (cipher, md, pk)?

@RonEld
Copy link
Contributor

RonEld commented Jan 24, 2018

@gilles-peskine-arm I don't think so. IMHO, I am talking about errors that should be returned by the alternative implementations, in case they don't support a specific feature. But, this could wait.

@Patater Patater requested a review from AndrzejKurek January 25, 2018 11:00
@@ -75,11 +78,11 @@
* X509 2 20
* PKCS5 2 4 (Started from top)
* DHM 3 9
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't adding MBEDTLS_ERR_DHM_HW_ACCEL_FAILED increase the DHM error count by 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Thanks, fixed.

Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

Blocker: status of ECJPAKE (either change it or convince me that it's indeed the least bad option).

Minor: redundant counter to update.

"SHA1", "SHA256", "SHA512", "GCM", "THREADING", "CCM" );
my @high_level_modules = ( "PEM", "X509", "DHM", "RSA", "ECP", "MD", "CIPHER", "SSL",
"PK", "PKCS12", "PKCS5" );
my @low_level_modules = qw( AES ARC4 ASN1 BASE64 BIGNUM BLOWFISH
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for cleaning up this list! However I'd have preferred a separate commit for the cleanup rather than mixing cleanup and adding new modules to that list. (As far as I'm concerned, don't bother rewriting history for that, just saying for the future.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I rushed this through. Since the PR needs updating anyway and it doesn't have a complicated history, I can rewrite the history while I'm at it, if it's ok with you.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, feel free to clean up the history!

* XTEA 1 0x0028-0x0028
* AES 4 0x0020-0x0022 0x0023-0x0025
* CAMELLIA 3 0x0024-0x0026 0x0027-0x0027
* XTEA 1 0x0028-0x0028 0x0029-0x0029
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the Nr column from 1 to 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -44,6 +44,8 @@
#include "ecp.h"
#include "md.h"

#define MBEDTLS_ERR_ECJPAKE_HW_ACCEL_FAILED -0x0078 /**< ECJPAKE 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.

Treating ECJPAKE as a low-level module it inconsistent with the fact that it's built on top of ECP which is considered a high-level module (due to the fact that it build on top of MPI I guess).

Now I realise that in practice that distinction mostly matters because so that we can do this in high-level modules:

ret = some_low_level_function();
if( ret != 0 )
    ret += my_high_level_code;

and in practice I don't see than happening here, but it still bothers me to have a low-level module based on a "high-level" one.

Now I also realise we don't have enough spots left for high-level module any more, and so far we've cheated by deciding that modules based on ECP use error codes in the ECP namespace (which is why we have such things as MBEDTLS_ERR_ECP_VERIFY_FAILED rather than having it in ECDSA. So far most errors returned by ECJPAKE functions live in the ECP namespace too.

So I understand there may not be any good solution here in our current system, but I'm not really happy with adding low-level error codes fro ECJPAKE.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: what I'm suggesting is that alternative implementation of ECJPAKE use the ECP error code, just like alt ECDH implementations do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh. That's a good point. Indeed, it's annoying. @hanno-arm ECJPAKE_HW_ACCEL_FAILED is to complement #1304 . What do you think of Manuel's proposal to use ECP_HW_ACCEL_FAILED?

Choose a reason for hiding this comment

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

@gilles-peskine-arm @mpg I support Manuel's proposal of using ECP_HW_ACCEL_FAILED. I think that while perhaps not optimal, having modules based on ECP use error codes from the ECP namespace -- thereby effectively collapsing the namespaces from there because our allocation of error codes doesn't allow to step 'one level up' -- is still cleaner than using low-level codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sbutcher-arm verbally approved using ECP_HW_ACCEL_FAILED for ECJPAKE, so I'll withdraw the ECJPAKE_HW_ACCEL_FAILED error code.

@gilles-peskine-arm
Copy link
Contributor Author

gilles-peskine-arm commented Jan 25, 2018

@mpg @hanno-arm @AndrzejKurek @RonEld I rewrote the history to split out the list sorting in generate_errors.pl, remove the error.h count fixups, and remove the addition of an ECJPAKE error code. The old history is at https://github.com/gilles-peskine-arm/mbedtls/tree/err_hw_failed-1

@AndrzejKurek
Copy link
Contributor

Looks fine to me.

#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available, e.g. unsupported AES key size. */
#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed */
Copy link

@hanno-becker hanno-becker Jan 26, 2018

Choose a reason for hiding this comment

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

Dot missing at the end, here and in the rest of the PR.

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 amended and force-pushed a version with dots at the end. The previous commit is at https://github.com/gilles-peskine-arm/mbedtls/tree/err_hw_failed-2

Copy link

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

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

With the recent changes to the documentation, all Doxygen comments should end with a dot, which is not the case for the documentation this PR adds. Apart from that, the changes look good to me.

Add MBEDTLS_ERR_XXX_HW_ACCEL_FAILED error codes for all cryptography
modules where the software implementation can be replaced by a hardware
implementation.

This does not include the individual message digest modules since they
currently have no way to return error codes.

This does include the higher-level md, cipher and pk modules since
alternative implementations and even algorithms can be plugged in at
runtime.
@mpg mpg added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Jan 29, 2018
@Patater Patater merged commit 7ecab3d into Mbed-TLS:development Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants