]> begriffs open source - freertos/blob - FreeRTOS-Plus/Source/WolfSSL/wolfssl/wolfcrypt/ed25519.h
Update WolfSSL library to the latest version.
[freertos] / FreeRTOS-Plus / Source / WolfSSL / wolfssl / wolfcrypt / ed25519.h
1 /* ed25519.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_ED25519_H
23 #define WOLF_CRYPT_ED25519_H
24
25 #include <wolfssl/wolfcrypt/types.h>
26
27 #ifdef HAVE_ED25519
28
29 #include <wolfssl/wolfcrypt/fe_operations.h>
30 #include <wolfssl/wolfcrypt/ge_operations.h>
31 #include <wolfssl/wolfcrypt/random.h>
32 #include <wolfssl/wolfcrypt/sha512.h>
33
34 #ifdef __cplusplus
35     extern "C" {
36 #endif
37
38
39 /* info about EdDSA curve specifically ed25519, defined as an elliptic curve
40    over GF(p) */
41 /*
42     32,                key size
43     "ED25519",         curve name
44     "2^255-19",        prime number
45     "SHA512",          hash function
46     "-121665/121666",  value of d
47 */
48
49 #define ED25519_KEY_SIZE 32
50 #define ED25519_SIG_SIZE 64
51
52
53 /* An ED25519 Key */
54 typedef struct {
55     byte    p[32];        /* compressed public key */
56     byte    k[64];        /* private key : 32 secret -- 32 public */
57 } ed25519_key;
58
59
60 WOLFSSL_API
61 int wc_ed25519_make_key(RNG* rng, int keysize, ed25519_key* key);
62 WOLFSSL_API
63 int wc_ed25519_sign_msg(const byte* in, word32 inlen, byte* out,
64                         word32 *outlen, ed25519_key* key);
65 WOLFSSL_API
66 int wc_ed25519_verify_msg(byte* sig, word32 siglen, const byte* msg,
67                           word32 msglen, int* stat, ed25519_key* key);
68 WOLFSSL_API
69 int wc_ed25519_init(ed25519_key* key);
70 WOLFSSL_API
71 void wc_ed25519_free(ed25519_key* key);
72 WOLFSSL_API
73 int wc_ed25519_import_public(const byte* in, word32 inLen, ed25519_key* key);
74 WOLFSSL_API
75 int wc_ed25519_import_private_key(const byte* priv, word32 privSz,
76                                const byte* pub, word32 pubSz, ed25519_key* key);
77 WOLFSSL_API
78 int wc_ed25519_export_public(ed25519_key*, byte* out, word32* outLen);
79 WOLFSSL_API
80 int wc_ed25519_export_private_only(ed25519_key* key, byte* out, word32* outLen);
81
82 /* size helper */
83 WOLFSSL_API
84 int wc_ed25519_size(ed25519_key* key);
85 WOLFSSL_API
86 int wc_ed25519_sig_size(ed25519_key* key);
87
88 #ifdef __cplusplus
89     }    /* extern "C" */
90 #endif
91
92 #endif /* HAVE_ED25519 */
93 #endif /* WOLF_CRYPT_ED25519_H */
94