wolfSSL 3.11.1 for TLS1.3 beta

Fork of wolfSSL by wolf SSL

Committer:
wolfSSL
Date:
Tue May 30 01:44:10 2017 +0000
Revision:
11:cee25a834751
wolfSSL 3.11.0

Who changed what in which revision?

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