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