Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions wolfcrypt/src/ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6482,8 +6482,8 @@ int wc_ecc_init_id(ecc_key* key, unsigned char* id, int len, void* heap,
{
int ret = 0;
#ifdef WOLFSSL_SE050
/* SE050 TLS users store a word32 at id, need to cast back */
word32* keyPtr = NULL;
/* SE050 TLS users store a word32 at id, need to read it back */
word32 keyId = 0;
#endif

if (key == NULL)
Expand All @@ -6498,8 +6498,8 @@ int wc_ecc_init_id(ecc_key* key, unsigned char* id, int len, void* heap,
#ifdef WOLFSSL_SE050
/* Set SE050 ID from word32, populate ecc_key with public from SE050 */
if (len == (int)sizeof(word32)) {
keyPtr = (word32*)key->id;
ret = wc_ecc_use_key_id(key, *keyPtr, 0);
keyId = readUnalignedWord32(key->id);
ret = wc_ecc_use_key_id(key, keyId, 0);
}
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions wolfcrypt/src/port/Renesas/renesas_fspsm_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ WOLFSSL_LOCAL int wc_fspsm_RsaFunction(const byte* in, word32 inLen, byte* out,
if (keySize == 1024) {
ret = FSPSM_RSA1024_PKCSDEC_FUNC(&cipher, &plain,
(FSPSM_RSA1024_WPI_KEY*)
key->ctx.wrapped_pri1024_key, &outLen);
key->ctx.wrapped_pri1024_key, outLen);
}
else {
ret = FSPSM_RSA2048_PKCSDEC_FUNC(&cipher, &plain,
(FSPSM_RSA2048_WPI_KEY*)
key->ctx.wrapped_pri2048_key, &outLen);
key->ctx.wrapped_pri2048_key, outLen);
}
}

Expand Down
3 changes: 2 additions & 1 deletion wolfcrypt/src/pwdbased.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,8 @@ static void scryptROMix(byte* x, byte* v, byte* y, int r, word32 n)
#endif
#else
byte* t = x + (2*r - 1) * 64;
j = (t[0] | (t[1] << 8) | (t[2] << 16) | ((word32)t[3] << 24)) & (n-1);
j = ((word32)t[0] | ((word32)t[1] << 8) | ((word32)t[2] << 16) |
((word32)t[3] << 24)) & (n-1);
#endif
#ifdef WORD64_AVAILABLE
for (k = 0; k < bSz / 8; k++)
Expand Down
186 changes: 94 additions & 92 deletions wolfcrypt/src/wc_slhdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1815,14 +1815,14 @@ do { \
*/
#define SHAKE256_SET_HASH_X4_16(state, hash) \
do { \
(state)[24] = ((word64*)((hash) + 0 * 16))[0]; \
(state)[25] = ((word64*)((hash) + 1 * 16))[0]; \
(state)[26] = ((word64*)((hash) + 2 * 16))[0]; \
(state)[27] = ((word64*)((hash) + 3 * 16))[0]; \
(state)[28] = ((word64*)((hash) + 0 * 16))[1]; \
(state)[29] = ((word64*)((hash) + 1 * 16))[1]; \
(state)[30] = ((word64*)((hash) + 2 * 16))[1]; \
(state)[31] = ((word64*)((hash) + 3 * 16))[1]; \
(state)[24] = readUnalignedWord64((hash) + 0 * 16 + 0 * 8); \
(state)[25] = readUnalignedWord64((hash) + 1 * 16 + 0 * 8); \
(state)[26] = readUnalignedWord64((hash) + 2 * 16 + 0 * 8); \
(state)[27] = readUnalignedWord64((hash) + 3 * 16 + 0 * 8); \
(state)[28] = readUnalignedWord64((hash) + 0 * 16 + 1 * 8); \
(state)[29] = readUnalignedWord64((hash) + 1 * 16 + 1 * 8); \
(state)[30] = readUnalignedWord64((hash) + 2 * 16 + 1 * 8); \
(state)[31] = readUnalignedWord64((hash) + 3 * 16 + 1 * 8); \
} while (0)

/* Get the four SHAKE-256 16-byte hash results.
Expand All @@ -1832,14 +1832,14 @@ do { \
*/
#define SHAKE256_GET_HASH_X4_16(state, hash) \
do { \
((word64*)((hash) + 0 * 16))[0] = (state)[0]; \
((word64*)((hash) + 1 * 16))[0] = (state)[1]; \
((word64*)((hash) + 2 * 16))[0] = (state)[2]; \
((word64*)((hash) + 3 * 16))[0] = (state)[3]; \
((word64*)((hash) + 0 * 16))[1] = (state)[4]; \
((word64*)((hash) + 1 * 16))[1] = (state)[5]; \
((word64*)((hash) + 2 * 16))[1] = (state)[6]; \
((word64*)((hash) + 3 * 16))[1] = (state)[7]; \
writeUnalignedWord64((hash) + 0 * 16 + 0 * 8, (state)[0]); \
writeUnalignedWord64((hash) + 1 * 16 + 0 * 8, (state)[1]); \
writeUnalignedWord64((hash) + 2 * 16 + 0 * 8, (state)[2]); \
writeUnalignedWord64((hash) + 3 * 16 + 0 * 8, (state)[3]); \
writeUnalignedWord64((hash) + 0 * 16 + 1 * 8, (state)[4]); \
writeUnalignedWord64((hash) + 1 * 16 + 1 * 8, (state)[5]); \
writeUnalignedWord64((hash) + 2 * 16 + 1 * 8, (state)[6]); \
writeUnalignedWord64((hash) + 3 * 16 + 1 * 8, (state)[7]); \
} while (0)
#endif

Expand Down Expand Up @@ -1876,18 +1876,18 @@ do { \
*/
#define SHAKE256_SET_HASH_X4_24(state, hash) \
do { \
(state)[28] = ((word64*)((hash) + 0 * 24))[0]; \
(state)[29] = ((word64*)((hash) + 1 * 24))[0]; \
(state)[30] = ((word64*)((hash) + 2 * 24))[0]; \
(state)[31] = ((word64*)((hash) + 3 * 24))[0]; \
(state)[32] = ((word64*)((hash) + 0 * 24))[1]; \
(state)[33] = ((word64*)((hash) + 1 * 24))[1]; \
(state)[34] = ((word64*)((hash) + 2 * 24))[1]; \
(state)[35] = ((word64*)((hash) + 3 * 24))[1]; \
(state)[36] = ((word64*)((hash) + 0 * 24))[2]; \
(state)[37] = ((word64*)((hash) + 1 * 24))[2]; \
(state)[38] = ((word64*)((hash) + 2 * 24))[2]; \
(state)[39] = ((word64*)((hash) + 3 * 24))[2]; \
(state)[28] = readUnalignedWord64((hash) + 0 * 24 + 0 * 8); \
(state)[29] = readUnalignedWord64((hash) + 1 * 24 + 0 * 8); \
(state)[30] = readUnalignedWord64((hash) + 2 * 24 + 0 * 8); \
(state)[31] = readUnalignedWord64((hash) + 3 * 24 + 0 * 8); \
(state)[32] = readUnalignedWord64((hash) + 0 * 24 + 1 * 8); \
(state)[33] = readUnalignedWord64((hash) + 1 * 24 + 1 * 8); \
(state)[34] = readUnalignedWord64((hash) + 2 * 24 + 1 * 8); \
(state)[35] = readUnalignedWord64((hash) + 3 * 24 + 1 * 8); \
(state)[36] = readUnalignedWord64((hash) + 0 * 24 + 2 * 8); \
(state)[37] = readUnalignedWord64((hash) + 1 * 24 + 2 * 8); \
(state)[38] = readUnalignedWord64((hash) + 2 * 24 + 2 * 8); \
(state)[39] = readUnalignedWord64((hash) + 3 * 24 + 2 * 8); \
} while (0)

/* Get the four SHAKE-256 24-byte (hash) results.
Expand All @@ -1897,18 +1897,18 @@ do { \
*/
#define SHAKE256_GET_HASH_X4_24(state, hash) \
do { \
((word64*)((hash) + 0 * 24))[0] = (state)[ 0]; \
((word64*)((hash) + 1 * 24))[0] = (state)[ 1]; \
((word64*)((hash) + 2 * 24))[0] = (state)[ 2]; \
((word64*)((hash) + 3 * 24))[0] = (state)[ 3]; \
((word64*)((hash) + 0 * 24))[1] = (state)[ 4]; \
((word64*)((hash) + 1 * 24))[1] = (state)[ 5]; \
((word64*)((hash) + 2 * 24))[1] = (state)[ 6]; \
((word64*)((hash) + 3 * 24))[1] = (state)[ 7]; \
((word64*)((hash) + 0 * 24))[2] = (state)[ 8]; \
((word64*)((hash) + 1 * 24))[2] = (state)[ 9]; \
((word64*)((hash) + 2 * 24))[2] = (state)[10]; \
((word64*)((hash) + 3 * 24))[2] = (state)[11]; \
writeUnalignedWord64((hash) + 0 * 24 + 0 * 8, (state)[ 0]); \
writeUnalignedWord64((hash) + 1 * 24 + 0 * 8, (state)[ 1]); \
writeUnalignedWord64((hash) + 2 * 24 + 0 * 8, (state)[ 2]); \
writeUnalignedWord64((hash) + 3 * 24 + 0 * 8, (state)[ 3]); \
writeUnalignedWord64((hash) + 0 * 24 + 1 * 8, (state)[ 4]); \
writeUnalignedWord64((hash) + 1 * 24 + 1 * 8, (state)[ 5]); \
writeUnalignedWord64((hash) + 2 * 24 + 1 * 8, (state)[ 6]); \
writeUnalignedWord64((hash) + 3 * 24 + 1 * 8, (state)[ 7]); \
writeUnalignedWord64((hash) + 0 * 24 + 2 * 8, (state)[ 8]); \
writeUnalignedWord64((hash) + 1 * 24 + 2 * 8, (state)[ 9]); \
writeUnalignedWord64((hash) + 2 * 24 + 2 * 8, (state)[10]); \
writeUnalignedWord64((hash) + 3 * 24 + 2 * 8, (state)[11]); \
} while (0)
#endif

Expand Down Expand Up @@ -1947,22 +1947,22 @@ do { \
*/
#define SHAKE256_SET_HASH_X4_32(state, hash) \
do { \
(state)[32] = ((word64*)((hash) + 0 * 32))[0]; \
(state)[33] = ((word64*)((hash) + 1 * 32))[0]; \
(state)[34] = ((word64*)((hash) + 2 * 32))[0]; \
(state)[35] = ((word64*)((hash) + 3 * 32))[0]; \
(state)[36] = ((word64*)((hash) + 0 * 32))[1]; \
(state)[37] = ((word64*)((hash) + 1 * 32))[1]; \
(state)[38] = ((word64*)((hash) + 2 * 32))[1]; \
(state)[39] = ((word64*)((hash) + 3 * 32))[1]; \
(state)[40] = ((word64*)((hash) + 0 * 32))[2]; \
(state)[41] = ((word64*)((hash) + 1 * 32))[2]; \
(state)[42] = ((word64*)((hash) + 2 * 32))[2]; \
(state)[43] = ((word64*)((hash) + 3 * 32))[2]; \
(state)[44] = ((word64*)((hash) + 0 * 32))[3]; \
(state)[45] = ((word64*)((hash) + 1 * 32))[3]; \
(state)[46] = ((word64*)((hash) + 2 * 32))[3]; \
(state)[47] = ((word64*)((hash) + 3 * 32))[3]; \
(state)[32] = readUnalignedWord64((hash) + 0 * 32 + 0 * 8); \
(state)[33] = readUnalignedWord64((hash) + 1 * 32 + 0 * 8); \
(state)[34] = readUnalignedWord64((hash) + 2 * 32 + 0 * 8); \
(state)[35] = readUnalignedWord64((hash) + 3 * 32 + 0 * 8); \
(state)[36] = readUnalignedWord64((hash) + 0 * 32 + 1 * 8); \
(state)[37] = readUnalignedWord64((hash) + 1 * 32 + 1 * 8); \
(state)[38] = readUnalignedWord64((hash) + 2 * 32 + 1 * 8); \
(state)[39] = readUnalignedWord64((hash) + 3 * 32 + 1 * 8); \
(state)[40] = readUnalignedWord64((hash) + 0 * 32 + 2 * 8); \
(state)[41] = readUnalignedWord64((hash) + 1 * 32 + 2 * 8); \
(state)[42] = readUnalignedWord64((hash) + 2 * 32 + 2 * 8); \
(state)[43] = readUnalignedWord64((hash) + 3 * 32 + 2 * 8); \
(state)[44] = readUnalignedWord64((hash) + 0 * 32 + 3 * 8); \
(state)[45] = readUnalignedWord64((hash) + 1 * 32 + 3 * 8); \
(state)[46] = readUnalignedWord64((hash) + 2 * 32 + 3 * 8); \
(state)[47] = readUnalignedWord64((hash) + 3 * 32 + 3 * 8); \
} while (0)

/* Get the four SHAKE-256 32-byte hash results.
Expand All @@ -1972,22 +1972,22 @@ do { \
*/
#define SHAKE256_GET_HASH_X4_32(state, hash) \
do { \
((word64*)((hash) + 0 * 32))[0] = (state)[ 0]; \
((word64*)((hash) + 1 * 32))[0] = (state)[ 1]; \
((word64*)((hash) + 2 * 32))[0] = (state)[ 2]; \
((word64*)((hash) + 3 * 32))[0] = (state)[ 3]; \
((word64*)((hash) + 0 * 32))[1] = (state)[ 4]; \
((word64*)((hash) + 1 * 32))[1] = (state)[ 5]; \
((word64*)((hash) + 2 * 32))[1] = (state)[ 6]; \
((word64*)((hash) + 3 * 32))[1] = (state)[ 7]; \
((word64*)((hash) + 0 * 32))[2] = (state)[ 8]; \
((word64*)((hash) + 1 * 32))[2] = (state)[ 9]; \
((word64*)((hash) + 2 * 32))[2] = (state)[10]; \
((word64*)((hash) + 3 * 32))[2] = (state)[11]; \
((word64*)((hash) + 0 * 32))[3] = (state)[12]; \
((word64*)((hash) + 1 * 32))[3] = (state)[13]; \
((word64*)((hash) + 2 * 32))[3] = (state)[14]; \
((word64*)((hash) + 3 * 32))[3] = (state)[15]; \
writeUnalignedWord64((hash) + 0 * 32 + 0 * 8, (state)[ 0]); \
writeUnalignedWord64((hash) + 1 * 32 + 0 * 8, (state)[ 1]); \
writeUnalignedWord64((hash) + 2 * 32 + 0 * 8, (state)[ 2]); \
writeUnalignedWord64((hash) + 3 * 32 + 0 * 8, (state)[ 3]); \
writeUnalignedWord64((hash) + 0 * 32 + 1 * 8, (state)[ 4]); \
writeUnalignedWord64((hash) + 1 * 32 + 1 * 8, (state)[ 5]); \
writeUnalignedWord64((hash) + 2 * 32 + 1 * 8, (state)[ 6]); \
writeUnalignedWord64((hash) + 3 * 32 + 1 * 8, (state)[ 7]); \
writeUnalignedWord64((hash) + 0 * 32 + 2 * 8, (state)[ 8]); \
writeUnalignedWord64((hash) + 1 * 32 + 2 * 8, (state)[ 9]); \
writeUnalignedWord64((hash) + 2 * 32 + 2 * 8, (state)[10]); \
writeUnalignedWord64((hash) + 3 * 32 + 2 * 8, (state)[11]); \
writeUnalignedWord64((hash) + 0 * 32 + 3 * 8, (state)[12]); \
writeUnalignedWord64((hash) + 1 * 32 + 3 * 8, (state)[13]); \
writeUnalignedWord64((hash) + 2 * 32 + 3 * 8, (state)[14]); \
writeUnalignedWord64((hash) + 3 * 32 + 3 * 8, (state)[15]); \
} while (0)
#endif

Expand Down Expand Up @@ -2084,10 +2084,10 @@ static void slhdsakey_shake256_get_hash_x4(const word64* state, byte* hash,
int i;

for (i = 0; i < (n / 8); i++) {
((word64*)(hash + 0 * n))[i] = state[4 * i + 0];
((word64*)(hash + 1 * n))[i] = state[4 * i + 1];
((word64*)(hash + 2 * n))[i] = state[4 * i + 2];
((word64*)(hash + 3 * n))[i] = state[4 * i + 3];
writeUnalignedWord64(hash + 0 * n + i * 8, state[4 * i + 0]);
writeUnalignedWord64(hash + 1 * n + i * 8, state[4 * i + 1]);
writeUnalignedWord64(hash + 2 * n + i * 8, state[4 * i + 2]);
writeUnalignedWord64(hash + 3 * n + i * 8, state[4 * i + 3]);
}
}

Expand Down Expand Up @@ -5155,10 +5155,10 @@ static int slhdsakey_hash_f_ti_x4(const byte* pk_seed, byte* addr, byte* node,
o = slhdsakey_shake256_set_seed_ha_x4(state, pk_seed, addr, n);
SHAKE256_SET_TREE_INDEX(state, o, ti);
for (i = 0; i < n / 8; i++) {
state[o + 0] = ((word64*)(node + 0 * n))[i];
state[o + 1] = ((word64*)(node + 1 * n))[i];
state[o + 2] = ((word64*)(node + 2 * n))[i];
state[o + 3] = ((word64*)(node + 3 * n))[i];
state[o + 0] = readUnalignedWord64(node + 0 * n + i * 8);
state[o + 1] = readUnalignedWord64(node + 1 * n + i * 8);
state[o + 2] = readUnalignedWord64(node + 2 * n + i * 8);
state[o + 3] = readUnalignedWord64(node + 3 * n + i * 8);
o += 4;
}
SHAKE256_SET_END_X4(state, o);
Expand Down Expand Up @@ -5212,10 +5212,10 @@ static int slhdsakey_hash_h_ti_x4(const byte* pk_seed, byte* addr,
o = slhdsakey_shake256_set_seed_ha_x4(state, pk_seed, addr, n);
SHAKE256_SET_TREE_INDEX(state, o, ti);
for (i = 0; i < 2 * n / 8; i++) {
state[o + 0] = ((const word64*)(m + 0 * n))[i];
state[o + 1] = ((const word64*)(m + 2 * n))[i];
state[o + 2] = ((const word64*)(m + 4 * n))[i];
state[o + 3] = ((const word64*)(m + 6 * n))[i];
state[o + 0] = readUnalignedWord64(m + 0 * n + i * 8);
state[o + 1] = readUnalignedWord64(m + 2 * n + i * 8);
state[o + 2] = readUnalignedWord64(m + 4 * n + i * 8);
state[o + 3] = readUnalignedWord64(m + 6 * n + i * 8);
o += 4;
}
SHAKE256_SET_END_X4(state, o);
Expand Down Expand Up @@ -6009,10 +6009,10 @@ static int slhdsakey_hash_f_ti4_x4(const byte* pk_seed, byte* addr,
o = slhdsakey_shake256_set_seed_ha_x4(state, pk_seed, addr, n);
SHAKE256_SET_TREE_INDEX_IDX(state, o, ti);
for (i = 0; i < n / 8; i++) {
state[o + 0] = ((const word64*)(sig_fors + 0 * so * n))[i];
state[o + 1] = ((const word64*)(sig_fors + 1 * so * n))[i];
state[o + 2] = ((const word64*)(sig_fors + 2 * so * n))[i];
state[o + 3] = ((const word64*)(sig_fors + 3 * so * n))[i];
state[o + 0] = readUnalignedWord64(sig_fors + 0 * so * n + i * 8);
state[o + 1] = readUnalignedWord64(sig_fors + 1 * so * n + i * 8);
state[o + 2] = readUnalignedWord64(sig_fors + 2 * so * n + i * 8);
state[o + 3] = readUnalignedWord64(sig_fors + 3 * so * n + i * 8);
o += 4;
}
SHAKE256_SET_END_X4(state, o);
Expand Down Expand Up @@ -6074,11 +6074,12 @@ static int slhdsakey_hash_h_2_x4(const byte* pk_seed, byte* addr, byte* node,
for (i = 0; i < n / 8; i++) {
for (j = 0; j < 4; j++) {
if (bit[j] == 0) {
state[o + j] = ((const word64*)(node + j * n))[i];
state[o + j] = readUnalignedWord64(node + j * n + i * 8);
}
else {
state[o + j] =
((const word64*)(sig_fors + j * (word32)so * n))[i];
readUnalignedWord64(sig_fors + j *
(word32)so * n + i * 8);
}
}
o += 4;
Expand All @@ -6087,10 +6088,11 @@ static int slhdsakey_hash_h_2_x4(const byte* pk_seed, byte* addr, byte* node,
for (j = 0; j < 4; j++) {
if (bit[j] == 0) {
state[o + j] =
((const word64*)(sig_fors + j * (word32)so * n))[i];
readUnalignedWord64(sig_fors + j *
(word32)so * n + i * 8);
}
else {
state[o + j] = ((const word64*)(node + j * n))[i];
state[o + j] = readUnalignedWord64(node + j * n + i * 8);
}
}
o += 4;
Expand Down
Loading
Loading