comparison src/encauth/ccm/ccm_test.c @ 380:d5faf4814ddb libtomcrypt-orig libtomcrypt-1.16

Update to LibTomCrypt 1.16
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:22:00 +0000
parents 59400faa4b44
children
comparison
equal deleted inserted replaced
280:59400faa4b44 380:d5faf4814ddb
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org 9 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file ccm_test.c 14 @file ccm_test.c
114 114
115 }; 115 };
116 unsigned long taglen, x; 116 unsigned long taglen, x;
117 unsigned char buf[64], buf2[64], tag2[16], tag[16]; 117 unsigned char buf[64], buf2[64], tag2[16], tag[16];
118 int err, idx; 118 int err, idx;
119 symmetric_key skey;
119 120
120 idx = find_cipher("aes"); 121 idx = find_cipher("aes");
121 if (idx == -1) { 122 if (idx == -1) {
122 idx = find_cipher("rijndael"); 123 idx = find_cipher("rijndael");
123 if (idx == -1) { 124 if (idx == -1) {
125 } 126 }
126 } 127 }
127 128
128 for (x = 0; x < (sizeof(tests)/sizeof(tests[0])); x++) { 129 for (x = 0; x < (sizeof(tests)/sizeof(tests[0])); x++) {
129 taglen = tests[x].taglen; 130 taglen = tests[x].taglen;
131 if ((err = cipher_descriptor[idx].setup(tests[x].key, 16, 0, &skey)) != CRYPT_OK) {
132 return err;
133 }
134
130 if ((err = ccm_memory(idx, 135 if ((err = ccm_memory(idx,
131 tests[x].key, 16, 136 tests[x].key, 16,
137 &skey,
132 tests[x].nonce, tests[x].noncelen, 138 tests[x].nonce, tests[x].noncelen,
133 tests[x].header, tests[x].headerlen, 139 tests[x].header, tests[x].headerlen,
134 (unsigned char*)tests[x].pt, tests[x].ptlen, 140 (unsigned char*)tests[x].pt, tests[x].ptlen,
135 buf, 141 buf,
136 tag, &taglen, 0)) != CRYPT_OK) { 142 tag, &taglen, 0)) != CRYPT_OK) {
137 return err; 143 return err;
138 } 144 }
139 145
140 if (memcmp(buf, tests[x].ct, tests[x].ptlen)) { 146 if (XMEMCMP(buf, tests[x].ct, tests[x].ptlen)) {
141 return CRYPT_FAIL_TESTVECTOR; 147 return CRYPT_FAIL_TESTVECTOR;
142 } 148 }
143 if (memcmp(tag, tests[x].tag, tests[x].taglen)) { 149 if (XMEMCMP(tag, tests[x].tag, tests[x].taglen)) {
144 return CRYPT_FAIL_TESTVECTOR; 150 return CRYPT_FAIL_TESTVECTOR;
145 } 151 }
146 152
147 if ((err = ccm_memory(idx, 153 if ((err = ccm_memory(idx,
148 tests[x].key, 16, 154 tests[x].key, 16,
155 NULL,
149 tests[x].nonce, tests[x].noncelen, 156 tests[x].nonce, tests[x].noncelen,
150 tests[x].header, tests[x].headerlen, 157 tests[x].header, tests[x].headerlen,
151 buf2, tests[x].ptlen, 158 buf2, tests[x].ptlen,
152 buf, 159 buf,
153 tag2, &taglen, 1 )) != CRYPT_OK) { 160 tag2, &taglen, 1 )) != CRYPT_OK) {
154 return err; 161 return err;
155 } 162 }
156 163
157 if (memcmp(buf2, tests[x].pt, tests[x].ptlen)) { 164 if (XMEMCMP(buf2, tests[x].pt, tests[x].ptlen)) {
158 return CRYPT_FAIL_TESTVECTOR; 165 return CRYPT_FAIL_TESTVECTOR;
159 } 166 }
160 if (memcmp(tag2, tests[x].tag, tests[x].taglen)) { 167 if (XMEMCMP(tag2, tests[x].tag, tests[x].taglen)) {
161 return CRYPT_FAIL_TESTVECTOR; 168 return CRYPT_FAIL_TESTVECTOR;
162 } 169 }
163 170 cipher_descriptor[idx].done(&skey);
164
165 } 171 }
166 return CRYPT_OK; 172 return CRYPT_OK;
167 #endif 173 #endif
168 } 174 }
169 175
170 #endif 176 #endif
171 177
172 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/ccm/ccm_test.c,v $ */ 178 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/ccm/ccm_test.c,v $ */
173 /* $Revision: 1.4 $ */ 179 /* $Revision: 1.8 $ */
174 /* $Date: 2005/05/05 14:35:58 $ */ 180 /* $Date: 2006/11/21 00:18:23 $ */