Commit e73d4e55 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

bcrypt: Added support for MD4 hashes.

parent b0329620
...@@ -61,6 +61,17 @@ void md2_update(MD2_CTX *ctx, const unsigned char *buf, ULONG len) DECLSPEC_HIDD ...@@ -61,6 +61,17 @@ void md2_update(MD2_CTX *ctx, const unsigned char *buf, ULONG len) DECLSPEC_HIDD
void md2_finalize(MD2_CTX *ctx, unsigned char *hash) DECLSPEC_HIDDEN; void md2_finalize(MD2_CTX *ctx, unsigned char *hash) DECLSPEC_HIDDEN;
/* Definitions from advapi32 */ /* Definitions from advapi32 */
typedef struct tagMD4_CTX {
unsigned int buf[4];
unsigned int i[2];
unsigned char in[64];
unsigned char digest[16];
} MD4_CTX;
VOID WINAPI MD4Init(MD4_CTX *ctx);
VOID WINAPI MD4Update(MD4_CTX *ctx, const unsigned char *buf, unsigned int len);
VOID WINAPI MD4Final(MD4_CTX *ctx);
typedef struct typedef struct
{ {
unsigned int i[2]; unsigned int i[2];
......
...@@ -146,6 +146,7 @@ enum alg_id ...@@ -146,6 +146,7 @@ enum alg_id
{ {
ALG_ID_AES, ALG_ID_AES,
ALG_ID_MD2, ALG_ID_MD2,
ALG_ID_MD4,
ALG_ID_MD5, ALG_ID_MD5,
ALG_ID_RNG, ALG_ID_RNG,
ALG_ID_SHA1, ALG_ID_SHA1,
...@@ -165,6 +166,7 @@ static const struct { ...@@ -165,6 +166,7 @@ static const struct {
} alg_props[] = { } alg_props[] = {
/* ALG_ID_AES */ { 654, 0, 0, BCRYPT_AES_ALGORITHM }, /* ALG_ID_AES */ { 654, 0, 0, BCRYPT_AES_ALGORITHM },
/* ALG_ID_MD2 */ { 270, 16, 128, BCRYPT_MD2_ALGORITHM }, /* ALG_ID_MD2 */ { 270, 16, 128, BCRYPT_MD2_ALGORITHM },
/* ALG_ID_MD4 */ { 270, 16, 512, BCRYPT_MD4_ALGORITHM },
/* ALG_ID_MD5 */ { 274, 16, 512, BCRYPT_MD5_ALGORITHM }, /* ALG_ID_MD5 */ { 274, 16, 512, BCRYPT_MD5_ALGORITHM },
/* ALG_ID_RNG */ { 0, 0, 0, BCRYPT_RNG_ALGORITHM }, /* ALG_ID_RNG */ { 0, 0, 0, BCRYPT_RNG_ALGORITHM },
/* ALG_ID_SHA1 */ { 278, 20, 512, BCRYPT_SHA1_ALGORITHM }, /* ALG_ID_SHA1 */ { 278, 20, 512, BCRYPT_SHA1_ALGORITHM },
...@@ -238,6 +240,7 @@ NTSTATUS WINAPI BCryptOpenAlgorithmProvider( BCRYPT_ALG_HANDLE *handle, LPCWSTR ...@@ -238,6 +240,7 @@ NTSTATUS WINAPI BCryptOpenAlgorithmProvider( BCRYPT_ALG_HANDLE *handle, LPCWSTR
if (!strcmpW( id, BCRYPT_AES_ALGORITHM )) alg_id = ALG_ID_AES; if (!strcmpW( id, BCRYPT_AES_ALGORITHM )) alg_id = ALG_ID_AES;
else if (!strcmpW( id, BCRYPT_MD2_ALGORITHM )) alg_id = ALG_ID_MD2; else if (!strcmpW( id, BCRYPT_MD2_ALGORITHM )) alg_id = ALG_ID_MD2;
else if (!strcmpW( id, BCRYPT_MD4_ALGORITHM )) alg_id = ALG_ID_MD4;
else if (!strcmpW( id, BCRYPT_MD5_ALGORITHM )) alg_id = ALG_ID_MD5; else if (!strcmpW( id, BCRYPT_MD5_ALGORITHM )) alg_id = ALG_ID_MD5;
else if (!strcmpW( id, BCRYPT_RNG_ALGORITHM )) alg_id = ALG_ID_RNG; else if (!strcmpW( id, BCRYPT_RNG_ALGORITHM )) alg_id = ALG_ID_RNG;
else if (!strcmpW( id, BCRYPT_SHA1_ALGORITHM )) alg_id = ALG_ID_SHA1; else if (!strcmpW( id, BCRYPT_SHA1_ALGORITHM )) alg_id = ALG_ID_SHA1;
...@@ -291,6 +294,7 @@ struct hash_impl ...@@ -291,6 +294,7 @@ struct hash_impl
union union
{ {
MD2_CTX md2; MD2_CTX md2;
MD4_CTX md4;
MD5_CTX md5; MD5_CTX md5;
SHA_CTX sha1; SHA_CTX sha1;
SHA256_CTX sha256; SHA256_CTX sha256;
...@@ -306,6 +310,10 @@ static NTSTATUS hash_init( struct hash_impl *hash, enum alg_id alg_id ) ...@@ -306,6 +310,10 @@ static NTSTATUS hash_init( struct hash_impl *hash, enum alg_id alg_id )
md2_init( &hash->u.md2 ); md2_init( &hash->u.md2 );
break; break;
case ALG_ID_MD4:
MD4Init( &hash->u.md4 );
break;
case ALG_ID_MD5: case ALG_ID_MD5:
MD5Init( &hash->u.md5 ); MD5Init( &hash->u.md5 );
break; break;
...@@ -342,6 +350,10 @@ static NTSTATUS hash_update( struct hash_impl *hash, enum alg_id alg_id, ...@@ -342,6 +350,10 @@ static NTSTATUS hash_update( struct hash_impl *hash, enum alg_id alg_id,
md2_update( &hash->u.md2, input, size ); md2_update( &hash->u.md2, input, size );
break; break;
case ALG_ID_MD4:
MD4Update( &hash->u.md4, input, size );
break;
case ALG_ID_MD5: case ALG_ID_MD5:
MD5Update( &hash->u.md5, input, size ); MD5Update( &hash->u.md5, input, size );
break; break;
...@@ -378,6 +390,11 @@ static NTSTATUS hash_finish( struct hash_impl *hash, enum alg_id alg_id, ...@@ -378,6 +390,11 @@ static NTSTATUS hash_finish( struct hash_impl *hash, enum alg_id alg_id,
md2_finalize( &hash->u.md2, output ); md2_finalize( &hash->u.md2, output );
break; break;
case ALG_ID_MD4:
MD4Final( &hash->u.md4 );
memcpy( output, hash->u.md4.digest, 16 );
break;
case ALG_ID_MD5: case ALG_ID_MD5:
MD5Final( &hash->u.md5 ); MD5Final( &hash->u.md5 );
memcpy( output, hash->u.md5.digest, 16 ); memcpy( output, hash->u.md5.digest, 16 );
......
...@@ -329,6 +329,12 @@ static void test_hashes(void) ...@@ -329,6 +329,12 @@ static void test_hashes(void)
"7f05b0638d77f4a27f3a9c4d353cd648" "7f05b0638d77f4a27f3a9c4d353cd648"
}, },
{ {
"MD4",
16,
"74b5db93c0b41e36ca7074338fc0b637",
"bc2e8ac4d8248ed21b8d26227a30ea3a"
},
{
"MD5", "MD5",
16, 16,
"e2a3e68d23ce348b8f68b3079de3d4c9", "e2a3e68d23ce348b8f68b3079de3d4c9",
......
...@@ -65,6 +65,7 @@ typedef LONG NTSTATUS; ...@@ -65,6 +65,7 @@ typedef LONG NTSTATUS;
#define BCRYPT_AES_ALGORITHM (const WCHAR []){'A','E','S',0} #define BCRYPT_AES_ALGORITHM (const WCHAR []){'A','E','S',0}
#define BCRYPT_MD2_ALGORITHM (const WCHAR []){'M','D','2',0} #define BCRYPT_MD2_ALGORITHM (const WCHAR []){'M','D','2',0}
#define BCRYPT_MD4_ALGORITHM (const WCHAR []){'M','D','4',0}
#define BCRYPT_MD5_ALGORITHM (const WCHAR []){'M','D','5',0} #define BCRYPT_MD5_ALGORITHM (const WCHAR []){'M','D','5',0}
#define BCRYPT_RNG_ALGORITHM (const WCHAR []){'R','N','G',0} #define BCRYPT_RNG_ALGORITHM (const WCHAR []){'R','N','G',0}
#define BCRYPT_SHA1_ALGORITHM (const WCHAR []){'S','H','A','1',0} #define BCRYPT_SHA1_ALGORITHM (const WCHAR []){'S','H','A','1',0}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment