summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2014-05-05 18:38:42 +0000
committertedu <tedu@openbsd.org>2014-05-05 18:38:42 +0000
commite7e0ff11ef54730650821e620f023d443925dbea (patch)
tree7c975dd8046322cb8faca51893182498a31f2756
parentDon't call the BOOTP handler indirectly. (diff)
downloadwireguard-openbsd-e7e0ff11ef54730650821e620f023d443925dbea.tar.xz
wireguard-openbsd-e7e0ff11ef54730650821e620f023d443925dbea.zip
inspired by a cloudflare diff, cleanse old memory when expanding a bignum.
however, instead of trying to audit all the places where a secret bignum is used, apply the big hammer and clear all bignums when freed. ok deraadt miod
-rw-r--r--lib/libcrypto/bn/bn_lib.c26
-rw-r--r--lib/libssl/src/crypto/bn/bn_lib.c26
2 files changed, 18 insertions, 34 deletions
diff --git a/lib/libcrypto/bn/bn_lib.c b/lib/libcrypto/bn/bn_lib.c
index 9787a31dbbf..a8022f66680 100644
--- a/lib/libcrypto/bn/bn_lib.c
+++ b/lib/libcrypto/bn/bn_lib.c
@@ -226,22 +226,11 @@ void BN_clear_free(BIGNUM *a)
free(a);
}
-void BN_free(BIGNUM *a)
- {
- if (a == NULL) return;
- bn_check_top(a);
- if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA)))
- free(a->d);
- if (a->flags & BN_FLG_MALLOCED)
- free(a);
- else
- {
-#ifndef OPENSSL_NO_DEPRECATED
- a->flags|=BN_FLG_FREE;
-#endif
- a->d = NULL;
- }
- }
+void
+BN_free(BIGNUM *a)
+{
+ BN_clear_free(a);
+}
void BN_init(BIGNUM *a)
{
@@ -400,7 +389,10 @@ BIGNUM *bn_expand2(BIGNUM *b, int words)
{
BN_ULONG *a = bn_expand_internal(b, words);
if(!a) return NULL;
- if(b->d) free(b->d);
+ if(b->d) {
+ OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));
+ free(b->d);
+ }
b->d=a;
b->dmax=words;
}
diff --git a/lib/libssl/src/crypto/bn/bn_lib.c b/lib/libssl/src/crypto/bn/bn_lib.c
index 9787a31dbbf..a8022f66680 100644
--- a/lib/libssl/src/crypto/bn/bn_lib.c
+++ b/lib/libssl/src/crypto/bn/bn_lib.c
@@ -226,22 +226,11 @@ void BN_clear_free(BIGNUM *a)
free(a);
}
-void BN_free(BIGNUM *a)
- {
- if (a == NULL) return;
- bn_check_top(a);
- if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA)))
- free(a->d);
- if (a->flags & BN_FLG_MALLOCED)
- free(a);
- else
- {
-#ifndef OPENSSL_NO_DEPRECATED
- a->flags|=BN_FLG_FREE;
-#endif
- a->d = NULL;
- }
- }
+void
+BN_free(BIGNUM *a)
+{
+ BN_clear_free(a);
+}
void BN_init(BIGNUM *a)
{
@@ -400,7 +389,10 @@ BIGNUM *bn_expand2(BIGNUM *b, int words)
{
BN_ULONG *a = bn_expand_internal(b, words);
if(!a) return NULL;
- if(b->d) free(b->d);
+ if(b->d) {
+ OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));
+ free(b->d);
+ }
b->d=a;
b->dmax=words;
}