Generic interface.
[u/mdw/catacomb] / rabin.h
CommitLineData
0f5ec153 1/* -*-c-*-
2 *
3 * $Id: rabin.h,v 1.1 1999/11/19 13:17:57 mdw Exp $
4 *
5 * Miller-Rabin primality test
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
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.
18 *
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.
23 *
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,
27 * MA 02111-1307, USA.
28 */
29
30/*----- Revision history --------------------------------------------------*
31 *
32 * $Log: rabin.h,v $
33 * Revision 1.1 1999/11/19 13:17:57 mdw
34 * Prime number generator and tester.
35 *
36 */
37
38#ifndef RABIN_H
39#define RABIN_H
40
41#ifdef __cplusplus
42 extern "C" {
43#endif
44
45/*----- Header files ------------------------------------------------------*/
46
47#ifndef MP_H
48# include "mp.h"
49#endif
50
51#ifndef MPMONT_H
52# include "mpmont.h"
53#endif
54
55#ifndef PGEN_H
56# include "pgen.h"
57#endif
58
59/*----- Data structures ---------------------------------------------------*/
60
61typedef struct rabin {
62 mpmont mm; /* Montgomery arithmetic context */
63 size_t s; /* %$m = 2^s r + 1$% */
64 mp *r; /* %$m = 2^s r + 1$% */
65 mp *m1; /* %$(m - 1)R \bmod m */
66} rabin;
67
68/*----- Functions provided ------------------------------------------------*/
69
70/* --- @rabin_create@ --- *
71 *
72 * Arguments: @rabin *r@ = pointer to Rabin-Miller context
73 * @mp *m@ = pointer to number to test
74 *
75 * Returns: ---
76 *
77 * Use: Precomputes some useful values for performing the
78 * Miller-Rabin probabilistic primality test.
79 */
80
81extern void rabin_create(rabin */*r*/, mp */*m*/);
82
83/* --- @rabin_destroy@ --- *
84 *
85 * Arguments: @rabin *r@ = pointer to Rabin-Miller context
86 *
87 * Returns: ---
88 *
89 * Use: Disposes of a Rabin-Miller context when it's no longer
90 * needed.
91 */
92
93extern void rabin_destroy(rabin */*r*/);
94
95/* --- @rabin_test@ --- *
96 *
97 * Arguments: @rabin *r@ = pointer to Rabin-Miller context
98 * @mp *g@ = base to test the number against
99 *
100 * Returns: Either @PGEN_COMPOSITE@ if the test failed, or @PGEN_MAYBE@
101 * if it succeeded.
102 *
103 * Use: Performs a single iteration of the Rabin-Miller primality
104 * test.
105 */
106
107extern int rabin_test(rabin */*r*/, mp */*g*/);
108
109/*----- That's all, folks -------------------------------------------------*/
110
111#ifdef __cplusplus
112 }
113#endif
114
115#endif