Cryptography Reference
In-Depth Information
Two further useful special cases of addition and subtraction are realized in
the functions inc_l() and dec_l() , which increase or decrease a CLINT value by 1.
These functions are designed as accumulator routines: The operand is overwritten
with the return value, which has proved practical in the implementation of many
algorithms.
It is not surprising that the implementations of inc_l() and dec_l() are
similar to those of the functions add_l() and sub_l() . They test for overflow and
underflow, respectively, and return the corresponding error codes E_CLINT_OFL
and E_CLINT_UFL .
increment a CLINT object by 1
Function:
int inc_l (CLINT a_l);
Syntax:
a_l (summand)
Input:
a_l (sum)
Output:
E_CLINT_OK if all is ok
E_CLINT_OFL if overflow
Return:
int
inc_l (CLINT a_l)
{
clint *msdptra_l, *aptr_l = LSDPTR_L (a_l);
ULONG carry = BASE;
int OFL = E_CLINT_OK;
msdptra_l = MSDPTR_L (a_l);
while ((aptr_l <= msdptra_l) && (carry & BASE))
{
*aptr_l = (USHORT)(carry = 1UL + (ULONG)*aptr_l);
aptr_l++;
}
if ((aptr_l > msdptra_l) && (carry & BASE))
{
*aptr_l = 1;
SETDIGITS_L (a_l, DIGITS_L (a_l) + 1);
if (DIGITS_L (a_l) > (USHORT) CLINTMAXDIGIT)
/* overflow ? */
{
SETZERO_L (a_l);
/* reduce modulo (Nmax + 1) */
OFL = E_CLINT_OFL;
}
}
return OFL;
}
 
Search WWH ::




Custom Search