diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/man/OPENSSL_sk_new.3 | 563 |
1 files changed, 563 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/OPENSSL_sk_new.3 b/src/lib/libcrypto/man/OPENSSL_sk_new.3 new file mode 100644 index 0000000000..5fe87b8fca --- /dev/null +++ b/src/lib/libcrypto/man/OPENSSL_sk_new.3 | |||
@@ -0,0 +1,563 @@ | |||
1 | .\" $OpenBSD: OPENSSL_sk_new.3,v 1.1 2018/03/01 19:20:09 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org> | ||
4 | .\" | ||
5 | .\" Permission to use, copy, modify, and distribute this software for any | ||
6 | .\" purpose with or without fee is hereby granted, provided that the above | ||
7 | .\" copyright notice and this permission notice appear in all copies. | ||
8 | .\" | ||
9 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | .\" | ||
17 | .Dd $Mdocdate: March 1 2018 $ | ||
18 | .Dt OPENSSL_SK_NEW 3 | ||
19 | .Os | ||
20 | .Sh NAME | ||
21 | .Nm sk_new_null , | ||
22 | .Nm sk_new , | ||
23 | .Nm sk_set_cmp_func , | ||
24 | .Nm sk_dup , | ||
25 | .Nm sk_free , | ||
26 | .Nm sk_pop_free , | ||
27 | .Nm sk_num , | ||
28 | .Nm sk_value , | ||
29 | .Nm sk_find , | ||
30 | .Nm sk_find_ex , | ||
31 | .Nm sk_sort , | ||
32 | .Nm sk_is_sorted , | ||
33 | .Nm sk_push , | ||
34 | .Nm sk_unshift , | ||
35 | .Nm sk_insert , | ||
36 | .Nm sk_set , | ||
37 | .Nm sk_pop , | ||
38 | .Nm sk_shift , | ||
39 | .Nm sk_delete , | ||
40 | .Nm sk_delete_ptr , | ||
41 | .Nm sk_zero | ||
42 | .Nd variable-sized arrays of void pointers, called OpenSSL stacks | ||
43 | .Sh SYNOPSIS | ||
44 | .In openssl/stack.h | ||
45 | .Ft _STACK * | ||
46 | .Fn sk_new_null void | ||
47 | .Ft _STACK * | ||
48 | .Fo sk_new | ||
49 | .Fa "int (*compfunc)(const void *, const void *)" | ||
50 | .Fc | ||
51 | .Ft old_function_pointer | ||
52 | .Fo sk_set_cmp_func | ||
53 | .Fa "_STACK *stack" | ||
54 | .Fa "int (*compfunc)(const void *, const void *)" | ||
55 | .Fc | ||
56 | .Ft _STACK * | ||
57 | .Fo sk_dup | ||
58 | .Fa "_STACK *stack" | ||
59 | .Fc | ||
60 | .Ft void | ||
61 | .Fo sk_free | ||
62 | .Fa "_STACK *stack" | ||
63 | .Fc | ||
64 | .Ft void | ||
65 | .Fo sk_pop_free | ||
66 | .Fa "_STACK *stack" | ||
67 | .Fa "void (*freefunc)(void *)" | ||
68 | .Fc | ||
69 | .Ft int | ||
70 | .Fo sk_num | ||
71 | .Fa "const _STACK *stack" | ||
72 | .Fc | ||
73 | .Ft void * | ||
74 | .Fo sk_value | ||
75 | .Fa "const _STACK *stack" | ||
76 | .Fa "int index" | ||
77 | .Fc | ||
78 | .Ft int | ||
79 | .Fo sk_find | ||
80 | .Fa "_STACK *stack" | ||
81 | .Fa "void *wanted" | ||
82 | .Fc | ||
83 | .Ft int | ||
84 | .Fo sk_find_ex | ||
85 | .Fa "_STACK *stack" | ||
86 | .Fa "void *wanted" | ||
87 | .Fc | ||
88 | .Ft void | ||
89 | .Fo sk_sort | ||
90 | .Fa "_STACK *stack" | ||
91 | .Fc | ||
92 | .Ft int | ||
93 | .Fo sk_is_sorted | ||
94 | .Fa "const _STACK *stack" | ||
95 | .Fc | ||
96 | .Ft int | ||
97 | .Fo sk_push | ||
98 | .Fa "_STACK *stack" | ||
99 | .Fa "void *new_item" | ||
100 | .Fc | ||
101 | .Ft int | ||
102 | .Fo sk_unshift | ||
103 | .Fa "_STACK *stack" | ||
104 | .Fa "void *new_item" | ||
105 | .Fc | ||
106 | .Ft int | ||
107 | .Fo sk_insert | ||
108 | .Fa "_STACK *stack" | ||
109 | .Fa "void *new_item" | ||
110 | .Fa "int index" | ||
111 | .Fc | ||
112 | .Ft void * | ||
113 | .Fo sk_set | ||
114 | .Fa "_STACK *stack" | ||
115 | .Fa "int index" | ||
116 | .Fa "void *new_item" | ||
117 | .Fc | ||
118 | .Ft void * | ||
119 | .Fo sk_pop | ||
120 | .Fa "_STACK *stack" | ||
121 | .Fc | ||
122 | .Ft void * | ||
123 | .Fo sk_shift | ||
124 | .Fa "_STACK *stack" | ||
125 | .Fc | ||
126 | .Ft void * | ||
127 | .Fo sk_delete | ||
128 | .Fa "_STACK *stack" | ||
129 | .Fa "int index" | ||
130 | .Fc | ||
131 | .Ft void * | ||
132 | .Fo sk_delete_ptr | ||
133 | .Fa "_STACK *stack" | ||
134 | .Fa "void *wanted" | ||
135 | .Fc | ||
136 | .Ft void | ||
137 | .Fo sk_zero | ||
138 | .Fa "_STACK *stack" | ||
139 | .Fc | ||
140 | .Sh DESCRIPTION | ||
141 | OpenSSL introduced an idiosyncratic concept of variable sized arrays | ||
142 | of pointers and somewhat misleadingly called such an array a | ||
143 | .Dq stack . | ||
144 | Intrinsically, and as documented in this manual page, OpenSSL stacks | ||
145 | are not type safe but only handle | ||
146 | .Vt void * | ||
147 | function arguments and return values. | ||
148 | .Pp | ||
149 | OpenSSL also provides a fragile, unusually complicated system of | ||
150 | macro-generates wrappers that offers superficial type safety at the | ||
151 | expense of extensive obfuscation, implemented using large amounts | ||
152 | of autogenerated code involving exceedingly ugly, nested | ||
153 | .Xr cpp 1 | ||
154 | macros; see the | ||
155 | .Xr STACK_OF 3 | ||
156 | manual page for details. | ||
157 | .Pp | ||
158 | The fundamental data type is the | ||
159 | .Vt _STACK | ||
160 | structure. | ||
161 | It stores a variable number of void pointers | ||
162 | and remembers the number of pointers currently stored. | ||
163 | It can optionally hold a pointer to a comparison function. | ||
164 | As long as no comparison function is installed, the order of pointers | ||
165 | is meaningful; as soon as a comparison function is installed, it | ||
166 | becomes ill-defined. | ||
167 | .Pp | ||
168 | .Fn sk_new_null | ||
169 | allocates and initializes a new, empty stack. | ||
170 | .Fn sk_new | ||
171 | is identical except that it also installs | ||
172 | .Fa compfunc | ||
173 | as the comparison function for the new stack object. | ||
174 | .Fn sk_set_cmp_func | ||
175 | installs | ||
176 | .Fa compfunc | ||
177 | for the existing | ||
178 | .Fa stack . | ||
179 | The | ||
180 | .Fa compfunc | ||
181 | is allowed to be | ||
182 | .Dv NULL , | ||
183 | but the | ||
184 | .Fa stack | ||
185 | is not. | ||
186 | .Pp | ||
187 | .Fn sk_dup | ||
188 | creates a shallow copy of the given | ||
189 | .Fa stack , | ||
190 | which must not be a | ||
191 | .Dv NULL | ||
192 | pointer. | ||
193 | It neither copies the objects pointed to from the stack nor | ||
194 | increases their reference counts, but merely copies the pointers. | ||
195 | Extreme care must be taken in order to avoid freeing the memory twice, | ||
196 | for example by calling | ||
197 | .Fn sk_free | ||
198 | on one copy and only calling | ||
199 | .Fn sk_pop_free | ||
200 | on the other. | ||
201 | .Pp | ||
202 | .Fn sk_free | ||
203 | frees the given | ||
204 | .Fa stack . | ||
205 | It does not free any of the pointers stored on the stack. | ||
206 | Unless these pointers are merely copies of pointers owner by | ||
207 | other objects, they must be freed before calling | ||
208 | .Fn sk_free , | ||
209 | in order to avoid leaking memory. | ||
210 | If | ||
211 | .Fa stack | ||
212 | is a | ||
213 | .Dv NULL | ||
214 | pointer, no action occurs. | ||
215 | .Pp | ||
216 | .Fn sk_pop_free | ||
217 | is severely misnamed. | ||
218 | It does not at all do what one would expect from a function called | ||
219 | .Dq pop . | ||
220 | Instead, it does the same as | ||
221 | .Fn sk_free , | ||
222 | except that it also calls the function | ||
223 | .Fa freefunc | ||
224 | on each of the pointers contained in the | ||
225 | .Fa stack . | ||
226 | If the calls to | ||
227 | .Fa freefunc | ||
228 | are intended to free the memory in use by the objects on the stack, | ||
229 | ensure that no other pointers to the same objects remain elsewhere. | ||
230 | .Pp | ||
231 | .Fn sk_find | ||
232 | searches the | ||
233 | .Fa stack | ||
234 | for the | ||
235 | .Fa wanted | ||
236 | pointer. | ||
237 | If the | ||
238 | .Fa stack | ||
239 | contains more than one copy of the | ||
240 | .Fa wanted | ||
241 | pointer, only the first match is found. | ||
242 | If a comparison function is installed for the stack, the stack is | ||
243 | first sorted with | ||
244 | .Fn sk_sort , | ||
245 | and instead of comparing pointers, two pointers are considered to match | ||
246 | if the comparison function returns 0. | ||
247 | .Pp | ||
248 | .Fn sk_find_ex | ||
249 | is identical to | ||
250 | .Fn sk_find | ||
251 | except that if the | ||
252 | .Fa stack | ||
253 | is not empty but no match is found, | ||
254 | the index of some pointer considered closest to | ||
255 | .Fa wanted | ||
256 | is returned. | ||
257 | .Pp | ||
258 | .Fn sk_sort | ||
259 | sorts the | ||
260 | .Fa stack | ||
261 | using | ||
262 | .Xr qsort 3 | ||
263 | and the installed comparison function. | ||
264 | If | ||
265 | .Fa stack | ||
266 | is a | ||
267 | .Dv NULL | ||
268 | pointer or already considered sorted, no action occurs. | ||
269 | This function can only be called if a comparison function is installed. | ||
270 | .Pp | ||
271 | .Fn sk_is_sorted | ||
272 | reports whether the | ||
273 | .Fa stack | ||
274 | is considered sorted. | ||
275 | Calling | ||
276 | .Fn sk_new_null | ||
277 | or | ||
278 | .Fn sk_new , | ||
279 | successfuly calling | ||
280 | .Fn sk_push , | ||
281 | .Fn sk_unshift , | ||
282 | or | ||
283 | .Fn sk_insert , | ||
284 | or changing the comparison function sets the state to unsorted. | ||
285 | If a comparison function is installed, calling | ||
286 | .Fn sk_sort , | ||
287 | .Fn sk_find , | ||
288 | or | ||
289 | .Fn sk_find_ex | ||
290 | sets the state to sorted. | ||
291 | .Pp | ||
292 | .Fn sk_push | ||
293 | pushes | ||
294 | .Fa new_item | ||
295 | onto the end of the | ||
296 | .Fa stack , | ||
297 | increasing the number of pointers by 1. | ||
298 | If | ||
299 | .Fa stack | ||
300 | is a | ||
301 | .Dv NULL | ||
302 | pointer, no action occurs. | ||
303 | .Pp | ||
304 | .Fn sk_unshift | ||
305 | inserts | ||
306 | .Fa new_item | ||
307 | at the beginning of the | ||
308 | .Fa stack , | ||
309 | such that it gets the index 0. | ||
310 | The number of pointers increases by 1. | ||
311 | If | ||
312 | .Fa stack | ||
313 | is a | ||
314 | .Dv NULL | ||
315 | pointer, no action occurs. | ||
316 | .Pp | ||
317 | .Fn sk_insert | ||
318 | inserts the | ||
319 | .Fa new_item | ||
320 | into the | ||
321 | .Fa stack | ||
322 | such that it gets the given | ||
323 | .Fa index . | ||
324 | If | ||
325 | .Fa index | ||
326 | is less than 0 or greater than or equal to | ||
327 | .Fn sk_num stack , | ||
328 | the effect is the same as for | ||
329 | .Fn sk_push . | ||
330 | If | ||
331 | .Fa stack | ||
332 | is a | ||
333 | .Dv NULL | ||
334 | pointer, no action occurs. | ||
335 | .Pp | ||
336 | .Fn sk_set | ||
337 | replaces the pointer with the given | ||
338 | .Fa index | ||
339 | on the | ||
340 | .Fa stack | ||
341 | with the | ||
342 | .Fa new_item . | ||
343 | The old pointer is not freed, | ||
344 | which may leak memory if no copy of it exists elsewhere. | ||
345 | If | ||
346 | .Fa stack | ||
347 | is a | ||
348 | .Dv NULL | ||
349 | pointer or if | ||
350 | .Fa index | ||
351 | is less than 0 or greater than or equal to | ||
352 | .Fn sk_num stack , | ||
353 | no action occurs. | ||
354 | .Pp | ||
355 | .Fn sk_pop | ||
356 | and | ||
357 | .Fn sk_shift | ||
358 | remove the pointer with the highest or lowest index from the | ||
359 | .Fa stack , | ||
360 | respectively, reducing the number of pointers by 1. | ||
361 | If | ||
362 | .Fa stack | ||
363 | is a | ||
364 | .Dv NULL | ||
365 | pointer or if it is empty, no action occurs. | ||
366 | .Pp | ||
367 | .Fn sk_delete | ||
368 | removes the pointer with the given | ||
369 | .Fa index | ||
370 | from the | ||
371 | .Fa stack , | ||
372 | reducing the number of pointers by 1. | ||
373 | If | ||
374 | .Fa stack | ||
375 | is a | ||
376 | .Dv NULL | ||
377 | pointer or the | ||
378 | .Fa index | ||
379 | is less than 0 or greater than or equal to | ||
380 | .Fn sk_num stack , | ||
381 | no action occurs. | ||
382 | .Pp | ||
383 | .Fn sk_delete_ptr | ||
384 | removes the | ||
385 | .Fa wanted | ||
386 | pointer from the | ||
387 | .Fa stack , | ||
388 | reducing the number of pointers by 1 if it is found. | ||
389 | It never uses a comparison function | ||
390 | but only compares pointers themselves. | ||
391 | The | ||
392 | .Fa stack | ||
393 | pointer must not be | ||
394 | .Dv NULL . | ||
395 | .Pp | ||
396 | .Fn sk_zero | ||
397 | removes all pointers from the | ||
398 | .Fa stack . | ||
399 | It does not free any of the pointers. | ||
400 | Unless these pointers are merely copies of pointers owner by other | ||
401 | objects, they must be freed before calling sk_zero(), in order to | ||
402 | avoid leaking memory. | ||
403 | If | ||
404 | .Fa stack | ||
405 | is a | ||
406 | .Dv NULL | ||
407 | pointer, no action occurs. | ||
408 | .Sh RETURN VALUES | ||
409 | .Fn sk_new_null , | ||
410 | .Fn sk_new , | ||
411 | and | ||
412 | .Fn sk_dup | ||
413 | return a pointer to the newly allocated stack object or | ||
414 | .Dv NULL | ||
415 | if insufficient memory is available. | ||
416 | .Pp | ||
417 | .Fn sk_set_cmp_func | ||
418 | returns a pointer to the comparison function | ||
419 | that was previously installed for the | ||
420 | .Fa stack | ||
421 | or | ||
422 | .Dv NULL | ||
423 | if none was installed. | ||
424 | .Pp | ||
425 | .Fn sk_num | ||
426 | returns the number of pointers currently stored on the | ||
427 | .Fa stack , | ||
428 | or \-1 if | ||
429 | .Fa stack | ||
430 | is a | ||
431 | .Dv NULL | ||
432 | pointer. | ||
433 | .Pp | ||
434 | .Fn sk_value | ||
435 | returns the pointer with the given | ||
436 | .Fa index | ||
437 | from the | ||
438 | .Fa stack , | ||
439 | or | ||
440 | .Dv NULL | ||
441 | if | ||
442 | .Fa stack | ||
443 | is a | ||
444 | .Dv NULL | ||
445 | pointer or if the | ||
446 | .Fa index | ||
447 | is less than 0 or greater than or equal to | ||
448 | .Fn sk_num stack . | ||
449 | .Pp | ||
450 | .Fn sk_find | ||
451 | returns the lowest index considered to match or \-1 if | ||
452 | .Fa stack | ||
453 | is a | ||
454 | .Dv NULL | ||
455 | pointer or if no match is found. | ||
456 | .Pp | ||
457 | .Fn sk_find_ex | ||
458 | returns some index or \-1 if | ||
459 | .Fa stack | ||
460 | is a | ||
461 | .Dv NULL | ||
462 | pointer or empty. | ||
463 | .Pp | ||
464 | .Fn sk_is_sorted | ||
465 | returns 1 if the | ||
466 | .Fa stack | ||
467 | is considered sorted or if it is a | ||
468 | .Dv NULL | ||
469 | pointer, or 0 otherwise. | ||
470 | .Pp | ||
471 | .Fn sk_push , | ||
472 | .Fn sk_unshift , | ||
473 | and | ||
474 | .Fn sk_insert | ||
475 | return the new number of pointers on the | ||
476 | .Fa stack | ||
477 | or 0 if | ||
478 | .Fa stack | ||
479 | is a | ||
480 | .Dv NULL | ||
481 | pointer or if memory allocation fails. | ||
482 | .Pp | ||
483 | .Fn sk_set | ||
484 | returns | ||
485 | .Fa new_item | ||
486 | or | ||
487 | .Dv NULL | ||
488 | if | ||
489 | .Fa stack | ||
490 | is a | ||
491 | .Dv NULL | ||
492 | pointer or if the | ||
493 | .Fa index | ||
494 | is less than 0 or greater than or equal to | ||
495 | .Fn sk_num stack . | ||
496 | .Pp | ||
497 | .Fn sk_pop | ||
498 | and | ||
499 | .Fn sk_shift | ||
500 | return the deleted pointer or | ||
501 | .Dv NULL | ||
502 | if | ||
503 | .Fa stack | ||
504 | is a | ||
505 | .Dv NULL | ||
506 | pointer or if it is empty. | ||
507 | .Pp | ||
508 | .Fn sk_delete | ||
509 | returns the deleted pointer or | ||
510 | .Dv NULL | ||
511 | if | ||
512 | .Fa stack | ||
513 | is a | ||
514 | .Dv NULL | ||
515 | pointer or if the | ||
516 | .Fa index | ||
517 | is less than 0 or greater than or equal to | ||
518 | .Fn sk_num stack . | ||
519 | .Pp | ||
520 | .Fn sk_delete_ptr | ||
521 | returns | ||
522 | .Fa wanted | ||
523 | or | ||
524 | .Dv NULL | ||
525 | if it is not found. | ||
526 | .Sh BUGS | ||
527 | .Fn sk_set | ||
528 | does not set the state of the | ||
529 | .Fa stack | ||
530 | to unsorted. | ||
531 | This can cause wrong results from subsequent | ||
532 | .Fn sk_find | ||
533 | and | ||
534 | .Fn sk_find_ex . | ||
535 | .Pp | ||
536 | Even if a comparison function is installed, empty stacks and | ||
537 | stacks containing a single pointer are sometimes considered | ||
538 | sorted and sometimes considered unsorted. | ||
539 | .Pp | ||
540 | If a comparison function is installed, the concept of | ||
541 | .Dq first match | ||
542 | in | ||
543 | .Fn sk_find | ||
544 | and | ||
545 | .Fn sk_find_ex | ||
546 | is ill-defined because | ||
547 | .Xr qsort 3 | ||
548 | is not a stable sorting function. | ||
549 | It is probably best to only assume that they return an arbitrary match. | ||
550 | .Pp | ||
551 | The concept of | ||
552 | .Dq closest | ||
553 | for | ||
554 | .Fn sk_find_ex | ||
555 | is even less clearly defined. | ||
556 | The match may sometimes be smaller and sometimes larger than | ||
557 | .Fa wanted , | ||
558 | even if both smaller and larger pointers exist in the | ||
559 | .Fa stack . | ||
560 | Besides, it is again ill-defined | ||
561 | which of several pointers that compare equal is selected. | ||
562 | It is probably best to not assume anything about the selection | ||
563 | for cases where there is no match. | ||