progs.pl 7.4 KB

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