comparison libtomcrypt/tests/store_test.c @ 1511:5916af64acd4 fuzz

merge from main
author Matt Johnston <matt@ucc.asn.au>
date Sat, 17 Feb 2018 19:29:51 +0800
parents 6dba84798cd5
children
comparison
equal deleted inserted replaced
1457:32f990cc96b1 1511:5916af64acd4
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9 #include <tomcrypt_test.h>
10
11 /* Test store/load macros with offsets */
12 int store_test(void)
13 {
14 unsigned char buf[256];
15 int y;
16 ulong32 L, L1;
17 ulong64 LL, LL1;
18 #ifdef LTC_FAST
19 int x, z;
20 #endif
21
22 for (y = 0; y < 4; y++) {
23 L = 0x12345678UL;
24 L1 = 0;
25 STORE32L(L, buf + y);
26 LOAD32L(L1, buf + y);
27 if (L1 != L) {
28 fprintf(stderr, "\n32L failed at offset %d\n", y);
29 return 1;
30 }
31 STORE32H(L, buf + y);
32 LOAD32H(L1, buf + y);
33 if (L1 != L) {
34 fprintf(stderr, "\n32H failed at offset %d\n", y);
35 return 1;
36 }
37 }
38
39 for (y = 0; y < 8; y++) {
40 LL = CONST64 (0x01020304050607);
41 LL1 = 0;
42 STORE64L(LL, buf + y);
43 LOAD64L(LL1, buf + y);
44 if (LL1 != LL) {
45 fprintf(stderr, "\n64L failed at offset %d\n", y);
46 return 1;
47 }
48 STORE64H(LL, buf + y);
49 LOAD64H(LL1, buf + y);
50 if (LL1 != LL) {
51 fprintf(stderr, "\n64H failed at offset %d\n", y);
52 return 1;
53 }
54 }
55
56 /* test LTC_FAST */
57 #ifdef LTC_FAST
58 y = 16;
59
60 for (z = 0; z < y; z++) {
61 /* fill y bytes with random */
62 yarrow_read(buf+z, y, &yarrow_prng);
63 yarrow_read(buf+z+y, y, &yarrow_prng);
64
65 /* now XOR it byte for byte */
66 for (x = 0; x < y; x++) {
67 buf[2*y+z+x] = buf[z+x] ^ buf[z+y+x];
68 }
69
70 /* now XOR it word for word */
71 for (x = 0; x < y; x += sizeof(LTC_FAST_TYPE)) {
72 *(LTC_FAST_TYPE_PTR_CAST(&buf[3*y+z+x])) = *(LTC_FAST_TYPE_PTR_CAST(&buf[z+x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&buf[z+y+x]));
73 }
74
75 if (memcmp(&buf[2*y+z], &buf[3*y+z], y)) {
76 fprintf(stderr, "\nLTC_FAST failed at offset %d\n", z);
77 return 1;
78 }
79 }
80 #endif
81 return 0;
82 }
83
84 /* ref: $Format:%D$ */
85 /* git commit: $Format:%H$ */
86 /* commit time: $Format:%ai$ */