chiark / gitweb /
pub/, progs/: Implement Bernstein's Ed25519 signature scheme.
[catacomb] / pub / ed25519.h
diff --git a/pub/ed25519.h b/pub/ed25519.h
new file mode 100644 (file)
index 0000000..2fc7444
--- /dev/null
@@ -0,0 +1,129 @@
+/* -*-c-*-
+ *
+ * The Ed25519 signature scheme
+ *
+ * (c) 2017 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.
+ */
+
+#ifndef CATACOMB_ED25519_H
+#define CATACOMB_ED25519_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Notes on the Ed25519 signature scheme -----------------------------*
+ *
+ * This is Ed25519, as described in Daniel J. Bernstein, Neils Duif, Tanja
+ * Lange, Peter Schwabe, and Bo-Yin Yang, `High-speed high-security
+ * signatures', CHES 2011, https://ed25519.cr.yp.to/ed25519-20110926.pdf
+ *
+ * Specifically, this code implements `PureEdDSA', according to the
+ * definition in Daniel J. Bernstein, Simon Josefsson, Tanja Lange, Peter
+ * Schwabe, and Bo-Yin Yang, `EdDSA for more curves',
+ * https://ed25519.cr.yp.to/eddsa-20150704.pdf.  HashEdEDSA can be
+ * implemented easily by presenting a hash of a message to the functions
+ * here, as the message to be signed or verified.
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <mLib/bits.h>
+
+#ifndef CATACOMB_KEY_H
+#  include "key.h"
+#endif
+
+/*----- Important constants -----------------------------------------------*/
+
+#define ED25519_KEYSZ 32u
+#define ED25519_PUBSZ 32u
+#define ED25519_SIGSZ 64u
+
+/*----- Key fetching ------------------------------------------------------*/
+
+typedef struct ed25519_priv { key_bin priv, pub; } ed25519_priv;
+typedef struct ed25519_pub { key_bin pub; } ed25519_pub;
+
+extern const key_fetchdef ed25519_pubfetch[], ed25519_privfetch[];
+#define ED25519_PUBFETCHSZ 3
+#define ED25519_PRIVFETCHSZ 6
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @ed25519_pubkey@ --- *
+ *
+ * Arguments:  @octet K[ED25519_PUBSZ]@ = where to put the public key
+ *             @const void *k@ = private key
+ *             @size_t ksz@ = length of private key
+ *
+ * Returns:    ---
+ *
+ * Use:                Derives the public key from a private key.
+ */
+
+extern void ed25519_pubkey(octet /*K*/[ED25519_PUBSZ],
+                          const void */*k*/, size_t /*ksz*/);
+
+/* --- @ed25519_sign@ --- *
+ *
+ * Arguments:  @octet sig[ED25519_SIGSZ]@ = where to put the signature
+ *             @const void *k@ = private key
+ *             @size_t ksz@ = length of private key
+ *             @const octet K[ED25519_PUBSZ]@ = public key
+ *             @const void *m@ = message to sign
+ *             @size_t msz@ = length of message
+ *
+ * Returns:    ---
+ *
+ * Use:                Signs a message.
+ */
+
+extern void ed25519_sign(octet /*sig*/[ED25519_SIGSZ],
+                        const void */*k*/, size_t /*ksz*/,
+                        const octet /*K*/[ED25519_PUBSZ],
+                        const void */*m*/, size_t /*msz*/);
+
+/* --- @ed25519_verify@ --- *
+ *
+ * Arguments:  @const octet K[ED25519_PUBSZ]@ = public key
+ *             @const void *m@ = message to sign
+ *             @size_t msz@ = length of message
+ *             @const octet sig[ED25519_SIGSZ]@ = signature
+ *
+ * Returns:    Zero if OK, negative on failure.
+ *
+ * Use:                Verify a signature.
+ */
+
+extern int ed25519_verify(const octet /*K*/[ED25519_PUBSZ],
+                         const void */*m*/, size_t /*msz*/,
+                         const octet /*sig*/[ED25519_SIGSZ]);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif