From 085ed64df6b048f1237006f5b58994b11fea1fb0 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 6 Jan 2016 14:19:19 +0100 Subject: [PATCH] bcrypt: Implement BCryptFinishHash. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/bcrypt/bcrypt.spec | 2 +- dlls/bcrypt/bcrypt_main.c | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/dlls/bcrypt/bcrypt.spec b/dlls/bcrypt/bcrypt.spec index 5d67516acd0..c52d89ffbcd 100644 --- a/dlls/bcrypt/bcrypt.spec +++ b/dlls/bcrypt/bcrypt.spec @@ -22,7 +22,7 @@ @ stub BCryptEnumRegisteredProviders @ stub BCryptExportKey @ stub BCryptFinalizeKeyPair -@ stub BCryptFinishHash +@ stdcall BCryptFinishHash(ptr ptr long long) @ stub BCryptFreeBuffer @ stdcall BCryptGenRandom(ptr ptr long long) @ stub BCryptGenerateKeyPair diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c index 806fee85fbc..9cc5227e058 100644 --- a/dlls/bcrypt/bcrypt_main.c +++ b/dlls/bcrypt/bcrypt_main.c @@ -228,6 +228,33 @@ static void hash_update( struct hash *hash, UCHAR *input, ULONG size ) break; } } + +static NTSTATUS hash_finish( struct hash *hash, UCHAR *output, ULONG size ) +{ + switch (hash->alg_id) + { + case ALG_ID_SHA1: + CC_SHA1_Final( output, &hash->u.sha1_ctx ); + break; + + case ALG_ID_SHA256: + CC_SHA256_Final( output, &hash->u.sha256_ctx ); + break; + + case ALG_ID_SHA384: + CC_SHA384_Final( output, &hash->u.sha512_ctx ); + break; + + case ALG_ID_SHA512: + CC_SHA512_Final( output, &hash->u.sha512_ctx ); + break; + + default: + ERR( "unhandled id %u\n", hash->alg_id ); + break; + } + return STATUS_SUCCESS; +} #else struct hash { @@ -245,6 +272,12 @@ static void hash_update( struct hash *hash, UCHAR *input, ULONG size ) { ERR( "support for hashes not available at build time\n" ); } + +static NTSTATUS hash_finish( struct hash *hash, UCHAR *output, ULONG size ) +{ + ERR( "support for hashes not available at build time\n" ); + return STATUS_NOT_IMPLEMENTED; +} #endif #define OBJECT_LENGTH_SHA1 278 @@ -454,3 +487,15 @@ NTSTATUS WINAPI BCryptHashData( BCRYPT_HASH_HANDLE handle, UCHAR *input, ULONG s hash_update( hash, input, size ); return STATUS_SUCCESS; } + +NTSTATUS WINAPI BCryptFinishHash( BCRYPT_HASH_HANDLE handle, UCHAR *output, ULONG size, ULONG flags ) +{ + struct hash *hash = handle; + + TRACE( "%p, %p, %u, %08x\n", handle, output, size, flags ); + + if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_HANDLE; + if (!output) return STATUS_INVALID_PARAMETER; + + return hash_finish( hash, output, size ); +}