forked from wolfSSL/wolfssl
refactor ForceZero of memory to gain performance
This commit is contained in:
@ -2033,6 +2033,13 @@ void fp_init(fp_int *a)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fp_zero(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->used = 0;
|
||||||
a->sign = FP_ZPOS;
|
a->sign = FP_ZPOS;
|
||||||
@ -2044,7 +2051,7 @@ void fp_zero(fp_int *a)
|
|||||||
/* clear one (frees) */
|
/* clear one (frees) */
|
||||||
void mp_clear (mp_int * a)
|
void mp_clear (mp_int * a)
|
||||||
{
|
{
|
||||||
fp_zero(a);
|
fp_clear(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* handle up to 6 inits */
|
/* handle up to 6 inits */
|
||||||
|
@ -368,9 +368,11 @@ typedef struct {
|
|||||||
#ifdef ALT_ECC_SIZE
|
#ifdef ALT_ECC_SIZE
|
||||||
void fp_init(fp_int *a);
|
void fp_init(fp_int *a);
|
||||||
void fp_zero(fp_int *a);
|
void fp_zero(fp_int *a);
|
||||||
|
void fp_clear(fp_int *a); /* uses ForceZero to clear sensitive memory */
|
||||||
#else
|
#else
|
||||||
#define fp_init(a) (void)XMEMSET((a), 0, sizeof(fp_int))
|
#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
|
#endif
|
||||||
|
|
||||||
/* zero/even/odd ? */
|
/* zero/even/odd ? */
|
||||||
|
Reference in New Issue
Block a user