Debian Codegraph @

debian/rust-vendor/openssl-src/openssl/apps/progs.pl

raw
1 #! /usr/bin/env perl
2 # Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9 # Generate progs.h file by looking for command mains in list of C files
10 # passed on the command line.
11
12 use strict;
13 use warnings;
14 use lib '.';
15 use configdata qw/@disablables %unified_info/;
16
17 my $opt = shift @ARGV;
18 die "Unrecognised option, must be -C or -H\n"
19 unless ($opt eq '-H' || $opt eq '-C');
20
21 my %commands = ();
22 # I think it is best reconsidered in favour of just a table
23 # of commands instead of this fragile regex. There really are not that
24 # many commands.
25 my $cmdre = qr/^\s*(int\s+|)\s*([a-z_][a-z0-9_]*)_main\s*\(\s*int\s+argc\s*,/;
26 my $apps_openssl = shift @ARGV;
27 my $YEAR = [gmtime($ENV{SOURCE_DATE_EPOCH} || time())]->[5] + 1900;
28
29 # because the program apps/openssl has object files as sources, and
30 # they then have the corresponding C files as source, we need to chain
31 # the lookups in %unified_info
32 my @openssl_source =
33 map { @{$unified_info{sources}->{$_}} }
34 grep { /\.o$/
35 && !$unified_info{attributes}->{sources}->{$apps_openssl}->{$_}->{nocheck} }
36 @{$unified_info{sources}->{$apps_openssl}};
37
38 foreach my $filename (@openssl_source) {
39 open F, $filename or die "Couldn't open $filename: $!\n";
40 foreach ( grep /$cmdre/, <F> ) {
41 my @foo = /$cmdre/;
42 $commands{$2} = 1;
43 }
44 close F;
45 }
46
47 @ARGV = sort keys %commands;
48
49 if ($opt eq '-H') {
50 print <<"EOF";
51 /*
52 * WARNING: do not edit!
53 * Generated by apps/progs.pl
54 *
55 * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
56 *
57 * Licensed under the Apache License 2.0 (the "License"). You may not use
58 * this file except in compliance with the License. You can obtain a copy
59 * in the file LICENSE in the source distribution or at
60 * https://www.openssl.org/source/license.html
61 */
62
63 #include "function.h"
64
65 EOF
66
67 foreach (@ARGV) {
68 printf "extern int %s_main(int argc, char *argv[]);\n", $_;
69 }
70 print "\n";
71
72 foreach (@ARGV) {
73 printf "extern const OPTIONS %s_options[];\n", $_;
74 }
75 print "\n";
76 print "extern FUNCTION functions[];\n";
77 }
78
79 if ($opt eq '-C') {
80 print <<"EOF";
81 /*
82 * WARNING: do not edit!
83 * Generated by apps/progs.pl
84 *
85 * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
86 *
87 * Licensed under the Apache License 2.0 (the "License"). You may not use
88 * this file except in compliance with the License. You can obtain a copy
89 * in the file LICENSE in the source distribution or at
90 * https://www.openssl.org/source/license.html
91 */
92
93 #include "progs.h"
94
95 EOF
96
97 my %cmd_disabler = (
98 ciphers => "sock",
99 gendsa => "dsa",
100 dsaparam => "dsa",
101 gendh => "dh",
102 dhparam => "dh",
103 ecparam => "ec",
104 );
105 my %cmd_deprecated = (
106 # The format of this table is:
107 # [0] = alternative command to use instead
108 # [1] = deprecented in this version
109 # [2] = preprocessor conditional for excluding irrespective of deprecation
110 # rsa => [ "pkey", "3_0", "rsa" ],
111 # genrsa => [ "genpkey", "3_0", "rsa" ],
112 rsautl => [ "pkeyutl", "3_0", "" ],
113 # dhparam => [ "pkeyparam", "3_0", "dh" ],
114 # dsaparam => [ "pkeyparam", "3_0", "dsa" ],
115 # dsa => [ "pkey", "3_0", "dsa" ],
116 # gendsa => [ "genpkey", "3_0", "dsa" ],
117 # ec => [ "pkey", "3_0", "ec" ],
118 # ecparam => [ "pkeyparam", "3_0", "ec" ],
119 );
120
121 print "FUNCTION functions[] = {\n";
122 foreach my $cmd ( @ARGV ) {
123 my $str =
124 " {FT_general, \"$cmd\", ${cmd}_main, ${cmd}_options, NULL, NULL},\n";
125 if ($cmd =~ /^s_/) {
126 print "#ifndef OPENSSL_NO_SOCK\n${str}#endif\n";
127 } elsif (my $deprecated = $cmd_deprecated{$cmd}) {
128 my @dep = @{$deprecated};
129 my $daltprg = $dep[0];
130 my $dver = $dep[1];
131 my $dsys = $dep[2];
132 print "#if !defined(OPENSSL_NO_DEPRECATED_" . $dver . ")";
133 if ($dsys) {
134 print " && !defined(OPENSSL_NO_" . uc($dsys) . ")";
135 }
136 $dver =~ s/_/./g;
137 my $dalt = "\"" . $daltprg . "\", \"" . $dver . "\"";
138 $str =~ s/NULL, NULL/$dalt/;
139 print "\n${str}#endif\n";
140 } elsif (grep { $cmd eq $_ } @disablables) {
141 print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
142 } elsif (my $disabler = $cmd_disabler{$cmd}) {
143 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
144 } else {
145 print $str;
146 }
147 }
148
149 my %md_disabler = (
150 blake2b512 => "blake2",
151 blake2s256 => "blake2",
152 );
153 foreach my $cmd (
154 "md2", "md4", "md5",
155 "sha1", "sha224", "sha256", "sha384",
156 "sha512", "sha512-224", "sha512-256",
157 "sha3-224", "sha3-256", "sha3-384", "sha3-512",
158 "shake128", "shake256",
159 "mdc2", "rmd160", "blake2b512", "blake2s256",
160 "sm3"
161 ) {
162 my $str = " {FT_md, \"$cmd\", dgst_main, NULL, NULL},\n";
163 if (grep { $cmd eq $_ } @disablables) {
164 print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
165 } elsif (my $disabler = $md_disabler{$cmd}) {
166 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
167 } else {
168 print $str;
169 }
170 }
171
172 my %cipher_disabler = (
173 des3 => "des",
174 desx => "des",
175 cast5 => "cast",
176 );
177 foreach my $cmd (
178 "aes-128-cbc", "aes-128-ecb",
179 "aes-192-cbc", "aes-192-ecb",
180 "aes-256-cbc", "aes-256-ecb",
181 "aria-128-cbc", "aria-128-cfb",
182 "aria-128-ctr", "aria-128-ecb", "aria-128-ofb",
183 "aria-128-cfb1", "aria-128-cfb8",
184 "aria-192-cbc", "aria-192-cfb",
185 "aria-192-ctr", "aria-192-ecb", "aria-192-ofb",
186 "aria-192-cfb1", "aria-192-cfb8",
187 "aria-256-cbc", "aria-256-cfb",
188 "aria-256-ctr", "aria-256-ecb", "aria-256-ofb",
189 "aria-256-cfb1", "aria-256-cfb8",
190 "camellia-128-cbc", "camellia-128-ecb",
191 "camellia-192-cbc", "camellia-192-ecb",
192 "camellia-256-cbc", "camellia-256-ecb",
193 "base64", "zlib", "brotli", "zstd",
194 "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
195 "rc2", "bf", "cast", "rc5",
196 "des-ecb", "des-ede", "des-ede3",
197 "des-cbc", "des-ede-cbc","des-ede3-cbc",
198 "des-cfb", "des-ede-cfb","des-ede3-cfb",
199 "des-ofb", "des-ede-ofb","des-ede3-ofb",
200 "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
201 "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
202 "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
203 "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
204 "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
205 "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb",
206 "sm4-cbc", "sm4-ecb", "sm4-cfb", "sm4-ofb", "sm4-ctr"
207 ) {
208 my $str = " {FT_cipher, \"$cmd\", enc_main, enc_options, NULL},\n";
209 (my $algo = $cmd) =~ s/-.*//g;
210 if (grep { $algo eq $_ } @disablables) {
211 print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
212 } elsif (my $disabler = $cipher_disabler{$algo}) {
213 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
214 } else {
215 print $str;
216 }
217 }
218
219 print " {0, NULL, NULL, NULL, NULL}\n};\n";
220 }