]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg: Update process_files.pl to automatically add PCD config option
authorYi Li <yi1.li@intel.com>
Tue, 10 May 2022 07:19:05 +0000 (15:19 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 11 May 2022 00:04:39 +0000 (00:04 +0000)
Recommend from Gerd:
(2) Keep the EC config option, but update process_files.pl to
  automatically add the PcdEcEnabled config option handling
  to the files it generates.

When remove 'no-ec' from openssl configure list, will automatically remove
'OPENSSL_NO_EC', 'OPENSSL_NO_ECDH', 'OPENSSL_NO_ECDSA', 'OPENSSL_NO_TLS1_3',
form header, and add '/ec/.', '/sm2/.' files to INF files.

Signed-off-by: Yi Li <yi1.li@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Xiaoyu Lu <xiaoyu1.lu@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
CryptoPkg/Library/OpensslLib/process_files.pl

index 2ebfbbbca0de142a4021841285e8e2af5f7f270d..545f2182842b90efe2bfa0e52e8fc3f8a6e1085e 100755 (executable)
@@ -81,6 +81,19 @@ my $uefi_config;
 my $extension;\r
 my $arch;\r
 my @inf;\r
+#\r
+# Use PCD to conditionally enable certain openssl features.\r
+# $conditional_feature contains pcd_name:fetures_names pairs\r
+# of conditional features.\r
+# @conditional_feature_dir contains relative_path:pcd_name pairs\r
+# of conditional features in openssl, MUST correspond to the content\r
+# in $conditional_feature.\r
+#\r
+# Configure list [openssl_configuration : new_define_list : new_file_list : pcd]\r
+# 1. no-ec : {NO_EC, NO_ECDH, NO_ECDSA, NO_TLS1_3, NO_SM2} : {/ec/, /sm2/} : PcdOpensslEcEnabled\r
+#\r
+my %conditional_feature = ("PcdOpensslEcEnabled"=>["EC", "ECDH", "ECDSA", "TLS1_3", "SM2"]);\r
+my %conditional_feature_dir = ("/ec/"=>"PcdOpensslEcEnabled", "/sm2/"=>"PcdOpensslEcEnabled");\r
 \r
 BEGIN {\r
     $inf_file = "OpensslLib.inf";\r
@@ -282,7 +295,13 @@ foreach my $product ((@{$unified_info{libraries}},
                 push @sslfilelist, '  $(OPENSSL_PATH)/' . $s . "\r\n";\r
                 next;\r
             }\r
-            push @cryptofilelist, '  $(OPENSSL_PATH)/' . $s . "\r\n";\r
+            push @cryptofilelist, '  $(OPENSSL_PATH)/' . $s;\r
+            foreach (keys(%conditional_feature_dir)) {\r
+                if ($s =~ $_) {\r
+                    push @cryptofilelist, '      |*|*|*|gEfiCryptoPkgTokenSpaceGuid.' . $conditional_feature_dir{$_};\r
+                }\r
+            }\r
+            push @cryptofilelist, "\r\n";\r
         }\r
     }\r
 }\r
@@ -311,7 +330,13 @@ foreach (@headers){
     push @sslfilelist, '  $(OPENSSL_PATH)/' . $_ . "\r\n";\r
     next;\r
   }\r
-  push @cryptofilelist, '  $(OPENSSL_PATH)/' . $_ . "\r\n";\r
+  push @cryptofilelist, '  $(OPENSSL_PATH)/' . $_;\r
+  foreach my $conditional_key (keys(%conditional_feature_dir)) {\r
+    if ($_ =~ $conditional_key) {\r
+        push @cryptofilelist, '      |*|*|*|gEfiCryptoPkgTokenSpaceGuid.' . $conditional_feature_dir{$conditional_key};\r
+    }\r
+  }\r
+  push @cryptofilelist, "\r\n";\r
 }\r
 \r
 \r
@@ -416,7 +441,7 @@ print "\n--> Duplicating opensslconf.h into Include/openssl ... ";
 system(\r
     "perl -pe 's/\\n/\\r\\n/' " .\r
     "< " . $OPENSSL_PATH . "/include/openssl/opensslconf.h " .\r
-    "> " . $OPENSSL_PATH . "/../../Include/openssl/opensslconf.h"\r
+    "> " . $OPENSSL_PATH . "/../../Include/openssl/opensslconf_generated.h"\r
     ) == 0 ||\r
     die "Cannot copy opensslconf.h!";\r
 print "Done!";\r
@@ -428,6 +453,52 @@ system(
     "> " . $OPENSSL_PATH . "/../../Include/crypto/dso_conf.h"\r
     ) == 0 ||\r
     die "Cannot copy dso_conf.h!";\r
+print "Done!";\r
+\r
+#\r
+# Add conditional feature to opensslconf.h\r
+#\r
+my $conf_file = "../Include/openssl/opensslconf.h";\r
+my @conf_raw = ();\r
+my @conditional_define = ();\r
+print "\n--> Updating conditional feature in $conf_file ... ";\r
+\r
+foreach my $pcd_name (keys(%conditional_feature)) {\r
+    push @conditional_define, "#if !FixedPcdGetBool ($pcd_name)\r\n";\r
+    foreach (@{$conditional_feature{$pcd_name}}) {\r
+        push @conditional_define, "# ifndef OPENSSL_NO_$_\r\n";\r
+        push @conditional_define, "#  define OPENSSL_NO_$_\r\n";\r
+        push @conditional_define, "# endif\r\n";\r
+    }\r
+    push @conditional_define, "#endif\r\n";\r
+}\r
+\r
+open( FD, "<" . $conf_file ) ||\r
+    die $conf_file;\r
+foreach (<FD>) {\r
+    # Insert conditional define to the begin of opensslconf.h\r
+    if ($_ =~ "Autogenerated conditional openssl feature list starts here") {\r
+        push @conf_raw, $_, @conditional_define;\r
+        $subbing = 1;\r
+        next;\r
+    }\r
+    if ($_ =~ "Autogenerated conditional openssl feature list ends here") {\r
+        push @conf_raw, $_;\r
+        $subbing = 0;\r
+        next;\r
+    }\r
+    push @conf_raw, $_\r
+        unless ($subbing);\r
+}\r
+close(FD) ||\r
+    die $conf_file;\r
+\r
+open( FD, ">" . $conf_file ) ||\r
+    die $conf_file;\r
+print( FD @conf_raw ) ||\r
+    die $conf_file;\r
+close(FD) ||\r
+    die $conf_file;\r
 print "Done!\n";\r
 \r
 print "\nProcessing Files Done!\n";\r