From 9f6795e7d2d1e35668ad70ba0afc480062be4e2e Mon Sep 17 00:00:00 2001
From: Pascal Cuoq <cuoq@trust-in-soft.com>
Date: Mon, 19 Oct 2015 22:24:23 +0200
Subject: [PATCH] BN_usub: Don't copy when r and a the same

Signed-off-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Rich Salz <rsalz@akamai.com>

RT #4100, MR #1264
---
 crypto/bn/bn_add.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/bn/bn_add.c b/crypto/bn/bn_add.c
index 0bfc3cc637..bbb0584245 100644
--- a/crypto/bn/bn_add.c
+++ b/crypto/bn/bn_add.c
@@ -222,7 +222,7 @@ int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
                 break;
         }
     }
-    if (dif)
+    if (dif && ap != rp)
         memcpy(rp, ap, sizeof(*rp) * dif);
 
     r->top = max;
-- 
2.25.1