comparison libtomcrypt/demos/multi.c @ 293:9d110777f345 contrib-blacklist

propagate from branch 'au.asn.ucc.matt.dropbear' (head 7ad1775ed65e75dbece27fe6b65bf1a234db386a) to branch 'au.asn.ucc.matt.dropbear.contrib.blacklist' (head 1d86a4f0a401cc68c2670d821a2f6366c37af143)
author Matt Johnston <matt@ucc.asn.au>
date Fri, 10 Mar 2006 06:31:29 +0000
parents 1b9e69c058d2
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
247:c07de41b53d7 293:9d110777f345
1 /* test the multi helpers... */
2 #include <tomcrypt.h>
3
4 int main(void)
5 {
6 unsigned char key[16], buf[2][MAXBLOCKSIZE];
7 unsigned long len, len2;
8
9
10 /* register algos */
11 register_hash(&sha256_desc);
12 register_cipher(&aes_desc);
13
14 /* HASH testing */
15 len = sizeof(buf[0]);
16 hash_memory(find_hash("sha256"), "hello", 5, buf[0], &len);
17 len2 = sizeof(buf[0]);
18 hash_memory_multi(find_hash("sha256"), buf[1], &len2, "hello", 5, NULL);
19 if (len != len2 || memcmp(buf[0], buf[1], len)) {
20 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
21 return EXIT_FAILURE;
22 }
23 len2 = sizeof(buf[0]);
24 hash_memory_multi(find_hash("sha256"), buf[1], &len2, "he", 2, "llo", 3, NULL);
25 if (len != len2 || memcmp(buf[0], buf[1], len)) {
26 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
27 return EXIT_FAILURE;
28 }
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);
31 if (len != len2 || memcmp(buf[0], buf[1], len)) {
32 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
33 return EXIT_FAILURE;
34 }
35
36 /* HMAC */
37 len = sizeof(buf[0]);
38 hmac_memory(find_hash("sha256"), key, 16, "hello", 5, buf[0], &len);
39 len2 = sizeof(buf[0]);
40 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "hello", 5, NULL);
41 if (len != len2 || memcmp(buf[0], buf[1], len)) {
42 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
43 return EXIT_FAILURE;
44 }
45 len2 = sizeof(buf[0]);
46 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL);
47 if (len != len2 || memcmp(buf[0], buf[1], len)) {
48 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
49 return EXIT_FAILURE;
50 }
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);
53 if (len != len2 || memcmp(buf[0], buf[1], len)) {
54 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
55 return EXIT_FAILURE;
56 }
57
58 /* OMAC */
59 len = sizeof(buf[0]);
60 omac_memory(find_cipher("aes"), key, 16, "hello", 5, buf[0], &len);
61 len2 = sizeof(buf[0]);
62 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "hello", 5, NULL);
63 if (len != len2 || memcmp(buf[0], buf[1], len)) {
64 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
65 return EXIT_FAILURE;
66 }
67 len2 = sizeof(buf[0]);
68 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL);
69 if (len != len2 || memcmp(buf[0], buf[1], len)) {
70 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
71 return EXIT_FAILURE;
72 }
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);
75 if (len != len2 || memcmp(buf[0], buf[1], len)) {
76 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
77 return EXIT_FAILURE;
78 }
79
80 /* PMAC */
81 len = sizeof(buf[0]);
82 pmac_memory(find_cipher("aes"), key, 16, "hello", 5, buf[0], &len);
83 len2 = sizeof(buf[0]);
84 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "hello", 5, NULL);
85 if (len != len2 || memcmp(buf[0], buf[1], len)) {
86 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
87 return EXIT_FAILURE;
88 }
89 len2 = sizeof(buf[0]);
90 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL);
91 if (len != len2 || memcmp(buf[0], buf[1], len)) {
92 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
93 return EXIT_FAILURE;
94 }
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);
97 if (len != len2 || memcmp(buf[0], buf[1], len)) {
98 printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
99 return EXIT_FAILURE;
100 }
101
102
103 printf("All passed\n");
104 return EXIT_SUCCESS;
105 }
106
107
108 /* $Source: /cvs/libtom/libtomcrypt/demos/multi.c,v $ */
109 /* $Revision: 1.2 $ */
110 /* $Date: 2005/05/05 14:35:56 $ */