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