Rearrange the file tree.
[u/mdw/catacomb] / pub / dh-fetch.c
1 /* -*-c-*-
2 *
3 * Key fetching for Diffie-Hellman public and private keys
4 *
5 * (c) 2000 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 /*----- Header files ------------------------------------------------------*/
29
30 #include "dh.h"
31 #include "key.h"
32
33 /*----- Key fetching ------------------------------------------------------*/
34
35 const key_fetchdef dh_paramfetch[] = {
36 { "p", offsetof(dh_param, p), KENC_MP, 0 },
37 { "q", offsetof(dh_param, q), KENC_MP, 0 },
38 { "g", offsetof(dh_param, g), KENC_MP, 0 },
39 { 0, 0, 0, 0 }
40 };
41
42 const key_fetchdef dh_pubfetch[] = {
43 { "p", offsetof(dh_pub, dp.p), KENC_MP, 0 },
44 { "q", offsetof(dh_pub, dp.q), KENC_MP, 0 },
45 { "g", offsetof(dh_pub, dp.g), KENC_MP, 0 },
46 { "y", offsetof(dh_pub, y), KENC_MP, 0 },
47 { 0, 0, 0, 0 }
48 };
49
50 static const key_fetchdef priv[] = {
51 { "x", offsetof(dh_priv, x), KENC_MP, 0 },
52 { 0, 0, 0, 0 }
53 };
54
55 const key_fetchdef dh_privfetch[] = {
56 { "p", offsetof(dh_priv, dp.p), KENC_MP, 0 },
57 { "q", offsetof(dh_priv, dp.q), KENC_MP, 0 },
58 { "g", offsetof(dh_priv, dp.g), KENC_MP, 0 },
59 { "y", offsetof(dh_priv, y), KENC_MP, 0 },
60 { "private", 0, KENC_STRUCT, priv },
61 { 0, 0, 0, 0 }
62 };
63
64 /* --- @dh_paramfree@, @dh_pubfree@, @dh_privfree@ --- *
65 *
66 * Arguments: @dh_param *dp@, @dh_pub *dp@, @dh_priv *dp@ = pointer
67 * to key block to free
68 *
69 * Returns: ---
70 *
71 * Use: Frees a Diffie-Hellman key block.
72 */
73
74 void dh_paramfree(dh_param *dp)
75 {
76 mp_drop(dp->p);
77 mp_drop(dp->q);
78 mp_drop(dp->g);
79 }
80
81 void dh_pubfree(dh_pub *dp)
82 {
83 mp_drop(dp->dp.p);
84 mp_drop(dp->dp.q);
85 mp_drop(dp->dp.g);
86 mp_drop(dp->y);
87 }
88
89 void dh_privfree(dh_priv *dp)
90 {
91 mp_drop(dp->dp.p);
92 mp_drop(dp->dp.q);
93 mp_drop(dp->dp.g);
94 mp_drop(dp->y);
95 mp_drop(dp->x);
96 }
97
98 /*----- That's all, folks -------------------------------------------------*/