10 #include "../cipher.h"
12 /******************************************************************************
14 *****************************************************************************/
15 #define MD4_TEST(data, digest) { \
16 PurpleCipher *cipher = NULL; \
17 PurpleCipherContext *context = NULL; \
19 gboolean ret = FALSE; \
21 cipher = purple_ciphers_find_cipher("md4"); \
22 context = purple_cipher_context_new(cipher, NULL); \
23 purple_cipher_context_append(context, (guchar *)(data), strlen((data))); \
25 ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
28 fail_unless(ret == TRUE, NULL); \
30 fail_unless(purple_strequal((digest), cdigest), NULL); \
32 purple_cipher_context_destroy(context); \
35 START_TEST(test_md4_empty_string
) {
36 MD4_TEST("", "31d6cfe0d16ae931b73c59d7e0c089c0");
40 START_TEST(test_md4_a
) {
41 MD4_TEST("a", "bde52cb31de33e46245e05fbdbd6fb24");
45 START_TEST(test_md4_abc
) {
46 MD4_TEST("abc", "a448017aaf21d8525fc10ae87aa6729d");
50 START_TEST(test_md4_message_digest
) {
51 MD4_TEST("message digest", "d9130a8164549fe818874806e1c7014b");
55 START_TEST(test_md4_a_to_z
) {
56 MD4_TEST("abcdefghijklmnopqrstuvwxyz",
57 "d79e1c308aa5bbcdeea8ed63df412da9");
61 START_TEST(test_md4_A_to_Z_a_to_z_0_to_9
) {
62 MD4_TEST("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
63 "043f8582f241db351ce627e153e7f0e4");
67 START_TEST(test_md4_1_to_0_8_times
) {
68 MD4_TEST("123456789012345678901234567890123456789012345678901234567890"
69 "12345678901234567890",
70 "e33b4ddc9c38f2199c3e7b164fcc0536");
75 /******************************************************************************
77 *****************************************************************************/
78 #define MD5_TEST(data, digest) { \
79 PurpleCipher *cipher = NULL; \
80 PurpleCipherContext *context = NULL; \
82 gboolean ret = FALSE; \
84 cipher = purple_ciphers_find_cipher("md5"); \
85 context = purple_cipher_context_new(cipher, NULL); \
86 purple_cipher_context_append(context, (guchar *)(data), strlen((data))); \
88 ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
91 fail_unless(ret == TRUE, NULL); \
93 fail_unless(purple_strequal((digest), cdigest), NULL); \
95 purple_cipher_context_destroy(context); \
98 START_TEST(test_md5_empty_string
) {
99 MD5_TEST("", "d41d8cd98f00b204e9800998ecf8427e");
103 START_TEST(test_md5_a
) {
104 MD5_TEST("a", "0cc175b9c0f1b6a831c399e269772661");
108 START_TEST(test_md5_abc
) {
109 MD5_TEST("abc", "900150983cd24fb0d6963f7d28e17f72");
113 START_TEST(test_md5_message_digest
) {
114 MD5_TEST("message digest", "f96b697d7cb7938d525a2f31aaf161d0");
118 START_TEST(test_md5_a_to_z
) {
119 MD5_TEST("abcdefghijklmnopqrstuvwxyz",
120 "c3fcd3d76192e4007dfb496cca67e13b");
124 START_TEST(test_md5_A_to_Z_a_to_z_0_to_9
) {
125 MD5_TEST("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
126 "d174ab98d277d9f5a5611c2c9f419d9f");
130 START_TEST(test_md5_1_to_0_8_times
) {
131 MD5_TEST("123456789012345678901234567890123456789012345678901234567890"
132 "12345678901234567890",
133 "57edf4a22be3c955ac49da2e2107b67a");
137 /******************************************************************************
139 *****************************************************************************/
140 #define SHA1_TEST(data, digest) { \
141 PurpleCipher *cipher = NULL; \
142 PurpleCipherContext *context = NULL; \
144 gboolean ret = FALSE; \
145 gchar *input = data; \
147 cipher = purple_ciphers_find_cipher("sha1"); \
148 context = purple_cipher_context_new(cipher, NULL); \
151 purple_cipher_context_append(context, (guchar *)input, strlen(input)); \
156 memset(buff, 'a', 1000); \
158 for(j = 0; j < 1000; j++) \
159 purple_cipher_context_append(context, buff, 1000); \
162 ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
165 fail_unless(ret == TRUE, NULL); \
167 fail_unless(purple_strequal((digest), cdigest), NULL); \
169 purple_cipher_context_destroy(context); \
172 START_TEST(test_sha1_empty_string
) {
173 SHA1_TEST("", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
177 START_TEST(test_sha1_a
) {
178 SHA1_TEST("a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");
182 START_TEST(test_sha1_abc
) {
183 SHA1_TEST("abc", "a9993e364706816aba3e25717850c26c9cd0d89d");
187 START_TEST(test_sha1_abcd_gibberish
) {
188 SHA1_TEST("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
189 "84983e441c3bd26ebaae4aa1f95129e5e54670f1");
193 START_TEST(test_sha1_1000_as_1000_times
) {
194 SHA1_TEST(NULL
, "34aa973cd4c4daa4f61eeb2bdbad27316534016f");
198 /******************************************************************************
200 *****************************************************************************/
201 #define SHA256_TEST(data, digest) { \
202 PurpleCipher *cipher = NULL; \
203 PurpleCipherContext *context = NULL; \
205 gboolean ret = FALSE; \
206 gchar *input = data; \
208 cipher = purple_ciphers_find_cipher("sha256"); \
209 context = purple_cipher_context_new(cipher, NULL); \
212 purple_cipher_context_append(context, (guchar *)input, strlen(input)); \
217 memset(buff, 'a', 1000); \
219 for(j = 0; j < 1000; j++) \
220 purple_cipher_context_append(context, buff, 1000); \
223 ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
226 fail_unless(ret == TRUE, NULL); \
228 fail_unless(purple_strequal((digest), cdigest), NULL); \
230 purple_cipher_context_destroy(context); \
233 START_TEST(test_sha256_empty_string
) {
234 SHA256_TEST("", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
238 START_TEST(test_sha256_a
) {
239 SHA256_TEST("a", "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb");
243 START_TEST(test_sha256_abc
) {
244 SHA256_TEST("abc", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
248 START_TEST(test_sha256_abcd_gibberish
) {
249 SHA256_TEST("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
250 "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
254 START_TEST(test_sha256_1000_as_1000_times
) {
255 SHA256_TEST(NULL
, "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0");
259 /******************************************************************************
261 *****************************************************************************/
262 #define DES_TEST(in, keyz, out, len) { \
263 PurpleCipher *cipher = NULL; \
264 PurpleCipherContext *context = NULL; \
265 guchar answer[len+1]; \
267 guchar decrypt[len+1] = in; \
268 guchar key[8+1] = keyz;\
269 guchar encrypt[len+1] = out;\
272 cipher = purple_ciphers_find_cipher("des"); \
273 context = purple_cipher_context_new(cipher, NULL); \
274 purple_cipher_context_set_key(context, key); \
276 ret = purple_cipher_context_encrypt(context, decrypt, len, answer, &outlen); \
277 fail_unless(ret == 0, NULL); \
278 fail_unless(outlen == (len), NULL); \
279 fail_unless(memcmp(encrypt, answer, len) == 0, NULL); \
281 ret = purple_cipher_context_decrypt(context, encrypt, len, answer, &outlen); \
282 fail_unless(ret == 0, NULL); \
283 fail_unless(outlen == (len), NULL); \
284 fail_unless(memcmp(decrypt, answer, len) == 0, NULL); \
286 purple_cipher_context_destroy(context); \
289 START_TEST(test_des_12345678
) {
291 "\x3b\x38\x98\x37\x15\x20\xf7\x5e",
292 "\x06\x22\x05\xac\x6a\x0d\x55\xdd",
297 START_TEST(test_des_abcdefgh
) {
299 "\x3b\x38\x98\x37\x15\x20\xf7\x5e",
300 "\x62\xe0\xc6\x8c\x48\xe4\x75\xed",
305 /******************************************************************************
307 * See http://csrc.nist.gov/groups/ST/toolkit/examples.html
308 * and some NULL things I made up
309 *****************************************************************************/
311 #define DES3_TEST(in, key, iv, out, len, mode) { \
312 PurpleCipher *cipher = NULL; \
313 PurpleCipherContext *context = NULL; \
314 guchar answer[len+1]; \
315 guchar decrypt[len+1] = in; \
316 guchar encrypt[len+1] = out; \
320 cipher = purple_ciphers_find_cipher("des3"); \
321 context = purple_cipher_context_new(cipher, NULL); \
322 purple_cipher_context_set_key(context, (guchar *)key); \
323 purple_cipher_context_set_batch_mode(context, (mode)); \
324 purple_cipher_context_set_iv(context, (guchar *)iv, 8); \
326 ret = purple_cipher_context_encrypt(context, decrypt, len, answer, &outlen); \
327 fail_unless(ret == 0, NULL); \
328 fail_unless(outlen == (len), NULL); \
329 fail_unless(memcmp(encrypt, answer, len) == 0, NULL); \
331 ret = purple_cipher_context_decrypt(context, encrypt, len, answer, &outlen); \
332 fail_unless(ret == 0, NULL); \
333 fail_unless(outlen == (len), NULL); \
334 fail_unless(memcmp(decrypt, answer, len) == 0, NULL); \
336 purple_cipher_context_destroy(context); \
339 START_TEST(test_des3_ecb_nist1
) {
341 "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A"
342 "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51",
343 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
344 "\x23\x45\x67\x89\xAB\xCD\xEF\x01"
345 "\x45\x67\x89\xAB\xCD\xEF\x01\x23",
346 "00000000", /* ignored */
347 "\x71\x47\x72\xF3\x39\x84\x1D\x34\x26\x7F\xCC\x4B\xD2\x94\x9C\xC3"
348 "\xEE\x11\xC2\x2A\x57\x6A\x30\x38\x76\x18\x3F\x99\xC0\xB6\xDE\x87",
350 PURPLE_CIPHER_BATCH_MODE_ECB
);
354 START_TEST(test_des3_ecb_nist2
) {
356 "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A"
357 "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51",
358 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
359 "\x23\x45\x67\x89\xAB\xCD\xEF\x01"
360 "\x01\x23\x45\x67\x89\xAB\xCD\xEF",
361 "00000000", /* ignored */
362 "\x06\xED\xE3\xD8\x28\x84\x09\x0A\xFF\x32\x2C\x19\xF0\x51\x84\x86"
363 "\x73\x05\x76\x97\x2A\x66\x6E\x58\xB6\xC8\x8C\xF1\x07\x34\x0D\x3D",
365 PURPLE_CIPHER_BATCH_MODE_ECB
);
369 START_TEST(test_des3_ecb_null_key
) {
371 "\x16\xf4\xb3\x77\xfd\x4b\x9e\xca",
372 "\x38\x00\x88\x6a\xef\xcb\x00\xad"
373 "\x5d\xe5\x29\x00\x7d\x98\x64\x4c"
374 "\x86\x00\x7b\xd3\xc7\x00\x7b\x32",
375 "00000000", /* ignored */
376 "\xc0\x60\x30\xa1\xb7\x25\x42\x44",
378 PURPLE_CIPHER_BATCH_MODE_ECB
);
382 START_TEST(test_des3_ecb_null_text
) {
384 "\x65\x73\x34\xc1\x19\x00\x79\x65",
385 "\x32\x64\xda\x10\x13\x6a\xfe\x1e"
386 "\x37\x54\xd1\x2c\x41\x04\x10\x40"
387 "\xaf\x1c\x75\x2b\x51\x3a\x03\xf5",
388 "00000000", /* ignored */
389 "\xe5\x80\xf6\x12\xf8\x4e\xd9\x6c",
391 PURPLE_CIPHER_BATCH_MODE_ECB
);
395 START_TEST(test_des3_ecb_null_key_and_text
) {
397 "\xdf\x7f\x00\x92\xe7\xc1\x49\xd2",
398 "\x0e\x41\x00\xc4\x8b\xf0\x6e\xa1"
399 "\x66\x49\x42\x63\x22\x00\xf0\x99"
400 "\x6b\x22\xc1\x37\x9c\x00\xe4\x8f",
401 "00000000", /* ignored */
402 "\x73\xd8\x1f\x1f\x50\x01\xe4\x79",
404 PURPLE_CIPHER_BATCH_MODE_ECB
);
408 START_TEST(test_des3_cbc_nist1
) {
410 "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A"
411 "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51",
412 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
413 "\x23\x45\x67\x89\xAB\xCD\xEF\x01"
414 "\x45\x67\x89\xAB\xCD\xEF\x01\x23",
415 "\xF6\x9F\x24\x45\xDF\x4F\x9B\x17",
416 "\x20\x79\xC3\xD5\x3A\xA7\x63\xE1\x93\xB7\x9E\x25\x69\xAB\x52\x62"
417 "\x51\x65\x70\x48\x1F\x25\xB5\x0F\x73\xC0\xBD\xA8\x5C\x8E\x0D\xA7",
419 PURPLE_CIPHER_BATCH_MODE_CBC
);
423 START_TEST(test_des3_cbc_nist2
) {
425 "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A"
426 "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51",
427 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
428 "\x23\x45\x67\x89\xAB\xCD\xEF\x01"
429 "\x01\x23\x45\x67\x89\xAB\xCD\xEF",
430 "\xF6\x9F\x24\x45\xDF\x4F\x9B\x17",
431 "\x74\x01\xCE\x1E\xAB\x6D\x00\x3C\xAF\xF8\x4B\xF4\x7B\x36\xCC\x21"
432 "\x54\xF0\x23\x8F\x9F\xFE\xCD\x8F\x6A\xCF\x11\x83\x92\xB4\x55\x81",
434 PURPLE_CIPHER_BATCH_MODE_CBC
);
438 START_TEST(test_des3_cbc_null_key
) {
440 "\x16\xf4\xb3\x77\xfd\x4b\x9e\xca",
441 "\x38\x00\x88\x6a\xef\xcb\x00\xad"
442 "\x5d\xe5\x29\x00\x7d\x98\x64\x4c"
443 "\x86\x00\x7b\xd3\xc7\x00\x7b\x32",
444 "\x31\x32\x33\x34\x35\x36\x37\x38",
445 "\x52\xe7\xde\x96\x39\x87\x87\xdb",
447 PURPLE_CIPHER_BATCH_MODE_CBC
);
451 START_TEST(test_des3_cbc_null_text
) {
453 "\x65\x73\x34\xc1\x19\x00\x79\x65",
454 "\x32\x64\xda\x10\x13\x6a\xfe\x1e"
455 "\x37\x54\xd1\x2c\x41\x04\x10\x40"
456 "\xaf\x1c\x75\x2b\x51\x3a\x03\xf5",
457 "\x7C\xAF\x0D\x57\x1E\x57\x10\xDA",
458 "\x40\x12\x0e\x00\x85\xff\x6c\xc2",
460 PURPLE_CIPHER_BATCH_MODE_CBC
);
464 START_TEST(test_des3_cbc_null_key_and_text
) {
466 "\xdf\x7f\x00\x92\xe7\xc1\x49\xd2",
467 "\x0e\x41\x00\xc4\x8b\xf0\x6e\xa1"
468 "\x66\x49\x42\x63\x22\x00\xf0\x99"
469 "\x6b\x22\xc1\x37\x9c\x00\xe4\x8f",
470 "\x01\x19\x0D\x2c\x40\x67\x89\x67",
471 "\xa7\xc1\x10\xbe\x9b\xd5\x8a\x67",
473 PURPLE_CIPHER_BATCH_MODE_CBC
);
477 /******************************************************************************
479 * See RFC2202 and some other NULL tests I made up
480 *****************************************************************************/
482 #define HMAC_TEST(data, data_len, key, key_len, type, digest) { \
483 PurpleCipher *cipher = NULL; \
484 PurpleCipherContext *context = NULL; \
486 gboolean ret = FALSE; \
488 cipher = purple_ciphers_find_cipher("hmac"); \
489 context = purple_cipher_context_new(cipher, NULL); \
490 purple_cipher_context_set_option(context, "hash", type); \
491 purple_cipher_context_set_key_with_len(context, (guchar *)key, (key_len)); \
493 purple_cipher_context_append(context, (guchar *)(data), (data_len)); \
494 ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
497 fail_unless(ret == TRUE, NULL); \
498 fail_unless(purple_strequal((digest), cdigest), NULL); \
500 purple_cipher_context_destroy(context); \
505 START_TEST(test_hmac_md5_Hi
) {
506 HMAC_TEST("Hi There",
508 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
511 "9294727a3638bb1c13f48ef8158bfc9d");
515 START_TEST(test_hmac_md5_what
) {
516 HMAC_TEST("what do ya want for nothing?",
521 "750c783e6ab0b503eaa86e310a5db738");
525 START_TEST(test_hmac_md5_dd
) {
526 HMAC_TEST("\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
527 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
528 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
529 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
530 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
532 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
535 "56be34521d144c88dbb8c733f0e8b3f6");
539 START_TEST(test_hmac_md5_cd
) {
540 HMAC_TEST("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
541 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
542 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
543 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
544 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
546 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
547 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
548 "\x15\x16\x17\x18\x19",
551 "697eaf0aca3a3aea3a75164746ffaa79");
555 START_TEST(test_hmac_md5_truncation
) {
556 HMAC_TEST("Test With Truncation",
558 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
561 "56461ef2342edc00f9bab995690efd4c");
565 START_TEST(test_hmac_md5_large_key
) {
566 HMAC_TEST("Test Using Larger Than Block-Size Key - Hash Key First",
568 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
569 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
570 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
571 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
572 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
573 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
574 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
575 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
578 "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd");
582 START_TEST(test_hmac_md5_large_key_and_data
) {
583 HMAC_TEST("Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
585 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
586 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
587 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
588 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
589 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
590 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
591 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
592 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
595 "6f630fad67cda0ee1fb1f562db3aa53e");
599 START_TEST(test_hmac_md5_null_key
) {
600 HMAC_TEST("Hi There",
602 "\x0a\x0b\x00\x0d\x0e\x0f\x1a\x2f\x0b\x0b"
603 "\x0b\x00\x00\x0b\x0b\x49\x5f\x6e\x0b\x0b",
606 "597bfd644b797a985561eeb03a169e59");
610 START_TEST(test_hmac_md5_null_text
) {
611 HMAC_TEST("Hi\x00There",
613 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
614 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
617 "70be8e1b7b50dfcc335d6cd7992c564f");
621 START_TEST(test_hmac_md5_null_key_and_text
) {
622 HMAC_TEST("Hi\x00Th\x00re",
624 "\x0c\x0d\x00\x0f\x10\x1a\x3a\x3a\xe6\x34"
625 "\x0b\x00\x00\x0b\x0b\x49\x5f\x6e\x0b\x0b",
628 "b31bcbba35a33a067cbba9131cba4889");
634 START_TEST(test_hmac_sha1_Hi
) {
635 HMAC_TEST("Hi There",
637 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
638 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
641 "b617318655057264e28bc0b6fb378c8ef146be00");
645 START_TEST(test_hmac_sha1_what
) {
646 HMAC_TEST("what do ya want for nothing?",
651 "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79");
655 START_TEST(test_hmac_sha1_dd
) {
656 HMAC_TEST("\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
657 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
658 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
659 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
660 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
662 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
663 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
666 "125d7342b9ac11cd91a39af48aa17b4f63f175d3");
670 START_TEST(test_hmac_sha1_cd
) {
671 HMAC_TEST("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
672 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
673 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
674 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
675 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
677 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
678 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
679 "\x15\x16\x17\x18\x19",
682 "4c9007f4026250c6bc8414f9bf50c86c2d7235da");
686 START_TEST(test_hmac_sha1_truncation
) {
687 HMAC_TEST("Test With Truncation",
689 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
690 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
693 "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04");
697 START_TEST(test_hmac_sha1_large_key
) {
698 HMAC_TEST("Test Using Larger Than Block-Size Key - Hash Key First",
700 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
701 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
702 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
703 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
704 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
705 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
706 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
707 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
710 "aa4ae5e15272d00e95705637ce8a3b55ed402112");
714 START_TEST(test_hmac_sha1_large_key_and_data
) {
715 HMAC_TEST("Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
717 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
718 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
719 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
720 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
721 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
722 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
723 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
724 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
727 "e8e99d0f45237d786d6bbaa7965c7808bbff1a91");
731 START_TEST(test_hmac_sha1_null_key
) {
732 HMAC_TEST("Hi There",
734 "\x0a\x0b\x00\x0d\x0e\x0f\x1a\x2f\x0b\x0b"
735 "\x0b\x00\x00\x0b\x0b\x49\x5f\x6e\x0b\x0b",
738 "eb62a2e0e33d300be669c52aab3f591bc960aac5");
742 START_TEST(test_hmac_sha1_null_text
) {
743 HMAC_TEST("Hi\x00There",
745 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
746 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
749 "31ca58d849e971e418e3439de2c6f83144b6abb7");
753 START_TEST(test_hmac_sha1_null_key_and_text
) {
754 HMAC_TEST("Hi\x00Th\x00re",
756 "\x0c\x0d\x00\x0f\x10\x1a\x3a\x3a\xe6\x34"
757 "\x0b\x00\x00\x0b\x0b\x49\x5f\x6e\x0b\x0b",
760 "e6b8e2fede87aa09dcb13e554df1435e056eae36");
764 /******************************************************************************
766 *****************************************************************************/
769 Suite
*s
= suite_create("Cipher Suite");
773 tc
= tcase_create("MD4");
774 tcase_add_test(tc
, test_md4_empty_string
);
775 tcase_add_test(tc
, test_md4_a
);
776 tcase_add_test(tc
, test_md4_abc
);
777 tcase_add_test(tc
, test_md4_message_digest
);
778 tcase_add_test(tc
, test_md4_a_to_z
);
779 tcase_add_test(tc
, test_md4_A_to_Z_a_to_z_0_to_9
);
780 tcase_add_test(tc
, test_md4_1_to_0_8_times
);
781 suite_add_tcase(s
, tc
);
784 tc
= tcase_create("MD5");
785 tcase_add_test(tc
, test_md5_empty_string
);
786 tcase_add_test(tc
, test_md5_a
);
787 tcase_add_test(tc
, test_md5_abc
);
788 tcase_add_test(tc
, test_md5_message_digest
);
789 tcase_add_test(tc
, test_md5_a_to_z
);
790 tcase_add_test(tc
, test_md5_A_to_Z_a_to_z_0_to_9
);
791 tcase_add_test(tc
, test_md5_1_to_0_8_times
);
792 suite_add_tcase(s
, tc
);
795 tc
= tcase_create("SHA1");
796 tcase_add_test(tc
, test_sha1_empty_string
);
797 tcase_add_test(tc
, test_sha1_a
);
798 tcase_add_test(tc
, test_sha1_abc
);
799 tcase_add_test(tc
, test_sha1_abcd_gibberish
);
800 tcase_add_test(tc
, test_sha1_1000_as_1000_times
);
801 suite_add_tcase(s
, tc
);
804 tc
= tcase_create("SHA256");
805 tcase_add_test(tc
, test_sha256_empty_string
);
806 tcase_add_test(tc
, test_sha256_a
);
807 tcase_add_test(tc
, test_sha256_abc
);
808 tcase_add_test(tc
, test_sha256_abcd_gibberish
);
809 tcase_add_test(tc
, test_sha256_1000_as_1000_times
);
810 suite_add_tcase(s
, tc
);
813 tc
= tcase_create("DES");
814 tcase_add_test(tc
, test_des_12345678
);
815 tcase_add_test(tc
, test_des_abcdefgh
);
816 suite_add_tcase(s
, tc
);
819 tc
= tcase_create("DES3 ECB");
820 tcase_add_test(tc
, test_des3_ecb_nist1
);
821 tcase_add_test(tc
, test_des3_ecb_nist2
);
822 tcase_add_test(tc
, test_des3_ecb_null_key
);
823 tcase_add_test(tc
, test_des3_ecb_null_text
);
824 tcase_add_test(tc
, test_des3_ecb_null_key_and_text
);
825 suite_add_tcase(s
, tc
);
827 tc
= tcase_create("DES3 CBC");
828 tcase_add_test(tc
, test_des3_cbc_nist1
);
829 tcase_add_test(tc
, test_des3_cbc_nist2
);
830 tcase_add_test(tc
, test_des3_cbc_null_key
);
831 tcase_add_test(tc
, test_des3_cbc_null_text
);
832 tcase_add_test(tc
, test_des3_cbc_null_key_and_text
);
833 suite_add_tcase(s
, tc
);
836 tc
= tcase_create("HMAC");
837 tcase_add_test(tc
, test_hmac_md5_Hi
);
838 tcase_add_test(tc
, test_hmac_md5_what
);
839 tcase_add_test(tc
, test_hmac_md5_dd
);
840 tcase_add_test(tc
, test_hmac_md5_cd
);
841 tcase_add_test(tc
, test_hmac_md5_truncation
);
842 tcase_add_test(tc
, test_hmac_md5_large_key
);
843 tcase_add_test(tc
, test_hmac_md5_large_key_and_data
);
844 tcase_add_test(tc
, test_hmac_md5_null_key
);
845 tcase_add_test(tc
, test_hmac_md5_null_text
);
846 tcase_add_test(tc
, test_hmac_md5_null_key_and_text
);
847 tcase_add_test(tc
, test_hmac_sha1_Hi
);
848 tcase_add_test(tc
, test_hmac_sha1_what
);
849 tcase_add_test(tc
, test_hmac_sha1_dd
);
850 tcase_add_test(tc
, test_hmac_sha1_cd
);
851 tcase_add_test(tc
, test_hmac_sha1_truncation
);
852 tcase_add_test(tc
, test_hmac_sha1_large_key
);
853 tcase_add_test(tc
, test_hmac_sha1_large_key_and_data
);
854 tcase_add_test(tc
, test_hmac_sha1_null_key
);
855 tcase_add_test(tc
, test_hmac_sha1_null_text
);
856 tcase_add_test(tc
, test_hmac_sha1_null_key_and_text
);
857 suite_add_tcase(s
, tc
);