Fix grammar in srp_verifier.txt
[openssl.git] / apps / progs.pl
1 #! /usr/bin/env perl
2 # Copyright 1995-2020 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
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 $opt          = shift @ARGV;
18 die "Unrecognised option, must be -C or -H\n"
19     unless ($opt eq '-H' || $opt eq '-C');
20
21 my %commands     = ();
22 my $cmdre        = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
23 my $apps_openssl = shift @ARGV;
24 my $YEAR         = [localtime()]->[5] + 1900;
25
26 # because the program apps/openssl has object files as sources, and
27 # they then have the corresponding C files as source, we need to chain
28 # the lookups in %unified_info
29 my @openssl_source =
30     map { @{$unified_info{sources}->{$_}} }
31     grep { /\.o$/ }
32         @{$unified_info{sources}->{$apps_openssl}};
33
34 foreach my $filename (@openssl_source) {
35     open F, $filename or die "Couldn't open $filename: $!\n";
36     foreach ( grep /$cmdre/, <F> ) {
37         my @foo = /$cmdre/;
38         $commands{$1} = 1;
39     }
40     close F;
41 }
42
43 @ARGV = sort keys %commands;
44
45 if ($opt eq '-H') {
46     print <<"EOF";
47 /*
48  * WARNING: do not edit!
49  * Generated by apps/progs.pl
50  *
51  * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
52  *
53  * Licensed under the Apache License 2.0 (the "License").  You may not use
54  * this file except in compliance with the License.  You can obtain a copy
55  * in the file LICENSE in the source distribution or at
56  * https://www.openssl.org/source/license.html
57  */
58
59 #include "function.h"
60
61 EOF
62
63     foreach (@ARGV) {
64         printf "extern int %s_main(int argc, char *argv[]);\n", $_;
65     }
66     print "\n";
67
68     foreach (@ARGV) {
69         printf "extern const OPTIONS %s_options[];\n", $_;
70     }
71     print "\n";
72     print "extern FUNCTION functions[];\n";
73 }
74
75 if ($opt eq '-C') {
76     print <<"EOF";
77 /*
78  * WARNING: do not edit!
79  * Generated by apps/progs.pl
80  *
81  * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
82  *
83  * Licensed under the Apache License 2.0 (the "License").  You may not use
84  * this file except in compliance with the License.  You can obtain a copy
85  * in the file LICENSE in the source distribution or at
86  * https://www.openssl.org/source/license.html
87  */
88
89 #include "progs.h"
90
91 EOF
92
93     my %cmd_disabler = (
94         ciphers  => "sock",
95         genrsa   => "rsa",
96         gendsa   => "dsa",
97         dsaparam => "dsa",
98         gendh    => "dh",
99         dhparam  => "dh",
100         ecparam  => "ec",
101         pkcs12   => "des",
102     );
103     my %cmd_deprecated = (
104 # The format of this table is:
105 #   [0] = alternative command to use instead
106 #   [1] = deprecented in this version
107 #   [2] = preprocessor conditional for exclusing irrespective of deprecation
108 #        rsa      => [ "pkey",      "3_0", "rsa" ],
109 #        genrsa   => [ "genpkey",   "3_0", "rsa" ],
110         rsautl   => [ "pkeyutl",   "3_0", "rsa" ],
111 #        dhparam  => [ "pkeyparam", "3_0", "dh"  ],
112 #        dsaparam => [ "pkeyparam", "3_0", "dsa" ],
113 #        dsa      => [ "pkey",      "3_0", "dsa" ],
114 #        gendsa   => [ "genpkey",   "3_0", "dsa" ],
115 #        ec       => [ "pkey",      "3_0", "ec"  ],
116 #        ecparam  => [ "pkeyparam", "3_0", "ec"  ],
117     );
118
119     print "FUNCTION functions[] = {\n";
120     foreach my $cmd ( @ARGV ) {
121         my $str =
122             "    {FT_general, \"$cmd\", ${cmd}_main, ${cmd}_options, NULL, NULL},\n";
123         if ($cmd =~ /^s_/) {
124             print "#ifndef OPENSSL_NO_SOCK\n${str}#endif\n";
125         } elsif (my $deprecated = $cmd_deprecated{$cmd}) {
126             my @dep = @{$deprecated};
127             my $daltprg = $dep[0];
128             my $dver = $dep[1];
129             my $dsys = $dep[2];
130             print "#if !defined(OPENSSL_NO_DEPRECATED_" . $dver . ")";
131             if ($dsys) {
132                 print " && !defined(OPENSSL_NO_" . uc($dsys) . ")";
133             }
134             $dver =~ s/_/./g;
135             my $dalt = "\"" . $daltprg . "\", \"" . $dver . "\"";
136             $str =~ s/NULL, NULL/$dalt/;
137             print "\n${str}#endif\n";
138         } elsif (grep { $cmd eq $_ } @disablables) {
139             print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
140         } elsif (my $disabler = $cmd_disabler{$cmd}) {
141             print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
142         } else {
143             print $str;
144         }
145     }
146
147     my %md_disabler = (
148         blake2b512 => "blake2",
149         blake2s256 => "blake2",
150     );
151     foreach my $cmd (
152         "md2", "md4", "md5",
153         "gost",
154         "sha1", "sha224", "sha256", "sha384",
155         "sha512", "sha512-224", "sha512-256",
156         "sha3-224", "sha3-256", "sha3-384", "sha3-512",
157         "shake128", "shake256",
158         "mdc2", "rmd160", "blake2b512", "blake2s256",
159         "sm3"
160     ) {
161         my $str = "    {FT_md, \"$cmd\", dgst_main, NULL, NULL},\n";
162         if (grep { $cmd eq $_ } @disablables) {
163             print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
164         } elsif (my $disabler = $md_disabler{$cmd}) {
165             print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
166         } else {
167             print $str;
168         }
169     }
170
171     my %cipher_disabler = (
172         des3  => "des",
173         desx  => "des",
174         cast5 => "cast",
175     );
176     foreach my $cmd (
177         "aes-128-cbc", "aes-128-ecb",
178         "aes-192-cbc", "aes-192-ecb",
179         "aes-256-cbc", "aes-256-ecb",
180         "aria-128-cbc", "aria-128-cfb",
181         "aria-128-ctr", "aria-128-ecb", "aria-128-ofb",
182         "aria-128-cfb1", "aria-128-cfb8",
183         "aria-192-cbc", "aria-192-cfb",
184         "aria-192-ctr", "aria-192-ecb", "aria-192-ofb",
185         "aria-192-cfb1", "aria-192-cfb8",
186         "aria-256-cbc", "aria-256-cfb",
187         "aria-256-ctr", "aria-256-ecb", "aria-256-ofb",
188         "aria-256-cfb1", "aria-256-cfb8",
189         "camellia-128-cbc", "camellia-128-ecb",
190         "camellia-192-cbc", "camellia-192-ecb",
191         "camellia-256-cbc", "camellia-256-ecb",
192         "base64", "zlib",
193         "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
194         "rc2", "bf", "cast", "rc5",
195         "des-ecb", "des-ede", "des-ede3",
196         "des-cbc", "des-ede-cbc","des-ede3-cbc",
197         "des-cfb", "des-ede-cfb","des-ede3-cfb",
198         "des-ofb", "des-ede-ofb","des-ede3-ofb",
199         "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
200         "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
201         "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
202         "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
203         "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
204         "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb",
205         "sm4-cbc", "sm4-ecb", "sm4-cfb", "sm4-ofb", "sm4-ctr"
206     ) {
207         my $str = "    {FT_cipher, \"$cmd\", enc_main, enc_options, NULL},\n";
208         (my $algo = $cmd) =~ s/-.*//g;
209         if ($cmd eq "zlib") {
210             print "#ifdef ZLIB\n${str}#endif\n";
211         } elsif (grep { $algo eq $_ } @disablables) {
212             print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
213         } elsif (my $disabler = $cipher_disabler{$algo}) {
214             print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
215         } else {
216             print $str;
217         }
218     }
219
220     print "    {0, NULL, NULL, NULL, NULL}\n};\n";
221 }