bcrypt: Move setting a symmetric key vector to the generic code.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
54c1b0ac26
commit
b8ada902d1
|
@ -257,7 +257,7 @@ NTSTATUS get_alg_property( const struct algorithm *, const WCHAR *, UCHAR *, ULO
|
|||
|
||||
NTSTATUS key_set_property( struct key *, const WCHAR *, UCHAR *, ULONG, ULONG ) DECLSPEC_HIDDEN;
|
||||
NTSTATUS key_symmetric_init( struct key *, struct algorithm *, const UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
||||
NTSTATUS key_symmetric_set_vector( struct key *, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
||||
void key_symmetric_vector_reset( struct key * ) DECLSPEC_HIDDEN;
|
||||
NTSTATUS key_symmetric_set_auth_data( struct key *, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
||||
NTSTATUS key_symmetric_encrypt( struct key *, const UCHAR *, ULONG, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
||||
NTSTATUS key_symmetric_decrypt( struct key *, const UCHAR *, ULONG, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
||||
|
@ -273,9 +273,6 @@ NTSTATUS key_export_ecc( struct key *, UCHAR *, ULONG, ULONG * ) DECLSPEC_HIDDEN
|
|||
NTSTATUS key_import_dsa_capi( struct key *, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
||||
NTSTATUS key_import_ecc( struct key *, UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
||||
|
||||
BOOL is_zero_vector( const UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
||||
BOOL is_equal_vector( const UCHAR *, ULONG, const UCHAR *, ULONG ) DECLSPEC_HIDDEN;
|
||||
|
||||
BOOL gnutls_initialize(void) DECLSPEC_HIDDEN;
|
||||
void gnutls_uninitialize(void) DECLSPEC_HIDDEN;
|
||||
|
||||
|
|
|
@ -891,7 +891,7 @@ BOOL key_is_symmetric( struct key *key )
|
|||
return builtin_algorithms[key->alg_id].class == BCRYPT_CIPHER_INTERFACE;
|
||||
}
|
||||
|
||||
BOOL is_zero_vector( const UCHAR *vector, ULONG len )
|
||||
static BOOL is_zero_vector( const UCHAR *vector, ULONG len )
|
||||
{
|
||||
ULONG i;
|
||||
if (!vector) return FALSE;
|
||||
|
@ -899,13 +899,31 @@ BOOL is_zero_vector( const UCHAR *vector, ULONG len )
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL is_equal_vector( const UCHAR *vector, ULONG len, const UCHAR *vector2, ULONG len2 )
|
||||
static BOOL is_equal_vector( const UCHAR *vector, ULONG len, const UCHAR *vector2, ULONG len2 )
|
||||
{
|
||||
if (!vector && !vector2) return TRUE;
|
||||
if (len != len2) return FALSE;
|
||||
return !memcmp( vector, vector2, len );
|
||||
}
|
||||
|
||||
static NTSTATUS key_symmetric_set_vector( struct key *key, UCHAR *vector, ULONG vector_len )
|
||||
{
|
||||
BOOL needs_reset = (!is_zero_vector( vector, vector_len ) ||
|
||||
!is_equal_vector( key->u.s.vector, key->u.s.vector_len, vector, vector_len ));
|
||||
|
||||
heap_free( key->u.s.vector );
|
||||
key->u.s.vector = NULL;
|
||||
key->u.s.vector_len = 0;
|
||||
if (vector)
|
||||
{
|
||||
if (!(key->u.s.vector = heap_alloc( vector_len ))) return STATUS_NO_MEMORY;
|
||||
memcpy( key->u.s.vector, vector, vector_len );
|
||||
key->u.s.vector_len = vector_len;
|
||||
}
|
||||
if (needs_reset) key_symmetric_vector_reset( key );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
|
|
|
@ -520,29 +520,14 @@ static gnutls_cipher_algorithm_t get_gnutls_cipher( const struct key *key )
|
|||
}
|
||||
}
|
||||
|
||||
NTSTATUS key_symmetric_set_vector( struct key *key, UCHAR *vector, ULONG vector_len )
|
||||
{
|
||||
if (key->u.s.handle && (!is_zero_vector( vector, vector_len ) ||
|
||||
!is_equal_vector( key->u.s.vector, key->u.s.vector_len, vector, vector_len )))
|
||||
void key_symmetric_vector_reset( struct key *key )
|
||||
{
|
||||
if (!key->u.s.handle) return;
|
||||
TRACE( "invalidating cipher handle\n" );
|
||||
pgnutls_cipher_deinit( key->u.s.handle );
|
||||
key->u.s.handle = NULL;
|
||||
}
|
||||
|
||||
heap_free( key->u.s.vector );
|
||||
key->u.s.vector = NULL;
|
||||
key->u.s.vector_len = 0;
|
||||
if (vector)
|
||||
{
|
||||
if (!(key->u.s.vector = heap_alloc( vector_len ))) return STATUS_NO_MEMORY;
|
||||
memcpy( key->u.s.vector, vector, vector_len );
|
||||
key->u.s.vector_len = vector_len;
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS init_cipher_handle( struct key *key )
|
||||
{
|
||||
gnutls_cipher_algorithm_t cipher;
|
||||
|
|
|
@ -123,11 +123,10 @@ static CCMode get_cryptor_mode( struct key *key )
|
|||
}
|
||||
}
|
||||
|
||||
NTSTATUS key_symmetric_set_vector( struct key *key, UCHAR *vector, ULONG vector_len )
|
||||
{
|
||||
if (key->u.s.ref_encrypt && (!is_zero_vector( vector, vector_len ) ||
|
||||
!is_equal_vector( key->u.s.vector, key->u.s.vector_len, vector, vector_len )))
|
||||
void key_symmetric_vector_reset( struct key *key )
|
||||
{
|
||||
if (!key->u.s.ref_encrypt) return;
|
||||
|
||||
TRACE( "invalidating cryptor handles\n" );
|
||||
CCCryptorRelease( key->u.s.ref_encrypt );
|
||||
key->u.s.ref_encrypt = NULL;
|
||||
|
@ -136,19 +135,6 @@ NTSTATUS key_symmetric_set_vector( struct key *key, UCHAR *vector, ULONG vector_
|
|||
key->u.s.ref_decrypt = NULL;
|
||||
}
|
||||
|
||||
heap_free( key->u.s.vector );
|
||||
key->u.s.vector = NULL;
|
||||
key->u.s.vector_len = 0;
|
||||
if (vector)
|
||||
{
|
||||
if (!(key->u.s.vector = heap_alloc( vector_len ))) return STATUS_NO_MEMORY;
|
||||
memcpy( key->u.s.vector, vector, vector_len );
|
||||
key->u.s.vector_len = vector_len;
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS init_cryptor_handles( struct key *key )
|
||||
{
|
||||
CCCryptorStatus status;
|
||||
|
|
Loading…
Reference in New Issue