[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Make crypto_pseudo_rand* never fail.



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv21871/or

Modified Files:
	connection_edge.c onion.c 
Log Message:
Make crypto_pseudo_rand* never fail.

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- connection_edge.c	11 Nov 2003 19:47:51 -0000	1.51
+++ connection_edge.c	12 Nov 2003 04:12:35 -0000	1.52
@@ -608,11 +608,8 @@
   assert(ap_conn->socks_request);
   assert(ap_conn->socks_request->addr);
 
-  if(crypto_pseudo_rand(STREAM_ID_SIZE, ap_conn->stream_id) < 0) {
-    /* XXX can we just make this call abort if it fails? then this func could be a void. */
-    /* FIXME check for collisions */
-    return -1;
-  }
+  crypto_pseudo_rand(STREAM_ID_SIZE, ap_conn->stream_id);
+  /* FIXME check for collisions */
 
   memcpy(payload, ap_conn->stream_id, STREAM_ID_SIZE);
   payload_len = STREAM_ID_SIZE + 1 +

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- onion.c	12 Nov 2003 02:58:45 -0000	1.79
+++ onion.c	12 Nov 2003 04:12:35 -0000	1.80
@@ -160,17 +160,13 @@
 /* uses a weighted coin with weight cw to choose a route length */
 static int chooselen(double cw) {
   int len = 2;
-  uint8_t coin;
   
   if ((cw < 0) || (cw >= 1)) /* invalid parameter */
     return -1;
   
   while(1)
   {
-    if (CRYPTO_PSEUDO_RAND_INT(coin))
-      return -1;
-    
-    if (coin > cw*255) /* don't extend */
+    if (crypto_pseudo_rand_int(255) > cw*255) /* don't extend */
       break;
     else
       len++;
@@ -279,10 +275,7 @@
   log_fn(LOG_DEBUG, "Path is %d long; we want %d", cur_len, path_len);
 
  again:
-  if (CRYPTO_PSEUDO_RAND_INT(choice)) {
-    return -1;
-  }
-  choice %= rarray_len;
+  choice = crypto_pseudo_rand_int(rarray_len);
   log_fn(LOG_DEBUG,"Contemplating router %s for hop %d",
          rarray[choice]->nickname, cur_len);
   for (i = 0, cpath = *head_ptr; i < cur_len; ++i, cpath=cpath->next) {