Renesas / SecureDweet
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ed25519.h Source File

ed25519.h

00001 /* ed25519.h
00002  *
00003  * Copyright (C) 2006-2016 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 
00023 #ifndef WOLF_CRYPT_ED25519_H
00024 #define WOLF_CRYPT_ED25519_H
00025 
00026 #include <wolfssl/wolfcrypt/types.h>
00027 
00028 #ifdef HAVE_ED25519
00029 
00030 #include <wolfssl/wolfcrypt/fe_operations.h>
00031 #include <wolfssl/wolfcrypt/ge_operations.h>
00032 #include <wolfssl/wolfcrypt/random.h>
00033 #include <wolfssl/wolfcrypt/sha512.h>
00034 
00035 #ifdef __cplusplus
00036     extern "C" {
00037 #endif
00038 
00039 
00040 /* info about EdDSA curve specifically ed25519, defined as an elliptic curve
00041    over GF(p) */
00042 /*
00043     32,                key size
00044     "ED25519",         curve name
00045     "2^255-19",        prime number
00046     "SHA512",          hash function
00047     "-121665/121666",  value of d
00048 */
00049 
00050 #define ED25519_KEY_SIZE     32 /* private key only */
00051 #define ED25519_SIG_SIZE     64
00052 
00053 #define ED25519_PUB_KEY_SIZE 32 /* compressed */
00054 /* both private and public key */
00055 #define ED25519_PRV_KEY_SIZE (ED25519_PUB_KEY_SIZE+ED25519_KEY_SIZE)
00056 
00057 /* An ED25519 Key */
00058 typedef struct {
00059     byte    p[ED25519_PUB_KEY_SIZE]; /* compressed public key */
00060     byte    k[ED25519_PRV_KEY_SIZE]; /* private key : 32 secret -- 32 public */
00061 } ed25519_key;
00062 
00063 
00064 WOLFSSL_API
00065 int wc_ed25519_make_key(WC_RNG* rng, int keysize, ed25519_key* key);
00066 WOLFSSL_API
00067 int wc_ed25519_sign_msg(const byte* in, word32 inlen, byte* out,
00068                         word32 *outlen, ed25519_key* key);
00069 WOLFSSL_API
00070 int wc_ed25519_verify_msg(byte* sig, word32 siglen, const byte* msg,
00071                           word32 msglen, int* stat, ed25519_key* key);
00072 WOLFSSL_API
00073 int wc_ed25519_init(ed25519_key* key);
00074 WOLFSSL_API
00075 void wc_ed25519_free(ed25519_key* key);
00076 WOLFSSL_API
00077 int wc_ed25519_import_public(const byte* in, word32 inLen, ed25519_key* key);
00078 WOLFSSL_API
00079 int wc_ed25519_import_private_key(const byte* priv, word32 privSz,
00080                                const byte* pub, word32 pubSz, ed25519_key* key);
00081 WOLFSSL_API
00082 int wc_ed25519_export_public(ed25519_key*, byte* out, word32* outLen);
00083 WOLFSSL_API
00084 int wc_ed25519_export_private_only(ed25519_key* key, byte* out, word32* outLen);
00085 WOLFSSL_API
00086 int wc_ed25519_export_private(ed25519_key* key, byte* out, word32* outLen);
00087 WOLFSSL_API
00088 int wc_ed25519_export_key(ed25519_key* key,
00089                           byte* priv, word32 *privSz,
00090                           byte* pub, word32 *pubSz);
00091 
00092 /* size helper */
00093 WOLFSSL_API
00094 int wc_ed25519_size(ed25519_key* key);
00095 WOLFSSL_API
00096 int wc_ed25519_priv_size(ed25519_key* key);
00097 WOLFSSL_API
00098 int wc_ed25519_pub_size(ed25519_key* key);
00099 WOLFSSL_API
00100 int wc_ed25519_sig_size(ed25519_key* key);
00101 
00102 #ifdef __cplusplus
00103     }    /* extern "C" */
00104 #endif
00105 
00106 #endif /* HAVE_ED25519 */
00107 #endif /* WOLF_CRYPT_ED25519_H */
00108 
00109