/* -*-c-*-
*
- * $Id: dsarand.c,v 1.1 1999/12/22 15:53:12 mdw Exp $
+ * $Id: dsarand.c,v 1.3 2001/02/03 16:08:56 mdw Exp $
*
* Random number generator for DSA
*
/*----- Revision history --------------------------------------------------*
*
* $Log: dsarand.c,v $
+ * Revision 1.3 2001/02/03 16:08:56 mdw
+ * Give generic random objects separate namespaces for their supported misc
+ * ops. Add operations for reading the current seed value.
+ *
+ * Revision 1.2 2000/06/17 10:54:00 mdw
+ * Typesetting fixes. Arena support.
+ *
* Revision 1.1 1999/12/22 15:53:12 mdw
* Random number generator for finding DSA parameters.
*
#include <stdarg.h>
#include <string.h>
+#include <mLib/alloc.h>
#include <mLib/bits.h>
#include <mLib/sub.h>
{
d->p = xmalloc(sz);
d->sz = sz;
+ d->passes = 1;
if (p)
memcpy(d->p, p, sz);
}
void dsarand_reseed(dsarand *d, const void *p, size_t sz)
{
- free(d->p);
+ xfree(d->p);
d->p = xmalloc(sz);
d->sz = sz;
d->passes = 1;
void dsarand_destroy(dsarand *d)
{
- free(d->p);
+ xfree(d->p);
}
/* --- @dsarand_fill@ --- *
*
* Let %$p$% be the numerical value of the input buffer, and let
* %$b$% be the number of bytes required. Let
- * %$z = \lceil b / 20 \rceil%$ be the number of SHA outputs
+ * %$z = \lceil b / 20 \rceil$% be the number of SHA outputs
* required. Then the output of pass %$n$% is
*
* %$P_n = \sum_{0 \le i < z} 2^{160i} SHA(p + nz + i)$%
case GRAND_SEEDBLOCK:
case GRAND_SEEDRAND:
case DSARAND_PASSES:
+ case DSARAND_SEEDSZ:
+ case DSARAND_GETSEED:
rc = 1;
break;
default:
case DSARAND_PASSES:
g->d.passes = va_arg(ap, unsigned);
break;
+ case DSARAND_SEEDSZ:
+ rc = g->d.sz;
+ break;
+ case DSARAND_GETSEED:
+ memcpy(va_arg(ap, void *), g->d.p, g->d.sz);
+ break;
default:
GRAND_BADOP;
break;
static const grand_ops gops = {
"dsarand",
- 0,
+ 0, 0,
gmisc, gdestroy,
grand_word, grand_byte, grand_word, grand_range, gfill
};