blob: d45585a3f1d65b05009d56655d809c4090655bd0 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* ed448.h
2 *
3 * Copyright (C) 2006-2021 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/ed448.h
24*/
25
26
27#ifndef WOLF_CRYPT_ED448_H
28#define WOLF_CRYPT_ED448_H
29
30#include <wolfssl/wolfcrypt/types.h>
31
32#ifdef HAVE_ED448
33
34#include <wolfssl/wolfcrypt/fe_448.h>
35#include <wolfssl/wolfcrypt/ge_448.h>
36#include <wolfssl/wolfcrypt/random.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
66enum {
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 */
77struct 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
92WOLFSSL_API
93int wc_ed448_make_public(ed448_key* key, unsigned char* pubKey,
94 word32 pubKeySz);
95WOLFSSL_API
96int wc_ed448_make_key(WC_RNG* rng, int keysize, ed448_key* key);
97WOLFSSL_API
98int wc_ed448_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
99 ed448_key* key, const byte* context, byte contextLen);
100WOLFSSL_API
101int wc_ed448ph_sign_hash(const byte* hash, word32 hashLen, byte* out,
102 word32 *outLen, ed448_key* key,
103 const byte* context, byte contextLen);
104WOLFSSL_API
105int wc_ed448ph_sign_msg(const byte* in, word32 inLen, byte* out,
106 word32 *outLen, ed448_key* key, const byte* context,
107 byte contextLen);
108WOLFSSL_API
109int 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);
112WOLFSSL_API
113int 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);
116WOLFSSL_API
117int 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);
120WOLFSSL_API
121int wc_ed448_init(ed448_key* key);
122WOLFSSL_API
123void wc_ed448_free(ed448_key* key);
124WOLFSSL_API
125int wc_ed448_import_public(const byte* in, word32 inLen, ed448_key* key);
126WOLFSSL_API
127int wc_ed448_import_private_only(const byte* priv, word32 privSz,
128 ed448_key* key);
129WOLFSSL_API
130int wc_ed448_import_private_key(const byte* priv, word32 privSz,
131 const byte* pub, word32 pubSz, ed448_key* key);
132WOLFSSL_API
133int wc_ed448_export_public(ed448_key*, byte* out, word32* outLen);
134WOLFSSL_API
135int wc_ed448_export_private_only(ed448_key* key, byte* out, word32* outLen);
136WOLFSSL_API
137int wc_ed448_export_private(ed448_key* key, byte* out, word32* outLen);
138WOLFSSL_API
139int wc_ed448_export_key(ed448_key* key, byte* priv, word32 *privSz,
140 byte* pub, word32 *pubSz);
141
142WOLFSSL_API
143int wc_ed448_check_key(ed448_key* key);
144
145/* size helper */
146WOLFSSL_API
147int wc_ed448_size(ed448_key* key);
148WOLFSSL_API
149int wc_ed448_priv_size(ed448_key* key);
150WOLFSSL_API
151int wc_ed448_pub_size(ed448_key* key);
152WOLFSSL_API
153int 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 */