]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/progs.pl
apps/dsaparam.c: fix -C output.
[thirdparty/openssl.git] / apps / progs.pl
CommitLineData
e0a65194 1#! /usr/bin/env perl
48e5119a 2# Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3850f8cb 3#
e0a65194
RS
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
3850f8cb 7# https://www.openssl.org/source/license.html
3850f8cb 8
fb3e2a88
RL
9# Generate progs.h file by looking for command mains in list of C files
10# passed on the command line.
11
12use strict;
13use warnings;
6a74806e
RL
14use lib '.';
15use configdata qw/@disablables %unified_info/;
fb3e2a88 16
aa74c2ec
RS
17my %commands = ();
18my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
6a74806e 19my $apps_openssl = shift @ARGV;
83900628 20my $YEAR = [localtime()]->[5] + 1900;
aa74c2ec 21
6a74806e
RL
22# because the program apps/openssl has object files as sources, and
23# they then have the corresponding C files as source, we need to chain
24# the lookups in %unified_info
25my @openssl_source =
26 map { @{$unified_info{sources}->{$_}} }
83900628 27 grep { /\.o$/ }
aa74c2ec 28 @{$unified_info{sources}->{$apps_openssl}};
6a74806e
RL
29
30foreach my $filename (@openssl_source) {
ab307dc6 31 open F, $filename or die "Couldn't open $filename: $!\n";
aa74c2ec
RS
32 foreach ( grep /$cmdre/, <F> ) {
33 my @foo = /$cmdre/;
34 $commands{$1} = 1;
35 }
36 close F;
fb3e2a88
RL
37}
38
39@ARGV = sort keys %commands;
d02b48c6 40
83900628 41print <<"EOF";
7e1b7485 42/*
e0a65194
RS
43 * WARNING: do not edit!
44 * Generated by apps/progs.pl
45 *
83900628 46 * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
3850f8cb 47 *
e0a65194
RS
48 * Licensed under the OpenSSL license (the "License"). You may not use
49 * this file except in compliance with the License. You can obtain a copy
50 * in the file LICENSE in the source distribution or at
3850f8cb 51 * https://www.openssl.org/source/license.html
7e1b7485 52 */
d02b48c6 53
7e1b7485
RS
54typedef enum FUNC_TYPE {
55 FT_none, FT_general, FT_md, FT_cipher, FT_pkey,
56 FT_md_alg, FT_cipher_alg
57} FUNC_TYPE;
d02b48c6 58
7e1b7485
RS
59typedef struct function_st {
60 FUNC_TYPE type;
474e469b 61 const char *name;
dc57696c 62 int (*func)(int argc, char *argv[]);
7e1b7485 63 const OPTIONS *help;
474e469b 64} FUNCTION;
d02b48c6 65
89d6aa10 66DEFINE_LHASH_OF(FUNCTION);
e6b5c341 67
d02b48c6
RE
68EOF
69
7e1b7485 70foreach (@ARGV) {
aa74c2ec 71 printf "extern int %s_main(int argc, char *argv[]);\n", $_;
7e1b7485 72}
df2ee0e2
BL
73print "\n";
74
7e1b7485 75foreach (@ARGV) {
aa74c2ec 76 printf "extern const OPTIONS %s_options[];\n", $_;
7e1b7485 77}
aa74c2ec 78print "\n";
3850f8cb
RL
79
80my %cmd_disabler = (
81 ciphers => "sock",
82 genrsa => "rsa",
83 rsautl => "rsa",
84 gendsa => "dsa",
85 dsaparam => "dsa",
86 gendh => "dh",
87 dhparam => "dh",
88 ecparam => "ec",
89 pkcs12 => "des",
aa74c2ec
RS
90);
91
92print "#ifdef INCLUDE_FUNCTION_TABLE\n";
93print "static FUNCTION functions[] = {\n";
94foreach my $cmd ( @ARGV ) {
95 my $str = " {FT_general, \"$cmd\", ${cmd}_main, ${cmd}_options},\n";
96 if ($cmd =~ /^s_/) {
97 print "#ifndef OPENSSL_NO_SOCK\n${str}#endif\n";
98 } elsif (grep { $cmd eq $_ } @disablables) {
99 print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
100 } elsif (my $disabler = $cmd_disabler{$cmd}) {
101 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
102 } else {
103 print $str;
104 }
7e1b7485 105}
d02b48c6 106
3850f8cb 107my %md_disabler = (
3850f8cb
RL
108 blake2b512 => "blake2",
109 blake2s256 => "blake2",
aa74c2ec 110);
3850f8cb 111foreach my $cmd (
6df34091
RT
112 "md2", "md4", "md5",
113 "gost",
bd982b48
RL
114 "sha1", "sha224", "sha256", "sha384",
115 "sha512", "sha512-224", "sha512-256",
116 "sha3-224", "sha3-256", "sha3-384", "sha3-512",
117 "shake128", "shake256",
6df34091
RT
118 "mdc2", "rmd160", "blake2b512", "blake2s256",
119 "sm3"
7e1b7485 120) {
aa74c2ec
RS
121 my $str = " {FT_md, \"$cmd\", dgst_main},\n";
122 if (grep { $cmd eq $_ } @disablables) {
123 print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
124 } elsif (my $disabler = $md_disabler{$cmd}) {
125 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
126 } else {
127 print $str;
128 }
7e1b7485 129}
d02b48c6 130
3850f8cb
RL
131my %cipher_disabler = (
132 des3 => "des",
133 desx => "des",
134 cast5 => "cast",
aa74c2ec 135);
3850f8cb 136foreach my $cmd (
aa74c2ec
RS
137 "aes-128-cbc", "aes-128-ecb",
138 "aes-192-cbc", "aes-192-ecb",
139 "aes-256-cbc", "aes-256-ecb",
140 "aria-128-cbc", "aria-128-cfb",
141 "aria-128-ctr", "aria-128-ecb", "aria-128-ofb",
142 "aria-128-cfb1", "aria-128-cfb8",
143 "aria-192-cbc", "aria-192-cfb",
144 "aria-192-ctr", "aria-192-ecb", "aria-192-ofb",
145 "aria-192-cfb1", "aria-192-cfb8",
146 "aria-256-cbc", "aria-256-cfb",
147 "aria-256-ctr", "aria-256-ecb", "aria-256-ofb",
148 "aria-256-cfb1", "aria-256-cfb8",
149 "camellia-128-cbc", "camellia-128-ecb",
150 "camellia-192-cbc", "camellia-192-ecb",
151 "camellia-256-cbc", "camellia-256-ecb",
152 "base64", "zlib",
153 "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
154 "rc2", "bf", "cast", "rc5",
155 "des-ecb", "des-ede", "des-ede3",
156 "des-cbc", "des-ede-cbc","des-ede3-cbc",
157 "des-cfb", "des-ede-cfb","des-ede3-cfb",
158 "des-ofb", "des-ede-ofb","des-ede3-ofb",
159 "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
160 "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
161 "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
162 "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
163 "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
6df34091
RT
164 "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb",
165 "sm4-cbc", "sm4-ecb", "sm4-cfb", "sm4-ofb", "sm4-ctr"
7e1b7485 166) {
aa74c2ec
RS
167 my $str = " {FT_cipher, \"$cmd\", enc_main, enc_options},\n";
168 (my $algo = $cmd) =~ s/-.*//g;
169 if ($cmd eq "zlib") {
170 print "#ifdef ZLIB\n${str}#endif\n";
171 } elsif (grep { $algo eq $_ } @disablables) {
172 print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
173 } elsif (my $disabler = $cipher_disabler{$algo}) {
174 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
175 } else {
176 print $str;
177 }
7e1b7485 178}
d02b48c6 179
aa74c2ec 180print " {0, NULL, NULL}\n};\n";
ad2c5ed7 181print "#endif\n";