15d9ed8afSbcook /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
25d9ed8afSbcook * All rights reserved.
35d9ed8afSbcook *
45d9ed8afSbcook * This package is an SSL implementation written
55d9ed8afSbcook * by Eric Young (eay@cryptsoft.com).
65d9ed8afSbcook * The implementation was written so as to conform with Netscapes SSL.
75d9ed8afSbcook *
85d9ed8afSbcook * This library is free for commercial and non-commercial use as long as
95d9ed8afSbcook * the following conditions are aheared to. The following conditions
105d9ed8afSbcook * apply to all code found in this distribution, be it the RC4, RSA,
115d9ed8afSbcook * lhash, DES, etc., code; not just the SSL code. The SSL documentation
125d9ed8afSbcook * included with this distribution is covered by the same copyright terms
135d9ed8afSbcook * except that the holder is Tim Hudson (tjh@cryptsoft.com).
145d9ed8afSbcook *
155d9ed8afSbcook * Copyright remains Eric Young's, and as such any Copyright notices in
165d9ed8afSbcook * the code are not to be removed.
175d9ed8afSbcook * If this package is used in a product, Eric Young should be given attribution
185d9ed8afSbcook * as the author of the parts of the library used.
195d9ed8afSbcook * This can be in the form of a textual message at program startup or
205d9ed8afSbcook * in documentation (online or textual) provided with the package.
215d9ed8afSbcook *
225d9ed8afSbcook * Redistribution and use in source and binary forms, with or without
235d9ed8afSbcook * modification, are permitted provided that the following conditions
245d9ed8afSbcook * are met:
255d9ed8afSbcook * 1. Redistributions of source code must retain the copyright
265d9ed8afSbcook * notice, this list of conditions and the following disclaimer.
275d9ed8afSbcook * 2. Redistributions in binary form must reproduce the above copyright
285d9ed8afSbcook * notice, this list of conditions and the following disclaimer in the
295d9ed8afSbcook * documentation and/or other materials provided with the distribution.
305d9ed8afSbcook * 3. All advertising materials mentioning features or use of this software
315d9ed8afSbcook * must display the following acknowledgement:
325d9ed8afSbcook * "This product includes cryptographic software written by
335d9ed8afSbcook * Eric Young (eay@cryptsoft.com)"
345d9ed8afSbcook * The word 'cryptographic' can be left out if the rouines from the library
355d9ed8afSbcook * being used are not cryptographic related :-).
365d9ed8afSbcook * 4. If you include any Windows specific code (or a derivative thereof) from
375d9ed8afSbcook * the apps directory (application code) you must include an acknowledgement:
385d9ed8afSbcook * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
395d9ed8afSbcook *
405d9ed8afSbcook * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
415d9ed8afSbcook * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
425d9ed8afSbcook * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
435d9ed8afSbcook * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
445d9ed8afSbcook * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
455d9ed8afSbcook * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
465d9ed8afSbcook * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
475d9ed8afSbcook * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
485d9ed8afSbcook * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
495d9ed8afSbcook * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
505d9ed8afSbcook * SUCH DAMAGE.
515d9ed8afSbcook *
525d9ed8afSbcook * The licence and distribution terms for any publically available version or
535d9ed8afSbcook * derivative of this code cannot be changed. i.e. this code cannot simply be
545d9ed8afSbcook * copied and put under another distribution licence
555d9ed8afSbcook * [including the GNU Public Licence.]
565d9ed8afSbcook */
575d9ed8afSbcook /* ====================================================================
585d9ed8afSbcook * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
595d9ed8afSbcook *
605d9ed8afSbcook * Redistribution and use in source and binary forms, with or without
615d9ed8afSbcook * modification, are permitted provided that the following conditions
625d9ed8afSbcook * are met:
635d9ed8afSbcook *
645d9ed8afSbcook * 1. Redistributions of source code must retain the above copyright
655d9ed8afSbcook * notice, this list of conditions and the following disclaimer.
665d9ed8afSbcook *
675d9ed8afSbcook * 2. Redistributions in binary form must reproduce the above copyright
685d9ed8afSbcook * notice, this list of conditions and the following disclaimer in
695d9ed8afSbcook * the documentation and/or other materials provided with the
705d9ed8afSbcook * distribution.
715d9ed8afSbcook *
725d9ed8afSbcook * 3. All advertising materials mentioning features or use of this
735d9ed8afSbcook * software must display the following acknowledgment:
745d9ed8afSbcook * "This product includes software developed by the OpenSSL Project
755d9ed8afSbcook * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
765d9ed8afSbcook *
775d9ed8afSbcook * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
785d9ed8afSbcook * endorse or promote products derived from this software without
795d9ed8afSbcook * prior written permission. For written permission, please contact
805d9ed8afSbcook * openssl-core@openssl.org.
815d9ed8afSbcook *
825d9ed8afSbcook * 5. Products derived from this software may not be called "OpenSSL"
835d9ed8afSbcook * nor may "OpenSSL" appear in their names without prior written
845d9ed8afSbcook * permission of the OpenSSL Project.
855d9ed8afSbcook *
865d9ed8afSbcook * 5. Products derived from this software may not be called "OpenSSL"
875d9ed8afSbcook * nor may "OpenSSL" appear in their names without prior written
885d9ed8afSbcook * permission of the OpenSSL Project.
895d9ed8afSbcook *
905d9ed8afSbcook * 6. Redistributions of any form whatsoever must retain the following
915d9ed8afSbcook * acknowledgment:
925d9ed8afSbcook * "This product includes software developed by the OpenSSL Project
935d9ed8afSbcook * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
945d9ed8afSbcook *
955d9ed8afSbcook * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
965d9ed8afSbcook * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
975d9ed8afSbcook * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
985d9ed8afSbcook * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
995d9ed8afSbcook * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1005d9ed8afSbcook * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1015d9ed8afSbcook * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1025d9ed8afSbcook * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1035d9ed8afSbcook * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1045d9ed8afSbcook * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1055d9ed8afSbcook * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
1065d9ed8afSbcook * OF THE POSSIBILITY OF SUCH DAMAGE.
1075d9ed8afSbcook * ====================================================================
1085d9ed8afSbcook *
1095d9ed8afSbcook * This product includes cryptographic software written by Eric Young
1105d9ed8afSbcook * (eay@cryptsoft.com). This product includes software written by Tim
1115d9ed8afSbcook * Hudson (tjh@cryptsoft.com).
1125d9ed8afSbcook *
1135d9ed8afSbcook */
1145d9ed8afSbcook
1155d9ed8afSbcook /*
1165d9ed8afSbcook * Functions that need to be overridden by non-POSIX operating systems.
1175d9ed8afSbcook */
1185d9ed8afSbcook
119a08a5a78Sjca #include <sys/resource.h>
120a08a5a78Sjca #include <sys/time.h>
1215d9ed8afSbcook
122a08a5a78Sjca #include <time.h>
1235d9ed8afSbcook
1245d9ed8afSbcook #include "apps.h"
1255d9ed8afSbcook
1262bd895b2Sjca double
app_timer_real(int get)127*f5e75c9eScheloha app_timer_real(int get)
128a08a5a78Sjca {
129a08a5a78Sjca static struct timespec start;
130a08a5a78Sjca struct timespec elapsed, now;
131a08a5a78Sjca
132a08a5a78Sjca clock_gettime(CLOCK_MONOTONIC, &now);
133*f5e75c9eScheloha if (get) {
134a08a5a78Sjca timespecsub(&now, &start, &elapsed);
135a08a5a78Sjca return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0;
136a08a5a78Sjca }
137a08a5a78Sjca start = now;
138a08a5a78Sjca return 0.0;
139a08a5a78Sjca }
140a08a5a78Sjca
1412bd895b2Sjca double
app_timer_user(int get)142*f5e75c9eScheloha app_timer_user(int get)
143a08a5a78Sjca {
144a08a5a78Sjca static struct timeval start;
145a08a5a78Sjca struct timeval elapsed;
146a08a5a78Sjca struct rusage now;
147a08a5a78Sjca
148a08a5a78Sjca getrusage(RUSAGE_SELF, &now);
149*f5e75c9eScheloha if (get) {
150a08a5a78Sjca timersub(&now.ru_utime, &start, &elapsed);
151a08a5a78Sjca return elapsed.tv_sec + elapsed.tv_usec / 1000000.0;
152a08a5a78Sjca }
153a08a5a78Sjca start = now.ru_utime;
154a08a5a78Sjca return 0.0;
155a08a5a78Sjca }
156a08a5a78Sjca
1575827cb97Sbcook int
setup_ui(void)1585827cb97Sbcook setup_ui(void)
1595827cb97Sbcook {
1605827cb97Sbcook ui_method = UI_create_method("OpenSSL application user interface");
1615827cb97Sbcook UI_method_set_opener(ui_method, ui_open);
1625827cb97Sbcook UI_method_set_reader(ui_method, ui_read);
1635827cb97Sbcook UI_method_set_writer(ui_method, ui_write);
1645827cb97Sbcook UI_method_set_closer(ui_method, ui_close);
1655827cb97Sbcook return 0;
1665827cb97Sbcook }
1675827cb97Sbcook
1685827cb97Sbcook void
destroy_ui(void)1695827cb97Sbcook destroy_ui(void)
1705827cb97Sbcook {
1715827cb97Sbcook if (ui_method) {
1725827cb97Sbcook UI_destroy_method(ui_method);
1735827cb97Sbcook ui_method = NULL;
1745827cb97Sbcook }
1755827cb97Sbcook }
176