progs.pl 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #! /usr/bin/env perl
  2. # Copyright 1995-2020 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 = [localtime()]->[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{sources}->{$apps_openssl}};
  28. foreach my $filename (@openssl_source) {
  29. open F, $filename or die "Couldn't open $filename: $!\n";
  30. foreach ( grep /$cmdre/, <F> ) {
  31. my @foo = /$cmdre/;
  32. $commands{$1} = 1;
  33. }
  34. close F;
  35. }
  36. @ARGV = sort keys %commands;
  37. if ($opt eq '-H') {
  38. print <<"EOF";
  39. /*
  40. * WARNING: do not edit!
  41. * Generated by apps/progs.pl
  42. *
  43. * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
  44. *
  45. * Licensed under the Apache License 2.0 (the "License"). You may not use
  46. * this file except in compliance with the License. You can obtain a copy
  47. * in the file LICENSE in the source distribution or at
  48. * https://www.openssl.org/source/license.html
  49. */
  50. #include "function.h"
  51. EOF
  52. foreach (@ARGV) {
  53. printf "extern int %s_main(int argc, char *argv[]);\n", $_;
  54. }
  55. print "\n";
  56. foreach (@ARGV) {
  57. printf "extern const OPTIONS %s_options[];\n", $_;
  58. }
  59. print "\n";
  60. print "extern FUNCTION functions[];\n";
  61. }
  62. if ($opt eq '-C') {
  63. print <<"EOF";
  64. /*
  65. * WARNING: do not edit!
  66. * Generated by apps/progs.pl
  67. *
  68. * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
  69. *
  70. * Licensed under the Apache License 2.0 (the "License"). You may not use
  71. * this file except in compliance with the License. You can obtain a copy
  72. * in the file LICENSE in the source distribution or at
  73. * https://www.openssl.org/source/license.html
  74. */
  75. #include "progs.h"
  76. EOF
  77. my %cmd_disabler = (
  78. ciphers => "sock",
  79. genrsa => "rsa",
  80. gendsa => "dsa",
  81. dsaparam => "dsa",
  82. gendh => "dh",
  83. dhparam => "dh",
  84. ecparam => "ec",
  85. pkcs12 => "des",
  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 exclusing 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. "gost",
  136. "sha1", "sha224", "sha256", "sha384",
  137. "sha512", "sha512-224", "sha512-256",
  138. "sha3-224", "sha3-256", "sha3-384", "sha3-512",
  139. "shake128", "shake256",
  140. "mdc2", "rmd160", "blake2b512", "blake2s256",
  141. "sm3"
  142. ) {
  143. my $str = " {FT_md, \"$cmd\", dgst_main, NULL, NULL},\n";
  144. if (grep { $cmd eq $_ } @disablables) {
  145. print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
  146. } elsif (my $disabler = $md_disabler{$cmd}) {
  147. print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
  148. } else {
  149. print $str;
  150. }
  151. }
  152. my %cipher_disabler = (
  153. des3 => "des",
  154. desx => "des",
  155. cast5 => "cast",
  156. );
  157. foreach my $cmd (
  158. "aes-128-cbc", "aes-128-ecb",
  159. "aes-192-cbc", "aes-192-ecb",
  160. "aes-256-cbc", "aes-256-ecb",
  161. "aria-128-cbc", "aria-128-cfb",
  162. "aria-128-ctr", "aria-128-ecb", "aria-128-ofb",
  163. "aria-128-cfb1", "aria-128-cfb8",
  164. "aria-192-cbc", "aria-192-cfb",
  165. "aria-192-ctr", "aria-192-ecb", "aria-192-ofb",
  166. "aria-192-cfb1", "aria-192-cfb8",
  167. "aria-256-cbc", "aria-256-cfb",
  168. "aria-256-ctr", "aria-256-ecb", "aria-256-ofb",
  169. "aria-256-cfb1", "aria-256-cfb8",
  170. "camellia-128-cbc", "camellia-128-ecb",
  171. "camellia-192-cbc", "camellia-192-ecb",
  172. "camellia-256-cbc", "camellia-256-ecb",
  173. "base64", "zlib",
  174. "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
  175. "rc2", "bf", "cast", "rc5",
  176. "des-ecb", "des-ede", "des-ede3",
  177. "des-cbc", "des-ede-cbc","des-ede3-cbc",
  178. "des-cfb", "des-ede-cfb","des-ede3-cfb",
  179. "des-ofb", "des-ede-ofb","des-ede3-ofb",
  180. "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
  181. "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
  182. "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
  183. "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
  184. "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
  185. "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb",
  186. "sm4-cbc", "sm4-ecb", "sm4-cfb", "sm4-ofb", "sm4-ctr"
  187. ) {
  188. my $str = " {FT_cipher, \"$cmd\", enc_main, enc_options, NULL},\n";
  189. (my $algo = $cmd) =~ s/-.*//g;
  190. if ($cmd eq "zlib") {
  191. print "#ifdef ZLIB\n${str}#endif\n";
  192. } elsif (grep { $algo eq $_ } @disablables) {
  193. print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
  194. } elsif (my $disabler = $cipher_disabler{$algo}) {
  195. print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
  196. } else {
  197. print $str;
  198. }
  199. }
  200. print " {0, NULL, NULL, NULL, NULL}\n};\n";
  201. }