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