progs/pixie.c: Rename `log' function to `pxlog'.
[u/mdw/catacomb] / pub / gdsa.h
1 /* -*-c-*-
2 *
3 * Generalized version of DSA
4 *
5 * (c) 2004 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of Catacomb.
11 *
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
16 *
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
28 #ifndef CATACOMB_GDSA_H
29 #define CATACOMB_GDSA_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #ifndef CATACOMB_GHASH_H
38 # include "ghash.h"
39 #endif
40
41 #ifndef CATACOMB_GROUP_H
42 # include "group.h"
43 #endif
44
45 /*----- Data structures ---------------------------------------------------*/
46
47 /* --- GDSA context --- *
48 *
49 * You don't need to fill in all of this stuff. See the description of the
50 * function you want to use to find out what members are needed.
51 */
52
53 typedef struct gdsa {
54 group *g; /* The group we work in */
55 mp *u; /* Private key, for signing */
56 ge *p; /* Public key, for verifying */
57 grand *r; /* Random number source */
58 const gchash *h; /* Hash function */
59 } gdsa;
60
61 /* --- GDSA signatures --- */
62
63 typedef struct gdsa_sig { mp *r, *s; } gdsa_sig;
64 #define GDSA_SIG_INIT { MP_NEW, MP_NEW }
65
66 /*----- Functions provided ------------------------------------------------*/
67
68 /* --- @gdsa_beginhash@ --- *
69 *
70 * Arguments: @const gdsa *c@ = pointer to the context structure
71 *
72 * Returns: A hashing context for you to hash the message.
73 *
74 * Use: Initializes a hash function correctly for you to hash a
75 * message. Requires @h@.
76 */
77
78 extern ghash *gdsa_beginhash(const gdsa */*c*/);
79
80 /* --- @gdsa_endhash@ --- *
81 *
82 * Arguments: @const gdsa *c@ = pointer to the context structure
83 * @ghash *h@ = the hashing context
84 *
85 * Returns: ---
86 *
87 * Use: Does any final thing that DSA wants to do when hashing a
88 * message. (Actually, there's nothing.) The hashing context
89 * isn't finalized.
90 */
91
92 extern void gdsa_endhash(const gdsa */*c*/, ghash */*h*/);
93
94 /* --- @gdsa_sign@ --- *
95 *
96 * Arguments: @const gdsa *c@ = my context structure
97 * @gdsa_sig *s@ = where to put the signature (initialized)
98 * @const void *m@ = pointer to message hash
99 * @mp *k@ = random exponent for this message or null
100 *
101 * Returns: ---
102 *
103 * Use: Signs a message. Requires @g@, @u@, @h@, and @r@ if @k@ is
104 * null. This is a better idea than inventing @k@ yourself.
105 */
106
107 extern void gdsa_sign(const gdsa */*c*/, gdsa_sig */*s*/,
108 const void */*m*/, mp */*k*/);
109
110 /* --- @gdsa_verify@ --- *
111 *
112 * Arguments: @const gdsa *c@ = my context structure
113 * @const gdsa_sig *s@ = the signature to verify
114 * @const void *m@ = pointer to message hash
115 *
116 * Returns: Zero if OK, negative on failure.
117 *
118 * Use: Checks a signature on a message, Requires @g@, @p@, @h@.
119 */
120
121 extern int gdsa_verify(const gdsa */*c*/, const gdsa_sig */*s*/,
122 const void */*m*/);
123
124 /*----- That's all, folks -------------------------------------------------*/
125
126 #ifdef __cplusplus
127 }
128 #endif
129
130 #endif