Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/bcrypt/bcrypt_internal.h
4387 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_P256,
66
ALG_ID_ECDH_P384,
67
ALG_ID_ECDH_P521,
68
69
/* signature */
70
ALG_ID_RSA_SIGN,
71
ALG_ID_ECDSA_P256,
72
ALG_ID_ECDSA_P384,
73
ALG_ID_ECDSA_P521,
74
ALG_ID_DSA,
75
76
/* rng */
77
ALG_ID_RNG,
78
79
/* key derivation */
80
ALG_ID_PBKDF2,
81
};
82
83
enum chain_mode
84
{
85
CHAIN_MODE_CBC,
86
CHAIN_MODE_ECB,
87
CHAIN_MODE_CFB,
88
CHAIN_MODE_CCM,
89
CHAIN_MODE_GCM,
90
};
91
92
struct algorithm
93
{
94
struct object hdr;
95
enum alg_id id;
96
enum chain_mode mode;
97
unsigned flags;
98
};
99
100
struct key_symmetric
101
{
102
enum chain_mode mode;
103
ULONG block_size;
104
UCHAR *vector;
105
ULONG vector_len;
106
UCHAR *secret;
107
unsigned secret_len;
108
CRITICAL_SECTION cs;
109
};
110
111
#define KEY_FLAG_LEGACY_DSA_V2 0x00000001
112
#define KEY_FLAG_FINALIZED 0x00000002
113
114
struct key_asymmetric
115
{
116
ULONG bitlen; /* ignored for ECC keys */
117
unsigned flags;
118
DSSSEED dss_seed;
119
};
120
121
#define PRIVATE_DATA_SIZE 3
122
struct key
123
{
124
struct object hdr;
125
enum alg_id alg_id;
126
UINT64 private[PRIVATE_DATA_SIZE]; /* private data for backend */
127
union
128
{
129
struct key_symmetric s;
130
struct key_asymmetric a;
131
} u;
132
};
133
134
struct secret
135
{
136
struct object hdr;
137
struct key *privkey;
138
struct key *pubkey;
139
};
140
141
struct key_symmetric_set_auth_data_params
142
{
143
struct key *key;
144
UCHAR *auth_data;
145
ULONG len;
146
};
147
148
struct key_symmetric_encrypt_params
149
{
150
struct key *key;
151
const UCHAR *input;
152
unsigned input_len;
153
UCHAR *output;
154
ULONG output_len;
155
};
156
157
struct key_symmetric_decrypt_params
158
{
159
struct key *key;
160
const UCHAR *input;
161
unsigned input_len;
162
UCHAR *output;
163
ULONG output_len;
164
};
165
166
struct key_symmetric_get_tag_params
167
{
168
struct key *key;
169
UCHAR *tag;
170
ULONG len;
171
};
172
173
struct key_asymmetric_decrypt_params
174
{
175
struct key *key;
176
UCHAR *input;
177
unsigned input_len;
178
void *padding;
179
UCHAR *output;
180
ULONG output_len;
181
ULONG *ret_len;
182
ULONG flags;
183
};
184
185
struct key_asymmetric_encrypt_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_duplicate_params
198
{
199
struct key *key_orig;
200
struct key *key_copy;
201
};
202
203
struct key_asymmetric_sign_params
204
{
205
struct key *key;
206
void *padding;
207
UCHAR *input;
208
unsigned input_len;
209
UCHAR *output;
210
ULONG output_len;
211
ULONG *ret_len;
212
unsigned flags;
213
};
214
215
struct key_asymmetric_verify_params
216
{
217
struct key *key;
218
void *padding;
219
UCHAR *hash;
220
unsigned hash_len;
221
UCHAR *signature;
222
ULONG signature_len;
223
unsigned flags;
224
};
225
226
#define KEY_EXPORT_FLAG_PUBLIC 0x00000001
227
#define KEY_EXPORT_FLAG_RSA_FULL 0x00000002
228
#define KEY_EXPORT_FLAG_DH_PARAMETERS 0x00000004
229
230
struct key_asymmetric_export_params
231
{
232
struct key *key;
233
ULONG flags;
234
UCHAR *buf;
235
ULONG len;
236
ULONG *ret_len;
237
};
238
239
#define KEY_IMPORT_FLAG_PUBLIC 0x00000001
240
#define KEY_IMPORT_FLAG_DH_PARAMETERS 0x00000002
241
242
struct key_asymmetric_import_params
243
{
244
struct key *key;
245
ULONG flags;
246
UCHAR *buf;
247
ULONG len;
248
};
249
250
struct key_asymmetric_derive_key_params
251
{
252
struct key *privkey;
253
struct key *pubkey;
254
UCHAR *output;
255
ULONG output_len;
256
ULONG *ret_len;
257
};
258
259
enum key_funcs
260
{
261
unix_process_attach,
262
unix_process_detach,
263
unix_key_symmetric_vector_reset,
264
unix_key_symmetric_set_auth_data,
265
unix_key_symmetric_encrypt,
266
unix_key_symmetric_decrypt,
267
unix_key_symmetric_get_tag,
268
unix_key_symmetric_destroy,
269
unix_key_asymmetric_generate,
270
unix_key_asymmetric_decrypt,
271
unix_key_asymmetric_encrypt,
272
unix_key_asymmetric_duplicate,
273
unix_key_asymmetric_sign,
274
unix_key_asymmetric_verify,
275
unix_key_asymmetric_destroy,
276
unix_key_asymmetric_export,
277
unix_key_asymmetric_import,
278
unix_key_asymmetric_derive_key,
279
unix_funcs_count,
280
};
281
282
static inline ULONG len_from_bitlen( ULONG bitlen )
283
{
284
return (bitlen + 7) / 8;
285
}
286
287
#endif /* __BCRYPT_INTERNAL_H */
288
289