Cryptography Reference
In-Depth Information
i--;
for ( mask = 0x01; mask; mask <<= 1 )
{
if ( mask & h2->rep[ i ] )
{
add( h1, &temp );
}
left_shift( &temp );
}
}
while ( i );
}
First, notice that you need a couple of utility routines:
copy_huge
,
free_huge
,
and
set_huge
. The implementations of the fi rst two are straightforward in
Listing 3-10.
Listing 3-10:
“huge.c” copy_huge and free_huge
void copy_huge( huge *tgt, huge *src )
{
if ( tgt->rep )
{
free( tgt->rep );
}
tgt->size = src->size;
tgt->rep = ( unsigned char * )
calloc( src->size, sizeof( unsigned char ) );
memcpy( tgt->rep, src->rep,
( src->size * sizeof( unsigned char ) ) );
}
void free_huge( huge *h )
{
if ( h->rep )
{
free( h->rep );
}
}
To be more generally useful,
set_huge
is perhaps a bit more complex than
you would expect. After all, what you're doing here is copying an
int
into a
byte array. However, you need to be as space-effi cient as possible, so you need
to look at the
int
in question and fi gure out the minimum number of bytes that
it can fi t into. Note that this space-effi ciency isn't merely a performance concern;
Search WWH ::
Custom Search