Skip to content
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

add HW error codes to tfm.h, sp_int.h, integer.h #6565

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 11 additions & 5 deletions wolfssl/wolfcrypt/integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,17 @@ extern "C" {
#define MP_ZPOS 0 /* positive integer */
#define MP_NEG 1 /* negative */

#define MP_OKAY 0 /* ok result */
#define MP_MEM (-2) /* out of mem */
#define MP_VAL (-3) /* invalid input */
#define MP_NOT_INF (-4) /* point not at infinity */
#define MP_RANGE MP_NOT_INF
#define MP_OKAY 0 /* ok result */
#define MP_ERROR (-1) /* generic math error */
#define MP_MEM (-2) /* out of mem */
#define MP_VAL (-3) /* invalid input */
#define MP_NOT_INF (-4) /* point not at infinity */
#define MP_NOT_USED (-5) /* not used, here for consistency only */
#define MP_HW_ERROR (-6) /* hardware error, consider SW fallback */
#define MP_HW_BUSY (-7) /* assigned -7 to match SP_HW_BUSY */
#define MP_HW_FALLBACK (-8) /* signal to caller to fall back to SW */
#define MP_HW_VALIDATION_ACTIVE (-9) /* optional HW validation ative */
#define MP_RANGE MP_HW_VALIDATION_ACTIVE /* range is last item */

#define MP_YES 1 /* yes response */
#define MP_NO 0 /* no response */
Expand Down
17 changes: 15 additions & 2 deletions wolfssl/wolfcrypt/sp_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,8 @@ typedef struct sp_ecc_ctx {
/* ERROR VALUES */
/** Error value on success. */
#define MP_OKAY 0
/* unexpected, generic error. xP_VAL elsewhere */
#define MP_ERROR (-1)
/** Error value when dynamic memory allocation fails. */
#define MP_MEM (-2)
/** Error value when value passed is not able to be used. */
Expand All @@ -739,10 +741,21 @@ typedef struct sp_ecc_ctx {
* completion.
*/
#define FP_WOULDBLOCK (-4)
#define MP_WOULDBLOCK (-4)
/* Unused error. Defined for backward compatibility. */
#define MP_NOT_INF (-5)
/* Unused error. Defined for backward compatibility. */
#define MP_RANGE MP_NOT_INF
/* hardware error, consider falling back to SW */
#define MP_HW_ERROR (-6)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets use the existing WC_HW_E

Copy link
Contributor

Choose a reason for hiding this comment

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

Debug logs with WOLFSSL_MSG could be used to narrow down location of hardware error and distinguish between math hardware acceleration and others if wanted.

/* hardware busy; wait or fall back to SW */
#define MP_HW_BUSY (-7)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets use the existing WC_HW_WAIT_E

/* signal to caller to fall back to SW (e.g unsupported, etc) */
#define MP_HW_FALLBACK (-8)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can NOT_COMPILED_IN or BAD_STATE_E be used instead?

/* typically used only during debugging, validation active
* will prevent recursive calls to HW for SW validation check.*/
#define MP_HW_VALIDATION_ACTIVE (-9)
#define MP_RANGE MP_HW_VALIDATION_ACTIVE /* last item is range */

#define MP_SIZE SP_INT_DIGITS

#ifdef USE_FAST_MATH
/* For old FIPS, need FP_MEM defined for old implementation. */
Expand Down
25 changes: 20 additions & 5 deletions wolfssl/wolfcrypt/tfm.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@
#define FP_MASK (fp_digit)(-1)
#define FP_DIGIT_MAX FP_MASK
#define FP_SIZE (FP_MAX_SIZE/DIGIT_BIT)
#define MP_SIZE (FP_MAX_SIZE/DIGIT_BIT) /* for compatibility with SP_INT */


#define FP_MAX_PRIME_SIZE (FP_MAX_BITS/(2*CHAR_BIT))
/* In terms of FP_MAX_BITS, it is double the size possible for a number
Expand All @@ -302,11 +304,18 @@
#define FP_NEG 1

/* return codes */
#define FP_OKAY 0
#define FP_VAL (-1)
#define FP_MEM (-2)
#define FP_NOT_INF (-3)
#define FP_WOULDBLOCK (-4)
#define FP_OKAY ( 0)
#define FP_VAL (-1)
#define FP_MEM (-2)
#define FP_NOT_INF (-3)
#define FP_WOULDBLOCK (-4)
#define FP_NOT_USED (-5) /* not used, here for consistency only */
#define FP_HW_ERROR (-6) /* hardware error, consider SW fallback */
#define FP_HW_BUSY (-7) /* assigned -7 to match SP_HW_BUSY */
#define FP_HW_FALLBACK (-8) /* signal to caller to fall back to SW */
#define FP_HW_VALIDATION_ACTIVE (-9) /* optional HW validation ative */

#define FP_RANGE MP_HW_VALIDATION_ACTIVE /* range is last item */

/* equalities */
#define FP_LT (-1) /* less than */
Expand Down Expand Up @@ -778,6 +787,12 @@ int fp_sqr_comba64(fp_int *a, fp_int *b);
#define MP_MEM FP_MEM /* memory error */
#define MP_NOT_INF FP_NOT_INF /* point not at infinity */
#define MP_OKAY FP_OKAY /* ok result */
#define MP_HW_ERROR FP_HW_ERROR /* HW accleration error */
#define MP_HW_BUSY FP_HW_BUSY /* hardware is busy, need to fall back to SW */
#define MP_HW_FALLBACK FP_HW_FALLBACK /* detected data that needs SW */
#define MP_HW_VALIDATION_ACTIVE FP_HW_VALIDATION_ACTIVE /* typically debug */
#define MP_RANGE FP_RANGE /* range is last item */

#define MP_NO FP_NO /* yes/no result */
#define MP_YES FP_YES /* yes/no result */
#define MP_ZPOS FP_ZPOS
Expand Down