Skip to content

Commit 57c9f4f

Browse files
committed
comment out the bid endian conversion
Signed-off-by: willieyz <willie.zhao@chelpis.com>
1 parent 26ed2ee commit 57c9f4f

File tree

1 file changed

+41
-30
lines changed
  • examples/custom_backend/mldsa_native/mldsa/src/fips202/native/custom/src

1 file changed

+41
-30
lines changed

examples/custom_backend/mldsa_native/mldsa/src/fips202/native/custom/src/sha3.c

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,25 @@ void sha3_keccakf(uint64_t st[25])
3131
int i, j, r;
3232
uint64_t t, bc[5];
3333

34-
#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
35-
uint8_t *v;
36-
37-
/* endianness conversion. this is redundant on little-endian targets */
38-
for (i = 0; i < 25; i++)
39-
{
40-
v = (uint8_t *)&st[i];
41-
st[i] = ((uint64_t)v[0]) | (((uint64_t)v[1]) << 8) |
42-
(((uint64_t)v[2]) << 16) | (((uint64_t)v[3]) << 24) |
43-
(((uint64_t)v[4]) << 32) | (((uint64_t)v[5]) << 40) |
44-
(((uint64_t)v[6]) << 48) | (((uint64_t)v[7]) << 56);
45-
}
46-
#endif /* __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ */
34+
/* NOTE:
35+
* This is present in the tiny_sha3 implementation because it uses
36+
* a byte-reversed presentation of the Keccakf1600 state for big endian
37+
* targets. mldsa-native uses the standard presentation, hence we don't
38+
* the reversal here. */
39+
/* #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ */
40+
/* uint8_t *v;*/
41+
42+
/* /\* endianness conversion. this is redundant on little-endian targets *\/
43+
*/
44+
/* for (i = 0; i < 25; i++) */
45+
/* {*/
46+
/* v = (uint8_t *)&st[i];*/
47+
/* st[i] = ((uint64_t)v[0]) | (((uint64_t)v[1]) << 8) |*/
48+
/* (((uint64_t)v[2]) << 16) | (((uint64_t)v[3]) << 24) |*/
49+
/* (((uint64_t)v[4]) << 32) | (((uint64_t)v[5]) << 40) |*/
50+
/* (((uint64_t)v[6]) << 48) | (((uint64_t)v[7]) << 56);*/
51+
/* }*/
52+
/* #endif */
4753

4854
/* actual iteration */
4955
for (r = 0; r < KECCAKF_ROUNDS; r++)
@@ -89,23 +95,28 @@ void sha3_keccakf(uint64_t st[25])
8995
/* Iota */
9096
st[0] ^= keccakf_rndc[r];
9197
}
92-
93-
#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
94-
/* endianness conversion. this is redundant on little-endian targets */
95-
for (i = 0; i < 25; i++)
96-
{
97-
v = (uint8_t *)&st[i];
98-
t = st[i];
99-
v[0] = (uint8_t)(t & 0xFF);
100-
v[1] = (uint8_t)((t >> 8) & 0xFF);
101-
v[2] = (uint8_t)((t >> 16) & 0xFF);
102-
v[3] = (uint8_t)((t >> 24) & 0xFF);
103-
v[4] = (uint8_t)((t >> 32) & 0xFF);
104-
v[5] = (uint8_t)((t >> 40) & 0xFF);
105-
v[6] = (uint8_t)((t >> 48) & 0xFF);
106-
v[7] = (uint8_t)((t >> 56) & 0xFF);
107-
}
108-
#endif /* __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ */
98+
/* NOTE:
99+
* This is present in the tiny_sha3 implementation because it uses
100+
* a byte-reversed presentation of the Keccakf1600 state for big endian
101+
* targets. mldsa-native uses the standard presentation, hence we don't
102+
* the reversal here. */
103+
/* #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ */
104+
/* /\* endianness conversion. this is redundant on little-endian targets *\/
105+
*/
106+
/* for (i = 0; i < 25; i++)*/
107+
/* {*/
108+
/* v = (uint8_t *)&st[i];*/
109+
/* t = st[i];*/
110+
/* v[0] = (uint8_t)(t & 0xFF);*/
111+
/* v[1] = (uint8_t)((t >> 8) & 0xFF);*/
112+
/* v[2] = (uint8_t)((t >> 16) & 0xFF);*/
113+
/* v[3] = (uint8_t)((t >> 24) & 0xFF);*/
114+
/* v[4] = (uint8_t)((t >> 32) & 0xFF);*/
115+
/* v[5] = (uint8_t)((t >> 40) & 0xFF);*/
116+
/* v[6] = (uint8_t)((t >> 48) & 0xFF);*/
117+
/* v[7] = (uint8_t)((t >> 56) & 0xFF);*/
118+
/* }*/
119+
/* #endif */
109120
}
110121

111122
/* Initialize the context for SHA3 */

0 commit comments

Comments
 (0)