Improve handling of mp_init / mp_clear for DH and DSA after speed-up.

This commit is contained in:
David Garske
2017-01-31 16:42:06 -08:00
parent da5825b94d
commit bced81d234
2 changed files with 31 additions and 25 deletions

View File

@ -51,20 +51,21 @@
void wc_InitDhKey(DhKey* key)
{
(void)key;
/* TomsFastMath doesn't use memory allocation */
#ifndef USE_FAST_MATH
key->p.dp = NULL;
key->g.dp = NULL;
#endif
if (key) {
mp_init(&key->p);
mp_init(&key->g);
}
}
void wc_FreeDhKey(DhKey* key)
{
(void)key;
if (key) {
#ifndef USE_FAST_MATH
mp_clear(&key->p);
mp_clear(&key->g);
#endif
}
}

View File

@ -52,18 +52,20 @@ enum {
void wc_InitDsaKey(DsaKey* key)
{
if (key == NULL)
return;
key->type = -1; /* haven't decided yet */
key->heap = NULL;
/* TomsFastMath doesn't use memory allocation */
#ifndef USE_FAST_MATH
key->p.dp = 0; /* public alloc parts */
key->q.dp = 0;
key->g.dp = 0;
key->y.dp = 0;
/* public alloc parts */
mp_init(&key->p);
mp_init(&key->q);
mp_init(&key->g);
mp_init(&key->y);
key->x.dp = 0; /* private alloc parts */
#endif
/* private alloc parts */
mp_init(&key->x);
}
@ -78,10 +80,13 @@ int wc_InitDsaKey_h(DsaKey* key, void* h)
void wc_FreeDsaKey(DsaKey* key)
{
(void)key;
/* TomsFastMath doesn't use memory allocation */
#ifndef USE_FAST_MATH
if (key == NULL)
return;
if (key->type == DSA_PRIVATE)
mp_forcezero(&key->x);
#ifndef USE_FAST_MATH
mp_clear(&key->x);
mp_clear(&key->y);
mp_clear(&key->g);