Cryptography Reference
In-Depth Information
We distinguish the cases
a_l
≥
b_l
and
a_l
<
b_l
. The first case is a standard
situation; in the second case we compute
(
b_l
−
a_l
)
, reduce modulo
m_l
,and
subtract a positive remainder from
m_l
.
if (GE_L (a_l, b_l))
/* a_l - b_l
≥
0*/
{
sub (a_l, b_l, tmp_l);
mod_l (tmp_l, m_l, c_l);
}
else
/* a_l - b_l<0*/
{
sub (b_l, a_l, tmp_l);
mod_l (tmp_l, m_l, tmp_l);
if (GTZ_L (tmp_l))
{
sub (m_l, tmp_l, c_l);
}
else
{
SETZERO_L (c_l);
}
}
return E_CLINT_OK;
}
Now come the functions
mmul_l()
and
msqr_l()
for modular multiplication and
squaring, of which we show only that for multiplication.
Function:
modular multiplication
int mmul_l (CLINT aa_l, CLINT bb_l, CLINT c_l,
CLINT m_l);
Syntax:
aa_l, bb_l
(factors),
m_l
(modulus)
Input:
c_l
(remainder)
Output:
E_CLINT_OK
if all ok
E_CLINT_DBZ
if division by 0
Return: