chiark / gitweb /
ec-bin (ec_binproj): Make curve setup faster.
[catacomb] / gkcdsa.h
1 /* -*-c-*-
2  *
3  * $Id$
4  *
5  * Generalized version of KCDSA
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 #ifndef CATACOMB_GKCDSA_H
31 #define CATACOMB_GKCDSA_H
32
33 #ifdef __cplusplus
34   extern "C" {
35 #endif
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #ifndef CATACOMB_GROUP_H
40 #  include "group.h"
41 #endif
42
43 #ifndef CATACOMB_GHASH_H
44 #  include "ghash.h"
45 #endif
46
47 #ifndef CATACOMB_GDSA_H
48 #  include "gdsa.h"
49 #endif
50
51 /*----- Data structures ---------------------------------------------------*/
52
53 /* --- Careful! --- *
54  *
55  * These structures are the same as for DSA.  However, the private key @u@ is
56  * the %$\emph{inverse}$% of the exponent.  Do this wrong and the maths will
57  * fail hopelessly.
58  */
59
60 typedef gdsa gkcdsa;
61
62 typedef struct gkcdsa_sig {
63   octet *r;                             /* Null means @xmalloc@ me */
64   mp *s;
65 } gkcdsa_sig;
66 #define GKCDSA_SIG_INIT { 0, 0 }
67
68 /*----- Functions provided ------------------------------------------------*/
69
70 /* --- @gkcdsa_beginhash@ --- *
71  *
72  * Arguments:   @const gkcdsa *c@ = pointer to the context structure
73  *
74  * Returns:     A hashing context for you to hash the message.
75  *
76  * Use:         Initializes a hash function correctly for you to hash a
77  *              message.  Requires @h@, @g@ and @p@.
78  */
79
80 extern ghash *gkcdsa_beginhash(const gkcdsa */*c*/);
81
82 /* --- @gkcdsa_endhash@ --- *
83  *
84  * Arguments:   @const gkcdsa *c@ = pointer to the context structure
85  *              @ghash *h@ = the hashing context
86  *
87  * Returns:     ---
88  *
89  * Use:         Does any final thing that KCDSA wants to do when hashing a
90  *              message.  (Actually, there's nothing.)  The hashing context
91  *              isn't finalized.
92  */
93
94 extern void gkcdsa_endhash(const gkcdsa */*c*/, ghash */*h*/);
95
96 /* --- @gkcdsa_sign@ --- *
97  *
98  * Arguments:   @const gkcdsa *c@ = my context structure
99  *              @gkcdsa_sig *s@ = where to put the signature (initialized)
100  *              @const void *m@ = pointer to message hash
101  *              @mp *k@ = random exponent for this message or null
102  *
103  * Returns:     ---
104  *
105  * Use:         Signs a message.  Requires @g@, @u@, @h@, and @r@ if @k@ is
106  *              null.  This is a better idea than inventing @k@ yourself.
107  */
108
109 extern void gkcdsa_sign(const gkcdsa */*c*/, gkcdsa_sig */*s*/,
110                         const void */*m*/, mp */*k*/);
111
112 /* --- @gkcdsa_verify@ --- *
113  *
114  * Arguments:   @const gkcdsa *c@ = my context structure
115  *              @const gkcdsa_sig *s@ = the signature to verify
116  *              @const void *m@ = pointer to message hash
117  *
118  * Returns:     Zero if OK, negative on failure.
119  *
120  * Use:         Checks a signature on a message,  Requires @g@, @p@, @h@.
121  */
122
123 extern int gkcdsa_verify(const gkcdsa */*c*/, const gkcdsa_sig */*s*/,
124                          const void */*m*/);
125
126 /*----- That's all, folks -------------------------------------------------*/
127
128 #ifdef __cplusplus
129   }
130 #endif
131
132 #endif