return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
}
+static void bn_free_d(BIGNUM *a)
+{
+ if (BN_get_flags(a,BN_FLG_SECURE))
+ OPENSSL_secure_free(a->d);
+ else
+ OPENSSL_free(a->d);
+}
+
+
void BN_clear_free(BIGNUM *a)
{
int i;
bn_check_top(a);
if (a->d != NULL) {
OPENSSL_cleanse(a->d, a->dmax * sizeof(a->d[0]));
- if (!(BN_get_flags(a, BN_FLG_STATIC_DATA))) {
- if (BN_get_flags(a,BN_FLG_SECURE))
- OPENSSL_secure_free(a->d);
- else
- OPENSSL_free(a->d);
- }
+ if (!BN_get_flags(a, BN_FLG_STATIC_DATA))
+ bn_free_d(a);
}
i = BN_get_flags(a, BN_FLG_MALLOCED);
- OPENSSL_cleanse(a, sizeof(BIGNUM));
+ OPENSSL_cleanse(a, sizeof(*a));
if (i)
OPENSSL_free(a);
}
return;
bn_check_top(a);
if (!BN_get_flags(a, BN_FLG_STATIC_DATA))
- if ((a->d != NULL) && !(BN_get_flags(a, BN_FLG_STATIC_DATA))) {
- if (BN_get_flags(a, BN_FLG_SECURE))
- OPENSSL_secure_free(a->d);
- else
- OPENSSL_free(a->d);
- }
+ bn_free_d(a);
if (a->flags & BN_FLG_MALLOCED)
OPENSSL_free(a);
else {
if (!a)
return NULL;
if (b->d) {
- if (BN_get_flags(b,BN_FLG_SECURE))
- OPENSSL_secure_free(b->d);
- else
- OPENSSL_free(b->d);
+ OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));
+ bn_free_d(b);
}
b->d = a;
b->dmax = words;
rp = r->d;
/* clear the top words of T */
- memset(&rp[r->top], 0, sizeof(*rp) * (max - r->top));
+ i = max - r->top;
+ if (i)
+ memset(&rp[r->top], 0, sizeof(*rp) * i);
r->top = max;
n0 = mont->n0[0];