Generate, store and retreive elliptic curve keys.
[u/mdw/catacomb] / ec-fetch.c
diff --git a/ec-fetch.c b/ec-fetch.c
new file mode 100644 (file)
index 0000000..ed7faa7
--- /dev/null
@@ -0,0 +1,99 @@
+/* -*-c-*-
+ *
+ * $Id: ec-fetch.c,v 1.1 2004/03/28 01:58:47 mdw Exp $
+ *
+ * Key fetching for elliptic curve public and private keys
+ *
+ * (c) 2004 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of Catacomb.
+ *
+ * Catacomb is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * Catacomb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Library General Public
+ * License along with Catacomb; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: ec-fetch.c,v $
+ * Revision 1.1  2004/03/28 01:58:47  mdw
+ * Generate, store and retreive elliptic curve keys.
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include "ec-keys.h"
+#include "key.h"
+
+/*----- Key fetching ------------------------------------------------------*/
+
+const key_fetchdef ec_paramfetch[] = {
+  { "curve",   offsetof(ec_pub, cstr),         KENC_STRING,    0 },
+  { 0,         0,                              0,              0 }
+};
+
+const key_fetchdef ec_pubfetch[] = {
+  { "curve",   offsetof(ec_pub, cstr),         KENC_STRING,    0 },
+  { "p",       offsetof(ec_pub, p),            KENC_EC,        0 },
+  { 0,         0,                              0,              0 }
+};
+
+static const key_fetchdef priv[] = {
+  { "x",       offsetof(ec_priv, x),           KENC_MP,        0 },
+  { 0,         0,                              0,              0 }
+};
+
+const key_fetchdef ec_privfetch[] = {
+  { "curve",   offsetof(ec_pub, cstr),         KENC_STRING,    0 },
+  { "p",       offsetof(ec_pub, p),            KENC_EC,        0 },
+  { "private", 0,                              KENC_STRUCT,    priv },
+  { 0,         0,                              0,              0 }  
+};
+
+/* --- @ec_paramfree@, @ec_pubfree@, @ec_privfree@ --- *
+ *
+ * Arguments:  @ec_param *ep@, @ec_pub *ep@, @ec_priv *ep@ = pointer to
+ *                     key block to free
+ *
+ * Returns:    ---
+ *
+ * Use:                Frees an elliptic curve key block
+ */
+
+void ec_paramfree(ec_param *ep)
+{
+  if (ep->ei.c) ec_freeinfo(&ep->ei);
+  xfree(ep->cstr);
+}
+
+void ec_pubfree(ec_pub *ep)
+{
+  if (ep->ei.c) ec_freeinfo(&ep->ei);
+  xfree(ep->cstr);
+  EC_DESTROY(&ep->p);
+}
+
+void ec_privfree(ec_priv *ep)
+{
+  if (ep->ei.c) ec_freeinfo(&ep->ei);
+  xfree(ep->cstr);
+  EC_DESTROY(&ep->p);
+  mp_drop(ep->x);
+}
+
+/*----- That's all, folks -------------------------------------------------*/