comparison demos/test/store_test.c @ 143:5d99163f7e32 libtomcrypt-orig

import of libtomcrypt 0.99
author Matt Johnston <matt@ucc.asn.au>
date Sun, 19 Dec 2004 11:34:45 +0000
parents 6362d3854bb4
children
comparison
equal deleted inserted replaced
15:6362d3854bb4 143:5d99163f7e32
1 #include "test.h" 1 #include "test.h"
2 2
3 /* Test store/load macros with offsets */
3 int store_test(void) 4 int store_test(void)
4 { 5 {
5 unsigned char buf[8]; 6 unsigned char buf[24];
6 unsigned long L; 7 unsigned long L, L1;
7 ulong64 LL; 8 int y;
9 ulong64 LL, LL1;
8 10
9 L = 0x12345678UL; 11 L = 0x12345678UL;
10 STORE32L (L, &buf[0]); 12 for (y = 0; y < 4; y++) {
11 L = 0; 13 STORE32L(L, buf + y);
12 LOAD32L (L, &buf[0]); 14 LOAD32L(L1, buf + y);
13 if (L != 0x12345678UL) { 15 if (L1 != L) {
14 printf ("LOAD/STORE32 Little don't work"); 16 fprintf(stderr, "\n32L failed at offset %d\n", y);
15 return 1; 17 return 1;
16 } 18 }
17 LL = CONST64 (0x01020304050607); 19 STORE32H(L, buf + y);
18 STORE64L (LL, &buf[0]); 20 LOAD32H(L1, buf + y);
19 LL = 0; 21 if (L1 != L) {
20 LOAD64L (LL, &buf[0]) 22 fprintf(stderr, "\n32H failed at offset %d\n", y);
21 if (LL != CONST64 (0x01020304050607)) { 23 return 1;
22 printf ("LOAD/STORE64 Little don't work"); 24 }
23 return 1;
24 } 25 }
25 26
26 L = 0x12345678UL; 27 LL = CONST64 (0x01020304050607);
27 STORE32H (L, &buf[0]); 28 for (y = 0; y < 8; y++) {
28 L = 0; 29 STORE64L(LL, buf + y);
29 LOAD32H (L, &buf[0]); 30 LOAD64L(LL1, buf + y);
30 if (L != 0x12345678UL) { 31 if (LL1 != LL) {
31 printf ("LOAD/STORE32 High don't work, %08lx", L); 32 fprintf(stderr, "\n64L failed at offset %d\n", y);
32 return 1; 33 return 1;
34 }
35 STORE64H(LL, buf + y);
36 LOAD64H(LL1, buf + y);
37 if (LL1 != LL) {
38 fprintf(stderr, "\n64H failed at offset %d\n", y);
39 return 1;
40 }
33 } 41 }
34 LL = CONST64 (0x01020304050607); 42
35 STORE64H (LL, &buf[0]);
36 LL = 0;
37 LOAD64H (LL, &buf[0])
38 if (LL != CONST64 (0x01020304050607)) {
39 printf ("LOAD/STORE64 High don't work");
40 return 1;
41 }
42 return 0; 43 return 0;
43 } 44 }