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