Cryptography Reference
In-Depth Information
int
div_l (CLINT d1_l, CLINT d2_l, CLINT quot_l, CLINT rem_l)
{
register clint *rptr_l, *bptr_l;
CLINT b_l;
/* Allow double-length dividend plus 1 digit */
clint r_l[2 + (CLINTMAXDIGIT << 1)];
clint *qptr_l, *msdptrb_l, *lsdptrr_l, *msdptrr_l;
USHORT bv, rv, qhat, ri, ri_1, ri_2, bn_1, bn_2;
ULONG right, left, rhat, borrow, carry, sbitsminusd;
unsigned intd=0;
int i;
The dividend
a
=
a
m
+
n
−
1
a
m
+
n
−
2
...a
0
B
and divisor
b
b
n
−
1
b
n
−
2
...b
0
B
arecopiedintothe
CLINT
variables
r_l
and
b_l
. Any leading zeros are purged.
If the divisor has the value zero, the function is terminated with the error code
E_CLINT_DBZ
.
We allow the dividend to possess up to double the number of digits determined
in
MAX
B
. This makes possible the later use of division in the functions of mod-
ular arithmetic. The storage allotment for a doubly long quotient must always be
available to the calling function.
cpy_l (r_l, d1_l);
cpy_l (b_l, d2_l);
if (EQZ_L (b_l))
return E_CLINT_DBZ;
A test is made as to whether one of the simple cases is at hand: dividend
=0
,
dividend
<
divisor, or dividend
=
divisor. In these cases we are done.
if (EQZ_L (r_l))
{
SETZERO_L (quot_l);
SETZERO_L (rem_l);
return E_CLINT_OK ;
}
i = cmp_l (r_l, b_l);