Cryptography Reference
In-Depth Information
Listing 6-6: “tls.c” init_parameters
static void init_protection_parameters( ProtectionParameters *parameters )
{
parameters->MAC_secret = NULL;
parameters->key = NULL;
parameters->IV = NULL;
}
static void init_parameters( TLSParameters *parameters )
{
init_protection_parameters( &parameters->pending_send_parameters );
init_protection_parameters( &parameters->pending_recv_parameters );
init_protection_parameters( &parameters->active_send_parameters );
init_protection_parameters( &parameters->active_recv_parameters );
memset( parameters->master_secret, '\0', MASTER_SECRET_LENGTH );
memset( parameters->client_random, '\0', RANDOM_LENGTH );
memset( parameters->server_random, '\0', RANDOM_LENGTH );
}
So, tls_connect , shown partially in Listing 6-7, starts off by calling
init_parameters .
Listing 6-7: “tls.c” tls_connect
/**
* Negotiate TLS parameters on an already-established socket.
*/
int tls_connect( int connection,
TLSParameters *parameters )
{
init_parameters( parameters );
// Step 1. Send the TLS handshake “client hello” message
if ( send_client_hello( connection, parameters ) < 0 )
{
perror( “Unable to send client hello” );
return 1;
}
Recall from the overview that the fi rst thing the client should do is send a
client hello message. The structure of this message is defi ned in Listing 6-8.
Listing 6-8: “tls.h” client hello structure
typedef struct
{
unsigned char major, minor;
}
ProtocolVersion;
Search WWH ::




Custom Search