-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsakke.h
More file actions
228 lines (189 loc) · 7.39 KB
/
sakke.h
File metadata and controls
228 lines (189 loc) · 7.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* sakke.h
*
* Copyright (C) 2006-2025 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
/*!
\file wolfssl/wolfcrypt/sakke.h
*/
#ifndef WOLF_CRYPT_SAKKE_H
#define WOLF_CRYPT_SAKKE_H
#include <wolfssl/wolfcrypt/types.h>
#ifdef WOLFCRYPT_HAVE_SAKKE
#include <wolfssl/wolfcrypt/wolfmath.h>
#include <wolfssl/wolfcrypt/ecc.h>
#include <wolfssl/wolfcrypt/hash.h>
#include <wolfssl/wolfcrypt/hmac.h>
#define WOLFCRYPT_SAKKE_KMS
#define WOLFCRYPT_SAKKE_CLIENT
#define SAKKE_ID_MAX_SIZE 128
/* Maximum number of loops of attempting to generate a key. */
#ifndef SAKKE_MAX_GEN_COUNT
#define SAKKE_MAX_GEN_COUNT 10
#endif
/** MP integer in projective form. */
typedef ecc_point mp_proj;
/** SAKKE ECC parameters in usable format. */
typedef struct SakkeKeyParams {
/** Prime as an MP integer. */
mp_int prime;
/** Q (order) as an MP integer. */
mp_int q;
/** G (pairing base) as an MP integer. */
mp_int g;
/** Temporary MP integer used during operations. */
mp_int a;
/** Base point for elliptic curve operations as an ECC point. */
ecc_point* base;
/** Bit indicate prime is set as an MP integer in SAKKE key. */
WC_BITFIELD havePrime:1;
/** Bit indicates q (order) is set as an MP integer in SAKKE key. */
WC_BITFIELD haveQ:1;
/** Bit indicates g (pairing base) is set as an MP integer in SAKKE key. */
WC_BITFIELD haveG:1;
/** Bit indicates a is set as an MP integer in SAKKE key. */
WC_BITFIELD haveA:1;
/** Bit indicates base point is set as an ECC point in SAKKE key. */
WC_BITFIELD haveBase:1;
} SakkeKeyParams;
/** Temporary values to use in SAKKE calculations. */
typedef struct SakkeKeyTmp {
/** Temporary MP integer used during operations. */
mp_int m1;
/** Temporary MP integer used during operations. */
mp_int m2;
#ifdef WOLFCRYPT_SAKKE_CLIENT
/** Temporary elliptic curve point for use in operations. */
ecc_point* p1;
/** Temporary elliptic curve point for use in operations. */
ecc_point* p2;
/** Temporary MP projective integer for use in operations. */
mp_proj* p3;
#endif
} SakkeKeyTmp;
#ifdef WOLFCRYPT_SAKKE_CLIENT
/** SAKKE data for the intermediate point I. */
typedef struct SakkeKeyPointI {
/** Temporary elliptic curve point for use in operations. */
ecc_point* i;
/** Table associated with point I. */
byte* table;
/** Length of table */
word32 tableLen;
/** Identity associated with point I. */
byte id[SAKKE_ID_MAX_SIZE];
/** Size of identity associated with point I. */
word16 idSz;
} SakkeKeyPointI;
/** SAKKE data for the Receiver Secret Key (RSK). */
typedef struct SakkeKeyRsk {
/** RSK (Receiver Secret Key). */
ecc_point* rsk;
/** Table associated with point I. */
byte* table;
/** Length of table */
word32 tableLen;
/** Indicates whether an RSK value has been set. */
WC_BITFIELD set:1;
} SakkeKeyRsk;
#endif
/**
* SAKKE key.
*/
typedef struct SakkeKey {
/** ECC key to perform elliptic curve operations with. */
ecc_key ecc;
/** ECC parameter in forms that can be used in computation. */
SakkeKeyParams params;
/** Temporaries used during calculations. */
SakkeKeyTmp tmp;
#ifdef WOLFCRYPT_SAKKE_CLIENT
/** Data relating to the RSK (Receiver Secret Key). */
SakkeKeyRsk rsk;
/** Identity to perform operations with. */
byte id[SAKKE_ID_MAX_SIZE];
/** Size of identity in bytes. */
word16 idSz;
/** Data relating to the intermediate point I. */
SakkeKeyPointI i;
/** Generic hash algorithm object. */
wc_HashAlg hash;
/** Temporary buffer for use in operations. */
byte data[(MAX_ECC_BYTES * 2) + 1];
#endif
/** Heap hint for dynamic memory allocation. */
void* heap;
/** Bit indicates Z, public key, is in montgomery form. */
WC_BITFIELD zMont:1;
/** Bit indicate MP integers have been initialized. */
WC_BITFIELD mpInit:1;
} SakkeKey;
#ifdef __cplusplus
extern "C" {
#endif
WOLFSSL_API int wc_InitSakkeKey(SakkeKey* key, void* heap, int devId);
WOLFSSL_API int wc_InitSakkeKey_ex(SakkeKey* key, int keySize, int curveId,
void* heap, int devId);
WOLFSSL_API void wc_FreeSakkeKey(SakkeKey* key);
WOLFSSL_API int wc_MakeSakkeKey(SakkeKey* key, WC_RNG* rng);
WOLFSSL_API int wc_MakeSakkePublicKey(SakkeKey* key, ecc_point* pub);
WOLFSSL_API int wc_MakeSakkeRsk(SakkeKey* key, const byte* id, word16 idSz,
ecc_point* rsk);
WOLFSSL_API int wc_ValidateSakkeRsk(SakkeKey* key, const byte* id, word16 idSz,
ecc_point* rsk, int* valid);
WOLFSSL_API int wc_ExportSakkeKey(SakkeKey* key, byte* data, word32* sz);
WOLFSSL_API int wc_ImportSakkeKey(SakkeKey* key, const byte* data, word32 sz);
WOLFSSL_API int wc_ExportSakkePrivateKey(SakkeKey* key, byte* data, word32* sz);
WOLFSSL_API int wc_ImportSakkePrivateKey(SakkeKey* key, const byte* data,
word32 sz);
WOLFSSL_API int wc_ExportSakkePublicKey(SakkeKey* key, byte* data,
word32* sz, int raw);
WOLFSSL_API int wc_ImportSakkePublicKey(SakkeKey* key, const byte* data,
word32 sz, int trusted);
WOLFSSL_API int wc_EncodeSakkeRsk(const SakkeKey* key, ecc_point* rsk,
byte* out, word32* sz, int raw);
WOLFSSL_API int wc_DecodeSakkeRsk(const SakkeKey* key, const byte* data,
word32 sz, ecc_point* rsk);
WOLFSSL_API int wc_ImportSakkeRsk(SakkeKey* key, const byte* data, word32 sz);
WOLFSSL_API int wc_GetSakkeAuthSize(SakkeKey* key, word16* authSz);
WOLFSSL_API int wc_SetSakkeIdentity(SakkeKey* key, const byte* id, word16 idSz);
WOLFSSL_API int wc_MakeSakkePointI(SakkeKey* key, const byte* id, word16 idSz);
WOLFSSL_API int wc_GetSakkePointI(SakkeKey* key, byte* data, word32* sz);
WOLFSSL_API int wc_SetSakkePointI(SakkeKey* key, const byte* id, word16 idSz,
const byte* data, word32 sz);
WOLFSSL_API int wc_GenerateSakkePointITable(SakkeKey* key, byte* table,
word32* len);
WOLFSSL_API int wc_SetSakkePointITable(SakkeKey* key, byte* table, word32 len);
WOLFSSL_API int wc_ClearSakkePointITable(SakkeKey* key);
WOLFSSL_API int wc_MakeSakkeEncapsulatedSSV(SakkeKey* key,
enum wc_HashType hashType, byte* ssv, word16 ssvSz, byte* auth,
word16* authSz);
WOLFSSL_API int wc_GenerateSakkeRskTable(const SakkeKey* key,
const ecc_point* rsk, byte* table, word32* len);
WOLFSSL_API int wc_SetSakkeRsk(SakkeKey* key, const ecc_point* rsk, byte* table,
word32 len);
WOLFSSL_API int wc_GenerateSakkeSSV(SakkeKey* key, WC_RNG* rng, byte* ssv,
word16* ssvSz);
WOLFSSL_API int wc_DeriveSakkeSSV(SakkeKey* key, enum wc_HashType hashType,
byte* ssv, word16 ssvSz, const byte* auth,
word16 authSz);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* WOLFCRYPT_HAVE_SAKKE */
#endif /* WOLF_CRYPT_SAKKE_H */