wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue Aug 22 10:48:22 2017 +0000
Revision:
13:f67a6c6013ca
wolfSSL3.12.0 with TLS1.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 13:f67a6c6013ca 1 /* ed25519.h
wolfSSL 13:f67a6c6013ca 2 *
wolfSSL 13:f67a6c6013ca 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 13:f67a6c6013ca 4 *
wolfSSL 13:f67a6c6013ca 5 * This file is part of wolfSSL.
wolfSSL 13:f67a6c6013ca 6 *
wolfSSL 13:f67a6c6013ca 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 13:f67a6c6013ca 8 * it under the terms of the GNU General Public License as published by
wolfSSL 13:f67a6c6013ca 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 13:f67a6c6013ca 10 * (at your option) any later version.
wolfSSL 13:f67a6c6013ca 11 *
wolfSSL 13:f67a6c6013ca 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 13:f67a6c6013ca 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 13:f67a6c6013ca 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 13:f67a6c6013ca 15 * GNU General Public License for more details.
wolfSSL 13:f67a6c6013ca 16 *
wolfSSL 13:f67a6c6013ca 17 * You should have received a copy of the GNU General Public License
wolfSSL 13:f67a6c6013ca 18 * along with this program; if not, write to the Free Software
wolfSSL 13:f67a6c6013ca 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 13:f67a6c6013ca 20 */
wolfSSL 13:f67a6c6013ca 21
wolfSSL 13:f67a6c6013ca 22
wolfSSL 13:f67a6c6013ca 23 #ifndef WOLF_CRYPT_ED25519_H
wolfSSL 13:f67a6c6013ca 24 #define WOLF_CRYPT_ED25519_H
wolfSSL 13:f67a6c6013ca 25
wolfSSL 13:f67a6c6013ca 26 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 13:f67a6c6013ca 27
wolfSSL 13:f67a6c6013ca 28 #ifdef HAVE_ED25519
wolfSSL 13:f67a6c6013ca 29
wolfSSL 13:f67a6c6013ca 30 #include <wolfssl/wolfcrypt/fe_operations.h>
wolfSSL 13:f67a6c6013ca 31 #include <wolfssl/wolfcrypt/ge_operations.h>
wolfSSL 13:f67a6c6013ca 32 #include <wolfssl/wolfcrypt/random.h>
wolfSSL 13:f67a6c6013ca 33 #include <wolfssl/wolfcrypt/sha512.h>
wolfSSL 13:f67a6c6013ca 34
wolfSSL 13:f67a6c6013ca 35 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 13:f67a6c6013ca 36 #include <wolfssl/wolfcrypt/async.h>
wolfSSL 13:f67a6c6013ca 37 #endif
wolfSSL 13:f67a6c6013ca 38
wolfSSL 13:f67a6c6013ca 39 #ifdef __cplusplus
wolfSSL 13:f67a6c6013ca 40 extern "C" {
wolfSSL 13:f67a6c6013ca 41 #endif
wolfSSL 13:f67a6c6013ca 42
wolfSSL 13:f67a6c6013ca 43
wolfSSL 13:f67a6c6013ca 44 /* info about EdDSA curve specifically ed25519, defined as an elliptic curve
wolfSSL 13:f67a6c6013ca 45 over GF(p) */
wolfSSL 13:f67a6c6013ca 46 /*
wolfSSL 13:f67a6c6013ca 47 32, key size
wolfSSL 13:f67a6c6013ca 48 "ED25519", curve name
wolfSSL 13:f67a6c6013ca 49 "2^255-19", prime number
wolfSSL 13:f67a6c6013ca 50 "SHA512", hash function
wolfSSL 13:f67a6c6013ca 51 "-121665/121666", value of d
wolfSSL 13:f67a6c6013ca 52 */
wolfSSL 13:f67a6c6013ca 53
wolfSSL 13:f67a6c6013ca 54 #define ED25519_KEY_SIZE 32 /* private key only */
wolfSSL 13:f67a6c6013ca 55 #define ED25519_SIG_SIZE 64
wolfSSL 13:f67a6c6013ca 56
wolfSSL 13:f67a6c6013ca 57 #define ED25519_PUB_KEY_SIZE 32 /* compressed */
wolfSSL 13:f67a6c6013ca 58 /* both private and public key */
wolfSSL 13:f67a6c6013ca 59 #define ED25519_PRV_KEY_SIZE (ED25519_PUB_KEY_SIZE+ED25519_KEY_SIZE)
wolfSSL 13:f67a6c6013ca 60
wolfSSL 13:f67a6c6013ca 61
wolfSSL 13:f67a6c6013ca 62 #ifndef WC_ED25519KEY_TYPE_DEFINED
wolfSSL 13:f67a6c6013ca 63 typedef struct ed25519_key ed25519_key;
wolfSSL 13:f67a6c6013ca 64 #define WC_ED25519KEY_TYPE_DEFINED
wolfSSL 13:f67a6c6013ca 65 #endif
wolfSSL 13:f67a6c6013ca 66
wolfSSL 13:f67a6c6013ca 67 /* An ED25519 Key */
wolfSSL 13:f67a6c6013ca 68 struct ed25519_key {
wolfSSL 13:f67a6c6013ca 69 byte p[ED25519_PUB_KEY_SIZE]; /* compressed public key */
wolfSSL 13:f67a6c6013ca 70 byte k[ED25519_PRV_KEY_SIZE]; /* private key : 32 secret -- 32 public */
wolfSSL 13:f67a6c6013ca 71 #ifdef FREESCALE_LTC_ECC
wolfSSL 13:f67a6c6013ca 72 /* uncompressed point coordinates */
wolfSSL 13:f67a6c6013ca 73 byte pointX[ED25519_KEY_SIZE]; /* recovered X coordinate */
wolfSSL 13:f67a6c6013ca 74 byte pointY[ED25519_KEY_SIZE]; /* Y coordinate is the public key with The most significant bit of the final octet always zero. */
wolfSSL 13:f67a6c6013ca 75 #endif
wolfSSL 13:f67a6c6013ca 76 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 13:f67a6c6013ca 77 WC_ASYNC_DEV asyncDev;
wolfSSL 13:f67a6c6013ca 78 #endif
wolfSSL 13:f67a6c6013ca 79 };
wolfSSL 13:f67a6c6013ca 80
wolfSSL 13:f67a6c6013ca 81
wolfSSL 13:f67a6c6013ca 82 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 83 int wc_ed25519_make_key(WC_RNG* rng, int keysize, ed25519_key* key);
wolfSSL 13:f67a6c6013ca 84 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 85 int wc_ed25519_sign_msg(const byte* in, word32 inlen, byte* out,
wolfSSL 13:f67a6c6013ca 86 word32 *outlen, ed25519_key* key);
wolfSSL 13:f67a6c6013ca 87 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 88 int wc_ed25519_verify_msg(const byte* sig, word32 siglen, const byte* msg,
wolfSSL 13:f67a6c6013ca 89 word32 msglen, int* stat, ed25519_key* key);
wolfSSL 13:f67a6c6013ca 90 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 91 int wc_ed25519_init(ed25519_key* key);
wolfSSL 13:f67a6c6013ca 92 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 93 void wc_ed25519_free(ed25519_key* key);
wolfSSL 13:f67a6c6013ca 94 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 95 int wc_ed25519_import_public(const byte* in, word32 inLen, ed25519_key* key);
wolfSSL 13:f67a6c6013ca 96 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 97 int wc_ed25519_import_private_only(const byte* priv, word32 privSz,
wolfSSL 13:f67a6c6013ca 98 ed25519_key* key);
wolfSSL 13:f67a6c6013ca 99 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 100 int wc_ed25519_import_private_key(const byte* priv, word32 privSz,
wolfSSL 13:f67a6c6013ca 101 const byte* pub, word32 pubSz, ed25519_key* key);
wolfSSL 13:f67a6c6013ca 102 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 103 int wc_ed25519_export_public(ed25519_key*, byte* out, word32* outLen);
wolfSSL 13:f67a6c6013ca 104 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 105 int wc_ed25519_export_private_only(ed25519_key* key, byte* out, word32* outLen);
wolfSSL 13:f67a6c6013ca 106 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 107 int wc_ed25519_export_private(ed25519_key* key, byte* out, word32* outLen);
wolfSSL 13:f67a6c6013ca 108 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 109 int wc_ed25519_export_key(ed25519_key* key,
wolfSSL 13:f67a6c6013ca 110 byte* priv, word32 *privSz,
wolfSSL 13:f67a6c6013ca 111 byte* pub, word32 *pubSz);
wolfSSL 13:f67a6c6013ca 112
wolfSSL 13:f67a6c6013ca 113 int wc_ed25519_check_key(ed25519_key* key);
wolfSSL 13:f67a6c6013ca 114
wolfSSL 13:f67a6c6013ca 115 /* size helper */
wolfSSL 13:f67a6c6013ca 116 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 117 int wc_ed25519_size(ed25519_key* key);
wolfSSL 13:f67a6c6013ca 118 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 119 int wc_ed25519_priv_size(ed25519_key* key);
wolfSSL 13:f67a6c6013ca 120 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 121 int wc_ed25519_pub_size(ed25519_key* key);
wolfSSL 13:f67a6c6013ca 122 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 123 int wc_ed25519_sig_size(ed25519_key* key);
wolfSSL 13:f67a6c6013ca 124
wolfSSL 13:f67a6c6013ca 125 #ifdef __cplusplus
wolfSSL 13:f67a6c6013ca 126 } /* extern "C" */
wolfSSL 13:f67a6c6013ca 127 #endif
wolfSSL 13:f67a6c6013ca 128
wolfSSL 13:f67a6c6013ca 129 #endif /* HAVE_ED25519 */
wolfSSL 13:f67a6c6013ca 130 #endif /* WOLF_CRYPT_ED25519_H */
wolfSSL 13:f67a6c6013ca 131
wolfSSL 13:f67a6c6013ca 132