85 {
if (
BN_copy(rem,m) == NULL)
return(0); }
94 if (D == NULL || dv == NULL || rem == NULL)
99 if (
BN_copy(D,d) == NULL)
goto end;
100 if (
BN_copy(rem,m) == NULL)
goto end;
109 for (i=nm-nd; i>=0; i--)
115 if (!
BN_usub(rem,rem,D))
goto end;
130 #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) \
131 && !defined(PEDANTIC) && !defined(BN_DIV3W)
132 # if defined(__GNUC__) && __GNUC__>=2
133 # if defined(__i386) || defined (__i386__)
144 # define bn_div_words(n0,n1,d0) \
147 : "=a"(q), "=d"(rem) \
148 : "a"(n1), "d"(n0), "g"(d0) \
152 # define REMAINDER_IS_ALREADY_CALCULATED
153 # elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG)
158 # define bn_div_words(n0,n1,d0) \
161 : "=a"(q), "=d"(rem) \
162 : "a"(n1), "d"(n0), "g"(d0) \
166 # define REMAINDER_IS_ALREADY_CALCULATED
182 int norm_shift,i,loop;
183 BIGNUM *tmp,wnum,*snum,*sdiv,*res;
184 BN_ULONG *resp,*wnump;
192 if (num->
top > 0 && num->
d[num->
top - 1] == 0)
216 if (!no_branch &&
BN_ucmp(num,divisor) < 0)
219 {
if (
BN_copy(rm,num) == NULL)
return(0); }
231 if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)
235 norm_shift=BN_BITS2-((
BN_num_bits(divisor))%BN_BITS2);
236 if (!(
BN_lshift(sdiv,divisor,norm_shift)))
goto err;
238 norm_shift+=BN_BITS2;
239 if (!(
BN_lshift(snum,num,norm_shift)))
goto err;
248 if (snum->
top <= sdiv->
top+1)
251 for (i = snum->
top; i < sdiv->top + 2; i++) snum->
d[i] = 0;
252 snum->
top = sdiv->
top + 2;
257 snum->
d[snum->
top] = 0;
269 wnum.
d = &(snum->
d[loop]);
277 d1=(div_n == 1)?0:sdiv->
d[div_n-2];
280 wnump= &(snum->
d[num_n-1]);
285 res->
top=loop-no_branch;
286 resp= &(res->
d[loop-1]);
313 for (i=0; i<loop-1; i++, wnump--, resp--)
319 #if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)
320 BN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);
321 q=bn_div_3_words(wnump,d1,d0);
323 BN_ULONG n0,n1,rem=0;
334 #if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)
335 q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);
338 #ifdef BN_DEBUG_LEVITTE
339 fprintf(stderr,
"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\
345 #ifndef REMAINDER_IS_ALREADY_CALCULATED
350 rem=(n1-q*d0)&BN_MASK2;
356 if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))
367 #ifdef BN_DEBUG_LEVITTE
368 fprintf(stderr,
"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\
372 #ifndef REMAINDER_IS_ALREADY_CALCULATED
373 rem=(n1-q*d0)&BN_MASK2;
376 #if defined(BN_UMULT_LOHI)
377 BN_UMULT_LOHI(t2l,t2h,d1,q);
378 #elif defined(BN_UMULT_HIGH)
380 t2h = BN_UMULT_HIGH(d1,q);
386 mul64(t2l,t2h,ql,qh);
393 ((t2h == rem) && (t2l <= wnump[-2])))
398 if (t2l < d1) t2h--; t2l -= d1;