~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/advapi32/tests/crypt_md4.c

Version: ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include <stdio.h>
 22 
 23 #include "ntstatus.h"
 24 #define WIN32_NO_STATUS
 25 #include "wine/test.h"
 26 #include "windef.h"
 27 #include "winbase.h"
 28 #include "winerror.h"
 29 #include "winternl.h"
 30 
 31 typedef struct
 32 {
 33     unsigned int buf[4];
 34     unsigned int i[2];
 35     unsigned char in[64];
 36     unsigned char digest[16];
 37 } MD4_CTX;
 38 
 39 typedef VOID (WINAPI *fnMD4Init)( MD4_CTX *ctx );
 40 typedef VOID (WINAPI *fnMD4Update)( MD4_CTX *ctx, const unsigned char *src, const int len );
 41 typedef VOID (WINAPI *fnMD4Final)( MD4_CTX *ctx );
 42 typedef int (WINAPI *fnSystemFunction007)(const UNICODE_STRING *, LPBYTE);
 43 typedef int (WINAPI *md4hashfunc)(LPVOID, const LPBYTE, LPBYTE);
 44 
 45 fnMD4Init pMD4Init;
 46 fnMD4Update pMD4Update;
 47 fnMD4Final pMD4Final;
 48 fnSystemFunction007 pSystemFunction007;
 49 md4hashfunc pSystemFunction010;
 50 md4hashfunc pSystemFunction011;
 51 
 52 #define ctxcmp( a, b ) memcmp( (char*)a, (char*)b, FIELD_OFFSET( MD4_CTX, in ) )
 53 
 54 static void test_md4_ctx(void)
 55 {
 56     static unsigned char message[] =
 57         "In our Life there's If"
 58         "In our beliefs there's Lie"
 59         "In our business there is Sin"
 60         "In our bodies, there is Die";
 61 
 62     int size = sizeof(message) - 1;
 63 
 64     MD4_CTX ctx;
 65     MD4_CTX ctx_initialized = 
 66     {
 67         { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 },
 68         { 0, 0 }
 69     };
 70 
 71     MD4_CTX ctx_update1 =
 72     {
 73         { 0x5e592ef7, 0xbdcb1567, 0x2b626d17, 0x7d1198bd },
 74         { 0x00000338, 0 }
 75     };
 76 
 77     MD4_CTX ctx_update2 =
 78     {
 79         { 0x05dcfd65, 0xb3711c0d, 0x9e3369c2, 0x903ead11 },
 80         { 0x00000670, 0 }
 81     };
 82 
 83     unsigned char expect[16] =
 84         { 0x5f, 0xd3, 0x9b, 0x29, 0x47, 0x53, 0x47, 0xaf,
 85           0xa5, 0xba, 0x0c, 0x05, 0xff, 0xc0, 0xc7, 0xda };
 86 
 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 }
103 
104 static void test_SystemFunction007(void)
105 {
106     int r;
107     UNICODE_STRING str;
108     BYTE output[0x10];
109     BYTE expected[0x10] = { 0x24, 0x0a, 0xf0, 0x9d, 0x84, 0x1c, 0xda, 0xcf, 
110                             0x56, 0xeb, 0x6b, 0x96, 0x55, 0xec, 0xcf, 0x0a };
111     WCHAR szFoo[] = {'f','o','o',0 };
112 
113     if (0)
114     {
115     /* crashes on Windows */
116     r = pSystemFunction007(NULL, NULL);
117     ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
118     }
119 
120     str.Buffer = szFoo;
121     str.Length = 4*sizeof(WCHAR);
122     str.MaximumLength = str.Length;
123 
124     memset(output, 0, sizeof output);
125     r = pSystemFunction007(&str, output);
126     ok( r == STATUS_SUCCESS, "wrong error code\n");
127 
128     ok(!memcmp(output, expected, sizeof expected), "response wrong\n");
129 }
130 
131 static void test_md4hashfunc(md4hashfunc func)
132 {
133     unsigned char expected[0x10] = {
134         0x48, 0x7c, 0x3f, 0x5e, 0x2b, 0x0d, 0x6a, 0x79,
135         0x32, 0x4e, 0xcd, 0xbe, 0x9c, 0x15, 0x16, 0x6f };
136     unsigned char in[0x10], output[0x10];
137     int r;
138 
139     memset(in, 0, sizeof in);
140     memset(output, 0, sizeof output);
141     r = func(0, in, output);
142     ok( r == STATUS_SUCCESS, "wrong error code\n");
143     ok( !memcmp(expected, output, sizeof output), "output wrong\n");
144 }
145 
146 START_TEST(crypt_md4)
147 {
148     HMODULE module;
149 
150     module = GetModuleHandleA( "advapi32.dll" );
151 
152     pMD4Init = (fnMD4Init)GetProcAddress( module, "MD4Init" );
153     pMD4Update = (fnMD4Update)GetProcAddress( module, "MD4Update" );
154     pMD4Final = (fnMD4Final)GetProcAddress( module, "MD4Final" );
155 
156     if (pMD4Init && pMD4Update && pMD4Final)
157         test_md4_ctx();
158     else
159         skip("MD4Init and/or MD4Update and/or MD4Final are not available\n");
160 
161     pSystemFunction007 = (fnSystemFunction007)GetProcAddress( module, "SystemFunction007" );
162     if (pSystemFunction007)
163         test_SystemFunction007();
164     else
165         skip("SystemFunction007 is not available\n");
166 
167     pSystemFunction010 = (md4hashfunc)GetProcAddress( module, "SystemFunction010" );
168     if (pSystemFunction010)
169         test_md4hashfunc(pSystemFunction010);
170     else
171         skip("SystemFunction010 is not available\n");
172 
173     pSystemFunction011 = (md4hashfunc)GetProcAddress( module, "SystemFunction011" );
174     if (pSystemFunction011)
175         test_md4hashfunc(pSystemFunction011);
176     else
177         skip("SystemFunction011 is not available\n");
178 }
179 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.