progs.pl 4.7 KB

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