curve448.h
1 /* curve448.h
2  *
3  * Copyright (C) 2006-2020 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 /* Implemented to: RFC 7748 */
23 
24 
25 #ifndef WOLF_CRYPT_CURVE448_H
26 #define WOLF_CRYPT_CURVE448_H
27 
29 
30 #ifdef HAVE_CURVE448
31 
32 #include <wolfssl/wolfcrypt/fe_448.h>
34 
35 #ifdef WOLFSSL_ASYNC_CRYPT
36  #include <wolfssl/wolfcrypt/async.h>
37 #endif
38 
39 #ifdef __cplusplus
40  extern "C" {
41 #endif
42 
43 #define CURVE448_KEY_SIZE 56
44 #define CURVE448_PUB_KEY_SIZE 56
45 
46 
47 /* A CURVE448 Key */
48 typedef struct curve448_key {
49  byte p[CURVE448_PUB_KEY_SIZE]; /* public key */
50  byte k[CURVE448_KEY_SIZE]; /* private key */
51 
52 #ifdef WOLFSSL_ASYNC_CRYPT
53  WC_ASYNC_DEV asyncDev;
54 #endif
55 } curve448_key;
56 
57 enum {
58  EC448_LITTLE_ENDIAN = 0,
59  EC448_BIG_ENDIAN = 1
60 };
61 
62 WOLFSSL_API
63 int wc_curve448_make_key(WC_RNG* rng, int keysize, curve448_key* key);
64 
65 WOLFSSL_API
66 int wc_curve448_shared_secret(curve448_key* private_key,
67  curve448_key* public_key,
68  byte* out, word32* outlen);
69 
70 WOLFSSL_API
71 int wc_curve448_shared_secret_ex(curve448_key* private_key,
72  curve448_key* public_key,
73  byte* out, word32* outlen, int endian);
74 
75 WOLFSSL_API
76 int wc_curve448_init(curve448_key* key);
77 
78 WOLFSSL_API
79 void wc_curve448_free(curve448_key* key);
80 
81 
82 /* raw key helpers */
83 WOLFSSL_API
84 int wc_curve448_import_private(const byte* priv, word32 privSz,
85  curve448_key* key);
86 WOLFSSL_API
87 int wc_curve448_import_private_ex(const byte* priv, word32 privSz,
88  curve448_key* key, int endian);
89 
90 WOLFSSL_API
91 int wc_curve448_import_private_raw(const byte* priv, word32 privSz,
92  const byte* pub, word32 pubSz,
93  curve448_key* key);
94 WOLFSSL_API
95 int wc_curve448_import_private_raw_ex(const byte* priv, word32 privSz,
96  const byte* pub, word32 pubSz,
97  curve448_key* key, int endian);
98 WOLFSSL_API
99 int wc_curve448_export_private_raw(curve448_key* key, byte* out,
100  word32* outLen);
101 WOLFSSL_API
102 int wc_curve448_export_private_raw_ex(curve448_key* key, byte* out,
103  word32* outLen, int endian);
104 
105 WOLFSSL_API
106 int wc_curve448_import_public(const byte* in, word32 inLen,
107  curve448_key* key);
108 WOLFSSL_API
109 int wc_curve448_import_public_ex(const byte* in, word32 inLen,
110  curve448_key* key, int endian);
111 WOLFSSL_API
112 int wc_curve448_check_public(const byte* pub, word32 pubSz, int endian);
113 
114 WOLFSSL_API
115 int wc_curve448_export_public(curve448_key* key, byte* out, word32* outLen);
116 WOLFSSL_API
117 int wc_curve448_export_public_ex(curve448_key* key, byte* out,
118  word32* outLen, int endian);
119 
120 WOLFSSL_API
121 int wc_curve448_export_key_raw(curve448_key* key,
122  byte* priv, word32 *privSz,
123  byte* pub, word32 *pubSz);
124 WOLFSSL_API
125 int wc_curve448_export_key_raw_ex(curve448_key* key,
126  byte* priv, word32 *privSz,
127  byte* pub, word32 *pubSz,
128  int endian);
129 /* size helper */
130 WOLFSSL_API
131 int wc_curve448_size(curve448_key* key);
132 
133 #ifdef __cplusplus
134  } /* extern "C" */
135 #endif
136 
137 #endif /* HAVE_CURVE448 */
138 #endif /* WOLF_CRYPT_CURVE448_H */
139 
Definition: random.h:153