Fixup for compiling verify only inline for PPC using GCC

This commit is contained in:
Sean Parkinson
2018-12-10 11:52:10 +10:00
parent c122f6082f
commit fb41510f12
4 changed files with 1071 additions and 979 deletions

View File

@ -458,8 +458,7 @@ static const char* bench_result_words1[][4] = {
#endif
};
#if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) ||\
defined(WOLFSSL_KEY_GEN) || defined(HAVE_NTRU) || \
#if !defined(NO_RSA) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_NTRU) || \
defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
defined(HAVE_ED25519)
@ -578,9 +577,7 @@ static const char* bench_desc_words[][9] = {
#if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || defined(HAVE_ECC) || \
defined(HAVE_ECC) || defined(HAVE_NTRU) || !defined(NO_DH) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
defined(HAVE_SCRYPT)
!defined(NO_RSA) || defined(HAVE_SCRYPT)
#define BENCH_ASYM
#endif
@ -3862,43 +3859,136 @@ void bench_rsaKeyGen_size(int doAsync, int keySz)
#define RSA_BUF_SIZE 384 /* for up to 3072 bit */
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
#elif 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,
0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
0x75, 0xd1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, 0x69, 0x0c, 0x52, 0xdc, 0x42,
0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
};
#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,
0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
0x07, 0xf1, 0xf6, 0x53,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x77, 0x78, 0x1f, 0xf2,
0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
};
#else
#error Not Supported Yet!
#endif
static void bench_rsa_helper(int doAsync, RsaKey rsaKey[BENCH_MAX_PENDING],
int rsaKeySz)
{
#ifndef WOLFSSL_RSA_VERIFY_ONLY
int ret = 0, i, times, count = 0, pending = 0;
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
word32 idx = 0;
#endif
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
const char* messageStr = "Everyone gets Friday off.";
const int len = (int)XSTRLEN((char*)messageStr);
#endif
double start = 0.0f;
const char**desc = bench_desc_words[lng_index];
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
DECLARE_VAR_INIT(message, byte, len, messageStr, HEAP_HINT);
#else
(void)doAsync;
(void)rsaKey;
(void)rsaKeySz;
#endif
#ifndef WOLFSSL_RSA_VERIFY_ONLY
#ifdef USE_CERT_BUFFERS_1024
DECLARE_ARRAY(enc, byte, BENCH_MAX_PENDING, 128, HEAP_HINT);
DECLARE_ARRAY(out, byte, BENCH_MAX_PENDING, 128, HEAP_HINT);
#ifndef WOLFSSL_RSA_VERIFY_INLINE
DECLARE_ARRAY(out, byte, BENCH_MAX_PENDING, 128, HEAP_HINT);
#else
byte* out[BENCH_MAX_PENDING];
#endif
#elif defined(USE_CERT_BUFFERS_2048)
DECLARE_ARRAY(enc, byte, BENCH_MAX_PENDING, 256, HEAP_HINT);
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
#ifndef WOLFSSL_RSA_VERIFY_INLINE
DECLARE_ARRAY(out, byte, BENCH_MAX_PENDING, 256, HEAP_HINT);
#else
byte* out[BENCH_MAX_PENDING];
#endif
#elif defined(USE_CERT_BUFFERS_3072)
DECLARE_ARRAY(enc, byte, BENCH_MAX_PENDING, 384, HEAP_HINT);
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
#ifndef WOLFSSL_RSA_VERIFY_INLINE
DECLARE_ARRAY(out, byte, BENCH_MAX_PENDING, 384, HEAP_HINT);
#else
byte* out[BENCH_MAX_PENDING];
#endif
#else
#error "need a cert buffer size"
#endif /* USE_CERT_BUFFERS */
#endif
if (!rsa_sign_verify) {
#ifndef WOLFSSL_RSA_VERIFY_ONLY
@ -3995,6 +4085,7 @@ exit_rsa_sign:
if (ret < 0) {
goto exit;
}
#endif
/* capture resulting encrypt length */
idx = rsaKeySz/8;
@ -4009,8 +4100,26 @@ exit_rsa_sign:
for (i = 0; i < BENCH_MAX_PENDING; i++) {
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]),
1, &times, ntimes, &pending)) {
#ifndef WOLFSSL_RSA_VERIFY_INLINE
ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
rsaKeySz/8, &rsaKey[i]);
#elif defined(USE_CERT_BUFFERS_2048)
XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
idx = sizeof(rsa_2048_sig);
out[i] = NULL;
ret = wc_RsaSSL_VerifyInline(enc[i], idx, &out[i],
&rsaKey[i]);
if (ret > 0)
ret = 0;
#elif defined(USE_CERT_BUFFERS_3072)
XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
idx = sizeof(rsa_3072_sig);
out[i] = NULL;
ret = wc_RsaSSL_VerifyInline(enc[i], idx, &out[i],
&rsaKey[i]);
if (ret > 0)
ret = 0;
#endif
if (!bench_async_handle(&ret,
BENCH_ASYNC_GET_DEV(&rsaKey[i]),
1, &times, &pending)) {
@ -4024,7 +4133,6 @@ exit_rsa_sign:
exit_rsa_verify:
bench_stats_asym_finish("RSA", rsaKeySz, desc[5], doAsync, count,
start, ret);
#endif
}
FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
@ -4085,7 +4193,18 @@ void bench_rsa(int doAsync)
}
#else
#ifdef USE_CERT_BUFFERS_2048
ret = mp_read_unsigned_bin(&rsaKey[i].n, &tmp[13], 256);
ret = mp_read_unsigned_bin(&rsaKey[i].n, &tmp[12], 256);
if (ret != 0) {
printf("Setting modulus failed! %d\n", ret);
goto exit_bench_rsa;
}
ret = mp_set_int(&rsaKey[i].e, WC_RSA_EXPONENT);
if (ret != 0) {
printf("Setting public exponent failed! %d\n", ret);
goto exit_bench_rsa;
}
#elif defined(USE_CERT_BUFFERS_3072)
ret = mp_read_unsigned_bin(&rsaKey[i].n, &tmp[12], 384);
if (ret != 0) {
printf("Setting modulus failed! %d\n", ret);
goto exit_bench_rsa;

View File

@ -1253,7 +1253,9 @@ static int RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
{
int ret;
word32 i;
#ifndef WOLFSSL_RSA_VERIFY_ONLY
byte invalid = 0;
#endif
if (output == NULL || pkcsBlockLen == 0) {
return BAD_FUNC_ARG;
@ -1278,6 +1280,7 @@ static int RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
*output = (byte *)(pkcsBlock + i);
ret = pkcsBlockLen - i;
}
#ifndef WOLFSSL_RSA_VERIFY_ONLY
else {
word32 j;
byte pastSep = 0;
@ -1301,6 +1304,7 @@ static int RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
*output = (byte *)(pkcsBlock + i);
ret = ((int)~invalid) & (pkcsBlockLen - i);
}
#endif
return ret;
}

File diff suppressed because it is too large Load Diff

View File

@ -2399,10 +2399,10 @@ void fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
/* Use Duff's device to unroll the loop. */
int idx = (c - 1) & ~3;
switch (c % 4) {
case 0: do { pd[idx+0] = *b++;
case 3: pd[idx+1] = *b++;
case 2: pd[idx+2] = *b++;
case 1: pd[idx+3] = *b++;
case 0: do { pd[idx+0] = *b++; // fallthrough
case 3: pd[idx+1] = *b++; // fallthrough
case 2: pd[idx+2] = *b++; // fallthrough
case 1: pd[idx+3] = *b++; // fallthrough
idx -= 4;
} while ((c -= 4) > 0);
}