Skip to content

Commit

Permalink
add HW error codes to tfm.h, sp_int.h, integer.h
Browse files Browse the repository at this point in the history
  • Loading branch information
gojimmypi committed Jul 1, 2023
1 parent a4c0586 commit f167fcf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
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)
/* hardware busy; wait or fall back to SW */
#define MP_HW_BUSY (-7)
/* signal to caller to fall back to SW (e.g unsupported, etc) */
#define MP_HW_FALLBACK (-8)
/* 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

0 comments on commit f167fcf

Please sign in to comment.