2 * Unit tests for MD4 functions
4 * Copyright 2004 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/test.h"
33 unsigned char digest[16];
36 typedef VOID (WINAPI *fnMD4Init)( MD4_CTX *ctx );
37 typedef VOID (WINAPI *fnMD4Update)( MD4_CTX *ctx, const unsigned char *src, const int len );
38 typedef VOID (WINAPI *fnMD4Final)( MD4_CTX *ctx );
41 fnMD4Update pMD4Update;
44 #define ctxcmp( a, b ) memcmp( (char*)a, (char*)b, FIELD_OFFSET( MD4_CTX, in ) )
46 static void test_md4_ctx(void)
48 static unsigned char message[] =
49 "In our Life there's If"
50 "In our beliefs there's Lie"
51 "In our business there is Sin"
52 "In our bodies, there is Die";
54 int size = strlen( message );
58 MD4_CTX ctx_initialized =
60 { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 },
66 { 0x5e592ef7, 0xbdcb1567, 0x2b626d17, 0x7d1198bd },
72 { 0x05dcfd65, 0xb3711c0d, 0x9e3369c2, 0x903ead11 },
76 unsigned char expect[16] =
77 { 0x5f, 0xd3, 0x9b, 0x29, 0x47, 0x53, 0x47, 0xaf,
78 0xa5, 0xba, 0x0c, 0x05, 0xff, 0xc0, 0xc7, 0xda };
80 if (!(module = LoadLibrary( "advapi32.dll" ))) return;
82 pMD4Init = (fnMD4Init)GetProcAddress( module, "MD4Init" );
83 pMD4Update = (fnMD4Update)GetProcAddress( module, "MD4Update" );
84 pMD4Final = (fnMD4Final)GetProcAddress( module, "MD4Final" );
86 if (!pMD4Init || !pMD4Update || !pMD4Final) goto out;
88 memset( &ctx, 0, sizeof(ctx) );
90 ok( !ctxcmp( &ctx, &ctx_initialized ), "invalid initialization\n" );
92 pMD4Update( &ctx, message, size );
93 ok( !ctxcmp( &ctx, &ctx_update1 ), "update doesn't work correctly\n" );
95 pMD4Update( &ctx, message, size );
96 ok( !ctxcmp( &ctx, &ctx_update2 ), "update doesn't work correctly\n" );
99 ok( ctxcmp( &ctx, &ctx_initialized ), "context has changed\n" );
100 ok( !memcmp( ctx.digest, expect, sizeof(expect) ), "incorrect result\n" );
103 FreeLibrary( module );
106 START_TEST(crypt_md4)