ReactOS  0.4.14-dev-552-g2fad488
crypt_md5.c
Go to the documentation of this file.
1 /*
2  * Unit tests for MD5 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 "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 
28 typedef struct
29 {
30  unsigned int i[2];
31  unsigned int buf[4];
32  unsigned char in[64];
33  unsigned char digest[16];
34 } MD5_CTX;
35 
36 static VOID (WINAPI *pMD5Init)( MD5_CTX *ctx );
37 static VOID (WINAPI *pMD5Update)( MD5_CTX *ctx, const unsigned char *src, const int len );
38 static VOID (WINAPI *pMD5Final)( MD5_CTX *ctx );
39 
40 #define ctxcmp( a, b ) memcmp( a, b, FIELD_OFFSET( MD5_CTX, in ) )
41 
42 static void test_md5_ctx(void)
43 {
44  static unsigned char message[] =
45  "In our Life there's If"
46  "In our beliefs there's Lie"
47  "In our business there is Sin"
48  "In our bodies, there is Die";
49 
50  int size = sizeof(message) - 1;
52 
53  MD5_CTX ctx;
54  MD5_CTX ctx_initialized =
55  {
56  { 0, 0 },
57  { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 }
58  };
59 
60  MD5_CTX ctx_update1 =
61  {
62  { 0x00000338, 0 },
63  { 0x068cb64d, 0xb7a05790, 0x426979ee, 0xed67e221 }
64  };
65 
66  MD5_CTX ctx_update2 =
67  {
68  { 0x00000670, 0 },
69  { 0x2f7afe58, 0xcc3e9315, 0x709c465c, 0xbf6414c8 }
70  };
71 
72  unsigned char expect[16] =
73  { 0x43, 0x03, 0xdd, 0x8c, 0x60, 0xd9, 0x3a, 0x22,
74  0x0b, 0x28, 0xd0, 0xb2, 0x65, 0x93, 0xd0, 0x36 };
75 
76  module = GetModuleHandleA("advapi32.dll");
77 
78  pMD5Init = (void *)GetProcAddress( module, "MD5Init" );
79  pMD5Update = (void *)GetProcAddress( module, "MD5Update" );
80  pMD5Final = (void *)GetProcAddress( module, "MD5Final" );
81 
82  if (!pMD5Init || !pMD5Update || !pMD5Final)
83  {
84  win_skip("Needed functions are not available\n");
85  return;
86  }
87 
88  memset( &ctx, 0, sizeof(ctx) );
89  pMD5Init( &ctx );
90  ok( !ctxcmp( &ctx, &ctx_initialized ), "invalid initialization\n" );
91 
92  pMD5Update( &ctx, message, size );
93  ok( !ctxcmp( &ctx, &ctx_update1 ), "update doesn't work correctly\n" );
94 
95  pMD5Update( &ctx, message, size );
96  ok( !ctxcmp( &ctx, &ctx_update2 ), "update doesn't work correctly\n" );
97 
98  pMD5Final( &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 START_TEST(crypt_md5)
104 {
105  test_md5_ctx();
106 }
Definition: tftpd.h:59
HMODULE module
Definition: main.cpp:47
static const unsigned char const int len
Definition: crypt_md5.c:37
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:5579
static const unsigned char * src
Definition: crypt_md5.c:37
struct tagMD5_CTX MD5_CTX
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
#define ctxcmp(a, b)
Definition: crypt_md5.c:40
GLsizeiptr size
Definition: glext.h:5919
START_TEST(crypt_md5)
Definition: crypt_md5.c:103
unsigned char digest[16]
Definition: msi.c:4083
#define WINAPI
Definition: msvc.h:8
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
static VOID(WINAPI *pMD5Init)(MD5_CTX *ctx)
GLuint in
Definition: glext.h:9616
#define ok(value,...)
Definition: atltest.h:57
#define expect(expected, got)
Definition: combo.c:36
static void test_md5_ctx(void)
Definition: crypt_md5.c:42
#define GetProcAddress(x, y)
Definition: compat.h:418
Definition: msi.c:4078
#define memset(x, y, z)
Definition: compat.h:39
#define win_skip
Definition: test.h:150