Mercurial > dropbear
comparison libtomcrypt/testprof/modes_test.c @ 415:8b9aba1d5fa4 channel-fix
merge of '73fe066c5d9e2395354ba74756124d45c978a04d'
and 'f5014cc84558f1e8eba42dbecf9f72f94bfe6134'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 06 Feb 2007 16:00:18 +0000 |
parents | 0cbe8f6dbf9e |
children | f849a5ca2efc |
comparison
equal
deleted
inserted
replaced
414:c53a26c430e5 | 415:8b9aba1d5fa4 |
---|---|
3 | 3 |
4 int modes_test(void) | 4 int modes_test(void) |
5 { | 5 { |
6 unsigned char pt[64], ct[64], tmp[64], key[16], iv[16], iv2[16]; | 6 unsigned char pt[64], ct[64], tmp[64], key[16], iv[16], iv2[16]; |
7 int cipher_idx; | 7 int cipher_idx; |
8 #ifdef LTC_CBC_MODE | |
8 symmetric_CBC cbc; | 9 symmetric_CBC cbc; |
10 #endif | |
11 #ifdef LTC_CFB_MODE | |
9 symmetric_CFB cfb; | 12 symmetric_CFB cfb; |
13 #endif | |
14 #ifdef LTC_OFB_MODE | |
10 symmetric_OFB ofb; | 15 symmetric_OFB ofb; |
11 symmetric_CTR ctr; | 16 #endif |
12 unsigned long l; | 17 unsigned long l; |
13 | 18 |
14 /* make a random pt, key and iv */ | 19 /* make a random pt, key and iv */ |
15 yarrow_read(pt, 64, &yarrow_prng); | 20 yarrow_read(pt, 64, &yarrow_prng); |
16 yarrow_read(key, 16, &yarrow_prng); | 21 yarrow_read(key, 16, &yarrow_prng); |
21 if (cipher_idx == -1) { | 26 if (cipher_idx == -1) { |
22 fprintf(stderr, "test requires AES"); | 27 fprintf(stderr, "test requires AES"); |
23 return 1; | 28 return 1; |
24 } | 29 } |
25 | 30 |
26 #ifdef CBC | 31 #ifdef LTC_F8_MODE |
32 DO(f8_test_mode()); | |
33 #endif | |
34 | |
35 #ifdef LTC_LRW_MODE | |
36 DO(lrw_test()); | |
37 #endif | |
38 | |
39 #ifdef LTC_CBC_MODE | |
27 /* test CBC mode */ | 40 /* test CBC mode */ |
28 /* encode the block */ | 41 /* encode the block */ |
29 DO(cbc_start(cipher_idx, iv, key, 16, 0, &cbc)); | 42 DO(cbc_start(cipher_idx, iv, key, 16, 0, &cbc)); |
30 l = sizeof(iv2); | 43 l = sizeof(iv2); |
31 DO(cbc_getiv(iv2, &l, &cbc)); | 44 DO(cbc_getiv(iv2, &l, &cbc)); |
43 fprintf(stderr, "CBC failed"); | 56 fprintf(stderr, "CBC failed"); |
44 return 1; | 57 return 1; |
45 } | 58 } |
46 #endif | 59 #endif |
47 | 60 |
48 #ifdef CFB | 61 #ifdef LTC_CFB_MODE |
49 /* test CFB mode */ | 62 /* test CFB mode */ |
50 /* encode the block */ | 63 /* encode the block */ |
51 DO(cfb_start(cipher_idx, iv, key, 16, 0, &cfb)); | 64 DO(cfb_start(cipher_idx, iv, key, 16, 0, &cfb)); |
52 l = sizeof(iv2); | 65 l = sizeof(iv2); |
53 DO(cfb_getiv(iv2, &l, &cfb)); | 66 DO(cfb_getiv(iv2, &l, &cfb)); |
66 fprintf(stderr, "CFB failed"); | 79 fprintf(stderr, "CFB failed"); |
67 return 1; | 80 return 1; |
68 } | 81 } |
69 #endif | 82 #endif |
70 | 83 |
71 #ifdef OFB | 84 #ifdef LTC_OFB_MODE |
72 /* test OFB mode */ | 85 /* test OFB mode */ |
73 /* encode the block */ | 86 /* encode the block */ |
74 DO(ofb_start(cipher_idx, iv, key, 16, 0, &ofb)); | 87 DO(ofb_start(cipher_idx, iv, key, 16, 0, &ofb)); |
75 l = sizeof(iv2); | 88 l = sizeof(iv2); |
76 DO(ofb_getiv(iv2, &l, &ofb)); | 89 DO(ofb_getiv(iv2, &l, &ofb)); |
88 fprintf(stderr, "OFB failed"); | 101 fprintf(stderr, "OFB failed"); |
89 return 1; | 102 return 1; |
90 } | 103 } |
91 #endif | 104 #endif |
92 | 105 |
93 #ifdef CTR | 106 #ifdef LTC_CTR_MODE |
94 /* test CTR mode */ | 107 DO(ctr_test()); |
95 /* encode the block */ | |
96 DO(ctr_start(cipher_idx, iv, key, 16, 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr)); | |
97 l = sizeof(iv2); | |
98 DO(ctr_getiv(iv2, &l, &ctr)); | |
99 if (l != 16 || memcmp(iv2, iv, 16)) { | |
100 fprintf(stderr, "ctr_getiv failed"); | |
101 return 1; | |
102 } | |
103 DO(ctr_encrypt(pt, ct, 57, &ctr)); | |
104 | |
105 /* decode the block */ | |
106 DO(ctr_setiv(iv2, l, &ctr)); | |
107 zeromem(tmp, sizeof(tmp)); | |
108 DO(ctr_decrypt(ct, tmp, 57, &ctr)); | |
109 if (memcmp(tmp, pt, 57) != 0) { | |
110 fprintf(stderr, "CTR failed"); | |
111 return 1; | |
112 } | |
113 #endif | 108 #endif |
114 | 109 |
115 return 0; | 110 return 0; |
116 } | 111 } |
117 | 112 |
118 /* $Source: /cvs/libtom/libtomcrypt/testprof/modes_test.c,v $ */ | 113 /* $Source: /cvs/libtom/libtomcrypt/testprof/modes_test.c,v $ */ |
119 /* $Revision: 1.6 $ */ | 114 /* $Revision: 1.14 $ */ |
120 /* $Date: 2005/05/21 12:51:25 $ */ | 115 /* $Date: 2006/11/13 11:55:25 $ */ |