From 4b4c0a19211bf73d81de52de697a1a9dc60aed82 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Mon, 5 Jan 2015 14:52:56 +0100 Subject: Fix for CVE-2014-3570. Reviewed-by: Emilia Kasper (cherry picked from commit e793809ba50c1e90ab592fb640a856168e50f3de) --- crypto/bn/bn_asm.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'crypto/bn/bn_asm.c') diff --git a/crypto/bn/bn_asm.c b/crypto/bn/bn_asm.c index 99bc2de491..b95b003e15 100644 --- a/crypto/bn/bn_asm.c +++ b/crypto/bn/bn_asm.c @@ -431,6 +431,10 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n) /* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */ /* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */ +/* + * Keep in mind that carrying into high part of multiplication result + * can not overflow, because it cannot be all-ones. + */ #ifdef BN_LLONG #define mul_add_c(a,b,c0,c1,c2) \ t=(BN_ULLONG)a*b; \ @@ -471,10 +475,10 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n) #define mul_add_c2(a,b,c0,c1,c2) { \ BN_ULONG ta=(a),tb=(b),t0; \ BN_UMULT_LOHI(t0,t1,ta,tb); \ - t2 = t1+t1; c2 += (t2