Cryptography Reference
In-Depth Information
The pointers for the addition loop are set. Here it is checked which of the two
summands has the greater number of digits. The pointers aptr_l and msdaptr_l
are initialized such that they point respectively to the least-significant and most-
significant digits of the summand that has the most digits, or to those digits of a_l
if both summands are of the same length. This holds analogously for the pointers
bptr_l and msdbptr_l , which point to the least-significant and most-significant
digits of the shorter summand, or to those digits of b_l . The initialization is
carried out with the help of the macro LSDPTR_L() for the least-significant dig-
its and MSDPTR_L() for the most-significant digits of a CLINT object. The macro
DIGITS_L (a_l) specifies the number of digits of the CLINT object a_l , and with
SETDIGITS_L(a_l, n) the number of digits of a_l is set to the value n .
if (DIGITS_L (a_l) < DIGITS_L (b_l))
{
aptr_l = LSDPTR_L (b_l);
bptr_l = LSDPTR_L (a_l);
msdptra_l = MSDPTR_L (b_l);
msdptrb_l = MSDPTR_L (a_l);
SETDIGITS_L (ss_l, DIGITS_L (b_l));
}
else
{
aptr_l = LSDPTR_L (a_l);
bptr_l = LSDPTR_L (b_l);
msdptra_l = MSDPTR_L (a_l);
msdptrb_l = MSDPTR_L (b_l);
SETDIGITS_L (ss_l, DIGITS_L (a_l));
}
Inthefirstloopof add_l the digits of a_l and b_l are added and stored in the result
variable ss_l . Any leading zeros cause no problem, and they are simply used in the
calculation and filtered out when the result is copied to s_l . The loop runs from the
least-significant digit of b_l to the most-significant digit. This corresponds exactly
to the process of pencil-and-paper addition as learned at school. As promised,
here is the implementation of the carry.
while (bptr_l <= msdptrb_l)
{
*sptr_l++ = (USHORT)(carry = (ULONG)*aptr_l++
+ (ULONG)*bptr_l++ + (ULONG)(USHORT)(carry >> BITPERDGT));
}
 
Search WWH ::




Custom Search