refactor ForceZero of memory to gain performance

This commit is contained in:
Jacob Barthelmeh
2016-02-04 10:31:05 -07:00
parent f84c0742ad
commit 42219a327a
2 changed files with 11 additions and 2 deletions

View File

@ -2033,6 +2033,13 @@ void fp_init(fp_int *a)
}
void fp_zero(fp_int *a)
{
a->used = 0;
a->sign = FP_ZPOS;
XMEMSET(a->dp, 0, a->size * sizeof(fp_digit));
}
void fp_clear(fp_int *a)
{
a->used = 0;
a->sign = FP_ZPOS;
@ -2044,7 +2051,7 @@ void fp_zero(fp_int *a)
/* clear one (frees) */
void mp_clear (mp_int * a)
{
fp_zero(a);
fp_clear(a);
}
/* handle up to 6 inits */

View File

@ -368,9 +368,11 @@ typedef struct {
#ifdef ALT_ECC_SIZE
void fp_init(fp_int *a);
void fp_zero(fp_int *a);
void fp_clear(fp_int *a); /* uses ForceZero to clear sensitive memory */
#else
#define fp_init(a) (void)XMEMSET((a), 0, sizeof(fp_int))
#define fp_zero(a) ForceZero((a), sizeof(fp_int))
#define fp_zero(a) fp_init(a)
#define fp_clear(a) ForceZero((a), sizeof(fp_int));
#endif
/* zero/even/odd ? */