Fixes for different build configurations

This commit is contained in:
Sean Parkinson
2019-03-25 09:28:27 +10:00
parent b24e122a0d
commit b40e0888ad
10 changed files with 57 additions and 31 deletions
+19 -6
View File
@@ -494,6 +494,7 @@ static const char* bench_result_words1[][4] = {
defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
defined(HAVE_ED25519)
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
static const char* bench_desc_words[][9] = {
/* 0 1 2 3 4 5 6 7 8 */
@@ -503,6 +504,7 @@ static const char* bench_desc_words[][9] = {
#endif
};
#endif
#endif
#if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
@@ -618,6 +620,7 @@ static const char* bench_desc_words[][9] = {
#endif
#if defined(BENCH_ASYM)
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
static const char* bench_result_words2[][5] = {
{ "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
#ifndef NO_MULTIBYTE_PRINT
@@ -625,6 +628,7 @@ static const char* bench_result_words2[][5] = {
#endif
};
#endif
#endif
/* Asynchronous helper macros */
static THREAD_LS_T int devId = INVALID_DEVID;
@@ -1051,6 +1055,7 @@ static void bench_stats_sym_finish(const char* desc, int doAsync, int count,
}
#ifdef BENCH_ASYM
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
static void bench_stats_asym_finish(const char* algo, int strength,
const char* desc, int doAsync, int count, double start, int ret)
{
@@ -1091,6 +1096,7 @@ static void bench_stats_asym_finish(const char* algo, int strength,
(void)doAsync;
(void)ret;
}
#endif
#endif /* BENCH_ASYM */
static WC_INLINE void bench_stats_free(void)
@@ -3945,7 +3951,8 @@ void bench_rsaKeyGen_size(int doAsync, int keySz)
#define RSA_BUF_SIZE 384 /* for up to 3072 bit */
#if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
#elif defined(USE_CERT_BUFFERS_2048)
#elif defined(WOLFSSL_PUBLIC_MP)
#if defined(USE_CERT_BUFFERS_2048)
static unsigned char rsa_2048_sig[] = {
0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
@@ -3980,7 +3987,7 @@ static unsigned char rsa_2048_sig[] = {
0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
};
#elif defined(USE_CERT_BUFFERS_3072)
#elif defined(USE_CERT_BUFFERS_3072)
static unsigned char rsa_3072_sig[] = {
0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
@@ -4031,10 +4038,12 @@ static unsigned char rsa_3072_sig[] = {
0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
};
#else
#error Not Supported Yet!
#else
#error Not Supported Yet!
#endif
#endif
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
static void bench_rsa_helper(int doAsync, RsaKey rsaKey[BENCH_MAX_PENDING],
int rsaKeySz)
{
@@ -4227,12 +4236,13 @@ exit_rsa_verify:
#endif
FREE_VAR(message, HEAP_HINT);
}
#endif
void bench_rsa(int doAsync)
{
int ret = 0, i;
RsaKey rsaKey[BENCH_MAX_PENDING];
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
int rsaKeySz = RSA_BUF_SIZE * 8; /* used in printf */
size_t bytes;
const byte* tmp;
@@ -4253,6 +4263,7 @@ void bench_rsa(int doAsync)
#else
#error "need a cert buffer size"
#endif /* USE_CERT_BUFFERS */
#endif
/* clear for done cleanup */
XMEMSET(rsaKey, 0, sizeof(rsaKey));
@@ -4281,7 +4292,7 @@ void bench_rsa(int doAsync)
printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
goto exit_bench_rsa;
}
#else
#elif defined(WOLFSSL_PUBLIC_MP)
#ifdef USE_CERT_BUFFERS_2048
ret = mp_read_unsigned_bin(&rsaKey[i].n, &tmp[12], 256);
if (ret != 0) {
@@ -4302,7 +4313,9 @@ void bench_rsa(int doAsync)
}
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_PUBLIC_MP)
bench_rsa_helper(doAsync, rsaKey, rsaKeySz);
#endif
exit_bench_rsa:
/* cleanup */
for (i = 0; i < BENCH_MAX_PENDING; i++) {
+3 -2
View File
@@ -22505,7 +22505,8 @@ int sp_ecc_mulmod_base_256(mp_int* km, ecc_point* r, int map, void* heap)
return err;
}
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN)
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
/* Returns 1 if the number of zero.
* Implementation is constant time.
*
@@ -22517,7 +22518,7 @@ static int sp_256_iszero_8(const sp_digit* a)
return (a[0] | a[1] | a[2] | a[3] | a[4] | a[5] | a[6] | a[7]) == 0;
}
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN */
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN || HAVE_ECC_VERIFY */
/* Add 1 to a. (a = a + 1)
*
* a A single precision integer.
+3 -2
View File
@@ -27825,7 +27825,8 @@ int sp_ecc_mulmod_base_256(mp_int* km, ecc_point* r, int map, void* heap)
return err;
}
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN)
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
/* Returns 1 if the number of zero.
* Implementation is constant time.
*
@@ -27837,7 +27838,7 @@ static int sp_256_iszero_4(const sp_digit* a)
return (a[0] | a[1] | a[2] | a[3]) == 0;
}
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN */
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN || HAVE_ECC_VERIFY */
/* Add 1 to a. (a = a + 1)
*
* a A single precision integer.
+3 -2
View File
@@ -14500,7 +14500,8 @@ int sp_ecc_mulmod_base_256(mp_int* km, ecc_point* r, int map, void* heap)
return err;
}
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN)
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
/* Returns 1 if the number of zero.
* Implementation is constant time.
*
@@ -14512,7 +14513,7 @@ static int sp_256_iszero_8(const sp_digit* a)
return (a[0] | a[1] | a[2] | a[3] | a[4] | a[5] | a[6] | a[7]) == 0;
}
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN */
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN || HAVE_ECC_VERIFY */
/* Add 1 to a. (a = a + 1)
*
* a A single precision integer.
+3 -2
View File
@@ -11036,7 +11036,8 @@ int sp_ecc_mulmod_base_256(mp_int* km, ecc_point* r, int map, void* heap)
return err;
}
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN)
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
/* Returns 1 if the number of zero.
* Implementation is constant time.
*
@@ -11049,7 +11050,7 @@ static int sp_256_iszero_10(const sp_digit* a)
a[8] | a[9]) == 0;
}
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN */
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN || HAVE_ECC_VERIFY */
/* Add 1 to a. (a = a + 1)
*
* r A single precision integer.
+3 -2
View File
@@ -10629,7 +10629,8 @@ int sp_ecc_mulmod_base_256(mp_int* km, ecc_point* r, int map, void* heap)
return err;
}
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN)
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
/* Returns 1 if the number of zero.
* Implementation is constant time.
*
@@ -10641,7 +10642,7 @@ static int sp_256_iszero_5(const sp_digit* a)
return (a[0] | a[1] | a[2] | a[3] | a[4]) == 0;
}
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN */
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN || HAVE_ECC_VERIFY */
/* Add 1 to a. (a = a + 1)
*
* r A single precision integer.
+3 -2
View File
@@ -15412,7 +15412,8 @@ int sp_ecc_mulmod_base_256(mp_int* km, ecc_point* r, int map, void* heap)
return err;
}
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN)
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
/* Returns 1 if the number of zero.
* Implementation is constant time.
*
@@ -15424,7 +15425,7 @@ static int sp_256_iszero_8(const sp_digit* a)
return (a[0] | a[1] | a[2] | a[3] | a[4] | a[5] | a[6] | a[7]) == 0;
}
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN */
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN || HAVE_ECC_VERIFY */
/* Add 1 to a. (a = a + 1)
*
* a A single precision integer.
+7 -3
View File
@@ -288,7 +288,8 @@ int sp_leading_bit(sp_int* a)
return bit;
}
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
#if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
!defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Convert the big number to an array of bytes in big-endian format.
* The array must be large enough for encoded number - use mp_unsigned_bin_size
* to calculate the number of bytes required.
@@ -479,7 +480,7 @@ int sp_cmp_d(sp_int *a, sp_int_digit d)
return MP_EQ;
}
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
#if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Left shift the number by number of bits.
* Bits may be larger than the word size.
*
@@ -620,7 +621,8 @@ int sp_add_d(sp_int* a, sp_int_digit d, sp_int* r)
return MP_OKAY;
}
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
#if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
!defined(WOLFSSL_RSA_VERIFY_ONLY)
/* Left shift the big number by a number of digits.
* WIll chop off digits overflowing maximum size.
*
@@ -639,7 +641,9 @@ int sp_lshd(sp_int* a, int s)
return MP_OKAY;
}
#endif
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
#ifndef NO_PWDBASED
/* Add two large numbers into result: r = a + b
*
+3 -2
View File
@@ -19630,7 +19630,8 @@ int sp_ecc_mulmod_base_256(mp_int* km, ecc_point* r, int map, void* heap)
return err;
}
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN)
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
/* Returns 1 if the number of zero.
* Implementation is constant time.
*
@@ -19642,7 +19643,7 @@ static int sp_256_iszero_4(const sp_digit* a)
return (a[0] | a[1] | a[2] | a[3]) == 0;
}
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN */
#endif /* WOLFSSL_VALIDATE_ECC_KEYGEN || HAVE_ECC_SIGN || HAVE_ECC_VERIFY */
extern void sp_256_add_one_4(sp_digit* a);
/* Read big endian unsigned byte aray into r.
*
+10 -8
View File
@@ -11008,12 +11008,14 @@ int rsa_test(void)
#if defined(HAVE_NTRU)
RsaKey caKey;
#endif
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_MP_PUBLIC)
word32 idx = 0;
byte* res;
const char* inStr = "Everyone gets Friday off.";
word32 inLen = (word32)XSTRLEN((char*)inStr);
byte* res;
const word32 outSz = RSA_TEST_BYTES;
const word32 plainSz = RSA_TEST_BYTES;
#endif
#ifndef NO_SIG_WRAPPER
int modLen;
#endif
@@ -11026,9 +11028,11 @@ int rsa_test(void)
DecodedCert cert;
#endif
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_MP_PUBLIC)
DECLARE_VAR_INIT(in, byte, inLen, inStr, HEAP_HINT);
DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
#endif
#ifdef WOLFSSL_ASYNC_CRYPT
if (in == NULL)
@@ -11103,7 +11107,7 @@ int rsa_test(void)
#ifndef NO_SIG_WRAPPER
modLen = wc_RsaEncryptSize(&key);
#endif
#elif defined(WOLFSSL_RSA_PUBLIC_ONLY)
#elif defined(WOLFSSL_RSA_PUBLIC_ONLY) && defined(WOLFSSL_MP_PUBLIC)
#ifdef USE_CERT_BUFFERS_2048
ret = mp_read_unsigned_bin(&key.n, &tmp[12], 256);
if (ret != 0) {
@@ -11213,7 +11217,7 @@ int rsa_test(void)
if (ret < 0) {
ERROR_OUT(-7013, exit_rsa);
}
#else
#elif defined(WOLFSSL_MP_PUBLIC)
(void)outSz;
(void)inLen;
(void)res;
@@ -11257,6 +11261,7 @@ int rsa_test(void)
}
#endif
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_MP_PUBLIC)
idx = (word32)ret;
XMEMSET(plain, 0, plainSz);
do {
@@ -11282,6 +11287,7 @@ int rsa_test(void)
if (XMEMCMP(plain, in, (size_t)ret)) {
ERROR_OUT(-7015, exit_rsa);
}
#endif
#ifndef WOLFSSL_RSA_VERIFY_ONLY
#ifndef WC_NO_RSA_OAEP
@@ -11304,10 +11310,8 @@ int rsa_test(void)
if (ret < 0) {
ERROR_OUT(-7016, exit_rsa);
}
#endif /* WOLFSSL_RSA_VERIFY_ONLY */
idx = (word32)ret;
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
do {
#if defined(WOLFSSL_ASYNC_CRYPT)
ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
@@ -11324,7 +11328,6 @@ int rsa_test(void)
if (XMEMCMP(plain, in, inLen)) {
ERROR_OUT(-7018, exit_rsa);
}
#endif /* WOLFSSL_RSA_PUBLIC_ONLY */
#endif /* NO_SHA */
#ifndef NO_SHA256
@@ -11461,7 +11464,6 @@ int rsa_test(void)
#ifndef NO_SHA
/* check fail using mismatch hash algorithms */
XMEMSET(plain, 0, plainSz);
#ifndef WOLFSSL_RSA_VERIFY_ONLY
do {
#if defined(WOLFSSL_ASYNC_CRYPT)
ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
@@ -11494,6 +11496,7 @@ int rsa_test(void)
ret = 0;
#endif /* !HAVE_CAVIUM */
#endif /* NO_SHA*/
#endif /* WOLFSSL_RSA_VERIFY_ONLY */
#endif /* NO_SHA256 */
#ifdef WOLFSSL_SHA512
@@ -11574,7 +11577,6 @@ int rsa_test(void)
#endif /* WOLFSSL_RSA_PUBLIC_ONLY */
#endif /* !HAVE_FAST_RSA && !HAVE_FIPS */
#endif /* WC_NO_RSA_OAEP */
#endif
#endif /* WOLFSSL_RSA_VERIFY_ONLY */
#if !defined(HAVE_FIPS) && !defined(HAVE_USER_RSA) && !defined(NO_ASN) \