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