summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/store/str_mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/store/str_mem.c')
-rw-r--r--src/lib/libcrypto/store/str_mem.c370
1 files changed, 0 insertions, 370 deletions
diff --git a/src/lib/libcrypto/store/str_mem.c b/src/lib/libcrypto/store/str_mem.c
deleted file mode 100644
index a85a8946b7..0000000000
--- a/src/lib/libcrypto/store/str_mem.c
+++ /dev/null
@@ -1,370 +0,0 @@
1/* $OpenBSD: str_mem.c,v 1.10 2014/10/28 05:46:56 miod Exp $ */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003.
4 */
5/* ====================================================================
6 * Copyright (c) 2003 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 * openssl-core@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 <string.h>
60#include <openssl/err.h>
61#include "str_locl.h"
62
63/* The memory store is currently highly experimental. It's meant to become
64 a base store used by other stores for internal caching (for full caching
65 support, aging needs to be added).
66
67 The database use is meant to support as much attribute association as
68 possible, while providing for as small search ranges as possible.
69 This is currently provided for by sorting the entries by numbers that
70 are composed of bits set at the positions indicated by attribute type
71 codes. This provides for ranges determined by the highest attribute
72 type code value. A better idea might be to sort by values computed
73 from the range of attributes associated with the object (basically,
74 the difference between the highest and lowest attribute type code)
75 and it's distance from a base (basically, the lowest associated
76 attribute type code).
77*/
78
79typedef struct mem_object_data_st {
80 STORE_OBJECT *object;
81 STORE_ATTR_INFO *attr_info;
82 int references;
83} MEM_OBJECT_DATA;
84
85DECLARE_STACK_OF(MEM_OBJECT_DATA)
86struct mem_data_st {
87 STACK_OF(MEM_OBJECT_DATA) *data; /* sorted with
88 * STORE_ATTR_INFO_compare(). */
89 unsigned int compute_components : 1; /* Currently unused, but can
90 be used to add attributes
91 from parts of the data. */
92};
93
94DECLARE_STACK_OF(STORE_ATTR_INFO)
95struct mem_ctx_st {
96 int type; /* The type we're searching for */
97 STACK_OF(STORE_ATTR_INFO) *search_attributes; /* Sets of
98 attributes to search for. Each
99 element is a STORE_ATTR_INFO. */
100 int search_index; /* which of the search attributes we
101 found a match for, -1 when we still
102 haven't found any */
103 int index; /* -1 as long as we're searching for
104 the first */
105};
106
107static int mem_init(STORE *s);
108static void mem_clean(STORE *s);
109static STORE_OBJECT *mem_generate(STORE *s, STORE_OBJECT_TYPES type,
110 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
111static STORE_OBJECT *mem_get(STORE *s, STORE_OBJECT_TYPES type,
112 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
113static int mem_store(STORE *s, STORE_OBJECT_TYPES type, STORE_OBJECT *data,
114 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
115static int mem_modify(STORE *s, STORE_OBJECT_TYPES type,
116 OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[],
117 OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[],
118 OPENSSL_ITEM parameters[]);
119static int mem_delete(STORE *s, STORE_OBJECT_TYPES type,
120 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
121static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type,
122 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
123static STORE_OBJECT *mem_list_next(STORE *s, void *handle);
124static int mem_list_end(STORE *s, void *handle);
125static int mem_list_endp(STORE *s, void *handle);
126static int mem_lock(STORE *s, OPENSSL_ITEM attributes[],
127 OPENSSL_ITEM parameters[]);
128static int mem_unlock(STORE *s, OPENSSL_ITEM attributes[],
129 OPENSSL_ITEM parameters[]);
130static int mem_ctrl(STORE *s, int cmd, long l, void *p, void (*f)(void));
131
132static STORE_METHOD store_memory = {
133 .name = "OpenSSL memory store interface",
134 .init = mem_init,
135 .clean = mem_clean,
136 .generate_object = mem_generate,
137 .get_object = mem_get,
138 .store_object = mem_store,
139 .modify_object = mem_modify,
140 .delete_object = mem_delete,
141 .list_object_start = mem_list_start,
142 .list_object_next = mem_list_next,
143 .list_object_end = mem_list_end,
144 .list_object_endp = mem_list_endp,
145 .lock_store = mem_lock,
146 .unlock_store = mem_unlock,
147 .ctrl = mem_ctrl
148};
149
150const STORE_METHOD *
151STORE_Memory(void)
152{
153 return &store_memory;
154}
155
156static int
157mem_init(STORE *s)
158{
159 return 1;
160}
161
162static void
163mem_clean(STORE *s)
164{
165 return;
166}
167
168static STORE_OBJECT *
169mem_generate(STORE *s, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[],
170 OPENSSL_ITEM parameters[])
171{
172 STOREerr(STORE_F_MEM_GENERATE, STORE_R_NOT_IMPLEMENTED);
173 return 0;
174}
175
176static STORE_OBJECT *
177mem_get(STORE *s, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[],
178 OPENSSL_ITEM parameters[])
179{
180 void *context = mem_list_start(s, type, attributes, parameters);
181
182 if (context) {
183 STORE_OBJECT *object = mem_list_next(s, context);
184
185 if (mem_list_end(s, context))
186 return object;
187 }
188 return NULL;
189}
190
191static int
192mem_store(STORE *s, STORE_OBJECT_TYPES type, STORE_OBJECT *data,
193 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
194{
195 STOREerr(STORE_F_MEM_STORE, STORE_R_NOT_IMPLEMENTED);
196 return 0;
197}
198
199static int
200mem_modify(STORE *s, STORE_OBJECT_TYPES type, OPENSSL_ITEM search_attributes[],
201 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
202 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
203{
204 STOREerr(STORE_F_MEM_MODIFY, STORE_R_NOT_IMPLEMENTED);
205 return 0;
206}
207
208static int
209mem_delete(STORE *s, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[],
210 OPENSSL_ITEM parameters[])
211{
212 STOREerr(STORE_F_MEM_DELETE, STORE_R_NOT_IMPLEMENTED);
213 return 0;
214}
215
216/* The list functions may be the hardest to understand. Basically,
217 mem_list_start compiles a stack of attribute info elements, and
218 puts that stack into the context to be returned. mem_list_next
219 will then find the first matching element in the store, and then
220 walk all the way to the end of the store (since any combination
221 of attribute bits above the starting point may match the searched
222 for bit pattern...). */
223static void *
224mem_list_start(STORE *s, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[],
225 OPENSSL_ITEM parameters[])
226{
227 struct mem_ctx_st *context;
228 void *attribute_context = NULL;
229 STORE_ATTR_INFO *attrs = NULL;
230
231 context = calloc(1, sizeof(struct mem_ctx_st));
232 if (!context) {
233 STOREerr(STORE_F_MEM_LIST_START, ERR_R_MALLOC_FAILURE);
234 return 0;
235 }
236
237 attribute_context = STORE_parse_attrs_start(attributes);
238 if (!attribute_context) {
239 STOREerr(STORE_F_MEM_LIST_START, ERR_R_STORE_LIB);
240 goto err;
241 }
242
243 while ((attrs = STORE_parse_attrs_next(attribute_context))) {
244 if (context->search_attributes == NULL) {
245 context->search_attributes =
246 sk_STORE_ATTR_INFO_new(STORE_ATTR_INFO_compare);
247 if (!context->search_attributes) {
248 STOREerr(STORE_F_MEM_LIST_START,
249 ERR_R_MALLOC_FAILURE);
250 goto err;
251 }
252 }
253 if (sk_STORE_ATTR_INFO_push(context->search_attributes,
254 attrs) == 0) {
255 STOREerr(STORE_F_MEM_LIST_START, ERR_R_MALLOC_FAILURE);
256 goto err;
257 }
258 }
259 if (!STORE_parse_attrs_endp(attribute_context))
260 goto err;
261 STORE_parse_attrs_end(attribute_context);
262 context->search_index = -1;
263 context->index = -1;
264 return context;
265
266err:
267 if (attribute_context)
268 STORE_parse_attrs_end(attribute_context);
269 mem_list_end(s, context);
270 return NULL;
271}
272
273static STORE_OBJECT *
274mem_list_next(STORE *s, void *handle)
275{
276 int i;
277 struct mem_ctx_st *context = (struct mem_ctx_st *)handle;
278 struct mem_object_data_st key = { 0, 0, 1 };
279 struct mem_data_st *store =
280 (struct mem_data_st *)STORE_get_ex_data(s, 1);
281 int srch;
282 int cres = 0;
283
284 if (!context) {
285 STOREerr(STORE_F_MEM_LIST_NEXT, ERR_R_PASSED_NULL_PARAMETER);
286 return NULL;
287 }
288 if (!store) {
289 STOREerr(STORE_F_MEM_LIST_NEXT, STORE_R_NO_STORE);
290 return NULL;
291 }
292
293 if (context->search_index == -1) {
294 for (i = 0;
295 i < sk_STORE_ATTR_INFO_num(context->search_attributes);
296 i++) {
297 key.attr_info
298 = sk_STORE_ATTR_INFO_value(context->search_attributes,
299 i);
300 srch = sk_MEM_OBJECT_DATA_find_ex(store->data, &key);
301
302 if (srch >= 0) {
303 context->search_index = srch;
304 break;
305 }
306 }
307 }
308 if (context->search_index < 0)
309 return NULL;
310
311 key.attr_info = sk_STORE_ATTR_INFO_value(context->search_attributes,
312 context->search_index);
313 for(srch = context->search_index;
314 srch < sk_MEM_OBJECT_DATA_num(store->data) &&
315 STORE_ATTR_INFO_in_range(key.attr_info,
316 sk_MEM_OBJECT_DATA_value(store->data, srch)->attr_info) &&
317 !(cres = STORE_ATTR_INFO_in_ex(key.attr_info,
318 sk_MEM_OBJECT_DATA_value(store->data, srch)->attr_info));
319 srch++)
320 ;
321
322 context->search_index = srch;
323 if (cres)
324 return (sk_MEM_OBJECT_DATA_value(store->data, srch))->object;
325 return NULL;
326}
327
328static int
329mem_list_end(STORE *s, void *handle)
330{
331 struct mem_ctx_st *context = (struct mem_ctx_st *)handle;
332
333 if (!context) {
334 STOREerr(STORE_F_MEM_LIST_END, ERR_R_PASSED_NULL_PARAMETER);
335 return 0;
336 }
337 if (context && context->search_attributes)
338 sk_STORE_ATTR_INFO_free(context->search_attributes);
339 free(context);
340 return 1;
341}
342
343static int
344mem_list_endp(STORE *s, void *handle)
345{
346 struct mem_ctx_st *context = (struct mem_ctx_st *)handle;
347
348 if (!context || context->search_index ==
349 sk_STORE_ATTR_INFO_num(context->search_attributes))
350 return 1;
351 return 0;
352}
353
354static int
355mem_lock(STORE *s, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
356{
357 return 1;
358}
359
360static int
361mem_unlock(STORE *s, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
362{
363 return 1;
364}
365
366static int
367mem_ctrl(STORE *s, int cmd, long l, void *p, void (*f)(void))
368{
369 return 1;
370}