Go to the documentation of this file.
71 BN_ULONG dh, dl, q,
ret = 0, th, tl, t;
79 assert((
i == BN_BITS2) || (h <= (BN_ULONG)1 <<
i));
88 h = (h <<
i) | (
l >> (BN_BITS2 -
i));
91 dh = (
d & BN_MASK2h) >> BN_BITS4;
94 if ((h >> BN_BITS4) == dh) {
104 if ((t & BN_MASK2h) ||
105 ((tl) <= ((t << BN_BITS4) | ((
l & BN_MASK2h) >> BN_BITS4)))) {
112 t = (tl >> BN_BITS4);
113 tl = (tl << BN_BITS4) & BN_MASK2h;
131 h = (h << BN_BITS4) | (
l >> BN_BITS4);
132 l = (
l & BN_MASK2l) << BN_BITS4;
140 BN_ULONG n0, BN_ULONG n1, BN_ULONG d0) {
157 #if defined(BN_CAN_USE_INLINE_ASM) && defined(OPENSSL_X86)
158 __asm__
volatile(
"divl %4"
159 :
"=a"(*quotient_out),
"=d"(*rem_out)
160 :
"a"(n1),
"d"(n0),
"rm"(d0)
162 #elif defined(BN_CAN_USE_INLINE_ASM) && defined(OPENSSL_X86_64)
163 __asm__
volatile(
"divq %4"
164 :
"=a"(*quotient_out),
"=d"(*rem_out)
165 :
"a"(n1),
"d"(n0),
"rm"(d0)
168 #if defined(BN_CAN_DIVIDE_ULLONG)
169 BN_ULLONG
n = (((BN_ULLONG)n0) << BN_BITS2) | n1;
170 *quotient_out = (BN_ULONG)(
n / d0);
174 *rem_out = n1 - (*quotient_out * d0);
196 int norm_shift,
loop;
198 BN_ULONG *
resp, *wnump;
210 if ((numerator_width > 0 && numerator->
d[numerator_width - 1] == 0) ||
211 (divisor_width > 0 && divisor->
d[divisor_width - 1] == 0)) {
226 if (quotient == NULL) {
231 if (sdiv == NULL || res == NULL) {
236 norm_shift = BN_BITS2 - (
BN_num_bits(divisor) % BN_BITS2);
237 if (!
BN_lshift(sdiv, divisor, norm_shift)) {
242 norm_shift += BN_BITS2;
243 if (!
BN_lshift(snum, numerator, norm_shift)) {
270 loop = num_n - div_n;
275 wnum.
d = &(snum->
d[
loop]);
282 d0 = sdiv->
d[div_n - 1];
283 d1 = (div_n == 1) ? 0 : sdiv->
d[div_n - 2];
286 wnump = &(snum->
d[num_n - 1]);
290 const int numerator_neg = numerator->
neg;
291 res->
neg = (numerator_neg ^ divisor->
neg);
305 if (res->
width == 0) {
311 for (
int i = 0;
i <
loop - 1;
i++, wnump--,
resp--) {
315 BN_ULONG n0, n1,
rm = 0;
326 BN_ULLONG t2 = (BN_ULLONG)d1 * q;
328 if (t2 <= ((((BN_ULLONG)
rm) << BN_BITS2) | wnump[-2])) {
340 BN_UMULT_LOHI(t2l, t2h, d1, q);
343 (t2h ==
rm && t2l <= wnump[-2])) {
388 rem->
neg = numerator_neg;
414 const BN_ULONG *
m,
size_t num) {
428 assert(carry == 0 || carry == (BN_ULONG)-1);
434 BN_ULONG *
tmp,
size_t num) {
437 assert(carry == 0 || carry == (BN_ULONG)-1);
443 const BN_ULONG *
m, BN_ULONG *
tmp,
size_t num) {
452 const BN_ULONG *
m, BN_ULONG *
tmp,
size_t num) {
459 unsigned divisor_min_bits,
BN_CTX *
ctx) {
475 BIGNUM *q = quotient, *
r = remainder;
476 if (quotient == NULL || quotient == numerator || quotient == divisor) {
479 if (remainder == NULL || remainder == numerator || remainder == divisor) {
483 if (q == NULL ||
r == NULL ||
tmp == NULL ||
491 q->width = numerator->
width;
495 r->width = divisor->
width;
508 int initial_words = 0;
509 if (divisor_min_bits > 0) {
510 initial_words = (divisor_min_bits - 1) / BN_BITS2;
511 if (initial_words > numerator->
width) {
512 initial_words = numerator->
width;
515 initial_words *
sizeof(BN_ULONG));
518 for (
int i = numerator->
width - initial_words - 1;
i >= 0;
i--) {
519 for (
int bit = BN_BITS2 - 1; bit >= 0; bit--) {
524 r->d[0] |= (numerator->
d[
i] >> bit) & 1;
532 q->d[
i] |= (~subtracted & 1) << bit;
536 if ((quotient != NULL && !
BN_copy(quotient, q)) ||
537 (remainder != NULL && !
BN_copy(remainder,
r))) {
591 int ok =
ctx != NULL &&
603 int ok =
a != NULL &&
b != NULL &&
tmp != NULL &&
628 int ok =
a != NULL &&
b != NULL &&
tmp != NULL &&
642 int ok =
ctx != NULL &&
717 for (
int i = 0;
i <
n;
i++) {
727 int ok =
ctx != NULL &&
748 int ok =
ctx != NULL &&
760 return (BN_ULONG) - 1;
771 return (BN_ULONG) - 1;
774 for (
i =
a->width - 1;
i >= 0;
i--) {
775 BN_ULONG
l =
a->d[
i];
789 #ifndef BN_CAN_DIVIDE_ULLONG
797 return (BN_ULONG) -1;
800 #ifndef BN_CAN_DIVIDE_ULLONG
803 if (w > ((BN_ULONG)1 << BN_BITS4)) {
814 for (
i =
a->width - 1;
i >= 0;
i--) {
815 #ifndef BN_CAN_DIVIDE_ULLONG
816 ret = ((
ret << BN_BITS4) | ((
a->d[
i] >> BN_BITS4) & BN_MASK2l)) % w;
817 ret = ((
ret << BN_BITS4) | (
a->d[
i] & BN_MASK2l)) % w;
819 ret = (BN_ULLONG)(((
ret << (BN_ULLONG)BN_BITS2) |
a->d[
i]) % (BN_ULLONG)w);
822 return (BN_ULONG)
ret;
826 if (e == 0 ||
a->width == 0) {
831 size_t num_words = 1 + ((e - 1) / BN_BITS2);
834 if ((
size_t)
a->width < num_words) {
848 size_t top_word_exponent = e % (
sizeof(BN_ULONG) * 8);
849 if (top_word_exponent != 0) {
850 r->d[num_words - 1] &= (((BN_ULONG) 1) << top_word_exponent) - 1;
855 r->width = (
int) num_words;
870 size_t num_words = 1 + (e - 1) / BN_BITS2;
882 r->width = (
int) num_words;
887 for (
int i = 0;
i <
r->width;
i++) {
892 size_t top_word_exponent = e % BN_BITS2;
893 if (top_word_exponent != 0) {
894 r->d[
r->width - 1] &= (((BN_ULONG) 1) << top_word_exponent) - 1;
int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m)
#define bn_set_minimal_width
void bn_mod_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, const BN_ULONG *m, BN_ULONG *tmp, size_t num)
int BN_mod_pow2(BIGNUM *r, const BIGNUM *a, size_t e)
#define OPENSSL_PUT_ERROR(library, reason)
static OPENSSL_UNUSED BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
static void bn_div_rem_words(BN_ULONG *quotient_out, BN_ULONG *rem_out, BN_ULONG n0, BN_ULONG n1, BN_ULONG d0)
int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx)
int bn_div_consttime(BIGNUM *quotient, BIGNUM *remainder, const BIGNUM *numerator, const BIGNUM *divisor, unsigned divisor_min_bits, BN_CTX *ctx)
int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
BN_ULONG bn_reduce_once(BN_ULONG *r, const BN_ULONG *a, BN_ULONG carry, const BN_ULONG *m, size_t num)
#define BN_mod(rem, numerator, divisor, ctx)
#define BN_R_NEGATIVE_NUMBER
int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m)
int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
static void * OPENSSL_memset(void *dst, int c, size_t n)
const OPENSSL_EXPORT BIGNUM * BN_value_one(void)
int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)
static const BIGNUM * bn_resized_from_ctx(const BIGNUM *bn, size_t width, BN_CTX *ctx)
int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
int BN_div(BIGNUM *quotient, BIGNUM *rem, const BIGNUM *numerator, const BIGNUM *divisor, BN_CTX *ctx)
int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m)
#define BN_R_NOT_INITIALIZED
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
int bn_mod_sub_consttime(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
static bool rm(upb_table *t, lookupkey_t key, upb_value *val, upb_tabkey *removed, uint32_t hash, eqlfunc_t *eql)
BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
void bn_mod_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, const BN_ULONG *m, BN_ULONG *tmp, size_t num)
UniquePtr< SSL_SESSION > ret
int bn_mod_lshift_consttime(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx)
BN_ULONG bn_reduce_once_in_place(BN_ULONG *r, BN_ULONG carry, const BN_ULONG *m, BN_ULONG *tmp, size_t num)
int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
static BIGNUM * bn_scratch_space_from_ctx(size_t width, BN_CTX *ctx)
int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
int bn_mod_add_consttime(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
int BN_nnmod_pow2(BIGNUM *r, const BIGNUM *a, size_t e)
int bn_mod_lshift1_consttime(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:12