wolfSSL SSL/TLS library, support up to TLS1.3
Dependents: CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more
wolfssl/wolfcrypt/curve25519.h@16:8e0d178b1d1e, 2020-06-04 (annotated)
- Committer:
- wolfSSL
- Date:
- Thu Jun 04 23:57:22 2020 +0000
- Revision:
- 16:8e0d178b1d1e
- Parent:
- 15:117db924cf7c
wolfSSL 4.4.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 15:117db924cf7c | 1 | /* curve25519.h |
wolfSSL | 15:117db924cf7c | 2 | * |
wolfSSL | 16:8e0d178b1d1e | 3 | * Copyright (C) 2006-2020 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 | 16:8e0d178b1d1e | 47 | #ifdef WOLFSSL_NAMES_STATIC |
wolfSSL | 16:8e0d178b1d1e | 48 | typedef char curve25519_str[12]; |
wolfSSL | 16:8e0d178b1d1e | 49 | #else |
wolfSSL | 16:8e0d178b1d1e | 50 | typedef const char* curve25519_str; |
wolfSSL | 16:8e0d178b1d1e | 51 | #endif |
wolfSSL | 16:8e0d178b1d1e | 52 | |
wolfSSL | 15:117db924cf7c | 53 | /* curve25519 set type */ |
wolfSSL | 15:117db924cf7c | 54 | typedef struct { |
wolfSSL | 16:8e0d178b1d1e | 55 | int size; /* The size of the curve in octets */ |
wolfSSL | 16:8e0d178b1d1e | 56 | curve25519_str name; /* name of this curve */ |
wolfSSL | 15:117db924cf7c | 57 | } curve25519_set_type; |
wolfSSL | 15:117db924cf7c | 58 | |
wolfSSL | 15:117db924cf7c | 59 | |
wolfSSL | 15:117db924cf7c | 60 | /* ECC point, the internal structure is Little endian |
wolfSSL | 16:8e0d178b1d1e | 61 | * the mathematical functions used the endianness */ |
wolfSSL | 15:117db924cf7c | 62 | typedef struct { |
wolfSSL | 15:117db924cf7c | 63 | byte point[CURVE25519_KEYSIZE]; |
wolfSSL | 15:117db924cf7c | 64 | #ifdef FREESCALE_LTC_ECC |
wolfSSL | 15:117db924cf7c | 65 | byte pointY[CURVE25519_KEYSIZE]; |
wolfSSL | 15:117db924cf7c | 66 | #endif |
wolfSSL | 15:117db924cf7c | 67 | } ECPoint; |
wolfSSL | 15:117db924cf7c | 68 | |
wolfSSL | 15:117db924cf7c | 69 | /* A CURVE25519 Key */ |
wolfSSL | 15:117db924cf7c | 70 | typedef struct curve25519_key { |
wolfSSL | 15:117db924cf7c | 71 | int idx; /* Index into the ecc_sets[] for the parameters of |
wolfSSL | 15:117db924cf7c | 72 | this curve if -1, this key is using user supplied |
wolfSSL | 15:117db924cf7c | 73 | curve in dp */ |
wolfSSL | 15:117db924cf7c | 74 | const curve25519_set_type* dp; /* domain parameters, either points to |
wolfSSL | 15:117db924cf7c | 75 | curves (idx >= 0) or user supplied */ |
wolfSSL | 15:117db924cf7c | 76 | ECPoint p; /* public key */ |
wolfSSL | 15:117db924cf7c | 77 | ECPoint k; /* private key */ |
wolfSSL | 15:117db924cf7c | 78 | |
wolfSSL | 15:117db924cf7c | 79 | #ifdef WOLFSSL_ASYNC_CRYPT |
wolfSSL | 15:117db924cf7c | 80 | WC_ASYNC_DEV asyncDev; |
wolfSSL | 15:117db924cf7c | 81 | #endif |
wolfSSL | 15:117db924cf7c | 82 | } curve25519_key; |
wolfSSL | 15:117db924cf7c | 83 | |
wolfSSL | 15:117db924cf7c | 84 | enum { |
wolfSSL | 15:117db924cf7c | 85 | EC25519_LITTLE_ENDIAN=0, |
wolfSSL | 15:117db924cf7c | 86 | EC25519_BIG_ENDIAN=1 |
wolfSSL | 15:117db924cf7c | 87 | }; |
wolfSSL | 15:117db924cf7c | 88 | |
wolfSSL | 15:117db924cf7c | 89 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 90 | int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key); |
wolfSSL | 15:117db924cf7c | 91 | |
wolfSSL | 15:117db924cf7c | 92 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 93 | int wc_curve25519_shared_secret(curve25519_key* private_key, |
wolfSSL | 15:117db924cf7c | 94 | curve25519_key* public_key, |
wolfSSL | 15:117db924cf7c | 95 | byte* out, word32* outlen); |
wolfSSL | 15:117db924cf7c | 96 | |
wolfSSL | 15:117db924cf7c | 97 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 98 | int wc_curve25519_shared_secret_ex(curve25519_key* private_key, |
wolfSSL | 15:117db924cf7c | 99 | curve25519_key* public_key, |
wolfSSL | 15:117db924cf7c | 100 | byte* out, word32* outlen, int endian); |
wolfSSL | 15:117db924cf7c | 101 | |
wolfSSL | 15:117db924cf7c | 102 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 103 | int wc_curve25519_init(curve25519_key* key); |
wolfSSL | 15:117db924cf7c | 104 | |
wolfSSL | 15:117db924cf7c | 105 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 106 | void wc_curve25519_free(curve25519_key* key); |
wolfSSL | 15:117db924cf7c | 107 | |
wolfSSL | 15:117db924cf7c | 108 | |
wolfSSL | 15:117db924cf7c | 109 | /* raw key helpers */ |
wolfSSL | 15:117db924cf7c | 110 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 111 | int wc_curve25519_import_private(const byte* priv, word32 privSz, |
wolfSSL | 15:117db924cf7c | 112 | curve25519_key* key); |
wolfSSL | 15:117db924cf7c | 113 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 114 | int wc_curve25519_import_private_ex(const byte* priv, word32 privSz, |
wolfSSL | 15:117db924cf7c | 115 | curve25519_key* key, int endian); |
wolfSSL | 15:117db924cf7c | 116 | |
wolfSSL | 15:117db924cf7c | 117 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 118 | int wc_curve25519_import_private_raw(const byte* priv, word32 privSz, |
wolfSSL | 15:117db924cf7c | 119 | const byte* pub, word32 pubSz, curve25519_key* key); |
wolfSSL | 15:117db924cf7c | 120 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 121 | int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz, |
wolfSSL | 15:117db924cf7c | 122 | const byte* pub, word32 pubSz, |
wolfSSL | 15:117db924cf7c | 123 | curve25519_key* key, int endian); |
wolfSSL | 15:117db924cf7c | 124 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 125 | int wc_curve25519_export_private_raw(curve25519_key* key, byte* out, |
wolfSSL | 15:117db924cf7c | 126 | word32* outLen); |
wolfSSL | 15:117db924cf7c | 127 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 128 | int wc_curve25519_export_private_raw_ex(curve25519_key* key, byte* out, |
wolfSSL | 15:117db924cf7c | 129 | word32* outLen, int endian); |
wolfSSL | 15:117db924cf7c | 130 | |
wolfSSL | 15:117db924cf7c | 131 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 132 | int wc_curve25519_import_public(const byte* in, word32 inLen, |
wolfSSL | 15:117db924cf7c | 133 | curve25519_key* key); |
wolfSSL | 15:117db924cf7c | 134 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 135 | int wc_curve25519_import_public_ex(const byte* in, word32 inLen, |
wolfSSL | 15:117db924cf7c | 136 | curve25519_key* key, int endian); |
wolfSSL | 16:8e0d178b1d1e | 137 | WOLFSSL_API |
wolfSSL | 16:8e0d178b1d1e | 138 | int wc_curve25519_check_public(const byte* pub, word32 pubSz, int endian); |
wolfSSL | 15:117db924cf7c | 139 | |
wolfSSL | 15:117db924cf7c | 140 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 141 | int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen); |
wolfSSL | 15:117db924cf7c | 142 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 143 | int wc_curve25519_export_public_ex(curve25519_key* key, byte* out, |
wolfSSL | 15:117db924cf7c | 144 | word32* outLen, int endian); |
wolfSSL | 15:117db924cf7c | 145 | |
wolfSSL | 15:117db924cf7c | 146 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 147 | int wc_curve25519_export_key_raw(curve25519_key* key, |
wolfSSL | 15:117db924cf7c | 148 | byte* priv, word32 *privSz, |
wolfSSL | 15:117db924cf7c | 149 | byte* pub, word32 *pubSz); |
wolfSSL | 15:117db924cf7c | 150 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 151 | int wc_curve25519_export_key_raw_ex(curve25519_key* key, |
wolfSSL | 15:117db924cf7c | 152 | byte* priv, word32 *privSz, |
wolfSSL | 15:117db924cf7c | 153 | byte* pub, word32 *pubSz, |
wolfSSL | 15:117db924cf7c | 154 | int endian); |
wolfSSL | 15:117db924cf7c | 155 | /* size helper */ |
wolfSSL | 15:117db924cf7c | 156 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 157 | int wc_curve25519_size(curve25519_key* key); |
wolfSSL | 15:117db924cf7c | 158 | |
wolfSSL | 15:117db924cf7c | 159 | #ifdef __cplusplus |
wolfSSL | 15:117db924cf7c | 160 | } /* extern "C" */ |
wolfSSL | 15:117db924cf7c | 161 | #endif |
wolfSSL | 15:117db924cf7c | 162 | |
wolfSSL | 15:117db924cf7c | 163 | #endif /* HAVE_CURVE25519 */ |
wolfSSL | 15:117db924cf7c | 164 | #endif /* WOLF_CRYPT_CURVE25519_H */ |
wolfSSL | 15:117db924cf7c | 165 | |
wolfSSL | 15:117db924cf7c | 166 |