Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa15c85

Browse files
committed
Issue #16113: take 2 on big endian machines.
1 parent 393b82e commit fa15c85

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

Modules/_sha3/kcp/KeccakP-1600-inplace32BI.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,18 @@ void KeccakP1600_AddLanes(void *state, const unsigned char *data, unsigned int l
188188
unsigned int lanePosition;
189189
for(lanePosition=0; lanePosition<laneCount; lanePosition++) {
190190
UINT8 laneAsBytes[8];
191+
UINT32 low, high, temp, temp0, temp1;
192+
UINT32 *stateAsHalfLanes;
191193
memcpy(laneAsBytes, data+lanePosition*8, 8);
192-
UINT32 low = laneAsBytes[0]
194+
low = laneAsBytes[0]
193195
| ((UINT32)(laneAsBytes[1]) << 8)
194196
| ((UINT32)(laneAsBytes[2]) << 16)
195197
| ((UINT32)(laneAsBytes[3]) << 24);
196-
UINT32 high = laneAsBytes[4]
198+
high = laneAsBytes[4]
197199
| ((UINT32)(laneAsBytes[5]) << 8)
198200
| ((UINT32)(laneAsBytes[6]) << 16)
199201
| ((UINT32)(laneAsBytes[7]) << 24);
200-
UINT32 even, odd, temp, temp0, temp1;
201-
UINT32 *stateAsHalfLanes = (UINT32*)state;
202+
stateAsHalfLanes = (UINT32*)state;
202203
toBitInterleavingAndXOR(low, high, stateAsHalfLanes[lanePosition*2+0], stateAsHalfLanes[lanePosition*2+1], temp, temp0, temp1);
203204
}
204205
#endif
@@ -243,17 +244,18 @@ void KeccakP1600_OverwriteLanes(void *state, const unsigned char *data, unsigned
243244
unsigned int lanePosition;
244245
for(lanePosition=0; lanePosition<laneCount; lanePosition++) {
245246
UINT8 laneAsBytes[8];
247+
UINT32 low, high, temp, temp0, temp1;
248+
UINT32 *stateAsHalfLanes;
246249
memcpy(laneAsBytes, data+lanePosition*8, 8);
247-
UINT32 low = laneAsBytes[0]
250+
low = laneAsBytes[0]
248251
| ((UINT32)(laneAsBytes[1]) << 8)
249252
| ((UINT32)(laneAsBytes[2]) << 16)
250253
| ((UINT32)(laneAsBytes[3]) << 24);
251-
UINT32 high = laneAsBytes[4]
254+
high = laneAsBytes[4]
252255
| ((UINT32)(laneAsBytes[5]) << 8)
253256
| ((UINT32)(laneAsBytes[6]) << 16)
254257
| ((UINT32)(laneAsBytes[7]) << 24);
255-
UINT32 even, odd, temp, temp0, temp1;
256-
UINT32 *stateAsHalfLanes = (UINT32*)state;
258+
stateAsHalfLanes = (UINT32*)state;
257259
toBitInterleavingAndSet(low, high, stateAsHalfLanes[lanePosition*2+0], stateAsHalfLanes[lanePosition*2+1], temp, temp0, temp1);
258260
}
259261
#endif
@@ -406,8 +408,8 @@ void KeccakP1600_ExtractAndAddLanes(const void *state, const unsigned char *inpu
406408
for(lanePosition=0; lanePosition<laneCount; lanePosition++) {
407409
UINT32 *stateAsHalfLanes = (UINT32*)state;
408410
UINT32 low, high, temp, temp0, temp1;
409-
fromBitInterleaving(stateAsHalfLanes[lanePosition*2], stateAsHalfLanes[lanePosition*2+1], low, high, temp, temp0, temp1);
410411
UINT8 laneAsBytes[8];
412+
fromBitInterleaving(stateAsHalfLanes[lanePosition*2], stateAsHalfLanes[lanePosition*2+1], low, high, temp, temp0, temp1);
411413
laneAsBytes[0] = low & 0xFF;
412414
laneAsBytes[1] = (low >> 8) & 0xFF;
413415
laneAsBytes[2] = (low >> 16) & 0xFF;

0 commit comments

Comments
 (0)