1 |
/* |
2 |
* Copyright (C) 1998,1999,2000 Nikos Mavroyanopoulos |
3 |
* |
4 |
* This program is free software; you can redistribute it and/or modify |
5 |
* it under the terms of the GNU General Public License as published by |
6 |
* the Free Software Foundation; either version 2 of the License, or |
7 |
* (at your option) any later version. |
8 |
* |
9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
* GNU General Public License for more details. |
13 |
* |
14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
16 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 |
*/ |
18 |
|
19 |
#include "../lib/mcrypt.h" |
20 |
#include <stdio.h> |
21 |
#include <string.h> |
22 |
#include <stdlib.h> |
23 |
|
24 |
/* $Id: key_test.c,v 1.3 2000/02/08 12:14:54 nikos Exp $ */ |
25 |
|
26 |
/* #define DEBUG */ |
27 |
|
28 |
char test0[2][500]; |
29 |
|
30 |
int main() |
31 |
{ |
32 |
|
33 |
int i; |
34 |
int j, x = 0; |
35 |
unsigned char *keyword; |
36 |
unsigned char cipher_tmp[1024]; |
37 |
unsigned char password[]="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; |
38 |
|
39 |
printf("Checking whether the key generation work normally\n"); |
40 |
|
41 |
/* Test vectors with key and plaintext == zero */ |
42 |
strcpy(test0[0], "84983e441c3bd26ebaae4aa1f95129e5e54670f17eb56d121b47824bf794d1fbc880e6f74dc01a93627ddea4268da4ee41b7a74000805b64e73a9d30e9e1fc03aeff576a543e50f5c5f25d404d96248b0762c374b8ca9ee6214d55e9de2d2aefab0e3b87d67c83654d506b4730115dc98bf9fc25712d4ad40a99722c3f652307"); |
43 |
strcpy(test0[1], "8215ef0796a20bcaaae116d3876c664ab5d4e00eef0f452f228d33518d1b9ebe9fecc659fd50fdfdcde8101de053c71e64e03358f3c631e05e74b2d4ec94300d02bc6461f35e7ea0fcd5793e4465ab0bf24ff5fee1fc8b901cb90b2684fafbb91f608e5a393af36f3de99fc380aa6e5f56dba13cef7fb1b01e35139f45bf6d7e"); |
44 |
bzero(cipher_tmp, sizeof(cipher_tmp)); |
45 |
|
46 |
keyword = malloc(128); |
47 |
|
48 |
mcrypt_gen_key("mcrypt-sha1", "../modules/keygen/.libs", keyword, 128, NULL, 0, |
49 |
password, strlen((char*)password)); |
50 |
|
51 |
printf("SHA-1: "); |
52 |
#ifdef DEBUG |
53 |
/* |
54 |
printf("\npassword: "); |
55 |
for (j = 0; j < 128; j++) |
56 |
printf("%.2x", password[j]); |
57 |
printf("\n"); |
58 |
*/ |
59 |
#endif |
60 |
|
61 |
|
62 |
for (j = 0; j < 128; j++) { |
63 |
sprintf(&((char *) cipher_tmp)[2 * j], "%.2x", keyword[j]); |
64 |
} |
65 |
|
66 |
#ifdef DEBUG |
67 |
printf("HASH: "); |
68 |
printf("%s\n", cipher_tmp); |
69 |
#endif |
70 |
|
71 |
if (strcmp( cipher_tmp, test0[0]) != 0) { |
72 |
printf("failed compatibility\n"); |
73 |
x = 1; |
74 |
} else { |
75 |
printf("ok\n"); |
76 |
} |
77 |
|
78 |
mcrypt_gen_key("mcrypt-md5", "../modules/keygen/.libs", keyword, 128, NULL, 0, |
79 |
password, strlen((char*)password)); |
80 |
|
81 |
printf("MD5: "); |
82 |
#ifdef DEBUG |
83 |
/* |
84 |
printf("\npassword: "); |
85 |
for (j = 0; j < 128; j++) { |
86 |
printf("%.2x", password[j]); |
87 |
} |
88 |
printf("\n"); |
89 |
*/ |
90 |
#endif |
91 |
|
92 |
|
93 |
for (j = 0; j < 128; j++) { |
94 |
sprintf(&((char *) cipher_tmp)[2 * j], "%.2x", keyword[j]); |
95 |
} |
96 |
|
97 |
#ifdef DEBUG |
98 |
printf("HASH: "); |
99 |
printf("%s\n", cipher_tmp); |
100 |
#endif |
101 |
|
102 |
if (strcmp( cipher_tmp, test0[1]) != 0) { |
103 |
printf("failed compatibility\n"); |
104 |
x = 1; |
105 |
} else { |
106 |
printf("ok\n"); |
107 |
} |
108 |
|
109 |
|
110 |
free(keyword); |
111 |
|
112 |
return x; |
113 |
|
114 |
} |