mirror of
https://github.com/libtom/libtomcrypt
synced 2026-08-25 20:26:07 -04:00
76 lines
1.8 KiB
C
76 lines
1.8 KiB
C
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
|
/* SPDX-License-Identifier: Unlicense */
|
|
#include <tomcrypt_test.h>
|
|
|
|
/* Test store/load macros with offsets */
|
|
int store_test(void)
|
|
{
|
|
unsigned char buf[256];
|
|
unsigned long y;
|
|
ulong32 L, L1;
|
|
ulong64 LL, LL1;
|
|
#ifdef LTC_FAST
|
|
unsigned long x, z, zz;
|
|
#endif
|
|
|
|
for (y = 0; y < 4; y++) {
|
|
L = 0x12345678UL;
|
|
L1 = 0;
|
|
STORE32L(L, buf + y);
|
|
LOAD32L(L1, buf + y);
|
|
if (L1 != L) {
|
|
fprintf(stderr, "\n32L failed at offset %lu\n", y);
|
|
return 1;
|
|
}
|
|
STORE32H(L, buf + y);
|
|
LOAD32H(L1, buf + y);
|
|
if (L1 != L) {
|
|
fprintf(stderr, "\n32H failed at offset %lu\n", y);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
for (y = 0; y < 8; y++) {
|
|
LL = CONST64 (0x01020304050607);
|
|
LL1 = 0;
|
|
STORE64L(LL, buf + y);
|
|
LOAD64L(LL1, buf + y);
|
|
if (LL1 != LL) {
|
|
fprintf(stderr, "\n64L failed at offset %lu\n", y);
|
|
return 1;
|
|
}
|
|
STORE64H(LL, buf + y);
|
|
LOAD64H(LL1, buf + y);
|
|
if (LL1 != LL) {
|
|
fprintf(stderr, "\n64H failed at offset %lu\n", y);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
/* test LTC_FAST */
|
|
#ifdef LTC_FAST
|
|
y = 16;
|
|
|
|
for (z = 0, zz = 2*y - 1; z < y; z++, zz-=2) {
|
|
/* fill y bytes with random */
|
|
ENSURE(yarrow_read(buf+z, y, &yarrow_prng) == y);
|
|
ENSURE(yarrow_read(buf+z+y+zz, y, &yarrow_prng) == y);
|
|
|
|
/* now XOR it byte for byte */
|
|
for (x = 0; x < y; x++) {
|
|
buf[4*y+z+x] = buf[z+x] ^ buf[z+y+x+zz];
|
|
}
|
|
|
|
/* now XOR it word for word */
|
|
for (x = 0; x < y; x += sizeof(LTC_FAST_TYPE)) {
|
|
LTC_FAST_XOR3(&buf[5*y+z+x], &buf[z+x], &buf[z+y+x+zz]);
|
|
}
|
|
|
|
if (memcmp(&buf[4*y+z], &buf[5*y+z], y)) {
|
|
fprintf(stderr, "\nLTC_FAST failed at offset %lu\n", z);
|
|
return 1;
|
|
}
|
|
}
|
|
#endif
|
|
return 0;
|
|
}
|