Cryptography Reference
In-Depth Information
The following function
wmexp_l()
offers for small bases and exponents up to
1000 bits, for example, a speed advantage of about ten percent over the universal
procedures that we shall tackle later.
modular exponentiation of a
USHORT
base
Function:
int wmexp_l (USHORT bas, CLINT e_l, CLINT rest_l,
CLINT m_l);
Syntax:
bas
(base)
e_l
(exponent)
m_l
(modulus)
Input:
rest_l
(remainder of
bas
e_l
mod
m_l
)
Output:
E_CLINT_OK
if all is ok
E_CLINT_DBZ
if division by 0
Return:
int
wmexp_l (USHORT bas, CLINT e_l, CLINT rest_l, CLINT m_l)
{
CLINT p_l, z_l;
USHORT k, b, w;
if (EQZ_L (m_l))
{
return E_CLINT_DBZ;
/* division by 0 */
}
if (EQONE_L (m_l))
{
SETZERO_L (rest_l);
/* modulus = 1 ==> remainder=0*/
return E_CLINT_OK;
}
if (EQZ_L (e_l))
{
SETONE_L (rest_l);
return E_CLINT_OK;
}
if (0 == bas)
{
SETZERO_L (rest_l);
return E_CLINT_OK;
}
SETONE_L (p_l);
cpy_l (z_l, e_l);