Swap the check in ssl3_write_pending to avoid using
[openssl.git] / apps / progs.pl
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
9 # Generate progs.h file by looking for command mains in list of C files
10 # passed on the command line.
11
12 use strict;
13 use warnings;
14 use lib '.';
15 use configdata qw/@disablables %unified_info/;
16
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
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         @{$unified_info{sources}->{$apps_openssl}};
27
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
37 @ARGV = sort keys %commands;
38
39 print <<'EOF';
40 /*
41  * WARNING: do not edit!
42  * Generated by apps/progs.pl
43  *
44  * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
45  *
46  * Licensed under the OpenSSL license (the "License").  You may not use
47  * this file except in compliance with the License.  You can obtain a copy
48  * in the file LICENSE in the source distribution or at
49  * https://www.openssl.org/source/license.html
50  */
51
52 typedef enum FUNC_TYPE {
53     FT_none, FT_general, FT_md, FT_cipher, FT_pkey,
54     FT_md_alg, FT_cipher_alg
55 } FUNC_TYPE;
56
57 typedef struct function_st {
58     FUNC_TYPE type;
59     const char *name;
60     int (*func)(int argc, char *argv[]);
61     const OPTIONS *help;
62 } FUNCTION;
63
64 DEFINE_LHASH_OF(FUNCTION);
65
66 EOF
67
68 foreach (@ARGV) {
69     printf "extern int %s_main(int argc, char *argv[]);\n", $_;
70 }
71 print "\n";
72
73 foreach (@ARGV) {
74     printf "extern const OPTIONS %s_options[];\n", $_;
75 }
76 print "\n";
77
78 my %cmd_disabler = (
79     ciphers  => "sock",
80     genrsa   => "rsa",
81     rsautl   => "rsa",
82     gendsa   => "dsa",
83     dsaparam => "dsa",
84     gendh    => "dh",
85     dhparam  => "dh",
86     ecparam  => "ec",
87     pkcs12   => "des",
88 );
89
90 print "#ifdef INCLUDE_FUNCTION_TABLE\n";
91 print "static FUNCTION functions[] = {\n";
92 foreach my $cmd ( @ARGV ) {
93     my $str = "    {FT_general, \"$cmd\", ${cmd}_main, ${cmd}_options},\n";
94     if ($cmd =~ /^s_/) {
95         print "#ifndef OPENSSL_NO_SOCK\n${str}#endif\n";
96     } elsif (grep { $cmd eq $_ } @disablables) {
97         print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
98     } elsif (my $disabler = $cmd_disabler{$cmd}) {
99         print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
100     } else {
101         print $str;
102     }
103 }
104
105 my %md_disabler = (
106     blake2b512 => "blake2",
107     blake2s256 => "blake2",
108 );
109 foreach my $cmd (
110     "md2", "md4", "md5",
111     "gost",
112     "sha1", "sha224", "sha256", "sha384", "sha512",
113     "mdc2", "rmd160", "blake2b512", "blake2s256",
114     "sm3"
115 ) {
116     my $str = "    {FT_md, \"$cmd\", dgst_main},\n";
117     if (grep { $cmd eq $_ } @disablables) {
118         print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
119     } elsif (my $disabler = $md_disabler{$cmd}) {
120         print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
121     } else {
122         print $str;
123     }
124 }
125
126 my %cipher_disabler = (
127     des3  => "des",
128     desx  => "des",
129     cast5 => "cast",
130 );
131 foreach my $cmd (
132     "aes-128-cbc", "aes-128-ecb",
133     "aes-192-cbc", "aes-192-ecb",
134     "aes-256-cbc", "aes-256-ecb",
135     "aria-128-cbc", "aria-128-cfb",
136     "aria-128-ctr", "aria-128-ecb", "aria-128-ofb",
137     "aria-128-cfb1", "aria-128-cfb8",
138     "aria-192-cbc", "aria-192-cfb",
139     "aria-192-ctr", "aria-192-ecb", "aria-192-ofb",
140     "aria-192-cfb1", "aria-192-cfb8",
141     "aria-256-cbc", "aria-256-cfb",
142     "aria-256-ctr", "aria-256-ecb", "aria-256-ofb",
143     "aria-256-cfb1", "aria-256-cfb8",
144     "camellia-128-cbc", "camellia-128-ecb",
145     "camellia-192-cbc", "camellia-192-ecb",
146     "camellia-256-cbc", "camellia-256-ecb",
147     "base64", "zlib",
148     "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
149     "rc2", "bf", "cast", "rc5",
150     "des-ecb", "des-ede", "des-ede3",
151     "des-cbc", "des-ede-cbc","des-ede3-cbc",
152     "des-cfb", "des-ede-cfb","des-ede3-cfb",
153     "des-ofb", "des-ede-ofb","des-ede3-ofb",
154     "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
155     "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
156     "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
157     "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
158     "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
159     "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb",
160     "sm4-cbc", "sm4-ecb", "sm4-cfb", "sm4-ofb", "sm4-ctr"
161 ) {
162     my $str = "    {FT_cipher, \"$cmd\", enc_main, enc_options},\n";
163     (my $algo = $cmd) =~ s/-.*//g;
164     if ($cmd eq "zlib") {
165         print "#ifdef ZLIB\n${str}#endif\n";
166     } elsif (grep { $algo eq $_ } @disablables) {
167         print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
168     } elsif (my $disabler = $cipher_disabler{$algo}) {
169         print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
170     } else {
171         print $str;
172     }
173 }
174
175 print "    {0, NULL, NULL}\n};\n";
176 print "#endif\n";