progs.pl 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #! /usr/bin/env perl
  2. # Copyright 1995-2018 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 %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 Apache License 2.0 (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. #include <openssl/lhash.h>
  47. #include "opt.h"
  48. typedef enum FUNC_TYPE {
  49. FT_none, FT_general, FT_md, FT_cipher, FT_pkey,
  50. FT_md_alg, FT_cipher_alg
  51. } FUNC_TYPE;
  52. typedef struct function_st {
  53. FUNC_TYPE type;
  54. const char *name;
  55. int (*func)(int argc, char *argv[]);
  56. const OPTIONS *help;
  57. } FUNCTION;
  58. DEFINE_LHASH_OF(FUNCTION);
  59. EOF
  60. foreach (@ARGV) {
  61. printf "extern int %s_main(int argc, char *argv[]);\n", $_;
  62. }
  63. print "\n";
  64. foreach (@ARGV) {
  65. printf "extern const OPTIONS %s_options[];\n", $_;
  66. }
  67. print "\n";
  68. my %cmd_disabler = (
  69. ciphers => "sock",
  70. genrsa => "rsa",
  71. rsautl => "rsa",
  72. gendsa => "dsa",
  73. dsaparam => "dsa",
  74. gendh => "dh",
  75. dhparam => "dh",
  76. ecparam => "ec",
  77. pkcs12 => "des",
  78. );
  79. print "#ifdef INCLUDE_FUNCTION_TABLE\n";
  80. print "static FUNCTION functions[] = {\n";
  81. foreach my $cmd ( @ARGV ) {
  82. my $str = " {FT_general, \"$cmd\", ${cmd}_main, ${cmd}_options},\n";
  83. if ($cmd =~ /^s_/) {
  84. print "#ifndef OPENSSL_NO_SOCK\n${str}#endif\n";
  85. } elsif (grep { $cmd eq $_ } @disablables) {
  86. print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
  87. } elsif (my $disabler = $cmd_disabler{$cmd}) {
  88. print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
  89. } else {
  90. print $str;
  91. }
  92. }
  93. my %md_disabler = (
  94. blake2b512 => "blake2",
  95. blake2s256 => "blake2",
  96. );
  97. foreach my $cmd (
  98. "md2", "md4", "md5",
  99. "gost",
  100. "sha1", "sha224", "sha256", "sha384",
  101. "sha512", "sha512-224", "sha512-256",
  102. "sha3-224", "sha3-256", "sha3-384", "sha3-512",
  103. "shake128", "shake256",
  104. "mdc2", "rmd160", "blake2b512", "blake2s256",
  105. "sm3"
  106. ) {
  107. my $str = " {FT_md, \"$cmd\", dgst_main},\n";
  108. if (grep { $cmd eq $_ } @disablables) {
  109. print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
  110. } elsif (my $disabler = $md_disabler{$cmd}) {
  111. print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
  112. } else {
  113. print $str;
  114. }
  115. }
  116. my %cipher_disabler = (
  117. des3 => "des",
  118. desx => "des",
  119. cast5 => "cast",
  120. );
  121. foreach my $cmd (
  122. "aes-128-cbc", "aes-128-ecb",
  123. "aes-192-cbc", "aes-192-ecb",
  124. "aes-256-cbc", "aes-256-ecb",
  125. "aria-128-cbc", "aria-128-cfb",
  126. "aria-128-ctr", "aria-128-ecb", "aria-128-ofb",
  127. "aria-128-cfb1", "aria-128-cfb8",
  128. "aria-192-cbc", "aria-192-cfb",
  129. "aria-192-ctr", "aria-192-ecb", "aria-192-ofb",
  130. "aria-192-cfb1", "aria-192-cfb8",
  131. "aria-256-cbc", "aria-256-cfb",
  132. "aria-256-ctr", "aria-256-ecb", "aria-256-ofb",
  133. "aria-256-cfb1", "aria-256-cfb8",
  134. "camellia-128-cbc", "camellia-128-ecb",
  135. "camellia-192-cbc", "camellia-192-ecb",
  136. "camellia-256-cbc", "camellia-256-ecb",
  137. "base64", "zlib",
  138. "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
  139. "rc2", "bf", "cast", "rc5",
  140. "des-ecb", "des-ede", "des-ede3",
  141. "des-cbc", "des-ede-cbc","des-ede3-cbc",
  142. "des-cfb", "des-ede-cfb","des-ede3-cfb",
  143. "des-ofb", "des-ede-ofb","des-ede3-ofb",
  144. "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
  145. "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
  146. "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
  147. "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
  148. "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
  149. "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb",
  150. "sm4-cbc", "sm4-ecb", "sm4-cfb", "sm4-ofb", "sm4-ctr"
  151. ) {
  152. my $str = " {FT_cipher, \"$cmd\", enc_main, enc_options},\n";
  153. (my $algo = $cmd) =~ s/-.*//g;
  154. if ($cmd eq "zlib") {
  155. print "#ifdef ZLIB\n${str}#endif\n";
  156. } elsif (grep { $algo eq $_ } @disablables) {
  157. print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
  158. } elsif (my $disabler = $cipher_disabler{$algo}) {
  159. print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
  160. } else {
  161. print $str;
  162. }
  163. }
  164. print " {0, NULL, NULL}\n};\n";
  165. print "#endif\n";