Rewrote the RegGetValue tests for REG_SZ / REG_EXPAND_SZ.
[wine] / dlls / advapi32 / tests / crypt_md4.c
1 /*
2  * Unit tests for MD4 functions
3  *
4  * Copyright 2004 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdio.h>
22
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27
28 typedef struct
29 {
30     unsigned int buf[4];
31     unsigned int i[2];
32     unsigned char in[64];
33     unsigned char digest[16];
34 } MD4_CTX;
35
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 );
39
40 fnMD4Init pMD4Init;
41 fnMD4Update pMD4Update;
42 fnMD4Final pMD4Final;
43
44 #define ctxcmp( a, b ) memcmp( (char*)a, (char*)b, FIELD_OFFSET( MD4_CTX, in ) )
45
46 static void test_md4_ctx(void)
47 {
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";
53
54     int size = strlen( message );
55     HMODULE module;
56
57     MD4_CTX ctx;
58     MD4_CTX ctx_initialized = 
59     {
60         { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 },
61         { 0, 0 }
62     };
63
64     MD4_CTX ctx_update1 =
65     {
66         { 0x5e592ef7, 0xbdcb1567, 0x2b626d17, 0x7d1198bd },
67         { 0x00000338, 0 }
68     };
69
70     MD4_CTX ctx_update2 =
71     {
72         { 0x05dcfd65, 0xb3711c0d, 0x9e3369c2, 0x903ead11 },
73         { 0x00000670, 0 }
74     };
75
76     unsigned char expect[16] =
77         { 0x5f, 0xd3, 0x9b, 0x29, 0x47, 0x53, 0x47, 0xaf,
78           0xa5, 0xba, 0x0c, 0x05, 0xff, 0xc0, 0xc7, 0xda };
79
80     if (!(module = LoadLibrary( "advapi32.dll" ))) return;
81
82     pMD4Init = (fnMD4Init)GetProcAddress( module, "MD4Init" );
83     pMD4Update = (fnMD4Update)GetProcAddress( module, "MD4Update" );
84     pMD4Final = (fnMD4Final)GetProcAddress( module, "MD4Final" );
85
86     if (!pMD4Init || !pMD4Update || !pMD4Final) goto out;
87
88     memset( &ctx, 0, sizeof(ctx) );
89     pMD4Init( &ctx );
90     ok( !ctxcmp( &ctx, &ctx_initialized ), "invalid initialization\n" );
91
92     pMD4Update( &ctx, message, size );
93     ok( !ctxcmp( &ctx, &ctx_update1 ), "update doesn't work correctly\n" );
94
95     pMD4Update( &ctx, message, size );
96     ok( !ctxcmp( &ctx, &ctx_update2 ), "update doesn't work correctly\n" );
97
98     pMD4Final( &ctx );
99     ok( ctxcmp( &ctx, &ctx_initialized ), "context has changed\n" );
100     ok( !memcmp( ctx.digest, expect, sizeof(expect) ), "incorrect result\n" );
101
102 out:
103     FreeLibrary( module );
104 }
105
106 START_TEST(crypt_md4)
107 {
108     test_md4_ctx();
109 }