3 * The Ed25519 signature scheme
5 * (c) 2017 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
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.
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.
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,
28 #ifndef CATACOMB_ED25519_H
29 #define CATACOMB_ED25519_H
35 /*----- Notes on the Ed25519 signature scheme -----------------------------*
37 * This is Ed25519, as described in Daniel J. Bernstein, Neils Duif, Tanja
38 * Lange, Peter Schwabe, and Bo-Yin Yang, `High-speed high-security
39 * signatures', CHES 2011, https://ed25519.cr.yp.to/ed25519-20110926.pdf
41 * Specifically, this code implements `PureEdDSA', according to the
42 * definition in Daniel J. Bernstein, Simon Josefsson, Tanja Lange, Peter
43 * Schwabe, and Bo-Yin Yang, `EdDSA for more curves',
44 * https://ed25519.cr.yp.to/eddsa-20150704.pdf. HashEdEDSA can be
45 * implemented easily by presenting a hash of a message to the functions
46 * here, as the message to be signed or verified.
49 /*----- Header files ------------------------------------------------------*/
51 #include <mLib/bits.h>
53 #ifndef CATACOMB_KEY_H
57 /*----- Important constants -----------------------------------------------*/
59 #define ED25519_KEYSZ 32u
60 #define ED25519_PUBSZ 32u
61 #define ED25519_SIGSZ 64u
63 /*----- Key fetching ------------------------------------------------------*/
65 typedef struct ed25519_priv { key_bin priv, pub; } ed25519_priv;
66 typedef struct ed25519_pub { key_bin pub; } ed25519_pub;
68 extern const key_fetchdef ed25519_pubfetch[], ed25519_privfetch[];
69 #define ED25519_PUBFETCHSZ 3
70 #define ED25519_PRIVFETCHSZ 6
72 /*----- Functions provided ------------------------------------------------*/
74 /* --- @ed25519_pubkey@ --- *
76 * Arguments: @octet K[ED25519_PUBSZ]@ = where to put the public key
77 * @const void *k@ = private key
78 * @size_t ksz@ = length of private key
82 * Use: Derives the public key from a private key.
85 extern void ed25519_pubkey(octet /*K*/[ED25519_PUBSZ],
86 const void */*k*/, size_t /*ksz*/);
88 /* --- @ed25519_sign@ --- *
90 * Arguments: @octet sig[ED25519_SIGSZ]@ = where to put the signature
91 * @const void *k@ = private key
92 * @size_t ksz@ = length of private key
93 * @const octet K[ED25519_PUBSZ]@ = public key
94 * @const void *m@ = message to sign
95 * @size_t msz@ = length of message
99 * Use: Signs a message.
102 extern void ed25519_sign(octet /*sig*/[ED25519_SIGSZ],
103 const void */*k*/, size_t /*ksz*/,
104 const octet /*K*/[ED25519_PUBSZ],
105 const void */*m*/, size_t /*msz*/);
107 /* --- @ed25519_verify@ --- *
109 * Arguments: @const octet K[ED25519_PUBSZ]@ = public key
110 * @const void *m@ = message to sign
111 * @size_t msz@ = length of message
112 * @const octet sig[ED25519_SIGSZ]@ = signature
114 * Returns: Zero if OK, negative on failure.
116 * Use: Verify a signature.
119 extern int ed25519_verify(const octet /*K*/[ED25519_PUBSZ],
120 const void */*m*/, size_t /*msz*/,
121 const octet /*sig*/[ED25519_SIGSZ]);
123 /*----- That's all, folks -------------------------------------------------*/