Cryptography Reference
In-Depth Information
leftover carry at the end, it is stored as the most-significant digit of the sum. The
output of this digit is suppressed if it has the value zero.
Steps 2 and 4 of the algorithm appear in a similar form in the case of
subtraction, multiplication, and division. The associated code, which is illustrated
by the following lines, is typical for arithmetic functions: 1
s = (USHORT)(carry = (ULONG)a + (ULONG)b + (ULONG)(USHORT)(carry >> BITPERDGT));
The intermediate value t that appears in the algorithm is represented by the
variable carry , of type ULONG , which holds the sum of the digits a i and b i as well
as the carry of the previous operation. The new summation digit s i is stored in
the less-significant part of carry , from where it is taken by means of a cast as a
USHORT . The resulting carry from this operation is held in the more-significant part
of carry for the next operation.
The implementation of this algorithm by our function add_l() deals with a
possible overflow of the sum, where in this case a reduction of the sum modulo
( N max +1) is carried out.
Function:
addition
int add_l (CLINT a_l, CLINT b_l, CLINT s_l);
Syntax:
a_l, b_l (summands)
Input:
s_l (sum)
Output:
E_CLINT_OK if all is ok
E_CLINT_OFL in the case of overflow
Return:
int
add_l (CLINT a_l, CLINT b_l, CLINT s_l)
{
clint ss_l[CLINTMAXSHORT + 1];
clint *msdptra_l, *msdptrb_l;
clint *aptr_l, *bptr_l, *sptr_l = LSDPTR_L (ss_l);
ULONG carry = 0L;
int OFL = E_CLINT_OK;
1
The C expression in this compact form is due to my colleague Robert Hammelrath.
 
Search WWH ::




Custom Search