| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: dh.h,v 1.4 2000/06/17 10:52:47 mdw Exp $ |
| 4 | * |
| 5 | * Diffie-Hellman and related public-key systems |
| 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: dh.h,v $ |
| 33 | * Revision 1.4 2000/06/17 10:52:47 mdw |
| 34 | * Minor changes for key fetching. |
| 35 | * |
| 36 | * Revision 1.3 2000/02/12 18:21:02 mdw |
| 37 | * Overhaul of key management (again). |
| 38 | * |
| 39 | */ |
| 40 | |
| 41 | #ifndef CATACOMB_DH_H |
| 42 | #define CATACOMB_DH_H |
| 43 | |
| 44 | #ifdef __cplusplus |
| 45 | extern "C" { |
| 46 | #endif |
| 47 | |
| 48 | /*----- Header files ------------------------------------------------------*/ |
| 49 | |
| 50 | #ifndef CATACOMB_GRAND_H |
| 51 | # include "grand.h" |
| 52 | #endif |
| 53 | |
| 54 | #ifndef CATACOMB_KEY_H |
| 55 | # include "key.h" |
| 56 | #endif |
| 57 | |
| 58 | #ifndef CATACOMB_PGEN_H |
| 59 | # include "pgen.h" |
| 60 | #endif |
| 61 | |
| 62 | /*----- Data structures ---------------------------------------------------*/ |
| 63 | |
| 64 | typedef struct dh_param { |
| 65 | mp *p, *q; |
| 66 | mp *g; |
| 67 | } dh_param; |
| 68 | |
| 69 | typedef struct dh_pub { |
| 70 | dh_param dp; |
| 71 | mp *y; |
| 72 | } dh_pub; |
| 73 | |
| 74 | typedef struct dh_priv { |
| 75 | dh_param dp; |
| 76 | mp *x; |
| 77 | mp *y; |
| 78 | } dh_priv; |
| 79 | |
| 80 | /*----- Key fetching ------------------------------------------------------*/ |
| 81 | |
| 82 | extern const key_fetchdef dh_paramfetch[]; |
| 83 | #define DH_PARAMFETCHSZ 5 |
| 84 | |
| 85 | extern const key_fetchdef dh_pubfetch[]; |
| 86 | #define DH_PUBFETCHSZ 6 |
| 87 | |
| 88 | extern const key_fetchdef dh_privfetch[]; |
| 89 | #define DH_PRIVFETCHSZ 9 |
| 90 | |
| 91 | /*----- Functions provided ------------------------------------------------*/ |
| 92 | |
| 93 | /* --- @dh_gen@ --- * |
| 94 | * |
| 95 | * Arguments: @dh_param *dp@ = pointer to output parameter block |
| 96 | * @unsigned ql@ = length of %$q$% in bits, or zero |
| 97 | * @unsigned pl@ = length of %$p$% in bits |
| 98 | * @unsigned steps@ = number of steps to go |
| 99 | * @grand *r@ = random number source |
| 100 | * @pgen_proc *event@ = event handler function |
| 101 | * @void *ectx@ = argument for the event handler |
| 102 | * |
| 103 | * Returns: @PGEN_DONE@ if it worked, @PGEN_ABORT@ if it didn't. |
| 104 | * |
| 105 | * Use: Generates Diffie-Hellman parameters. |
| 106 | * |
| 107 | * The parameters are a prime %$q$%, relatively small, and a |
| 108 | * large prime %$p = kq + 1$% for some %$k$%, together with a |
| 109 | * generator %$g$% of the cyclic subgroup of order %$q$%. These |
| 110 | * are actually the same as the DSA parameter set, but the |
| 111 | * generation algorithm is different. Also, if @ql@ is zero, |
| 112 | * this algorithm forces %$k = 2$%, and chooses %$g = 4$%. Make |
| 113 | * sure you have something interesting to do if you choose this |
| 114 | * option. |
| 115 | */ |
| 116 | |
| 117 | extern int dh_gen(dh_param */*dp*/, unsigned /*ql*/, unsigned /*pl*/, |
| 118 | unsigned /*steps*/, grand */*r*/, pgen_proc */*event*/, |
| 119 | void */*ectx*/); |
| 120 | |
| 121 | /*----- That's all, folks -------------------------------------------------*/ |
| 122 | |
| 123 | #ifdef __cplusplus |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | #endif |