OOps, sorry for that. I pasted the wrong command in the terminal. This
is the real deal but was only supposed to be sent if the previous 5
test patches were commited.
On Fri, Dec 2, 2016 at 8:28 PM, Bruno Jesus <00cpxxx(a)gmail.com> wrote:
> From: Hans Leidekker <hans(a)codeweavers.com>
> Signed-off-by: Bruno Jesus <00cpxxx(a)gmail.com>
> ---
> dlls/bcrypt/bcrypt_main.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 79 insertions(+)
>
> diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
> index 6023c94..50c05c0 100644
> --- a/dlls/bcrypt/bcrypt_main.c
> +++ b/dlls/bcrypt/bcrypt_main.c
> @@ -138,6 +138,8 @@ NTSTATUS WINAPI BCryptEnumAlgorithms(ULONG dwAlgOperations, ULONG *pAlgCount,
>
> #define MAGIC_ALG (('A' << 24) | ('L' << 16) | ('G' << 8) | '0')
> #define MAGIC_HASH (('H' << 24) | ('A' << 16) | ('S' << 8) | 'H')
> +#define MAGIC_KEY (('K' << 24) | ('E' << 16) | ('Y' << 8) | '0')
> +
> struct object
> {
> ULONG magic;
> @@ -172,6 +174,8 @@ struct algorithm
> BOOL hmac;
> };
>
> +static ULONG get_block_size( enum alg_id alg );
> +
> NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE handle, UCHAR *buffer, ULONG count, ULONG flags)
> {
> const DWORD supported_flags = BCRYPT_USE_SYSTEM_PREFERRED_RNG;
> @@ -541,6 +545,37 @@ static NTSTATUS hmac_finish( struct hash *hash, UCHAR *output, ULONG size )
> pgnutls_hmac_deinit( hash->u.hmac_handle, output );
> return STATUS_SUCCESS;
> }
> +
> +struct key
> +{
> + struct object hdr;
> + enum alg_id alg_id;
> + ULONG block_size;
> + gnutls_cipher_hd_t handle;
> + UCHAR *secret;
> + ULONG secret_len;
> +};
> +
> +static NTSTATUS key_init( struct key *key, enum alg_id id, UCHAR *secret, ULONG secret_len )
> +{
> + if (!libgnutls_handle) return STATUS_INTERNAL_ERROR;
> +
> + switch (id)
> + {
> + default:
> + FIXME( "algorithm %u not supported\n", id );
> + return STATUS_NOT_SUPPORTED;
> + }
> +
> + if (!(key->block_size = get_block_size( id ))) return STATUS_INVALID_PARAMETER;
> +
> + key->alg_id = id;
> + key->handle = 0; /* initialized on first use */
> + key->secret = secret;
> + key->secret_len = secret_len;
> +
> + return STATUS_SUCCESS;
> +}
> #else
> struct hash
> {
> @@ -584,6 +619,17 @@ static NTSTATUS hmac_finish( struct hash *hash, UCHAR *output, ULONG size )
> ERR( "support for hashes not available at build time\n" );
> return STATUS_NOT_IMPLEMENTED;
> }
> +
> +struct key
> +{
> + struct object hdr;
> +};
> +
> +static NTSTATUS key_init( struct key *key, enum alg_id id, const UCHAR *secret, ULONG secret_len )
> +{
> + ERR( "support for keys not available at build time\n" );
> + return STATUS_NOT_IMPLEMENTED;
> +}
> #endif
>
> #define OBJECT_LENGTH_MD5 274
> @@ -694,6 +740,13 @@ static NTSTATUS get_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *buf,
> return STATUS_SUCCESS;
> }
>
> +static ULONG get_block_size( enum alg_id alg )
> +{
> + ULONG ret = 0, size = sizeof(ret);
> + get_alg_property( alg, BCRYPT_BLOCK_LENGTH, (UCHAR *)&ret, sizeof(ret), &size );
> + return ret;
> +}
> +
> static NTSTATUS get_hash_property( enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size )
> {
> NTSTATUS status;
> @@ -854,6 +907,32 @@ NTSTATUS WINAPI BCryptHash( BCRYPT_ALG_HANDLE algorithm, UCHAR *secret, ULONG se
> return BCryptDestroyHash( handle );
> }
>
> +NTSTATUS WINAPI BCryptGenerateSymmetricKey( BCRYPT_ALG_HANDLE algorithm, BCRYPT_KEY_HANDLE *handle,
> + UCHAR *object, ULONG object_len, UCHAR *secret, ULONG secret_len,
> + ULONG flags )
> +{
> + struct algorithm *alg = algorithm;
> + struct key *key;
> + NTSTATUS status;
> +
> + TRACE( "%p, %p, %p, %u, %p, %u, %08x\n", alg, handle, object, object_len, secret, secret_len, flags );
> +
> + if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE;
> + if (object) FIXME( "ignoring object buffer\n" );
> +
> + if (!(key = HeapAlloc( GetProcessHeap(), 0, sizeof(*key) ))) return STATUS_NO_MEMORY;
> + key->hdr.magic = MAGIC_KEY;
> +
> + if ((status = key_init( key, alg->id, secret, secret_len )))
> + {
> + HeapFree( GetProcessHeap(), 0, key );
> + return status;
> + }
> +
> + *handle = key;
> + return STATUS_SUCCESS;
> +}
> +
> BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
> {
> switch (reason)
> --
> 2.9.3
>