Cryptography Reference
In-Depth Information
{
result_sign = h1->sign;
if ( h1->sign == h2->sign )
{
add_magnitude( h1, h2 );
}
else
{
subtract_magnitude( h1, h2 );
}
}
else
{
huge tmp;
// put h1 into tmp and h2 into h1 to swap the operands
set_huge( &tmp, 0 ); // initialize
copy_huge( &tmp, h1 );
copy_huge( h1, h2 );
if ( h1->sign == tmp.sign )
{
result_sign = h1->sign;
add_magnitude( h1, &tmp );
}
else
{
result_sign = h2->sign;
subtract_magnitude( h1, &tmp );
}
free_huge( &tmp );
}
// Use the stored sign to set the result
h1->sign = result_sign;
}
5. This routine embodies the signing rules described by the fi rst half of
Table 3-2. If
h1
is greater than
h2
(see Figure 3-7), add or subtract, depend-
ing on whether the signs of the two operands are the same or different,
and preserve the sign of
h1
.
h2
never changes regardless. If
h1
is less
than
h2
, swap them; you want to preserve
h2
as before, so copy
h1
into
a temporary object and
h2
into
h1
.
The net effect here is that you add or subtract
h1
from
h2
, overwriting
h1
,
just as if the operation had been called with the operators reversed, but
not touching
h2
, which is what you want.
Search WWH ::
Custom Search