This commit is contained in:
toddouska 2012-09-20 15:39:15 -07:00
parent bd0f508a0f
commit 7716da0881
12 changed files with 81 additions and 59 deletions

View File

@ -421,12 +421,12 @@ void bench_rsa(void)
word32 idx = 0; word32 idx = 0;
byte message[] = "Everyone gets Friday off."; byte message[] = "Everyone gets Friday off.";
byte cipher[512]; /* for up to 4096 bit */ byte enc[512]; /* for up to 4096 bit */
byte* output; byte* output;
const int len = (int)strlen((char*)message); const int len = (int)strlen((char*)message);
double start, total, each, milliEach; double start, total, each, milliEach;
RsaKey key; RsaKey rsaKey;
FILE* file = fopen("./certs/rsa2048.der", "rb"); FILE* file = fopen("./certs/rsa2048.der", "rb");
if (!file) { if (!file) {
@ -437,13 +437,13 @@ void bench_rsa(void)
InitRng(&rng); InitRng(&rng);
bytes = fread(tmp, 1, sizeof(tmp), file); bytes = fread(tmp, 1, sizeof(tmp), file);
InitRsaKey(&key, 0); InitRsaKey(&rsaKey, 0);
bytes = RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes); bytes = RsaPrivateKeyDecode(tmp, &idx, &rsaKey, (word32)bytes);
start = current_time(); start = current_time();
for (i = 0; i < times; i++) for (i = 0; i < times; i++)
bytes = RsaPublicEncrypt(message,len,cipher,sizeof(cipher), &key, &rng); bytes = RsaPublicEncrypt(message,len,enc,sizeof(enc), &rsaKey, &rng);
total = current_time() - start; total = current_time() - start;
each = total / times; /* per second */ each = total / times; /* per second */
@ -455,7 +455,7 @@ void bench_rsa(void)
start = current_time(); start = current_time();
for (i = 0; i < times; i++) for (i = 0; i < times; i++)
RsaPrivateDecryptInline(cipher, (word32)bytes, &output, &key); RsaPrivateDecryptInline(enc, (word32)bytes, &output, &rsaKey);
total = current_time() - start; total = current_time() - start;
each = total / times; /* per second */ each = total / times; /* per second */
@ -465,7 +465,7 @@ void bench_rsa(void)
" iterations\n", milliEach, times); " iterations\n", milliEach, times);
fclose(file); fclose(file);
FreeRsaKey(&key); FreeRsaKey(&rsaKey);
} }
@ -484,7 +484,7 @@ void bench_dh(void)
byte agree[256]; /* for 2048 bit */ byte agree[256]; /* for 2048 bit */
double start, total, each, milliEach; double start, total, each, milliEach;
DhKey key; DhKey dhKey;
FILE* file = fopen("./certs/dh2048.der", "rb"); FILE* file = fopen("./certs/dh2048.der", "rb");
if (!file) { if (!file) {
@ -494,13 +494,13 @@ void bench_dh(void)
} }
bytes = fread(tmp, 1, sizeof(tmp), file); bytes = fread(tmp, 1, sizeof(tmp), file);
InitDhKey(&key); InitDhKey(&dhKey);
bytes = DhKeyDecode(tmp, &idx, &key, (word32)bytes); bytes = DhKeyDecode(tmp, &idx, &dhKey, (word32)bytes);
start = current_time(); start = current_time();
for (i = 0; i < times; i++) for (i = 0; i < times; i++)
DhGenerateKeyPair(&key, &rng, priv, &privSz, pub, &pubSz); DhGenerateKeyPair(&dhKey, &rng, priv, &privSz, pub, &pubSz);
total = current_time() - start; total = current_time() - start;
each = total / times; /* per second */ each = total / times; /* per second */
@ -509,11 +509,11 @@ void bench_dh(void)
printf("DH 2048 key generation %6.2f milliseconds, avg over %d" printf("DH 2048 key generation %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times); " iterations\n", milliEach, times);
DhGenerateKeyPair(&key, &rng, priv2, &privSz2, pub2, &pubSz2); DhGenerateKeyPair(&dhKey, &rng, priv2, &privSz2, pub2, &pubSz2);
start = current_time(); start = current_time();
for (i = 0; i < times; i++) for (i = 0; i < times; i++)
DhAgree(&key, agree, &agreeSz, priv, privSz, pub2, pubSz2); DhAgree(&dhKey, agree, &agreeSz, priv, privSz, pub2, pubSz2);
total = current_time() - start; total = current_time() - start;
each = total / times; /* per second */ each = total / times; /* per second */
@ -523,7 +523,7 @@ void bench_dh(void)
" iterations\n", milliEach, times); " iterations\n", milliEach, times);
fclose(file); fclose(file);
FreeDhKey(&key); FreeDhKey(&dhKey);
} }
#endif #endif

View File

@ -83,8 +83,8 @@
typedef struct testVector { typedef struct testVector {
char* input; const char* input;
char* output; const char* output;
size_t inLen; size_t inLen;
size_t outLen; size_t outLen;
} testVector; } testVector;

View File

@ -160,7 +160,7 @@ static INLINE void err_sys(const char* msg)
extern int myoptind; extern int myoptind;
extern char* myoptarg; extern char* myoptarg;
static INLINE int mygetopt(int argc, char** argv, char* optstring) static INLINE int mygetopt(int argc, char** argv, const char* optstring)
{ {
static char* next = NULL; static char* next = NULL;
@ -238,7 +238,6 @@ static INLINE int PasswordCallBack(char* passwd, int sz, int rw, void* userdata)
static INLINE void showPeer(CYASSL* ssl) static INLINE void showPeer(CYASSL* ssl)
{ {
(void)ssl;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
CYASSL_CIPHER* cipher; CYASSL_CIPHER* cipher;
@ -300,7 +299,7 @@ static INLINE void showPeer(CYASSL* ssl)
} }
} }
#endif #endif
(void)ssl;
} }
@ -432,9 +431,9 @@ static INLINE int udp_read_connect(SOCKET_T sockfd)
static INLINE void udp_accept(SOCKET_T* sockfd, int* clientfd, func_args* args) static INLINE void udp_accept(SOCKET_T* sockfd, int* clientfd, func_args* args)
{ {
(void)args;
SOCKADDR_IN_T addr; SOCKADDR_IN_T addr;
(void)args;
tcp_socket(sockfd, &addr, yasslIP, yasslPort, 1); tcp_socket(sockfd, &addr, yasslIP, yasslPort, 1);

View File

@ -116,7 +116,7 @@ void client_test(void* args)
int port = yasslPort; int port = yasslPort;
char* host = (char*)yasslIP; char* host = (char*)yasslIP;
char* domain = "www.yassl.com"; char* domain = (char*)"www.yassl.com";
int ch; int ch;
int version = CLIENT_DEFAULT_VERSION; int version = CLIENT_DEFAULT_VERSION;

View File

@ -38,7 +38,7 @@ void echoclient_test(void* args)
int inCreated = 0; int inCreated = 0;
int outCreated = 0; int outCreated = 0;
char send[1024]; char msg[1024];
char reply[1024]; char reply[1024];
SSL_METHOD* method = 0; SSL_METHOD* method = 0;
@ -109,19 +109,19 @@ void echoclient_test(void* args)
#endif #endif
if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed"); if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");
while (fgets(send, sizeof(send), fin)) { while (fgets(msg, sizeof(msg), fin)) {
sendSz = (int)strlen(send); sendSz = (int)strlen(msg);
if (SSL_write(ssl, send, sendSz) != sendSz) if (SSL_write(ssl, msg, sendSz) != sendSz)
err_sys("SSL_write failed"); err_sys("SSL_write failed");
if (strncmp(send, "quit", 4) == 0) { if (strncmp(msg, "quit", 4) == 0) {
fputs("sending server shutdown command: quit!\n", fout); fputs("sending server shutdown command: quit!\n", fout);
break; break;
} }
if (strncmp(send, "break", 5) == 0) { if (strncmp(msg, "break", 5) == 0) {
fputs("sending server session close: break!\n", fout); fputs("sending server session close: break!\n", fout);
break; break;
} }
@ -139,10 +139,10 @@ void echoclient_test(void* args)
} }
#ifdef CYASSL_DTLS #ifdef CYASSL_DTLS
strncpy(send, "break", 6); strncpy(msg, "break", 6);
sendSz = (int)strlen(send); sendSz = (int)strlen(msg);
/* try to tell server done */ /* try to tell server done */
SSL_write(ssl, send, sendSz); SSL_write(ssl, msg, sendSz);
#else #else
SSL_shutdown(ssl); SSL_shutdown(ssl);
#endif #endif

View File

@ -40,7 +40,6 @@
static void SignalReady(void* args) static void SignalReady(void* args)
{ {
(void)args;
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) #if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER)
/* signal ready to tcp_accept */ /* signal ready to tcp_accept */
func_args* server_args = (func_args*)args; func_args* server_args = (func_args*)args;
@ -50,6 +49,7 @@ static void SignalReady(void* args)
pthread_cond_signal(&ready->cond); pthread_cond_signal(&ready->cond);
pthread_mutex_unlock(&ready->mutex); pthread_mutex_unlock(&ready->mutex);
#endif #endif
(void)args;
} }
@ -61,13 +61,10 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
int doDTLS = 0; int doDTLS = 0;
int outCreated = 0; int outCreated = 0;
(void)outCreated; int shutDown = 0;
int shutdown = 0;
int useAnyAddr = 0; int useAnyAddr = 0;
int argc = ((func_args*)args)->argc; int argc = ((func_args*)args)->argc;
(void)argc;
char** argv = ((func_args*)args)->argv; char** argv = ((func_args*)args)->argv;
(void)argv;
#ifdef ECHO_OUT #ifdef ECHO_OUT
FILE* fout = stdout; FILE* fout = stdout;
@ -77,6 +74,9 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
} }
if (!fout) err_sys("can't open output file"); if (!fout) err_sys("can't open output file");
#endif #endif
(void)outCreated;
(void)argc;
(void)argv;
((func_args*)args)->return_code = -1; /* error state */ ((func_args*)args)->return_code = -1; /* error state */
@ -112,7 +112,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
!= SSL_SUCCESS) != SSL_SUCCESS)
err_sys("can't load ntru key file, " err_sys("can't load ntru key file, "
"Please run from CyaSSL home dir"); "Please run from CyaSSL home dir");
#elif HAVE_ECC #elif defined(HAVE_ECC)
/* ecc */ /* ecc */
if (CyaSSL_CTX_use_certificate_file(ctx, eccCert, SSL_FILETYPE_PEM) if (CyaSSL_CTX_use_certificate_file(ctx, eccCert, SSL_FILETYPE_PEM)
!= SSL_SUCCESS) != SSL_SUCCESS)
@ -147,7 +147,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
SignalReady(args); SignalReady(args);
while (!shutdown) { while (!shutDown) {
CYASSL* ssl = 0; CYASSL* ssl = 0;
char command[1024]; char command[1024];
int echoSz = 0; int echoSz = 0;
@ -199,7 +199,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
if ( strncmp(command, "quit", 4) == 0) { if ( strncmp(command, "quit", 4) == 0) {
printf("client sent quit command: shutting down!\n"); printf("client sent quit command: shutting down!\n");
shutdown = 1; shutDown = 1;
break; break;
} }
if ( strncmp(command, "break", 5) == 0) { if ( strncmp(command, "break", 5) == 0) {

View File

@ -52,6 +52,7 @@
# AX_APPEND_COMPILE_FLAGS([-Wstack-protector]) -- Issues on 32bit compile # AX_APPEND_COMPILE_FLAGS([-Wstack-protector]) -- Issues on 32bit compile
# AX_APPEND_COMPILE_FLAGS([-fstack-protector-all]) -- Issues on 32bit compile # AX_APPEND_COMPILE_FLAGS([-fstack-protector-all]) -- Issues on 32bit compile
# AX_APPEND_COMPILE_FLAGS([-Wlong-long]) -- Don't turn on for compatibility issues memcached_stat_st # AX_APPEND_COMPILE_FLAGS([-Wlong-long]) -- Don't turn on for compatibility issues memcached_stat_st
# AX_APPEND_COMPILE_FLAGS([-Wold-style-definition]) -- Mixed with -Werror either before or after is a problem because tests use main() instead of main(void)
#serial 2 #serial 2
AC_DEFUN([AX_HARDEN_LINKER_FLAGS], [ AC_DEFUN([AX_HARDEN_LINKER_FLAGS], [
@ -75,23 +76,45 @@
AX_APPEND_COMPILE_FLAGS([-O2]) AX_APPEND_COMPILE_FLAGS([-O2])
]) ])
AX_APPEND_COMPILE_FLAGS([-Wall])
AX_APPEND_COMPILE_FLAGS([-Wextra])
AX_APPEND_COMPILE_FLAGS([-std=c99])
AX_APPEND_COMPILE_FLAGS([-Wbad-function-cast])
AX_APPEND_COMPILE_FLAGS([-Wmissing-prototypes])
AX_APPEND_COMPILE_FLAGS([-Wnested-externs])
AX_APPEND_COMPILE_FLAGS([-Wold-style-definition])
AX_APPEND_COMPILE_FLAGS([-Woverride-init])
AX_APPEND_COMPILE_FLAGS([-Wstrict-prototypes])
AX_APPEND_COMPILE_FLAGS([-Wlogical-op])
ac_cv_warnings_as_errors=no ac_cv_warnings_as_errors=no
AS_IF([test "$ac_cv_vcs_checkout" = yes], [ AS_IF([test "$ac_cv_vcs_checkout" = yes], [
AX_APPEND_COMPILE_FLAGS([-Werror]) AX_APPEND_COMPILE_FLAGS([-Werror])
ac_cv_warnings_as_errors=yes ac_cv_warnings_as_errors=yes
]) ])
AX_APPEND_COMPILE_FLAGS([-Wall])
AX_APPEND_COMPILE_FLAGS([-Wextra])
AX_APPEND_COMPILE_FLAGS([-std=c99])
AX_APPEND_COMPILE_FLAGS([-Wbad-function-cast])
AX_APPEND_COMPILE_FLAGS([-Wmissing-prototypes])
AX_APPEND_COMPILE_FLAGS([-Wnested-externs])
AX_APPEND_COMPILE_FLAGS([-Woverride-init])
AX_APPEND_COMPILE_FLAGS([-Wstrict-prototypes])
AX_APPEND_COMPILE_FLAGS([-Wlogical-op])
AX_APPEND_COMPILE_FLAGS([-Wno-strict-aliasing])
AX_APPEND_COMPILE_FLAGS([-Wfloat-equal])
AX_APPEND_COMPILE_FLAGS([-Wundef])
AX_APPEND_COMPILE_FLAGS([-Wpointer-arith])
AX_APPEND_COMPILE_FLAGS([-Wwrite-strings])
AX_APPEND_COMPILE_FLAGS([-Wredundant-decls])
AX_APPEND_COMPILE_FLAGS([-Wchar-subscripts])
AX_APPEND_COMPILE_FLAGS([-Wcomment])
AX_APPEND_COMPILE_FLAGS([-Wformat=2])
AX_APPEND_COMPILE_FLAGS([-Wmissing-declarations])
AX_APPEND_COMPILE_FLAGS([-Wswitch-enum])
AX_APPEND_COMPILE_FLAGS([-Winit-self])
AX_APPEND_COMPILE_FLAGS([-Wmissing-field-initializers])
AX_APPEND_COMPILE_FLAGS([-Wdeclaration-after-statement])
AX_APPEND_COMPILE_FLAGS([-Waddress])
AX_APPEND_COMPILE_FLAGS([-Wmissing-noreturn])
AX_APPEND_COMPILE_FLAGS([-Wnormalized=id])
AX_APPEND_COMPILE_FLAGS([-Wstrict-overflow=1])
AX_APPEND_COMPILE_FLAGS([-Wformat])
AX_APPEND_COMPILE_FLAGS([-Wformat-security])
AX_APPEND_COMPILE_FLAGS([-Wpointer-sign])
AX_APPEND_COMPILE_FLAGS([-Wshadow])
AX_APPEND_COMPILE_FLAGS([-Wswitch-default])
AX_APPEND_COMPILE_FLAGS([-Warray-bounds])
AC_LANG_POP AC_LANG_POP
]) ])

View File

@ -58,8 +58,8 @@ void test_client_nofail(void*);
#endif #endif
static const char* bogusFile = "/dev/null"; static const char* bogusFile = "/dev/null";
static const char* testingFmt = " %s:"; #define testingFmt " %s:"
static const char* resultFmt = " %s\n"; #define resultFmt " %s\n"
static const char* passed = "passed"; static const char* passed = "passed";
static const char* failed = "failed"; static const char* failed = "failed";
@ -661,8 +661,8 @@ void test_client_nofail(void* args)
int msgSz = strlen(msg); int msgSz = strlen(msg);
int argc = ((func_args*)args)->argc; int argc = ((func_args*)args)->argc;
(void)argc;
char** argv = ((func_args*)args)->argv; char** argv = ((func_args*)args)->argv;
(void)argc;
(void)argv; (void)argv;
((func_args*)args)->return_code = TEST_FAIL; ((func_args*)args)->return_code = TEST_FAIL;

View File

@ -36,8 +36,8 @@
#include <tests/unit.h> #include <tests/unit.h>
typedef struct testVector { typedef struct testVector {
char* input; const char* input;
char* output; const char* output;
size_t inLen; size_t inLen;
size_t outLen; size_t outLen;
} testVector; } testVector;

View File

@ -96,7 +96,7 @@ static void test_harness(void* vargs)
int cliArgsSz; int cliArgsSz;
char* cursor; char* cursor;
char* comment; char* comment;
char* fname = "tests/test.conf"; const char* fname = "tests/test.conf";
if (args->argc == 1) { if (args->argc == 1) {

View File

@ -9,10 +9,10 @@ char* myoptarg = NULL;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
(void)argc;
(void)argv;
int ret; int ret;
(void)argc;
(void)argv;
printf("staring unit tests...\n"); printf("staring unit tests...\n");
if ( (ret = ApiTest()) != 0) { if ( (ret = ApiTest()) != 0) {

View File

@ -41,7 +41,7 @@
void client_test(void*); void client_test(void*);
void file_test(char* file, byte* hash); void file_test(const char* file, byte* hash);
enum { enum {
NUMARGS = 3 NUMARGS = 3
@ -207,7 +207,7 @@ void FreeTcpReady(tcp_ready* ready)
} }
void file_test(char* file, byte* check) void file_test(const char* file, byte* check)
{ {
FILE* f; FILE* f;
int i = 0, j; int i = 0, j;