6d88a4da3e12eeb809bb45f4a0add106e3d6d1ce
[u/mdw/catacomb] / gdsa.h
1 /* -*-c-*-
2 *
3 * $Id: gdsa.h,v 1.1 2004/04/04 19:42:59 mdw Exp $
4 *
5 * Generalized version of DSA
6 *
7 * (c) 2004 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: gdsa.h,v $
33 * Revision 1.1 2004/04/04 19:42:59 mdw
34 * Add set -e.
35 *
36 */
37
38 #ifndef CATACOMB_GDSA_H
39 #define CATACOMB_GDSA_H
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /*----- Header files ------------------------------------------------------*/
46
47 #ifndef CATACOMB_GHASH_H
48 # include "ghash.h"
49 #endif
50
51 #ifndef CATACOMB_GROUP_H
52 # include "group.h"
53 #endif
54
55 /*----- Data structures ---------------------------------------------------*/
56
57 /* --- GDSA context --- *
58 *
59 * You don't need to fill in all of this stuff. See the description of the
60 * function you want to use to find out what members are needed.
61 */
62
63 typedef struct gdsa {
64 group *g; /* The group we work in */
65 mp *u; /* Private key, for signing */
66 ge *p; /* Public key, for verifying */
67 grand *r; /* Random number source */
68 const gchash *h; /* Hash function */
69 } gdsa;
70
71 /* --- GDSA signatures --- */
72
73 typedef struct gdsa_sig { mp *r, *s; } gdsa_sig;
74 #define GDSA_SIG_INIT { MP_NEW, MP_NEW }
75
76 /*----- Functions provided ------------------------------------------------*/
77
78 /* --- @gdsa_beginhash@ --- *
79 *
80 * Arguments: @const gdsa *c@ = pointer to the context structure
81 *
82 * Returns: A hashing context for you to hash the message.
83 *
84 * Use: Initializes a hash function correctly for you to hash a
85 * message. Requires @h@.
86 */
87
88 extern ghash *gdsa_beginhash(const gdsa */*c*/);
89
90 /* --- @gdsa_endhash@ --- *
91 *
92 * Arguments: @const gdsa *c@ = pointer to the context structure
93 * @ghash *h@ = the hashing context
94 *
95 * Returns: ---
96 *
97 * Use: Does any final thing that DSA wants to do when hashing a
98 * message. (Actually, there's nothing.) The hashing context
99 * isn't finalized.
100 */
101
102 extern void gdsa_endhash(gdsa */*c*/, ghash */*h*/);
103
104 /* --- @gdsa_sign@ --- *
105 *
106 * Arguments: @const gdsa *c@ = my context structure
107 * @gdsa_sig *s@ = where to put the signature (initialized)
108 * @const void *m@ = pointer to message hash
109 * @mp *k@ = random exponent for this message or null
110 *
111 * Returns: ---
112 *
113 * Use: Signs a message. Requires @g@, @u@, @h@, and @r@ if @k@ is
114 * null. This is a better idea than inventing @k@ yourself.
115 */
116
117 extern void gdsa_sign(const gdsa */*c*/, gdsa_sig */*s*/,
118 const void */*m*/, mp */*k*/);
119
120 /* --- @gdsa_verify@ --- *
121 *
122 * Arguments: @const gdsa *c@ = my context structure
123 * @const gdsa_sig *s@ = the signature to verify
124 * @const void *m@ = pointer to message hash
125 *
126 * Returns: Zero if OK, negative on failure.
127 *
128 * Use: Checks a signature on a message, Requires @g@, @p@, @h@.
129 */
130
131 extern int gdsa_verify(const gdsa */*c*/, const gdsa_sig */*s*/,
132 const void */*m*/);
133
134 /*----- That's all, folks -------------------------------------------------*/
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif