| 1 |
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
| 2 |
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ |
| 3 |
#include "kwsysPrivate.h" |
| 4 |
#include KWSYS_HEADER(MD5.h) |
| 5 |
|
| 6 |
/* Work-around CMake dependency scanning limitation. This must |
| 7 |
duplicate the above list of headers. */ |
| 8 |
#if 0 |
| 9 |
# include "MD5.h.in" |
| 10 |
#endif |
| 11 |
|
| 12 |
#include <stdio.h> |
| 13 |
#include <string.h> |
| 14 |
|
| 15 |
static const unsigned char testMD5input1[] = |
| 16 |
" A quick brown fox jumps over the lazy dog.\n" |
| 17 |
" This is sample text for MD5 sum input.\n"; |
| 18 |
static const char testMD5output1[] = "8f146af46ed4f267921bb937d4d3500c"; |
| 19 |
|
| 20 |
static const int testMD5input2len = 28; |
| 21 |
static const unsigned char testMD5input2[] = "the cow jumped over the moon"; |
| 22 |
static const char testMD5output2[] = "a2ad137b746138fae4e5adca9c85d3ae"; |
| 23 |
|
| 24 |
static int testMD5_1(kwsysMD5* md5) |
| 25 |
{ |
| 26 |
char md5out[33]; |
| 27 |
kwsysMD5_Initialize(md5); |
| 28 |
kwsysMD5_Append(md5, testMD5input1, -1); |
| 29 |
kwsysMD5_FinalizeHex(md5, md5out); |
| 30 |
md5out[32] = 0; |
| 31 |
printf("md5sum 1: expected [%s]\n" |
| 32 |
" got [%s]\n", |
| 33 |
testMD5output1, md5out); |
| 34 |
return (strcmp(md5out, testMD5output1) != 0) ? 1 : 0; |
| 35 |
} |
| 36 |
|
| 37 |
static int testMD5_2(kwsysMD5* md5) |
| 38 |
{ |
| 39 |
unsigned char digest[16]; |
| 40 |
char md5out[33]; |
| 41 |
kwsysMD5_Initialize(md5); |
| 42 |
kwsysMD5_Append(md5, testMD5input2, testMD5input2len); |
| 43 |
kwsysMD5_Finalize(md5, digest); |
| 44 |
kwsysMD5_DigestToHex(digest, md5out); |
| 45 |
md5out[32] = 0; |
| 46 |
printf("md5sum 2: expected [%s]\n" |
| 47 |
" got [%s]\n", |
| 48 |
testMD5output2, md5out); |
| 49 |
return (strcmp(md5out, testMD5output2) != 0) ? 1 : 0; |
| 50 |
} |
| 51 |
|
| 52 |
int testEncode(int argc, char* argv[]) |
| 53 |
{ |
| 54 |
int result = 0; |
| 55 |
(void)argc; |
| 56 |
(void)argv; |
| 57 |
|
| 58 |
/* Test MD5 digest. */ |
| 59 |
{ |
| 60 |
kwsysMD5* md5 = kwsysMD5_New(); |
| 61 |
result |= testMD5_1(md5); |
| 62 |
result |= testMD5_2(md5); |
| 63 |
kwsysMD5_Delete(md5); |
| 64 |
} |
| 65 |
|
| 66 |
return result; |
| 67 |
} |