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 /* curve25519.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_CURVE25519_H
wolfSSL 13:f67a6c6013ca 24 #define WOLF_CRYPT_CURVE25519_H
wolfSSL 13:f67a6c6013ca 25
wolfSSL 13:f67a6c6013ca 26 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 13:f67a6c6013ca 27
wolfSSL 13:f67a6c6013ca 28 #ifdef HAVE_CURVE25519
wolfSSL 13:f67a6c6013ca 29
wolfSSL 13:f67a6c6013ca 30 #include <wolfssl/wolfcrypt/fe_operations.h>
wolfSSL 13:f67a6c6013ca 31 #include <wolfssl/wolfcrypt/random.h>
wolfSSL 13:f67a6c6013ca 32
wolfSSL 13:f67a6c6013ca 33 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 13:f67a6c6013ca 34 #include <wolfssl/wolfcrypt/async.h>
wolfSSL 13:f67a6c6013ca 35 #endif
wolfSSL 13:f67a6c6013ca 36
wolfSSL 13:f67a6c6013ca 37 #ifdef __cplusplus
wolfSSL 13:f67a6c6013ca 38 extern "C" {
wolfSSL 13:f67a6c6013ca 39 #endif
wolfSSL 13:f67a6c6013ca 40
wolfSSL 13:f67a6c6013ca 41 #define CURVE25519_KEYSIZE 32
wolfSSL 13:f67a6c6013ca 42
wolfSSL 13:f67a6c6013ca 43 /* curve25519 set type */
wolfSSL 13:f67a6c6013ca 44 typedef struct {
wolfSSL 13:f67a6c6013ca 45 int size; /* The size of the curve in octets */
wolfSSL 13:f67a6c6013ca 46 const char* name; /* name of this curve */
wolfSSL 13:f67a6c6013ca 47 } curve25519_set_type;
wolfSSL 13:f67a6c6013ca 48
wolfSSL 13:f67a6c6013ca 49
wolfSSL 13:f67a6c6013ca 50 /* ECC point, the internal structure is Little endian
wolfSSL 13:f67a6c6013ca 51 * the mathematical functions used the endianess */
wolfSSL 13:f67a6c6013ca 52 typedef struct {
wolfSSL 13:f67a6c6013ca 53 byte point[CURVE25519_KEYSIZE];
wolfSSL 13:f67a6c6013ca 54 #ifdef FREESCALE_LTC_ECC
wolfSSL 13:f67a6c6013ca 55 byte pointY[CURVE25519_KEYSIZE];
wolfSSL 13:f67a6c6013ca 56 #endif
wolfSSL 13:f67a6c6013ca 57 } ECPoint;
wolfSSL 13:f67a6c6013ca 58
wolfSSL 13:f67a6c6013ca 59 /* A CURVE25519 Key */
wolfSSL 13:f67a6c6013ca 60 typedef struct curve25519_key {
wolfSSL 13:f67a6c6013ca 61 int idx; /* Index into the ecc_sets[] for the parameters of
wolfSSL 13:f67a6c6013ca 62 this curve if -1, this key is using user supplied
wolfSSL 13:f67a6c6013ca 63 curve in dp */
wolfSSL 13:f67a6c6013ca 64 const curve25519_set_type* dp; /* domain parameters, either points to
wolfSSL 13:f67a6c6013ca 65 curves (idx >= 0) or user supplied */
wolfSSL 13:f67a6c6013ca 66 ECPoint p; /* public key */
wolfSSL 13:f67a6c6013ca 67 ECPoint k; /* private key */
wolfSSL 13:f67a6c6013ca 68
wolfSSL 13:f67a6c6013ca 69 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 13:f67a6c6013ca 70 WC_ASYNC_DEV asyncDev;
wolfSSL 13:f67a6c6013ca 71 #endif
wolfSSL 13:f67a6c6013ca 72 } curve25519_key;
wolfSSL 13:f67a6c6013ca 73
wolfSSL 13:f67a6c6013ca 74 enum {
wolfSSL 13:f67a6c6013ca 75 EC25519_LITTLE_ENDIAN=0,
wolfSSL 13:f67a6c6013ca 76 EC25519_BIG_ENDIAN=1
wolfSSL 13:f67a6c6013ca 77 };
wolfSSL 13:f67a6c6013ca 78
wolfSSL 13:f67a6c6013ca 79 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 80 int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key);
wolfSSL 13:f67a6c6013ca 81
wolfSSL 13:f67a6c6013ca 82 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 83 int wc_curve25519_shared_secret(curve25519_key* private_key,
wolfSSL 13:f67a6c6013ca 84 curve25519_key* public_key,
wolfSSL 13:f67a6c6013ca 85 byte* out, word32* outlen);
wolfSSL 13:f67a6c6013ca 86
wolfSSL 13:f67a6c6013ca 87 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 88 int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
wolfSSL 13:f67a6c6013ca 89 curve25519_key* public_key,
wolfSSL 13:f67a6c6013ca 90 byte* out, word32* outlen, int endian);
wolfSSL 13:f67a6c6013ca 91
wolfSSL 13:f67a6c6013ca 92 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 93 int wc_curve25519_init(curve25519_key* key);
wolfSSL 13:f67a6c6013ca 94
wolfSSL 13:f67a6c6013ca 95 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 96 void wc_curve25519_free(curve25519_key* key);
wolfSSL 13:f67a6c6013ca 97
wolfSSL 13:f67a6c6013ca 98
wolfSSL 13:f67a6c6013ca 99 /* raw key helpers */
wolfSSL 13:f67a6c6013ca 100 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 101 int wc_curve25519_import_private(const byte* priv, word32 privSz,
wolfSSL 13:f67a6c6013ca 102 curve25519_key* key);
wolfSSL 13:f67a6c6013ca 103 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 104 int wc_curve25519_import_private_ex(const byte* priv, word32 privSz,
wolfSSL 13:f67a6c6013ca 105 curve25519_key* key, int endian);
wolfSSL 13:f67a6c6013ca 106
wolfSSL 13:f67a6c6013ca 107 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 108 int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
wolfSSL 13:f67a6c6013ca 109 const byte* pub, word32 pubSz, curve25519_key* key);
wolfSSL 13:f67a6c6013ca 110 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 111 int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz,
wolfSSL 13:f67a6c6013ca 112 const byte* pub, word32 pubSz,
wolfSSL 13:f67a6c6013ca 113 curve25519_key* key, int endian);
wolfSSL 13:f67a6c6013ca 114 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 115 int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
wolfSSL 13:f67a6c6013ca 116 word32* outLen);
wolfSSL 13:f67a6c6013ca 117 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 118 int wc_curve25519_export_private_raw_ex(curve25519_key* key, byte* out,
wolfSSL 13:f67a6c6013ca 119 word32* outLen, int endian);
wolfSSL 13:f67a6c6013ca 120
wolfSSL 13:f67a6c6013ca 121 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 122 int wc_curve25519_import_public(const byte* in, word32 inLen,
wolfSSL 13:f67a6c6013ca 123 curve25519_key* key);
wolfSSL 13:f67a6c6013ca 124 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 125 int wc_curve25519_import_public_ex(const byte* in, word32 inLen,
wolfSSL 13:f67a6c6013ca 126 curve25519_key* key, int endian);
wolfSSL 13:f67a6c6013ca 127
wolfSSL 13:f67a6c6013ca 128 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 129 int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen);
wolfSSL 13:f67a6c6013ca 130 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 131 int wc_curve25519_export_public_ex(curve25519_key* key, byte* out,
wolfSSL 13:f67a6c6013ca 132 word32* outLen, int endian);
wolfSSL 13:f67a6c6013ca 133
wolfSSL 13:f67a6c6013ca 134 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 135 int wc_curve25519_export_key_raw(curve25519_key* key,
wolfSSL 13:f67a6c6013ca 136 byte* priv, word32 *privSz,
wolfSSL 13:f67a6c6013ca 137 byte* pub, word32 *pubSz);
wolfSSL 13:f67a6c6013ca 138 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 139 int wc_curve25519_export_key_raw_ex(curve25519_key* key,
wolfSSL 13:f67a6c6013ca 140 byte* priv, word32 *privSz,
wolfSSL 13:f67a6c6013ca 141 byte* pub, word32 *pubSz,
wolfSSL 13:f67a6c6013ca 142 int endian);
wolfSSL 13:f67a6c6013ca 143 /* size helper */
wolfSSL 13:f67a6c6013ca 144 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 145 int wc_curve25519_size(curve25519_key* key);
wolfSSL 13:f67a6c6013ca 146
wolfSSL 13:f67a6c6013ca 147 #ifdef __cplusplus
wolfSSL 13:f67a6c6013ca 148 } /* extern "C" */
wolfSSL 13:f67a6c6013ca 149 #endif
wolfSSL 13:f67a6c6013ca 150
wolfSSL 13:f67a6c6013ca 151 #endif /* HAVE_CURVE25519 */
wolfSSL 13:f67a6c6013ca 152 #endif /* WOLF_CRYPT_CURVE25519_H */
wolfSSL 13:f67a6c6013ca 153
wolfSSL 13:f67a6c6013ca 154