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

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

Committer:
wolfSSL
Date:
Thu Apr 28 00:57:21 2016 +0000
Revision:
4:1b0d80432c79
wolfSSL 3.9.0

Who changed what in which revision?

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