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