Implementation of the Digital Signature Algorithm.
[u/mdw/catacomb] / pgen.h
CommitLineData
0f5ec153 1/* -*-c-*-
2 *
3 * $Id: pgen.h,v 1.1 1999/11/19 13:17:57 mdw Exp $
4 *
5 * Finding and testing prime numbers
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: pgen.h,v $
33 * Revision 1.1 1999/11/19 13:17:57 mdw
34 * Prime number generator and tester.
35 *
36 */
37
38#ifndef PGEN_H
39#define PGEN_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 PTAB_H
52# include "ptab.h"
53#endif
54
55/*----- Constants ---------------------------------------------------------*/
56
57#define PGEN_COMPOSITE (-1) /* Number is definitely composite */
58#define PGEN_MAYBE (0) /* Number may be prime */
59#define PGEN_PRIME (1) /* Number is definitely prime */
60
61/*----- Data structures ---------------------------------------------------*/
62
63typedef struct pgen {
64 mp *m;
65 unsigned char r[NPRIME];
66} pgen;
67
68/*----- Functions provided ------------------------------------------------*/
69
70/* --- @pgen_create@ --- *
71 *
72 * Arguments: @pgen *p@ = pointer to prime generation context
73 * @mp *m@ = pointer to initial number to test
74 *
75 * Returns: One of the @PGEN@ constants above.
76 *
77 * Use: Tests an initial number for primality by computing its
78 * residue modulo various small prime numbers. This is fairly
79 * quick, but not particularly certain. If a @PGEN_MAYBE@
80 * result is returned, perform Rabin-Miller tests to confirm.
81 */
82
83extern int pgen_create(pgen */*p*/, mp */*m*/);
84
85/* --- @pgen_destroy@ --- *
86 *
87 * Arguments: @pgen *p@ = pointer to prime generation context
88 *
89 * Returns: ---
90 *
91 * Use: Discards a context and all the resources it holds.
92 */
93
94extern void pgen_destroy(pgen */*p*/);
95
96/* --- @pgen_step@ --- *
97 *
98 * Arguments: @pgen *p@ = pointer to prime generation context
99 * @mpw step@ = how much to step the number
100 *
101 * Returns: One of the @PGEN@ constants above.
102 *
103 * Use: Steps a number by a small amount. Stepping is much faster
104 * than initializing with a new number. The test performed is
105 * the same simple one used by @ptab_create@, so @PGEN_MAYBE@
106 * results should be followed up by a Rabin-Miller test.
107 */
108
109extern int pgen_step(pgen */*p*/, mpw /*step*/);
110
111/* --- @pgen_jump@ --- *
112 *
113 * Arguments: @pgen *p@ = pointer to prime generation context
114 * @pgen *j@ = pointer to another generation context
115 *
116 * Returns: One of the @PGEN@ constants above.
117 *
118 * Use: Steps a number by a large amount. Even so, jumping is much
119 * faster than initializing a new number. The test peformed is
120 * the same simple one used by @ptab_create@, so @PGEN_MAYBE@
121 * results should be followed up by a Rabin-Miller test.
122 *
123 * Note that the number stored in the @j@ context is probably
124 * better off being even than prime. The important thing is
125 * that all of the residues for the number have already been
126 * computed.
127 */
128
129extern int pgen_jump(pgen */*p*/, pgen */*j*/);
130
131/*----- That's all, folks -------------------------------------------------*/
132
133#ifdef __cplusplus
134 }
135#endif
136
137#endif