progs.pl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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", "sha512",
  99. "mdc2", "rmd160", "blake2b512", "blake2s256",
  100. "sm3"
  101. ) {
  102. my $str = " {FT_md, \"$cmd\", dgst_main},\n";
  103. if (grep { $cmd eq $_ } @disablables) {
  104. print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
  105. } elsif (my $disabler = $md_disabler{$cmd}) {
  106. print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
  107. } else {
  108. print $str;
  109. }
  110. }
  111. my %cipher_disabler = (
  112. des3 => "des",
  113. desx => "des",
  114. cast5 => "cast",
  115. );
  116. foreach my $cmd (
  117. "aes-128-cbc", "aes-128-ecb",
  118. "aes-192-cbc", "aes-192-ecb",
  119. "aes-256-cbc", "aes-256-ecb",
  120. "aria-128-cbc", "aria-128-cfb",
  121. "aria-128-ctr", "aria-128-ecb", "aria-128-ofb",
  122. "aria-128-cfb1", "aria-128-cfb8",
  123. "aria-192-cbc", "aria-192-cfb",
  124. "aria-192-ctr", "aria-192-ecb", "aria-192-ofb",
  125. "aria-192-cfb1", "aria-192-cfb8",
  126. "aria-256-cbc", "aria-256-cfb",
  127. "aria-256-ctr", "aria-256-ecb", "aria-256-ofb",
  128. "aria-256-cfb1", "aria-256-cfb8",
  129. "camellia-128-cbc", "camellia-128-ecb",
  130. "camellia-192-cbc", "camellia-192-ecb",
  131. "camellia-256-cbc", "camellia-256-ecb",
  132. "base64", "zlib",
  133. "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
  134. "rc2", "bf", "cast", "rc5",
  135. "des-ecb", "des-ede", "des-ede3",
  136. "des-cbc", "des-ede-cbc","des-ede3-cbc",
  137. "des-cfb", "des-ede-cfb","des-ede3-cfb",
  138. "des-ofb", "des-ede-ofb","des-ede3-ofb",
  139. "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
  140. "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
  141. "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
  142. "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
  143. "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
  144. "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb",
  145. "sm4-cbc", "sm4-ecb", "sm4-cfb", "sm4-ofb", "sm4-ctr"
  146. ) {
  147. my $str = " {FT_cipher, \"$cmd\", enc_main, enc_options},\n";
  148. (my $algo = $cmd) =~ s/-.*//g;
  149. if ($cmd eq "zlib") {
  150. print "#ifdef ZLIB\n${str}#endif\n";
  151. } elsif (grep { $algo eq $_ } @disablables) {
  152. print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
  153. } elsif (my $disabler = $cipher_disabler{$algo}) {
  154. print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
  155. } else {
  156. print $str;
  157. }
  158. }
  159. print " {0, NULL, NULL}\n};\n";
  160. print "#endif\n";