[164] | 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 /* private key only */
|
---|
| 50 | #define ED25519_SIG_SIZE 64
|
---|
| 51 |
|
---|
| 52 | #define ED25519_PUB_KEY_SIZE 32 /* compressed */
|
---|
| 53 | /* both private and public key */
|
---|
| 54 | #define ED25519_PRV_KEY_SIZE (ED25519_PUB_KEY_SIZE+ED25519_KEY_SIZE)
|
---|
| 55 |
|
---|
| 56 | /* An ED25519 Key */
|
---|
| 57 | typedef struct {
|
---|
| 58 | byte p[ED25519_PUB_KEY_SIZE]; /* compressed public key */
|
---|
| 59 | byte k[ED25519_PRV_KEY_SIZE]; /* private key : 32 secret -- 32 public */
|
---|
| 60 | } ed25519_key;
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | WOLFSSL_API
|
---|
| 64 | int wc_ed25519_make_key(WC_RNG* rng, int keysize, ed25519_key* key);
|
---|
| 65 | WOLFSSL_API
|
---|
| 66 | int wc_ed25519_sign_msg(const byte* in, word32 inlen, byte* out,
|
---|
| 67 | word32 *outlen, ed25519_key* key);
|
---|
| 68 | WOLFSSL_API
|
---|
| 69 | int wc_ed25519_verify_msg(byte* sig, word32 siglen, const byte* msg,
|
---|
| 70 | word32 msglen, int* stat, ed25519_key* key);
|
---|
| 71 | WOLFSSL_API
|
---|
| 72 | int wc_ed25519_init(ed25519_key* key);
|
---|
| 73 | WOLFSSL_API
|
---|
| 74 | void wc_ed25519_free(ed25519_key* key);
|
---|
| 75 | WOLFSSL_API
|
---|
| 76 | int wc_ed25519_import_public(const byte* in, word32 inLen, ed25519_key* key);
|
---|
| 77 | WOLFSSL_API
|
---|
| 78 | int wc_ed25519_import_private_key(const byte* priv, word32 privSz,
|
---|
| 79 | const byte* pub, word32 pubSz, ed25519_key* key);
|
---|
| 80 | WOLFSSL_API
|
---|
| 81 | int wc_ed25519_export_public(ed25519_key*, byte* out, word32* outLen);
|
---|
| 82 | WOLFSSL_API
|
---|
| 83 | int wc_ed25519_export_private_only(ed25519_key* key, byte* out, word32* outLen);
|
---|
| 84 | WOLFSSL_API
|
---|
| 85 | int wc_ed25519_export_private(ed25519_key* key, byte* out, word32* outLen);
|
---|
| 86 | WOLFSSL_API
|
---|
| 87 | int wc_ed25519_export_key(ed25519_key* key,
|
---|
| 88 | byte* priv, word32 *privSz,
|
---|
| 89 | byte* pub, word32 *pubSz);
|
---|
| 90 |
|
---|
| 91 | /* size helper */
|
---|
| 92 | WOLFSSL_API
|
---|
| 93 | int wc_ed25519_size(ed25519_key* key);
|
---|
| 94 | WOLFSSL_API
|
---|
| 95 | int wc_ed25519_priv_size(ed25519_key* key);
|
---|
| 96 | WOLFSSL_API
|
---|
| 97 | int wc_ed25519_pub_size(ed25519_key* key);
|
---|
| 98 | WOLFSSL_API
|
---|
| 99 | int wc_ed25519_sig_size(ed25519_key* key);
|
---|
| 100 |
|
---|
| 101 | #ifdef __cplusplus
|
---|
| 102 | } /* extern "C" */
|
---|
| 103 | #endif
|
---|
| 104 |
|
---|
| 105 | #endif /* HAVE_ED25519 */
|
---|
| 106 | #endif /* WOLF_CRYPT_ED25519_H */
|
---|
| 107 |
|
---|