/[mcrypt]/module-skipjack/src/cipher_test.c
ViewVC logotype

Contents of /module-skipjack/src/cipher_test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Sun Sep 16 18:54:04 2001 UTC (20 years, 2 months ago) by nmav
Branch: MAIN
CVS Tags: libmcrypt_2_4_16, HEAD
Changes since 1.1: +85 -13 lines
File MIME type: text/plain
updated for libmcrypt 2.4.16

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 <mcrypt.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 /* Prints plaintext and ciphertext in hex for all the algorithms */
25
26 #define ALGORITHMS_DIR "../modules/algorithms/.libs"
27 #define MODES_DIR "../modules/modes/.libs"
28 /* #define ALGORITHMS_DIR NULL
29 * #define MODES_DIR NULL
30 */
31 #define TEXT "a small text, just to test the implementation"
32
33 int main()
34 {
35 MCRYPT td, td2;
36 int i, t, imax;
37 int j, jmax, ivsize;
38 int x = 0, siz;
39 char **names;
40 char **modes;
41 char *text;
42 unsigned char *IV;
43 unsigned char *key;
44 int keysize;
45
46 names = mcrypt_list_algorithms (ALGORITHMS_DIR, &jmax);
47 modes = mcrypt_list_modes (MODES_DIR, &imax);
48
49 if (names==NULL || modes==NULL) {
50 fprintf(stderr, "Error getting algorithms/modes\n");
51 exit(1);
52 }
53
54 for (j=0;j<jmax;j++) {
55 printf( "Algorithm: %s... ", names[j]);
56 if (mcrypt_module_self_test( names[j], ALGORITHMS_DIR)==0) {
57 printf( "ok\n");
58 } else {
59 x=1;
60 printf( "\n");
61 }
62
63 printf( "Modes:\n");
64 for (i=0;i<imax;i++) {
65 td = mcrypt_module_open(names[j], ALGORITHMS_DIR, modes[i], MODES_DIR);
66 td2 = mcrypt_module_open(names[j], ALGORITHMS_DIR, modes[i], MODES_DIR);
67 if (td != MCRYPT_FAILED) {
68 keysize = mcrypt_enc_get_key_size(td);
69 key = calloc(1, keysize);
70 for (t=0;t<keysize;t++)
71 key[t] = (t % 255) + 13;
72
73 ivsize = mcrypt_enc_get_iv_size(td);
74 if (ivsize>0) {
75 IV = calloc( 1, ivsize);
76 for (t=0;t<ivsize;t++)
77 IV[t] = (t*2 % 255) + 15;
78 }
79 if (mcrypt_generic_init( td, key, keysize, IV) < 0) {
80 fprintf(stderr, "Failed to Initialize algorithm!\n");
81 return -1;
82 }
83
84 siz = (strlen(TEXT) / mcrypt_enc_get_block_size(td))*mcrypt_enc_get_block_size(td);
85 text = calloc( 1, siz);
86 memmove( text, TEXT, siz);
87
88 mcrypt_generic( td, text, siz);
89
90 if (mcrypt_generic_init( td2, key, keysize, IV) < 0) {
91 fprintf(stderr, "Failed to Initialize algorithm!\n");
92 return -1;
93 }
94
95 mdecrypt_generic( td2, text, siz);
96 if ( memcmp( text, TEXT, siz) == 0) {
97 printf( " %s: ok\n", modes[i]);
98 } else {
99 printf( " %s: failed\n", modes[i]);
100 x=1;
101 }
102 mcrypt_generic_deinit(td);
103 mcrypt_generic_deinit(td2);
104 mcrypt_module_close(td);
105 mcrypt_module_close(td2); free(text);
106 free(key);
107 if (ivsize>0) free(IV);
108 }
109 }
110 printf("\n");
111
112 }
113 mcrypt_free_p(names, jmax);
114 mcrypt_free_p(modes, imax);
115
116
117 if (x>0) fprintf(stderr, "\nProbably some of the algorithms listed above failed. "
118 "Try not to use these algorithms, and file a bug report to mcrypt-dev@lists.hellug.gr\n\n");
119 return x;
120 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26