comparison libtommath/bn_mp_clear.c @ 1281:eebff2079bdc

use m_burn for mp_clear
author Matt Johnston <matt@ucc.asn.au>
date Thu, 17 Mar 2016 00:06:26 +0800
parents 5ff8218bcee9
children 3017bc7d6238
comparison
equal deleted inserted replaced
1280:94d4038bb34c 1281:eebff2079bdc
1 #include <tommath.h> 1 #include <tommath.h>
2 #include "dbutil.h"
2 #ifdef BN_MP_CLEAR_C 3 #ifdef BN_MP_CLEAR_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4 * 5 *
5 * LibTomMath is a library that provides multiple-precision 6 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality. 7 * integer arithmetic as well as number theoretic functionality.
17 18
18 /* clear one (frees) */ 19 /* clear one (frees) */
19 void 20 void
20 mp_clear (mp_int * a) 21 mp_clear (mp_int * a)
21 { 22 {
22 volatile mp_digit *p;
23 int len;
24
25 /* only do anything if a hasn't been freed previously */ 23 /* only do anything if a hasn't been freed previously */
26 if (a->dp != NULL) { 24 if (a->dp != NULL) {
27 /* first zero the digits */ 25 /* first zero the digits */
28 len = a->alloc; 26 m_burn(a->dp, a->alloc * sizeof(*a->dp));
29 p = a->dp;
30 while (len--) {
31 *p++ = 0;
32 }
33 27
34 /* free ram */ 28 /* free ram */
35 XFREE(a->dp); 29 XFREE(a->dp);
36 30
37 /* reset members to make debugging easier */ 31 /* reset members to make debugging easier */