1 #include <tomcrypt_test.h>
2
3 /* Test store/load macros with offsets */
store_test(void)4 int store_test(void)
5 {
6 unsigned char buf[256];
7 int y;
8 ulong32 L, L1;
9 ulong64 LL, LL1;
10 #ifdef LTC_FAST
11 int x, z;
12 #endif
13
14 for (y = 0; y < 4; y++) {
15 L = 0x12345678UL;
16 L1 = 0;
17 STORE32L(L, buf + y);
18 LOAD32L(L1, buf + y);
19 if (L1 != L) {
20 fprintf(stderr, "\n32L failed at offset %d\n", y);
21 return 1;
22 }
23 STORE32H(L, buf + y);
24 LOAD32H(L1, buf + y);
25 if (L1 != L) {
26 fprintf(stderr, "\n32H failed at offset %d\n", y);
27 return 1;
28 }
29 }
30
31 for (y = 0; y < 8; y++) {
32 LL = CONST64 (0x01020304050607);
33 LL1 = 0;
34 STORE64L(LL, buf + y);
35 LOAD64L(LL1, buf + y);
36 if (LL1 != LL) {
37 fprintf(stderr, "\n64L failed at offset %d\n", y);
38 return 1;
39 }
40 STORE64H(LL, buf + y);
41 LOAD64H(LL1, buf + y);
42 if (LL1 != LL) {
43 fprintf(stderr, "\n64H failed at offset %d\n", y);
44 return 1;
45 }
46 }
47
48 /* test LTC_FAST */
49 #ifdef LTC_FAST
50 y = 16;
51
52 for (z = 0; z < y; z++) {
53 /* fill y bytes with random */
54 yarrow_read(buf+z, y, &yarrow_prng);
55 yarrow_read(buf+z+y, y, &yarrow_prng);
56
57 /* now XOR it byte for byte */
58 for (x = 0; x < y; x++) {
59 buf[2*y+z+x] = buf[z+x] ^ buf[z+y+x];
60 }
61
62 /* now XOR it word for word */
63 for (x = 0; x < y; x += sizeof(LTC_FAST_TYPE)) {
64 *((LTC_FAST_TYPE*)(&buf[3*y+z+x])) = *((LTC_FAST_TYPE*)(&buf[z+x])) ^ *((LTC_FAST_TYPE*)(&buf[z+y+x]));
65 }
66
67 if (memcmp(&buf[2*y+z], &buf[3*y+z], y)) {
68 fprintf(stderr, "\nLTC_FAST failed at offset %d\n", z);
69 return 1;
70 }
71 }
72 #endif
73 return 0;
74 }
75
76 /* $Source: /cvs/libtom/libtomcrypt/testprof/store_test.c,v $ */
77 /* $Revision: 1.6 $ */
78 /* $Date: 2005/05/05 14:35:59 $ */
79