Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
wolfssl/wolfcrypt/ed25519.h@16:048e5e270a58, 2019-11-19 (annotated)
- Committer:
- sPymbed
- Date:
- Tue Nov 19 14:32:16 2019 +0000
- Revision:
- 16:048e5e270a58
- Parent:
- 15:117db924cf7c
working ssl
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 | 15:117db924cf7c | 3 | * Copyright (C) 2006-2017 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 | 15:117db924cf7c | 66 | #ifndef WC_ED25519KEY_TYPE_DEFINED |
wolfSSL | 15:117db924cf7c | 67 | typedef struct ed25519_key ed25519_key; |
wolfSSL | 15:117db924cf7c | 68 | #define WC_ED25519KEY_TYPE_DEFINED |
wolfSSL | 15:117db924cf7c | 69 | #endif |
wolfSSL | 15:117db924cf7c | 70 | |
wolfSSL | 15:117db924cf7c | 71 | /* An ED25519 Key */ |
wolfSSL | 15:117db924cf7c | 72 | struct ed25519_key { |
wolfSSL | 15:117db924cf7c | 73 | byte p[ED25519_PUB_KEY_SIZE]; /* compressed public key */ |
wolfSSL | 15:117db924cf7c | 74 | byte k[ED25519_PRV_KEY_SIZE]; /* private key : 32 secret -- 32 public */ |
wolfSSL | 15:117db924cf7c | 75 | #ifdef FREESCALE_LTC_ECC |
wolfSSL | 15:117db924cf7c | 76 | /* uncompressed point coordinates */ |
wolfSSL | 15:117db924cf7c | 77 | byte pointX[ED25519_KEY_SIZE]; /* recovered X coordinate */ |
wolfSSL | 15:117db924cf7c | 78 | 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 | 79 | #endif |
wolfSSL | 15:117db924cf7c | 80 | int pubKeySet:1; |
wolfSSL | 15:117db924cf7c | 81 | #ifdef WOLFSSL_ASYNC_CRYPT |
wolfSSL | 15:117db924cf7c | 82 | WC_ASYNC_DEV asyncDev; |
wolfSSL | 15:117db924cf7c | 83 | #endif |
wolfSSL | 15:117db924cf7c | 84 | }; |
wolfSSL | 15:117db924cf7c | 85 | |
wolfSSL | 15:117db924cf7c | 86 | |
wolfSSL | 15:117db924cf7c | 87 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 88 | int wc_ed25519_make_key(WC_RNG* rng, int keysize, ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 89 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 90 | int wc_ed25519_sign_msg(const byte* in, word32 inlen, byte* out, |
wolfSSL | 15:117db924cf7c | 91 | word32 *outlen, ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 92 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 93 | int wc_ed25519_verify_msg(const byte* sig, word32 siglen, const byte* msg, |
wolfSSL | 15:117db924cf7c | 94 | word32 msglen, int* stat, ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 95 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 96 | int wc_ed25519_init(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 97 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 98 | void wc_ed25519_free(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 99 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 100 | int wc_ed25519_import_public(const byte* in, word32 inLen, ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 101 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 102 | int wc_ed25519_import_private_only(const byte* priv, word32 privSz, |
wolfSSL | 15:117db924cf7c | 103 | ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 104 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 105 | int wc_ed25519_import_private_key(const byte* priv, word32 privSz, |
wolfSSL | 15:117db924cf7c | 106 | const byte* pub, word32 pubSz, ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 107 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 108 | int wc_ed25519_export_public(ed25519_key*, byte* out, word32* outLen); |
wolfSSL | 15:117db924cf7c | 109 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 110 | int wc_ed25519_export_private_only(ed25519_key* key, byte* out, word32* outLen); |
wolfSSL | 15:117db924cf7c | 111 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 112 | int wc_ed25519_export_private(ed25519_key* key, byte* out, word32* outLen); |
wolfSSL | 15:117db924cf7c | 113 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 114 | int wc_ed25519_export_key(ed25519_key* key, |
wolfSSL | 15:117db924cf7c | 115 | byte* priv, word32 *privSz, |
wolfSSL | 15:117db924cf7c | 116 | byte* pub, word32 *pubSz); |
wolfSSL | 15:117db924cf7c | 117 | |
wolfSSL | 15:117db924cf7c | 118 | int wc_ed25519_check_key(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 119 | |
wolfSSL | 15:117db924cf7c | 120 | /* size helper */ |
wolfSSL | 15:117db924cf7c | 121 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 122 | int wc_ed25519_size(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 123 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 124 | int wc_ed25519_priv_size(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 125 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 126 | int wc_ed25519_pub_size(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 127 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 128 | int wc_ed25519_sig_size(ed25519_key* key); |
wolfSSL | 15:117db924cf7c | 129 | |
wolfSSL | 15:117db924cf7c | 130 | #ifdef __cplusplus |
wolfSSL | 15:117db924cf7c | 131 | } /* extern "C" */ |
wolfSSL | 15:117db924cf7c | 132 | #endif |
wolfSSL | 15:117db924cf7c | 133 | |
wolfSSL | 15:117db924cf7c | 134 | #endif /* HAVE_ED25519 */ |
wolfSSL | 15:117db924cf7c | 135 | #endif /* WOLF_CRYPT_ED25519_H */ |
wolfSSL | 15:117db924cf7c | 136 | |
wolfSSL | 15:117db924cf7c | 137 |