]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/progs.pl
Add brotli compression support (RFC7924)
[thirdparty/openssl.git] / apps / progs.pl
CommitLineData
e0a65194 1#! /usr/bin/env perl
fecb3aae 2# Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
3850f8cb 3#
dffa7520 4# Licensed under the Apache License 2.0 (the "License"). You may not use
e0a65194
RS
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
4b62b8ed
RL
17my $opt = shift @ARGV;
18die "Unrecognised option, must be -C or -H\n"
19 unless ($opt eq '-H' || $opt eq '-C');
20
aa74c2ec
RS
21my %commands = ();
22my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
6a74806e 23my $apps_openssl = shift @ARGV;
27aca04e 24my $YEAR = [gmtime($ENV{SOURCE_DATE_EPOCH} || time())]->[5] + 1900;
aa74c2ec 25
6a74806e
RL
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
29my @openssl_source =
30 map { @{$unified_info{sources}->{$_}} }
da750b15
RL
31 grep { /\.o$/
32 && !$unified_info{attributes}->{sources}->{$apps_openssl}->{$_}->{nocheck} }
aa74c2ec 33 @{$unified_info{sources}->{$apps_openssl}};
6a74806e
RL
34
35foreach my $filename (@openssl_source) {
ab307dc6 36 open F, $filename or die "Couldn't open $filename: $!\n";
aa74c2ec
RS
37 foreach ( grep /$cmdre/, <F> ) {
38 my @foo = /$cmdre/;
39 $commands{$1} = 1;
40 }
41 close F;
fb3e2a88
RL
42}
43
44@ARGV = sort keys %commands;
d02b48c6 45
4b62b8ed
RL
46if ($opt eq '-H') {
47 print <<"EOF";
7e1b7485 48/*
e0a65194
RS
49 * WARNING: do not edit!
50 * Generated by apps/progs.pl
51 *
83900628 52 * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
3850f8cb 53 *
dffa7520 54 * Licensed under the Apache License 2.0 (the "License"). You may not use
e0a65194
RS
55 * this file except in compliance with the License. You can obtain a copy
56 * in the file LICENSE in the source distribution or at
3850f8cb 57 * https://www.openssl.org/source/license.html
7e1b7485 58 */
d02b48c6 59
4b62b8ed 60#include "function.h"
0109e030 61
4b62b8ed 62EOF
d02b48c6 63
4b62b8ed
RL
64 foreach (@ARGV) {
65 printf "extern int %s_main(int argc, char *argv[]);\n", $_;
66 }
67 print "\n";
d02b48c6 68
4b62b8ed
RL
69 foreach (@ARGV) {
70 printf "extern const OPTIONS %s_options[];\n", $_;
71 }
72 print "\n";
73 print "extern FUNCTION functions[];\n";
74}
e6b5c341 75
4b62b8ed
RL
76if ($opt eq '-C') {
77 print <<"EOF";
78/*
79 * WARNING: do not edit!
80 * Generated by apps/progs.pl
81 *
82 * Copyright 1995-$YEAR The OpenSSL Project Authors. All Rights Reserved.
83 *
84 * Licensed under the Apache License 2.0 (the "License"). You may not use
85 * this file except in compliance with the License. You can obtain a copy
86 * in the file LICENSE in the source distribution or at
87 * https://www.openssl.org/source/license.html
88 */
d02b48c6 89
4b62b8ed 90#include "progs.h"
df2ee0e2 91
4b62b8ed
RL
92EOF
93
94 my %cmd_disabler = (
95 ciphers => "sock",
99a7c3a7
P
96 genrsa => "rsa",
97 gendsa => "dsa",
98 dsaparam => "dsa",
99 gendh => "dh",
100 dhparam => "dh",
101 ecparam => "ec",
4b62b8ed 102 );
c2ec4a16 103 my %cmd_deprecated = (
cd3572a1 104# The format of this table is:
19d9be09
P
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" ],
c2ec4a16 117 );
4b62b8ed
RL
118
119 print "FUNCTION functions[] = {\n";
120 foreach my $cmd ( @ARGV ) {
121 my $str =
99a7c3a7 122 " {FT_general, \"$cmd\", ${cmd}_main, ${cmd}_options, NULL, NULL},\n";
4b62b8ed
RL
123 if ($cmd =~ /^s_/) {
124 print "#ifndef OPENSSL_NO_SOCK\n${str}#endif\n";
c2ec4a16
P
125 } elsif (my $deprecated = $cmd_deprecated{$cmd}) {
126 my @dep = @{$deprecated};
19d9be09
P
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) . ")";
cd3572a1 133 }
19d9be09
P
134 $dver =~ s/_/./g;
135 my $dalt = "\"" . $daltprg . "\", \"" . $dver . "\"";
136 $str =~ s/NULL, NULL/$dalt/;
c2ec4a16 137 print "\n${str}#endif\n";
4b62b8ed
RL
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 }
aa74c2ec 145 }
d02b48c6 146
4b62b8ed
RL
147 my %md_disabler = (
148 blake2b512 => "blake2",
149 blake2s256 => "blake2",
150 );
151 foreach my $cmd (
152 "md2", "md4", "md5",
4b62b8ed
RL
153 "sha1", "sha224", "sha256", "sha384",
154 "sha512", "sha512-224", "sha512-256",
155 "sha3-224", "sha3-256", "sha3-384", "sha3-512",
156 "shake128", "shake256",
157 "mdc2", "rmd160", "blake2b512", "blake2s256",
158 "sm3"
159 ) {
c2ec4a16 160 my $str = " {FT_md, \"$cmd\", dgst_main, NULL, NULL},\n";
4b62b8ed
RL
161 if (grep { $cmd eq $_ } @disablables) {
162 print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
163 } elsif (my $disabler = $md_disabler{$cmd}) {
164 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
165 } else {
166 print $str;
167 }
aa74c2ec 168 }
d02b48c6 169
4b62b8ed
RL
170 my %cipher_disabler = (
171 des3 => "des",
172 desx => "des",
173 cast5 => "cast",
174 );
175 foreach my $cmd (
176 "aes-128-cbc", "aes-128-ecb",
177 "aes-192-cbc", "aes-192-ecb",
178 "aes-256-cbc", "aes-256-ecb",
179 "aria-128-cbc", "aria-128-cfb",
180 "aria-128-ctr", "aria-128-ecb", "aria-128-ofb",
181 "aria-128-cfb1", "aria-128-cfb8",
182 "aria-192-cbc", "aria-192-cfb",
183 "aria-192-ctr", "aria-192-ecb", "aria-192-ofb",
184 "aria-192-cfb1", "aria-192-cfb8",
185 "aria-256-cbc", "aria-256-cfb",
186 "aria-256-ctr", "aria-256-ecb", "aria-256-ofb",
187 "aria-256-cfb1", "aria-256-cfb8",
188 "camellia-128-cbc", "camellia-128-ecb",
189 "camellia-192-cbc", "camellia-192-ecb",
190 "camellia-256-cbc", "camellia-256-ecb",
12e96a23 191 "base64", "zlib", "brotli",
4b62b8ed
RL
192 "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
193 "rc2", "bf", "cast", "rc5",
194 "des-ecb", "des-ede", "des-ede3",
195 "des-cbc", "des-ede-cbc","des-ede3-cbc",
196 "des-cfb", "des-ede-cfb","des-ede3-cfb",
197 "des-ofb", "des-ede-ofb","des-ede3-ofb",
198 "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
199 "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
200 "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
201 "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
202 "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
203 "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb",
204 "sm4-cbc", "sm4-ecb", "sm4-cfb", "sm4-ofb", "sm4-ctr"
205 ) {
c2ec4a16 206 my $str = " {FT_cipher, \"$cmd\", enc_main, enc_options, NULL},\n";
4b62b8ed
RL
207 (my $algo = $cmd) =~ s/-.*//g;
208 if ($cmd eq "zlib") {
209 print "#ifdef ZLIB\n${str}#endif\n";
210 } elsif (grep { $algo eq $_ } @disablables) {
211 print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
212 } elsif (my $disabler = $cipher_disabler{$algo}) {
213 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
214 } else {
215 print $str;
216 }
aa74c2ec 217 }
d02b48c6 218
c2ec4a16 219 print " {0, NULL, NULL, NULL, NULL}\n};\n";
4b62b8ed 220}