]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/OpensslLib/process_files.pl
CryptoPkg/OpensslLib: Set TDES disable in OpensslLib
[mirror_edk2.git] / CryptoPkg / Library / OpensslLib / process_files.pl
CommitLineData
264702a0
HW
1#!/usr/bin/perl -w\r
2#\r
3# This script runs the OpenSSL Configure script, then processes the\r
4# resulting file list into our local OpensslLib[Crypto].inf and also\r
1bcc65b9 5# takes copies of opensslconf.h and dso_conf.h.\r
264702a0
HW
6#\r
7# This only needs to be done once by a developer when updating to a\r
8# new version of OpenSSL (or changing options, etc.). Normal users\r
9# do not need to do this, since the results are stored in the EDK2\r
10# git repository for them.\r
11#\r
12use strict;\r
13use Cwd;\r
14use File::Copy;\r
15\r
16#\r
17# Find the openssl directory name for use lib. We have to do this\r
18# inside of BEGIN. The variables we create here, however, don't seem\r
19# to be available to the main script, so we have to repeat the\r
20# exercise.\r
21#\r
22my $inf_file;\r
23my $OPENSSL_PATH;\r
24my @inf;\r
25\r
26BEGIN {\r
27 $inf_file = "OpensslLib.inf";\r
28\r
29 # Read the contents of the inf file\r
30 open( FD, "<" . $inf_file ) ||\r
31 die "Cannot open \"" . $inf_file . "\"!";\r
32 @inf = (<FD>);\r
33 close(FD) ||\r
34 die "Cannot close \"" . $inf_file . "\"!";\r
35\r
36 foreach (@inf) {\r
37 if (/DEFINE\s+OPENSSL_PATH\s*=\s*([a-z]+)/) {\r
38\r
39 # We need to run Configure before we can include its result...\r
40 $OPENSSL_PATH = $1;\r
41\r
42 my $basedir = getcwd();\r
43\r
44 chdir($OPENSSL_PATH) ||\r
45 die "Cannot change to OpenSSL directory \"" . $OPENSSL_PATH . "\"";\r
46\r
47 # Configure UEFI\r
48 system(\r
49 "./Configure",\r
50 "UEFI",\r
51 "no-afalgeng",\r
52 "no-asm",\r
53 "no-async",\r
264702a0 54 "no-autoerrinit",\r
c72ca466 55 "no-autoload-config",\r
264702a0
HW
56 "no-bf",\r
57 "no-blake2",\r
58 "no-camellia",\r
59 "no-capieng",\r
60 "no-cast",\r
61 "no-chacha",\r
62 "no-cms",\r
63 "no-ct",\r
64 "no-deprecated",\r
394d5896 65 "no-des",\r
264702a0
HW
66 "no-dgram",\r
67 "no-dsa",\r
68 "no-dynamic-engine",\r
69 "no-ec",\r
70 "no-ec2m",\r
71 "no-engine",\r
72 "no-err",\r
73 "no-filenames",\r
74 "no-gost",\r
75 "no-hw",\r
76 "no-idea",\r
9b2a082e 77 "no-md4",\r
264702a0
HW
78 "no-mdc2",\r
79 "no-pic",\r
80 "no-ocb",\r
81 "no-poly1305",\r
82 "no-posix-io",\r
83 "no-rc2",\r
f4c15d38 84 "no-rc4",\r
264702a0
HW
85 "no-rfc3779",\r
86 "no-rmd160",\r
87 "no-scrypt",\r
88 "no-seed",\r
89 "no-sock",\r
90 "no-srp",\r
91 "no-ssl",\r
92 "no-stdio",\r
93 "no-threads",\r
94 "no-ts",\r
95 "no-ui",\r
6fcc3d68
XL
96 "no-whirlpool",\r
97 # OpenSSL1_1_1b doesn't support default rand-seed-os for UEFI\r
98 # UEFI only support --with-rand-seed=none\r
99 "--with-rand-seed=none"\r
264702a0
HW
100 ) == 0 ||\r
101 die "OpenSSL Configure failed!\n";\r
102\r
103 # Generate opensslconf.h per config data\r
104 system(\r
105 "perl -I. -Mconfigdata util/dofile.pl " .\r
106 "include/openssl/opensslconf.h.in " .\r
107 "> include/openssl/opensslconf.h"\r
108 ) == 0 ||\r
109 die "Failed to generate opensslconf.h!\n";\r
110\r
1bcc65b9
SZ
111 # Generate dso_conf.h per config data\r
112 system(\r
113 "perl -I. -Mconfigdata util/dofile.pl " .\r
114 "crypto/include/internal/dso_conf.h.in " .\r
115 "> include/internal/dso_conf.h"\r
116 ) == 0 ||\r
117 die "Failed to generate dso_conf.h!\n";\r
118\r
264702a0
HW
119 chdir($basedir) ||\r
120 die "Cannot change to base directory \"" . $basedir . "\"";\r
121\r
122 push @INC, $1;\r
123 last;\r
124 }\r
125 }\r
126}\r
127\r
128#\r
129# Retrieve file lists from OpenSSL configdata\r
130#\r
131use configdata qw/%unified_info/;\r
132\r
133my @cryptofilelist = ();\r
134my @sslfilelist = ();\r
135foreach my $product ((@{$unified_info{libraries}},\r
136 @{$unified_info{engines}})) {\r
137 foreach my $o (@{$unified_info{sources}->{$product}}) {\r
138 foreach my $s (@{$unified_info{sources}->{$o}}) {\r
139 next if ($unified_info{generate}->{$s});\r
140 next if $s =~ "crypto/bio/b_print.c";\r
7eee0488
XL
141\r
142 # No need to add unused files in UEFI.\r
143 # So it can reduce porting time, compile time, library size.\r
144 next if $s =~ "crypto/rand/randfile.c";\r
145 next if $s =~ "crypto/store/";\r
51f7a3e6 146 next if $s =~ "crypto/err/err_all.c";\r
7eee0488 147\r
264702a0
HW
148 if ($product =~ "libssl") {\r
149 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
150 next;\r
151 }\r
152 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
153 }\r
154 }\r
155}\r
156\r
9f4fbd56
SZ
157\r
158#\r
159# Update the perl script to generate the missing header files\r
160#\r
161my @dir_list = ();\r
c72ca466 162for (sort keys %{$unified_info{dirinfo}}){\r
9f4fbd56
SZ
163 push @dir_list,$_;\r
164}\r
165\r
166my $dir = getcwd();\r
167my @files = ();\r
168my @headers = ();\r
169chdir ("openssl");\r
170foreach(@dir_list){\r
171 @files = glob($_."/*.h");\r
172 push @headers, @files;\r
173}\r
174chdir ($dir);\r
175\r
176foreach (@headers){\r
177 if(/ssl/){\r
178 push @sslfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";\r
179 next;\r
180 }\r
181 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";\r
182}\r
183\r
184\r
264702a0
HW
185#\r
186# Update OpensslLib.inf with autogenerated file list\r
187#\r
188my @new_inf = ();\r
189my $subbing = 0;\r
190print "\n--> Updating OpensslLib.inf ... ";\r
191foreach (@inf) {\r
192 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
193 push @new_inf, $_, @cryptofilelist, @sslfilelist;\r
194 $subbing = 1;\r
195 next;\r
196 }\r
197 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
198 push @new_inf, $_;\r
199 $subbing = 0;\r
200 next;\r
201 }\r
202\r
203 push @new_inf, $_\r
204 unless ($subbing);\r
205}\r
206\r
207my $new_inf_file = $inf_file . ".new";\r
208open( FD, ">" . $new_inf_file ) ||\r
209 die $new_inf_file;\r
210print( FD @new_inf ) ||\r
211 die $new_inf_file;\r
212close(FD) ||\r
213 die $new_inf_file;\r
214rename( $new_inf_file, $inf_file ) ||\r
215 die "rename $inf_file";\r
216print "Done!";\r
217\r
218#\r
219# Update OpensslLibCrypto.inf with auto-generated file list (no libssl)\r
220#\r
221$inf_file = "OpensslLibCrypto.inf";\r
222\r
223# Read the contents of the inf file\r
224@inf = ();\r
225@new_inf = ();\r
226open( FD, "<" . $inf_file ) ||\r
227 die "Cannot open \"" . $inf_file . "\"!";\r
228@inf = (<FD>);\r
229close(FD) ||\r
230 die "Cannot close \"" . $inf_file . "\"!";\r
231\r
232$subbing = 0;\r
233print "\n--> Updating OpensslLibCrypto.inf ... ";\r
234foreach (@inf) {\r
235 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
236 push @new_inf, $_, @cryptofilelist;\r
237 $subbing = 1;\r
238 next;\r
239 }\r
240 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
241 push @new_inf, $_;\r
242 $subbing = 0;\r
243 next;\r
244 }\r
245\r
246 push @new_inf, $_\r
247 unless ($subbing);\r
248}\r
249\r
250$new_inf_file = $inf_file . ".new";\r
251open( FD, ">" . $new_inf_file ) ||\r
252 die $new_inf_file;\r
253print( FD @new_inf ) ||\r
254 die $new_inf_file;\r
255close(FD) ||\r
256 die $new_inf_file;\r
257rename( $new_inf_file, $inf_file ) ||\r
258 die "rename $inf_file";\r
259print "Done!";\r
260\r
261#\r
1bcc65b9 262# Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration\r
264702a0
HW
263#\r
264print "\n--> Duplicating opensslconf.h into Include/openssl ... ";\r
265copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",\r
abc4c817 266 $OPENSSL_PATH . "/../../Include/openssl/") ||\r
264702a0 267 die "Cannot copy opensslconf.h!";\r
1bcc65b9
SZ
268print "Done!";\r
269print "\n--> Duplicating dso_conf.h into Include/internal ... ";\r
270copy($OPENSSL_PATH . "/include/internal/dso_conf.h",\r
271 $OPENSSL_PATH . "/../../Include/internal/") ||\r
272 die "Cannot copy dso_conf.h!";\r
264702a0
HW
273print "Done!\n";\r
274\r
275print "\nProcessing Files Done!\n";\r
276\r
277exit(0);\r
278\r