reduce benchmark stack use, reduce max variable sizes

This commit is contained in:
toddouska
2015-05-07 14:24:58 -07:00
parent 4fe04c6bed
commit 8f8fb3834a

View File

@ -93,6 +93,11 @@
#define SHOW_INTEL_CYCLES
#endif
/* let's use buffers, we have them */
#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
#define USE_CERT_BUFFERS_2048
#endif
#if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) \
|| !defined(NO_DH)
/* include test cert and key buffers for use with NO_FILESYSTEM */
@ -1127,12 +1132,12 @@ void bench_rsa(void)
{
int i;
int ret;
byte tmp[3072];
size_t bytes;
word32 idx = 0;
const byte* tmp;
byte message[] = "Everyone gets Friday off.";
byte enc[512]; /* for up to 4096 bit */
byte enc[256]; /* for up to 2048 bit */
const int len = (int)strlen((char*)message);
double start, total, each, milliEach;
@ -1140,22 +1145,14 @@ void bench_rsa(void)
int rsaKeySz = 2048; /* used in printf */
#ifdef USE_CERT_BUFFERS_1024
XMEMCPY(tmp, rsa_key_der_1024, sizeof_rsa_key_der_1024);
tmp = rsa_key_der_1024;
bytes = sizeof_rsa_key_der_1024;
rsaKeySz = 1024;
#elif defined(USE_CERT_BUFFERS_2048)
XMEMCPY(tmp, rsa_key_der_2048, sizeof_rsa_key_der_2048);
tmp = rsa_key_der_2048;
bytes = sizeof_rsa_key_der_2048;
#else
FILE* file = fopen(certRSAname, "rb");
if (!file) {
printf("can't find %s, Please run from wolfSSL home dir\n", certRSAname);
return;
}
bytes = fread(tmp, 1, sizeof(tmp), file);
fclose(file);
#error "need a cert buffer size"
#endif /* USE_CERT_BUFFERS */
@ -1190,7 +1187,7 @@ void bench_rsa(void)
start = current_time(1);
for (i = 0; i < ntimes; i++) {
byte out[512]; /* for up to 4096 bit */
byte out[256]; /* for up to 2048 bit */
wc_RsaPrivateDecrypt(enc, (word32)ret, out, sizeof(out), &rsaKey);
}
@ -1229,15 +1226,15 @@ void bench_rsa(void)
void bench_dh(void)
{
int i ;
byte tmp[1024];
size_t bytes;
word32 idx = 0, pubSz, privSz = 0, pubSz2, privSz2, agreeSz;
const byte* tmp;
byte pub[256]; /* for 2048 bit */
byte priv[256]; /* for 2048 bit */
byte pub2[256]; /* for 2048 bit */
byte priv2[256]; /* for 2048 bit */
byte agree[256]; /* for 2048 bit */
byte priv[32]; /* for 2048 bit */
byte priv2[32]; /* for 2048 bit */
double start, total, each, milliEach;
DhKey dhKey;
@ -1248,24 +1245,17 @@ void bench_dh(void)
#ifdef USE_CERT_BUFFERS_1024
XMEMCPY(tmp, dh_key_der_1024, sizeof_dh_key_der_1024);
tmp = dh_key_der_1024;
bytes = sizeof_dh_key_der_1024;
dhKeySz = 1024;
#elif defined(USE_CERT_BUFFERS_2048)
XMEMCPY(tmp, dh_key_der_2048, sizeof_dh_key_der_2048);
tmp = dh_key_der_2048;
bytes = sizeof_dh_key_der_2048;
#elif defined(NO_ASN)
dhKeySz = 1024;
/* do nothing, but don't use default FILE */
#else
FILE* file = fopen(certDHname, "rb");
if (!file) {
printf("can't find %s, Please run from wolfSSL home dir\n", certDHname);
return;
}
bytes = fread(tmp, 1, sizeof(tmp), file);
#error "need to define a cert buffer size"
#endif /* USE_CERT_BUFFERS */
@ -1274,9 +1264,6 @@ void bench_dh(void)
bytes = wc_DhSetKey(&dhKey, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
#else
bytes = wc_DhKeyDecode(tmp, &idx, &dhKey, (word32)bytes);
#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
fclose(file);
#endif
#endif
if (bytes != 0) {
printf("dhekydecode failed, can't benchmark\n");
@ -1576,8 +1563,8 @@ void bench_eccKeyAgree(void)
ecc_key genKey, genKey2;
double start, total, each, milliEach;
int i, ret;
byte shared[1024];
byte sig[1024];
byte shared[32];
byte sig[64+16]; /* der encoding too */
byte digest[32];
word32 x = 0;
@ -1686,7 +1673,7 @@ void bench_curve25519KeyAgree(void)
curve25519_key genKey, genKey2;
double start, total, each, milliEach;
int i, ret;
byte shared[1024];
byte shared[32];
word32 x = 0;
wc_curve25519_init(&genKey);