bcrypt: Use builtin MD5/SHA1 implementation.

Signed-off-by: Michael Müller <michael@fds-team.de>
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Michael Müller 2017-03-07 23:14:36 +01:00 committed by Alexandre Julliard
parent 9c123204f3
commit 03630a42f4
2 changed files with 106 additions and 7 deletions

View File

@ -0,0 +1,53 @@
/*
* Copyright 2016 Michael Müller
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
#ifndef __BCRYPT_INTERNAL_H
#define __BCRYPT_INTERNAL_H
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
/* Definitions from advapi32 */
typedef struct
{
unsigned int i[2];
unsigned int buf[4];
unsigned char in[64];
unsigned char digest[16];
} MD5_CTX;
VOID WINAPI MD5Init(MD5_CTX *ctx);
VOID WINAPI MD5Update(MD5_CTX *ctx, const unsigned char *buf, unsigned int len);
VOID WINAPI MD5Final(MD5_CTX *ctx);
typedef struct
{
ULONG Unknown[6];
ULONG State[5];
ULONG Count[2];
UCHAR Buffer[64];
} SHA_CTX;
VOID WINAPI A_SHAInit(SHA_CTX *ctx);
VOID WINAPI A_SHAUpdate(SHA_CTX *ctx, const UCHAR *buffer, UINT size);
VOID WINAPI A_SHAFinal(SHA_CTX *ctx, PULONG result);
#endif /* __BCRYPT_INTERNAL_H */

View File

@ -36,6 +36,8 @@
#include "ntsecapi.h"
#include "bcrypt.h"
#include "bcrypt_internal.h"
#include "wine/debug.h"
#include "wine/library.h"
#include "wine/unicode.h"
@ -442,27 +444,71 @@ static NTSTATUS hash_finish( struct hash_impl *hash, enum alg_id alg_id,
#else
struct hash_impl
{
union
{
MD5_CTX md5;
SHA_CTX sha1;
} u;
};
static NTSTATUS hash_init( struct hash_impl *hash, enum alg_id alg_id )
{
ERR( "support for hashes not available at build time\n" );
return STATUS_NOT_IMPLEMENTED;
switch (alg_id)
{
case ALG_ID_MD5:
MD5Init( &hash->u.md5 );
break;
case ALG_ID_SHA1:
A_SHAInit( &hash->u.sha1 );
break;
default:
ERR( "unhandled id %u\n", alg_id );
return STATUS_NOT_IMPLEMENTED;
}
return STATUS_SUCCESS;
}
static NTSTATUS hash_update( struct hash_impl *hash, enum alg_id alg_id,
UCHAR *input, ULONG size )
{
ERR( "support for hashes not available at build time\n" );
return STATUS_NOT_IMPLEMENTED;
switch (alg_id)
{
case ALG_ID_MD5:
MD5Update( &hash->u.md5, input, size );
break;
case ALG_ID_SHA1:
A_SHAUpdate( &hash->u.sha1, input, size );
break;
default:
ERR( "unhandled id %u\n", alg_id );
return STATUS_NOT_IMPLEMENTED;
}
return STATUS_SUCCESS;
}
static NTSTATUS hash_finish( struct hash_impl *hash, enum alg_id alg_id,
UCHAR *output, ULONG size )
{
ERR( "support for hashes not available at build time\n" );
return STATUS_NOT_IMPLEMENTED;
switch (alg_id)
{
case ALG_ID_MD5:
MD5Final( &hash->u.md5 );
memcpy( output, hash->u.md5.digest, 16 );
break;
case ALG_ID_SHA1:
A_SHAFinal( &hash->u.sha1, (ULONG *)output );
break;
default:
ERR( "unhandled id %u\n", alg_id );
return STATUS_NOT_IMPLEMENTED;
}
return STATUS_SUCCESS;
}
#endif