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

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

Committer:
wolfSSL
Date:
Sat Aug 18 22:20:43 2018 +0000
Revision:
15:117db924cf7c
Child:
16:8e0d178b1d1e
wolfSSL 3.15.3

Who changed what in which revision?

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