These should work, but are currently untested and disabled.
ok tb@
-/* $OpenBSD: bn_arch.h,v 1.1 2023/01/20 10:04:33 jsing Exp $ */
+/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:57:08 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
#ifndef OPENSSL_NO_ASM
+#if 0 /* Needs testing and enabling. */
+#if defined(__GNUC__)
+#define HAVE_BN_UMUL_HILO
+
+static inline void
+bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l)
+{
+ BN_ULONG h, l;
+
+ /* Unsigned multiplication using a umulh/mulq pair. */
+ __asm__ ("umulh %2, %3, %0; mulq %2, %3, %1"
+ : "=r"(h), "=r"(l)
+ : "r"(a), "r"(b));
+
+ *out_h = h;
+ *out_l = l;
+}
+#endif /* __GNUC__ */
+#endif
+
#endif
#endif
-/* $OpenBSD: bn_arch.h,v 1.1 2023/01/20 10:04:34 jsing Exp $ */
+/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:57:08 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
#ifndef OPENSSL_NO_ASM
+#if 0 /* Needs testing and enabling. */
+#if defined(__GNUC__)
+#define HAVE_BN_UMUL_HILO
+
+static inline void
+bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l)
+{
+ BN_ULONG h, l;
+
+ /* Unsigned multiplication using a mulhdu/mul pair. */
+ __asm__ ("mulhdu %0, %2, %3; mul %1, %2, %3"
+ : "=r"(h), "=r"(l)
+ : "r"(a), "r"(b));
+
+ *out_h = h;
+ *out_l = l;
+}
+#endif /* __GNUC__ */
+#endif
+
#endif
#endif
-/* $OpenBSD: bn_arch.h,v 1.1 2023/01/20 10:04:34 jsing Exp $ */
+/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:57:08 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
#ifndef OPENSSL_NO_ASM
+#if 0 /* Needs testing and enabling. */
+#if defined(__GNUC__)
+#define HAVE_BN_UMUL_HILO
+
+static inline void
+bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l)
+{
+ BN_ULONG h, l;
+
+ /*
+ * Unsigned multiplication using a mulh/mul pair. Note that the order
+ * of these instructions is important, as they can potentially be fused
+ * into a single operation.
+ */
+ __asm__ ("mulh %0, %2, %3; mul %1, %2, %3"
+ : "=r"(h), "=r"(l)
+ : "r"(a), "r"(b));
+
+ *out_h = h;
+ *out_l = l;
+}
+#endif /* __GNUC__ */
+#endif
+
#endif
#endif