comparison modes_test.c @ 15:6362d3854bb4 libtomcrypt-orig

0.96 release of LibTomCrypt
author Matt Johnston <matt@ucc.asn.au>
date Tue, 15 Jun 2004 14:07:21 +0000
parents
children
comparison
equal deleted inserted replaced
3:7faae8f46238 15:6362d3854bb4
1 /* test CFB/OFB/CBC modes */
2 #include "test.h"
3
4 int modes_test(void)
5 {
6 unsigned char pt[64], ct[64], tmp[64], key[16], iv[16];
7 int x, cipher_idx;
8 symmetric_CBC cbc;
9
10 /* make a random pt, key and iv */
11 yarrow_read(pt, 64, &test_yarrow);
12 yarrow_read(key, 16, &test_yarrow);
13 yarrow_read(iv, 16, &test_yarrow);
14
15 /* test CBC mode */
16 cipher_idx = find_cipher("aes");
17 if (cipher_idx == -1) {
18 printf("test requires AES");
19 return 1;
20 }
21
22
23 /* encode the block */
24 DO(cbc_start(cipher_idx, iv, key, 16, 0, &cbc));
25 for (x = 0; x < 4; x++) {
26 DO(cbc_encrypt(pt+x*16, ct+x*16, &cbc));
27 }
28
29 /* decode the block */
30 DO(cbc_start(cipher_idx, iv, key, 16, 0, &cbc));
31 for (x = 0; x < 4; x++) {
32 DO(cbc_decrypt(ct+x*16, tmp+x*16, &cbc));
33 }
34 if (memcmp(tmp, pt, 64) != 0) {
35 printf("CBC failed");
36 return 1;
37 }
38
39 /*
40 extern int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
41 int keylen, int num_rounds, symmetric_CBC *cbc);
42 extern int cbc_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_CBC *cbc);
43 extern int cbc_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_CBC *cbc);
44 */
45
46 }