Skip to content

Commit 32cecd4

Browse files
committed
Big-endian suppprt fixes
1 parent 48fe405 commit 32cecd4

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

src/arithmetic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
#include <stddef.h>
1111

1212
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
13+
#ifndef TARGET_BIG_ENDIAN
1314
#define TARGET_BIG_ENDIAN
1415
#endif
16+
#endif
1517

1618
#if defined(MAYO_AVX) || defined(MAYO_NEON)
1719
#include <shuffle_arithmetic.h>

src/mayo.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ static void compute_A(const mayo_params_t *p, uint64_t *VtL, unsigned char *A_ou
241241
}
242242
}
243243

244+
#ifdef TARGET_BIG_ENDIAN
245+
for (int i = 0; i < (((PARAM_o(p)*PARAM_k(p)+15)/16)*16)*MAYO_M_OVER_8; ++i)
246+
A[i] = BSWAP64(A[i]);
247+
#endif
248+
249+
244250
for (int r = 0; r < PARAM_m(p); r+=16)
245251
{
246252
for (int c = 0; c < PARAM_A_cols(p)-1 ; c+=16)
@@ -313,10 +319,6 @@ int mayo_expand_sk(const mayo_params_t *p, const unsigned char *csk,
313319
const int param_O_bytes = PARAM_O_bytes(p);
314320
const int param_pk_seed_bytes = PARAM_pk_seed_bytes(p);
315321
const int param_sk_seed_bytes = PARAM_sk_seed_bytes(p);
316-
#ifdef TARGET_BIG_ENDIAN
317-
const int param_P1_bytes = PARAM_P1_bytes(p);
318-
const int param_P2_bytes = PARAM_P2_bytes(p);
319-
#endif
320322

321323
const unsigned char *seed_sk = csk;
322324
unsigned char *seed_pk = S;
@@ -330,22 +332,22 @@ int mayo_expand_sk(const mayo_params_t *p, const unsigned char *csk,
330332
#endif
331333

332334
expand_P1_P2(p, P, seed_pk);
333-
uint64_t *P2 = P + PARAM_P1_limbs(p);
334-
335335
#ifdef TARGET_BIG_ENDIAN
336-
for (int i = 0; i < (param_P1_bytes + param_P2_bytes) / 8; ++i) {
336+
for (int i = 0; i < PARAM_P1_limbs(p) + PARAM_P2_limbs(p); ++i) {
337337
P[i] = BSWAP64(P[i]);
338338
}
339339
#endif
340340

341+
uint64_t *P2 = P + PARAM_P1_limbs(p);
342+
341343
uint64_t *P1 = P;
342344

343345
// compute L_i = (P1 + P1^t)*O + P2
344346
uint64_t *L = P2;
345347
P1P1t_times_O(p, P1, O, L);
346348

347349
#ifdef TARGET_BIG_ENDIAN
348-
for (int i = 0; i < (param_P1_bytes + param_P2_bytes) / 8; ++i) {
350+
for (int i = 0; i < PARAM_P1_limbs(p) + PARAM_P2_limbs(p); ++i) {
349351
P[i] = BSWAP64(P[i]);
350352
}
351353
#endif
@@ -386,10 +388,6 @@ int mayo_sign_signature(const mayo_params_t *p, unsigned char *sig,
386388
const int param_digest_bytes = PARAM_digest_bytes(p);
387389
const int param_sk_seed_bytes = PARAM_sk_seed_bytes(p);
388390
const int param_salt_bytes = PARAM_salt_bytes(p);
389-
#ifdef TARGET_BIG_ENDIAN
390-
const int param_P1_bytes = PARAM_P1_bytes(p);
391-
const int param_P2_bytes = PARAM_P2_bytes(p);
392-
#endif
393391

394392
ret = mayo_expand_sk(p, csk, &sk);
395393
if (ret != MAYO_OK) {
@@ -409,10 +407,10 @@ int mayo_sign_signature(const mayo_params_t *p, unsigned char *sig,
409407

410408

411409
#ifdef TARGET_BIG_ENDIAN
412-
for (int i = 0; i < param_P1_bytes / 8; ++i) {
410+
for (int i = 0; i < PARAM_P1_limbs(p); ++i) {
413411
P1[i] = BSWAP64(P1[i]);
414412
}
415-
for (int i = 0; i < param_P2_bytes / 8; ++i) {
413+
for (int i = 0; i < PARAM_P2_limbs(p); ++i) {
416414
L[i] = BSWAP64(L[i]);
417415
}
418416
#endif
@@ -631,9 +629,6 @@ int mayo_verify(const mayo_params_t *p, const unsigned char *m,
631629
const int param_n = PARAM_n(p);
632630
const int param_k = PARAM_k(p);
633631
const int param_m_bytes = PARAM_m_bytes(p);
634-
#ifdef TARGET_BIG_ENDIAN
635-
const int param_P3_bytes = PARAM_P3_bytes(p);
636-
#endif
637632
const int param_sig_bytes = PARAM_sig_bytes(p);
638633
const int param_digest_bytes = PARAM_digest_bytes(p);
639634
const int param_salt_bytes = PARAM_salt_bytes(p);
@@ -648,13 +643,13 @@ int mayo_verify(const mayo_params_t *p, const unsigned char *m,
648643
uint64_t *P3 = P2 + PARAM_P2_limbs(p);
649644

650645
#ifdef TARGET_BIG_ENDIAN
651-
for (int i = 0; i < param_P1_bytes / 8; ++i) {
646+
for (int i = 0; i < PARAM_P1_limbs(p); ++i) {
652647
P1[i] = BSWAP64(P1[i]);
653648
}
654-
for (int i = 0; i < param_P2_bytes / 8; ++i) {
649+
for (int i = 0; i < PARAM_P2_limbs(p); ++i) {
655650
P2[i] = BSWAP64(P2[i]);
656651
}
657-
for (int i = 0; i < param_P3_bytes / 8; ++i) {
652+
for (int i = 0; i < PARAM_P3_limbs(p); ++i) {
658653
P3[i] = BSWAP64(P3[i]);
659654
}
660655
#endif

test/test_kat.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ int main(int argc, char *argv[]) {
5555
return rc;
5656
}
5757

58-
5958
static int test_sig_kat(const mayo_params_t *p) {
6059
unsigned char seed[48];
6160
unsigned char *m, *sm, *m1, *sm_rsp;

0 commit comments

Comments
 (0)