comparison demos/multi.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
11 register_hash(&sha256_desc); 11 register_hash(&sha256_desc);
12 register_cipher(&aes_desc); 12 register_cipher(&aes_desc);
13 13
14 /* HASH testing */ 14 /* HASH testing */
15 len = sizeof(buf[0]); 15 len = sizeof(buf[0]);
16 hash_memory(find_hash("sha256"), "hello", 5, buf[0], &len); 16 hash_memory(find_hash("sha256"), (unsigned char*)"hello", 5, buf[0], &len);
17 len2 = sizeof(buf[0]); 17 len2 = sizeof(buf[0]);
18 hash_memory_multi(find_hash("sha256"), buf[1], &len2, "hello", 5, NULL); 18 hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"hello", 5, NULL);
19 if (len != len2 || memcmp(buf[0], buf[1], len)) { 19 if (len != len2 || memcmp(buf[0], buf[1], len)) {
20 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 20 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
21 return EXIT_FAILURE; 21 return EXIT_FAILURE;
22 } 22 }
23 len2 = sizeof(buf[0]); 23 len2 = sizeof(buf[0]);
24 hash_memory_multi(find_hash("sha256"), buf[1], &len2, "he", 2, "llo", 3, NULL); 24 hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL, 0);
25 if (len != len2 || memcmp(buf[0], buf[1], len)) { 25 if (len != len2 || memcmp(buf[0], buf[1], len)) {
26 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 26 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
27 return EXIT_FAILURE; 27 return EXIT_FAILURE;
28 } 28 }
29 len2 = sizeof(buf[0]); 29 len2 = sizeof(buf[0]);
30 hash_memory_multi(find_hash("sha256"), buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL); 30 hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
31 if (len != len2 || memcmp(buf[0], buf[1], len)) { 31 if (len != len2 || memcmp(buf[0], buf[1], len)) {
32 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 32 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
33 return EXIT_FAILURE; 33 return EXIT_FAILURE;
34 } 34 }
35 35
36 /* HMAC */ 36 /* HMAC */
37 len = sizeof(buf[0]); 37 len = sizeof(buf[0]);
38 hmac_memory(find_hash("sha256"), key, 16, "hello", 5, buf[0], &len); 38 hmac_memory(find_hash("sha256"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
39 len2 = sizeof(buf[0]); 39 len2 = sizeof(buf[0]);
40 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "hello", 5, NULL); 40 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL);
41 if (len != len2 || memcmp(buf[0], buf[1], len)) { 41 if (len != len2 || memcmp(buf[0], buf[1], len)) {
42 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 42 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
43 return EXIT_FAILURE; 43 return EXIT_FAILURE;
44 } 44 }
45 len2 = sizeof(buf[0]); 45 len2 = sizeof(buf[0]);
46 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL); 46 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
47 if (len != len2 || memcmp(buf[0], buf[1], len)) { 47 if (len != len2 || memcmp(buf[0], buf[1], len)) {
48 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 48 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
49 return EXIT_FAILURE; 49 return EXIT_FAILURE;
50 } 50 }
51 len2 = sizeof(buf[0]); 51 len2 = sizeof(buf[0]);
52 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL); 52 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
53 if (len != len2 || memcmp(buf[0], buf[1], len)) { 53 if (len != len2 || memcmp(buf[0], buf[1], len)) {
54 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 54 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
55 return EXIT_FAILURE; 55 return EXIT_FAILURE;
56 } 56 }
57 57
58 /* OMAC */ 58 /* OMAC */
59 len = sizeof(buf[0]); 59 len = sizeof(buf[0]);
60 omac_memory(find_cipher("aes"), key, 16, "hello", 5, buf[0], &len); 60 omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
61 len2 = sizeof(buf[0]); 61 len2 = sizeof(buf[0]);
62 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "hello", 5, NULL); 62 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL);
63 if (len != len2 || memcmp(buf[0], buf[1], len)) { 63 if (len != len2 || memcmp(buf[0], buf[1], len)) {
64 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 64 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
65 return EXIT_FAILURE; 65 return EXIT_FAILURE;
66 } 66 }
67 len2 = sizeof(buf[0]); 67 len2 = sizeof(buf[0]);
68 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL); 68 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
69 if (len != len2 || memcmp(buf[0], buf[1], len)) { 69 if (len != len2 || memcmp(buf[0], buf[1], len)) {
70 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 70 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
71 return EXIT_FAILURE; 71 return EXIT_FAILURE;
72 } 72 }
73 len2 = sizeof(buf[0]); 73 len2 = sizeof(buf[0]);
74 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL); 74 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
75 if (len != len2 || memcmp(buf[0], buf[1], len)) { 75 if (len != len2 || memcmp(buf[0], buf[1], len)) {
76 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 76 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
77 return EXIT_FAILURE; 77 return EXIT_FAILURE;
78 } 78 }
79 79
80 /* PMAC */ 80 /* PMAC */
81 len = sizeof(buf[0]); 81 len = sizeof(buf[0]);
82 pmac_memory(find_cipher("aes"), key, 16, "hello", 5, buf[0], &len); 82 pmac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
83 len2 = sizeof(buf[0]); 83 len2 = sizeof(buf[0]);
84 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "hello", 5, NULL); 84 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL);
85 if (len != len2 || memcmp(buf[0], buf[1], len)) { 85 if (len != len2 || memcmp(buf[0], buf[1], len)) {
86 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 86 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
87 return EXIT_FAILURE; 87 return EXIT_FAILURE;
88 } 88 }
89 len2 = sizeof(buf[0]); 89 len2 = sizeof(buf[0]);
90 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL); 90 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
91 if (len != len2 || memcmp(buf[0], buf[1], len)) { 91 if (len != len2 || memcmp(buf[0], buf[1], len)) {
92 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 92 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
93 return EXIT_FAILURE; 93 return EXIT_FAILURE;
94 } 94 }
95 len2 = sizeof(buf[0]); 95 len2 = sizeof(buf[0]);
96 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL); 96 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
97 if (len != len2 || memcmp(buf[0], buf[1], len)) { 97 if (len != len2 || memcmp(buf[0], buf[1], len)) {
98 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); 98 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
99 return EXIT_FAILURE; 99 return EXIT_FAILURE;
100 } 100 }
101 101
104 return EXIT_SUCCESS; 104 return EXIT_SUCCESS;
105 } 105 }
106 106
107 107
108 /* $Source: /cvs/libtom/libtomcrypt/demos/multi.c,v $ */ 108 /* $Source: /cvs/libtom/libtomcrypt/demos/multi.c,v $ */
109 /* $Revision: 1.2 $ */ 109 /* $Revision: 1.3 $ */
110 /* $Date: 2005/05/05 14:35:56 $ */ 110 /* $Date: 2006/06/07 22:25:09 $ */