Skip to content

Commit 8ad73d8

Browse files
committed
Fix compile and crypt test failures when selftest is enabled
1 parent 9427f9f commit 8ad73d8

5 files changed

Lines changed: 25 additions & 4 deletions

File tree

tests/api/test_dsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int test_wc_DsaSignVerify(void)
117117
ExpectIntEQ(wc_DsaVerify(hash, signature, NULL, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
118118
ExpectIntEQ(wc_DsaVerify(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
119119

120-
#if !defined(HAVE_FIPS) && defined(WOLFSSL_PUBLIC_MP)
120+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) && defined(WOLFSSL_PUBLIC_MP)
121121
/* hard set q to 0 and test fail case */
122122
mp_free(&key.q);
123123
ExpectIntEQ(mp_init(&key.q), 0);

tests/api/test_ecc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,8 @@ int test_wc_ecc_export_x963_ex(void)
676676
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
677677
ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, COMP),
678678
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
679-
#if defined(HAVE_FIPS) && (!defined(FIPS_VERSION_LT) || FIPS_VERSION_LT(5,3))
679+
#if (defined(HAVE_FIPS) && (!defined(FIPS_VERSION_LT) || FIPS_VERSION_LT(5,3)))\
680+
|| defined(HAVE_SELFTEST)
680681
ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP),
681682
WC_NO_ERR_TRACE(BUFFER_E));
682683
#else

tests/api/test_ossl_ec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ int test_wolfSSL_EC_POINT(void)
610610
hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_COMPRESSED, ctx);
611611
ExpectNotNull(hexStr);
612612
ExpectStrEQ(hexStr, compG);
613-
#ifdef HAVE_COMP_KEY
613+
#if defined(HAVE_COMP_KEY) && !defined(HAVE_SELFTEST)
614614
ExpectNotNull(get_point = EC_POINT_hex2point
615615
(group, hexStr, get_point, ctx));
616616
ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);

wolfcrypt/src/asn.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13211,7 +13211,8 @@ static int SetEccPublicKey(byte* output, ecc_key* key, int outLen,
1321113211
if (ret == 0) {
1321213212
/* Calculate the size of the encoded public point. */
1321313213
PRIVATE_KEY_UNLOCK();
13214-
#if defined(HAVE_COMP_KEY) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
13214+
#if defined(HAVE_COMP_KEY) && \
13215+
(defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)))
1321513216
/* in earlier versions of FIPS the get length functionality is not
1321613217
* available with compressed keys */
1321713218
pubSz = key->dp ? key->dp->size : MAX_ECC_BYTES;

wolfcrypt/src/cmac.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,19 @@ int wc_InitCmac_ex(Cmac* cmac, const byte* key, word32 keySz,
163163
byte l[WC_AES_BLOCK_SIZE];
164164

165165
XMEMSET(l, 0, WC_AES_BLOCK_SIZE);
166+
#ifndef HAVE_SELFTEST
166167
ret = wc_AesEncryptDirect(&cmac->aes, l, l);
167168
if (ret == 0) {
168169
ShiftAndXorRb(cmac->k1, l);
169170
ShiftAndXorRb(cmac->k2, cmac->k1);
170171
ForceZero(l, WC_AES_BLOCK_SIZE);
171172
}
173+
#else
174+
wc_AesEncryptDirect(&cmac->aes, l, l);
175+
ShiftAndXorRb(cmac->k1, l);
176+
ShiftAndXorRb(cmac->k2, cmac->k1);
177+
ForceZero(l, WC_AES_BLOCK_SIZE);
178+
#endif
172179
}
173180
break;
174181
#endif /* !NO_AES && WOLFSSL_AES_DIRECT */
@@ -233,12 +240,19 @@ int wc_CmacUpdate(Cmac* cmac, const byte* in, word32 inSz)
233240
if (cmac->totalSz != 0) {
234241
xorbuf(cmac->buffer, cmac->digest, WC_AES_BLOCK_SIZE);
235242
}
243+
#ifndef HAVE_SELFTEST
236244
ret = wc_AesEncryptDirect(&cmac->aes, cmac->digest,
237245
cmac->buffer);
238246
if (ret == 0) {
239247
cmac->totalSz += WC_AES_BLOCK_SIZE;
240248
cmac->bufferSz = 0;
241249
}
250+
#else
251+
wc_AesEncryptDirect(&cmac->aes, cmac->digest,
252+
cmac->buffer);
253+
cmac->totalSz += WC_AES_BLOCK_SIZE;
254+
cmac->bufferSz = 0;
255+
#endif
242256
}
243257
}
244258
}; break;
@@ -332,10 +346,15 @@ int wc_CmacFinalNoFree(Cmac* cmac, byte* out, word32* outSz)
332346
}
333347
xorbuf(cmac->buffer, cmac->digest, WC_AES_BLOCK_SIZE);
334348
xorbuf(cmac->buffer, subKey, WC_AES_BLOCK_SIZE);
349+
#ifndef HAVE_SELFTEST
335350
ret = wc_AesEncryptDirect(&cmac->aes, cmac->digest, cmac->buffer);
336351
if (ret == 0) {
337352
XMEMCPY(out, cmac->digest, *outSz);
338353
}
354+
#else
355+
wc_AesEncryptDirect(&cmac->aes, cmac->digest, cmac->buffer);
356+
XMEMCPY(out, cmac->digest, *outSz);
357+
#endif
339358
}; break;
340359
#endif /* !NO_AES && WOLFSSL_AES_DIRECT */
341360
default:

0 commit comments

Comments
 (0)