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