summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2023-02-04 11:48:55 +0000
committerjsing <>2023-02-04 11:48:55 +0000
commit6fee4189019f0d88575b1a34a9ac2d619669d416 (patch)
treea295d7975e7b264dbd235da1734cd25c0c93f44d /src
parenteea9d6117d7c8bf1dce983b524e7340321ae9035 (diff)
downloadopenbsd-6fee4189019f0d88575b1a34a9ac2d619669d416.tar.gz
openbsd-6fee4189019f0d88575b1a34a9ac2d619669d416.tar.bz2
openbsd-6fee4189019f0d88575b1a34a9ac2d619669d416.zip
Fix output constraints for bn_umul_hilo().
When bn_umul_hilo() is implemented using an instruction pair, mark the first output with a constraint that prevents the output from overlapping with the inputs ("&"). Otherwise the first instruction can overwrite the inputs, which then results in the second instruction producing incorrect value.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bn/arch/aarch64/bn_arch.h4
-rw-r--r--src/lib/libcrypto/bn/arch/alpha/bn_arch.h4
-rw-r--r--src/lib/libcrypto/bn/arch/powerpc64/bn_arch.h4
-rw-r--r--src/lib/libcrypto/bn/arch/riscv64/bn_arch.h4
4 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h b/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h
index 5cf25adc48..7592971dc0 100644
--- a/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h
+++ b/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:53:49 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.3 2023/02/04 11:48:55 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -32,7 +32,7 @@ bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l)
32 32
33 /* Unsigned multiplication using a umulh/mul pair. */ 33 /* Unsigned multiplication using a umulh/mul pair. */
34 __asm__ ("umulh %0, %2, %3; mul %1, %2, %3" 34 __asm__ ("umulh %0, %2, %3; mul %1, %2, %3"
35 : "=r"(h), "=r"(l) 35 : "=&r"(h), "=r"(l)
36 : "r"(a), "r"(b)); 36 : "r"(a), "r"(b));
37 37
38 *out_h = h; 38 *out_h = h;
diff --git a/src/lib/libcrypto/bn/arch/alpha/bn_arch.h b/src/lib/libcrypto/bn/arch/alpha/bn_arch.h
index 9bc00911ab..0f7c582fdf 100644
--- a/src/lib/libcrypto/bn/arch/alpha/bn_arch.h
+++ b/src/lib/libcrypto/bn/arch/alpha/bn_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:57:08 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.3 2023/02/04 11:48:55 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -31,7 +31,7 @@ bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l)
31 31
32 /* Unsigned multiplication using a umulh/mulq pair. */ 32 /* Unsigned multiplication using a umulh/mulq pair. */
33 __asm__ ("umulh %2, %3, %0; mulq %2, %3, %1" 33 __asm__ ("umulh %2, %3, %0; mulq %2, %3, %1"
34 : "=r"(h), "=r"(l) 34 : "=&r"(h), "=r"(l)
35 : "r"(a), "r"(b)); 35 : "r"(a), "r"(b));
36 36
37 *out_h = h; 37 *out_h = h;
diff --git a/src/lib/libcrypto/bn/arch/powerpc64/bn_arch.h b/src/lib/libcrypto/bn/arch/powerpc64/bn_arch.h
index 1b8bd61138..92e16e9f9c 100644
--- a/src/lib/libcrypto/bn/arch/powerpc64/bn_arch.h
+++ b/src/lib/libcrypto/bn/arch/powerpc64/bn_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:57:08 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.3 2023/02/04 11:48:55 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -31,7 +31,7 @@ bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l)
31 31
32 /* Unsigned multiplication using a mulhdu/mul pair. */ 32 /* Unsigned multiplication using a mulhdu/mul pair. */
33 __asm__ ("mulhdu %0, %2, %3; mul %1, %2, %3" 33 __asm__ ("mulhdu %0, %2, %3; mul %1, %2, %3"
34 : "=r"(h), "=r"(l) 34 : "=&r"(h), "=r"(l)
35 : "r"(a), "r"(b)); 35 : "r"(a), "r"(b));
36 36
37 *out_h = h; 37 *out_h = h;
diff --git a/src/lib/libcrypto/bn/arch/riscv64/bn_arch.h b/src/lib/libcrypto/bn/arch/riscv64/bn_arch.h
index 1b4267acc0..36cf3a4f66 100644
--- a/src/lib/libcrypto/bn/arch/riscv64/bn_arch.h
+++ b/src/lib/libcrypto/bn/arch/riscv64/bn_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:57:08 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.3 2023/02/04 11:48:55 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -35,7 +35,7 @@ bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l)
35 * into a single operation. 35 * into a single operation.
36 */ 36 */
37 __asm__ ("mulh %0, %2, %3; mul %1, %2, %3" 37 __asm__ ("mulh %0, %2, %3; mul %1, %2, %3"
38 : "=r"(h), "=r"(l) 38 : "=&r"(h), "=r"(l)
39 : "r"(a), "r"(b)); 39 : "r"(a), "r"(b));
40 40
41 *out_h = h; 41 *out_h = h;