ed448.h
Go to the documentation of this file.
1 /* ed448.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 
27 #ifndef WOLF_CRYPT_ED448_H
28 #define WOLF_CRYPT_ED448_H
29 
31 
32 #ifdef HAVE_ED448
33 
34 #include <wolfssl/wolfcrypt/fe_448.h>
35 #include <wolfssl/wolfcrypt/ge_448.h>
37 #include <wolfssl/wolfcrypt/sha3.h>
38 
39 #ifdef WOLFSSL_ASYNC_CRYPT
40  #include <wolfssl/wolfcrypt/async.h>
41 #endif
42 
43 #ifdef __cplusplus
44  extern "C" {
45 #endif
46 
47 
48 /* info about EdDSA curve specifically ed448, defined as an elliptic curve
49  * over GF(p)
50  *
51  * 56 key size
52  * "ED448" curve name
53  * "2^448-2^224-1" prime number
54  * "-39081" value of d
55  * "SHAKE256" hash function
56  */
57 
58 #define ED448_KEY_SIZE 57 /* private key only */
59 #define ED448_SIG_SIZE 114 /* two elements */
60 
61 #define ED448_PUB_KEY_SIZE 57 /* compressed */
62 /* both private and public key */
63 #define ED448_PRV_KEY_SIZE (ED448_PUB_KEY_SIZE+ED448_KEY_SIZE)
64 
65 
66 enum {
67  Ed448 = 0,
68  Ed448ph = 1,
69 };
70 
71 #ifndef WC_ED448KEY_TYPE_DEFINED
72  typedef struct ed448_key ed448_key;
73  #define WC_ED448KEY_TYPE_DEFINED
74 #endif
75 
76 /* An ED448 Key */
77 struct ed448_key {
78  byte p[ED448_PUB_KEY_SIZE]; /* compressed public key */
79  byte k[ED448_PRV_KEY_SIZE]; /* private key : 56 secret -- 56 public */
80 #ifdef FREESCALE_LTC_ECC
81  /* uncompressed point coordinates */
82  byte pointX[ED448_KEY_SIZE]; /* recovered X coordinate */
83  byte pointY[ED448_KEY_SIZE]; /* Y coordinate is the public key with The most significant bit of the final octet always zero. */
84 #endif
85  word16 pubKeySet:1;
86 #ifdef WOLFSSL_ASYNC_CRYPT
87  WC_ASYNC_DEV asyncDev;
88 #endif
89 };
90 
91 
92 WOLFSSL_API
93 int wc_ed448_make_public(ed448_key* key, unsigned char* pubKey,
94  word32 pubKeySz);
95 WOLFSSL_API
96 int wc_ed448_make_key(WC_RNG* rng, int keysize, ed448_key* key);
97 WOLFSSL_API
98 int wc_ed448_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
99  ed448_key* key, const byte* context, byte contextLen);
100 WOLFSSL_API
101 int wc_ed448ph_sign_hash(const byte* hash, word32 hashLen, byte* out,
102  word32 *outLen, ed448_key* key,
103  const byte* context, byte contextLen);
104 WOLFSSL_API
105 int wc_ed448ph_sign_msg(const byte* in, word32 inLen, byte* out,
106  word32 *outLen, ed448_key* key, const byte* context,
107  byte contextLen);
108 WOLFSSL_API
109 int wc_ed448_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
110  word32 msgLen, int* stat, ed448_key* key,
111  const byte* context, byte contextLen);
112 WOLFSSL_API
113 int wc_ed448ph_verify_hash(const byte* sig, word32 sigLen, const byte* hash,
114  word32 hashLen, int* stat, ed448_key* key,
115  const byte* context, byte contextLen);
116 WOLFSSL_API
117 int wc_ed448ph_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
118  word32 msgLen, int* stat, ed448_key* key,
119  const byte* context, byte contextLen);
120 WOLFSSL_API
121 int wc_ed448_init(ed448_key* key);
122 WOLFSSL_API
123 void wc_ed448_free(ed448_key* key);
124 WOLFSSL_API
125 int wc_ed448_import_public(const byte* in, word32 inLen, ed448_key* key);
126 WOLFSSL_API
127 int wc_ed448_import_private_only(const byte* priv, word32 privSz,
128  ed448_key* key);
129 WOLFSSL_API
130 int wc_ed448_import_private_key(const byte* priv, word32 privSz,
131  const byte* pub, word32 pubSz, ed448_key* key);
132 WOLFSSL_API
133 int wc_ed448_export_public(ed448_key*, byte* out, word32* outLen);
134 WOLFSSL_API
135 int wc_ed448_export_private_only(ed448_key* key, byte* out, word32* outLen);
136 WOLFSSL_API
137 int wc_ed448_export_private(ed448_key* key, byte* out, word32* outLen);
138 WOLFSSL_API
139 int wc_ed448_export_key(ed448_key* key, byte* priv, word32 *privSz,
140  byte* pub, word32 *pubSz);
141 
142 WOLFSSL_API
143 int wc_ed448_check_key(ed448_key* key);
144 
145 /* size helper */
146 WOLFSSL_API
147 int wc_ed448_size(ed448_key* key);
148 WOLFSSL_API
149 int wc_ed448_priv_size(ed448_key* key);
150 WOLFSSL_API
151 int wc_ed448_pub_size(ed448_key* key);
152 WOLFSSL_API
153 int wc_ed448_sig_size(ed448_key* key);
154 
155 #ifdef __cplusplus
156  } /* extern "C" */
157 #endif
158 
159 #endif /* HAVE_ED448 */
160 #endif /* WOLF_CRYPT_ED448_H */
Definition: ed448.h:77
Definition: random.h:153