BN_usub: Don't copy when r and a the same
[openssl.git] / crypto / bn / bn_add.c
index 57e1cdac16626be3d588fc0939167dd93f91ff2a..bbb05842452e6558fead3bc84a1cb9cd1482ebbb 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
 #include "bn_lcl.h"
 
 /* r can == a or b */
@@ -222,7 +222,8 @@ int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
                 break;
         }
     }
-    memcpy(rp, ap, sizeof(*rp) * dif);
+    if (dif && ap != rp)
+        memcpy(rp, ap, sizeof(*rp) * dif);
 
     r->top = max;
     r->neg = 0;