Skip to content

Commit 7103c56

Browse files
committed
Mark Keccak functions that contain expected misaligned accesses.
To avoid undefined behavior warnings for those accesses.
1 parent c8a5402 commit 7103c56

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ext/hash/sha3/generic32lc/KeccakP-1600-inplace32BI.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ and related or neighboring rights to the source code in this file.
1717
#include "brg_endian.h"
1818
#include "KeccakP-1600-SnP.h"
1919
#include "SnP-Relaned.h"
20+
#ifdef __has_feature
21+
# if __has_feature(undefined_behavior_sanitizer)
22+
# define ALLOW_MISALIGNED_ACCESS __attribute__((no_sanitize("alignment")))
23+
# endif
24+
#endif
25+
#ifndef ALLOW_MISALIGNED_ACCESS
26+
# define ALLOW_MISALIGNED_ACCESS
27+
#endif
2028

2129
typedef unsigned char UINT8;
2230
typedef unsigned int UINT32;
@@ -162,6 +170,7 @@ void KeccakP1600_AddBytesInLane(void *state, unsigned int lanePosition, const un
162170

163171
/* ---------------------------------------------------------------- */
164172

173+
ALLOW_MISALIGNED_ACCESS
165174
void KeccakP1600_AddLanes(void *state, const unsigned char *data, unsigned int laneCount)
166175
{
167176
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
@@ -217,6 +226,7 @@ void KeccakP1600_OverwriteBytesInLane(void *state, unsigned int lanePosition, co
217226

218227
/* ---------------------------------------------------------------- */
219228

229+
ALLOW_MISALIGNED_ACCESS
220230
void KeccakP1600_OverwriteLanes(void *state, const unsigned char *data, unsigned int laneCount)
221231
{
222232
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
@@ -304,6 +314,7 @@ void KeccakP1600_ExtractBytesInLane(const void *state, unsigned int lanePosition
304314

305315
/* ---------------------------------------------------------------- */
306316

317+
ALLOW_MISALIGNED_ACCESS
307318
void KeccakP1600_ExtractLanes(const void *state, unsigned char *data, unsigned int laneCount)
308319
{
309320
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
@@ -378,6 +389,7 @@ void KeccakP1600_ExtractAndAddBytesInLane(const void *state, unsigned int lanePo
378389

379390
/* ---------------------------------------------------------------- */
380391

392+
ALLOW_MISALIGNED_ACCESS
381393
void KeccakP1600_ExtractAndAddLanes(const void *state, const unsigned char *input, unsigned char *output, unsigned int laneCount)
382394
{
383395
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)

ext/hash/sha3/generic64lc/KeccakP-1600-opt64.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ and related or neighboring rights to the source code in this file.
1717
#include <stdlib.h>
1818
#include "brg_endian.h"
1919
#include "KeccakP-1600-opt64-config.h"
20+
#ifdef __has_feature
21+
# if __has_feature(undefined_behavior_sanitizer)
22+
# define ALLOW_MISALIGNED_ACCESS __attribute__((no_sanitize("alignment")))
23+
# endif
24+
#endif
25+
#ifndef ALLOW_MISALIGNED_ACCESS
26+
# define ALLOW_MISALIGNED_ACCESS
27+
#endif
2028

2129
typedef unsigned char UINT8;
2230
typedef unsigned long long int UINT64;
@@ -114,6 +122,7 @@ void KeccakP1600_AddBytesInLane(void *state, unsigned int lanePosition, const un
114122

115123
/* ---------------------------------------------------------------- */
116124

125+
ALLOW_MISALIGNED_ACCESS
117126
void KeccakP1600_AddLanes(void *state, const unsigned char *data, unsigned int laneCount)
118127
{
119128
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
@@ -462,6 +471,7 @@ void KeccakP1600_ExtractAndAddBytes(const void *state, const unsigned char *inpu
462471

463472
/* ---------------------------------------------------------------- */
464473

474+
ALLOW_MISALIGNED_ACCESS
465475
size_t KeccakF1600_FastLoop_Absorb(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen)
466476
{
467477
size_t originalDataByteLen = dataByteLen;

0 commit comments

Comments
 (0)