summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_word.c
diff options
context:
space:
mode:
authorjsing <>2023-01-28 16:33:34 +0000
committerjsing <>2023-01-28 16:33:34 +0000
commitd63f41446c0a5c6fb98126ac39bea7d011911bf2 (patch)
tree77285c9d112391ced3ea1c6ee831bf186ff9316b /src/lib/libcrypto/bn/bn_word.c
parent6738561f9181a99b8aa084f27caeea50afddc836 (diff)
downloadopenbsd-d63f41446c0a5c6fb98126ac39bea7d011911bf2.tar.gz
openbsd-d63f41446c0a5c6fb98126ac39bea7d011911bf2.tar.bz2
openbsd-d63f41446c0a5c6fb98126ac39bea7d011911bf2.zip
Provide bn_div_rem_words() and make use of it.
Provide a function that divides a double word (h:l) by d, returning the quotient q and the remainder r, such that q * d + r is equal to the numerator. Call this from the three places that currently implement this themselves. This is implemented with some slight indirection, which allows for per architecture implementations, replacing the define/macro tangle, which messes with variables that are not passed to it. Also remove a duplicate of bn_div_words() for the BN_ULLONG && BN_DIV2W case - this is already handled. ok tb@
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/bn/bn_word.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
index 4663237b05..7077d3ad7a 100644
--- a/src/lib/libcrypto/bn/bn_word.c
+++ b/src/lib/libcrypto/bn/bn_word.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_word.c,v 1.16 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: bn_word.c,v 1.17 2023/01/28 16:33:34 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -125,8 +125,7 @@ BN_div_word(BIGNUM *a, BN_ULONG w)
125 BN_ULONG l, d; 125 BN_ULONG l, d;
126 126
127 l = a->d[i]; 127 l = a->d[i];
128 d = bn_div_words(ret, l, w); 128 bn_div_rem_words(ret, l, w, &d, &ret);
129 ret = (l - ((d*w)&BN_MASK2))&BN_MASK2;
130 a->d[i] = d; 129 a->d[i] = d;
131 } 130 }
132 if ((a->top > 0) && (a->d[a->top - 1] == 0)) 131 if ((a->top > 0) && (a->d[a->top - 1] == 0))