1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 15:08:12 +00:00

refactor(crypto): remove unused macros in groestl512

This commit is contained in:
Ondřej Vejpustek 2024-08-09 15:45:17 +02:00
parent 729da01b88
commit cb9c56e83f

View File

@ -58,28 +58,6 @@
#define QC32up(j, r) SPH_C32(0xFFFFFFFF)
#define QC32dn(j, r) (((sph_u32)(r) << 24) ^ SPH_T32(~((sph_u32)(j) << 24)))
#define C64e(x) ((SPH_C64(x) >> 56) \
| ((SPH_C64(x) >> 40) & SPH_C64(0x000000000000FF00)) \
| ((SPH_C64(x) >> 24) & SPH_C64(0x0000000000FF0000)) \
| ((SPH_C64(x) >> 8) & SPH_C64(0x00000000FF000000)) \
| ((SPH_C64(x) << 8) & SPH_C64(0x000000FF00000000)) \
| ((SPH_C64(x) << 24) & SPH_C64(0x0000FF0000000000)) \
| ((SPH_C64(x) << 40) & SPH_C64(0x00FF000000000000)) \
| ((SPH_C64(x) << 56) & SPH_C64(0xFF00000000000000)))
#define dec64e_aligned sph_dec64le_aligned
#define enc64e sph_enc64le
#define B64_0(x) ((x) & 0xFF)
#define B64_1(x) (((x) >> 8) & 0xFF)
#define B64_2(x) (((x) >> 16) & 0xFF)
#define B64_3(x) (((x) >> 24) & 0xFF)
#define B64_4(x) (((x) >> 32) & 0xFF)
#define B64_5(x) (((x) >> 40) & 0xFF)
#define B64_6(x) (((x) >> 48) & 0xFF)
#define B64_7(x) ((x) >> 56)
#define R64 SPH_ROTL64
#define PC64(j, r) ((sph_u64)((j) + (r)))
#define QC64(j, r) (((sph_u64)(r) << 56) ^ SPH_T64(~((sph_u64)(j) << 56)))
static const sph_u32 T0up[] = {
C32e(0xc632f4a5), C32e(0xf86f9784), C32e(0xee5eb099), C32e(0xf67a8c8d),
@ -349,132 +327,6 @@ static const sph_u32 T1dn[] = {
C32e(0xcb46f6cb), C32e(0xfc1f4bfc), C32e(0xd661dad6), C32e(0x3a4e583a)
};
#define DECL_STATE_SMALL \
sph_u32 H[16] = {0};
#define READ_STATE_SMALL(sc) do { \
memcpy(H, (sc)->state.narrow, sizeof H); \
} while (0)
#define WRITE_STATE_SMALL(sc) do { \
memcpy((sc)->state.narrow, H, sizeof H); \
} while (0)
#define XCAT(x, y) XCAT_(x, y)
#define XCAT_(x, y) x ## y
#define RSTT(d0, d1, a, b0, b1, b2, b3, b4, b5, b6, b7) do { \
t[d0] = T0up[B32_0(a[b0])] \
^ T1up[B32_1(a[b1])] \
^ T2up[B32_2(a[b2])] \
^ T3up[B32_3(a[b3])] \
^ T0dn[B32_0(a[b4])] \
^ T1dn[B32_1(a[b5])] \
^ T2dn[B32_2(a[b6])] \
^ T3dn[B32_3(a[b7])]; \
t[d1] = T0dn[B32_0(a[b0])] \
^ T1dn[B32_1(a[b1])] \
^ T2dn[B32_2(a[b2])] \
^ T3dn[B32_3(a[b3])] \
^ T0up[B32_0(a[b4])] \
^ T1up[B32_1(a[b5])] \
^ T2up[B32_2(a[b6])] \
^ T3up[B32_3(a[b7])]; \
} while (0)
#define ROUND_SMALL_P(a, r) do { \
sph_u32 t[16]; \
a[0x0] ^= PC32up(0x00, r); \
a[0x1] ^= PC32dn(0x00, r); \
a[0x2] ^= PC32up(0x10, r); \
a[0x3] ^= PC32dn(0x10, r); \
a[0x4] ^= PC32up(0x20, r); \
a[0x5] ^= PC32dn(0x20, r); \
a[0x6] ^= PC32up(0x30, r); \
a[0x7] ^= PC32dn(0x30, r); \
a[0x8] ^= PC32up(0x40, r); \
a[0x9] ^= PC32dn(0x40, r); \
a[0xA] ^= PC32up(0x50, r); \
a[0xB] ^= PC32dn(0x50, r); \
a[0xC] ^= PC32up(0x60, r); \
a[0xD] ^= PC32dn(0x60, r); \
a[0xE] ^= PC32up(0x70, r); \
a[0xF] ^= PC32dn(0x70, r); \
RSTT(0x0, 0x1, a, 0x0, 0x2, 0x4, 0x6, 0x9, 0xB, 0xD, 0xF); \
RSTT(0x2, 0x3, a, 0x2, 0x4, 0x6, 0x8, 0xB, 0xD, 0xF, 0x1); \
RSTT(0x4, 0x5, a, 0x4, 0x6, 0x8, 0xA, 0xD, 0xF, 0x1, 0x3); \
RSTT(0x6, 0x7, a, 0x6, 0x8, 0xA, 0xC, 0xF, 0x1, 0x3, 0x5); \
RSTT(0x8, 0x9, a, 0x8, 0xA, 0xC, 0xE, 0x1, 0x3, 0x5, 0x7); \
RSTT(0xA, 0xB, a, 0xA, 0xC, 0xE, 0x0, 0x3, 0x5, 0x7, 0x9); \
RSTT(0xC, 0xD, a, 0xC, 0xE, 0x0, 0x2, 0x5, 0x7, 0x9, 0xB); \
RSTT(0xE, 0xF, a, 0xE, 0x0, 0x2, 0x4, 0x7, 0x9, 0xB, 0xD); \
memcpy(a, t, sizeof t); \
} while (0)
#define ROUND_SMALL_Q(a, r) do { \
sph_u32 t[16]; \
a[0x0] ^= QC32up(0x00, r); \
a[0x1] ^= QC32dn(0x00, r); \
a[0x2] ^= QC32up(0x10, r); \
a[0x3] ^= QC32dn(0x10, r); \
a[0x4] ^= QC32up(0x20, r); \
a[0x5] ^= QC32dn(0x20, r); \
a[0x6] ^= QC32up(0x30, r); \
a[0x7] ^= QC32dn(0x30, r); \
a[0x8] ^= QC32up(0x40, r); \
a[0x9] ^= QC32dn(0x40, r); \
a[0xA] ^= QC32up(0x50, r); \
a[0xB] ^= QC32dn(0x50, r); \
a[0xC] ^= QC32up(0x60, r); \
a[0xD] ^= QC32dn(0x60, r); \
a[0xE] ^= QC32up(0x70, r); \
a[0xF] ^= QC32dn(0x70, r); \
RSTT(0x0, 0x1, a, 0x2, 0x6, 0xA, 0xE, 0x1, 0x5, 0x9, 0xD); \
RSTT(0x2, 0x3, a, 0x4, 0x8, 0xC, 0x0, 0x3, 0x7, 0xB, 0xF); \
RSTT(0x4, 0x5, a, 0x6, 0xA, 0xE, 0x2, 0x5, 0x9, 0xD, 0x1); \
RSTT(0x6, 0x7, a, 0x8, 0xC, 0x0, 0x4, 0x7, 0xB, 0xF, 0x3); \
RSTT(0x8, 0x9, a, 0xA, 0xE, 0x2, 0x6, 0x9, 0xD, 0x1, 0x5); \
RSTT(0xA, 0xB, a, 0xC, 0x0, 0x4, 0x8, 0xB, 0xF, 0x3, 0x7); \
RSTT(0xC, 0xD, a, 0xE, 0x2, 0x6, 0xA, 0xD, 0x1, 0x5, 0x9); \
RSTT(0xE, 0xF, a, 0x0, 0x4, 0x8, 0xC, 0xF, 0x3, 0x7, 0xB); \
memcpy(a, t, sizeof t); \
} while (0)
#define PERM_SMALL_P(a) do { \
int r; \
for (r = 0; r < 10; r ++) \
ROUND_SMALL_P(a, r); \
} while (0)
#define PERM_SMALL_Q(a) do { \
int r; \
for (r = 0; r < 10; r ++) \
ROUND_SMALL_Q(a, r); \
} while (0)
#define COMPRESS_SMALL do { \
sph_u32 g[16], m[16]; \
size_t u; \
for (u = 0; u < 16; u ++) { \
m[u] = dec32e_aligned(buf + (u << 2)); \
g[u] = m[u] ^ H[u]; \
} \
PERM_SMALL_P(g); \
PERM_SMALL_Q(m); \
for (u = 0; u < 16; u ++) \
H[u] ^= g[u] ^ m[u]; \
} while (0)
#define FINAL_SMALL do { \
sph_u32 x[16]; \
size_t u; \
memcpy(x, H, sizeof x); \
PERM_SMALL_P(x); \
for (u = 0; u < 16; u ++) \
H[u] ^= x[u]; \
} while (0)
#define DECL_STATE_BIG \
sph_u32 H[32] = {0};