Cryptography Reference
In-Depth Information
{
int i, out_len = 0;
huge c, m;
int modulus_length = private_key->modulus->size;
unsigned char *padded_block = ( unsigned char * ) malloc(
modulus_length );
*output = NULL;
while ( len )
{
if ( len < modulus_length )
{
fprintf( stderr, “Error - input must be an even multiple \
of key modulus %d (got %d)\n”,
private_key->modulus->size, len );
free( padded_block );
return -1;
}
load_huge( &c, input, modulus_length );
mod_pow( &c, private_key->exponent,
private_key->modulus, &m );
unload_huge( &m, padded_block, modulus_length );
if ( padded_block[ 1 ] > 0x02 )
{
fprintf( stderr, “Decryption error or unrecognized block \
type %d.\n”, padded_block[ 1 ] );
free_huge( &c );
free_huge( &m );
free( padded_block );
return -1;
}
// Find next 0 byte after the padding type byte; this signifies
// start-of-data
i = 2;
while ( padded_block[ i++ ] );
out_len += modulus_length - i;
*output = realloc( *output, out_len );
memcpy( *output + ( out_len - ( modulus_length - i ) ),
padded_block + i, modulus_length - i );
len -= modulus_length;
input += modulus_length;
(Continued)
Search WWH ::




Custom Search