Table for driving key data extraction.
[u/mdw/catacomb] / rsa.h
1 /* -*-c-*-
2 *
3 * $Id: rsa.h,v 1.1 1999/12/22 15:50:45 mdw Exp $
4 *
5 * The RSA public-key cryptosystem
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: rsa.h,v $
33 * Revision 1.1 1999/12/22 15:50:45 mdw
34 * Initial RSA support.
35 *
36 */
37
38 #ifndef CATACOMB_RSA_H
39 #define CATACOMB_RSA_H
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /*----- Header files ------------------------------------------------------*/
46
47 #ifndef CATACOMB_GRAND_H
48 # include "grand.h"
49 #endif
50
51 #ifndef CATACOMB_MP_H
52 # include "mp.h"
53 #endif
54
55 #ifndef CATACOMB_PGEN_H
56 # include "pgen.h"
57 #endif
58
59 /*----- Data structures ---------------------------------------------------*/
60
61 typedef struct rsa_param {
62 mp *p, *q;
63 mp *n;
64 mp *q_inv;
65 mp *e, *d, *dp, *dq;
66 } rsa_param;
67
68 /*----- Functions provided ------------------------------------------------*/
69
70 /* --- @rsa_gen@ --- *
71 *
72 * Arguments: @rsa_param *rp@ = pointer to block to be filled in
73 * @unsigned nbits@ = required modulus size in bits
74 * @grand *r@ = random number source
75 * @unsigned n@ = number of attempts to make
76 * @pgen_proc *event@ = event handler function
77 * @void *ectx@ = argument for the event handler
78 *
79 * Returns: Zero if all went well, nonzero otherwise.
80 *
81 * Use: Constructs a pair of strong RSA primes and other useful RSA
82 * parameters. A small encryption exponent is chosen if
83 * possible.
84 */
85
86 extern int rsa_gen(rsa_param */*rp*/, unsigned /*nbits*/,
87 grand */*r*/, unsigned /*n*/,
88 pgen_proc */*event*/, void */*ectx*/);
89
90 /* --- @rsa_decrypt@ --- *
91 *
92 * Arguments: @rsa_param *rp@ = pointer to RSA parameters
93 * @mp *d@ = destination
94 * @mp *c@ = ciphertext message
95 * @grand *r@ = pointer to random number source for blinding
96 *
97 * Returns: Correctly decrypted message.
98 *
99 * Use: Performs RSA decryption, very carefully.
100 */
101
102 extern mp *rsa_decrypt(rsa_param */*rp*/, mp */*d*/, mp */*c*/,
103 grand */*r*/);
104
105 /* --- @rsa_recover@ --- *
106 *
107 * Arguments: @rsa_param *rp@ = pointer to parameter block
108 *
109 * Returns: Zero if all went well, nonzero if the parameters make no
110 * sense.
111 *
112 * Use: Derives the full set of RSA parameters given a minimal set.
113 */
114
115 extern int rsa_recover(rsa_param */*rp*/);
116
117 /*----- That's all, folks -------------------------------------------------*/
118
119 #ifdef __cplusplus
120 }
121 #endif
122
123 #endif