]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/OpensslLib/process_files.pl
CryptoPkg/OpensslLib: Set ARC4 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
65 "no-dgram",\r
66 "no-dsa",\r
67 "no-dynamic-engine",\r
68 "no-ec",\r
69 "no-ec2m",\r
70 "no-engine",\r
71 "no-err",\r
72 "no-filenames",\r
73 "no-gost",\r
74 "no-hw",\r
75 "no-idea",\r
9b2a082e 76 "no-md4",\r
264702a0
HW
77 "no-mdc2",\r
78 "no-pic",\r
79 "no-ocb",\r
80 "no-poly1305",\r
81 "no-posix-io",\r
82 "no-rc2",\r
f4c15d38 83 "no-rc4",\r
264702a0
HW
84 "no-rfc3779",\r
85 "no-rmd160",\r
86 "no-scrypt",\r
87 "no-seed",\r
88 "no-sock",\r
89 "no-srp",\r
90 "no-ssl",\r
91 "no-stdio",\r
92 "no-threads",\r
93 "no-ts",\r
94 "no-ui",\r
6fcc3d68
XL
95 "no-whirlpool",\r
96 # OpenSSL1_1_1b doesn't support default rand-seed-os for UEFI\r
97 # UEFI only support --with-rand-seed=none\r
98 "--with-rand-seed=none"\r
264702a0
HW
99 ) == 0 ||\r
100 die "OpenSSL Configure failed!\n";\r
101\r
102 # Generate opensslconf.h per config data\r
103 system(\r
104 "perl -I. -Mconfigdata util/dofile.pl " .\r
105 "include/openssl/opensslconf.h.in " .\r
106 "> include/openssl/opensslconf.h"\r
107 ) == 0 ||\r
108 die "Failed to generate opensslconf.h!\n";\r
109\r
1bcc65b9
SZ
110 # Generate dso_conf.h per config data\r
111 system(\r
112 "perl -I. -Mconfigdata util/dofile.pl " .\r
113 "crypto/include/internal/dso_conf.h.in " .\r
114 "> include/internal/dso_conf.h"\r
115 ) == 0 ||\r
116 die "Failed to generate dso_conf.h!\n";\r
117\r
264702a0
HW
118 chdir($basedir) ||\r
119 die "Cannot change to base directory \"" . $basedir . "\"";\r
120\r
121 push @INC, $1;\r
122 last;\r
123 }\r
124 }\r
125}\r
126\r
127#\r
128# Retrieve file lists from OpenSSL configdata\r
129#\r
130use configdata qw/%unified_info/;\r
131\r
132my @cryptofilelist = ();\r
133my @sslfilelist = ();\r
134foreach my $product ((@{$unified_info{libraries}},\r
135 @{$unified_info{engines}})) {\r
136 foreach my $o (@{$unified_info{sources}->{$product}}) {\r
137 foreach my $s (@{$unified_info{sources}->{$o}}) {\r
138 next if ($unified_info{generate}->{$s});\r
139 next if $s =~ "crypto/bio/b_print.c";\r
7eee0488
XL
140\r
141 # No need to add unused files in UEFI.\r
142 # So it can reduce porting time, compile time, library size.\r
143 next if $s =~ "crypto/rand/randfile.c";\r
144 next if $s =~ "crypto/store/";\r
51f7a3e6 145 next if $s =~ "crypto/err/err_all.c";\r
7eee0488 146\r
264702a0
HW
147 if ($product =~ "libssl") {\r
148 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
149 next;\r
150 }\r
151 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
152 }\r
153 }\r
154}\r
155\r
9f4fbd56
SZ
156\r
157#\r
158# Update the perl script to generate the missing header files\r
159#\r
160my @dir_list = ();\r
c72ca466 161for (sort keys %{$unified_info{dirinfo}}){\r
9f4fbd56
SZ
162 push @dir_list,$_;\r
163}\r
164\r
165my $dir = getcwd();\r
166my @files = ();\r
167my @headers = ();\r
168chdir ("openssl");\r
169foreach(@dir_list){\r
170 @files = glob($_."/*.h");\r
171 push @headers, @files;\r
172}\r
173chdir ($dir);\r
174\r
175foreach (@headers){\r
176 if(/ssl/){\r
177 push @sslfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";\r
178 next;\r
179 }\r
180 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";\r
181}\r
182\r
183\r
264702a0
HW
184#\r
185# Update OpensslLib.inf with autogenerated file list\r
186#\r
187my @new_inf = ();\r
188my $subbing = 0;\r
189print "\n--> Updating OpensslLib.inf ... ";\r
190foreach (@inf) {\r
191 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
192 push @new_inf, $_, @cryptofilelist, @sslfilelist;\r
193 $subbing = 1;\r
194 next;\r
195 }\r
196 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
197 push @new_inf, $_;\r
198 $subbing = 0;\r
199 next;\r
200 }\r
201\r
202 push @new_inf, $_\r
203 unless ($subbing);\r
204}\r
205\r
206my $new_inf_file = $inf_file . ".new";\r
207open( FD, ">" . $new_inf_file ) ||\r
208 die $new_inf_file;\r
209print( FD @new_inf ) ||\r
210 die $new_inf_file;\r
211close(FD) ||\r
212 die $new_inf_file;\r
213rename( $new_inf_file, $inf_file ) ||\r
214 die "rename $inf_file";\r
215print "Done!";\r
216\r
217#\r
218# Update OpensslLibCrypto.inf with auto-generated file list (no libssl)\r
219#\r
220$inf_file = "OpensslLibCrypto.inf";\r
221\r
222# Read the contents of the inf file\r
223@inf = ();\r
224@new_inf = ();\r
225open( FD, "<" . $inf_file ) ||\r
226 die "Cannot open \"" . $inf_file . "\"!";\r
227@inf = (<FD>);\r
228close(FD) ||\r
229 die "Cannot close \"" . $inf_file . "\"!";\r
230\r
231$subbing = 0;\r
232print "\n--> Updating OpensslLibCrypto.inf ... ";\r
233foreach (@inf) {\r
234 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
235 push @new_inf, $_, @cryptofilelist;\r
236 $subbing = 1;\r
237 next;\r
238 }\r
239 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
240 push @new_inf, $_;\r
241 $subbing = 0;\r
242 next;\r
243 }\r
244\r
245 push @new_inf, $_\r
246 unless ($subbing);\r
247}\r
248\r
249$new_inf_file = $inf_file . ".new";\r
250open( FD, ">" . $new_inf_file ) ||\r
251 die $new_inf_file;\r
252print( FD @new_inf ) ||\r
253 die $new_inf_file;\r
254close(FD) ||\r
255 die $new_inf_file;\r
256rename( $new_inf_file, $inf_file ) ||\r
257 die "rename $inf_file";\r
258print "Done!";\r
259\r
260#\r
1bcc65b9 261# Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration\r
264702a0
HW
262#\r
263print "\n--> Duplicating opensslconf.h into Include/openssl ... ";\r
264copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",\r
abc4c817 265 $OPENSSL_PATH . "/../../Include/openssl/") ||\r
264702a0 266 die "Cannot copy opensslconf.h!";\r
1bcc65b9
SZ
267print "Done!";\r
268print "\n--> Duplicating dso_conf.h into Include/internal ... ";\r
269copy($OPENSSL_PATH . "/include/internal/dso_conf.h",\r
270 $OPENSSL_PATH . "/../../Include/internal/") ||\r
271 die "Cannot copy dso_conf.h!";\r
264702a0
HW
272print "Done!\n";\r
273\r
274print "\nProcessing Files Done!\n";\r
275\r
276exit(0);\r
277\r