Add support for seeding from a generic pseudorandom source.
[u/mdw/catacomb] / bbs-rand.c
index 054a158..006bc07 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: bbs-rand.c,v 1.1 1999/12/10 23:14:59 mdw Exp $
+ * $Id: bbs-rand.c,v 1.2 1999/12/13 15:34:01 mdw Exp $
  *
  * Blum-Blum-Shub secure random number generator
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: bbs-rand.c,v $
+ * Revision 1.2  1999/12/13 15:34:01  mdw
+ * Add support for seeding from a generic pseudorandom source.
+ *
  * Revision 1.1  1999/12/10 23:14:59  mdw
  * Blum-Blum-Shub generator, and Blum-Goldwasser encryption.
  *
@@ -49,6 +52,7 @@
 #include "mp.h"
 #include "mpbarrett.h"
 #include "mpint.h"
+#include "mprand.h"
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -245,6 +249,7 @@ static int gmisc(grand *r, unsigned op, ...)
         case GRAND_SEEDINT:
         case GRAND_SEEDUINT32:
         case GRAND_SEEDMP:
+       case GRAND_SEEDRAND:
        case BBS_SET:
           rc = 1;
           break;
@@ -266,6 +271,12 @@ static int gmisc(grand *r, unsigned op, ...)
     case GRAND_SEEDMP:
       bbs_seed(&g->b, va_arg(ap, mp *));
       break;
+    case GRAND_SEEDRAND: {
+      grand *rr = va_arg(ap, grand *);
+      mp *m = mprand(MP_NEW, mp_bits(g->b.mb.m) - 1, rr, 0);
+      bbs_seed(&g->b, m);
+      mp_drop(m);
+    } break;
     case BBS_SET:
       bbs_set(&g->b, va_arg(ap, mp *));
       break;