Cryptography Reference
In-Depth Information
{
while ( head->next != NULL )
{
head = ( StoredSessionsList * ) head->next;
}
head->next = malloc( sizeof( StoredSessionsList ) );
head = ( StoredSessionsList * ) head->next;
}
head->session_id_length = parameters->session_id_length;
memcpy( head->session_id, &session_id, head->session_id_length );
memcpy( head->master_secret, parameters->master_secret,
MASTER_SECRET_LENGTH );
head->next = NULL;
}
}
Figure 8-3 illustrates how this would be laid out in memory if you stored,
for example, six sessions with IDs 100, 106, 199, 200, 299, and 599. Each entry in
the stored_sessions array is a pointer to a linked list of every session whose
ID is equal to its index, mod 100.
If you've ever studied data structures, this common technique for balancing
storage space with lookup speed ought to look familiar. Listing 8-13 is the cor-
responding retrieval function.
Listing 8-13: “tls.c” fi nd_stored_session
/**
* Check to see if the requested session ID is stored in the local cache.
* If the session ID is recognized, parameters will be updated to include
* it, and the master secret will be stored in the parameters.
* If it is not recognized, the session
* ID in the parameters will be left empty, indicating that a new handshake
* should commence.
*/
static void find_stored_session( int session_id_length,
const unsigned char *session_id,
TLSParameters *parameters )
{
int session_id_num;
StoredSessionsList *head;
if ( session_id_length > sizeof( int ) )
{
// Definitely didn't come from this server.
return;
}
memcpy( &session_id_num, session_id, session_id_length );
for ( head = stored_sessions[ session_id_num % HASH_TABLE_SIZE ];
(Continued)
 
Search WWH ::




Custom Search