bcrypt: Move the backend code to a new Unix library.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
209b968efc
commit
a472ad191f
|
@ -189,25 +189,25 @@ struct secret
|
||||||
struct object hdr;
|
struct object hdr;
|
||||||
};
|
};
|
||||||
|
|
||||||
NTSTATUS key_set_property( struct key *, const WCHAR *, UCHAR *, ULONG, ULONG ) DECLSPEC_HIDDEN;
|
struct key_funcs
|
||||||
NTSTATUS key_symmetric_init( struct key * ) DECLSPEC_HIDDEN;
|
{
|
||||||
void key_symmetric_vector_reset( struct key * ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_set_property)( struct key *, const WCHAR *, UCHAR *, ULONG, ULONG );
|
||||||
NTSTATUS key_symmetric_set_auth_data( struct key *, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_symmetric_init)( struct key * );
|
||||||
NTSTATUS key_symmetric_encrypt( struct key *, const UCHAR *, ULONG, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
void (CDECL *key_symmetric_vector_reset)( struct key * );
|
||||||
NTSTATUS key_symmetric_decrypt( struct key *, const UCHAR *, ULONG, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_symmetric_set_auth_data)( struct key *, UCHAR *, ULONG );
|
||||||
NTSTATUS key_symmetric_get_tag( struct key *, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_symmetric_encrypt)( struct key *, const UCHAR *, ULONG, UCHAR *, ULONG );
|
||||||
void key_symmetric_destroy( struct key * ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_symmetric_decrypt)( struct key *, const UCHAR *, ULONG, UCHAR *, ULONG );
|
||||||
NTSTATUS key_asymmetric_init( struct key * ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_symmetric_get_tag)( struct key *, UCHAR *, ULONG );
|
||||||
NTSTATUS key_asymmetric_generate( struct key * ) DECLSPEC_HIDDEN;
|
void (CDECL *key_symmetric_destroy)( struct key * );
|
||||||
NTSTATUS key_asymmetric_sign( struct key *, void *, UCHAR *, ULONG, UCHAR *, ULONG, ULONG *, ULONG ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_asymmetric_init)( struct key * );
|
||||||
NTSTATUS key_asymmetric_verify( struct key *, void *, UCHAR *, ULONG, UCHAR *, ULONG, DWORD ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_asymmetric_generate)( struct key * );
|
||||||
void key_asymmetric_destroy( struct key * ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_asymmetric_sign)( struct key *, void *, UCHAR *, ULONG, UCHAR *, ULONG, ULONG *, ULONG );
|
||||||
NTSTATUS key_export_dsa_capi( struct key *, UCHAR *, ULONG, ULONG * ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_asymmetric_verify)( struct key *, void *, UCHAR *, ULONG, UCHAR *, ULONG, DWORD );
|
||||||
NTSTATUS key_export_ecc( struct key *, UCHAR *, ULONG, ULONG * ) DECLSPEC_HIDDEN;
|
void (CDECL *key_asymmetric_destroy)( struct key * );
|
||||||
NTSTATUS key_import_dsa_capi( struct key *, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_export_dsa_capi)( struct key *, UCHAR *, ULONG, ULONG * );
|
||||||
NTSTATUS key_import_ecc( struct key *, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_export_ecc)( struct key *, UCHAR *, ULONG, ULONG * );
|
||||||
|
NTSTATUS (CDECL *key_import_dsa_capi)( struct key *, UCHAR *, ULONG );
|
||||||
BOOL gnutls_initialize(void) DECLSPEC_HIDDEN;
|
NTSTATUS (CDECL *key_import_ecc)( struct key *, UCHAR *, ULONG );
|
||||||
void gnutls_uninitialize(void) DECLSPEC_HIDDEN;
|
};
|
||||||
|
|
||||||
#endif /* __BCRYPT_INTERNAL_H */
|
#endif /* __BCRYPT_INTERNAL_H */
|
||||||
|
|
|
@ -21,10 +21,6 @@
|
||||||
#include "wine/port.h"
|
#include "wine/port.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
|
|
||||||
#include <AvailabilityMacros.h>
|
|
||||||
#include <CommonCrypto/CommonCryptor.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "ntstatus.h"
|
#include "ntstatus.h"
|
||||||
#define WIN32_NO_STATUS
|
#define WIN32_NO_STATUS
|
||||||
|
@ -32,6 +28,7 @@
|
||||||
#include "winbase.h"
|
#include "winbase.h"
|
||||||
#include "ntsecapi.h"
|
#include "ntsecapi.h"
|
||||||
#include "wincrypt.h"
|
#include "wincrypt.h"
|
||||||
|
#include "winternl.h"
|
||||||
#include "bcrypt.h"
|
#include "bcrypt.h"
|
||||||
|
|
||||||
#include "bcrypt_internal.h"
|
#include "bcrypt_internal.h"
|
||||||
|
@ -44,6 +41,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(bcrypt);
|
||||||
|
|
||||||
static HINSTANCE instance;
|
static HINSTANCE instance;
|
||||||
|
|
||||||
|
static const struct key_funcs *key_funcs;
|
||||||
|
|
||||||
NTSTATUS WINAPI BCryptAddContextFunction(ULONG table, LPCWSTR context, ULONG iface, LPCWSTR function, ULONG pos)
|
NTSTATUS WINAPI BCryptAddContextFunction(ULONG table, LPCWSTR context, ULONG iface, LPCWSTR function, ULONG pos)
|
||||||
{
|
{
|
||||||
FIXME("%08x, %s, %08x, %s, %u: stub\n", table, debugstr_w(context), iface, debugstr_w(function), pos);
|
FIXME("%08x, %s, %08x, %s, %u: stub\n", table, debugstr_w(context), iface, debugstr_w(function), pos);
|
||||||
|
@ -861,6 +860,12 @@ static NTSTATUS key_asymmetric_create( struct key **ret_key, struct algorithm *a
|
||||||
struct key *key;
|
struct key *key;
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
|
if (!key_funcs)
|
||||||
|
{
|
||||||
|
ERR( "no encryption support\n" );
|
||||||
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(key = heap_alloc_zero( sizeof(*key) ))) return STATUS_NO_MEMORY;
|
if (!(key = heap_alloc_zero( sizeof(*key) ))) return STATUS_NO_MEMORY;
|
||||||
key->hdr.magic = MAGIC_KEY;
|
key->hdr.magic = MAGIC_KEY;
|
||||||
key->alg_id = alg->id;
|
key->alg_id = alg->id;
|
||||||
|
@ -876,7 +881,7 @@ static NTSTATUS key_asymmetric_create( struct key **ret_key, struct algorithm *a
|
||||||
memcpy( key->u.a.pubkey, pubkey, pubkey_len );
|
memcpy( key->u.a.pubkey, pubkey, pubkey_len );
|
||||||
key->u.a.pubkey_len = pubkey_len;
|
key->u.a.pubkey_len = pubkey_len;
|
||||||
}
|
}
|
||||||
if ((status = key_asymmetric_init( key )))
|
if ((status = key_funcs->key_asymmetric_init( key )))
|
||||||
{
|
{
|
||||||
heap_free( key->u.a.pubkey );
|
heap_free( key->u.a.pubkey );
|
||||||
heap_free( key );
|
heap_free( key );
|
||||||
|
@ -891,7 +896,6 @@ static BOOL key_is_symmetric( struct key *key )
|
||||||
return builtin_algorithms[key->alg_id].class == BCRYPT_CIPHER_INTERFACE;
|
return builtin_algorithms[key->alg_id].class == BCRYPT_CIPHER_INTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_GNUTLS_CIPHER_INIT) || defined(HAVE_COMMONCRYPTO_COMMONCRYPTOR_H) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
|
|
||||||
static BOOL is_zero_vector( const UCHAR *vector, ULONG len )
|
static BOOL is_zero_vector( const UCHAR *vector, ULONG len )
|
||||||
{
|
{
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
@ -921,7 +925,7 @@ static NTSTATUS key_symmetric_set_vector( struct key *key, UCHAR *vector, ULONG
|
||||||
memcpy( key->u.s.vector, vector, vector_len );
|
memcpy( key->u.s.vector, vector, vector_len );
|
||||||
key->u.s.vector_len = vector_len;
|
key->u.s.vector_len = vector_len;
|
||||||
}
|
}
|
||||||
if (needs_reset) key_symmetric_vector_reset( key );
|
if (needs_reset) key_funcs->key_symmetric_vector_reset( key );
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,11 +1001,11 @@ static NTSTATUS key_export( struct key *key, const WCHAR *type, UCHAR *output, U
|
||||||
}
|
}
|
||||||
else if (!strcmpW( type, BCRYPT_ECCPRIVATE_BLOB ))
|
else if (!strcmpW( type, BCRYPT_ECCPRIVATE_BLOB ))
|
||||||
{
|
{
|
||||||
return key_export_ecc( key, output, output_len, size );
|
return key_funcs->key_export_ecc( key, output, output_len, size );
|
||||||
}
|
}
|
||||||
else if (!strcmpW( type, LEGACY_DSA_V2_PRIVATE_BLOB ))
|
else if (!strcmpW( type, LEGACY_DSA_V2_PRIVATE_BLOB ))
|
||||||
{
|
{
|
||||||
return key_export_dsa_capi( key, output, output_len, size );
|
return key_funcs->key_export_dsa_capi( key, output, output_len, size );
|
||||||
}
|
}
|
||||||
|
|
||||||
FIXME( "unsupported key type %s\n", debugstr_w(type) );
|
FIXME( "unsupported key type %s\n", debugstr_w(type) );
|
||||||
|
@ -1064,11 +1068,11 @@ static NTSTATUS key_encrypt( struct key *key, UCHAR *input, ULONG input_len, vo
|
||||||
if (input && !output) return STATUS_SUCCESS;
|
if (input && !output) return STATUS_SUCCESS;
|
||||||
if (output_len < *ret_len) return STATUS_BUFFER_TOO_SMALL;
|
if (output_len < *ret_len) return STATUS_BUFFER_TOO_SMALL;
|
||||||
|
|
||||||
if ((status = key_symmetric_set_auth_data( key, auth_info->pbAuthData, auth_info->cbAuthData )))
|
if ((status = key_funcs->key_symmetric_set_auth_data( key, auth_info->pbAuthData, auth_info->cbAuthData )))
|
||||||
return status;
|
return status;
|
||||||
if ((status = key_symmetric_encrypt( key, input, input_len, output, output_len ))) return status;
|
if ((status = key_funcs->key_symmetric_encrypt( key, input, input_len, output, output_len ))) return status;
|
||||||
|
|
||||||
return key_symmetric_get_tag( key, auth_info->pbTag, auth_info->cbTag );
|
return key_funcs->key_symmetric_get_tag( key, auth_info->pbTag, auth_info->cbTag );
|
||||||
}
|
}
|
||||||
|
|
||||||
*ret_len = input_len;
|
*ret_len = input_len;
|
||||||
|
@ -1087,9 +1091,10 @@ static NTSTATUS key_encrypt( struct key *key, UCHAR *input, ULONG input_len, vo
|
||||||
dst = output;
|
dst = output;
|
||||||
while (bytes_left >= key->u.s.block_size)
|
while (bytes_left >= key->u.s.block_size)
|
||||||
{
|
{
|
||||||
if ((status = key_symmetric_encrypt( key, src, key->u.s.block_size, dst, key->u.s.block_size )))
|
if ((status = key_funcs->key_symmetric_encrypt( key, src, key->u.s.block_size, dst, key->u.s.block_size )))
|
||||||
|
return status;
|
||||||
|
if (key->u.s.mode == MODE_ID_ECB && (status = key_symmetric_set_vector( key, NULL, 0 )))
|
||||||
return status;
|
return status;
|
||||||
if (key->u.s.mode == MODE_ID_ECB && (status = key_symmetric_set_vector( key, NULL, 0 ))) return status;
|
|
||||||
bytes_left -= key->u.s.block_size;
|
bytes_left -= key->u.s.block_size;
|
||||||
src += key->u.s.block_size;
|
src += key->u.s.block_size;
|
||||||
dst += key->u.s.block_size;
|
dst += key->u.s.block_size;
|
||||||
|
@ -1100,7 +1105,7 @@ static NTSTATUS key_encrypt( struct key *key, UCHAR *input, ULONG input_len, vo
|
||||||
if (!(buf = heap_alloc( key->u.s.block_size ))) return STATUS_NO_MEMORY;
|
if (!(buf = heap_alloc( key->u.s.block_size ))) return STATUS_NO_MEMORY;
|
||||||
memcpy( buf, src, bytes_left );
|
memcpy( buf, src, bytes_left );
|
||||||
memset( buf + bytes_left, key->u.s.block_size - bytes_left, key->u.s.block_size - bytes_left );
|
memset( buf + bytes_left, key->u.s.block_size - bytes_left, key->u.s.block_size - bytes_left );
|
||||||
status = key_symmetric_encrypt( key, buf, key->u.s.block_size, dst, key->u.s.block_size );
|
status = key_funcs->key_symmetric_encrypt( key, buf, key->u.s.block_size, dst, key->u.s.block_size );
|
||||||
heap_free( buf );
|
heap_free( buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1132,11 +1137,11 @@ static NTSTATUS key_decrypt( struct key *key, UCHAR *input, ULONG input_len, voi
|
||||||
if (!output) return STATUS_SUCCESS;
|
if (!output) return STATUS_SUCCESS;
|
||||||
if (output_len < *ret_len) return STATUS_BUFFER_TOO_SMALL;
|
if (output_len < *ret_len) return STATUS_BUFFER_TOO_SMALL;
|
||||||
|
|
||||||
if ((status = key_symmetric_set_auth_data( key, auth_info->pbAuthData, auth_info->cbAuthData )))
|
if ((status = key_funcs->key_symmetric_set_auth_data( key, auth_info->pbAuthData, auth_info->cbAuthData )))
|
||||||
return status;
|
return status;
|
||||||
if ((status = key_symmetric_decrypt( key, input, input_len, output, output_len ))) return status;
|
if ((status = key_funcs->key_symmetric_decrypt( key, input, input_len, output, output_len ))) return status;
|
||||||
|
|
||||||
if ((status = key_symmetric_get_tag( key, tag, sizeof(tag) ))) return status;
|
if ((status = key_funcs->key_symmetric_get_tag( key, tag, sizeof(tag) ))) return status;
|
||||||
if (memcmp( tag, auth_info->pbTag, auth_info->cbTag )) return STATUS_AUTH_TAG_MISMATCH;
|
if (memcmp( tag, auth_info->pbTag, auth_info->cbTag )) return STATUS_AUTH_TAG_MISMATCH;
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
|
@ -1161,9 +1166,10 @@ static NTSTATUS key_decrypt( struct key *key, UCHAR *input, ULONG input_len, voi
|
||||||
dst = output;
|
dst = output;
|
||||||
while (bytes_left >= key->u.s.block_size)
|
while (bytes_left >= key->u.s.block_size)
|
||||||
{
|
{
|
||||||
if ((status = key_symmetric_decrypt( key, src, key->u.s.block_size, dst, key->u.s.block_size )))
|
if ((status = key_funcs->key_symmetric_decrypt( key, src, key->u.s.block_size, dst, key->u.s.block_size )))
|
||||||
|
return status;
|
||||||
|
if (key->u.s.mode == MODE_ID_ECB && (status = key_symmetric_set_vector( key, NULL, 0 )))
|
||||||
return status;
|
return status;
|
||||||
if (key->u.s.mode == MODE_ID_ECB && (status = key_symmetric_set_vector( key, NULL, 0 ))) return status;
|
|
||||||
bytes_left -= key->u.s.block_size;
|
bytes_left -= key->u.s.block_size;
|
||||||
src += key->u.s.block_size;
|
src += key->u.s.block_size;
|
||||||
dst += key->u.s.block_size;
|
dst += key->u.s.block_size;
|
||||||
|
@ -1172,7 +1178,7 @@ static NTSTATUS key_decrypt( struct key *key, UCHAR *input, ULONG input_len, voi
|
||||||
if (flags & BCRYPT_BLOCK_PADDING)
|
if (flags & BCRYPT_BLOCK_PADDING)
|
||||||
{
|
{
|
||||||
if (!(buf = heap_alloc( key->u.s.block_size ))) return STATUS_NO_MEMORY;
|
if (!(buf = heap_alloc( key->u.s.block_size ))) return STATUS_NO_MEMORY;
|
||||||
status = key_symmetric_decrypt( key, src, key->u.s.block_size, buf, key->u.s.block_size );
|
status = key_funcs->key_symmetric_decrypt( key, src, key->u.s.block_size, buf, key->u.s.block_size );
|
||||||
if (!status && buf[ key->u.s.block_size - 1 ] <= key->u.s.block_size)
|
if (!status && buf[ key->u.s.block_size - 1 ] <= key->u.s.block_size)
|
||||||
{
|
{
|
||||||
*ret_len -= buf[ key->u.s.block_size - 1 ];
|
*ret_len -= buf[ key->u.s.block_size - 1 ];
|
||||||
|
@ -1256,7 +1262,7 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP
|
||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
if ((status = key_asymmetric_create( &key, alg, key_size * 8, NULL, 0 ))) return status;
|
if ((status = key_asymmetric_create( &key, alg, key_size * 8, NULL, 0 ))) return status;
|
||||||
if ((status = key_import_ecc( key, input, input_len )))
|
if ((status = key_funcs->key_import_ecc( key, input, input_len )))
|
||||||
{
|
{
|
||||||
BCryptDestroyKey( key );
|
BCryptDestroyKey( key );
|
||||||
return status;
|
return status;
|
||||||
|
@ -1315,7 +1321,7 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP
|
||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
if ((status = key_asymmetric_create( &key, alg, pubkey->bitlen, NULL, 0 ))) return status;
|
if ((status = key_asymmetric_create( &key, alg, pubkey->bitlen, NULL, 0 ))) return status;
|
||||||
if ((status = key_import_dsa_capi( key, input, input_len )))
|
if ((status = key_funcs->key_import_dsa_capi( key, input, input_len )))
|
||||||
{
|
{
|
||||||
BCryptDestroyKey( key );
|
BCryptDestroyKey( key );
|
||||||
return status;
|
return status;
|
||||||
|
@ -1328,107 +1334,6 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP
|
||||||
FIXME( "unsupported key type %s\n", debugstr_w(type) );
|
FIXME( "unsupported key type %s\n", debugstr_w(type) );
|
||||||
return STATUS_NOT_SUPPORTED;
|
return STATUS_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
NTSTATUS key_symmetric_init( struct key *key )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS key_set_property( struct key *key, const WCHAR *prop, UCHAR *value, ULONG size, ULONG flags )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
static NTSTATUS key_duplicate( struct key *key_orig, struct key *key_copy )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_init( struct key *key )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_generate( struct key *key )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_sign( struct key *key, void *padding, UCHAR *input, ULONG input_len, UCHAR *output,
|
|
||||||
ULONG output_len, ULONG *ret_len, ULONG flags )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_verify( struct key *key, void *padding, UCHAR *hash, ULONG hash_len, UCHAR *signature,
|
|
||||||
ULONG signature_len, DWORD flags )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
static NTSTATUS key_import( BCRYPT_ALG_HANDLE algorithm, const WCHAR *type, BCRYPT_KEY_HANDLE *key, UCHAR *object,
|
|
||||||
ULONG object_len, UCHAR *input, ULONG input_len )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
static NTSTATUS key_export( struct key *key, const WCHAR *type, UCHAR *output, ULONG output_len, ULONG *size )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
void key_symmetric_destroy( struct key *key )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
void key_asymmetric_destroy( struct key *key )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
static NTSTATUS key_encrypt( struct key *key, UCHAR *input, ULONG input_len, void *padding, UCHAR *iv,
|
|
||||||
ULONG iv_len, UCHAR *output, ULONG output_len, ULONG *ret_len, ULONG flags )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
static NTSTATUS key_decrypt( struct key *key, UCHAR *input, ULONG input_len, void *padding, UCHAR *iv,
|
|
||||||
ULONG iv_len, UCHAR *output, ULONG output_len, ULONG *ret_len, ULONG flags )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYPT_KEY_HANDLE *ret_key, UCHAR *input,
|
|
||||||
ULONG input_len )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS key_export_ecc( struct key *key, UCHAR *output, ULONG len, ULONG *ret_len )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS key_import_ecc( struct key *key, UCHAR *input, ULONG len )
|
|
||||||
{
|
|
||||||
ERR( "support for keys not available at build time\n" );
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static ULONG get_block_size( struct algorithm *alg )
|
static ULONG get_block_size( struct algorithm *alg )
|
||||||
{
|
{
|
||||||
|
@ -1451,6 +1356,12 @@ NTSTATUS WINAPI BCryptGenerateSymmetricKey( BCRYPT_ALG_HANDLE algorithm, BCRYPT_
|
||||||
if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE;
|
if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE;
|
||||||
if (object) FIXME( "ignoring object buffer\n" );
|
if (object) FIXME( "ignoring object buffer\n" );
|
||||||
|
|
||||||
|
if (!key_funcs)
|
||||||
|
{
|
||||||
|
ERR( "no encryption support\n" );
|
||||||
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(block_size = get_block_size( alg ))) return STATUS_INVALID_PARAMETER;
|
if (!(block_size = get_block_size( alg ))) return STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
if (!(key = heap_alloc_zero( sizeof(*key) ))) return STATUS_NO_MEMORY;
|
if (!(key = heap_alloc_zero( sizeof(*key) ))) return STATUS_NO_MEMORY;
|
||||||
|
@ -1467,7 +1378,7 @@ NTSTATUS WINAPI BCryptGenerateSymmetricKey( BCRYPT_ALG_HANDLE algorithm, BCRYPT_
|
||||||
memcpy( key->u.s.secret, secret, secret_len );
|
memcpy( key->u.s.secret, secret, secret_len );
|
||||||
key->u.s.secret_len = secret_len;
|
key->u.s.secret_len = secret_len;
|
||||||
|
|
||||||
if ((status = key_symmetric_init( key )))
|
if ((status = key_funcs->key_symmetric_init( key )))
|
||||||
{
|
{
|
||||||
heap_free( key->u.s.secret );
|
heap_free( key->u.s.secret );
|
||||||
heap_free( key );
|
heap_free( key );
|
||||||
|
@ -1501,7 +1412,7 @@ NTSTATUS WINAPI BCryptFinalizeKeyPair( BCRYPT_KEY_HANDLE handle, ULONG flags )
|
||||||
TRACE( "%p, %08x\n", key, flags );
|
TRACE( "%p, %08x\n", key, flags );
|
||||||
if (!key || key->hdr.magic != MAGIC_KEY) return STATUS_INVALID_HANDLE;
|
if (!key || key->hdr.magic != MAGIC_KEY) return STATUS_INVALID_HANDLE;
|
||||||
|
|
||||||
return key_asymmetric_generate( key );
|
return key_funcs->key_asymmetric_generate( key );
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS WINAPI BCryptImportKey( BCRYPT_ALG_HANDLE algorithm, BCRYPT_KEY_HANDLE decrypt_key, LPCWSTR type,
|
NTSTATUS WINAPI BCryptImportKey( BCRYPT_ALG_HANDLE algorithm, BCRYPT_KEY_HANDLE decrypt_key, LPCWSTR type,
|
||||||
|
@ -1602,7 +1513,7 @@ NTSTATUS WINAPI BCryptSignHash( BCRYPT_KEY_HANDLE handle, void *padding, UCHAR *
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return key_asymmetric_sign( key, padding, input, input_len, output, output_len, ret_len, flags );
|
return key_funcs->key_asymmetric_sign( key, padding, input, input_len, output, output_len, ret_len, flags );
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS WINAPI BCryptVerifySignature( BCRYPT_KEY_HANDLE handle, void *padding, UCHAR *hash, ULONG hash_len,
|
NTSTATUS WINAPI BCryptVerifySignature( BCRYPT_KEY_HANDLE handle, void *padding, UCHAR *hash, ULONG hash_len,
|
||||||
|
@ -1616,7 +1527,7 @@ NTSTATUS WINAPI BCryptVerifySignature( BCRYPT_KEY_HANDLE handle, void *padding,
|
||||||
if (!hash || !hash_len || !signature || !signature_len) return STATUS_INVALID_PARAMETER;
|
if (!hash || !hash_len || !signature || !signature_len) return STATUS_INVALID_PARAMETER;
|
||||||
if (key_is_symmetric( key )) return STATUS_NOT_SUPPORTED;
|
if (key_is_symmetric( key )) return STATUS_NOT_SUPPORTED;
|
||||||
|
|
||||||
return key_asymmetric_verify( key, padding, hash, hash_len, signature, signature_len, flags );
|
return key_funcs->key_asymmetric_verify( key, padding, hash, hash_len, signature, signature_len, flags );
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS WINAPI BCryptDestroyKey( BCRYPT_KEY_HANDLE handle )
|
NTSTATUS WINAPI BCryptDestroyKey( BCRYPT_KEY_HANDLE handle )
|
||||||
|
@ -1628,13 +1539,13 @@ NTSTATUS WINAPI BCryptDestroyKey( BCRYPT_KEY_HANDLE handle )
|
||||||
if (!key || key->hdr.magic != MAGIC_KEY) return STATUS_INVALID_HANDLE;
|
if (!key || key->hdr.magic != MAGIC_KEY) return STATUS_INVALID_HANDLE;
|
||||||
if (key_is_symmetric( key ))
|
if (key_is_symmetric( key ))
|
||||||
{
|
{
|
||||||
key_symmetric_destroy( key );
|
key_funcs->key_symmetric_destroy( key );
|
||||||
heap_free( key->u.s.vector );
|
heap_free( key->u.s.vector );
|
||||||
heap_free( key->u.s.secret );
|
heap_free( key->u.s.secret );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
key_asymmetric_destroy( key );
|
key_funcs->key_asymmetric_destroy( key );
|
||||||
heap_free( key->u.a.pubkey );
|
heap_free( key->u.a.pubkey );
|
||||||
}
|
}
|
||||||
key->hdr.magic = 0;
|
key->hdr.magic = 0;
|
||||||
|
@ -1706,7 +1617,7 @@ NTSTATUS WINAPI BCryptSetProperty( BCRYPT_HANDLE handle, const WCHAR *prop, UCHA
|
||||||
case MAGIC_KEY:
|
case MAGIC_KEY:
|
||||||
{
|
{
|
||||||
struct key *key = (struct key *)object;
|
struct key *key = (struct key *)object;
|
||||||
return key_set_property( key, prop, value, size, flags );
|
return key_funcs->key_set_property( key, prop, value, size, flags );
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
WARN( "unknown magic %08x\n", object->magic );
|
WARN( "unknown magic %08x\n", object->magic );
|
||||||
|
@ -1916,16 +1827,11 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
instance = hinst;
|
instance = hinst;
|
||||||
DisableThreadLibraryCalls( hinst );
|
DisableThreadLibraryCalls( hinst );
|
||||||
#ifdef HAVE_GNUTLS_CIPHER_INIT
|
__wine_init_unix_lib( hinst, reason, NULL, &key_funcs );
|
||||||
gnutls_initialize();
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
if (reserved) break;
|
if (reserved) break;
|
||||||
#ifdef HAVE_GNUTLS_CIPHER_INIT
|
__wine_init_unix_lib( hinst, reason, NULL, NULL );
|
||||||
gnutls_uninitialize();
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -18,20 +18,25 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#pragma makedep unix
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "wine/port.h"
|
#include "wine/port.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#ifdef HAVE_GNUTLS_CIPHER_INIT
|
#ifdef HAVE_GNUTLS_CIPHER_INIT
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <gnutls/gnutls.h>
|
#include <gnutls/gnutls.h>
|
||||||
#include <gnutls/crypto.h>
|
#include <gnutls/crypto.h>
|
||||||
#include <gnutls/abstract.h>
|
#include <gnutls/abstract.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "ntstatus.h"
|
#include "ntstatus.h"
|
||||||
#define WIN32_NO_STATUS
|
#define WIN32_NO_STATUS
|
||||||
#include "windef.h"
|
#include "windef.h"
|
||||||
#include "winbase.h"
|
#include "winbase.h"
|
||||||
|
#include "winternl.h"
|
||||||
#include "ntsecapi.h"
|
#include "ntsecapi.h"
|
||||||
#include "wincrypt.h"
|
#include "wincrypt.h"
|
||||||
#include "bcrypt.h"
|
#include "bcrypt.h"
|
||||||
|
@ -39,10 +44,8 @@
|
||||||
#include "bcrypt_internal.h"
|
#include "bcrypt_internal.h"
|
||||||
|
|
||||||
#include "wine/debug.h"
|
#include "wine/debug.h"
|
||||||
#include "wine/heap.h"
|
|
||||||
#include "wine/unicode.h"
|
#include "wine/unicode.h"
|
||||||
|
|
||||||
#ifdef HAVE_GNUTLS_CIPHER_INIT
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(bcrypt);
|
WINE_DEFAULT_DEBUG_CHANNEL(bcrypt);
|
||||||
WINE_DECLARE_DEBUG_CHANNEL(winediag);
|
WINE_DECLARE_DEBUG_CHANNEL(winediag);
|
||||||
|
|
||||||
|
@ -207,7 +210,7 @@ static void gnutls_log( int level, const char *msg )
|
||||||
TRACE( "<%d> %s", level, msg );
|
TRACE( "<%d> %s", level, msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL gnutls_initialize(void)
|
static BOOL gnutls_initialize(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -327,7 +330,7 @@ fail:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnutls_uninitialize(void)
|
static void gnutls_uninitialize(void)
|
||||||
{
|
{
|
||||||
pgnutls_global_deinit();
|
pgnutls_global_deinit();
|
||||||
dlclose( libgnutls_handle );
|
dlclose( libgnutls_handle );
|
||||||
|
@ -352,7 +355,7 @@ static void buffer_init( struct buffer *buffer )
|
||||||
|
|
||||||
static void buffer_free( struct buffer *buffer )
|
static void buffer_free( struct buffer *buffer )
|
||||||
{
|
{
|
||||||
heap_free( buffer->buffer );
|
free( buffer->buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buffer_append( struct buffer *buffer, BYTE *data, DWORD len )
|
static void buffer_append( struct buffer *buffer, BYTE *data, DWORD len )
|
||||||
|
@ -364,7 +367,7 @@ static void buffer_append( struct buffer *buffer, BYTE *data, DWORD len )
|
||||||
DWORD new_length = max( max( buffer->pos + len, buffer->length * 2 ), 64 );
|
DWORD new_length = max( max( buffer->pos + len, buffer->length * 2 ), 64 );
|
||||||
BYTE *new_buffer;
|
BYTE *new_buffer;
|
||||||
|
|
||||||
if (!(new_buffer = heap_realloc( buffer->buffer, new_length )))
|
if (!(new_buffer = realloc( buffer->buffer, new_length )))
|
||||||
{
|
{
|
||||||
ERR( "out of memory\n" );
|
ERR( "out of memory\n" );
|
||||||
buffer->error = TRUE;
|
buffer->error = TRUE;
|
||||||
|
@ -437,7 +440,7 @@ static void buffer_append_asn1_r_s( struct buffer *buffer, BYTE *r, DWORD r_len,
|
||||||
buffer_free( &value );
|
buffer_free( &value );
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_set_property( struct key *key, const WCHAR *prop, UCHAR *value, ULONG size, ULONG flags )
|
static NTSTATUS CDECL key_set_property( struct key *key, const WCHAR *prop, UCHAR *value, ULONG size, ULONG flags )
|
||||||
{
|
{
|
||||||
if (!strcmpW( prop, BCRYPT_CHAINING_MODE ))
|
if (!strcmpW( prop, BCRYPT_CHAINING_MODE ))
|
||||||
{
|
{
|
||||||
|
@ -467,7 +470,7 @@ NTSTATUS key_set_property( struct key *key, const WCHAR *prop, UCHAR *value, ULO
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_symmetric_init( struct key *key )
|
static NTSTATUS CDECL key_symmetric_init( struct key *key )
|
||||||
{
|
{
|
||||||
if (!libgnutls_handle) return STATUS_INTERNAL_ERROR;
|
if (!libgnutls_handle) return STATUS_INTERNAL_ERROR;
|
||||||
|
|
||||||
|
@ -512,7 +515,7 @@ static gnutls_cipher_algorithm_t get_gnutls_cipher( const struct key *key )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_symmetric_vector_reset( struct key *key )
|
static void CDECL key_symmetric_vector_reset( struct key *key )
|
||||||
{
|
{
|
||||||
if (!key_data(key)->cipher) return;
|
if (!key_data(key)->cipher) return;
|
||||||
TRACE( "invalidating cipher handle\n" );
|
TRACE( "invalidating cipher handle\n" );
|
||||||
|
@ -544,7 +547,7 @@ static NTSTATUS init_cipher_handle( struct key *key )
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_symmetric_set_auth_data( struct key *key, UCHAR *auth_data, ULONG len )
|
static NTSTATUS CDECL key_symmetric_set_auth_data( struct key *key, UCHAR *auth_data, ULONG len )
|
||||||
{
|
{
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -560,7 +563,7 @@ NTSTATUS key_symmetric_set_auth_data( struct key *key, UCHAR *auth_data, ULONG l
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_symmetric_encrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output, ULONG output_len )
|
static NTSTATUS CDECL key_symmetric_encrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output, ULONG output_len )
|
||||||
{
|
{
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -575,7 +578,7 @@ NTSTATUS key_symmetric_encrypt( struct key *key, const UCHAR *input, ULONG input
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_symmetric_decrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output, ULONG output_len )
|
static NTSTATUS CDECL key_symmetric_decrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output, ULONG output_len )
|
||||||
{
|
{
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -590,7 +593,7 @@ NTSTATUS key_symmetric_decrypt( struct key *key, const UCHAR *input, ULONG input
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_symmetric_get_tag( struct key *key, UCHAR *tag, ULONG len )
|
static NTSTATUS CDECL key_symmetric_get_tag( struct key *key, UCHAR *tag, ULONG len )
|
||||||
{
|
{
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -605,7 +608,7 @@ NTSTATUS key_symmetric_get_tag( struct key *key, UCHAR *tag, ULONG len )
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_symmetric_destroy( struct key *key )
|
static void CDECL key_symmetric_destroy( struct key *key )
|
||||||
{
|
{
|
||||||
if (key_data(key)->cipher) pgnutls_cipher_deinit( key_data(key)->cipher );
|
if (key_data(key)->cipher) pgnutls_cipher_deinit( key_data(key)->cipher );
|
||||||
}
|
}
|
||||||
|
@ -623,7 +626,7 @@ static NTSTATUS export_gnutls_pubkey_rsa( gnutls_privkey_t gnutls_key, ULONG bit
|
||||||
return STATUS_INTERNAL_ERROR;
|
return STATUS_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(rsa_blob = heap_alloc( sizeof(*rsa_blob) + e.size + m.size )))
|
if (!(rsa_blob = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*rsa_blob) + e.size + m.size )))
|
||||||
{
|
{
|
||||||
pgnutls_perror( ret );
|
pgnutls_perror( ret );
|
||||||
free( e.data ); free( m.data );
|
free( e.data ); free( m.data );
|
||||||
|
@ -700,7 +703,7 @@ static NTSTATUS export_gnutls_pubkey_ecc( gnutls_privkey_t gnutls_key, enum alg_
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ecc_blob = heap_alloc( sizeof(*ecc_blob) + x.size + y.size )))
|
if (!(ecc_blob = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*ecc_blob) + x.size + y.size )))
|
||||||
{
|
{
|
||||||
pgnutls_perror( ret );
|
pgnutls_perror( ret );
|
||||||
free( x.data ); free( y.data );
|
free( x.data ); free( y.data );
|
||||||
|
@ -746,7 +749,7 @@ static NTSTATUS export_gnutls_pubkey_dsa( gnutls_privkey_t gnutls_key, ULONG bit
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(dsa_blob = heap_alloc( sizeof(*dsa_blob) + p.size + g.size + y.size )))
|
if (!(dsa_blob = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*dsa_blob) + p.size + g.size + y.size )))
|
||||||
{
|
{
|
||||||
pgnutls_perror( ret );
|
pgnutls_perror( ret );
|
||||||
free( p.data ); free( q.data ); free( g.data ); free( y.data );
|
free( p.data ); free( q.data ); free( g.data ); free( y.data );
|
||||||
|
@ -801,7 +804,7 @@ static NTSTATUS export_gnutls_pubkey_dsa( gnutls_privkey_t gnutls_key, ULONG bit
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_generate( struct key *key )
|
static NTSTATUS CDECL key_asymmetric_generate( struct key *key )
|
||||||
{
|
{
|
||||||
gnutls_pk_algorithm_t pk_alg;
|
gnutls_pk_algorithm_t pk_alg;
|
||||||
gnutls_privkey_t handle;
|
gnutls_privkey_t handle;
|
||||||
|
@ -877,7 +880,7 @@ NTSTATUS key_asymmetric_generate( struct key *key )
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_export_ecc( struct key *key, UCHAR *buf, ULONG len, ULONG *ret_len )
|
static NTSTATUS CDECL key_export_ecc( struct key *key, UCHAR *buf, ULONG len, ULONG *ret_len )
|
||||||
{
|
{
|
||||||
BCRYPT_ECCKEY_BLOB *ecc_blob;
|
BCRYPT_ECCKEY_BLOB *ecc_blob;
|
||||||
gnutls_ecc_curve_t curve;
|
gnutls_ecc_curve_t curve;
|
||||||
|
@ -942,7 +945,7 @@ NTSTATUS key_export_ecc( struct key *key, UCHAR *buf, ULONG len, ULONG *ret_len
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_import_ecc( struct key *key, UCHAR *buf, ULONG len )
|
static NTSTATUS CDECL key_import_ecc( struct key *key, UCHAR *buf, ULONG len )
|
||||||
{
|
{
|
||||||
BCRYPT_ECCKEY_BLOB *ecc_blob;
|
BCRYPT_ECCKEY_BLOB *ecc_blob;
|
||||||
gnutls_ecc_curve_t curve;
|
gnutls_ecc_curve_t curve;
|
||||||
|
@ -994,7 +997,7 @@ NTSTATUS key_import_ecc( struct key *key, UCHAR *buf, ULONG len )
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_export_dsa_capi( struct key *key, UCHAR *buf, ULONG len, ULONG *ret_len )
|
static NTSTATUS CDECL key_export_dsa_capi( struct key *key, UCHAR *buf, ULONG len, ULONG *ret_len )
|
||||||
{
|
{
|
||||||
BLOBHEADER *hdr;
|
BLOBHEADER *hdr;
|
||||||
DSSPUBKEY *pubkey;
|
DSSPUBKEY *pubkey;
|
||||||
|
@ -1057,7 +1060,7 @@ NTSTATUS key_export_dsa_capi( struct key *key, UCHAR *buf, ULONG len, ULONG *ret
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_import_dsa_capi( struct key *key, UCHAR *buf, ULONG len )
|
static NTSTATUS CDECL key_import_dsa_capi( struct key *key, UCHAR *buf, ULONG len )
|
||||||
{
|
{
|
||||||
BLOBHEADER *hdr = (BLOBHEADER *)buf;
|
BLOBHEADER *hdr = (BLOBHEADER *)buf;
|
||||||
DSSPUBKEY *pubkey;
|
DSSPUBKEY *pubkey;
|
||||||
|
@ -1103,7 +1106,7 @@ NTSTATUS key_import_dsa_capi( struct key *key, UCHAR *buf, ULONG len )
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_init( struct key *key )
|
static NTSTATUS CDECL key_asymmetric_init( struct key *key )
|
||||||
{
|
{
|
||||||
if (!libgnutls_handle) return STATUS_INTERNAL_ERROR;
|
if (!libgnutls_handle) return STATUS_INTERNAL_ERROR;
|
||||||
|
|
||||||
|
@ -1304,8 +1307,8 @@ static gnutls_digest_algorithm_t get_digest_from_id( const WCHAR *alg_id )
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_verify( struct key *key, void *padding, UCHAR *hash, ULONG hash_len, UCHAR *signature,
|
static NTSTATUS CDECL key_asymmetric_verify( struct key *key, void *padding, UCHAR *hash, ULONG hash_len,
|
||||||
ULONG signature_len, DWORD flags )
|
UCHAR *signature, ULONG signature_len, DWORD flags )
|
||||||
{
|
{
|
||||||
gnutls_digest_algorithm_t hash_alg;
|
gnutls_digest_algorithm_t hash_alg;
|
||||||
gnutls_sign_algorithm_t sign_alg;
|
gnutls_sign_algorithm_t sign_alg;
|
||||||
|
@ -1386,7 +1389,7 @@ NTSTATUS key_asymmetric_verify( struct key *key, void *padding, UCHAR *hash, ULO
|
||||||
gnutls_hash.size = hash_len;
|
gnutls_hash.size = hash_len;
|
||||||
ret = pgnutls_pubkey_verify_hash2( gnutls_key, sign_alg, 0, &gnutls_hash, &gnutls_signature );
|
ret = pgnutls_pubkey_verify_hash2( gnutls_key, sign_alg, 0, &gnutls_hash, &gnutls_signature );
|
||||||
|
|
||||||
if (gnutls_signature.data != signature) heap_free( gnutls_signature.data );
|
if (gnutls_signature.data != signature) free( gnutls_signature.data );
|
||||||
pgnutls_pubkey_deinit( gnutls_key );
|
pgnutls_pubkey_deinit( gnutls_key );
|
||||||
return (ret < 0) ? STATUS_INVALID_SIGNATURE : STATUS_SUCCESS;
|
return (ret < 0) ? STATUS_INVALID_SIGNATURE : STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1470,7 +1473,7 @@ static NTSTATUS format_gnutls_signature( enum alg_id type, gnutls_datum_t signat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_sign( struct key *key, void *padding, UCHAR *input, ULONG input_len, UCHAR *output,
|
static NTSTATUS CDECL key_asymmetric_sign( struct key *key, void *padding, UCHAR *input, ULONG input_len, UCHAR *output,
|
||||||
ULONG output_len, ULONG *ret_len, ULONG flags )
|
ULONG output_len, ULONG *ret_len, ULONG flags )
|
||||||
{
|
{
|
||||||
BCRYPT_PKCS1_PADDING_INFO *pad = padding;
|
BCRYPT_PKCS1_PADDING_INFO *pad = padding;
|
||||||
|
@ -1560,8 +1563,45 @@ NTSTATUS key_asymmetric_sign( struct key *key, void *padding, UCHAR *input, ULON
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_asymmetric_destroy( struct key *key )
|
static void CDECL key_asymmetric_destroy( struct key *key )
|
||||||
{
|
{
|
||||||
if (key_data(key)->privkey) pgnutls_privkey_deinit( key_data(key)->privkey );
|
if (key_data(key)->privkey) pgnutls_privkey_deinit( key_data(key)->privkey );
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
static const struct key_funcs key_funcs =
|
||||||
|
{
|
||||||
|
key_set_property,
|
||||||
|
key_symmetric_init,
|
||||||
|
key_symmetric_vector_reset,
|
||||||
|
key_symmetric_set_auth_data,
|
||||||
|
key_symmetric_encrypt,
|
||||||
|
key_symmetric_decrypt,
|
||||||
|
key_symmetric_get_tag,
|
||||||
|
key_symmetric_destroy,
|
||||||
|
key_asymmetric_init,
|
||||||
|
key_asymmetric_generate,
|
||||||
|
key_asymmetric_sign,
|
||||||
|
key_asymmetric_verify,
|
||||||
|
key_asymmetric_destroy,
|
||||||
|
key_export_dsa_capi,
|
||||||
|
key_export_ecc,
|
||||||
|
key_import_dsa_capi,
|
||||||
|
key_import_ecc
|
||||||
|
};
|
||||||
|
|
||||||
|
NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
|
||||||
|
{
|
||||||
|
switch (reason)
|
||||||
|
{
|
||||||
|
case DLL_PROCESS_ATTACH:
|
||||||
|
if (!gnutls_initialize()) return STATUS_DLL_NOT_FOUND;
|
||||||
|
*(const struct key_funcs **)ptr_out = &key_funcs;
|
||||||
|
break;
|
||||||
|
case DLL_PROCESS_DETACH:
|
||||||
|
gnutls_uninitialize();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_GNUTLS_CIPHER_INIT */
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#pragma makedep unix
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "wine/port.h"
|
#include "wine/port.h"
|
||||||
|
|
||||||
|
@ -37,7 +41,6 @@
|
||||||
#include "bcrypt_internal.h"
|
#include "bcrypt_internal.h"
|
||||||
|
|
||||||
#include "wine/debug.h"
|
#include "wine/debug.h"
|
||||||
#include "wine/heap.h"
|
|
||||||
#include "wine/unicode.h"
|
#include "wine/unicode.h"
|
||||||
|
|
||||||
#if defined(HAVE_COMMONCRYPTO_COMMONCRYPTOR_H) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 && !defined(HAVE_GNUTLS_CIPHER_INIT)
|
#if defined(HAVE_COMMONCRYPTO_COMMONCRYPTOR_H) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 && !defined(HAVE_GNUTLS_CIPHER_INIT)
|
||||||
|
@ -55,7 +58,7 @@ static struct key_data *key_data( struct key *key )
|
||||||
return (struct key_data *)key->private;
|
return (struct key_data *)key->private;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_set_property( struct key *key, const WCHAR *prop, UCHAR *value, ULONG size, ULONG flags )
|
static NTSTATUS CDECL key_set_property( struct key *key, const WCHAR *prop, UCHAR *value, ULONG size, ULONG flags )
|
||||||
{
|
{
|
||||||
if (!strcmpW( prop, BCRYPT_CHAINING_MODE ))
|
if (!strcmpW( prop, BCRYPT_CHAINING_MODE ))
|
||||||
{
|
{
|
||||||
|
@ -80,7 +83,7 @@ NTSTATUS key_set_property( struct key *key, const WCHAR *prop, UCHAR *value, ULO
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_symmetric_init( struct key *key )
|
static NTSTATUS CDECL key_symmetric_init( struct key *key )
|
||||||
{
|
{
|
||||||
switch (key->alg_id)
|
switch (key->alg_id)
|
||||||
{
|
{
|
||||||
|
@ -114,7 +117,7 @@ static CCMode get_cryptor_mode( struct key *key )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_symmetric_vector_reset( struct key *key )
|
static void CDECL key_symmetric_vector_reset( struct key *key )
|
||||||
{
|
{
|
||||||
if (!key_data(key)->ref_encrypt) return;
|
if (!key_data(key)->ref_encrypt) return;
|
||||||
|
|
||||||
|
@ -154,13 +157,13 @@ static NTSTATUS init_cryptor_handles( struct key *key )
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_symmetric_set_auth_data( struct key *key, UCHAR *auth_data, ULONG len )
|
static NTSTATUS CDECL key_symmetric_set_auth_data( struct key *key, UCHAR *auth_data, ULONG len )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
FIXME( "not implemented on Mac\n" );
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_symmetric_encrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output, ULONG output_len )
|
static NTSTATUS CDECL key_symmetric_encrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output, ULONG output_len )
|
||||||
{
|
{
|
||||||
CCCryptorStatus status;
|
CCCryptorStatus status;
|
||||||
NTSTATUS ret;
|
NTSTATUS ret;
|
||||||
|
@ -175,7 +178,7 @@ NTSTATUS key_symmetric_encrypt( struct key *key, const UCHAR *input, ULONG input
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_symmetric_decrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output, ULONG output_len )
|
static NTSTATUS CDECL key_symmetric_decrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output, ULONG output_len )
|
||||||
{
|
{
|
||||||
CCCryptorStatus status;
|
CCCryptorStatus status;
|
||||||
NTSTATUS ret;
|
NTSTATUS ret;
|
||||||
|
@ -190,70 +193,98 @@ NTSTATUS key_symmetric_decrypt( struct key *key, const UCHAR *input, ULONG input
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_symmetric_get_tag( struct key *key, UCHAR *tag, ULONG len )
|
static NTSTATUS CDECL key_symmetric_get_tag( struct key *key, UCHAR *tag, ULONG len )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
FIXME( "not implemented on Mac\n" );
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_symmetric_destroy( struct key *key )
|
static void CDECL key_symmetric_destroy( struct key *key )
|
||||||
{
|
{
|
||||||
if (key_data(key)->ref_encrypt) CCCryptorRelease( key_data(key)->ref_encrypt );
|
if (key_data(key)->ref_encrypt) CCCryptorRelease( key_data(key)->ref_encrypt );
|
||||||
if (key_data(key)->ref_decrypt) CCCryptorRelease( key_data(key)->ref_decrypt );
|
if (key_data(key)->ref_decrypt) CCCryptorRelease( key_data(key)->ref_decrypt );
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_init( struct key *key )
|
static NTSTATUS CDECL key_asymmetric_init( struct key *key )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
FIXME( "not implemented on Mac\n" );
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_sign( struct key *key, void *padding, UCHAR *input, ULONG input_len, UCHAR *output,
|
static NTSTATUS CDECL key_asymmetric_sign( struct key *key, void *padding, UCHAR *input, ULONG input_len, UCHAR *output,
|
||||||
ULONG output_len, ULONG *ret_len, ULONG flags )
|
ULONG output_len, ULONG *ret_len, ULONG flags )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
FIXME( "not implemented on Mac\n" );
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_verify( struct key *key, void *padding, UCHAR *hash, ULONG hash_len, UCHAR *signature,
|
static NTSTATUS CDECL key_asymmetric_verify( struct key *key, void *padding, UCHAR *hash, ULONG hash_len,
|
||||||
ULONG signature_len, DWORD flags )
|
UCHAR *signature, ULONG signature_len, DWORD flags )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
FIXME( "not implemented on Mac\n" );
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_export_dsa_capi( struct key *key, UCHAR *buf, ULONG len, ULONG *ret_len )
|
static NTSTATUS CDECL key_export_dsa_capi( struct key *key, UCHAR *buf, ULONG len, ULONG *ret_len )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
FIXME( "not implemented on Mac\n" );
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_export_ecc( struct key *key, UCHAR *output, ULONG len, ULONG *ret_len )
|
static NTSTATUS CDECL key_export_ecc( struct key *key, UCHAR *output, ULONG len, ULONG *ret_len )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
FIXME( "not implemented on Mac\n" );
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_import_dsa_capi( struct key *key, UCHAR *buf, ULONG len )
|
static NTSTATUS CDECL key_import_dsa_capi( struct key *key, UCHAR *buf, ULONG len )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
FIXME( "not implemented on Mac\n" );
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_import_ecc( struct key *key, UCHAR *input, ULONG len )
|
static NTSTATUS CDECL key_import_ecc( struct key *key, UCHAR *input, ULONG len )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
FIXME( "not implemented on Mac\n" );
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS key_asymmetric_generate( struct key *key )
|
static NTSTATUS CDECL key_asymmetric_generate( struct key *key )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
FIXME( "not implemented on Mac\n" );
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_asymmetric_destroy( struct key *key )
|
static void CDECL key_asymmetric_destroy( struct key *key )
|
||||||
{
|
{
|
||||||
FIXME( "not implemented on Mac\n" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct key_funcs key_funcs =
|
||||||
|
{
|
||||||
|
key_set_property,
|
||||||
|
key_symmetric_init,
|
||||||
|
key_symmetric_vector_reset,
|
||||||
|
key_symmetric_set_auth_data,
|
||||||
|
key_symmetric_encrypt,
|
||||||
|
key_symmetric_decrypt,
|
||||||
|
key_symmetric_get_tag,
|
||||||
|
key_symmetric_destroy,
|
||||||
|
key_asymmetric_init,
|
||||||
|
key_asymmetric_generate,
|
||||||
|
key_asymmetric_sign,
|
||||||
|
key_asymmetric_verify,
|
||||||
|
key_asymmetric_destroy,
|
||||||
|
key_export_dsa_capi,
|
||||||
|
key_export_ecc,
|
||||||
|
key_import_dsa_capi,
|
||||||
|
key_import_ecc
|
||||||
|
};
|
||||||
|
|
||||||
|
NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
|
||||||
|
{
|
||||||
|
if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS;
|
||||||
|
*(const struct key_funcs **)ptr_out = &key_funcs;
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue