]> git.ipfire.org Git - thirdparty/openssl.git/blob - apps/progs.pl
Fix no-gost
[thirdparty/openssl.git] / apps / progs.pl
1 #!/usr/bin/perl
2
3 # Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
4 #
5 # Licensed under the OpenSSL licenses, (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 # https://www.openssl.org/source/license.html
9 # or in the file LICENSE in the source distribution.
10
11 # Generate progs.h file by looking for command mains in list of C files
12 # passed on the command line.
13
14 use strict;
15 use warnings;
16 use configdata qw/@disablables/;
17
18 my %commands = ();
19 my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
20
21 foreach my $filename (@ARGV) {
22 open F, $filename or die "Coudn't open $_: $!\n";
23 foreach (grep /$cmdre/, <F>) {
24 my @foo = /$cmdre/;
25 $commands{$1} = 1;
26 }
27 close F;
28 }
29
30 @ARGV = sort keys %commands;
31
32 print <<'EOF';
33 /*
34 * Automatically generated by progs.pl for openssl.c
35 * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
36 *
37 * Licensed under the OpenSSL licenses, (the "License");
38 * you may not use this file except in compliance with the License.
39 * You may obtain a copy of the License at
40 * https://www.openssl.org/source/license.html
41 * or in the file LICENSE in the source distribution.
42 */
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
49 typedef struct function_st {
50 FUNC_TYPE type;
51 const char *name;
52 int (*func)(int argc,char *argv[]);
53 const OPTIONS *help;
54 } FUNCTION;
55
56 DEFINE_LHASH_OF(FUNCTION);
57
58 EOF
59
60 foreach (@ARGV) {
61 printf "extern int %s_main(int argc, char *argv[]);\n", $_;
62 }
63
64 print "\n";
65
66 foreach (@ARGV) {
67 printf "extern OPTIONS %s_options[];\n", $_;
68 }
69
70 print "\n#ifdef INCLUDE_FUNCTION_TABLE\n";
71 print "static FUNCTION functions[] = {\n";
72 my %cmd_disabler = (
73 ciphers => "sock",
74 genrsa => "rsa",
75 rsautl => "rsa",
76 gendsa => "dsa",
77 dsaparam => "dsa",
78 gendh => "dh",
79 dhparam => "dh",
80 ecparam => "ec",
81 pkcs12 => "des",
82 );
83 foreach my $cmd (@ARGV) {
84 my $str=" { FT_general, \"$cmd\", ${cmd}_main, ${cmd}_options },\n";
85 if ($cmd =~ /^s_/) {
86 print "#ifndef OPENSSL_NO_SOCK\n${str}#endif\n";
87 } elsif (grep { $cmd eq $_ } @disablables) {
88 print "#ifndef OPENSSL_NO_".uc($cmd)."\n${str}#endif\n";
89 } elsif (my $disabler = $cmd_disabler{$cmd}) {
90 print "#ifndef OPENSSL_NO_".uc($disabler)."\n${str}#endif\n";
91 } else {
92 print $str;
93 }
94 }
95
96 my %md_disabler = (
97 sha1 => "sha",
98 sha224 => "sha",
99 sha256 => "sha",
100 sha384 => "sha",
101 sha512 => "sha",
102 blake2b512 => "blake2",
103 blake2s256 => "blake2",
104 );
105 foreach my $cmd (
106 "md2", "md4", "md5",
107 "gost",
108 "sha1", "sha224", "sha256", "sha384", "sha512",
109 "mdc2", "rmd160", "blake2b512", "blake2s256"
110 ) {
111 my $str = " { FT_md, \"".$cmd."\", dgst_main},\n";
112 if (grep { $cmd eq $_ } @disablables) {
113 print "#ifndef OPENSSL_NO_".uc($cmd)."\n${str}#endif\n";
114 } elsif (my $disabler = $md_disabler{$cmd}) {
115 print "#ifndef OPENSSL_NO_".uc($disabler)."\n${str}#endif\n";
116 } else {
117 print "#ifndef OPENSSL_NO_".uc($cmd)."\n${str}#endif\n";
118 }
119 }
120
121 my %cipher_disabler = (
122 des3 => "des",
123 desx => "des",
124 cast5 => "cast",
125 );
126 foreach my $cmd (
127 "aes-128-cbc", "aes-128-ecb",
128 "aes-192-cbc", "aes-192-ecb",
129 "aes-256-cbc", "aes-256-ecb",
130 "camellia-128-cbc", "camellia-128-ecb",
131 "camellia-192-cbc", "camellia-192-ecb",
132 "camellia-256-cbc", "camellia-256-ecb",
133 "base64", "zlib",
134 "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
135 "rc2", "bf", "cast", "rc5",
136 "des-ecb", "des-ede", "des-ede3",
137 "des-cbc", "des-ede-cbc","des-ede3-cbc",
138 "des-cfb", "des-ede-cfb","des-ede3-cfb",
139 "des-ofb", "des-ede-ofb","des-ede3-ofb",
140 "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
141 "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
142 "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
143 "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
144 "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
145 "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb"
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
160 print " { 0, NULL, NULL}\n};\n";
161 print "#endif\n";