ct.c, ct.h: New constant-time operations.
[u/mdw/catacomb] / rand.c
diff --git a/rand.c b/rand.c
index 827474b..b004b3f 100644 (file)
--- a/rand.c
+++ b/rand.c
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: rand.c,v 1.6 2004/04/08 01:36:15 mdw Exp $
+ * $Id$
  *
  * Secure random number generator
  *
  * (c) 1998 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of Catacomb.
  *
  * it under the terms of the GNU Library General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
- * 
+ *
  * Catacomb is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Library General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Library General Public
  * License along with Catacomb; if not, write to the Free
  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
@@ -213,9 +213,9 @@ void rand_add(rand_pool *r, const void *p, size_t sz, unsigned goodbits)
 
 /* --- @rand_goodbits@ --- *
  *
- * Arguments:   @rand_pool *r@ = pointer to a randomness pool
+ * Arguments:  @rand_pool *r@ = pointer to a randomness pool
  *
- * Returns:     Estimate of the number of good bits remaining in the pool.
+ * Returns:    Estimate of the number of good bits remaining in the pool.
  */
 
 unsigned rand_goodbits(rand_pool *r)
@@ -464,6 +464,9 @@ static int gmisc(grand *r, unsigned op, ...)
        case RAND_KEY:
        case RAND_NOISESRC:
        case RAND_SEED:
+       case RAND_TIMER:
+       case RAND_GOODBITS:
+       case RAND_ADD:
          rc = 1;
          break;
        default:
@@ -507,6 +510,18 @@ static int gmisc(grand *r, unsigned op, ...)
     case RAND_SEED:
       rand_seed(&g->p, va_arg(ap, unsigned));
       break;
+    case RAND_TIMER:
+      TIMER(&g->p);
+      break;
+    case RAND_GOODBITS:
+      rc = rand_goodbits(&g->p);
+      break;
+    case RAND_ADD: {
+      const void *p = va_arg(ap, const void *);
+      size_t sz = va_arg(ap, size_t);
+      unsigned goodbits = va_arg(ap, unsigned);
+      rand_add(&g->p, p, sz, goodbits);
+    } break;
     default:
       GRAND_BADOP;
       break;