source: azure_iot_hub/trunk/wolfssl-3.15.7/wolfssl/wolfcrypt/ed25519.h@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr
File size: 4.1 KB
Line 
1/* ed25519.h
2 *
3 * Copyright (C) 2006-2017 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/ed25519.h
24*/
25
26
27#ifndef WOLF_CRYPT_ED25519_H
28#define WOLF_CRYPT_ED25519_H
29
30#include <wolfssl/wolfcrypt/types.h>
31
32#ifdef HAVE_ED25519
33
34#include <wolfssl/wolfcrypt/fe_operations.h>
35#include <wolfssl/wolfcrypt/ge_operations.h>
36#include <wolfssl/wolfcrypt/random.h>
37#include <wolfssl/wolfcrypt/sha512.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 ed25519, defined as an elliptic curve
49 over GF(p) */
50/*
51 32, key size
52 "ED25519", curve name
53 "2^255-19", prime number
54 "SHA512", hash function
55 "-121665/121666", value of d
56*/
57
58#define ED25519_KEY_SIZE 32 /* private key only */
59#define ED25519_SIG_SIZE 64
60
61#define ED25519_PUB_KEY_SIZE 32 /* compressed */
62/* both private and public key */
63#define ED25519_PRV_KEY_SIZE (ED25519_PUB_KEY_SIZE+ED25519_KEY_SIZE)
64
65
66#ifndef WC_ED25519KEY_TYPE_DEFINED
67 typedef struct ed25519_key ed25519_key;
68 #define WC_ED25519KEY_TYPE_DEFINED
69#endif
70
71/* An ED25519 Key */
72struct ed25519_key {
73 byte p[ED25519_PUB_KEY_SIZE]; /* compressed public key */
74 byte k[ED25519_PRV_KEY_SIZE]; /* private key : 32 secret -- 32 public */
75#ifdef FREESCALE_LTC_ECC
76 /* uncompressed point coordinates */
77 byte pointX[ED25519_KEY_SIZE]; /* recovered X coordinate */
78 byte pointY[ED25519_KEY_SIZE]; /* Y coordinate is the public key with The most significant bit of the final octet always zero. */
79#endif
80 word16 pubKeySet:1;
81#ifdef WOLFSSL_ASYNC_CRYPT
82 WC_ASYNC_DEV asyncDev;
83#endif
84};
85
86
87WOLFSSL_API
88int wc_ed25519_make_key(WC_RNG* rng, int keysize, ed25519_key* key);
89WOLFSSL_API
90int wc_ed25519_sign_msg(const byte* in, word32 inlen, byte* out,
91 word32 *outlen, ed25519_key* key);
92WOLFSSL_API
93int wc_ed25519_verify_msg(const byte* sig, word32 siglen, const byte* msg,
94 word32 msglen, int* stat, ed25519_key* key);
95WOLFSSL_API
96int wc_ed25519_init(ed25519_key* key);
97WOLFSSL_API
98void wc_ed25519_free(ed25519_key* key);
99WOLFSSL_API
100int wc_ed25519_import_public(const byte* in, word32 inLen, ed25519_key* key);
101WOLFSSL_API
102int wc_ed25519_import_private_only(const byte* priv, word32 privSz,
103 ed25519_key* key);
104WOLFSSL_API
105int wc_ed25519_import_private_key(const byte* priv, word32 privSz,
106 const byte* pub, word32 pubSz, ed25519_key* key);
107WOLFSSL_API
108int wc_ed25519_export_public(ed25519_key*, byte* out, word32* outLen);
109WOLFSSL_API
110int wc_ed25519_export_private_only(ed25519_key* key, byte* out, word32* outLen);
111WOLFSSL_API
112int wc_ed25519_export_private(ed25519_key* key, byte* out, word32* outLen);
113WOLFSSL_API
114int wc_ed25519_export_key(ed25519_key* key,
115 byte* priv, word32 *privSz,
116 byte* pub, word32 *pubSz);
117
118int wc_ed25519_check_key(ed25519_key* key);
119
120/* size helper */
121WOLFSSL_API
122int wc_ed25519_size(ed25519_key* key);
123WOLFSSL_API
124int wc_ed25519_priv_size(ed25519_key* key);
125WOLFSSL_API
126int wc_ed25519_pub_size(ed25519_key* key);
127WOLFSSL_API
128int wc_ed25519_sig_size(ed25519_key* key);
129
130#ifdef __cplusplus
131 } /* extern "C" */
132#endif
133
134#endif /* HAVE_ED25519 */
135#endif /* WOLF_CRYPT_ED25519_H */
136
Note: See TracBrowser for help on using the repository browser.