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