Cryptography Reference
In-Depth Information
return NULL;
}
break;
default:
fprintf( stderr, “Error, unsupported curve type %d.\n”,
curve_type );
return NULL;
}
// Followed by a length-delimited (opaque) public key.
read_pos = read_buffer( ( void * ) &public_key_length, read_pos, 1 );
read_pos = read_buffer( ( void * ) &point_type, read_pos, 1 );
if ( point_type == uncompressed )
{
load_huge( &parameters->server_ecdh_key.x, read_pos,
( public_key_length - 1 ) / 2 );
load_huge( &parameters->server_ecdh_key.y,
( read_pos + ( ( public_key_length - 1 ) / 2 ) ),
( ( public_key_length - 1 ) / 2 ) );
read_pos += ( public_key_length - 1 );
// Read and verify the signature
memcpy( &length, read_pos, 2 );
length = ntohs( length );
read_pos += 2;
if ( !verify_signature( dh_params, ( read_pos - 2 - dh_params ),
read_pos, length, parameters ) )
{
return NULL;
}
read_pos += length;
}
else
{
printf( “point type %d\n”, point_type );
fprintf( stderr, “Error, compressed ECDH public keys not supported.\n” );
return NULL;
}
break;
default:
// XXX assume DHE if not ECDHE
for ( i = 0; i < 4; i++ )
{
Most of the logic here surrounds erroring out if any of the unsupported
options are presented. This code handles the simplest case, when the server
uses a named curve and presents the public key in uncompressed format.
The fi rst part of this is pretty similar to the public key parsing in Listing 9-35,
which is unsurprising because both functions are parsing an ECC public key.
Search WWH ::




Custom Search