/[mcrypt]/libmcrypt-nm/src/mode_test.c
ViewVC logotype

Contents of /libmcrypt-nm/src/mode_test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Mon May 22 13:09:19 2000 UTC (23 years, 10 months ago) by nmav
Branch: MAIN, mcrypt
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/plain

1 #include "../lib/mcrypt-nm.h"
2 #include <stdio.h>
3 #include <strings.h>
4 #include <stdlib.h>
5
6 /* $Id: mode_test.c,v 1.2 1999/10/16 15:18:14 nmav Exp $ */
7
8 /* Prints plaintext and ciphertext in hex for all the algorithms */
9
10 int main()
11 {
12
13 MCRYPT td, td2;
14 int i;
15 int x = 0, mode;
16 char *keyword = NULL;
17 unsigned char *plaintext;
18 unsigned char *ciphertext;
19 unsigned char cipher_tmp[200];
20 unsigned char *IV;
21 char *name, *name2;
22
23 printf("Checking whether the algorithm's modes work normally\n");
24
25 for (i = 0; i <= 150; i++) {
26 for (mode = 0; mode < 6; mode++) {
27
28 if (mcrypt_is_ok_algorithm(i) != 0)
29 continue;
30 if (mcrypt_is_ok_mode(mode) != 0)
31 continue;
32
33 if (mcrypt_is_block_algorithm(i) == 0) {
34 if (mode!=0) continue;
35
36 keyword = malloc(24);
37 strcpy(keyword, "Ena poly megalo keyword");
38
39 bzero(cipher_tmp, sizeof(cipher_tmp));
40 td =
41 mcrypt_generic_init(MCRYPT_STREAM, i,
42 keyword, 24, NULL);
43
44 td2 =
45 mcrypt_generic_init(MCRYPT_STREAM, i,
46 keyword, 24, NULL);
47
48 if (td == MCRYPT_FAILED)
49 continue;
50
51 name = mcrypt_get_algorithms_name(i);
52 if (name == NULL)
53 continue;
54 printf("Algorithm: %s... ", name);
55
56 printf("Mode: STREAM... ");
57
58
59 ciphertext = malloc(10);
60 plaintext = malloc(10);
61 bzero(plaintext, 10);
62 bzero(ciphertext, 10);
63
64 #ifdef DEBUG
65 printf("\nplaintext: ");
66 for (j = 0; j < 10; j++) {
67 printf("%.2x", ciphertext[j]);
68 }
69 #endif
70
71 #ifdef DEBUG
72 printf("\nkeyword: ");
73 for (j = 0; j < 24; j++) {
74 printf("%.2x", keyword[j]);
75 }
76 #endif
77
78 mcrypt_generic(td, ciphertext, 10);
79
80 mdecrypt_generic(td2, ciphertext, 10);
81
82 #ifdef DEBUG
83 printf("\nplaintext: ");
84 for (j = 0; j < 10; j++) {
85 printf("%.2x", ciphertext[j]);
86 }
87 printf("\n");
88 #endif
89
90 if (memcmp(ciphertext, plaintext, 10) != 0) {
91 printf("failed internally\n");
92 x = 1;
93 mcrypt_generic_end(td);
94 mcrypt_generic_end(td2);
95 free(name);
96 free(keyword);
97 free(ciphertext);
98 free(plaintext);
99 continue;
100 }
101 printf("ok\n");
102
103 mcrypt_generic_end(td);
104 mcrypt_generic_end(td2);
105 free(name);
106 free(keyword);
107 free(ciphertext);
108 free(plaintext);
109
110 continue;
111 }
112 IV = malloc(mcrypt_get_block_size(i));
113 memset(IV, '\234', mcrypt_get_block_size(i));
114 memset(IV, '\123', mcrypt_get_block_size(i) / 2);
115 memset(IV, '\53', mcrypt_get_block_size(i) / 4);
116
117 keyword = malloc(mcrypt_get_key_size(i));
118 memset(keyword, '\2', mcrypt_get_key_size(i));
119 memset(keyword, '\3', mcrypt_get_key_size(i) / 2);
120 memset(keyword, '\5', mcrypt_get_key_size(i) / 4);
121
122 bzero(cipher_tmp, sizeof(cipher_tmp));
123 td =
124 mcrypt_generic_init(mode, i, keyword,
125 mcrypt_get_key_size(i),
126 IV);
127
128 if (td == MCRYPT_FAILED)
129 continue;
130
131 name = mcrypt_get_algorithms_name(i);
132 if (name == NULL)
133 continue;
134 printf("Algorithm: %s... ", name);
135
136 name2 = mcrypt_get_modes_name(mode);
137 if (name2 == NULL)
138 continue;
139 printf("Mode: %s... ", name2);
140
141
142 ciphertext = malloc(mcrypt_get_block_size(i));
143 plaintext = malloc(mcrypt_get_block_size(i));
144 bzero(plaintext, mcrypt_get_block_size(i));
145 bzero(ciphertext, mcrypt_get_block_size(i));
146
147 #ifdef DEBUG
148 printf("plaintext: ");
149 for (j = 0; j < mcrypt_get_block_size(i); j++) {
150 printf("%.2x", ciphertext[j]);
151 }
152 #endif
153
154 #ifdef DEBUG
155 printf("\nkeyword: ");
156 for (j = 0; j < mcrypt_get_key_size(i); j++) {
157 printf("%.2x", keyword[j]);
158 }
159 #endif
160
161 mcrypt_generic(td, ciphertext,
162 mcrypt_get_block_size(i));
163
164 mdecrypt_generic(td, ciphertext,
165 mcrypt_get_block_size(i));
166
167 if (memcmp
168 (ciphertext, plaintext,
169 mcrypt_get_block_size(i)) != 0) {
170 printf("failed internally\n");
171 x = 1;
172 mcrypt_generic_end(td);
173 free(IV);
174 free(name2);
175 free(name);
176 free(keyword);
177 free(ciphertext);
178 free(plaintext);
179 continue;
180 }
181 printf("ok\n");
182
183 mcrypt_generic_end(td);
184 free(IV);
185 free(name2);
186 free(name);
187 free(keyword);
188 free(ciphertext);
189 free(plaintext);
190 }
191 }
192 return x;
193
194 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26