/* -*-c-*-
*
- * $Id: dh-prime.c,v 1.1 1999/11/20 22:24:44 mdw Exp $
+ * $Id: dh-prime.c,v 1.2 1999/12/10 23:18:38 mdw Exp $
*
* Generate (safe) Diffie-Hellman primes
*
/*----- Revision history --------------------------------------------------*
*
* $Log: dh-prime.c,v $
+ * Revision 1.2 1999/12/10 23:18:38 mdw
+ * Change interface for suggested destinations.
+ *
* Revision 1.1 1999/11/20 22:24:44 mdw
* Add Diffie-Hellman support.
*
#include <string.h>
#include "dh.h"
+#include "fibrand.h"
#include "mp.h"
+#include "mprand.h"
#include "pgen.h"
#include "rabin.h"
{
pgen pq, pp;
int rc_q, rc_p;
- mpw bw;
- mp b;
+ grand *gr = fibrand_create(0);
+ mp *b = MP_NEW;
+ size_t sz = mp_bits(s);
/* --- Initialize prime generators --- */
rc_q = pgen_create(&pq, s);
rc_p = pgen_muladd(&pp, &pq, 2, 1);
- mp_build(&b, &bw, &bw + 1);
/* --- Now step along until something crops up --- */
*/
for (i = 0; i < 5; i++) {
- bw = ptab[i];
+ b = mprand(b, sz, gr, 1);
if (rc_q == PGEN_MAYBE &&
- (rc_q = rabin_test(&rq, &b)) == PGEN_COMPOSITE)
+ (rc_q = rabin_test(&rq, b)) == PGEN_COMPOSITE)
break;
if (rc_p == PGEN_MAYBE &&
- (rc_p = rabin_test(&rp, &b)) == PGEN_COMPOSITE)
+ (rc_p = rabin_test(&rp, b)) == PGEN_COMPOSITE)
break;
if (proc && proc(DHEV_PASS, arg))
break;
mp *p = MP_COPY(pp.m);
pgen_destroy(&pq);
pgen_destroy(&pp);
+ mp_drop(b);
+ gr->ops->destroy(gr);
return (p);
}
fail:
pgen_destroy(&pq);
pgen_destroy(&pp);
+ mp_drop(b);
+ gr->ops->destroy(gr);
return (0);
}