Skip to content

Commit 7d0ef5b

Browse files
authored
Merge pull request wolfSSL#8512 from douzzer/20250226-fixes
20250226-fixes
2 parents 0a6a851 + f7ddc49 commit 7d0ef5b

File tree

8 files changed

+97
-14
lines changed

8 files changed

+97
-14
lines changed

linuxkm/linuxkm_wc_port.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
#error Unsupported kernel.
3131
#endif
3232

33+
#if defined(HAVE_FIPS) && defined(LINUXKM_LKCAPI_REGISTER_AESXTS) && defined(CONFIG_CRYPTO_MANAGER_EXTRA_TESTS)
34+
/* CONFIG_CRYPTO_MANAGER_EXTRA_TESTS expects AES-XTS-384 to work, even when CONFIG_CRYPTO_FIPS, but FIPS 140-3 only allows AES-XTS-256 and AES-XTS-512. */
35+
#error CONFIG_CRYPTO_MANAGER_EXTRA_TESTS is incompatible with FIPS wolfCrypt AES-XTS -- please reconfigure the target kernel to disable CONFIG_CRYPTO_MANAGER_EXTRA_TESTS.
36+
#endif
37+
3338
#ifdef HAVE_CONFIG_H
3439
#ifndef PACKAGE_NAME
3540
#error wc_port.h included before config.h

src/internal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41793,7 +41793,7 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
4179341793
ret = args->lastErr;
4179441794
args->lastErr = 0; /* reset */
4179541795
/* On error 'ret' will be negative */
41796-
mask = (byte)((ret >> ((sizeof(ret) * 8) - 1)) & 0xFF) - 1;
41796+
mask = (byte)(((unsigned int)ret >> ((sizeof(ret) * 8) - 1)) - 1);
4179741797

4179841798
/* build PreMasterSecret */
4179941799
ssl->arrays->preMasterSecret[0] = ssl->chVersion.major;

tests/api/test_sha256.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ int test_wc_Sha256Transform(void)
202202
{
203203
EXPECT_DECLS;
204204
#if !defined(NO_SHA256) && (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && \
205+
!defined(WOLFSSL_KCAPI_HASH) && !defined(WOLFSSL_AFALG_HASH) && \
205206
!defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
206207
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))
207208
DIGEST_TRANSFORM_FINAL_RAW_TEST(wc_Sha256, Sha256, SHA256,

tests/api/test_sha3.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ int test_wc_Shake128_Absorb(void)
861861

862862
ExpectIntEQ(wc_InitShake128(&shake128, HEAP_HINT, INVALID_DEVID), 0);
863863

864+
#if !defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)
864865
ExpectIntEQ(wc_Shake128_Absorb(NULL , NULL , 1),
865866
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
866867
ExpectIntEQ(wc_Shake128_Absorb(&shake128, NULL , 1),
@@ -869,6 +870,8 @@ int test_wc_Shake128_Absorb(void)
869870
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
870871

871872
ExpectIntEQ(wc_Shake128_Absorb(&shake128, NULL, 0), 0);
873+
#endif
874+
872875
ExpectIntEQ(wc_Shake128_Absorb(&shake128, (byte*)"a", 1), 0);
873876

874877
wc_Shake128_Free(&shake128);
@@ -885,6 +888,7 @@ int test_wc_Shake128_SqueezeBlocks(void)
885888

886889
ExpectIntEQ(wc_InitShake128(&shake128, HEAP_HINT, INVALID_DEVID), 0);
887890

891+
#if !defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)
888892
ExpectIntEQ(wc_Shake128_SqueezeBlocks(NULL , NULL, 1),
889893
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
890894
ExpectIntEQ(wc_Shake128_SqueezeBlocks(&shake128, NULL, 1),
@@ -893,6 +897,7 @@ int test_wc_Shake128_SqueezeBlocks(void)
893897
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
894898

895899
ExpectIntEQ(wc_Shake128_SqueezeBlocks(&shake128, NULL, 0), 0);
900+
#endif
896901
ExpectIntEQ(wc_Shake128_SqueezeBlocks(&shake128, hash, 1), 0);
897902

898903
wc_Shake128_Free(&shake128);
@@ -1281,6 +1286,7 @@ int test_wc_Shake256_Absorb(void)
12811286

12821287
ExpectIntEQ(wc_InitShake256(&shake256, HEAP_HINT, INVALID_DEVID), 0);
12831288

1289+
#if !defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)
12841290
ExpectIntEQ(wc_Shake256_Absorb(NULL , NULL , 1),
12851291
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
12861292
ExpectIntEQ(wc_Shake256_Absorb(&shake256, NULL , 1),
@@ -1289,6 +1295,7 @@ int test_wc_Shake256_Absorb(void)
12891295
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
12901296

12911297
ExpectIntEQ(wc_Shake256_Absorb(&shake256, NULL, 0), 0);
1298+
#endif
12921299
ExpectIntEQ(wc_Shake256_Absorb(&shake256, (byte*)"a", 1), 0);
12931300

12941301
wc_Shake256_Free(&shake256);
@@ -1305,6 +1312,7 @@ int test_wc_Shake256_SqueezeBlocks(void)
13051312

13061313
ExpectIntEQ(wc_InitShake256(&shake256, HEAP_HINT, INVALID_DEVID), 0);
13071314

1315+
#if !defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)
13081316
ExpectIntEQ(wc_Shake256_SqueezeBlocks(NULL , NULL, 1),
13091317
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
13101318
ExpectIntEQ(wc_Shake256_SqueezeBlocks(&shake256, NULL, 1),
@@ -1313,6 +1321,7 @@ int test_wc_Shake256_SqueezeBlocks(void)
13131321
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
13141322

13151323
ExpectIntEQ(wc_Shake256_SqueezeBlocks(&shake256, NULL, 0), 0);
1324+
#endif
13161325
ExpectIntEQ(wc_Shake256_SqueezeBlocks(&shake256, hash, 1), 0);
13171326

13181327
wc_Shake256_Free(&shake256);

wolfcrypt/src/misc.c

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,28 @@ WC_MISC_STATIC WC_INLINE void ByteReverseWords(word32* out, const word32* in,
189189
out[i] = ByteReverseWord32(in[i]);
190190
}
191191
#ifdef WOLFSSL_USE_ALIGN
192+
else if (((size_t)in & 0x3) == 0) {
193+
byte *out_bytes = (byte *)out;
194+
word32 scratch;
195+
196+
byteCount &= ~0x3U;
197+
198+
for (i = 0; i < byteCount; i += (word32)sizeof(word32)) {
199+
scratch = ByteReverseWord32(*in++);
200+
XMEMCPY(out_bytes + i, &scratch, sizeof(scratch));
201+
}
202+
}
203+
else if (((size_t)out & 0x3) == 0) {
204+
byte *in_bytes = (byte *)in;
205+
word32 scratch;
206+
207+
byteCount &= ~0x3U;
208+
209+
for (i = 0; i < byteCount; i += (word32)sizeof(word32)) {
210+
XMEMCPY(&scratch, in_bytes + i, sizeof(scratch));
211+
*out++ = ByteReverseWord32(scratch);
212+
}
213+
}
192214
else {
193215
byte *in_bytes = (byte *)in;
194216
byte *out_bytes = (byte *)out;
@@ -335,9 +357,51 @@ WC_MISC_STATIC WC_INLINE void ByteReverseWords64(word64* out, const word64* in,
335357
{
336358
word32 count = byteCount/(word32)sizeof(word64), i;
337359

338-
for (i = 0; i < count; i++)
339-
out[i] = ByteReverseWord64(in[i]);
360+
#ifdef WOLFSSL_USE_ALIGN
361+
if ((((size_t)in & 0x7) == 0) &&
362+
(((size_t)out & 0x7) == 0))
363+
#endif
364+
{
365+
for (i = 0; i < count; i++)
366+
out[i] = ByteReverseWord64(in[i]);
367+
}
368+
#ifdef WOLFSSL_USE_ALIGN
369+
else if (((size_t)in & 0x7) == 0) {
370+
byte *out_bytes = (byte *)out;
371+
word64 scratch;
372+
373+
byteCount &= ~0x7U;
374+
375+
for (i = 0; i < byteCount; i += (word32)sizeof(word64)) {
376+
scratch = ByteReverseWord64(*in++);
377+
XMEMCPY(out_bytes + i, &scratch, sizeof(scratch));
378+
}
379+
}
380+
else if (((size_t)out & 0x7) == 0) {
381+
byte *in_bytes = (byte *)in;
382+
word64 scratch;
340383

384+
byteCount &= ~0x7U;
385+
386+
for (i = 0; i < byteCount; i += (word32)sizeof(word64)) {
387+
XMEMCPY(&scratch, in_bytes + i, sizeof(scratch));
388+
*out++ = ByteReverseWord64(scratch);
389+
}
390+
}
391+
else {
392+
byte *in_bytes = (byte *)in;
393+
byte *out_bytes = (byte *)out;
394+
word64 scratch;
395+
396+
byteCount &= ~0x7U;
397+
398+
for (i = 0; i < byteCount; i += (word32)sizeof(word64)) {
399+
XMEMCPY(&scratch, in_bytes + i, sizeof(scratch));
400+
scratch = ByteReverseWord64(scratch);
401+
XMEMCPY(out_bytes + i, &scratch, sizeof(scratch));
402+
}
403+
}
404+
#endif
341405
}
342406

343407
#endif /* WORD64_AVAILABLE && !WOLFSSL_NO_WORD64_OPS */

wolfssl/wolfcrypt/hash.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@ enum wc_MACAlgorithm {
8383
sm3_mac
8484
};
8585

86-
enum wc_HashFlags {
87-
WC_HASH_FLAG_NONE = 0x00000000,
88-
WC_HASH_FLAG_WILLCOPY = 0x00000001, /* flag to indicate hash will be copied */
89-
WC_HASH_FLAG_ISCOPY = 0x00000002, /* hash is copy */
90-
#ifdef WOLFSSL_SHA3
91-
WC_HASH_SHA3_KECCAK256 =0x00010000, /* Older KECCAK256 */
92-
#endif
93-
WOLF_ENUM_DUMMY_LAST_ELEMENT(WC_HASH)
94-
};
95-
9686
/* hash union */
9787
typedef union {
9888
#ifndef NO_MD5

wolfssl/wolfcrypt/sha256.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,14 @@ struct wc_Sha256 {
264264
WOLFSSL_API int wc_InitSha256(wc_Sha256* sha);
265265
WOLFSSL_API int wc_InitSha256_ex(wc_Sha256* sha, void* heap, int devId);
266266
WOLFSSL_API int wc_Sha256Update(wc_Sha256* sha, const byte* data, word32 len);
267+
268+
#if !defined(WOLFSSL_KCAPI_HASH) && !defined(WOLFSSL_AFALG_HASH)
267269
WOLFSSL_API int wc_Sha256FinalRaw(wc_Sha256* sha256, byte* hash);
270+
#endif
268271
WOLFSSL_API int wc_Sha256Final(wc_Sha256* sha256, byte* hash);
269272
WOLFSSL_API void wc_Sha256Free(wc_Sha256* sha256);
270-
#if defined(OPENSSL_EXTRA) || defined(HAVE_CURL)
273+
#if (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && \
274+
!defined(WOLFSSL_KCAPI_HASH) && !defined(WOLFSSL_AFALG_HASH)
271275
WOLFSSL_API int wc_Sha256Transform(wc_Sha256* sha, const unsigned char* data);
272276
#endif
273277
#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_FULL_HASH)

wolfssl/wolfcrypt/types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,16 @@ typedef struct w64wrapper {
12471247
#endif /* HAVE_SELFTEST */
12481248
};
12491249

1250+
enum wc_HashFlags {
1251+
WC_HASH_FLAG_NONE = 0x00000000,
1252+
WC_HASH_FLAG_WILLCOPY = 0x00000001, /* flag to indicate hash will be copied */
1253+
WC_HASH_FLAG_ISCOPY = 0x00000002, /* hash is copy */
1254+
#ifdef WOLFSSL_SHA3
1255+
WC_HASH_SHA3_KECCAK256 =0x00010000, /* Older KECCAK256 */
1256+
#endif
1257+
WOLF_ENUM_DUMMY_LAST_ELEMENT(WC_HASH)
1258+
};
1259+
12501260
/* cipher types */
12511261
enum wc_CipherType {
12521262
WC_CIPHER_NONE = 0,

0 commit comments

Comments
 (0)