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