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