25 typedef unsigned char byte;
27 void taocrypt_test(
void*);
28 void file_test(
const char*, byte*);
30 void client_test(
void*);
31 void echoclient_test(
void*);
33 THREAD_RETURN YASSL_API server_test(
void*);
34 THREAD_RETURN YASSL_API echoserver_test(
void*);
40 int main(
int argc,
char** argv)
47 assert(args.return_code == 0);
52 server_args.SetSignal(&ready);
54 THREAD_TYPE serverThread;
55 start_thread(server_test, &server_args, &serverThread);
56 wait_tcp_ready(server_args);
59 assert(args.return_code == 0);
60 join_thread(serverThread);
61 assert(server_args.return_code == 0);
65 start_thread(echoserver_test, &server_args, &serverThread);
66 wait_tcp_ready(server_args);
70 const int numArgs = 3;
71 echo_args.argc = numArgs;
72 char* myArgv[numArgs];
82 echo_args.argv = myArgv;
84 strcpy(echo_args.argv[0],
"echoclient");
85 strcpy(echo_args.argv[1],
"input");
86 strcpy(echo_args.argv[2],
"output");
90 echoclient_test(&echo_args);
91 assert(echo_args.return_code == 0);
96 strcpy(echo_args.argv[1],
"quit");
98 echoclient_test(&echo_args);
99 assert(echo_args.return_code == 0);
100 join_thread(serverThread);
101 assert(server_args.return_code == 0);
105 byte input[TaoCrypt::MD5::DIGEST_SIZE];
106 byte output[TaoCrypt::MD5::DIGEST_SIZE];
107 file_test(
"input", input);
108 file_test(
"output", output);
109 assert(memcmp(input, output,
sizeof(input)) == 0);
111 printf(
"\nAll tests passed!\n");
119 void start_thread(THREAD_FUNC fun,
func_args* args, THREAD_TYPE* thread)
121 #ifndef _POSIX_THREADS
122 *thread = (HANDLE)_beginthreadex(0, 0, fun, args, 0, 0);
124 pthread_create(thread, 0, fun, args);
129 void join_thread(THREAD_TYPE thread)
131 #ifndef _POSIX_THREADS
132 int res = WaitForSingleObject(thread, INFINITE);
133 assert(res == WAIT_OBJECT_0);
134 res = CloseHandle(thread);
137 pthread_join(thread, 0);
145 #ifdef _POSIX_THREADS
146 pthread_mutex_lock(&args.signal_->mutex_);
148 if (!args.signal_->ready_)
149 pthread_cond_wait(&args.signal_->cond_, &args.signal_->mutex_);
150 args.signal_->ready_ =
false;
152 pthread_mutex_unlock(&args.signal_->mutex_);
157 int test_openSSL_des()
160 char data[] =
"this is my data ";
161 int dataSz = (int)strlen(data);
162 DES_key_schedule key[3];
164 EVP_BytesToKey(EVP_des_ede3_cbc(), EVP_md5(), NULL, (byte*)data, dataSz, 1,
168 DES_ede3_cbc_encrypt((byte*)data, cipher, dataSz, &key[0], &key[1],
171 DES_ede3_cbc_encrypt(cipher, plain, 16, &key[0], &key[1], &key[2],