source: asp3_tinet_ecnl_rx/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/curve25519.h@ 337

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

ASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 4.9 KB
Line 
1/* curve25519.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#ifndef WOLF_CRYPT_CURVE25519_H
24#define WOLF_CRYPT_CURVE25519_H
25
26#include <wolfssl/wolfcrypt/types.h>
27
28#ifdef HAVE_CURVE25519
29
30#include <wolfssl/wolfcrypt/fe_operations.h>
31#include <wolfssl/wolfcrypt/random.h>
32
33#ifdef WOLFSSL_ASYNC_CRYPT
34 #include <wolfssl/wolfcrypt/async.h>
35#endif
36
37#ifdef __cplusplus
38 extern "C" {
39#endif
40
41#define CURVE25519_KEYSIZE 32
42
43/* curve25519 set type */
44typedef struct {
45 int size; /* The size of the curve in octets */
46 const char* name; /* name of this curve */
47} curve25519_set_type;
48
49
50/* ECC point, the internal structure is Little endian
51 * the mathematical functions used the endianess */
52typedef struct {
53 byte point[CURVE25519_KEYSIZE];
54 #ifdef FREESCALE_LTC_ECC
55 byte pointY[CURVE25519_KEYSIZE];
56 #endif
57} ECPoint;
58
59/* A CURVE25519 Key */
60typedef struct curve25519_key {
61 int idx; /* Index into the ecc_sets[] for the parameters of
62 this curve if -1, this key is using user supplied
63 curve in dp */
64 const curve25519_set_type* dp; /* domain parameters, either points to
65 curves (idx >= 0) or user supplied */
66 ECPoint p; /* public key */
67 ECPoint k; /* private key */
68
69#ifdef WOLFSSL_ASYNC_CRYPT
70 WC_ASYNC_DEV asyncDev;
71#endif
72} curve25519_key;
73
74enum {
75 EC25519_LITTLE_ENDIAN=0,
76 EC25519_BIG_ENDIAN=1
77};
78
79WOLFSSL_API
80int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key);
81
82WOLFSSL_API
83int wc_curve25519_shared_secret(curve25519_key* private_key,
84 curve25519_key* public_key,
85 byte* out, word32* outlen);
86
87WOLFSSL_API
88int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
89 curve25519_key* public_key,
90 byte* out, word32* outlen, int endian);
91
92WOLFSSL_API
93int wc_curve25519_init(curve25519_key* key);
94
95WOLFSSL_API
96void wc_curve25519_free(curve25519_key* key);
97
98
99/* raw key helpers */
100WOLFSSL_API
101int wc_curve25519_import_private(const byte* priv, word32 privSz,
102 curve25519_key* key);
103WOLFSSL_API
104int wc_curve25519_import_private_ex(const byte* priv, word32 privSz,
105 curve25519_key* key, int endian);
106
107WOLFSSL_API
108int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
109 const byte* pub, word32 pubSz, curve25519_key* key);
110WOLFSSL_API
111int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz,
112 const byte* pub, word32 pubSz,
113 curve25519_key* key, int endian);
114WOLFSSL_API
115int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
116 word32* outLen);
117WOLFSSL_API
118int wc_curve25519_export_private_raw_ex(curve25519_key* key, byte* out,
119 word32* outLen, int endian);
120
121WOLFSSL_API
122int wc_curve25519_import_public(const byte* in, word32 inLen,
123 curve25519_key* key);
124WOLFSSL_API
125int wc_curve25519_import_public_ex(const byte* in, word32 inLen,
126 curve25519_key* key, int endian);
127
128WOLFSSL_API
129int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen);
130WOLFSSL_API
131int wc_curve25519_export_public_ex(curve25519_key* key, byte* out,
132 word32* outLen, int endian);
133
134WOLFSSL_API
135int wc_curve25519_export_key_raw(curve25519_key* key,
136 byte* priv, word32 *privSz,
137 byte* pub, word32 *pubSz);
138WOLFSSL_API
139int wc_curve25519_export_key_raw_ex(curve25519_key* key,
140 byte* priv, word32 *privSz,
141 byte* pub, word32 *pubSz,
142 int endian);
143/* size helper */
144WOLFSSL_API
145int wc_curve25519_size(curve25519_key* key);
146
147#ifdef __cplusplus
148 } /* extern "C" */
149#endif
150
151#endif /* HAVE_CURVE25519 */
152#endif /* WOLF_CRYPT_CURVE25519_H */
153
Note: See TracBrowser for help on using the repository browser.