summaryrefslogtreecommitdiff
path: root/src/regress/lib/libcrypto/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libcrypto/engine')
-rw-r--r--src/regress/lib/libcrypto/engine/Makefile9
-rw-r--r--src/regress/lib/libcrypto/engine/enginetest.c244
2 files changed, 0 insertions, 253 deletions
diff --git a/src/regress/lib/libcrypto/engine/Makefile b/src/regress/lib/libcrypto/engine/Makefile
deleted file mode 100644
index 7f11b0d382..0000000000
--- a/src/regress/lib/libcrypto/engine/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
1# $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $
2
3PROG= enginetest
4LDADD= -lcrypto
5DPADD= ${LIBCRYPTO}
6WARNINGS= Yes
7CFLAGS+= -DLIBRESSL_INTERNAL -Werror
8
9.include <bsd.regress.mk>
diff --git a/src/regress/lib/libcrypto/engine/enginetest.c b/src/regress/lib/libcrypto/engine/enginetest.c
deleted file mode 100644
index 123866259b..0000000000
--- a/src/regress/lib/libcrypto/engine/enginetest.c
+++ /dev/null
@@ -1,244 +0,0 @@
1/* $OpenBSD: enginetest.c,v 1.8 2018/07/17 17:06:49 tb Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61
62#include <openssl/buffer.h>
63#include <openssl/crypto.h>
64#include <openssl/engine.h>
65#include <openssl/err.h>
66
67static void display_engine_list(void)
68{
69 ENGINE *h;
70 int loop;
71
72 h = ENGINE_get_first();
73 loop = 0;
74 printf("listing available engine types\n");
75 while (h) {
76 printf("engine %i, id = \"%s\", name = \"%s\"\n",
77 loop++, ENGINE_get_id(h), ENGINE_get_name(h));
78 h = ENGINE_get_next(h);
79 }
80
81 printf("end of list\n");
82 /*
83 * ENGINE_get_first() increases the struct_ref counter, so we must call
84 * ENGINE_free() to decrease it again
85 */
86 ENGINE_free(h);
87}
88
89int main(int argc, char *argv[])
90{
91 ENGINE *block[512];
92 char *id, *name;
93 ENGINE *ptr;
94 int loop;
95 int to_return = 1;
96 ENGINE *new_h1 = NULL;
97 ENGINE *new_h2 = NULL;
98 ENGINE *new_h3 = NULL;
99 ENGINE *new_h4 = NULL;
100
101 ERR_load_crypto_strings();
102
103 memset(block, 0, 512 * sizeof(ENGINE *));
104 if (((new_h1 = ENGINE_new()) == NULL) ||
105 !ENGINE_set_id(new_h1, "test_id0") ||
106 !ENGINE_set_name(new_h1, "First test item") ||
107 ((new_h2 = ENGINE_new()) == NULL) ||
108 !ENGINE_set_id(new_h2, "test_id1") ||
109 !ENGINE_set_name(new_h2, "Second test item") ||
110 ((new_h3 = ENGINE_new()) == NULL) ||
111 !ENGINE_set_id(new_h3, "test_id2") ||
112 !ENGINE_set_name(new_h3, "Third test item") ||
113 ((new_h4 = ENGINE_new()) == NULL) ||
114 !ENGINE_set_id(new_h4, "test_id3") ||
115 !ENGINE_set_name(new_h4, "Fourth test item")) {
116 printf("Couldn't set up test ENGINE structures\n");
117 goto end;
118 }
119
120 printf("\nenginetest beginning\n\n");
121 display_engine_list();
122 if (!ENGINE_add(new_h1)) {
123 printf("Add failed!\n");
124 goto end;
125 }
126 display_engine_list();
127 ptr = ENGINE_get_first();
128 if (!ENGINE_remove(ptr)) {
129 printf("Remove failed!\n");
130 goto end;
131 }
132 ENGINE_free(ptr);
133 display_engine_list();
134 if (!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) {
135 printf("Add failed!\n");
136 goto end;
137 }
138 display_engine_list();
139 if (!ENGINE_remove(new_h2)) {
140 printf("Remove failed!\n");
141 goto end;
142 }
143 display_engine_list();
144 if (!ENGINE_add(new_h4)) {
145 printf("Add failed!\n");
146 goto end;
147 }
148 display_engine_list();
149 if (ENGINE_add(new_h3)) {
150 printf("Add *should* have failed but didn't!\n");
151 goto end;
152 } else
153 printf("Add that should fail did.\n");
154 ERR_clear_error();
155 if (ENGINE_remove(new_h2)) {
156 printf("Remove *should* have failed but didn't!\n");
157 goto end;
158 } else
159 printf("Remove that should fail did.\n");
160 ERR_clear_error();
161 if (!ENGINE_remove(new_h3)) {
162 printf("Remove failed!\n");
163 goto end;
164 }
165 display_engine_list();
166 if (!ENGINE_remove(new_h4)) {
167 printf("Remove failed!\n");
168 goto end;
169 }
170 display_engine_list();
171 /*
172 * Depending on whether there's any hardware support compiled
173 * in, this remove may be destined to fail.
174 */
175 ptr = ENGINE_get_first();
176 if (ptr)
177 if (!ENGINE_remove(ptr))
178 printf("Remove failed!i - probably no hardware "
179 "support present.\n");
180 ENGINE_free(ptr);
181 display_engine_list();
182
183 if (!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) {
184 printf("Couldn't add and remove to an empty list!\n");
185 goto end;
186 } else
187 printf("Successfully added and removed to an empty list!\n");
188
189 printf("About to beef up the engine-type list\n");
190 for (loop = 0; loop < 512; loop++) {
191 if (asprintf(&id, "id%i", loop) == -1)
192 goto end;
193 if (asprintf(&name, "Fake engine type %i", loop) == -1)
194 goto end;
195
196 if (((block[loop] = ENGINE_new()) == NULL) ||
197 !id || !ENGINE_set_id(block[loop], id) ||
198 !name || !ENGINE_set_name(block[loop], name)) {
199 printf("Couldn't create block of ENGINE structures.\n");
200 goto end;
201 }
202 }
203
204 for (loop = 0; loop < 512; loop++) {
205 if (!ENGINE_add(block[loop])) {
206 printf("\nAdding stopped at %i, (%s,%s)\n",
207 loop, ENGINE_get_id(block[loop]),
208 ENGINE_get_name(block[loop]));
209 break;
210 }
211 printf(".");
212 fflush(stdout);
213 }
214 printf("\nAbout to empty the engine-type list\n");
215 while ((ptr = ENGINE_get_first()) != NULL) {
216 if (!ENGINE_remove(ptr)) {
217 printf("\nRemove failed!\n");
218 goto end;
219 }
220 ENGINE_free(ptr);
221 printf("."); fflush(stdout);
222 }
223 for (loop = 0; loop < 512; loop++) {
224 free((void *)ENGINE_get_id(block[loop]));
225 free((void *)ENGINE_get_name(block[loop]));
226 }
227 printf("\nTests completed happily\n");
228 to_return = 0;
229end:
230 if (to_return)
231 ERR_print_errors_fp(stderr);
232 ENGINE_free(new_h1);
233 ENGINE_free(new_h2);
234 ENGINE_free(new_h3);
235 ENGINE_free(new_h4);
236 for (loop = 0; loop < 512; loop++)
237 ENGINE_free(block[loop]);
238 ENGINE_cleanup();
239 CRYPTO_cleanup_all_ex_data();
240 ERR_free_strings();
241 ERR_remove_thread_state(NULL);
242 CRYPTO_mem_leaks_fp(stderr);
243 return to_return;
244}