Cryptography Reference
In-Depth Information
We are now equipped to develop the functions madd_l() , msub_l() , mmul_l() ,and
msqr_l() for modular arithmetic.
Function:
modular addition
int madd_l (CLINT aa_l, CLINT bb_l, CLINT c_l,
CLINT m_l);
Syntax:
aa_l, bb_l (summands), m_l (modulus)
Input:
c_l (remainder)
Output:
E_CLINT_OK if all is ok
E_CLINT_DBZ if division by 0
Return:
int
madd_l (CLINT aa_l, CLINT bb_l, CLINT c_l, CLINT m_l)
{
CLINT a_l, b_l;
clint tmp_l[CLINTMAXSHORT + 1];
if (EQZ_L (m_l))
{
return E_CLINT_DBZ;
}
cpy_l (a_l, aa_l);
cpy_l (b_l, bb_l);
if (GE_L (a_l, m_l) || GE_L (b_l, m_l))
{
add (a_l, b_l, tmp_l);
mod_l (tmp_l, m_l, c_l);
}
else
If a_l and b_l both lie below m_l , then we are spared a division.
{
add (a_l, b_l, tmp_l);
if (GE_L (tmp_l, m_l))
{
sub_l (tmp_l, m_l, tmp_l);
/* underflow excluded */
}
 
Search WWH ::




Custom Search