From: Billy Brumley Date: Thu, 26 Apr 2018 16:01:22 +0000 (+0300) Subject: fix: BN_swap mishandles flags (1.1.0) X-Git-Tag: OpenSSL_1_1_0i~144 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b3c586753b57a3899b40d3e10e2af45d1eb515a2;p=oweals%2Fopenssl.git fix: BN_swap mishandles flags (1.1.0) Reviewed-by: Rich Salz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/6101) --- diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c index 07b715d597..c59bdb7c9e 100644 --- a/crypto/bn/bn_lib.c +++ b/crypto/bn/bn_lib.c @@ -385,6 +385,11 @@ BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) return (a); } +#define FLAGS_DATA(flags) ((flags) & (BN_FLG_STATIC_DATA \ + | BN_FLG_CONSTTIME \ + | BN_FLG_SECURE)) +#define FLAGS_STRUCT(flags) ((flags) & (BN_FLG_MALLOCED)) + void BN_swap(BIGNUM *a, BIGNUM *b) { int flags_old_a, flags_old_b; @@ -412,10 +417,8 @@ void BN_swap(BIGNUM *a, BIGNUM *b) b->dmax = tmp_dmax; b->neg = tmp_neg; - a->flags = - (flags_old_a & BN_FLG_MALLOCED) | (flags_old_b & BN_FLG_STATIC_DATA); - b->flags = - (flags_old_b & BN_FLG_MALLOCED) | (flags_old_a & BN_FLG_STATIC_DATA); + a->flags = FLAGS_STRUCT(flags_old_a) | FLAGS_DATA(flags_old_b); + b->flags = FLAGS_STRUCT(flags_old_b) | FLAGS_DATA(flags_old_a); bn_check_top(a); bn_check_top(b); }