comparison testprof/store_test.c @ 209:39d5d58461d6 libtomcrypt-orig LTC_1.05

Import of libtomcrypt 1.05
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jul 2005 03:53:40 +0000
parents 1c15b283127b
children
comparison
equal deleted inserted replaced
191:1c15b283127b 209:39d5d58461d6
1 #include <tomcrypt_test.h> 1 #include <tomcrypt_test.h>
2 2
3 /* Test store/load macros with offsets */ 3 /* Test store/load macros with offsets */
4 int store_test(void) 4 int store_test(void)
5 { 5 {
6 unsigned char buf[24]; 6 unsigned char buf[256];
7 int y; 7 int y;
8 ulong32 L, L1; 8 ulong32 L, L1;
9 ulong64 LL, LL1; 9 ulong64 LL, LL1;
10 #ifdef LTC_FAST
11 int x, z;
12 #endif
10 13
11 L = 0x12345678UL;
12 for (y = 0; y < 4; y++) { 14 for (y = 0; y < 4; y++) {
15 L = 0x12345678UL;
16 L1 = 0;
13 STORE32L(L, buf + y); 17 STORE32L(L, buf + y);
14 LOAD32L(L1, buf + y); 18 LOAD32L(L1, buf + y);
15 if (L1 != L) { 19 if (L1 != L) {
16 fprintf(stderr, "\n32L failed at offset %d\n", y); 20 fprintf(stderr, "\n32L failed at offset %d\n", y);
17 return 1; 21 return 1;
22 fprintf(stderr, "\n32H failed at offset %d\n", y); 26 fprintf(stderr, "\n32H failed at offset %d\n", y);
23 return 1; 27 return 1;
24 } 28 }
25 } 29 }
26 30
27 LL = CONST64 (0x01020304050607);
28 for (y = 0; y < 8; y++) { 31 for (y = 0; y < 8; y++) {
32 LL = CONST64 (0x01020304050607);
33 LL1 = 0;
29 STORE64L(LL, buf + y); 34 STORE64L(LL, buf + y);
30 LOAD64L(LL1, buf + y); 35 LOAD64L(LL1, buf + y);
31 if (LL1 != LL) { 36 if (LL1 != LL) {
32 fprintf(stderr, "\n64L failed at offset %d\n", y); 37 fprintf(stderr, "\n64L failed at offset %d\n", y);
33 return 1; 38 return 1;
38 fprintf(stderr, "\n64H failed at offset %d\n", y); 43 fprintf(stderr, "\n64H failed at offset %d\n", y);
39 return 1; 44 return 1;
40 } 45 }
41 } 46 }
42 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
43 return 0; 73 return 0;
44 } 74 }
75
76 /* $Source: /cvs/libtom/libtomcrypt/testprof/store_test.c,v $ */
77 /* $Revision: 1.6 $ */
78 /* $Date: 2005/05/05 14:35:59 $ */