Fix for benchmarking X25519

This commit is contained in:
Sean Parkinson
2017-05-31 11:44:43 +10:00
parent 1bc862ae24
commit a30e8eb4ad

View File

@ -156,7 +156,7 @@ static void ShowVersions(void)
/* Measures average time to create, connect and disconnect a connection (TPS). /* Measures average time to create, connect and disconnect a connection (TPS).
Benchmark = number of connections. */ Benchmark = number of connections. */
static int ClientBenchmarkConnections(WOLFSSL_CTX* ctx, char* host, word16 port, static int ClientBenchmarkConnections(WOLFSSL_CTX* ctx, char* host, word16 port,
int dtlsUDP, int dtlsSCTP, int benchmark, int resumeSession) int dtlsUDP, int dtlsSCTP, int benchmark, int resumeSession, int useX25519)
{ {
/* time passed in number of connects give average */ /* time passed in number of connects give average */
int times = benchmark; int times = benchmark;
@ -171,6 +171,7 @@ static int ClientBenchmarkConnections(WOLFSSL_CTX* ctx, char* host, word16 port,
#endif #endif
(void)resumeSession; (void)resumeSession;
(void)useX25519;
while (loops--) { while (loops--) {
#ifndef NO_SESSION_CACHE #ifndef NO_SESSION_CACHE
@ -190,6 +191,16 @@ static int ClientBenchmarkConnections(WOLFSSL_CTX* ctx, char* host, word16 port,
#ifndef NO_SESSION_CACHE #ifndef NO_SESSION_CACHE
if (benchResume) if (benchResume)
wolfSSL_set_session(ssl, benchSession); wolfSSL_set_session(ssl, benchSession);
#endif
#ifdef WOLFSSL_TLS13
#ifdef HAVE_CURVE25519
else if (useX25519) {
if (wolfSSL_UseKeyShare(ssl, WOLFSSL_ECC_X25519)
!= SSL_SUCCESS) {
err_sys("unable to use curve secp256r1");
}
}
#endif
#endif #endif
if (wolfSSL_set_fd(ssl, sockfd) != SSL_SUCCESS) { if (wolfSSL_set_fd(ssl, sockfd) != SSL_SUCCESS) {
err_sys("error in setting fd"); err_sys("error in setting fd");
@ -247,7 +258,7 @@ static int ClientBenchmarkConnections(WOLFSSL_CTX* ctx, char* host, word16 port,
/* Measures throughput in kbps. Throughput = number of bytes */ /* Measures throughput in kbps. Throughput = number of bytes */
static int ClientBenchmarkThroughput(WOLFSSL_CTX* ctx, char* host, word16 port, static int ClientBenchmarkThroughput(WOLFSSL_CTX* ctx, char* host, word16 port,
int dtlsUDP, int dtlsSCTP, int throughput) int dtlsUDP, int dtlsSCTP, int throughput, int useX25519)
{ {
double start, conn_time = 0, tx_time = 0, rx_time = 0; double start, conn_time = 0, tx_time = 0, rx_time = 0;
SOCKET_T sockfd; SOCKET_T sockfd;
@ -264,6 +275,18 @@ static int ClientBenchmarkThroughput(WOLFSSL_CTX* ctx, char* host, word16 port,
err_sys("error in setting fd"); err_sys("error in setting fd");
} }
(void)useX25519;
#ifdef WOLFSSL_TLS13
#ifdef HAVE_CURVE25519
if (useX25519) {
if (wolfSSL_UseKeyShare(ssl, WOLFSSL_ECC_X25519)
!= SSL_SUCCESS) {
err_sys("unable to use curve secp256r1");
}
}
#endif
#endif
do { do {
err = 0; /* reset error */ err = 0; /* reset error */
ret = wolfSSL_connect(ssl); ret = wolfSSL_connect(ssl);
@ -735,9 +758,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
int useOcsp = 0; int useOcsp = 0;
char* ocspUrl = NULL; char* ocspUrl = NULL;
#endif #endif
#ifdef HAVE_CURVE25519
int useX25519 = 0; int useX25519 = 0;
#endif
#ifdef HAVE_WNR #ifdef HAVE_WNR
const char* wnrConfigFile = wnrConfig; const char* wnrConfigFile = wnrConfig;
@ -771,6 +792,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
(void)alpnList; (void)alpnList;
(void)alpn_opt; (void)alpn_opt;
(void)updateKeysIVs; (void)updateKeysIVs;
(void)useX25519;
StackTrap(); StackTrap();
@ -1479,7 +1501,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
if (benchmark) { if (benchmark) {
((func_args*)args)->return_code = ((func_args*)args)->return_code =
ClientBenchmarkConnections(ctx, host, port, dtlsUDP, dtlsSCTP, ClientBenchmarkConnections(ctx, host, port, dtlsUDP, dtlsSCTP,
benchmark, resumeSession); benchmark, resumeSession, useX25519);
wolfSSL_CTX_free(ctx); wolfSSL_CTX_free(ctx);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
@ -1487,7 +1509,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
if(throughput) { if(throughput) {
((func_args*)args)->return_code = ((func_args*)args)->return_code =
ClientBenchmarkThroughput(ctx, host, port, dtlsUDP, dtlsSCTP, ClientBenchmarkThroughput(ctx, host, port, dtlsUDP, dtlsSCTP,
throughput); throughput, useX25519);
wolfSSL_CTX_free(ctx); wolfSSL_CTX_free(ctx);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }