diff options
| author | tedu <> | 2014-05-05 18:38:42 +0000 | 
|---|---|---|
| committer | tedu <> | 2014-05-05 18:38:42 +0000 | 
| commit | ea4c5fe65a1a57d21b6df96ba87a025fd0af156d (patch) | |
| tree | fecb97ef019ce703123a21bd3be7d59d759c8dd6 | |
| parent | dd76b70ee540a90047b18c07bee53ce49d9b7d20 (diff) | |
| download | openbsd-ea4c5fe65a1a57d21b6df96ba87a025fd0af156d.tar.gz openbsd-ea4c5fe65a1a57d21b6df96ba87a025fd0af156d.tar.bz2 openbsd-ea4c5fe65a1a57d21b6df96ba87a025fd0af156d.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
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_lib.c | 26 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_lib.c | 26 | 
2 files changed, 18 insertions, 34 deletions
| diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index 9787a31dbb..a8022f6668 100644 --- a/src/lib/libcrypto/bn/bn_lib.c +++ b/src/lib/libcrypto/bn/bn_lib.c | |||
| @@ -226,22 +226,11 @@ void BN_clear_free(BIGNUM *a) | |||
| 226 | free(a); | 226 | free(a); | 
| 227 | } | 227 | } | 
| 228 | 228 | ||
| 229 | void BN_free(BIGNUM *a) | 229 | void | 
| 230 | { | 230 | BN_free(BIGNUM *a) | 
| 231 | if (a == NULL) return; | 231 | { | 
| 232 | bn_check_top(a); | 232 | BN_clear_free(a); | 
| 233 | if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA))) | 233 | } | 
| 234 | free(a->d); | ||
| 235 | if (a->flags & BN_FLG_MALLOCED) | ||
| 236 | free(a); | ||
| 237 | else | ||
| 238 | { | ||
| 239 | #ifndef OPENSSL_NO_DEPRECATED | ||
| 240 | a->flags|=BN_FLG_FREE; | ||
| 241 | #endif | ||
| 242 | a->d = NULL; | ||
| 243 | } | ||
| 244 | } | ||
| 245 | 234 | ||
| 246 | void BN_init(BIGNUM *a) | 235 | void BN_init(BIGNUM *a) | 
| 247 | { | 236 | { | 
| @@ -400,7 +389,10 @@ BIGNUM *bn_expand2(BIGNUM *b, int words) | |||
| 400 | { | 389 | { | 
| 401 | BN_ULONG *a = bn_expand_internal(b, words); | 390 | BN_ULONG *a = bn_expand_internal(b, words); | 
| 402 | if(!a) return NULL; | 391 | if(!a) return NULL; | 
| 403 | if(b->d) free(b->d); | 392 | if(b->d) { | 
| 393 | OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0])); | ||
| 394 | free(b->d); | ||
| 395 | } | ||
| 404 | b->d=a; | 396 | b->d=a; | 
| 405 | b->dmax=words; | 397 | b->dmax=words; | 
| 406 | } | 398 | } | 
| diff --git a/src/lib/libssl/src/crypto/bn/bn_lib.c b/src/lib/libssl/src/crypto/bn/bn_lib.c index 9787a31dbb..a8022f6668 100644 --- a/src/lib/libssl/src/crypto/bn/bn_lib.c +++ b/src/lib/libssl/src/crypto/bn/bn_lib.c | |||
| @@ -226,22 +226,11 @@ void BN_clear_free(BIGNUM *a) | |||
| 226 | free(a); | 226 | free(a); | 
| 227 | } | 227 | } | 
| 228 | 228 | ||
| 229 | void BN_free(BIGNUM *a) | 229 | void | 
| 230 | { | 230 | BN_free(BIGNUM *a) | 
| 231 | if (a == NULL) return; | 231 | { | 
| 232 | bn_check_top(a); | 232 | BN_clear_free(a); | 
| 233 | if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA))) | 233 | } | 
| 234 | free(a->d); | ||
| 235 | if (a->flags & BN_FLG_MALLOCED) | ||
| 236 | free(a); | ||
| 237 | else | ||
| 238 | { | ||
| 239 | #ifndef OPENSSL_NO_DEPRECATED | ||
| 240 | a->flags|=BN_FLG_FREE; | ||
| 241 | #endif | ||
| 242 | a->d = NULL; | ||
| 243 | } | ||
| 244 | } | ||
| 245 | 234 | ||
| 246 | void BN_init(BIGNUM *a) | 235 | void BN_init(BIGNUM *a) | 
| 247 | { | 236 | { | 
| @@ -400,7 +389,10 @@ BIGNUM *bn_expand2(BIGNUM *b, int words) | |||
| 400 | { | 389 | { | 
| 401 | BN_ULONG *a = bn_expand_internal(b, words); | 390 | BN_ULONG *a = bn_expand_internal(b, words); | 
| 402 | if(!a) return NULL; | 391 | if(!a) return NULL; | 
| 403 | if(b->d) free(b->d); | 392 | if(b->d) { | 
| 393 | OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0])); | ||
| 394 | free(b->d); | ||
| 395 | } | ||
| 404 | b->d=a; | 396 | b->d=a; | 
| 405 | b->dmax=words; | 397 | b->dmax=words; | 
| 406 | } | 398 | } | 
