ReactOS  0.4.14-dev-323-g6fe6a88
crypt_md4.c
Go to the documentation of this file.
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 static VOID (WINAPI *pMD4Init)( MD4_CTX *ctx );
40 static VOID (WINAPI *pMD4Update)( MD4_CTX *ctx, const unsigned char *src, const int len );
41 static VOID (WINAPI *pMD4Final)( MD4_CTX *ctx );
42 static int (WINAPI *pSystemFunction007)(const UNICODE_STRING *, LPBYTE);
43 typedef int (WINAPI *md4hashfunc)(LPVOID, const LPBYTE, LPBYTE);
44 
47 
48 #define ctxcmp( a, b ) memcmp( a, b, FIELD_OFFSET( MD4_CTX, in ) )
49 
50 static void test_md4_ctx(void)
51 {
52  static unsigned char message[] =
53  "In our Life there's If"
54  "In our beliefs there's Lie"
55  "In our business there is Sin"
56  "In our bodies, there is Die";
57 
58  int size = sizeof(message) - 1;
59 
60  MD4_CTX ctx;
61  MD4_CTX ctx_initialized =
62  {
63  { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 },
64  { 0, 0 }
65  };
66 
67  MD4_CTX ctx_update1 =
68  {
69  { 0x5e592ef7, 0xbdcb1567, 0x2b626d17, 0x7d1198bd },
70  { 0x00000338, 0 }
71  };
72 
73  MD4_CTX ctx_update2 =
74  {
75  { 0x05dcfd65, 0xb3711c0d, 0x9e3369c2, 0x903ead11 },
76  { 0x00000670, 0 }
77  };
78 
79  unsigned char expect[16] =
80  { 0x5f, 0xd3, 0x9b, 0x29, 0x47, 0x53, 0x47, 0xaf,
81  0xa5, 0xba, 0x0c, 0x05, 0xff, 0xc0, 0xc7, 0xda };
82 
83 
84  memset( &ctx, 0, sizeof(ctx) );
85  pMD4Init( &ctx );
86  ok( !ctxcmp( &ctx, &ctx_initialized ), "invalid initialization\n" );
87 
88  pMD4Update( &ctx, message, size );
89  ok( !ctxcmp( &ctx, &ctx_update1 ), "update doesn't work correctly\n" );
90 
91  pMD4Update( &ctx, message, size );
92  ok( !ctxcmp( &ctx, &ctx_update2 ), "update doesn't work correctly\n" );
93 
94  pMD4Final( &ctx );
95  ok( ctxcmp( &ctx, &ctx_initialized ), "context has changed\n" );
96  ok( !memcmp( ctx.digest, expect, sizeof(expect) ), "incorrect result\n" );
97 
98 }
99 
100 static void test_SystemFunction007(void)
101 {
102  int r;
104  BYTE output[0x10];
105  BYTE expected[0x10] = { 0x24, 0x0a, 0xf0, 0x9d, 0x84, 0x1c, 0xda, 0xcf,
106  0x56, 0xeb, 0x6b, 0x96, 0x55, 0xec, 0xcf, 0x0a };
107  WCHAR szFoo[] = {'f','o','o',0 };
108 
109  if (0)
110  {
111  /* crashes on Windows */
112  r = pSystemFunction007(NULL, NULL);
113  ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
114  }
115 
116  str.Buffer = szFoo;
117  str.Length = 4*sizeof(WCHAR);
118  str.MaximumLength = str.Length;
119 
120  memset(output, 0, sizeof output);
121  r = pSystemFunction007(&str, output);
122  ok( r == STATUS_SUCCESS, "wrong error code\n");
123 
124  ok(!memcmp(output, expected, sizeof expected), "response wrong\n");
125 }
126 
128 {
129  unsigned char expected[0x10] = {
130  0x48, 0x7c, 0x3f, 0x5e, 0x2b, 0x0d, 0x6a, 0x79,
131  0x32, 0x4e, 0xcd, 0xbe, 0x9c, 0x15, 0x16, 0x6f };
132  unsigned char in[0x10], output[0x10];
133  int r;
134 
135  memset(in, 0, sizeof in);
136  memset(output, 0, sizeof output);
137  r = func(0, in, output);
138  ok( r == STATUS_SUCCESS, "wrong error code\n");
139  ok( !memcmp(expected, output, sizeof output), "output wrong\n");
140 }
141 
142 START_TEST(crypt_md4)
143 {
144  HMODULE module;
145 
146  module = GetModuleHandleA( "advapi32.dll" );
147 
148  pMD4Init = (void *)GetProcAddress( module, "MD4Init" );
149  pMD4Update = (void *)GetProcAddress( module, "MD4Update" );
150  pMD4Final = (void *)GetProcAddress( module, "MD4Final" );
151 
152  if (pMD4Init && pMD4Update && pMD4Final)
153  test_md4_ctx();
154  else
155  win_skip("MD4Init and/or MD4Update and/or MD4Final are not available\n");
156 
157  pSystemFunction007 = (void *)GetProcAddress( module, "SystemFunction007" );
158  if (pSystemFunction007)
160  else
161  win_skip("SystemFunction007 is not available\n");
162 
163  pSystemFunction010 = (md4hashfunc)GetProcAddress( module, "SystemFunction010" );
164  if (pSystemFunction010)
166  else
167  win_skip("SystemFunction010 is not available\n");
168 
169  pSystemFunction011 = (md4hashfunc)GetProcAddress( module, "SystemFunction011" );
170  if (pSystemFunction011)
172  else
173  win_skip("SystemFunction011 is not available\n");
174 }
GLenum func
Definition: glext.h:6028
unsigned char digest[16]
Definition: util.c:86
Definition: tftpd.h:59
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
HMODULE module
Definition: main.cpp:47
START_TEST(crypt_md4)
Definition: crypt_md4.c:142
#define ctxcmp(a, b)
Definition: crypt_md4.c:48
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static void test_md4_ctx(void)
Definition: crypt_md4.c:50
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:5579
static VOID(WINAPI *pMD4Init)(MD4_CTX *ctx)
static void test_md4hashfunc(md4hashfunc func)
Definition: crypt_md4.c:127
static int(WINAPI *pSystemFunction007)(const UNICODE_STRING *
static LPBYTE
Definition: crypt_md4.c:42
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
static md4hashfunc pSystemFunction010
Definition: crypt_md4.c:45
static md4hashfunc pSystemFunction011
Definition: crypt_md4.c:46
GLsizeiptr size
Definition: glext.h:5919
static const unsigned char const int len
Definition: crypt_md4.c:40
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WINAPI
Definition: msvc.h:8
static void test_SystemFunction007(void)
Definition: crypt_md4.c:100
#define LPVOID
Definition: nt_native.h:45
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
unsigned char BYTE
Definition: mem.h:68
Definition: util.c:81
GLuint in
Definition: glext.h:9616
#define ok(value,...)
Definition: atltest.h:57
int(WINAPI * md4hashfunc)(LPVOID, const LPBYTE, LPBYTE)
Definition: crypt_md4.c:43
#define expect(expected, got)
Definition: combo.c:36
static const unsigned char * src
Definition: crypt_md4.c:40
#define GetProcAddress(x, y)
Definition: compat.h:410
struct tagMD4_CTX MD4_CTX
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define memset(x, y, z)
Definition: compat.h:39
#define win_skip
Definition: test.h:141
BOOL expected
Definition: store.c:2063