Xuyi Wang / wolfSSL

Dependents:   OS

Committer:
wolfSSL
Date:
Tue May 02 08:44:47 2017 +0000
Revision:
7:481bce714567
wolfSSL3.10.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 7:481bce714567 1 /* curve25519.h
wolfSSL 7:481bce714567 2 *
wolfSSL 7:481bce714567 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 7:481bce714567 4 *
wolfSSL 7:481bce714567 5 * This file is part of wolfSSL.
wolfSSL 7:481bce714567 6 *
wolfSSL 7:481bce714567 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 7:481bce714567 8 * it under the terms of the GNU General Public License as published by
wolfSSL 7:481bce714567 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 7:481bce714567 10 * (at your option) any later version.
wolfSSL 7:481bce714567 11 *
wolfSSL 7:481bce714567 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 7:481bce714567 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 7:481bce714567 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 7:481bce714567 15 * GNU General Public License for more details.
wolfSSL 7:481bce714567 16 *
wolfSSL 7:481bce714567 17 * You should have received a copy of the GNU General Public License
wolfSSL 7:481bce714567 18 * along with this program; if not, write to the Free Software
wolfSSL 7:481bce714567 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 7:481bce714567 20 */
wolfSSL 7:481bce714567 21
wolfSSL 7:481bce714567 22
wolfSSL 7:481bce714567 23 #ifndef WOLF_CRYPT_CURVE25519_H
wolfSSL 7:481bce714567 24 #define WOLF_CRYPT_CURVE25519_H
wolfSSL 7:481bce714567 25
wolfSSL 7:481bce714567 26 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 7:481bce714567 27
wolfSSL 7:481bce714567 28 #ifdef HAVE_CURVE25519
wolfSSL 7:481bce714567 29
wolfSSL 7:481bce714567 30 #include <wolfssl/wolfcrypt/fe_operations.h>
wolfSSL 7:481bce714567 31 #include <wolfssl/wolfcrypt/random.h>
wolfSSL 7:481bce714567 32
wolfSSL 7:481bce714567 33 #ifdef __cplusplus
wolfSSL 7:481bce714567 34 extern "C" {
wolfSSL 7:481bce714567 35 #endif
wolfSSL 7:481bce714567 36
wolfSSL 7:481bce714567 37 #define CURVE25519_KEYSIZE 32
wolfSSL 7:481bce714567 38
wolfSSL 7:481bce714567 39 /* curve25519 set type */
wolfSSL 7:481bce714567 40 typedef struct {
wolfSSL 7:481bce714567 41 int size; /* The size of the curve in octets */
wolfSSL 7:481bce714567 42 const char* name; /* name of this curve */
wolfSSL 7:481bce714567 43 } curve25519_set_type;
wolfSSL 7:481bce714567 44
wolfSSL 7:481bce714567 45
wolfSSL 7:481bce714567 46 /* ECC point, the internal structure is Little endian
wolfSSL 7:481bce714567 47 * the mathematical functions used the endianess */
wolfSSL 7:481bce714567 48 typedef struct {
wolfSSL 7:481bce714567 49 byte point[CURVE25519_KEYSIZE];
wolfSSL 7:481bce714567 50 #ifdef FREESCALE_LTC_ECC
wolfSSL 7:481bce714567 51 byte pointY[CURVE25519_KEYSIZE];
wolfSSL 7:481bce714567 52 #endif
wolfSSL 7:481bce714567 53 }ECPoint;
wolfSSL 7:481bce714567 54
wolfSSL 7:481bce714567 55 /* A CURVE25519 Key */
wolfSSL 7:481bce714567 56 typedef struct {
wolfSSL 7:481bce714567 57 int idx; /* Index into the ecc_sets[] for the parameters of
wolfSSL 7:481bce714567 58 this curve if -1, this key is using user supplied
wolfSSL 7:481bce714567 59 curve in dp */
wolfSSL 7:481bce714567 60 const curve25519_set_type* dp; /* domain parameters, either points to
wolfSSL 7:481bce714567 61 curves (idx >= 0) or user supplied */
wolfSSL 7:481bce714567 62 ECPoint p; /* public key */
wolfSSL 7:481bce714567 63 ECPoint k; /* private key */
wolfSSL 7:481bce714567 64 } curve25519_key;
wolfSSL 7:481bce714567 65
wolfSSL 7:481bce714567 66 enum {
wolfSSL 7:481bce714567 67 EC25519_LITTLE_ENDIAN=0,
wolfSSL 7:481bce714567 68 EC25519_BIG_ENDIAN=1
wolfSSL 7:481bce714567 69 };
wolfSSL 7:481bce714567 70
wolfSSL 7:481bce714567 71 WOLFSSL_API
wolfSSL 7:481bce714567 72 int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key);
wolfSSL 7:481bce714567 73
wolfSSL 7:481bce714567 74 WOLFSSL_API
wolfSSL 7:481bce714567 75 int wc_curve25519_shared_secret(curve25519_key* private_key,
wolfSSL 7:481bce714567 76 curve25519_key* public_key,
wolfSSL 7:481bce714567 77 byte* out, word32* outlen);
wolfSSL 7:481bce714567 78
wolfSSL 7:481bce714567 79 WOLFSSL_API
wolfSSL 7:481bce714567 80 int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
wolfSSL 7:481bce714567 81 curve25519_key* public_key,
wolfSSL 7:481bce714567 82 byte* out, word32* outlen, int endian);
wolfSSL 7:481bce714567 83
wolfSSL 7:481bce714567 84 WOLFSSL_API
wolfSSL 7:481bce714567 85 int wc_curve25519_init(curve25519_key* key);
wolfSSL 7:481bce714567 86
wolfSSL 7:481bce714567 87 WOLFSSL_API
wolfSSL 7:481bce714567 88 void wc_curve25519_free(curve25519_key* key);
wolfSSL 7:481bce714567 89
wolfSSL 7:481bce714567 90
wolfSSL 7:481bce714567 91 /* raw key helpers */
wolfSSL 7:481bce714567 92 WOLFSSL_API
wolfSSL 7:481bce714567 93 int wc_curve25519_import_private(const byte* priv, word32 privSz,
wolfSSL 7:481bce714567 94 curve25519_key* key);
wolfSSL 7:481bce714567 95 WOLFSSL_API
wolfSSL 7:481bce714567 96 int wc_curve25519_import_private_ex(const byte* priv, word32 privSz,
wolfSSL 7:481bce714567 97 curve25519_key* key, int endian);
wolfSSL 7:481bce714567 98
wolfSSL 7:481bce714567 99 WOLFSSL_API
wolfSSL 7:481bce714567 100 int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
wolfSSL 7:481bce714567 101 const byte* pub, word32 pubSz, curve25519_key* key);
wolfSSL 7:481bce714567 102 WOLFSSL_API
wolfSSL 7:481bce714567 103 int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz,
wolfSSL 7:481bce714567 104 const byte* pub, word32 pubSz,
wolfSSL 7:481bce714567 105 curve25519_key* key, int endian);
wolfSSL 7:481bce714567 106 WOLFSSL_API
wolfSSL 7:481bce714567 107 int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
wolfSSL 7:481bce714567 108 word32* outLen);
wolfSSL 7:481bce714567 109 WOLFSSL_API
wolfSSL 7:481bce714567 110 int wc_curve25519_export_private_raw_ex(curve25519_key* key, byte* out,
wolfSSL 7:481bce714567 111 word32* outLen, int endian);
wolfSSL 7:481bce714567 112
wolfSSL 7:481bce714567 113 WOLFSSL_API
wolfSSL 7:481bce714567 114 int wc_curve25519_import_public(const byte* in, word32 inLen,
wolfSSL 7:481bce714567 115 curve25519_key* key);
wolfSSL 7:481bce714567 116 WOLFSSL_API
wolfSSL 7:481bce714567 117 int wc_curve25519_import_public_ex(const byte* in, word32 inLen,
wolfSSL 7:481bce714567 118 curve25519_key* key, int endian);
wolfSSL 7:481bce714567 119
wolfSSL 7:481bce714567 120 WOLFSSL_API
wolfSSL 7:481bce714567 121 int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen);
wolfSSL 7:481bce714567 122 WOLFSSL_API
wolfSSL 7:481bce714567 123 int wc_curve25519_export_public_ex(curve25519_key* key, byte* out,
wolfSSL 7:481bce714567 124 word32* outLen, int endian);
wolfSSL 7:481bce714567 125
wolfSSL 7:481bce714567 126 WOLFSSL_API
wolfSSL 7:481bce714567 127 int wc_curve25519_export_key_raw(curve25519_key* key,
wolfSSL 7:481bce714567 128 byte* priv, word32 *privSz,
wolfSSL 7:481bce714567 129 byte* pub, word32 *pubSz);
wolfSSL 7:481bce714567 130 WOLFSSL_API
wolfSSL 7:481bce714567 131 int wc_curve25519_export_key_raw_ex(curve25519_key* key,
wolfSSL 7:481bce714567 132 byte* priv, word32 *privSz,
wolfSSL 7:481bce714567 133 byte* pub, word32 *pubSz,
wolfSSL 7:481bce714567 134 int endian);
wolfSSL 7:481bce714567 135 /* size helper */
wolfSSL 7:481bce714567 136 WOLFSSL_API
wolfSSL 7:481bce714567 137 int wc_curve25519_size(curve25519_key* key);
wolfSSL 7:481bce714567 138
wolfSSL 7:481bce714567 139 #ifdef __cplusplus
wolfSSL 7:481bce714567 140 } /* extern "C" */
wolfSSL 7:481bce714567 141 #endif
wolfSSL 7:481bce714567 142
wolfSSL 7:481bce714567 143 #endif /* HAVE_CURVE25519 */
wolfSSL 7:481bce714567 144 #endif /* WOLF_CRYPT_CURVE25519_H */
wolfSSL 7:481bce714567 145
wolfSSL 7:481bce714567 146