wolfSSL SSL/TLS library, support up to TLS1.3
Dependents: CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more
wolfssl/wolfcrypt/ed25519.h@17:a5f916481144, 2020-06-05 (annotated)
- Committer:
- wolfSSL
- Date:
- Fri Jun 05 00:11:07 2020 +0000
- Revision:
- 17:a5f916481144
- Parent:
- 16:8e0d178b1d1e
wolfSSL 4.4.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 15:117db924cf7c | 1 | /* ed25519.h |
wolfSSL | 15:117db924cf7c | 2 | * |
wolfSSL | 16:8e0d178b1d1e | 3 | * Copyright (C) 2006-2020 wolfSSL Inc. |
wolfSSL | 15:117db924cf7c | 4 | * |
wolfSSL | 15:117db924cf7c | 5 | * This file is part of wolfSSL. |
wolfSSL | 15:117db924cf7c | 6 | * |
wolfSSL | 15:117db924cf7c | 7 | * wolfSSL is free software; you can redistribute it and/or modify |
wolfSSL | 15:117db924cf7c | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 15:117db924cf7c | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 15:117db924cf7c | 10 | * (at your option) any later version. |
wolfSSL | 15:117db924cf7c | 11 | * |
wolfSSL | 15:117db924cf7c | 12 | * wolfSSL is distributed in the hope that it will be useful, |
wolfSSL | 15:117db924cf7c | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 15:117db924cf7c | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 15:117db924cf7c | 15 | * GNU General Public License for more details. |
wolfSSL | 15:117db924cf7c | 16 | * |
wolfSSL | 15:117db924cf7c | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 15:117db924cf7c | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 15:117db924cf7c | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
wolfSSL | 15:117db924cf7c | 20 | */ |
wolfSSL | 15:117db924cf7c | 21 | |
wolfSSL | 15:117db924cf7c | 22 | /*! |
wolfSSL | 15:117db924cf7c | 23 | \file wolfssl/wolfcrypt/ed25519.h |
wolfSSL | 15:117db924cf7c | 24 | */ |
wolfSSL | 15:117db924cf7c | 25 | |
wolfSSL | 15:117db924cf7c | 26 | |
wolfSSL | 15:117db924cf7c | 27 | #ifndef WOLF_CRYPT_ED25519_H |
wolfSSL | 15:117db924cf7c | 28 | #define WOLF_CRYPT_ED25519_H |
wolfSSL | 15:117db924cf7c | 29 | |
wolfSSL | 15:117db924cf7c | 30 | #include <wolfssl/wolfcrypt/types.h> |
wolfSSL | 15:117db924cf7c | 31 | |
wolfSSL | 15:117db924cf7c | 32 | #ifdef HAVE_ED25519 |
wolfSSL | 15:117db924cf7c | 33 | |
wolfSSL | 15:117db924cf7c | 34 | #include <wolfssl/wolfcrypt/fe_operations.h> |
wolfSSL | 15:117db924cf7c | 35 | #include <wolfssl/wolfcrypt/ge_operations.h> |
wolfSSL | 15:117db924cf7c | 36 | #include <wolfssl/wolfcrypt/random.h> |
wolfSSL | 15:117db924cf7c | 37 | #include <wolfssl/wolfcrypt/sha512.h> |
wolfSSL | 15:117db924cf7c | 38 | |
wolfSSL | 15:117db924cf7c | 39 | #ifdef WOLFSSL_ASYNC_CRYPT |
wolfSSL | 15:117db924cf7c | 40 | #include <wolfssl/wolfcrypt/async.h> |
wolfSSL | 15:117db924cf7c | 41 | #endif |
wolfSSL | 15:117db924cf7c | 42 | |
wolfSSL | 15:117db924cf7c | 43 | #ifdef __cplusplus |
wolfSSL | 15:117db924cf7c | 44 | extern "C" { |
wolfSSL | 15:117db924cf7c | 45 | #endif |
wolfSSL | 15:117db924cf7c | 46 | |
wolfSSL | 15:117db924cf7c | 47 | |
wolfSSL | 15:117db924cf7c | 48 | /* info about EdDSA curve specifically ed25519, defined as an elliptic curve |
wolfSSL | 15:117db924cf7c | 49 | over GF(p) */ |
wolfSSL | 15:117db924cf7c | 50 | /* |
wolfSSL | 15:117db924cf7c | 51 | 32, key size |
wolfSSL | 15:117db924cf7c | 52 | "ED25519", curve name |
wolfSSL | 15:117db924cf7c | 53 | "2^255-19", prime number |
wolfSSL | 15:117db924cf7c | 54 | "SHA512", hash function |
wolfSSL | 15:117db924cf7c | 55 | "-121665/121666", value of d |
wolfSSL | 15:117db924cf7c | 56 | */ |
wolfSSL | 15:117db924cf7c | 57 | |
wolfSSL | 15:117db924cf7c | 58 | #define ED25519_KEY_SIZE 32 /* private key only */ |
wolfSSL | 15:117db924cf7c | 59 | #define ED25519_SIG_SIZE 64 |
wolfSSL | 15:117db924cf7c | 60 | |
wolfSSL | 15:117db924cf7c | 61 | #define ED25519_PUB_KEY_SIZE 32 /* compressed */ |
wolfSSL | 15:117db924cf7c | 62 | /* both private and public key */ |
wolfSSL | 15:117db924cf7c | 63 | #define ED25519_PRV_KEY_SIZE (ED25519_PUB_KEY_SIZE+ED25519_KEY_SIZE) |
wolfSSL | 15:117db924cf7c | 64 | |
wolfSSL | 15:117db924cf7c | 65 | |
wolfSSL | 16:8e0d178b1d1e | 66 | enum { |
wolfSSL | 16:8e0d178b1d1e | 67 | Ed25519 = -1, |
wolfSSL | 16:8e0d178b1d1e | 68 | Ed25519ctx = 0, |
wolfSSL | 16:8e0d178b1d1e | 69 | Ed25519ph = 1, |
wolfSSL | 16:8e0d178b1d1e | 70 | }; |
wolfSSL | 16:8e0d178b1d1e | 71 | |
wolfSSL | 15:117db924cf7c | 72 | #ifndef WC_ED25519KEY_TYPE_DEFINED |
wolfSSL | 15:117db924cf7c | 73 | typedef struct ed25519_key ed25519_key; |
wolfSSL | 15:117db924cf7c | 74 | #define WC_ED25519KEY_TYPE_DEFINED |
wolfSSL | 15:117db924cf7c | 75 | #endif |
wolfSSL | 15:117db924cf7c | 76 | |
wolfSSL | 15:117db924cf7c | 77 | /* An ED25519 Key */ |
wolfSSL | 15:117db924cf7c | 78 | struct ed25519_key { |
wolfSSL | 15:117db924cf7c | 79 | byte p[ED25519_PUB_KEY_SIZE]; /* compressed public key */ |
wolfSSL | 15:117db924cf7c | 80 | byte k[ED25519_PRV_KEY_SIZE]; /* private key : 32 secret -- 32 public */ |
wolfSSL | 15:117db924cf7c | 81 | #ifdef FREESCALE_LTC_ECC |
wolfSSL | 15:117db924cf7c | 82 | /* uncompressed point coordinates */ |
wolfSSL | 15:117db924cf7c | 83 | byte pointX[ED25519_KEY_SIZE]; /* recovered X coordinate */ |
wolfSSL | 15:117db924cf7c | 84 | byte pointY[ED25519_KEY_SIZE]; /* Y coordinate is the public key with The most significant bit of the final octet always zero. */ |
wolfSSL | 15:117db924cf7c | 85 | #endif |
wolfSSL | 16:8e0d178b1d1e | 86 | word16 pubKeySet:1; |
wolfSSL | 15:117db924cf7c | 87 | #ifdef WOLFSSL_ASYNC_CRYPT |
wolfSSL | 15:117db924cf7c | 88 | WC_ASYNC_DEV asyncDev; |
wolfSSL | 15:117db924cf7c | 89 | #endif |
wolfSSL | 15:117db924cf7c | 90 | }; |
wolfSSL | 15:117db924cf7c | 91 | |
wolfSSL | 15:117db924cf7c | 92 | |
wolfSSL | 15:117db924cf7c | 93 | WOLFSSL_API |
wolfSSL | 16:8e0d178b1d1e | 94 | int wc_ed25519_make_public(ed25519_key* key, unsigned char* pubKey, |
wolfSSL | 16:8e0d178b1d1e | 95 | word32 pubKeySz); |
wolfSSL | 16:8e0d178b1d1e | 96 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 97 | int wc_ed25519_make_key(WC_RNG* rng, int keysize, ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 98 | WOLFSSL_API |
wolfSSL | 16:8e0d178b1d1e | 99 | int wc_ed25519_sign_msg(const byte* in, word32 inLen, byte* out, |
wolfSSL | 16:8e0d178b1d1e | 100 | word32 *outLen, ed25519_key* key); |
wolfSSL | 16:8e0d178b1d1e | 101 | WOLFSSL_API |
wolfSSL | 16:8e0d178b1d1e | 102 | int wc_ed25519ctx_sign_msg(const byte* in, word32 inLen, byte* out, |
wolfSSL | 16:8e0d178b1d1e | 103 | word32 *outLen, ed25519_key* key, |
wolfSSL | 16:8e0d178b1d1e | 104 | const byte* context, byte contextLen); |
wolfSSL | 16:8e0d178b1d1e | 105 | WOLFSSL_API |
wolfSSL | 16:8e0d178b1d1e | 106 | int wc_ed25519ph_sign_hash(const byte* hash, word32 hashLen, byte* out, |
wolfSSL | 16:8e0d178b1d1e | 107 | word32 *outLen, ed25519_key* key, |
wolfSSL | 16:8e0d178b1d1e | 108 | const byte* context, byte contextLen); |
wolfSSL | 16:8e0d178b1d1e | 109 | WOLFSSL_API |
wolfSSL | 16:8e0d178b1d1e | 110 | int wc_ed25519ph_sign_msg(const byte* in, word32 inLen, byte* out, |
wolfSSL | 16:8e0d178b1d1e | 111 | word32 *outLen, ed25519_key* key, const byte* context, |
wolfSSL | 16:8e0d178b1d1e | 112 | byte contextLen); |
wolfSSL | 15:117db924cf7c | 113 | WOLFSSL_API |
wolfSSL | 16:8e0d178b1d1e | 114 | int wc_ed25519_verify_msg(const byte* sig, word32 sigLen, const byte* msg, |
wolfSSL | 16:8e0d178b1d1e | 115 | word32 msgLen, int* stat, ed25519_key* key); |
wolfSSL | 16:8e0d178b1d1e | 116 | WOLFSSL_API |
wolfSSL | 16:8e0d178b1d1e | 117 | int wc_ed25519ctx_verify_msg(const byte* sig, word32 sigLen, const byte* msg, |
wolfSSL | 16:8e0d178b1d1e | 118 | word32 msgLen, int* stat, ed25519_key* key, |
wolfSSL | 16:8e0d178b1d1e | 119 | const byte* context, byte contextLen); |
wolfSSL | 16:8e0d178b1d1e | 120 | WOLFSSL_API |
wolfSSL | 16:8e0d178b1d1e | 121 | int wc_ed25519ph_verify_hash(const byte* sig, word32 sigLen, const byte* hash, |
wolfSSL | 16:8e0d178b1d1e | 122 | word32 hashLen, int* stat, ed25519_key* key, |
wolfSSL | 16:8e0d178b1d1e | 123 | const byte* context, byte contextLen); |
wolfSSL | 16:8e0d178b1d1e | 124 | WOLFSSL_API |
wolfSSL | 16:8e0d178b1d1e | 125 | int wc_ed25519ph_verify_msg(const byte* sig, word32 sigLen, const byte* msg, |
wolfSSL | 16:8e0d178b1d1e | 126 | word32 msgLen, int* stat, ed25519_key* key, |
wolfSSL | 16:8e0d178b1d1e | 127 | const byte* context, byte contextLen); |
wolfSSL | 15:117db924cf7c | 128 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 129 | int wc_ed25519_init(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 130 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 131 | void wc_ed25519_free(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 132 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 133 | int wc_ed25519_import_public(const byte* in, word32 inLen, ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 134 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 135 | int wc_ed25519_import_private_only(const byte* priv, word32 privSz, |
wolfSSL | 15:117db924cf7c | 136 | ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 137 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 138 | int wc_ed25519_import_private_key(const byte* priv, word32 privSz, |
wolfSSL | 15:117db924cf7c | 139 | const byte* pub, word32 pubSz, ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 140 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 141 | int wc_ed25519_export_public(ed25519_key*, byte* out, word32* outLen); |
wolfSSL | 15:117db924cf7c | 142 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 143 | int wc_ed25519_export_private_only(ed25519_key* key, byte* out, word32* outLen); |
wolfSSL | 15:117db924cf7c | 144 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 145 | int wc_ed25519_export_private(ed25519_key* key, byte* out, word32* outLen); |
wolfSSL | 15:117db924cf7c | 146 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 147 | int wc_ed25519_export_key(ed25519_key* key, |
wolfSSL | 15:117db924cf7c | 148 | byte* priv, word32 *privSz, |
wolfSSL | 15:117db924cf7c | 149 | byte* pub, word32 *pubSz); |
wolfSSL | 15:117db924cf7c | 150 | |
wolfSSL | 16:8e0d178b1d1e | 151 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 152 | int wc_ed25519_check_key(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 153 | |
wolfSSL | 15:117db924cf7c | 154 | /* size helper */ |
wolfSSL | 15:117db924cf7c | 155 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 156 | int wc_ed25519_size(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 157 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 158 | int wc_ed25519_priv_size(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 159 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 160 | int wc_ed25519_pub_size(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 161 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 162 | int wc_ed25519_sig_size(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 163 | |
wolfSSL | 15:117db924cf7c | 164 | #ifdef __cplusplus |
wolfSSL | 15:117db924cf7c | 165 | } /* extern "C" */ |
wolfSSL | 15:117db924cf7c | 166 | #endif |
wolfSSL | 15:117db924cf7c | 167 | |
wolfSSL | 15:117db924cf7c | 168 | #endif /* HAVE_ED25519 */ |
wolfSSL | 15:117db924cf7c | 169 | #endif /* WOLF_CRYPT_ED25519_H */ |
wolfSSL | 15:117db924cf7c | 170 |