xref: /freebsd/crypto/openssl/util/perl/OpenSSL/stackhash.pm (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert#! /usr/bin/env perl
2*e0c4386eSCy Schubert# Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert#
4*e0c4386eSCy Schubert# Licensed under the Apache License 2.0 (the "License").  You may not use
5*e0c4386eSCy Schubert# this file except in compliance with the License.  You can obtain a copy
6*e0c4386eSCy Schubert# in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert# https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert
9*e0c4386eSCy Schubertpackage OpenSSL::stackhash;
10*e0c4386eSCy Schubert
11*e0c4386eSCy Schubertuse strict;
12*e0c4386eSCy Schubertuse warnings;
13*e0c4386eSCy Schubert
14*e0c4386eSCy Schubertrequire Exporter;
15*e0c4386eSCy Schubertour @ISA = qw(Exporter);
16*e0c4386eSCy Schubertour @EXPORT_OK = qw(generate_stack_macros generate_const_stack_macros
17*e0c4386eSCy Schubert                    generate_stack_string_macros
18*e0c4386eSCy Schubert                    generate_stack_const_string_macros
19*e0c4386eSCy Schubert                    generate_stack_block_macros
20*e0c4386eSCy Schubert                    generate_lhash_macros);
21*e0c4386eSCy Schubert
22*e0c4386eSCy Schubertsub generate_stack_macros_int {
23*e0c4386eSCy Schubert    my $nametype = shift;
24*e0c4386eSCy Schubert    my $realtype = shift;
25*e0c4386eSCy Schubert    my $plaintype = shift;
26*e0c4386eSCy Schubert
27*e0c4386eSCy Schubert    my $macros = <<END_MACROS;
28*e0c4386eSCy SchubertSKM_DEFINE_STACK_OF_INTERNAL(${nametype}, ${realtype}, ${plaintype})
29*e0c4386eSCy Schubert#define sk_${nametype}_num(sk) OPENSSL_sk_num(ossl_check_const_${nametype}_sk_type(sk))
30*e0c4386eSCy Schubert#define sk_${nametype}_value(sk, idx) ((${realtype} *)OPENSSL_sk_value(ossl_check_const_${nametype}_sk_type(sk), (idx)))
31*e0c4386eSCy Schubert#define sk_${nametype}_new(cmp) ((STACK_OF(${nametype}) *)OPENSSL_sk_new(ossl_check_${nametype}_compfunc_type(cmp)))
32*e0c4386eSCy Schubert#define sk_${nametype}_new_null() ((STACK_OF(${nametype}) *)OPENSSL_sk_new_null())
33*e0c4386eSCy Schubert#define sk_${nametype}_new_reserve(cmp, n) ((STACK_OF(${nametype}) *)OPENSSL_sk_new_reserve(ossl_check_${nametype}_compfunc_type(cmp), (n)))
34*e0c4386eSCy Schubert#define sk_${nametype}_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_${nametype}_sk_type(sk), (n))
35*e0c4386eSCy Schubert#define sk_${nametype}_free(sk) OPENSSL_sk_free(ossl_check_${nametype}_sk_type(sk))
36*e0c4386eSCy Schubert#define sk_${nametype}_zero(sk) OPENSSL_sk_zero(ossl_check_${nametype}_sk_type(sk))
37*e0c4386eSCy Schubert#define sk_${nametype}_delete(sk, i) ((${realtype} *)OPENSSL_sk_delete(ossl_check_${nametype}_sk_type(sk), (i)))
38*e0c4386eSCy Schubert#define sk_${nametype}_delete_ptr(sk, ptr) ((${realtype} *)OPENSSL_sk_delete_ptr(ossl_check_${nametype}_sk_type(sk), ossl_check_${nametype}_type(ptr)))
39*e0c4386eSCy Schubert#define sk_${nametype}_push(sk, ptr) OPENSSL_sk_push(ossl_check_${nametype}_sk_type(sk), ossl_check_${nametype}_type(ptr))
40*e0c4386eSCy Schubert#define sk_${nametype}_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_${nametype}_sk_type(sk), ossl_check_${nametype}_type(ptr))
41*e0c4386eSCy Schubert#define sk_${nametype}_pop(sk) ((${realtype} *)OPENSSL_sk_pop(ossl_check_${nametype}_sk_type(sk)))
42*e0c4386eSCy Schubert#define sk_${nametype}_shift(sk) ((${realtype} *)OPENSSL_sk_shift(ossl_check_${nametype}_sk_type(sk)))
43*e0c4386eSCy Schubert#define sk_${nametype}_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_${nametype}_sk_type(sk),ossl_check_${nametype}_freefunc_type(freefunc))
44*e0c4386eSCy Schubert#define sk_${nametype}_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_${nametype}_sk_type(sk), ossl_check_${nametype}_type(ptr), (idx))
45*e0c4386eSCy Schubert#define sk_${nametype}_set(sk, idx, ptr) ((${realtype} *)OPENSSL_sk_set(ossl_check_${nametype}_sk_type(sk), (idx), ossl_check_${nametype}_type(ptr)))
46*e0c4386eSCy Schubert#define sk_${nametype}_find(sk, ptr) OPENSSL_sk_find(ossl_check_${nametype}_sk_type(sk), ossl_check_${nametype}_type(ptr))
47*e0c4386eSCy Schubert#define sk_${nametype}_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_${nametype}_sk_type(sk), ossl_check_${nametype}_type(ptr))
48*e0c4386eSCy Schubert#define sk_${nametype}_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_${nametype}_sk_type(sk), ossl_check_${nametype}_type(ptr), pnum)
49*e0c4386eSCy Schubert#define sk_${nametype}_sort(sk) OPENSSL_sk_sort(ossl_check_${nametype}_sk_type(sk))
50*e0c4386eSCy Schubert#define sk_${nametype}_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_${nametype}_sk_type(sk))
51*e0c4386eSCy Schubert#define sk_${nametype}_dup(sk) ((STACK_OF(${nametype}) *)OPENSSL_sk_dup(ossl_check_const_${nametype}_sk_type(sk)))
52*e0c4386eSCy Schubert#define sk_${nametype}_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(${nametype}) *)OPENSSL_sk_deep_copy(ossl_check_const_${nametype}_sk_type(sk), ossl_check_${nametype}_copyfunc_type(copyfunc), ossl_check_${nametype}_freefunc_type(freefunc)))
53*e0c4386eSCy Schubert#define sk_${nametype}_set_cmp_func(sk, cmp) ((sk_${nametype}_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_${nametype}_sk_type(sk), ossl_check_${nametype}_compfunc_type(cmp)))
54*e0c4386eSCy SchubertEND_MACROS
55*e0c4386eSCy Schubert
56*e0c4386eSCy Schubert    return $macros;
57*e0c4386eSCy Schubert}
58*e0c4386eSCy Schubert
59*e0c4386eSCy Schubertsub generate_stack_macros {
60*e0c4386eSCy Schubert    my $type = shift;
61*e0c4386eSCy Schubert
62*e0c4386eSCy Schubert    return generate_stack_macros_int($type, $type, $type);
63*e0c4386eSCy Schubert}
64*e0c4386eSCy Schubert
65*e0c4386eSCy Schubertsub generate_const_stack_macros {
66*e0c4386eSCy Schubert    my $type = shift;
67*e0c4386eSCy Schubert
68*e0c4386eSCy Schubert    return generate_stack_macros_int($type, "const $type", $type);
69*e0c4386eSCy Schubert}
70*e0c4386eSCy Schubert
71*e0c4386eSCy Schubertsub generate_stack_string_macros {
72*e0c4386eSCy Schubert    return generate_stack_macros_int("OPENSSL_STRING", "char", "char");
73*e0c4386eSCy Schubert}
74*e0c4386eSCy Schubert
75*e0c4386eSCy Schubertsub generate_stack_const_string_macros {
76*e0c4386eSCy Schubert    return generate_stack_macros_int("OPENSSL_CSTRING", "const char", "char");
77*e0c4386eSCy Schubert}
78*e0c4386eSCy Schubert
79*e0c4386eSCy Schubertsub generate_stack_block_macros {
80*e0c4386eSCy Schubert    return generate_stack_macros_int("OPENSSL_BLOCK", "void", "void");
81*e0c4386eSCy Schubert}
82*e0c4386eSCy Schubert
83*e0c4386eSCy Schubertsub generate_lhash_macros {
84*e0c4386eSCy Schubert    my $type = shift;
85*e0c4386eSCy Schubert
86*e0c4386eSCy Schubert    my $macros = <<END_MACROS;
87*e0c4386eSCy SchubertDEFINE_LHASH_OF_INTERNAL(${type});
88*e0c4386eSCy Schubert#define lh_${type}_new(hfn, cmp) ((LHASH_OF(${type}) *)OPENSSL_LH_new(ossl_check_${type}_lh_hashfunc_type(hfn), ossl_check_${type}_lh_compfunc_type(cmp)))
89*e0c4386eSCy Schubert#define lh_${type}_free(lh) OPENSSL_LH_free(ossl_check_${type}_lh_type(lh))
90*e0c4386eSCy Schubert#define lh_${type}_flush(lh) OPENSSL_LH_flush(ossl_check_${type}_lh_type(lh))
91*e0c4386eSCy Schubert#define lh_${type}_insert(lh, ptr) ((${type} *)OPENSSL_LH_insert(ossl_check_${type}_lh_type(lh), ossl_check_${type}_lh_plain_type(ptr)))
92*e0c4386eSCy Schubert#define lh_${type}_delete(lh, ptr) ((${type} *)OPENSSL_LH_delete(ossl_check_${type}_lh_type(lh), ossl_check_const_${type}_lh_plain_type(ptr)))
93*e0c4386eSCy Schubert#define lh_${type}_retrieve(lh, ptr) ((${type} *)OPENSSL_LH_retrieve(ossl_check_${type}_lh_type(lh), ossl_check_const_${type}_lh_plain_type(ptr)))
94*e0c4386eSCy Schubert#define lh_${type}_error(lh) OPENSSL_LH_error(ossl_check_${type}_lh_type(lh))
95*e0c4386eSCy Schubert#define lh_${type}_num_items(lh) OPENSSL_LH_num_items(ossl_check_${type}_lh_type(lh))
96*e0c4386eSCy Schubert#define lh_${type}_node_stats_bio(lh, out) OPENSSL_LH_node_stats_bio(ossl_check_const_${type}_lh_type(lh), out)
97*e0c4386eSCy Schubert#define lh_${type}_node_usage_stats_bio(lh, out) OPENSSL_LH_node_usage_stats_bio(ossl_check_const_${type}_lh_type(lh), out)
98*e0c4386eSCy Schubert#define lh_${type}_stats_bio(lh, out) OPENSSL_LH_stats_bio(ossl_check_const_${type}_lh_type(lh), out)
99*e0c4386eSCy Schubert#define lh_${type}_get_down_load(lh) OPENSSL_LH_get_down_load(ossl_check_${type}_lh_type(lh))
100*e0c4386eSCy Schubert#define lh_${type}_set_down_load(lh, dl) OPENSSL_LH_set_down_load(ossl_check_${type}_lh_type(lh), dl)
101*e0c4386eSCy Schubert#define lh_${type}_doall(lh, dfn) OPENSSL_LH_doall(ossl_check_${type}_lh_type(lh), ossl_check_${type}_lh_doallfunc_type(dfn))
102*e0c4386eSCy SchubertEND_MACROS
103*e0c4386eSCy Schubert
104*e0c4386eSCy Schubert    return $macros;
105*e0c4386eSCy Schubert}
106*e0c4386eSCy Schubert1;
107