Cryptography Reference
In-Depth Information
The two
USHORT
values
*aptr
and
*bptr
are copied via a
cast
to
ULONG
representa-
tion and added. To this the carry from the last interation is added. The result is
a
ULONG
value that contains the carry from the addition step in its higher-valued
word. This value is allocated to the variable
carry
and there reserved for the next
iteration. The value of the resulting digit is taken from the lower-valued word of the
addition result via a cast to the type
USHORT
. The carry saved in the higher-valued
word of
carry
is included in the next iteration by a shift to the right by the number
BITPERDGT
of bits used for the representation of
USHORT
and a cast to
USHORT.
In the second loop only the remaining digits of
a_l
are added to a possible existing
carry and stored in
s_l
.
while (aptr_l <= msdptra_l)
{
*sptr_l++ = (USHORT)(carry = (ULONG)*aptr_l++
+ (ULONG)(USHORT)(carry >> BITPERDGT));
}
If after the second loop there is a carry, the result is one digit longer than
a_l
.If
it is determined that the result exceeds the maximal value
N
max
representable
by the
CLINT
type, then the result is reduced modulo
(
N
max
+1)
(see Chapter 5),
analogously to the treatment of standard unsigned types. In this case the status
announcement of the error code
E_CLINT_OFL
is returned.
if (carry & BASE)
{
*sptr_l = 1;
SETDIGITS_L (ss_l, DIGITS_L (ss_l) + 1);
}
if (DIGITS_L (ss_l) > (USHORT)CLINTMAXDIGIT)
/* overflow? */
{
ANDMAX_L (ss_l);
/* reduce modulo (Nmax + 1) */
OFL = E_CLINT_OFL;
}
cpy_l (s_l, ss_l);
return OFL;
}
The run time
t
of all the procedures given here for addition and subtraction is
t
=
O
(
n
)
, and thus proportional to the number of digits of the larger of the two
operands.