bcrypt: Pad exported datums in export_gnutls_pubkey_ecc().

Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Paul Gofman 2021-01-18 12:38:24 +01:00 committed by Alexandre Julliard
parent 88a1848ca4
commit c5c2b7da3e
1 changed files with 16 additions and 10 deletions

View File

@ -670,6 +670,7 @@ static void export_gnutls_datum( UCHAR *buffer, ULONG length, gnutls_datum_t *d,
{ {
ULONG size = d->size; ULONG size = d->size;
UCHAR *src = d->data; UCHAR *src = d->data;
ULONG offset;
assert( size <= length + 1 ); assert( size <= length + 1 );
if (size == length + 1) if (size == length + 1)
@ -678,8 +679,17 @@ static void export_gnutls_datum( UCHAR *buffer, ULONG length, gnutls_datum_t *d,
++src; ++src;
--size; --size;
} }
*actual_length = size; if (actual_length)
memcpy( buffer, src, size ); {
offset = 0;
*actual_length = size;
}
else
{
offset = length - size;
memset( buffer, 0, offset );
}
memcpy( buffer + offset, src, size );
} }
static NTSTATUS export_gnutls_pubkey_rsa( gnutls_privkey_t gnutls_key, ULONG bitlen, UCHAR **pubkey, ULONG *pubkey_len ) static NTSTATUS export_gnutls_pubkey_rsa( gnutls_privkey_t gnutls_key, ULONG bitlen, UCHAR **pubkey, ULONG *pubkey_len )
@ -727,7 +737,7 @@ static NTSTATUS export_gnutls_pubkey_ecc( gnutls_privkey_t gnutls_key, enum alg_
gnutls_ecc_curve_t curve; gnutls_ecc_curve_t curve;
gnutls_datum_t x, y; gnutls_datum_t x, y;
DWORD magic, size; DWORD magic, size;
UCHAR *src, *dst; UCHAR *dst;
int ret; int ret;
switch (alg_id) switch (alg_id)
@ -758,7 +768,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 = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*ecc_blob) + x.size + y.size ))) if (!(ecc_blob = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*ecc_blob) + size * 2 )))
{ {
pgnutls_perror( ret ); pgnutls_perror( ret );
free( x.data ); free( y.data ); free( x.data ); free( y.data );
@ -769,14 +779,10 @@ static NTSTATUS export_gnutls_pubkey_ecc( gnutls_privkey_t gnutls_key, enum alg_
ecc_blob->cbKey = size; ecc_blob->cbKey = size;
dst = (UCHAR *)(ecc_blob + 1); dst = (UCHAR *)(ecc_blob + 1);
if (x.size == size + 1) src = x.data + 1; export_gnutls_datum( dst, size, &x, NULL );
else src = x.data;
memcpy( dst, src, size );
dst += size; dst += size;
if (y.size == size + 1) src = y.data + 1; export_gnutls_datum( dst, size, &y, NULL );
else src = y.data;
memcpy( dst, src, size );
*pubkey = (UCHAR *)ecc_blob; *pubkey = (UCHAR *)ecc_blob;
*pubkey_len = sizeof(*ecc_blob) + ecc_blob->cbKey * 2; *pubkey_len = sizeof(*ecc_blob) + ecc_blob->cbKey * 2;