]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/CyaSSL/cyassl/test.h
82cee429e80620cccfe314da989eb91f519a3b39
[freertos] / FreeRTOS-Plus / CyaSSL / cyassl / test.h
1 /* test.h */
2
3 #ifndef CyaSSL_TEST_H
4 #define CyaSSL_TEST_H
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <assert.h>
9 #include <ctype.h>
10 #include <cyassl/ssl.h>
11 #include <cyassl/ctaocrypt/types.h>
12
13 #ifdef USE_WINDOWS_API 
14     #include <winsock2.h>
15     #include <process.h>
16     #ifdef TEST_IPV6            /* don't require newer SDK for IPV4 */
17             #include <ws2tcpip.h>
18         #include <wspiapi.h>
19     #endif
20     #define SOCKET_T int
21 #else
22     #include <string.h>
23     #include <unistd.h>
24     #include <netdb.h>
25     #include <netinet/in.h>
26     #include <netinet/tcp.h>
27     #include <arpa/inet.h>
28     #include <sys/ioctl.h>
29     #include <sys/time.h>
30     #include <sys/types.h>
31     #include <sys/socket.h>
32     #include <pthread.h>
33     #ifdef NON_BLOCKING
34         #include <fcntl.h>
35     #endif
36     #ifdef TEST_IPV6
37         #include <netdb.h>
38     #endif
39     #define SOCKET_T unsigned int
40 #endif /* USE_WINDOWS_API */
41
42 #ifdef _MSC_VER
43     /* disable conversion warning */
44     /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
45     #pragma warning(disable:4244 4996)
46 #endif
47
48
49 #if defined(__MACH__) || defined(USE_WINDOWS_API)
50     #ifndef _SOCKLEN_T
51         typedef int socklen_t;
52     #endif
53 #endif
54
55
56 /* HPUX doesn't use socklent_t for third parameter to accept */
57 #if !defined(__hpux__)
58     typedef socklen_t* ACCEPT_THIRD_T;
59 #else
60     typedef int*       ACCEPT_THIRD_T;
61 #endif
62
63
64 #ifdef USE_WINDOWS_API 
65     #define CloseSocket(s) closesocket(s)
66     #define StartTCP() { WSADATA wsd; WSAStartup(0x0002, &wsd); }
67 #else
68     #define CloseSocket(s) close(s)
69     #define StartTCP() 
70 #endif
71
72
73 #ifdef SINGLE_THREADED
74     typedef unsigned int  THREAD_RETURN;
75     typedef void*         THREAD_TYPE;
76     #define CYASSL_THREAD
77 #else
78     #ifdef _POSIX_THREADS
79         typedef void*         THREAD_RETURN;
80         typedef pthread_t     THREAD_TYPE;
81         #define CYASSL_THREAD
82         #define INFINITE -1
83         #define WAIT_OBJECT_0 0L
84     #else
85         typedef unsigned int  THREAD_RETURN;
86         typedef HANDLE        THREAD_TYPE;
87         #define CYASSL_THREAD __stdcall
88     #endif
89 #endif
90
91
92 #ifdef TEST_IPV6
93     typedef struct sockaddr_in6 SOCKADDR_IN_T;
94     #define AF_INET_V    AF_INET6
95 #else
96     typedef struct sockaddr_in  SOCKADDR_IN_T;
97     #define AF_INET_V    AF_INET
98 #endif
99    
100
101 #define SERVER_DEFAULT_VERSION 3
102 #define CLIENT_DEFAULT_VERSION 3
103
104 /* all certs relative to CyaSSL home directory now */
105 #define caCert     "./certs/ca-cert.pem"
106 #define eccCert    "./certs/server-ecc.pem"
107 #define eccKey     "./certs/ecc-key.pem"
108 #define svrCert    "./certs/server-cert.pem"
109 #define svrKey     "./certs/server-key.pem"
110 #define cliCert    "./certs/client-cert.pem"
111 #define cliKey     "./certs/client-key.pem"
112 #define ntruCert   "./certs/ntru-cert.pem"
113 #define ntruKey    "./certs/ntru-key.raw"
114 #define dhParam    "./certs/dh2048.pem"
115 #define cliEccKey  "./certs/ecc-client-key.pem"
116 #define cliEccCert "./certs/client-ecc-cert.pem"
117 #define crlPemDir  "./certs/crl"
118
119 typedef struct tcp_ready {
120     int ready;              /* predicate */
121 #ifdef _POSIX_THREADS
122     pthread_mutex_t mutex;
123     pthread_cond_t  cond;
124 #endif
125 } tcp_ready;    
126
127
128 void InitTcpReady(tcp_ready*);
129 void FreeTcpReady(tcp_ready*);
130
131
132 typedef struct func_args {
133     int    argc;
134     char** argv;
135     int    return_code;
136     tcp_ready* signal;
137 } func_args;
138
139 void wait_tcp_ready(func_args*);
140
141 typedef THREAD_RETURN CYASSL_THREAD THREAD_FUNC(void*);
142
143 void start_thread(THREAD_FUNC, func_args*, THREAD_TYPE*);
144 void join_thread(THREAD_TYPE);
145
146 /* yaSSL */
147 static const char* const yasslIP   = "127.0.0.1";
148 static const word16      yasslPort = 11111;
149
150
151 static INLINE void err_sys(const char* msg)
152 {
153     printf("yassl error: %s\n", msg);
154     exit(EXIT_FAILURE);
155 }
156
157
158 #define MY_EX_USAGE 2
159
160 extern int   myoptind;
161 extern char* myoptarg;
162
163 static INLINE int mygetopt(int argc, char** argv, char* optstring)
164 {
165     static char* next = NULL;
166
167     char  c;
168     char* cp;
169
170     if (myoptind == 0)
171         next = NULL;   /* we're starting new/over */
172
173     if (next == NULL || *next == '\0') {
174         if (myoptind == 0)
175             myoptind++;
176
177         if (myoptind >= argc || argv[myoptind][0] != '-' ||
178                                 argv[myoptind][1] == '\0') {
179             myoptarg = NULL;
180             if (myoptind < argc)
181                 myoptarg = argv[myoptind];
182
183             return -1;
184         }
185
186         if (strcmp(argv[myoptind], "--") == 0) {
187             myoptind++;
188             myoptarg = NULL;
189
190             if (myoptind < argc)
191                 myoptarg = argv[myoptind];
192
193             return -1;
194         }
195
196         next = argv[myoptind];
197         next++;                  /* skip - */
198         myoptind++;
199     }
200
201     c  = *next++;
202     cp = strchr(optstring, c);
203
204     if (cp == NULL || c == ':') 
205         return '?';
206
207     cp++;
208
209     if (*cp == ':') {
210         if (*next != '\0') {
211             myoptarg = next;
212             next     = NULL;
213         }
214         else if (myoptind < argc) {
215             myoptarg = argv[myoptind];
216             myoptind++;
217         }
218         else 
219             return '?';
220     }
221
222     return c;
223 }
224
225
226 #ifdef OPENSSL_EXTRA
227
228 static INLINE int PasswordCallBack(char* passwd, int sz, int rw, void* userdata)
229 {
230     strncpy(passwd, "yassl123", sz);
231     return 8;
232 }
233
234 #endif
235
236
237 static INLINE void showPeer(CYASSL* ssl)
238 {
239 #ifdef OPENSSL_EXTRA
240
241     CYASSL_CIPHER* cipher;
242     CYASSL_X509*   peer = CyaSSL_get_peer_certificate(ssl);
243     if (peer) {
244         char* altName;
245         char* issuer  = CyaSSL_X509_NAME_oneline(
246                                        CyaSSL_X509_get_issuer_name(peer), 0, 0);
247         char* subject = CyaSSL_X509_NAME_oneline(
248                                       CyaSSL_X509_get_subject_name(peer), 0, 0);
249         byte  serial[32];
250         int   ret;
251         int   sz = sizeof(serial);
252         
253         printf("peer's cert info:\n issuer : %s\n subject: %s\n", issuer,
254                                                                   subject);
255
256         while ( (altName = CyaSSL_X509_get_next_altname(peer)) )
257             printf(" altname = %s\n", altName);
258
259         ret = CyaSSL_X509_get_serial_number(peer, serial, &sz);
260         if (ret == 0) {
261             int  i;
262             int  strLen;
263             char serialMsg[80];
264
265             /* testsuite has multiple threads writing to stdout, get output
266                message ready to write once */
267             strLen = sprintf(serialMsg, " serial number");
268             for (i = 0; i < sz; i++)
269                 sprintf(serialMsg + strLen + (i*3), ":%02x ", serial[i]);
270             printf("%s\n", serialMsg);
271         }
272
273         XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
274         XFREE(issuer,  0, DYNAMIC_TYPE_OPENSSL);
275     }
276     else
277         printf("peer has no cert!\n");
278     printf("SSL version is %s\n", CyaSSL_get_version(ssl));
279
280     cipher = CyaSSL_get_current_cipher(ssl);
281     printf("SSL cipher suite is %s\n", CyaSSL_CIPHER_get_name(cipher));
282 #endif
283
284 #if defined(SESSION_CERTS) && defined(SHOW_CERTS)
285     {
286         CYASSL_X509_CHAIN* chain = CyaSSL_get_peer_chain(ssl);
287         int                count = CyaSSL_get_chain_count(chain);
288         int i;
289
290         for (i = 0; i < count; i++) {
291             int length;
292             unsigned char buffer[3072];
293
294             CyaSSL_get_chain_cert_pem(chain,i,buffer, sizeof(buffer), &length);
295             buffer[length] = 0;
296             printf("cert %d has length %d data = \n%s\n", i, length, buffer);
297         }
298     }
299 #endif
300
301 }
302
303
304 static INLINE void tcp_socket(SOCKET_T* sockfd, SOCKADDR_IN_T* addr,
305                               const char* peer, word16 port, int udp)
306 {
307 #ifndef TEST_IPV6
308     const char* host = peer;
309
310     /* peer could be in human readable form */
311     if (peer != INADDR_ANY && isalpha(peer[0])) {
312         struct hostent* entry = gethostbyname(peer);
313
314         if (entry) {
315             struct sockaddr_in tmp;
316             memset(&tmp, 0, sizeof(struct sockaddr_in));
317             memcpy(&tmp.sin_addr.s_addr, entry->h_addr_list[0],
318                    entry->h_length);
319             host = inet_ntoa(tmp.sin_addr);
320         }
321         else
322             err_sys("no entry for host");
323     }
324 #endif
325
326     if (udp)
327         *sockfd = socket(AF_INET_V, SOCK_DGRAM, 0);
328     else
329         *sockfd = socket(AF_INET_V, SOCK_STREAM, 0);
330     memset(addr, 0, sizeof(SOCKADDR_IN_T));
331
332 #ifndef TEST_IPV6
333     addr->sin_family = AF_INET_V;
334     addr->sin_port = htons(port);
335     if (host == INADDR_ANY)
336         addr->sin_addr.s_addr = INADDR_ANY;
337     else
338         addr->sin_addr.s_addr = inet_addr(host);
339 #else
340     addr->sin6_family = AF_INET_V;
341     addr->sin6_port = htons(port);
342     addr->sin6_addr = in6addr_loopback;
343 #endif
344
345 #ifndef USE_WINDOWS_API 
346 #ifdef SO_NOSIGPIPE
347     {
348         int       on = 1;
349         socklen_t len = sizeof(on);
350         int       res = setsockopt(*sockfd, SOL_SOCKET, SO_NOSIGPIPE, &on, len);
351         if (res < 0)
352             err_sys("setsockopt SO_NOSIGPIPE failed\n");
353     }
354 #endif
355
356 #if defined(TCP_NODELAY)
357     if (!udp)
358     {
359         int       on = 1;
360         socklen_t len = sizeof(on);
361         int       res = setsockopt(*sockfd, IPPROTO_TCP, TCP_NODELAY, &on, len);
362         if (res < 0)
363             err_sys("setsockopt TCP_NODELAY failed\n");
364     }
365 #endif
366 #endif  /* USE_WINDOWS_API */
367 }
368
369
370 static INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port,
371                                int udp)
372 {
373     SOCKADDR_IN_T addr;
374     tcp_socket(sockfd, &addr, ip, port, udp);
375
376     if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0)
377         err_sys("tcp connect failed");
378 }
379
380
381 static INLINE void tcp_listen(SOCKET_T* sockfd, int port, int useAnyAddr,
382                               int udp)
383 {
384     SOCKADDR_IN_T addr;
385
386     /* don't use INADDR_ANY by default, firewall may block, make user switch
387        on */
388     if (useAnyAddr)
389         tcp_socket(sockfd, &addr, INADDR_ANY, port, udp);
390     else
391         tcp_socket(sockfd, &addr, yasslIP, port, udp);
392
393 #ifndef USE_WINDOWS_API 
394     {
395         int       on  = 1;
396         socklen_t len = sizeof(on);
397         setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR, &on, len);
398     }
399 #endif
400
401     if (bind(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0)
402         err_sys("tcp bind failed");
403     if (!udp) {
404         if (listen(*sockfd, 5) != 0)
405             err_sys("tcp listen failed");
406     }
407 }
408
409
410 static INLINE int udp_read_connect(SOCKET_T sockfd)
411 {
412     SOCKADDR_IN_T cliaddr;
413     byte          b[1500];
414     int           n;
415     socklen_t     len = sizeof(cliaddr);
416
417     n = recvfrom(sockfd, (char*)b, sizeof(b), MSG_PEEK,
418                 (struct sockaddr*)&cliaddr, &len);
419     if (n > 0) {
420         if (connect(sockfd, (const struct sockaddr*)&cliaddr,
421                     sizeof(cliaddr)) != 0)
422             err_sys("udp connect failed");
423     }
424     else
425         err_sys("recvfrom failed");
426
427     return sockfd;
428 }
429
430 static INLINE void udp_accept(SOCKET_T* sockfd, int* clientfd, func_args* args)
431 {
432     SOCKADDR_IN_T addr;
433
434     tcp_socket(sockfd, &addr, yasslIP, yasslPort, 1);
435
436
437 #ifndef USE_WINDOWS_API 
438     {
439         int       on  = 1;
440         socklen_t len = sizeof(on);
441         setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR, &on, len);
442     }
443 #endif
444
445     if (bind(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0)
446         err_sys("tcp bind failed");
447
448 #if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER)
449     /* signal ready to accept data */
450     {
451     tcp_ready* ready = args->signal;
452     pthread_mutex_lock(&ready->mutex);
453     ready->ready = 1;
454     pthread_cond_signal(&ready->cond);
455     pthread_mutex_unlock(&ready->mutex);
456     }
457 #endif
458
459     *clientfd = udp_read_connect(*sockfd);
460 }
461
462 static INLINE void tcp_accept(SOCKET_T* sockfd, int* clientfd, func_args* args,
463                               int port, int useAnyAddr, int udp)
464 {
465     SOCKADDR_IN_T client;
466     socklen_t client_len = sizeof(client);
467
468     if (udp) {
469         udp_accept(sockfd, clientfd, args);
470         return;
471     }
472
473     tcp_listen(sockfd, port, useAnyAddr, udp);
474
475 #if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER)
476     /* signal ready to tcp_accept */
477     {
478     tcp_ready* ready = args->signal;
479     pthread_mutex_lock(&ready->mutex);
480     ready->ready = 1;
481     pthread_cond_signal(&ready->cond);
482     pthread_mutex_unlock(&ready->mutex);
483     }
484 #endif
485
486     *clientfd = accept(*sockfd, (struct sockaddr*)&client,
487                       (ACCEPT_THIRD_T)&client_len);
488     if (*clientfd == -1)
489         err_sys("tcp accept failed");
490 }
491
492
493 static INLINE void tcp_set_nonblocking(SOCKET_T* sockfd)
494 {
495 #ifdef NON_BLOCKING
496     #ifdef USE_WINDOWS_API 
497         unsigned long blocking = 1;
498         int ret = ioctlsocket(*sockfd, FIONBIO, &blocking);
499     #else
500         int flags = fcntl(*sockfd, F_GETFL, 0);
501         int ret = fcntl(*sockfd, F_SETFL, flags | O_NONBLOCK);
502     #endif
503 #endif
504 }
505
506
507 #ifndef NO_PSK
508
509 static INLINE unsigned int my_psk_client_cb(CYASSL* ssl, const char* hint,
510         char* identity, unsigned int id_max_len, unsigned char* key,
511         unsigned int key_max_len)
512 {
513     /* identity is OpenSSL testing default for openssl s_client, keep same */
514     strncpy(identity, "Client_identity", id_max_len);
515
516
517     /* test key in hex is 0x1a2b3c4d , in decimal 439,041,101 , we're using
518        unsigned binary */
519     key[0] = 26;
520     key[1] = 43;
521     key[2] = 60;
522     key[3] = 77;
523
524     return 4;   /* length of key in octets or 0 for error */
525 }
526
527
528 static INLINE unsigned int my_psk_server_cb(CYASSL* ssl, const char* identity,
529         unsigned char* key, unsigned int key_max_len)
530 {
531     /* identity is OpenSSL testing default for openssl s_client, keep same */
532     if (strncmp(identity, "Client_identity", 15) != 0)
533         return 0;
534
535     /* test key in hex is 0x1a2b3c4d , in decimal 439,041,101 , we're using
536        unsigned binary */
537     key[0] = 26;
538     key[1] = 43;
539     key[2] = 60;
540     key[3] = 77;
541
542     return 4;   /* length of key in octets or 0 for error */
543 }
544
545 #endif /* NO_PSK */
546
547
548 #ifdef USE_WINDOWS_API 
549
550     #define WIN32_LEAN_AND_MEAN
551     #include <windows.h>
552
553     static INLINE double current_time()
554     {
555         static int init = 0;
556         static LARGE_INTEGER freq;
557     
558         LARGE_INTEGER count;
559
560         if (!init) {
561             QueryPerformanceFrequency(&freq);
562             init = 1;
563         }
564
565         QueryPerformanceCounter(&count);
566
567         return (double)count.QuadPart / freq.QuadPart;
568     }
569
570 #else
571
572     #include <sys/time.h>
573
574     static INLINE double current_time()
575     {
576         struct timeval tv;
577         gettimeofday(&tv, 0);
578
579         return (double)tv.tv_sec + (double)tv.tv_usec / 1000000;
580     }
581
582 #endif /* USE_WINDOWS_API */
583
584
585 #ifdef NO_FILESYSTEM
586
587     enum {
588         CYASSL_CA   = 1,
589         CYASSL_CERT = 2,
590         CYASSL_KEY  = 3
591     };
592
593     static INLINE void load_buffer(CYASSL_CTX* ctx, const char* fname, int type)
594     {
595         /* test buffer load */
596         long  sz = 0;
597         byte  buff[10000];
598         FILE* file = fopen(fname, "rb");
599
600         if (!file)
601             err_sys("can't open file for buffer load "
602                     "Please run from CyaSSL home directory if not");
603         fseek(file, 0, SEEK_END);
604         sz = ftell(file);
605         rewind(file);
606         fread(buff, sizeof(buff), 1, file);
607   
608         if (type == CYASSL_CA) {
609             if (CyaSSL_CTX_load_verify_buffer(ctx, buff, sz, SSL_FILETYPE_PEM)
610                                               != SSL_SUCCESS)
611                 err_sys("can't load buffer ca file");
612         }
613         else if (type == CYASSL_CERT) {
614             if (CyaSSL_CTX_use_certificate_buffer(ctx, buff, sz,
615                         SSL_FILETYPE_PEM) != SSL_SUCCESS)
616                 err_sys("can't load buffer cert file");
617         }
618         else if (type == CYASSL_KEY) {
619             if (CyaSSL_CTX_use_PrivateKey_buffer(ctx, buff, sz,
620                         SSL_FILETYPE_PEM) != SSL_SUCCESS)
621                 err_sys("can't load buffer key file");
622         }
623     }
624
625 #endif /* NO_FILESYSTEM */
626
627 #ifdef VERIFY_CALLBACK
628
629 static INLINE int myVerify(int preverify, CYASSL_X509_STORE_CTX* store)
630 {
631     char buffer[80];
632
633     printf("In verification callback, error = %d, %s\n", store->error,
634                                  CyaSSL_ERR_error_string(store->error, buffer));
635 #ifdef OPENSSL_EXTRA
636     CYASSL_X509* peer = store->current_cert;
637     if (peer) {
638         char* issuer  = CyaSSL_X509_NAME_oneline(
639                                        CyaSSL_X509_get_issuer_name(peer), 0, 0);
640         char* subject = CyaSSL_X509_NAME_oneline(
641                                       CyaSSL_X509_get_subject_name(peer), 0, 0);
642         printf("peer's cert info:\n issuer : %s\n subject: %s\n", issuer,
643                                                                   subject);
644         XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
645         XFREE(issuer,  0, DYNAMIC_TYPE_OPENSSL);
646     }
647     else
648         printf("peer has no cert!\n");
649 #endif
650     printf("Subject's domain name is %s\n", store->domain);
651
652     printf("Allowing to continue anyway (shouldn't do this, EVER!!!)\n");
653     return 1;
654 }
655
656 #endif /* VERIFY_CALLBACK */
657
658
659 #ifdef HAVE_CRL
660
661 static void INLINE CRL_CallBack(const char* url)
662 {
663     printf("CRL callback url = %s\n", url);
664 }
665
666 #endif
667
668
669 static INLINE void CaCb(unsigned char* der, int sz, int type)
670 {
671     printf("Got CA cache add callback, derSz = %d, type = %d\n", sz, type);
672 }
673
674
675 static INLINE void SetDH(CYASSL* ssl)
676 {
677     /* dh1024 p */
678     static unsigned char p[] =
679     {
680         0xE6, 0x96, 0x9D, 0x3D, 0x49, 0x5B, 0xE3, 0x2C, 0x7C, 0xF1, 0x80, 0xC3,
681         0xBD, 0xD4, 0x79, 0x8E, 0x91, 0xB7, 0x81, 0x82, 0x51, 0xBB, 0x05, 0x5E,
682         0x2A, 0x20, 0x64, 0x90, 0x4A, 0x79, 0xA7, 0x70, 0xFA, 0x15, 0xA2, 0x59,
683         0xCB, 0xD5, 0x23, 0xA6, 0xA6, 0xEF, 0x09, 0xC4, 0x30, 0x48, 0xD5, 0xA2,
684         0x2F, 0x97, 0x1F, 0x3C, 0x20, 0x12, 0x9B, 0x48, 0x00, 0x0E, 0x6E, 0xDD,
685         0x06, 0x1C, 0xBC, 0x05, 0x3E, 0x37, 0x1D, 0x79, 0x4E, 0x53, 0x27, 0xDF,
686         0x61, 0x1E, 0xBB, 0xBE, 0x1B, 0xAC, 0x9B, 0x5C, 0x60, 0x44, 0xCF, 0x02,
687         0x3D, 0x76, 0xE0, 0x5E, 0xEA, 0x9B, 0xAD, 0x99, 0x1B, 0x13, 0xA6, 0x3C,
688         0x97, 0x4E, 0x9E, 0xF1, 0x83, 0x9E, 0xB5, 0xDB, 0x12, 0x51, 0x36, 0xF7,
689         0x26, 0x2E, 0x56, 0xA8, 0x87, 0x15, 0x38, 0xDF, 0xD8, 0x23, 0xC6, 0x50,
690         0x50, 0x85, 0xE2, 0x1F, 0x0D, 0xD5, 0xC8, 0x6B,
691     };
692
693     /* dh1024 g */
694     static unsigned char g[] =
695     {
696       0x02,
697     };
698
699     CyaSSL_SetTmpDH(ssl, p, sizeof(p), g, sizeof(g));
700 }
701
702 static INLINE void SetDHCtx(CYASSL_CTX* ctx)
703 {
704     /* dh1024 p */
705     static unsigned char p[] =
706     {
707         0xE6, 0x96, 0x9D, 0x3D, 0x49, 0x5B, 0xE3, 0x2C, 0x7C, 0xF1, 0x80, 0xC3,
708         0xBD, 0xD4, 0x79, 0x8E, 0x91, 0xB7, 0x81, 0x82, 0x51, 0xBB, 0x05, 0x5E,
709         0x2A, 0x20, 0x64, 0x90, 0x4A, 0x79, 0xA7, 0x70, 0xFA, 0x15, 0xA2, 0x59,
710         0xCB, 0xD5, 0x23, 0xA6, 0xA6, 0xEF, 0x09, 0xC4, 0x30, 0x48, 0xD5, 0xA2,
711         0x2F, 0x97, 0x1F, 0x3C, 0x20, 0x12, 0x9B, 0x48, 0x00, 0x0E, 0x6E, 0xDD,
712         0x06, 0x1C, 0xBC, 0x05, 0x3E, 0x37, 0x1D, 0x79, 0x4E, 0x53, 0x27, 0xDF,
713         0x61, 0x1E, 0xBB, 0xBE, 0x1B, 0xAC, 0x9B, 0x5C, 0x60, 0x44, 0xCF, 0x02,
714         0x3D, 0x76, 0xE0, 0x5E, 0xEA, 0x9B, 0xAD, 0x99, 0x1B, 0x13, 0xA6, 0x3C,
715         0x97, 0x4E, 0x9E, 0xF1, 0x83, 0x9E, 0xB5, 0xDB, 0x12, 0x51, 0x36, 0xF7,
716         0x26, 0x2E, 0x56, 0xA8, 0x87, 0x15, 0x38, 0xDF, 0xD8, 0x23, 0xC6, 0x50,
717         0x50, 0x85, 0xE2, 0x1F, 0x0D, 0xD5, 0xC8, 0x6B,
718     };
719
720     /* dh1024 g */
721     static unsigned char g[] =
722     {
723       0x02,
724     };
725
726     CyaSSL_CTX_SetTmpDH(ctx, p, sizeof(p), g, sizeof(g));
727 }
728
729 #ifdef USE_WINDOWS_API 
730
731 /* do back x number of directories */
732 static INLINE void ChangeDirBack(int x)
733 {
734     char path[MAX_PATH];
735
736     if (x == 1)
737         strncpy(path, "..\\", MAX_PATH);
738     else if (x == 2)
739         strncpy(path, "..\\..\\", MAX_PATH);
740     else if (x == 3)
741         strncpy(path, "..\\..\\..\\", MAX_PATH);
742     else if (x == 4)
743         strncpy(path, "..\\..\\..\\..\\", MAX_PATH);
744     else
745         strncpy(path, ".\\", MAX_PATH);
746     
747     SetCurrentDirectoryA(path);
748 }
749
750 /* does current dir contain str */
751 static INLINE int CurrentDir(const char* str)
752 {
753     char path[MAX_PATH];
754
755     GetCurrentDirectoryA(sizeof(path), path);
756     if (strstr(path, str))
757         return 1;
758
759     return 0;
760 }
761
762 #else
763
764 #ifndef MAX_PATH
765     #define MAX_PATH 256
766 #endif
767
768 /* do back x number of directories */
769 static INLINE void ChangeDirBack(int x)
770 {
771     char path[MAX_PATH];
772
773     if (x == 1)
774         strncpy(path, "../", MAX_PATH);
775     else if (x == 2)
776         strncpy(path, "../../", MAX_PATH);
777     else if (x == 3)
778         strncpy(path, "../../../", MAX_PATH);
779     else if (x == 4)
780         strncpy(path, "../../../../", MAX_PATH);
781     else
782         strncpy(path, "./", MAX_PATH);
783     
784     if (chdir(path) < 0)
785         printf("chdir to %s failed\n", path);
786 }
787
788 /* does current dir contain str */
789 static INLINE int CurrentDir(const char* str)
790 {
791     char path[MAX_PATH];
792
793     if (getcwd(path, sizeof(path)) == NULL) {
794         printf("no current dir?\n");
795         return 0;
796     }
797     if (strstr(path, str))
798         return 1;
799
800     return 0;
801 }
802
803 #endif /* USE_WINDOWS_API */
804
805 #endif /* CyaSSL_TEST_H */
806