3 * $Id: rabin.h,v 1.4 2000/06/17 11:52:48 mdw Exp $
5 * Miller-Rabin primality test
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.4 2000/06/17 11:52:48 mdw
36 * Revision 1.3 1999/12/22 15:50:29 mdw
37 * Reworking for new prime-search system. Add function for working out how
38 * many iterations to use for a particular number.
40 * Revision 1.2 1999/12/10 23:29:48 mdw
41 * Change header file guard names.
43 * Revision 1.1 1999/11/19 13:17:57 mdw
44 * Prime number generator and tester.
48 #ifndef CATACOMB_RABIN_H
49 #define CATACOMB_RABIN_H
55 /*----- Header files ------------------------------------------------------*/
61 #ifndef CATACOMB_MPMONT_H
65 #ifndef CATACOMB_PFILT_H
69 /*----- Data structures ---------------------------------------------------*/
71 typedef struct rabin
{
72 mpmont mm
; /* Montgomery arithmetic context */
73 size_t s
; /* %$m = 2^s r + 1$% */
74 mp
*r
; /* %$m = 2^s r + 1$% */
75 mp
*m1
; /* %$(m - 1)R \bmod m$% */
78 /*----- Functions provided ------------------------------------------------*/
80 /* --- @rabin_create@ --- *
82 * Arguments: @rabin *r@ = pointer to Rabin-Miller context
83 * @mp *m@ = pointer to number to test
87 * Use: Precomputes some useful values for performing the
88 * Miller-Rabin probabilistic primality test.
91 extern void rabin_create(rabin */
*r*/
, mp */
*m*/
);
93 /* --- @rabin_destroy@ --- *
95 * Arguments: @rabin *r@ = pointer to Rabin-Miller context
99 * Use: Disposes of a Rabin-Miller context when it's no longer
103 extern void rabin_destroy(rabin */
*r*/
);
105 /* --- @rabin_test@ --- *
107 * Arguments: @rabin *r@ = pointer to Rabin-Miller context
108 * @mp *g@ = base to test the number against
110 * Returns: Either @PGEN_FAIL@ if the test failed, or @PGEN_TRY@
113 * Use: Performs a single iteration of the Rabin-Miller primality
117 extern int rabin_test(rabin */
*r*/
, mp */
*g*/
);
119 /* --- @rabin_iters@ --- *
121 * Arguments: @unsigned len@ = number of bits in value
123 * Returns: Number of iterations recommended.
125 * Use: Returns the recommended number of iterations to ensure that a
126 * number with @len@ bits is really prime.
129 extern int rabin_iters(unsigned /*len*/);
131 /*----- That's all, folks -------------------------------------------------*/