| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * The Ed448 signature scheme |
| 4 | * |
| 5 | * (c) 2017 Straylight/Edgeware |
| 6 | */ |
| 7 | |
| 8 | /*----- Licensing notice --------------------------------------------------* |
| 9 | * |
| 10 | * This file is part of secnet. |
| 11 | * See README for full list of copyright holders. |
| 12 | * |
| 13 | * secnet is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version d of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * secnet is distributed in the hope that it will be useful, but |
| 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | * General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * version 3 along with secnet; if not, see |
| 25 | * https://www.gnu.org/licenses/gpl.html. |
| 26 | * |
| 27 | * This file was originally part of Catacomb, but has been automatically |
| 28 | * modified for incorporation into secnet: see `import-catacomb-crypto' |
| 29 | * for details. |
| 30 | * |
| 31 | * Catacomb is free software; you can redistribute it and/or modify |
| 32 | * it under the terms of the GNU Library General Public License as |
| 33 | * published by the Free Software Foundation; either version 2 of the |
| 34 | * License, or (at your option) any later version. |
| 35 | * |
| 36 | * Catacomb is distributed in the hope that it will be useful, |
| 37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 39 | * GNU Library General Public License for more details. |
| 40 | * |
| 41 | * You should have received a copy of the GNU Library General Public |
| 42 | * License along with Catacomb; if not, write to the Free |
| 43 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 44 | * MA 02111-1307, USA. |
| 45 | */ |
| 46 | |
| 47 | /*----- Notes on the Ed448 signature scheme -------------------------------* |
| 48 | * |
| 49 | * This is Ed448, as described in RFC8032, using the EdDSA signature scheme |
| 50 | * defined by Daniel J. Bernstein, Neils Duif, Simon Josefsson, Tanja Lange, |
| 51 | * Peter Schwabe, and Bo-Yin Yang, `High-speed high-security signatures', |
| 52 | * CHES 2011, https://ed25519.cr.yp.to/ed25519-20110926.pdf and `EdDSA for |
| 53 | * more curves', http://ed25519.cr.yp.to/eddsa-20150704.pdf. |
| 54 | * |
| 55 | * This is not the signature scheme described in Hamburg's paper |
| 56 | * `Ed448-Goldilocks, a new elliptic curve', EUROCRYPT 2016, |
| 57 | * https://eprint.iacr.org/2015/625/, which (a) made use of his `Decaf' |
| 58 | * cofactor elimination technique, and (b) was based on Schnorr rather than |
| 59 | * EdDSA. |
| 60 | * |
| 61 | * This code implements the `Ed448' and `Ed448ph' schemes described in |
| 62 | * RFC8032, though in the latter case it assumes that you've already done the |
| 63 | * hashing and have provided the hash as the `message' input. |
| 64 | */ |
| 65 | |
| 66 | #ifndef CATACOMB_ED448_H |
| 67 | #define CATACOMB_ED448_H |
| 68 | |
| 69 | #ifdef __cplusplus |
| 70 | extern "C" { |
| 71 | #endif |
| 72 | |
| 73 | /*----- Header files ------------------------------------------------------*/ |
| 74 | |
| 75 | #include "fake-mLib-bits.h" |
| 76 | |
| 77 | /*----- Important constants -----------------------------------------------*/ |
| 78 | |
| 79 | #define ED448_KEYSZ 57u |
| 80 | #define ED448_PUBSZ 57u |
| 81 | #define ED448_SIGSZ 114u |
| 82 | |
| 83 | #define ED448_MAXPERSOSZ 255u |
| 84 | |
| 85 | /*----- Functions provided ------------------------------------------------*/ |
| 86 | |
| 87 | /* --- @ed448_pubkey@ --- * |
| 88 | * |
| 89 | * Arguments: @octet K[ED448_PUBSZ]@ = where to put the public key |
| 90 | * @const void *k@ = private key |
| 91 | * @size_t ksz@ = length of private key |
| 92 | * |
| 93 | * Returns: --- |
| 94 | * |
| 95 | * Use: Derives the public key from a private key. |
| 96 | */ |
| 97 | |
| 98 | extern void ed448_pubkey(octet /*K*/[ED448_PUBSZ], |
| 99 | const void */*k*/, size_t /*ksz*/); |
| 100 | |
| 101 | /* --- @ed448_sign@ --- * |
| 102 | * |
| 103 | * Arguments: @octet sig[ED448_SIGSZ]@ = where to put the signature |
| 104 | * @const void *k@ = private key |
| 105 | * @size_t ksz@ = length of private key |
| 106 | * @const octet K[ED448_PUBSZ]@ = public key |
| 107 | * @int phflag@ = whether the `message' has been hashed already |
| 108 | * @const void *p@ = personalization string |
| 109 | * @size_t psz@ = length of personalization string |
| 110 | * @const void *m@ = message to sign |
| 111 | * @size_t msz@ = length of message |
| 112 | * |
| 113 | * Returns: --- |
| 114 | * |
| 115 | * Use: Signs a message. |
| 116 | */ |
| 117 | |
| 118 | extern void ed448_sign(octet /*sig*/[ED448_SIGSZ], |
| 119 | const void */*k*/, size_t /*ksz*/, |
| 120 | const octet /*K*/[ED448_PUBSZ], |
| 121 | int /*phflag*/, const void */*p*/, size_t /*psz*/, |
| 122 | const void */*m*/, size_t /*msz*/); |
| 123 | |
| 124 | /* --- @ed448_verify@ --- * |
| 125 | * |
| 126 | * Arguments: @const octet K[ED448_PUBSZ]@ = public key |
| 127 | * @const void *m@ = message to sign |
| 128 | * @int phflag@ = whether the `message' has been hashed already |
| 129 | * @const void *p@ = personalization string |
| 130 | * @size_t psz@ = length of personalization string |
| 131 | * @size_t msz@ = length of message |
| 132 | * @const octet sig[ED448_SIGSZ]@ = signature |
| 133 | * |
| 134 | * Returns: Zero if OK, negative on failure. |
| 135 | * |
| 136 | * Use: Verify a signature. |
| 137 | */ |
| 138 | |
| 139 | extern int ed448_verify(const octet /*K*/[ED448_PUBSZ], |
| 140 | int /*phflag*/, const void */*p*/, size_t /*psz*/, |
| 141 | const void */*m*/, size_t /*msz*/, |
| 142 | const octet /*sig*/[ED448_SIGSZ]); |
| 143 | |
| 144 | /*----- That's all, folks -------------------------------------------------*/ |
| 145 | |
| 146 | #ifdef __cplusplus |
| 147 | } |
| 148 | #endif |
| 149 | |
| 150 | #endif |