/* The old slow way */
#if 0
-int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)
+int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
+ BN_CTX *ctx)
{
int i,nm,nd;
BIGNUM *D;
: "cc"); \
q; \
})
-# define REMINDER_IS_ALREADY_CALCULATED
+# define REMAINDER_IS_ALREADY_CALCULATED
# endif /* __<cpu> */
# endif /* __GNUC__ */
#endif /* NO_ASM */
n0=wnump[0];
n1=wnump[-1];
if (n0 == d0)
+ {
q=BN_MASK2;
- else
+#ifdef REMAINDER_IS_ALREADY_CALCULATED /* in this case it isn't */
+ rem=(n1-q*d0)&BN_MASK2;
+#endif
+ }
+ else /* n0 < d0 */
#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)
- q=((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0;
+ q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);
#else
q=bn_div_words(n0,n1,d0);
#endif
#ifdef BN_LLONG
BN_ULLONG t2;
-#ifndef REMINDER_IS_ALREADY_CALCULATED
+#ifndef REMAINDER_IS_ALREADY_CALCULATED
/*
* rem doesn't have to be BN_ULLONG. The least we
* know it's less that d0, isn't it?
#else
BN_ULONG t2l,t2h,ql,qh;
-#ifndef REMINDER_IS_ALREADY_CALCULATED
+#ifndef REMAINDER_IS_ALREADY_CALCULATED
/*
* It's more than enough with the only multiplication.
* See the comment above in BN_LLONG section...