Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/bcrypt/bcrypt_internal.h
8602 views
1
/*
2
* Copyright 2016 Michael Müller
3
*
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
8
*
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
13
*
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17
*
18
*/
19
20
#ifndef __BCRYPT_INTERNAL_H
21
#define __BCRYPT_INTERNAL_H
22
23
#include <stdarg.h>
24
25
#include "windef.h"
26
#include "winbase.h"
27
#include "winternl.h"
28
#include "wincrypt.h"
29
#include "bcrypt.h"
30
#include "wine/unixlib.h"
31
32
#define MAGIC_DSS1 ('D' | ('S' << 8) | ('S' << 16) | ('1' << 24))
33
#define MAGIC_DSS2 ('D' | ('S' << 8) | ('S' << 16) | ('2' << 24))
34
35
#define MAGIC_ALG (('A' << 24) | ('L' << 16) | ('G' << 8) | '0')
36
#define MAGIC_HASH (('H' << 24) | ('A' << 16) | ('S' << 8) | 'H')
37
#define MAGIC_KEY (('K' << 24) | ('E' << 16) | ('Y' << 8) | '0')
38
#define MAGIC_SECRET (('S' << 24) | ('C' << 16) | ('R' << 8) | 'T')
39
struct object
40
{
41
ULONG magic;
42
};
43
44
enum alg_id
45
{
46
/* cipher */
47
ALG_ID_3DES,
48
ALG_ID_AES,
49
ALG_ID_RC4,
50
51
/* hash */
52
ALG_ID_SHA256,
53
ALG_ID_SHA384,
54
ALG_ID_SHA512,
55
ALG_ID_SHA1,
56
ALG_ID_MD5,
57
ALG_ID_MD4,
58
ALG_ID_MD2,
59
60
/* asymmetric encryption */
61
ALG_ID_RSA,
62
63
/* secret agreement */
64
ALG_ID_DH,
65
ALG_ID_ECDH,
66
ALG_ID_ECDH_P256,
67
ALG_ID_ECDH_P384,
68
ALG_ID_ECDH_P521,
69
70
/* signature */
71
ALG_ID_RSA_SIGN,
72
ALG_ID_ECDSA,
73
ALG_ID_ECDSA_P256,
74
ALG_ID_ECDSA_P384,
75
ALG_ID_ECDSA_P521,
76
ALG_ID_DSA,
77
78
/* rng */
79
ALG_ID_RNG,
80
81
/* key derivation */
82
ALG_ID_PBKDF2,
83
};
84
85
enum chain_mode
86
{
87
CHAIN_MODE_CBC,
88
CHAIN_MODE_ECB,
89
CHAIN_MODE_CFB,
90
CHAIN_MODE_CCM,
91
CHAIN_MODE_GCM,
92
};
93
94
enum ecc_curve_id
95
{
96
ECC_CURVE_NONE,
97
ECC_CURVE_P256R1,
98
ECC_CURVE_P384R1,
99
ECC_CURVE_P521R1,
100
};
101
102
struct algorithm
103
{
104
struct object hdr;
105
enum alg_id id;
106
enum chain_mode mode;
107
unsigned flags;
108
enum ecc_curve_id curve_id;
109
};
110
111
struct key_symmetric
112
{
113
enum chain_mode mode;
114
ULONG block_size;
115
UCHAR *vector;
116
ULONG vector_len;
117
UCHAR *secret;
118
unsigned secret_len;
119
CRITICAL_SECTION cs;
120
};
121
122
#define KEY_FLAG_LEGACY_DSA_V2 0x00000001
123
#define KEY_FLAG_FINALIZED 0x00000002
124
125
struct key_asymmetric
126
{
127
ULONG bitlen; /* key strength for ECC keys */
128
enum ecc_curve_id curve_id;
129
unsigned flags;
130
DSSSEED dss_seed;
131
};
132
133
#define PRIVATE_DATA_SIZE 3
134
struct key
135
{
136
struct object hdr;
137
enum alg_id alg_id;
138
UINT64 private[PRIVATE_DATA_SIZE]; /* private data for backend */
139
union
140
{
141
struct key_symmetric s;
142
struct key_asymmetric a;
143
} u;
144
};
145
146
struct secret
147
{
148
struct object hdr;
149
struct key *privkey;
150
struct key *pubkey;
151
};
152
153
struct key_symmetric_set_auth_data_params
154
{
155
struct key *key;
156
UCHAR *auth_data;
157
ULONG len;
158
};
159
160
struct key_symmetric_encrypt_params
161
{
162
struct key *key;
163
const UCHAR *input;
164
unsigned input_len;
165
UCHAR *output;
166
ULONG output_len;
167
};
168
169
struct key_symmetric_decrypt_params
170
{
171
struct key *key;
172
const UCHAR *input;
173
unsigned input_len;
174
UCHAR *output;
175
ULONG output_len;
176
};
177
178
struct key_symmetric_get_tag_params
179
{
180
struct key *key;
181
UCHAR *tag;
182
ULONG len;
183
};
184
185
struct key_asymmetric_decrypt_params
186
{
187
struct key *key;
188
UCHAR *input;
189
unsigned input_len;
190
void *padding;
191
UCHAR *output;
192
ULONG output_len;
193
ULONG *ret_len;
194
ULONG flags;
195
};
196
197
struct key_asymmetric_encrypt_params
198
{
199
struct key *key;
200
UCHAR *input;
201
unsigned input_len;
202
void *padding;
203
UCHAR *output;
204
ULONG output_len;
205
ULONG *ret_len;
206
ULONG flags;
207
};
208
209
struct key_asymmetric_duplicate_params
210
{
211
struct key *key_orig;
212
struct key *key_copy;
213
};
214
215
struct key_asymmetric_sign_params
216
{
217
struct key *key;
218
void *padding;
219
UCHAR *input;
220
unsigned input_len;
221
UCHAR *output;
222
ULONG output_len;
223
ULONG *ret_len;
224
unsigned flags;
225
};
226
227
struct key_asymmetric_verify_params
228
{
229
struct key *key;
230
void *padding;
231
UCHAR *hash;
232
unsigned hash_len;
233
UCHAR *signature;
234
ULONG signature_len;
235
unsigned flags;
236
};
237
238
#define KEY_EXPORT_FLAG_PUBLIC 0x00000001
239
#define KEY_EXPORT_FLAG_RSA_FULL 0x00000002
240
#define KEY_EXPORT_FLAG_DH_PARAMETERS 0x00000004
241
242
struct key_asymmetric_export_params
243
{
244
struct key *key;
245
ULONG flags;
246
UCHAR *buf;
247
ULONG len;
248
ULONG *ret_len;
249
};
250
251
#define KEY_IMPORT_FLAG_PUBLIC 0x00000001
252
#define KEY_IMPORT_FLAG_DH_PARAMETERS 0x00000002
253
254
struct key_asymmetric_import_params
255
{
256
struct key *key;
257
ULONG flags;
258
UCHAR *buf;
259
ULONG len;
260
};
261
262
struct key_asymmetric_derive_key_params
263
{
264
struct key *privkey;
265
struct key *pubkey;
266
UCHAR *output;
267
ULONG output_len;
268
ULONG *ret_len;
269
};
270
271
enum key_funcs
272
{
273
unix_process_attach,
274
unix_process_detach,
275
unix_key_symmetric_vector_reset,
276
unix_key_symmetric_set_auth_data,
277
unix_key_symmetric_encrypt,
278
unix_key_symmetric_decrypt,
279
unix_key_symmetric_get_tag,
280
unix_key_symmetric_destroy,
281
unix_key_asymmetric_generate,
282
unix_key_asymmetric_decrypt,
283
unix_key_asymmetric_encrypt,
284
unix_key_asymmetric_duplicate,
285
unix_key_asymmetric_sign,
286
unix_key_asymmetric_verify,
287
unix_key_asymmetric_destroy,
288
unix_key_asymmetric_export,
289
unix_key_asymmetric_import,
290
unix_key_asymmetric_derive_key,
291
unix_funcs_count,
292
};
293
294
static inline ULONG len_from_bitlen( ULONG bitlen )
295
{
296
return (bitlen + 7) / 8;
297
}
298
299
#endif /* __BCRYPT_INTERNAL_H */
300
301