ed7faa7de07d8839ff415ca3d2046a0da066477f
[u/mdw/catacomb] / ec-fetch.c
1 /* -*-c-*-
2 *
3 * $Id: ec-fetch.c,v 1.1 2004/03/28 01:58:47 mdw Exp $
4 *
5 * Key fetching for elliptic curve public and private keys
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: ec-fetch.c,v $
33 * Revision 1.1 2004/03/28 01:58:47 mdw
34 * Generate, store and retreive elliptic curve keys.
35 *
36 */
37
38 /*----- Header files ------------------------------------------------------*/
39
40 #include "ec-keys.h"
41 #include "key.h"
42
43 /*----- Key fetching ------------------------------------------------------*/
44
45 const key_fetchdef ec_paramfetch[] = {
46 { "curve", offsetof(ec_pub, cstr), KENC_STRING, 0 },
47 { 0, 0, 0, 0 }
48 };
49
50 const key_fetchdef ec_pubfetch[] = {
51 { "curve", offsetof(ec_pub, cstr), KENC_STRING, 0 },
52 { "p", offsetof(ec_pub, p), KENC_EC, 0 },
53 { 0, 0, 0, 0 }
54 };
55
56 static const key_fetchdef priv[] = {
57 { "x", offsetof(ec_priv, x), KENC_MP, 0 },
58 { 0, 0, 0, 0 }
59 };
60
61 const key_fetchdef ec_privfetch[] = {
62 { "curve", offsetof(ec_pub, cstr), KENC_STRING, 0 },
63 { "p", offsetof(ec_pub, p), KENC_EC, 0 },
64 { "private", 0, KENC_STRUCT, priv },
65 { 0, 0, 0, 0 }
66 };
67
68 /* --- @ec_paramfree@, @ec_pubfree@, @ec_privfree@ --- *
69 *
70 * Arguments: @ec_param *ep@, @ec_pub *ep@, @ec_priv *ep@ = pointer to
71 * key block to free
72 *
73 * Returns: ---
74 *
75 * Use: Frees an elliptic curve key block
76 */
77
78 void ec_paramfree(ec_param *ep)
79 {
80 if (ep->ei.c) ec_freeinfo(&ep->ei);
81 xfree(ep->cstr);
82 }
83
84 void ec_pubfree(ec_pub *ep)
85 {
86 if (ep->ei.c) ec_freeinfo(&ep->ei);
87 xfree(ep->cstr);
88 EC_DESTROY(&ep->p);
89 }
90
91 void ec_privfree(ec_priv *ep)
92 {
93 if (ep->ei.c) ec_freeinfo(&ep->ei);
94 xfree(ep->cstr);
95 EC_DESTROY(&ep->p);
96 mp_drop(ep->x);
97 }
98
99 /*----- That's all, folks -------------------------------------------------*/