1/* test the multi helpers... */
2#include <tomcrypt.h>
3
4int 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"), (unsigned char*)"hello", 5, buf[0], &len);
17   len2 = sizeof(buf[0]);
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)) {
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, (unsigned char*)"he", 2UL, "llo", 3UL, NULL, 0);
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, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, 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, (unsigned char*)"hello", 5, buf[0], &len);
39   len2 = sizeof(buf[0]);
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)) {
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, (unsigned char*)"he", 2UL, "llo", 3UL, 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, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, 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, (unsigned char*)"hello", 5, buf[0], &len);
61   len2 = sizeof(buf[0]);
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)) {
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, (unsigned char*)"he", 2UL, "llo", 3UL, 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, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, 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, (unsigned char*)"hello", 5, buf[0], &len);
83   len2 = sizeof(buf[0]);
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)) {
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, (unsigned char*)"he", 2UL, "llo", 3UL, 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, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, 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.3 $ */
110/* $Date: 2006/06/07 22:25:09 $ */
111