summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/arch
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/arch')
-rw-r--r--src/lib/libcrypto/bn/arch/amd64/bn_arch.h27
-rw-r--r--src/lib/libcrypto/bn/arch/i386/bn_arch.h27
2 files changed, 52 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bn/arch/amd64/bn_arch.h b/src/lib/libcrypto/bn/arch/amd64/bn_arch.h
index 065f6b1c3b..6b7eaf5eee 100644
--- a/src/lib/libcrypto/bn/arch/amd64/bn_arch.h
+++ b/src/lib/libcrypto/bn/arch/amd64/bn_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_arch.h,v 1.7 2023/01/23 12:17:57 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.8 2023/01/28 16:33:34 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -15,6 +15,8 @@
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */ 16 */
17 17
18#include <openssl/bn.h>
19
18#ifndef HEADER_BN_ARCH_H 20#ifndef HEADER_BN_ARCH_H
19#define HEADER_BN_ARCH_H 21#define HEADER_BN_ARCH_H
20 22
@@ -36,5 +38,28 @@
36 38
37#define HAVE_BN_SUB_WORDS 39#define HAVE_BN_SUB_WORDS
38 40
41#if defined(__GNUC__)
42#define HAVE_BN_DIV_REM_WORDS_INLINE
43
44static inline void
45bn_div_rem_words_inline(BN_ULONG h, BN_ULONG l, BN_ULONG d, BN_ULONG *out_q,
46 BN_ULONG *out_r)
47{
48 BN_ULONG q, r;
49
50 /*
51 * Unsigned division of %rdx:%rax by d with quotient being stored in
52 * %rax and remainder in %rdx.
53 */
54 __asm__ volatile ("divq %4"
55 : "=a"(q), "=d"(r)
56 : "d"(h), "a"(l), "rm"(d)
57 : "cc");
58
59 *out_q = q;
60 *out_r = r;
61}
62#endif /* __GNUC__ */
63
39#endif 64#endif
40#endif 65#endif
diff --git a/src/lib/libcrypto/bn/arch/i386/bn_arch.h b/src/lib/libcrypto/bn/arch/i386/bn_arch.h
index 681c2090a7..e2b4957efc 100644
--- a/src/lib/libcrypto/bn/arch/i386/bn_arch.h
+++ b/src/lib/libcrypto/bn/arch/i386/bn_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_arch.h,v 1.6 2023/01/23 12:17:57 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.7 2023/01/28 16:33:34 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -15,6 +15,8 @@
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */ 16 */
17 17
18#include <openssl/bn.h>
19
18#ifndef HEADER_BN_ARCH_H 20#ifndef HEADER_BN_ARCH_H
19#define HEADER_BN_ARCH_H 21#define HEADER_BN_ARCH_H
20 22
@@ -35,5 +37,28 @@
35 37
36#define HAVE_BN_SUB_WORDS 38#define HAVE_BN_SUB_WORDS
37 39
40#if defined(__GNUC__)
41#define HAVE_BN_DIV_REM_WORDS_INLINE
42
43static inline void
44bn_div_rem_words_inline(BN_ULONG h, BN_ULONG l, BN_ULONG d, BN_ULONG *out_q,
45 BN_ULONG *out_r)
46{
47 BN_ULONG q, r;
48
49 /*
50 * Unsigned division of %edx:%eax by d with quotient being stored in
51 * %eax and remainder in %edx.
52 */
53 __asm__ volatile ("divl %4"
54 : "=a"(q), "=d"(r)
55 : "a"(l), "d"(h), "rm"(d)
56 : "cc");
57
58 *out_q = q;
59 *out_r = r;
60}
61#endif /* __GNUC__ */
62
38#endif 63#endif
39#endif 64#endif