2 * Copyright 2009 Henri Verbeet for CodeWeavers
3 * Copyright 2018 Hans Leidekker for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
28 #ifdef HAVE_GNUTLS_CIPHER_INIT
32 #include <gnutls/gnutls.h>
33 #include <gnutls/crypto.h>
34 #include <gnutls/abstract.h>
37 #define WIN32_NO_STATUS
45 #include "bcrypt_internal.h"
47 #include "wine/debug.h"
48 #include "wine/unicode.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(bcrypt
);
51 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
53 #if GNUTLS_VERSION_MAJOR < 3
54 #define GNUTLS_CIPHER_AES_192_CBC 92
55 #define GNUTLS_CIPHER_AES_128_GCM 93
56 #define GNUTLS_CIPHER_AES_256_GCM 94
57 #define GNUTLS_PK_ECC 4
59 #define GNUTLS_CURVE_TO_BITS(curve) (unsigned int)(((unsigned int)1<<31)|((unsigned int)(curve)))
63 GNUTLS_ECC_CURVE_INVALID
,
64 GNUTLS_ECC_CURVE_SECP224R1
,
65 GNUTLS_ECC_CURVE_SECP256R1
,
66 GNUTLS_ECC_CURVE_SECP384R1
,
67 GNUTLS_ECC_CURVE_SECP521R1
,
73 gnutls_cipher_hd_t cipher
;
74 gnutls_privkey_t privkey
;
76 C_ASSERT( sizeof(union key_data
) <= sizeof(((struct key
*)0)->private) );
78 static union key_data
*key_data( struct key
*key
)
80 return (union key_data
*)key
->private;
83 /* Not present in gnutls version < 3.0 */
84 static int (*pgnutls_cipher_tag
)(gnutls_cipher_hd_t
, void *, size_t);
85 static int (*pgnutls_cipher_add_auth
)(gnutls_cipher_hd_t
, const void *, size_t);
86 static gnutls_sign_algorithm_t (*pgnutls_pk_to_sign
)(gnutls_pk_algorithm_t
, gnutls_digest_algorithm_t
);
87 static int (*pgnutls_pubkey_import_ecc_raw
)(gnutls_pubkey_t
, gnutls_ecc_curve_t
,
88 const gnutls_datum_t
*, const gnutls_datum_t
*);
89 static int (*pgnutls_privkey_import_ecc_raw
)(gnutls_privkey_t
, gnutls_ecc_curve_t
, const gnutls_datum_t
*,
90 const gnutls_datum_t
*, const gnutls_datum_t
*);
91 static int (*pgnutls_pubkey_verify_hash2
)(gnutls_pubkey_t
, gnutls_sign_algorithm_t
, unsigned int,
92 const gnutls_datum_t
*, const gnutls_datum_t
*);
94 /* Not present in gnutls version < 2.11.0 */
95 static int (*pgnutls_pubkey_import_rsa_raw
)(gnutls_pubkey_t
, const gnutls_datum_t
*, const gnutls_datum_t
*);
97 /* Not present in gnutls version < 2.12.0 */
98 static int (*pgnutls_pubkey_import_dsa_raw
)(gnutls_pubkey_t
, const gnutls_datum_t
*, const gnutls_datum_t
*,
99 const gnutls_datum_t
*, const gnutls_datum_t
*);
101 /* Not present in gnutls version < 3.3.0 */
102 static int (*pgnutls_privkey_export_ecc_raw
)(gnutls_privkey_t
, gnutls_ecc_curve_t
*,
103 gnutls_datum_t
*, gnutls_datum_t
*, gnutls_datum_t
*);
104 static int (*pgnutls_privkey_export_rsa_raw
)(gnutls_privkey_t
, gnutls_datum_t
*, gnutls_datum_t
*, gnutls_datum_t
*,
105 gnutls_datum_t
*, gnutls_datum_t
*, gnutls_datum_t
*, gnutls_datum_t
*,
107 static int (*pgnutls_privkey_export_dsa_raw
)(gnutls_privkey_t
, gnutls_datum_t
*, gnutls_datum_t
*, gnutls_datum_t
*,
108 gnutls_datum_t
*, gnutls_datum_t
*);
109 static int (*pgnutls_privkey_generate
)(gnutls_privkey_t
, gnutls_pk_algorithm_t
, unsigned int, unsigned int);
110 static int (*pgnutls_privkey_import_rsa_raw
)(gnutls_privkey_t
, const gnutls_datum_t
*, const gnutls_datum_t
*,
111 const gnutls_datum_t
*, const gnutls_datum_t
*, const gnutls_datum_t
*,
112 const gnutls_datum_t
*, const gnutls_datum_t
*, const gnutls_datum_t
*);
113 static int (*pgnutls_privkey_decrypt_data
)(gnutls_privkey_t
, unsigned int flags
, const gnutls_datum_t
*, gnutls_datum_t
*);
115 /* Not present in gnutls version < 3.6.0 */
116 static int (*pgnutls_decode_rs_value
)(const gnutls_datum_t
*, gnutls_datum_t
*, gnutls_datum_t
*);
118 static void *libgnutls_handle
;
119 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
120 MAKE_FUNCPTR(gnutls_cipher_decrypt2
);
121 MAKE_FUNCPTR(gnutls_cipher_deinit
);
122 MAKE_FUNCPTR(gnutls_cipher_encrypt2
);
123 MAKE_FUNCPTR(gnutls_cipher_init
);
124 MAKE_FUNCPTR(gnutls_global_deinit
);
125 MAKE_FUNCPTR(gnutls_global_init
);
126 MAKE_FUNCPTR(gnutls_global_set_log_function
);
127 MAKE_FUNCPTR(gnutls_global_set_log_level
);
128 MAKE_FUNCPTR(gnutls_perror
);
129 MAKE_FUNCPTR(gnutls_privkey_decrypt_data
);
130 MAKE_FUNCPTR(gnutls_privkey_deinit
);
131 MAKE_FUNCPTR(gnutls_privkey_import_dsa_raw
);
132 MAKE_FUNCPTR(gnutls_privkey_init
);
133 MAKE_FUNCPTR(gnutls_privkey_sign_hash
);
134 MAKE_FUNCPTR(gnutls_pubkey_deinit
);
135 MAKE_FUNCPTR(gnutls_pubkey_init
);
138 static int compat_gnutls_cipher_tag(gnutls_cipher_hd_t handle
, void *tag
, size_t tag_size
)
140 return GNUTLS_E_UNKNOWN_CIPHER_TYPE
;
143 static int compat_gnutls_cipher_add_auth(gnutls_cipher_hd_t handle
, const void *ptext
, size_t ptext_size
)
145 return GNUTLS_E_UNKNOWN_CIPHER_TYPE
;
148 static int compat_gnutls_pubkey_import_ecc_raw(gnutls_pubkey_t key
, gnutls_ecc_curve_t curve
,
149 const gnutls_datum_t
*x
, const gnutls_datum_t
*y
)
151 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
154 static int compat_gnutls_privkey_export_rsa_raw(gnutls_privkey_t key
, gnutls_datum_t
*m
, gnutls_datum_t
*e
,
155 gnutls_datum_t
*d
, gnutls_datum_t
*p
, gnutls_datum_t
*q
,
156 gnutls_datum_t
*u
, gnutls_datum_t
*e1
, gnutls_datum_t
*e2
)
158 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
161 static int compat_gnutls_privkey_export_ecc_raw(gnutls_privkey_t key
, gnutls_ecc_curve_t
*curve
,
162 gnutls_datum_t
*x
, gnutls_datum_t
*y
, gnutls_datum_t
*k
)
164 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
167 static int compat_gnutls_privkey_import_ecc_raw(gnutls_privkey_t key
, gnutls_ecc_curve_t curve
,
168 const gnutls_datum_t
*x
, const gnutls_datum_t
*y
,
169 const gnutls_datum_t
*k
)
171 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
174 static int compat_gnutls_privkey_export_dsa_raw(gnutls_privkey_t key
, gnutls_datum_t
*p
, gnutls_datum_t
*q
,
175 gnutls_datum_t
*g
, gnutls_datum_t
*y
, gnutls_datum_t
*x
)
177 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
180 static gnutls_sign_algorithm_t
compat_gnutls_pk_to_sign(gnutls_pk_algorithm_t pk
, gnutls_digest_algorithm_t hash
)
182 return GNUTLS_SIGN_UNKNOWN
;
185 static int compat_gnutls_pubkey_verify_hash2(gnutls_pubkey_t key
, gnutls_sign_algorithm_t algo
,
186 unsigned int flags
, const gnutls_datum_t
*hash
,
187 const gnutls_datum_t
*signature
)
189 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
192 static int compat_gnutls_pubkey_import_rsa_raw(gnutls_pubkey_t key
, const gnutls_datum_t
*m
, const gnutls_datum_t
*e
)
194 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
197 static int compat_gnutls_pubkey_import_dsa_raw(gnutls_pubkey_t key
, const gnutls_datum_t
*p
, const gnutls_datum_t
*q
,
198 const gnutls_datum_t
*g
, const gnutls_datum_t
*y
)
200 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
203 static int compat_gnutls_privkey_generate(gnutls_privkey_t key
, gnutls_pk_algorithm_t algo
, unsigned int bits
,
206 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
209 static int compat_gnutls_decode_rs_value(const gnutls_datum_t
* sig_value
, gnutls_datum_t
* r
, gnutls_datum_t
* s
)
211 return GNUTLS_E_INTERNAL_ERROR
;
214 static int compat_gnutls_privkey_import_rsa_raw(gnutls_privkey_t key
, const gnutls_datum_t
*m
, const gnutls_datum_t
*e
,
215 const gnutls_datum_t
*d
, const gnutls_datum_t
*p
, const gnutls_datum_t
*q
,
216 const gnutls_datum_t
*u
, const gnutls_datum_t
*e1
, const gnutls_datum_t
*e2
)
218 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
221 static int compat_gnutls_privkey_decrypt_data(gnutls_privkey_t key
, unsigned int flags
, const gnutls_datum_t
*cipher_text
,
222 gnutls_datum_t
*plain_text
)
224 return GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
227 static void gnutls_log( int level
, const char *msg
)
229 TRACE( "<%d> %s", level
, msg
);
232 static BOOL
gnutls_initialize(void)
237 if ((env_str
= getenv("GNUTLS_SYSTEM_PRIORITY_FILE")))
239 WARN("GNUTLS_SYSTEM_PRIORITY_FILE is %s.\n", debugstr_a(env_str
));
243 WARN("Setting GNUTLS_SYSTEM_PRIORITY_FILE to \"/dev/null\".\n");
244 setenv("GNUTLS_SYSTEM_PRIORITY_FILE", "/dev/null", 0);
247 if (!(libgnutls_handle
= dlopen( SONAME_LIBGNUTLS
, RTLD_NOW
)))
249 ERR_(winediag
)( "failed to load libgnutls, no support for encryption\n" );
253 #define LOAD_FUNCPTR(f) \
254 if (!(p##f = dlsym( libgnutls_handle, #f ))) \
256 ERR( "failed to load %s\n", #f ); \
260 LOAD_FUNCPTR(gnutls_cipher_decrypt2
)
261 LOAD_FUNCPTR(gnutls_cipher_deinit
)
262 LOAD_FUNCPTR(gnutls_cipher_encrypt2
)
263 LOAD_FUNCPTR(gnutls_cipher_init
)
264 LOAD_FUNCPTR(gnutls_global_deinit
)
265 LOAD_FUNCPTR(gnutls_global_init
)
266 LOAD_FUNCPTR(gnutls_global_set_log_function
)
267 LOAD_FUNCPTR(gnutls_global_set_log_level
)
268 LOAD_FUNCPTR(gnutls_perror
)
269 LOAD_FUNCPTR(gnutls_privkey_deinit
);
270 LOAD_FUNCPTR(gnutls_privkey_import_dsa_raw
);
271 LOAD_FUNCPTR(gnutls_privkey_init
);
272 LOAD_FUNCPTR(gnutls_privkey_sign_hash
);
273 LOAD_FUNCPTR(gnutls_pubkey_deinit
);
274 LOAD_FUNCPTR(gnutls_pubkey_init
);
277 if (!(pgnutls_cipher_tag
= dlsym( libgnutls_handle
, "gnutls_cipher_tag" )))
279 WARN("gnutls_cipher_tag not found\n");
280 pgnutls_cipher_tag
= compat_gnutls_cipher_tag
;
282 if (!(pgnutls_cipher_add_auth
= dlsym( libgnutls_handle
, "gnutls_cipher_add_auth" )))
284 WARN("gnutls_cipher_add_auth not found\n");
285 pgnutls_cipher_add_auth
= compat_gnutls_cipher_add_auth
;
288 if ((ret
= pgnutls_global_init()) != GNUTLS_E_SUCCESS
)
290 pgnutls_perror( ret
);
293 if (!(pgnutls_pubkey_import_ecc_raw
= dlsym( libgnutls_handle
, "gnutls_pubkey_import_ecc_raw" )))
295 WARN("gnutls_pubkey_import_ecc_raw not found\n");
296 pgnutls_pubkey_import_ecc_raw
= compat_gnutls_pubkey_import_ecc_raw
;
298 if (!(pgnutls_privkey_export_rsa_raw
= dlsym( libgnutls_handle
, "gnutls_privkey_export_rsa_raw" )))
300 WARN("gnutls_privkey_export_rsa_raw not found\n");
301 pgnutls_privkey_export_rsa_raw
= compat_gnutls_privkey_export_rsa_raw
;
303 if (!(pgnutls_privkey_export_ecc_raw
= dlsym( libgnutls_handle
, "gnutls_privkey_export_ecc_raw" )))
305 WARN("gnutls_privkey_export_ecc_raw not found\n");
306 pgnutls_privkey_export_ecc_raw
= compat_gnutls_privkey_export_ecc_raw
;
308 if (!(pgnutls_privkey_import_ecc_raw
= dlsym( libgnutls_handle
, "gnutls_privkey_import_ecc_raw" )))
310 WARN("gnutls_privkey_import_ecc_raw not found\n");
311 pgnutls_privkey_import_ecc_raw
= compat_gnutls_privkey_import_ecc_raw
;
313 if (!(pgnutls_privkey_export_dsa_raw
= dlsym( libgnutls_handle
, "gnutls_privkey_export_dsa_raw" )))
315 WARN("gnutls_privkey_export_dsa_raw not found\n");
316 pgnutls_privkey_export_dsa_raw
= compat_gnutls_privkey_export_dsa_raw
;
318 if (!(pgnutls_pk_to_sign
= dlsym( libgnutls_handle
, "gnutls_pk_to_sign" )))
320 WARN("gnutls_pk_to_sign not found\n");
321 pgnutls_pk_to_sign
= compat_gnutls_pk_to_sign
;
323 if (!(pgnutls_pubkey_verify_hash2
= dlsym( libgnutls_handle
, "gnutls_pubkey_verify_hash2" )))
325 WARN("gnutls_pubkey_verify_hash2 not found\n");
326 pgnutls_pubkey_verify_hash2
= compat_gnutls_pubkey_verify_hash2
;
328 if (!(pgnutls_pubkey_import_rsa_raw
= dlsym( libgnutls_handle
, "gnutls_pubkey_import_rsa_raw" )))
330 WARN("gnutls_pubkey_import_rsa_raw not found\n");
331 pgnutls_pubkey_import_rsa_raw
= compat_gnutls_pubkey_import_rsa_raw
;
333 if (!(pgnutls_pubkey_import_dsa_raw
= dlsym( libgnutls_handle
, "gnutls_pubkey_import_dsa_raw" )))
335 WARN("gnutls_pubkey_import_dsa_raw not found\n");
336 pgnutls_pubkey_import_dsa_raw
= compat_gnutls_pubkey_import_dsa_raw
;
338 if (!(pgnutls_privkey_generate
= dlsym( libgnutls_handle
, "gnutls_privkey_generate" )))
340 WARN("gnutls_privkey_generate not found\n");
341 pgnutls_privkey_generate
= compat_gnutls_privkey_generate
;
343 if (!(pgnutls_decode_rs_value
= dlsym( libgnutls_handle
, "gnutls_decode_rs_value" )))
345 WARN("gnutls_decode_rs_value not found\n");
346 pgnutls_decode_rs_value
= compat_gnutls_decode_rs_value
;
348 if (!(pgnutls_privkey_import_rsa_raw
= dlsym( libgnutls_handle
, "gnutls_privkey_import_rsa_raw" )))
350 WARN("gnutls_privkey_import_rsa_raw not found\n");
351 pgnutls_privkey_import_rsa_raw
= compat_gnutls_privkey_import_rsa_raw
;
353 if (!(pgnutls_privkey_decrypt_data
= dlsym( libgnutls_handle
, "gnutls_privkey_decrypt_data" )))
355 WARN("gnutls_privkey_decrypt_data not found\n");
356 pgnutls_privkey_decrypt_data
= compat_gnutls_privkey_decrypt_data
;
359 if (TRACE_ON( bcrypt
))
361 pgnutls_global_set_log_level( 4 );
362 pgnutls_global_set_log_function( gnutls_log
);
368 dlclose( libgnutls_handle
);
369 libgnutls_handle
= NULL
;
373 static void gnutls_uninitialize(void)
375 pgnutls_global_deinit();
376 dlclose( libgnutls_handle
);
377 libgnutls_handle
= NULL
;
388 static void buffer_init( struct buffer
*buffer
)
390 buffer
->buffer
= NULL
;
393 buffer
->error
= FALSE
;
396 static void buffer_free( struct buffer
*buffer
)
398 free( buffer
->buffer
);
401 static void buffer_append( struct buffer
*buffer
, BYTE
*data
, DWORD len
)
405 if (buffer
->pos
+ len
> buffer
->length
)
407 DWORD new_length
= max( max( buffer
->pos
+ len
, buffer
->length
* 2 ), 64 );
410 if (!(new_buffer
= realloc( buffer
->buffer
, new_length
)))
412 ERR( "out of memory\n" );
413 buffer
->error
= TRUE
;
417 buffer
->buffer
= new_buffer
;
418 buffer
->length
= new_length
;
421 memcpy( &buffer
->buffer
[buffer
->pos
], data
, len
);
425 static void buffer_append_byte( struct buffer
*buffer
, BYTE value
)
427 buffer_append( buffer
, &value
, sizeof(value
) );
430 static void buffer_append_asn1_length( struct buffer
*buffer
, DWORD length
)
436 buffer_append_byte( buffer
, length
);
440 if (length
<= 0xff) num_bytes
= 1;
441 else if (length
<= 0xffff) num_bytes
= 2;
442 else if (length
<= 0xffffff) num_bytes
= 3;
445 buffer_append_byte( buffer
, 0x80 | num_bytes
);
446 while (num_bytes
--) buffer_append_byte( buffer
, length
>> (num_bytes
* 8) );
449 static void buffer_append_asn1_integer( struct buffer
*buffer
, BYTE
*data
, DWORD len
)
451 DWORD leading_zero
= (*data
& 0x80) != 0;
453 buffer_append_byte( buffer
, 0x02 ); /* tag */
454 buffer_append_asn1_length( buffer
, len
+ leading_zero
);
455 if (leading_zero
) buffer_append_byte( buffer
, 0 );
456 buffer_append( buffer
, data
, len
);
459 static void buffer_append_asn1_sequence( struct buffer
*buffer
, struct buffer
*content
)
463 buffer
->error
= TRUE
;
467 buffer_append_byte( buffer
, 0x30 ); /* tag */
468 buffer_append_asn1_length( buffer
, content
->pos
);
469 buffer_append( buffer
, content
->buffer
, content
->pos
);
472 static void buffer_append_asn1_r_s( struct buffer
*buffer
, BYTE
*r
, DWORD r_len
, BYTE
*s
, DWORD s_len
)
476 buffer_init( &value
);
477 buffer_append_asn1_integer( &value
, r
, r_len
);
478 buffer_append_asn1_integer( &value
, s
, s_len
);
479 buffer_append_asn1_sequence( buffer
, &value
);
480 buffer_free( &value
);
483 static NTSTATUS CDECL
key_set_property( struct key
*key
, const WCHAR
*prop
, UCHAR
*value
, ULONG size
, ULONG flags
)
485 if (!strcmpW( prop
, BCRYPT_CHAINING_MODE
))
487 if (!strcmpW( (WCHAR
*)value
, BCRYPT_CHAIN_MODE_ECB
))
489 key
->u
.s
.mode
= MODE_ID_ECB
;
490 return STATUS_SUCCESS
;
492 else if (!strcmpW( (WCHAR
*)value
, BCRYPT_CHAIN_MODE_CBC
))
494 key
->u
.s
.mode
= MODE_ID_CBC
;
495 return STATUS_SUCCESS
;
497 else if (!strcmpW( (WCHAR
*)value
, BCRYPT_CHAIN_MODE_GCM
))
499 key
->u
.s
.mode
= MODE_ID_GCM
;
500 return STATUS_SUCCESS
;
504 FIXME( "unsupported mode %s\n", debugstr_w((WCHAR
*)value
) );
505 return STATUS_NOT_IMPLEMENTED
;
509 FIXME( "unsupported key property %s\n", debugstr_w(prop
) );
510 return STATUS_NOT_IMPLEMENTED
;
513 static NTSTATUS CDECL
key_symmetric_init( struct key
*key
)
515 if (!libgnutls_handle
) return STATUS_INTERNAL_ERROR
;
521 return STATUS_SUCCESS
;
524 FIXME( "algorithm %u not supported\n", key
->alg_id
);
525 return STATUS_NOT_SUPPORTED
;
529 static gnutls_cipher_algorithm_t
get_gnutls_cipher( const struct key
*key
)
534 WARN( "handle block size\n" );
535 switch (key
->u
.s
.mode
)
538 return GNUTLS_CIPHER_3DES_CBC
;
542 FIXME( "3DES mode %u with key length %u not supported\n", key
->u
.s
.mode
, key
->u
.s
.secret_len
);
543 return GNUTLS_CIPHER_UNKNOWN
;
546 WARN( "handle block size\n" );
547 switch (key
->u
.s
.mode
)
550 if (key
->u
.s
.secret_len
== 16) return GNUTLS_CIPHER_AES_128_GCM
;
551 if (key
->u
.s
.secret_len
== 32) return GNUTLS_CIPHER_AES_256_GCM
;
553 case MODE_ID_ECB
: /* can be emulated with CBC + empty IV */
555 if (key
->u
.s
.secret_len
== 16) return GNUTLS_CIPHER_AES_128_CBC
;
556 if (key
->u
.s
.secret_len
== 24) return GNUTLS_CIPHER_AES_192_CBC
;
557 if (key
->u
.s
.secret_len
== 32) return GNUTLS_CIPHER_AES_256_CBC
;
562 FIXME( "AES mode %u with key length %u not supported\n", key
->u
.s
.mode
, key
->u
.s
.secret_len
);
563 return GNUTLS_CIPHER_UNKNOWN
;
566 FIXME( "algorithm %u not supported\n", key
->alg_id
);
567 return GNUTLS_CIPHER_UNKNOWN
;
571 static void CDECL
key_symmetric_vector_reset( struct key
*key
)
573 if (!key_data(key
)->cipher
) return;
574 TRACE( "invalidating cipher handle\n" );
575 pgnutls_cipher_deinit( key_data(key
)->cipher
);
576 key_data(key
)->cipher
= NULL
;
579 static NTSTATUS
init_cipher_handle( struct key
*key
)
581 gnutls_cipher_algorithm_t cipher
;
582 gnutls_datum_t secret
, vector
;
585 if (key_data(key
)->cipher
) return STATUS_SUCCESS
;
586 if ((cipher
= get_gnutls_cipher( key
)) == GNUTLS_CIPHER_UNKNOWN
) return STATUS_NOT_SUPPORTED
;
588 secret
.data
= key
->u
.s
.secret
;
589 secret
.size
= key
->u
.s
.secret_len
;
591 vector
.data
= key
->u
.s
.vector
;
592 vector
.size
= key
->u
.s
.vector_len
;
594 if ((ret
= pgnutls_cipher_init( &key_data(key
)->cipher
, cipher
, &secret
, key
->u
.s
.vector
? &vector
: NULL
)))
596 pgnutls_perror( ret
);
597 return STATUS_INTERNAL_ERROR
;
600 return STATUS_SUCCESS
;
603 static NTSTATUS CDECL
key_symmetric_set_auth_data( struct key
*key
, UCHAR
*auth_data
, ULONG len
)
608 if (!auth_data
) return STATUS_SUCCESS
;
609 if ((status
= init_cipher_handle( key
))) return status
;
611 if ((ret
= pgnutls_cipher_add_auth( key_data(key
)->cipher
, auth_data
, len
)))
613 pgnutls_perror( ret
);
614 return STATUS_INTERNAL_ERROR
;
616 return STATUS_SUCCESS
;
619 static NTSTATUS CDECL
key_symmetric_encrypt( struct key
*key
, const UCHAR
*input
, ULONG input_len
, UCHAR
*output
, ULONG output_len
)
624 if ((status
= init_cipher_handle( key
))) return status
;
626 if ((ret
= pgnutls_cipher_encrypt2( key_data(key
)->cipher
, input
, input_len
, output
, output_len
)))
628 pgnutls_perror( ret
);
629 return STATUS_INTERNAL_ERROR
;
631 return STATUS_SUCCESS
;
634 static NTSTATUS CDECL
key_symmetric_decrypt( struct key
*key
, const UCHAR
*input
, ULONG input_len
, UCHAR
*output
, ULONG output_len
)
639 if ((status
= init_cipher_handle( key
))) return status
;
641 if ((ret
= pgnutls_cipher_decrypt2( key_data(key
)->cipher
, input
, input_len
, output
, output_len
)))
643 pgnutls_perror( ret
);
644 return STATUS_INTERNAL_ERROR
;
646 return STATUS_SUCCESS
;
649 static NTSTATUS CDECL
key_symmetric_get_tag( struct key
*key
, UCHAR
*tag
, ULONG len
)
654 if ((status
= init_cipher_handle( key
))) return status
;
656 if ((ret
= pgnutls_cipher_tag( key_data(key
)->cipher
, tag
, len
)))
658 pgnutls_perror( ret
);
659 return STATUS_INTERNAL_ERROR
;
661 return STATUS_SUCCESS
;
664 static void CDECL
key_symmetric_destroy( struct key
*key
)
666 if (key_data(key
)->cipher
) pgnutls_cipher_deinit( key_data(key
)->cipher
);
669 static void export_gnutls_datum( UCHAR
*buffer
, ULONG length
, gnutls_datum_t
*d
, ULONG
*actual_length
)
671 ULONG size
= d
->size
;
672 UCHAR
*src
= d
->data
;
675 assert( size
<= length
+ 1 );
676 if (size
== length
+ 1)
685 *actual_length
= size
;
689 offset
= length
- size
;
690 memset( buffer
, 0, offset
);
692 memcpy( buffer
+ offset
, src
, size
);
695 static NTSTATUS
export_gnutls_pubkey_rsa( gnutls_privkey_t gnutls_key
, ULONG bitlen
, UCHAR
**pubkey
, ULONG
*pubkey_len
)
697 BCRYPT_RSAKEY_BLOB
*rsa_blob
;
702 if ((ret
= pgnutls_privkey_export_rsa_raw( gnutls_key
, &m
, &e
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
)))
704 pgnutls_perror( ret
);
705 return STATUS_INTERNAL_ERROR
;
708 if (!(rsa_blob
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*rsa_blob
) + e
.size
+ m
.size
)))
710 pgnutls_perror( ret
);
711 free( e
.data
); free( m
.data
);
712 return STATUS_NO_MEMORY
;
715 dst
= (UCHAR
*)(rsa_blob
+ 1);
716 export_gnutls_datum( dst
, bitlen
/ 8, &e
, &rsa_blob
->cbPublicExp
);
718 dst
+= rsa_blob
->cbPublicExp
;
719 export_gnutls_datum( dst
, bitlen
/ 8, &m
, &rsa_blob
->cbModulus
);
721 rsa_blob
->Magic
= BCRYPT_RSAPUBLIC_MAGIC
;
722 rsa_blob
->BitLength
= bitlen
;
723 rsa_blob
->cbPrime1
= 0;
724 rsa_blob
->cbPrime2
= 0;
726 *pubkey
= (UCHAR
*)rsa_blob
;
727 *pubkey_len
= sizeof(*rsa_blob
) + rsa_blob
->cbPublicExp
+ rsa_blob
->cbModulus
;
729 free( e
.data
); free( m
.data
);
730 return STATUS_SUCCESS
;
733 static NTSTATUS
export_gnutls_pubkey_ecc( gnutls_privkey_t gnutls_key
, enum alg_id alg_id
, UCHAR
**pubkey
,
736 BCRYPT_ECCKEY_BLOB
*ecc_blob
;
737 gnutls_ecc_curve_t curve
;
745 case ALG_ID_ECDH_P256
:
746 magic
= BCRYPT_ECDH_PUBLIC_P256_MAGIC
;
749 case ALG_ID_ECDSA_P256
:
750 magic
= BCRYPT_ECDSA_PUBLIC_P256_MAGIC
;
754 FIXME( "algorithm %u not supported\n", alg_id
);
755 return STATUS_NOT_IMPLEMENTED
;
758 if ((ret
= pgnutls_privkey_export_ecc_raw( gnutls_key
, &curve
, &x
, &y
, NULL
)))
760 pgnutls_perror( ret
);
761 return STATUS_INTERNAL_ERROR
;
764 if (curve
!= GNUTLS_ECC_CURVE_SECP256R1
)
766 FIXME( "curve %u not supported\n", curve
);
767 free( x
.data
); free( y
.data
);
768 return STATUS_NOT_IMPLEMENTED
;
771 if (!(ecc_blob
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*ecc_blob
) + size
* 2 )))
773 pgnutls_perror( ret
);
774 free( x
.data
); free( y
.data
);
775 return STATUS_NO_MEMORY
;
778 ecc_blob
->dwMagic
= magic
;
779 ecc_blob
->cbKey
= size
;
781 dst
= (UCHAR
*)(ecc_blob
+ 1);
782 export_gnutls_datum( dst
, size
, &x
, NULL
);
785 export_gnutls_datum( dst
, size
, &y
, NULL
);
787 *pubkey
= (UCHAR
*)ecc_blob
;
788 *pubkey_len
= sizeof(*ecc_blob
) + ecc_blob
->cbKey
* 2;
790 free( x
.data
); free( y
.data
);
791 return STATUS_SUCCESS
;
794 static NTSTATUS
export_gnutls_pubkey_dsa( gnutls_privkey_t gnutls_key
, ULONG bitlen
, UCHAR
**pubkey
, ULONG
*pubkey_len
)
796 BCRYPT_DSA_KEY_BLOB
*dsa_blob
;
797 gnutls_datum_t p
, q
, g
, y
;
801 if ((ret
= pgnutls_privkey_export_dsa_raw( gnutls_key
, &p
, &q
, &g
, &y
, NULL
)))
803 pgnutls_perror( ret
);
804 return STATUS_INTERNAL_ERROR
;
809 FIXME( "bitlen > 1024 not supported\n" );
810 return STATUS_NOT_IMPLEMENTED
;
813 if (!(dsa_blob
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*dsa_blob
) + bitlen
/ 8 * 3 )))
815 pgnutls_perror( ret
);
816 free( p
.data
); free( q
.data
); free( g
.data
); free( y
.data
);
817 return STATUS_NO_MEMORY
;
820 dst
= (UCHAR
*)(dsa_blob
+ 1);
821 export_gnutls_datum( dst
, bitlen
/ 8, &p
, NULL
);
824 export_gnutls_datum( dst
, bitlen
/ 8, &g
, NULL
);
827 export_gnutls_datum( dst
, bitlen
/ 8, &y
, NULL
);
830 export_gnutls_datum( dst
, sizeof(dsa_blob
->q
), &q
, NULL
);
832 dsa_blob
->dwMagic
= BCRYPT_DSA_PUBLIC_MAGIC
;
833 dsa_blob
->cbKey
= bitlen
/ 8;
834 memset( dsa_blob
->Count
, 0, sizeof(dsa_blob
->Count
) ); /* FIXME */
835 memset( dsa_blob
->Seed
, 0, sizeof(dsa_blob
->Seed
) ); /* FIXME */
837 *pubkey
= (UCHAR
*)dsa_blob
;
838 *pubkey_len
= sizeof(*dsa_blob
) + dsa_blob
->cbKey
* 3;
840 free( p
.data
); free( q
.data
); free( g
.data
); free( y
.data
);
841 return STATUS_SUCCESS
;
844 static void reverse_bytes( UCHAR
*buf
, ULONG len
)
849 for (i
= 0; i
< len
/ 2; ++i
)
852 buf
[i
] = buf
[len
- i
- 1];
853 buf
[len
- i
- 1] = tmp
;
858 static NTSTATUS
export_gnutls_pubkey_dsa_capi( gnutls_privkey_t gnutls_key
, const DSSSEED
*seed
, ULONG bitlen
,
859 UCHAR
**pubkey
, ULONG
*pubkey_len
)
863 gnutls_datum_t p
, q
, g
, y
;
865 int ret
, size
= sizeof(*hdr
) + sizeof(*dsskey
) + sizeof(*seed
);
869 FIXME( "bitlen > 1024 not supported\n" );
870 return STATUS_NOT_IMPLEMENTED
;
873 if ((ret
= pgnutls_privkey_export_dsa_raw( gnutls_key
, &p
, &q
, &g
, &y
, NULL
)))
875 pgnutls_perror( ret
);
876 return STATUS_INTERNAL_ERROR
;
879 if (!(hdr
= RtlAllocateHeap( GetProcessHeap(), 0, size
+ bitlen
/ 8 * 3 + Q_SIZE
)))
881 pgnutls_perror( ret
);
882 free( p
.data
); free( q
.data
); free( g
.data
); free( y
.data
);
883 return STATUS_NO_MEMORY
;
886 hdr
->bType
= PUBLICKEYBLOB
;
889 hdr
->aiKeyAlg
= CALG_DSS_SIGN
;
891 dsskey
= (DSSPUBKEY
*)(hdr
+ 1);
892 dsskey
->magic
= MAGIC_DSS1
;
893 dsskey
->bitlen
= bitlen
;
895 dst
= (UCHAR
*)(dsskey
+ 1);
896 export_gnutls_datum( dst
, bitlen
/ 8, &p
, NULL
);
897 reverse_bytes( dst
, bitlen
/ 8 );
900 export_gnutls_datum( dst
, Q_SIZE
, &q
, NULL
);
901 reverse_bytes( dst
, Q_SIZE
);
904 export_gnutls_datum( dst
, bitlen
/ 8, &g
, NULL
);
905 reverse_bytes( dst
, bitlen
/ 8 );
908 export_gnutls_datum( dst
, bitlen
/ 8, &y
, NULL
);
909 reverse_bytes( dst
, bitlen
/ 8 );
912 memcpy( dst
, seed
, sizeof(*seed
) );
914 *pubkey
= (UCHAR
*)hdr
;
915 *pubkey_len
= size
+ bitlen
/ 8 * 3 + Q_SIZE
;
917 free( p
.data
); free( q
.data
); free( g
.data
); free( y
.data
);
918 return STATUS_SUCCESS
;
921 static NTSTATUS CDECL
key_asymmetric_generate( struct key
*key
)
923 gnutls_pk_algorithm_t pk_alg
;
924 gnutls_privkey_t handle
;
929 if (!libgnutls_handle
) return STATUS_INTERNAL_ERROR
;
934 case ALG_ID_RSA_SIGN
:
935 pk_alg
= GNUTLS_PK_RSA
;
936 bitlen
= key
->u
.a
.bitlen
;
940 pk_alg
= GNUTLS_PK_DSA
;
941 bitlen
= key
->u
.a
.bitlen
;
944 case ALG_ID_ECDH_P256
:
945 case ALG_ID_ECDSA_P256
:
946 pk_alg
= GNUTLS_PK_ECC
; /* compatible with ECDSA and ECDH */
947 bitlen
= GNUTLS_CURVE_TO_BITS( GNUTLS_ECC_CURVE_SECP256R1
);
951 FIXME( "algorithm %u not supported\n", key
->alg_id
);
952 return STATUS_NOT_SUPPORTED
;
955 if ((ret
= pgnutls_privkey_init( &handle
)))
957 pgnutls_perror( ret
);
958 return STATUS_INTERNAL_ERROR
;
961 if ((ret
= pgnutls_privkey_generate( handle
, pk_alg
, bitlen
, 0 )))
963 pgnutls_perror( ret
);
964 pgnutls_privkey_deinit( handle
);
965 return STATUS_INTERNAL_ERROR
;
971 status
= export_gnutls_pubkey_rsa( handle
, key
->u
.a
.bitlen
, &key
->u
.a
.pubkey
, &key
->u
.a
.pubkey_len
);
975 status
= export_gnutls_pubkey_ecc( handle
, key
->alg_id
, &key
->u
.a
.pubkey
, &key
->u
.a
.pubkey_len
);
979 status
= export_gnutls_pubkey_dsa( handle
, key
->u
.a
.bitlen
, &key
->u
.a
.pubkey
, &key
->u
.a
.pubkey_len
);
983 ERR( "unhandled algorithm %u\n", pk_alg
);
984 return STATUS_INTERNAL_ERROR
;
989 pgnutls_privkey_deinit( handle
);
993 key_data(key
)->privkey
= handle
;
994 return STATUS_SUCCESS
;
997 static NTSTATUS CDECL
key_export_ecc( struct key
*key
, UCHAR
*buf
, ULONG len
, ULONG
*ret_len
)
999 BCRYPT_ECCKEY_BLOB
*ecc_blob
;
1000 gnutls_ecc_curve_t curve
;
1001 gnutls_datum_t x
, y
, d
;
1006 switch (key
->alg_id
)
1008 case ALG_ID_ECDH_P256
:
1009 magic
= BCRYPT_ECDH_PRIVATE_P256_MAGIC
;
1012 case ALG_ID_ECDSA_P256
:
1013 magic
= BCRYPT_ECDSA_PRIVATE_P256_MAGIC
;
1018 FIXME( "algorithm %u does not yet support exporting ecc blob\n", key
->alg_id
);
1019 return STATUS_NOT_IMPLEMENTED
;
1022 if ((ret
= pgnutls_privkey_export_ecc_raw( key_data(key
)->privkey
, &curve
, &x
, &y
, &d
)))
1024 pgnutls_perror( ret
);
1025 return STATUS_INTERNAL_ERROR
;
1028 if (curve
!= GNUTLS_ECC_CURVE_SECP256R1
)
1030 FIXME( "curve %u not supported\n", curve
);
1031 free( x
.data
); free( y
.data
); free( d
.data
);
1032 return STATUS_NOT_IMPLEMENTED
;
1035 *ret_len
= sizeof(*ecc_blob
) + size
* 3;
1036 if (len
>= *ret_len
&& buf
)
1038 ecc_blob
= (BCRYPT_ECCKEY_BLOB
*)buf
;
1039 ecc_blob
->dwMagic
= magic
;
1040 ecc_blob
->cbKey
= size
;
1042 dst
= (UCHAR
*)(ecc_blob
+ 1);
1043 export_gnutls_datum( dst
, size
, &x
, NULL
);
1046 export_gnutls_datum( dst
, size
, &y
, NULL
);
1049 export_gnutls_datum( dst
, size
, &d
, NULL
);
1052 free( x
.data
); free( y
.data
); free( d
.data
);
1053 return STATUS_SUCCESS
;
1056 static NTSTATUS CDECL
key_import_ecc( struct key
*key
, UCHAR
*buf
, ULONG len
)
1058 BCRYPT_ECCKEY_BLOB
*ecc_blob
;
1059 gnutls_ecc_curve_t curve
;
1060 gnutls_privkey_t handle
;
1061 gnutls_datum_t x
, y
, k
;
1065 switch (key
->alg_id
)
1067 case ALG_ID_ECDH_P256
:
1068 case ALG_ID_ECDSA_P256
:
1069 curve
= GNUTLS_ECC_CURVE_SECP256R1
;
1073 FIXME( "algorithm %u not yet supported\n", key
->alg_id
);
1074 return STATUS_NOT_IMPLEMENTED
;
1077 if ((ret
= pgnutls_privkey_init( &handle
)))
1079 pgnutls_perror( ret
);
1080 return STATUS_INTERNAL_ERROR
;
1083 ecc_blob
= (BCRYPT_ECCKEY_BLOB
*)buf
;
1084 x
.data
= (unsigned char *)(ecc_blob
+ 1);
1085 x
.size
= ecc_blob
->cbKey
;
1086 y
.data
= x
.data
+ ecc_blob
->cbKey
;
1087 y
.size
= ecc_blob
->cbKey
;
1088 k
.data
= y
.data
+ ecc_blob
->cbKey
;
1089 k
.size
= ecc_blob
->cbKey
;
1091 if ((ret
= pgnutls_privkey_import_ecc_raw( handle
, curve
, &x
, &y
, &k
)))
1093 pgnutls_perror( ret
);
1094 pgnutls_privkey_deinit( handle
);
1095 return STATUS_INTERNAL_ERROR
;
1098 if ((status
= export_gnutls_pubkey_ecc( handle
, key
->alg_id
, &key
->u
.a
.pubkey
, &key
->u
.a
.pubkey_len
)))
1100 pgnutls_privkey_deinit( handle
);
1104 key_data(key
)->privkey
= handle
;
1105 return STATUS_SUCCESS
;
1108 static NTSTATUS CDECL
key_import_rsa( struct key
*key
, UCHAR
*buf
, ULONG len
)
1110 BCRYPT_RSAKEY_BLOB
*rsa_blob
= (BCRYPT_RSAKEY_BLOB
*)buf
;
1111 gnutls_datum_t m
, e
, p
, q
;
1112 gnutls_privkey_t handle
;
1115 if ((ret
= pgnutls_privkey_init( &handle
)))
1117 pgnutls_perror( ret
);
1118 return STATUS_INTERNAL_ERROR
;
1121 e
.data
= (unsigned char *)(rsa_blob
+ 1);
1122 e
.size
= rsa_blob
->cbPublicExp
;
1123 m
.data
= e
.data
+ e
.size
;
1124 m
.size
= rsa_blob
->cbModulus
;
1125 p
.data
= m
.data
+ m
.size
;
1126 p
.size
= rsa_blob
->cbPrime1
;
1127 q
.data
= p
.data
+ p
.size
;
1128 q
.size
= rsa_blob
->cbPrime2
;
1130 if ((ret
= pgnutls_privkey_import_rsa_raw( handle
, &m
, &e
, NULL
, &p
, &q
, NULL
, NULL
, NULL
)))
1132 pgnutls_perror( ret
);
1133 pgnutls_privkey_deinit( handle
);
1134 return STATUS_INTERNAL_ERROR
;
1137 key_data(key
)->privkey
= handle
;
1138 return STATUS_SUCCESS
;
1141 static NTSTATUS CDECL
key_export_dsa_capi( struct key
*key
, UCHAR
*buf
, ULONG len
, ULONG
*ret_len
)
1145 gnutls_datum_t p
, q
, g
, y
, x
;
1149 if ((ret
= pgnutls_privkey_export_dsa_raw( key_data(key
)->privkey
, &p
, &q
, &g
, &y
, &x
)))
1151 pgnutls_perror( ret
);
1152 return STATUS_INTERNAL_ERROR
;
1155 if (q
.size
> 21 || x
.size
> 21)
1157 ERR( "can't export key in this format\n" );
1158 free( p
.data
); free( q
.data
); free( g
.data
); free( y
.data
); free( x
.data
);
1159 return STATUS_NOT_SUPPORTED
;
1162 size
= key
->u
.a
.bitlen
/ 8;
1163 *ret_len
= sizeof(*hdr
) + sizeof(*pubkey
) + size
* 2 + 40 + sizeof(key
->u
.a
.dss_seed
);
1164 if (len
>= *ret_len
&& buf
)
1166 hdr
= (BLOBHEADER
*)buf
;
1167 hdr
->bType
= PRIVATEKEYBLOB
;
1170 hdr
->aiKeyAlg
= CALG_DSS_SIGN
;
1172 pubkey
= (DSSPUBKEY
*)(hdr
+ 1);
1173 pubkey
->magic
= MAGIC_DSS2
;
1174 pubkey
->bitlen
= key
->u
.a
.bitlen
;
1176 dst
= (UCHAR
*)(pubkey
+ 1);
1177 export_gnutls_datum( dst
, size
, &p
, NULL
);
1178 reverse_bytes( dst
, size
);
1181 export_gnutls_datum( dst
, 20, &q
, NULL
);
1182 reverse_bytes( dst
, 20 );
1185 export_gnutls_datum( dst
, size
, &g
, NULL
);
1186 reverse_bytes( dst
, size
);
1189 export_gnutls_datum( dst
, 20, &x
, NULL
);
1190 reverse_bytes( dst
, 20 );
1193 memcpy( dst
, &key
->u
.a
.dss_seed
, sizeof(key
->u
.a
.dss_seed
) );
1196 free( p
.data
); free( q
.data
); free( g
.data
); free( y
.data
); free( x
.data
);
1197 return STATUS_SUCCESS
;
1200 static NTSTATUS CDECL
key_import_dsa_capi( struct key
*key
, UCHAR
*buf
, ULONG len
)
1202 BLOBHEADER
*hdr
= (BLOBHEADER
*)buf
;
1204 gnutls_privkey_t handle
;
1205 gnutls_datum_t p
, q
, g
, y
, x
;
1206 unsigned char dummy
[128];
1207 unsigned char *data
, p_data
[128], q_data
[20], g_data
[128], x_data
[20];
1211 if ((ret
= pgnutls_privkey_init( &handle
)))
1213 pgnutls_perror( ret
);
1214 return STATUS_INTERNAL_ERROR
;
1217 hdr
= (BLOBHEADER
*)buf
;
1218 pubkey
= (DSSPUBKEY
*)(hdr
+ 1);
1219 if ((size
= pubkey
->bitlen
/ 8) > sizeof(p_data
))
1221 FIXME( "size %u not supported\n", size
);
1222 pgnutls_privkey_deinit( handle
);
1223 return STATUS_NOT_SUPPORTED
;
1225 data
= (unsigned char *)(pubkey
+ 1);
1229 for (i
= 0; i
< p
.size
; i
++) p
.data
[i
] = data
[p
.size
- i
- 1];
1233 q
.size
= sizeof(q_data
);
1234 for (i
= 0; i
< q
.size
; i
++) q
.data
[i
] = data
[q
.size
- i
- 1];
1239 for (i
= 0; i
< g
.size
; i
++) g
.data
[i
] = data
[g
.size
- i
- 1];
1243 x
.size
= sizeof(x_data
);
1244 for (i
= 0; i
< x
.size
; i
++) x
.data
[i
] = data
[x
.size
- i
- 1];
1247 WARN( "using dummy public key\n" );
1248 memset( dummy
, 1, sizeof(dummy
) );
1250 y
.size
= min( p
.size
, sizeof(dummy
) );
1252 if ((ret
= pgnutls_privkey_import_dsa_raw( handle
, &p
, &q
, &g
, &y
, &x
)))
1254 pgnutls_perror( ret
);
1255 pgnutls_privkey_deinit( handle
);
1256 return STATUS_INTERNAL_ERROR
;
1259 if ((status
= export_gnutls_pubkey_dsa_capi( handle
, &key
->u
.a
.dss_seed
, key
->u
.a
.bitlen
, &key
->u
.a
.pubkey
,
1260 &key
->u
.a
.pubkey_len
)))
1262 pgnutls_privkey_deinit( handle
);
1266 memcpy( &key
->u
.a
.dss_seed
, data
, sizeof(key
->u
.a
.dss_seed
) );
1268 key
->u
.a
.flags
|= KEY_FLAG_LEGACY_DSA_V2
;
1269 key_data(key
)->privkey
= handle
;
1271 return STATUS_SUCCESS
;
1274 static NTSTATUS CDECL
key_asymmetric_init( struct key
*key
)
1276 if (!libgnutls_handle
) return STATUS_INTERNAL_ERROR
;
1278 switch (key
->alg_id
)
1280 case ALG_ID_ECDH_P256
:
1281 case ALG_ID_ECDSA_P256
:
1282 case ALG_ID_ECDSA_P384
:
1284 case ALG_ID_RSA_SIGN
:
1286 return STATUS_SUCCESS
;
1289 FIXME( "algorithm %u not supported\n", key
->alg_id
);
1290 return STATUS_NOT_SUPPORTED
;
1294 static NTSTATUS
import_gnutls_pubkey_ecc( struct key
*key
, gnutls_pubkey_t
*gnutls_key
)
1296 BCRYPT_ECCKEY_BLOB
*ecc_blob
;
1297 gnutls_ecc_curve_t curve
;
1298 gnutls_datum_t x
, y
;
1301 switch (key
->alg_id
)
1303 case ALG_ID_ECDSA_P256
: curve
= GNUTLS_ECC_CURVE_SECP256R1
; break;
1304 case ALG_ID_ECDSA_P384
: curve
= GNUTLS_ECC_CURVE_SECP384R1
; break;
1307 FIXME( "algorithm %u not yet supported\n", key
->alg_id
);
1308 return STATUS_NOT_IMPLEMENTED
;
1311 if ((ret
= pgnutls_pubkey_init( gnutls_key
)))
1313 pgnutls_perror( ret
);
1314 return STATUS_INTERNAL_ERROR
;
1317 ecc_blob
= (BCRYPT_ECCKEY_BLOB
*)key
->u
.a
.pubkey
;
1318 x
.data
= key
->u
.a
.pubkey
+ sizeof(*ecc_blob
);
1319 x
.size
= ecc_blob
->cbKey
;
1320 y
.data
= key
->u
.a
.pubkey
+ sizeof(*ecc_blob
) + ecc_blob
->cbKey
;
1321 y
.size
= ecc_blob
->cbKey
;
1323 if ((ret
= pgnutls_pubkey_import_ecc_raw( *gnutls_key
, curve
, &x
, &y
)))
1325 pgnutls_perror( ret
);
1326 pgnutls_pubkey_deinit( *gnutls_key
);
1327 return STATUS_INTERNAL_ERROR
;
1330 return STATUS_SUCCESS
;
1333 static NTSTATUS
import_gnutls_pubkey_rsa( struct key
*key
, gnutls_pubkey_t
*gnutls_key
)
1335 BCRYPT_RSAKEY_BLOB
*rsa_blob
;
1336 gnutls_datum_t m
, e
;
1339 if ((ret
= pgnutls_pubkey_init( gnutls_key
)))
1341 pgnutls_perror( ret
);
1342 return STATUS_INTERNAL_ERROR
;
1345 rsa_blob
= (BCRYPT_RSAKEY_BLOB
*)key
->u
.a
.pubkey
;
1346 e
.data
= key
->u
.a
.pubkey
+ sizeof(*rsa_blob
);
1347 e
.size
= rsa_blob
->cbPublicExp
;
1348 m
.data
= key
->u
.a
.pubkey
+ sizeof(*rsa_blob
) + rsa_blob
->cbPublicExp
;
1349 m
.size
= rsa_blob
->cbModulus
;
1351 if ((ret
= pgnutls_pubkey_import_rsa_raw( *gnutls_key
, &m
, &e
)))
1353 pgnutls_perror( ret
);
1354 pgnutls_pubkey_deinit( *gnutls_key
);
1355 return STATUS_INTERNAL_ERROR
;
1358 return STATUS_SUCCESS
;
1361 static NTSTATUS
import_gnutls_pubkey_dsa( struct key
*key
, gnutls_pubkey_t
*gnutls_key
)
1363 BCRYPT_DSA_KEY_BLOB
*dsa_blob
;
1364 gnutls_datum_t p
, q
, g
, y
;
1367 if ((ret
= pgnutls_pubkey_init( gnutls_key
)))
1369 pgnutls_perror( ret
);
1370 return STATUS_INTERNAL_ERROR
;
1373 dsa_blob
= (BCRYPT_DSA_KEY_BLOB
*)key
->u
.a
.pubkey
;
1374 p
.data
= key
->u
.a
.pubkey
+ sizeof(*dsa_blob
);
1375 p
.size
= dsa_blob
->cbKey
;
1376 q
.data
= dsa_blob
->q
;
1377 q
.size
= sizeof(dsa_blob
->q
);
1378 g
.data
= key
->u
.a
.pubkey
+ sizeof(*dsa_blob
) + dsa_blob
->cbKey
;
1379 g
.size
= dsa_blob
->cbKey
;
1380 y
.data
= key
->u
.a
.pubkey
+ sizeof(*dsa_blob
) + dsa_blob
->cbKey
* 2;
1381 y
.size
= dsa_blob
->cbKey
;
1383 if ((ret
= pgnutls_pubkey_import_dsa_raw( *gnutls_key
, &p
, &q
, &g
, &y
)))
1385 pgnutls_perror( ret
);
1386 pgnutls_pubkey_deinit( *gnutls_key
);
1387 return STATUS_INTERNAL_ERROR
;
1390 return STATUS_SUCCESS
;
1393 static NTSTATUS
import_gnutls_pubkey_dsa_capi( struct key
*key
, gnutls_pubkey_t
*gnutls_key
)
1397 gnutls_datum_t p
, q
, g
, y
;
1398 unsigned char *data
, p_data
[128], q_data
[20], g_data
[128], y_data
[128];
1401 if ((ret
= pgnutls_pubkey_init( gnutls_key
)))
1403 pgnutls_perror( ret
);
1404 return STATUS_INTERNAL_ERROR
;
1407 hdr
= (BLOBHEADER
*)key
->u
.a
.pubkey
;
1408 pubkey
= (DSSPUBKEY
*)(hdr
+ 1);
1409 size
= pubkey
->bitlen
/ 8;
1410 data
= (unsigned char *)(pubkey
+ 1);
1414 for (i
= 0; i
< p
.size
; i
++) p
.data
[i
] = data
[p
.size
- i
- 1];
1418 q
.size
= sizeof(q_data
);
1419 for (i
= 0; i
< q
.size
; i
++) q
.data
[i
] = data
[q
.size
- i
- 1];
1424 for (i
= 0; i
< g
.size
; i
++) g
.data
[i
] = data
[g
.size
- i
- 1];
1428 y
.size
= sizeof(y_data
);
1429 for (i
= 0; i
< y
.size
; i
++) y
.data
[i
] = data
[y
.size
- i
- 1];
1431 if ((ret
= pgnutls_pubkey_import_dsa_raw( *gnutls_key
, &p
, &q
, &g
, &y
)))
1433 pgnutls_perror( ret
);
1434 pgnutls_pubkey_deinit( *gnutls_key
);
1435 return STATUS_INTERNAL_ERROR
;
1438 return STATUS_SUCCESS
;
1441 static NTSTATUS
import_gnutls_pubkey( struct key
*key
, gnutls_pubkey_t
*gnutls_key
)
1443 switch (key
->alg_id
)
1445 case ALG_ID_ECDSA_P256
:
1446 case ALG_ID_ECDSA_P384
:
1447 return import_gnutls_pubkey_ecc( key
, gnutls_key
);
1450 case ALG_ID_RSA_SIGN
:
1451 return import_gnutls_pubkey_rsa( key
, gnutls_key
);
1454 if (key
->u
.a
.flags
& KEY_FLAG_LEGACY_DSA_V2
)
1455 return import_gnutls_pubkey_dsa_capi( key
, gnutls_key
);
1457 return import_gnutls_pubkey_dsa( key
, gnutls_key
);
1460 FIXME("algorithm %u not yet supported\n", key
->alg_id
);
1461 return STATUS_NOT_IMPLEMENTED
;
1465 static NTSTATUS
prepare_gnutls_signature_dsa( struct key
*key
, UCHAR
*signature
, ULONG signature_len
,
1466 gnutls_datum_t
*gnutls_signature
)
1468 struct buffer buffer
;
1469 DWORD r_len
= signature_len
/ 2;
1470 DWORD s_len
= r_len
;
1471 BYTE
*r
= signature
;
1472 BYTE
*s
= signature
+ r_len
;
1474 buffer_init( &buffer
);
1475 buffer_append_asn1_r_s( &buffer
, r
, r_len
, s
, s_len
);
1478 buffer_free( &buffer
);
1479 return STATUS_NO_MEMORY
;
1482 gnutls_signature
->data
= buffer
.buffer
;
1483 gnutls_signature
->size
= buffer
.pos
;
1484 return STATUS_SUCCESS
;
1487 static NTSTATUS
prepare_gnutls_signature_rsa( struct key
*key
, UCHAR
*signature
, ULONG signature_len
,
1488 gnutls_datum_t
*gnutls_signature
)
1490 gnutls_signature
->data
= signature
;
1491 gnutls_signature
->size
= signature_len
;
1492 return STATUS_SUCCESS
;
1495 static NTSTATUS
prepare_gnutls_signature( struct key
*key
, UCHAR
*signature
, ULONG signature_len
,
1496 gnutls_datum_t
*gnutls_signature
)
1498 switch (key
->alg_id
)
1500 case ALG_ID_ECDSA_P256
:
1501 case ALG_ID_ECDSA_P384
:
1503 return prepare_gnutls_signature_dsa( key
, signature
, signature_len
, gnutls_signature
);
1506 case ALG_ID_RSA_SIGN
:
1507 return prepare_gnutls_signature_rsa( key
, signature
, signature_len
, gnutls_signature
);
1510 FIXME( "algorithm %u not yet supported\n", key
->alg_id
);
1511 return STATUS_NOT_IMPLEMENTED
;
1515 static gnutls_digest_algorithm_t
get_digest_from_id( const WCHAR
*alg_id
)
1517 if (!strcmpW( alg_id
, BCRYPT_SHA1_ALGORITHM
)) return GNUTLS_DIG_SHA1
;
1518 if (!strcmpW( alg_id
, BCRYPT_SHA256_ALGORITHM
)) return GNUTLS_DIG_SHA256
;
1519 if (!strcmpW( alg_id
, BCRYPT_SHA384_ALGORITHM
)) return GNUTLS_DIG_SHA384
;
1520 if (!strcmpW( alg_id
, BCRYPT_SHA512_ALGORITHM
)) return GNUTLS_DIG_SHA512
;
1521 if (!strcmpW( alg_id
, BCRYPT_MD2_ALGORITHM
)) return GNUTLS_DIG_MD2
;
1522 if (!strcmpW( alg_id
, BCRYPT_MD5_ALGORITHM
)) return GNUTLS_DIG_MD5
;
1526 static NTSTATUS CDECL
key_asymmetric_verify( struct key
*key
, void *padding
, UCHAR
*hash
, ULONG hash_len
,
1527 UCHAR
*signature
, ULONG signature_len
, DWORD flags
)
1529 gnutls_digest_algorithm_t hash_alg
;
1530 gnutls_sign_algorithm_t sign_alg
;
1531 gnutls_datum_t gnutls_hash
, gnutls_signature
;
1532 gnutls_pk_algorithm_t pk_alg
;
1533 gnutls_pubkey_t gnutls_key
;
1537 switch (key
->alg_id
)
1539 case ALG_ID_ECDSA_P256
:
1540 case ALG_ID_ECDSA_P384
:
1542 if (flags
) FIXME( "flags %08x not supported\n", flags
);
1544 /* only the hash size must match, not the actual hash function */
1547 case 20: hash_alg
= GNUTLS_DIG_SHA1
; break;
1548 case 32: hash_alg
= GNUTLS_DIG_SHA256
; break;
1549 case 48: hash_alg
= GNUTLS_DIG_SHA384
; break;
1552 FIXME( "hash size %u not yet supported\n", hash_len
);
1553 return STATUS_INVALID_SIGNATURE
;
1555 pk_alg
= GNUTLS_PK_ECC
;
1559 case ALG_ID_RSA_SIGN
:
1561 BCRYPT_PKCS1_PADDING_INFO
*info
= (BCRYPT_PKCS1_PADDING_INFO
*)padding
;
1563 if (!(flags
& BCRYPT_PAD_PKCS1
) || !info
) return STATUS_INVALID_PARAMETER
;
1564 if (!info
->pszAlgId
) return STATUS_INVALID_SIGNATURE
;
1566 if ((hash_alg
= get_digest_from_id(info
->pszAlgId
)) == -1)
1568 FIXME( "hash algorithm %s not supported\n", debugstr_w(info
->pszAlgId
) );
1569 return STATUS_NOT_SUPPORTED
;
1571 pk_alg
= GNUTLS_PK_RSA
;
1576 if (flags
) FIXME( "flags %08x not supported\n", flags
);
1579 FIXME( "hash size %u not supported\n", hash_len
);
1580 return STATUS_INVALID_PARAMETER
;
1582 hash_alg
= GNUTLS_DIG_SHA1
;
1583 pk_alg
= GNUTLS_PK_DSA
;
1587 FIXME( "algorithm %u not yet supported\n", key
->alg_id
);
1588 return STATUS_NOT_IMPLEMENTED
;
1591 if ((sign_alg
= pgnutls_pk_to_sign( pk_alg
, hash_alg
)) == GNUTLS_SIGN_UNKNOWN
)
1593 FIXME("GnuTLS does not support algorithm %u with hash len %u\n", key
->alg_id
, hash_len
);
1594 return STATUS_NOT_IMPLEMENTED
;
1597 if ((status
= import_gnutls_pubkey( key
, &gnutls_key
))) return status
;
1598 if ((status
= prepare_gnutls_signature( key
, signature
, signature_len
, &gnutls_signature
)))
1600 pgnutls_pubkey_deinit( gnutls_key
);
1604 gnutls_hash
.data
= hash
;
1605 gnutls_hash
.size
= hash_len
;
1606 ret
= pgnutls_pubkey_verify_hash2( gnutls_key
, sign_alg
, 0, &gnutls_hash
, &gnutls_signature
);
1608 if (gnutls_signature
.data
!= signature
) free( gnutls_signature
.data
);
1609 pgnutls_pubkey_deinit( gnutls_key
);
1610 return (ret
< 0) ? STATUS_INVALID_SIGNATURE
: STATUS_SUCCESS
;
1613 static unsigned int get_signature_length( enum alg_id id
)
1617 case ALG_ID_ECDSA_P256
: return 64;
1618 case ALG_ID_ECDSA_P384
: return 96;
1619 case ALG_ID_DSA
: return 40;
1621 FIXME( "unhandled algorithm %u\n", id
);
1626 static NTSTATUS
format_gnutls_signature( enum alg_id type
, gnutls_datum_t signature
,
1627 UCHAR
*output
, ULONG output_len
, ULONG
*ret_len
)
1632 case ALG_ID_RSA_SIGN
:
1634 *ret_len
= signature
.size
;
1635 if (output_len
< signature
.size
) return STATUS_BUFFER_TOO_SMALL
;
1636 if (output
) memcpy( output
, signature
.data
, signature
.size
);
1637 return STATUS_SUCCESS
;
1639 case ALG_ID_ECDSA_P256
:
1640 case ALG_ID_ECDSA_P384
:
1644 unsigned int sig_len
= get_signature_length( type
);
1645 gnutls_datum_t r
, s
; /* format as r||s */
1647 if ((err
= pgnutls_decode_rs_value( &signature
, &r
, &s
)))
1649 pgnutls_perror( err
);
1650 return STATUS_INTERNAL_ERROR
;
1654 if (output_len
< sig_len
) return STATUS_BUFFER_TOO_SMALL
;
1656 if (r
.size
> sig_len
/ 2 + 1 || s
.size
> sig_len
/ 2 + 1)
1658 ERR( "we didn't get a correct signature\n" );
1659 return STATUS_INTERNAL_ERROR
;
1664 export_gnutls_datum( output
, sig_len
/ 2, &r
, NULL
);
1665 export_gnutls_datum( output
+ sig_len
/ 2, sig_len
/ 2, &s
, NULL
);
1668 free( r
.data
); free( s
.data
);
1669 return STATUS_SUCCESS
;
1672 return STATUS_INTERNAL_ERROR
;
1676 static NTSTATUS CDECL
key_asymmetric_sign( struct key
*key
, void *padding
, UCHAR
*input
, ULONG input_len
, UCHAR
*output
,
1677 ULONG output_len
, ULONG
*ret_len
, ULONG flags
)
1679 BCRYPT_PKCS1_PADDING_INFO
*pad
= padding
;
1680 gnutls_datum_t hash
, signature
;
1681 gnutls_digest_algorithm_t hash_alg
;
1685 if (key
->alg_id
== ALG_ID_ECDSA_P256
|| key
->alg_id
== ALG_ID_ECDSA_P384
)
1687 /* With ECDSA, we find the digest algorithm from the hash length, and verify it */
1690 case 20: hash_alg
= GNUTLS_DIG_SHA1
; break;
1691 case 32: hash_alg
= GNUTLS_DIG_SHA256
; break;
1692 case 48: hash_alg
= GNUTLS_DIG_SHA384
; break;
1693 case 64: hash_alg
= GNUTLS_DIG_SHA512
; break;
1696 FIXME( "hash size %u not yet supported\n", input_len
);
1697 return STATUS_INVALID_PARAMETER
;
1700 if (flags
== BCRYPT_PAD_PKCS1
&& pad
&& pad
->pszAlgId
&& get_digest_from_id( pad
->pszAlgId
) != hash_alg
)
1702 WARN( "incorrect hashing algorithm %s, expected %u\n", debugstr_w(pad
->pszAlgId
), hash_alg
);
1703 return STATUS_INVALID_PARAMETER
;
1706 else if (key
->alg_id
== ALG_ID_DSA
)
1708 if (flags
) FIXME( "flags %08x not supported\n", flags
);
1709 if (input_len
!= 20)
1711 FIXME( "hash size %u not supported\n", input_len
);
1712 return STATUS_INVALID_PARAMETER
;
1714 hash_alg
= GNUTLS_DIG_SHA1
;
1716 else if (flags
== BCRYPT_PAD_PKCS1
)
1718 if (!pad
|| !pad
->pszAlgId
)
1720 WARN( "padding info not found\n" );
1721 return STATUS_INVALID_PARAMETER
;
1724 if ((hash_alg
= get_digest_from_id( pad
->pszAlgId
)) == -1)
1726 FIXME( "hash algorithm %s not recognized\n", debugstr_w(pad
->pszAlgId
) );
1727 return STATUS_NOT_SUPPORTED
;
1732 WARN( "invalid flags %08x\n", flags
);
1733 return STATUS_INVALID_PARAMETER
;
1737 FIXME( "flags %08x not implemented\n", flags
);
1738 return STATUS_NOT_IMPLEMENTED
;
1743 *ret_len
= key
->u
.a
.bitlen
/ 8;
1744 return STATUS_SUCCESS
;
1746 if (!key_data(key
)->privkey
) return STATUS_INVALID_PARAMETER
;
1749 hash
.size
= input_len
;
1751 signature
.data
= NULL
;
1754 if ((ret
= pgnutls_privkey_sign_hash( key_data(key
)->privkey
, hash_alg
, 0, &hash
, &signature
)))
1756 pgnutls_perror( ret
);
1757 return STATUS_INTERNAL_ERROR
;
1760 status
= format_gnutls_signature( key
->alg_id
, signature
, output
, output_len
, ret_len
);
1762 free( signature
.data
);
1766 static void CDECL
key_asymmetric_destroy( struct key
*key
)
1768 if (key_data(key
)->privkey
) pgnutls_privkey_deinit( key_data(key
)->privkey
);
1771 static NTSTATUS CDECL
key_asymmetric_duplicate( struct key
*key_orig
, struct key
*key_copy
)
1775 if (!key_data(key_orig
)->privkey
) return STATUS_SUCCESS
;
1777 if ((ret
= pgnutls_privkey_init( &key_data(key_copy
)->privkey
)))
1779 pgnutls_perror( ret
);
1780 return STATUS_INTERNAL_ERROR
;
1783 switch (key_orig
->alg_id
)
1786 case ALG_ID_RSA_SIGN
:
1788 gnutls_datum_t m
, e
, d
, p
, q
, u
, e1
, e2
;
1789 if ((ret
= pgnutls_privkey_export_rsa_raw( key_data(key_orig
)->privkey
, &m
, &e
, &d
, &p
, &q
, &u
, &e1
, &e2
)))
1791 pgnutls_perror( ret
);
1792 return STATUS_INTERNAL_ERROR
;
1794 ret
= pgnutls_privkey_import_rsa_raw( key_data(key_copy
)->privkey
, &m
, &e
, &d
, &p
, &q
, &u
, &e1
, &e2
);
1795 free( m
.data
); free( e
.data
); free( d
.data
); free( p
.data
); free( q
.data
); free( u
.data
);
1796 free( e1
.data
); free( e2
.data
);
1799 pgnutls_perror( ret
);
1800 return STATUS_INTERNAL_ERROR
;
1806 gnutls_datum_t p
, q
, g
, y
, x
;
1807 if ((ret
= pgnutls_privkey_export_dsa_raw( key_data(key_orig
)->privkey
, &p
, &q
, &g
, &y
, &x
)))
1809 pgnutls_perror( ret
);
1810 return STATUS_INTERNAL_ERROR
;
1812 ret
= pgnutls_privkey_import_dsa_raw( key_data(key_copy
)->privkey
, &p
, &q
, &g
, &y
, &x
);
1813 free( p
.data
); free( q
.data
); free( g
.data
); free( y
.data
); free( x
.data
);
1816 pgnutls_perror( ret
);
1817 return STATUS_INTERNAL_ERROR
;
1821 case ALG_ID_ECDH_P256
:
1822 case ALG_ID_ECDSA_P256
:
1823 case ALG_ID_ECDSA_P384
:
1825 gnutls_ecc_curve_t curve
;
1826 gnutls_datum_t x
, y
, k
;
1827 if ((ret
= pgnutls_privkey_export_ecc_raw( key_data(key_orig
)->privkey
, &curve
, &x
, &y
, &k
)))
1829 pgnutls_perror( ret
);
1830 return STATUS_INTERNAL_ERROR
;
1832 ret
= pgnutls_privkey_import_ecc_raw( key_data(key_copy
)->privkey
, curve
, &x
, &y
, &k
);
1833 free( x
.data
); free( y
.data
); free( k
.data
);
1836 pgnutls_perror( ret
);
1837 return STATUS_INTERNAL_ERROR
;
1842 ERR( "unhandled algorithm %u\n", key_orig
->alg_id
);
1843 return STATUS_INTERNAL_ERROR
;
1846 return STATUS_SUCCESS
;
1849 static NTSTATUS CDECL
key_asymmetric_decrypt( struct key
*key
, UCHAR
*input
, ULONG input_len
,
1850 UCHAR
*output
, ULONG
*output_len
)
1852 gnutls_datum_t e
, d
= { 0 };
1853 NTSTATUS status
= STATUS_SUCCESS
;
1856 e
.data
= (unsigned char *)input
;
1859 if ((ret
= pgnutls_privkey_decrypt_data( key_data(key
)->privkey
, 0, &e
, &d
)))
1861 pgnutls_perror( ret
);
1862 return STATUS_INTERNAL_ERROR
;
1865 if (*output_len
>= d
.size
)
1867 *output_len
= d
.size
;
1868 memcpy( output
, d
.data
, *output_len
);
1871 status
= STATUS_BUFFER_TOO_SMALL
;
1878 static const struct key_funcs key_funcs
=
1882 key_symmetric_vector_reset
,
1883 key_symmetric_set_auth_data
,
1884 key_symmetric_encrypt
,
1885 key_symmetric_decrypt
,
1886 key_symmetric_get_tag
,
1887 key_symmetric_destroy
,
1888 key_asymmetric_init
,
1889 key_asymmetric_generate
,
1890 key_asymmetric_decrypt
,
1891 key_asymmetric_duplicate
,
1892 key_asymmetric_sign
,
1893 key_asymmetric_verify
,
1894 key_asymmetric_destroy
,
1895 key_export_dsa_capi
,
1897 key_import_dsa_capi
,
1902 NTSTATUS CDECL
__wine_init_unix_lib( HMODULE module
, DWORD reason
, const void *ptr_in
, void *ptr_out
)
1906 case DLL_PROCESS_ATTACH
:
1907 if (!gnutls_initialize()) return STATUS_DLL_NOT_FOUND
;
1908 *(const struct key_funcs
**)ptr_out
= &key_funcs
;
1910 case DLL_PROCESS_DETACH
:
1911 gnutls_uninitialize();
1914 return STATUS_SUCCESS
;
1917 #endif /* HAVE_GNUTLS_CIPHER_INIT */