From 975679c728722cd4f201ed67eeba83560fdcb5d6 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 11 Feb 2006 15:37:20 +0000 Subject: [PATCH] pgen-safe: Expunge. No trace remains. This is an incompatible change, but I doubt anybody cares. The high-level key-generation functions still exist and do the same things they ever did. --- Makefile.m4 | 2 +- pgen-safe.c | 199 ------------------------------------------------------------ pgen.h | 39 ------------ 3 files changed, 1 insertion(+), 239 deletions(-) delete mode 100644 pgen-safe.c diff --git a/Makefile.m4 b/Makefile.m4 index 960e8e8..98218ba 100644 --- a/Makefile.m4 +++ b/Makefile.m4 @@ -202,7 +202,7 @@ define(`EC_SOURCES', define(`PGEN_SOURCES', `pfilt.c rabin.c \ - pgen.c pgen-stdev.c pgen-safe.c pgen-gcd.c pgen-simul.c \ + pgen.c pgen-stdev.c pgen-gcd.c pgen-simul.c \ prim.c strongprime.c limlee.c \ keycheck.c keycheck-mp.c keycheck-report.c \ bbs-rand.c bbs-gen.c bbs-jump.c bbs-fetch.c \ diff --git a/pgen-safe.c b/pgen-safe.c deleted file mode 100644 index bd644dc..0000000 --- a/pgen-safe.c +++ /dev/null @@ -1,199 +0,0 @@ -/* -*-c-*- - * - * $Id: pgen-safe.c,v 1.5 2004/04/08 01:36:15 mdw Exp $ - * - * Safe prime generation - * - * (c) 1999 Straylight/Edgeware - */ - -/*----- Licensing notice --------------------------------------------------* - * - * This file is part of Catacomb. - * - * Catacomb is free software; you can redistribute it and/or modify - * 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, - * MA 02111-1307, USA. - */ - -/*----- Header files ------------------------------------------------------*/ - -#include "mp.h" -#include "mprand.h" -#include "pgen.h" - -/*----- Main code ---------------------------------------------------------*/ - -/* --- @pgen_safestep@ --- * - * - * Steps two numbers, %$q$% and %$p = 2q + 1$%, such that neither has any - * small factors. %$p$% is put in the event block. - */ - -int pgen_safestep(int rq, pgen_event *ev, void *p) -{ - pgen_safestepctx *c = p; - int rc = PGEN_ABORT, qrc = 0; - - switch (rq) { - - /* --- Set up the contexts --- */ - - case PGEN_BEGIN: { - mp *p = mp_split(MP_COPY(ev->m)); - mp *q; - p->v[0] |= 3; - q = mp_lsr(MP_NEW, p, 1); - rc = pfilt_create(&c->p, p); - qrc = pfilt_create(&c->q, q); - mp_drop(p); mp_drop(q); - } break; - - /* --- Step along --- */ - - case PGEN_TRY: - mp_drop(ev->m); - rc = pfilt_step(&c->p, 4); - qrc = pfilt_step(&c->q, 2); - break; - - break; - - /* --- Tidy the toys away --- */ - - case PGEN_DONE: - pfilt_destroy(&c->q); - pfilt_destroy(&c->p); - return (PGEN_DONE); - } - - /* --- Continue stepping if necessary --- */ - - while (rc == PGEN_FAIL || qrc == PGEN_FAIL) { - rc = pfilt_step(&c->p, 4); - qrc = pfilt_step(&c->q, 2); - } - - ev->m = MP_COPY(c->p.m); - if (qrc == PGEN_TRY) - rc = PGEN_TRY; - return (rc); -} - -/* --- @pgen_safejump@ --- * - * - * Jumps two numbers, %$q$% and %$p = 2q + 1$% such that neither has any - * small factors. - */ - -int pgen_safejump(int rq, pgen_event *ev, void *p) -{ - pgen_safejumpctx *j = p; - int rc = PGEN_ABORT, qrc = 0; - - switch (rq) { - - /* --- Set up the jump contexts --- * - * - * The jump in @j.q@ is congruent to 2 (mod 4); see @strongprime_setup@. - * If @p@ is initially 1 (mod 4) then add @j.q@. Then double @j.q@ to - * ensure that the step is 0 (mod 4). Ensure that @jq@ and @q@ don't - * have any common factors. - */ - - case PGEN_BEGIN: { - mp *p = ev->m; - mp *q; - mp *g = MP_NEW; - if ((p->v[0] & 3) != 3) - p = mp_add(p, p, j->jq.m); - q = mp_lsr(MP_NEW, p, 1); - mp_gcd(&g, 0, 0, p, j->jq.m); - if (MP_CMP(g, >, MP_ONE)) { - ev->m = p; - mp_drop(q); - mp_drop(g); - return (PGEN_ABORT); - } - mp_drop(g); - rc = pfilt_create(&j->p, p); - pfilt_muladd(&j->jp, &j->jq, 2, 0); - qrc = pfilt_create(&j->q, q); - mp_drop(p); - mp_drop(q); - } break; - - /* --- Step on one place --- */ - - case PGEN_TRY: - mp_drop(ev->m); - rc = pfilt_jump(&j->p, &j->jp); - qrc = pfilt_jump(&j->q, &j->jq); - break; - - /* --- Tidy everything up --- */ - - case PGEN_DONE: - pfilt_destroy(&j->jp); - pfilt_destroy(&j->p); - pfilt_destroy(&j->q); - return (PGEN_DONE); - } - - /* --- Step on while @p@ or @q@ have small factors --- */ - - while (rc == PGEN_FAIL || qrc == PGEN_FAIL) { - rc = pfilt_jump(&j->p, &j->jp); - qrc = pfilt_jump(&j->q, &j->jq); - } - ev->m = MP_COPY(j->p.m); - if (qrc == PGEN_TRY) - rc = PGEN_TRY; - return (rc); -} - -/* --- @pgen_safetest@ --- * - * - * Applies Rabin-Miller tests to %$p$% and %$q$%. - */ - -int pgen_safetest(int rq, pgen_event *ev, void *p) -{ - pgen_safetestctx *c = p; - int rc = PGEN_ABORT; - - switch (rq) { - case PGEN_BEGIN: - rabin_create(&c->q, c->c.q.m); - rabin_create(&c->p, c->c.p.m); - rc = PGEN_TRY; - break; - case PGEN_TRY: { - mp *m = mprand_range(MP_NEW, c->c.p.m, ev->r, 0); - rc = rabin_test(&c->p, m); - if (rc == PGEN_PASS) { - m = mprand_range(m, c->c.q.m, ev->r, 0); - rc = rabin_test(&c->q, m); - } - mp_drop(m); - } break; - case PGEN_DONE: - rabin_destroy(&c->q); - rabin_destroy(&c->p); - break; - } - return (rc); -} - -/*----- That's all, folks -------------------------------------------------*/ diff --git a/pgen.h b/pgen.h index 52e62bb..a80fefa 100644 --- a/pgen.h +++ b/pgen.h @@ -204,45 +204,6 @@ extern pgen_proc pgen_simulstep; extern pgen_proc pgen_simultest; -/*----- Safe prime functions ----------------------------------------------*/ - -/* --- @pgen_safestep@ --- * - * - * Steps two numbers, %$q$% and %$p = 2q + 1$%, such that neither has any - * small factors. %$p$% is put in the event block. - */ - -typedef struct pgen_safestepctx { - pfilt q, p; -} pgen_safestepctx; - -extern pgen_proc pgen_safestep; - -/* --- @pgen_safejump@ --- * - * - * Jumps two numbers, %$q$% and %$p = 2q + 1$% such that neither has any - * small factors. - */ - -typedef struct pgen_safejumpctx { - pfilt q, jq; - pfilt p, jp; -} pgen_safejumpctx; - -extern pgen_proc pgen_safejump; - -/* --- @pgen_safetest@ --- * - * - * Applies Rabin-Miller tests to %$p$% and %$(p - 1)/2$%. - */ - -typedef struct pgen_safetestctx { - pgen_safestepctx c; - rabin q, p; -} pgen_safetestctx; - -extern pgen_proc pgen_safetest; - /*----- Miscellaneous steppers and testers --------------------------------*/ typedef struct pgen_gcdstepctx { -- 2.11.0