Release 20050930.
[wine/gsoc-2012-control.git] / dlls / advapi32 / tests / crypt_md4.c
blob3a68c88caaed22852e30e10bd48540866869ccaf
1 /*
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
21 #include <stdio.h>
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
28 typedef struct
30 unsigned int buf[4];
31 unsigned int i[2];
32 unsigned char in[64];
33 unsigned char digest[16];
34 } MD4_CTX;
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 );
40 fnMD4Init pMD4Init;
41 fnMD4Update pMD4Update;
42 fnMD4Final pMD4Final;
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 = sizeof(message) - 1;
55 HMODULE module;
57 MD4_CTX ctx;
58 MD4_CTX ctx_initialized =
60 { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 },
61 { 0, 0 }
64 MD4_CTX ctx_update1 =
66 { 0x5e592ef7, 0xbdcb1567, 0x2b626d17, 0x7d1198bd },
67 { 0x00000338, 0 }
70 MD4_CTX ctx_update2 =
72 { 0x05dcfd65, 0xb3711c0d, 0x9e3369c2, 0x903ead11 },
73 { 0x00000670, 0 }
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) );
89 pMD4Init( &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" );
98 pMD4Final( &ctx );
99 ok( ctxcmp( &ctx, &ctx_initialized ), "context has changed\n" );
100 ok( !memcmp( ctx.digest, expect, sizeof(expect) ), "incorrect result\n" );
102 out:
103 FreeLibrary( module );
106 START_TEST(crypt_md4)
108 test_md4_ctx();