progs.pl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #! /usr/bin/env perl
  2. # Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (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 %commands = ();
  15. my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
  16. my $apps_openssl = shift @ARGV;
  17. my $YEAR = [localtime()]->[5] + 1900;
  18. # because the program apps/openssl has object files as sources, and
  19. # they then have the corresponding C files as source, we need to chain
  20. # the lookups in %unified_info
  21. my @openssl_source =
  22. map { @{$unified_info{sources}->{$_}} }
  23. grep { /\.o$/ }
  24. @{$unified_info{sources}->{$apps_openssl}};
  25. foreach my $filename (@openssl_source) {
  26. open F, $filename or die "Couldn't open $filename: $!\n";
  27. foreach ( grep /$cmdre/, <F> ) {
  28. my @foo = /$cmdre/;
  29. $commands{$1} = 1;
  30. }
  31. close F;
  32. }
  33. @ARGV = sort keys %commands;
  34. print <<"EOF";
  35. /*
  36. * WARNING: do not edit!
  37. * Generated by apps/progs.pl
  38. *
  39. * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
  40. *
  41. * Licensed under the OpenSSL license (the "License"). You may not use
  42. * this file except in compliance with the License. You can obtain a copy
  43. * in the file LICENSE in the source distribution or at
  44. * https://www.openssl.org/source/license.html
  45. */
  46. typedef enum FUNC_TYPE {
  47. FT_none, FT_general, FT_md, FT_cipher, FT_pkey,
  48. FT_md_alg, FT_cipher_alg
  49. } FUNC_TYPE;
  50. typedef struct function_st {
  51. FUNC_TYPE type;
  52. const char *name;
  53. int (*func)(int argc, char *argv[]);
  54. const OPTIONS *help;
  55. } FUNCTION;
  56. DEFINE_LHASH_OF(FUNCTION);
  57. EOF
  58. foreach (@ARGV) {
  59. printf "extern int %s_main(int argc, char *argv[]);\n", $_;
  60. }
  61. print "\n";
  62. foreach (@ARGV) {
  63. printf "extern const OPTIONS %s_options[];\n", $_;
  64. }
  65. print "\n";
  66. my %cmd_disabler = (
  67. ciphers => "sock",
  68. genrsa => "rsa",
  69. rsautl => "rsa",
  70. gendsa => "dsa",
  71. dsaparam => "dsa",
  72. gendh => "dh",
  73. dhparam => "dh",
  74. ecparam => "ec",
  75. pkcs12 => "des",
  76. );
  77. print "#ifdef INCLUDE_FUNCTION_TABLE\n";
  78. print "static FUNCTION functions[] = {\n";
  79. foreach my $cmd ( @ARGV ) {
  80. my $str = " {FT_general, \"$cmd\", ${cmd}_main, ${cmd}_options},\n";
  81. if ($cmd =~ /^s_/) {
  82. print "#ifndef OPENSSL_NO_SOCK\n${str}#endif\n";
  83. } elsif (grep { $cmd eq $_ } @disablables) {
  84. print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
  85. } elsif (my $disabler = $cmd_disabler{$cmd}) {
  86. print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
  87. } else {
  88. print $str;
  89. }
  90. }
  91. my %md_disabler = (
  92. blake2b512 => "blake2",
  93. blake2s256 => "blake2",
  94. );
  95. foreach my $cmd (
  96. "md2", "md4", "md5",
  97. "gost",
  98. "sha1", "sha224", "sha256", "sha384",
  99. "sha512", "sha512-224", "sha512-256",
  100. "sha3-224", "sha3-256", "sha3-384", "sha3-512",
  101. "shake128", "shake256",
  102. "mdc2", "rmd160", "blake2b512", "blake2s256",
  103. "sm3"
  104. ) {
  105. my $str = " {FT_md, \"$cmd\", dgst_main},\n";
  106. if (grep { $cmd eq $_ } @disablables) {
  107. print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
  108. } elsif (my $disabler = $md_disabler{$cmd}) {
  109. print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
  110. } else {
  111. print $str;
  112. }
  113. }
  114. my %cipher_disabler = (
  115. des3 => "des",
  116. desx => "des",
  117. cast5 => "cast",
  118. );
  119. foreach my $cmd (
  120. "aes-128-cbc", "aes-128-ecb",
  121. "aes-192-cbc", "aes-192-ecb",
  122. "aes-256-cbc", "aes-256-ecb",
  123. "aria-128-cbc", "aria-128-cfb",
  124. "aria-128-ctr", "aria-128-ecb", "aria-128-ofb",
  125. "aria-128-cfb1", "aria-128-cfb8",
  126. "aria-192-cbc", "aria-192-cfb",
  127. "aria-192-ctr", "aria-192-ecb", "aria-192-ofb",
  128. "aria-192-cfb1", "aria-192-cfb8",
  129. "aria-256-cbc", "aria-256-cfb",
  130. "aria-256-ctr", "aria-256-ecb", "aria-256-ofb",
  131. "aria-256-cfb1", "aria-256-cfb8",
  132. "camellia-128-cbc", "camellia-128-ecb",
  133. "camellia-192-cbc", "camellia-192-ecb",
  134. "camellia-256-cbc", "camellia-256-ecb",
  135. "base64", "zlib",
  136. "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
  137. "rc2", "bf", "cast", "rc5",
  138. "des-ecb", "des-ede", "des-ede3",
  139. "des-cbc", "des-ede-cbc","des-ede3-cbc",
  140. "des-cfb", "des-ede-cfb","des-ede3-cfb",
  141. "des-ofb", "des-ede-ofb","des-ede3-ofb",
  142. "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
  143. "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
  144. "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
  145. "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
  146. "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
  147. "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb",
  148. "sm4-cbc", "sm4-ecb", "sm4-cfb", "sm4-ofb", "sm4-ctr"
  149. ) {
  150. my $str = " {FT_cipher, \"$cmd\", enc_main, enc_options},\n";
  151. (my $algo = $cmd) =~ s/-.*//g;
  152. if ($cmd eq "zlib") {
  153. print "#ifdef ZLIB\n${str}#endif\n";
  154. } elsif (grep { $algo eq $_ } @disablables) {
  155. print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
  156. } elsif (my $disabler = $cipher_disabler{$algo}) {
  157. print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
  158. } else {
  159. print $str;
  160. }
  161. }
  162. print " {0, NULL, NULL}\n};\n";
  163. print "#endif\n";