Refactor {client,server}_random to call an intermediate function
authorNick Mathewson <nickm@torproject.org>
Wed, 9 Oct 2013 14:28:42 +0000 (10:28 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 9 Oct 2013 14:28:42 +0000 (10:28 -0400)
I'll be using this to make an option for randomizing the time.

ssl/d1_clnt.c
ssl/d1_srvr.c
ssl/s23_clnt.c
ssl/s3_clnt.c
ssl/s3_srvr.c
ssl/ssl_locl.h

index bfde14e09f1f5fc4517598e4011e14b3bcab19bf..556ac9ccc7a5e54ab6a21b116c8e6ad07401f7f9 100644 (file)
@@ -801,7 +801,7 @@ int dtls1_client_hello(SSL *s)
                for (i=0;p[i]=='\0' && i<sizeof(s->s3->client_random);i++) ;
                if (i==sizeof(s->s3->client_random))
                        {
-                       RAND_pseudo_bytes(p,sizeof(s->s3->client_random));
+                       ssl_fill_hello_random(s,0,p,sizeof(s->s3->client_random));
                        }
 
                /* Do the message type and length last */
index 5b0c86a3ab8cdf038ae55b99c191bb1291f11d80..9563066bd1b05fa82c75be7c14b2aba5135dd45b 100644 (file)
@@ -918,7 +918,7 @@ int dtls1_send_server_hello(SSL *s)
                {
                buf=(unsigned char *)s->init_buf->data;
                p=s->s3->server_random;
-               RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE);
+               ssl_fill_hello_random(s, 1, p, SSL3_RANDOM_SIZE);
                /* Do the message type and length last */
                d=p= &(buf[DTLS1_HM_HEADER_LENGTH]);
 
index c9ef0f5cfce6a4823edd2c7f0b8a24dc15a3c237..01e492adfbd48c8751554c110e836b2d51a37187 100644 (file)
@@ -269,6 +269,13 @@ static int ssl23_no_ssl2_ciphers(SSL *s)
        return 1;
        }
 
+/* Fill a ClientRandom or ServerRandom field of length len. Returns <= 0
+ * on failure, 1 on success. */
+int ssl_fill_hello_random(SSL *s, int server, unsigned char *result, int len)
+       {
+       return RAND_pseudo_bytes(result, len);
+       }
+
 static int ssl23_client_hello(SSL *s)
        {
        unsigned char *buf;
@@ -355,7 +362,7 @@ static int ssl23_client_hello(SSL *s)
 #endif
 
                p=s->s3->client_random;
-               if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE) <= 0)
+               if (ssl_fill_hello_random(s, 0, p, SSL3_RANDOM_SIZE) <= 0)
                        return -1;
 
                if (version == TLS1_2_VERSION)
index 1b540112522720e21a70cfbffc164ae9b593066e..a6b3c01afa18ae7c26e87f45296131cc4e092dd3 100644 (file)
@@ -680,7 +680,8 @@ int ssl3_client_hello(SSL *s)
                /* else use the pre-loaded session */
 
                p=s->s3->client_random;
-               if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE) <= 0)
+
+               if (ssl_fill_hello_random(s, 0, p, SSL3_RANDOM_SIZE) <= 0)
                        goto err;
 
                /* Do the message type and length last */
index 511f5bef4cb03cfdc59fcfd981fbc268132b6a99..508239fce5276c67c79aa0b4f0113674b17afa7e 100644 (file)
@@ -1194,8 +1194,8 @@ int ssl3_get_client_hello(SSL *s)
         * SessionTicket processing to use it in key derivation. */
        {
                unsigned char *pos;
-               pos=s->s3->server_random;
-               if (RAND_pseudo_bytes(pos,SSL3_RANDOM_SIZE) <= 0)
+               pos=s->s3->server_random;
+               if (ssl_fill_hello_random(s,1,pos,SSL3_RANDOM_SIZE) <= 0)
                        {
                        al=SSL_AD_INTERNAL_ERROR;
                        goto f_err;
index 1b98947e677bb6ccf8a0335108509d1eabfac37b..96ce9a72458d8b98a1cca001665761b79a2ac63b 100644 (file)
@@ -847,6 +847,7 @@ void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher);
 STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
 int ssl_verify_alarm_type(long type);
 void ssl_load_ciphers(void);
+int ssl_fill_hello_random(SSL *s, int server, unsigned char *field, int len);
 
 int ssl2_enc_init(SSL *s, int client);
 int ssl2_generate_key_material(SSL *s);