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