From 174573b3a7270221c5851e0db63bd0e98498eb38 Mon Sep 17 00:00:00 2001 From: Qihang Gao Date: Wed, 10 Jun 2026 17:41:17 +0800 Subject: [PATCH 001/406] MdeModulePkg: Display VID and DID using 4-digit hexadecimal number No functional change. Signed-off-by: Qihang Gao --- MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c index bd5dd71fb3..9043e8ddc2 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c @@ -373,7 +373,7 @@ PciSearchDevice ( DEBUG (( DEBUG_INFO, - "PciBus: Discovered %s @ [%02x|%02x|%02x] [VID = 0x%x, DID = 0x%0x]\n", + "PciBus: Discovered %s @ [%02x|%02x|%02x] [VID = 0x%04x, DID = 0x%04x]\n", IS_PCI_BRIDGE (Pci) ? L"PPB" : IS_CARDBUS_BRIDGE (Pci) ? L"P2C" : L"PCI", From 92b2428c063a21f1442b0bc387c8e310d4651bff Mon Sep 17 00:00:00 2001 From: Jean-Tiare Le Bigot Date: Fri, 12 Jun 2026 21:31:49 +0200 Subject: [PATCH 002/406] CryptoPkg: Log TLS handshake certificate verification error reason When the TLS error is `SSL_R_CERTIFICATE_VERIFY_FAILED`, the verification failure reason is reported by `SSL_get_verify_result`. Adding this reason to the debug logs is valuable to pin-point certificate rejection that are specific to EDK II. Signed-off-by: Jean-Tiare Le Bigot --- CryptoPkg/Library/TlsLib/TlsProcess.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CryptoPkg/Library/TlsLib/TlsProcess.c b/CryptoPkg/Library/TlsLib/TlsProcess.c index 17aeff1c37..953bffcea7 100644 --- a/CryptoPkg/Library/TlsLib/TlsProcess.c +++ b/CryptoPkg/Library/TlsLib/TlsProcess.c @@ -151,6 +151,22 @@ TlsDoHandshake ( Func, Data )); + + if ((ERR_GET_LIB (ErrorCode) == ERR_LIB_SSL) && \ + (ERR_GET_REASON (ErrorCode) == SSL_R_CERTIFICATE_VERIFY_FAILED)) + { + INT32 X509Err; + + X509Err = SSL_get_verify_result (TlsConn->Ssl); + + DEBUG (( + DEBUG_ERROR, + "%a X509_verify_result: %d (%a)\n", + __func__, + X509Err, + X509_verify_cert_error_string (X509Err) + )); + } } DEBUG_CODE_END (); From eaa1e19c7a039b3d178ac960c33dc057c4d75243 Mon Sep 17 00:00:00 2001 From: Lee LonghaoX Date: Wed, 15 Apr 2026 14:31:23 +0800 Subject: [PATCH 003/406] CryptoPkg: Added lite version openssl library Lite version OpensslLib base on OpensslLibFull but no-camellia, no -ecx and no-dh. It save the size about ~192KB. REF: Signed-off-by: Lee LonghaoX --- CryptoPkg/CryptoPkg.dsc | 2 + CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c | 3 + .../include/openssl/configuration-ec-lite.h | 409 +++ .../include/openssl/configuration.h | 4 +- .../OpensslLib/OpensslLibFullAccelLite.inf | 2356 +++++++++++++++++ .../OpensslLib/OpensslLibFullAccelLite.uni | 15 + .../Library/OpensslLib/OpensslLibFullLite.inf | 842 ++++++ .../Library/OpensslLib/OpensslLibFullLite.uni | 12 + .../OpensslLib/OpensslStub/CamelliaNull.c | 2 + .../Library/OpensslLib/OpensslStub/DhNull.c | 96 + CryptoPkg/Library/OpensslLib/configure.py | 39 +- 11 files changed, 3770 insertions(+), 10 deletions(-) create mode 100644 CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec-lite.h create mode 100644 CryptoPkg/Library/OpensslLib/OpensslLibFullAccelLite.inf create mode 100644 CryptoPkg/Library/OpensslLib/OpensslLibFullAccelLite.uni create mode 100644 CryptoPkg/Library/OpensslLib/OpensslLibFullLite.inf create mode 100644 CryptoPkg/Library/OpensslLib/OpensslLibFullLite.uni create mode 100644 CryptoPkg/Library/OpensslLib/OpensslStub/DhNull.c diff --git a/CryptoPkg/CryptoPkg.dsc b/CryptoPkg/CryptoPkg.dsc index 9bc7421f65..9d13ec35ff 100644 --- a/CryptoPkg/CryptoPkg.dsc +++ b/CryptoPkg/CryptoPkg.dsc @@ -381,6 +381,7 @@ CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf CryptoPkg/Library/OpensslLib/OpensslLib.inf CryptoPkg/Library/OpensslLib/OpensslLibFull.inf + CryptoPkg/Library/OpensslLib/OpensslLibFullLite.inf CryptoPkg/Library/OpensslLib/OpensslLibSm3.inf CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.inf CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.inf @@ -406,6 +407,7 @@ # CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf + CryptoPkg/Library/OpensslLib/OpensslLibFullAccelLite.inf !endif # diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c index 950e18158c..ec6aa40418 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c @@ -7,6 +7,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "InternalCryptLib.h" +#include +#undef OPENSSL_NO_DH + #include #include diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec-lite.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec-lite.h new file mode 100644 index 0000000000..a552755134 --- /dev/null +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec-lite.h @@ -0,0 +1,409 @@ +/* + * WARNING: do not edit! + * Generated by configdata.pm from Configurations/common0.tmpl, Configurations/unix-Makefile.tmpl + * via Makefile.in + * + * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef OPENSSL_CONFIGURATION_H +#define OPENSSL_CONFIGURATION_H +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_ALGORITHM_DEFINES + #error OPENSSL_ALGORITHM_DEFINES no longer supported +#endif + +/* + * OpenSSL was configured with the following options: + */ + +#ifndef OPENSSL_SYS_UEFI +#define OPENSSL_SYS_UEFI 1 +#endif +#define OPENSSL_CONFIGURED_API 10101 +#ifndef OPENSSL_RAND_SEED_NONE +#define OPENSSL_RAND_SEED_NONE +#endif +#ifndef OPENSSL_NO_ACVP_TESTS +#define OPENSSL_NO_ACVP_TESTS +#endif +#ifndef OPENSSL_NO_AFALGENG +#define OPENSSL_NO_AFALGENG +#endif +#ifndef OPENSSL_NO_APPS +#define OPENSSL_NO_APPS +#endif +#ifndef OPENSSL_NO_ARGON2 +#define OPENSSL_NO_ARGON2 +#endif +#ifndef OPENSSL_NO_ARIA +#define OPENSSL_NO_ARIA +#endif +#ifndef OPENSSL_NO_ASAN +#define OPENSSL_NO_ASAN +#endif +#ifndef OPENSSL_NO_ASYNC +#define OPENSSL_NO_ASYNC +#endif +#ifndef OPENSSL_NO_AUTOERRINIT +#define OPENSSL_NO_AUTOERRINIT +#endif +#ifndef OPENSSL_NO_AUTOLOAD_CONFIG +#define OPENSSL_NO_AUTOLOAD_CONFIG +#endif +#ifndef OPENSSL_NO_BF +#define OPENSSL_NO_BF +#endif +#ifndef OPENSSL_NO_BLAKE2 +#define OPENSSL_NO_BLAKE2 +#endif +#ifndef OPENSSL_NO_BROTLI +#define OPENSSL_NO_BROTLI +#endif +#ifndef OPENSSL_NO_BROTLI_DYNAMIC +#define OPENSSL_NO_BROTLI_DYNAMIC +#endif +#ifndef OPENSSL_NO_CAMELLIA +#define OPENSSL_NO_CAMELLIA +#endif +#ifndef OPENSSL_NO_CAPIENG +#define OPENSSL_NO_CAPIENG +#endif +#ifndef OPENSSL_NO_CAST +#define OPENSSL_NO_CAST +#endif +#ifndef OPENSSL_NO_CHACHA +#define OPENSSL_NO_CHACHA +#endif +#ifndef OPENSSL_NO_CMP +#define OPENSSL_NO_CMP +#endif +#ifndef OPENSSL_NO_CMS +#define OPENSSL_NO_CMS +#endif +#ifndef OPENSSL_NO_CRMF +#define OPENSSL_NO_CRMF +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG +#define OPENSSL_NO_CRYPTO_MDEBUG +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +#define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +#endif +#ifndef OPENSSL_NO_CT +#define OPENSSL_NO_CT +#endif +#ifndef OPENSSL_NO_DEFAULT_THREAD_POOL +#define OPENSSL_NO_DEFAULT_THREAD_POOL +#endif +#ifndef OPENSSL_NO_DEMOS +#define OPENSSL_NO_DEMOS +#endif +#ifndef OPENSSL_NO_DEPRECATED +#define OPENSSL_NO_DEPRECATED +#endif +#ifndef OPENSSL_NO_DES +#define OPENSSL_NO_DES +#endif +#ifndef OPENSSL_NO_DEVCRYPTOENG +#define OPENSSL_NO_DEVCRYPTOENG +#endif +#ifndef OPENSSL_NO_DGRAM +#define OPENSSL_NO_DGRAM +#endif +#ifndef OPENSSL_NO_DH +#define OPENSSL_NO_DH +#endif +#ifndef OPENSSL_NO_DSA +#define OPENSSL_NO_DSA +#endif +#ifndef OPENSSL_NO_DSO +#define OPENSSL_NO_DSO +#endif +#ifndef OPENSSL_NO_DTLS +#define OPENSSL_NO_DTLS +#endif +#ifndef OPENSSL_NO_DTLS1 +#define OPENSSL_NO_DTLS1 +#endif +#ifndef OPENSSL_NO_DTLS1_METHOD +#define OPENSSL_NO_DTLS1_METHOD +#endif +#ifndef OPENSSL_NO_DTLS1_2 +#define OPENSSL_NO_DTLS1_2 +#endif +#ifndef OPENSSL_NO_DTLS1_2_METHOD +#define OPENSSL_NO_DTLS1_2_METHOD +#endif +#ifndef OPENSSL_NO_EC2M +#define OPENSSL_NO_EC2M +#endif +#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 +#define OPENSSL_NO_EC_NISTP_64_GCC_128 +#endif +#ifndef OPENSSL_NO_ECX +#define OPENSSL_NO_ECX +#endif +#ifndef OPENSSL_NO_EGD +#define OPENSSL_NO_EGD +#endif +#ifndef OPENSSL_NO_ENGINE +#define OPENSSL_NO_ENGINE +#endif +#ifndef OPENSSL_NO_ERR +#define OPENSSL_NO_ERR +#endif +#ifndef OPENSSL_NO_EXTERNAL_TESTS +#define OPENSSL_NO_EXTERNAL_TESTS +#endif +#ifndef OPENSSL_NO_FILENAMES +#define OPENSSL_NO_FILENAMES +#endif +#ifndef OPENSSL_NO_FIPS_JITTER +#define OPENSSL_NO_FIPS_JITTER +#endif +#ifndef OPENSSL_NO_FIPS_POST +#define OPENSSL_NO_FIPS_POST +#endif +#ifndef OPENSSL_NO_FIPS_SECURITYCHECKS +#define OPENSSL_NO_FIPS_SECURITYCHECKS +#endif +#ifndef OPENSSL_NO_FUZZ_AFL +#define OPENSSL_NO_FUZZ_AFL +#endif +#ifndef OPENSSL_NO_FUZZ_LIBFUZZER +#define OPENSSL_NO_FUZZ_LIBFUZZER +#endif +#ifndef OPENSSL_NO_GOST +#define OPENSSL_NO_GOST +#endif +#ifndef OPENSSL_NO_H3DEMO +#define OPENSSL_NO_H3DEMO +#endif +#ifndef OPENSSL_NO_HQINTEROP +#define OPENSSL_NO_HQINTEROP +#endif +#ifndef OPENSSL_NO_IDEA +#define OPENSSL_NO_IDEA +#endif +#ifndef OPENSSL_NO_JITTER +#define OPENSSL_NO_JITTER +#endif +#ifndef OPENSSL_NO_KTLS +#define OPENSSL_NO_KTLS +#endif +#ifndef OPENSSL_NO_LOADERENG +#define OPENSSL_NO_LOADERENG +#endif +#ifndef OPENSSL_NO_MD2 +#define OPENSSL_NO_MD2 +#endif +#ifndef OPENSSL_NO_MD4 +#define OPENSSL_NO_MD4 +#endif +#ifndef OPENSSL_NO_MDC2 +#define OPENSSL_NO_MDC2 +#endif +#ifndef OPENSSL_NO_ML_DSA +#define OPENSSL_NO_ML_DSA +#endif +#ifndef OPENSSL_NO_ML_KEM +#define OPENSSL_NO_ML_KEM +#endif +#ifndef OPENSSL_NO_MSAN +#define OPENSSL_NO_MSAN +#endif +#ifndef OPENSSL_NO_MULTIBLOCK +#define OPENSSL_NO_MULTIBLOCK +#endif +#ifndef OPENSSL_NO_NEXTPROTONEG +#define OPENSSL_NO_NEXTPROTONEG +#endif +#ifndef OPENSSL_NO_OCB +#define OPENSSL_NO_OCB +#endif +#ifndef OPENSSL_NO_OCSP +#define OPENSSL_NO_OCSP +#endif +#ifndef OPENSSL_NO_PADLOCKENG +#define OPENSSL_NO_PADLOCKENG +#endif +#ifndef OPENSSL_NO_PIE +#define OPENSSL_NO_PIE +#endif +#ifndef OPENSSL_NO_POLY1305 +#define OPENSSL_NO_POLY1305 +#endif +#ifndef OPENSSL_NO_POSIX_IO +#define OPENSSL_NO_POSIX_IO +#endif +#ifndef OPENSSL_NO_PSK +#define OPENSSL_NO_PSK +#endif +#ifndef OPENSSL_NO_QLOG +#define OPENSSL_NO_QLOG +#endif +#ifndef OPENSSL_NO_QUIC +#define OPENSSL_NO_QUIC +#endif +#ifndef OPENSSL_NO_RC2 +#define OPENSSL_NO_RC2 +#endif +#ifndef OPENSSL_NO_RC4 +#define OPENSSL_NO_RC4 +#endif +#ifndef OPENSSL_NO_RC5 +#define OPENSSL_NO_RC5 +#endif +#ifndef OPENSSL_NO_RFC3779 +#define OPENSSL_NO_RFC3779 +#endif +#ifndef OPENSSL_NO_RMD160 +#define OPENSSL_NO_RMD160 +#endif +#ifndef OPENSSL_NO_SCRYPT +#define OPENSSL_NO_SCRYPT +#endif +#ifndef OPENSSL_NO_SCTP +#define OPENSSL_NO_SCTP +#endif +#ifndef OPENSSL_NO_SEED +#define OPENSSL_NO_SEED +#endif +#ifndef OPENSSL_NO_SIPHASH +#define OPENSSL_NO_SIPHASH +#endif +#ifndef OPENSSL_NO_SIV +#define OPENSSL_NO_SIV +#endif +#ifndef OPENSSL_NO_SLH_DSA +#define OPENSSL_NO_SLH_DSA +#endif +#ifndef OPENSSL_NO_SM2 +#define OPENSSL_NO_SM2 +#endif +#ifndef OPENSSL_NO_SM4 +#define OPENSSL_NO_SM4 +#endif +#ifndef OPENSSL_NO_SOCK +#define OPENSSL_NO_SOCK +#endif +#ifndef OPENSSL_NO_SRP +#define OPENSSL_NO_SRP +#endif +#ifndef OPENSSL_NO_SRTP +#define OPENSSL_NO_SRTP +#endif +#ifndef OPENSSL_NO_SSL_TRACE +#define OPENSSL_NO_SSL_TRACE +#endif +#ifndef OPENSSL_NO_SSL3 +#define OPENSSL_NO_SSL3 +#endif +#ifndef OPENSSL_NO_SSL3_METHOD +#define OPENSSL_NO_SSL3_METHOD +#endif +#ifndef OPENSSL_NO_SSLKEYLOG +#define OPENSSL_NO_SSLKEYLOG +#endif +#ifndef OPENSSL_NO_STDIO +#define OPENSSL_NO_STDIO +#endif +#ifndef OPENSSL_NO_TESTS +#define OPENSSL_NO_TESTS +#endif +#ifndef OPENSSL_NO_TFO +#define OPENSSL_NO_TFO +#endif +#ifndef OPENSSL_NO_THREAD_POOL +#define OPENSSL_NO_THREAD_POOL +#endif +#ifndef OPENSSL_NO_TLS_DEPRECATED_EC +#define OPENSSL_NO_TLS_DEPRECATED_EC +#endif +#ifndef OPENSSL_NO_TLS1_3 +#define OPENSSL_NO_TLS1_3 +#endif +#ifndef OPENSSL_NO_TRACE +#define OPENSSL_NO_TRACE +#endif +#ifndef OPENSSL_NO_TS +#define OPENSSL_NO_TS +#endif +#ifndef OPENSSL_NO_UBSAN +#define OPENSSL_NO_UBSAN +#endif +#ifndef OPENSSL_NO_UI_CONSOLE +#define OPENSSL_NO_UI_CONSOLE +#endif +#ifndef OPENSSL_NO_UNIT_TEST +#define OPENSSL_NO_UNIT_TEST +#endif +#ifndef OPENSSL_NO_UNSTABLE_QLOG +#define OPENSSL_NO_UNSTABLE_QLOG +#endif +#ifndef OPENSSL_NO_UPLINK +#define OPENSSL_NO_UPLINK +#endif +#ifndef OPENSSL_NO_WEAK_SSL_CIPHERS +#define OPENSSL_NO_WEAK_SSL_CIPHERS +#endif +#ifndef OPENSSL_NO_WHIRLPOOL +#define OPENSSL_NO_WHIRLPOOL +#endif +#ifndef OPENSSL_NO_WINSTORE +#define OPENSSL_NO_WINSTORE +#endif +#ifndef OPENSSL_NO_ZLIB +#define OPENSSL_NO_ZLIB +#endif +#ifndef OPENSSL_NO_ZLIB_DYNAMIC +#define OPENSSL_NO_ZLIB_DYNAMIC +#endif +#ifndef OPENSSL_NO_ZSTD +#define OPENSSL_NO_ZSTD +#endif +#ifndef OPENSSL_NO_ZSTD_DYNAMIC +#define OPENSSL_NO_ZSTD_DYNAMIC +#endif +#ifndef OPENSSL_NO_DYNAMIC_ENGINE +#define OPENSSL_NO_DYNAMIC_ENGINE +#endif + +/* Generate 80386 code? */ +#undef I386_ONLY + +/* + * The following are cipher-specific, but are part of the public API. + */ +#if !defined (OPENSSL_SYS_UEFI) + #undef BN_LLONG +/* Only one for the following should be defined */ + #undef SIXTY_FOUR_BIT_LONG + #undef SIXTY_FOUR_BIT +#define THIRTY_TWO_BIT +#endif + +#define RC4_INT unsigned int + +#if defined (OPENSSL_NO_COMP) || (defined (OPENSSL_NO_BROTLI) && defined (OPENSSL_NO_ZSTD) && defined (OPENSSL_NO_ZLIB)) +#define OPENSSL_NO_COMP_ALG +#else + #undef OPENSSL_NO_COMP_ALG +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* OPENSSL_CONFIGURATION_H */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration.h index 5897c43614..e7d6059343 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration.h @@ -1,5 +1,7 @@ -#ifdef EDK2_OPENSSL_NOEC +#if defined(EDK2_OPENSSL_NOEC) # include "configuration-noec.h" +#elif defined(EDK2_OPENSSL_LITE) +# include "configuration-ec-lite.h" #else # include "configuration-ec.h" #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccelLite.inf b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccelLite.inf new file mode 100644 index 0000000000..88f60e1455 --- /dev/null +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccelLite.inf @@ -0,0 +1,2356 @@ +## @file +# This module provides OpenSSL Library implementation with ECC and TLS +# features along with performance optimized implementations of SHA1, +# SHA256, SHA512 AESNI, VPAED, and GHASH for IA32 and X64 and AARCH64, +# but without Camellia. +# +# This library should be used if a module module needs ECC in TLS, or +# asymmetric cryptography services such as X509 certificate or PEM format +# data processing. This is lite version (no-camellia, no-dh, no-ecx). +# This library decreases the size up to ~192 KB +# compared to OpensslLibAccel.inf library instance. +# +# Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved.
+# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023 - 2024, Arm Limited. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = OpensslLibFullAccelLite + MODULE_UNI_FILE = OpensslLibFullAccelLite.uni + FILE_GUID = D5DB5111-4A45-4F16-ACFD-3AD31C8C1AAC + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = OpensslLib + CONSTRUCTOR = OpensslLibConstructor + + DEFINE OPENSSL_PATH = openssl + DEFINE OPENSSL_GEN_PATH = OpensslGen + DEFINE OPENSSL_FLAGS = -DL_ENDIAN -DOPENSSL_SMALL_FOOTPRINT -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D OPENSSL_NO_INLINE_ASM -DEDK2_OPENSSL_LITE=1 + DEFINE OPENSSL_FLAGS_IA32 = -DAES_ASM -DGHASH_ASM -DMD5_ASM -DOPENSSL_CPUID_OBJ -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DVPAES_ASM + DEFINE OPENSSL_FLAGS_X64 = -DAES_ASM -DBSAES_ASM -DGHASH_ASM -DKECCAK1600_ASM -DMD5_ASM -DOPENSSL_CPUID_OBJ -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DVPAES_ASM + DEFINE OPENSSL_FLAGS_AARCH64 = -DBSAES_ASM -DKECCAK1600_ASM -DMD5_ASM -DOPENSSL_CPUID_OBJ -DOPENSSL_SM3_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DVPAES_ASM + +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# + +[Sources] + OpensslLibConstructor.c + $(OPENSSL_PATH)/ms/uplink.h + $(OPENSSL_PATH)/crypto/bn/bn_asm.c +# Autogenerated files list starts here +# Autogenerated files list ends here + buildinf.h + buildinf.c + OpensslStub/ossl_store.c + OpensslStub/rand_pool.c +# OpensslStub/SslNull.c +# OpensslStub/EcSm2Null.c + OpensslStub/uefiprov.c + OpensslStub/EncoderNull.c + OpensslStub/SslStatServNull.c + OpensslStub/SslExtServNull.c + OpensslStub/CamelliaNull.c + OpensslStub/DhNull.c + +[Sources.IA32] +# Autogenerated files list starts here + $(OPENSSL_PATH)/crypto/aes/aes_cfb.c + $(OPENSSL_PATH)/crypto/aes/aes_ecb.c + $(OPENSSL_PATH)/crypto/aes/aes_ige.c + $(OPENSSL_PATH)/crypto/aes/aes_misc.c + $(OPENSSL_PATH)/crypto/aes/aes_ofb.c + $(OPENSSL_PATH)/crypto/aes/aes_wrap.c + $(OPENSSL_PATH)/crypto/asn1/a_bitstr.c + $(OPENSSL_PATH)/crypto/asn1/a_d2i_fp.c + $(OPENSSL_PATH)/crypto/asn1/a_digest.c + $(OPENSSL_PATH)/crypto/asn1/a_dup.c + $(OPENSSL_PATH)/crypto/asn1/a_gentm.c + $(OPENSSL_PATH)/crypto/asn1/a_i2d_fp.c + $(OPENSSL_PATH)/crypto/asn1/a_int.c + $(OPENSSL_PATH)/crypto/asn1/a_mbstr.c + $(OPENSSL_PATH)/crypto/asn1/a_object.c + $(OPENSSL_PATH)/crypto/asn1/a_octet.c + $(OPENSSL_PATH)/crypto/asn1/a_print.c + $(OPENSSL_PATH)/crypto/asn1/a_sign.c + $(OPENSSL_PATH)/crypto/asn1/a_strex.c + $(OPENSSL_PATH)/crypto/asn1/a_strnid.c + $(OPENSSL_PATH)/crypto/asn1/a_time.c + $(OPENSSL_PATH)/crypto/asn1/a_type.c + $(OPENSSL_PATH)/crypto/asn1/a_utctm.c + $(OPENSSL_PATH)/crypto/asn1/a_utf8.c + $(OPENSSL_PATH)/crypto/asn1/a_verify.c + $(OPENSSL_PATH)/crypto/asn1/ameth_lib.c + $(OPENSSL_PATH)/crypto/asn1/asn1_err.c + $(OPENSSL_PATH)/crypto/asn1/asn1_gen.c + $(OPENSSL_PATH)/crypto/asn1/asn1_item_list.c + $(OPENSSL_PATH)/crypto/asn1/asn1_lib.c + $(OPENSSL_PATH)/crypto/asn1/asn1_parse.c + $(OPENSSL_PATH)/crypto/asn1/asn_mime.c + $(OPENSSL_PATH)/crypto/asn1/asn_moid.c + $(OPENSSL_PATH)/crypto/asn1/asn_mstbl.c + $(OPENSSL_PATH)/crypto/asn1/asn_pack.c + $(OPENSSL_PATH)/crypto/asn1/bio_asn1.c + $(OPENSSL_PATH)/crypto/asn1/bio_ndef.c + $(OPENSSL_PATH)/crypto/asn1/d2i_param.c + $(OPENSSL_PATH)/crypto/asn1/d2i_pr.c + $(OPENSSL_PATH)/crypto/asn1/d2i_pu.c + $(OPENSSL_PATH)/crypto/asn1/evp_asn1.c + $(OPENSSL_PATH)/crypto/asn1/f_int.c + $(OPENSSL_PATH)/crypto/asn1/f_string.c + $(OPENSSL_PATH)/crypto/asn1/i2d_evp.c + $(OPENSSL_PATH)/crypto/asn1/nsseq.c + $(OPENSSL_PATH)/crypto/asn1/p5_pbe.c + $(OPENSSL_PATH)/crypto/asn1/p5_pbev2.c + $(OPENSSL_PATH)/crypto/asn1/p5_scrypt.c + $(OPENSSL_PATH)/crypto/asn1/p8_pkey.c + $(OPENSSL_PATH)/crypto/asn1/t_bitst.c + $(OPENSSL_PATH)/crypto/asn1/t_pkey.c + $(OPENSSL_PATH)/crypto/asn1/t_spki.c + $(OPENSSL_PATH)/crypto/asn1/tasn_dec.c + $(OPENSSL_PATH)/crypto/asn1/tasn_enc.c + $(OPENSSL_PATH)/crypto/asn1/tasn_fre.c + $(OPENSSL_PATH)/crypto/asn1/tasn_new.c + $(OPENSSL_PATH)/crypto/asn1/tasn_prn.c + $(OPENSSL_PATH)/crypto/asn1/tasn_scn.c + $(OPENSSL_PATH)/crypto/asn1/tasn_typ.c + $(OPENSSL_PATH)/crypto/asn1/tasn_utl.c + $(OPENSSL_PATH)/crypto/asn1/x_algor.c + $(OPENSSL_PATH)/crypto/asn1/x_bignum.c + $(OPENSSL_PATH)/crypto/asn1/x_info.c + $(OPENSSL_PATH)/crypto/asn1/x_int64.c + $(OPENSSL_PATH)/crypto/asn1/x_long.c + $(OPENSSL_PATH)/crypto/asn1/x_pkey.c + $(OPENSSL_PATH)/crypto/asn1/x_sig.c + $(OPENSSL_PATH)/crypto/asn1/x_spki.c + $(OPENSSL_PATH)/crypto/asn1/x_val.c + $(OPENSSL_PATH)/crypto/async/arch/async_null.c + $(OPENSSL_PATH)/crypto/async/arch/async_posix.c + $(OPENSSL_PATH)/crypto/async/arch/async_win.c + $(OPENSSL_PATH)/crypto/async/async.c + $(OPENSSL_PATH)/crypto/async/async_err.c + $(OPENSSL_PATH)/crypto/async/async_wait.c + $(OPENSSL_PATH)/crypto/bio/bf_buff.c + $(OPENSSL_PATH)/crypto/bio/bf_lbuf.c + $(OPENSSL_PATH)/crypto/bio/bf_nbio.c + $(OPENSSL_PATH)/crypto/bio/bf_null.c + $(OPENSSL_PATH)/crypto/bio/bf_prefix.c + $(OPENSSL_PATH)/crypto/bio/bf_readbuff.c + $(OPENSSL_PATH)/crypto/bio/bio_addr.c + $(OPENSSL_PATH)/crypto/bio/bio_cb.c + $(OPENSSL_PATH)/crypto/bio/bio_dump.c + $(OPENSSL_PATH)/crypto/bio/bio_err.c + $(OPENSSL_PATH)/crypto/bio/bio_lib.c + $(OPENSSL_PATH)/crypto/bio/bio_meth.c + $(OPENSSL_PATH)/crypto/bio/bio_print.c + $(OPENSSL_PATH)/crypto/bio/bio_sock.c + $(OPENSSL_PATH)/crypto/bio/bio_sock2.c + $(OPENSSL_PATH)/crypto/bio/bss_acpt.c + $(OPENSSL_PATH)/crypto/bio/bss_bio.c + $(OPENSSL_PATH)/crypto/bio/bss_conn.c + $(OPENSSL_PATH)/crypto/bio/bss_core.c + $(OPENSSL_PATH)/crypto/bio/bss_dgram.c + $(OPENSSL_PATH)/crypto/bio/bss_dgram_pair.c + $(OPENSSL_PATH)/crypto/bio/bss_fd.c + $(OPENSSL_PATH)/crypto/bio/bss_file.c + $(OPENSSL_PATH)/crypto/bio/bss_log.c + $(OPENSSL_PATH)/crypto/bio/bss_mem.c + $(OPENSSL_PATH)/crypto/bio/bss_null.c + $(OPENSSL_PATH)/crypto/bio/bss_sock.c + $(OPENSSL_PATH)/crypto/bio/ossl_core_bio.c + $(OPENSSL_PATH)/crypto/bn/bn_add.c + $(OPENSSL_PATH)/crypto/bn/bn_blind.c + $(OPENSSL_PATH)/crypto/bn/bn_const.c + $(OPENSSL_PATH)/crypto/bn/bn_conv.c + $(OPENSSL_PATH)/crypto/bn/bn_ctx.c + $(OPENSSL_PATH)/crypto/bn/bn_dh.c + $(OPENSSL_PATH)/crypto/bn/bn_div.c + $(OPENSSL_PATH)/crypto/bn/bn_err.c + $(OPENSSL_PATH)/crypto/bn/bn_exp.c + $(OPENSSL_PATH)/crypto/bn/bn_exp2.c + $(OPENSSL_PATH)/crypto/bn/bn_gcd.c + $(OPENSSL_PATH)/crypto/bn/bn_gf2m.c + $(OPENSSL_PATH)/crypto/bn/bn_intern.c + $(OPENSSL_PATH)/crypto/bn/bn_kron.c + $(OPENSSL_PATH)/crypto/bn/bn_lib.c + $(OPENSSL_PATH)/crypto/bn/bn_mod.c + $(OPENSSL_PATH)/crypto/bn/bn_mont.c + $(OPENSSL_PATH)/crypto/bn/bn_mpi.c + $(OPENSSL_PATH)/crypto/bn/bn_mul.c + $(OPENSSL_PATH)/crypto/bn/bn_nist.c + $(OPENSSL_PATH)/crypto/bn/bn_prime.c + $(OPENSSL_PATH)/crypto/bn/bn_print.c + $(OPENSSL_PATH)/crypto/bn/bn_rand.c + $(OPENSSL_PATH)/crypto/bn/bn_recp.c + $(OPENSSL_PATH)/crypto/bn/bn_rsa_fips186_4.c + $(OPENSSL_PATH)/crypto/bn/bn_shift.c + $(OPENSSL_PATH)/crypto/bn/bn_sqr.c + $(OPENSSL_PATH)/crypto/bn/bn_sqrt.c + $(OPENSSL_PATH)/crypto/bn/bn_srp.c + $(OPENSSL_PATH)/crypto/bn/bn_word.c + $(OPENSSL_PATH)/crypto/bn/bn_x931p.c + $(OPENSSL_PATH)/crypto/buffer/buf_err.c + $(OPENSSL_PATH)/crypto/buffer/buffer.c + $(OPENSSL_PATH)/crypto/cmac/cmac.c + $(OPENSSL_PATH)/crypto/comp/c_brotli.c + $(OPENSSL_PATH)/crypto/comp/c_zlib.c + $(OPENSSL_PATH)/crypto/comp/c_zstd.c + $(OPENSSL_PATH)/crypto/comp/comp_err.c + $(OPENSSL_PATH)/crypto/comp/comp_lib.c + $(OPENSSL_PATH)/crypto/conf/conf_api.c + $(OPENSSL_PATH)/crypto/conf/conf_def.c + $(OPENSSL_PATH)/crypto/conf/conf_err.c + $(OPENSSL_PATH)/crypto/conf/conf_lib.c + $(OPENSSL_PATH)/crypto/conf/conf_mall.c + $(OPENSSL_PATH)/crypto/conf/conf_mod.c + $(OPENSSL_PATH)/crypto/conf/conf_sap.c + $(OPENSSL_PATH)/crypto/conf/conf_ssl.c + $(OPENSSL_PATH)/crypto/dso/dso_dl.c + $(OPENSSL_PATH)/crypto/dso/dso_dlfcn.c + $(OPENSSL_PATH)/crypto/dso/dso_err.c + $(OPENSSL_PATH)/crypto/dso/dso_lib.c + $(OPENSSL_PATH)/crypto/dso/dso_openssl.c + $(OPENSSL_PATH)/crypto/dso/dso_vms.c + $(OPENSSL_PATH)/crypto/dso/dso_win32.c + $(OPENSSL_PATH)/crypto/ec/ec2_oct.c + $(OPENSSL_PATH)/crypto/ec/ec2_smpl.c + $(OPENSSL_PATH)/crypto/ec/ec_ameth.c + $(OPENSSL_PATH)/crypto/ec/ec_asn1.c + $(OPENSSL_PATH)/crypto/ec/ec_backend.c + $(OPENSSL_PATH)/crypto/ec/ec_check.c + $(OPENSSL_PATH)/crypto/ec/ec_curve.c + $(OPENSSL_PATH)/crypto/ec/ec_cvt.c + $(OPENSSL_PATH)/crypto/ec/ec_deprecated.c + $(OPENSSL_PATH)/crypto/ec/ec_err.c + $(OPENSSL_PATH)/crypto/ec/ec_key.c + $(OPENSSL_PATH)/crypto/ec/ec_kmeth.c + $(OPENSSL_PATH)/crypto/ec/ec_lib.c + $(OPENSSL_PATH)/crypto/ec/ec_mult.c + $(OPENSSL_PATH)/crypto/ec/ec_oct.c + $(OPENSSL_PATH)/crypto/ec/ec_pmeth.c + $(OPENSSL_PATH)/crypto/ec/ec_print.c + $(OPENSSL_PATH)/crypto/ec/ecdh_kdf.c + $(OPENSSL_PATH)/crypto/ec/ecdh_ossl.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_ossl.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_sign.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_vrf.c + $(OPENSSL_PATH)/crypto/ec/eck_prn.c + $(OPENSSL_PATH)/crypto/ec/ecp_mont.c + $(OPENSSL_PATH)/crypto/ec/ecp_nist.c + $(OPENSSL_PATH)/crypto/ec/ecp_oct.c + $(OPENSSL_PATH)/crypto/ec/ecp_smpl.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_err.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_lib.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_meth.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_pkey.c + $(OPENSSL_PATH)/crypto/err/err.c + $(OPENSSL_PATH)/crypto/err/err_all.c + $(OPENSSL_PATH)/crypto/err/err_all_legacy.c + $(OPENSSL_PATH)/crypto/err/err_blocks.c + $(OPENSSL_PATH)/crypto/err/err_mark.c + $(OPENSSL_PATH)/crypto/err/err_prn.c + $(OPENSSL_PATH)/crypto/err/err_save.c + $(OPENSSL_PATH)/crypto/ess/ess_asn1.c + $(OPENSSL_PATH)/crypto/ess/ess_err.c + $(OPENSSL_PATH)/crypto/ess/ess_lib.c + $(OPENSSL_PATH)/crypto/evp/asymcipher.c + $(OPENSSL_PATH)/crypto/evp/bio_b64.c + $(OPENSSL_PATH)/crypto/evp/bio_enc.c + $(OPENSSL_PATH)/crypto/evp/bio_md.c + $(OPENSSL_PATH)/crypto/evp/bio_ok.c + $(OPENSSL_PATH)/crypto/evp/c_allc.c + $(OPENSSL_PATH)/crypto/evp/c_alld.c + $(OPENSSL_PATH)/crypto/evp/cmeth_lib.c + $(OPENSSL_PATH)/crypto/evp/ctrl_params_translate.c + $(OPENSSL_PATH)/crypto/evp/dh_ctrl.c + $(OPENSSL_PATH)/crypto/evp/dh_support.c + $(OPENSSL_PATH)/crypto/evp/digest.c + $(OPENSSL_PATH)/crypto/evp/dsa_ctrl.c + $(OPENSSL_PATH)/crypto/evp/e_aes.c + $(OPENSSL_PATH)/crypto/evp/e_aes_cbc_hmac_sha1.c + $(OPENSSL_PATH)/crypto/evp/e_aes_cbc_hmac_sha256.c + $(OPENSSL_PATH)/crypto/evp/e_aria.c + $(OPENSSL_PATH)/crypto/evp/e_bf.c + $(OPENSSL_PATH)/crypto/evp/e_cast.c + $(OPENSSL_PATH)/crypto/evp/e_chacha20_poly1305.c + $(OPENSSL_PATH)/crypto/evp/e_des.c + $(OPENSSL_PATH)/crypto/evp/e_des3.c + $(OPENSSL_PATH)/crypto/evp/e_idea.c + $(OPENSSL_PATH)/crypto/evp/e_null.c + $(OPENSSL_PATH)/crypto/evp/e_rc2.c + $(OPENSSL_PATH)/crypto/evp/e_rc4.c + $(OPENSSL_PATH)/crypto/evp/e_rc4_hmac_md5.c + $(OPENSSL_PATH)/crypto/evp/e_rc5.c + $(OPENSSL_PATH)/crypto/evp/e_sm4.c + $(OPENSSL_PATH)/crypto/evp/e_xcbc_d.c + $(OPENSSL_PATH)/crypto/evp/ec_ctrl.c + $(OPENSSL_PATH)/crypto/evp/ec_support.c + $(OPENSSL_PATH)/crypto/evp/encode.c + $(OPENSSL_PATH)/crypto/evp/evp_cnf.c + $(OPENSSL_PATH)/crypto/evp/evp_enc.c + $(OPENSSL_PATH)/crypto/evp/evp_err.c + $(OPENSSL_PATH)/crypto/evp/evp_fetch.c + $(OPENSSL_PATH)/crypto/evp/evp_key.c + $(OPENSSL_PATH)/crypto/evp/evp_lib.c + $(OPENSSL_PATH)/crypto/evp/evp_pbe.c + $(OPENSSL_PATH)/crypto/evp/evp_pkey.c + $(OPENSSL_PATH)/crypto/evp/evp_rand.c + $(OPENSSL_PATH)/crypto/evp/evp_utils.c + $(OPENSSL_PATH)/crypto/evp/exchange.c + $(OPENSSL_PATH)/crypto/evp/kdf_lib.c + $(OPENSSL_PATH)/crypto/evp/kdf_meth.c + $(OPENSSL_PATH)/crypto/evp/kem.c + $(OPENSSL_PATH)/crypto/evp/keymgmt_lib.c + $(OPENSSL_PATH)/crypto/evp/keymgmt_meth.c + $(OPENSSL_PATH)/crypto/evp/legacy_md5.c + $(OPENSSL_PATH)/crypto/evp/legacy_md5_sha1.c + $(OPENSSL_PATH)/crypto/evp/legacy_sha.c + $(OPENSSL_PATH)/crypto/evp/m_null.c + $(OPENSSL_PATH)/crypto/evp/m_sigver.c + $(OPENSSL_PATH)/crypto/evp/mac_lib.c + $(OPENSSL_PATH)/crypto/evp/mac_meth.c + $(OPENSSL_PATH)/crypto/evp/names.c + $(OPENSSL_PATH)/crypto/evp/p5_crpt.c + $(OPENSSL_PATH)/crypto/evp/p5_crpt2.c + $(OPENSSL_PATH)/crypto/evp/p_dec.c + $(OPENSSL_PATH)/crypto/evp/p_enc.c + $(OPENSSL_PATH)/crypto/evp/p_legacy.c + $(OPENSSL_PATH)/crypto/evp/p_lib.c + $(OPENSSL_PATH)/crypto/evp/p_open.c + $(OPENSSL_PATH)/crypto/evp/p_seal.c + $(OPENSSL_PATH)/crypto/evp/p_sign.c + $(OPENSSL_PATH)/crypto/evp/p_verify.c + $(OPENSSL_PATH)/crypto/evp/pbe_scrypt.c + $(OPENSSL_PATH)/crypto/evp/pmeth_check.c + $(OPENSSL_PATH)/crypto/evp/pmeth_gn.c + $(OPENSSL_PATH)/crypto/evp/pmeth_lib.c + $(OPENSSL_PATH)/crypto/evp/s_lib.c + $(OPENSSL_PATH)/crypto/evp/signature.c + $(OPENSSL_PATH)/crypto/evp/skeymgmt_meth.c + $(OPENSSL_PATH)/crypto/ffc/ffc_backend.c + $(OPENSSL_PATH)/crypto/ffc/ffc_dh.c + $(OPENSSL_PATH)/crypto/ffc/ffc_key_generate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_key_validate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params_generate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params_validate.c + $(OPENSSL_PATH)/crypto/hashtable/hashfunc.c + $(OPENSSL_PATH)/crypto/hashtable/hashtable.c + $(OPENSSL_PATH)/crypto/hmac/hmac.c + $(OPENSSL_PATH)/crypto/hpke/hpke.c + $(OPENSSL_PATH)/crypto/hpke/hpke_util.c + $(OPENSSL_PATH)/crypto/http/http_client.c + $(OPENSSL_PATH)/crypto/http/http_err.c + $(OPENSSL_PATH)/crypto/http/http_lib.c + $(OPENSSL_PATH)/crypto/kdf/kdf_err.c + $(OPENSSL_PATH)/crypto/lhash/lh_stats.c + $(OPENSSL_PATH)/crypto/lhash/lhash.c + $(OPENSSL_PATH)/crypto/asn1_dsa.c + $(OPENSSL_PATH)/crypto/bsearch.c + $(OPENSSL_PATH)/crypto/comp_methods.c + $(OPENSSL_PATH)/crypto/context.c + $(OPENSSL_PATH)/crypto/core_algorithm.c + $(OPENSSL_PATH)/crypto/core_fetch.c + $(OPENSSL_PATH)/crypto/core_namemap.c + $(OPENSSL_PATH)/crypto/cpt_err.c + $(OPENSSL_PATH)/crypto/cpuid.c + $(OPENSSL_PATH)/crypto/cryptlib.c + $(OPENSSL_PATH)/crypto/ctype.c + $(OPENSSL_PATH)/crypto/cversion.c + $(OPENSSL_PATH)/crypto/defaults.c + $(OPENSSL_PATH)/crypto/der_writer.c + $(OPENSSL_PATH)/crypto/deterministic_nonce.c + $(OPENSSL_PATH)/crypto/ebcdic.c + $(OPENSSL_PATH)/crypto/ex_data.c + $(OPENSSL_PATH)/crypto/getenv.c + $(OPENSSL_PATH)/crypto/indicator_core.c + $(OPENSSL_PATH)/crypto/info.c + $(OPENSSL_PATH)/crypto/init.c + $(OPENSSL_PATH)/crypto/initthread.c + $(OPENSSL_PATH)/crypto/mem.c + $(OPENSSL_PATH)/crypto/mem_sec.c + $(OPENSSL_PATH)/crypto/o_dir.c + $(OPENSSL_PATH)/crypto/o_fopen.c + $(OPENSSL_PATH)/crypto/o_init.c + $(OPENSSL_PATH)/crypto/o_str.c + $(OPENSSL_PATH)/crypto/o_time.c + $(OPENSSL_PATH)/crypto/packet.c + $(OPENSSL_PATH)/crypto/param_build.c + $(OPENSSL_PATH)/crypto/param_build_set.c + $(OPENSSL_PATH)/crypto/params.c + $(OPENSSL_PATH)/crypto/params_dup.c + $(OPENSSL_PATH)/crypto/params_from_text.c + $(OPENSSL_PATH)/crypto/passphrase.c + $(OPENSSL_PATH)/crypto/provider.c + $(OPENSSL_PATH)/crypto/provider_child.c + $(OPENSSL_PATH)/crypto/provider_conf.c + $(OPENSSL_PATH)/crypto/provider_core.c + $(OPENSSL_PATH)/crypto/punycode.c + $(OPENSSL_PATH)/crypto/quic_vlint.c + $(OPENSSL_PATH)/crypto/self_test_core.c + $(OPENSSL_PATH)/crypto/sleep.c + $(OPENSSL_PATH)/crypto/sparse_array.c + $(OPENSSL_PATH)/crypto/ssl_err.c + $(OPENSSL_PATH)/crypto/threads_lib.c + $(OPENSSL_PATH)/crypto/threads_none.c + $(OPENSSL_PATH)/crypto/threads_pthread.c + $(OPENSSL_PATH)/crypto/threads_win.c + $(OPENSSL_PATH)/crypto/time.c + $(OPENSSL_PATH)/crypto/trace.c + $(OPENSSL_PATH)/crypto/uid.c + $(OPENSSL_PATH)/crypto/md5/md5_dgst.c + $(OPENSSL_PATH)/crypto/md5/md5_one.c + $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/modes/cbc128.c + $(OPENSSL_PATH)/crypto/modes/ccm128.c + $(OPENSSL_PATH)/crypto/modes/cfb128.c + $(OPENSSL_PATH)/crypto/modes/ctr128.c + $(OPENSSL_PATH)/crypto/modes/cts128.c + $(OPENSSL_PATH)/crypto/modes/gcm128.c + $(OPENSSL_PATH)/crypto/modes/ocb128.c + $(OPENSSL_PATH)/crypto/modes/ofb128.c + $(OPENSSL_PATH)/crypto/modes/siv128.c + $(OPENSSL_PATH)/crypto/modes/wrap128.c + $(OPENSSL_PATH)/crypto/modes/xts128.c + $(OPENSSL_PATH)/crypto/modes/xts128gb.c + $(OPENSSL_PATH)/crypto/objects/o_names.c + $(OPENSSL_PATH)/crypto/objects/obj_dat.c + $(OPENSSL_PATH)/crypto/objects/obj_err.c + $(OPENSSL_PATH)/crypto/objects/obj_lib.c + $(OPENSSL_PATH)/crypto/objects/obj_xref.c + $(OPENSSL_PATH)/crypto/pem/pem_all.c + $(OPENSSL_PATH)/crypto/pem/pem_err.c + $(OPENSSL_PATH)/crypto/pem/pem_info.c + $(OPENSSL_PATH)/crypto/pem/pem_lib.c + $(OPENSSL_PATH)/crypto/pem/pem_oth.c + $(OPENSSL_PATH)/crypto/pem/pem_pk8.c + $(OPENSSL_PATH)/crypto/pem/pem_pkey.c + $(OPENSSL_PATH)/crypto/pem/pem_sign.c + $(OPENSSL_PATH)/crypto/pem/pem_x509.c + $(OPENSSL_PATH)/crypto/pem/pem_xaux.c + $(OPENSSL_PATH)/crypto/pem/pvkfmt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_add.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_asn.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_attr.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_crpt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_crt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_decr.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_init.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_key.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_kiss.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_mutl.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_npas.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_p8d.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_p8e.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_sbag.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_utl.c + $(OPENSSL_PATH)/crypto/pkcs12/pk12err.c + $(OPENSSL_PATH)/crypto/pkcs7/bio_pk7.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_asn1.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_attr.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_doit.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_lib.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_mime.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_smime.c + $(OPENSSL_PATH)/crypto/pkcs7/pkcs7err.c + $(OPENSSL_PATH)/crypto/property/defn_cache.c + $(OPENSSL_PATH)/crypto/property/property.c + $(OPENSSL_PATH)/crypto/property/property_err.c + $(OPENSSL_PATH)/crypto/property/property_parse.c + $(OPENSSL_PATH)/crypto/property/property_query.c + $(OPENSSL_PATH)/crypto/property/property_string.c + $(OPENSSL_PATH)/crypto/rand/prov_seed.c + $(OPENSSL_PATH)/crypto/rand/rand_deprecated.c + $(OPENSSL_PATH)/crypto/rand/rand_err.c + $(OPENSSL_PATH)/crypto/rand/rand_lib.c + $(OPENSSL_PATH)/crypto/rand/rand_meth.c + $(OPENSSL_PATH)/crypto/rand/rand_pool.c + $(OPENSSL_PATH)/crypto/rand/rand_uniform.c + $(OPENSSL_PATH)/crypto/rsa/rsa_ameth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_asn1.c + $(OPENSSL_PATH)/crypto/rsa/rsa_backend.c + $(OPENSSL_PATH)/crypto/rsa/rsa_chk.c + $(OPENSSL_PATH)/crypto/rsa/rsa_crpt.c + $(OPENSSL_PATH)/crypto/rsa/rsa_err.c + $(OPENSSL_PATH)/crypto/rsa/rsa_gen.c + $(OPENSSL_PATH)/crypto/rsa/rsa_lib.c + $(OPENSSL_PATH)/crypto/rsa/rsa_meth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_mp.c + $(OPENSSL_PATH)/crypto/rsa/rsa_mp_names.c + $(OPENSSL_PATH)/crypto/rsa/rsa_none.c + $(OPENSSL_PATH)/crypto/rsa/rsa_oaep.c + $(OPENSSL_PATH)/crypto/rsa/rsa_ossl.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pk1.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pmeth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_prn.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pss.c + $(OPENSSL_PATH)/crypto/rsa/rsa_saos.c + $(OPENSSL_PATH)/crypto/rsa/rsa_schemes.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sign.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sp800_56b_check.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sp800_56b_gen.c + $(OPENSSL_PATH)/crypto/rsa/rsa_x931.c + $(OPENSSL_PATH)/crypto/rsa/rsa_x931g.c + $(OPENSSL_PATH)/crypto/sha/keccak1600.c + $(OPENSSL_PATH)/crypto/sha/sha1_one.c + $(OPENSSL_PATH)/crypto/sha/sha1dgst.c + $(OPENSSL_PATH)/crypto/sha/sha256.c + $(OPENSSL_PATH)/crypto/sha/sha3.c + $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c + $(OPENSSL_PATH)/crypto/sm3/sm3.c + $(OPENSSL_PATH)/crypto/stack/stack.c + $(OPENSSL_PATH)/crypto/thread/arch/thread_win.c + $(OPENSSL_PATH)/crypto/thread/api.c + $(OPENSSL_PATH)/crypto/txt_db/txt_db.c + $(OPENSSL_PATH)/crypto/ui/ui_err.c + $(OPENSSL_PATH)/crypto/ui/ui_lib.c + $(OPENSSL_PATH)/crypto/ui/ui_null.c + $(OPENSSL_PATH)/crypto/ui/ui_openssl.c + $(OPENSSL_PATH)/crypto/ui/ui_util.c + $(OPENSSL_PATH)/crypto/x509/by_dir.c + $(OPENSSL_PATH)/crypto/x509/by_file.c + $(OPENSSL_PATH)/crypto/x509/by_store.c + $(OPENSSL_PATH)/crypto/x509/pcy_cache.c + $(OPENSSL_PATH)/crypto/x509/pcy_data.c + $(OPENSSL_PATH)/crypto/x509/pcy_lib.c + $(OPENSSL_PATH)/crypto/x509/pcy_map.c + $(OPENSSL_PATH)/crypto/x509/pcy_node.c + $(OPENSSL_PATH)/crypto/x509/pcy_tree.c + $(OPENSSL_PATH)/crypto/x509/t_acert.c + $(OPENSSL_PATH)/crypto/x509/t_crl.c + $(OPENSSL_PATH)/crypto/x509/t_req.c + $(OPENSSL_PATH)/crypto/x509/t_x509.c + $(OPENSSL_PATH)/crypto/x509/v3_aaa.c + $(OPENSSL_PATH)/crypto/x509/v3_ac_tgt.c + $(OPENSSL_PATH)/crypto/x509/v3_addr.c + $(OPENSSL_PATH)/crypto/x509/v3_admis.c + $(OPENSSL_PATH)/crypto/x509/v3_akeya.c + $(OPENSSL_PATH)/crypto/x509/v3_akid.c + $(OPENSSL_PATH)/crypto/x509/v3_asid.c + $(OPENSSL_PATH)/crypto/x509/v3_attrdesc.c + $(OPENSSL_PATH)/crypto/x509/v3_attrmap.c + $(OPENSSL_PATH)/crypto/x509/v3_audit_id.c + $(OPENSSL_PATH)/crypto/x509/v3_authattid.c + $(OPENSSL_PATH)/crypto/x509/v3_battcons.c + $(OPENSSL_PATH)/crypto/x509/v3_bcons.c + $(OPENSSL_PATH)/crypto/x509/v3_bitst.c + $(OPENSSL_PATH)/crypto/x509/v3_conf.c + $(OPENSSL_PATH)/crypto/x509/v3_cpols.c + $(OPENSSL_PATH)/crypto/x509/v3_crld.c + $(OPENSSL_PATH)/crypto/x509/v3_enum.c + $(OPENSSL_PATH)/crypto/x509/v3_extku.c + $(OPENSSL_PATH)/crypto/x509/v3_genn.c + $(OPENSSL_PATH)/crypto/x509/v3_group_ac.c + $(OPENSSL_PATH)/crypto/x509/v3_ia5.c + $(OPENSSL_PATH)/crypto/x509/v3_ind_iss.c + $(OPENSSL_PATH)/crypto/x509/v3_info.c + $(OPENSSL_PATH)/crypto/x509/v3_int.c + $(OPENSSL_PATH)/crypto/x509/v3_iobo.c + $(OPENSSL_PATH)/crypto/x509/v3_ist.c + $(OPENSSL_PATH)/crypto/x509/v3_lib.c + $(OPENSSL_PATH)/crypto/x509/v3_ncons.c + $(OPENSSL_PATH)/crypto/x509/v3_no_ass.c + $(OPENSSL_PATH)/crypto/x509/v3_no_rev_avail.c + $(OPENSSL_PATH)/crypto/x509/v3_pci.c + $(OPENSSL_PATH)/crypto/x509/v3_pcia.c + $(OPENSSL_PATH)/crypto/x509/v3_pcons.c + $(OPENSSL_PATH)/crypto/x509/v3_pku.c + $(OPENSSL_PATH)/crypto/x509/v3_pmaps.c + $(OPENSSL_PATH)/crypto/x509/v3_prn.c + $(OPENSSL_PATH)/crypto/x509/v3_purp.c + $(OPENSSL_PATH)/crypto/x509/v3_rolespec.c + $(OPENSSL_PATH)/crypto/x509/v3_san.c + $(OPENSSL_PATH)/crypto/x509/v3_sda.c + $(OPENSSL_PATH)/crypto/x509/v3_single_use.c + $(OPENSSL_PATH)/crypto/x509/v3_skid.c + $(OPENSSL_PATH)/crypto/x509/v3_soa_id.c + $(OPENSSL_PATH)/crypto/x509/v3_sxnet.c + $(OPENSSL_PATH)/crypto/x509/v3_timespec.c + $(OPENSSL_PATH)/crypto/x509/v3_tlsf.c + $(OPENSSL_PATH)/crypto/x509/v3_usernotice.c + $(OPENSSL_PATH)/crypto/x509/v3_utf8.c + $(OPENSSL_PATH)/crypto/x509/v3_utl.c + $(OPENSSL_PATH)/crypto/x509/v3err.c + $(OPENSSL_PATH)/crypto/x509/x509_acert.c + $(OPENSSL_PATH)/crypto/x509/x509_att.c + $(OPENSSL_PATH)/crypto/x509/x509_cmp.c + $(OPENSSL_PATH)/crypto/x509/x509_d2.c + $(OPENSSL_PATH)/crypto/x509/x509_def.c + $(OPENSSL_PATH)/crypto/x509/x509_err.c + $(OPENSSL_PATH)/crypto/x509/x509_ext.c + $(OPENSSL_PATH)/crypto/x509/x509_lu.c + $(OPENSSL_PATH)/crypto/x509/x509_meth.c + $(OPENSSL_PATH)/crypto/x509/x509_obj.c + $(OPENSSL_PATH)/crypto/x509/x509_r2x.c + $(OPENSSL_PATH)/crypto/x509/x509_req.c + $(OPENSSL_PATH)/crypto/x509/x509_set.c + $(OPENSSL_PATH)/crypto/x509/x509_trust.c + $(OPENSSL_PATH)/crypto/x509/x509_txt.c + $(OPENSSL_PATH)/crypto/x509/x509_v3.c + $(OPENSSL_PATH)/crypto/x509/x509_vfy.c + $(OPENSSL_PATH)/crypto/x509/x509_vpm.c + $(OPENSSL_PATH)/crypto/x509/x509aset.c + $(OPENSSL_PATH)/crypto/x509/x509cset.c + $(OPENSSL_PATH)/crypto/x509/x509name.c + $(OPENSSL_PATH)/crypto/x509/x509rset.c + $(OPENSSL_PATH)/crypto/x509/x509spki.c + $(OPENSSL_PATH)/crypto/x509/x509type.c + $(OPENSSL_PATH)/crypto/x509/x_all.c + $(OPENSSL_PATH)/crypto/x509/x_attrib.c + $(OPENSSL_PATH)/crypto/x509/x_crl.c + $(OPENSSL_PATH)/crypto/x509/x_exten.c + $(OPENSSL_PATH)/crypto/x509/x_ietfatt.c + $(OPENSSL_PATH)/crypto/x509/x_name.c + $(OPENSSL_PATH)/crypto/x509/x_pubkey.c + $(OPENSSL_PATH)/crypto/x509/x_req.c + $(OPENSSL_PATH)/crypto/x509/x_x509.c + $(OPENSSL_PATH)/crypto/x509/x_x509a.c + $(OPENSSL_PATH)/providers/nullprov.c + $(OPENSSL_PATH)/providers/prov_running.c + $(OPENSSL_PATH)/providers/common/der/der_rsa_sig.c + $(OPENSSL_PATH)/providers/common/bio_prov.c + $(OPENSSL_PATH)/providers/common/capabilities.c + $(OPENSSL_PATH)/providers/common/digest_to_nid.c + $(OPENSSL_PATH)/providers/common/provider_seeding.c + $(OPENSSL_PATH)/providers/common/provider_util.c + $(OPENSSL_PATH)/providers/common/securitycheck.c + $(OPENSSL_PATH)/providers/common/securitycheck_default.c + $(OPENSSL_PATH)/providers/implementations/asymciphers/rsa_enc.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha1_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha256_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_ccm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_ccm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_gcm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_gcm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_wrp.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts_fips.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_cts.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_null.c + $(OPENSSL_PATH)/providers/implementations/digests/md5_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/md5_sha1_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/null_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sha2_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sha3_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sm3_prov.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_der2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_epki2pki.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_msblob2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pem2der.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/exchange/ecdh_exch.c + $(OPENSSL_PATH)/providers/implementations/exchange/kdf_exch.c + $(OPENSSL_PATH)/providers/implementations/kdfs/argon2.c + $(OPENSSL_PATH)/providers/implementations/kdfs/hkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/hmacdrbg_kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/kbkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/krb5kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pbkdf2.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pbkdf2_fips.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pkcs12kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/scrypt.c + $(OPENSSL_PATH)/providers/implementations/kdfs/sshkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/sskdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/tls1_prf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/x942kdf.c + $(OPENSSL_PATH)/providers/implementations/kem/ec_kem.c + $(OPENSSL_PATH)/providers/implementations/kem/kem_util.c + $(OPENSSL_PATH)/providers/implementations/kem/rsa_kem.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ec_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/kmac_prov.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_ctr.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_hash.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_hmac.c + $(OPENSSL_PATH)/providers/implementations/rands/seed_src.c + $(OPENSSL_PATH)/providers/implementations/rands/seed_src_jitter.c + $(OPENSSL_PATH)/providers/implementations/rands/test_rng.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_cpu_x86.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_tsc.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_unix.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_win.c + $(OPENSSL_PATH)/providers/implementations/signature/ecdsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c + $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c + $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c + $(OPENSSL_GEN_PATH)/crypto/params_idx.c + $(OPENSSL_PATH)/providers/common/der/der_ec_key.c + $(OPENSSL_PATH)/providers/common/der/der_ec_sig.c + $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/provider_ctx.c + $(OPENSSL_PATH)/providers/common/provider_err.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_block.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_ccm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_ccm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_gcm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_gcm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_hw.c + $(OPENSSL_PATH)/providers/implementations/digests/digestcommon.c + $(OPENSSL_PATH)/ssl/record/methods/tls_pad.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ec_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c + $(OPENSSL_PATH)/ssl/bio_ssl.c + $(OPENSSL_PATH)/ssl/d1_lib.c + $(OPENSSL_PATH)/ssl/d1_msg.c + $(OPENSSL_PATH)/ssl/d1_srtp.c + $(OPENSSL_PATH)/ssl/methods.c + $(OPENSSL_PATH)/ssl/pqueue.c + $(OPENSSL_PATH)/ssl/s3_enc.c + $(OPENSSL_PATH)/ssl/s3_lib.c + $(OPENSSL_PATH)/ssl/s3_msg.c + $(OPENSSL_PATH)/ssl/ssl_asn1.c + $(OPENSSL_PATH)/ssl/ssl_cert.c + $(OPENSSL_PATH)/ssl/ssl_cert_comp.c + $(OPENSSL_PATH)/ssl/ssl_ciph.c + $(OPENSSL_PATH)/ssl/ssl_conf.c + $(OPENSSL_PATH)/ssl/ssl_err_legacy.c + $(OPENSSL_PATH)/ssl/ssl_init.c + $(OPENSSL_PATH)/ssl/ssl_lib.c + $(OPENSSL_PATH)/ssl/ssl_mcnf.c + $(OPENSSL_PATH)/ssl/ssl_rsa.c + $(OPENSSL_PATH)/ssl/ssl_rsa_legacy.c + $(OPENSSL_PATH)/ssl/ssl_sess.c + $(OPENSSL_PATH)/ssl/ssl_stat.c + $(OPENSSL_PATH)/ssl/ssl_txt.c + $(OPENSSL_PATH)/ssl/ssl_utst.c + $(OPENSSL_PATH)/ssl/t1_enc.c + $(OPENSSL_PATH)/ssl/t1_lib.c + $(OPENSSL_PATH)/ssl/t1_trce.c + $(OPENSSL_PATH)/ssl/tls13_enc.c + $(OPENSSL_PATH)/ssl/tls_depr.c + $(OPENSSL_PATH)/ssl/tls_srp.c + $(OPENSSL_PATH)/ssl/quic/quic_tls.c + $(OPENSSL_PATH)/ssl/quic/quic_tls_api.c + $(OPENSSL_PATH)/ssl/record/rec_layer_d1.c + $(OPENSSL_PATH)/ssl/record/rec_layer_s3.c + $(OPENSSL_PATH)/ssl/record/methods/dtls_meth.c + $(OPENSSL_PATH)/ssl/record/methods/ssl3_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls13_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls1_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls_common.c + $(OPENSSL_PATH)/ssl/record/methods/tls_multib.c + $(OPENSSL_PATH)/ssl/record/methods/tlsany_meth.c + $(OPENSSL_PATH)/ssl/rio/poll_immediate.c + $(OPENSSL_PATH)/ssl/statem/extensions.c + $(OPENSSL_PATH)/ssl/statem/extensions_clnt.c + $(OPENSSL_PATH)/ssl/statem/extensions_cust.c + $(OPENSSL_PATH)/ssl/statem/statem.c + $(OPENSSL_PATH)/ssl/statem/statem_clnt.c + $(OPENSSL_PATH)/ssl/statem/statem_dtls.c + $(OPENSSL_PATH)/ssl/statem/statem_lib.c + $(OPENSSL_GEN_PATH)/IA32-MSFT/crypto/aes/aes-586.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-MSFT/crypto/aes/aesni-x86.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-MSFT/crypto/aes/vpaes-x86.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-MSFT/crypto/x86cpuid.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-MSFT/crypto/md5/md5-586.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-MSFT/crypto/modes/ghash-x86.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-MSFT/crypto/sha/sha1-586.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-MSFT/crypto/sha/sha256-586.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-MSFT/crypto/sha/sha512-586.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-GCC/crypto/aes/aes-586.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-GCC/crypto/aes/aesni-x86.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-GCC/crypto/aes/vpaes-x86.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-GCC/crypto/x86cpuid.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-GCC/crypto/md5/md5-586.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-GCC/crypto/modes/ghash-x86.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-GCC/crypto/sha/sha1-586.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-GCC/crypto/sha/sha256-586.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/IA32-GCC/crypto/sha/sha512-586.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm +# Autogenerated files list ends here + +[Sources.X64] + X64/ApiHooks.c +# Autogenerated files list starts here + $(OPENSSL_PATH)/crypto/aes/aes_cfb.c + $(OPENSSL_PATH)/crypto/aes/aes_ecb.c + $(OPENSSL_PATH)/crypto/aes/aes_ige.c + $(OPENSSL_PATH)/crypto/aes/aes_misc.c + $(OPENSSL_PATH)/crypto/aes/aes_ofb.c + $(OPENSSL_PATH)/crypto/aes/aes_wrap.c + $(OPENSSL_PATH)/crypto/asn1/a_bitstr.c + $(OPENSSL_PATH)/crypto/asn1/a_d2i_fp.c + $(OPENSSL_PATH)/crypto/asn1/a_digest.c + $(OPENSSL_PATH)/crypto/asn1/a_dup.c + $(OPENSSL_PATH)/crypto/asn1/a_gentm.c + $(OPENSSL_PATH)/crypto/asn1/a_i2d_fp.c + $(OPENSSL_PATH)/crypto/asn1/a_int.c + $(OPENSSL_PATH)/crypto/asn1/a_mbstr.c + $(OPENSSL_PATH)/crypto/asn1/a_object.c + $(OPENSSL_PATH)/crypto/asn1/a_octet.c + $(OPENSSL_PATH)/crypto/asn1/a_print.c + $(OPENSSL_PATH)/crypto/asn1/a_sign.c + $(OPENSSL_PATH)/crypto/asn1/a_strex.c + $(OPENSSL_PATH)/crypto/asn1/a_strnid.c + $(OPENSSL_PATH)/crypto/asn1/a_time.c + $(OPENSSL_PATH)/crypto/asn1/a_type.c + $(OPENSSL_PATH)/crypto/asn1/a_utctm.c + $(OPENSSL_PATH)/crypto/asn1/a_utf8.c + $(OPENSSL_PATH)/crypto/asn1/a_verify.c + $(OPENSSL_PATH)/crypto/asn1/ameth_lib.c + $(OPENSSL_PATH)/crypto/asn1/asn1_err.c + $(OPENSSL_PATH)/crypto/asn1/asn1_gen.c + $(OPENSSL_PATH)/crypto/asn1/asn1_item_list.c + $(OPENSSL_PATH)/crypto/asn1/asn1_lib.c + $(OPENSSL_PATH)/crypto/asn1/asn1_parse.c + $(OPENSSL_PATH)/crypto/asn1/asn_mime.c + $(OPENSSL_PATH)/crypto/asn1/asn_moid.c + $(OPENSSL_PATH)/crypto/asn1/asn_mstbl.c + $(OPENSSL_PATH)/crypto/asn1/asn_pack.c + $(OPENSSL_PATH)/crypto/asn1/bio_asn1.c + $(OPENSSL_PATH)/crypto/asn1/bio_ndef.c + $(OPENSSL_PATH)/crypto/asn1/d2i_param.c + $(OPENSSL_PATH)/crypto/asn1/d2i_pr.c + $(OPENSSL_PATH)/crypto/asn1/d2i_pu.c + $(OPENSSL_PATH)/crypto/asn1/evp_asn1.c + $(OPENSSL_PATH)/crypto/asn1/f_int.c + $(OPENSSL_PATH)/crypto/asn1/f_string.c + $(OPENSSL_PATH)/crypto/asn1/i2d_evp.c + $(OPENSSL_PATH)/crypto/asn1/nsseq.c + $(OPENSSL_PATH)/crypto/asn1/p5_pbe.c + $(OPENSSL_PATH)/crypto/asn1/p5_pbev2.c + $(OPENSSL_PATH)/crypto/asn1/p5_scrypt.c + $(OPENSSL_PATH)/crypto/asn1/p8_pkey.c + $(OPENSSL_PATH)/crypto/asn1/t_bitst.c + $(OPENSSL_PATH)/crypto/asn1/t_pkey.c + $(OPENSSL_PATH)/crypto/asn1/t_spki.c + $(OPENSSL_PATH)/crypto/asn1/tasn_dec.c + $(OPENSSL_PATH)/crypto/asn1/tasn_enc.c + $(OPENSSL_PATH)/crypto/asn1/tasn_fre.c + $(OPENSSL_PATH)/crypto/asn1/tasn_new.c + $(OPENSSL_PATH)/crypto/asn1/tasn_prn.c + $(OPENSSL_PATH)/crypto/asn1/tasn_scn.c + $(OPENSSL_PATH)/crypto/asn1/tasn_typ.c + $(OPENSSL_PATH)/crypto/asn1/tasn_utl.c + $(OPENSSL_PATH)/crypto/asn1/x_algor.c + $(OPENSSL_PATH)/crypto/asn1/x_bignum.c + $(OPENSSL_PATH)/crypto/asn1/x_info.c + $(OPENSSL_PATH)/crypto/asn1/x_int64.c + $(OPENSSL_PATH)/crypto/asn1/x_long.c + $(OPENSSL_PATH)/crypto/asn1/x_pkey.c + $(OPENSSL_PATH)/crypto/asn1/x_sig.c + $(OPENSSL_PATH)/crypto/asn1/x_spki.c + $(OPENSSL_PATH)/crypto/asn1/x_val.c + $(OPENSSL_PATH)/crypto/async/arch/async_null.c + $(OPENSSL_PATH)/crypto/async/arch/async_posix.c + $(OPENSSL_PATH)/crypto/async/arch/async_win.c + $(OPENSSL_PATH)/crypto/async/async.c + $(OPENSSL_PATH)/crypto/async/async_err.c + $(OPENSSL_PATH)/crypto/async/async_wait.c + $(OPENSSL_PATH)/crypto/bio/bf_buff.c + $(OPENSSL_PATH)/crypto/bio/bf_lbuf.c + $(OPENSSL_PATH)/crypto/bio/bf_nbio.c + $(OPENSSL_PATH)/crypto/bio/bf_null.c + $(OPENSSL_PATH)/crypto/bio/bf_prefix.c + $(OPENSSL_PATH)/crypto/bio/bf_readbuff.c + $(OPENSSL_PATH)/crypto/bio/bio_addr.c + $(OPENSSL_PATH)/crypto/bio/bio_cb.c + $(OPENSSL_PATH)/crypto/bio/bio_dump.c + $(OPENSSL_PATH)/crypto/bio/bio_err.c + $(OPENSSL_PATH)/crypto/bio/bio_lib.c + $(OPENSSL_PATH)/crypto/bio/bio_meth.c + $(OPENSSL_PATH)/crypto/bio/bio_print.c + $(OPENSSL_PATH)/crypto/bio/bio_sock.c + $(OPENSSL_PATH)/crypto/bio/bio_sock2.c + $(OPENSSL_PATH)/crypto/bio/bss_acpt.c + $(OPENSSL_PATH)/crypto/bio/bss_bio.c + $(OPENSSL_PATH)/crypto/bio/bss_conn.c + $(OPENSSL_PATH)/crypto/bio/bss_core.c + $(OPENSSL_PATH)/crypto/bio/bss_dgram.c + $(OPENSSL_PATH)/crypto/bio/bss_dgram_pair.c + $(OPENSSL_PATH)/crypto/bio/bss_fd.c + $(OPENSSL_PATH)/crypto/bio/bss_file.c + $(OPENSSL_PATH)/crypto/bio/bss_log.c + $(OPENSSL_PATH)/crypto/bio/bss_mem.c + $(OPENSSL_PATH)/crypto/bio/bss_null.c + $(OPENSSL_PATH)/crypto/bio/bss_sock.c + $(OPENSSL_PATH)/crypto/bio/ossl_core_bio.c + $(OPENSSL_PATH)/crypto/bn/bn_add.c + $(OPENSSL_PATH)/crypto/bn/bn_blind.c + $(OPENSSL_PATH)/crypto/bn/bn_const.c + $(OPENSSL_PATH)/crypto/bn/bn_conv.c + $(OPENSSL_PATH)/crypto/bn/bn_ctx.c + $(OPENSSL_PATH)/crypto/bn/bn_dh.c + $(OPENSSL_PATH)/crypto/bn/bn_div.c + $(OPENSSL_PATH)/crypto/bn/bn_err.c + $(OPENSSL_PATH)/crypto/bn/bn_exp.c + $(OPENSSL_PATH)/crypto/bn/bn_exp2.c + $(OPENSSL_PATH)/crypto/bn/bn_gcd.c + $(OPENSSL_PATH)/crypto/bn/bn_gf2m.c + $(OPENSSL_PATH)/crypto/bn/bn_intern.c + $(OPENSSL_PATH)/crypto/bn/bn_kron.c + $(OPENSSL_PATH)/crypto/bn/bn_lib.c + $(OPENSSL_PATH)/crypto/bn/bn_mod.c + $(OPENSSL_PATH)/crypto/bn/bn_mont.c + $(OPENSSL_PATH)/crypto/bn/bn_mpi.c + $(OPENSSL_PATH)/crypto/bn/bn_mul.c + $(OPENSSL_PATH)/crypto/bn/bn_nist.c + $(OPENSSL_PATH)/crypto/bn/bn_prime.c + $(OPENSSL_PATH)/crypto/bn/bn_print.c + $(OPENSSL_PATH)/crypto/bn/bn_rand.c + $(OPENSSL_PATH)/crypto/bn/bn_recp.c + $(OPENSSL_PATH)/crypto/bn/bn_rsa_fips186_4.c + $(OPENSSL_PATH)/crypto/bn/bn_shift.c + $(OPENSSL_PATH)/crypto/bn/bn_sqr.c + $(OPENSSL_PATH)/crypto/bn/bn_sqrt.c + $(OPENSSL_PATH)/crypto/bn/bn_srp.c + $(OPENSSL_PATH)/crypto/bn/bn_word.c + $(OPENSSL_PATH)/crypto/bn/bn_x931p.c + $(OPENSSL_PATH)/crypto/bn/rsaz_exp.c + $(OPENSSL_PATH)/crypto/bn/rsaz_exp_x2.c + $(OPENSSL_PATH)/crypto/buffer/buf_err.c + $(OPENSSL_PATH)/crypto/buffer/buffer.c + $(OPENSSL_PATH)/crypto/cmac/cmac.c + $(OPENSSL_PATH)/crypto/comp/c_brotli.c + $(OPENSSL_PATH)/crypto/comp/c_zlib.c + $(OPENSSL_PATH)/crypto/comp/c_zstd.c + $(OPENSSL_PATH)/crypto/comp/comp_err.c + $(OPENSSL_PATH)/crypto/comp/comp_lib.c + $(OPENSSL_PATH)/crypto/conf/conf_api.c + $(OPENSSL_PATH)/crypto/conf/conf_def.c + $(OPENSSL_PATH)/crypto/conf/conf_err.c + $(OPENSSL_PATH)/crypto/conf/conf_lib.c + $(OPENSSL_PATH)/crypto/conf/conf_mall.c + $(OPENSSL_PATH)/crypto/conf/conf_mod.c + $(OPENSSL_PATH)/crypto/conf/conf_sap.c + $(OPENSSL_PATH)/crypto/conf/conf_ssl.c + $(OPENSSL_PATH)/crypto/dso/dso_dl.c + $(OPENSSL_PATH)/crypto/dso/dso_dlfcn.c + $(OPENSSL_PATH)/crypto/dso/dso_err.c + $(OPENSSL_PATH)/crypto/dso/dso_lib.c + $(OPENSSL_PATH)/crypto/dso/dso_openssl.c + $(OPENSSL_PATH)/crypto/dso/dso_vms.c + $(OPENSSL_PATH)/crypto/dso/dso_win32.c + $(OPENSSL_PATH)/crypto/ec/ec2_oct.c + $(OPENSSL_PATH)/crypto/ec/ec2_smpl.c + $(OPENSSL_PATH)/crypto/ec/ec_ameth.c + $(OPENSSL_PATH)/crypto/ec/ec_asn1.c + $(OPENSSL_PATH)/crypto/ec/ec_backend.c + $(OPENSSL_PATH)/crypto/ec/ec_check.c + $(OPENSSL_PATH)/crypto/ec/ec_curve.c + $(OPENSSL_PATH)/crypto/ec/ec_cvt.c + $(OPENSSL_PATH)/crypto/ec/ec_deprecated.c + $(OPENSSL_PATH)/crypto/ec/ec_err.c + $(OPENSSL_PATH)/crypto/ec/ec_key.c + $(OPENSSL_PATH)/crypto/ec/ec_kmeth.c + $(OPENSSL_PATH)/crypto/ec/ec_lib.c + $(OPENSSL_PATH)/crypto/ec/ec_mult.c + $(OPENSSL_PATH)/crypto/ec/ec_oct.c + $(OPENSSL_PATH)/crypto/ec/ec_pmeth.c + $(OPENSSL_PATH)/crypto/ec/ec_print.c + $(OPENSSL_PATH)/crypto/ec/ecdh_kdf.c + $(OPENSSL_PATH)/crypto/ec/ecdh_ossl.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_ossl.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_sign.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_vrf.c + $(OPENSSL_PATH)/crypto/ec/eck_prn.c + $(OPENSSL_PATH)/crypto/ec/ecp_mont.c + $(OPENSSL_PATH)/crypto/ec/ecp_nist.c + $(OPENSSL_PATH)/crypto/ec/ecp_oct.c + $(OPENSSL_PATH)/crypto/ec/ecp_smpl.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_err.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_lib.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_meth.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_pkey.c + $(OPENSSL_PATH)/crypto/err/err.c + $(OPENSSL_PATH)/crypto/err/err_all.c + $(OPENSSL_PATH)/crypto/err/err_all_legacy.c + $(OPENSSL_PATH)/crypto/err/err_blocks.c + $(OPENSSL_PATH)/crypto/err/err_mark.c + $(OPENSSL_PATH)/crypto/err/err_prn.c + $(OPENSSL_PATH)/crypto/err/err_save.c + $(OPENSSL_PATH)/crypto/ess/ess_asn1.c + $(OPENSSL_PATH)/crypto/ess/ess_err.c + $(OPENSSL_PATH)/crypto/ess/ess_lib.c + $(OPENSSL_PATH)/crypto/evp/asymcipher.c + $(OPENSSL_PATH)/crypto/evp/bio_b64.c + $(OPENSSL_PATH)/crypto/evp/bio_enc.c + $(OPENSSL_PATH)/crypto/evp/bio_md.c + $(OPENSSL_PATH)/crypto/evp/bio_ok.c + $(OPENSSL_PATH)/crypto/evp/c_allc.c + $(OPENSSL_PATH)/crypto/evp/c_alld.c + $(OPENSSL_PATH)/crypto/evp/cmeth_lib.c + $(OPENSSL_PATH)/crypto/evp/ctrl_params_translate.c + $(OPENSSL_PATH)/crypto/evp/dh_ctrl.c + $(OPENSSL_PATH)/crypto/evp/dh_support.c + $(OPENSSL_PATH)/crypto/evp/digest.c + $(OPENSSL_PATH)/crypto/evp/dsa_ctrl.c + $(OPENSSL_PATH)/crypto/evp/e_aes.c + $(OPENSSL_PATH)/crypto/evp/e_aes_cbc_hmac_sha1.c + $(OPENSSL_PATH)/crypto/evp/e_aes_cbc_hmac_sha256.c + $(OPENSSL_PATH)/crypto/evp/e_aria.c + $(OPENSSL_PATH)/crypto/evp/e_bf.c + $(OPENSSL_PATH)/crypto/evp/e_cast.c + $(OPENSSL_PATH)/crypto/evp/e_chacha20_poly1305.c + $(OPENSSL_PATH)/crypto/evp/e_des.c + $(OPENSSL_PATH)/crypto/evp/e_des3.c + $(OPENSSL_PATH)/crypto/evp/e_idea.c + $(OPENSSL_PATH)/crypto/evp/e_null.c + $(OPENSSL_PATH)/crypto/evp/e_rc2.c + $(OPENSSL_PATH)/crypto/evp/e_rc4.c + $(OPENSSL_PATH)/crypto/evp/e_rc4_hmac_md5.c + $(OPENSSL_PATH)/crypto/evp/e_rc5.c + $(OPENSSL_PATH)/crypto/evp/e_sm4.c + $(OPENSSL_PATH)/crypto/evp/e_xcbc_d.c + $(OPENSSL_PATH)/crypto/evp/ec_ctrl.c + $(OPENSSL_PATH)/crypto/evp/ec_support.c + $(OPENSSL_PATH)/crypto/evp/encode.c + $(OPENSSL_PATH)/crypto/evp/evp_cnf.c + $(OPENSSL_PATH)/crypto/evp/evp_enc.c + $(OPENSSL_PATH)/crypto/evp/evp_err.c + $(OPENSSL_PATH)/crypto/evp/evp_fetch.c + $(OPENSSL_PATH)/crypto/evp/evp_key.c + $(OPENSSL_PATH)/crypto/evp/evp_lib.c + $(OPENSSL_PATH)/crypto/evp/evp_pbe.c + $(OPENSSL_PATH)/crypto/evp/evp_pkey.c + $(OPENSSL_PATH)/crypto/evp/evp_rand.c + $(OPENSSL_PATH)/crypto/evp/evp_utils.c + $(OPENSSL_PATH)/crypto/evp/exchange.c + $(OPENSSL_PATH)/crypto/evp/kdf_lib.c + $(OPENSSL_PATH)/crypto/evp/kdf_meth.c + $(OPENSSL_PATH)/crypto/evp/kem.c + $(OPENSSL_PATH)/crypto/evp/keymgmt_lib.c + $(OPENSSL_PATH)/crypto/evp/keymgmt_meth.c + $(OPENSSL_PATH)/crypto/evp/legacy_md5.c + $(OPENSSL_PATH)/crypto/evp/legacy_md5_sha1.c + $(OPENSSL_PATH)/crypto/evp/legacy_sha.c + $(OPENSSL_PATH)/crypto/evp/m_null.c + $(OPENSSL_PATH)/crypto/evp/m_sigver.c + $(OPENSSL_PATH)/crypto/evp/mac_lib.c + $(OPENSSL_PATH)/crypto/evp/mac_meth.c + $(OPENSSL_PATH)/crypto/evp/names.c + $(OPENSSL_PATH)/crypto/evp/p5_crpt.c + $(OPENSSL_PATH)/crypto/evp/p5_crpt2.c + $(OPENSSL_PATH)/crypto/evp/p_dec.c + $(OPENSSL_PATH)/crypto/evp/p_enc.c + $(OPENSSL_PATH)/crypto/evp/p_legacy.c + $(OPENSSL_PATH)/crypto/evp/p_lib.c + $(OPENSSL_PATH)/crypto/evp/p_open.c + $(OPENSSL_PATH)/crypto/evp/p_seal.c + $(OPENSSL_PATH)/crypto/evp/p_sign.c + $(OPENSSL_PATH)/crypto/evp/p_verify.c + $(OPENSSL_PATH)/crypto/evp/pbe_scrypt.c + $(OPENSSL_PATH)/crypto/evp/pmeth_check.c + $(OPENSSL_PATH)/crypto/evp/pmeth_gn.c + $(OPENSSL_PATH)/crypto/evp/pmeth_lib.c + $(OPENSSL_PATH)/crypto/evp/s_lib.c + $(OPENSSL_PATH)/crypto/evp/signature.c + $(OPENSSL_PATH)/crypto/evp/skeymgmt_meth.c + $(OPENSSL_PATH)/crypto/ffc/ffc_backend.c + $(OPENSSL_PATH)/crypto/ffc/ffc_dh.c + $(OPENSSL_PATH)/crypto/ffc/ffc_key_generate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_key_validate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params_generate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params_validate.c + $(OPENSSL_PATH)/crypto/hashtable/hashfunc.c + $(OPENSSL_PATH)/crypto/hashtable/hashtable.c + $(OPENSSL_PATH)/crypto/hmac/hmac.c + $(OPENSSL_PATH)/crypto/hpke/hpke.c + $(OPENSSL_PATH)/crypto/hpke/hpke_util.c + $(OPENSSL_PATH)/crypto/http/http_client.c + $(OPENSSL_PATH)/crypto/http/http_err.c + $(OPENSSL_PATH)/crypto/http/http_lib.c + $(OPENSSL_PATH)/crypto/kdf/kdf_err.c + $(OPENSSL_PATH)/crypto/lhash/lh_stats.c + $(OPENSSL_PATH)/crypto/lhash/lhash.c + $(OPENSSL_PATH)/crypto/asn1_dsa.c + $(OPENSSL_PATH)/crypto/bsearch.c + $(OPENSSL_PATH)/crypto/comp_methods.c + $(OPENSSL_PATH)/crypto/context.c + $(OPENSSL_PATH)/crypto/core_algorithm.c + $(OPENSSL_PATH)/crypto/core_fetch.c + $(OPENSSL_PATH)/crypto/core_namemap.c + $(OPENSSL_PATH)/crypto/cpt_err.c + $(OPENSSL_PATH)/crypto/cpuid.c + $(OPENSSL_PATH)/crypto/cryptlib.c + $(OPENSSL_PATH)/crypto/ctype.c + $(OPENSSL_PATH)/crypto/cversion.c + $(OPENSSL_PATH)/crypto/defaults.c + $(OPENSSL_PATH)/crypto/der_writer.c + $(OPENSSL_PATH)/crypto/deterministic_nonce.c + $(OPENSSL_PATH)/crypto/ebcdic.c + $(OPENSSL_PATH)/crypto/ex_data.c + $(OPENSSL_PATH)/crypto/getenv.c + $(OPENSSL_PATH)/crypto/indicator_core.c + $(OPENSSL_PATH)/crypto/info.c + $(OPENSSL_PATH)/crypto/init.c + $(OPENSSL_PATH)/crypto/initthread.c + $(OPENSSL_PATH)/crypto/mem.c + $(OPENSSL_PATH)/crypto/mem_sec.c + $(OPENSSL_PATH)/crypto/o_dir.c + $(OPENSSL_PATH)/crypto/o_fopen.c + $(OPENSSL_PATH)/crypto/o_init.c + $(OPENSSL_PATH)/crypto/o_str.c + $(OPENSSL_PATH)/crypto/o_time.c + $(OPENSSL_PATH)/crypto/packet.c + $(OPENSSL_PATH)/crypto/param_build.c + $(OPENSSL_PATH)/crypto/param_build_set.c + $(OPENSSL_PATH)/crypto/params.c + $(OPENSSL_PATH)/crypto/params_dup.c + $(OPENSSL_PATH)/crypto/params_from_text.c + $(OPENSSL_PATH)/crypto/passphrase.c + $(OPENSSL_PATH)/crypto/provider.c + $(OPENSSL_PATH)/crypto/provider_child.c + $(OPENSSL_PATH)/crypto/provider_conf.c + $(OPENSSL_PATH)/crypto/provider_core.c + $(OPENSSL_PATH)/crypto/punycode.c + $(OPENSSL_PATH)/crypto/quic_vlint.c + $(OPENSSL_PATH)/crypto/self_test_core.c + $(OPENSSL_PATH)/crypto/sleep.c + $(OPENSSL_PATH)/crypto/sparse_array.c + $(OPENSSL_PATH)/crypto/ssl_err.c + $(OPENSSL_PATH)/crypto/threads_lib.c + $(OPENSSL_PATH)/crypto/threads_none.c + $(OPENSSL_PATH)/crypto/threads_pthread.c + $(OPENSSL_PATH)/crypto/threads_win.c + $(OPENSSL_PATH)/crypto/time.c + $(OPENSSL_PATH)/crypto/trace.c + $(OPENSSL_PATH)/crypto/uid.c + $(OPENSSL_PATH)/crypto/md5/md5_dgst.c + $(OPENSSL_PATH)/crypto/md5/md5_one.c + $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/modes/cbc128.c + $(OPENSSL_PATH)/crypto/modes/ccm128.c + $(OPENSSL_PATH)/crypto/modes/cfb128.c + $(OPENSSL_PATH)/crypto/modes/ctr128.c + $(OPENSSL_PATH)/crypto/modes/cts128.c + $(OPENSSL_PATH)/crypto/modes/gcm128.c + $(OPENSSL_PATH)/crypto/modes/ocb128.c + $(OPENSSL_PATH)/crypto/modes/ofb128.c + $(OPENSSL_PATH)/crypto/modes/siv128.c + $(OPENSSL_PATH)/crypto/modes/wrap128.c + $(OPENSSL_PATH)/crypto/modes/xts128.c + $(OPENSSL_PATH)/crypto/modes/xts128gb.c + $(OPENSSL_PATH)/crypto/objects/o_names.c + $(OPENSSL_PATH)/crypto/objects/obj_dat.c + $(OPENSSL_PATH)/crypto/objects/obj_err.c + $(OPENSSL_PATH)/crypto/objects/obj_lib.c + $(OPENSSL_PATH)/crypto/objects/obj_xref.c + $(OPENSSL_PATH)/crypto/pem/pem_all.c + $(OPENSSL_PATH)/crypto/pem/pem_err.c + $(OPENSSL_PATH)/crypto/pem/pem_info.c + $(OPENSSL_PATH)/crypto/pem/pem_lib.c + $(OPENSSL_PATH)/crypto/pem/pem_oth.c + $(OPENSSL_PATH)/crypto/pem/pem_pk8.c + $(OPENSSL_PATH)/crypto/pem/pem_pkey.c + $(OPENSSL_PATH)/crypto/pem/pem_sign.c + $(OPENSSL_PATH)/crypto/pem/pem_x509.c + $(OPENSSL_PATH)/crypto/pem/pem_xaux.c + $(OPENSSL_PATH)/crypto/pem/pvkfmt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_add.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_asn.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_attr.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_crpt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_crt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_decr.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_init.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_key.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_kiss.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_mutl.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_npas.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_p8d.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_p8e.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_sbag.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_utl.c + $(OPENSSL_PATH)/crypto/pkcs12/pk12err.c + $(OPENSSL_PATH)/crypto/pkcs7/bio_pk7.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_asn1.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_attr.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_doit.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_lib.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_mime.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_smime.c + $(OPENSSL_PATH)/crypto/pkcs7/pkcs7err.c + $(OPENSSL_PATH)/crypto/property/defn_cache.c + $(OPENSSL_PATH)/crypto/property/property.c + $(OPENSSL_PATH)/crypto/property/property_err.c + $(OPENSSL_PATH)/crypto/property/property_parse.c + $(OPENSSL_PATH)/crypto/property/property_query.c + $(OPENSSL_PATH)/crypto/property/property_string.c + $(OPENSSL_PATH)/crypto/rand/prov_seed.c + $(OPENSSL_PATH)/crypto/rand/rand_deprecated.c + $(OPENSSL_PATH)/crypto/rand/rand_err.c + $(OPENSSL_PATH)/crypto/rand/rand_lib.c + $(OPENSSL_PATH)/crypto/rand/rand_meth.c + $(OPENSSL_PATH)/crypto/rand/rand_pool.c + $(OPENSSL_PATH)/crypto/rand/rand_uniform.c + $(OPENSSL_PATH)/crypto/rsa/rsa_ameth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_asn1.c + $(OPENSSL_PATH)/crypto/rsa/rsa_backend.c + $(OPENSSL_PATH)/crypto/rsa/rsa_chk.c + $(OPENSSL_PATH)/crypto/rsa/rsa_crpt.c + $(OPENSSL_PATH)/crypto/rsa/rsa_err.c + $(OPENSSL_PATH)/crypto/rsa/rsa_gen.c + $(OPENSSL_PATH)/crypto/rsa/rsa_lib.c + $(OPENSSL_PATH)/crypto/rsa/rsa_meth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_mp.c + $(OPENSSL_PATH)/crypto/rsa/rsa_mp_names.c + $(OPENSSL_PATH)/crypto/rsa/rsa_none.c + $(OPENSSL_PATH)/crypto/rsa/rsa_oaep.c + $(OPENSSL_PATH)/crypto/rsa/rsa_ossl.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pk1.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pmeth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_prn.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pss.c + $(OPENSSL_PATH)/crypto/rsa/rsa_saos.c + $(OPENSSL_PATH)/crypto/rsa/rsa_schemes.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sign.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sp800_56b_check.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sp800_56b_gen.c + $(OPENSSL_PATH)/crypto/rsa/rsa_x931.c + $(OPENSSL_PATH)/crypto/rsa/rsa_x931g.c + $(OPENSSL_PATH)/crypto/sha/sha1_one.c + $(OPENSSL_PATH)/crypto/sha/sha1dgst.c + $(OPENSSL_PATH)/crypto/sha/sha256.c + $(OPENSSL_PATH)/crypto/sha/sha3.c + $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c + $(OPENSSL_PATH)/crypto/sm3/sm3.c + $(OPENSSL_PATH)/crypto/stack/stack.c + $(OPENSSL_PATH)/crypto/thread/arch/thread_win.c + $(OPENSSL_PATH)/crypto/thread/api.c + $(OPENSSL_PATH)/crypto/txt_db/txt_db.c + $(OPENSSL_PATH)/crypto/ui/ui_err.c + $(OPENSSL_PATH)/crypto/ui/ui_lib.c + $(OPENSSL_PATH)/crypto/ui/ui_null.c + $(OPENSSL_PATH)/crypto/ui/ui_openssl.c + $(OPENSSL_PATH)/crypto/ui/ui_util.c + $(OPENSSL_PATH)/crypto/x509/by_dir.c + $(OPENSSL_PATH)/crypto/x509/by_file.c + $(OPENSSL_PATH)/crypto/x509/by_store.c + $(OPENSSL_PATH)/crypto/x509/pcy_cache.c + $(OPENSSL_PATH)/crypto/x509/pcy_data.c + $(OPENSSL_PATH)/crypto/x509/pcy_lib.c + $(OPENSSL_PATH)/crypto/x509/pcy_map.c + $(OPENSSL_PATH)/crypto/x509/pcy_node.c + $(OPENSSL_PATH)/crypto/x509/pcy_tree.c + $(OPENSSL_PATH)/crypto/x509/t_acert.c + $(OPENSSL_PATH)/crypto/x509/t_crl.c + $(OPENSSL_PATH)/crypto/x509/t_req.c + $(OPENSSL_PATH)/crypto/x509/t_x509.c + $(OPENSSL_PATH)/crypto/x509/v3_aaa.c + $(OPENSSL_PATH)/crypto/x509/v3_ac_tgt.c + $(OPENSSL_PATH)/crypto/x509/v3_addr.c + $(OPENSSL_PATH)/crypto/x509/v3_admis.c + $(OPENSSL_PATH)/crypto/x509/v3_akeya.c + $(OPENSSL_PATH)/crypto/x509/v3_akid.c + $(OPENSSL_PATH)/crypto/x509/v3_asid.c + $(OPENSSL_PATH)/crypto/x509/v3_attrdesc.c + $(OPENSSL_PATH)/crypto/x509/v3_attrmap.c + $(OPENSSL_PATH)/crypto/x509/v3_audit_id.c + $(OPENSSL_PATH)/crypto/x509/v3_authattid.c + $(OPENSSL_PATH)/crypto/x509/v3_battcons.c + $(OPENSSL_PATH)/crypto/x509/v3_bcons.c + $(OPENSSL_PATH)/crypto/x509/v3_bitst.c + $(OPENSSL_PATH)/crypto/x509/v3_conf.c + $(OPENSSL_PATH)/crypto/x509/v3_cpols.c + $(OPENSSL_PATH)/crypto/x509/v3_crld.c + $(OPENSSL_PATH)/crypto/x509/v3_enum.c + $(OPENSSL_PATH)/crypto/x509/v3_extku.c + $(OPENSSL_PATH)/crypto/x509/v3_genn.c + $(OPENSSL_PATH)/crypto/x509/v3_group_ac.c + $(OPENSSL_PATH)/crypto/x509/v3_ia5.c + $(OPENSSL_PATH)/crypto/x509/v3_ind_iss.c + $(OPENSSL_PATH)/crypto/x509/v3_info.c + $(OPENSSL_PATH)/crypto/x509/v3_int.c + $(OPENSSL_PATH)/crypto/x509/v3_iobo.c + $(OPENSSL_PATH)/crypto/x509/v3_ist.c + $(OPENSSL_PATH)/crypto/x509/v3_lib.c + $(OPENSSL_PATH)/crypto/x509/v3_ncons.c + $(OPENSSL_PATH)/crypto/x509/v3_no_ass.c + $(OPENSSL_PATH)/crypto/x509/v3_no_rev_avail.c + $(OPENSSL_PATH)/crypto/x509/v3_pci.c + $(OPENSSL_PATH)/crypto/x509/v3_pcia.c + $(OPENSSL_PATH)/crypto/x509/v3_pcons.c + $(OPENSSL_PATH)/crypto/x509/v3_pku.c + $(OPENSSL_PATH)/crypto/x509/v3_pmaps.c + $(OPENSSL_PATH)/crypto/x509/v3_prn.c + $(OPENSSL_PATH)/crypto/x509/v3_purp.c + $(OPENSSL_PATH)/crypto/x509/v3_rolespec.c + $(OPENSSL_PATH)/crypto/x509/v3_san.c + $(OPENSSL_PATH)/crypto/x509/v3_sda.c + $(OPENSSL_PATH)/crypto/x509/v3_single_use.c + $(OPENSSL_PATH)/crypto/x509/v3_skid.c + $(OPENSSL_PATH)/crypto/x509/v3_soa_id.c + $(OPENSSL_PATH)/crypto/x509/v3_sxnet.c + $(OPENSSL_PATH)/crypto/x509/v3_timespec.c + $(OPENSSL_PATH)/crypto/x509/v3_tlsf.c + $(OPENSSL_PATH)/crypto/x509/v3_usernotice.c + $(OPENSSL_PATH)/crypto/x509/v3_utf8.c + $(OPENSSL_PATH)/crypto/x509/v3_utl.c + $(OPENSSL_PATH)/crypto/x509/v3err.c + $(OPENSSL_PATH)/crypto/x509/x509_acert.c + $(OPENSSL_PATH)/crypto/x509/x509_att.c + $(OPENSSL_PATH)/crypto/x509/x509_cmp.c + $(OPENSSL_PATH)/crypto/x509/x509_d2.c + $(OPENSSL_PATH)/crypto/x509/x509_def.c + $(OPENSSL_PATH)/crypto/x509/x509_err.c + $(OPENSSL_PATH)/crypto/x509/x509_ext.c + $(OPENSSL_PATH)/crypto/x509/x509_lu.c + $(OPENSSL_PATH)/crypto/x509/x509_meth.c + $(OPENSSL_PATH)/crypto/x509/x509_obj.c + $(OPENSSL_PATH)/crypto/x509/x509_r2x.c + $(OPENSSL_PATH)/crypto/x509/x509_req.c + $(OPENSSL_PATH)/crypto/x509/x509_set.c + $(OPENSSL_PATH)/crypto/x509/x509_trust.c + $(OPENSSL_PATH)/crypto/x509/x509_txt.c + $(OPENSSL_PATH)/crypto/x509/x509_v3.c + $(OPENSSL_PATH)/crypto/x509/x509_vfy.c + $(OPENSSL_PATH)/crypto/x509/x509_vpm.c + $(OPENSSL_PATH)/crypto/x509/x509aset.c + $(OPENSSL_PATH)/crypto/x509/x509cset.c + $(OPENSSL_PATH)/crypto/x509/x509name.c + $(OPENSSL_PATH)/crypto/x509/x509rset.c + $(OPENSSL_PATH)/crypto/x509/x509spki.c + $(OPENSSL_PATH)/crypto/x509/x509type.c + $(OPENSSL_PATH)/crypto/x509/x_all.c + $(OPENSSL_PATH)/crypto/x509/x_attrib.c + $(OPENSSL_PATH)/crypto/x509/x_crl.c + $(OPENSSL_PATH)/crypto/x509/x_exten.c + $(OPENSSL_PATH)/crypto/x509/x_ietfatt.c + $(OPENSSL_PATH)/crypto/x509/x_name.c + $(OPENSSL_PATH)/crypto/x509/x_pubkey.c + $(OPENSSL_PATH)/crypto/x509/x_req.c + $(OPENSSL_PATH)/crypto/x509/x_x509.c + $(OPENSSL_PATH)/crypto/x509/x_x509a.c + $(OPENSSL_PATH)/providers/nullprov.c + $(OPENSSL_PATH)/providers/prov_running.c + $(OPENSSL_PATH)/providers/common/der/der_rsa_sig.c + $(OPENSSL_PATH)/providers/common/bio_prov.c + $(OPENSSL_PATH)/providers/common/capabilities.c + $(OPENSSL_PATH)/providers/common/digest_to_nid.c + $(OPENSSL_PATH)/providers/common/provider_seeding.c + $(OPENSSL_PATH)/providers/common/provider_util.c + $(OPENSSL_PATH)/providers/common/securitycheck.c + $(OPENSSL_PATH)/providers/common/securitycheck_default.c + $(OPENSSL_PATH)/providers/implementations/asymciphers/rsa_enc.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha1_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha256_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_ccm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_ccm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_gcm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_gcm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_wrp.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts_fips.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_cts.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_null.c + $(OPENSSL_PATH)/providers/implementations/digests/md5_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/md5_sha1_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/null_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sha2_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sha3_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sm3_prov.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_der2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_epki2pki.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_msblob2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pem2der.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/exchange/ecdh_exch.c + $(OPENSSL_PATH)/providers/implementations/exchange/kdf_exch.c + $(OPENSSL_PATH)/providers/implementations/kdfs/argon2.c + $(OPENSSL_PATH)/providers/implementations/kdfs/hkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/hmacdrbg_kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/kbkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/krb5kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pbkdf2.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pbkdf2_fips.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pkcs12kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/scrypt.c + $(OPENSSL_PATH)/providers/implementations/kdfs/sshkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/sskdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/tls1_prf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/x942kdf.c + $(OPENSSL_PATH)/providers/implementations/kem/ec_kem.c + $(OPENSSL_PATH)/providers/implementations/kem/kem_util.c + $(OPENSSL_PATH)/providers/implementations/kem/rsa_kem.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ec_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/kmac_prov.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_ctr.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_hash.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_hmac.c + $(OPENSSL_PATH)/providers/implementations/rands/seed_src.c + $(OPENSSL_PATH)/providers/implementations/rands/seed_src_jitter.c + $(OPENSSL_PATH)/providers/implementations/rands/test_rng.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_cpu_x86.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_tsc.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_unix.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_win.c + $(OPENSSL_PATH)/providers/implementations/signature/ecdsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c + $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c + $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c + $(OPENSSL_GEN_PATH)/crypto/params_idx.c + $(OPENSSL_PATH)/providers/common/der/der_ec_key.c + $(OPENSSL_PATH)/providers/common/der/der_ec_sig.c + $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/provider_ctx.c + $(OPENSSL_PATH)/providers/common/provider_err.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_block.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_ccm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_ccm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_gcm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_gcm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_hw.c + $(OPENSSL_PATH)/providers/implementations/digests/digestcommon.c + $(OPENSSL_PATH)/ssl/record/methods/tls_pad.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ec_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c + $(OPENSSL_PATH)/ssl/bio_ssl.c + $(OPENSSL_PATH)/ssl/d1_lib.c + $(OPENSSL_PATH)/ssl/d1_msg.c + $(OPENSSL_PATH)/ssl/d1_srtp.c + $(OPENSSL_PATH)/ssl/methods.c + $(OPENSSL_PATH)/ssl/pqueue.c + $(OPENSSL_PATH)/ssl/s3_enc.c + $(OPENSSL_PATH)/ssl/s3_lib.c + $(OPENSSL_PATH)/ssl/s3_msg.c + $(OPENSSL_PATH)/ssl/ssl_asn1.c + $(OPENSSL_PATH)/ssl/ssl_cert.c + $(OPENSSL_PATH)/ssl/ssl_cert_comp.c + $(OPENSSL_PATH)/ssl/ssl_ciph.c + $(OPENSSL_PATH)/ssl/ssl_conf.c + $(OPENSSL_PATH)/ssl/ssl_err_legacy.c + $(OPENSSL_PATH)/ssl/ssl_init.c + $(OPENSSL_PATH)/ssl/ssl_lib.c + $(OPENSSL_PATH)/ssl/ssl_mcnf.c + $(OPENSSL_PATH)/ssl/ssl_rsa.c + $(OPENSSL_PATH)/ssl/ssl_rsa_legacy.c + $(OPENSSL_PATH)/ssl/ssl_sess.c + $(OPENSSL_PATH)/ssl/ssl_stat.c + $(OPENSSL_PATH)/ssl/ssl_txt.c + $(OPENSSL_PATH)/ssl/ssl_utst.c + $(OPENSSL_PATH)/ssl/t1_enc.c + $(OPENSSL_PATH)/ssl/t1_lib.c + $(OPENSSL_PATH)/ssl/t1_trce.c + $(OPENSSL_PATH)/ssl/tls13_enc.c + $(OPENSSL_PATH)/ssl/tls_depr.c + $(OPENSSL_PATH)/ssl/tls_srp.c + $(OPENSSL_PATH)/ssl/quic/quic_tls.c + $(OPENSSL_PATH)/ssl/quic/quic_tls_api.c + $(OPENSSL_PATH)/ssl/record/rec_layer_d1.c + $(OPENSSL_PATH)/ssl/record/rec_layer_s3.c + $(OPENSSL_PATH)/ssl/record/methods/dtls_meth.c + $(OPENSSL_PATH)/ssl/record/methods/ssl3_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls13_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls1_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls_common.c + $(OPENSSL_PATH)/ssl/record/methods/tls_multib.c + $(OPENSSL_PATH)/ssl/record/methods/tlsany_meth.c + $(OPENSSL_PATH)/ssl/rio/poll_immediate.c + $(OPENSSL_PATH)/ssl/statem/extensions.c + $(OPENSSL_PATH)/ssl/statem/extensions_clnt.c + $(OPENSSL_PATH)/ssl/statem/extensions_cust.c + $(OPENSSL_PATH)/ssl/statem/statem.c + $(OPENSSL_PATH)/ssl/statem/statem_clnt.c + $(OPENSSL_PATH)/ssl/statem/statem_dtls.c + $(OPENSSL_PATH)/ssl/statem/statem_lib.c + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/aes/aes-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/aes/aesni-mb-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/aes/aesni-sha1-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/aes/aesni-sha256-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/aes/aesni-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/aes/aesni-xts-avx512.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/aes/bsaes-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/aes/vpaes-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/x86_64cpuid.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/md5/md5-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/modes/aes-gcm-avx512.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/modes/aesni-gcm-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/modes/ghash-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/sha/keccak1600-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/sha/sha1-mb-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/sha/sha1-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/sha/sha256-mb-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/sha/sha256-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-MSFT/crypto/sha/sha512-x86_64.nasm ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/aes/aes-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/aes/aesni-mb-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/aes/aesni-sha1-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/aes/aesni-sha256-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/aes/aesni-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/aes/aesni-xts-avx512.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/aes/bsaes-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/aes/vpaes-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/x86_64cpuid.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/md5/md5-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/modes/aes-gcm-avx512.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/modes/aesni-gcm-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/modes/ghash-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/sha/keccak1600-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/sha/sha1-mb-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/sha/sha1-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/sha/sha256-mb-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/sha/sha256-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + $(OPENSSL_GEN_PATH)/X64-GCC/crypto/sha/sha512-x86_64.s ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm +# Autogenerated files list ends here + +[Sources.AARCH64] + OpensslStub/AArch64Cap.c +# Autogenerated files list starts here + $(OPENSSL_PATH)/crypto/aes/aes_cbc.c + $(OPENSSL_PATH)/crypto/aes/aes_cfb.c + $(OPENSSL_PATH)/crypto/aes/aes_core.c + $(OPENSSL_PATH)/crypto/aes/aes_ecb.c + $(OPENSSL_PATH)/crypto/aes/aes_ige.c + $(OPENSSL_PATH)/crypto/aes/aes_misc.c + $(OPENSSL_PATH)/crypto/aes/aes_ofb.c + $(OPENSSL_PATH)/crypto/aes/aes_wrap.c + $(OPENSSL_PATH)/crypto/asn1/a_bitstr.c + $(OPENSSL_PATH)/crypto/asn1/a_d2i_fp.c + $(OPENSSL_PATH)/crypto/asn1/a_digest.c + $(OPENSSL_PATH)/crypto/asn1/a_dup.c + $(OPENSSL_PATH)/crypto/asn1/a_gentm.c + $(OPENSSL_PATH)/crypto/asn1/a_i2d_fp.c + $(OPENSSL_PATH)/crypto/asn1/a_int.c + $(OPENSSL_PATH)/crypto/asn1/a_mbstr.c + $(OPENSSL_PATH)/crypto/asn1/a_object.c + $(OPENSSL_PATH)/crypto/asn1/a_octet.c + $(OPENSSL_PATH)/crypto/asn1/a_print.c + $(OPENSSL_PATH)/crypto/asn1/a_sign.c + $(OPENSSL_PATH)/crypto/asn1/a_strex.c + $(OPENSSL_PATH)/crypto/asn1/a_strnid.c + $(OPENSSL_PATH)/crypto/asn1/a_time.c + $(OPENSSL_PATH)/crypto/asn1/a_type.c + $(OPENSSL_PATH)/crypto/asn1/a_utctm.c + $(OPENSSL_PATH)/crypto/asn1/a_utf8.c + $(OPENSSL_PATH)/crypto/asn1/a_verify.c + $(OPENSSL_PATH)/crypto/asn1/ameth_lib.c + $(OPENSSL_PATH)/crypto/asn1/asn1_err.c + $(OPENSSL_PATH)/crypto/asn1/asn1_gen.c + $(OPENSSL_PATH)/crypto/asn1/asn1_item_list.c + $(OPENSSL_PATH)/crypto/asn1/asn1_lib.c + $(OPENSSL_PATH)/crypto/asn1/asn1_parse.c + $(OPENSSL_PATH)/crypto/asn1/asn_mime.c + $(OPENSSL_PATH)/crypto/asn1/asn_moid.c + $(OPENSSL_PATH)/crypto/asn1/asn_mstbl.c + $(OPENSSL_PATH)/crypto/asn1/asn_pack.c + $(OPENSSL_PATH)/crypto/asn1/bio_asn1.c + $(OPENSSL_PATH)/crypto/asn1/bio_ndef.c + $(OPENSSL_PATH)/crypto/asn1/d2i_param.c + $(OPENSSL_PATH)/crypto/asn1/d2i_pr.c + $(OPENSSL_PATH)/crypto/asn1/d2i_pu.c + $(OPENSSL_PATH)/crypto/asn1/evp_asn1.c + $(OPENSSL_PATH)/crypto/asn1/f_int.c + $(OPENSSL_PATH)/crypto/asn1/f_string.c + $(OPENSSL_PATH)/crypto/asn1/i2d_evp.c + $(OPENSSL_PATH)/crypto/asn1/nsseq.c + $(OPENSSL_PATH)/crypto/asn1/p5_pbe.c + $(OPENSSL_PATH)/crypto/asn1/p5_pbev2.c + $(OPENSSL_PATH)/crypto/asn1/p5_scrypt.c + $(OPENSSL_PATH)/crypto/asn1/p8_pkey.c + $(OPENSSL_PATH)/crypto/asn1/t_bitst.c + $(OPENSSL_PATH)/crypto/asn1/t_pkey.c + $(OPENSSL_PATH)/crypto/asn1/t_spki.c + $(OPENSSL_PATH)/crypto/asn1/tasn_dec.c + $(OPENSSL_PATH)/crypto/asn1/tasn_enc.c + $(OPENSSL_PATH)/crypto/asn1/tasn_fre.c + $(OPENSSL_PATH)/crypto/asn1/tasn_new.c + $(OPENSSL_PATH)/crypto/asn1/tasn_prn.c + $(OPENSSL_PATH)/crypto/asn1/tasn_scn.c + $(OPENSSL_PATH)/crypto/asn1/tasn_typ.c + $(OPENSSL_PATH)/crypto/asn1/tasn_utl.c + $(OPENSSL_PATH)/crypto/asn1/x_algor.c + $(OPENSSL_PATH)/crypto/asn1/x_bignum.c + $(OPENSSL_PATH)/crypto/asn1/x_info.c + $(OPENSSL_PATH)/crypto/asn1/x_int64.c + $(OPENSSL_PATH)/crypto/asn1/x_long.c + $(OPENSSL_PATH)/crypto/asn1/x_pkey.c + $(OPENSSL_PATH)/crypto/asn1/x_sig.c + $(OPENSSL_PATH)/crypto/asn1/x_spki.c + $(OPENSSL_PATH)/crypto/asn1/x_val.c + $(OPENSSL_PATH)/crypto/async/arch/async_null.c + $(OPENSSL_PATH)/crypto/async/arch/async_posix.c + $(OPENSSL_PATH)/crypto/async/arch/async_win.c + $(OPENSSL_PATH)/crypto/async/async.c + $(OPENSSL_PATH)/crypto/async/async_err.c + $(OPENSSL_PATH)/crypto/async/async_wait.c + $(OPENSSL_PATH)/crypto/bio/bf_buff.c + $(OPENSSL_PATH)/crypto/bio/bf_lbuf.c + $(OPENSSL_PATH)/crypto/bio/bf_nbio.c + $(OPENSSL_PATH)/crypto/bio/bf_null.c + $(OPENSSL_PATH)/crypto/bio/bf_prefix.c + $(OPENSSL_PATH)/crypto/bio/bf_readbuff.c + $(OPENSSL_PATH)/crypto/bio/bio_addr.c + $(OPENSSL_PATH)/crypto/bio/bio_cb.c + $(OPENSSL_PATH)/crypto/bio/bio_dump.c + $(OPENSSL_PATH)/crypto/bio/bio_err.c + $(OPENSSL_PATH)/crypto/bio/bio_lib.c + $(OPENSSL_PATH)/crypto/bio/bio_meth.c + $(OPENSSL_PATH)/crypto/bio/bio_print.c + $(OPENSSL_PATH)/crypto/bio/bio_sock.c + $(OPENSSL_PATH)/crypto/bio/bio_sock2.c + $(OPENSSL_PATH)/crypto/bio/bss_acpt.c + $(OPENSSL_PATH)/crypto/bio/bss_bio.c + $(OPENSSL_PATH)/crypto/bio/bss_conn.c + $(OPENSSL_PATH)/crypto/bio/bss_core.c + $(OPENSSL_PATH)/crypto/bio/bss_dgram.c + $(OPENSSL_PATH)/crypto/bio/bss_dgram_pair.c + $(OPENSSL_PATH)/crypto/bio/bss_fd.c + $(OPENSSL_PATH)/crypto/bio/bss_file.c + $(OPENSSL_PATH)/crypto/bio/bss_log.c + $(OPENSSL_PATH)/crypto/bio/bss_mem.c + $(OPENSSL_PATH)/crypto/bio/bss_null.c + $(OPENSSL_PATH)/crypto/bio/bss_sock.c + $(OPENSSL_PATH)/crypto/bio/ossl_core_bio.c + $(OPENSSL_PATH)/crypto/bn/bn_add.c + $(OPENSSL_PATH)/crypto/bn/bn_asm.c + $(OPENSSL_PATH)/crypto/bn/bn_blind.c + $(OPENSSL_PATH)/crypto/bn/bn_const.c + $(OPENSSL_PATH)/crypto/bn/bn_conv.c + $(OPENSSL_PATH)/crypto/bn/bn_ctx.c + $(OPENSSL_PATH)/crypto/bn/bn_dh.c + $(OPENSSL_PATH)/crypto/bn/bn_div.c + $(OPENSSL_PATH)/crypto/bn/bn_err.c + $(OPENSSL_PATH)/crypto/bn/bn_exp.c + $(OPENSSL_PATH)/crypto/bn/bn_exp2.c + $(OPENSSL_PATH)/crypto/bn/bn_gcd.c + $(OPENSSL_PATH)/crypto/bn/bn_gf2m.c + $(OPENSSL_PATH)/crypto/bn/bn_intern.c + $(OPENSSL_PATH)/crypto/bn/bn_kron.c + $(OPENSSL_PATH)/crypto/bn/bn_lib.c + $(OPENSSL_PATH)/crypto/bn/bn_mod.c + $(OPENSSL_PATH)/crypto/bn/bn_mont.c + $(OPENSSL_PATH)/crypto/bn/bn_mpi.c + $(OPENSSL_PATH)/crypto/bn/bn_mul.c + $(OPENSSL_PATH)/crypto/bn/bn_nist.c + $(OPENSSL_PATH)/crypto/bn/bn_prime.c + $(OPENSSL_PATH)/crypto/bn/bn_print.c + $(OPENSSL_PATH)/crypto/bn/bn_rand.c + $(OPENSSL_PATH)/crypto/bn/bn_recp.c + $(OPENSSL_PATH)/crypto/bn/bn_rsa_fips186_4.c + $(OPENSSL_PATH)/crypto/bn/bn_shift.c + $(OPENSSL_PATH)/crypto/bn/bn_sqr.c + $(OPENSSL_PATH)/crypto/bn/bn_sqrt.c + $(OPENSSL_PATH)/crypto/bn/bn_srp.c + $(OPENSSL_PATH)/crypto/bn/bn_word.c + $(OPENSSL_PATH)/crypto/bn/bn_x931p.c + $(OPENSSL_PATH)/crypto/buffer/buf_err.c + $(OPENSSL_PATH)/crypto/buffer/buffer.c + $(OPENSSL_PATH)/crypto/cmac/cmac.c + $(OPENSSL_PATH)/crypto/comp/c_brotli.c + $(OPENSSL_PATH)/crypto/comp/c_zlib.c + $(OPENSSL_PATH)/crypto/comp/c_zstd.c + $(OPENSSL_PATH)/crypto/comp/comp_err.c + $(OPENSSL_PATH)/crypto/comp/comp_lib.c + $(OPENSSL_PATH)/crypto/conf/conf_api.c + $(OPENSSL_PATH)/crypto/conf/conf_def.c + $(OPENSSL_PATH)/crypto/conf/conf_err.c + $(OPENSSL_PATH)/crypto/conf/conf_lib.c + $(OPENSSL_PATH)/crypto/conf/conf_mall.c + $(OPENSSL_PATH)/crypto/conf/conf_mod.c + $(OPENSSL_PATH)/crypto/conf/conf_sap.c + $(OPENSSL_PATH)/crypto/conf/conf_ssl.c + $(OPENSSL_PATH)/crypto/dso/dso_dl.c + $(OPENSSL_PATH)/crypto/dso/dso_dlfcn.c + $(OPENSSL_PATH)/crypto/dso/dso_err.c + $(OPENSSL_PATH)/crypto/dso/dso_lib.c + $(OPENSSL_PATH)/crypto/dso/dso_openssl.c + $(OPENSSL_PATH)/crypto/dso/dso_vms.c + $(OPENSSL_PATH)/crypto/dso/dso_win32.c + $(OPENSSL_PATH)/crypto/ec/ec2_oct.c + $(OPENSSL_PATH)/crypto/ec/ec2_smpl.c + $(OPENSSL_PATH)/crypto/ec/ec_ameth.c + $(OPENSSL_PATH)/crypto/ec/ec_asn1.c + $(OPENSSL_PATH)/crypto/ec/ec_backend.c + $(OPENSSL_PATH)/crypto/ec/ec_check.c + $(OPENSSL_PATH)/crypto/ec/ec_curve.c + $(OPENSSL_PATH)/crypto/ec/ec_cvt.c + $(OPENSSL_PATH)/crypto/ec/ec_deprecated.c + $(OPENSSL_PATH)/crypto/ec/ec_err.c + $(OPENSSL_PATH)/crypto/ec/ec_key.c + $(OPENSSL_PATH)/crypto/ec/ec_kmeth.c + $(OPENSSL_PATH)/crypto/ec/ec_lib.c + $(OPENSSL_PATH)/crypto/ec/ec_mult.c + $(OPENSSL_PATH)/crypto/ec/ec_oct.c + $(OPENSSL_PATH)/crypto/ec/ec_pmeth.c + $(OPENSSL_PATH)/crypto/ec/ec_print.c + $(OPENSSL_PATH)/crypto/ec/ecdh_kdf.c + $(OPENSSL_PATH)/crypto/ec/ecdh_ossl.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_ossl.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_sign.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_vrf.c + $(OPENSSL_PATH)/crypto/ec/eck_prn.c + $(OPENSSL_PATH)/crypto/ec/ecp_mont.c + $(OPENSSL_PATH)/crypto/ec/ecp_nist.c + $(OPENSSL_PATH)/crypto/ec/ecp_oct.c + $(OPENSSL_PATH)/crypto/ec/ecp_smpl.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_err.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_lib.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_meth.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_pkey.c + $(OPENSSL_PATH)/crypto/err/err.c + $(OPENSSL_PATH)/crypto/err/err_all.c + $(OPENSSL_PATH)/crypto/err/err_all_legacy.c + $(OPENSSL_PATH)/crypto/err/err_blocks.c + $(OPENSSL_PATH)/crypto/err/err_mark.c + $(OPENSSL_PATH)/crypto/err/err_prn.c + $(OPENSSL_PATH)/crypto/err/err_save.c + $(OPENSSL_PATH)/crypto/ess/ess_asn1.c + $(OPENSSL_PATH)/crypto/ess/ess_err.c + $(OPENSSL_PATH)/crypto/ess/ess_lib.c + $(OPENSSL_PATH)/crypto/evp/asymcipher.c + $(OPENSSL_PATH)/crypto/evp/bio_b64.c + $(OPENSSL_PATH)/crypto/evp/bio_enc.c + $(OPENSSL_PATH)/crypto/evp/bio_md.c + $(OPENSSL_PATH)/crypto/evp/bio_ok.c + $(OPENSSL_PATH)/crypto/evp/c_allc.c + $(OPENSSL_PATH)/crypto/evp/c_alld.c + $(OPENSSL_PATH)/crypto/evp/cmeth_lib.c + $(OPENSSL_PATH)/crypto/evp/ctrl_params_translate.c + $(OPENSSL_PATH)/crypto/evp/dh_ctrl.c + $(OPENSSL_PATH)/crypto/evp/dh_support.c + $(OPENSSL_PATH)/crypto/evp/digest.c + $(OPENSSL_PATH)/crypto/evp/dsa_ctrl.c + $(OPENSSL_PATH)/crypto/evp/e_aes.c + $(OPENSSL_PATH)/crypto/evp/e_aes_cbc_hmac_sha1.c + $(OPENSSL_PATH)/crypto/evp/e_aes_cbc_hmac_sha256.c + $(OPENSSL_PATH)/crypto/evp/e_aria.c + $(OPENSSL_PATH)/crypto/evp/e_bf.c + $(OPENSSL_PATH)/crypto/evp/e_cast.c + $(OPENSSL_PATH)/crypto/evp/e_chacha20_poly1305.c + $(OPENSSL_PATH)/crypto/evp/e_des.c + $(OPENSSL_PATH)/crypto/evp/e_des3.c + $(OPENSSL_PATH)/crypto/evp/e_idea.c + $(OPENSSL_PATH)/crypto/evp/e_null.c + $(OPENSSL_PATH)/crypto/evp/e_rc2.c + $(OPENSSL_PATH)/crypto/evp/e_rc4.c + $(OPENSSL_PATH)/crypto/evp/e_rc4_hmac_md5.c + $(OPENSSL_PATH)/crypto/evp/e_rc5.c + $(OPENSSL_PATH)/crypto/evp/e_sm4.c + $(OPENSSL_PATH)/crypto/evp/e_xcbc_d.c + $(OPENSSL_PATH)/crypto/evp/ec_ctrl.c + $(OPENSSL_PATH)/crypto/evp/ec_support.c + $(OPENSSL_PATH)/crypto/evp/encode.c + $(OPENSSL_PATH)/crypto/evp/evp_cnf.c + $(OPENSSL_PATH)/crypto/evp/evp_enc.c + $(OPENSSL_PATH)/crypto/evp/evp_err.c + $(OPENSSL_PATH)/crypto/evp/evp_fetch.c + $(OPENSSL_PATH)/crypto/evp/evp_key.c + $(OPENSSL_PATH)/crypto/evp/evp_lib.c + $(OPENSSL_PATH)/crypto/evp/evp_pbe.c + $(OPENSSL_PATH)/crypto/evp/evp_pkey.c + $(OPENSSL_PATH)/crypto/evp/evp_rand.c + $(OPENSSL_PATH)/crypto/evp/evp_utils.c + $(OPENSSL_PATH)/crypto/evp/exchange.c + $(OPENSSL_PATH)/crypto/evp/kdf_lib.c + $(OPENSSL_PATH)/crypto/evp/kdf_meth.c + $(OPENSSL_PATH)/crypto/evp/kem.c + $(OPENSSL_PATH)/crypto/evp/keymgmt_lib.c + $(OPENSSL_PATH)/crypto/evp/keymgmt_meth.c + $(OPENSSL_PATH)/crypto/evp/legacy_md5.c + $(OPENSSL_PATH)/crypto/evp/legacy_md5_sha1.c + $(OPENSSL_PATH)/crypto/evp/legacy_sha.c + $(OPENSSL_PATH)/crypto/evp/m_null.c + $(OPENSSL_PATH)/crypto/evp/m_sigver.c + $(OPENSSL_PATH)/crypto/evp/mac_lib.c + $(OPENSSL_PATH)/crypto/evp/mac_meth.c + $(OPENSSL_PATH)/crypto/evp/names.c + $(OPENSSL_PATH)/crypto/evp/p5_crpt.c + $(OPENSSL_PATH)/crypto/evp/p5_crpt2.c + $(OPENSSL_PATH)/crypto/evp/p_dec.c + $(OPENSSL_PATH)/crypto/evp/p_enc.c + $(OPENSSL_PATH)/crypto/evp/p_legacy.c + $(OPENSSL_PATH)/crypto/evp/p_lib.c + $(OPENSSL_PATH)/crypto/evp/p_open.c + $(OPENSSL_PATH)/crypto/evp/p_seal.c + $(OPENSSL_PATH)/crypto/evp/p_sign.c + $(OPENSSL_PATH)/crypto/evp/p_verify.c + $(OPENSSL_PATH)/crypto/evp/pbe_scrypt.c + $(OPENSSL_PATH)/crypto/evp/pmeth_check.c + $(OPENSSL_PATH)/crypto/evp/pmeth_gn.c + $(OPENSSL_PATH)/crypto/evp/pmeth_lib.c + $(OPENSSL_PATH)/crypto/evp/s_lib.c + $(OPENSSL_PATH)/crypto/evp/signature.c + $(OPENSSL_PATH)/crypto/evp/skeymgmt_meth.c + $(OPENSSL_PATH)/crypto/ffc/ffc_backend.c + $(OPENSSL_PATH)/crypto/ffc/ffc_dh.c + $(OPENSSL_PATH)/crypto/ffc/ffc_key_generate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_key_validate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params_generate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params_validate.c + $(OPENSSL_PATH)/crypto/hashtable/hashfunc.c + $(OPENSSL_PATH)/crypto/hashtable/hashtable.c + $(OPENSSL_PATH)/crypto/hmac/hmac.c + $(OPENSSL_PATH)/crypto/hpke/hpke.c + $(OPENSSL_PATH)/crypto/hpke/hpke_util.c + $(OPENSSL_PATH)/crypto/http/http_client.c + $(OPENSSL_PATH)/crypto/http/http_err.c + $(OPENSSL_PATH)/crypto/http/http_lib.c + $(OPENSSL_PATH)/crypto/kdf/kdf_err.c + $(OPENSSL_PATH)/crypto/lhash/lh_stats.c + $(OPENSSL_PATH)/crypto/lhash/lhash.c + $(OPENSSL_PATH)/crypto/asn1_dsa.c + $(OPENSSL_PATH)/crypto/bsearch.c + $(OPENSSL_PATH)/crypto/comp_methods.c + $(OPENSSL_PATH)/crypto/context.c + $(OPENSSL_PATH)/crypto/core_algorithm.c + $(OPENSSL_PATH)/crypto/core_fetch.c + $(OPENSSL_PATH)/crypto/core_namemap.c + $(OPENSSL_PATH)/crypto/cpt_err.c + $(OPENSSL_PATH)/crypto/cpuid.c + $(OPENSSL_PATH)/crypto/cryptlib.c + $(OPENSSL_PATH)/crypto/ctype.c + $(OPENSSL_PATH)/crypto/cversion.c + $(OPENSSL_PATH)/crypto/defaults.c + $(OPENSSL_PATH)/crypto/der_writer.c + $(OPENSSL_PATH)/crypto/deterministic_nonce.c + $(OPENSSL_PATH)/crypto/ebcdic.c + $(OPENSSL_PATH)/crypto/ex_data.c + $(OPENSSL_PATH)/crypto/getenv.c + $(OPENSSL_PATH)/crypto/indicator_core.c + $(OPENSSL_PATH)/crypto/info.c + $(OPENSSL_PATH)/crypto/init.c + $(OPENSSL_PATH)/crypto/initthread.c + $(OPENSSL_PATH)/crypto/mem.c + $(OPENSSL_PATH)/crypto/mem_sec.c + $(OPENSSL_PATH)/crypto/o_dir.c + $(OPENSSL_PATH)/crypto/o_fopen.c + $(OPENSSL_PATH)/crypto/o_init.c + $(OPENSSL_PATH)/crypto/o_str.c + $(OPENSSL_PATH)/crypto/o_time.c + $(OPENSSL_PATH)/crypto/packet.c + $(OPENSSL_PATH)/crypto/param_build.c + $(OPENSSL_PATH)/crypto/param_build_set.c + $(OPENSSL_PATH)/crypto/params.c + $(OPENSSL_PATH)/crypto/params_dup.c + $(OPENSSL_PATH)/crypto/params_from_text.c + $(OPENSSL_PATH)/crypto/passphrase.c + $(OPENSSL_PATH)/crypto/provider.c + $(OPENSSL_PATH)/crypto/provider_child.c + $(OPENSSL_PATH)/crypto/provider_conf.c + $(OPENSSL_PATH)/crypto/provider_core.c + $(OPENSSL_PATH)/crypto/punycode.c + $(OPENSSL_PATH)/crypto/quic_vlint.c + $(OPENSSL_PATH)/crypto/self_test_core.c + $(OPENSSL_PATH)/crypto/sleep.c + $(OPENSSL_PATH)/crypto/sparse_array.c + $(OPENSSL_PATH)/crypto/ssl_err.c + $(OPENSSL_PATH)/crypto/threads_lib.c + $(OPENSSL_PATH)/crypto/threads_none.c + $(OPENSSL_PATH)/crypto/threads_pthread.c + $(OPENSSL_PATH)/crypto/threads_win.c + $(OPENSSL_PATH)/crypto/time.c + $(OPENSSL_PATH)/crypto/trace.c + $(OPENSSL_PATH)/crypto/uid.c + $(OPENSSL_PATH)/crypto/md5/md5_dgst.c + $(OPENSSL_PATH)/crypto/md5/md5_one.c + $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/modes/cbc128.c + $(OPENSSL_PATH)/crypto/modes/ccm128.c + $(OPENSSL_PATH)/crypto/modes/cfb128.c + $(OPENSSL_PATH)/crypto/modes/ctr128.c + $(OPENSSL_PATH)/crypto/modes/cts128.c + $(OPENSSL_PATH)/crypto/modes/gcm128.c + $(OPENSSL_PATH)/crypto/modes/ocb128.c + $(OPENSSL_PATH)/crypto/modes/ofb128.c + $(OPENSSL_PATH)/crypto/modes/siv128.c + $(OPENSSL_PATH)/crypto/modes/wrap128.c + $(OPENSSL_PATH)/crypto/modes/xts128.c + $(OPENSSL_PATH)/crypto/modes/xts128gb.c + $(OPENSSL_PATH)/crypto/objects/o_names.c + $(OPENSSL_PATH)/crypto/objects/obj_dat.c + $(OPENSSL_PATH)/crypto/objects/obj_err.c + $(OPENSSL_PATH)/crypto/objects/obj_lib.c + $(OPENSSL_PATH)/crypto/objects/obj_xref.c + $(OPENSSL_PATH)/crypto/pem/pem_all.c + $(OPENSSL_PATH)/crypto/pem/pem_err.c + $(OPENSSL_PATH)/crypto/pem/pem_info.c + $(OPENSSL_PATH)/crypto/pem/pem_lib.c + $(OPENSSL_PATH)/crypto/pem/pem_oth.c + $(OPENSSL_PATH)/crypto/pem/pem_pk8.c + $(OPENSSL_PATH)/crypto/pem/pem_pkey.c + $(OPENSSL_PATH)/crypto/pem/pem_sign.c + $(OPENSSL_PATH)/crypto/pem/pem_x509.c + $(OPENSSL_PATH)/crypto/pem/pem_xaux.c + $(OPENSSL_PATH)/crypto/pem/pvkfmt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_add.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_asn.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_attr.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_crpt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_crt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_decr.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_init.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_key.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_kiss.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_mutl.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_npas.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_p8d.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_p8e.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_sbag.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_utl.c + $(OPENSSL_PATH)/crypto/pkcs12/pk12err.c + $(OPENSSL_PATH)/crypto/pkcs7/bio_pk7.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_asn1.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_attr.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_doit.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_lib.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_mime.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_smime.c + $(OPENSSL_PATH)/crypto/pkcs7/pkcs7err.c + $(OPENSSL_PATH)/crypto/property/defn_cache.c + $(OPENSSL_PATH)/crypto/property/property.c + $(OPENSSL_PATH)/crypto/property/property_err.c + $(OPENSSL_PATH)/crypto/property/property_parse.c + $(OPENSSL_PATH)/crypto/property/property_query.c + $(OPENSSL_PATH)/crypto/property/property_string.c + $(OPENSSL_PATH)/crypto/rand/prov_seed.c + $(OPENSSL_PATH)/crypto/rand/rand_deprecated.c + $(OPENSSL_PATH)/crypto/rand/rand_err.c + $(OPENSSL_PATH)/crypto/rand/rand_lib.c + $(OPENSSL_PATH)/crypto/rand/rand_meth.c + $(OPENSSL_PATH)/crypto/rand/rand_pool.c + $(OPENSSL_PATH)/crypto/rand/rand_uniform.c + $(OPENSSL_PATH)/crypto/rsa/rsa_ameth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_asn1.c + $(OPENSSL_PATH)/crypto/rsa/rsa_backend.c + $(OPENSSL_PATH)/crypto/rsa/rsa_chk.c + $(OPENSSL_PATH)/crypto/rsa/rsa_crpt.c + $(OPENSSL_PATH)/crypto/rsa/rsa_err.c + $(OPENSSL_PATH)/crypto/rsa/rsa_gen.c + $(OPENSSL_PATH)/crypto/rsa/rsa_lib.c + $(OPENSSL_PATH)/crypto/rsa/rsa_meth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_mp.c + $(OPENSSL_PATH)/crypto/rsa/rsa_mp_names.c + $(OPENSSL_PATH)/crypto/rsa/rsa_none.c + $(OPENSSL_PATH)/crypto/rsa/rsa_oaep.c + $(OPENSSL_PATH)/crypto/rsa/rsa_ossl.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pk1.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pmeth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_prn.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pss.c + $(OPENSSL_PATH)/crypto/rsa/rsa_saos.c + $(OPENSSL_PATH)/crypto/rsa/rsa_schemes.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sign.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sp800_56b_check.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sp800_56b_gen.c + $(OPENSSL_PATH)/crypto/rsa/rsa_x931.c + $(OPENSSL_PATH)/crypto/rsa/rsa_x931g.c + $(OPENSSL_PATH)/crypto/sha/sha1_one.c + $(OPENSSL_PATH)/crypto/sha/sha1dgst.c + $(OPENSSL_PATH)/crypto/sha/sha256.c + $(OPENSSL_PATH)/crypto/sha/sha3.c + $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c + $(OPENSSL_PATH)/crypto/sm3/sm3.c + $(OPENSSL_PATH)/crypto/stack/stack.c + $(OPENSSL_PATH)/crypto/thread/arch/thread_win.c + $(OPENSSL_PATH)/crypto/thread/api.c + $(OPENSSL_PATH)/crypto/txt_db/txt_db.c + $(OPENSSL_PATH)/crypto/ui/ui_err.c + $(OPENSSL_PATH)/crypto/ui/ui_lib.c + $(OPENSSL_PATH)/crypto/ui/ui_null.c + $(OPENSSL_PATH)/crypto/ui/ui_openssl.c + $(OPENSSL_PATH)/crypto/ui/ui_util.c + $(OPENSSL_PATH)/crypto/x509/by_dir.c + $(OPENSSL_PATH)/crypto/x509/by_file.c + $(OPENSSL_PATH)/crypto/x509/by_store.c + $(OPENSSL_PATH)/crypto/x509/pcy_cache.c + $(OPENSSL_PATH)/crypto/x509/pcy_data.c + $(OPENSSL_PATH)/crypto/x509/pcy_lib.c + $(OPENSSL_PATH)/crypto/x509/pcy_map.c + $(OPENSSL_PATH)/crypto/x509/pcy_node.c + $(OPENSSL_PATH)/crypto/x509/pcy_tree.c + $(OPENSSL_PATH)/crypto/x509/t_acert.c + $(OPENSSL_PATH)/crypto/x509/t_crl.c + $(OPENSSL_PATH)/crypto/x509/t_req.c + $(OPENSSL_PATH)/crypto/x509/t_x509.c + $(OPENSSL_PATH)/crypto/x509/v3_aaa.c + $(OPENSSL_PATH)/crypto/x509/v3_ac_tgt.c + $(OPENSSL_PATH)/crypto/x509/v3_addr.c + $(OPENSSL_PATH)/crypto/x509/v3_admis.c + $(OPENSSL_PATH)/crypto/x509/v3_akeya.c + $(OPENSSL_PATH)/crypto/x509/v3_akid.c + $(OPENSSL_PATH)/crypto/x509/v3_asid.c + $(OPENSSL_PATH)/crypto/x509/v3_attrdesc.c + $(OPENSSL_PATH)/crypto/x509/v3_attrmap.c + $(OPENSSL_PATH)/crypto/x509/v3_audit_id.c + $(OPENSSL_PATH)/crypto/x509/v3_authattid.c + $(OPENSSL_PATH)/crypto/x509/v3_battcons.c + $(OPENSSL_PATH)/crypto/x509/v3_bcons.c + $(OPENSSL_PATH)/crypto/x509/v3_bitst.c + $(OPENSSL_PATH)/crypto/x509/v3_conf.c + $(OPENSSL_PATH)/crypto/x509/v3_cpols.c + $(OPENSSL_PATH)/crypto/x509/v3_crld.c + $(OPENSSL_PATH)/crypto/x509/v3_enum.c + $(OPENSSL_PATH)/crypto/x509/v3_extku.c + $(OPENSSL_PATH)/crypto/x509/v3_genn.c + $(OPENSSL_PATH)/crypto/x509/v3_group_ac.c + $(OPENSSL_PATH)/crypto/x509/v3_ia5.c + $(OPENSSL_PATH)/crypto/x509/v3_ind_iss.c + $(OPENSSL_PATH)/crypto/x509/v3_info.c + $(OPENSSL_PATH)/crypto/x509/v3_int.c + $(OPENSSL_PATH)/crypto/x509/v3_iobo.c + $(OPENSSL_PATH)/crypto/x509/v3_ist.c + $(OPENSSL_PATH)/crypto/x509/v3_lib.c + $(OPENSSL_PATH)/crypto/x509/v3_ncons.c + $(OPENSSL_PATH)/crypto/x509/v3_no_ass.c + $(OPENSSL_PATH)/crypto/x509/v3_no_rev_avail.c + $(OPENSSL_PATH)/crypto/x509/v3_pci.c + $(OPENSSL_PATH)/crypto/x509/v3_pcia.c + $(OPENSSL_PATH)/crypto/x509/v3_pcons.c + $(OPENSSL_PATH)/crypto/x509/v3_pku.c + $(OPENSSL_PATH)/crypto/x509/v3_pmaps.c + $(OPENSSL_PATH)/crypto/x509/v3_prn.c + $(OPENSSL_PATH)/crypto/x509/v3_purp.c + $(OPENSSL_PATH)/crypto/x509/v3_rolespec.c + $(OPENSSL_PATH)/crypto/x509/v3_san.c + $(OPENSSL_PATH)/crypto/x509/v3_sda.c + $(OPENSSL_PATH)/crypto/x509/v3_single_use.c + $(OPENSSL_PATH)/crypto/x509/v3_skid.c + $(OPENSSL_PATH)/crypto/x509/v3_soa_id.c + $(OPENSSL_PATH)/crypto/x509/v3_sxnet.c + $(OPENSSL_PATH)/crypto/x509/v3_timespec.c + $(OPENSSL_PATH)/crypto/x509/v3_tlsf.c + $(OPENSSL_PATH)/crypto/x509/v3_usernotice.c + $(OPENSSL_PATH)/crypto/x509/v3_utf8.c + $(OPENSSL_PATH)/crypto/x509/v3_utl.c + $(OPENSSL_PATH)/crypto/x509/v3err.c + $(OPENSSL_PATH)/crypto/x509/x509_acert.c + $(OPENSSL_PATH)/crypto/x509/x509_att.c + $(OPENSSL_PATH)/crypto/x509/x509_cmp.c + $(OPENSSL_PATH)/crypto/x509/x509_d2.c + $(OPENSSL_PATH)/crypto/x509/x509_def.c + $(OPENSSL_PATH)/crypto/x509/x509_err.c + $(OPENSSL_PATH)/crypto/x509/x509_ext.c + $(OPENSSL_PATH)/crypto/x509/x509_lu.c + $(OPENSSL_PATH)/crypto/x509/x509_meth.c + $(OPENSSL_PATH)/crypto/x509/x509_obj.c + $(OPENSSL_PATH)/crypto/x509/x509_r2x.c + $(OPENSSL_PATH)/crypto/x509/x509_req.c + $(OPENSSL_PATH)/crypto/x509/x509_set.c + $(OPENSSL_PATH)/crypto/x509/x509_trust.c + $(OPENSSL_PATH)/crypto/x509/x509_txt.c + $(OPENSSL_PATH)/crypto/x509/x509_v3.c + $(OPENSSL_PATH)/crypto/x509/x509_vfy.c + $(OPENSSL_PATH)/crypto/x509/x509_vpm.c + $(OPENSSL_PATH)/crypto/x509/x509aset.c + $(OPENSSL_PATH)/crypto/x509/x509cset.c + $(OPENSSL_PATH)/crypto/x509/x509name.c + $(OPENSSL_PATH)/crypto/x509/x509rset.c + $(OPENSSL_PATH)/crypto/x509/x509spki.c + $(OPENSSL_PATH)/crypto/x509/x509type.c + $(OPENSSL_PATH)/crypto/x509/x_all.c + $(OPENSSL_PATH)/crypto/x509/x_attrib.c + $(OPENSSL_PATH)/crypto/x509/x_crl.c + $(OPENSSL_PATH)/crypto/x509/x_exten.c + $(OPENSSL_PATH)/crypto/x509/x_ietfatt.c + $(OPENSSL_PATH)/crypto/x509/x_name.c + $(OPENSSL_PATH)/crypto/x509/x_pubkey.c + $(OPENSSL_PATH)/crypto/x509/x_req.c + $(OPENSSL_PATH)/crypto/x509/x_x509.c + $(OPENSSL_PATH)/crypto/x509/x_x509a.c + $(OPENSSL_PATH)/providers/nullprov.c + $(OPENSSL_PATH)/providers/prov_running.c + $(OPENSSL_PATH)/providers/common/der/der_rsa_sig.c + $(OPENSSL_PATH)/providers/common/bio_prov.c + $(OPENSSL_PATH)/providers/common/capabilities.c + $(OPENSSL_PATH)/providers/common/digest_to_nid.c + $(OPENSSL_PATH)/providers/common/provider_seeding.c + $(OPENSSL_PATH)/providers/common/provider_util.c + $(OPENSSL_PATH)/providers/common/securitycheck.c + $(OPENSSL_PATH)/providers/common/securitycheck_default.c + $(OPENSSL_PATH)/providers/implementations/asymciphers/rsa_enc.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha1_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha256_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_ccm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_ccm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_gcm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_gcm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_wrp.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts_fips.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_cts.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_null.c + $(OPENSSL_PATH)/providers/implementations/digests/md5_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/md5_sha1_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/null_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sha2_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sha3_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sm3_prov.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_der2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_epki2pki.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_msblob2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pem2der.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/exchange/ecdh_exch.c + $(OPENSSL_PATH)/providers/implementations/exchange/kdf_exch.c + $(OPENSSL_PATH)/providers/implementations/kdfs/argon2.c + $(OPENSSL_PATH)/providers/implementations/kdfs/hkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/hmacdrbg_kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/kbkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/krb5kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pbkdf2.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pbkdf2_fips.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pkcs12kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/scrypt.c + $(OPENSSL_PATH)/providers/implementations/kdfs/sshkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/sskdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/tls1_prf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/x942kdf.c + $(OPENSSL_PATH)/providers/implementations/kem/ec_kem.c + $(OPENSSL_PATH)/providers/implementations/kem/kem_util.c + $(OPENSSL_PATH)/providers/implementations/kem/rsa_kem.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ec_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/kmac_prov.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_ctr.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_hash.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_hmac.c + $(OPENSSL_PATH)/providers/implementations/rands/seed_src.c + $(OPENSSL_PATH)/providers/implementations/rands/seed_src_jitter.c + $(OPENSSL_PATH)/providers/implementations/rands/test_rng.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_cpu_x86.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_tsc.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_unix.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_win.c + $(OPENSSL_PATH)/providers/implementations/signature/ecdsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c + $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c + $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c + $(OPENSSL_GEN_PATH)/crypto/params_idx.c + $(OPENSSL_PATH)/providers/common/der/der_ec_key.c + $(OPENSSL_PATH)/providers/common/der/der_ec_sig.c + $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/provider_ctx.c + $(OPENSSL_PATH)/providers/common/provider_err.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_block.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_ccm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_ccm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_gcm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_gcm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_hw.c + $(OPENSSL_PATH)/providers/implementations/digests/digestcommon.c + $(OPENSSL_PATH)/ssl/record/methods/tls_pad.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ec_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c + $(OPENSSL_PATH)/ssl/bio_ssl.c + $(OPENSSL_PATH)/ssl/d1_lib.c + $(OPENSSL_PATH)/ssl/d1_msg.c + $(OPENSSL_PATH)/ssl/d1_srtp.c + $(OPENSSL_PATH)/ssl/methods.c + $(OPENSSL_PATH)/ssl/pqueue.c + $(OPENSSL_PATH)/ssl/s3_enc.c + $(OPENSSL_PATH)/ssl/s3_lib.c + $(OPENSSL_PATH)/ssl/s3_msg.c + $(OPENSSL_PATH)/ssl/ssl_asn1.c + $(OPENSSL_PATH)/ssl/ssl_cert.c + $(OPENSSL_PATH)/ssl/ssl_cert_comp.c + $(OPENSSL_PATH)/ssl/ssl_ciph.c + $(OPENSSL_PATH)/ssl/ssl_conf.c + $(OPENSSL_PATH)/ssl/ssl_err_legacy.c + $(OPENSSL_PATH)/ssl/ssl_init.c + $(OPENSSL_PATH)/ssl/ssl_lib.c + $(OPENSSL_PATH)/ssl/ssl_mcnf.c + $(OPENSSL_PATH)/ssl/ssl_rsa.c + $(OPENSSL_PATH)/ssl/ssl_rsa_legacy.c + $(OPENSSL_PATH)/ssl/ssl_sess.c + $(OPENSSL_PATH)/ssl/ssl_stat.c + $(OPENSSL_PATH)/ssl/ssl_txt.c + $(OPENSSL_PATH)/ssl/ssl_utst.c + $(OPENSSL_PATH)/ssl/t1_enc.c + $(OPENSSL_PATH)/ssl/t1_lib.c + $(OPENSSL_PATH)/ssl/t1_trce.c + $(OPENSSL_PATH)/ssl/tls13_enc.c + $(OPENSSL_PATH)/ssl/tls_depr.c + $(OPENSSL_PATH)/ssl/tls_srp.c + $(OPENSSL_PATH)/ssl/quic/quic_tls.c + $(OPENSSL_PATH)/ssl/quic/quic_tls_api.c + $(OPENSSL_PATH)/ssl/record/rec_layer_d1.c + $(OPENSSL_PATH)/ssl/record/rec_layer_s3.c + $(OPENSSL_PATH)/ssl/record/methods/dtls_meth.c + $(OPENSSL_PATH)/ssl/record/methods/ssl3_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls13_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls1_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls_common.c + $(OPENSSL_PATH)/ssl/record/methods/tls_multib.c + $(OPENSSL_PATH)/ssl/record/methods/tlsany_meth.c + $(OPENSSL_PATH)/ssl/rio/poll_immediate.c + $(OPENSSL_PATH)/ssl/statem/extensions.c + $(OPENSSL_PATH)/ssl/statem/extensions_clnt.c + $(OPENSSL_PATH)/ssl/statem/extensions_cust.c + $(OPENSSL_PATH)/ssl/statem/statem.c + $(OPENSSL_PATH)/ssl/statem/statem_clnt.c + $(OPENSSL_PATH)/ssl/statem/statem_dtls.c + $(OPENSSL_PATH)/ssl/statem/statem_lib.c + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/aes/aesv8-armx.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/aes/bsaes-armv8.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/aes/vpaes-armv8.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/arm64cpuid.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/md5/md5-aarch64.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/modes/aes-gcm-armv8-unroll8_64.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/modes/aes-gcm-armv8_64.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/modes/ghashv8-armx.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/sha/keccak1600-armv8.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/sha/sha1-armv8.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/sha/sha256-armv8.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/sha/sha512-armv8.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-ELF/crypto/sm3/sm3-armv8.S ||||!gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/aes/aesv8-armx.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/aes/bsaes-armv8.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/aes/vpaes-armv8.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/arm64cpuid.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/md5/md5-aarch64.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/modes/aes-gcm-armv8-unroll8_64.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/modes/aes-gcm-armv8_64.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/modes/ghashv8-armx.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/sha/keccak1600-armv8.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/sha/sha1-armv8.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/sha/sha256-armv8.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/sha/sha512-armv8.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + $(OPENSSL_GEN_PATH)/AARCH64-PE/crypto/sm3/sm3-armv8.S ||||gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe +# Autogenerated files list ends here + +[Packages] + MdePkg/MdePkg.dec + CryptoPkg/CryptoPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + RngLib + +[FeaturePcd.IA32, FeaturePcd.X64] + gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStyleNasm + +[FeaturePcd.AARCH64] + gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe + +[BuildOptions] + # + # Disables the following Visual Studio compiler warnings brought by openssl source, + # so we do not break the build with /WX option: + # C4090: 'function' : different 'const' qualifiers + # C4132: 'object' : const object should be initialized (tls13_enc.c) + # C4210: nonstandard extension used: function given file scope + # C4244: conversion from type1 to type2, possible loss of data + # C4245: conversion from type1 to type2, signed/unsigned mismatch + # C4267: conversion from size_t to type, possible loss of data + # C4306: 'identifier' : conversion from 'type1' to 'type2' of greater size + # C4310: cast truncates constant value + # C4389: 'operator' : signed/unsigned mismatch (xxxx) + # C4700: uninitialized local variable 'name' used. (conf_sap.c(71)) + # C4702: unreachable code + # C4706: assignment within conditional expression + # C4819: The file contains a character that cannot be represented in the current code page + # C4133: incompatible types - from 'ASN1_TYPE *' to 'const ASN1_STRING *' (v3_genn.c(101)) + # C4319: zero extending type to type of greater size + # + MSFT:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_IA32) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4310 /wd4389 /wd4700 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 + MSFT:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_X64) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4306 /wd4310 /wd4700 /wd4389 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 + + # + # Disable following Visual Studio 2015 compiler warnings brought by openssl source, + # so we do not break the build with /WX option: + # C4718: recursive call has no side effects, deleting + # + MSFT:*_VS2015x86_IA32_CC_FLAGS = /wd4718 + MSFT:*_VS2015x86_X64_CC_FLAGS = /wd4718 + + INTEL:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_IA32) /w + INTEL:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_X64) /w + + # + # Suppress the following build warnings in openssl so we don't break the build with -Werror + # -Werror=maybe-uninitialized: there exist some other paths for which the variable is not initialized. + # -Werror=format: Check calls to printf and scanf, etc., to make sure that the arguments supplied have + # types appropriate to the format string specified. + # -Werror=unused-but-set-variable: Warn whenever a local variable is assigned to, but otherwise unused (aside from its declaration). + # + GCC:*_*_IA32_CC_FLAGS = -U_WIN32 -UWIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_IA32) -Wno-error=maybe-uninitialized -Wno-error=unused-but-set-variable + GCC:*_*_X64_CC_FLAGS = -U_WIN32 -UWIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_X64) -Wno-error=maybe-uninitialized -Wno-error=format -Wno-format -Wno-error=unused-but-set-variable -DNO_MSABI_VA_FUNCS + GCC:*_CLANGDWARF_*_CC_FLAGS = -std=gnu99 -Wno-error=uninitialized -Wno-error=incompatible-pointer-types -Wno-error=pointer-sign -Wno-error=implicit-function-declaration -Wno-error=ignored-pragma-optimize + GCC:*_CLANGPDB_*_CC_FLAGS = -U_WIN32 -UWIN32 -U_WIN64 -U_MSC_VER -std=c99 -Wno-error=uninitialized -Wno-error=incompatible-pointer-types -Wno-error=pointer-sign -Wno-error=implicit-function-declaration -Wno-error=ignored-pragma-optimize -Wno-error=unused-function + + # suppress the following warnings in openssl so we don't break the build with warnings-as-errors: + # 1295: Deprecated declaration - give arg types + # 550: was set but never used + # 1293: assignment in condition + # 111: statement is unreachable (invariably "break;" after "return X;" in case statement) + # 68: integer conversion resulted in a change of sign ("if (Status == -1)") + # 177: was declared but never referenced + # 223: function declared implicitly + # 144: a value of type cannot be used to initialize an entity of type + # 513: a value of type cannot be assigned to an entity of type + # 188: enumerated type mixed with another type (i.e. passing an integer as an enum without a cast) + # 1296: Extended constant initialiser used + # 128: loop is not reachable - may be emitted inappropriately if code follows a conditional return + # from the function that evaluates to true at compile time + # 546: transfer of control bypasses initialization - may be emitted inappropriately if the uninitialized + # variable is never referenced after the jump + # 1: ignore "#1-D: last line of file ends without a newline" + # 3017: may be used before being set (NOTE: This was fixed in OpenSSL 1.1 HEAD with + # commit d9b8b89bec4480de3a10bdaf9425db371c19145b, and can be dropped then.) + XCODE:*_*_IA32_CC_FLAGS = -mmmx -msse -U_WIN32 -U_WIN64 $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_IA32) -w -std=c99 -Wno-error=uninitialized -DOPENSSL_NO_APPLE_CRYPTO_RANDOM + XCODE:*_*_X64_CC_FLAGS = -mmmx -msse -U_WIN32 -U_WIN64 $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_X64) -w -std=c99 -Wno-error=uninitialized -DOPENSSL_NO_APPLE_CRYPTO_RANDOM + + GCC:*_*_AARCH64_CC_FLAGS = $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_AARCH64) -Wno-error=format -Wno-format -D_BITS_STDINT_UINTN_H -D_BITS_STDINT_INTN_H + + # + # AARCH64 uses strict alignment and avoids SIMD registers for code that may execute + # with the MMU off. This involves SEC, PEI_CORE and PEIM modules as well as BASE + # libraries, given that they may be included into such modules. + # This library, even though of the BASE type, is never used in such cases, and + # avoiding the SIMD register file (which is shared with the FPU) prevents the + # compiler from successfully building some of the OpenSSL source files that + # use floating point types, so clear the flags here. + # + GCC:*_*_AARCH64_CC_XIPFLAGS == diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccelLite.uni b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccelLite.uni new file mode 100644 index 0000000000..58d0f2963e --- /dev/null +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccelLite.uni @@ -0,0 +1,15 @@ +// /** @file +// This module provides openSSL Library implementation with ECC and TLS +// features along with performance optimized implementations of SHA1, +// SHA256, SHA512 AESNI, VPAED, and GHASH for IA32 and X64, +// but lite version (no-camellia, no-dh, no-ecx). +// +// Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "OpenSSL Library implementation with TLS and ECC features but lite version (no-camellia, no-dh, no-ecx) and performance optimizations" + +#string STR_MODULE_DESCRIPTION #language en-US "This module provides OpenSSL Library implementation with TLS and ECC features but lite version (no-camellia, no-dh, no-ecx) and performance optimizations." diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFullLite.inf b/CryptoPkg/Library/OpensslLib/OpensslLibFullLite.inf new file mode 100644 index 0000000000..5af2ae87d1 --- /dev/null +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFullLite.inf @@ -0,0 +1,842 @@ +## @file +# This module provides OpenSSL Library implementation with ECC and TLS +# features but lite version (no-camellia, no-dh, no-ecx). +# +# This library should be used if a module module needs ECC in TLS, or +# asymmetric cryptography services such as X509 certificate or PEM format +# data processing. This library decreases the size up to ~192 KB +# compared to OpensslLibFull.inf library instance. +# +# Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved.
+# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = OpensslLibFullLite + MODULE_UNI_FILE = OpensslLibFullLite.uni + FILE_GUID = 986565C5-5FD5-453E-A5F5-1BA453FE0EAD + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = OpensslLib + CONSTRUCTOR = OpensslLibConstructor + + DEFINE OPENSSL_PATH = openssl + DEFINE OPENSSL_GEN_PATH = OpensslGen + DEFINE OPENSSL_FLAGS = -DL_ENDIAN -DOPENSSL_SMALL_FOOTPRINT -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DOPENSSL_NO_ASM -DEDK2_OPENSSL_NOCAMELLIA=1 + DEFINE OPENSSL_FLAGS_NOASM = + +[Sources] + OpensslLibConstructor.c + $(OPENSSL_PATH)/ms/uplink.h +# Autogenerated files list starts here + $(OPENSSL_PATH)/crypto/aes/aes_cbc.c + $(OPENSSL_PATH)/crypto/aes/aes_cfb.c + $(OPENSSL_PATH)/crypto/aes/aes_core.c + $(OPENSSL_PATH)/crypto/aes/aes_ecb.c + $(OPENSSL_PATH)/crypto/aes/aes_ige.c + $(OPENSSL_PATH)/crypto/aes/aes_misc.c + $(OPENSSL_PATH)/crypto/aes/aes_ofb.c + $(OPENSSL_PATH)/crypto/aes/aes_wrap.c + $(OPENSSL_PATH)/crypto/asn1/a_bitstr.c + $(OPENSSL_PATH)/crypto/asn1/a_d2i_fp.c + $(OPENSSL_PATH)/crypto/asn1/a_digest.c + $(OPENSSL_PATH)/crypto/asn1/a_dup.c + $(OPENSSL_PATH)/crypto/asn1/a_gentm.c + $(OPENSSL_PATH)/crypto/asn1/a_i2d_fp.c + $(OPENSSL_PATH)/crypto/asn1/a_int.c + $(OPENSSL_PATH)/crypto/asn1/a_mbstr.c + $(OPENSSL_PATH)/crypto/asn1/a_object.c + $(OPENSSL_PATH)/crypto/asn1/a_octet.c + $(OPENSSL_PATH)/crypto/asn1/a_print.c + $(OPENSSL_PATH)/crypto/asn1/a_sign.c + $(OPENSSL_PATH)/crypto/asn1/a_strex.c + $(OPENSSL_PATH)/crypto/asn1/a_strnid.c + $(OPENSSL_PATH)/crypto/asn1/a_time.c + $(OPENSSL_PATH)/crypto/asn1/a_type.c + $(OPENSSL_PATH)/crypto/asn1/a_utctm.c + $(OPENSSL_PATH)/crypto/asn1/a_utf8.c + $(OPENSSL_PATH)/crypto/asn1/a_verify.c + $(OPENSSL_PATH)/crypto/asn1/ameth_lib.c + $(OPENSSL_PATH)/crypto/asn1/asn1_err.c + $(OPENSSL_PATH)/crypto/asn1/asn1_gen.c + $(OPENSSL_PATH)/crypto/asn1/asn1_item_list.c + $(OPENSSL_PATH)/crypto/asn1/asn1_lib.c + $(OPENSSL_PATH)/crypto/asn1/asn1_parse.c + $(OPENSSL_PATH)/crypto/asn1/asn_mime.c + $(OPENSSL_PATH)/crypto/asn1/asn_moid.c + $(OPENSSL_PATH)/crypto/asn1/asn_mstbl.c + $(OPENSSL_PATH)/crypto/asn1/asn_pack.c + $(OPENSSL_PATH)/crypto/asn1/bio_asn1.c + $(OPENSSL_PATH)/crypto/asn1/bio_ndef.c + $(OPENSSL_PATH)/crypto/asn1/d2i_param.c + $(OPENSSL_PATH)/crypto/asn1/d2i_pr.c + $(OPENSSL_PATH)/crypto/asn1/d2i_pu.c + $(OPENSSL_PATH)/crypto/asn1/evp_asn1.c + $(OPENSSL_PATH)/crypto/asn1/f_int.c + $(OPENSSL_PATH)/crypto/asn1/f_string.c + $(OPENSSL_PATH)/crypto/asn1/i2d_evp.c + $(OPENSSL_PATH)/crypto/asn1/nsseq.c + $(OPENSSL_PATH)/crypto/asn1/p5_pbe.c + $(OPENSSL_PATH)/crypto/asn1/p5_pbev2.c + $(OPENSSL_PATH)/crypto/asn1/p5_scrypt.c + $(OPENSSL_PATH)/crypto/asn1/p8_pkey.c + $(OPENSSL_PATH)/crypto/asn1/t_bitst.c + $(OPENSSL_PATH)/crypto/asn1/t_pkey.c + $(OPENSSL_PATH)/crypto/asn1/t_spki.c + $(OPENSSL_PATH)/crypto/asn1/tasn_dec.c + $(OPENSSL_PATH)/crypto/asn1/tasn_enc.c + $(OPENSSL_PATH)/crypto/asn1/tasn_fre.c + $(OPENSSL_PATH)/crypto/asn1/tasn_new.c + $(OPENSSL_PATH)/crypto/asn1/tasn_prn.c + $(OPENSSL_PATH)/crypto/asn1/tasn_scn.c + $(OPENSSL_PATH)/crypto/asn1/tasn_typ.c + $(OPENSSL_PATH)/crypto/asn1/tasn_utl.c + $(OPENSSL_PATH)/crypto/asn1/x_algor.c + $(OPENSSL_PATH)/crypto/asn1/x_bignum.c + $(OPENSSL_PATH)/crypto/asn1/x_info.c + $(OPENSSL_PATH)/crypto/asn1/x_int64.c + $(OPENSSL_PATH)/crypto/asn1/x_long.c + $(OPENSSL_PATH)/crypto/asn1/x_pkey.c + $(OPENSSL_PATH)/crypto/asn1/x_sig.c + $(OPENSSL_PATH)/crypto/asn1/x_spki.c + $(OPENSSL_PATH)/crypto/asn1/x_val.c + $(OPENSSL_PATH)/crypto/async/arch/async_null.c + $(OPENSSL_PATH)/crypto/async/arch/async_posix.c + $(OPENSSL_PATH)/crypto/async/arch/async_win.c + $(OPENSSL_PATH)/crypto/async/async.c + $(OPENSSL_PATH)/crypto/async/async_err.c + $(OPENSSL_PATH)/crypto/async/async_wait.c + $(OPENSSL_PATH)/crypto/bio/bf_buff.c + $(OPENSSL_PATH)/crypto/bio/bf_lbuf.c + $(OPENSSL_PATH)/crypto/bio/bf_nbio.c + $(OPENSSL_PATH)/crypto/bio/bf_null.c + $(OPENSSL_PATH)/crypto/bio/bf_prefix.c + $(OPENSSL_PATH)/crypto/bio/bf_readbuff.c + $(OPENSSL_PATH)/crypto/bio/bio_addr.c + $(OPENSSL_PATH)/crypto/bio/bio_cb.c + $(OPENSSL_PATH)/crypto/bio/bio_dump.c + $(OPENSSL_PATH)/crypto/bio/bio_err.c + $(OPENSSL_PATH)/crypto/bio/bio_lib.c + $(OPENSSL_PATH)/crypto/bio/bio_meth.c + $(OPENSSL_PATH)/crypto/bio/bio_print.c + $(OPENSSL_PATH)/crypto/bio/bio_sock.c + $(OPENSSL_PATH)/crypto/bio/bio_sock2.c + $(OPENSSL_PATH)/crypto/bio/bss_acpt.c + $(OPENSSL_PATH)/crypto/bio/bss_bio.c + $(OPENSSL_PATH)/crypto/bio/bss_conn.c + $(OPENSSL_PATH)/crypto/bio/bss_core.c + $(OPENSSL_PATH)/crypto/bio/bss_dgram.c + $(OPENSSL_PATH)/crypto/bio/bss_dgram_pair.c + $(OPENSSL_PATH)/crypto/bio/bss_fd.c + $(OPENSSL_PATH)/crypto/bio/bss_file.c + $(OPENSSL_PATH)/crypto/bio/bss_log.c + $(OPENSSL_PATH)/crypto/bio/bss_mem.c + $(OPENSSL_PATH)/crypto/bio/bss_null.c + $(OPENSSL_PATH)/crypto/bio/bss_sock.c + $(OPENSSL_PATH)/crypto/bio/ossl_core_bio.c + $(OPENSSL_PATH)/crypto/bn/bn_add.c + $(OPENSSL_PATH)/crypto/bn/bn_asm.c + $(OPENSSL_PATH)/crypto/bn/bn_blind.c + $(OPENSSL_PATH)/crypto/bn/bn_const.c + $(OPENSSL_PATH)/crypto/bn/bn_conv.c + $(OPENSSL_PATH)/crypto/bn/bn_ctx.c + $(OPENSSL_PATH)/crypto/bn/bn_dh.c + $(OPENSSL_PATH)/crypto/bn/bn_div.c + $(OPENSSL_PATH)/crypto/bn/bn_err.c + $(OPENSSL_PATH)/crypto/bn/bn_exp.c + $(OPENSSL_PATH)/crypto/bn/bn_exp2.c + $(OPENSSL_PATH)/crypto/bn/bn_gcd.c + $(OPENSSL_PATH)/crypto/bn/bn_gf2m.c + $(OPENSSL_PATH)/crypto/bn/bn_intern.c + $(OPENSSL_PATH)/crypto/bn/bn_kron.c + $(OPENSSL_PATH)/crypto/bn/bn_lib.c + $(OPENSSL_PATH)/crypto/bn/bn_mod.c + $(OPENSSL_PATH)/crypto/bn/bn_mont.c + $(OPENSSL_PATH)/crypto/bn/bn_mpi.c + $(OPENSSL_PATH)/crypto/bn/bn_mul.c + $(OPENSSL_PATH)/crypto/bn/bn_nist.c + $(OPENSSL_PATH)/crypto/bn/bn_prime.c + $(OPENSSL_PATH)/crypto/bn/bn_print.c + $(OPENSSL_PATH)/crypto/bn/bn_rand.c + $(OPENSSL_PATH)/crypto/bn/bn_recp.c + $(OPENSSL_PATH)/crypto/bn/bn_rsa_fips186_4.c + $(OPENSSL_PATH)/crypto/bn/bn_shift.c + $(OPENSSL_PATH)/crypto/bn/bn_sqr.c + $(OPENSSL_PATH)/crypto/bn/bn_sqrt.c + $(OPENSSL_PATH)/crypto/bn/bn_srp.c + $(OPENSSL_PATH)/crypto/bn/bn_word.c + $(OPENSSL_PATH)/crypto/bn/bn_x931p.c + $(OPENSSL_PATH)/crypto/buffer/buf_err.c + $(OPENSSL_PATH)/crypto/buffer/buffer.c + $(OPENSSL_PATH)/crypto/cmac/cmac.c + $(OPENSSL_PATH)/crypto/comp/c_brotli.c + $(OPENSSL_PATH)/crypto/comp/c_zlib.c + $(OPENSSL_PATH)/crypto/comp/c_zstd.c + $(OPENSSL_PATH)/crypto/comp/comp_err.c + $(OPENSSL_PATH)/crypto/comp/comp_lib.c + $(OPENSSL_PATH)/crypto/conf/conf_api.c + $(OPENSSL_PATH)/crypto/conf/conf_def.c + $(OPENSSL_PATH)/crypto/conf/conf_err.c + $(OPENSSL_PATH)/crypto/conf/conf_lib.c + $(OPENSSL_PATH)/crypto/conf/conf_mall.c + $(OPENSSL_PATH)/crypto/conf/conf_mod.c + $(OPENSSL_PATH)/crypto/conf/conf_sap.c + $(OPENSSL_PATH)/crypto/conf/conf_ssl.c + $(OPENSSL_PATH)/crypto/dso/dso_dl.c + $(OPENSSL_PATH)/crypto/dso/dso_dlfcn.c + $(OPENSSL_PATH)/crypto/dso/dso_err.c + $(OPENSSL_PATH)/crypto/dso/dso_lib.c + $(OPENSSL_PATH)/crypto/dso/dso_openssl.c + $(OPENSSL_PATH)/crypto/dso/dso_vms.c + $(OPENSSL_PATH)/crypto/dso/dso_win32.c + $(OPENSSL_PATH)/crypto/ec/ec2_oct.c + $(OPENSSL_PATH)/crypto/ec/ec2_smpl.c + $(OPENSSL_PATH)/crypto/ec/ec_ameth.c + $(OPENSSL_PATH)/crypto/ec/ec_asn1.c + $(OPENSSL_PATH)/crypto/ec/ec_backend.c + $(OPENSSL_PATH)/crypto/ec/ec_check.c + $(OPENSSL_PATH)/crypto/ec/ec_curve.c + $(OPENSSL_PATH)/crypto/ec/ec_cvt.c + $(OPENSSL_PATH)/crypto/ec/ec_deprecated.c + $(OPENSSL_PATH)/crypto/ec/ec_err.c + $(OPENSSL_PATH)/crypto/ec/ec_key.c + $(OPENSSL_PATH)/crypto/ec/ec_kmeth.c + $(OPENSSL_PATH)/crypto/ec/ec_lib.c + $(OPENSSL_PATH)/crypto/ec/ec_mult.c + $(OPENSSL_PATH)/crypto/ec/ec_oct.c + $(OPENSSL_PATH)/crypto/ec/ec_pmeth.c + $(OPENSSL_PATH)/crypto/ec/ec_print.c + $(OPENSSL_PATH)/crypto/ec/ecdh_kdf.c + $(OPENSSL_PATH)/crypto/ec/ecdh_ossl.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_ossl.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_sign.c + $(OPENSSL_PATH)/crypto/ec/ecdsa_vrf.c + $(OPENSSL_PATH)/crypto/ec/eck_prn.c + $(OPENSSL_PATH)/crypto/ec/ecp_mont.c + $(OPENSSL_PATH)/crypto/ec/ecp_nist.c + $(OPENSSL_PATH)/crypto/ec/ecp_oct.c + $(OPENSSL_PATH)/crypto/ec/ecp_smpl.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_err.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_lib.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_meth.c + $(OPENSSL_PATH)/crypto/encode_decode/decoder_pkey.c + $(OPENSSL_PATH)/crypto/err/err.c + $(OPENSSL_PATH)/crypto/err/err_all.c + $(OPENSSL_PATH)/crypto/err/err_all_legacy.c + $(OPENSSL_PATH)/crypto/err/err_blocks.c + $(OPENSSL_PATH)/crypto/err/err_mark.c + $(OPENSSL_PATH)/crypto/err/err_prn.c + $(OPENSSL_PATH)/crypto/err/err_save.c + $(OPENSSL_PATH)/crypto/ess/ess_asn1.c + $(OPENSSL_PATH)/crypto/ess/ess_err.c + $(OPENSSL_PATH)/crypto/ess/ess_lib.c + $(OPENSSL_PATH)/crypto/evp/asymcipher.c + $(OPENSSL_PATH)/crypto/evp/bio_b64.c + $(OPENSSL_PATH)/crypto/evp/bio_enc.c + $(OPENSSL_PATH)/crypto/evp/bio_md.c + $(OPENSSL_PATH)/crypto/evp/bio_ok.c + $(OPENSSL_PATH)/crypto/evp/c_allc.c + $(OPENSSL_PATH)/crypto/evp/c_alld.c + $(OPENSSL_PATH)/crypto/evp/cmeth_lib.c + $(OPENSSL_PATH)/crypto/evp/ctrl_params_translate.c + $(OPENSSL_PATH)/crypto/evp/dh_ctrl.c + $(OPENSSL_PATH)/crypto/evp/dh_support.c + $(OPENSSL_PATH)/crypto/evp/digest.c + $(OPENSSL_PATH)/crypto/evp/dsa_ctrl.c + $(OPENSSL_PATH)/crypto/evp/e_aes.c + $(OPENSSL_PATH)/crypto/evp/e_aes_cbc_hmac_sha1.c + $(OPENSSL_PATH)/crypto/evp/e_aes_cbc_hmac_sha256.c + $(OPENSSL_PATH)/crypto/evp/e_aria.c + $(OPENSSL_PATH)/crypto/evp/e_bf.c + $(OPENSSL_PATH)/crypto/evp/e_cast.c + $(OPENSSL_PATH)/crypto/evp/e_chacha20_poly1305.c + $(OPENSSL_PATH)/crypto/evp/e_des.c + $(OPENSSL_PATH)/crypto/evp/e_des3.c + $(OPENSSL_PATH)/crypto/evp/e_idea.c + $(OPENSSL_PATH)/crypto/evp/e_null.c + $(OPENSSL_PATH)/crypto/evp/e_rc2.c + $(OPENSSL_PATH)/crypto/evp/e_rc4.c + $(OPENSSL_PATH)/crypto/evp/e_rc4_hmac_md5.c + $(OPENSSL_PATH)/crypto/evp/e_rc5.c + $(OPENSSL_PATH)/crypto/evp/e_sm4.c + $(OPENSSL_PATH)/crypto/evp/e_xcbc_d.c + $(OPENSSL_PATH)/crypto/evp/ec_ctrl.c + $(OPENSSL_PATH)/crypto/evp/ec_support.c + $(OPENSSL_PATH)/crypto/evp/encode.c + $(OPENSSL_PATH)/crypto/evp/evp_cnf.c + $(OPENSSL_PATH)/crypto/evp/evp_enc.c + $(OPENSSL_PATH)/crypto/evp/evp_err.c + $(OPENSSL_PATH)/crypto/evp/evp_fetch.c + $(OPENSSL_PATH)/crypto/evp/evp_key.c + $(OPENSSL_PATH)/crypto/evp/evp_lib.c + $(OPENSSL_PATH)/crypto/evp/evp_pbe.c + $(OPENSSL_PATH)/crypto/evp/evp_pkey.c + $(OPENSSL_PATH)/crypto/evp/evp_rand.c + $(OPENSSL_PATH)/crypto/evp/evp_utils.c + $(OPENSSL_PATH)/crypto/evp/exchange.c + $(OPENSSL_PATH)/crypto/evp/kdf_lib.c + $(OPENSSL_PATH)/crypto/evp/kdf_meth.c + $(OPENSSL_PATH)/crypto/evp/kem.c + $(OPENSSL_PATH)/crypto/evp/keymgmt_lib.c + $(OPENSSL_PATH)/crypto/evp/keymgmt_meth.c + $(OPENSSL_PATH)/crypto/evp/legacy_md5.c + $(OPENSSL_PATH)/crypto/evp/legacy_md5_sha1.c + $(OPENSSL_PATH)/crypto/evp/legacy_sha.c + $(OPENSSL_PATH)/crypto/evp/m_null.c + $(OPENSSL_PATH)/crypto/evp/m_sigver.c + $(OPENSSL_PATH)/crypto/evp/mac_lib.c + $(OPENSSL_PATH)/crypto/evp/mac_meth.c + $(OPENSSL_PATH)/crypto/evp/names.c + $(OPENSSL_PATH)/crypto/evp/p5_crpt.c + $(OPENSSL_PATH)/crypto/evp/p5_crpt2.c + $(OPENSSL_PATH)/crypto/evp/p_dec.c + $(OPENSSL_PATH)/crypto/evp/p_enc.c + $(OPENSSL_PATH)/crypto/evp/p_legacy.c + $(OPENSSL_PATH)/crypto/evp/p_lib.c + $(OPENSSL_PATH)/crypto/evp/p_open.c + $(OPENSSL_PATH)/crypto/evp/p_seal.c + $(OPENSSL_PATH)/crypto/evp/p_sign.c + $(OPENSSL_PATH)/crypto/evp/p_verify.c + $(OPENSSL_PATH)/crypto/evp/pbe_scrypt.c + $(OPENSSL_PATH)/crypto/evp/pmeth_check.c + $(OPENSSL_PATH)/crypto/evp/pmeth_gn.c + $(OPENSSL_PATH)/crypto/evp/pmeth_lib.c + $(OPENSSL_PATH)/crypto/evp/s_lib.c + $(OPENSSL_PATH)/crypto/evp/signature.c + $(OPENSSL_PATH)/crypto/evp/skeymgmt_meth.c + $(OPENSSL_PATH)/crypto/ffc/ffc_backend.c + $(OPENSSL_PATH)/crypto/ffc/ffc_dh.c + $(OPENSSL_PATH)/crypto/ffc/ffc_key_generate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_key_validate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params_generate.c + $(OPENSSL_PATH)/crypto/ffc/ffc_params_validate.c + $(OPENSSL_PATH)/crypto/hashtable/hashfunc.c + $(OPENSSL_PATH)/crypto/hashtable/hashtable.c + $(OPENSSL_PATH)/crypto/hmac/hmac.c + $(OPENSSL_PATH)/crypto/hpke/hpke.c + $(OPENSSL_PATH)/crypto/hpke/hpke_util.c + $(OPENSSL_PATH)/crypto/http/http_client.c + $(OPENSSL_PATH)/crypto/http/http_err.c + $(OPENSSL_PATH)/crypto/http/http_lib.c + $(OPENSSL_PATH)/crypto/kdf/kdf_err.c + $(OPENSSL_PATH)/crypto/lhash/lh_stats.c + $(OPENSSL_PATH)/crypto/lhash/lhash.c + $(OPENSSL_PATH)/crypto/asn1_dsa.c + $(OPENSSL_PATH)/crypto/bsearch.c + $(OPENSSL_PATH)/crypto/comp_methods.c + $(OPENSSL_PATH)/crypto/context.c + $(OPENSSL_PATH)/crypto/core_algorithm.c + $(OPENSSL_PATH)/crypto/core_fetch.c + $(OPENSSL_PATH)/crypto/core_namemap.c + $(OPENSSL_PATH)/crypto/cpt_err.c + $(OPENSSL_PATH)/crypto/cpuid.c + $(OPENSSL_PATH)/crypto/cryptlib.c + $(OPENSSL_PATH)/crypto/ctype.c + $(OPENSSL_PATH)/crypto/cversion.c + $(OPENSSL_PATH)/crypto/defaults.c + $(OPENSSL_PATH)/crypto/der_writer.c + $(OPENSSL_PATH)/crypto/deterministic_nonce.c + $(OPENSSL_PATH)/crypto/ebcdic.c + $(OPENSSL_PATH)/crypto/ex_data.c + $(OPENSSL_PATH)/crypto/getenv.c + $(OPENSSL_PATH)/crypto/indicator_core.c + $(OPENSSL_PATH)/crypto/info.c + $(OPENSSL_PATH)/crypto/init.c + $(OPENSSL_PATH)/crypto/initthread.c + $(OPENSSL_PATH)/crypto/mem.c + $(OPENSSL_PATH)/crypto/mem_clr.c + $(OPENSSL_PATH)/crypto/mem_sec.c + $(OPENSSL_PATH)/crypto/o_dir.c + $(OPENSSL_PATH)/crypto/o_fopen.c + $(OPENSSL_PATH)/crypto/o_init.c + $(OPENSSL_PATH)/crypto/o_str.c + $(OPENSSL_PATH)/crypto/o_time.c + $(OPENSSL_PATH)/crypto/packet.c + $(OPENSSL_PATH)/crypto/param_build.c + $(OPENSSL_PATH)/crypto/param_build_set.c + $(OPENSSL_PATH)/crypto/params.c + $(OPENSSL_PATH)/crypto/params_dup.c + $(OPENSSL_PATH)/crypto/params_from_text.c + $(OPENSSL_PATH)/crypto/passphrase.c + $(OPENSSL_PATH)/crypto/provider.c + $(OPENSSL_PATH)/crypto/provider_child.c + $(OPENSSL_PATH)/crypto/provider_conf.c + $(OPENSSL_PATH)/crypto/provider_core.c + $(OPENSSL_PATH)/crypto/punycode.c + $(OPENSSL_PATH)/crypto/quic_vlint.c + $(OPENSSL_PATH)/crypto/self_test_core.c + $(OPENSSL_PATH)/crypto/sleep.c + $(OPENSSL_PATH)/crypto/sparse_array.c + $(OPENSSL_PATH)/crypto/ssl_err.c + $(OPENSSL_PATH)/crypto/threads_lib.c + $(OPENSSL_PATH)/crypto/threads_none.c + $(OPENSSL_PATH)/crypto/threads_pthread.c + $(OPENSSL_PATH)/crypto/threads_win.c + $(OPENSSL_PATH)/crypto/time.c + $(OPENSSL_PATH)/crypto/trace.c + $(OPENSSL_PATH)/crypto/uid.c + $(OPENSSL_PATH)/crypto/md5/md5_dgst.c + $(OPENSSL_PATH)/crypto/md5/md5_one.c + $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/modes/cbc128.c + $(OPENSSL_PATH)/crypto/modes/ccm128.c + $(OPENSSL_PATH)/crypto/modes/cfb128.c + $(OPENSSL_PATH)/crypto/modes/ctr128.c + $(OPENSSL_PATH)/crypto/modes/cts128.c + $(OPENSSL_PATH)/crypto/modes/gcm128.c + $(OPENSSL_PATH)/crypto/modes/ocb128.c + $(OPENSSL_PATH)/crypto/modes/ofb128.c + $(OPENSSL_PATH)/crypto/modes/siv128.c + $(OPENSSL_PATH)/crypto/modes/wrap128.c + $(OPENSSL_PATH)/crypto/modes/xts128.c + $(OPENSSL_PATH)/crypto/modes/xts128gb.c + $(OPENSSL_PATH)/crypto/objects/o_names.c + $(OPENSSL_PATH)/crypto/objects/obj_dat.c + $(OPENSSL_PATH)/crypto/objects/obj_err.c + $(OPENSSL_PATH)/crypto/objects/obj_lib.c + $(OPENSSL_PATH)/crypto/objects/obj_xref.c + $(OPENSSL_PATH)/crypto/pem/pem_all.c + $(OPENSSL_PATH)/crypto/pem/pem_err.c + $(OPENSSL_PATH)/crypto/pem/pem_info.c + $(OPENSSL_PATH)/crypto/pem/pem_lib.c + $(OPENSSL_PATH)/crypto/pem/pem_oth.c + $(OPENSSL_PATH)/crypto/pem/pem_pk8.c + $(OPENSSL_PATH)/crypto/pem/pem_pkey.c + $(OPENSSL_PATH)/crypto/pem/pem_sign.c + $(OPENSSL_PATH)/crypto/pem/pem_x509.c + $(OPENSSL_PATH)/crypto/pem/pem_xaux.c + $(OPENSSL_PATH)/crypto/pem/pvkfmt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_add.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_asn.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_attr.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_crpt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_crt.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_decr.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_init.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_key.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_kiss.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_mutl.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_npas.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_p8d.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_p8e.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_sbag.c + $(OPENSSL_PATH)/crypto/pkcs12/p12_utl.c + $(OPENSSL_PATH)/crypto/pkcs12/pk12err.c + $(OPENSSL_PATH)/crypto/pkcs7/bio_pk7.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_asn1.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_attr.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_doit.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_lib.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_mime.c + $(OPENSSL_PATH)/crypto/pkcs7/pk7_smime.c + $(OPENSSL_PATH)/crypto/pkcs7/pkcs7err.c + $(OPENSSL_PATH)/crypto/property/defn_cache.c + $(OPENSSL_PATH)/crypto/property/property.c + $(OPENSSL_PATH)/crypto/property/property_err.c + $(OPENSSL_PATH)/crypto/property/property_parse.c + $(OPENSSL_PATH)/crypto/property/property_query.c + $(OPENSSL_PATH)/crypto/property/property_string.c + $(OPENSSL_PATH)/crypto/rand/prov_seed.c + $(OPENSSL_PATH)/crypto/rand/rand_deprecated.c + $(OPENSSL_PATH)/crypto/rand/rand_err.c + $(OPENSSL_PATH)/crypto/rand/rand_lib.c + $(OPENSSL_PATH)/crypto/rand/rand_meth.c + $(OPENSSL_PATH)/crypto/rand/rand_pool.c + $(OPENSSL_PATH)/crypto/rand/rand_uniform.c + $(OPENSSL_PATH)/crypto/rsa/rsa_ameth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_asn1.c + $(OPENSSL_PATH)/crypto/rsa/rsa_backend.c + $(OPENSSL_PATH)/crypto/rsa/rsa_chk.c + $(OPENSSL_PATH)/crypto/rsa/rsa_crpt.c + $(OPENSSL_PATH)/crypto/rsa/rsa_err.c + $(OPENSSL_PATH)/crypto/rsa/rsa_gen.c + $(OPENSSL_PATH)/crypto/rsa/rsa_lib.c + $(OPENSSL_PATH)/crypto/rsa/rsa_meth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_mp.c + $(OPENSSL_PATH)/crypto/rsa/rsa_mp_names.c + $(OPENSSL_PATH)/crypto/rsa/rsa_none.c + $(OPENSSL_PATH)/crypto/rsa/rsa_oaep.c + $(OPENSSL_PATH)/crypto/rsa/rsa_ossl.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pk1.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pmeth.c + $(OPENSSL_PATH)/crypto/rsa/rsa_prn.c + $(OPENSSL_PATH)/crypto/rsa/rsa_pss.c + $(OPENSSL_PATH)/crypto/rsa/rsa_saos.c + $(OPENSSL_PATH)/crypto/rsa/rsa_schemes.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sign.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sp800_56b_check.c + $(OPENSSL_PATH)/crypto/rsa/rsa_sp800_56b_gen.c + $(OPENSSL_PATH)/crypto/rsa/rsa_x931.c + $(OPENSSL_PATH)/crypto/rsa/rsa_x931g.c + $(OPENSSL_PATH)/crypto/sha/keccak1600.c + $(OPENSSL_PATH)/crypto/sha/sha1_one.c + $(OPENSSL_PATH)/crypto/sha/sha1dgst.c + $(OPENSSL_PATH)/crypto/sha/sha256.c + $(OPENSSL_PATH)/crypto/sha/sha3.c + $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c + $(OPENSSL_PATH)/crypto/sm3/sm3.c + $(OPENSSL_PATH)/crypto/stack/stack.c + $(OPENSSL_PATH)/crypto/thread/arch/thread_win.c + $(OPENSSL_PATH)/crypto/thread/api.c + $(OPENSSL_PATH)/crypto/txt_db/txt_db.c + $(OPENSSL_PATH)/crypto/ui/ui_err.c + $(OPENSSL_PATH)/crypto/ui/ui_lib.c + $(OPENSSL_PATH)/crypto/ui/ui_null.c + $(OPENSSL_PATH)/crypto/ui/ui_openssl.c + $(OPENSSL_PATH)/crypto/ui/ui_util.c + $(OPENSSL_PATH)/crypto/x509/by_dir.c + $(OPENSSL_PATH)/crypto/x509/by_file.c + $(OPENSSL_PATH)/crypto/x509/by_store.c + $(OPENSSL_PATH)/crypto/x509/pcy_cache.c + $(OPENSSL_PATH)/crypto/x509/pcy_data.c + $(OPENSSL_PATH)/crypto/x509/pcy_lib.c + $(OPENSSL_PATH)/crypto/x509/pcy_map.c + $(OPENSSL_PATH)/crypto/x509/pcy_node.c + $(OPENSSL_PATH)/crypto/x509/pcy_tree.c + $(OPENSSL_PATH)/crypto/x509/t_acert.c + $(OPENSSL_PATH)/crypto/x509/t_crl.c + $(OPENSSL_PATH)/crypto/x509/t_req.c + $(OPENSSL_PATH)/crypto/x509/t_x509.c + $(OPENSSL_PATH)/crypto/x509/v3_aaa.c + $(OPENSSL_PATH)/crypto/x509/v3_ac_tgt.c + $(OPENSSL_PATH)/crypto/x509/v3_addr.c + $(OPENSSL_PATH)/crypto/x509/v3_admis.c + $(OPENSSL_PATH)/crypto/x509/v3_akeya.c + $(OPENSSL_PATH)/crypto/x509/v3_akid.c + $(OPENSSL_PATH)/crypto/x509/v3_asid.c + $(OPENSSL_PATH)/crypto/x509/v3_attrdesc.c + $(OPENSSL_PATH)/crypto/x509/v3_attrmap.c + $(OPENSSL_PATH)/crypto/x509/v3_audit_id.c + $(OPENSSL_PATH)/crypto/x509/v3_authattid.c + $(OPENSSL_PATH)/crypto/x509/v3_battcons.c + $(OPENSSL_PATH)/crypto/x509/v3_bcons.c + $(OPENSSL_PATH)/crypto/x509/v3_bitst.c + $(OPENSSL_PATH)/crypto/x509/v3_conf.c + $(OPENSSL_PATH)/crypto/x509/v3_cpols.c + $(OPENSSL_PATH)/crypto/x509/v3_crld.c + $(OPENSSL_PATH)/crypto/x509/v3_enum.c + $(OPENSSL_PATH)/crypto/x509/v3_extku.c + $(OPENSSL_PATH)/crypto/x509/v3_genn.c + $(OPENSSL_PATH)/crypto/x509/v3_group_ac.c + $(OPENSSL_PATH)/crypto/x509/v3_ia5.c + $(OPENSSL_PATH)/crypto/x509/v3_ind_iss.c + $(OPENSSL_PATH)/crypto/x509/v3_info.c + $(OPENSSL_PATH)/crypto/x509/v3_int.c + $(OPENSSL_PATH)/crypto/x509/v3_iobo.c + $(OPENSSL_PATH)/crypto/x509/v3_ist.c + $(OPENSSL_PATH)/crypto/x509/v3_lib.c + $(OPENSSL_PATH)/crypto/x509/v3_ncons.c + $(OPENSSL_PATH)/crypto/x509/v3_no_ass.c + $(OPENSSL_PATH)/crypto/x509/v3_no_rev_avail.c + $(OPENSSL_PATH)/crypto/x509/v3_pci.c + $(OPENSSL_PATH)/crypto/x509/v3_pcia.c + $(OPENSSL_PATH)/crypto/x509/v3_pcons.c + $(OPENSSL_PATH)/crypto/x509/v3_pku.c + $(OPENSSL_PATH)/crypto/x509/v3_pmaps.c + $(OPENSSL_PATH)/crypto/x509/v3_prn.c + $(OPENSSL_PATH)/crypto/x509/v3_purp.c + $(OPENSSL_PATH)/crypto/x509/v3_rolespec.c + $(OPENSSL_PATH)/crypto/x509/v3_san.c + $(OPENSSL_PATH)/crypto/x509/v3_sda.c + $(OPENSSL_PATH)/crypto/x509/v3_single_use.c + $(OPENSSL_PATH)/crypto/x509/v3_skid.c + $(OPENSSL_PATH)/crypto/x509/v3_soa_id.c + $(OPENSSL_PATH)/crypto/x509/v3_sxnet.c + $(OPENSSL_PATH)/crypto/x509/v3_timespec.c + $(OPENSSL_PATH)/crypto/x509/v3_tlsf.c + $(OPENSSL_PATH)/crypto/x509/v3_usernotice.c + $(OPENSSL_PATH)/crypto/x509/v3_utf8.c + $(OPENSSL_PATH)/crypto/x509/v3_utl.c + $(OPENSSL_PATH)/crypto/x509/v3err.c + $(OPENSSL_PATH)/crypto/x509/x509_acert.c + $(OPENSSL_PATH)/crypto/x509/x509_att.c + $(OPENSSL_PATH)/crypto/x509/x509_cmp.c + $(OPENSSL_PATH)/crypto/x509/x509_d2.c + $(OPENSSL_PATH)/crypto/x509/x509_def.c + $(OPENSSL_PATH)/crypto/x509/x509_err.c + $(OPENSSL_PATH)/crypto/x509/x509_ext.c + $(OPENSSL_PATH)/crypto/x509/x509_lu.c + $(OPENSSL_PATH)/crypto/x509/x509_meth.c + $(OPENSSL_PATH)/crypto/x509/x509_obj.c + $(OPENSSL_PATH)/crypto/x509/x509_r2x.c + $(OPENSSL_PATH)/crypto/x509/x509_req.c + $(OPENSSL_PATH)/crypto/x509/x509_set.c + $(OPENSSL_PATH)/crypto/x509/x509_trust.c + $(OPENSSL_PATH)/crypto/x509/x509_txt.c + $(OPENSSL_PATH)/crypto/x509/x509_v3.c + $(OPENSSL_PATH)/crypto/x509/x509_vfy.c + $(OPENSSL_PATH)/crypto/x509/x509_vpm.c + $(OPENSSL_PATH)/crypto/x509/x509aset.c + $(OPENSSL_PATH)/crypto/x509/x509cset.c + $(OPENSSL_PATH)/crypto/x509/x509name.c + $(OPENSSL_PATH)/crypto/x509/x509rset.c + $(OPENSSL_PATH)/crypto/x509/x509spki.c + $(OPENSSL_PATH)/crypto/x509/x509type.c + $(OPENSSL_PATH)/crypto/x509/x_all.c + $(OPENSSL_PATH)/crypto/x509/x_attrib.c + $(OPENSSL_PATH)/crypto/x509/x_crl.c + $(OPENSSL_PATH)/crypto/x509/x_exten.c + $(OPENSSL_PATH)/crypto/x509/x_ietfatt.c + $(OPENSSL_PATH)/crypto/x509/x_name.c + $(OPENSSL_PATH)/crypto/x509/x_pubkey.c + $(OPENSSL_PATH)/crypto/x509/x_req.c + $(OPENSSL_PATH)/crypto/x509/x_x509.c + $(OPENSSL_PATH)/crypto/x509/x_x509a.c + $(OPENSSL_PATH)/providers/nullprov.c + $(OPENSSL_PATH)/providers/prov_running.c + $(OPENSSL_PATH)/providers/common/der/der_rsa_sig.c + $(OPENSSL_PATH)/providers/common/bio_prov.c + $(OPENSSL_PATH)/providers/common/capabilities.c + $(OPENSSL_PATH)/providers/common/digest_to_nid.c + $(OPENSSL_PATH)/providers/common/provider_seeding.c + $(OPENSSL_PATH)/providers/common/provider_util.c + $(OPENSSL_PATH)/providers/common/securitycheck.c + $(OPENSSL_PATH)/providers/common/securitycheck_default.c + $(OPENSSL_PATH)/providers/implementations/asymciphers/rsa_enc.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha1_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_cbc_hmac_sha256_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_ccm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_ccm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_gcm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_gcm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_wrp.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts_fips.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_aes_xts_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_cts.c + $(OPENSSL_PATH)/providers/implementations/ciphers/cipher_null.c + $(OPENSSL_PATH)/providers/implementations/digests/md5_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/md5_sha1_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/null_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sha2_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sha3_prov.c + $(OPENSSL_PATH)/providers/implementations/digests/sm3_prov.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_der2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_epki2pki.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_msblob2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pem2der.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/exchange/ecdh_exch.c + $(OPENSSL_PATH)/providers/implementations/exchange/kdf_exch.c + $(OPENSSL_PATH)/providers/implementations/kdfs/argon2.c + $(OPENSSL_PATH)/providers/implementations/kdfs/hkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/hmacdrbg_kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/kbkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/krb5kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pbkdf2.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pbkdf2_fips.c + $(OPENSSL_PATH)/providers/implementations/kdfs/pkcs12kdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/scrypt.c + $(OPENSSL_PATH)/providers/implementations/kdfs/sshkdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/sskdf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/tls1_prf.c + $(OPENSSL_PATH)/providers/implementations/kdfs/x942kdf.c + $(OPENSSL_PATH)/providers/implementations/kem/ec_kem.c + $(OPENSSL_PATH)/providers/implementations/kem/kem_util.c + $(OPENSSL_PATH)/providers/implementations/kem/rsa_kem.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ec_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c + $(OPENSSL_PATH)/providers/implementations/macs/kmac_prov.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_ctr.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_hash.c + $(OPENSSL_PATH)/providers/implementations/rands/drbg_hmac.c + $(OPENSSL_PATH)/providers/implementations/rands/seed_src.c + $(OPENSSL_PATH)/providers/implementations/rands/seed_src_jitter.c + $(OPENSSL_PATH)/providers/implementations/rands/test_rng.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_cpu_x86.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_tsc.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_unix.c + $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_win.c + $(OPENSSL_PATH)/providers/implementations/signature/ecdsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c + $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c + $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c + $(OPENSSL_GEN_PATH)/crypto/params_idx.c + $(OPENSSL_PATH)/providers/common/der/der_ec_key.c + $(OPENSSL_PATH)/providers/common/der/der_ec_sig.c + $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/provider_ctx.c + $(OPENSSL_PATH)/providers/common/provider_err.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_block.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_ccm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_ccm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_gcm.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_gcm_hw.c + $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon_hw.c + $(OPENSSL_PATH)/providers/implementations/digests/digestcommon.c + $(OPENSSL_PATH)/ssl/record/methods/tls_pad.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ec_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c + $(OPENSSL_PATH)/ssl/bio_ssl.c + $(OPENSSL_PATH)/ssl/d1_lib.c + $(OPENSSL_PATH)/ssl/d1_msg.c + $(OPENSSL_PATH)/ssl/d1_srtp.c + $(OPENSSL_PATH)/ssl/methods.c + $(OPENSSL_PATH)/ssl/pqueue.c + $(OPENSSL_PATH)/ssl/s3_enc.c + $(OPENSSL_PATH)/ssl/s3_lib.c + $(OPENSSL_PATH)/ssl/s3_msg.c + $(OPENSSL_PATH)/ssl/ssl_asn1.c + $(OPENSSL_PATH)/ssl/ssl_cert.c + $(OPENSSL_PATH)/ssl/ssl_cert_comp.c + $(OPENSSL_PATH)/ssl/ssl_ciph.c + $(OPENSSL_PATH)/ssl/ssl_conf.c + $(OPENSSL_PATH)/ssl/ssl_err_legacy.c + $(OPENSSL_PATH)/ssl/ssl_init.c + $(OPENSSL_PATH)/ssl/ssl_lib.c + $(OPENSSL_PATH)/ssl/ssl_mcnf.c + $(OPENSSL_PATH)/ssl/ssl_rsa.c + $(OPENSSL_PATH)/ssl/ssl_rsa_legacy.c + $(OPENSSL_PATH)/ssl/ssl_sess.c + $(OPENSSL_PATH)/ssl/ssl_stat.c + $(OPENSSL_PATH)/ssl/ssl_txt.c + $(OPENSSL_PATH)/ssl/ssl_utst.c + $(OPENSSL_PATH)/ssl/t1_enc.c + $(OPENSSL_PATH)/ssl/t1_lib.c + $(OPENSSL_PATH)/ssl/t1_trce.c + $(OPENSSL_PATH)/ssl/tls13_enc.c + $(OPENSSL_PATH)/ssl/tls_depr.c + $(OPENSSL_PATH)/ssl/tls_srp.c + $(OPENSSL_PATH)/ssl/quic/quic_tls.c + $(OPENSSL_PATH)/ssl/quic/quic_tls_api.c + $(OPENSSL_PATH)/ssl/record/rec_layer_d1.c + $(OPENSSL_PATH)/ssl/record/rec_layer_s3.c + $(OPENSSL_PATH)/ssl/record/methods/dtls_meth.c + $(OPENSSL_PATH)/ssl/record/methods/ssl3_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls13_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls1_meth.c + $(OPENSSL_PATH)/ssl/record/methods/tls_common.c + $(OPENSSL_PATH)/ssl/record/methods/tls_multib.c + $(OPENSSL_PATH)/ssl/record/methods/tlsany_meth.c + $(OPENSSL_PATH)/ssl/rio/poll_immediate.c + $(OPENSSL_PATH)/ssl/statem/extensions.c + $(OPENSSL_PATH)/ssl/statem/extensions_clnt.c + $(OPENSSL_PATH)/ssl/statem/extensions_cust.c + $(OPENSSL_PATH)/ssl/statem/statem.c + $(OPENSSL_PATH)/ssl/statem/statem_clnt.c + $(OPENSSL_PATH)/ssl/statem/statem_dtls.c + $(OPENSSL_PATH)/ssl/statem/statem_lib.c +# Autogenerated files list ends here + buildinf.h + buildinf.c + OpensslStub/ossl_store.c + OpensslStub/rand_pool.c +# OpensslStub/SslNull.c +# OpensslStub/EcSm2Null.c + OpensslStub/uefiprov.c + OpensslStub/EncoderNull.c + OpensslStub/SslStatServNull.c + OpensslStub/SslExtServNull.c + OpensslStub/CamelliaNull.c + +[Packages] + MdePkg/MdePkg.dec + CryptoPkg/CryptoPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + RngLib + +[BuildOptions] + # + # Disables the following Visual Studio compiler warnings brought by openssl source, + # so we do not break the build with /WX option: + # C4090: 'function' : different 'const' qualifiers + # C4132: 'object' : const object should be initialized (tls13_enc.c) + # C4210: nonstandard extension used: function given file scope + # C4244: conversion from type1 to type2, possible loss of data + # C4245: conversion from type1 to type2, signed/unsigned mismatch + # C4267: conversion from size_t to type, possible loss of data + # C4306: 'identifier' : conversion from 'type1' to 'type2' of greater size + # C4310: cast truncates constant value + # C4389: 'operator' : signed/unsigned mismatch (xxxx) + # C4700: uninitialized local variable 'name' used. (conf_sap.c(71)) + # C4702: unreachable code + # C4706: assignment within conditional expression + # C4819: The file contains a character that cannot be represented in the current code page + # C4133: incompatible types - from 'ASN1_TYPE *' to 'const ASN1_STRING *' (v3_genn.c(101)) + # C4319: zero extending type to type of greater size + # + MSFT:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4310 /wd4389 /wd4700 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 + MSFT:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4306 /wd4310 /wd4700 /wd4389 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 + + # + # Disable following Visual Studio 2015 compiler warnings brought by openssl source, + # so we do not break the build with /WX option: + # C4718: recursive call has no side effects, deleting + # + MSFT:*_VS2015x86_IA32_CC_FLAGS = /wd4718 + MSFT:*_VS2015x86_X64_CC_FLAGS = /wd4718 + + INTEL:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /w + INTEL:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /w + + # + # Suppress the following build warnings in openssl so we don't break the build with -Werror + # -Werror=maybe-uninitialized: there exist some other paths for which the variable is not initialized. + # -Werror=format: Check calls to printf and scanf, etc., to make sure that the arguments supplied have + # types appropriate to the format string specified. + # -Werror=unused-but-set-variable: Warn whenever a local variable is assigned to, but otherwise unused (aside from its declaration). + # + GCC:*_*_IA32_CC_FLAGS = -U_WIN32 -UWIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) -Wno-error=maybe-uninitialized -Wno-error=unused-but-set-variable + GCC:*_*_X64_CC_FLAGS = -U_WIN32 -UWIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) -Wno-error=maybe-uninitialized -Wno-error=format -Wno-format -Wno-error=unused-but-set-variable -DNO_MSABI_VA_FUNCS + GCC:*_*_AARCH64_CC_FLAGS = $(OPENSSL_FLAGS) -Wno-error=maybe-uninitialized -Wno-format -Wno-error=unused-but-set-variable -Wno-error=format + GCC:*_*_RISCV64_CC_FLAGS = $(OPENSSL_FLAGS) -Wno-error=maybe-uninitialized -Wno-format -Wno-error=unused-but-set-variable + GCC:*_*_LOONGARCH64_CC_FLAGS = $(OPENSSL_FLAGS) -Wno-error=maybe-uninitialized -Wno-format -Wno-error=unused-but-set-variable + GCC:*_CLANGDWARF_*_CC_FLAGS = -std=c99 -Wno-error=uninitialized -Wno-error=incompatible-pointer-types -Wno-error=pointer-sign -Wno-error=implicit-function-declaration -Wno-error=ignored-pragma-optimize + GCC:*_CLANGPDB_*_CC_FLAGS = -U_WIN32 -UWIN32 -U_WIN64 -U_MSC_VER -std=c99 -Wno-error=uninitialized -Wno-error=incompatible-pointer-types -Wno-error=pointer-sign -Wno-error=implicit-function-declaration -Wno-error=ignored-pragma-optimize -Wno-error=unused-function + + # suppress the following warnings in openssl so we don't break the build with warnings-as-errors: + # 1295: Deprecated declaration - give arg types + # 550: was set but never used + # 1293: assignment in condition + # 111: statement is unreachable (invariably "break;" after "return X;" in case statement) + # 68: integer conversion resulted in a change of sign ("if (Status == -1)") + # 177: was declared but never referenced + # 223: function declared implicitly + # 144: a value of type cannot be used to initialize an entity of type + # 513: a value of type cannot be assigned to an entity of type + # 188: enumerated type mixed with another type (i.e. passing an integer as an enum without a cast) + # 1296: Extended constant initialiser used + # 128: loop is not reachable - may be emitted inappropriately if code follows a conditional return + # from the function that evaluates to true at compile time + # 546: transfer of control bypasses initialization - may be emitted inappropriately if the uninitialized + # variable is never referenced after the jump + # 1: ignore "#1-D: last line of file ends without a newline" + # 3017: may be used before being set (NOTE: This was fixed in OpenSSL 1.1 HEAD with + # commit d9b8b89bec4480de3a10bdaf9425db371c19145b, and can be dropped then.) + XCODE:*_*_IA32_CC_FLAGS = -mmmx -msse -U_WIN32 -U_WIN64 $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) -w -std=c99 -Wno-error=uninitialized -DOPENSSL_NO_APPLE_CRYPTO_RANDOM + XCODE:*_*_X64_CC_FLAGS = -mmmx -msse -U_WIN32 -U_WIN64 $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) -w -std=c99 -Wno-error=uninitialized -DOPENSSL_NO_APPLE_CRYPTO_RANDOM + + # + # AARCH64 uses strict alignment and avoids SIMD registers for code that may execute + # with the MMU off. This involves SEC, PEI_CORE and PEIM modules as well as BASE + # libraries, given that they may be included into such modules. + # This library, even though of the BASE type, is never used in such cases, and + # avoiding the SIMD register file (which is shared with the FPU) prevents the + # compiler from successfully building some of the OpenSSL source files that + # use floating point types, so clear the flags here. + # + GCC:*_*_AARCH64_CC_XIPFLAGS == diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFullLite.uni b/CryptoPkg/Library/OpensslLib/OpensslLibFullLite.uni new file mode 100644 index 0000000000..c642e61fbe --- /dev/null +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFullLite.uni @@ -0,0 +1,12 @@ +// /** @file +// This module provides OpenSSL Library implementation with TLS and ECC features but lite version (no-camellia, no-dh, no-ecx). +// +// Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "OpenSSL Library implementation with TLS and ECC features but lite version (no-camellia, no-dh, no-ecx) " + +#string STR_MODULE_DESCRIPTION #language en-US "This module provides OpenSSL Library implementation with TLS and ECC features but lite version (no-camellia, no-dh, no-ecx)." diff --git a/CryptoPkg/Library/OpensslLib/OpensslStub/CamelliaNull.c b/CryptoPkg/Library/OpensslLib/OpensslStub/CamelliaNull.c index 61d67b972a..229f887214 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslStub/CamelliaNull.c +++ b/CryptoPkg/Library/OpensslLib/OpensslStub/CamelliaNull.c @@ -10,6 +10,8 @@ #include #undef EDK2_OPENSSL_NOEC +#include +#undef OPENSSL_NO_CAMELLIA #include diff --git a/CryptoPkg/Library/OpensslLib/OpensslStub/DhNull.c b/CryptoPkg/Library/OpensslLib/OpensslStub/DhNull.c new file mode 100644 index 0000000000..179f6c5cf1 --- /dev/null +++ b/CryptoPkg/Library/OpensslLib/OpensslStub/DhNull.c @@ -0,0 +1,96 @@ +/** @file + Null implementation of DH functions called by BaseCryptLib. + + Copyright (c) 2026, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#undef OPENSSL_NO_DH +#include +#include + +DH * +DH_new ( + void + ) +{ + ASSERT (FALSE); + return NULL; +} + +void +DH_free ( + DH *dh + ) +{ + ASSERT (FALSE); +} + +int +DH_generate_parameters_ex ( + DH *dh, + int prime_len, + int generator, + BN_GENCB *cb + ) +{ + ASSERT (FALSE); + return 0; +} + +void +DH_get0_pqg ( + const DH *dh, + const BIGNUM **p, + const BIGNUM **q, + const BIGNUM **g + ) +{ + ASSERT (FALSE); +} + +int +DH_set0_pqg ( + DH *dh, + BIGNUM *p, + BIGNUM *q, + BIGNUM *g + ) +{ + ASSERT (FALSE); + return 0; +} + +int +DH_generate_key ( + DH *dh + ) +{ + ASSERT (FALSE); + return 0; +} + +void +DH_get0_key ( + const DH *dh, + const BIGNUM **pub_key, + const BIGNUM **priv_key + ) +{ + ASSERT (FALSE); +} + +int +DH_compute_key ( + unsigned char *key, + const BIGNUM *pub_key, + DH *dh + ) +{ + ASSERT (FALSE); + return 0; +} diff --git a/CryptoPkg/Library/OpensslLib/configure.py b/CryptoPkg/Library/OpensslLib/configure.py index 4b70006064..d82eb98d2d 100755 --- a/CryptoPkg/Library/OpensslLib/configure.py +++ b/CryptoPkg/Library/OpensslLib/configure.py @@ -8,7 +8,7 @@ import pprint import argparse import subprocess -def openssl_configure(openssldir, target, ec = True): +def openssl_configure(openssldir, target, ec = True, lite = True): """ Run openssl Configure script. """ cmdline = [ 'perl', @@ -93,8 +93,10 @@ def openssl_configure(openssldir, target, ec = True): ] if not ec: cmdline += [ 'no-ec', 'no-camellia', 'no-cmac' ] + if lite: + cmdline += [ 'no-camellia', 'no-dh', 'no-ecx'] print('') - print(f'# -*- configure openssl for {target} (ec={ec}) -*-') + print(f'# -*- configure openssl for {target} (ec={ec}, lite={lite}) -*-') rc = subprocess.run(cmdline, cwd = openssldir, stdout = subprocess.PIPE, stderr = subprocess.PIPE) @@ -345,13 +347,16 @@ def main(): opensslgendir = os.path.join(os.getcwd(), 'OpensslGen') # asm accel configs (see UefiAsm.conf) - for ec in [True, False]: - if ec: + for ec, lite in [(True, True), (False, False), (True, False)]: + if ec and not lite: inf = 'OpensslLibFullAccel.inf' hdr = 'configuration-ec.h' - else: + elif not ec and not lite: inf = 'OpensslLibAccel.inf' hdr = 'configuration-noec.h' + elif ec and lite: + inf = 'OpensslLibFullAccelLite.inf' + hdr = 'configuration-ec-lite.h' sources = {} defines = {} for asm in [ 'UEFI-IA32-MSFT', 'UEFI-IA32-GCC', @@ -360,7 +365,7 @@ def main(): (uefi, arch, cc) = asm.split('-') archcc = f'{arch}-{cc}' - openssl_configure(openssldir, asm, ec = ec); + openssl_configure(openssldir, asm, ec = ec, lite=lite) cfg = get_configdata(openssldir) generate_all_files(openssldir, opensslgendir, archcc, cfg) shutil.move(os.path.join(opensslgendir, 'include', 'openssl', 'configuration.h'), @@ -388,7 +393,7 @@ def main(): update_inf(inf, aarch64accel, 'AARCH64', defines['AARCH64']) # noaccel - ec enabled - openssl_configure(openssldir, 'UEFI', ec = True); + openssl_configure(openssldir, 'UEFI', ec = True, lite=False) cfg = get_configdata(openssldir) generate_all_files(openssldir, opensslgendir, None, cfg) openssl_run_make(openssldir, 'distclean') @@ -402,7 +407,7 @@ def main(): defines) # noaccel - ec disabled - openssl_configure(openssldir, 'UEFI', ec = False); + openssl_configure(openssldir, 'UEFI', ec=False, lite=False) cfg = get_configdata(openssldir) generate_all_files(openssldir, opensslgendir, None, cfg) openssl_run_make(openssldir, 'distclean') @@ -414,11 +419,27 @@ def main(): libcrypto_sources(cfg) + libssl_sources(cfg), None, defines) + # lite version (full but lite) - ec enabled + openssl_configure(openssldir, 'UEFI', ec=True, lite=True) + cfg = get_configdata(openssldir) + generate_all_files(openssldir, opensslgendir, None, cfg) + openssl_run_make(openssldir, 'distclean') + + defines = [] + if 'libcrypto' in cfg['unified_info']['defines']: + defines = cfg['unified_info']['defines']['libcrypto'] + + update_inf('OpensslLibFullLite.inf', + libcrypto_sources(cfg) + libssl_sources(cfg), + None, defines) + # wrap header file confighdr = os.path.join(opensslgendir, 'include', 'openssl', 'configuration.h') with open(confighdr, 'w') as f: - f.write('#ifdef EDK2_OPENSSL_NOEC\r\n' + f.write('#if defined(EDK2_OPENSSL_NOEC)\r\n' '# include "configuration-noec.h"\r\n' + '#elif defined(EDK2_OPENSSL_LITE)\r\n' + '# include "configuration-ec-lite.h"\r\n' '#else\r\n' '# include "configuration-ec.h"\r\n' '#endif\r\n') From 68df5172e57b9b671d981d01035aa8377675ec63 Mon Sep 17 00:00:00 2001 From: Chris Fernald Date: Thu, 11 Jun 2026 13:40:07 -0700 Subject: [PATCH 004/406] Maintainers.txt: Add Chris Fernald as maintainer to SecurityPkg Signed-off-by: Chris Fernald --- Maintainers.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Maintainers.txt b/Maintainers.txt index 44a1998aea..2952caea1d 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -629,6 +629,7 @@ SecurityPkg F: SecurityPkg/ W: https://www.tianocore.org/tianocore-wiki.github.io/platforms-packages/core-packages/security_pkg.html M: Jiewen Yao [jyao1] +M: Chris Fernald [cfernald] SecurityPkg: Secure boot related modules F: SecurityPkg/Library/DxeImageVerificationLib/ From d7bf8b91f327914e67605e0f26d5d60b4a368bb9 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Wed, 10 Jun 2026 16:04:55 -0400 Subject: [PATCH 005/406] .mergify/config.yml: Explicitly set reporting_method to check-runs The default value of merge_protections_settings.reporting_method is changing from check-runs to deployments. This commit updates the mergify configuration to explicitly set check-runs to preserve current behavior. (deadline: 2026-07-31) --- This was originally auto-generated by the Mergify bot in a PR to the edk2 repo. That change did not comply with edk2 commit requirements and modified the line endings of the file. It is manually recreated here with the correct line endings and commit message format. Signed-off-by: Michael Kubacki --- .mergify/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.mergify/config.yml b/.mergify/config.yml index 09ea7f9923..46ca46da26 100644 --- a/.mergify/config.yml +++ b/.mergify/config.yml @@ -52,3 +52,7 @@ pull_request_rules: actions: comment: message: PR can not be merged due to conflict. Please rebase and resubmit + +merge_protections_settings: + reporting_method: check-runs + From d48465508bd7ef0777e627ff9fd07d67ef92ae93 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Mon, 8 Jun 2026 19:30:38 -0700 Subject: [PATCH 006/406] UefiCpuPkg: RiscV64: CpuTimerLib: Add SEC/PEI and DXE library instances Commit c27b5554 introduced a constructor that calls GetPerformanceCounterProperties() to help initializing mTimeBase early. However, in the PEI phase, this constructor may run before the HOB list is available, leading to a crash. This patch fixes the issue by providing a separate library instances for the SEC/PEI phases that avoid invoking this constructor. Also, rename this library as it can not be base library anymore. Signed-off-by: Tuan Phan --- .../CpuTimerLib.c | 4 +-- .../RiscV64CpuTimerDxeLib.inf} | 11 +++--- .../RiscV64CpuTimerLib.uni} | 0 .../RiscV64CpuTimerSecLib.inf | 36 +++++++++++++++++++ UefiCpuPkg/UefiCpuPkg.dsc | 3 +- 5 files changed, 46 insertions(+), 8 deletions(-) rename UefiCpuPkg/Library/{BaseRiscV64CpuTimerLib => RiscV64CpuTimerLib}/CpuTimerLib.c (95%) rename UefiCpuPkg/Library/{BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf => RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf} (58%) rename UefiCpuPkg/Library/{BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.uni => RiscV64CpuTimerLib/RiscV64CpuTimerLib.uni} (100%) create mode 100644 UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c b/UefiCpuPkg/Library/RiscV64CpuTimerLib/CpuTimerLib.c similarity index 95% rename from UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c rename to UefiCpuPkg/Library/RiscV64CpuTimerLib/CpuTimerLib.c index df4f8c2245..243ae48c33 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c +++ b/UefiCpuPkg/Library/RiscV64CpuTimerLib/CpuTimerLib.c @@ -124,7 +124,7 @@ GetPerformanceCounter ( return (UINT64)RiscVReadTimer (); } -/**return +/** Retrieves the 64-bit frequency in Hz and the range of performance counter values. @@ -275,7 +275,7 @@ GetTimeInNanoSecond ( **/ EFI_STATUS EFIAPI -BaseRiscV64CpuTimerLibConstructor ( +RiscV64CpuTimerLibConstructor ( VOID ) { diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf b/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf similarity index 58% rename from UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf rename to UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf index a3d25cda41..999d601005 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf +++ b/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf @@ -1,8 +1,9 @@ ## @file -# RISC-V Base CPU Timer Library Instance +# RISC-V CPU Timer Library Instance # # Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# Copyright (C) 2026 Qualcomm Technologies, Inc. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -10,13 +11,13 @@ [Defines] INF_VERSION = 0x0001001B - BASE_NAME = BaseRisV64CpuTimerLib + BASE_NAME = RiscV64CpuTimerDxeLib FILE_GUID = B635A600-EA24-4199-88E8-5761EEA96A51 MODULE_TYPE = BASE VERSION_STRING = 1.0 - LIBRARY_CLASS = TimerLib - MODULE_UNI_FILE = BaseRisV64CpuTimerLib.uni - CONSTRUCTOR = BaseRiscV64CpuTimerLibConstructor + LIBRARY_CLASS = TimerLib | DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION + MODULE_UNI_FILE = RiscV64CpuTimerLib.uni + CONSTRUCTOR = RiscV64CpuTimerLibConstructor [Sources] CpuTimerLib.c diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.uni b/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerLib.uni similarity index 100% rename from UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.uni rename to UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerLib.uni diff --git a/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf b/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf new file mode 100644 index 0000000000..e4f0bf36e4 --- /dev/null +++ b/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf @@ -0,0 +1,36 @@ +## @file +# RISC-V CPU Timer Library Instance +# +# Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
+# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# Copyright (C) 2026 Qualcomm Technologies, Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = RiscV64CpuTimerSecLib + FILE_GUID = 59D73C04-6D8F-4F7A-A444-86F059CCF939 + MODULE_TYPE = SEC + VERSION_STRING = 1.0 + LIBRARY_CLASS = TimerLib | SEC PEI_CORE PEIM + MODULE_UNI_FILE = RiscV64CpuTimerLib.uni + +[Sources] + CpuTimerLib.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + PcdLib + DebugLib + FdtLib + HobLib + +[Guids] + gFdtHobGuid diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index e7a72a370c..f281c1174b 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -224,8 +224,9 @@ UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf [Components.RISCV64] - UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf + UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf + UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf From 04bf52c212d1b97bbc8b4ac0c7f53b1bb7e1a111 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Mon, 15 Jun 2026 19:16:54 -0700 Subject: [PATCH 007/406] UefiCpuPkg: RiscV64: CpuTimerLib: Fix coding style error Fixed coding style reported by Ecc tool. Signed-off-by: Tuan Phan --- .../Library/RiscV64CpuTimerLib/CpuTimerLib.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/UefiCpuPkg/Library/RiscV64CpuTimerLib/CpuTimerLib.c b/UefiCpuPkg/Library/RiscV64CpuTimerLib/CpuTimerLib.c index 243ae48c33..0244dc57ef 100644 --- a/UefiCpuPkg/Library/RiscV64CpuTimerLib/CpuTimerLib.c +++ b/UefiCpuPkg/Library/RiscV64CpuTimerLib/CpuTimerLib.c @@ -159,6 +159,9 @@ GetPerformanceCounterProperties ( CONST EFI_GUID SecHobDataGuid = RISCV_SEC_HANDOFF_HOB_GUID; UINT64 TimeBase; CONST VOID *FdtBase; + INT32 Node; + INT32 Len; + CONST FDT_PROPERTY *Prop; if (StartValue != NULL) { *StartValue = 0; @@ -194,22 +197,14 @@ GetPerformanceCounterProperties ( // // /cpus node // - INT32 Node = FdtSubnodeOffsetNameLen ( - FdtBase, - 0, - "cpus", - sizeof ("cpus") - 1 - ); - + Node = FdtSubnodeOffsetNameLen (FdtBase, 0, "cpus", (INT32)AsciiStrLen ("cpus")); ASSERT (Node >= 0); // // timebase-frequency property // - INT32 Len; - CONST FDT_PROPERTY *Prop = - FdtGetProperty (FdtBase, Node, "timebase-frequency", &Len); - + Len = 0; + Prop = FdtGetProperty (FdtBase, Node, "timebase-frequency", &Len); ASSERT (Prop != NULL && Len == sizeof (UINT32)); // From 8812785128a3574abf5da87cd3388bd435073a7f Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Mon, 8 Jun 2026 19:45:20 -0700 Subject: [PATCH 008/406] OvmfPkg/RiscVVirt: Add TimerLib instance for SEC/PEI and DXE Provide separate TimerLib instances for the SEC, PEI and DXE phases. Signed-off-by: Tuan Phan --- OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 40 +++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc index 261226de01..7d16fc6a30 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc @@ -114,7 +114,6 @@ DxeRiscvMpxyLib|MdePkg/Library/DxeRiscvMpxyLib/DxeRiscvMpxy.inf DxeRasAgentClientLib|MdePkg/Library/DxeRiscvRasAgentClientLib/DxeRiscvRasAgentClientLib.inf - TimerLib|UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf VirtNorFlashDeviceLib|OvmfPkg/Library/VirtNorFlashDeviceLib/VirtNorFlashDeviceLib.inf VirtNorFlashPlatformLib|OvmfPkg/RiscVVirt/Library/VirtNorFlashPlatformLib/VirtNorFlashDeviceTreeLib.inf @@ -156,7 +155,24 @@ RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf !endif +[LibraryClasses.common.SEC] + TimerLib|UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf + +[LibraryClasses.common.PEI_CORE, LibraryClasses.common.PEIM] + TimerLib|UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf +!if $(TPM2_ENABLE) == TRUE + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf +!else + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf +!endif + +[LibraryClasses.common.DXE_CORE] + TimerLib|UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf + [LibraryClasses.common.DXE_DRIVER] + TimerLib|UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf @@ -165,15 +181,20 @@ Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf !endif -[LibraryClasses.common.UEFI_DRIVER] - UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf - PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf - [LibraryClasses.common.DXE_RUNTIME_DRIVER] + TimerLib|UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf !if $(CAPSULE_ENABLE) == TRUE CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf !endif +[LibraryClasses.common.UEFI_DRIVER] + TimerLib|UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf + UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf + PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf + +[LibraryClasses.common.UEFI_APPLICATION] + TimerLib|UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf + ################################################################################ # # Pcd Section - list of all EDK II PCD Entries defined by this Platform. @@ -292,15 +313,6 @@ gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|5 -[LibraryClasses.common.PEI_CORE, LibraryClasses.common.PEIM] -!if $(TPM2_ENABLE) == TRUE - PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf - BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf - Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf -!else - PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf -!endif - ################################################################################ # # Components Section - list of all EDK II Modules needed by this Platform. From 58cd060ae6e78d6d5b098f1f330cc8a18d830af3 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Mon, 15 Jun 2026 15:43:51 -0400 Subject: [PATCH 009/406] .github: Use windows-2022 for UPL build Currently, the UPL fails on Windows hosts because it specifies the `windows-latest` image which has moved on to Visual Studio 2026 while the build uses VS2022. The decision to move the actual build to a later Visual Studio version can be made independently, but for now, this change allows the UPL build to succeed on GitHub hosted runner Windows hosts. Signed-off-by: Michael Kubacki --- .github/workflows/upl-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/upl-build.yml b/.github/workflows/upl-build.yml index 10fd4ad5cd..73480f08a5 100644 --- a/.github/workflows/upl-build.yml +++ b/.github/workflows/upl-build.yml @@ -17,7 +17,7 @@ jobs: build_vs2022: strategy: matrix: - os: [windows-latest] + os: [windows-2022] python-version: ['3.12'] tool-chain: ['VS2022'] target: ['DEBUG'] From e78042379cb6edfcb3633b28b8de34db2fb84fa7 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 12 Jun 2026 19:04:16 -0400 Subject: [PATCH 010/406] BaseTools: Update tools_def.template version to 3.07 Commit 87e486f defined a 3.07 version for tools_def.template, but the version in the file was not updated. This commit updates the version to 3.07 and includes changes made since 3.06. Signed-off-by: Michael Kubacki --- BaseTools/Conf/tools_def.template | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index 43452f7613..d61c704c92 100644 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -27,8 +27,15 @@ # 3.05 - Add CLANGPDB AARCH64 Support # 3.06 - Remove GCC48, GCC49 and GCC5 # 3.07 - Switch alignemnt to 4k for X64 builds add XIP_FLAGS. +# - Add --apply-dynamic-relocs option for AARCH64 CLANGDWARF builds +# - Add missing CLANGDWARF OBJCOPY_FLAGS +# - Canonicalize CLANGDWARF definitions +# - Align X64 CLANGDWARF and CLANGPDB definitions +# - Add GENFWHII_FLAGS to fix VS2026 GenFw build issue +# - Add -malign-double to IA32 ASLCC_FLAGS +# - Add CLANGDWARF support for LoongArch64 # -#!VERSION=3.06 +#!VERSION=3.07 IDENTIFIER = Default TOOL_CHAIN_CONF From 02fa0cb9116f9c46d01abd7df5de1af3ebf2680c Mon Sep 17 00:00:00 2001 From: Jared Pan Date: Mon, 1 Jun 2026 15:00:50 +0800 Subject: [PATCH 011/406] MdeModulePkg/ReportStatusCodeRouter: Prevent recursive entry in PEI phase Prevent recursive invocation of the PEI Report Status Code (RSC) Router that can lead to system hang or unexpected re-entrancy behavior during early boot. The defect was observed when PEI modules reported status codes while the router was already processing a previous request. This patch aligns PEI behavior with the robust RSC routing mechanisms already used in DXE and Runtime phases by adding a lightweight recursion guard to the PEI router. This ensures consistent behavior across boot stages and improves early-boot stability. Signed-off-by: Jared Pan --- .../Pei/ReportStatusCodeRouterPei.c | 67 ++++++++++++++++++- .../Pei/ReportStatusCodeRouterPei.h | 5 ++ .../Pei/ReportStatusCodeRouterPei.inf | 1 + 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.c b/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.c index e1b1021b41..318b79ccab 100644 --- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.c +++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.c @@ -33,6 +33,38 @@ EFI_PEI_PPI_DESCRIPTOR mStatusCodePpiList[] = { } }; +// +// GUID for the Report Status Code Router nest status HOB. +// This HOB stores the reentrant lock to prevent recursive calls in PEI phase. +// +EFI_GUID mRscRouterNestStatusHobGuid = RSC_ROUTER_NEST_STATUS_HOB_GUID; + +typedef struct { + UINT32 NestStatus; +} RSC_ROUTER_NEST_STATUS_HOB; + +/** + Check the RSC Router nest status HOB. + + @return Pointer to the RSC_ROUTER_NEST_STATUS_HOB data, or NULL on failure. + +**/ +STATIC +RSC_ROUTER_NEST_STATUS_HOB * +CheckNestStatusHob ( + VOID + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + + GuidHob = GetFirstGuidHob (&mRscRouterNestStatusHobGuid); + if (GuidHob != NULL) { + return GET_GUID_HOB_DATA (GuidHob); + } + + return NULL; +} + /** Worker function to create one memory status code GUID'ed HOB, using PacketIndex to identify the packet. @@ -241,6 +273,17 @@ ReportDispatcher ( EFI_PEI_RSC_HANDLER_CALLBACK *CallbackEntry; UINTN *NumberOfEntries; UINTN Index; + RSC_ROUTER_NEST_STATUS_HOB *NestStatusHob; + + // + // Use atom operation to avoid the reentant of report. + // If current status is not zero, then the function is reentrancy. + // + NestStatusHob = CheckNestStatusHob (); + + if ((NestStatusHob != NULL) && ((InterlockedCompareExchange32 (&NestStatusHob->NestStatus, 0, 1) == 1))) { + return EFI_DEVICE_ERROR; + } Hob.Raw = GetFirstGuidHob (&gStatusCodeCallbackGuid); while (Hob.Raw != NULL) { @@ -263,6 +306,13 @@ ReportDispatcher ( Hob.Raw = GetNextGuidHob (&gStatusCodeCallbackGuid, Hob.Raw); } + // + // Restore the nest status of report + // + if (NestStatusHob != NULL) { + InterlockedCompareExchange32 (&NestStatusHob->NestStatus, 1, 0); + } + return EFI_SUCCESS; } @@ -285,12 +335,23 @@ GenericStatusCodePeiEntry ( IN CONST EFI_PEI_SERVICES **PeiServices ) { - EFI_STATUS Status; - EFI_PEI_PPI_DESCRIPTOR *OldDescriptor; - EFI_PEI_PROGRESS_CODE_PPI *OldStatusCodePpi; + EFI_STATUS Status; + EFI_PEI_PPI_DESCRIPTOR *OldDescriptor; + EFI_PEI_PROGRESS_CODE_PPI *OldStatusCodePpi; + RSC_ROUTER_NEST_STATUS_HOB *NestStatusHob; CreateRscHandlerCallbackPacket (); + // + // Build NestStatus HOB for installing PPIs to avoid recursive calls. + // + if (GetFirstGuidHob (&mRscRouterNestStatusHobGuid) == NULL) { + NestStatusHob = BuildGuidHob (&mRscRouterNestStatusHobGuid, sizeof (RSC_ROUTER_NEST_STATUS_HOB)); + if (NestStatusHob != NULL) { + NestStatusHob->NestStatus = 0; + } + } + // // Install Report Status Code Handler PPI // diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.h b/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.h index 6d07186b67..e4c66c0883 100644 --- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.h +++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.h @@ -17,6 +17,11 @@ #include #include #include +#include + +#define RSC_ROUTER_NEST_STATUS_HOB_GUID { \ + 0x7a1a8e9e, 0x2c3f, 0x4a5b, { 0x8d, 0x1c, 0x3e, 0x72, 0xa9, 0x1f, 0x6b, 0x04 } \ + } /** Register the callback function for ReportStatusCode() notification. diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf b/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf index a53d0587e9..32ae28b405 100644 --- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf +++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf @@ -37,6 +37,7 @@ PeiServicesLib DebugLib HobLib + SynchronizationLib [Guids] ## PRODUCES ## HOB From fde05ad8f6cc72c571542b52e2e587377b8dd5bc Mon Sep 17 00:00:00 2001 From: rdiaz Date: Thu, 23 Oct 2025 01:03:58 +0000 Subject: [PATCH 012/406] SecurityPkg: Introduce Tpm2HelpLib Creation of a new Tpm2HelpLib which contains the functions from Tpm2Help.c. This new library is meant to replace Tpm2Help.c such that inclusion of Tpm2CommandLib and Tpm2DeviceLib is not required when only needing access to the Tpm2Help.c functions. Due to Tpm2HelpLib being a new library, the prefix Tpm2 has been added to all library functions to indicate where the functions originate from. Signed-off-by: Raymond Diaz --- SecurityPkg/Include/Library/Tpm2HelpLib.h | 186 ++++++ SecurityPkg/Library/Tpm2HelpLib/Tpm2Help.c | 562 ++++++++++++++++++ .../Library/Tpm2HelpLib/Tpm2HelpLib.inf | 30 + SecurityPkg/SecurityPkg.dec | 4 + SecurityPkg/SecurityPkg.dsc | 2 + 5 files changed, 784 insertions(+) create mode 100644 SecurityPkg/Include/Library/Tpm2HelpLib.h create mode 100644 SecurityPkg/Library/Tpm2HelpLib/Tpm2Help.c create mode 100644 SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf diff --git a/SecurityPkg/Include/Library/Tpm2HelpLib.h b/SecurityPkg/Include/Library/Tpm2HelpLib.h new file mode 100644 index 0000000000..758dc17a6b --- /dev/null +++ b/SecurityPkg/Include/Library/Tpm2HelpLib.h @@ -0,0 +1,186 @@ +/** @file + Declares reusable TPM 2.0 data helper routines that are independent + of TPM command/device communication libraries. Includes serialization + and parsing helpers for common TPM data structures. + +Copyright (c) Microsoft Corporation. +Copyright (c) 2013 - 2024, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#pragma once + +#include + +/** + Return size of digest. + + @param[in] HashAlgo Hash algorithm + + @return size of digest +**/ +UINT16 +EFIAPI +Tpm2GetHashSizeFromAlgo ( + IN TPMI_ALG_HASH HashAlgo + ); + +/** + Get hash mask from algorithm. + + @param[in] HashAlgo Hash algorithm + + @return Hash mask +**/ +UINT32 +EFIAPI +Tpm2GetHashMaskFromAlgo ( + IN TPMI_ALG_HASH HashAlgo + ); + +/** + Copy AuthSessionIn to TPM2 command buffer. + + @param [in] AuthSessionIn Input AuthSession data + @param [out] AuthSessionOut Output AuthSession data in TPM2 command buffer + + @return AuthSession size +**/ +UINT32 +EFIAPI +Tpm2CopyAuthSessionCommand ( + IN TPMS_AUTH_COMMAND *AuthSessionIn OPTIONAL, + OUT UINT8 *AuthSessionOut + ); + +/** + Copy AuthSessionIn from TPM2 response buffer. + + @param [in] AuthSessionIn Input AuthSession data in TPM2 response buffer + @param [out] AuthSessionOut Output AuthSession data + + @return AuthSession size +**/ +UINT32 +EFIAPI +Tpm2CopyAuthSessionResponse ( + IN UINT8 *AuthSessionIn, + OUT TPMS_AUTH_RESPONSE *AuthSessionOut OPTIONAL + ); + +/** + Return if hash alg is supported in HashAlgorithmMask. + + @param HashAlg Hash algorithm to be checked. + @param HashAlgorithmMask Bitfield of allowed hash algorithms. + + @retval TRUE Hash algorithm is supported. + @retval FALSE Hash algorithm is not supported. +**/ +BOOLEAN +EFIAPI +Tpm2IsHashAlgSupportedInHashAlgorithmMask ( + IN TPMI_ALG_HASH HashAlg, + IN UINT32 HashAlgorithmMask + ); + +/** + Copy TPML_DIGEST_VALUES into a buffer + + @param[in,out] Buffer Buffer to hold copied TPML_DIGEST_VALUES compact binary. + @param[in] DigestList TPML_DIGEST_VALUES to be copied. + @param[in] HashAlgorithmMask HASH bits corresponding to the desired digests to copy. + + @return The end of buffer to hold TPML_DIGEST_VALUES. +**/ +VOID * +EFIAPI +Tpm2CopyDigestListToBuffer ( + IN OUT VOID *Buffer, + IN TPML_DIGEST_VALUES *DigestList, + IN UINT32 HashAlgorithmMask + ); + +/** + Copy a buffer into a TPML_DIGEST_VALUES structure. + + @param[in] Buffer Buffer to hold TPML_DIGEST_VALUES compact binary. + @param[in] BufferSize Size of Buffer. + @param[out] DigestList TPML_DIGEST_VALUES. + + @return EFI_STATUS + @retval EFI_SUCCESS Buffer was successfully copied to Digest List. + @retval EFI_BAD_BUFFER_SIZE Bad buffer size passed to function. + @retval EFI_INVALID_PARAMETER Invalid parameter passed to function: NULL pointer or + BufferSize bigger than TPML_DIGEST_VALUES +**/ +EFI_STATUS +EFIAPI +Tpm2CopyBufferToDigestList ( + IN CONST VOID *Buffer, + IN UINTN BufferSize, + OUT TPML_DIGEST_VALUES *DigestList + ); + +/** + Get TPML_DIGEST_VALUES data size. + + @param[in] DigestList TPML_DIGEST_VALUES data. + + @return TPML_DIGEST_VALUES data size. +**/ +UINT32 +EFIAPI +Tpm2GetDigestListSize ( + IN TPML_DIGEST_VALUES *DigestList + ); + +/** + Get TPML_DIGEST_VALUES data size from HashAlgorithmMask + + @param[in] HashAlgorithmMask Bitfield of allowed hash algorithms + + @return TPML_DIGEST_VALUES data size. +**/ +UINT32 +EFIAPI +Tpm2GetDigestListSizeFromHashAlgorithmMask ( + IN UINT32 HashAlgorithmMask + ); + +/** + This function get digest from digest list. + + @param[in] HashAlg Digest algorithm + @param[in] DigestList Digest list + @param[out] Digest Digest + + @retval EFI_SUCCESS Digest is found and returned. + @retval EFI_NOT_FOUND Digest is not found. + @retval EFI_INVALID_PARAMETER DigestList or Digest invalid. +**/ +EFI_STATUS +EFIAPI +Tpm2GetDigestFromDigestList ( + IN TPMI_ALG_HASH HashAlg, + IN TPML_DIGEST_VALUES *DigestList, + OUT VOID *Digest + ); + +/** + Check if all hash algorithms supported in HashAlgorithmMask are + present in the DigestList. + + @param DigestList Digest list + @param HashAlgorithmMask Bitfield of allowed hash algorithms. + + @retval TRUE All hash algorithms present. + @retval FALSE Some hash algorithms not present. +**/ +BOOLEAN +EFIAPI +Tpm2IsDigestListInSyncWithHashAlgorithmMask ( + IN TPML_DIGEST_VALUES *DigestList, + IN UINT32 HashAlgorithmMask + ); diff --git a/SecurityPkg/Library/Tpm2HelpLib/Tpm2Help.c b/SecurityPkg/Library/Tpm2HelpLib/Tpm2Help.c new file mode 100644 index 0000000000..521b842c92 --- /dev/null +++ b/SecurityPkg/Library/Tpm2HelpLib/Tpm2Help.c @@ -0,0 +1,562 @@ +/** @file + Defines reusable TPM 2.0 data helper routines that are independent + of TPM command/device communication libraries. Includes serialization + and parsing helpers for common TPM data structures. + +Copyright (c) Microsoft Corporation. +Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +typedef struct { + TPMI_ALG_HASH HashAlgo; + UINT16 HashSize; + UINT32 HashMask; +} INTERNAL_HASH_INFO; + +STATIC INTERNAL_HASH_INFO mHashInfo[] = { + { TPM_ALG_SHA1, SHA1_DIGEST_SIZE, HASH_ALG_SHA1 }, + { TPM_ALG_SHA256, SHA256_DIGEST_SIZE, HASH_ALG_SHA256 }, + { TPM_ALG_SM3_256, SM3_256_DIGEST_SIZE, HASH_ALG_SM3_256 }, + { TPM_ALG_SHA384, SHA384_DIGEST_SIZE, HASH_ALG_SHA384 }, + { TPM_ALG_SHA512, SHA512_DIGEST_SIZE, HASH_ALG_SHA512 }, +}; + +/** + Check if DigestList has an entry for HashAlg. + + @param DigestList Digest list. + @param HashAlg Hash algorithm id. + + @retval TRUE Match found. + @retval FALSE No match found. +**/ +STATIC +BOOLEAN +CheckDigestListForHashAlg ( + IN TPML_DIGEST_VALUES *DigestList, + IN TPM_ALG_ID HashAlg + ) +{ + UINT32 Index; + + if (DigestList->count > HASH_COUNT) { + return FALSE; + } + + for (Index = 0; Index < DigestList->count; Index++) { + if (DigestList->digests[Index].hashAlg == HashAlg) { + DEBUG ((DEBUG_INFO, "Hash alg 0x%x found in DigestList.\n", HashAlg)); + return TRUE; + } + } + + DEBUG ((DEBUG_INFO, "Hash alg 0x%x not found in DigestList.\n", HashAlg)); + return FALSE; +} + +/** + Return size of digest. + + @param[in] HashAlgo Hash algorithm + + @return size of digest +**/ +UINT16 +EFIAPI +Tpm2GetHashSizeFromAlgo ( + IN TPMI_ALG_HASH HashAlgo + ) +{ + UINTN Index; + + for (Index = 0; Index < sizeof (mHashInfo)/sizeof (mHashInfo[0]); Index++) { + if (mHashInfo[Index].HashAlgo == HashAlgo) { + return mHashInfo[Index].HashSize; + } + } + + return 0; +} + +/** + Get hash mask from algorithm. + + @param[in] HashAlgo Hash algorithm + + @return Hash mask +**/ +UINT32 +EFIAPI +Tpm2GetHashMaskFromAlgo ( + IN TPMI_ALG_HASH HashAlgo + ) +{ + UINTN Index; + + for (Index = 0; Index < sizeof (mHashInfo)/sizeof (mHashInfo[0]); Index++) { + if (mHashInfo[Index].HashAlgo == HashAlgo) { + return mHashInfo[Index].HashMask; + } + } + + return 0; +} + +/** + Copy AuthSessionIn to TPM2 command buffer. + + @param [in] AuthSessionIn Input AuthSession data + @param [out] AuthSessionOut Output AuthSession data in TPM2 command buffer + + @return AuthSession size +**/ +UINT32 +EFIAPI +Tpm2CopyAuthSessionCommand ( + IN TPMS_AUTH_COMMAND *AuthSessionIn OPTIONAL, + OUT UINT8 *AuthSessionOut + ) +{ + UINT8 *Buffer; + + if (AuthSessionOut == NULL) { + return 0; + } + + Buffer = (UINT8 *)AuthSessionOut; + + // + // Add in Auth session + // + if (AuthSessionIn != NULL) { + // sessionHandle + WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (AuthSessionIn->sessionHandle)); + Buffer += sizeof (UINT32); + + // nonce + WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (AuthSessionIn->nonce.size)); + Buffer += sizeof (UINT16); + + CopyMem (Buffer, AuthSessionIn->nonce.buffer, AuthSessionIn->nonce.size); + Buffer += AuthSessionIn->nonce.size; + + // sessionAttributes + *(UINT8 *)Buffer = *(UINT8 *)&AuthSessionIn->sessionAttributes; + Buffer++; + + // hmac + WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (AuthSessionIn->hmac.size)); + Buffer += sizeof (UINT16); + + CopyMem (Buffer, AuthSessionIn->hmac.buffer, AuthSessionIn->hmac.size); + Buffer += AuthSessionIn->hmac.size; + } else { + // sessionHandle + WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (TPM_RS_PW)); + Buffer += sizeof (UINT32); + + // nonce = nullNonce + WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (0)); + Buffer += sizeof (UINT16); + + // sessionAttributes = 0 + *(UINT8 *)Buffer = 0x00; + Buffer++; + + // hmac = nullAuth + WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (0)); + Buffer += sizeof (UINT16); + } + + return (UINT32)((UINTN)Buffer - (UINTN)AuthSessionOut); +} + +/** + Copy AuthSessionIn from TPM2 response buffer. + + @param [in] AuthSessionIn Input AuthSession data in TPM2 response buffer + @param [out] AuthSessionOut Output AuthSession data + + @return 0 copy failed + else AuthSession size +**/ +UINT32 +EFIAPI +Tpm2CopyAuthSessionResponse ( + IN UINT8 *AuthSessionIn, + OUT TPMS_AUTH_RESPONSE *AuthSessionOut OPTIONAL + ) +{ + UINT8 *Buffer; + TPMS_AUTH_RESPONSE LocalAuthSessionOut; + + if (AuthSessionOut == NULL) { + AuthSessionOut = &LocalAuthSessionOut; + } + + if (AuthSessionIn == NULL) { + return 0; + } + + Buffer = (UINT8 *)AuthSessionIn; + + // nonce + AuthSessionOut->nonce.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer)); + Buffer += sizeof (UINT16); + if (AuthSessionOut->nonce.size > sizeof (TPMU_HA)) { + DEBUG ((DEBUG_ERROR, "Tpm2CopyAuthSessionResponse - nonce.size error %x\n", AuthSessionOut->nonce.size)); + return 0; + } + + CopyMem (AuthSessionOut->nonce.buffer, Buffer, AuthSessionOut->nonce.size); + Buffer += AuthSessionOut->nonce.size; + + // sessionAttributes + *(UINT8 *) &AuthSessionOut->sessionAttributes = *(UINT8 *)Buffer; + Buffer++; + + // hmac + AuthSessionOut->hmac.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer)); + Buffer += sizeof (UINT16); + if (AuthSessionOut->hmac.size > sizeof (TPMU_HA)) { + DEBUG ((DEBUG_ERROR, "Tpm2CopyAuthSessionResponse - hmac.size error %x\n", AuthSessionOut->hmac.size)); + return 0; + } + + CopyMem (AuthSessionOut->hmac.buffer, Buffer, AuthSessionOut->hmac.size); + Buffer += AuthSessionOut->hmac.size; + + return (UINT32)((UINTN)Buffer - (UINTN)AuthSessionIn); +} + +/** + Return if hash alg is supported in HashAlgorithmMask. + + @param HashAlg Hash algorithm to be checked. + @param HashAlgorithmMask Bitfield of allowed hash algorithms. + + @retval TRUE Hash algorithm is supported. + @retval FALSE Hash algorithm is not supported. +**/ +BOOLEAN +EFIAPI +Tpm2IsHashAlgSupportedInHashAlgorithmMask ( + IN TPMI_ALG_HASH HashAlg, + IN UINT32 HashAlgorithmMask + ) +{ + switch (HashAlg) { + case TPM_ALG_SHA1: + if ((HashAlgorithmMask & HASH_ALG_SHA1) != 0) { + return TRUE; + } + + break; + case TPM_ALG_SHA256: + if ((HashAlgorithmMask & HASH_ALG_SHA256) != 0) { + return TRUE; + } + + break; + case TPM_ALG_SHA384: + if ((HashAlgorithmMask & HASH_ALG_SHA384) != 0) { + return TRUE; + } + + break; + case TPM_ALG_SHA512: + if ((HashAlgorithmMask & HASH_ALG_SHA512) != 0) { + return TRUE; + } + + break; + case TPM_ALG_SM3_256: + if ((HashAlgorithmMask & HASH_ALG_SM3_256) != 0) { + return TRUE; + } + + break; + } + + return FALSE; +} + +/** + Copy TPML_DIGEST_VALUES into a buffer + + @param[in,out] Buffer Buffer to hold copied TPML_DIGEST_VALUES compact binary. + @param[in] DigestList TPML_DIGEST_VALUES to be copied. + @param[in] HashAlgorithmMask HASH bits corresponding to the desired digests to copy. + + @return The end of buffer to hold TPML_DIGEST_VALUES, NULL otherwise. +**/ +VOID * +EFIAPI +Tpm2CopyDigestListToBuffer ( + IN OUT VOID *Buffer, + IN TPML_DIGEST_VALUES *DigestList, + IN UINT32 HashAlgorithmMask + ) +{ + UINTN Index; + UINT16 DigestSize; + UINT32 DigestListCount; + UINT32 *DigestListCountPtr; + + if ((Buffer == NULL) || (DigestList == NULL)) { + return NULL; + } + + if (DigestList->count > HASH_COUNT) { + return NULL; + } + + DigestListCountPtr = (UINT32 *)Buffer; + DigestListCount = 0; + Buffer = (UINT8 *)Buffer + sizeof (DigestList->count); + for (Index = 0; Index < DigestList->count; Index++) { + if (!Tpm2IsHashAlgSupportedInHashAlgorithmMask (DigestList->digests[Index].hashAlg, HashAlgorithmMask)) { + DEBUG ((DEBUG_ERROR, "WARNING: TPM2 Event log has HashAlg unsupported by PCR bank (0x%x)\n", DigestList->digests[Index].hashAlg)); + continue; + } + + CopyMem (Buffer, &DigestList->digests[Index].hashAlg, sizeof (DigestList->digests[Index].hashAlg)); + Buffer = (UINT8 *)Buffer + sizeof (DigestList->digests[Index].hashAlg); + DigestSize = Tpm2GetHashSizeFromAlgo (DigestList->digests[Index].hashAlg); + CopyMem (Buffer, &DigestList->digests[Index].digest, DigestSize); + Buffer = (UINT8 *)Buffer + DigestSize; + DigestListCount++; + } + + WriteUnaligned32 (DigestListCountPtr, DigestListCount); + + return Buffer; +} + +/** + Copy a buffer into a TPML_DIGEST_VALUES structure. + + @param[in] Buffer Buffer to hold TPML_DIGEST_VALUES compact binary. + @param[in] BufferSize Size of Buffer. + @param[out] DigestList TPML_DIGEST_VALUES. + + @return EFI_STATUS + @retval EFI_SUCCESS Buffer was successfully copied to Digest List. + @retval EFI_BAD_BUFFER_SIZE Bad buffer size passed to function. + @retval EFI_INVALID_PARAMETER Invalid parameter passed to function: NULL pointer or + BufferSize bigger than TPML_DIGEST_VALUES +**/ +EFI_STATUS +EFIAPI +Tpm2CopyBufferToDigestList ( + IN CONST VOID *Buffer, + IN UINTN BufferSize, + OUT TPML_DIGEST_VALUES *DigestList + ) +{ + EFI_STATUS Status; + UINTN Index; + UINT16 DigestSize; + CONST UINT8 *BufferPtr; + + if ((Buffer == NULL) || (DigestList == NULL) || (BufferSize > sizeof (TPML_DIGEST_VALUES))) { + return EFI_INVALID_PARAMETER; + } + + DigestList->count = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *)Buffer)); + if (DigestList->count > HASH_COUNT) { + return EFI_INVALID_PARAMETER; + } + + Status = EFI_INVALID_PARAMETER; + BufferPtr = (CONST UINT8 *)Buffer + sizeof (UINT32); + for (Index = 0; Index < DigestList->count; Index++) { + if (BufferPtr - (CONST UINT8 *)Buffer + sizeof (UINT16) > BufferSize) { + Status = EFI_BAD_BUFFER_SIZE; + break; + } else { + DigestList->digests[Index].hashAlg = SwapBytes16 (ReadUnaligned16 ((CONST UINT16 *)BufferPtr)); + } + + BufferPtr += sizeof (UINT16); + DigestSize = Tpm2GetHashSizeFromAlgo (DigestList->digests[Index].hashAlg); + if (BufferPtr - (CONST UINT8 *)Buffer + (UINTN)DigestSize > BufferSize) { + Status = EFI_BAD_BUFFER_SIZE; + break; + } else { + CopyMem (&DigestList->digests[Index].digest, BufferPtr, DigestSize); + } + + BufferPtr += DigestSize; + Status = EFI_SUCCESS; + } + + return Status; +} + +/** + Get TPML_DIGEST_VALUES data size. + + @param[in] DigestList TPML_DIGEST_VALUES data. + + @return TPML_DIGEST_VALUES data size, 0 otherwise. +**/ +UINT32 +EFIAPI +Tpm2GetDigestListSize ( + IN TPML_DIGEST_VALUES *DigestList + ) +{ + UINTN Index; + UINT16 DigestSize; + UINT32 TotalSize; + + if (DigestList == NULL) { + return 0; + } + + if (DigestList->count > HASH_COUNT) { + return 0; + } + + TotalSize = sizeof (DigestList->count); + for (Index = 0; Index < DigestList->count; Index++) { + DigestSize = Tpm2GetHashSizeFromAlgo (DigestList->digests[Index].hashAlg); + TotalSize += sizeof (DigestList->digests[Index].hashAlg) + DigestSize; + } + + return TotalSize; +} + +/** + Get TPML_DIGEST_VALUES data size from HashAlgorithmMask + + @param[in] HashAlgorithmMask Bitfield of allowed hash algorithms + + @return TPML_DIGEST_VALUES data size. +**/ +UINT32 +EFIAPI +Tpm2GetDigestListSizeFromHashAlgorithmMask ( + IN UINT32 HashAlgorithmMask + ) +{ + UINTN Index; + UINT32 TotalSize; + + TotalSize = sizeof (UINT32); + for (Index = 0; Index < ARRAY_SIZE (mHashInfo); Index++) { + if ((mHashInfo[Index].HashMask & HashAlgorithmMask) != 0) { + TotalSize += sizeof (TPMI_ALG_HASH) + mHashInfo[Index].HashSize; + } + } + + return TotalSize; +} + +/** + This function get digest from digest list. + + @param[in] HashAlg Digest algorithm + @param[in] DigestList Digest list + @param[out] Digest Digest + + @retval EFI_SUCCESS Digest is found and returned. + @retval EFI_NOT_FOUND Digest is not found. + @retval EFI_INVALID_PARAMETER DigestList or Digest invalid. +**/ +EFI_STATUS +EFIAPI +Tpm2GetDigestFromDigestList ( + IN TPMI_ALG_HASH HashAlg, + IN TPML_DIGEST_VALUES *DigestList, + OUT VOID *Digest + ) +{ + UINTN Index; + UINT16 DigestSize; + + if ((DigestList == NULL) || (Digest == NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (DigestList->count > HASH_COUNT) { + return EFI_INVALID_PARAMETER; + } + + DigestSize = Tpm2GetHashSizeFromAlgo (HashAlg); + for (Index = 0; Index < DigestList->count; Index++) { + if (DigestList->digests[Index].hashAlg == HashAlg) { + CopyMem ( + Digest, + &DigestList->digests[Index].digest, + DigestSize + ); + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** + Check if all hash algorithms supported in HashAlgorithmMask are + present in the DigestList. + + @param DigestList Digest list. + @param HashAlgorithmMask Bitfield of allowed hash algorithms. + + @retval TRUE All hash algorithms present. + @retval FALSE Some hash algorithms not present. +**/ +BOOLEAN +EFIAPI +Tpm2IsDigestListInSyncWithHashAlgorithmMask ( + IN TPML_DIGEST_VALUES *DigestList, + IN UINT32 HashAlgorithmMask + ) +{ + if (DigestList == NULL) { + return FALSE; + } + + if ((HashAlgorithmMask & HASH_ALG_SHA1) != 0) { + if (!CheckDigestListForHashAlg (DigestList, TPM_ALG_SHA1)) { + return FALSE; + } + } + + if ((HashAlgorithmMask & HASH_ALG_SHA256) != 0) { + if (!CheckDigestListForHashAlg (DigestList, TPM_ALG_SHA256)) { + return FALSE; + } + } + + if ((HashAlgorithmMask & HASH_ALG_SHA384) != 0) { + if (!CheckDigestListForHashAlg (DigestList, TPM_ALG_SHA384)) { + return FALSE; + } + } + + if ((HashAlgorithmMask & HASH_ALG_SHA512) != 0) { + if (!CheckDigestListForHashAlg (DigestList, TPM_ALG_SHA512)) { + return FALSE; + } + } + + if ((HashAlgorithmMask & HASH_ALG_SM3_256) != 0) { + if (!CheckDigestListForHashAlg (DigestList, TPM_ALG_SM3_256)) { + return FALSE; + } + } + + return TRUE; +} diff --git a/SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf b/SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf new file mode 100644 index 0000000000..5fbccdb8e0 --- /dev/null +++ b/SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf @@ -0,0 +1,30 @@ +## @file +# Provides reusable TPM 2.0 data helper routines that are independent +# of TPM command/device communication libraries. Includes serialization +# and parsing helpers for common TPM data structures. +# +# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = Tpm2HelpLib + FILE_GUID = DDFCEB08-9CE3-4CB8-ABBD-D32925E8CAAB + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = Tpm2HelpLib + +[Sources] + Tpm2Help.c + +[Packages] + MdePkg/MdePkg.dec + SecurityPkg/SecurityPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib diff --git a/SecurityPkg/SecurityPkg.dec b/SecurityPkg/SecurityPkg.dec index 98da4addfa..d21a9bcabb 100644 --- a/SecurityPkg/SecurityPkg.dec +++ b/SecurityPkg/SecurityPkg.dec @@ -46,6 +46,10 @@ # Tpm2CommandLib|Include/Library/Tpm2CommandLib.h + ## @libraryclass Provides helper functions for interfacing with TPM 2.0 data. + # + Tpm2HelpLib|Include/Library/Tpm2HelpLib.h + ## @libraryclass Provides interfaces on how to access TPM 2.0 hardware device. # Tpm2DeviceLib|Include/Library/Tpm2DeviceLib.h diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 746675a516..34b20b4cf6 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -55,6 +55,7 @@ TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf Tpm12CommandLib|SecurityPkg/Library/Tpm12CommandLib/Tpm12CommandLib.inf Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tpm2HelpLib|SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf TcgPpVendorLib|SecurityPkg/Library/TcgPpVendorLibNull/TcgPpVendorLibNull.inf Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf @@ -239,6 +240,7 @@ SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf From 3219c8bf5ff0cb7aa11a2af373140a8f05872dc0 Mon Sep 17 00:00:00 2001 From: rdiaz Date: Thu, 23 Oct 2025 01:11:45 +0000 Subject: [PATCH 013/406] ArmPlatformPkg: Add Tpm2HelpLib Add Tpm2HelpLib to ArmPlatformPkg.dsc Signed-off-by: Raymond Diaz --- ArmPlatformPkg/ArmPlatformPkg.dsc | 1 + 1 file changed, 1 insertion(+) diff --git a/ArmPlatformPkg/ArmPlatformPkg.dsc b/ArmPlatformPkg/ArmPlatformPkg.dsc index eaa6523919..688922dc93 100644 --- a/ArmPlatformPkg/ArmPlatformPkg.dsc +++ b/ArmPlatformPkg/ArmPlatformPkg.dsc @@ -88,6 +88,7 @@ MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tpm2HelpLib|SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf HashLib|SecurityPkg/Library/HashLibTpm2/HashLibTpm2PeilessSecLib.inf PeilessSecMeasureLib|SecurityPkg/Library/PeilessSecMeasureLib/PeilessSecMeasureLib.inf From 75991df764eed88f48dd21ad197265eeeffeb552 Mon Sep 17 00:00:00 2001 From: rdiaz Date: Thu, 23 Oct 2025 01:13:27 +0000 Subject: [PATCH 014/406] ArmVirtPkg: Add Tpm2HelpLib Add Tpm2HelpLib to ArmVirtPkg.dsc Signed-off-by: Raymond Diaz --- ArmVirtPkg/ArmVirtQemu.dsc | 1 + 1 file changed, 1 insertion(+) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index d705d35619..fc197cc208 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -78,6 +78,7 @@ !if $(TPM2_ENABLE) == TRUE Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tpm2HelpLib|SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/PeiDxeTpmPlatformHierarchyLib.inf From 6b3272fd82c3917c6c4fef15109048db3550ca31 Mon Sep 17 00:00:00 2001 From: rdiaz Date: Thu, 23 Oct 2025 01:14:44 +0000 Subject: [PATCH 015/406] IntelFsp2WrapperPkg: Add Tpm2HelpLib Add Tpm2HelpLib to IntelFsp2WrapperPkg.dsc Signed-off-by: Raymond Diaz --- IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dsc | 1 + 1 file changed, 1 insertion(+) diff --git a/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dsc b/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dsc index f51e1c89f6..381690bbf7 100644 --- a/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dsc +++ b/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dsc @@ -56,6 +56,7 @@ FspWrapperHobProcessLib|IntelFsp2WrapperPkg/Library/PeiFspWrapperHobProcessLibSample/PeiFspWrapperHobProcessLibSample.inf Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tpm2HelpLib|SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf [LibraryClasses.common.PEIM,LibraryClasses.common.PEI_CORE] PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf From 4ff351e9f281c935ce74dfa656b8a79bf717ec81 Mon Sep 17 00:00:00 2001 From: rdiaz Date: Thu, 23 Oct 2025 01:16:13 +0000 Subject: [PATCH 016/406] OvmfPkg: Add Tpm2HelpLib Add Tpm2HelpLib to OvmfPkg/RiscVVirtQemu.dsc, OvmfPkg/OvmfTpmLibs.dsc.inc and IntelTdxX64.dsc. Signed-off-by: Raymond Diaz --- OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc | 1 + OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 + OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 1 + 3 files changed, 3 insertions(+) diff --git a/OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc b/OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc index ff5346aae7..d664775718 100644 --- a/OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc +++ b/OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc @@ -3,6 +3,7 @@ ## [LibraryClasses] + Tpm2HelpLib|SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf !if $(TPM2_ENABLE) == TRUE !if $(TPM1_ENABLE) == TRUE Tpm12CommandLib|SecurityPkg/Library/Tpm12CommandLib/Tpm12CommandLib.inf diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc index 79ca7748af..3062fac11d 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -206,6 +206,7 @@ Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf + Tpm2HelpLib|SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf !include OvmfPkg/Include/Dsc/ShellLibs.dsc.inc diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc index 7d16fc6a30..828793f588 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc @@ -135,6 +135,7 @@ !if $(TPM2_ENABLE) == TRUE Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tpm2HelpLib|SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/PeiDxeTpmPlatformHierarchyLib.inf From 159a86fb09963219a7677007b6ed6f85f8b6fae8 Mon Sep 17 00:00:00 2001 From: rdiaz Date: Mon, 15 Jun 2026 19:41:28 +0000 Subject: [PATCH 017/406] OvmfPkg: Integrate Tpm2HelpLib Replace instances of the old Tpm2Help.c functions with the new Tpm2HelpLib versions. Update files to use Tpm2HelpLib in place of Tpm2Help.c from Tpm2CommandLib. Signed-off-by: Raymond Diaz --- OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c | 119 ++-------------------------- OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.inf | 1 + 2 files changed, 9 insertions(+), 111 deletions(-) diff --git a/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c b/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c index 8547c76d4c..44a751d865 100644 --- a/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c +++ b/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c @@ -45,6 +45,7 @@ #include #include #include +#include #define PERF_ID_CC_TCG2_DXE 0x3130 @@ -79,12 +80,6 @@ typedef struct _TDX_DXE_DATA { EFI_CC_FINAL_EVENTS_TABLE *FinalEventsTable[CC_EVENT_LOG_AREA_COUNT_MAX]; } TDX_DXE_DATA; -typedef struct { - TPMI_ALG_HASH HashAlgo; - UINT16 HashSize; - UINT32 HashMask; -} TDX_HASH_INFO; - // // CC_EVENT_INFO_STRUCT mCcEventInfo[] = { @@ -129,104 +124,6 @@ EFI_CC_EVENTLOG_ACPI_TABLE mTdxEventlogAcpiTemplate = { 0, // lasa }; -// -// Supported Hash list in Td guest. -// Currently SHA384 is supported. -// -TDX_HASH_INFO mHashInfo[] = { - { TPM_ALG_SHA384, SHA384_DIGEST_SIZE, HASH_ALG_SHA384 } -}; - -/** - Get hash size based on Algo - - @param[in] HashAlgo Hash Algorithm Id. - - @return Size of the hash. -**/ -UINT16 -GetHashSizeFromAlgo ( - IN TPMI_ALG_HASH HashAlgo - ) -{ - UINTN Index; - - for (Index = 0; Index < sizeof (mHashInfo)/sizeof (mHashInfo[0]); Index++) { - if (mHashInfo[Index].HashAlgo == HashAlgo) { - return mHashInfo[Index].HashSize; - } - } - - return 0; -} - -/** - Get hash mask based on Algo - - @param[in] HashAlgo Hash Algorithm Id. - - @return Hash mask. -**/ -UINT32 -GetHashMaskFromAlgo ( - IN TPMI_ALG_HASH HashAlgo - ) -{ - UINTN Index; - - for (Index = 0; Index < ARRAY_SIZE (mHashInfo); Index++) { - if (mHashInfo[Index].HashAlgo == HashAlgo) { - return mHashInfo[Index].HashMask; - } - } - - ASSERT (FALSE); - return 0; -} - -/** - Copy TPML_DIGEST_VALUES into a buffer - - @param[in,out] Buffer Buffer to hold copied TPML_DIGEST_VALUES compact binary. - @param[in] DigestList TPML_DIGEST_VALUES to be copied. - @param[in] HashAlgorithmMask HASH bits corresponding to the desired digests to copy. - - @return The end of buffer to hold TPML_DIGEST_VALUES. -**/ -VOID * -CopyDigestListToBuffer ( - IN OUT VOID *Buffer, - IN TPML_DIGEST_VALUES *DigestList, - IN UINT32 HashAlgorithmMask - ) -{ - UINTN Index; - UINT16 DigestSize; - UINT32 DigestListCount; - UINT32 *DigestListCountPtr; - - DigestListCountPtr = (UINT32 *)Buffer; - DigestListCount = 0; - Buffer = (UINT8 *)Buffer + sizeof (DigestList->count); - for (Index = 0; Index < DigestList->count; Index++) { - if ((DigestList->digests[Index].hashAlg & HashAlgorithmMask) == 0) { - DEBUG ((DEBUG_ERROR, "WARNING: TD Event log has HashAlg unsupported (0x%x)\n", DigestList->digests[Index].hashAlg)); - continue; - } - - CopyMem (Buffer, &DigestList->digests[Index].hashAlg, sizeof (DigestList->digests[Index].hashAlg)); - Buffer = (UINT8 *)Buffer + sizeof (DigestList->digests[Index].hashAlg); - DigestSize = GetHashSizeFromAlgo (DigestList->digests[Index].hashAlg); - CopyMem (Buffer, &DigestList->digests[Index].digest, DigestSize); - Buffer = (UINT8 *)Buffer + DigestSize; - DigestListCount++; - } - - WriteUnaligned32 (DigestListCountPtr, DigestListCount); - - return Buffer; -} - EFI_HANDLE mImageHandle; /** @@ -346,7 +243,7 @@ InitNoActionEvent ( if ((mTdxDxeData.BsCap.HashAlgorithmBitmap & EFI_CC_BOOT_HASH_ALG_SHA384) != 0) { HashAlgId = TPM_ALG_SHA384; CopyMem (DigestBuffer, &HashAlgId, sizeof (TPMI_ALG_HASH)); - DigestBuffer += sizeof (TPMI_ALG_HASH) + GetHashSizeFromAlgo (HashAlgId); + DigestBuffer += sizeof (TPMI_ALG_HASH) + Tpm2GetHashSizeFromAlgo (HashAlgId); DigestListCount++; } @@ -605,7 +502,7 @@ DumpCcEvent ( for (DigestIndex = 0; DigestIndex < DigestCount; DigestIndex++) { DEBUG ((DEBUG_INFO, " HashAlgo : 0x%04x\n", HashAlgo)); DEBUG ((DEBUG_INFO, " Digest(%d): \n", DigestIndex)); - DigestSize = GetHashSizeFromAlgo (HashAlgo); + DigestSize = Tpm2GetHashSizeFromAlgo (HashAlgo); InternalDumpHex (DigestBuffer, DigestSize); // // Prepare next @@ -647,7 +544,7 @@ GetCcEventSize ( HashAlgo = CcEvent->Digests.digests[0].hashAlg; DigestBuffer = (UINT8 *)&CcEvent->Digests.digests[0].digest; for (DigestIndex = 0; DigestIndex < DigestCount; DigestIndex++) { - DigestSize = GetHashSizeFromAlgo (HashAlgo); + DigestSize = Tpm2GetHashSizeFromAlgo (HashAlgo); // // Prepare next // @@ -1078,7 +975,7 @@ GetDigestListBinSize ( TotalSize += sizeof (HashAlg); DigestListBin = (UINT8 *)DigestListBin + sizeof (HashAlg); - DigestSize = GetHashSizeFromAlgo (HashAlg); + DigestSize = Tpm2GetHashSizeFromAlgo (HashAlg); TotalSize += DigestSize; DigestListBin = (UINT8 *)DigestListBin + DigestSize; } @@ -1121,7 +1018,7 @@ CopyDigestListBinToBuffer ( for (Index = 0; Index < Count; Index++) { HashAlg = ReadUnaligned16 (DigestListBin); DigestListBin = (UINT8 *)DigestListBin + sizeof (HashAlg); - DigestSize = GetHashSizeFromAlgo (HashAlg); + DigestSize = Tpm2GetHashSizeFromAlgo (HashAlg); if ((HashAlg & HashAlgorithmMask) != 0) { CopyMem (Buffer, &HashAlg, sizeof (HashAlg)); @@ -1129,7 +1026,7 @@ CopyDigestListBinToBuffer ( CopyMem (Buffer, DigestListBin, DigestSize); Buffer = (UINT8 *)Buffer + DigestSize; DigestListCount++; - (*HashAlgorithmMaskCopied) |= GetHashMaskFromAlgo (HashAlg); + (*HashAlgorithmMaskCopied) |= Tpm2GetHashMaskFromAlgo (HashAlg); } else { DEBUG ((DEBUG_ERROR, "WARNING: CopyDigestListBinToBuffer Event log has HashAlg unsupported by PCR bank (0x%x)\n", HashAlg)); } @@ -1178,7 +1075,7 @@ TdxDxeLogHashEvent ( CcEvent.MrIndex = NewEventHdr->MrIndex; CcEvent.EventType = NewEventHdr->EventType; DigestBuffer = (UINT8 *)&CcEvent.Digests; - EventSizePtr = CopyDigestListToBuffer (DigestBuffer, DigestList, HASH_ALG_SHA384); + EventSizePtr = Tpm2CopyDigestListToBuffer (DigestBuffer, DigestList, HASH_ALG_SHA384); CopyMem (EventSizePtr, &NewEventHdr->EventSize, sizeof (NewEventHdr->EventSize)); // diff --git a/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.inf b/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.inf index 039603fa16..e0248d1e91 100644 --- a/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.inf +++ b/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.inf @@ -50,6 +50,7 @@ TpmMeasurementLib TdxLib TdxMeasurementLib + Tpm2HelpLib [Guids] ## SOMETIMES_CONSUMES ## Variable:L"SecureBoot" From 2d49d517224f060dfe1d35436437a5eafe586f3e Mon Sep 17 00:00:00 2001 From: rdiaz Date: Mon, 15 Jun 2026 19:41:44 +0000 Subject: [PATCH 018/406] SecurityPkg: Integrate Tpm2HelpLib Replace instances of the old Tpm2Help.c functions with the new Tpm2HelpLib versions. Update files to use Tpm2HelpLib in place of Tpm2Help.c from Tpm2CommandLib. Signed-off-by: Raymond Diaz --- .../HashLibBaseCryptoRouterDxe.c | 3 ++- .../HashLibBaseCryptoRouterDxe.inf | 1 + .../PeilessSecMeasureLib.c | 7 ++--- .../PeilessSecMeasureLib.inf | 1 + .../Library/Tpm2CommandLib/Tpm2CommandLib.inf | 1 + .../Tpm2CommandLib/Tpm2DictionaryAttack.c | 5 ++-- .../Tpm2EnhancedAuthorization.c | 3 ++- .../Library/Tpm2CommandLib/Tpm2Hierarchy.c | 15 ++++++----- .../Library/Tpm2CommandLib/Tpm2Integrity.c | 11 ++++---- .../Tpm2CommandLib/Tpm2Miscellaneous.c | 3 ++- .../Library/Tpm2CommandLib/Tpm2NVStorage.c | 17 ++++++------ .../Library/Tpm2CommandLib/Tpm2Sequences.c | 11 ++++---- SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c | 27 ++++++++++--------- SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf | 1 + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c | 11 ++++---- SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf | 1 + 16 files changed, 67 insertions(+), 51 deletions(-) diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c index 2169c5e185..8c2c4f0db2 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c @@ -12,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include @@ -234,7 +235,7 @@ HashCompleteAndExtend ( ASSERT_EFI_ERROR (Status); ActivePcrBanks = ActivePcrBanks & mSupportedHashMaskCurrent; ZeroMem (&TcgPcrEvent2Digest, sizeof (TcgPcrEvent2Digest)); - BufferPtr = CopyDigestListToBuffer (&TcgPcrEvent2Digest, DigestList, ActivePcrBanks); + BufferPtr = Tpm2CopyDigestListToBuffer (&TcgPcrEvent2Digest, DigestList, ActivePcrBanks); DigestListBinSize = (UINT32)((UINT8 *)BufferPtr - (UINT8 *)&TcgPcrEvent2Digest); // diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf index aad1b92ce1..4be5eca446 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf @@ -40,6 +40,7 @@ BaseMemoryLib DebugLib Tpm2CommandLib + Tpm2HelpLib MemoryAllocationLib PcdLib diff --git a/SecurityPkg/Library/PeilessSecMeasureLib/PeilessSecMeasureLib.c b/SecurityPkg/Library/PeilessSecMeasureLib/PeilessSecMeasureLib.c index 5e53d0f743..f7a9d827b0 100644 --- a/SecurityPkg/Library/PeilessSecMeasureLib/PeilessSecMeasureLib.c +++ b/SecurityPkg/Library/PeilessSecMeasureLib/PeilessSecMeasureLib.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -68,12 +69,12 @@ LogHashEvent ( UINT8 *DigestBuffer; // - // Use GetDigestListSize (DigestList) in the GUID HOB DataLength calculation + // Use Tpm2GetDigestListSize (DigestList) in the GUID HOB DataLength calculation // to reserve enough buffer to hold TPML_DIGEST_VALUES compact binary. // HobData = BuildGuidHob ( &gTcgEvent2EntryHobGuid, - sizeof (TcgPcrEvent2->PCRIndex) + sizeof (TcgPcrEvent2->EventType) + GetDigestListSize (DigestList) + sizeof (TcgPcrEvent2->EventSize) + NewEventHdr->EventSize + sizeof (TcgPcrEvent2->PCRIndex) + sizeof (TcgPcrEvent2->EventType) + Tpm2GetDigestListSize (DigestList) + sizeof (TcgPcrEvent2->EventSize) + NewEventHdr->EventSize ); if (HobData == NULL) { return EFI_OUT_OF_RESOURCES; @@ -90,7 +91,7 @@ LogHashEvent ( * - TPM_ALG_SHA384 * - TPM_ALG_SHA512 */ - DigestBuffer = CopyDigestListToBuffer ( + DigestBuffer = Tpm2CopyDigestListToBuffer ( DigestBuffer, DigestList, TPM_ALG_SHA256 | TPM_ALG_SHA384 | TPM_ALG_SHA512 diff --git a/SecurityPkg/Library/PeilessSecMeasureLib/PeilessSecMeasureLib.inf b/SecurityPkg/Library/PeilessSecMeasureLib/PeilessSecMeasureLib.inf index ffab315042..eb7b08ef63 100644 --- a/SecurityPkg/Library/PeilessSecMeasureLib/PeilessSecMeasureLib.inf +++ b/SecurityPkg/Library/PeilessSecMeasureLib/PeilessSecMeasureLib.inf @@ -38,6 +38,7 @@ HashLib PrePiLib Tpm2CommandLib + Tpm2HelpLib [Guids] gTcgEvent2EntryHobGuid diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf b/SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf index f584f34aed..ed2643b7e1 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf @@ -48,3 +48,4 @@ BaseMemoryLib DebugLib Tpm2DeviceLib + Tpm2HelpLib diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2DictionaryAttack.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2DictionaryAttack.c index ac8183d9ea..85d0884b2c 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2DictionaryAttack.c +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2DictionaryAttack.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +#include #include #include #include @@ -85,7 +86,7 @@ Tpm2DictionaryAttackLockReset ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); @@ -167,7 +168,7 @@ Tpm2DictionaryAttackParameters ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2EnhancedAuthorization.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2EnhancedAuthorization.c index c63db70336..92f18fab69 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2EnhancedAuthorization.c +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2EnhancedAuthorization.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +#include #include #include #include @@ -121,7 +122,7 @@ Tpm2PolicySecret ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Hierarchy.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Hierarchy.c index 7144955be1..7a006a020c 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Hierarchy.c +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Hierarchy.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +#include #include #include #include @@ -157,7 +158,7 @@ Tpm2SetPrimaryPolicy ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); @@ -239,7 +240,7 @@ Tpm2Clear ( Buffer = (UINT8 *)&Cmd.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize); @@ -329,7 +330,7 @@ Tpm2ClearControl ( Buffer = (UINT8 *)&Cmd.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize); @@ -428,7 +429,7 @@ Tpm2HierarchyChangeAuth ( Buffer = (UINT8 *)&Cmd.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize); @@ -534,7 +535,7 @@ Tpm2ChangeEPS ( Buffer = (UINT8 *)&Cmd.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize); @@ -632,7 +633,7 @@ Tpm2ChangePPS ( Buffer = (UINT8 *)&Cmd.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize); @@ -734,7 +735,7 @@ Tpm2HierarchyControl ( Buffer = (UINT8 *)&Cmd.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize); diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Integrity.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Integrity.c index 581b05d134..bcb9837dcd 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Integrity.c +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Integrity.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +#include #include #include #include @@ -115,7 +116,7 @@ Tpm2PcrExtend ( Buffer = (UINT8 *)&Cmd.AuthSessionPcr; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (NULL, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (NULL, Buffer); Buffer += SessionInfoSize; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize); @@ -127,7 +128,7 @@ Tpm2PcrExtend ( for (Index = 0; Index < Digests->count; Index++) { WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Digests->digests[Index].hashAlg)); Buffer += sizeof (UINT16); - DigestSize = GetHashSizeFromAlgo (Digests->digests[Index].hashAlg); + DigestSize = Tpm2GetHashSizeFromAlgo (Digests->digests[Index].hashAlg); if (DigestSize == 0) { DEBUG ((DEBUG_ERROR, "Unknown hash algorithm %d\r\n", Digests->digests[Index].hashAlg)); return EFI_DEVICE_ERROR; @@ -247,7 +248,7 @@ Tpm2PcrEvent ( Buffer = (UINT8 *)&Cmd.AuthSessionPcr; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (NULL, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (NULL, Buffer); Buffer += SessionInfoSize; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize); @@ -304,7 +305,7 @@ Tpm2PcrEvent ( for (Index = 0; Index < Digests->count; Index++) { Digests->digests[Index].hashAlg = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer)); Buffer += sizeof (UINT16); - DigestSize = GetHashSizeFromAlgo (Digests->digests[Index].hashAlg); + DigestSize = Tpm2GetHashSizeFromAlgo (Digests->digests[Index].hashAlg); if (DigestSize == 0) { DEBUG ((DEBUG_ERROR, "Unknown hash algorithm %d\r\n", Digests->digests[Index].hashAlg)); return EFI_DEVICE_ERROR; @@ -507,7 +508,7 @@ Tpm2PcrAllocate ( Buffer = (UINT8 *)&Cmd.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; Cmd.AuthSessionSize = SwapBytes32 (SessionInfoSize); diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Miscellaneous.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Miscellaneous.c index 6f6ac1e2d0..8d23aedeb6 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Miscellaneous.c +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Miscellaneous.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +#include #include #include #include @@ -73,7 +74,7 @@ Tpm2SetAlgorithmSet ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c index 7ca892735b..27157d7476 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +#include #include #include #include @@ -328,7 +329,7 @@ Tpm2NvDefineSpace ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); @@ -465,7 +466,7 @@ Tpm2NvUndefineSpace ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); @@ -576,7 +577,7 @@ Tpm2NvRead ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); @@ -723,7 +724,7 @@ Tpm2NvWrite ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); @@ -852,7 +853,7 @@ Tpm2NvReadLock ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); @@ -940,7 +941,7 @@ Tpm2NvWriteLock ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); @@ -1025,7 +1026,7 @@ Tpm2NvGlobalWriteLock ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); @@ -1115,7 +1116,7 @@ Tpm2NvExtend ( Buffer = (UINT8 *)&SendBuffer.AuthSession; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer); + SessionInfoSize = Tpm2CopyAuthSessionCommand (AuthSession, Buffer); Buffer += SessionInfoSize; SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize); diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Sequences.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Sequences.c index 00ae39feb7..458d987e6e 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Sequences.c +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Sequences.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +#include #include #include #include @@ -207,7 +208,7 @@ Tpm2SequenceUpdate ( BufferPtr = (UINT8 *)&Cmd.AuthSessionSeq; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (NULL, BufferPtr); + SessionInfoSize = Tpm2CopyAuthSessionCommand (NULL, BufferPtr); BufferPtr += SessionInfoSize; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize); @@ -312,11 +313,11 @@ Tpm2EventSequenceComplete ( BufferPtr = (UINT8 *)&Cmd.AuthSessionPcr; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (NULL, BufferPtr); + SessionInfoSize = Tpm2CopyAuthSessionCommand (NULL, BufferPtr); BufferPtr += SessionInfoSize; // sessionInfoSize - SessionInfoSize2 = CopyAuthSessionCommand (NULL, BufferPtr); + SessionInfoSize2 = Tpm2CopyAuthSessionCommand (NULL, BufferPtr); BufferPtr += SessionInfoSize2; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize + SessionInfoSize2); @@ -380,7 +381,7 @@ Tpm2EventSequenceComplete ( Results->digests[Index].hashAlg = SwapBytes16 (ReadUnaligned16 ((UINT16 *)BufferPtr)); BufferPtr += sizeof (UINT16); - DigestSize = GetHashSizeFromAlgo (Results->digests[Index].hashAlg); + DigestSize = Tpm2GetHashSizeFromAlgo (Results->digests[Index].hashAlg); if (DigestSize == 0) { DEBUG ((DEBUG_ERROR, "EventSequenceComplete: Unknown hash algorithm %d\r\n", Results->digests[Index].hashAlg)); return EFI_DEVICE_ERROR; @@ -439,7 +440,7 @@ Tpm2SequenceComplete ( BufferPtr = (UINT8 *)&Cmd.AuthSessionSeq; // sessionInfoSize - SessionInfoSize = CopyAuthSessionCommand (NULL, BufferPtr); + SessionInfoSize = Tpm2CopyAuthSessionCommand (NULL, BufferPtr); BufferPtr += SessionInfoSize; Cmd.AuthorizationSize = SwapBytes32 (SessionInfoSize); diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c index 0c0fa26932..096e3ef6eb 100644 --- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c +++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c @@ -38,6 +38,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include @@ -205,35 +206,35 @@ InitNoActionEvent ( if ((mTcgDxeData.BsCap.ActivePcrBanks & EFI_TCG2_BOOT_HASH_ALG_SHA1) != 0) { HashAlgId = TPM_ALG_SHA1; CopyMem (DigestBuffer, &HashAlgId, sizeof (TPMI_ALG_HASH)); - DigestBuffer += sizeof (TPMI_ALG_HASH) + GetHashSizeFromAlgo (HashAlgId); + DigestBuffer += sizeof (TPMI_ALG_HASH) + Tpm2GetHashSizeFromAlgo (HashAlgId); DigestListCount++; } if ((mTcgDxeData.BsCap.ActivePcrBanks & EFI_TCG2_BOOT_HASH_ALG_SHA256) != 0) { HashAlgId = TPM_ALG_SHA256; CopyMem (DigestBuffer, &HashAlgId, sizeof (TPMI_ALG_HASH)); - DigestBuffer += sizeof (TPMI_ALG_HASH) + GetHashSizeFromAlgo (HashAlgId); + DigestBuffer += sizeof (TPMI_ALG_HASH) + Tpm2GetHashSizeFromAlgo (HashAlgId); DigestListCount++; } if ((mTcgDxeData.BsCap.ActivePcrBanks & EFI_TCG2_BOOT_HASH_ALG_SHA384) != 0) { HashAlgId = TPM_ALG_SHA384; CopyMem (DigestBuffer, &HashAlgId, sizeof (TPMI_ALG_HASH)); - DigestBuffer += sizeof (TPMI_ALG_HASH) + GetHashSizeFromAlgo (HashAlgId); + DigestBuffer += sizeof (TPMI_ALG_HASH) + Tpm2GetHashSizeFromAlgo (HashAlgId); DigestListCount++; } if ((mTcgDxeData.BsCap.ActivePcrBanks & EFI_TCG2_BOOT_HASH_ALG_SHA512) != 0) { HashAlgId = TPM_ALG_SHA512; CopyMem (DigestBuffer, &HashAlgId, sizeof (TPMI_ALG_HASH)); - DigestBuffer += sizeof (TPMI_ALG_HASH) + GetHashSizeFromAlgo (HashAlgId); + DigestBuffer += sizeof (TPMI_ALG_HASH) + Tpm2GetHashSizeFromAlgo (HashAlgId); DigestListCount++; } if ((mTcgDxeData.BsCap.ActivePcrBanks & EFI_TCG2_BOOT_HASH_ALG_SM3_256) != 0) { HashAlgId = TPM_ALG_SM3_256; CopyMem (DigestBuffer, &HashAlgId, sizeof (TPMI_ALG_HASH)); - DigestBuffer += sizeof (TPMI_ALG_HASH) + GetHashSizeFromAlgo (HashAlgId); + DigestBuffer += sizeof (TPMI_ALG_HASH) + Tpm2GetHashSizeFromAlgo (HashAlgId); DigestListCount++; } @@ -552,7 +553,7 @@ DumpEvent2 ( for (DigestIndex = 0; DigestIndex < DigestCount; DigestIndex++) { DEBUG ((DEBUG_SECURITY, " HashAlgo : 0x%04x\n", HashAlgo)); DEBUG ((DEBUG_SECURITY, " Digest(%d): ", DigestIndex)); - DigestSize = GetHashSizeFromAlgo (HashAlgo); + DigestSize = Tpm2GetHashSizeFromAlgo (HashAlgo); for (Index = 0; Index < DigestSize; Index++) { DEBUG ((DEBUG_SECURITY, "%02x ", DigestBuffer[Index])); } @@ -598,7 +599,7 @@ GetPcrEvent2Size ( HashAlgo = TcgPcrEvent2->Digest.digests[0].hashAlg; DigestBuffer = (UINT8 *)&TcgPcrEvent2->Digest.digests[0].digest; for (DigestIndex = 0; DigestIndex < DigestCount; DigestIndex++) { - DigestSize = GetHashSizeFromAlgo (HashAlgo); + DigestSize = Tpm2GetHashSizeFromAlgo (HashAlgo); // // Prepare next // @@ -1056,7 +1057,7 @@ GetDigestListBinSize ( TotalSize += sizeof (HashAlg); DigestListBin = (UINT8 *)DigestListBin + sizeof (HashAlg); - DigestSize = GetHashSizeFromAlgo (HashAlg); + DigestSize = Tpm2GetHashSizeFromAlgo (HashAlg); TotalSize += DigestSize; DigestListBin = (UINT8 *)DigestListBin + DigestSize; } @@ -1099,15 +1100,15 @@ CopyDigestListBinToBuffer ( for (Index = 0; Index < Count; Index++) { HashAlg = ReadUnaligned16 (DigestListBin); DigestListBin = (UINT8 *)DigestListBin + sizeof (HashAlg); - DigestSize = GetHashSizeFromAlgo (HashAlg); + DigestSize = Tpm2GetHashSizeFromAlgo (HashAlg); - if (IsHashAlgSupportedInHashAlgorithmMask (HashAlg, HashAlgorithmMask)) { + if (Tpm2IsHashAlgSupportedInHashAlgorithmMask (HashAlg, HashAlgorithmMask)) { CopyMem (Buffer, &HashAlg, sizeof (HashAlg)); Buffer = (UINT8 *)Buffer + sizeof (HashAlg); CopyMem (Buffer, DigestListBin, DigestSize); Buffer = (UINT8 *)Buffer + DigestSize; DigestListCount++; - (*HashAlgorithmMaskCopied) |= GetHashMaskFromAlgo (HashAlg); + (*HashAlgorithmMaskCopied) |= Tpm2GetHashMaskFromAlgo (HashAlg); } else { DEBUG ((DEBUG_ERROR, "WARNING: CopyDigestListBinToBuffer Event log has HashAlg unsupported by PCR bank (0x%x)\n", HashAlg)); } @@ -1150,7 +1151,7 @@ TcgDxeLogHashEvent ( if ((mTcgDxeData.BsCap.SupportedEventLogs & mTcg2EventInfo[Index].LogFormat) != 0) { switch (mTcg2EventInfo[Index].LogFormat) { case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2: - Status = GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest); + Status = Tpm2GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest); if (!EFI_ERROR (Status)) { // // Enter critical region @@ -1179,7 +1180,7 @@ TcgDxeLogHashEvent ( TcgPcrEvent2.PCRIndex = NewEventHdr->PCRIndex; TcgPcrEvent2.EventType = NewEventHdr->EventType; DigestBuffer = (UINT8 *)&TcgPcrEvent2.Digest; - EventSizePtr = CopyDigestListToBuffer (DigestBuffer, DigestList, mTcgDxeData.BsCap.ActivePcrBanks); + EventSizePtr = Tpm2CopyDigestListToBuffer (DigestBuffer, DigestList, mTcgDxeData.BsCap.ActivePcrBanks); CopyMem (EventSizePtr, &NewEventHdr->EventSize, sizeof (NewEventHdr->EventSize)); // diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf index a645474bf3..d291c03254 100644 --- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf @@ -64,6 +64,7 @@ ReportStatusCodeLib Tcg2PhysicalPresenceLib PeCoffLib + Tpm2HelpLib [Guids] ## SOMETIMES_CONSUMES ## Variable:L"SecureBoot" diff --git a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c index 4dc72d1626..ab7ad9a306 100644 --- a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c +++ b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c @@ -29,6 +29,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include @@ -389,7 +390,7 @@ LogHashEvent ( DEBUG ((DEBUG_INFO, " LogFormat - 0x%08x\n", mTcg2EventInfo[Index].LogFormat)); switch (mTcg2EventInfo[Index].LogFormat) { case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2: - Status = GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest); + Status = Tpm2GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest); if (!EFI_ERROR (Status)) { HobData = BuildGuidHob ( &gTcgEventEntryHobGuid, @@ -408,12 +409,12 @@ LogHashEvent ( break; case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2: // - // Use GetDigestListSize (DigestList) in the GUID HOB DataLength calculation + // Use Tpm2GetDigestListSize (DigestList) in the GUID HOB DataLength calculation // to reserve enough buffer to hold TPML_DIGEST_VALUES compact binary. // HobData = BuildGuidHob ( &gTcgEvent2EntryHobGuid, - sizeof (TcgPcrEvent2->PCRIndex) + sizeof (TcgPcrEvent2->EventType) + GetDigestListSize (DigestList) + sizeof (TcgPcrEvent2->EventSize) + NewEventHdr->EventSize + sizeof (TcgPcrEvent2->PCRIndex) + sizeof (TcgPcrEvent2->EventType) + Tpm2GetDigestListSize (DigestList) + sizeof (TcgPcrEvent2->EventSize) + NewEventHdr->EventSize ); if (HobData == NULL) { RetStatus = EFI_OUT_OF_RESOURCES; @@ -424,7 +425,7 @@ LogHashEvent ( TcgPcrEvent2->PCRIndex = NewEventHdr->PCRIndex; TcgPcrEvent2->EventType = NewEventHdr->EventType; DigestBuffer = (UINT8 *)&TcgPcrEvent2->Digest; - DigestBuffer = CopyDigestListToBuffer (DigestBuffer, DigestList, PcdGet32 (PcdTpm2HashMask)); + DigestBuffer = Tpm2CopyDigestListToBuffer (DigestBuffer, DigestList, PcdGet32 (PcdTpm2HashMask)); CopyMem (DigestBuffer, &NewEventHdr->EventSize, sizeof (TcgPcrEvent2->EventSize)); DigestBuffer = DigestBuffer + sizeof (TcgPcrEvent2->EventSize); CopyMem (DigestBuffer, NewEventData, NewEventHdr->EventSize); @@ -687,7 +688,7 @@ MeasureFvImage ( PreHashInfo = (HASH_INFO *)(PrehashedFvPpi + 1); for (Index = 0, DigestCount = 0; Index < PrehashedFvPpi->Count; Index++) { DEBUG ((DEBUG_INFO, "Hash Algo ID in PrehashedFvPpi=0x%x\n", PreHashInfo->HashAlgoId)); - HashAlgoMask = GetHashMaskFromAlgo (PreHashInfo->HashAlgoId); + HashAlgoMask = Tpm2GetHashMaskFromAlgo (PreHashInfo->HashAlgoId); if ((Tpm2HashMask & HashAlgoMask) != 0 ) { // // Hash is required, copy it to DigestList diff --git a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf index 17ad116126..88f7b21698 100644 --- a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf +++ b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf @@ -55,6 +55,7 @@ ReportStatusCodeLib ResetSystemLib PrintLib + Tpm2HelpLib [Guids] gTcgEventEntryHobGuid ## PRODUCES ## HOB From c0208dc79e71a4b01fb59a1580b1c2af23382804 Mon Sep 17 00:00:00 2001 From: rdiaz Date: Tue, 21 Apr 2026 19:16:27 +0000 Subject: [PATCH 019/406] SecurityPkg: Update Tpm2Help.c Functions Update the Tpm2Help.c functions to become wrappers for the functions in Tpm2HelpLib. This prevents platforms from breaking due to the updated prefix naming but will still allow us to keep one instance of the function implementations. Signed-off-by: Raymond Diaz --- SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c | 263 +----------------- 1 file changed, 11 insertions(+), 252 deletions(-) diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c index ac802733d3..69d8b47736 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c @@ -9,24 +9,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include -typedef struct { - TPMI_ALG_HASH HashAlgo; - UINT16 HashSize; - UINT32 HashMask; -} INTERNAL_HASH_INFO; - -STATIC INTERNAL_HASH_INFO mHashInfo[] = { - { TPM_ALG_SHA1, SHA1_DIGEST_SIZE, HASH_ALG_SHA1 }, - { TPM_ALG_SHA256, SHA256_DIGEST_SIZE, HASH_ALG_SHA256 }, - { TPM_ALG_SM3_256, SM3_256_DIGEST_SIZE, HASH_ALG_SM3_256 }, - { TPM_ALG_SHA384, SHA384_DIGEST_SIZE, HASH_ALG_SHA384 }, - { TPM_ALG_SHA512, SHA512_DIGEST_SIZE, HASH_ALG_SHA512 }, -}; - /** Return size of digest. @@ -40,15 +27,7 @@ GetHashSizeFromAlgo ( IN TPMI_ALG_HASH HashAlgo ) { - UINTN Index; - - for (Index = 0; Index < sizeof (mHashInfo)/sizeof (mHashInfo[0]); Index++) { - if (mHashInfo[Index].HashAlgo == HashAlgo) { - return mHashInfo[Index].HashSize; - } - } - - return 0; + return Tpm2GetHashSizeFromAlgo (HashAlgo); } /** @@ -64,15 +43,7 @@ GetHashMaskFromAlgo ( IN TPMI_ALG_HASH HashAlgo ) { - UINTN Index; - - for (Index = 0; Index < sizeof (mHashInfo)/sizeof (mHashInfo[0]); Index++) { - if (mHashInfo[Index].HashAlgo == HashAlgo) { - return mHashInfo[Index].HashMask; - } - } - - return 0; + return Tpm2GetHashMaskFromAlgo (HashAlgo); } /** @@ -90,54 +61,7 @@ CopyAuthSessionCommand ( OUT UINT8 *AuthSessionOut ) { - UINT8 *Buffer; - - Buffer = (UINT8 *)AuthSessionOut; - - // - // Add in Auth session - // - if (AuthSessionIn != NULL) { - // sessionHandle - WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (AuthSessionIn->sessionHandle)); - Buffer += sizeof (UINT32); - - // nonce - WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (AuthSessionIn->nonce.size)); - Buffer += sizeof (UINT16); - - CopyMem (Buffer, AuthSessionIn->nonce.buffer, AuthSessionIn->nonce.size); - Buffer += AuthSessionIn->nonce.size; - - // sessionAttributes - *(UINT8 *)Buffer = *(UINT8 *)&AuthSessionIn->sessionAttributes; - Buffer++; - - // hmac - WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (AuthSessionIn->hmac.size)); - Buffer += sizeof (UINT16); - - CopyMem (Buffer, AuthSessionIn->hmac.buffer, AuthSessionIn->hmac.size); - Buffer += AuthSessionIn->hmac.size; - } else { - // sessionHandle - WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (TPM_RS_PW)); - Buffer += sizeof (UINT32); - - // nonce = nullNonce - WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (0)); - Buffer += sizeof (UINT16); - - // sessionAttributes = 0 - *(UINT8 *)Buffer = 0x00; - Buffer++; - - // hmac = nullAuth - WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (0)); - Buffer += sizeof (UINT16); - } - - return (UINT32)((UINTN)Buffer - (UINTN)AuthSessionOut); + return Tpm2CopyAuthSessionCommand (AuthSessionIn, AuthSessionOut); } /** @@ -156,42 +80,7 @@ CopyAuthSessionResponse ( OUT TPMS_AUTH_RESPONSE *AuthSessionOut OPTIONAL ) { - UINT8 *Buffer; - TPMS_AUTH_RESPONSE LocalAuthSessionOut; - - if (AuthSessionOut == NULL) { - AuthSessionOut = &LocalAuthSessionOut; - } - - Buffer = (UINT8 *)AuthSessionIn; - - // nonce - AuthSessionOut->nonce.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer)); - Buffer += sizeof (UINT16); - if (AuthSessionOut->nonce.size > sizeof (TPMU_HA)) { - DEBUG ((DEBUG_ERROR, "CopyAuthSessionResponse - nonce.size error %x\n", AuthSessionOut->nonce.size)); - return 0; - } - - CopyMem (AuthSessionOut->nonce.buffer, Buffer, AuthSessionOut->nonce.size); - Buffer += AuthSessionOut->nonce.size; - - // sessionAttributes - *(UINT8 *) &AuthSessionOut->sessionAttributes = *(UINT8 *)Buffer; - Buffer++; - - // hmac - AuthSessionOut->hmac.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer)); - Buffer += sizeof (UINT16); - if (AuthSessionOut->hmac.size > sizeof (TPMU_HA)) { - DEBUG ((DEBUG_ERROR, "CopyAuthSessionResponse - hmac.size error %x\n", AuthSessionOut->hmac.size)); - return 0; - } - - CopyMem (AuthSessionOut->hmac.buffer, Buffer, AuthSessionOut->hmac.size); - Buffer += AuthSessionOut->hmac.size; - - return (UINT32)((UINTN)Buffer - (UINTN)AuthSessionIn); + return Tpm2CopyAuthSessionResponse (AuthSessionIn, AuthSessionOut); } /** @@ -210,40 +99,7 @@ IsHashAlgSupportedInHashAlgorithmMask ( IN UINT32 HashAlgorithmMask ) { - switch (HashAlg) { - case TPM_ALG_SHA1: - if ((HashAlgorithmMask & HASH_ALG_SHA1) != 0) { - return TRUE; - } - - break; - case TPM_ALG_SHA256: - if ((HashAlgorithmMask & HASH_ALG_SHA256) != 0) { - return TRUE; - } - - break; - case TPM_ALG_SHA384: - if ((HashAlgorithmMask & HASH_ALG_SHA384) != 0) { - return TRUE; - } - - break; - case TPM_ALG_SHA512: - if ((HashAlgorithmMask & HASH_ALG_SHA512) != 0) { - return TRUE; - } - - break; - case TPM_ALG_SM3_256: - if ((HashAlgorithmMask & HASH_ALG_SM3_256) != 0) { - return TRUE; - } - - break; - } - - return FALSE; + return Tpm2IsHashAlgSupportedInHashAlgorithmMask (HashAlg, HashAlgorithmMask); } /** @@ -263,31 +119,7 @@ CopyDigestListToBuffer ( IN UINT32 HashAlgorithmMask ) { - UINTN Index; - UINT16 DigestSize; - UINT32 DigestListCount; - UINT32 *DigestListCountPtr; - - DigestListCountPtr = (UINT32 *)Buffer; - DigestListCount = 0; - Buffer = (UINT8 *)Buffer + sizeof (DigestList->count); - for (Index = 0; Index < DigestList->count; Index++) { - if (!IsHashAlgSupportedInHashAlgorithmMask (DigestList->digests[Index].hashAlg, HashAlgorithmMask)) { - DEBUG ((DEBUG_ERROR, "WARNING: TPM2 Event log has HashAlg unsupported by PCR bank (0x%x)\n", DigestList->digests[Index].hashAlg)); - continue; - } - - CopyMem (Buffer, &DigestList->digests[Index].hashAlg, sizeof (DigestList->digests[Index].hashAlg)); - Buffer = (UINT8 *)Buffer + sizeof (DigestList->digests[Index].hashAlg); - DigestSize = GetHashSizeFromAlgo (DigestList->digests[Index].hashAlg); - CopyMem (Buffer, &DigestList->digests[Index].digest, DigestSize); - Buffer = (UINT8 *)Buffer + DigestSize; - DigestListCount++; - } - - WriteUnaligned32 (DigestListCountPtr, DigestListCount); - - return Buffer; + return Tpm2CopyDigestListToBuffer (Buffer, DigestList, HashAlgorithmMask); } /** @@ -310,45 +142,7 @@ CopyBufferToDigestList ( OUT TPML_DIGEST_VALUES *DigestList ) { - EFI_STATUS Status; - UINTN Index; - UINT16 DigestSize; - CONST UINT8 *BufferPtr; - - Status = EFI_INVALID_PARAMETER; - - if ((Buffer == NULL) || (DigestList == NULL) || (BufferSize > sizeof (TPML_DIGEST_VALUES))) { - return EFI_INVALID_PARAMETER; - } - - DigestList->count = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *)Buffer)); - if (DigestList->count > HASH_COUNT) { - return EFI_INVALID_PARAMETER; - } - - BufferPtr = (CONST UINT8 *)Buffer + sizeof (UINT32); - for (Index = 0; Index < DigestList->count; Index++) { - if (BufferPtr - (CONST UINT8 *)Buffer + sizeof (UINT16) > BufferSize) { - Status = EFI_BAD_BUFFER_SIZE; - break; - } else { - DigestList->digests[Index].hashAlg = SwapBytes16 (ReadUnaligned16 ((CONST UINT16 *)BufferPtr)); - } - - BufferPtr += sizeof (UINT16); - DigestSize = GetHashSizeFromAlgo (DigestList->digests[Index].hashAlg); - if (BufferPtr - (CONST UINT8 *)Buffer + (UINTN)DigestSize > BufferSize) { - Status = EFI_BAD_BUFFER_SIZE; - break; - } else { - CopyMem (&DigestList->digests[Index].digest, BufferPtr, DigestSize); - } - - BufferPtr += DigestSize; - Status = EFI_SUCCESS; - } - - return Status; + return Tpm2CopyBufferToDigestList (Buffer, BufferSize, DigestList); } /** @@ -364,17 +158,7 @@ GetDigestListSize ( IN TPML_DIGEST_VALUES *DigestList ) { - UINTN Index; - UINT16 DigestSize; - UINT32 TotalSize; - - TotalSize = sizeof (DigestList->count); - for (Index = 0; Index < DigestList->count; Index++) { - DigestSize = GetHashSizeFromAlgo (DigestList->digests[Index].hashAlg); - TotalSize += sizeof (DigestList->digests[Index].hashAlg) + DigestSize; - } - - return TotalSize; + return Tpm2GetDigestListSize (DigestList); } /** @@ -390,17 +174,7 @@ GetDigestListSizeFromHashAlgorithmMask ( IN UINT32 HashAlgorithmMask ) { - UINTN Index; - UINT32 TotalSize; - - TotalSize = sizeof (UINT32); - for (Index = 0; Index < ARRAY_SIZE (mHashInfo); Index++) { - if ((mHashInfo[Index].HashMask & HashAlgorithmMask) != 0) { - TotalSize += sizeof (TPMI_ALG_HASH) + mHashInfo[Index].HashSize; - } - } - - return TotalSize; + return Tpm2GetDigestListSizeFromHashAlgorithmMask (HashAlgorithmMask); } /** @@ -421,20 +195,5 @@ GetDigestFromDigestList ( OUT VOID *Digest ) { - UINTN Index; - UINT16 DigestSize; - - DigestSize = GetHashSizeFromAlgo (HashAlg); - for (Index = 0; Index < DigestList->count; Index++) { - if (DigestList->digests[Index].hashAlg == HashAlg) { - CopyMem ( - Digest, - &DigestList->digests[Index].digest, - DigestSize - ); - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; + return Tpm2GetDigestFromDigestList (HashAlg, DigestList, Digest); } From a48fae661125042e16c8f7e082226ecbd9a29adb Mon Sep 17 00:00:00 2001 From: rdiaz Date: Tue, 10 Feb 2026 02:49:59 +0000 Subject: [PATCH 020/406] SecurityPkg: Update HashLibBaseCryptoRouter HashLibBaseCryptoRouterCommon contained a version of Tpm2GetHashMaskFromAlgo which was causing conflicts with the version in Tpm2HelpLib. This version used a GUID to query the HashMask, updated the name to remove the conflict and be more inline with the actual function implementation. Signed-off-by: Raymond Diaz --- .../HashLibBaseCryptoRouterCommon.c | 4 ++-- .../HashLibBaseCryptoRouterCommon.h | 5 +++-- .../HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c | 8 ++++---- .../HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c | 8 ++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c index 1013380844..acf51bd6c1 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c @@ -29,7 +29,7 @@ TPM2_HASH_MASK mTpm2HashMask[] = { }; /** - The function get hash mask info from algorithm. + The function get hash mask info from GUID. @param HashGuid Hash Guid @@ -37,7 +37,7 @@ TPM2_HASH_MASK mTpm2HashMask[] = { **/ UINT32 EFIAPI -Tpm2GetHashMaskFromAlgo ( +Tpm2GetHashMaskFromGuid ( IN EFI_GUID *HashGuid ) { diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.h b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.h index 3a104e0971..fbe7568562 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.h +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.h @@ -2,6 +2,7 @@ This is BaseCrypto router support function definition. Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation. SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -9,7 +10,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #pragma once /** - The function get hash mask info from algorithm. + The function get hash mask info from GUID. @param HashGuid Hash Guid @@ -17,7 +18,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ UINT32 EFIAPI -Tpm2GetHashMaskFromAlgo ( +Tpm2GetHashMaskFromGuid ( IN EFI_GUID *HashGuid ); diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c index 8c2c4f0db2..f691f6e902 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c @@ -80,7 +80,7 @@ HashStart ( ASSERT (HashCtx != NULL); for (Index = 0; Index < mHashInterfaceCount; Index++) { - HashMask = Tpm2GetHashMaskFromAlgo (&mHashInterface[Index].HashGuid); + HashMask = Tpm2GetHashMaskFromGuid (&mHashInterface[Index].HashGuid); if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) { mHashInterface[Index].HashInit (&HashCtx[Index]); } @@ -121,7 +121,7 @@ HashUpdate ( HashCtx = (HASH_HANDLE *)HashHandle; for (Index = 0; Index < mHashInterfaceCount; Index++) { - HashMask = Tpm2GetHashMaskFromAlgo (&mHashInterface[Index].HashGuid); + HashMask = Tpm2GetHashMaskFromGuid (&mHashInterface[Index].HashGuid); if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) { mHashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen); } @@ -215,7 +215,7 @@ HashCompleteAndExtend ( ZeroMem (DigestList, sizeof (*DigestList)); for (Index = 0; Index < mHashInterfaceCount; Index++) { - HashMask = Tpm2GetHashMaskFromAlgo (&mHashInterface[Index].HashGuid); + HashMask = Tpm2GetHashMaskFromGuid (&mHashInterface[Index].HashGuid); if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) { mHashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen); mHashInterface[Index].HashFinal (HashCtx[Index], &Digest); @@ -309,7 +309,7 @@ RegisterHashInterfaceLib ( // // Check allow // - HashMask = Tpm2GetHashMaskFromAlgo (&HashInterface->HashGuid); + HashMask = Tpm2GetHashMaskFromGuid (&HashInterface->HashGuid); Tpm2HashMask = PcdGet32 (PcdTpm2HashMask); if ((Tpm2HashMask != 0) && diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c index eeb424b6c3..90356bd6c1 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c @@ -155,7 +155,7 @@ HashStart ( ASSERT (HashCtx != NULL); for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) { - HashMask = Tpm2GetHashMaskFromAlgo (&HashInterfaceHob->HashInterface[Index].HashGuid); + HashMask = Tpm2GetHashMaskFromGuid (&HashInterfaceHob->HashInterface[Index].HashGuid); if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) { HashInterfaceHob->HashInterface[Index].HashInit (&HashCtx[Index]); } @@ -202,7 +202,7 @@ HashUpdate ( HashCtx = (HASH_HANDLE *)HashHandle; for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) { - HashMask = Tpm2GetHashMaskFromAlgo (&HashInterfaceHob->HashInterface[Index].HashGuid); + HashMask = Tpm2GetHashMaskFromGuid (&HashInterfaceHob->HashInterface[Index].HashGuid); if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) { HashInterfaceHob->HashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen); } @@ -254,7 +254,7 @@ HashCompleteAndExtend ( ZeroMem (DigestList, sizeof (*DigestList)); for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) { - HashMask = Tpm2GetHashMaskFromAlgo (&HashInterfaceHob->HashInterface[Index].HashGuid); + HashMask = Tpm2GetHashMaskFromGuid (&HashInterfaceHob->HashInterface[Index].HashGuid); if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) { HashInterfaceHob->HashInterface[Index].HashUpdate (HashCtx[Index], DataToHash, DataToHashLen); HashInterfaceHob->HashInterface[Index].HashFinal (HashCtx[Index], &Digest); @@ -336,7 +336,7 @@ RegisterHashInterfaceLib ( // // Check allow // - HashMask = Tpm2GetHashMaskFromAlgo (&HashInterface->HashGuid); + HashMask = Tpm2GetHashMaskFromGuid (&HashInterface->HashGuid); Tpm2HashMask = PcdGet32 (PcdTpm2HashMask); if ((Tpm2HashMask != 0) && From d93ad5f525e5a994a0b51fb46bea5fe8c0bbb98e Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Tue, 12 May 2026 14:36:35 -0700 Subject: [PATCH 021/406] MdeModulePkg: Dxe Core: Allocate Memory Bins Contiguously Currently, there is no guarantee that the memory bins will be allocated contiguously. However, there are assumptions in the code that bins are allocated contiguously, such as the GCD init code requiring a free memory region be large enough for a contiguous bin range on DXE Core init. Ensuring contiguous bins also makes a cleaner model for the bins and keeps the memory map in a more standard configuration between different configurations, as platforms today can pass a resource descriptor HOB to DXE core to describe the bin range and this only supports a contiguous range. This also sets up reusing the memory bin logic for PEI memory bin support which will use the aforementioned resource descriptor HOB to pass the bin range to DXE. This commit updates CoreAddMemoryDescriptor() to allocate a contiguous range. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Mem/Page.c | 126 +++++++++++++------------------ 1 file changed, 53 insertions(+), 73 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 5a3a9f102d..897848757f 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -650,6 +650,13 @@ CoreSetMemoryTypeInformationRange ( } } + DEBUG (( + DEBUG_INFO, + "%a: Inherited range 0x%llx - 0x%llx for memory bins\n", + __func__, + Start, + Start + Length -1 + )); mMemoryTypeInformationInitialized = TRUE; } @@ -677,11 +684,10 @@ CoreAddMemoryDescriptor ( ) { EFI_PHYSICAL_ADDRESS End; - EFI_STATUS Status; UINTN Index; - UINTN FreeIndex; - UINT64 Alignment; - UINT64 BinSize; + EFI_PHYSICAL_ADDRESS BaseAddress; + EFI_PHYSICAL_ADDRESS LastBinAddress; + UINT64 RequiredSize; if ((Start & EFI_PAGE_MASK) != 0) { return; @@ -718,6 +724,42 @@ CoreAddMemoryDescriptor ( return; } + BaseAddress = 0; + RequiredSize = CalculateTotalMemoryBinSizeNeeded (NULL); + if (RequiredSize == 0) { + mMemoryTypeInformationInitialized = TRUE; + return; + } + + // To ensure we get a contiguous range of memory for our bins, we will attempt to allocate + // all of the memory needed in one go. If that works, we can then carve it up into the individual bins. + // Our size is already aligned to the correct granularity, allocate aligned pages to ensure the base address is + // aligned. + BaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAlignedPages ( + EFI_SIZE_TO_PAGES ((UINTN)RequiredSize), + RUNTIME_PAGE_ALLOCATION_GRANULARITY + ); + + if (BaseAddress == 0) { + DEBUG (( + DEBUG_INFO, + "%a: Could not allocate contiguous pages for all memory bins. It will be attempted again when more memory is added.\n", + __func__ + )); + return; + } + + DEBUG (( + DEBUG_INFO, + "%a: Allocated 0x%llx - 0x%llx for memory bins\n", + __func__, + BaseAddress, + BaseAddress + RequiredSize - 1 + )); + + LastBinAddress = BaseAddress + RequiredSize; + mDefaultMaximumAddress = BaseAddress - 1; + // // Loop through each memory type in the order specified by the gMemoryTypeInformation[] array // @@ -731,71 +773,9 @@ CoreAddMemoryDescriptor ( } if (gMemoryTypeInformation[Index].NumberOfPages != 0) { - Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY; - if ((gMemoryTypeInformation[Index].Type == EfiReservedMemoryType) || - (gMemoryTypeInformation[Index].Type == EfiACPIMemoryNVS) || - (gMemoryTypeInformation[Index].Type == EfiRuntimeServicesCode) || - (gMemoryTypeInformation[Index].Type == EfiRuntimeServicesData)) - { - Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY; - } - - BinSize = EFI_PAGES_TO_SIZE ((UINTN)gMemoryTypeInformation[Index].NumberOfPages); - BinSize = ALIGN_VALUE (BinSize, Alignment); - - gMemoryTypeInformation[Index].NumberOfPages = (UINT32)EFI_SIZE_TO_PAGES ((UINTN)BinSize); - - // - // Allocate pages for the current memory type from the top of available memory - // - Status = CoreAllocatePages ( - AllocateAnyPages, - Type, - gMemoryTypeInformation[Index].NumberOfPages, - &mMemoryTypeStatistics[Type].BaseAddress - ); - if (EFI_ERROR (Status)) { - // - // If an error occurs allocating the pages for the current memory type, then - // free all the pages allocates for the previous memory types and return. This - // operation with be retied when/if more memory is added to the system - // - for (FreeIndex = 0; FreeIndex < Index; FreeIndex++) { - // - // Make sure the memory type in the gMemoryTypeInformation[] array is valid - // - Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[FreeIndex].Type); - if ((UINT32)Type > EfiMaxMemoryType) { - continue; - } - - if (gMemoryTypeInformation[FreeIndex].NumberOfPages != 0) { - CoreFreePages ( - mMemoryTypeStatistics[Type].BaseAddress, - gMemoryTypeInformation[FreeIndex].NumberOfPages - ); - mMemoryTypeStatistics[Type].BaseAddress = 0; - mMemoryTypeStatistics[Type].MaximumAddress = MAX_ALLOC_ADDRESS; - } - } - - return; - } - - // - // Compute the address at the top of the current statistics - // - mMemoryTypeStatistics[Type].MaximumAddress = - mMemoryTypeStatistics[Type].BaseAddress + - LShiftU64 (gMemoryTypeInformation[Index].NumberOfPages, EFI_PAGE_SHIFT) - 1; - - // - // If the current base address is the lowest address so far, then update the default - // maximum address - // - if (mMemoryTypeStatistics[Type].BaseAddress < mDefaultMaximumAddress) { - mDefaultMaximumAddress = mMemoryTypeStatistics[Type].BaseAddress - 1; - } + mMemoryTypeStatistics[Type].BaseAddress = LastBinAddress - EFI_PAGES_TO_SIZE (gMemoryTypeInformation[Index].NumberOfPages); + mMemoryTypeStatistics[Type].MaximumAddress = LastBinAddress - 1; + LastBinAddress = mMemoryTypeStatistics[Type].BaseAddress; } } @@ -804,6 +784,10 @@ CoreAddMemoryDescriptor ( // those memory areas can be freed for future allocations, and all future memory // allocations can occur within their respective bins // + FreeAlignedPages ( + (VOID *)(UINTN)BaseAddress, + EFI_SIZE_TO_PAGES ((UINTN)RequiredSize) + ); for (Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { // // Make sure the memory type in the gMemoryTypeInformation[] array is valid @@ -814,10 +798,6 @@ CoreAddMemoryDescriptor ( } if (gMemoryTypeInformation[Index].NumberOfPages != 0) { - CoreFreePages ( - mMemoryTypeStatistics[Type].BaseAddress, - gMemoryTypeInformation[Index].NumberOfPages - ); mMemoryTypeStatistics[Type].NumberOfPages = gMemoryTypeInformation[Index].NumberOfPages; gMemoryTypeInformation[Index].NumberOfPages = 0; } From 3b61f4d266ba8e8a4c320a06295637b01f098c2b Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Fri, 29 May 2026 11:57:31 +0100 Subject: [PATCH 022/406] EmbeddedPkg,MdeModulePkg,DynamicTablesPkg: Move ACPI helper macros Move the ACPI table helper macros from EmbeddedPkg's AcpiLib.h to MdeModulePkg's AcpiHelperMacros.h. These macros describe ACPI data initializers and do not depend on the AcpiLib library interface. Keeping them in AcpiLib.h forces users that only need the macros to include the AcpiLib library header unnecessarily. Place the macros in a common MdeModulePkg public header so ACPI table producers can include the macro definitions directly without implying use of AcpiLib. The companion edk2-platforms change is: "Global: Include AcpiHelperMacros.h for ACPI helper macros" Tested: DynamicTablesPkg: X64/AARCH64 DEBUG/RELEASE/NOOPT MdeModulePkg: X64/AARCH64 DEBUG/RELEASE/NOOPT EmbeddedPkg: X64/AARCH64 DEBUG/RELEASE/NOOPT Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Varshit Pandya --- .../Acpi/Common/AcpiFadtLib/FadtGenerator.c | 23 ++--- .../Acpi/Common/AcpiSpcrLib/SpcrGenerator.c | 4 +- EmbeddedPkg/Include/Library/AcpiLib.h | 75 ---------------- MdeModulePkg/Include/AcpiHelperMacros.h | 86 +++++++++++++++++++ 4 files changed, 100 insertions(+), 88 deletions(-) create mode 100644 MdeModulePkg/Include/AcpiHelperMacros.h diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c index 58ac024157..0934fb3541 100644 --- a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c @@ -16,6 +16,7 @@ #include // Module specific include files. +#include #include #include #include @@ -209,7 +210,7 @@ EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE AcpiFadt = { // UINT32 Flags 0, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE ResetReg - NULL_GAS, + ACPI_NULL_GAS, // UINT8 ResetValue 0, // UINT16 ArmBootArch @@ -221,25 +222,25 @@ EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE AcpiFadt = { // UINT64 XDsdt 0, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE XPm1aEvtBlk - NULL_GAS, + ACPI_NULL_GAS, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE XPm1bEvtBlk - NULL_GAS, + ACPI_NULL_GAS, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE XPm1aCntBlk - NULL_GAS, + ACPI_NULL_GAS, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE XPm1bCntBlk - NULL_GAS, + ACPI_NULL_GAS, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE XPm2CntBlk - NULL_GAS, + ACPI_NULL_GAS, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE XPmTmrBlk - NULL_GAS, + ACPI_NULL_GAS, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE XGpe0Blk - NULL_GAS, + ACPI_NULL_GAS, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE XGpe1Blk - NULL_GAS, + ACPI_NULL_GAS, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE SleepControlReg - NULL_GAS, + ACPI_NULL_GAS, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE SleepStatusReg - NULL_GAS, + ACPI_NULL_GAS, // UINT64 HypervisorVendorIdentity EFI_ACPI_RESERVED_QWORD // {Template}: Hypervisor Vendor ID }; diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiSpcrLib/SpcrGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiSpcrLib/SpcrGenerator.c index 421594bec0..7e7546532f 100644 --- a/DynamicTablesPkg/Library/Acpi/Common/AcpiSpcrLib/SpcrGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiSpcrLib/SpcrGenerator.c @@ -11,7 +11,7 @@ Specification - Version 1.03 - August 10, 2015. **/ - +#include #include #include #include @@ -84,7 +84,7 @@ EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_4 AcpiSpcr = { EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE }, - ARM_GAS32 (0), // {Template}: Serial Port Base Address + ACPI_GAS32 (0), // {Template}: Serial Port Base Address EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC, 0, // Not used on ARM 0, // {Template}: Serial Port Interrupt diff --git a/EmbeddedPkg/Include/Library/AcpiLib.h b/EmbeddedPkg/Include/Library/AcpiLib.h index 026072748c..943288a643 100644 --- a/EmbeddedPkg/Include/Library/AcpiLib.h +++ b/EmbeddedPkg/Include/Library/AcpiLib.h @@ -15,81 +15,6 @@ #include #include -// -// Macros for the Generic Address Space -// -#define NULL_GAS { EFI_ACPI_5_0_SYSTEM_MEMORY, 0, 0, EFI_ACPI_5_0_UNDEFINED, 0L } -#define ARM_GAS8(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 8, 0, EFI_ACPI_5_0_BYTE, Address } -#define ARM_GAS16(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 16, 0, EFI_ACPI_5_0_WORD, Address } -#define ARM_GAS32(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 32, 0, EFI_ACPI_5_0_DWORD, Address } -#define ARM_GASN(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 0, 0, EFI_ACPI_5_0_DWORD, Address } - -// -// Macros for the Multiple APIC Description Table (MADT) -// -#define EFI_ACPI_5_0_GIC_DISTRIBUTOR_INIT(GicDistHwId, GicDistBase, GicDistVector) \ - { \ - EFI_ACPI_5_0_GICD, sizeof (EFI_ACPI_5_0_GIC_DISTRIBUTOR_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ - GicDistHwId, GicDistBase, GicDistVector, EFI_ACPI_RESERVED_DWORD \ - } - -#define EFI_ACPI_6_0_GIC_DISTRIBUTOR_INIT(GicDistHwId, GicDistBase, GicDistVector, GicVersion) \ - { \ - EFI_ACPI_6_0_GICD, sizeof (EFI_ACPI_6_0_GIC_DISTRIBUTOR_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ - GicDistHwId, GicDistBase, GicDistVector, GicVersion, \ - {EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE} \ - } - -// Note the parking protocol is configured by UEFI if required -#define EFI_ACPI_5_0_GIC_STRUCTURE_INIT(GicId, AcpiCpuId, Flags, PmuIrq, GicBase) \ - { \ - EFI_ACPI_5_0_GIC, sizeof (EFI_ACPI_5_0_GIC_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ - GicId, AcpiCpuId, Flags, 0, PmuIrq, 0, GicBase \ - } - -// Note the parking protocol is configured by UEFI if required -#define EFI_ACPI_5_1_GICC_STRUCTURE_INIT(GicId, AcpiCpuUid, Mpidr, Flags, PmuIrq, \ - GicBase, GicVBase, GicHBase, GsivId, GicRBase) \ - { \ - EFI_ACPI_5_1_GIC, sizeof (EFI_ACPI_5_1_GIC_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ - GicId, AcpiCpuUid, Flags, 0, PmuIrq, 0, GicBase, GicVBase, GicHBase, \ - GsivId, GicRBase, Mpidr \ - } - -#define EFI_ACPI_6_0_GICC_STRUCTURE_INIT(GicId, AcpiCpuUid, Mpidr, Flags, PmuIrq, \ - GicBase, GicVBase, GicHBase, GsivId, GicRBase, Efficiency) \ - { \ - EFI_ACPI_6_0_GIC, sizeof (EFI_ACPI_6_0_GIC_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ - GicId, AcpiCpuUid, Flags, 0, PmuIrq, 0, GicBase, GicVBase, GicHBase, \ - GsivId, GicRBase, Mpidr, Efficiency, \ - {EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE} \ - } - -#define EFI_ACPI_6_3_GICC_STRUCTURE_INIT(GicId, AcpiCpuUid, Mpidr, Flags, PmuIrq, \ - GicBase, GicVBase, GicHBase, GsivId, GicRBase, Efficiency, SpeOvflIrq) \ - { \ - EFI_ACPI_6_0_GIC, sizeof (EFI_ACPI_6_3_GIC_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ - GicId, AcpiCpuUid, Flags, 0, PmuIrq, 0, GicBase, GicVBase, GicHBase, \ - GsivId, GicRBase, Mpidr, Efficiency, EFI_ACPI_RESERVED_BYTE, SpeOvflIrq \ - } - -#define EFI_ACPI_6_0_GIC_MSI_FRAME_INIT(GicMsiFrameId, PhysicalBaseAddress, Flags, SPICount, SPIBase) \ - { \ - EFI_ACPI_6_0_GIC_MSI_FRAME, sizeof (EFI_ACPI_6_0_GIC_MSI_FRAME_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ - GicMsiFrameId, PhysicalBaseAddress, Flags, SPICount, SPIBase \ - } - -// -// SBSA Generic Watchdog -// -#define EFI_ACPI_5_1_SBSA_GENERIC_WATCHDOG_STRUCTURE_INIT(RefreshFramePhysicalAddress, \ - ControlFramePhysicalAddress, WatchdogTimerGSIV, WatchdogTimerFlags) \ - { \ - EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG, sizeof(EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE), \ - EFI_ACPI_RESERVED_BYTE, RefreshFramePhysicalAddress, ControlFramePhysicalAddress, \ - WatchdogTimerGSIV, WatchdogTimerFlags \ - } - typedef BOOLEAN (EFIAPI *EFI_LOCATE_ACPI_CHECK)( diff --git a/MdeModulePkg/Include/AcpiHelperMacros.h b/MdeModulePkg/Include/AcpiHelperMacros.h new file mode 100644 index 0000000000..5a34720bc9 --- /dev/null +++ b/MdeModulePkg/Include/AcpiHelperMacros.h @@ -0,0 +1,86 @@ +/** @file + Helper Library for ACPI + + Copyright (c) 2014-2026, ARM Ltd. All rights reserved. + Copyright (c) 2021, Ampere Computing LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#pragma once + +// +// Macros for the Generic Address Space +// +#define ACPI_NULL_GAS { EFI_ACPI_5_0_SYSTEM_MEMORY, 0, 0, EFI_ACPI_5_0_UNDEFINED, 0L } +#define ACPI_GAS8(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 8, 0, EFI_ACPI_5_0_BYTE, Address } +#define ACPI_GAS16(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 16, 0, EFI_ACPI_5_0_WORD, Address } +#define ACPI_GAS32(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 32, 0, EFI_ACPI_5_0_DWORD, Address } +#define ACPI_GASN(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 0, 0, EFI_ACPI_5_0_DWORD, Address } + +// +// Macros for the Multiple APIC Description Table (MADT) +// +#define EFI_ACPI_5_0_GIC_DISTRIBUTOR_INIT(GicDistHwId, GicDistBase, GicDistVector) \ + { \ + EFI_ACPI_5_0_GICD, sizeof (EFI_ACPI_5_0_GIC_DISTRIBUTOR_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ + GicDistHwId, GicDistBase, GicDistVector, EFI_ACPI_RESERVED_DWORD \ + } + +#define EFI_ACPI_6_0_GIC_DISTRIBUTOR_INIT(GicDistHwId, GicDistBase, GicDistVector, GicVersion) \ + { \ + EFI_ACPI_6_0_GICD, sizeof (EFI_ACPI_6_0_GIC_DISTRIBUTOR_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ + GicDistHwId, GicDistBase, GicDistVector, GicVersion, \ + {EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE} \ + } + +// Note the parking protocol is configured by UEFI if required +#define EFI_ACPI_5_0_GIC_STRUCTURE_INIT(GicId, AcpiCpuId, Flags, PmuIrq, GicBase) \ + { \ + EFI_ACPI_5_0_GIC, sizeof (EFI_ACPI_5_0_GIC_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ + GicId, AcpiCpuId, Flags, 0, PmuIrq, 0, GicBase \ + } + +// Note the parking protocol is configured by UEFI if required +#define EFI_ACPI_5_1_GICC_STRUCTURE_INIT(GicId, AcpiCpuUid, Mpidr, Flags, PmuIrq, \ + GicBase, GicVBase, GicHBase, GsivId, GicRBase) \ + { \ + EFI_ACPI_5_1_GIC, sizeof (EFI_ACPI_5_1_GIC_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ + GicId, AcpiCpuUid, Flags, 0, PmuIrq, 0, GicBase, GicVBase, GicHBase, \ + GsivId, GicRBase, Mpidr \ + } + +#define EFI_ACPI_6_0_GICC_STRUCTURE_INIT(GicId, AcpiCpuUid, Mpidr, Flags, PmuIrq, \ + GicBase, GicVBase, GicHBase, GsivId, GicRBase, Efficiency) \ + { \ + EFI_ACPI_6_0_GIC, sizeof (EFI_ACPI_6_0_GIC_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ + GicId, AcpiCpuUid, Flags, 0, PmuIrq, 0, GicBase, GicVBase, GicHBase, \ + GsivId, GicRBase, Mpidr, Efficiency, \ + {EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE} \ + } + +#define EFI_ACPI_6_3_GICC_STRUCTURE_INIT(GicId, AcpiCpuUid, Mpidr, Flags, PmuIrq, \ + GicBase, GicVBase, GicHBase, GsivId, GicRBase, Efficiency, SpeOvflIrq) \ + { \ + EFI_ACPI_6_0_GIC, sizeof (EFI_ACPI_6_3_GIC_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ + GicId, AcpiCpuUid, Flags, 0, PmuIrq, 0, GicBase, GicVBase, GicHBase, \ + GsivId, GicRBase, Mpidr, Efficiency, EFI_ACPI_RESERVED_BYTE, SpeOvflIrq \ + } + +#define EFI_ACPI_6_0_GIC_MSI_FRAME_INIT(GicMsiFrameId, PhysicalBaseAddress, Flags, SPICount, SPIBase) \ + { \ + EFI_ACPI_6_0_GIC_MSI_FRAME, sizeof (EFI_ACPI_6_0_GIC_MSI_FRAME_STRUCTURE), EFI_ACPI_RESERVED_WORD, \ + GicMsiFrameId, PhysicalBaseAddress, Flags, SPICount, SPIBase \ + } + +// +// SBSA Generic Watchdog +// +#define EFI_ACPI_5_1_SBSA_GENERIC_WATCHDOG_STRUCTURE_INIT(RefreshFramePhysicalAddress, \ + ControlFramePhysicalAddress, WatchdogTimerGSIV, WatchdogTimerFlags) \ + { \ + EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG, sizeof(EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE), \ + EFI_ACPI_RESERVED_BYTE, RefreshFramePhysicalAddress, ControlFramePhysicalAddress, \ + WatchdogTimerGSIV, WatchdogTimerFlags \ + } From 9bf69ed7ed03d88535a43987e5b8105406b42d57 Mon Sep 17 00:00:00 2001 From: jmestwa-coder Date: Sat, 30 May 2026 08:04:50 +0530 Subject: [PATCH 023/406] NetworkPkg/Dhcp6Dxe: bound IA inner option length to buffer Dhcp6SeekInnerOptionSafe() reads the IA_NA/IA_TA option-len field from a received datagram and only validates it against the fixed minimums, never against OptionLen (the bytes actually remaining in the packet). A reply can declare an option-len up to 0xFFFF while the real buffer is only the 16-byte (IA_NA) or 8-byte (IA_TA) minimum, so the returned inner length is far larger than the buffer. That length is then passed as SeekLen to Dhcp6SeekOption(), which walks ReadUnaligned16() cursors up to Buf + SeekLen and reads past the end of the packet allocation, an attacker-controlled out-of-bounds read. Bound the declared inner length against OptionLen minus the IA header size in both the IA_NA and IA_TA branches, rejecting over-declared options with EFI_DEVICE_ERROR. Parenthesize DHCP6_MIN_SIZE_OF_IA_NA so the subtraction in that bound binds correctly. Add host tests covering the over-declared, off-by-one, and exact-boundary cases for both IA_NA and IA_TA. Signed-off-by: jmestwa-coder --- NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h | 4 +- NetworkPkg/Dhcp6Dxe/Dhcp6Io.c | 14 ++ .../Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp | 176 ++++++++++++++++++ 3 files changed, 192 insertions(+), 2 deletions(-) diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h b/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h index 3ec5de1dd6..a7e358a7c8 100644 --- a/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h +++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h @@ -148,8 +148,8 @@ STATIC_ASSERT ( ); // This is the size of IA_NA without options (16) -#define DHCP6_MIN_SIZE_OF_IA_NA DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN + \ - DHCP6_SIZE_OF_COMBINED_IAID_T1_T2 +#define DHCP6_MIN_SIZE_OF_IA_NA (DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN + \ + DHCP6_SIZE_OF_COMBINED_IAID_T1_T2) STATIC_ASSERT ( DHCP6_MIN_SIZE_OF_IA_NA == 16, "Minimum combined size of IA_TA per RFC 8415" diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c b/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c index 34cf8473d3..79a67796ee 100644 --- a/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c +++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c @@ -750,6 +750,13 @@ Dhcp6SeekInnerOptionSafe ( } IaInnerLenTmp -= DHCP6_SIZE_OF_COMBINED_IAID_T1_T2; + + // + // Verify the declared inner length does not run past the option buffer. + // + if (IaInnerLenTmp > OptionLen - DHCP6_MIN_SIZE_OF_IA_NA) { + return EFI_DEVICE_ERROR; + } } else if (IaType == Dhcp6OptIata) { // // Verify the OptionLen is valid. @@ -769,6 +776,13 @@ Dhcp6SeekInnerOptionSafe ( } IaInnerLenTmp -= DHCP6_SIZE_OF_IAID; + + // + // Verify the declared inner length does not run past the option buffer. + // + if (IaInnerLenTmp > OptionLen - DHCP6_MIN_SIZE_OF_IA_TA) { + return EFI_DEVICE_ERROR; + } } else { return EFI_DEVICE_ERROR; } diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp index 7f14bebc44..6caf4c1628 100644 --- a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp @@ -699,6 +699,182 @@ TEST_F (Dhcp6SeekInnerOptionSafeTest, InvalidOption) { ASSERT_EQ (Result, EFI_DEVICE_ERROR); } +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe rejects an IANA option whose +// declared length runs past the end of the option buffer. +TEST_F (Dhcp6SeekInnerOptionSafeTest, IANAInnerLenExceedsBufferExpectFail) { + EFI_STATUS Status; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_NA) + SEARCH_PATTERN_LEN] = { 0 }; + UINT32 OptionLength = sizeof (Option); + DHCPv6_OPTION_IA_NA *OptionPtr = (DHCPv6_OPTION_IA_NA *)Option; + + UINT8 *InnerOptionPtr = NULL; + UINT16 InnerOptionLength = 0; + + OptionPtr->Header.Code = Dhcp6OptIana; + OptionPtr->Header.Len = HTONS (0xFFFF); // Declare far more inner data than the buffer holds + OptionPtr->Header.IAID = 0x12345678; + OptionPtr->T1 = 0x11111111; + OptionPtr->T2 = 0x22222222; + + Status = Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIana, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_DEVICE_ERROR); +} + +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe rejects an IATA option whose +// declared length runs past the end of the option buffer. +TEST_F (Dhcp6SeekInnerOptionSafeTest, IATAInnerLenExceedsBufferExpectFail) { + EFI_STATUS Status; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_TA) + SEARCH_PATTERN_LEN] = { 0 }; + UINT32 OptionLength = sizeof (Option); + DHCPv6_OPTION_IA_TA *OptionPtr = (DHCPv6_OPTION_IA_TA *)Option; + + UINT8 *InnerOptionPtr = NULL; + UINT16 InnerOptionLength = 0; + + OptionPtr->Header.Code = Dhcp6OptIata; + OptionPtr->Header.Len = HTONS (0xFFFF); // Declare far more inner data than the buffer holds + OptionPtr->Header.IAID = 0x12345678; + + Status = Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIata, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_DEVICE_ERROR); +} + +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe rejects an IANA option whose +// declared inner length is one byte past the end of the option buffer. +TEST_F (Dhcp6SeekInnerOptionSafeTest, IANAInnerLenOffByOneExpectFail) { + EFI_STATUS Status; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_NA) + SEARCH_PATTERN_LEN] = { 0 }; + UINT32 OptionLength = sizeof (Option); + DHCPv6_OPTION_IA_NA *OptionPtr = (DHCPv6_OPTION_IA_NA *)Option; + + UINT8 *InnerOptionPtr = NULL; + UINT16 InnerOptionLength = 0; + + OptionPtr->Header.Code = Dhcp6OptIana; + // One byte more inner data than OptionLen - DHCP6_MIN_SIZE_OF_IA_NA allows + OptionPtr->Header.Len = HTONS (DHCP6_SIZE_OF_COMBINED_IAID_T1_T2 + (OptionLength - DHCP6_MIN_SIZE_OF_IA_NA) + 1); + OptionPtr->Header.IAID = 0x12345678; + OptionPtr->T1 = 0x11111111; + OptionPtr->T2 = 0x22222222; + + Status = Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIana, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_DEVICE_ERROR); +} + +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe rejects an IATA option whose +// declared inner length is one byte past the end of the option buffer. +TEST_F (Dhcp6SeekInnerOptionSafeTest, IATAInnerLenOffByOneExpectFail) { + EFI_STATUS Status; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_TA) + SEARCH_PATTERN_LEN] = { 0 }; + UINT32 OptionLength = sizeof (Option); + DHCPv6_OPTION_IA_TA *OptionPtr = (DHCPv6_OPTION_IA_TA *)Option; + + UINT8 *InnerOptionPtr = NULL; + UINT16 InnerOptionLength = 0; + + OptionPtr->Header.Code = Dhcp6OptIata; + // One byte more inner data than OptionLen - DHCP6_MIN_SIZE_OF_IA_TA allows + OptionPtr->Header.Len = HTONS ((UINT16)(DHCP6_SIZE_OF_IAID + (OptionLength - DHCP6_MIN_SIZE_OF_IA_TA) + 1)); + OptionPtr->Header.IAID = 0x12345678; + + Status = Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIata, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_DEVICE_ERROR); +} + +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe accepts an IANA option whose +// declared inner length exactly matches OptionLen - DHCP6_MIN_SIZE_OF_IA_NA. +TEST_F (Dhcp6SeekInnerOptionSafeTest, IANAInnerLenExactMatchExpectSuccess) { + EFI_STATUS Status; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_NA) + SEARCH_PATTERN_LEN] = { 0 }; + UINT32 OptionLength = sizeof (Option); + DHCPv6_OPTION_IA_NA *OptionPtr = (DHCPv6_OPTION_IA_NA *)Option; + UINT32 SearchPattern = SEARCH_PATTERN; + + UINTN SearchPatternLength = SEARCH_PATTERN_LEN; + UINT8 *InnerOptionPtr = NULL; + UINT16 InnerOptionLength = 0; + + OptionPtr->Header.Code = Dhcp6OptIana; + // Inner length exactly equal to OptionLen - DHCP6_MIN_SIZE_OF_IA_NA + OptionPtr->Header.Len = HTONS (DHCP6_SIZE_OF_COMBINED_IAID_T1_T2 + (OptionLength - DHCP6_MIN_SIZE_OF_IA_NA)); + OptionPtr->Header.IAID = 0x12345678; + OptionPtr->T1 = 0x11111111; + OptionPtr->T2 = 0x22222222; + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength); + + Status = Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIana, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_SUCCESS); + ASSERT_EQ (InnerOptionLength, (UINT16)(OptionLength - DHCP6_MIN_SIZE_OF_IA_NA)); + ASSERT_EQ (CompareMem (InnerOptionPtr, &SearchPattern, SearchPatternLength), 0); +} + +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe accepts an IATA option whose +// declared inner length exactly matches OptionLen - DHCP6_MIN_SIZE_OF_IA_TA. +TEST_F (Dhcp6SeekInnerOptionSafeTest, IATAInnerLenExactMatchExpectSuccess) { + EFI_STATUS Status; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_TA) + SEARCH_PATTERN_LEN] = { 0 }; + UINT32 OptionLength = sizeof (Option); + DHCPv6_OPTION_IA_TA *OptionPtr = (DHCPv6_OPTION_IA_TA *)Option; + UINT32 SearchPattern = SEARCH_PATTERN; + + UINTN SearchPatternLength = SEARCH_PATTERN_LEN; + UINT8 *InnerOptionPtr = NULL; + UINT16 InnerOptionLength = 0; + + OptionPtr->Header.Code = Dhcp6OptIata; + // Inner length exactly equal to OptionLen - DHCP6_MIN_SIZE_OF_IA_TA + OptionPtr->Header.Len = HTONS ((UINT16)(DHCP6_SIZE_OF_IAID + (OptionLength - DHCP6_MIN_SIZE_OF_IA_TA))); + OptionPtr->Header.IAID = 0x12345678; + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength); + + Status = Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIata, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_SUCCESS); + ASSERT_EQ (InnerOptionLength, (UINT16)(OptionLength - DHCP6_MIN_SIZE_OF_IA_TA)); + ASSERT_EQ (CompareMem (InnerOptionPtr, &SearchPattern, SearchPatternLength), 0); +} + //////////////////////////////////////////////////////////////////////// // Dhcp6SeekStsOption Tests //////////////////////////////////////////////////////////////////////// From 0573bda1c67e95e105ab721f8c4c3bc04efa0916 Mon Sep 17 00:00:00 2001 From: Qihang Gao Date: Thu, 7 May 2026 17:27:36 +0800 Subject: [PATCH 024/406] ManageabilityPkg: Fix build failure issue on CLANGDWARF X64 When building ManageabilityPkg with `-a X64 -t CLANGDWARF`, error message is throwed: BaseManageabilityTransportHelper.c:462:3: error: '__builtin_ms_va_start' used in System V ABI function 462 | VA_START (Marker, Format); | ^ Functions that call VA_START()/VA_END() must be declared with EFIAPI. The function HelperManageabilityDebugPrint() should also be declared with EFIAPI to ensure compliance with Microsoft X64 calling convention for CLANG. Signed-off-by: Qihang Gao --- .../Include/Library/ManageabilityTransportHelperLib.h | 1 + .../BaseManageabilityTransportHelper.c | 1 + 2 files changed, 2 insertions(+) diff --git a/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h b/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h index 6c07452d1e..43852e1e14 100644 --- a/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h +++ b/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h @@ -180,6 +180,7 @@ HelperManageabilityPayLoadDebugPrint ( **/ VOID +EFIAPI HelperManageabilityDebugPrint ( IN VOID *Payload, IN UINT32 PayloadSize, diff --git a/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c b/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c index b097a8a912..e4d16fa18d 100644 --- a/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c +++ b/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c @@ -450,6 +450,7 @@ HelperManageabilityPayLoadDebugPrint ( **/ VOID +EFIAPI HelperManageabilityDebugPrint ( IN VOID *Payload, IN UINT32 PayloadSize, From 0abce029801c1b1a2d84ee7c47534e291405b99b Mon Sep 17 00:00:00 2001 From: Chris Fernald Date: Thu, 18 Jun 2026 12:19:07 -0700 Subject: [PATCH 025/406] ArmPkg: Only flush cache for memory that is mapped and intentional The previous commit to add cache flushing for memory being changed from a cacheable memory to non-cacheable memory did not check if the new memory type would be marked as a valid mapping. Because of this, if the cacheability is changed on memory that has `EFI_MEMORY_RP` set, the flush be VA would still be invoked which would cause a synchronous data abort. Additionally, this commit removes flushing the cache if no attribute was provided by the caller. It have been observed that in some cases, including the core itself, the caller does not provide a cacheability attribute and this code will default to a unused (so device) index. To avoid unexpected behavior, we must ignore this scenario since it is already in err and this shouldn't be made worse. Signed-off-by: Chris Fernald --- ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c b/ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c index 7f3b6fd68a..addcf76a83 100644 --- a/ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c +++ b/ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c @@ -285,10 +285,18 @@ CpuSetMemoryAttributes ( // stale cache lines are written back and invalidated. If this is not done, // depending on the caching behavior of the platform, dirty cache lines may // be written back corrupting data in the future, or stale cache lines may - // persist if caching is enabled later. + // persist if caching is enabled later. In scenarios where the caller didn't + // explicitly change the cacheability, ignore this. This could still lead to + // unexpected caches, but this is a necessary concession to incorrect behavior + // in higher-level components. // FlushCache = FALSE; - if (!EFI_ERROR (Status) && IsArmAttributeCacheable (RegionArmAttributes) && !IsArmAttributeCacheable (ArmAttributes)) { + if (!EFI_ERROR (Status) && + ((EfiAttributes & EFI_MEMORY_RP) == 0) && + ((EfiAttributes & EFI_MEMORY_CACHETYPE_MASK) != 0) && + IsArmAttributeCacheable (RegionArmAttributes) && + !IsArmAttributeCacheable (ArmAttributes)) + { FlushCache = TRUE; } From 70741a15d9a714323a5598eac47727e60507e22f Mon Sep 17 00:00:00 2001 From: Qihang Gao Date: Thu, 18 Jun 2026 11:00:24 +0800 Subject: [PATCH 026/406] ShellPkg: Fix the issue that the UEFI Shell layout is messed up Fixes https://github.com/tianocore/edk2/issues/12689 When the UEFI Shell mapping table is empty (NULL), the console layout becomes corrupted in DEBUG builds. This occurs because the cursor position for the message map: No mapping found. is computed incorrectly under DEBUG mode. The presence of DEBUG output from the Shell driver causes gST->ConOut->Mode->CursorRow to no longer reflect the actual cursor position on the serial port, leading to misplacement of subsequent output. This patch replaces the existing print routine with ShellPrintHiiDefaultEx(). The new function automatically calculates the correct cursor position for the "No mapping found" line, eliminating the dependency on the stale CursorRow value. As a result, the layout remains consistent regardless of DEBUG message activity. Signed-off-by: Qihang Gao --- ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c index dabbe15852..d2943c728f 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c @@ -698,9 +698,9 @@ PerformMappingDisplay ( if (!Found) { if (Specific != NULL) { - ShellPrintHiiEx (gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, L"map", Specific); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, L"map", Specific); } else { - ShellPrintHiiEx (gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle, L"map"); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle, L"map"); } } From 01b02a8c220dd8561f79533f5444b9e226574788 Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Tue, 16 Jun 2026 20:31:21 +0100 Subject: [PATCH 027/406] BaseTools: strip trailing whitespace in build_rule.template Since most editors just ignore it, only source files get syntax checked, and next to no one looks at their diffs before raising a PR, trailing whitespace keep piling up in particularly this file. Signed-off-by: Leif Lindholm --- BaseTools/Conf/build_rule.template | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template index 0c454ee3d5..a89866d700 100755 --- a/BaseTools/Conf/build_rule.template +++ b/BaseTools/Conf/build_rule.template @@ -290,7 +290,7 @@ $(RM) ${dst} "$(SLINK)" cr ${dst} $(SLINK_FLAGS) @$(OBJECT_FILES_LIST) - + "$(SLINK)" $(SLINK_FLAGS) ${dst} -filelist $(OBJECT_FILES_LIST) @@ -321,8 +321,8 @@ "$(DLINK)" $(DLINK_FLAGS) -o ${dst} $(DLINK_SPATH) -filelist $(STATIC_LIBRARY_FILES_LIST) $(DLINK2_FLAGS) - - + + [Static-Library-File.SEC, Static-Library-File.PEI_CORE, Static-Library-File.PEIM] *.lib @@ -387,8 +387,8 @@ "$(DLINK)" -o ${dst} $(DLINK_FLAGS) $(DLINK_SPATH) -filelist $(STATIC_LIBRARY_FILES_LIST) $(DLINK2_FLAGS) - - + + [Dynamic-Library-File] ?.dll @@ -403,7 +403,7 @@ $(CP) ${dst} $(DEBUG_DIR) $(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi -$(CP) $(DEBUG_DIR)(+)*.map $(OUTPUT_DIR) - -$(CP) $(DEBUG_DIR)(+)*.pdb $(OUTPUT_DIR) + -$(CP) $(DEBUG_DIR)(+)*.pdb $(OUTPUT_DIR) $(CP) ${src} $(DEBUG_DIR)(+)$(MODULE_NAME).debug @@ -420,7 +420,7 @@ $(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi -$(CP) $(DEBUG_DIR)(+)*.map $(OUTPUT_DIR) -$(CP) $(DEBUG_DIR)(+)*.pdb $(OUTPUT_DIR) - + # tool to convert Mach-O to PE/COFF "$(MTOC)" -subsystem $(MODULE_TYPE) $(MTOC_FLAGS) ${src} $(DEBUG_DIR)(+)$(MODULE_NAME).pecoff @@ -460,14 +460,14 @@ Trim --asl-file --asl-deps -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i -i $(INC_LIST) ${src} "$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) /I${s_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii - Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii + Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii "$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(CP) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.amli Trim --asl-file --asl-deps -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i -i $(INC_LIST) ${src} "$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) -I${s_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii - Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii + Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii "$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(CP) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.amli @@ -531,13 +531,13 @@ "$(ASLDLINK)" /OUT:$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll $(ASLDLINK_FLAGS) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj "$(GENFW)" -o ${dst} -c $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll $(GENFW_FLAGS) - + "$(ASLCC)" $(DEPS_FLAGS) -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj $(ASLCC_FLAGS) $(DEPS_FLAGS) $(INC) ${src} "$(ASLDLINK)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll $(ASLDLINK_FLAGS) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj "$(MTOC)" -subsystem $(MODULE_TYPE) $(MTOC_FLAGS) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.pecoff "$(GENFW)" -o ${dst} -c $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.pecoff $(GENFW_FLAGS) - - + + [Masm16-Code-File] ?.asm16, ?.Asm16, ?.ASM16, ?.s16, ?.S16 @@ -562,7 +562,7 @@ Trim --source-code -o ${d_path}(+)${s_base}.iii ${d_path}(+)${s_base}.ii "$(ASM)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj $(ASM_FLAGS) $(INC) ${d_path}(+)${s_base}.iii "$(DLINK)" -o ${dst} $(DLINK_FLAGS) --start-group $(DLINK_SPATH) $(LIBS) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj --end-group - + Trim --asm-file -o ${d_path}(+)${s_base}.i -i $(INC_LIST) ${src} "$(PP)" $(DEPS_FLAGS) $(PP_FLAGS) $(INC) ${src} > ${d_path}(+)${s_base}.ii @@ -570,7 +570,7 @@ "$(ASM)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj $(ASM_FLAGS) $(INC) ${d_path}(+)${s_base}.iii "$(SLINK)" $(SLINK_FLAGS) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.slib $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj otool -t $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.slib | hex2bin.py ${dst} - + [Nasm-to-Binary-Code-File] From 0225975462ae28b2c3ba0bc18cf13f639ab741d9 Mon Sep 17 00:00:00 2001 From: Dongyan Qian Date: Thu, 11 Jun 2026 19:58:56 +0800 Subject: [PATCH 028/406] BaseTools/GenFw: Fix LoongArch ELF-to-PE RVA conversion GenFw converts linked ELF images to PE/COFF images using a new section layout. The generated PE/COFF section RVAs are not required to match the linked ELF section addresses, so relocation fixups that rewrite section contents must use the generated PE/COFF RVA space. A linker script layout change can expose this on LoongArch64 when .text and .data are linked with 0x1000 alignment while .hii still keeps a 0x4000 alignment. GenFw then keeps a 0x4000 PE/COFF section alignment because of .hii, producing different ELF and PE/COFF layouts. Fix two LoongArch relocation paths exposed by this layout mismatch. R_LARCH_64 entries stored in section contents, such as switch jump tables, must be translated from the linked ELF section address space to the generated PE/COFF RVA space. R_LARCH_PCALA_* and R_LARCH_GOT_PC_* must also convert the referenced symbol to its generated PE/COFF RVA before calculating the PC-relative offset. The LoongArch ELF ABI defines PCALA/GOT_PC relocations as page-based, but this GenFw path rewrites the HI/LO pair to PCADDU12I plus ADDI.D. After that rewrite, the offset split must be based on the generated PE/COFF instruction-relative offset. For example, in the failing LogoDxe image, _gUefiDriverRevision is at ELF address 0x5400 in .text, and the relocation referencing it is at ELF address 0x104c. With ELF .text at 0x1000 and PE/COFF .text at 0x4000, the generated PE/COFF RVAs are 0x8400 for the symbol and 0x404c for the relocation site. Mixing the ELF symbol address with the PE/COFF relocation-site RVA makes the entry wrapper read PE/COFF RVA 0x5400 instead of 0x8400, causing EFI_INCOMPATIBLE_VERSION. Use PE/COFF RVAs consistently when rewriting LoongArch absolute and PC-relative references during WriteSections64(). The existing WriteRelocations64() base relocation emission is kept for load-time image rebasing. Reported-by: Chao Li Signed-off-by: Dongyan Qian Signed-off-by: Chao Li Tested-by: Dongyan Qian --- BaseTools/Source/C/GenFw/Elf64Convert.c | 48 ++++++++++++++++--------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c index 1ff8184c7e..f6398cb2b2 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -1739,16 +1739,24 @@ WriteSections64 ( INT32 LoImm, HiImm; UINT8 *PreTarg; Elf_Rela *PreRel; + INT64 SymCoffRva; + INT64 InsnCoffRva; + INT64 PairHiCoffRva; case R_LARCH_SOP_PUSH_ABSOLUTE: + case R_LARCH_64: // - // Absolute relocation. + // R_LARCH_SOP_PUSH_ABSOLUTE is an absolute relocation, and + // R_LARCH_64 stores an absolute runtime address in section + // contents. Translate such values from the linked ELF section + // address space to the generated PE/COFF RVA space. + // WriteRelocations64() still emits the PE/COFF base relocation + // for load-time image rebasing. // *(UINT64 *)Targ = *(UINT64 *)Targ - SymShdr->sh_addr + mCoffSectionsOffset[Sym->st_shndx]; break; case R_LARCH_MARK_LA: - case R_LARCH_64: case R_LARCH_NONE: case R_LARCH_32: case R_LARCH_RELATIVE: @@ -1851,29 +1859,32 @@ WriteSections64 ( case R_LARCH_PCALA_HI20: case R_LARCH_GOT_PC_HI20: Offset = 0; + SymCoffRva = (INT64)Sym->st_value - (INT64)SymShdr->sh_addr + (INT64)mCoffSectionsOffset[Sym->st_shndx]; + InsnCoffRva = (INT64)(UINTN)(Targ - mCoffFile); if (ELF_R_TYPE(Rel->r_info) == R_LARCH_PCALA_HI20) { // - // Recover the offset of the ELF PCALAU12I symbol relative to PC. + // Calculate the PE PC-relative offset. SymCoffRva is the + // referenced symbol in the generated PE/COFF RVA space, and + // InsnCoffRva is the PE/COFF RVA of this instruction. // - Offset = (INT32)((Sym->st_value + Rel->r_addend) - (Rel->r_offset & ~0xFFF)); - // - // Calculate the offset of PE PCADDU12I relative to PC. - // - Offset -= (UINTN)(Targ - mCoffFile) & 0xFFF; + Offset = (INT32)((SymCoffRva + Rel->r_addend) - InsnCoffRva); } else if (ELF_R_TYPE(Rel->r_info) == R_LARCH_GOT_PC_HI20) { // - // Calculate the offset of PE PCADDU12I relative to PC using the ELF symbol value. + // Convert the referenced symbol from the linked ELF section + // address space to the generated PE/COFF RVA space before + // calculating the PE PC-relative offset. Targ already points + // into the generated PE/COFF image buffer. // - Offset = Sym->st_value - (UINTN)(Targ - mCoffFile); + Offset = SymCoffRva - InsnCoffRva; } else { Error (NULL, 0, 3000, "Invalid", "LoongArch PC related: wrong relocation type."); break; } // - // PCALA or GOT offset is relative to the previous page boundary, whereas PCADD - // offset is relative to the instruction itself. - // So fix up the offset so it points to the page containing the symbol. + // The original PCALA/GOT_PC relocations are page based, but this + // path rewrites the HI/LO pair to PCADDU12I plus ADDI.D. Split + // the generated PE/COFF instruction-relative offset for that pair. // HiImm = (UINT32)((Offset + 0x800) >> 12) & 0xFFFFF; @@ -1912,11 +1923,12 @@ WriteSections64 ( } // - // Calculate the corresponding HI relative to PC using the ELF symbol value and fix the LO offset. + // Calculate the corresponding HI relative to PC using the PE symbol RVA and fix the LO offset. // if (ELF_R_TYPE(Rel->r_info) == R_LARCH_PCALA_LO12 && ELF_R_TYPE(PreRel->r_info) == R_LARCH_PCALA_HI20) { - Offset = (INT32)((Sym->st_value + PreRel->r_addend) - (PreRel->r_offset & ~0xFFF)); - Offset -= (UINTN)(PreTarg - mCoffFile) & 0xFFF; + SymCoffRva = (INT64)Sym->st_value - (INT64)SymShdr->sh_addr + (INT64)mCoffSectionsOffset[Sym->st_shndx]; + PairHiCoffRva = (INT64)(UINTN)(PreTarg - mCoffFile); + Offset = (INT32)((SymCoffRva + PreRel->r_addend) - PairHiCoffRva); LoImm = (UINT32)(Offset & 0xFFF); // // Only fill the LO offset in corresponding instructions. @@ -1924,7 +1936,9 @@ WriteSections64 ( *(UINT32 *)Targ &= 0xFFC003FF; *(UINT32 *)Targ |= LoImm << 10; } else if (ELF_R_TYPE(Rel->r_info) == R_LARCH_GOT_PC_LO12 && ELF_R_TYPE(PreRel->r_info) == R_LARCH_GOT_PC_HI20) { - Offset = Sym->st_value - (UINTN)(PreTarg - mCoffFile); + SymCoffRva = (INT64)Sym->st_value - (INT64)SymShdr->sh_addr + (INT64)mCoffSectionsOffset[Sym->st_shndx]; + PairHiCoffRva = (INT64)(UINTN)(PreTarg - mCoffFile); + Offset = SymCoffRva - PairHiCoffRva; LoImm = (UINT32)(Offset & 0xFFF); // // Convert this instruction as ADDI.D and fill the LO offset into it. From cb07945647fd31ac4c172489c97aab07e3a74f7c Mon Sep 17 00:00:00 2001 From: Thamballi Sreelalitha Date: Tue, 16 Jun 2026 10:39:36 +0530 Subject: [PATCH 029/406] CryptoPkg/OpensslLib: Update openssl submodule to openssl-3.5.7 release This update includes fixes for the following security vulnerabilities: - CVE-2026-45447 - CVE-2026-34180 - CVE-2026-34181 - CVE-2025-69419 Fixes: #12658 Signed-off-by: Thamballi Sreelalitha --- CryptoPkg/Library/OpensslLib/openssl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CryptoPkg/Library/OpensslLib/openssl b/CryptoPkg/Library/OpensslLib/openssl index aea7aaf2ab..8cf17aaeb4 160000 --- a/CryptoPkg/Library/OpensslLib/openssl +++ b/CryptoPkg/Library/OpensslLib/openssl @@ -1 +1 @@ -Subproject commit aea7aaf2abb04789f5868cbabec406ea43aa84bf +Subproject commit 8cf17aaeb4599f8af87fefd810b5b5fee90fe69e From 91a464a35230d7b831237bd8ade8c6618e52fcf5 Mon Sep 17 00:00:00 2001 From: Thamballi Sreelalitha Date: Tue, 16 Jun 2026 10:40:56 +0530 Subject: [PATCH 030/406] CryptoPkg/OpensslLib: Update generated files for openssl-3.5.7 Fixes: #12658 Signed-off-by: Thamballi Sreelalitha --- .../OpensslLib/OpensslGen/crypto/params_idx.c | 4 + .../OpensslGen/include/crypto/bn_conf.h | 12 +- .../OpensslGen/include/crypto/dso_conf.h | 10 +- .../OpensslGen/include/internal/param_names.h | 4 + .../OpensslGen/include/openssl/asn1.h | 649 ++-- .../OpensslGen/include/openssl/asn1t.h | 913 +++--- .../OpensslGen/include/openssl/bio.h | 1072 ++++--- .../OpensslGen/include/openssl/cmp.h | 454 +-- .../OpensslGen/include/openssl/cms.h | 350 +- .../OpensslGen/include/openssl/comp.h | 55 +- .../OpensslGen/include/openssl/conf.h | 109 +- .../include/openssl/configuration-ec-lite.h | 745 ++--- .../include/openssl/configuration-ec.h | 50 +- .../include/openssl/configuration-noec.h | 50 +- .../OpensslGen/include/openssl/core_names.h | 160 +- .../OpensslGen/include/openssl/crmf.h | 169 +- .../OpensslGen/include/openssl/crypto.h | 523 +-- .../OpensslGen/include/openssl/ct.h | 93 +- .../OpensslGen/include/openssl/err.h | 503 +-- .../OpensslGen/include/openssl/ess.h | 45 +- .../OpensslGen/include/openssl/fipskey.h | 18 +- .../OpensslGen/include/openssl/lhash.h | 559 ++-- .../OpensslGen/include/openssl/ocsp.h | 308 +- .../OpensslGen/include/openssl/opensslv.h | 67 +- .../OpensslGen/include/openssl/pkcs12.h | 330 +- .../OpensslGen/include/openssl/pkcs7.h | 225 +- .../OpensslGen/include/openssl/safestack.h | 308 +- .../OpensslGen/include/openssl/srp.h | 124 +- .../OpensslGen/include/openssl/ssl.h | 2843 +++++++++-------- .../OpensslGen/include/openssl/ui.h | 154 +- .../OpensslGen/include/openssl/x509.h | 690 ++-- .../OpensslGen/include/openssl/x509_acert.h | 100 +- .../OpensslGen/include/openssl/x509_vfy.h | 661 ++-- .../OpensslGen/include/openssl/x509v3.h | 761 ++--- .../providers/common/der/der_digests_gen.c | 2 + .../providers/common/der/der_ec_gen.c | 2 + .../providers/common/der/der_ecx_gen.c | 2 + .../providers/common/der/der_rsa_gen.c | 2 + .../providers/common/der/der_wrap_gen.c | 2 + .../common/include/prov/der_digests.h | 2 + .../providers/common/include/prov/der_ec.h | 4 +- .../providers/common/include/prov/der_ecx.h | 2 + .../providers/common/include/prov/der_rsa.h | 10 +- .../providers/common/include/prov/der_wrap.h | 2 + 44 files changed, 6701 insertions(+), 6447 deletions(-) diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/crypto/params_idx.c b/CryptoPkg/Library/OpensslLib/OpensslGen/crypto/params_idx.c index e77a242602..6292c35f7f 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/crypto/params_idx.c +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/crypto/params_idx.c @@ -9,13 +9,16 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #include "internal/e_os.h" #include "internal/param_names.h" #include /* Machine generated TRIE -- generated by util/perl/OpenSSL/paramnames.pm */ +/* clang-format off */ int ossl_param_find_pidx(const char *s) { switch(s[0]) { @@ -3363,4 +3366,5 @@ int ossl_param_find_pidx(const char *s) return -1; } +/* clang-format on */ /* End of TRIE */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/crypto/bn_conf.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/crypto/bn_conf.h index be8d576f08..fe7917353a 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/crypto/bn_conf.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/crypto/bn_conf.h @@ -1,5 +1,7 @@ +/* clang-format off */ /* WARNING: do not edit! */ /* Generated by Makefile from include/crypto/bn_conf.h.in */ +/* clang-format on */ /* * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved. * @@ -10,8 +12,8 @@ */ #ifndef OSSL_CRYPTO_BN_CONF_H -# define OSSL_CRYPTO_BN_CONF_H -# pragma once +#define OSSL_CRYPTO_BN_CONF_H +#pragma once /* * The contents of this file are not used in the UEFI build, as @@ -22,8 +24,14 @@ /* Should we define BN_DIV2W here? */ /* Only one for the following should be defined */ +/* clang-format off */ #undef SIXTY_FOUR_BIT_LONG + /* clang-format on */ + /* clang-format off */ #undef SIXTY_FOUR_BIT + /* clang-format on */ + /* clang-format off */ #define THIRTY_TWO_BIT +/* clang-format on */ #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/crypto/dso_conf.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/crypto/dso_conf.h index 2c88fbc5c2..3dbf5481fa 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/crypto/dso_conf.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/crypto/dso_conf.h @@ -1,5 +1,7 @@ +/* clang-format off */ /* WARNING: do not edit! */ /* Generated by Makefile from include/crypto/dso_conf.h.in */ +/* clang-format on */ /* * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved. * @@ -10,9 +12,13 @@ */ #ifndef OSSL_CRYPTO_DSO_CONF_H -# define OSSL_CRYPTO_DSO_CONF_H -# pragma once +#define OSSL_CRYPTO_DSO_CONF_H +#pragma once +/* clang-format off */ # define DSO_NONE +/* clang-format on */ +/* clang-format off */ # define DSO_EXTENSION ".so" +/* clang-format on */ #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/internal/param_names.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/internal/param_names.h index 10e995f20c..000863e31f 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/internal/param_names.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/internal/param_names.h @@ -9,11 +9,14 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ int ossl_param_find_pidx(const char *s); /* Parameter name definitions - generated by util/perl/OpenSSL/paramnames.pm */ +/* clang-format off */ #define NUM_PIDX 346 #define PIDX_ALG_PARAM_ALGORITHM_ID 0 @@ -467,3 +470,4 @@ int ossl_param_find_pidx(const char *s); #define PIDX_STORE_PARAM_PROPERTIES 7 #define PIDX_STORE_PARAM_SERIAL 344 #define PIDX_STORE_PARAM_SUBJECT 345 +/* clang-format on */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/asn1.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/asn1.h index d6c943ac69..8781ae9baa 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/asn1.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/asn1.h @@ -10,83 +10,85 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_ASN1_H -# define OPENSSL_ASN1_H -# pragma once +#define OPENSSL_ASN1_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_ASN1_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_ASN1_H +#endif -# ifndef OPENSSL_NO_STDIO -# include -# endif -# include -# include -# include -# include -# include -# include -# include +#ifndef OPENSSL_NO_STDIO +#include +#endif +#include +#include +#include +#include +#include +#include +#include -# include -# include +#include +#include -# ifdef OPENSSL_BUILD_SHLIBCRYPTO -# undef OPENSSL_EXTERN -# define OPENSSL_EXTERN OPENSSL_EXPORT -# endif +#ifdef OPENSSL_BUILD_SHLIBCRYPTO +#undef OPENSSL_EXTERN +#define OPENSSL_EXTERN OPENSSL_EXPORT +#endif -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif -# define V_ASN1_UNIVERSAL 0x00 -# define V_ASN1_APPLICATION 0x40 -# define V_ASN1_CONTEXT_SPECIFIC 0x80 -# define V_ASN1_PRIVATE 0xc0 +#define V_ASN1_UNIVERSAL 0x00 +#define V_ASN1_APPLICATION 0x40 +#define V_ASN1_CONTEXT_SPECIFIC 0x80 +#define V_ASN1_PRIVATE 0xc0 -# define V_ASN1_CONSTRUCTED 0x20 -# define V_ASN1_PRIMITIVE_TAG 0x1f -# define V_ASN1_PRIMATIVE_TAG /*compat*/ V_ASN1_PRIMITIVE_TAG +#define V_ASN1_CONSTRUCTED 0x20 +#define V_ASN1_PRIMITIVE_TAG 0x1f +#define V_ASN1_PRIMATIVE_TAG /*compat*/ V_ASN1_PRIMITIVE_TAG -# define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */ -# define V_ASN1_OTHER -3 /* used in ASN1_TYPE */ -# define V_ASN1_ANY -4 /* used in ASN1 template code */ +#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */ +#define V_ASN1_OTHER -3 /* used in ASN1_TYPE */ +#define V_ASN1_ANY -4 /* used in ASN1 template code */ -# define V_ASN1_UNDEF -1 +#define V_ASN1_UNDEF -1 /* ASN.1 tag values */ -# define V_ASN1_EOC 0 -# define V_ASN1_BOOLEAN 1 -# define V_ASN1_INTEGER 2 -# define V_ASN1_BIT_STRING 3 -# define V_ASN1_OCTET_STRING 4 -# define V_ASN1_NULL 5 -# define V_ASN1_OBJECT 6 -# define V_ASN1_OBJECT_DESCRIPTOR 7 -# define V_ASN1_EXTERNAL 8 -# define V_ASN1_REAL 9 -# define V_ASN1_ENUMERATED 10 -# define V_ASN1_UTF8STRING 12 -# define V_ASN1_SEQUENCE 16 -# define V_ASN1_SET 17 -# define V_ASN1_NUMERICSTRING 18 -# define V_ASN1_PRINTABLESTRING 19 -# define V_ASN1_T61STRING 20 -# define V_ASN1_TELETEXSTRING 20 /* alias */ -# define V_ASN1_VIDEOTEXSTRING 21 -# define V_ASN1_IA5STRING 22 -# define V_ASN1_UTCTIME 23 -# define V_ASN1_GENERALIZEDTIME 24 -# define V_ASN1_GRAPHICSTRING 25 -# define V_ASN1_ISO64STRING 26 -# define V_ASN1_VISIBLESTRING 26 /* alias */ -# define V_ASN1_GENERALSTRING 27 -# define V_ASN1_UNIVERSALSTRING 28 -# define V_ASN1_BMPSTRING 30 +#define V_ASN1_EOC 0 +#define V_ASN1_BOOLEAN 1 +#define V_ASN1_INTEGER 2 +#define V_ASN1_BIT_STRING 3 +#define V_ASN1_OCTET_STRING 4 +#define V_ASN1_NULL 5 +#define V_ASN1_OBJECT 6 +#define V_ASN1_OBJECT_DESCRIPTOR 7 +#define V_ASN1_EXTERNAL 8 +#define V_ASN1_REAL 9 +#define V_ASN1_ENUMERATED 10 +#define V_ASN1_UTF8STRING 12 +#define V_ASN1_SEQUENCE 16 +#define V_ASN1_SET 17 +#define V_ASN1_NUMERICSTRING 18 +#define V_ASN1_PRINTABLESTRING 19 +#define V_ASN1_T61STRING 20 +#define V_ASN1_TELETEXSTRING 20 /* alias */ +#define V_ASN1_VIDEOTEXSTRING 21 +#define V_ASN1_IA5STRING 22 +#define V_ASN1_UTCTIME 23 +#define V_ASN1_GENERALIZEDTIME 24 +#define V_ASN1_GRAPHICSTRING 25 +#define V_ASN1_ISO64STRING 26 +#define V_ASN1_VISIBLESTRING 26 /* alias */ +#define V_ASN1_GENERALSTRING 27 +#define V_ASN1_UNIVERSALSTRING 28 +#define V_ASN1_BMPSTRING 30 /* * NB the constants below are used internally by ASN1_INTEGER @@ -94,41 +96,42 @@ extern "C" { * the wire tag values. */ -# define V_ASN1_NEG 0x100 -# define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG) -# define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG) +#define V_ASN1_NEG 0x100 +#define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG) +#define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG) /* For use with d2i_ASN1_type_bytes() */ -# define B_ASN1_NUMERICSTRING 0x0001 -# define B_ASN1_PRINTABLESTRING 0x0002 -# define B_ASN1_T61STRING 0x0004 -# define B_ASN1_TELETEXSTRING 0x0004 -# define B_ASN1_VIDEOTEXSTRING 0x0008 -# define B_ASN1_IA5STRING 0x0010 -# define B_ASN1_GRAPHICSTRING 0x0020 -# define B_ASN1_ISO64STRING 0x0040 -# define B_ASN1_VISIBLESTRING 0x0040 -# define B_ASN1_GENERALSTRING 0x0080 -# define B_ASN1_UNIVERSALSTRING 0x0100 -# define B_ASN1_OCTET_STRING 0x0200 -# define B_ASN1_BIT_STRING 0x0400 -# define B_ASN1_BMPSTRING 0x0800 -# define B_ASN1_UNKNOWN 0x1000 -# define B_ASN1_UTF8STRING 0x2000 -# define B_ASN1_UTCTIME 0x4000 -# define B_ASN1_GENERALIZEDTIME 0x8000 -# define B_ASN1_SEQUENCE 0x10000 +#define B_ASN1_NUMERICSTRING 0x0001 +#define B_ASN1_PRINTABLESTRING 0x0002 +#define B_ASN1_T61STRING 0x0004 +#define B_ASN1_TELETEXSTRING 0x0004 +#define B_ASN1_VIDEOTEXSTRING 0x0008 +#define B_ASN1_IA5STRING 0x0010 +#define B_ASN1_GRAPHICSTRING 0x0020 +#define B_ASN1_ISO64STRING 0x0040 +#define B_ASN1_VISIBLESTRING 0x0040 +#define B_ASN1_GENERALSTRING 0x0080 +#define B_ASN1_UNIVERSALSTRING 0x0100 +#define B_ASN1_OCTET_STRING 0x0200 +#define B_ASN1_BIT_STRING 0x0400 +#define B_ASN1_BMPSTRING 0x0800 +#define B_ASN1_UNKNOWN 0x1000 +#define B_ASN1_UTF8STRING 0x2000 +#define B_ASN1_UTCTIME 0x4000 +#define B_ASN1_GENERALIZEDTIME 0x8000 +#define B_ASN1_SEQUENCE 0x10000 /* For use with ASN1_mbstring_copy() */ -# define MBSTRING_FLAG 0x1000 -# define MBSTRING_UTF8 (MBSTRING_FLAG) -# define MBSTRING_ASC (MBSTRING_FLAG|1) -# define MBSTRING_BMP (MBSTRING_FLAG|2) -# define MBSTRING_UNIV (MBSTRING_FLAG|4) -# define SMIME_OLDMIME 0x400 -# define SMIME_CRLFEOL 0x800 -# define SMIME_STREAM 0x1000 +#define MBSTRING_FLAG 0x1000 +#define MBSTRING_UTF8 (MBSTRING_FLAG) +#define MBSTRING_ASC (MBSTRING_FLAG | 1) +#define MBSTRING_BMP (MBSTRING_FLAG | 2) +#define MBSTRING_UNIV (MBSTRING_FLAG | 4) +#define SMIME_OLDMIME 0x400 +#define SMIME_CRLFEOL 0x800 +#define SMIME_STREAM 0x1000 /* Stacks for types not otherwise defined in this header */ +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509_ALGOR, X509_ALGOR, X509_ALGOR) #define sk_X509_ALGOR_num(sk) OPENSSL_sk_num(ossl_check_const_X509_ALGOR_sk_type(sk)) #define sk_X509_ALGOR_value(sk, idx) ((X509_ALGOR *)OPENSSL_sk_value(ossl_check_const_X509_ALGOR_sk_type(sk), (idx))) @@ -156,15 +159,15 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_ALGOR, X509_ALGOR, X509_ALGOR) #define sk_X509_ALGOR_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_copyfunc_type(copyfunc), ossl_check_X509_ALGOR_freefunc_type(freefunc))) #define sk_X509_ALGOR_set_cmp_func(sk, cmp) ((sk_X509_ALGOR_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_compfunc_type(cmp))) +/* clang-format on */ - -# define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */ +#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */ /* * This indicates that the ASN1_STRING is not a real value but just a place * holder for the location where indefinite length constructed data should be * inserted in the memory buffer */ -# define ASN1_STRING_FLAG_NDEF 0x010 +#define ASN1_STRING_FLAG_NDEF 0x010 /* * This flag is used by the CMS code to indicate that a string is not @@ -172,16 +175,16 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_ALGOR, X509_ALGOR, X509_ALGOR) * The flag will be reset when content has been written to it. */ -# define ASN1_STRING_FLAG_CONT 0x020 +#define ASN1_STRING_FLAG_CONT 0x020 /* * This flag is used by ASN1 code to indicate an ASN1_STRING is an MSTRING * type. */ -# define ASN1_STRING_FLAG_MSTRING 0x040 +#define ASN1_STRING_FLAG_MSTRING 0x040 /* String is embedded and only content should be freed */ -# define ASN1_STRING_FLAG_EMBED 0x080 +#define ASN1_STRING_FLAG_EMBED 0x080 /* String should be parsed in RFC 5280's time format */ -# define ASN1_STRING_FLAG_X509_TIME 0x100 +#define ASN1_STRING_FLAG_X509_TIME 0x100 /* This is the base type that holds just about everything :-) */ struct asn1_string_st { int length; @@ -202,26 +205,26 @@ struct asn1_string_st { */ typedef struct ASN1_ENCODING_st { - unsigned char *enc; /* DER encoding */ - long len; /* Length of encoding */ - int modified; /* set to 1 if 'enc' is invalid */ + unsigned char *enc; /* DER encoding */ + long len; /* Length of encoding */ + int modified; /* set to 1 if 'enc' is invalid */ } ASN1_ENCODING; /* Used with ASN1 LONG type: if a long is set to this it is omitted */ -# define ASN1_LONG_UNDEF 0x7fffffffL +#define ASN1_LONG_UNDEF 0x7fffffffL -# define STABLE_FLAGS_MALLOC 0x01 +#define STABLE_FLAGS_MALLOC 0x01 /* * A zero passed to ASN1_STRING_TABLE_new_add for the flags is interpreted * as "don't change" and STABLE_FLAGS_MALLOC is always set. By setting * STABLE_FLAGS_MALLOC only we can clear the existing value. Use the alias * STABLE_FLAGS_CLEAR to reflect this. */ -# define STABLE_FLAGS_CLEAR STABLE_FLAGS_MALLOC -# define STABLE_NO_MASK 0x02 -# define DIRSTRING_TYPE \ - (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING) -# define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING) +#define STABLE_FLAGS_CLEAR STABLE_FLAGS_MALLOC +#define STABLE_NO_MASK 0x02 +#define DIRSTRING_TYPE \ + (B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_BMPSTRING | B_ASN1_UTF8STRING) +#define PKCS9STRING_TYPE (DIRSTRING_TYPE | B_ASN1_IA5STRING) struct asn1_string_table_st { int nid; @@ -231,6 +234,7 @@ struct asn1_string_table_st { unsigned long flags; }; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_STRING_TABLE, ASN1_STRING_TABLE, ASN1_STRING_TABLE) #define sk_ASN1_STRING_TABLE_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk)) #define sk_ASN1_STRING_TABLE_value(sk, idx) ((ASN1_STRING_TABLE *)OPENSSL_sk_value(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk), (idx))) @@ -258,17 +262,18 @@ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_STRING_TABLE, ASN1_STRING_TABLE, ASN1_STRING_T #define sk_ASN1_STRING_TABLE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_copyfunc_type(copyfunc), ossl_check_ASN1_STRING_TABLE_freefunc_type(freefunc))) #define sk_ASN1_STRING_TABLE_set_cmp_func(sk, cmp) ((sk_ASN1_STRING_TABLE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_compfunc_type(cmp))) +/* clang-format on */ /* size limits: this stuff is taken straight from RFC2459 */ -# define ub_name 32768 -# define ub_common_name 64 -# define ub_locality_name 128 -# define ub_state_name 128 -# define ub_organization_name 64 -# define ub_organization_unit_name 64 -# define ub_title 64 -# define ub_email_address 128 +#define ub_name 32768 +#define ub_common_name 64 +#define ub_locality_name 128 +#define ub_state_name 128 +#define ub_organization_name 64 +#define ub_organization_unit_name 64 +#define ub_title 64 +#define ub_email_address 128 /* * Declarations for template structures: for full definitions see asn1t.h @@ -286,88 +291,90 @@ typedef struct ASN1_VALUE_st ASN1_VALUE; * arguments in macro calls. */ -# define DECLARE_ASN1_FUNCTIONS_attr(attr, type) \ +#define DECLARE_ASN1_FUNCTIONS_attr(attr, type) \ DECLARE_ASN1_FUNCTIONS_name_attr(attr, type, type) -# define DECLARE_ASN1_FUNCTIONS(type) \ +#define DECLARE_ASN1_FUNCTIONS(type) \ DECLARE_ASN1_FUNCTIONS_attr(extern, type) -# define DECLARE_ASN1_ALLOC_FUNCTIONS_attr(attr, type) \ +#define DECLARE_ASN1_ALLOC_FUNCTIONS_attr(attr, type) \ DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, type) -# define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \ +#define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \ DECLARE_ASN1_ALLOC_FUNCTIONS_attr(extern, type) -# define DECLARE_ASN1_FUNCTIONS_name_attr(attr, type, name) \ - DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, name) \ +#define DECLARE_ASN1_FUNCTIONS_name_attr(attr, type, name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, name) \ DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(attr, type, name) -# define DECLARE_ASN1_FUNCTIONS_name(type, name) \ +#define DECLARE_ASN1_FUNCTIONS_name(type, name) \ DECLARE_ASN1_FUNCTIONS_name_attr(extern, type, name) -# define DECLARE_ASN1_ENCODE_FUNCTIONS_attr(attr, type, itname, name) \ - DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(attr, type, name) \ +#define DECLARE_ASN1_ENCODE_FUNCTIONS_attr(attr, type, itname, name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(attr, type, name) \ DECLARE_ASN1_ITEM_attr(attr, itname) -# define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \ +#define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \ DECLARE_ASN1_ENCODE_FUNCTIONS_attr(extern, type, itname, name) -# define DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(attr, type, name) \ +#define DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(attr, type, name) \ DECLARE_ASN1_ENCODE_FUNCTIONS_attr(attr, type, name, name) -# define DECLARE_ASN1_ENCODE_FUNCTIONS_name(type, name) \ +#define DECLARE_ASN1_ENCODE_FUNCTIONS_name(type, name) \ DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(extern, type, name) -# define DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(attr, type, name) \ - attr type *d2i_##name(type **a, const unsigned char **in, long len); \ +#define DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(attr, type, name) \ + attr type *d2i_##name(type **a, const unsigned char **in, long len); \ attr int i2d_##name(const type *a, unsigned char **out); -# define DECLARE_ASN1_ENCODE_FUNCTIONS_only(type, name) \ +#define DECLARE_ASN1_ENCODE_FUNCTIONS_only(type, name) \ DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(extern, type, name) -# define DECLARE_ASN1_NDEF_FUNCTION_attr(attr, name) \ +#define DECLARE_ASN1_NDEF_FUNCTION_attr(attr, name) \ attr int i2d_##name##_NDEF(const name *a, unsigned char **out); -# define DECLARE_ASN1_NDEF_FUNCTION(name) \ +#define DECLARE_ASN1_NDEF_FUNCTION(name) \ DECLARE_ASN1_NDEF_FUNCTION_attr(extern, name) -# define DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, name) \ - attr type *name##_new(void); \ +#define DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, name) \ + attr type *name##_new(void); \ attr void name##_free(type *a); -# define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ +#define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(extern, type, name) -# define DECLARE_ASN1_DUP_FUNCTION_attr(attr, type) \ +#define DECLARE_ASN1_DUP_FUNCTION_attr(attr, type) \ DECLARE_ASN1_DUP_FUNCTION_name_attr(attr, type, type) -# define DECLARE_ASN1_DUP_FUNCTION(type) \ +#define DECLARE_ASN1_DUP_FUNCTION(type) \ DECLARE_ASN1_DUP_FUNCTION_attr(extern, type) -# define DECLARE_ASN1_DUP_FUNCTION_name_attr(attr, type, name) \ +#define DECLARE_ASN1_DUP_FUNCTION_name_attr(attr, type, name) \ attr type *name##_dup(const type *a); -# define DECLARE_ASN1_DUP_FUNCTION_name(type, name) \ +#define DECLARE_ASN1_DUP_FUNCTION_name(type, name) \ DECLARE_ASN1_DUP_FUNCTION_name_attr(extern, type, name) -# define DECLARE_ASN1_PRINT_FUNCTION_attr(attr, stname) \ +#define DECLARE_ASN1_PRINT_FUNCTION_attr(attr, stname) \ DECLARE_ASN1_PRINT_FUNCTION_fname_attr(attr, stname, stname) -# define DECLARE_ASN1_PRINT_FUNCTION(stname) \ +#define DECLARE_ASN1_PRINT_FUNCTION(stname) \ DECLARE_ASN1_PRINT_FUNCTION_attr(extern, stname) -# define DECLARE_ASN1_PRINT_FUNCTION_fname_attr(attr, stname, fname) \ - attr int fname##_print_ctx(BIO *out, const stname *x, int indent, \ - const ASN1_PCTX *pctx); -# define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \ +#define DECLARE_ASN1_PRINT_FUNCTION_fname_attr(attr, stname, fname) \ + attr int fname##_print_ctx(BIO *out, const stname *x, int indent, \ + const ASN1_PCTX *pctx); +#define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \ DECLARE_ASN1_PRINT_FUNCTION_fname_attr(extern, stname, fname) -# define D2I_OF(type) type *(*)(type **,const unsigned char **,long) -# define I2D_OF(type) int (*)(const type *,unsigned char **) +#define D2I_OF(type) type *(*)(type **, const unsigned char **, long) +#define I2D_OF(type) int (*)(const type *, unsigned char **) -# define CHECKED_D2I_OF(type, d2i) \ - ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0))) -# define CHECKED_I2D_OF(type, i2d) \ - ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0))) -# define CHECKED_NEW_OF(type, xnew) \ - ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0))) -# define CHECKED_PTR_OF(type, p) \ - ((void*) (1 ? p : (type*)0)) -# define CHECKED_PPTR_OF(type, p) \ - ((void**) (1 ? p : (type**)0)) +#define CHECKED_D2I_OF(type, d2i) \ + ((d2i_of_void *)(1 ? d2i : ((D2I_OF(type))0))) +#define CHECKED_I2D_OF(type, i2d) \ + ((i2d_of_void *)(1 ? i2d : ((I2D_OF(type))0))) +#define CHECKED_NEW_OF(type, xnew) \ + ((void *(*)(void))(1 ? xnew : ((type * (*)(void))0))) +#define CHECKED_PTR_OF(type, p) \ + ((void *)(1 ? p : (type *)0)) +#define CHECKED_PPTR_OF(type, p) \ + ((void **)(1 ? p : (type **)0)) -# define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long) -# define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(const type *,unsigned char **) -# define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type) +#define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **, const unsigned char **, long) +#define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(const type *, unsigned char **) +#define TYPEDEF_D2I2D_OF(type) \ + TYPEDEF_D2I_OF(type); \ + TYPEDEF_I2D_OF(type) typedef void *d2i_of_void(void **, const unsigned char **, long); typedef int i2d_of_void(const void *, unsigned char **); @@ -409,26 +416,25 @@ typedef int OSSL_i2d_of_void_ctx(const void *, unsigned char **, void *vctx); * */ - /* * Platforms that can't easily handle shared global variables are declared as * functions returning ASN1_ITEM pointers. */ /* ASN1_ITEM pointer exported type */ -typedef const ASN1_ITEM *ASN1_ITEM_EXP (void); +typedef const ASN1_ITEM *ASN1_ITEM_EXP(void); /* Macro to obtain ASN1_ITEM pointer from exported type */ -# define ASN1_ITEM_ptr(iptr) (iptr()) +#define ASN1_ITEM_ptr(iptr) (iptr()) /* Macro to include ASN1_ITEM pointer from base type */ -# define ASN1_ITEM_ref(iptr) (iptr##_it) +#define ASN1_ITEM_ref(iptr) (iptr##_it) -# define ASN1_ITEM_rptr(ref) (ref##_it()) +#define ASN1_ITEM_rptr(ref) (ref##_it()) -# define DECLARE_ASN1_ITEM_attr(attr, name) \ - attr const ASN1_ITEM * name##_it(void); -# define DECLARE_ASN1_ITEM(name) \ +#define DECLARE_ASN1_ITEM_attr(attr, name) \ + attr const ASN1_ITEM *name##_it(void); +#define DECLARE_ASN1_ITEM(name) \ DECLARE_ASN1_ITEM_attr(extern, name) /* Parameters used by ASN1_STRING_print_ex() */ @@ -438,30 +444,30 @@ typedef const ASN1_ITEM *ASN1_ITEM_EXP (void); * control characters and MSB set characters */ -# define ASN1_STRFLGS_ESC_2253 1 -# define ASN1_STRFLGS_ESC_CTRL 2 -# define ASN1_STRFLGS_ESC_MSB 4 +#define ASN1_STRFLGS_ESC_2253 1 +#define ASN1_STRFLGS_ESC_CTRL 2 +#define ASN1_STRFLGS_ESC_MSB 4 /* Lower 8 bits are reserved as an output type specifier */ -# define ASN1_DTFLGS_TYPE_MASK 0x0FUL -# define ASN1_DTFLGS_RFC822 0x00UL -# define ASN1_DTFLGS_ISO8601 0x01UL +#define ASN1_DTFLGS_TYPE_MASK 0x0FUL +#define ASN1_DTFLGS_RFC822 0x00UL +#define ASN1_DTFLGS_ISO8601 0x01UL /* * This flag determines how we do escaping: normally RC2253 backslash only, * set this to use backslash and quote. */ -# define ASN1_STRFLGS_ESC_QUOTE 8 +#define ASN1_STRFLGS_ESC_QUOTE 8 /* These three flags are internal use only. */ /* Character is a valid PrintableString character */ -# define CHARTYPE_PRINTABLESTRING 0x10 +#define CHARTYPE_PRINTABLESTRING 0x10 /* Character needs escaping if it is the first character */ -# define CHARTYPE_FIRST_ESC_2253 0x20 +#define CHARTYPE_FIRST_ESC_2253 0x20 /* Character needs escaping if it is the last character */ -# define CHARTYPE_LAST_ESC_2253 0x40 +#define CHARTYPE_LAST_ESC_2253 0x40 /* * NB the internal flags are safely reused below by flags handled at the top @@ -472,7 +478,7 @@ typedef const ASN1_ITEM *ASN1_ITEM_EXP (void); * If this is set we convert all character strings to UTF8 first */ -# define ASN1_STRFLGS_UTF8_CONVERT 0x10 +#define ASN1_STRFLGS_UTF8_CONVERT 0x10 /* * If this is set we don't attempt to interpret content: just assume all @@ -480,10 +486,10 @@ typedef const ASN1_ITEM *ASN1_ITEM_EXP (void); * looking output! */ -# define ASN1_STRFLGS_IGNORE_TYPE 0x20 +#define ASN1_STRFLGS_IGNORE_TYPE 0x20 /* If this is set we include the string type in the output */ -# define ASN1_STRFLGS_SHOW_TYPE 0x40 +#define ASN1_STRFLGS_SHOW_TYPE 0x40 /* * This determines which strings to display and which to 'dump' (hex dump of @@ -493,33 +499,27 @@ typedef const ASN1_ITEM *ASN1_ITEM_EXP (void); * options. */ -# define ASN1_STRFLGS_DUMP_ALL 0x80 -# define ASN1_STRFLGS_DUMP_UNKNOWN 0x100 +#define ASN1_STRFLGS_DUMP_ALL 0x80 +#define ASN1_STRFLGS_DUMP_UNKNOWN 0x100 /* * These determine what 'dumping' does, we can dump the content octets or the * DER encoding: both use the RFC2253 #XXXXX notation. */ -# define ASN1_STRFLGS_DUMP_DER 0x200 +#define ASN1_STRFLGS_DUMP_DER 0x200 /* * This flag specifies that RC2254 escaping shall be performed. */ -#define ASN1_STRFLGS_ESC_2254 0x400 +#define ASN1_STRFLGS_ESC_2254 0x400 /* * All the string flags consistent with RFC2253, escaping control characters * isn't essential in RFC2253 but it is advisable anyway. */ -# define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \ - ASN1_STRFLGS_ESC_CTRL | \ - ASN1_STRFLGS_ESC_MSB | \ - ASN1_STRFLGS_UTF8_CONVERT | \ - ASN1_STRFLGS_DUMP_UNKNOWN | \ - ASN1_STRFLGS_DUMP_DER) - +#define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB | ASN1_STRFLGS_UTF8_CONVERT | ASN1_STRFLGS_DUMP_UNKNOWN | ASN1_STRFLGS_DUMP_DER) struct asn1_type_st { int type; @@ -552,6 +552,7 @@ struct asn1_type_st { } value; }; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_TYPE, ASN1_TYPE, ASN1_TYPE) #define sk_ASN1_TYPE_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_TYPE_sk_type(sk)) #define sk_ASN1_TYPE_value(sk, idx) ((ASN1_TYPE *)OPENSSL_sk_value(ossl_check_const_ASN1_TYPE_sk_type(sk), (idx))) @@ -579,6 +580,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_TYPE, ASN1_TYPE, ASN1_TYPE) #define sk_ASN1_TYPE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_copyfunc_type(copyfunc), ossl_check_ASN1_TYPE_freefunc_type(freefunc))) #define sk_ASN1_TYPE_set_cmp_func(sk, cmp) ((sk_ASN1_TYPE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY; @@ -592,34 +594,17 @@ typedef struct BIT_STRING_BITNAME_st { const char *sname; } BIT_STRING_BITNAME; -# define B_ASN1_TIME \ - B_ASN1_UTCTIME | \ - B_ASN1_GENERALIZEDTIME +#define B_ASN1_TIME \ + B_ASN1_UTCTIME | B_ASN1_GENERALIZEDTIME -# define B_ASN1_PRINTABLE \ - B_ASN1_NUMERICSTRING| \ - B_ASN1_PRINTABLESTRING| \ - B_ASN1_T61STRING| \ - B_ASN1_IA5STRING| \ - B_ASN1_BIT_STRING| \ - B_ASN1_UNIVERSALSTRING|\ - B_ASN1_BMPSTRING|\ - B_ASN1_UTF8STRING|\ - B_ASN1_SEQUENCE|\ - B_ASN1_UNKNOWN +#define B_ASN1_PRINTABLE \ + B_ASN1_NUMERICSTRING | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_IA5STRING | B_ASN1_BIT_STRING | B_ASN1_UNIVERSALSTRING | B_ASN1_BMPSTRING | B_ASN1_UTF8STRING | B_ASN1_SEQUENCE | B_ASN1_UNKNOWN -# define B_ASN1_DIRECTORYSTRING \ - B_ASN1_PRINTABLESTRING| \ - B_ASN1_TELETEXSTRING|\ - B_ASN1_BMPSTRING|\ - B_ASN1_UNIVERSALSTRING|\ - B_ASN1_UTF8STRING +#define B_ASN1_DIRECTORYSTRING \ + B_ASN1_PRINTABLESTRING | B_ASN1_TELETEXSTRING | B_ASN1_BMPSTRING | B_ASN1_UNIVERSALSTRING | B_ASN1_UTF8STRING -# define B_ASN1_DISPLAYTEXT \ - B_ASN1_IA5STRING| \ - B_ASN1_VISIBLESTRING| \ - B_ASN1_BMPSTRING|\ - B_ASN1_UTF8STRING +#define B_ASN1_DISPLAYTEXT \ + B_ASN1_IA5STRING | B_ASN1_VISIBLESTRING | B_ASN1_BMPSTRING | B_ASN1_UTF8STRING DECLARE_ASN1_ALLOC_FUNCTIONS_name(ASN1_TYPE, ASN1_TYPE) DECLARE_ASN1_ENCODE_FUNCTIONS(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) @@ -632,6 +617,7 @@ int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b); ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t); void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t); +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_OBJECT, ASN1_OBJECT, ASN1_OBJECT) #define sk_ASN1_OBJECT_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_OBJECT_sk_type(sk)) #define sk_ASN1_OBJECT_value(sk, idx) ((ASN1_OBJECT *)OPENSSL_sk_value(ossl_check_const_ASN1_OBJECT_sk_type(sk), (idx))) @@ -659,6 +645,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_OBJECT, ASN1_OBJECT, ASN1_OBJECT) #define sk_ASN1_OBJECT_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_copyfunc_type(copyfunc), ossl_check_ASN1_OBJECT_freefunc_type(freefunc))) #define sk_ASN1_OBJECT_set_cmp_func(sk, cmp) ((sk_ASN1_OBJECT_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_compfunc_type(cmp))) +/* clang-format on */ DECLARE_ASN1_FUNCTIONS(ASN1_OBJECT) @@ -669,20 +656,20 @@ int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str); DECLARE_ASN1_DUP_FUNCTION(ASN1_STRING) ASN1_STRING *ASN1_STRING_type_new(int type); int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b); - /* - * Since this is used to store all sorts of things, via macros, for now, - * make its data void * - */ +/* + * Since this is used to store all sorts of things, via macros, for now, + * make its data void * + */ int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len); int ASN1_STRING_length(const ASN1_STRING *x); -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 void ASN1_STRING_length_set(ASN1_STRING *x, int n); -# endif +#endif int ASN1_STRING_type(const ASN1_STRING *x); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 unsigned char *ASN1_STRING_data(ASN1_STRING *x); -# endif +#endif const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x); DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING) @@ -690,14 +677,15 @@ int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, int length); int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value); int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n); int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, - const unsigned char *flags, int flags_len); + const unsigned char *flags, int flags_len); int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, - BIT_STRING_BITNAME *tbl, int indent); + BIT_STRING_BITNAME *tbl, int indent); int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl); int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value, - BIT_STRING_BITNAME *tbl); + BIT_STRING_BITNAME *tbl); +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_INTEGER, ASN1_INTEGER, ASN1_INTEGER) #define sk_ASN1_INTEGER_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_INTEGER_sk_type(sk)) #define sk_ASN1_INTEGER_value(sk, idx) ((ASN1_INTEGER *)OPENSSL_sk_value(ossl_check_const_ASN1_INTEGER_sk_type(sk), (idx))) @@ -725,11 +713,11 @@ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_INTEGER, ASN1_INTEGER, ASN1_INTEGER) #define sk_ASN1_INTEGER_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_copyfunc_type(copyfunc), ossl_check_ASN1_INTEGER_freefunc_type(freefunc))) #define sk_ASN1_INTEGER_set_cmp_func(sk, cmp) ((sk_ASN1_INTEGER_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_compfunc_type(cmp))) - +/* clang-format on */ DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER) ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, - long length); + long length); DECLARE_ASN1_DUP_FUNCTION(ASN1_INTEGER) int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y); @@ -738,28 +726,29 @@ DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED) int ASN1_UTCTIME_check(const ASN1_UTCTIME *a); ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t); ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, - int offset_day, long offset_sec); + int offset_day, long offset_sec); int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str); int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t); int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a); ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, - time_t t); + time_t t); ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, - time_t t, int offset_day, - long offset_sec); + time_t t, int offset_day, + long offset_sec); int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str); int ASN1_TIME_diff(int *pday, int *psec, - const ASN1_TIME *from, const ASN1_TIME *to); + const ASN1_TIME *from, const ASN1_TIME *to); DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING) DECLARE_ASN1_DUP_FUNCTION(ASN1_OCTET_STRING) int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, - const ASN1_OCTET_STRING *b); + const ASN1_OCTET_STRING *b); int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, - int len); + int len); +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_UTF8STRING, ASN1_UTF8STRING, ASN1_UTF8STRING) #define sk_ASN1_UTF8STRING_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_UTF8STRING_sk_type(sk)) #define sk_ASN1_UTF8STRING_value(sk, idx) ((ASN1_UTF8STRING *)OPENSSL_sk_value(ossl_check_const_ASN1_UTF8STRING_sk_type(sk), (idx))) @@ -787,6 +776,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_UTF8STRING, ASN1_UTF8STRING, ASN1_UTF8STRING) #define sk_ASN1_UTF8STRING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_copyfunc_type(copyfunc), ossl_check_ASN1_UTF8STRING_freefunc_type(freefunc))) #define sk_ASN1_UTF8STRING_set_cmp_func(sk, cmp) ((sk_ASN1_UTF8STRING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_compfunc_type(cmp))) +/* clang-format on */ DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) @@ -797,6 +787,7 @@ DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) int UTF8_getc(const unsigned char *str, int len, unsigned long *val); int UTF8_putc(unsigned char *str, int len, unsigned long value); +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_GENERALSTRING, ASN1_GENERALSTRING, ASN1_GENERALSTRING) #define sk_ASN1_GENERALSTRING_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk)) #define sk_ASN1_GENERALSTRING_value(sk, idx) ((ASN1_GENERALSTRING *)OPENSSL_sk_value(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk), (idx))) @@ -824,6 +815,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_GENERALSTRING, ASN1_GENERALSTRING, ASN1_GENERA #define sk_ASN1_GENERALSTRING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_copyfunc_type(copyfunc), ossl_check_ASN1_GENERALSTRING_freefunc_type(freefunc))) #define sk_ASN1_GENERALSTRING_set_cmp_func(sk, cmp) ((sk_ASN1_GENERALSTRING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_compfunc_type(cmp))) +/* clang-format on */ DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) @@ -845,10 +837,10 @@ DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF) ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t); ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, - int offset_day, long offset_sec); + int offset_day, long offset_sec); int ASN1_TIME_check(const ASN1_TIME *t); ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t, - ASN1_GENERALIZEDTIME **out); + ASN1_GENERALIZEDTIME **out); int ASN1_TIME_set_string(ASN1_TIME *s, const char *str); int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str); int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm); @@ -867,7 +859,7 @@ int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a); int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num); ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, - const char *sn, const char *ln); + const char *sn, const char *ln); int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a); int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r); @@ -882,7 +874,6 @@ BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn); int ASN1_ENUMERATED_get_int64(int64_t *pr, const ASN1_ENUMERATED *a); int ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t r); - int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a); ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai); @@ -896,81 +887,81 @@ unsigned long ASN1_tag2bit(int tag); /* SPECIALS */ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, - int *pclass, long omax); + int *pclass, long omax); int ASN1_check_infinite_end(unsigned char **p, long len); int ASN1_const_check_infinite_end(const unsigned char **p, long len); void ASN1_put_object(unsigned char **pp, int constructed, int length, - int tag, int xclass); + int tag, int xclass); int ASN1_put_eoc(unsigned char **pp); int ASN1_object_size(int constructed, int length, int tag); /* Used to implement other functions */ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, const void *x); -# define ASN1_dup_of(type,i2d,d2i,x) \ - ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \ - CHECKED_D2I_OF(type, d2i), \ - CHECKED_PTR_OF(const type, x))) +#define ASN1_dup_of(type, i2d, d2i, x) \ + ((type *)ASN1_dup(CHECKED_I2D_OF(type, i2d), \ + CHECKED_D2I_OF(type, d2i), \ + CHECKED_PTR_OF(const type, x))) void *ASN1_item_dup(const ASN1_ITEM *it, const void *x); int ASN1_item_sign_ex(const ASN1_ITEM *it, X509_ALGOR *algor1, - X509_ALGOR *algor2, ASN1_BIT_STRING *signature, - const void *data, const ASN1_OCTET_STRING *id, - EVP_PKEY *pkey, const EVP_MD *md, OSSL_LIB_CTX *libctx, - const char *propq); + X509_ALGOR *algor2, ASN1_BIT_STRING *signature, + const void *data, const ASN1_OCTET_STRING *id, + EVP_PKEY *pkey, const EVP_MD *md, OSSL_LIB_CTX *libctx, + const char *propq); int ASN1_item_verify_ex(const ASN1_ITEM *it, const X509_ALGOR *alg, - const ASN1_BIT_STRING *signature, const void *data, - const ASN1_OCTET_STRING *id, EVP_PKEY *pkey, - OSSL_LIB_CTX *libctx, const char *propq); + const ASN1_BIT_STRING *signature, const void *data, + const ASN1_OCTET_STRING *id, EVP_PKEY *pkey, + OSSL_LIB_CTX *libctx, const char *propq); /* ASN1 alloc/free macros for when a type is only used internally */ -# define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type)) -# define M_ASN1_free_of(x, type) \ - ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type)) +#define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type)) +#define M_ASN1_free_of(x, type) \ + ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type)) -# ifndef OPENSSL_NO_STDIO -void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x); +#ifndef OPENSSL_NO_STDIO +void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x); -# define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \ - ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \ - CHECKED_D2I_OF(type, d2i), \ - in, \ - CHECKED_PPTR_OF(type, x))) +#define ASN1_d2i_fp_of(type, xnew, d2i, in, x) \ + ((type *)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \ + CHECKED_D2I_OF(type, d2i), \ + in, \ + CHECKED_PPTR_OF(type, x))) void *ASN1_item_d2i_fp_ex(const ASN1_ITEM *it, FILE *in, void *x, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x); int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, const void *x); -# define ASN1_i2d_fp_of(type,i2d,out,x) \ +#define ASN1_i2d_fp_of(type, i2d, out, x) \ (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \ - out, \ - CHECKED_PTR_OF(const type, x))) + out, \ + CHECKED_PTR_OF(const type, x))) int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, const void *x); int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags); -# endif +#endif int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in); -void *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x); +void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x); -# define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \ - ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \ - CHECKED_D2I_OF(type, d2i), \ - in, \ - CHECKED_PPTR_OF(type, x))) +#define ASN1_d2i_bio_of(type, xnew, d2i, in, x) \ + ((type *)ASN1_d2i_bio(CHECKED_NEW_OF(type, xnew), \ + CHECKED_D2I_OF(type, d2i), \ + in, \ + CHECKED_PPTR_OF(type, x))) void *ASN1_item_d2i_bio_ex(const ASN1_ITEM *it, BIO *in, void *pval, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *pval); int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, const void *x); -# define ASN1_i2d_bio_of(type,i2d,out,x) \ +#define ASN1_i2d_bio_of(type, i2d, out, x) \ (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \ - out, \ - CHECKED_PTR_OF(const type, x))) + out, \ + CHECKED_PTR_OF(const type, x))) int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, const void *x); BIO *ASN1_item_i2d_mem_bio(const ASN1_ITEM *it, const ASN1_VALUE *val); @@ -982,10 +973,10 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v); int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags); int ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int off); int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, - unsigned char *buf, int off); + unsigned char *buf, int off); int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent); int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, - int dump); + int dump); const char *ASN1_tag2str(int tag); /* Used to load and write Netscape format cert */ @@ -995,29 +986,29 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s); int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len); int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len); int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, - unsigned char *data, int len); + unsigned char *data, int len); int ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *a, long *num, - unsigned char *data, int max_len); + unsigned char *data, int max_len); void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it); void *ASN1_item_unpack_ex(const ASN1_STRING *oct, const ASN1_ITEM *it, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, - ASN1_OCTET_STRING **oct); + ASN1_OCTET_STRING **oct); void ASN1_STRING_set_default_mask(unsigned long mask); int ASN1_STRING_set_default_mask_asc(const char *p); unsigned long ASN1_STRING_get_default_mask(void); int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, - int inform, unsigned long mask); + int inform, unsigned long mask); int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, - int inform, unsigned long mask, - long minsize, long maxsize); + int inform, unsigned long mask, + long minsize, long maxsize); ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, - const unsigned char *in, int inlen, - int inform, int nid); + const unsigned char *in, int inlen, + int inform, int nid); ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid); int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long); void ASN1_STRING_TABLE_cleanup(void); @@ -1027,16 +1018,16 @@ void ASN1_STRING_TABLE_cleanup(void); /* Old API compatible functions */ ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it); ASN1_VALUE *ASN1_item_new_ex(const ASN1_ITEM *it, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it); ASN1_VALUE *ASN1_item_d2i_ex(ASN1_VALUE **val, const unsigned char **in, - long len, const ASN1_ITEM *it, - OSSL_LIB_CTX *libctx, const char *propq); + long len, const ASN1_ITEM *it, + OSSL_LIB_CTX *libctx, const char *propq); ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in, - long len, const ASN1_ITEM *it); + long len, const ASN1_ITEM *it); int ASN1_item_i2d(const ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); int ASN1_item_ndef_i2d(const ASN1_VALUE *val, unsigned char **out, - const ASN1_ITEM *it); + const ASN1_ITEM *it); void ASN1_add_oid_module(void); void ASN1_add_stable_module(void); @@ -1048,26 +1039,26 @@ int ASN1_str2mask(const char *str, unsigned long *pmask); /* ASN1 Print flags */ /* Indicate missing OPTIONAL fields */ -# define ASN1_PCTX_FLAGS_SHOW_ABSENT 0x001 +#define ASN1_PCTX_FLAGS_SHOW_ABSENT 0x001 /* Mark start and end of SEQUENCE */ -# define ASN1_PCTX_FLAGS_SHOW_SEQUENCE 0x002 +#define ASN1_PCTX_FLAGS_SHOW_SEQUENCE 0x002 /* Mark start and end of SEQUENCE/SET OF */ -# define ASN1_PCTX_FLAGS_SHOW_SSOF 0x004 +#define ASN1_PCTX_FLAGS_SHOW_SSOF 0x004 /* Show the ASN1 type of primitives */ -# define ASN1_PCTX_FLAGS_SHOW_TYPE 0x008 +#define ASN1_PCTX_FLAGS_SHOW_TYPE 0x008 /* Don't show ASN1 type of ANY */ -# define ASN1_PCTX_FLAGS_NO_ANY_TYPE 0x010 +#define ASN1_PCTX_FLAGS_NO_ANY_TYPE 0x010 /* Don't show ASN1 type of MSTRINGs */ -# define ASN1_PCTX_FLAGS_NO_MSTRING_TYPE 0x020 +#define ASN1_PCTX_FLAGS_NO_MSTRING_TYPE 0x020 /* Don't show field names in SEQUENCE */ -# define ASN1_PCTX_FLAGS_NO_FIELD_NAME 0x040 +#define ASN1_PCTX_FLAGS_NO_FIELD_NAME 0x040 /* Show structure names of each SEQUENCE field */ -# define ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME 0x080 +#define ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME 0x080 /* Don't show structure name even at top level */ -# define ASN1_PCTX_FLAGS_NO_STRUCT_NAME 0x100 +#define ASN1_PCTX_FLAGS_NO_STRUCT_NAME 0x100 int ASN1_item_print(BIO *out, const ASN1_VALUE *ifld, int indent, - const ASN1_ITEM *it, const ASN1_PCTX *pctx); + const ASN1_ITEM *it, const ASN1_PCTX *pctx); ASN1_PCTX *ASN1_PCTX_new(void); void ASN1_PCTX_free(ASN1_PCTX *p); unsigned long ASN1_PCTX_get_flags(const ASN1_PCTX *p); @@ -1081,7 +1072,7 @@ void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags); unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p); void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags); -ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx)); +ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb)(ASN1_SCTX *ctx)); void ASN1_SCTX_free(ASN1_SCTX *p); const ASN1_ITEM *ASN1_SCTX_get_item(ASN1_SCTX *p); const ASN1_TEMPLATE *ASN1_SCTX_get_template(ASN1_SCTX *p); @@ -1095,21 +1086,21 @@ const BIO_METHOD *BIO_f_asn1(void); BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it); int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, - const ASN1_ITEM *it); + const ASN1_ITEM *it); int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, - const char *hdr, const ASN1_ITEM *it); + const char *hdr, const ASN1_ITEM *it); /* cannot constify val because of CMS_dataFinal() */ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, - int ctype_nid, int econt_nid, - STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it); + int ctype_nid, int econt_nid, + STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it); int SMIME_write_ASN1_ex(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, - int ctype_nid, int econt_nid, - STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it, - OSSL_LIB_CTX *libctx, const char *propq); + int ctype_nid, int econt_nid, + STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it, + OSSL_LIB_CTX *libctx, const char *propq); ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it); ASN1_VALUE *SMIME_read_ASN1_ex(BIO *bio, int flags, BIO **bcont, - const ASN1_ITEM *it, ASN1_VALUE **x, - OSSL_LIB_CTX *libctx, const char *propq); + const ASN1_ITEM *it, ASN1_VALUE **x, + OSSL_LIB_CTX *libctx, const char *propq); int SMIME_crlf_copy(BIO *in, BIO *out, int flags); int SMIME_text(BIO *in, BIO *out); @@ -1117,18 +1108,18 @@ const ASN1_ITEM *ASN1_ITEM_lookup(const char *name); const ASN1_ITEM *ASN1_ITEM_get(size_t i); /* Legacy compatibility */ -# define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \ - DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ - DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) -# define DECLARE_ASN1_FUNCTIONS_const(type) DECLARE_ASN1_FUNCTIONS(type) -# define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \ - DECLARE_ASN1_ENCODE_FUNCTIONS(type, name) -# define I2D_OF_const(type) I2D_OF(type) -# define ASN1_dup_of_const(type,i2d,d2i,x) ASN1_dup_of(type,i2d,d2i,x) -# define ASN1_i2d_fp_of_const(type,i2d,out,x) ASN1_i2d_fp_of(type,i2d,out,x) -# define ASN1_i2d_bio_of_const(type,i2d,out,x) ASN1_i2d_bio_of(type,i2d,out,x) +#define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) +#define DECLARE_ASN1_FUNCTIONS_const(type) DECLARE_ASN1_FUNCTIONS(type) +#define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS(type, name) +#define I2D_OF_const(type) I2D_OF(type) +#define ASN1_dup_of_const(type, i2d, d2i, x) ASN1_dup_of(type, i2d, d2i, x) +#define ASN1_i2d_fp_of_const(type, i2d, out, x) ASN1_i2d_fp_of(type, i2d, out, x) +#define ASN1_i2d_bio_of_const(type, i2d, out, x) ASN1_i2d_bio_of(type, i2d, out, x) -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/asn1t.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/asn1t.h index a9a5ea7a78..b46e4519f9 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/asn1t.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/asn1t.h @@ -10,29 +10,31 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_ASN1T_H -# define OPENSSL_ASN1T_H -# pragma once +#define OPENSSL_ASN1T_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_ASN1T_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_ASN1T_H +#endif -# include -# include -# include +#include +#include +#include -# ifdef OPENSSL_BUILD_SHLIBCRYPTO -# undef OPENSSL_EXTERN -# define OPENSSL_EXTERN OPENSSL_EXPORT -# endif +#ifdef OPENSSL_BUILD_SHLIBCRYPTO +#undef OPENSSL_EXTERN +#define OPENSSL_EXTERN OPENSSL_EXPORT +#endif /* ASN1 template defines, structures and functions */ -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -77,59 +79,58 @@ extern "C" { * */ -# define ASN1_ITYPE_PRIMITIVE 0x0 -# define ASN1_ITYPE_SEQUENCE 0x1 -# define ASN1_ITYPE_CHOICE 0x2 +#define ASN1_ITYPE_PRIMITIVE 0x0 +#define ASN1_ITYPE_SEQUENCE 0x1 +#define ASN1_ITYPE_CHOICE 0x2 /* unused value 0x3 */ -# define ASN1_ITYPE_EXTERN 0x4 -# define ASN1_ITYPE_MSTRING 0x5 -# define ASN1_ITYPE_NDEF_SEQUENCE 0x6 +#define ASN1_ITYPE_EXTERN 0x4 +#define ASN1_ITYPE_MSTRING 0x5 +#define ASN1_ITYPE_NDEF_SEQUENCE 0x6 /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ -# define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)((iptr)())) +#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)((iptr)())) /* Macros for start and end of ASN1_ITEM definition */ -# define ASN1_ITEM_start(itname) \ - const ASN1_ITEM * itname##_it(void) \ - { \ - static const ASN1_ITEM local_it = { +#define ASN1_ITEM_start(itname) \ + const ASN1_ITEM *itname##_it(void) \ + { \ + static const ASN1_ITEM local_it = { -# define static_ASN1_ITEM_start(itname) \ - static ASN1_ITEM_start(itname) +#define static_ASN1_ITEM_start(itname) \ + static ASN1_ITEM_start(itname) -# define ASN1_ITEM_end(itname) \ - }; \ - return &local_it; \ - } +#define ASN1_ITEM_end(itname) \ + } \ + ; \ + return &local_it; \ + } /* Macros to aid ASN1 template writing */ -# define ASN1_ITEM_TEMPLATE(tname) \ - static const ASN1_TEMPLATE tname##_item_tt +#define ASN1_ITEM_TEMPLATE(tname) \ + static const ASN1_TEMPLATE tname##_item_tt -# define ASN1_ITEM_TEMPLATE_END(tname) \ - ;\ - ASN1_ITEM_start(tname) \ - ASN1_ITYPE_PRIMITIVE,\ - -1,\ - &tname##_item_tt,\ - 0,\ - NULL,\ - 0,\ - #tname \ - ASN1_ITEM_end(tname) -# define static_ASN1_ITEM_TEMPLATE_END(tname) \ - ;\ - static_ASN1_ITEM_start(tname) \ - ASN1_ITYPE_PRIMITIVE,\ - -1,\ - &tname##_item_tt,\ - 0,\ - NULL,\ - 0,\ - #tname \ - ASN1_ITEM_end(tname) +#define ASN1_ITEM_TEMPLATE_END(tname) \ + ; \ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_PRIMITIVE, \ + -1, \ + &tname##_item_tt, \ + 0, \ + NULL, \ + 0, \ + #tname ASN1_ITEM_end(tname) +#define static_ASN1_ITEM_TEMPLATE_END(tname) \ + ; \ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_PRIMITIVE, \ + -1, \ + &tname##_item_tt, \ + 0, \ + NULL, \ + 0, \ + #tname ASN1_ITEM_end(tname) /* This is a ASN1 type which just embeds a template */ @@ -154,128 +155,118 @@ extern "C" { * a structure called stname. */ -# define ASN1_SEQUENCE(tname) \ - static const ASN1_TEMPLATE tname##_seq_tt[] +#define ASN1_SEQUENCE(tname) \ + static const ASN1_TEMPLATE tname##_seq_tt[] -# define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) +#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) -# define static_ASN1_SEQUENCE_END(stname) static_ASN1_SEQUENCE_END_name(stname, stname) +#define static_ASN1_SEQUENCE_END(stname) static_ASN1_SEQUENCE_END_name(stname, stname) -# define ASN1_SEQUENCE_END_name(stname, tname) \ - ;\ - ASN1_ITEM_start(tname) \ - ASN1_ITYPE_SEQUENCE,\ - V_ASN1_SEQUENCE,\ - tname##_seq_tt,\ - sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ - NULL,\ - sizeof(stname),\ - #tname \ - ASN1_ITEM_end(tname) +#define ASN1_SEQUENCE_END_name(stname, tname) \ + ; \ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE, \ + V_ASN1_SEQUENCE, \ + tname##_seq_tt, \ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \ + NULL, \ + sizeof(stname), \ + #tname ASN1_ITEM_end(tname) -# define static_ASN1_SEQUENCE_END_name(stname, tname) \ - ;\ - static_ASN1_ITEM_start(tname) \ - ASN1_ITYPE_SEQUENCE,\ - V_ASN1_SEQUENCE,\ - tname##_seq_tt,\ - sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ - NULL,\ - sizeof(stname),\ - #stname \ - ASN1_ITEM_end(tname) +#define static_ASN1_SEQUENCE_END_name(stname, tname) \ + ; \ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE, \ + V_ASN1_SEQUENCE, \ + tname##_seq_tt, \ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \ + NULL, \ + sizeof(stname), \ + #stname ASN1_ITEM_end(tname) -# define ASN1_NDEF_SEQUENCE(tname) \ - ASN1_SEQUENCE(tname) +#define ASN1_NDEF_SEQUENCE(tname) \ + ASN1_SEQUENCE(tname) -# define ASN1_NDEF_SEQUENCE_cb(tname, cb) \ - ASN1_SEQUENCE_cb(tname, cb) +#define ASN1_NDEF_SEQUENCE_cb(tname, cb) \ + ASN1_SEQUENCE_cb(tname, cb) -# define ASN1_SEQUENCE_cb(tname, cb) \ - static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0, NULL}; \ - ASN1_SEQUENCE(tname) +#define ASN1_SEQUENCE_cb(tname, cb) \ + static const ASN1_AUX tname##_aux = { NULL, 0, 0, 0, cb, 0, NULL }; \ + ASN1_SEQUENCE(tname) -# define ASN1_SEQUENCE_const_cb(tname, const_cb) \ - static const ASN1_AUX tname##_aux = \ - {NULL, ASN1_AFLG_CONST_CB, 0, 0, NULL, 0, const_cb}; \ - ASN1_SEQUENCE(tname) +#define ASN1_SEQUENCE_const_cb(tname, const_cb) \ + static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_CONST_CB, 0, 0, NULL, 0, const_cb }; \ + ASN1_SEQUENCE(tname) -# define ASN1_SEQUENCE_cb_const_cb(tname, cb, const_cb) \ - static const ASN1_AUX tname##_aux = \ - {NULL, ASN1_AFLG_CONST_CB, 0, 0, cb, 0, const_cb}; \ - ASN1_SEQUENCE(tname) +#define ASN1_SEQUENCE_cb_const_cb(tname, cb, const_cb) \ + static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_CONST_CB, 0, 0, cb, 0, const_cb }; \ + ASN1_SEQUENCE(tname) -# define ASN1_SEQUENCE_ref(tname, cb) \ - static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), offsetof(tname, lock), cb, 0, NULL}; \ - ASN1_SEQUENCE(tname) +#define ASN1_SEQUENCE_ref(tname, cb) \ + static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), offsetof(tname, lock), cb, 0, NULL }; \ + ASN1_SEQUENCE(tname) -# define ASN1_SEQUENCE_enc(tname, enc, cb) \ - static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc), NULL}; \ - ASN1_SEQUENCE(tname) +#define ASN1_SEQUENCE_enc(tname, enc, cb) \ + static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc), NULL }; \ + ASN1_SEQUENCE(tname) -# define ASN1_NDEF_SEQUENCE_END(tname) \ - ;\ - ASN1_ITEM_start(tname) \ - ASN1_ITYPE_NDEF_SEQUENCE,\ - V_ASN1_SEQUENCE,\ - tname##_seq_tt,\ - sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ - NULL,\ - sizeof(tname),\ - #tname \ - ASN1_ITEM_end(tname) -# define static_ASN1_NDEF_SEQUENCE_END(tname) \ - ;\ - static_ASN1_ITEM_start(tname) \ - ASN1_ITYPE_NDEF_SEQUENCE,\ - V_ASN1_SEQUENCE,\ - tname##_seq_tt,\ - sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ - NULL,\ - sizeof(tname),\ - #tname \ - ASN1_ITEM_end(tname) +#define ASN1_NDEF_SEQUENCE_END(tname) \ + ; \ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_NDEF_SEQUENCE, \ + V_ASN1_SEQUENCE, \ + tname##_seq_tt, \ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \ + NULL, \ + sizeof(tname), \ + #tname ASN1_ITEM_end(tname) +#define static_ASN1_NDEF_SEQUENCE_END(tname) \ + ; \ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_NDEF_SEQUENCE, \ + V_ASN1_SEQUENCE, \ + tname##_seq_tt, \ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \ + NULL, \ + sizeof(tname), \ + #tname ASN1_ITEM_end(tname) +#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) -# define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) +#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) +#define static_ASN1_SEQUENCE_END_cb(stname, tname) static_ASN1_SEQUENCE_END_ref(stname, tname) -# define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) -# define static_ASN1_SEQUENCE_END_cb(stname, tname) static_ASN1_SEQUENCE_END_ref(stname, tname) +#define ASN1_SEQUENCE_END_ref(stname, tname) \ + ; \ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE, \ + V_ASN1_SEQUENCE, \ + tname##_seq_tt, \ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \ + &tname##_aux, \ + sizeof(stname), \ + #tname ASN1_ITEM_end(tname) +#define static_ASN1_SEQUENCE_END_ref(stname, tname) \ + ; \ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE, \ + V_ASN1_SEQUENCE, \ + tname##_seq_tt, \ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \ + &tname##_aux, \ + sizeof(stname), \ + #stname ASN1_ITEM_end(tname) -# define ASN1_SEQUENCE_END_ref(stname, tname) \ - ;\ - ASN1_ITEM_start(tname) \ - ASN1_ITYPE_SEQUENCE,\ - V_ASN1_SEQUENCE,\ - tname##_seq_tt,\ - sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ - &tname##_aux,\ - sizeof(stname),\ - #tname \ - ASN1_ITEM_end(tname) -# define static_ASN1_SEQUENCE_END_ref(stname, tname) \ - ;\ - static_ASN1_ITEM_start(tname) \ - ASN1_ITYPE_SEQUENCE,\ - V_ASN1_SEQUENCE,\ - tname##_seq_tt,\ - sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ - &tname##_aux,\ - sizeof(stname),\ - #stname \ - ASN1_ITEM_end(tname) - -# define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \ - ;\ - ASN1_ITEM_start(tname) \ - ASN1_ITYPE_NDEF_SEQUENCE,\ - V_ASN1_SEQUENCE,\ - tname##_seq_tt,\ - sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ - &tname##_aux,\ - sizeof(stname),\ - #stname \ - ASN1_ITEM_end(tname) +#define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \ + ; \ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_NDEF_SEQUENCE, \ + V_ASN1_SEQUENCE, \ + tname##_seq_tt, \ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \ + &tname##_aux, \ + sizeof(stname), \ + #stname ASN1_ITEM_end(tname) /*- * This pair helps declare a CHOICE type. We can do: @@ -300,185 +291,183 @@ extern "C" { * ASN1_CHOICE_END_selector() version. */ -# define ASN1_CHOICE(tname) \ - static const ASN1_TEMPLATE tname##_ch_tt[] +#define ASN1_CHOICE(tname) \ + static const ASN1_TEMPLATE tname##_ch_tt[] -# define ASN1_CHOICE_cb(tname, cb) \ - static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0, NULL}; \ - ASN1_CHOICE(tname) +#define ASN1_CHOICE_cb(tname, cb) \ + static const ASN1_AUX tname##_aux = { NULL, 0, 0, 0, cb, 0, NULL }; \ + ASN1_CHOICE(tname) -# define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) +#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) -# define static_ASN1_CHOICE_END(stname) static_ASN1_CHOICE_END_name(stname, stname) +#define static_ASN1_CHOICE_END(stname) static_ASN1_CHOICE_END_name(stname, stname) -# define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type) +#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type) -# define static_ASN1_CHOICE_END_name(stname, tname) static_ASN1_CHOICE_END_selector(stname, tname, type) +#define static_ASN1_CHOICE_END_name(stname, tname) static_ASN1_CHOICE_END_selector(stname, tname, type) -# define ASN1_CHOICE_END_selector(stname, tname, selname) \ - ;\ - ASN1_ITEM_start(tname) \ - ASN1_ITYPE_CHOICE,\ - offsetof(stname,selname) ,\ - tname##_ch_tt,\ - sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ - NULL,\ - sizeof(stname),\ - #stname \ - ASN1_ITEM_end(tname) +#define ASN1_CHOICE_END_selector(stname, tname, selname) \ + ; \ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE, \ + offsetof(stname, selname), \ + tname##_ch_tt, \ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE), \ + NULL, \ + sizeof(stname), \ + #stname ASN1_ITEM_end(tname) -# define static_ASN1_CHOICE_END_selector(stname, tname, selname) \ - ;\ - static_ASN1_ITEM_start(tname) \ - ASN1_ITYPE_CHOICE,\ - offsetof(stname,selname) ,\ - tname##_ch_tt,\ - sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ - NULL,\ - sizeof(stname),\ - #stname \ - ASN1_ITEM_end(tname) +#define static_ASN1_CHOICE_END_selector(stname, tname, selname) \ + ; \ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE, \ + offsetof(stname, selname), \ + tname##_ch_tt, \ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE), \ + NULL, \ + sizeof(stname), \ + #stname ASN1_ITEM_end(tname) -# define ASN1_CHOICE_END_cb(stname, tname, selname) \ - ;\ - ASN1_ITEM_start(tname) \ - ASN1_ITYPE_CHOICE,\ - offsetof(stname,selname) ,\ - tname##_ch_tt,\ - sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ - &tname##_aux,\ - sizeof(stname),\ - #stname \ - ASN1_ITEM_end(tname) +#define ASN1_CHOICE_END_cb(stname, tname, selname) \ + ; \ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE, \ + offsetof(stname, selname), \ + tname##_ch_tt, \ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE), \ + &tname##_aux, \ + sizeof(stname), \ + #stname ASN1_ITEM_end(tname) /* This helps with the template wrapper form of ASN1_ITEM */ -# define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ - (flags), (tag), 0,\ - #name, ASN1_ITEM_ref(type) } +#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ + (flags), (tag), 0, \ + #name, ASN1_ITEM_ref(type) \ +} /* These help with SEQUENCE or CHOICE components */ /* used to declare other types */ -# define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ - (flags), (tag), offsetof(stname, field),\ - #field, ASN1_ITEM_ref(type) } +#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ + (flags), (tag), offsetof(stname, field), \ + #field, ASN1_ITEM_ref(type) \ +} /* implicit and explicit helper macros */ -# define ASN1_IMP_EX(stname, field, type, tag, ex) \ - ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | (ex), tag, stname, field, type) +#define ASN1_IMP_EX(stname, field, type, tag, ex) \ + ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | (ex), tag, stname, field, type) -# define ASN1_EXP_EX(stname, field, type, tag, ex) \ - ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | (ex), tag, stname, field, type) +#define ASN1_EXP_EX(stname, field, type, tag, ex) \ + ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | (ex), tag, stname, field, type) /* Any defined by macros: the field used is in the table itself */ -# define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb } -# define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb } +#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb } +#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb } /* Plain simple type */ -# define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type) +#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0, 0, stname, field, type) /* Embedded simple type */ -# define ASN1_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_EMBED,0, stname, field, type) +#define ASN1_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_EMBED, 0, stname, field, type) /* OPTIONAL simple type */ -# define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type) -# define ASN1_OPT_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED, 0, stname, field, type) +#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type) +#define ASN1_OPT_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL | ASN1_TFLG_EMBED, 0, stname, field, type) /* IMPLICIT tagged simple type */ -# define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0) -# define ASN1_IMP_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_EMBED) +#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0) +#define ASN1_IMP_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_EMBED) /* IMPLICIT tagged OPTIONAL simple type */ -# define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) -# define ASN1_IMP_OPT_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED) +#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) +#define ASN1_IMP_OPT_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL | ASN1_TFLG_EMBED) /* Same as above but EXPLICIT */ -# define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0) -# define ASN1_EXP_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_EMBED) -# define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) -# define ASN1_EXP_OPT_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED) +#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0) +#define ASN1_EXP_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_EMBED) +#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) +#define ASN1_EXP_OPT_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL | ASN1_TFLG_EMBED) /* SEQUENCE OF type */ -# define ASN1_SEQUENCE_OF(stname, field, type) \ - ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type) +#define ASN1_SEQUENCE_OF(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type) /* OPTIONAL SEQUENCE OF */ -# define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ - ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) +#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL, 0, stname, field, type) /* Same as above but for SET OF */ -# define ASN1_SET_OF(stname, field, type) \ - ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type) +#define ASN1_SET_OF(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type) -# define ASN1_SET_OF_OPT(stname, field, type) \ - ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) +#define ASN1_SET_OF_OPT(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL, 0, stname, field, type) /* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */ -# define ASN1_IMP_SET_OF(stname, field, type, tag) \ - ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) +#define ASN1_IMP_SET_OF(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) -# define ASN1_EXP_SET_OF(stname, field, type, tag) \ - ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) +#define ASN1_EXP_SET_OF(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) -# define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ - ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) +#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL) -# define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ - ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) +#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL) -# define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ - ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) +#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) -# define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ - ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) +#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL) -# define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ - ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) +#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) -# define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ - ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) +#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL) /* EXPLICIT using indefinite length constructed form */ -# define ASN1_NDEF_EXP(stname, field, type, tag) \ - ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF) +#define ASN1_NDEF_EXP(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF) /* EXPLICIT OPTIONAL using indefinite length constructed form */ -# define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \ - ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF) +#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL | ASN1_TFLG_NDEF) /* Macros for the ASN1_ADB structure */ -# define ASN1_ADB(name) \ - static const ASN1_ADB_TABLE name##_adbtbl[] +#define ASN1_ADB(name) \ + static const ASN1_ADB_TABLE name##_adbtbl[] -# define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \ - ;\ - static const ASN1_ITEM *name##_adb(void) \ - { \ - static const ASN1_ADB internal_adb = \ - {\ - flags,\ - offsetof(name, field),\ - adb_cb,\ - name##_adbtbl,\ - sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ - def,\ - none\ - }; \ - return (const ASN1_ITEM *) &internal_adb; \ - } \ - void dummy_function(void) +#define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \ + ; \ + static const ASN1_ITEM *name##_adb(void) \ + { \ + static const ASN1_ADB internal_adb = { \ + flags, \ + offsetof(name, field), \ + adb_cb, \ + name##_adbtbl, \ + sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE), \ + def, \ + none \ + }; \ + return (const ASN1_ITEM *)&internal_adb; \ + } \ + void dummy_function(void) -# define ADB_ENTRY(val, template) {val, template} +#define ADB_ENTRY(val, template) { val, template } -# define ASN1_ADB_TEMPLATE(name) \ - static const ASN1_TEMPLATE name##_tt +#define ASN1_ADB_TEMPLATE(name) \ + static const ASN1_TEMPLATE name##_tt /* * This is the ASN1 template structure that defines a wrapper round the @@ -487,56 +476,56 @@ extern "C" { */ struct ASN1_TEMPLATE_st { - unsigned long flags; /* Various flags */ - long tag; /* tag, not used if no tagging */ - unsigned long offset; /* Offset of this field in structure */ - const char *field_name; /* Field name */ - ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ + unsigned long flags; /* Various flags */ + long tag; /* tag, not used if no tagging */ + unsigned long offset; /* Offset of this field in structure */ + const char *field_name; /* Field name */ + ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ }; /* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */ -# define ASN1_TEMPLATE_item(t) (t->item_ptr) -# define ASN1_TEMPLATE_adb(t) (t->item_ptr) +#define ASN1_TEMPLATE_item(t) (t->item_ptr) +#define ASN1_TEMPLATE_adb(t) (t->item_ptr) typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE; typedef struct ASN1_ADB_st ASN1_ADB; struct ASN1_ADB_st { - unsigned long flags; /* Various flags */ - unsigned long offset; /* Offset of selector field */ - int (*adb_cb)(long *psel); /* Application callback */ - const ASN1_ADB_TABLE *tbl; /* Table of possible types */ - long tblcount; /* Number of entries in tbl */ + unsigned long flags; /* Various flags */ + unsigned long offset; /* Offset of selector field */ + int (*adb_cb)(long *psel); /* Application callback */ + const ASN1_ADB_TABLE *tbl; /* Table of possible types */ + long tblcount; /* Number of entries in tbl */ const ASN1_TEMPLATE *default_tt; /* Type to use if no match */ const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */ }; struct ASN1_ADB_TABLE_st { - long value; /* NID for an object or value for an int */ - const ASN1_TEMPLATE tt; /* item for this value */ + long value; /* NID for an object or value for an int */ + const ASN1_TEMPLATE tt; /* item for this value */ }; /* template flags */ /* Field is optional */ -# define ASN1_TFLG_OPTIONAL (0x1) +#define ASN1_TFLG_OPTIONAL (0x1) /* Field is a SET OF */ -# define ASN1_TFLG_SET_OF (0x1 << 1) +#define ASN1_TFLG_SET_OF (0x1 << 1) /* Field is a SEQUENCE OF */ -# define ASN1_TFLG_SEQUENCE_OF (0x2 << 1) +#define ASN1_TFLG_SEQUENCE_OF (0x2 << 1) /* * Special case: this refers to a SET OF that will be sorted into DER order * when encoded *and* the corresponding STACK will be modified to match the * new order. */ -# define ASN1_TFLG_SET_ORDER (0x3 << 1) +#define ASN1_TFLG_SET_ORDER (0x3 << 1) /* Mask for SET OF or SEQUENCE OF */ -# define ASN1_TFLG_SK_MASK (0x3 << 1) +#define ASN1_TFLG_SK_MASK (0x3 << 1) /* * These flags mean the tag should be taken from the tag field. If EXPLICIT @@ -544,18 +533,18 @@ struct ASN1_ADB_TABLE_st { */ /* IMPLICIT tagging */ -# define ASN1_TFLG_IMPTAG (0x1 << 3) +#define ASN1_TFLG_IMPTAG (0x1 << 3) /* EXPLICIT tagging, inner tag from underlying type */ -# define ASN1_TFLG_EXPTAG (0x2 << 3) +#define ASN1_TFLG_EXPTAG (0x2 << 3) -# define ASN1_TFLG_TAG_MASK (0x3 << 3) +#define ASN1_TFLG_TAG_MASK (0x3 << 3) /* context specific IMPLICIT */ -# define ASN1_TFLG_IMPLICIT (ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT) +#define ASN1_TFLG_IMPLICIT (ASN1_TFLG_IMPTAG | ASN1_TFLG_CONTEXT) /* context specific EXPLICIT */ -# define ASN1_TFLG_EXPLICIT (ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT) +#define ASN1_TFLG_EXPLICIT (ASN1_TFLG_EXPTAG | ASN1_TFLG_CONTEXT) /* * If tagging is in force these determine the type of tag to use. Otherwise @@ -564,15 +553,15 @@ struct ASN1_ADB_TABLE_st { */ /* Universal tag */ -# define ASN1_TFLG_UNIVERSAL (0x0<<6) +#define ASN1_TFLG_UNIVERSAL (0x0 << 6) /* Application tag */ -# define ASN1_TFLG_APPLICATION (0x1<<6) +#define ASN1_TFLG_APPLICATION (0x1 << 6) /* Context specific tag */ -# define ASN1_TFLG_CONTEXT (0x2<<6) +#define ASN1_TFLG_CONTEXT (0x2 << 6) /* Private tag */ -# define ASN1_TFLG_PRIVATE (0x3<<6) +#define ASN1_TFLG_PRIVATE (0x3 << 6) -# define ASN1_TFLG_TAG_CLASS (0x3<<6) +#define ASN1_TFLG_TAG_CLASS (0x3 << 6) /* * These are for ANY DEFINED BY type. In this case the 'item' field points to @@ -580,35 +569,35 @@ struct ASN1_ADB_TABLE_st { * relevant type */ -# define ASN1_TFLG_ADB_MASK (0x3<<8) +#define ASN1_TFLG_ADB_MASK (0x3 << 8) -# define ASN1_TFLG_ADB_OID (0x1<<8) +#define ASN1_TFLG_ADB_OID (0x1 << 8) -# define ASN1_TFLG_ADB_INT (0x1<<9) +#define ASN1_TFLG_ADB_INT (0x1 << 9) /* * This flag when present in a SEQUENCE OF, SET OF or EXPLICIT causes * indefinite length constructed encoding to be used if required. */ -# define ASN1_TFLG_NDEF (0x1<<11) +#define ASN1_TFLG_NDEF (0x1 << 11) /* Field is embedded and not a pointer */ -# define ASN1_TFLG_EMBED (0x1 << 12) +#define ASN1_TFLG_EMBED (0x1 << 12) /* This is the actual ASN1 item itself */ struct ASN1_ITEM_st { - char itype; /* The item type, primitive, SEQUENCE, CHOICE - * or extern */ - long utype; /* underlying type */ + char itype; /* The item type, primitive, SEQUENCE, CHOICE + * or extern */ + long utype; /* underlying type */ const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains * the contents */ - long tcount; /* Number of templates if SEQUENCE or CHOICE */ - const void *funcs; /* further data and type-specific functions */ + long tcount; /* Number of templates if SEQUENCE or CHOICE */ + const void *funcs; /* further data and type-specific functions */ /* funcs can be ASN1_PRIMITIVE_FUNCS*, ASN1_EXTERN_FUNCS*, or ASN1_AUX* */ - long size; /* Structure size (usually) */ - const char *sname; /* Structure name */ + long size; /* Structure size (usually) */ + const char *sname; /* Structure name */ }; /* @@ -617,42 +606,42 @@ struct ASN1_ITEM_st { */ struct ASN1_TLC_st { - char valid; /* Values below are valid */ - int ret; /* return value */ - long plen; /* length */ - int ptag; /* class value */ - int pclass; /* class value */ - int hdrlen; /* header length */ + char valid; /* Values below are valid */ + int ret; /* return value */ + long plen; /* length */ + int ptag; /* class value */ + int pclass; /* class value */ + int hdrlen; /* header length */ }; /* Typedefs for ASN1 function pointers */ typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, - const ASN1_ITEM *it, int tag, int aclass, char opt, - ASN1_TLC *ctx); + const ASN1_ITEM *it, int tag, int aclass, char opt, + ASN1_TLC *ctx); typedef int ASN1_ex_d2i_ex(ASN1_VALUE **pval, const unsigned char **in, long len, - const ASN1_ITEM *it, int tag, int aclass, char opt, - ASN1_TLC *ctx, OSSL_LIB_CTX *libctx, - const char *propq); + const ASN1_ITEM *it, int tag, int aclass, char opt, + ASN1_TLC *ctx, OSSL_LIB_CTX *libctx, + const char *propq); typedef int ASN1_ex_i2d(const ASN1_VALUE **pval, unsigned char **out, - const ASN1_ITEM *it, int tag, int aclass); + const ASN1_ITEM *it, int tag, int aclass); typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); typedef int ASN1_ex_new_ex_func(ASN1_VALUE **pval, const ASN1_ITEM *it, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); typedef int ASN1_ex_print_func(BIO *out, const ASN1_VALUE **pval, - int indent, const char *fname, - const ASN1_PCTX *pctx); + int indent, const char *fname, + const ASN1_PCTX *pctx); typedef int ASN1_primitive_i2c(const ASN1_VALUE **pval, unsigned char *cont, - int *putype, const ASN1_ITEM *it); + int *putype, const ASN1_ITEM *it); typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, - int len, int utype, char *free_cont, - const ASN1_ITEM *it); + int len, int utype, char *free_cont, + const ASN1_ITEM *it); typedef int ASN1_primitive_print(BIO *out, const ASN1_VALUE **pval, - const ASN1_ITEM *it, int indent, - const ASN1_PCTX *pctx); + const ASN1_ITEM *it, int indent, + const ASN1_PCTX *pctx); typedef struct ASN1_EXTERN_FUNCS_st { void *app_data; @@ -695,17 +684,17 @@ typedef struct ASN1_PRIMITIVE_FUNCS_st { */ typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it, - void *exarg); + void *exarg); typedef int ASN1_aux_const_cb(int operation, const ASN1_VALUE **in, - const ASN1_ITEM *it, void *exarg); + const ASN1_ITEM *it, void *exarg); typedef struct ASN1_AUX_st { void *app_data; int flags; - int ref_offset; /* Offset of reference value */ - int ref_lock; /* Offset of lock value */ + int ref_offset; /* Offset of reference value */ + int ref_lock; /* Offset of lock value */ ASN1_aux_cb *asn1_cb; - int enc_offset; /* Offset of ASN1_ENCODING structure */ + int enc_offset; /* Offset of ASN1_ENCODING structure */ ASN1_aux_const_cb *asn1_const_cb; /* for ASN1_OP_I2D_ and ASN1_OP_PRINT_ */ } ASN1_AUX; @@ -729,143 +718,142 @@ typedef struct ASN1_STREAM_ARG_st { /* Flags in ASN1_AUX */ /* Use a reference count */ -# define ASN1_AFLG_REFCOUNT 1 +#define ASN1_AFLG_REFCOUNT 1 /* Save the encoding of structure (useful for signatures) */ -# define ASN1_AFLG_ENCODING 2 +#define ASN1_AFLG_ENCODING 2 /* The Sequence length is invalid */ -# define ASN1_AFLG_BROKEN 4 +#define ASN1_AFLG_BROKEN 4 /* Use the new asn1_const_cb */ -# define ASN1_AFLG_CONST_CB 8 +#define ASN1_AFLG_CONST_CB 8 /* operation values for asn1_cb */ -# define ASN1_OP_NEW_PRE 0 -# define ASN1_OP_NEW_POST 1 -# define ASN1_OP_FREE_PRE 2 -# define ASN1_OP_FREE_POST 3 -# define ASN1_OP_D2I_PRE 4 -# define ASN1_OP_D2I_POST 5 -# define ASN1_OP_I2D_PRE 6 -# define ASN1_OP_I2D_POST 7 -# define ASN1_OP_PRINT_PRE 8 -# define ASN1_OP_PRINT_POST 9 -# define ASN1_OP_STREAM_PRE 10 -# define ASN1_OP_STREAM_POST 11 -# define ASN1_OP_DETACHED_PRE 12 -# define ASN1_OP_DETACHED_POST 13 -# define ASN1_OP_DUP_PRE 14 -# define ASN1_OP_DUP_POST 15 -# define ASN1_OP_GET0_LIBCTX 16 -# define ASN1_OP_GET0_PROPQ 17 +#define ASN1_OP_NEW_PRE 0 +#define ASN1_OP_NEW_POST 1 +#define ASN1_OP_FREE_PRE 2 +#define ASN1_OP_FREE_POST 3 +#define ASN1_OP_D2I_PRE 4 +#define ASN1_OP_D2I_POST 5 +#define ASN1_OP_I2D_PRE 6 +#define ASN1_OP_I2D_POST 7 +#define ASN1_OP_PRINT_PRE 8 +#define ASN1_OP_PRINT_POST 9 +#define ASN1_OP_STREAM_PRE 10 +#define ASN1_OP_STREAM_POST 11 +#define ASN1_OP_DETACHED_PRE 12 +#define ASN1_OP_DETACHED_POST 13 +#define ASN1_OP_DUP_PRE 14 +#define ASN1_OP_DUP_POST 15 +#define ASN1_OP_GET0_LIBCTX 16 +#define ASN1_OP_GET0_PROPQ 17 /* Macro to implement a primitive type */ -# define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) -# define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ - ASN1_ITEM_start(itname) \ - ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \ - ASN1_ITEM_end(itname) +#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) +#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ + ASN1_ITEM_start(itname) \ + ASN1_ITYPE_PRIMITIVE, \ + V_##vname, NULL, 0, NULL, ex, #itname ASN1_ITEM_end(itname) /* Macro to implement a multi string type */ -# define IMPLEMENT_ASN1_MSTRING(itname, mask) \ - ASN1_ITEM_start(itname) \ - ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \ - ASN1_ITEM_end(itname) +#define IMPLEMENT_ASN1_MSTRING(itname, mask) \ + ASN1_ITEM_start(itname) \ + ASN1_ITYPE_MSTRING, \ + mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname ASN1_ITEM_end(itname) -# define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \ - ASN1_ITEM_start(sname) \ - ASN1_ITYPE_EXTERN, \ - tag, \ - NULL, \ - 0, \ - &fptrs, \ - 0, \ - #sname \ - ASN1_ITEM_end(sname) +#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \ + ASN1_ITEM_start(sname) \ + ASN1_ITYPE_EXTERN, \ + tag, \ + NULL, \ + 0, \ + &fptrs, \ + 0, \ + #sname ASN1_ITEM_end(sname) /* Macro to implement standard functions in terms of ASN1_ITEM structures */ -# define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname) +#define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname) -# define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname) +#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname) -# define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ - IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) +#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ + IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) -# define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \ - IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname) +#define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname) -# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ - IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) +#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) -# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \ - pre stname *fname##_new(void) \ - { \ - return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ - } \ - pre void fname##_free(stname *a) \ - { \ - ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ - } +#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \ + pre stname *fname##_new(void) \ + { \ + return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ + } \ + pre void fname##_free(stname *a) \ + { \ + ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ + } -# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ - stname *fname##_new(void) \ - { \ - return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ - } \ - void fname##_free(stname *a) \ - { \ - ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ - } +#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ + stname *fname##_new(void) \ + { \ + return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ + } \ + void fname##_free(stname *a) \ + { \ + ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ + } -# define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \ - IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ - IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) +#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) -# define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ - stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ - { \ - return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ - } \ - int i2d_##fname(const stname *a, unsigned char **out) \ - { \ - return ASN1_item_i2d((const ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ - } +#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ + stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ + { \ + return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname)); \ + } \ + int i2d_##fname(const stname *a, unsigned char **out) \ + { \ + return ASN1_item_i2d((const ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname)); \ + } -# define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \ - int i2d_##stname##_NDEF(const stname *a, unsigned char **out) \ - { \ - return ASN1_item_ndef_i2d((const ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\ - } +#define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \ + int i2d_##stname##_NDEF(const stname *a, unsigned char **out) \ + { \ + return ASN1_item_ndef_i2d((const ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname)); \ + } -# define IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(stname) \ - static stname *d2i_##stname(stname **a, \ - const unsigned char **in, long len) \ - { \ - return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, \ - ASN1_ITEM_rptr(stname)); \ - } \ - static int i2d_##stname(const stname *a, unsigned char **out) \ - { \ - return ASN1_item_i2d((const ASN1_VALUE *)a, out, \ - ASN1_ITEM_rptr(stname)); \ - } +#define IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(stname) \ + static stname *d2i_##stname(stname **a, \ + const unsigned char **in, long len) \ + { \ + return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, \ + ASN1_ITEM_rptr(stname)); \ + } \ + static int i2d_##stname(const stname *a, unsigned char **out) \ + { \ + return ASN1_item_i2d((const ASN1_VALUE *)a, out, \ + ASN1_ITEM_rptr(stname)); \ + } -# define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ - stname * stname##_dup(const stname *x) \ - { \ +#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ + stname *stname##_dup(const stname *x) \ + { \ return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ - } + } -# define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \ - IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname) +#define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \ + IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname) -# define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \ - int fname##_print_ctx(BIO *out, const stname *x, int indent, \ - const ASN1_PCTX *pctx) \ - { \ - return ASN1_item_print(out, (const ASN1_VALUE *)x, indent, \ - ASN1_ITEM_rptr(itname), pctx); \ - } +#define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \ + int fname##_print_ctx(BIO *out, const stname *x, int indent, \ + const ASN1_PCTX *pctx) \ + { \ + return ASN1_item_print(out, (const ASN1_VALUE *)x, indent, \ + ASN1_ITEM_rptr(itname), pctx); \ + } /* external definitions for primitive types */ @@ -884,7 +872,7 @@ DECLARE_ASN1_ITEM(ZINT64) DECLARE_ASN1_ITEM(UINT64) DECLARE_ASN1_ITEM(ZUINT64) -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 /* * LONG and ZLONG are strongly discouraged for use as stored data, as the * underlying C type (long) differs in size depending on the architecture. @@ -892,8 +880,9 @@ DECLARE_ASN1_ITEM(ZUINT64) */ DECLARE_ASN1_ITEM(LONG) DECLARE_ASN1_ITEM(ZLONG) -# endif +#endif +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_VALUE, ASN1_VALUE, ASN1_VALUE) #define sk_ASN1_VALUE_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_VALUE_sk_type(sk)) #define sk_ASN1_VALUE_value(sk, idx) ((ASN1_VALUE *)OPENSSL_sk_value(ossl_check_const_ASN1_VALUE_sk_type(sk), (idx))) @@ -921,7 +910,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_VALUE, ASN1_VALUE, ASN1_VALUE) #define sk_ASN1_VALUE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_VALUE) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_copyfunc_type(copyfunc), ossl_check_ASN1_VALUE_freefunc_type(freefunc))) #define sk_ASN1_VALUE_set_cmp_func(sk, cmp) ((sk_ASN1_VALUE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_compfunc_type(cmp))) - +/* clang-format on */ /* Functions used internally by the ASN1 code */ @@ -929,18 +918,18 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it); int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, - const ASN1_ITEM *it, int tag, int aclass, char opt, - ASN1_TLC *ctx); + const ASN1_ITEM *it, int tag, int aclass, char opt, + ASN1_TLC *ctx); int ASN1_item_ex_i2d(const ASN1_VALUE **pval, unsigned char **out, - const ASN1_ITEM *it, int tag, int aclass); + const ASN1_ITEM *it, int tag, int aclass); /* Legacy compatibility */ -# define IMPLEMENT_ASN1_FUNCTIONS_const(name) IMPLEMENT_ASN1_FUNCTIONS(name) -# define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ - IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) +#define IMPLEMENT_ASN1_FUNCTIONS_const(name) IMPLEMENT_ASN1_FUNCTIONS(name) +#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) -#ifdef __cplusplus +#ifdef __cplusplus } #endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/bio.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/bio.h index 8a1f9f039b..6c571fe125 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/bio.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/bio.h @@ -9,154 +9,156 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_BIO_H -# define OPENSSL_BIO_H -# pragma once +#define OPENSSL_BIO_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_BIO_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_BIO_H +#endif -# include +#include -# ifndef OPENSSL_NO_STDIO -# include -# endif -# include +#ifndef OPENSSL_NO_STDIO +#include +#endif +#include -# include -# include -# include +#include +#include +#include -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif /* There are the classes of BIOs */ -# define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ -# define BIO_TYPE_FILTER 0x0200 -# define BIO_TYPE_SOURCE_SINK 0x0400 +#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ +#define BIO_TYPE_FILTER 0x0200 +#define BIO_TYPE_SOURCE_SINK 0x0400 /* These are the 'types' of BIOs */ -# define BIO_TYPE_NONE 0 -# define BIO_TYPE_MEM ( 1|BIO_TYPE_SOURCE_SINK) -# define BIO_TYPE_FILE ( 2|BIO_TYPE_SOURCE_SINK) +#define BIO_TYPE_NONE 0 +#define BIO_TYPE_MEM (1 | BIO_TYPE_SOURCE_SINK) +#define BIO_TYPE_FILE (2 | BIO_TYPE_SOURCE_SINK) -# define BIO_TYPE_FD ( 4|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) -# define BIO_TYPE_SOCKET ( 5|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) -# define BIO_TYPE_NULL ( 6|BIO_TYPE_SOURCE_SINK) -# define BIO_TYPE_SSL ( 7|BIO_TYPE_FILTER) -# define BIO_TYPE_MD ( 8|BIO_TYPE_FILTER) -# define BIO_TYPE_BUFFER ( 9|BIO_TYPE_FILTER) -# define BIO_TYPE_CIPHER (10|BIO_TYPE_FILTER) -# define BIO_TYPE_BASE64 (11|BIO_TYPE_FILTER) -# define BIO_TYPE_CONNECT (12|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) -# define BIO_TYPE_ACCEPT (13|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +#define BIO_TYPE_FD (4 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) +#define BIO_TYPE_SOCKET (5 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) +#define BIO_TYPE_NULL (6 | BIO_TYPE_SOURCE_SINK) +#define BIO_TYPE_SSL (7 | BIO_TYPE_FILTER) +#define BIO_TYPE_MD (8 | BIO_TYPE_FILTER) +#define BIO_TYPE_BUFFER (9 | BIO_TYPE_FILTER) +#define BIO_TYPE_CIPHER (10 | BIO_TYPE_FILTER) +#define BIO_TYPE_BASE64 (11 | BIO_TYPE_FILTER) +#define BIO_TYPE_CONNECT (12 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) +#define BIO_TYPE_ACCEPT (13 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) -# define BIO_TYPE_NBIO_TEST (16|BIO_TYPE_FILTER)/* server proxy BIO */ -# define BIO_TYPE_NULL_FILTER (17|BIO_TYPE_FILTER) -# define BIO_TYPE_BIO (19|BIO_TYPE_SOURCE_SINK)/* half a BIO pair */ -# define BIO_TYPE_LINEBUFFER (20|BIO_TYPE_FILTER) -# define BIO_TYPE_DGRAM (21|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) -# define BIO_TYPE_ASN1 (22|BIO_TYPE_FILTER) -# define BIO_TYPE_COMP (23|BIO_TYPE_FILTER) -# ifndef OPENSSL_NO_SCTP -# define BIO_TYPE_DGRAM_SCTP (24|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) -# endif -# define BIO_TYPE_CORE_TO_PROV (25|BIO_TYPE_SOURCE_SINK) -# define BIO_TYPE_DGRAM_PAIR (26|BIO_TYPE_SOURCE_SINK) -# define BIO_TYPE_DGRAM_MEM (27|BIO_TYPE_SOURCE_SINK) +#define BIO_TYPE_NBIO_TEST (16 | BIO_TYPE_FILTER) /* server proxy BIO */ +#define BIO_TYPE_NULL_FILTER (17 | BIO_TYPE_FILTER) +#define BIO_TYPE_BIO (19 | BIO_TYPE_SOURCE_SINK) /* half a BIO pair */ +#define BIO_TYPE_LINEBUFFER (20 | BIO_TYPE_FILTER) +#define BIO_TYPE_DGRAM (21 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) +#define BIO_TYPE_ASN1 (22 | BIO_TYPE_FILTER) +#define BIO_TYPE_COMP (23 | BIO_TYPE_FILTER) +#ifndef OPENSSL_NO_SCTP +#define BIO_TYPE_DGRAM_SCTP (24 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) +#endif +#define BIO_TYPE_CORE_TO_PROV (25 | BIO_TYPE_SOURCE_SINK) +#define BIO_TYPE_DGRAM_PAIR (26 | BIO_TYPE_SOURCE_SINK) +#define BIO_TYPE_DGRAM_MEM (27 | BIO_TYPE_SOURCE_SINK) /* Custom type starting index returned by BIO_get_new_index() */ -#define BIO_TYPE_START 128 +#define BIO_TYPE_START 128 /* Custom type maximum index that can be returned by BIO_get_new_index() */ -#define BIO_TYPE_MASK 0xFF +#define BIO_TYPE_MASK 0xFF /* * BIO_FILENAME_READ|BIO_CLOSE to open or close on free. * BIO_set_fp(in,stdin,BIO_NOCLOSE); */ -# define BIO_NOCLOSE 0x00 -# define BIO_CLOSE 0x01 +#define BIO_NOCLOSE 0x00 +#define BIO_CLOSE 0x01 /* * These are used in the following macros and are passed to BIO_ctrl() */ -# define BIO_CTRL_RESET 1/* opt - rewind/zero etc */ -# define BIO_CTRL_EOF 2/* opt - are we at the eof */ -# define BIO_CTRL_INFO 3/* opt - extra tit-bits */ -# define BIO_CTRL_SET 4/* man - set the 'IO' type */ -# define BIO_CTRL_GET 5/* man - get the 'IO' type */ -# define BIO_CTRL_PUSH 6/* opt - internal, used to signify change */ -# define BIO_CTRL_POP 7/* opt - internal, used to signify change */ -# define BIO_CTRL_GET_CLOSE 8/* man - set the 'close' on free */ -# define BIO_CTRL_SET_CLOSE 9/* man - set the 'close' on free */ -# define BIO_CTRL_PENDING 10/* opt - is their more data buffered */ -# define BIO_CTRL_FLUSH 11/* opt - 'flush' buffered output */ -# define BIO_CTRL_DUP 12/* man - extra stuff for 'duped' BIO */ -# define BIO_CTRL_WPENDING 13/* opt - number of bytes still to write */ -# define BIO_CTRL_SET_CALLBACK 14/* opt - set callback function */ -# define BIO_CTRL_GET_CALLBACK 15/* opt - set callback function */ +#define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */ +#define BIO_CTRL_EOF 2 /* opt - are we at the eof */ +#define BIO_CTRL_INFO 3 /* opt - extra tit-bits */ +#define BIO_CTRL_SET 4 /* man - set the 'IO' type */ +#define BIO_CTRL_GET 5 /* man - get the 'IO' type */ +#define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */ +#define BIO_CTRL_POP 7 /* opt - internal, used to signify change */ +#define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */ +#define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */ +#define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */ +#define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */ +#define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */ +#define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */ +#define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */ +#define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */ -# define BIO_CTRL_PEEK 29/* BIO_f_buffer special */ -# define BIO_CTRL_SET_FILENAME 30/* BIO_s_file special */ +#define BIO_CTRL_PEEK 29 /* BIO_f_buffer special */ +#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */ /* dgram BIO stuff */ -# define BIO_CTRL_DGRAM_CONNECT 31/* BIO dgram special */ -# define BIO_CTRL_DGRAM_SET_CONNECTED 32/* allow for an externally connected +#define BIO_CTRL_DGRAM_CONNECT 31 /* BIO dgram special */ +#define BIO_CTRL_DGRAM_SET_CONNECTED 32 /* allow for an externally connected \ * socket to be passed in */ -# define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33/* setsockopt, essentially */ -# define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34/* getsockopt, essentially */ -# define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35/* setsockopt, essentially */ -# define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36/* getsockopt, essentially */ +#define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33 /* setsockopt, essentially */ +#define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34 /* getsockopt, essentially */ +#define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35 /* setsockopt, essentially */ +#define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36 /* getsockopt, essentially */ -# define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37/* flag whether the last */ -# define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38/* I/O operation timed out */ +#define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */ +#define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation timed out */ /* #ifdef IP_MTU_DISCOVER */ -# define BIO_CTRL_DGRAM_MTU_DISCOVER 39/* set DF bit on egress packets */ +#define BIO_CTRL_DGRAM_MTU_DISCOVER 39 /* set DF bit on egress packets */ /* #endif */ -# define BIO_CTRL_DGRAM_QUERY_MTU 40/* as kernel for current MTU */ -# define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47 -# define BIO_CTRL_DGRAM_GET_MTU 41/* get cached value for MTU */ -# define BIO_CTRL_DGRAM_SET_MTU 42/* set cached value for MTU. - * want to use this if asking - * the kernel fails */ +#define BIO_CTRL_DGRAM_QUERY_MTU 40 /* as kernel for current MTU */ +#define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47 +#define BIO_CTRL_DGRAM_GET_MTU 41 /* get cached value for MTU */ +#define BIO_CTRL_DGRAM_SET_MTU 42 /* set cached value for MTU. \ + * want to use this if asking \ + * the kernel fails */ -# define BIO_CTRL_DGRAM_MTU_EXCEEDED 43/* check whether the MTU was - * exceed in the previous write - * operation */ +#define BIO_CTRL_DGRAM_MTU_EXCEEDED 43 /* check whether the MTU was \ + * exceed in the previous write \ + * operation */ -# define BIO_CTRL_DGRAM_GET_PEER 46 -# define BIO_CTRL_DGRAM_SET_PEER 44/* Destination for the data */ +#define BIO_CTRL_DGRAM_GET_PEER 46 +#define BIO_CTRL_DGRAM_SET_PEER 44 /* Destination for the data */ -# define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT 45/* Next DTLS handshake timeout - * to adjust socket timeouts */ -# define BIO_CTRL_DGRAM_SET_DONT_FRAG 48 +#define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT 45 /* Next DTLS handshake timeout \ + * to adjust socket timeouts */ +#define BIO_CTRL_DGRAM_SET_DONT_FRAG 48 -# define BIO_CTRL_DGRAM_GET_MTU_OVERHEAD 49 +#define BIO_CTRL_DGRAM_GET_MTU_OVERHEAD 49 /* Deliberately outside of OPENSSL_NO_SCTP - used in bss_dgram.c */ -# define BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE 50 -# ifndef OPENSSL_NO_SCTP +#define BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE 50 +#ifndef OPENSSL_NO_SCTP /* SCTP stuff */ -# define BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY 51 -# define BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY 52 -# define BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD 53 -# define BIO_CTRL_DGRAM_SCTP_GET_SNDINFO 60 -# define BIO_CTRL_DGRAM_SCTP_SET_SNDINFO 61 -# define BIO_CTRL_DGRAM_SCTP_GET_RCVINFO 62 -# define BIO_CTRL_DGRAM_SCTP_SET_RCVINFO 63 -# define BIO_CTRL_DGRAM_SCTP_GET_PRINFO 64 -# define BIO_CTRL_DGRAM_SCTP_SET_PRINFO 65 -# define BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN 70 -# endif +#define BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY 51 +#define BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY 52 +#define BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD 53 +#define BIO_CTRL_DGRAM_SCTP_GET_SNDINFO 60 +#define BIO_CTRL_DGRAM_SCTP_SET_SNDINFO 61 +#define BIO_CTRL_DGRAM_SCTP_GET_RCVINFO 62 +#define BIO_CTRL_DGRAM_SCTP_SET_RCVINFO 63 +#define BIO_CTRL_DGRAM_SCTP_GET_PRINFO 64 +#define BIO_CTRL_DGRAM_SCTP_SET_PRINFO 65 +#define BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN 70 +#endif -# define BIO_CTRL_DGRAM_SET_PEEK_MODE 71 +#define BIO_CTRL_DGRAM_SET_PEEK_MODE 71 /* * internal BIO: @@ -165,78 +167,78 @@ extern "C" { * # define BIO_CTRL_CLEAR_KTLS_CTRL_MSG 75 */ -# define BIO_CTRL_GET_KTLS_SEND 73 -# define BIO_CTRL_GET_KTLS_RECV 76 +#define BIO_CTRL_GET_KTLS_SEND 73 +#define BIO_CTRL_GET_KTLS_RECV 76 -# define BIO_CTRL_DGRAM_SCTP_WAIT_FOR_DRY 77 -# define BIO_CTRL_DGRAM_SCTP_MSG_WAITING 78 +#define BIO_CTRL_DGRAM_SCTP_WAIT_FOR_DRY 77 +#define BIO_CTRL_DGRAM_SCTP_MSG_WAITING 78 /* BIO_f_prefix controls */ -# define BIO_CTRL_SET_PREFIX 79 -# define BIO_CTRL_SET_INDENT 80 -# define BIO_CTRL_GET_INDENT 81 +#define BIO_CTRL_SET_PREFIX 79 +#define BIO_CTRL_SET_INDENT 80 +#define BIO_CTRL_GET_INDENT 81 -# define BIO_CTRL_DGRAM_GET_LOCAL_ADDR_CAP 82 -# define BIO_CTRL_DGRAM_GET_LOCAL_ADDR_ENABLE 83 -# define BIO_CTRL_DGRAM_SET_LOCAL_ADDR_ENABLE 84 -# define BIO_CTRL_DGRAM_GET_EFFECTIVE_CAPS 85 -# define BIO_CTRL_DGRAM_GET_CAPS 86 -# define BIO_CTRL_DGRAM_SET_CAPS 87 -# define BIO_CTRL_DGRAM_GET_NO_TRUNC 88 -# define BIO_CTRL_DGRAM_SET_NO_TRUNC 89 +#define BIO_CTRL_DGRAM_GET_LOCAL_ADDR_CAP 82 +#define BIO_CTRL_DGRAM_GET_LOCAL_ADDR_ENABLE 83 +#define BIO_CTRL_DGRAM_SET_LOCAL_ADDR_ENABLE 84 +#define BIO_CTRL_DGRAM_GET_EFFECTIVE_CAPS 85 +#define BIO_CTRL_DGRAM_GET_CAPS 86 +#define BIO_CTRL_DGRAM_SET_CAPS 87 +#define BIO_CTRL_DGRAM_GET_NO_TRUNC 88 +#define BIO_CTRL_DGRAM_SET_NO_TRUNC 89 /* * internal BIO: * # define BIO_CTRL_SET_KTLS_TX_ZEROCOPY_SENDFILE 90 */ -# define BIO_CTRL_GET_RPOLL_DESCRIPTOR 91 -# define BIO_CTRL_GET_WPOLL_DESCRIPTOR 92 -# define BIO_CTRL_DGRAM_DETECT_PEER_ADDR 93 -# define BIO_CTRL_DGRAM_SET0_LOCAL_ADDR 94 +#define BIO_CTRL_GET_RPOLL_DESCRIPTOR 91 +#define BIO_CTRL_GET_WPOLL_DESCRIPTOR 92 +#define BIO_CTRL_DGRAM_DETECT_PEER_ADDR 93 +#define BIO_CTRL_DGRAM_SET0_LOCAL_ADDR 94 -# define BIO_DGRAM_CAP_NONE 0U -# define BIO_DGRAM_CAP_HANDLES_SRC_ADDR (1U << 0) -# define BIO_DGRAM_CAP_HANDLES_DST_ADDR (1U << 1) -# define BIO_DGRAM_CAP_PROVIDES_SRC_ADDR (1U << 2) -# define BIO_DGRAM_CAP_PROVIDES_DST_ADDR (1U << 3) +#define BIO_DGRAM_CAP_NONE 0U +#define BIO_DGRAM_CAP_HANDLES_SRC_ADDR (1U << 0) +#define BIO_DGRAM_CAP_HANDLES_DST_ADDR (1U << 1) +#define BIO_DGRAM_CAP_PROVIDES_SRC_ADDR (1U << 2) +#define BIO_DGRAM_CAP_PROVIDES_DST_ADDR (1U << 3) -# ifndef OPENSSL_NO_KTLS -# define BIO_get_ktls_send(b) \ - (BIO_ctrl(b, BIO_CTRL_GET_KTLS_SEND, 0, NULL) > 0) -# define BIO_get_ktls_recv(b) \ - (BIO_ctrl(b, BIO_CTRL_GET_KTLS_RECV, 0, NULL) > 0) -# else -# define BIO_get_ktls_send(b) (0) -# define BIO_get_ktls_recv(b) (0) -# endif +#ifndef OPENSSL_NO_KTLS +#define BIO_get_ktls_send(b) \ + (BIO_ctrl(b, BIO_CTRL_GET_KTLS_SEND, 0, NULL) > 0) +#define BIO_get_ktls_recv(b) \ + (BIO_ctrl(b, BIO_CTRL_GET_KTLS_RECV, 0, NULL) > 0) +#else +#define BIO_get_ktls_send(b) (0) +#define BIO_get_ktls_recv(b) (0) +#endif /* modifiers */ -# define BIO_FP_READ 0x02 -# define BIO_FP_WRITE 0x04 -# define BIO_FP_APPEND 0x08 -# define BIO_FP_TEXT 0x10 +#define BIO_FP_READ 0x02 +#define BIO_FP_WRITE 0x04 +#define BIO_FP_APPEND 0x08 +#define BIO_FP_TEXT 0x10 -# define BIO_FLAGS_READ 0x01 -# define BIO_FLAGS_WRITE 0x02 -# define BIO_FLAGS_IO_SPECIAL 0x04 -# define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) -# define BIO_FLAGS_SHOULD_RETRY 0x08 -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#define BIO_FLAGS_READ 0x01 +#define BIO_FLAGS_WRITE 0x02 +#define BIO_FLAGS_IO_SPECIAL 0x04 +#define BIO_FLAGS_RWS (BIO_FLAGS_READ | BIO_FLAGS_WRITE | BIO_FLAGS_IO_SPECIAL) +#define BIO_FLAGS_SHOULD_RETRY 0x08 +#ifndef OPENSSL_NO_DEPRECATED_3_0 /* This #define was replaced by an internal constant and should not be used. */ -# define BIO_FLAGS_UPLINK 0 -# endif +#define BIO_FLAGS_UPLINK 0 +#endif -# define BIO_FLAGS_BASE64_NO_NL 0x100 +#define BIO_FLAGS_BASE64_NO_NL 0x100 /* * This is used with memory BIOs: * BIO_FLAGS_MEM_RDONLY means we shouldn't free up or change the data in any way; * BIO_FLAGS_NONCLEAR_RST means we shouldn't clear data on reset. */ -# define BIO_FLAGS_MEM_RDONLY 0x200 -# define BIO_FLAGS_NONCLEAR_RST 0x400 -# define BIO_FLAGS_IN_EOF 0x800 +#define BIO_FLAGS_MEM_RDONLY 0x200 +#define BIO_FLAGS_NONCLEAR_RST 0x400 +#define BIO_FLAGS_IN_EOF 0x800 /* the BIO FLAGS values 0x1000 to 0x8000 are reserved for internal KTLS flags */ @@ -248,26 +250,26 @@ void BIO_set_flags(BIO *b, int flags); int BIO_test_flags(const BIO *b, int flags); void BIO_clear_flags(BIO *b, int flags); -# define BIO_get_flags(b) BIO_test_flags(b, ~(0x0)) -# define BIO_set_retry_special(b) \ - BIO_set_flags(b, (BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY)) -# define BIO_set_retry_read(b) \ - BIO_set_flags(b, (BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)) -# define BIO_set_retry_write(b) \ - BIO_set_flags(b, (BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY)) +#define BIO_get_flags(b) BIO_test_flags(b, ~(0x0)) +#define BIO_set_retry_special(b) \ + BIO_set_flags(b, (BIO_FLAGS_IO_SPECIAL | BIO_FLAGS_SHOULD_RETRY)) +#define BIO_set_retry_read(b) \ + BIO_set_flags(b, (BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY)) +#define BIO_set_retry_write(b) \ + BIO_set_flags(b, (BIO_FLAGS_WRITE | BIO_FLAGS_SHOULD_RETRY)) /* These are normally used internally in BIOs */ -# define BIO_clear_retry_flags(b) \ - BIO_clear_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) -# define BIO_get_retry_flags(b) \ - BIO_test_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) +#define BIO_clear_retry_flags(b) \ + BIO_clear_flags(b, (BIO_FLAGS_RWS | BIO_FLAGS_SHOULD_RETRY)) +#define BIO_get_retry_flags(b) \ + BIO_test_flags(b, (BIO_FLAGS_RWS | BIO_FLAGS_SHOULD_RETRY)) /* These should be used by the application to tell why we should retry */ -# define BIO_should_read(a) BIO_test_flags(a, BIO_FLAGS_READ) -# define BIO_should_write(a) BIO_test_flags(a, BIO_FLAGS_WRITE) -# define BIO_should_io_special(a) BIO_test_flags(a, BIO_FLAGS_IO_SPECIAL) -# define BIO_retry_type(a) BIO_test_flags(a, BIO_FLAGS_RWS) -# define BIO_should_retry(a) BIO_test_flags(a, BIO_FLAGS_SHOULD_RETRY) +#define BIO_should_read(a) BIO_test_flags(a, BIO_FLAGS_READ) +#define BIO_should_write(a) BIO_test_flags(a, BIO_FLAGS_WRITE) +#define BIO_should_io_special(a) BIO_test_flags(a, BIO_FLAGS_IO_SPECIAL) +#define BIO_retry_type(a) BIO_test_flags(a, BIO_FLAGS_RWS) +#define BIO_should_retry(a) BIO_test_flags(a, BIO_FLAGS_SHOULD_RETRY) /* * The next three are used in conjunction with the BIO_should_io_special() @@ -279,48 +281,48 @@ void BIO_clear_flags(BIO *b, int flags); /* * Returned from the SSL bio when the certificate retrieval code had an error */ -# define BIO_RR_SSL_X509_LOOKUP 0x01 +#define BIO_RR_SSL_X509_LOOKUP 0x01 /* Returned from the connect BIO when a connect would have blocked */ -# define BIO_RR_CONNECT 0x02 +#define BIO_RR_CONNECT 0x02 /* Returned from the accept BIO when an accept would have blocked */ -# define BIO_RR_ACCEPT 0x03 +#define BIO_RR_ACCEPT 0x03 /* These are passed by the BIO callback */ -# define BIO_CB_FREE 0x01 -# define BIO_CB_READ 0x02 -# define BIO_CB_WRITE 0x03 -# define BIO_CB_PUTS 0x04 -# define BIO_CB_GETS 0x05 -# define BIO_CB_CTRL 0x06 -# define BIO_CB_RECVMMSG 0x07 -# define BIO_CB_SENDMMSG 0x08 +#define BIO_CB_FREE 0x01 +#define BIO_CB_READ 0x02 +#define BIO_CB_WRITE 0x03 +#define BIO_CB_PUTS 0x04 +#define BIO_CB_GETS 0x05 +#define BIO_CB_CTRL 0x06 +#define BIO_CB_RECVMMSG 0x07 +#define BIO_CB_SENDMMSG 0x08 /* * The callback is called before and after the underling operation, The * BIO_CB_RETURN flag indicates if it is after the call */ -# define BIO_CB_RETURN 0x80 -# define BIO_CB_return(a) ((a)|BIO_CB_RETURN) -# define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) -# define BIO_cb_post(a) ((a)&BIO_CB_RETURN) +#define BIO_CB_RETURN 0x80 +#define BIO_CB_return(a) ((a) | BIO_CB_RETURN) +#define BIO_cb_pre(a) (!((a) & BIO_CB_RETURN)) +#define BIO_cb_post(a) ((a) & BIO_CB_RETURN) -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 typedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi, - long argl, long ret); + long argl, long ret); OSSL_DEPRECATEDIN_3_0 BIO_callback_fn BIO_get_callback(const BIO *b); OSSL_DEPRECATEDIN_3_0 void BIO_set_callback(BIO *b, BIO_callback_fn callback); OSSL_DEPRECATEDIN_3_0 long BIO_debug_callback(BIO *bio, int cmd, - const char *argp, int argi, - long argl, long ret); -# endif + const char *argp, int argi, + long argl, long ret); +#endif typedef long (*BIO_callback_fn_ex)(BIO *b, int oper, const char *argp, - size_t len, int argi, - long argl, int ret, size_t *processed); + size_t len, int argi, + long argl, int ret, size_t *processed); BIO_callback_fn_ex BIO_get_callback_ex(const BIO *b); void BIO_set_callback_ex(BIO *b, BIO_callback_fn_ex callback); long BIO_debug_callback_ex(BIO *bio, int oper, const char *argp, size_t len, - int argi, long argl, int ret, size_t *processed); + int argi, long argl, int ret, size_t *processed); char *BIO_get_callback_arg(const BIO *b); void BIO_set_callback_arg(BIO *b, char *arg); @@ -331,8 +333,9 @@ const char *BIO_method_name(const BIO *b); int BIO_method_type(const BIO *b); typedef int BIO_info_cb(BIO *, int, int); -typedef BIO_info_cb bio_info_cb; /* backward compatibility */ +typedef BIO_info_cb bio_info_cb; /* backward compatibility */ +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(BIO, BIO, BIO) #define sk_BIO_num(sk) OPENSSL_sk_num(ossl_check_const_BIO_sk_type(sk)) #define sk_BIO_value(sk, idx) ((BIO *)OPENSSL_sk_value(ossl_check_const_BIO_sk_type(sk), (idx))) @@ -360,16 +363,16 @@ SKM_DEFINE_STACK_OF_INTERNAL(BIO, BIO, BIO) #define sk_BIO_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(BIO) *)OPENSSL_sk_deep_copy(ossl_check_const_BIO_sk_type(sk), ossl_check_BIO_copyfunc_type(copyfunc), ossl_check_BIO_freefunc_type(freefunc))) #define sk_BIO_set_cmp_func(sk, cmp) ((sk_BIO_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_BIO_sk_type(sk), ossl_check_BIO_compfunc_type(cmp))) - +/* clang-format on */ /* Prefix and suffix callback in ASN1 BIO */ -typedef int asn1_ps_func (BIO *b, unsigned char **pbuf, int *plen, - void *parg); +typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, + void *parg); -typedef void (*BIO_dgram_sctp_notification_handler_fn) (BIO *b, - void *context, - void *buf); -# ifndef OPENSSL_NO_SCTP +typedef void (*BIO_dgram_sctp_notification_handler_fn)(BIO *b, + void *context, + void *buf); +#ifndef OPENSSL_NO_SCTP /* SCTP parameter structs */ struct bio_dgram_sctp_sndinfo { uint16_t snd_sid; @@ -392,7 +395,7 @@ struct bio_dgram_sctp_prinfo { uint16_t pr_policy; uint32_t pr_value; }; -# endif +#endif /* BIO_sendmmsg/BIO_recvmmsg-related definitions */ typedef struct bio_msg_st { @@ -403,24 +406,24 @@ typedef struct bio_msg_st { } BIO_MSG; typedef struct bio_mmsg_cb_args_st { - BIO_MSG *msg; - size_t stride, num_msg; - uint64_t flags; - size_t *msgs_processed; + BIO_MSG *msg; + size_t stride, num_msg; + uint64_t flags; + size_t *msgs_processed; } BIO_MMSG_CB_ARGS; -#define BIO_POLL_DESCRIPTOR_TYPE_NONE 0 -#define BIO_POLL_DESCRIPTOR_TYPE_SOCK_FD 1 -#define BIO_POLL_DESCRIPTOR_TYPE_SSL 2 -#define BIO_POLL_DESCRIPTOR_CUSTOM_START 8192 +#define BIO_POLL_DESCRIPTOR_TYPE_NONE 0 +#define BIO_POLL_DESCRIPTOR_TYPE_SOCK_FD 1 +#define BIO_POLL_DESCRIPTOR_TYPE_SSL 2 +#define BIO_POLL_DESCRIPTOR_CUSTOM_START 8192 typedef struct bio_poll_descriptor_st { uint32_t type; union { - int fd; - void *custom; - uintptr_t custom_ui; - SSL *ssl; + int fd; + void *custom; + uintptr_t custom_ui; + SSL *ssl; } value; } BIO_POLL_DESCRIPTOR; @@ -428,167 +431,167 @@ typedef struct bio_poll_descriptor_st { * #define BIO_CONN_get_param_hostname BIO_ctrl */ -# define BIO_C_SET_CONNECT 100 -# define BIO_C_DO_STATE_MACHINE 101 -# define BIO_C_SET_NBIO 102 +#define BIO_C_SET_CONNECT 100 +#define BIO_C_DO_STATE_MACHINE 101 +#define BIO_C_SET_NBIO 102 /* # define BIO_C_SET_PROXY_PARAM 103 */ -# define BIO_C_SET_FD 104 -# define BIO_C_GET_FD 105 -# define BIO_C_SET_FILE_PTR 106 -# define BIO_C_GET_FILE_PTR 107 -# define BIO_C_SET_FILENAME 108 -# define BIO_C_SET_SSL 109 -# define BIO_C_GET_SSL 110 -# define BIO_C_SET_MD 111 -# define BIO_C_GET_MD 112 -# define BIO_C_GET_CIPHER_STATUS 113 -# define BIO_C_SET_BUF_MEM 114 -# define BIO_C_GET_BUF_MEM_PTR 115 -# define BIO_C_GET_BUFF_NUM_LINES 116 -# define BIO_C_SET_BUFF_SIZE 117 -# define BIO_C_SET_ACCEPT 118 -# define BIO_C_SSL_MODE 119 -# define BIO_C_GET_MD_CTX 120 +#define BIO_C_SET_FD 104 +#define BIO_C_GET_FD 105 +#define BIO_C_SET_FILE_PTR 106 +#define BIO_C_GET_FILE_PTR 107 +#define BIO_C_SET_FILENAME 108 +#define BIO_C_SET_SSL 109 +#define BIO_C_GET_SSL 110 +#define BIO_C_SET_MD 111 +#define BIO_C_GET_MD 112 +#define BIO_C_GET_CIPHER_STATUS 113 +#define BIO_C_SET_BUF_MEM 114 +#define BIO_C_GET_BUF_MEM_PTR 115 +#define BIO_C_GET_BUFF_NUM_LINES 116 +#define BIO_C_SET_BUFF_SIZE 117 +#define BIO_C_SET_ACCEPT 118 +#define BIO_C_SSL_MODE 119 +#define BIO_C_GET_MD_CTX 120 /* # define BIO_C_GET_PROXY_PARAM 121 */ -# define BIO_C_SET_BUFF_READ_DATA 122/* data to read first */ -# define BIO_C_GET_CONNECT 123 -# define BIO_C_GET_ACCEPT 124 -# define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 -# define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 -# define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 -# define BIO_C_FILE_SEEK 128 -# define BIO_C_GET_CIPHER_CTX 129 -# define BIO_C_SET_BUF_MEM_EOF_RETURN 130/* return end of input - * value */ -# define BIO_C_SET_BIND_MODE 131 -# define BIO_C_GET_BIND_MODE 132 -# define BIO_C_FILE_TELL 133 -# define BIO_C_GET_SOCKS 134 -# define BIO_C_SET_SOCKS 135 +#define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */ +#define BIO_C_GET_CONNECT 123 +#define BIO_C_GET_ACCEPT 124 +#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 +#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 +#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 +#define BIO_C_FILE_SEEK 128 +#define BIO_C_GET_CIPHER_CTX 129 +#define BIO_C_SET_BUF_MEM_EOF_RETURN 130 /* return end of input \ + * value */ +#define BIO_C_SET_BIND_MODE 131 +#define BIO_C_GET_BIND_MODE 132 +#define BIO_C_FILE_TELL 133 +#define BIO_C_GET_SOCKS 134 +#define BIO_C_SET_SOCKS 135 -# define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ -# define BIO_C_GET_WRITE_BUF_SIZE 137 -# define BIO_C_MAKE_BIO_PAIR 138 -# define BIO_C_DESTROY_BIO_PAIR 139 -# define BIO_C_GET_WRITE_GUARANTEE 140 -# define BIO_C_GET_READ_REQUEST 141 -# define BIO_C_SHUTDOWN_WR 142 -# define BIO_C_NREAD0 143 -# define BIO_C_NREAD 144 -# define BIO_C_NWRITE0 145 -# define BIO_C_NWRITE 146 -# define BIO_C_RESET_READ_REQUEST 147 -# define BIO_C_SET_MD_CTX 148 +#define BIO_C_SET_WRITE_BUF_SIZE 136 /* for BIO_s_bio */ +#define BIO_C_GET_WRITE_BUF_SIZE 137 +#define BIO_C_MAKE_BIO_PAIR 138 +#define BIO_C_DESTROY_BIO_PAIR 139 +#define BIO_C_GET_WRITE_GUARANTEE 140 +#define BIO_C_GET_READ_REQUEST 141 +#define BIO_C_SHUTDOWN_WR 142 +#define BIO_C_NREAD0 143 +#define BIO_C_NREAD 144 +#define BIO_C_NWRITE0 145 +#define BIO_C_NWRITE 146 +#define BIO_C_RESET_READ_REQUEST 147 +#define BIO_C_SET_MD_CTX 148 -# define BIO_C_SET_PREFIX 149 -# define BIO_C_GET_PREFIX 150 -# define BIO_C_SET_SUFFIX 151 -# define BIO_C_GET_SUFFIX 152 +#define BIO_C_SET_PREFIX 149 +#define BIO_C_GET_PREFIX 150 +#define BIO_C_SET_SUFFIX 151 +#define BIO_C_GET_SUFFIX 152 -# define BIO_C_SET_EX_ARG 153 -# define BIO_C_GET_EX_ARG 154 +#define BIO_C_SET_EX_ARG 153 +#define BIO_C_GET_EX_ARG 154 -# define BIO_C_SET_CONNECT_MODE 155 +#define BIO_C_SET_CONNECT_MODE 155 -# define BIO_C_SET_TFO 156 /* like BIO_C_SET_NBIO */ +#define BIO_C_SET_TFO 156 /* like BIO_C_SET_NBIO */ -# define BIO_C_SET_SOCK_TYPE 157 -# define BIO_C_GET_SOCK_TYPE 158 -# define BIO_C_GET_DGRAM_BIO 159 +#define BIO_C_SET_SOCK_TYPE 157 +#define BIO_C_GET_SOCK_TYPE 158 +#define BIO_C_GET_DGRAM_BIO 159 -# define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg) -# define BIO_get_app_data(s) BIO_get_ex_data(s,0) +#define BIO_set_app_data(s, arg) BIO_set_ex_data(s, 0, arg) +#define BIO_get_app_data(s) BIO_get_ex_data(s, 0) -# define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) -# define BIO_set_tfo(b,n) BIO_ctrl(b,BIO_C_SET_TFO,(n),NULL) +#define BIO_set_nbio(b, n) BIO_ctrl(b, BIO_C_SET_NBIO, (n), NULL) +#define BIO_set_tfo(b, n) BIO_ctrl(b, BIO_C_SET_TFO, (n), NULL) -# ifndef OPENSSL_NO_SOCK +#ifndef OPENSSL_NO_SOCK /* IP families we support, for BIO_s_connect() and BIO_s_accept() */ /* Note: the underlying operating system may not support some of them */ -# define BIO_FAMILY_IPV4 4 -# define BIO_FAMILY_IPV6 6 -# define BIO_FAMILY_IPANY 256 +#define BIO_FAMILY_IPV4 4 +#define BIO_FAMILY_IPV6 6 +#define BIO_FAMILY_IPANY 256 /* BIO_s_connect() */ -# define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0, \ - (char *)(name)) -# define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1, \ - (char *)(port)) -# define BIO_set_conn_address(b,addr) BIO_ctrl(b,BIO_C_SET_CONNECT,2, \ - (char *)(addr)) -# define BIO_set_conn_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,f) -# define BIO_get_conn_hostname(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)) -# define BIO_get_conn_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)) -# define BIO_get_conn_address(b) ((const BIO_ADDR *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2)) -# define BIO_get_conn_ip_family(b) BIO_ctrl(b,BIO_C_GET_CONNECT,3,NULL) -# define BIO_get_conn_mode(b) BIO_ctrl(b,BIO_C_GET_CONNECT,4,NULL) -# define BIO_set_conn_mode(b,n) BIO_ctrl(b,BIO_C_SET_CONNECT_MODE,(n),NULL) -# define BIO_set_sock_type(b,t) BIO_ctrl(b,BIO_C_SET_SOCK_TYPE,(t),NULL) -# define BIO_get_sock_type(b) BIO_ctrl(b,BIO_C_GET_SOCK_TYPE,0,NULL) -# define BIO_get0_dgram_bio(b, p) BIO_ctrl(b,BIO_C_GET_DGRAM_BIO,0,(void *)(BIO **)(p)) +#define BIO_set_conn_hostname(b, name) BIO_ctrl(b, BIO_C_SET_CONNECT, 0, \ + (char *)(name)) +#define BIO_set_conn_port(b, port) BIO_ctrl(b, BIO_C_SET_CONNECT, 1, \ + (char *)(port)) +#define BIO_set_conn_address(b, addr) BIO_ctrl(b, BIO_C_SET_CONNECT, 2, \ + (char *)(addr)) +#define BIO_set_conn_ip_family(b, f) BIO_int_ctrl(b, BIO_C_SET_CONNECT, 3, f) +#define BIO_get_conn_hostname(b) ((const char *)BIO_ptr_ctrl(b, BIO_C_GET_CONNECT, 0)) +#define BIO_get_conn_port(b) ((const char *)BIO_ptr_ctrl(b, BIO_C_GET_CONNECT, 1)) +#define BIO_get_conn_address(b) ((const BIO_ADDR *)BIO_ptr_ctrl(b, BIO_C_GET_CONNECT, 2)) +#define BIO_get_conn_ip_family(b) BIO_ctrl(b, BIO_C_GET_CONNECT, 3, NULL) +#define BIO_get_conn_mode(b) BIO_ctrl(b, BIO_C_GET_CONNECT, 4, NULL) +#define BIO_set_conn_mode(b, n) BIO_ctrl(b, BIO_C_SET_CONNECT_MODE, (n), NULL) +#define BIO_set_sock_type(b, t) BIO_ctrl(b, BIO_C_SET_SOCK_TYPE, (t), NULL) +#define BIO_get_sock_type(b) BIO_ctrl(b, BIO_C_GET_SOCK_TYPE, 0, NULL) +#define BIO_get0_dgram_bio(b, p) BIO_ctrl(b, BIO_C_GET_DGRAM_BIO, 0, (void *)(BIO **)(p)) /* BIO_s_accept() */ -# define BIO_set_accept_name(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0, \ - (char *)(name)) -# define BIO_set_accept_port(b,port) BIO_ctrl(b,BIO_C_SET_ACCEPT,1, \ - (char *)(port)) -# define BIO_get_accept_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)) -# define BIO_get_accept_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,1)) -# define BIO_get_peer_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,2)) -# define BIO_get_peer_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,3)) +#define BIO_set_accept_name(b, name) BIO_ctrl(b, BIO_C_SET_ACCEPT, 0, \ + (char *)(name)) +#define BIO_set_accept_port(b, port) BIO_ctrl(b, BIO_C_SET_ACCEPT, 1, \ + (char *)(port)) +#define BIO_get_accept_name(b) ((const char *)BIO_ptr_ctrl(b, BIO_C_GET_ACCEPT, 0)) +#define BIO_get_accept_port(b) ((const char *)BIO_ptr_ctrl(b, BIO_C_GET_ACCEPT, 1)) +#define BIO_get_peer_name(b) ((const char *)BIO_ptr_ctrl(b, BIO_C_GET_ACCEPT, 2)) +#define BIO_get_peer_port(b) ((const char *)BIO_ptr_ctrl(b, BIO_C_GET_ACCEPT, 3)) /* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ -# define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(n)?(void *)"a":NULL) -# define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,3, \ - (char *)(bio)) -# define BIO_set_accept_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_ACCEPT,4,f) -# define BIO_get_accept_ip_family(b) BIO_ctrl(b,BIO_C_GET_ACCEPT,4,NULL) -# define BIO_set_tfo_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,5,(n)?(void *)"a":NULL) +#define BIO_set_nbio_accept(b, n) BIO_ctrl(b, BIO_C_SET_ACCEPT, 2, (n) ? (void *)"a" : NULL) +#define BIO_set_accept_bios(b, bio) BIO_ctrl(b, BIO_C_SET_ACCEPT, 3, \ + (char *)(bio)) +#define BIO_set_accept_ip_family(b, f) BIO_int_ctrl(b, BIO_C_SET_ACCEPT, 4, f) +#define BIO_get_accept_ip_family(b) BIO_ctrl(b, BIO_C_GET_ACCEPT, 4, NULL) +#define BIO_set_tfo_accept(b, n) BIO_ctrl(b, BIO_C_SET_ACCEPT, 5, (n) ? (void *)"a" : NULL) /* Aliases kept for backward compatibility */ -# define BIO_BIND_NORMAL 0 -# define BIO_BIND_REUSEADDR BIO_SOCK_REUSEADDR -# define BIO_BIND_REUSEADDR_IF_UNUSED BIO_SOCK_REUSEADDR -# define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) -# define BIO_get_bind_mode(b) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) -# endif /* OPENSSL_NO_SOCK */ +#define BIO_BIND_NORMAL 0 +#define BIO_BIND_REUSEADDR BIO_SOCK_REUSEADDR +#define BIO_BIND_REUSEADDR_IF_UNUSED BIO_SOCK_REUSEADDR +#define BIO_set_bind_mode(b, mode) BIO_ctrl(b, BIO_C_SET_BIND_MODE, mode, NULL) +#define BIO_get_bind_mode(b) BIO_ctrl(b, BIO_C_GET_BIND_MODE, 0, NULL) +#endif /* OPENSSL_NO_SOCK */ -# define BIO_do_connect(b) BIO_do_handshake(b) -# define BIO_do_accept(b) BIO_do_handshake(b) +#define BIO_do_connect(b) BIO_do_handshake(b) +#define BIO_do_accept(b) BIO_do_handshake(b) -# define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) +#define BIO_do_handshake(b) BIO_ctrl(b, BIO_C_DO_STATE_MACHINE, 0, NULL) /* BIO_s_datagram(), BIO_s_fd(), BIO_s_socket(), BIO_s_accept() and BIO_s_connect() */ -# define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd) -# define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)(c)) +#define BIO_set_fd(b, fd, c) BIO_int_ctrl(b, BIO_C_SET_FD, c, fd) +#define BIO_get_fd(b, c) BIO_ctrl(b, BIO_C_GET_FD, 0, (char *)(c)) /* BIO_s_file() */ -# define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)(fp)) -# define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)(fpp)) +#define BIO_set_fp(b, fp, c) BIO_ctrl(b, BIO_C_SET_FILE_PTR, c, (char *)(fp)) +#define BIO_get_fp(b, fpp) BIO_ctrl(b, BIO_C_GET_FILE_PTR, 0, (char *)(fpp)) /* BIO_s_fd() and BIO_s_file() */ -# define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) -# define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) +#define BIO_seek(b, ofs) (int)BIO_ctrl(b, BIO_C_FILE_SEEK, ofs, NULL) +#define BIO_tell(b) (int)BIO_ctrl(b, BIO_C_FILE_TELL, 0, NULL) /* * name is cast to lose const, but might be better to route through a * function so we can do it safely */ -# ifdef CONST_STRICT +#ifdef CONST_STRICT /* * If you are wondering why this isn't defined, its because CONST_STRICT is * purely a compile-time kludge to allow const to be checked. */ int BIO_read_filename(BIO *b, const char *name); -# else -# define BIO_read_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ - BIO_CLOSE|BIO_FP_READ,(char *)(name)) -# endif -# define BIO_write_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ - BIO_CLOSE|BIO_FP_WRITE,name) -# define BIO_append_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ - BIO_CLOSE|BIO_FP_APPEND,name) -# define BIO_rw_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ - BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) +#else +#define BIO_read_filename(b, name) (int)BIO_ctrl(b, BIO_C_SET_FILENAME, \ + BIO_CLOSE | BIO_FP_READ, (char *)(name)) +#endif +#define BIO_write_filename(b, name) (int)BIO_ctrl(b, BIO_C_SET_FILENAME, \ + BIO_CLOSE | BIO_FP_WRITE, name) +#define BIO_append_filename(b, name) (int)BIO_ctrl(b, BIO_C_SET_FILENAME, \ + BIO_CLOSE | BIO_FP_APPEND, name) +#define BIO_rw_filename(b, name) (int)BIO_ctrl(b, BIO_C_SET_FILENAME, \ + BIO_CLOSE | BIO_FP_READ | BIO_FP_WRITE, name) /* * WARNING WARNING, this ups the reference count on the read bio of the SSL @@ -596,111 +599,111 @@ int BIO_read_filename(BIO *b, const char *name); * next_bio field in the bio. So when you free the BIO, make sure you are * doing a BIO_free_all() to catch the underlying BIO. */ -# define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)(ssl)) -# define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)(sslp)) -# define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL) -# define BIO_set_ssl_renegotiate_bytes(b,num) \ - BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL) -# define BIO_get_num_renegotiates(b) \ - BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL) -# define BIO_set_ssl_renegotiate_timeout(b,seconds) \ - BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL) +#define BIO_set_ssl(b, ssl, c) BIO_ctrl(b, BIO_C_SET_SSL, c, (char *)(ssl)) +#define BIO_get_ssl(b, sslp) BIO_ctrl(b, BIO_C_GET_SSL, 0, (char *)(sslp)) +#define BIO_set_ssl_mode(b, client) BIO_ctrl(b, BIO_C_SSL_MODE, client, NULL) +#define BIO_set_ssl_renegotiate_bytes(b, num) \ + BIO_ctrl(b, BIO_C_SET_SSL_RENEGOTIATE_BYTES, num, NULL) +#define BIO_get_num_renegotiates(b) \ + BIO_ctrl(b, BIO_C_GET_SSL_NUM_RENEGOTIATES, 0, NULL) +#define BIO_set_ssl_renegotiate_timeout(b, seconds) \ + BIO_ctrl(b, BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT, seconds, NULL) /* defined in evp.h */ /* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)(md)) */ -# define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)(pp)) -# define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)(bm)) -# define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0, \ - (char *)(pp)) -# define BIO_set_mem_eof_return(b,v) \ - BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) +#define BIO_get_mem_data(b, pp) BIO_ctrl(b, BIO_CTRL_INFO, 0, (char *)(pp)) +#define BIO_set_mem_buf(b, bm, c) BIO_ctrl(b, BIO_C_SET_BUF_MEM, c, (char *)(bm)) +#define BIO_get_mem_ptr(b, pp) BIO_ctrl(b, BIO_C_GET_BUF_MEM_PTR, 0, \ + (char *)(pp)) +#define BIO_set_mem_eof_return(b, v) \ + BIO_ctrl(b, BIO_C_SET_BUF_MEM_EOF_RETURN, v, NULL) /* For the BIO_f_buffer() type */ -# define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) -# define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL) -# define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0) -# define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1) -# define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf) +#define BIO_get_buffer_num_lines(b) BIO_ctrl(b, BIO_C_GET_BUFF_NUM_LINES, 0, NULL) +#define BIO_set_buffer_size(b, size) BIO_ctrl(b, BIO_C_SET_BUFF_SIZE, size, NULL) +#define BIO_set_read_buffer_size(b, size) BIO_int_ctrl(b, BIO_C_SET_BUFF_SIZE, size, 0) +#define BIO_set_write_buffer_size(b, size) BIO_int_ctrl(b, BIO_C_SET_BUFF_SIZE, size, 1) +#define BIO_set_buffer_read_data(b, buf, num) BIO_ctrl(b, BIO_C_SET_BUFF_READ_DATA, num, buf) /* Don't use the next one unless you know what you are doing :-) */ -# define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret)) +#define BIO_dup_state(b, ret) BIO_ctrl(b, BIO_CTRL_DUP, 0, (char *)(ret)) -# define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL) -# define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL) -# define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL) -# define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) -# define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) -# define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) +#define BIO_reset(b) (int)BIO_ctrl(b, BIO_CTRL_RESET, 0, NULL) +#define BIO_eof(b) (int)BIO_ctrl(b, BIO_CTRL_EOF, 0, NULL) +#define BIO_set_close(b, c) (int)BIO_ctrl(b, BIO_CTRL_SET_CLOSE, (c), NULL) +#define BIO_get_close(b) (int)BIO_ctrl(b, BIO_CTRL_GET_CLOSE, 0, NULL) +#define BIO_pending(b) (int)BIO_ctrl(b, BIO_CTRL_PENDING, 0, NULL) +#define BIO_wpending(b) (int)BIO_ctrl(b, BIO_CTRL_WPENDING, 0, NULL) /* ...pending macros have inappropriate return type */ size_t BIO_ctrl_pending(BIO *b); size_t BIO_ctrl_wpending(BIO *b); -# define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) -# define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \ - cbp) -# define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb) +#define BIO_flush(b) (int)BIO_ctrl(b, BIO_CTRL_FLUSH, 0, NULL) +#define BIO_get_info_callback(b, cbp) (int)BIO_ctrl(b, BIO_CTRL_GET_CALLBACK, 0, \ + cbp) +#define BIO_set_info_callback(b, cb) (int)BIO_callback_ctrl(b, BIO_CTRL_SET_CALLBACK, cb) /* For the BIO_f_buffer() type */ -# define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) -# define BIO_buffer_peek(b,s,l) BIO_ctrl(b,BIO_CTRL_PEEK,(l),(s)) +#define BIO_buffer_get_num_lines(b) BIO_ctrl(b, BIO_CTRL_GET, 0, NULL) +#define BIO_buffer_peek(b, s, l) BIO_ctrl(b, BIO_CTRL_PEEK, (l), (s)) /* For BIO_s_bio() */ -# define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL) -# define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) -# define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) -# define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) -# define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL) +#define BIO_set_write_buf_size(b, size) (int)BIO_ctrl(b, BIO_C_SET_WRITE_BUF_SIZE, size, NULL) +#define BIO_get_write_buf_size(b, size) (size_t)BIO_ctrl(b, BIO_C_GET_WRITE_BUF_SIZE, size, NULL) +#define BIO_make_bio_pair(b1, b2) (int)BIO_ctrl(b1, BIO_C_MAKE_BIO_PAIR, 0, b2) +#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b, BIO_C_DESTROY_BIO_PAIR, 0, NULL) +#define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL) /* macros with inappropriate type -- but ...pending macros use int too: */ -# define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) -# define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) +#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b, BIO_C_GET_WRITE_GUARANTEE, 0, NULL) +#define BIO_get_read_request(b) (int)BIO_ctrl(b, BIO_C_GET_READ_REQUEST, 0, NULL) size_t BIO_ctrl_get_write_guarantee(BIO *b); size_t BIO_ctrl_get_read_request(BIO *b); int BIO_ctrl_reset_read_request(BIO *b); /* ctrl macros for dgram */ -# define BIO_ctrl_dgram_connect(b,peer) \ - (int)BIO_ctrl(b,BIO_CTRL_DGRAM_CONNECT,0, (char *)(peer)) -# define BIO_ctrl_set_connected(b,peer) \ - (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, 0, (char *)(peer)) -# define BIO_dgram_recv_timedout(b) \ - (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL) -# define BIO_dgram_send_timedout(b) \ - (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL) -# define BIO_dgram_get_peer(b,peer) \ - (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)(peer)) -# define BIO_dgram_set_peer(b,peer) \ - (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)(peer)) -# define BIO_dgram_detect_peer_addr(b,peer) \ - (int)BIO_ctrl(b, BIO_CTRL_DGRAM_DETECT_PEER_ADDR, 0, (char *)(peer)) -# define BIO_dgram_get_mtu_overhead(b) \ - (unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_MTU_OVERHEAD, 0, NULL) -# define BIO_dgram_get_local_addr_cap(b) \ - (int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_LOCAL_ADDR_CAP, 0, NULL) -# define BIO_dgram_get_local_addr_enable(b, penable) \ - (int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_LOCAL_ADDR_ENABLE, 0, (char *)(penable)) -# define BIO_dgram_set_local_addr_enable(b, enable) \ - (int)BIO_ctrl((b), BIO_CTRL_DGRAM_SET_LOCAL_ADDR_ENABLE, (enable), NULL) -# define BIO_dgram_get_effective_caps(b) \ - (uint32_t)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_EFFECTIVE_CAPS, 0, NULL) -# define BIO_dgram_get_caps(b) \ - (uint32_t)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_CAPS, 0, NULL) -# define BIO_dgram_set_caps(b, caps) \ - (int)BIO_ctrl((b), BIO_CTRL_DGRAM_SET_CAPS, (long)(caps), NULL) -# define BIO_dgram_get_no_trunc(b) \ - (unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_NO_TRUNC, 0, NULL) -# define BIO_dgram_set_no_trunc(b, enable) \ - (int)BIO_ctrl((b), BIO_CTRL_DGRAM_SET_NO_TRUNC, (enable), NULL) -# define BIO_dgram_get_mtu(b) \ - (unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_MTU, 0, NULL) -# define BIO_dgram_set_mtu(b, mtu) \ - (int)BIO_ctrl((b), BIO_CTRL_DGRAM_SET_MTU, (mtu), NULL) -# define BIO_dgram_set0_local_addr(b, addr) \ - (int)BIO_ctrl((b), BIO_CTRL_DGRAM_SET0_LOCAL_ADDR, 0, (addr)) +#define BIO_ctrl_dgram_connect(b, peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_CONNECT, 0, (char *)(peer)) +#define BIO_ctrl_set_connected(b, peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, 0, (char *)(peer)) +#define BIO_dgram_recv_timedout(b) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL) +#define BIO_dgram_send_timedout(b) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL) +#define BIO_dgram_get_peer(b, peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)(peer)) +#define BIO_dgram_set_peer(b, peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)(peer)) +#define BIO_dgram_detect_peer_addr(b, peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_DETECT_PEER_ADDR, 0, (char *)(peer)) +#define BIO_dgram_get_mtu_overhead(b) \ + (unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_MTU_OVERHEAD, 0, NULL) +#define BIO_dgram_get_local_addr_cap(b) \ + (int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_LOCAL_ADDR_CAP, 0, NULL) +#define BIO_dgram_get_local_addr_enable(b, penable) \ + (int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_LOCAL_ADDR_ENABLE, 0, (char *)(penable)) +#define BIO_dgram_set_local_addr_enable(b, enable) \ + (int)BIO_ctrl((b), BIO_CTRL_DGRAM_SET_LOCAL_ADDR_ENABLE, (enable), NULL) +#define BIO_dgram_get_effective_caps(b) \ + (uint32_t)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_EFFECTIVE_CAPS, 0, NULL) +#define BIO_dgram_get_caps(b) \ + (uint32_t)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_CAPS, 0, NULL) +#define BIO_dgram_set_caps(b, caps) \ + (int)BIO_ctrl((b), BIO_CTRL_DGRAM_SET_CAPS, (long)(caps), NULL) +#define BIO_dgram_get_no_trunc(b) \ + (unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_NO_TRUNC, 0, NULL) +#define BIO_dgram_set_no_trunc(b, enable) \ + (int)BIO_ctrl((b), BIO_CTRL_DGRAM_SET_NO_TRUNC, (enable), NULL) +#define BIO_dgram_get_mtu(b) \ + (unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_MTU, 0, NULL) +#define BIO_dgram_set_mtu(b, mtu) \ + (int)BIO_ctrl((b), BIO_CTRL_DGRAM_SET_MTU, (mtu), NULL) +#define BIO_dgram_set0_local_addr(b, addr) \ + (int)BIO_ctrl((b), BIO_CTRL_DGRAM_SET0_LOCAL_ADDR, 0, (addr)) /* ctrl macros for BIO_f_prefix */ -# define BIO_set_prefix(b,p) BIO_ctrl((b), BIO_CTRL_SET_PREFIX, 0, (void *)(p)) -# define BIO_set_indent(b,i) BIO_ctrl((b), BIO_CTRL_SET_INDENT, (i), NULL) -# define BIO_get_indent(b) BIO_ctrl((b), BIO_CTRL_GET_INDENT, 0, NULL) +#define BIO_set_prefix(b, p) BIO_ctrl((b), BIO_CTRL_SET_PREFIX, 0, (void *)(p)) +#define BIO_set_indent(b, i) BIO_ctrl((b), BIO_CTRL_SET_INDENT, (i), NULL) +#define BIO_get_indent(b) BIO_ctrl((b), BIO_CTRL_GET_INDENT, 0, NULL) #define BIO_get_ex_new_index(l, p, newf, dupf, freef) \ CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, l, p, newf, dupf, freef) @@ -711,20 +714,20 @@ uint64_t BIO_number_written(BIO *bio); /* For BIO_f_asn1() */ int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, - asn1_ps_func *prefix_free); + asn1_ps_func *prefix_free); int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, - asn1_ps_func **pprefix_free); + asn1_ps_func **pprefix_free); int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, - asn1_ps_func *suffix_free); + asn1_ps_func *suffix_free); int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, - asn1_ps_func **psuffix_free); + asn1_ps_func **psuffix_free); const BIO_METHOD *BIO_s_file(void); BIO *BIO_new_file(const char *filename, const char *mode); BIO *BIO_new_from_core_bio(OSSL_LIB_CTX *libctx, OSSL_CORE_BIO *corebio); -# ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_STDIO BIO *BIO_new_fp(FILE *stream, int close_flag); -# endif +#endif BIO *BIO_new_ex(OSSL_LIB_CTX *libctx, const BIO_METHOD *method); BIO *BIO_new(const BIO_METHOD *type); int BIO_free(BIO *a); @@ -739,15 +742,15 @@ int BIO_up_ref(BIO *a); int BIO_read(BIO *b, void *data, int dlen); int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes); __owur int BIO_recvmmsg(BIO *b, BIO_MSG *msg, - size_t stride, size_t num_msg, uint64_t flags, - size_t *msgs_processed); + size_t stride, size_t num_msg, uint64_t flags, + size_t *msgs_processed); int BIO_gets(BIO *bp, char *buf, int size); int BIO_get_line(BIO *bio, char *buf, int size); int BIO_write(BIO *b, const void *data, int dlen); int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written); __owur int BIO_sendmmsg(BIO *b, BIO_MSG *msg, - size_t stride, size_t num_msg, uint64_t flags, - size_t *msgs_processed); + size_t stride, size_t num_msg, uint64_t flags, + size_t *msgs_processed); __owur int BIO_get_rpoll_descriptor(BIO *b, BIO_POLL_DESCRIPTOR *desc); __owur int BIO_get_wpoll_descriptor(BIO *b, BIO_POLL_DESCRIPTOR *desc); int BIO_puts(BIO *bp, const char *buf); @@ -773,16 +776,16 @@ int BIO_nwrite0(BIO *bio, char **buf); int BIO_nwrite(BIO *bio, char **buf, int num); const BIO_METHOD *BIO_s_mem(void); -# ifndef OPENSSL_NO_DGRAM +#ifndef OPENSSL_NO_DGRAM const BIO_METHOD *BIO_s_dgram_mem(void); -# endif +#endif const BIO_METHOD *BIO_s_secmem(void); BIO *BIO_new_mem_buf(const void *buf, int len); -# ifndef OPENSSL_NO_SOCK +#ifndef OPENSSL_NO_SOCK const BIO_METHOD *BIO_s_socket(void); const BIO_METHOD *BIO_s_connect(void); const BIO_METHOD *BIO_s_accept(void); -# endif +#endif const BIO_METHOD *BIO_s_fd(void); const BIO_METHOD *BIO_s_log(void); const BIO_METHOD *BIO_s_bio(void); @@ -794,53 +797,53 @@ const BIO_METHOD *BIO_f_linebuffer(void); const BIO_METHOD *BIO_f_nbio_test(void); const BIO_METHOD *BIO_f_prefix(void); const BIO_METHOD *BIO_s_core(void); -# ifndef OPENSSL_NO_DGRAM +#ifndef OPENSSL_NO_DGRAM const BIO_METHOD *BIO_s_dgram_pair(void); const BIO_METHOD *BIO_s_datagram(void); int BIO_dgram_non_fatal_error(int error); BIO *BIO_new_dgram(int fd, int close_flag); -# ifndef OPENSSL_NO_SCTP +#ifndef OPENSSL_NO_SCTP const BIO_METHOD *BIO_s_datagram_sctp(void); BIO *BIO_new_dgram_sctp(int fd, int close_flag); int BIO_dgram_is_sctp(BIO *bio); int BIO_dgram_sctp_notification_cb(BIO *b, - BIO_dgram_sctp_notification_handler_fn handle_notifications, - void *context); + BIO_dgram_sctp_notification_handler_fn handle_notifications, + void *context); int BIO_dgram_sctp_wait_for_dry(BIO *b); int BIO_dgram_sctp_msg_waiting(BIO *b); -# endif -# endif +#endif +#endif -# ifndef OPENSSL_NO_SOCK +#ifndef OPENSSL_NO_SOCK int BIO_sock_should_retry(int i); int BIO_sock_non_fatal_error(int error); int BIO_err_is_non_fatal(unsigned int errcode); int BIO_socket_wait(int fd, int for_read, time_t max_time); -# endif +#endif int BIO_wait(BIO *bio, time_t max_time, unsigned int nap_milliseconds); int BIO_do_connect_retry(BIO *bio, int timeout, int nap_milliseconds); int BIO_fd_should_retry(int i); int BIO_fd_non_fatal_error(int error); -int BIO_dump_cb(int (*cb) (const void *data, size_t len, void *u), - void *u, const void *s, int len); -int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u), - void *u, const void *s, int len, int indent); +int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), + void *u, const void *s, int len); +int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), + void *u, const void *s, int len, int indent); int BIO_dump(BIO *b, const void *bytes, int len); int BIO_dump_indent(BIO *b, const void *bytes, int len, int indent); -# ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_STDIO int BIO_dump_fp(FILE *fp, const void *s, int len); int BIO_dump_indent_fp(FILE *fp, const void *s, int len, int indent); -# endif +#endif int BIO_hex_string(BIO *out, int indent, int width, const void *data, - int datalen); + int datalen); -# ifndef OPENSSL_NO_SOCK +#ifndef OPENSSL_NO_SOCK BIO_ADDR *BIO_ADDR_new(void); int BIO_ADDR_copy(BIO_ADDR *dst, const BIO_ADDR *src); BIO_ADDR *BIO_ADDR_dup(const BIO_ADDR *ap); int BIO_ADDR_rawmake(BIO_ADDR *ap, int family, - const void *where, size_t wherelen, unsigned short port); + const void *where, size_t wherelen, unsigned short port); void BIO_ADDR_free(BIO_ADDR *); void BIO_ADDR_clear(BIO_ADDR *ap); int BIO_ADDR_family(const BIO_ADDR *ap); @@ -858,34 +861,38 @@ const BIO_ADDR *BIO_ADDRINFO_address(const BIO_ADDRINFO *bai); void BIO_ADDRINFO_free(BIO_ADDRINFO *bai); enum BIO_hostserv_priorities { - BIO_PARSE_PRIO_HOST, BIO_PARSE_PRIO_SERV + BIO_PARSE_PRIO_HOST, + BIO_PARSE_PRIO_SERV }; int BIO_parse_hostserv(const char *hostserv, char **host, char **service, - enum BIO_hostserv_priorities hostserv_prio); + enum BIO_hostserv_priorities hostserv_prio); enum BIO_lookup_type { - BIO_LOOKUP_CLIENT, BIO_LOOKUP_SERVER + BIO_LOOKUP_CLIENT, + BIO_LOOKUP_SERVER }; int BIO_lookup(const char *host, const char *service, - enum BIO_lookup_type lookup_type, - int family, int socktype, BIO_ADDRINFO **res); + enum BIO_lookup_type lookup_type, + int family, int socktype, BIO_ADDRINFO **res); int BIO_lookup_ex(const char *host, const char *service, - int lookup_type, int family, int socktype, int protocol, - BIO_ADDRINFO **res); + int lookup_type, int family, int socktype, int protocol, + BIO_ADDRINFO **res); int BIO_sock_error(int sock); int BIO_socket_ioctl(int fd, long type, void *arg); int BIO_socket_nbio(int fd, int mode); int BIO_sock_init(void); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define BIO_sock_cleanup() while(0) continue -# endif +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define BIO_sock_cleanup() \ + while (0) \ + continue +#endif int BIO_set_tcp_ndelay(int sock, int turn_on); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 struct hostent *BIO_gethostbyname(const char *name); OSSL_DEPRECATEDIN_1_1_0 int BIO_get_port(const char *str, unsigned short *port_ptr); OSSL_DEPRECATEDIN_1_1_0 int BIO_get_host_ip(const char *str, unsigned char *ip); OSSL_DEPRECATEDIN_1_1_0 int BIO_get_accept_socket(char *host_port, int mode); OSSL_DEPRECATEDIN_1_1_0 int BIO_accept(int sock, char **ip_port); -# endif +#endif union BIO_sock_info_u { BIO_ADDR *addr; @@ -894,14 +901,14 @@ enum BIO_sock_info_type { BIO_SOCK_INFO_ADDRESS }; int BIO_sock_info(int sock, - enum BIO_sock_info_type type, union BIO_sock_info_u *info); + enum BIO_sock_info_type type, union BIO_sock_info_u *info); -# define BIO_SOCK_REUSEADDR 0x01 -# define BIO_SOCK_V6_ONLY 0x02 -# define BIO_SOCK_KEEPALIVE 0x04 -# define BIO_SOCK_NONBLOCK 0x08 -# define BIO_SOCK_NODELAY 0x10 -# define BIO_SOCK_TFO 0x20 +#define BIO_SOCK_REUSEADDR 0x01 +#define BIO_SOCK_V6_ONLY 0x02 +#define BIO_SOCK_KEEPALIVE 0x04 +#define BIO_SOCK_NONBLOCK 0x08 +#define BIO_SOCK_NODELAY 0x10 +#define BIO_SOCK_TFO 0x20 int BIO_socket(int domain, int socktype, int protocol, int options); int BIO_connect(int sock, const BIO_ADDR *addr, int options); @@ -913,16 +920,16 @@ int BIO_closesocket(int sock); BIO *BIO_new_socket(int sock, int close_flag); BIO *BIO_new_connect(const char *host_port); BIO *BIO_new_accept(const char *host_port); -# endif /* OPENSSL_NO_SOCK*/ +#endif /* OPENSSL_NO_SOCK*/ BIO *BIO_new_fd(int fd, int close_flag); int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, - BIO **bio2, size_t writebuf2); -# ifndef OPENSSL_NO_DGRAM + BIO **bio2, size_t writebuf2); +#ifndef OPENSSL_NO_DGRAM int BIO_new_bio_dgram_pair(BIO **bio1, size_t writebuf1, - BIO **bio2, size_t writebuf2); -# endif + BIO **bio2, size_t writebuf2); +#endif /* * If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. @@ -936,87 +943,86 @@ void BIO_copy_next_retry(BIO *b); * long BIO_ghbn_ctrl(int cmd,int iarg,char *parg); */ -# define ossl_bio__attr__(x) -# if defined(__GNUC__) && defined(__STDC_VERSION__) \ +#define ossl_bio__attr__(x) +#if defined(__GNUC__) && defined(__STDC_VERSION__) \ && !defined(__MINGW32__) && !defined(__MINGW64__) \ && !defined(__APPLE__) - /* - * Because we support the 'z' modifier, which made its appearance in C99, - * we can't use __attribute__ with pre C99 dialects. - */ -# if __STDC_VERSION__ >= 199901L -# undef ossl_bio__attr__ -# define ossl_bio__attr__ __attribute__ -# if __GNUC__*10 + __GNUC_MINOR__ >= 44 -# define ossl_bio__printf__ __gnu_printf__ -# else -# define ossl_bio__printf__ __printf__ -# endif -# endif -# endif +/* + * Because we support the 'z' modifier, which made its appearance in C99, + * we can't use __attribute__ with pre C99 dialects. + */ +#if __STDC_VERSION__ >= 199901L +#undef ossl_bio__attr__ +#define ossl_bio__attr__ __attribute__ +#if __GNUC__ * 10 + __GNUC_MINOR__ >= 44 +#define ossl_bio__printf__ __gnu_printf__ +#else +#define ossl_bio__printf__ __printf__ +#endif +#endif +#endif int BIO_printf(BIO *bio, const char *format, ...) -ossl_bio__attr__((__format__(ossl_bio__printf__, 2, 3))); + ossl_bio__attr__((__format__(ossl_bio__printf__, 2, 3))); int BIO_vprintf(BIO *bio, const char *format, va_list args) -ossl_bio__attr__((__format__(ossl_bio__printf__, 2, 0))); + ossl_bio__attr__((__format__(ossl_bio__printf__, 2, 0))); int BIO_snprintf(char *buf, size_t n, const char *format, ...) -ossl_bio__attr__((__format__(ossl_bio__printf__, 3, 4))); + ossl_bio__attr__((__format__(ossl_bio__printf__, 3, 4))); int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) -ossl_bio__attr__((__format__(ossl_bio__printf__, 3, 0))); -# undef ossl_bio__attr__ -# undef ossl_bio__printf__ - + ossl_bio__attr__((__format__(ossl_bio__printf__, 3, 0))); +#undef ossl_bio__attr__ +#undef ossl_bio__printf__ BIO_METHOD *BIO_meth_new(int type, const char *name); void BIO_meth_free(BIO_METHOD *biom); int BIO_meth_set_write(BIO_METHOD *biom, - int (*write) (BIO *, const char *, int)); + int (*write)(BIO *, const char *, int)); int BIO_meth_set_write_ex(BIO_METHOD *biom, - int (*bwrite) (BIO *, const char *, size_t, size_t *)); + int (*bwrite)(BIO *, const char *, size_t, size_t *)); int BIO_meth_set_sendmmsg(BIO_METHOD *biom, - int (*f) (BIO *, BIO_MSG *, size_t, size_t, - uint64_t, size_t *)); + int (*f)(BIO *, BIO_MSG *, size_t, size_t, + uint64_t, size_t *)); int BIO_meth_set_read(BIO_METHOD *biom, - int (*read) (BIO *, char *, int)); + int (*read)(BIO *, char *, int)); int BIO_meth_set_read_ex(BIO_METHOD *biom, - int (*bread) (BIO *, char *, size_t, size_t *)); + int (*bread)(BIO *, char *, size_t, size_t *)); int BIO_meth_set_recvmmsg(BIO_METHOD *biom, - int (*f) (BIO *, BIO_MSG *, size_t, size_t, - uint64_t, size_t *)); + int (*f)(BIO *, BIO_MSG *, size_t, size_t, + uint64_t, size_t *)); int BIO_meth_set_puts(BIO_METHOD *biom, - int (*puts) (BIO *, const char *)); + int (*puts)(BIO *, const char *)); int BIO_meth_set_gets(BIO_METHOD *biom, - int (*ossl_gets) (BIO *, char *, int)); + int (*ossl_gets)(BIO *, char *, int)); int BIO_meth_set_ctrl(BIO_METHOD *biom, - long (*ctrl) (BIO *, int, long, void *)); -int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *)); -int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *)); + long (*ctrl)(BIO *, int, long, void *)); +int BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *)); +int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *)); int BIO_meth_set_callback_ctrl(BIO_METHOD *biom, - long (*callback_ctrl) (BIO *, int, - BIO_info_cb *)); -# ifndef OPENSSL_NO_DEPRECATED_3_5 -OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_write(const BIO_METHOD *biom)) (BIO *, const char *, - int); -OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_write_ex(const BIO_METHOD *biom)) (BIO *, const char *, - size_t, size_t *); + long (*callback_ctrl)(BIO *, int, + BIO_info_cb *)); +#ifndef OPENSSL_NO_DEPRECATED_3_5 +OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_write(const BIO_METHOD *biom))(BIO *, const char *, + int); +OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_write_ex(const BIO_METHOD *biom))(BIO *, const char *, + size_t, size_t *); OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_sendmmsg(const BIO_METHOD *biom))(BIO *, BIO_MSG *, - size_t, size_t, - uint64_t, size_t *); -OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_read(const BIO_METHOD *biom)) (BIO *, char *, int); -OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_read_ex(const BIO_METHOD *biom)) (BIO *, char *, - size_t, size_t *); + size_t, size_t, + uint64_t, size_t *); +OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_read(const BIO_METHOD *biom))(BIO *, char *, int); +OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_read_ex(const BIO_METHOD *biom))(BIO *, char *, + size_t, size_t *); OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_recvmmsg(const BIO_METHOD *biom))(BIO *, BIO_MSG *, - size_t, size_t, - uint64_t, size_t *); -OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_puts(const BIO_METHOD *biom)) (BIO *, const char *); -OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_gets(const BIO_METHOD *biom)) (BIO *, char *, int); -OSSL_DEPRECATEDIN_3_5 long (*BIO_meth_get_ctrl(const BIO_METHOD *biom)) (BIO *, int, - long, void *); -OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_create(const BIO_METHOD *bion)) (BIO *); -OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_destroy(const BIO_METHOD *biom)) (BIO *); -OSSL_DEPRECATEDIN_3_5 long (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom)) (BIO *, int, - BIO_info_cb *); -# endif -# ifdef __cplusplus -} -# endif + size_t, size_t, + uint64_t, size_t *); +OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_puts(const BIO_METHOD *biom))(BIO *, const char *); +OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_gets(const BIO_METHOD *biom))(BIO *, char *, int); +OSSL_DEPRECATEDIN_3_5 long (*BIO_meth_get_ctrl(const BIO_METHOD *biom))(BIO *, int, + long, void *); +OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_create(const BIO_METHOD *bion))(BIO *); +OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_destroy(const BIO_METHOD *biom))(BIO *); +OSSL_DEPRECATEDIN_3_5 long (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))(BIO *, int, + BIO_info_cb *); +#endif +#ifdef __cplusplus +} +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/cmp.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/cmp.h index 284398b237..4ff14f9b5d 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/cmp.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/cmp.h @@ -2,7 +2,7 @@ * WARNING: do not edit! * Generated by Makefile from include/openssl/cmp.h.in * - * Copyright 2007-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2007-2026 The OpenSSL Project Authors. All Rights Reserved. * Copyright Nokia 2007-2019 * Copyright Siemens AG 2015-2019 * @@ -12,32 +12,34 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_CMP_H -# define OPENSSL_CMP_H +#define OPENSSL_CMP_H -# include -# ifndef OPENSSL_NO_CMP +#include +#ifndef OPENSSL_NO_CMP -# include -# include -# include -# include +#include +#include +#include +#include /* explicit #includes not strictly needed since implied by the above: */ -# include -# include -# include -# include +#include +#include +#include +#include -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif -# define OSSL_CMP_PVNO_2 2 -# define OSSL_CMP_PVNO_3 3 -# define OSSL_CMP_PVNO OSSL_CMP_PVNO_2 /* v2 is the default */ +#define OSSL_CMP_PVNO_2 2 +#define OSSL_CMP_PVNO_3 3 +#define OSSL_CMP_PVNO OSSL_CMP_PVNO_2 /* v2 is the default */ /*- * PKIFailureInfo ::= BIT STRING { @@ -106,68 +108,68 @@ extern "C" { * -- certificate already exists * } */ -# define OSSL_CMP_PKIFAILUREINFO_badAlg 0 -# define OSSL_CMP_PKIFAILUREINFO_badMessageCheck 1 -# define OSSL_CMP_PKIFAILUREINFO_badRequest 2 -# define OSSL_CMP_PKIFAILUREINFO_badTime 3 -# define OSSL_CMP_PKIFAILUREINFO_badCertId 4 -# define OSSL_CMP_PKIFAILUREINFO_badDataFormat 5 -# define OSSL_CMP_PKIFAILUREINFO_wrongAuthority 6 -# define OSSL_CMP_PKIFAILUREINFO_incorrectData 7 -# define OSSL_CMP_PKIFAILUREINFO_missingTimeStamp 8 -# define OSSL_CMP_PKIFAILUREINFO_badPOP 9 -# define OSSL_CMP_PKIFAILUREINFO_certRevoked 10 -# define OSSL_CMP_PKIFAILUREINFO_certConfirmed 11 -# define OSSL_CMP_PKIFAILUREINFO_wrongIntegrity 12 -# define OSSL_CMP_PKIFAILUREINFO_badRecipientNonce 13 -# define OSSL_CMP_PKIFAILUREINFO_timeNotAvailable 14 -# define OSSL_CMP_PKIFAILUREINFO_unacceptedPolicy 15 -# define OSSL_CMP_PKIFAILUREINFO_unacceptedExtension 16 -# define OSSL_CMP_PKIFAILUREINFO_addInfoNotAvailable 17 -# define OSSL_CMP_PKIFAILUREINFO_badSenderNonce 18 -# define OSSL_CMP_PKIFAILUREINFO_badCertTemplate 19 -# define OSSL_CMP_PKIFAILUREINFO_signerNotTrusted 20 -# define OSSL_CMP_PKIFAILUREINFO_transactionIdInUse 21 -# define OSSL_CMP_PKIFAILUREINFO_unsupportedVersion 22 -# define OSSL_CMP_PKIFAILUREINFO_notAuthorized 23 -# define OSSL_CMP_PKIFAILUREINFO_systemUnavail 24 -# define OSSL_CMP_PKIFAILUREINFO_systemFailure 25 -# define OSSL_CMP_PKIFAILUREINFO_duplicateCertReq 26 -# define OSSL_CMP_PKIFAILUREINFO_MAX 26 -# define OSSL_CMP_PKIFAILUREINFO_MAX_BIT_PATTERN \ +#define OSSL_CMP_PKIFAILUREINFO_badAlg 0 +#define OSSL_CMP_PKIFAILUREINFO_badMessageCheck 1 +#define OSSL_CMP_PKIFAILUREINFO_badRequest 2 +#define OSSL_CMP_PKIFAILUREINFO_badTime 3 +#define OSSL_CMP_PKIFAILUREINFO_badCertId 4 +#define OSSL_CMP_PKIFAILUREINFO_badDataFormat 5 +#define OSSL_CMP_PKIFAILUREINFO_wrongAuthority 6 +#define OSSL_CMP_PKIFAILUREINFO_incorrectData 7 +#define OSSL_CMP_PKIFAILUREINFO_missingTimeStamp 8 +#define OSSL_CMP_PKIFAILUREINFO_badPOP 9 +#define OSSL_CMP_PKIFAILUREINFO_certRevoked 10 +#define OSSL_CMP_PKIFAILUREINFO_certConfirmed 11 +#define OSSL_CMP_PKIFAILUREINFO_wrongIntegrity 12 +#define OSSL_CMP_PKIFAILUREINFO_badRecipientNonce 13 +#define OSSL_CMP_PKIFAILUREINFO_timeNotAvailable 14 +#define OSSL_CMP_PKIFAILUREINFO_unacceptedPolicy 15 +#define OSSL_CMP_PKIFAILUREINFO_unacceptedExtension 16 +#define OSSL_CMP_PKIFAILUREINFO_addInfoNotAvailable 17 +#define OSSL_CMP_PKIFAILUREINFO_badSenderNonce 18 +#define OSSL_CMP_PKIFAILUREINFO_badCertTemplate 19 +#define OSSL_CMP_PKIFAILUREINFO_signerNotTrusted 20 +#define OSSL_CMP_PKIFAILUREINFO_transactionIdInUse 21 +#define OSSL_CMP_PKIFAILUREINFO_unsupportedVersion 22 +#define OSSL_CMP_PKIFAILUREINFO_notAuthorized 23 +#define OSSL_CMP_PKIFAILUREINFO_systemUnavail 24 +#define OSSL_CMP_PKIFAILUREINFO_systemFailure 25 +#define OSSL_CMP_PKIFAILUREINFO_duplicateCertReq 26 +#define OSSL_CMP_PKIFAILUREINFO_MAX 26 +#define OSSL_CMP_PKIFAILUREINFO_MAX_BIT_PATTERN \ ((1 << (OSSL_CMP_PKIFAILUREINFO_MAX + 1)) - 1) -# if OSSL_CMP_PKIFAILUREINFO_MAX_BIT_PATTERN > INT_MAX -# error CMP_PKIFAILUREINFO_MAX bit pattern does not fit in type int -# endif +#if OSSL_CMP_PKIFAILUREINFO_MAX_BIT_PATTERN > INT_MAX +#error CMP_PKIFAILUREINFO_MAX bit pattern does not fit in type int +#endif typedef ASN1_BIT_STRING OSSL_CMP_PKIFAILUREINFO; -# define OSSL_CMP_CTX_FAILINFO_badAlg (1 << 0) -# define OSSL_CMP_CTX_FAILINFO_badMessageCheck (1 << 1) -# define OSSL_CMP_CTX_FAILINFO_badRequest (1 << 2) -# define OSSL_CMP_CTX_FAILINFO_badTime (1 << 3) -# define OSSL_CMP_CTX_FAILINFO_badCertId (1 << 4) -# define OSSL_CMP_CTX_FAILINFO_badDataFormat (1 << 5) -# define OSSL_CMP_CTX_FAILINFO_wrongAuthority (1 << 6) -# define OSSL_CMP_CTX_FAILINFO_incorrectData (1 << 7) -# define OSSL_CMP_CTX_FAILINFO_missingTimeStamp (1 << 8) -# define OSSL_CMP_CTX_FAILINFO_badPOP (1 << 9) -# define OSSL_CMP_CTX_FAILINFO_certRevoked (1 << 10) -# define OSSL_CMP_CTX_FAILINFO_certConfirmed (1 << 11) -# define OSSL_CMP_CTX_FAILINFO_wrongIntegrity (1 << 12) -# define OSSL_CMP_CTX_FAILINFO_badRecipientNonce (1 << 13) -# define OSSL_CMP_CTX_FAILINFO_timeNotAvailable (1 << 14) -# define OSSL_CMP_CTX_FAILINFO_unacceptedPolicy (1 << 15) -# define OSSL_CMP_CTX_FAILINFO_unacceptedExtension (1 << 16) -# define OSSL_CMP_CTX_FAILINFO_addInfoNotAvailable (1 << 17) -# define OSSL_CMP_CTX_FAILINFO_badSenderNonce (1 << 18) -# define OSSL_CMP_CTX_FAILINFO_badCertTemplate (1 << 19) -# define OSSL_CMP_CTX_FAILINFO_signerNotTrusted (1 << 20) -# define OSSL_CMP_CTX_FAILINFO_transactionIdInUse (1 << 21) -# define OSSL_CMP_CTX_FAILINFO_unsupportedVersion (1 << 22) -# define OSSL_CMP_CTX_FAILINFO_notAuthorized (1 << 23) -# define OSSL_CMP_CTX_FAILINFO_systemUnavail (1 << 24) -# define OSSL_CMP_CTX_FAILINFO_systemFailure (1 << 25) -# define OSSL_CMP_CTX_FAILINFO_duplicateCertReq (1 << 26) +#define OSSL_CMP_CTX_FAILINFO_badAlg (1 << 0) +#define OSSL_CMP_CTX_FAILINFO_badMessageCheck (1 << 1) +#define OSSL_CMP_CTX_FAILINFO_badRequest (1 << 2) +#define OSSL_CMP_CTX_FAILINFO_badTime (1 << 3) +#define OSSL_CMP_CTX_FAILINFO_badCertId (1 << 4) +#define OSSL_CMP_CTX_FAILINFO_badDataFormat (1 << 5) +#define OSSL_CMP_CTX_FAILINFO_wrongAuthority (1 << 6) +#define OSSL_CMP_CTX_FAILINFO_incorrectData (1 << 7) +#define OSSL_CMP_CTX_FAILINFO_missingTimeStamp (1 << 8) +#define OSSL_CMP_CTX_FAILINFO_badPOP (1 << 9) +#define OSSL_CMP_CTX_FAILINFO_certRevoked (1 << 10) +#define OSSL_CMP_CTX_FAILINFO_certConfirmed (1 << 11) +#define OSSL_CMP_CTX_FAILINFO_wrongIntegrity (1 << 12) +#define OSSL_CMP_CTX_FAILINFO_badRecipientNonce (1 << 13) +#define OSSL_CMP_CTX_FAILINFO_timeNotAvailable (1 << 14) +#define OSSL_CMP_CTX_FAILINFO_unacceptedPolicy (1 << 15) +#define OSSL_CMP_CTX_FAILINFO_unacceptedExtension (1 << 16) +#define OSSL_CMP_CTX_FAILINFO_addInfoNotAvailable (1 << 17) +#define OSSL_CMP_CTX_FAILINFO_badSenderNonce (1 << 18) +#define OSSL_CMP_CTX_FAILINFO_badCertTemplate (1 << 19) +#define OSSL_CMP_CTX_FAILINFO_signerNotTrusted (1 << 20) +#define OSSL_CMP_CTX_FAILINFO_transactionIdInUse (1 << 21) +#define OSSL_CMP_CTX_FAILINFO_unsupportedVersion (1 << 22) +#define OSSL_CMP_CTX_FAILINFO_notAuthorized (1 << 23) +#define OSSL_CMP_CTX_FAILINFO_systemUnavail (1 << 24) +#define OSSL_CMP_CTX_FAILINFO_systemFailure (1 << 25) +#define OSSL_CMP_CTX_FAILINFO_duplicateCertReq (1 << 26) /*- * PKIStatus ::= INTEGER { @@ -194,22 +196,24 @@ typedef ASN1_BIT_STRING OSSL_CMP_PKIFAILUREINFO; * -- CertReqMsg * } */ -# define OSSL_CMP_PKISTATUS_request -3 -# define OSSL_CMP_PKISTATUS_trans -2 -# define OSSL_CMP_PKISTATUS_unspecified -1 -# define OSSL_CMP_PKISTATUS_accepted 0 -# define OSSL_CMP_PKISTATUS_grantedWithMods 1 -# define OSSL_CMP_PKISTATUS_rejection 2 -# define OSSL_CMP_PKISTATUS_waiting 3 -# define OSSL_CMP_PKISTATUS_revocationWarning 4 -# define OSSL_CMP_PKISTATUS_revocationNotification 5 -# define OSSL_CMP_PKISTATUS_keyUpdateWarning 6 +#define OSSL_CMP_PKISTATUS_rejected_by_client -5 +#define OSSL_CMP_PKISTATUS_checking_response -4 +#define OSSL_CMP_PKISTATUS_request -3 +#define OSSL_CMP_PKISTATUS_trans -2 +#define OSSL_CMP_PKISTATUS_unspecified -1 +#define OSSL_CMP_PKISTATUS_accepted 0 +#define OSSL_CMP_PKISTATUS_grantedWithMods 1 +#define OSSL_CMP_PKISTATUS_rejection 2 +#define OSSL_CMP_PKISTATUS_waiting 3 +#define OSSL_CMP_PKISTATUS_revocationWarning 4 +#define OSSL_CMP_PKISTATUS_revocationNotification 5 +#define OSSL_CMP_PKISTATUS_keyUpdateWarning 6 typedef ASN1_INTEGER OSSL_CMP_PKISTATUS; DECLARE_ASN1_ITEM(OSSL_CMP_PKISTATUS) -# define OSSL_CMP_CERTORENCCERT_CERTIFICATE 0 -# define OSSL_CMP_CERTORENCCERT_ENCRYPTEDCERT 1 +#define OSSL_CMP_CERTORENCCERT_CERTIFICATE 0 +#define OSSL_CMP_CERTORENCCERT_ENCRYPTEDCERT 1 /* data type declarations */ typedef struct ossl_cmp_ctx_st OSSL_CMP_CTX; @@ -219,6 +223,7 @@ typedef struct ossl_cmp_msg_st OSSL_CMP_MSG; DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_MSG) DECLARE_ASN1_ENCODE_FUNCTIONS(OSSL_CMP_MSG, OSSL_CMP_MSG, OSSL_CMP_MSG) typedef struct ossl_cmp_certstatus_st OSSL_CMP_CERTSTATUS; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_CERTSTATUS, OSSL_CMP_CERTSTATUS, OSSL_CMP_CERTSTATUS) #define sk_OSSL_CMP_CERTSTATUS_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_CMP_CERTSTATUS_sk_type(sk)) #define sk_OSSL_CMP_CERTSTATUS_value(sk, idx) ((OSSL_CMP_CERTSTATUS *)OPENSSL_sk_value(ossl_check_const_OSSL_CMP_CERTSTATUS_sk_type(sk), (idx))) @@ -246,8 +251,10 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_CERTSTATUS, OSSL_CMP_CERTSTATUS, OSSL_CMP_ #define sk_OSSL_CMP_CERTSTATUS_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_CMP_CERTSTATUS) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_CMP_CERTSTATUS_sk_type(sk), ossl_check_OSSL_CMP_CERTSTATUS_copyfunc_type(copyfunc), ossl_check_OSSL_CMP_CERTSTATUS_freefunc_type(freefunc))) #define sk_OSSL_CMP_CERTSTATUS_set_cmp_func(sk, cmp) ((sk_OSSL_CMP_CERTSTATUS_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_CMP_CERTSTATUS_sk_type(sk), ossl_check_OSSL_CMP_CERTSTATUS_compfunc_type(cmp))) +/* clang-format on */ typedef struct ossl_cmp_itav_st OSSL_CMP_ITAV; DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_ITAV) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_ITAV, OSSL_CMP_ITAV, OSSL_CMP_ITAV) #define sk_OSSL_CMP_ITAV_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_CMP_ITAV_sk_type(sk)) #define sk_OSSL_CMP_ITAV_value(sk, idx) ((OSSL_CMP_ITAV *)OPENSSL_sk_value(ossl_check_const_OSSL_CMP_ITAV_sk_type(sk), (idx))) @@ -275,8 +282,10 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_ITAV, OSSL_CMP_ITAV, OSSL_CMP_ITAV) #define sk_OSSL_CMP_ITAV_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_CMP_ITAV) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_CMP_ITAV_sk_type(sk), ossl_check_OSSL_CMP_ITAV_copyfunc_type(copyfunc), ossl_check_OSSL_CMP_ITAV_freefunc_type(freefunc))) #define sk_OSSL_CMP_ITAV_set_cmp_func(sk, cmp) ((sk_OSSL_CMP_ITAV_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_CMP_ITAV_sk_type(sk), ossl_check_OSSL_CMP_ITAV_compfunc_type(cmp))) +/* clang-format on */ typedef struct ossl_cmp_crlstatus_st OSSL_CMP_CRLSTATUS; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_CRLSTATUS, OSSL_CMP_CRLSTATUS, OSSL_CMP_CRLSTATUS) #define sk_OSSL_CMP_CRLSTATUS_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_CMP_CRLSTATUS_sk_type(sk)) #define sk_OSSL_CMP_CRLSTATUS_value(sk, idx) ((OSSL_CMP_CRLSTATUS *)OPENSSL_sk_value(ossl_check_const_OSSL_CMP_CRLSTATUS_sk_type(sk), (idx))) @@ -304,21 +313,23 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_CRLSTATUS, OSSL_CMP_CRLSTATUS, OSSL_CMP_CR #define sk_OSSL_CMP_CRLSTATUS_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_CMP_CRLSTATUS) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_CMP_CRLSTATUS_sk_type(sk), ossl_check_OSSL_CMP_CRLSTATUS_copyfunc_type(copyfunc), ossl_check_OSSL_CMP_CRLSTATUS_freefunc_type(freefunc))) #define sk_OSSL_CMP_CRLSTATUS_set_cmp_func(sk, cmp) ((sk_OSSL_CMP_CRLSTATUS_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_CMP_CRLSTATUS_sk_type(sk), ossl_check_OSSL_CMP_CRLSTATUS_compfunc_type(cmp))) +/* clang-format on */ typedef OSSL_CRMF_ATTRIBUTETYPEANDVALUE OSSL_CMP_ATAV; -# define OSSL_CMP_ATAV_free OSSL_CRMF_ATTRIBUTETYPEANDVALUE_free +#define OSSL_CMP_ATAV_free OSSL_CRMF_ATTRIBUTETYPEANDVALUE_free typedef STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) OSSL_CMP_ATAVS; DECLARE_ASN1_FUNCTIONS(OSSL_CMP_ATAVS) -# define stack_st_OSSL_CMP_ATAV stack_st_OSSL_CRMF_ATTRIBUTETYPEANDVALUE -# define sk_OSSL_CMP_ATAV_num sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_num -# define sk_OSSL_CMP_ATAV_value sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_value -# define sk_OSSL_CMP_ATAV_push sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_push -# define sk_OSSL_CMP_ATAV_pop_free sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_pop_free +#define stack_st_OSSL_CMP_ATAV stack_st_OSSL_CRMF_ATTRIBUTETYPEANDVALUE +#define sk_OSSL_CMP_ATAV_num sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_num +#define sk_OSSL_CMP_ATAV_value sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_value +#define sk_OSSL_CMP_ATAV_push sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_push +#define sk_OSSL_CMP_ATAV_pop_free sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_pop_free typedef struct ossl_cmp_revrepcontent_st OSSL_CMP_REVREPCONTENT; typedef struct ossl_cmp_pkisi_st OSSL_CMP_PKISI; DECLARE_ASN1_FUNCTIONS(OSSL_CMP_PKISI) DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_PKISI) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_PKISI, OSSL_CMP_PKISI, OSSL_CMP_PKISI) #define sk_OSSL_CMP_PKISI_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_CMP_PKISI_sk_type(sk)) #define sk_OSSL_CMP_PKISI_value(sk, idx) ((OSSL_CMP_PKISI *)OPENSSL_sk_value(ossl_check_const_OSSL_CMP_PKISI_sk_type(sk), (idx))) @@ -346,7 +357,9 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_PKISI, OSSL_CMP_PKISI, OSSL_CMP_PKISI) #define sk_OSSL_CMP_PKISI_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_CMP_PKISI) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_CMP_PKISI_sk_type(sk), ossl_check_OSSL_CMP_PKISI_copyfunc_type(copyfunc), ossl_check_OSSL_CMP_PKISI_freefunc_type(freefunc))) #define sk_OSSL_CMP_PKISI_set_cmp_func(sk, cmp) ((sk_OSSL_CMP_PKISI_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_CMP_PKISI_sk_type(sk), ossl_check_OSSL_CMP_PKISI_compfunc_type(cmp))) +/* clang-format on */ typedef struct ossl_cmp_certrepmessage_st OSSL_CMP_CERTREPMESSAGE; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_CERTREPMESSAGE, OSSL_CMP_CERTREPMESSAGE, OSSL_CMP_CERTREPMESSAGE) #define sk_OSSL_CMP_CERTREPMESSAGE_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_CMP_CERTREPMESSAGE_sk_type(sk)) #define sk_OSSL_CMP_CERTREPMESSAGE_value(sk, idx) ((OSSL_CMP_CERTREPMESSAGE *)OPENSSL_sk_value(ossl_check_const_OSSL_CMP_CERTREPMESSAGE_sk_type(sk), (idx))) @@ -374,9 +387,11 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_CERTREPMESSAGE, OSSL_CMP_CERTREPMESSAGE, O #define sk_OSSL_CMP_CERTREPMESSAGE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_CMP_CERTREPMESSAGE) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_CMP_CERTREPMESSAGE_sk_type(sk), ossl_check_OSSL_CMP_CERTREPMESSAGE_copyfunc_type(copyfunc), ossl_check_OSSL_CMP_CERTREPMESSAGE_freefunc_type(freefunc))) #define sk_OSSL_CMP_CERTREPMESSAGE_set_cmp_func(sk, cmp) ((sk_OSSL_CMP_CERTREPMESSAGE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_CMP_CERTREPMESSAGE_sk_type(sk), ossl_check_OSSL_CMP_CERTREPMESSAGE_compfunc_type(cmp))) +/* clang-format on */ typedef struct ossl_cmp_pollrep_st OSSL_CMP_POLLREP; typedef STACK_OF(OSSL_CMP_POLLREP) OSSL_CMP_POLLREPCONTENT; typedef struct ossl_cmp_certresponse_st OSSL_CMP_CERTRESPONSE; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_CERTRESPONSE, OSSL_CMP_CERTRESPONSE, OSSL_CMP_CERTRESPONSE) #define sk_OSSL_CMP_CERTRESPONSE_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_CMP_CERTRESPONSE_sk_type(sk)) #define sk_OSSL_CMP_CERTRESPONSE_value(sk, idx) ((OSSL_CMP_CERTRESPONSE *)OPENSSL_sk_value(ossl_check_const_OSSL_CMP_CERTRESPONSE_sk_type(sk), (idx))) @@ -404,6 +419,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CMP_CERTRESPONSE, OSSL_CMP_CERTRESPONSE, OSSL_ #define sk_OSSL_CMP_CERTRESPONSE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_CMP_CERTRESPONSE) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_CMP_CERTRESPONSE_sk_type(sk), ossl_check_OSSL_CMP_CERTRESPONSE_copyfunc_type(copyfunc), ossl_check_OSSL_CMP_CERTRESPONSE_freefunc_type(freefunc))) #define sk_OSSL_CMP_CERTRESPONSE_set_cmp_func(sk, cmp) ((sk_OSSL_CMP_CERTRESPONSE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_CMP_CERTRESPONSE_sk_type(sk), ossl_check_OSSL_CMP_CERTRESPONSE_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(ASN1_UTF8STRING) OSSL_CMP_PKIFREETEXT; /* @@ -413,55 +429,55 @@ typedef STACK_OF(ASN1_UTF8STRING) OSSL_CMP_PKIFREETEXT; /* from cmp_asn.c */ OSSL_CMP_ITAV *OSSL_CMP_ITAV_create(ASN1_OBJECT *type, ASN1_TYPE *value); void OSSL_CMP_ITAV_set0(OSSL_CMP_ITAV *itav, ASN1_OBJECT *type, - ASN1_TYPE *value); + ASN1_TYPE *value); ASN1_OBJECT *OSSL_CMP_ITAV_get0_type(const OSSL_CMP_ITAV *itav); ASN1_TYPE *OSSL_CMP_ITAV_get0_value(const OSSL_CMP_ITAV *itav); int OSSL_CMP_ITAV_push0_stack_item(STACK_OF(OSSL_CMP_ITAV) **sk_p, - OSSL_CMP_ITAV *itav); + OSSL_CMP_ITAV *itav); void OSSL_CMP_ITAV_free(OSSL_CMP_ITAV *itav); OSSL_CMP_ITAV *OSSL_CMP_ITAV_new0_certProfile(STACK_OF(ASN1_UTF8STRING) - *certProfile); + *certProfile); int OSSL_CMP_ITAV_get0_certProfile(const OSSL_CMP_ITAV *itav, - STACK_OF(ASN1_UTF8STRING) **out); + STACK_OF(ASN1_UTF8STRING) **out); OSSL_CMP_ITAV *OSSL_CMP_ITAV_new_caCerts(const STACK_OF(X509) *caCerts); int OSSL_CMP_ITAV_get0_caCerts(const OSSL_CMP_ITAV *itav, STACK_OF(X509) **out); OSSL_CMP_ITAV *OSSL_CMP_ITAV_new_rootCaCert(const X509 *rootCaCert); int OSSL_CMP_ITAV_get0_rootCaCert(const OSSL_CMP_ITAV *itav, X509 **out); OSSL_CMP_ITAV *OSSL_CMP_ITAV_new_rootCaKeyUpdate(const X509 *newWithNew, - const X509 *newWithOld, - const X509 *oldWithNew); + const X509 *newWithOld, + const X509 *oldWithNew); int OSSL_CMP_ITAV_get0_rootCaKeyUpdate(const OSSL_CMP_ITAV *itav, - X509 **newWithNew, - X509 **newWithOld, - X509 **oldWithNew); + X509 **newWithNew, + X509 **newWithOld, + X509 **oldWithNew); OSSL_CMP_CRLSTATUS *OSSL_CMP_CRLSTATUS_create(const X509_CRL *crl, - const X509 *cert, int only_DN); + const X509 *cert, int only_DN); OSSL_CMP_CRLSTATUS *OSSL_CMP_CRLSTATUS_new1(const DIST_POINT_NAME *dpn, - const GENERAL_NAMES *issuer, - const ASN1_TIME *thisUpdate); + const GENERAL_NAMES *issuer, + const ASN1_TIME *thisUpdate); int OSSL_CMP_CRLSTATUS_get0(const OSSL_CMP_CRLSTATUS *crlstatus, - DIST_POINT_NAME **dpn, GENERAL_NAMES **issuer, - ASN1_TIME **thisUpdate); + DIST_POINT_NAME **dpn, GENERAL_NAMES **issuer, + ASN1_TIME **thisUpdate); void OSSL_CMP_CRLSTATUS_free(OSSL_CMP_CRLSTATUS *crlstatus); OSSL_CMP_ITAV *OSSL_CMP_ITAV_new0_crlStatusList(STACK_OF(OSSL_CMP_CRLSTATUS) *crlStatusList); int OSSL_CMP_ITAV_get0_crlStatusList(const OSSL_CMP_ITAV *itav, - STACK_OF(OSSL_CMP_CRLSTATUS) **out); + STACK_OF(OSSL_CMP_CRLSTATUS) **out); OSSL_CMP_ITAV *OSSL_CMP_ITAV_new_crls(const X509_CRL *crls); int OSSL_CMP_ITAV_get0_crls(const OSSL_CMP_ITAV *it, STACK_OF(X509_CRL) **out); OSSL_CMP_ITAV *OSSL_CMP_ITAV_new0_certReqTemplate(OSSL_CRMF_CERTTEMPLATE *certTemplate, - OSSL_CMP_ATAVS *keySpec); + OSSL_CMP_ATAVS *keySpec); int OSSL_CMP_ITAV_get1_certReqTemplate(const OSSL_CMP_ITAV *itav, - OSSL_CRMF_CERTTEMPLATE **certTemplate, - OSSL_CMP_ATAVS **keySpec); + OSSL_CRMF_CERTTEMPLATE **certTemplate, + OSSL_CMP_ATAVS **keySpec); OSSL_CMP_ATAV *OSSL_CMP_ATAV_create(ASN1_OBJECT *type, ASN1_TYPE *value); void OSSL_CMP_ATAV_set0(OSSL_CMP_ATAV *itav, ASN1_OBJECT *type, - ASN1_TYPE *value); + ASN1_TYPE *value); ASN1_OBJECT *OSSL_CMP_ATAV_get0_type(const OSSL_CMP_ATAV *itav); ASN1_TYPE *OSSL_CMP_ATAV_get0_value(const OSSL_CMP_ATAV *itav); OSSL_CMP_ATAV *OSSL_CMP_ATAV_new_algId(const X509_ALGOR *alg); @@ -479,35 +495,35 @@ int OSSL_CMP_CTX_reinit(OSSL_CMP_CTX *ctx); OSSL_LIB_CTX *OSSL_CMP_CTX_get0_libctx(const OSSL_CMP_CTX *ctx); const char *OSSL_CMP_CTX_get0_propq(const OSSL_CMP_CTX *ctx); /* CMP general options: */ -# define OSSL_CMP_OPT_LOG_VERBOSITY 0 +#define OSSL_CMP_OPT_LOG_VERBOSITY 0 /* CMP transfer options: */ -# define OSSL_CMP_OPT_KEEP_ALIVE 10 -# define OSSL_CMP_OPT_MSG_TIMEOUT 11 -# define OSSL_CMP_OPT_TOTAL_TIMEOUT 12 -# define OSSL_CMP_OPT_USE_TLS 13 +#define OSSL_CMP_OPT_KEEP_ALIVE 10 +#define OSSL_CMP_OPT_MSG_TIMEOUT 11 +#define OSSL_CMP_OPT_TOTAL_TIMEOUT 12 +#define OSSL_CMP_OPT_USE_TLS 13 /* CMP request options: */ -# define OSSL_CMP_OPT_VALIDITY_DAYS 20 -# define OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT 21 -# define OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL 22 -# define OSSL_CMP_OPT_POLICIES_CRITICAL 23 -# define OSSL_CMP_OPT_POPO_METHOD 24 -# define OSSL_CMP_OPT_IMPLICIT_CONFIRM 25 -# define OSSL_CMP_OPT_DISABLE_CONFIRM 26 -# define OSSL_CMP_OPT_REVOCATION_REASON 27 +#define OSSL_CMP_OPT_VALIDITY_DAYS 20 +#define OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT 21 +#define OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL 22 +#define OSSL_CMP_OPT_POLICIES_CRITICAL 23 +#define OSSL_CMP_OPT_POPO_METHOD 24 +#define OSSL_CMP_OPT_IMPLICIT_CONFIRM 25 +#define OSSL_CMP_OPT_DISABLE_CONFIRM 26 +#define OSSL_CMP_OPT_REVOCATION_REASON 27 /* CMP protection options: */ -# define OSSL_CMP_OPT_UNPROTECTED_SEND 30 -# define OSSL_CMP_OPT_UNPROTECTED_ERRORS 31 -# define OSSL_CMP_OPT_OWF_ALGNID 32 -# define OSSL_CMP_OPT_MAC_ALGNID 33 -# define OSSL_CMP_OPT_DIGEST_ALGNID 34 -# define OSSL_CMP_OPT_IGNORE_KEYUSAGE 35 -# define OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR 36 -# define OSSL_CMP_OPT_NO_CACHE_EXTRACERTS 37 +#define OSSL_CMP_OPT_UNPROTECTED_SEND 30 +#define OSSL_CMP_OPT_UNPROTECTED_ERRORS 31 +#define OSSL_CMP_OPT_OWF_ALGNID 32 +#define OSSL_CMP_OPT_MAC_ALGNID 33 +#define OSSL_CMP_OPT_DIGEST_ALGNID 34 +#define OSSL_CMP_OPT_IGNORE_KEYUSAGE 35 +#define OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR 36 +#define OSSL_CMP_OPT_NO_CACHE_EXTRACERTS 37 int OSSL_CMP_CTX_set_option(OSSL_CMP_CTX *ctx, int opt, int val); int OSSL_CMP_CTX_get_option(const OSSL_CMP_CTX *ctx, int opt); /* CMP-specific callback for logging and outputting the error queue: */ int OSSL_CMP_CTX_set_log_cb(OSSL_CMP_CTX *ctx, OSSL_CMP_log_cb_t cb); -# define OSSL_CMP_CTX_set_log_verbosity(ctx, level) \ +#define OSSL_CMP_CTX_set_log_verbosity(ctx, level) \ OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_LOG_VERBOSITY, level) void OSSL_CMP_CTX_print_errors(const OSSL_CMP_CTX *ctx); /* message transfer: */ @@ -516,13 +532,13 @@ int OSSL_CMP_CTX_set1_server(OSSL_CMP_CTX *ctx, const char *address); int OSSL_CMP_CTX_set_serverPort(OSSL_CMP_CTX *ctx, int port); int OSSL_CMP_CTX_set1_proxy(OSSL_CMP_CTX *ctx, const char *name); int OSSL_CMP_CTX_set1_no_proxy(OSSL_CMP_CTX *ctx, const char *names); -# ifndef OPENSSL_NO_HTTP +#ifndef OPENSSL_NO_HTTP int OSSL_CMP_CTX_set_http_cb(OSSL_CMP_CTX *ctx, OSSL_HTTP_bio_cb_t cb); int OSSL_CMP_CTX_set_http_cb_arg(OSSL_CMP_CTX *ctx, void *arg); void *OSSL_CMP_CTX_get_http_cb_arg(const OSSL_CMP_CTX *ctx); -# endif -typedef OSSL_CMP_MSG *(*OSSL_CMP_transfer_cb_t) (OSSL_CMP_CTX *ctx, - const OSSL_CMP_MSG *req); +#endif +typedef OSSL_CMP_MSG *(*OSSL_CMP_transfer_cb_t)(OSSL_CMP_CTX *ctx, + const OSSL_CMP_MSG *req); int OSSL_CMP_CTX_set_transfer_cb(OSSL_CMP_CTX *ctx, OSSL_CMP_transfer_cb_t cb); int OSSL_CMP_CTX_set_transfer_cb_arg(OSSL_CMP_CTX *ctx, void *arg); void *OSSL_CMP_CTX_get_transfer_cb_arg(const OSSL_CMP_CTX *ctx); @@ -530,28 +546,28 @@ void *OSSL_CMP_CTX_get_transfer_cb_arg(const OSSL_CMP_CTX *ctx); int OSSL_CMP_CTX_set1_srvCert(OSSL_CMP_CTX *ctx, X509 *cert); int OSSL_CMP_CTX_set1_expected_sender(OSSL_CMP_CTX *ctx, const X509_NAME *name); int OSSL_CMP_CTX_set0_trustedStore(OSSL_CMP_CTX *ctx, X509_STORE *store); -# define OSSL_CMP_CTX_set0_trusted OSSL_CMP_CTX_set0_trustedStore +#define OSSL_CMP_CTX_set0_trusted OSSL_CMP_CTX_set0_trustedStore X509_STORE *OSSL_CMP_CTX_get0_trustedStore(const OSSL_CMP_CTX *ctx); -# define OSSL_CMP_CTX_get0_trusted OSSL_CMP_CTX_get0_trustedStore +#define OSSL_CMP_CTX_get0_trusted OSSL_CMP_CTX_get0_trustedStore int OSSL_CMP_CTX_set1_untrusted(OSSL_CMP_CTX *ctx, STACK_OF(X509) *certs); STACK_OF(X509) *OSSL_CMP_CTX_get0_untrusted(const OSSL_CMP_CTX *ctx); /* client authentication: */ int OSSL_CMP_CTX_set1_cert(OSSL_CMP_CTX *ctx, X509 *cert); int OSSL_CMP_CTX_build_cert_chain(OSSL_CMP_CTX *ctx, X509_STORE *own_trusted, - STACK_OF(X509) *candidates); + STACK_OF(X509) *candidates); int OSSL_CMP_CTX_set1_pkey(OSSL_CMP_CTX *ctx, EVP_PKEY *pkey); int OSSL_CMP_CTX_set1_referenceValue(OSSL_CMP_CTX *ctx, - const unsigned char *ref, int len); + const unsigned char *ref, int len); int OSSL_CMP_CTX_set1_secretValue(OSSL_CMP_CTX *ctx, - const unsigned char *sec, int len); + const unsigned char *sec, int len); /* CMP message header and extra certificates: */ int OSSL_CMP_CTX_set1_recipient(OSSL_CMP_CTX *ctx, const X509_NAME *name); int OSSL_CMP_CTX_push0_geninfo_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav); int OSSL_CMP_CTX_reset_geninfo_ITAVs(OSSL_CMP_CTX *ctx); STACK_OF(OSSL_CMP_ITAV) - *OSSL_CMP_CTX_get0_geninfo_ITAVs(const OSSL_CMP_CTX *ctx); +*OSSL_CMP_CTX_get0_geninfo_ITAVs(const OSSL_CMP_CTX *ctx); int OSSL_CMP_CTX_set1_extraCertsOut(OSSL_CMP_CTX *ctx, - STACK_OF(X509) *extraCertsOut); + STACK_OF(X509) *extraCertsOut); /* certificate template: */ int OSSL_CMP_CTX_set0_newPkey(OSSL_CMP_CTX *ctx, int priv, EVP_PKEY *pkey); EVP_PKEY *OSSL_CMP_CTX_get0_newPkey(const OSSL_CMP_CTX *ctx, int priv); @@ -559,7 +575,7 @@ int OSSL_CMP_CTX_set1_issuer(OSSL_CMP_CTX *ctx, const X509_NAME *name); int OSSL_CMP_CTX_set1_serialNumber(OSSL_CMP_CTX *ctx, const ASN1_INTEGER *sn); int OSSL_CMP_CTX_set1_subjectName(OSSL_CMP_CTX *ctx, const X509_NAME *name); int OSSL_CMP_CTX_push1_subjectAltName(OSSL_CMP_CTX *ctx, - const GENERAL_NAME *name); + const GENERAL_NAME *name); int OSSL_CMP_CTX_set0_reqExtensions(OSSL_CMP_CTX *ctx, X509_EXTENSIONS *exts); int OSSL_CMP_CTX_reqExtensions_have_SAN(OSSL_CMP_CTX *ctx); int OSSL_CMP_CTX_push0_policy(OSSL_CMP_CTX *ctx, POLICYINFO *pinfo); @@ -568,10 +584,10 @@ int OSSL_CMP_CTX_set1_p10CSR(OSSL_CMP_CTX *ctx, const X509_REQ *csr); /* misc body contents: */ int OSSL_CMP_CTX_push0_genm_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav); /* certificate confirmation: */ -typedef int (*OSSL_CMP_certConf_cb_t) (OSSL_CMP_CTX *ctx, X509 *cert, - int fail_info, const char **txt); +typedef int (*OSSL_CMP_certConf_cb_t)(OSSL_CMP_CTX *ctx, X509 *cert, + int fail_info, const char **txt); int OSSL_CMP_certConf_cb(OSSL_CMP_CTX *ctx, X509 *cert, int fail_info, - const char **text); + const char **text); int OSSL_CMP_CTX_set_certConf_cb(OSSL_CMP_CTX *ctx, OSSL_CMP_certConf_cb_t cb); int OSSL_CMP_CTX_set_certConf_cb_arg(OSSL_CMP_CTX *ctx, void *arg); void *OSSL_CMP_CTX_get_certConf_cb_arg(const OSSL_CMP_CTX *ctx); @@ -579,31 +595,30 @@ void *OSSL_CMP_CTX_get_certConf_cb_arg(const OSSL_CMP_CTX *ctx); int OSSL_CMP_CTX_get_status(const OSSL_CMP_CTX *ctx); OSSL_CMP_PKIFREETEXT *OSSL_CMP_CTX_get0_statusString(const OSSL_CMP_CTX *ctx); int OSSL_CMP_CTX_get_failInfoCode(const OSSL_CMP_CTX *ctx); -# define OSSL_CMP_PKISI_BUFLEN 1024 +#define OSSL_CMP_PKISI_BUFLEN 1024 X509 *OSSL_CMP_CTX_get0_validatedSrvCert(const OSSL_CMP_CTX *ctx); X509 *OSSL_CMP_CTX_get0_newCert(const OSSL_CMP_CTX *ctx); STACK_OF(X509) *OSSL_CMP_CTX_get1_newChain(const OSSL_CMP_CTX *ctx); STACK_OF(X509) *OSSL_CMP_CTX_get1_caPubs(const OSSL_CMP_CTX *ctx); STACK_OF(X509) *OSSL_CMP_CTX_get1_extraCertsIn(const OSSL_CMP_CTX *ctx); int OSSL_CMP_CTX_set1_transactionID(OSSL_CMP_CTX *ctx, - const ASN1_OCTET_STRING *id); + const ASN1_OCTET_STRING *id); int OSSL_CMP_CTX_set1_senderNonce(OSSL_CMP_CTX *ctx, - const ASN1_OCTET_STRING *nonce); + const ASN1_OCTET_STRING *nonce); /* from cmp_status.c */ char *OSSL_CMP_CTX_snprint_PKIStatus(const OSSL_CMP_CTX *ctx, char *buf, - size_t bufsize); + size_t bufsize); char *OSSL_CMP_snprint_PKIStatusInfo(const OSSL_CMP_PKISI *statusInfo, - char *buf, size_t bufsize); + char *buf, size_t bufsize); OSSL_CMP_PKISI * OSSL_CMP_STATUSINFO_new(int status, int fail_info, const char *text); /* from cmp_hdr.c */ -ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_transactionID(const - OSSL_CMP_PKIHEADER *hdr); +ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_transactionID(const OSSL_CMP_PKIHEADER *hdr); ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_recipNonce(const OSSL_CMP_PKIHEADER *hdr); STACK_OF(OSSL_CMP_ITAV) - *OSSL_CMP_HDR_get0_geninfo_ITAVs(const OSSL_CMP_PKIHEADER *hdr); +*OSSL_CMP_HDR_get0_geninfo_ITAVs(const OSSL_CMP_PKIHEADER *hdr); /* from cmp_msg.c */ OSSL_CMP_PKIHEADER *OSSL_CMP_MSG_get0_header(const OSSL_CMP_MSG *msg); @@ -613,7 +628,7 @@ int OSSL_CMP_MSG_update_transactionID(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg); int OSSL_CMP_MSG_update_recipNonce(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg); OSSL_CRMF_MSG *OSSL_CMP_CTX_setup_CRM(OSSL_CMP_CTX *ctx, int for_KUR, int rid); OSSL_CMP_MSG *OSSL_CMP_MSG_read(const char *file, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); int OSSL_CMP_MSG_write(const char *file, const OSSL_CMP_MSG *msg); OSSL_CMP_MSG *d2i_OSSL_CMP_MSG_bio(BIO *bio, OSSL_CMP_MSG **msg); int i2d_OSSL_CMP_MSG_bio(BIO *bio, const OSSL_CMP_MSG *msg); @@ -621,107 +636,106 @@ int i2d_OSSL_CMP_MSG_bio(BIO *bio, const OSSL_CMP_MSG *msg); /* from cmp_vfy.c */ int OSSL_CMP_validate_msg(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg); int OSSL_CMP_validate_cert_path(const OSSL_CMP_CTX *ctx, - X509_STORE *trusted_store, X509 *cert); + X509_STORE *trusted_store, X509 *cert); /* from cmp_http.c */ -# ifndef OPENSSL_NO_HTTP +#ifndef OPENSSL_NO_HTTP OSSL_CMP_MSG *OSSL_CMP_MSG_http_perform(OSSL_CMP_CTX *ctx, - const OSSL_CMP_MSG *req); -# endif + const OSSL_CMP_MSG *req); +#endif /* from cmp_server.c */ typedef struct ossl_cmp_srv_ctx_st OSSL_CMP_SRV_CTX; OSSL_CMP_MSG *OSSL_CMP_SRV_process_request(OSSL_CMP_SRV_CTX *srv_ctx, - const OSSL_CMP_MSG *req); -OSSL_CMP_MSG * OSSL_CMP_CTX_server_perform(OSSL_CMP_CTX *client_ctx, - const OSSL_CMP_MSG *req); + const OSSL_CMP_MSG *req); +OSSL_CMP_MSG *OSSL_CMP_CTX_server_perform(OSSL_CMP_CTX *client_ctx, + const OSSL_CMP_MSG *req); OSSL_CMP_SRV_CTX *OSSL_CMP_SRV_CTX_new(OSSL_LIB_CTX *libctx, const char *propq); void OSSL_CMP_SRV_CTX_free(OSSL_CMP_SRV_CTX *srv_ctx); -typedef OSSL_CMP_PKISI *(*OSSL_CMP_SRV_cert_request_cb_t) - (OSSL_CMP_SRV_CTX *srv_ctx, const OSSL_CMP_MSG *req, int certReqId, - const OSSL_CRMF_MSG *crm, const X509_REQ *p10cr, - X509 **certOut, STACK_OF(X509) **chainOut, STACK_OF(X509) **caPubs); +typedef OSSL_CMP_PKISI *(*OSSL_CMP_SRV_cert_request_cb_t)(OSSL_CMP_SRV_CTX *srv_ctx, const OSSL_CMP_MSG *req, int certReqId, + const OSSL_CRMF_MSG *crm, const X509_REQ *p10cr, + X509 **certOut, STACK_OF(X509) **chainOut, STACK_OF(X509) **caPubs); typedef OSSL_CMP_PKISI *(*OSSL_CMP_SRV_rr_cb_t)(OSSL_CMP_SRV_CTX *srv_ctx, - const OSSL_CMP_MSG *req, - const X509_NAME *issuer, - const ASN1_INTEGER *serial); + const OSSL_CMP_MSG *req, + const X509_NAME *issuer, + const ASN1_INTEGER *serial); typedef int (*OSSL_CMP_SRV_genm_cb_t)(OSSL_CMP_SRV_CTX *srv_ctx, - const OSSL_CMP_MSG *req, - const STACK_OF(OSSL_CMP_ITAV) *in, - STACK_OF(OSSL_CMP_ITAV) **out); + const OSSL_CMP_MSG *req, + const STACK_OF(OSSL_CMP_ITAV) *in, + STACK_OF(OSSL_CMP_ITAV) **out); typedef void (*OSSL_CMP_SRV_error_cb_t)(OSSL_CMP_SRV_CTX *srv_ctx, - const OSSL_CMP_MSG *req, - const OSSL_CMP_PKISI *statusInfo, - const ASN1_INTEGER *errorCode, - const OSSL_CMP_PKIFREETEXT *errDetails); + const OSSL_CMP_MSG *req, + const OSSL_CMP_PKISI *statusInfo, + const ASN1_INTEGER *errorCode, + const OSSL_CMP_PKIFREETEXT *errDetails); typedef int (*OSSL_CMP_SRV_certConf_cb_t)(OSSL_CMP_SRV_CTX *srv_ctx, - const OSSL_CMP_MSG *req, - int certReqId, - const ASN1_OCTET_STRING *certHash, - const OSSL_CMP_PKISI *si); + const OSSL_CMP_MSG *req, + int certReqId, + const ASN1_OCTET_STRING *certHash, + const OSSL_CMP_PKISI *si); typedef int (*OSSL_CMP_SRV_pollReq_cb_t)(OSSL_CMP_SRV_CTX *srv_ctx, - const OSSL_CMP_MSG *req, int certReqId, - OSSL_CMP_MSG **certReq, - int64_t *check_after); + const OSSL_CMP_MSG *req, int certReqId, + OSSL_CMP_MSG **certReq, + int64_t *check_after); int OSSL_CMP_SRV_CTX_init(OSSL_CMP_SRV_CTX *srv_ctx, void *custom_ctx, - OSSL_CMP_SRV_cert_request_cb_t process_cert_request, - OSSL_CMP_SRV_rr_cb_t process_rr, - OSSL_CMP_SRV_genm_cb_t process_genm, - OSSL_CMP_SRV_error_cb_t process_error, - OSSL_CMP_SRV_certConf_cb_t process_certConf, - OSSL_CMP_SRV_pollReq_cb_t process_pollReq); + OSSL_CMP_SRV_cert_request_cb_t process_cert_request, + OSSL_CMP_SRV_rr_cb_t process_rr, + OSSL_CMP_SRV_genm_cb_t process_genm, + OSSL_CMP_SRV_error_cb_t process_error, + OSSL_CMP_SRV_certConf_cb_t process_certConf, + OSSL_CMP_SRV_pollReq_cb_t process_pollReq); typedef int (*OSSL_CMP_SRV_delayed_delivery_cb_t)(OSSL_CMP_SRV_CTX *srv_ctx, - const OSSL_CMP_MSG *req); + const OSSL_CMP_MSG *req); typedef int (*OSSL_CMP_SRV_clean_transaction_cb_t)(OSSL_CMP_SRV_CTX *srv_ctx, - const ASN1_OCTET_STRING *id); + const ASN1_OCTET_STRING *id); int OSSL_CMP_SRV_CTX_init_trans(OSSL_CMP_SRV_CTX *srv_ctx, - OSSL_CMP_SRV_delayed_delivery_cb_t delay, - OSSL_CMP_SRV_clean_transaction_cb_t clean); + OSSL_CMP_SRV_delayed_delivery_cb_t delay, + OSSL_CMP_SRV_clean_transaction_cb_t clean); OSSL_CMP_CTX *OSSL_CMP_SRV_CTX_get0_cmp_ctx(const OSSL_CMP_SRV_CTX *srv_ctx); void *OSSL_CMP_SRV_CTX_get0_custom_ctx(const OSSL_CMP_SRV_CTX *srv_ctx); int OSSL_CMP_SRV_CTX_set_send_unprotected_errors(OSSL_CMP_SRV_CTX *srv_ctx, - int val); + int val); int OSSL_CMP_SRV_CTX_set_accept_unprotected(OSSL_CMP_SRV_CTX *srv_ctx, int val); int OSSL_CMP_SRV_CTX_set_accept_raverified(OSSL_CMP_SRV_CTX *srv_ctx, int val); int OSSL_CMP_SRV_CTX_set_grant_implicit_confirm(OSSL_CMP_SRV_CTX *srv_ctx, - int val); + int val); /* from cmp_client.c */ X509 *OSSL_CMP_exec_certreq(OSSL_CMP_CTX *ctx, int req_type, - const OSSL_CRMF_MSG *crm); -# define OSSL_CMP_IR 0 -# define OSSL_CMP_CR 2 -# define OSSL_CMP_P10CR 4 -# define OSSL_CMP_KUR 7 -# define OSSL_CMP_GENM 21 -# define OSSL_CMP_ERROR 23 -# define OSSL_CMP_exec_IR_ses(ctx) \ + const OSSL_CRMF_MSG *crm); +#define OSSL_CMP_IR 0 +#define OSSL_CMP_CR 2 +#define OSSL_CMP_P10CR 4 +#define OSSL_CMP_KUR 7 +#define OSSL_CMP_GENM 21 +#define OSSL_CMP_ERROR 23 +#define OSSL_CMP_exec_IR_ses(ctx) \ OSSL_CMP_exec_certreq(ctx, OSSL_CMP_IR, NULL) -# define OSSL_CMP_exec_CR_ses(ctx) \ +#define OSSL_CMP_exec_CR_ses(ctx) \ OSSL_CMP_exec_certreq(ctx, OSSL_CMP_CR, NULL) -# define OSSL_CMP_exec_P10CR_ses(ctx) \ +#define OSSL_CMP_exec_P10CR_ses(ctx) \ OSSL_CMP_exec_certreq(ctx, OSSL_CMP_P10CR, NULL) -# define OSSL_CMP_exec_KUR_ses(ctx) \ +#define OSSL_CMP_exec_KUR_ses(ctx) \ OSSL_CMP_exec_certreq(ctx, OSSL_CMP_KUR, NULL) int OSSL_CMP_try_certreq(OSSL_CMP_CTX *ctx, int req_type, - const OSSL_CRMF_MSG *crm, int *checkAfter); + const OSSL_CRMF_MSG *crm, int *checkAfter); int OSSL_CMP_exec_RR_ses(OSSL_CMP_CTX *ctx); STACK_OF(OSSL_CMP_ITAV) *OSSL_CMP_exec_GENM_ses(OSSL_CMP_CTX *ctx); /* from cmp_genm.c */ int OSSL_CMP_get1_caCerts(OSSL_CMP_CTX *ctx, STACK_OF(X509) **out); int OSSL_CMP_get1_rootCaKeyUpdate(OSSL_CMP_CTX *ctx, - const X509 *oldWithOld, X509 **newWithNew, - X509 **newWithOld, X509 **oldWithNew); + const X509 *oldWithOld, X509 **newWithNew, + X509 **newWithOld, X509 **oldWithNew); int OSSL_CMP_get1_crlUpdate(OSSL_CMP_CTX *ctx, const X509 *crlcert, - const X509_CRL *last_crl, - X509_CRL **crl); + const X509_CRL *last_crl, + X509_CRL **crl); int OSSL_CMP_get1_certReqTemplate(OSSL_CMP_CTX *ctx, - OSSL_CRMF_CERTTEMPLATE **certTemplate, - OSSL_CMP_ATAVS **keySpec); + OSSL_CRMF_CERTTEMPLATE **certTemplate, + OSSL_CMP_ATAVS **keySpec); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif -# endif /* !defined(OPENSSL_NO_CMP) */ +#endif +#endif /* !defined(OPENSSL_NO_CMP) */ #endif /* !defined(OPENSSL_CMP_H) */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/cms.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/cms.h index 6713419cfc..1fb568a8cb 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/cms.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/cms.h @@ -10,26 +10,28 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_CMS_H -# define OPENSSL_CMS_H -# pragma once +#define OPENSSL_CMS_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_CMS_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_CMS_H +#endif -# include +#include -# ifndef OPENSSL_NO_CMS -# include -# include -# include -# ifdef __cplusplus +#ifndef OPENSSL_NO_CMS +#include +#include +#include +#ifdef __cplusplus extern "C" { -# endif +#endif typedef struct CMS_EnvelopedData_st CMS_EnvelopedData; typedef struct CMS_ContentInfo_st CMS_ContentInfo; @@ -43,6 +45,7 @@ typedef struct CMS_Receipt_st CMS_Receipt; typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey; typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(CMS_SignerInfo, CMS_SignerInfo, CMS_SignerInfo) #define sk_CMS_SignerInfo_num(sk) OPENSSL_sk_num(ossl_check_const_CMS_SignerInfo_sk_type(sk)) #define sk_CMS_SignerInfo_value(sk, idx) ((CMS_SignerInfo *)OPENSSL_sk_value(ossl_check_const_CMS_SignerInfo_sk_type(sk), (idx))) @@ -148,6 +151,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(CMS_RevocationInfoChoice, CMS_RevocationInfoChoice, #define sk_CMS_RevocationInfoChoice_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(CMS_RevocationInfoChoice) *)OPENSSL_sk_deep_copy(ossl_check_const_CMS_RevocationInfoChoice_sk_type(sk), ossl_check_CMS_RevocationInfoChoice_copyfunc_type(copyfunc), ossl_check_CMS_RevocationInfoChoice_freefunc_type(freefunc))) #define sk_CMS_RevocationInfoChoice_set_cmp_func(sk, cmp) ((sk_CMS_RevocationInfoChoice_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_CMS_RevocationInfoChoice_sk_type(sk), ossl_check_CMS_RevocationInfoChoice_compfunc_type(cmp))) +/* clang-format on */ DECLARE_ASN1_ITEM(CMS_EnvelopedData) DECLARE_ASN1_ALLOC_FUNCTIONS(CMS_SignedData) @@ -159,44 +163,44 @@ DECLARE_ASN1_DUP_FUNCTION(CMS_EnvelopedData) CMS_ContentInfo *CMS_ContentInfo_new_ex(OSSL_LIB_CTX *libctx, const char *propq); -# define CMS_SIGNERINFO_ISSUER_SERIAL 0 -# define CMS_SIGNERINFO_KEYIDENTIFIER 1 +#define CMS_SIGNERINFO_ISSUER_SERIAL 0 +#define CMS_SIGNERINFO_KEYIDENTIFIER 1 -# define CMS_RECIPINFO_NONE -1 -# define CMS_RECIPINFO_TRANS 0 -# define CMS_RECIPINFO_AGREE 1 -# define CMS_RECIPINFO_KEK 2 -# define CMS_RECIPINFO_PASS 3 -# define CMS_RECIPINFO_OTHER 4 +#define CMS_RECIPINFO_NONE -1 +#define CMS_RECIPINFO_TRANS 0 +#define CMS_RECIPINFO_AGREE 1 +#define CMS_RECIPINFO_KEK 2 +#define CMS_RECIPINFO_PASS 3 +#define CMS_RECIPINFO_OTHER 4 /* S/MIME related flags */ -# define CMS_TEXT 0x1 -# define CMS_NOCERTS 0x2 -# define CMS_NO_CONTENT_VERIFY 0x4 -# define CMS_NO_ATTR_VERIFY 0x8 -# define CMS_NOSIGS \ - (CMS_NO_CONTENT_VERIFY|CMS_NO_ATTR_VERIFY) -# define CMS_NOINTERN 0x10 -# define CMS_NO_SIGNER_CERT_VERIFY 0x20 -# define CMS_NOVERIFY 0x20 -# define CMS_DETACHED 0x40 -# define CMS_BINARY 0x80 -# define CMS_NOATTR 0x100 -# define CMS_NOSMIMECAP 0x200 -# define CMS_NOOLDMIMETYPE 0x400 -# define CMS_CRLFEOL 0x800 -# define CMS_STREAM 0x1000 -# define CMS_NOCRL 0x2000 -# define CMS_PARTIAL 0x4000 -# define CMS_REUSE_DIGEST 0x8000 -# define CMS_USE_KEYID 0x10000 -# define CMS_DEBUG_DECRYPT 0x20000 -# define CMS_KEY_PARAM 0x40000 -# define CMS_ASCIICRLF 0x80000 -# define CMS_CADES 0x100000 -# define CMS_USE_ORIGINATOR_KEYID 0x200000 -# define CMS_NO_SIGNING_TIME 0x400000 +#define CMS_TEXT 0x1 +#define CMS_NOCERTS 0x2 +#define CMS_NO_CONTENT_VERIFY 0x4 +#define CMS_NO_ATTR_VERIFY 0x8 +#define CMS_NOSIGS \ + (CMS_NO_CONTENT_VERIFY | CMS_NO_ATTR_VERIFY) +#define CMS_NOINTERN 0x10 +#define CMS_NO_SIGNER_CERT_VERIFY 0x20 +#define CMS_NOVERIFY 0x20 +#define CMS_DETACHED 0x40 +#define CMS_BINARY 0x80 +#define CMS_NOATTR 0x100 +#define CMS_NOSMIMECAP 0x200 +#define CMS_NOOLDMIMETYPE 0x400 +#define CMS_CRLFEOL 0x800 +#define CMS_STREAM 0x1000 +#define CMS_NOCRL 0x2000 +#define CMS_PARTIAL 0x4000 +#define CMS_REUSE_DIGEST 0x8000 +#define CMS_USE_KEYID 0x10000 +#define CMS_DEBUG_DECRYPT 0x20000 +#define CMS_KEY_PARAM 0x40000 +#define CMS_ASCIICRLF 0x80000 +#define CMS_CADES 0x100000 +#define CMS_USE_ORIGINATOR_KEYID 0x200000 +#define CMS_NO_SIGNING_TIME 0x400000 const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms); @@ -207,9 +211,9 @@ ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms); int CMS_is_detached(CMS_ContentInfo *cms); int CMS_set_detached(CMS_ContentInfo *cms, int detached); -# ifdef OPENSSL_PEM_H +#ifdef OPENSSL_PEM_H DECLARE_PEM_rw(CMS, CMS_ContentInfo) -# endif +#endif int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms); CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms); int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms); @@ -217,83 +221,83 @@ int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms); BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms); int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags); int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, - int flags); + int flags); CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont); CMS_ContentInfo *SMIME_read_CMS_ex(BIO *bio, int flags, BIO **bcont, CMS_ContentInfo **ci); int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags); int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, - unsigned int flags); + unsigned int flags); int CMS_final_digest(CMS_ContentInfo *cms, - const unsigned char *md, unsigned int mdlen, BIO *dcont, - unsigned int flags); + const unsigned char *md, unsigned int mdlen, BIO *dcont, + unsigned int flags); CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, - STACK_OF(X509) *certs, BIO *data, - unsigned int flags); + STACK_OF(X509) *certs, BIO *data, + unsigned int flags); CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey, - STACK_OF(X509) *certs, BIO *data, - unsigned int flags, OSSL_LIB_CTX *libctx, - const char *propq); + STACK_OF(X509) *certs, BIO *data, + unsigned int flags, OSSL_LIB_CTX *libctx, + const char *propq); CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si, - X509 *signcert, EVP_PKEY *pkey, - STACK_OF(X509) *certs, unsigned int flags); + X509 *signcert, EVP_PKEY *pkey, + STACK_OF(X509) *certs, unsigned int flags); int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags); CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags); CMS_ContentInfo *CMS_data_create_ex(BIO *in, unsigned int flags, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, - unsigned int flags); + unsigned int flags); CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md, - unsigned int flags); + unsigned int flags); CMS_ContentInfo *CMS_digest_create_ex(BIO *in, const EVP_MD *md, - unsigned int flags, OSSL_LIB_CTX *libctx, - const char *propq); + unsigned int flags, OSSL_LIB_CTX *libctx, + const char *propq); int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, - const unsigned char *key, size_t keylen, - BIO *dcont, BIO *out, unsigned int flags); + const unsigned char *key, size_t keylen, + BIO *dcont, BIO *out, unsigned int flags); CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, - const unsigned char *key, - size_t keylen, unsigned int flags); + const unsigned char *key, + size_t keylen, unsigned int flags); CMS_ContentInfo *CMS_EncryptedData_encrypt_ex(BIO *in, const EVP_CIPHER *cipher, - const unsigned char *key, - size_t keylen, unsigned int flags, - OSSL_LIB_CTX *libctx, - const char *propq); + const unsigned char *key, + size_t keylen, unsigned int flags, + OSSL_LIB_CTX *libctx, + const char *propq); int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph, - const unsigned char *key, size_t keylen); + const unsigned char *key, size_t keylen); int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, - X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags); + X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags); int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms, - STACK_OF(X509) *certs, - X509_STORE *store, unsigned int flags); + STACK_OF(X509) *certs, + X509_STORE *store, unsigned int flags); STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms); CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in, - const EVP_CIPHER *cipher, unsigned int flags); + const EVP_CIPHER *cipher, unsigned int flags); CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *in, - const EVP_CIPHER *cipher, unsigned int flags, - OSSL_LIB_CTX *libctx, const char *propq); + const EVP_CIPHER *cipher, unsigned int flags, + OSSL_LIB_CTX *libctx, const char *propq); int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert, - BIO *dcont, BIO *out, unsigned int flags); + BIO *dcont, BIO *out, unsigned int flags); int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert); int CMS_decrypt_set1_pkey_and_peer(CMS_ContentInfo *cms, EVP_PKEY *pk, - X509 *cert, X509 *peer); + X509 *cert, X509 *peer); int CMS_decrypt_set1_key(CMS_ContentInfo *cms, - unsigned char *key, size_t keylen, - const unsigned char *id, size_t idlen); + unsigned char *key, size_t keylen, + const unsigned char *id, size_t idlen); int CMS_decrypt_set1_password(CMS_ContentInfo *cms, - unsigned char *pass, ossl_ssize_t passlen); + unsigned char *pass, ossl_ssize_t passlen); STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms); int CMS_RecipientInfo_type(CMS_RecipientInfo *ri); @@ -301,66 +305,66 @@ EVP_PKEY_CTX *CMS_RecipientInfo_get0_pkey_ctx(CMS_RecipientInfo *ri); CMS_ContentInfo *CMS_AuthEnvelopedData_create(const EVP_CIPHER *cipher); CMS_ContentInfo * CMS_AuthEnvelopedData_create_ex(const EVP_CIPHER *cipher, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher); CMS_ContentInfo *CMS_EnvelopedData_create_ex(const EVP_CIPHER *cipher, - OSSL_LIB_CTX *libctx, - const char *propq); + OSSL_LIB_CTX *libctx, + const char *propq); BIO *CMS_EnvelopedData_decrypt(CMS_EnvelopedData *env, BIO *detached_data, - EVP_PKEY *pkey, X509 *cert, - ASN1_OCTET_STRING *secret, unsigned int flags, - OSSL_LIB_CTX *libctx, const char *propq); + EVP_PKEY *pkey, X509 *cert, + ASN1_OCTET_STRING *secret, unsigned int flags, + OSSL_LIB_CTX *libctx, const char *propq); CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms, - X509 *recip, unsigned int flags); + X509 *recip, unsigned int flags); CMS_RecipientInfo *CMS_add1_recipient(CMS_ContentInfo *cms, X509 *recip, - EVP_PKEY *originatorPrivKey, X509 * originator, unsigned int flags); + EVP_PKEY *originatorPrivKey, X509 *originator, unsigned int flags); int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey); int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert); int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri, - EVP_PKEY **pk, X509 **recip, - X509_ALGOR **palg); + EVP_PKEY **pk, X509 **recip, + X509_ALGOR **palg); int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri, - ASN1_OCTET_STRING **keyid, - X509_NAME **issuer, - ASN1_INTEGER **sno); + ASN1_OCTET_STRING **keyid, + X509_NAME **issuer, + ASN1_INTEGER **sno); CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid, - unsigned char *key, size_t keylen, - unsigned char *id, size_t idlen, - ASN1_GENERALIZEDTIME *date, - ASN1_OBJECT *otherTypeId, - ASN1_TYPE *otherType); + unsigned char *key, size_t keylen, + unsigned char *id, size_t idlen, + ASN1_GENERALIZEDTIME *date, + ASN1_OBJECT *otherTypeId, + ASN1_TYPE *otherType); int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri, - X509_ALGOR **palg, - ASN1_OCTET_STRING **pid, - ASN1_GENERALIZEDTIME **pdate, - ASN1_OBJECT **potherid, - ASN1_TYPE **pothertype); + X509_ALGOR **palg, + ASN1_OCTET_STRING **pid, + ASN1_GENERALIZEDTIME **pdate, + ASN1_OBJECT **potherid, + ASN1_TYPE **pothertype); int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri, - unsigned char *key, size_t keylen); + unsigned char *key, size_t keylen); int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri, - const unsigned char *id, size_t idlen); + const unsigned char *id, size_t idlen); int CMS_RecipientInfo_set0_password(CMS_RecipientInfo *ri, - unsigned char *pass, - ossl_ssize_t passlen); + unsigned char *pass, + ossl_ssize_t passlen); CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms, - int iter, int wrap_nid, - int pbe_nid, - unsigned char *pass, - ossl_ssize_t passlen, - const EVP_CIPHER *kekciph); + int iter, int wrap_nid, + int pbe_nid, + unsigned char *pass, + ossl_ssize_t passlen, + const EVP_CIPHER *kekciph); int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri); int CMS_RecipientInfo_encrypt(const CMS_ContentInfo *cms, CMS_RecipientInfo *ri); int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, - unsigned int flags); + unsigned int flags); CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags); int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid); @@ -378,77 +382,77 @@ STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms); int CMS_SignedData_init(CMS_ContentInfo *cms); CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, - X509 *signer, EVP_PKEY *pk, const EVP_MD *md, - unsigned int flags); + X509 *signer, EVP_PKEY *pk, const EVP_MD *md, + unsigned int flags); EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si); EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si); STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms); void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer); int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si, - ASN1_OCTET_STRING **keyid, - X509_NAME **issuer, ASN1_INTEGER **sno); + ASN1_OCTET_STRING **keyid, + X509_NAME **issuer, ASN1_INTEGER **sno); int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert); int CMS_set1_signers_certs(CMS_ContentInfo *cms, STACK_OF(X509) *certs, - unsigned int flags); + unsigned int flags); void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, - X509 **signer, X509_ALGOR **pdig, - X509_ALGOR **psig); + X509 **signer, X509_ALGOR **pdig, + X509_ALGOR **psig); ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si); int CMS_SignerInfo_sign(CMS_SignerInfo *si); int CMS_SignerInfo_verify(CMS_SignerInfo *si); int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain); BIO *CMS_SignedData_verify(CMS_SignedData *sd, BIO *detached_data, - STACK_OF(X509) *scerts, X509_STORE *store, - STACK_OF(X509) *extra, STACK_OF(X509_CRL) *crls, - unsigned int flags, - OSSL_LIB_CTX *libctx, const char *propq); + STACK_OF(X509) *scerts, X509_STORE *store, + STACK_OF(X509) *extra, STACK_OF(X509_CRL) *crls, + unsigned int flags, + OSSL_LIB_CTX *libctx, const char *propq); int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs); int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs, - int algnid, int keysize); + int algnid, int keysize); int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap); int CMS_signed_get_attr_count(const CMS_SignerInfo *si); int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid, - int lastpos); + int lastpos); int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj, - int lastpos); + int lastpos); X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc); X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc); int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr); int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si, - const ASN1_OBJECT *obj, int type, - const void *bytes, int len); + const ASN1_OBJECT *obj, int type, + const void *bytes, int len); int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si, - int nid, int type, - const void *bytes, int len); + int nid, int type, + const void *bytes, int len); int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si, - const char *attrname, int type, - const void *bytes, int len); + const char *attrname, int type, + const void *bytes, int len); void *CMS_signed_get0_data_by_OBJ(const CMS_SignerInfo *si, - const ASN1_OBJECT *oid, - int lastpos, int type); + const ASN1_OBJECT *oid, + int lastpos, int type); int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si); int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid, - int lastpos); + int lastpos); int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si, - const ASN1_OBJECT *obj, int lastpos); + const ASN1_OBJECT *obj, int lastpos); X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc); X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc); int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr); int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si, - const ASN1_OBJECT *obj, int type, - const void *bytes, int len); + const ASN1_OBJECT *obj, int type, + const void *bytes, int len); int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si, - int nid, int type, - const void *bytes, int len); + int nid, int type, + const void *bytes, int len); int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si, - const char *attrname, int type, - const void *bytes, int len); + const char *attrname, int type, + const void *bytes, int len); void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid, - int lastpos, int type); + int lastpos, int type); int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr); CMS_ReceiptRequest *CMS_ReceiptRequest_create0( @@ -463,49 +467,49 @@ CMS_ReceiptRequest *CMS_ReceiptRequest_create0_ex( int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr); void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, - ASN1_STRING **pcid, - int *pallorfirst, - STACK_OF(GENERAL_NAMES) **plist, - STACK_OF(GENERAL_NAMES) **prto); + ASN1_STRING **pcid, + int *pallorfirst, + STACK_OF(GENERAL_NAMES) **plist, + STACK_OF(GENERAL_NAMES) **prto); int CMS_RecipientInfo_kari_get0_alg(CMS_RecipientInfo *ri, - X509_ALGOR **palg, - ASN1_OCTET_STRING **pukm); + X509_ALGOR **palg, + ASN1_OCTET_STRING **pukm); STACK_OF(CMS_RecipientEncryptedKey) *CMS_RecipientInfo_kari_get0_reks(CMS_RecipientInfo *ri); int CMS_RecipientInfo_kari_get0_orig_id(CMS_RecipientInfo *ri, - X509_ALGOR **pubalg, - ASN1_BIT_STRING **pubkey, - ASN1_OCTET_STRING **keyid, - X509_NAME **issuer, - ASN1_INTEGER **sno); + X509_ALGOR **pubalg, + ASN1_BIT_STRING **pubkey, + ASN1_OCTET_STRING **keyid, + X509_NAME **issuer, + ASN1_INTEGER **sno); int CMS_RecipientInfo_kari_orig_id_cmp(CMS_RecipientInfo *ri, X509 *cert); int CMS_RecipientEncryptedKey_get0_id(CMS_RecipientEncryptedKey *rek, - ASN1_OCTET_STRING **keyid, - ASN1_GENERALIZEDTIME **tm, - CMS_OtherKeyAttribute **other, - X509_NAME **issuer, ASN1_INTEGER **sno); + ASN1_OCTET_STRING **keyid, + ASN1_GENERALIZEDTIME **tm, + CMS_OtherKeyAttribute **other, + X509_NAME **issuer, ASN1_INTEGER **sno); int CMS_RecipientEncryptedKey_cert_cmp(CMS_RecipientEncryptedKey *rek, - X509 *cert); + X509 *cert); int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk); int CMS_RecipientInfo_kari_set0_pkey_and_peer(CMS_RecipientInfo *ri, EVP_PKEY *pk, X509 *peer); EVP_CIPHER_CTX *CMS_RecipientInfo_kari_get0_ctx(CMS_RecipientInfo *ri); int CMS_RecipientInfo_kari_decrypt(CMS_ContentInfo *cms, - CMS_RecipientInfo *ri, - CMS_RecipientEncryptedKey *rek); + CMS_RecipientInfo *ri, + CMS_RecipientEncryptedKey *rek); int CMS_SharedInfo_encode(unsigned char **pder, X509_ALGOR *kekalg, - ASN1_OCTET_STRING *ukm, int keylen); + ASN1_OCTET_STRING *ukm, int keylen); /* Backward compatibility for spelling errors. */ -# define CMS_R_UNKNOWN_DIGEST_ALGORITM CMS_R_UNKNOWN_DIGEST_ALGORITHM -# define CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE \ +#define CMS_R_UNKNOWN_DIGEST_ALGORITM CMS_R_UNKNOWN_DIGEST_ALGORITHM +#define CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE \ CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE -# ifdef __cplusplus +#ifdef __cplusplus } -# endif -# endif +#endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/comp.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/comp.h index 1aa062f192..694e76cf3d 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/comp.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/comp.h @@ -7,40 +7,40 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_COMP_H -# define OPENSSL_COMP_H -# pragma once +#define OPENSSL_COMP_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_COMP_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_COMP_H +#endif -# include +#include -# include -# include -# ifdef __cplusplus +#include +#include +#ifdef __cplusplus extern "C" { -# endif +#endif - - -# ifndef OPENSSL_NO_COMP +#ifndef OPENSSL_NO_COMP COMP_CTX *COMP_CTX_new(COMP_METHOD *meth); const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx); -int COMP_CTX_get_type(const COMP_CTX* comp); +int COMP_CTX_get_type(const COMP_CTX *comp); int COMP_get_type(const COMP_METHOD *meth); const char *COMP_get_name(const COMP_METHOD *meth); void COMP_CTX_free(COMP_CTX *ctx); int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, - unsigned char *in, int ilen); + unsigned char *in, int ilen); int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, - unsigned char *in, int ilen); + unsigned char *in, int ilen); COMP_METHOD *COMP_zlib(void); COMP_METHOD *COMP_zlib_oneshot(void); @@ -49,20 +49,23 @@ COMP_METHOD *COMP_brotli_oneshot(void); COMP_METHOD *COMP_zstd(void); COMP_METHOD *COMP_zstd_oneshot(void); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define COMP_zlib_cleanup() while(0) continue -# endif +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define COMP_zlib_cleanup() \ + while (0) \ + continue +#endif -# ifdef OPENSSL_BIO_H +#ifdef OPENSSL_BIO_H const BIO_METHOD *BIO_f_zlib(void); const BIO_METHOD *BIO_f_brotli(void); const BIO_METHOD *BIO_f_zstd(void); -# endif +#endif -# endif +#endif typedef struct ssl_comp_st SSL_COMP; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(SSL_COMP, SSL_COMP, SSL_COMP) #define sk_SSL_COMP_num(sk) OPENSSL_sk_num(ossl_check_const_SSL_COMP_sk_type(sk)) #define sk_SSL_COMP_value(sk, idx) ((SSL_COMP *)OPENSSL_sk_value(ossl_check_const_SSL_COMP_sk_type(sk), (idx))) @@ -90,9 +93,9 @@ SKM_DEFINE_STACK_OF_INTERNAL(SSL_COMP, SSL_COMP, SSL_COMP) #define sk_SSL_COMP_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_deep_copy(ossl_check_const_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_copyfunc_type(copyfunc), ossl_check_SSL_COMP_freefunc_type(freefunc))) #define sk_SSL_COMP_set_cmp_func(sk, cmp) ((sk_SSL_COMP_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_compfunc_type(cmp))) +/* clang-format on */ - -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/conf.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/conf.h index 195bb014db..4e4ea8f747 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/conf.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/conf.h @@ -10,28 +10,30 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ -#ifndef OPENSSL_CONF_H -# define OPENSSL_CONF_H -# pragma once +#ifndef OPENSSL_CONF_H +#define OPENSSL_CONF_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_CONF_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_CONF_H +#endif -# include -# include -# include -# include -# include -# include -# ifndef OPENSSL_NO_STDIO -# include -# endif +#include +#include +#include +#include +#include +#include +#ifndef OPENSSL_NO_STDIO +#include +#endif -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -41,6 +43,7 @@ typedef struct { char *value; } CONF_VALUE; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(CONF_VALUE, CONF_VALUE, CONF_VALUE) #define sk_CONF_VALUE_num(sk) OPENSSL_sk_num(ossl_check_const_CONF_VALUE_sk_type(sk)) #define sk_CONF_VALUE_value(sk, idx) ((CONF_VALUE *)OPENSSL_sk_value(ossl_check_const_CONF_VALUE_sk_type(sk), (idx))) @@ -83,14 +86,15 @@ DEFINE_LHASH_OF_INTERNAL(CONF_VALUE); #define lh_CONF_VALUE_set_down_load(lh, dl) OPENSSL_LH_set_down_load(ossl_check_CONF_VALUE_lh_type(lh), dl) #define lh_CONF_VALUE_doall(lh, dfn) OPENSSL_LH_doall(ossl_check_CONF_VALUE_lh_type(lh), ossl_check_CONF_VALUE_lh_doallfunc_type(dfn)) +/* clang-format on */ struct conf_st; struct conf_method_st; typedef struct conf_method_st CONF_METHOD; -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# include -# endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#include +#endif /* Module definitions */ typedef struct conf_imodule_st CONF_IMODULE; @@ -100,32 +104,32 @@ STACK_OF(CONF_MODULE); STACK_OF(CONF_IMODULE); /* DSO module function typedefs */ -typedef int conf_init_func (CONF_IMODULE *md, const CONF *cnf); -typedef void conf_finish_func (CONF_IMODULE *md); +typedef int conf_init_func(CONF_IMODULE *md, const CONF *cnf); +typedef void conf_finish_func(CONF_IMODULE *md); -# define CONF_MFLAGS_IGNORE_ERRORS 0x1 -# define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2 -# define CONF_MFLAGS_SILENT 0x4 -# define CONF_MFLAGS_NO_DSO 0x8 -# define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10 -# define CONF_MFLAGS_DEFAULT_SECTION 0x20 +#define CONF_MFLAGS_IGNORE_ERRORS 0x1 +#define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2 +#define CONF_MFLAGS_SILENT 0x4 +#define CONF_MFLAGS_NO_DSO 0x8 +#define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10 +#define CONF_MFLAGS_DEFAULT_SECTION 0x20 int CONF_set_default_method(CONF_METHOD *meth); void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash); LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file, - long *eline); -# ifndef OPENSSL_NO_STDIO + long *eline); +#ifndef OPENSSL_NO_STDIO LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp, - long *eline); -# endif + long *eline); +#endif LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp, - long *eline); + long *eline); STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf, - const char *section); + const char *section); char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group, - const char *name); + const char *name); long CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group, - const char *name); + const char *name); void CONF_free(LHASH_OF(CONF_VALUE) *conf); #ifndef OPENSSL_NO_STDIO int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out); @@ -136,7 +140,7 @@ OSSL_DEPRECATEDIN_1_1_0 void OPENSSL_config(const char *config_name); #endif #ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define OPENSSL_no_config() \ +#define OPENSSL_no_config() \ OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL) #endif @@ -156,38 +160,40 @@ void NCONF_free(CONF *conf); void NCONF_free_data(CONF *conf); int NCONF_load(CONF *conf, const char *file, long *eline); -# ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_STDIO int NCONF_load_fp(CONF *conf, FILE *fp, long *eline); -# endif +#endif int NCONF_load_bio(CONF *conf, BIO *bp, long *eline); STACK_OF(OPENSSL_CSTRING) *NCONF_get_section_names(const CONF *conf); STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, - const char *section); + const char *section); char *NCONF_get_string(const CONF *conf, const char *group, const char *name); int NCONF_get_number_e(const CONF *conf, const char *group, const char *name, - long *result); + long *result); #ifndef OPENSSL_NO_STDIO int NCONF_dump_fp(const CONF *conf, FILE *out); #endif int NCONF_dump_bio(const CONF *conf, BIO *out); -#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r) +#define NCONF_get_number(c, g, n, r) NCONF_get_number_e(c, g, n, r) /* Module functions */ int CONF_modules_load(const CONF *cnf, const char *appname, - unsigned long flags); + unsigned long flags); int CONF_modules_load_file_ex(OSSL_LIB_CTX *libctx, const char *filename, - const char *appname, unsigned long flags); + const char *appname, unsigned long flags); int CONF_modules_load_file(const char *filename, const char *appname, - unsigned long flags); + unsigned long flags); void CONF_modules_unload(int all); void CONF_modules_finish(void); #ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define CONF_modules_free() while(0) continue +#define CONF_modules_free() \ + while (0) \ + continue #endif int CONF_module_add(const char *name, conf_init_func *ifunc, - conf_finish_func *ffunc); + conf_finish_func *ffunc); const char *CONF_imodule_get_name(const CONF_IMODULE *md); const char *CONF_imodule_get_value(const CONF_IMODULE *md); @@ -202,13 +208,12 @@ void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data); char *CONF_get1_default_config_file(void); int CONF_parse_list(const char *list, int sep, int nospc, - int (*list_cb) (const char *elem, int len, void *usr), - void *arg); + int (*list_cb)(const char *elem, int len, void *usr), + void *arg); void OPENSSL_load_builtin_modules(void); - -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec-lite.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec-lite.h index a552755134..eb3e308185 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec-lite.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec-lite.h @@ -15,394 +15,409 @@ #define OPENSSL_CONFIGURATION_H #pragma once -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif #ifdef OPENSSL_ALGORITHM_DEFINES - #error OPENSSL_ALGORITHM_DEFINES no longer supported +#error OPENSSL_ALGORITHM_DEFINES no longer supported #endif /* * OpenSSL was configured with the following options: */ -#ifndef OPENSSL_SYS_UEFI -#define OPENSSL_SYS_UEFI 1 -#endif -#define OPENSSL_CONFIGURED_API 10101 -#ifndef OPENSSL_RAND_SEED_NONE -#define OPENSSL_RAND_SEED_NONE -#endif -#ifndef OPENSSL_NO_ACVP_TESTS -#define OPENSSL_NO_ACVP_TESTS -#endif -#ifndef OPENSSL_NO_AFALGENG -#define OPENSSL_NO_AFALGENG -#endif -#ifndef OPENSSL_NO_APPS -#define OPENSSL_NO_APPS -#endif -#ifndef OPENSSL_NO_ARGON2 -#define OPENSSL_NO_ARGON2 -#endif -#ifndef OPENSSL_NO_ARIA -#define OPENSSL_NO_ARIA -#endif -#ifndef OPENSSL_NO_ASAN -#define OPENSSL_NO_ASAN -#endif -#ifndef OPENSSL_NO_ASYNC -#define OPENSSL_NO_ASYNC -#endif -#ifndef OPENSSL_NO_AUTOERRINIT -#define OPENSSL_NO_AUTOERRINIT -#endif -#ifndef OPENSSL_NO_AUTOLOAD_CONFIG -#define OPENSSL_NO_AUTOLOAD_CONFIG -#endif -#ifndef OPENSSL_NO_BF -#define OPENSSL_NO_BF -#endif -#ifndef OPENSSL_NO_BLAKE2 -#define OPENSSL_NO_BLAKE2 -#endif -#ifndef OPENSSL_NO_BROTLI -#define OPENSSL_NO_BROTLI -#endif -#ifndef OPENSSL_NO_BROTLI_DYNAMIC -#define OPENSSL_NO_BROTLI_DYNAMIC -#endif -#ifndef OPENSSL_NO_CAMELLIA -#define OPENSSL_NO_CAMELLIA -#endif -#ifndef OPENSSL_NO_CAPIENG -#define OPENSSL_NO_CAPIENG -#endif -#ifndef OPENSSL_NO_CAST -#define OPENSSL_NO_CAST -#endif -#ifndef OPENSSL_NO_CHACHA -#define OPENSSL_NO_CHACHA -#endif -#ifndef OPENSSL_NO_CMP -#define OPENSSL_NO_CMP -#endif -#ifndef OPENSSL_NO_CMS -#define OPENSSL_NO_CMS -#endif -#ifndef OPENSSL_NO_CRMF -#define OPENSSL_NO_CRMF -#endif -#ifndef OPENSSL_NO_CRYPTO_MDEBUG -#define OPENSSL_NO_CRYPTO_MDEBUG -#endif -#ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE -#define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE -#endif -#ifndef OPENSSL_NO_CT -#define OPENSSL_NO_CT -#endif -#ifndef OPENSSL_NO_DEFAULT_THREAD_POOL -#define OPENSSL_NO_DEFAULT_THREAD_POOL -#endif -#ifndef OPENSSL_NO_DEMOS -#define OPENSSL_NO_DEMOS -#endif -#ifndef OPENSSL_NO_DEPRECATED -#define OPENSSL_NO_DEPRECATED -#endif -#ifndef OPENSSL_NO_DES -#define OPENSSL_NO_DES -#endif -#ifndef OPENSSL_NO_DEVCRYPTOENG -#define OPENSSL_NO_DEVCRYPTOENG -#endif -#ifndef OPENSSL_NO_DGRAM -#define OPENSSL_NO_DGRAM -#endif -#ifndef OPENSSL_NO_DH -#define OPENSSL_NO_DH -#endif -#ifndef OPENSSL_NO_DSA -#define OPENSSL_NO_DSA -#endif -#ifndef OPENSSL_NO_DSO -#define OPENSSL_NO_DSO -#endif -#ifndef OPENSSL_NO_DTLS -#define OPENSSL_NO_DTLS -#endif -#ifndef OPENSSL_NO_DTLS1 -#define OPENSSL_NO_DTLS1 -#endif -#ifndef OPENSSL_NO_DTLS1_METHOD -#define OPENSSL_NO_DTLS1_METHOD -#endif -#ifndef OPENSSL_NO_DTLS1_2 -#define OPENSSL_NO_DTLS1_2 -#endif -#ifndef OPENSSL_NO_DTLS1_2_METHOD -#define OPENSSL_NO_DTLS1_2_METHOD -#endif -#ifndef OPENSSL_NO_EC2M -#define OPENSSL_NO_EC2M -#endif -#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 -#define OPENSSL_NO_EC_NISTP_64_GCC_128 -#endif -#ifndef OPENSSL_NO_ECX -#define OPENSSL_NO_ECX -#endif -#ifndef OPENSSL_NO_EGD -#define OPENSSL_NO_EGD -#endif -#ifndef OPENSSL_NO_ENGINE -#define OPENSSL_NO_ENGINE -#endif -#ifndef OPENSSL_NO_ERR -#define OPENSSL_NO_ERR -#endif -#ifndef OPENSSL_NO_EXTERNAL_TESTS -#define OPENSSL_NO_EXTERNAL_TESTS -#endif -#ifndef OPENSSL_NO_FILENAMES -#define OPENSSL_NO_FILENAMES -#endif -#ifndef OPENSSL_NO_FIPS_JITTER -#define OPENSSL_NO_FIPS_JITTER -#endif -#ifndef OPENSSL_NO_FIPS_POST -#define OPENSSL_NO_FIPS_POST -#endif -#ifndef OPENSSL_NO_FIPS_SECURITYCHECKS -#define OPENSSL_NO_FIPS_SECURITYCHECKS -#endif -#ifndef OPENSSL_NO_FUZZ_AFL -#define OPENSSL_NO_FUZZ_AFL -#endif -#ifndef OPENSSL_NO_FUZZ_LIBFUZZER -#define OPENSSL_NO_FUZZ_LIBFUZZER -#endif -#ifndef OPENSSL_NO_GOST -#define OPENSSL_NO_GOST -#endif -#ifndef OPENSSL_NO_H3DEMO -#define OPENSSL_NO_H3DEMO -#endif -#ifndef OPENSSL_NO_HQINTEROP -#define OPENSSL_NO_HQINTEROP -#endif -#ifndef OPENSSL_NO_IDEA -#define OPENSSL_NO_IDEA -#endif -#ifndef OPENSSL_NO_JITTER -#define OPENSSL_NO_JITTER -#endif -#ifndef OPENSSL_NO_KTLS -#define OPENSSL_NO_KTLS -#endif -#ifndef OPENSSL_NO_LOADERENG -#define OPENSSL_NO_LOADERENG -#endif -#ifndef OPENSSL_NO_MD2 -#define OPENSSL_NO_MD2 -#endif -#ifndef OPENSSL_NO_MD4 -#define OPENSSL_NO_MD4 -#endif -#ifndef OPENSSL_NO_MDC2 -#define OPENSSL_NO_MDC2 -#endif -#ifndef OPENSSL_NO_ML_DSA -#define OPENSSL_NO_ML_DSA -#endif -#ifndef OPENSSL_NO_ML_KEM -#define OPENSSL_NO_ML_KEM -#endif -#ifndef OPENSSL_NO_MSAN -#define OPENSSL_NO_MSAN -#endif -#ifndef OPENSSL_NO_MULTIBLOCK -#define OPENSSL_NO_MULTIBLOCK -#endif -#ifndef OPENSSL_NO_NEXTPROTONEG -#define OPENSSL_NO_NEXTPROTONEG -#endif -#ifndef OPENSSL_NO_OCB -#define OPENSSL_NO_OCB -#endif -#ifndef OPENSSL_NO_OCSP -#define OPENSSL_NO_OCSP -#endif -#ifndef OPENSSL_NO_PADLOCKENG -#define OPENSSL_NO_PADLOCKENG -#endif -#ifndef OPENSSL_NO_PIE -#define OPENSSL_NO_PIE -#endif -#ifndef OPENSSL_NO_POLY1305 -#define OPENSSL_NO_POLY1305 -#endif -#ifndef OPENSSL_NO_POSIX_IO -#define OPENSSL_NO_POSIX_IO -#endif -#ifndef OPENSSL_NO_PSK -#define OPENSSL_NO_PSK -#endif -#ifndef OPENSSL_NO_QLOG -#define OPENSSL_NO_QLOG -#endif -#ifndef OPENSSL_NO_QUIC -#define OPENSSL_NO_QUIC -#endif -#ifndef OPENSSL_NO_RC2 -#define OPENSSL_NO_RC2 -#endif -#ifndef OPENSSL_NO_RC4 -#define OPENSSL_NO_RC4 -#endif -#ifndef OPENSSL_NO_RC5 -#define OPENSSL_NO_RC5 -#endif -#ifndef OPENSSL_NO_RFC3779 -#define OPENSSL_NO_RFC3779 -#endif -#ifndef OPENSSL_NO_RMD160 -#define OPENSSL_NO_RMD160 -#endif -#ifndef OPENSSL_NO_SCRYPT -#define OPENSSL_NO_SCRYPT -#endif -#ifndef OPENSSL_NO_SCTP -#define OPENSSL_NO_SCTP -#endif -#ifndef OPENSSL_NO_SEED -#define OPENSSL_NO_SEED -#endif -#ifndef OPENSSL_NO_SIPHASH -#define OPENSSL_NO_SIPHASH -#endif -#ifndef OPENSSL_NO_SIV -#define OPENSSL_NO_SIV -#endif -#ifndef OPENSSL_NO_SLH_DSA -#define OPENSSL_NO_SLH_DSA -#endif -#ifndef OPENSSL_NO_SM2 -#define OPENSSL_NO_SM2 -#endif -#ifndef OPENSSL_NO_SM4 -#define OPENSSL_NO_SM4 -#endif -#ifndef OPENSSL_NO_SOCK -#define OPENSSL_NO_SOCK -#endif -#ifndef OPENSSL_NO_SRP -#define OPENSSL_NO_SRP -#endif -#ifndef OPENSSL_NO_SRTP -#define OPENSSL_NO_SRTP -#endif -#ifndef OPENSSL_NO_SSL_TRACE -#define OPENSSL_NO_SSL_TRACE -#endif -#ifndef OPENSSL_NO_SSL3 -#define OPENSSL_NO_SSL3 -#endif -#ifndef OPENSSL_NO_SSL3_METHOD -#define OPENSSL_NO_SSL3_METHOD -#endif -#ifndef OPENSSL_NO_SSLKEYLOG -#define OPENSSL_NO_SSLKEYLOG -#endif -#ifndef OPENSSL_NO_STDIO -#define OPENSSL_NO_STDIO -#endif -#ifndef OPENSSL_NO_TESTS -#define OPENSSL_NO_TESTS -#endif -#ifndef OPENSSL_NO_TFO -#define OPENSSL_NO_TFO -#endif -#ifndef OPENSSL_NO_THREAD_POOL -#define OPENSSL_NO_THREAD_POOL -#endif -#ifndef OPENSSL_NO_TLS_DEPRECATED_EC -#define OPENSSL_NO_TLS_DEPRECATED_EC -#endif -#ifndef OPENSSL_NO_TLS1_3 -#define OPENSSL_NO_TLS1_3 -#endif -#ifndef OPENSSL_NO_TRACE -#define OPENSSL_NO_TRACE -#endif -#ifndef OPENSSL_NO_TS -#define OPENSSL_NO_TS -#endif -#ifndef OPENSSL_NO_UBSAN -#define OPENSSL_NO_UBSAN -#endif -#ifndef OPENSSL_NO_UI_CONSOLE -#define OPENSSL_NO_UI_CONSOLE -#endif -#ifndef OPENSSL_NO_UNIT_TEST -#define OPENSSL_NO_UNIT_TEST -#endif -#ifndef OPENSSL_NO_UNSTABLE_QLOG -#define OPENSSL_NO_UNSTABLE_QLOG -#endif -#ifndef OPENSSL_NO_UPLINK -#define OPENSSL_NO_UPLINK -#endif -#ifndef OPENSSL_NO_WEAK_SSL_CIPHERS -#define OPENSSL_NO_WEAK_SSL_CIPHERS -#endif -#ifndef OPENSSL_NO_WHIRLPOOL -#define OPENSSL_NO_WHIRLPOOL -#endif -#ifndef OPENSSL_NO_WINSTORE -#define OPENSSL_NO_WINSTORE -#endif -#ifndef OPENSSL_NO_ZLIB -#define OPENSSL_NO_ZLIB -#endif -#ifndef OPENSSL_NO_ZLIB_DYNAMIC -#define OPENSSL_NO_ZLIB_DYNAMIC -#endif -#ifndef OPENSSL_NO_ZSTD -#define OPENSSL_NO_ZSTD -#endif -#ifndef OPENSSL_NO_ZSTD_DYNAMIC -#define OPENSSL_NO_ZSTD_DYNAMIC -#endif -#ifndef OPENSSL_NO_DYNAMIC_ENGINE -#define OPENSSL_NO_DYNAMIC_ENGINE -#endif +/* clang-format off */ +# ifndef OPENSSL_SYS_UEFI +# define OPENSSL_SYS_UEFI 1 +# endif +# define OPENSSL_CONFIGURED_API 10101 +# ifndef OPENSSL_RAND_SEED_NONE +# define OPENSSL_RAND_SEED_NONE +# endif +# ifndef OPENSSL_NO_ACVP_TESTS +# define OPENSSL_NO_ACVP_TESTS +# endif +# ifndef OPENSSL_NO_AFALGENG +# define OPENSSL_NO_AFALGENG +# endif +# ifndef OPENSSL_NO_APPS +# define OPENSSL_NO_APPS +# endif +# ifndef OPENSSL_NO_ARGON2 +# define OPENSSL_NO_ARGON2 +# endif +# ifndef OPENSSL_NO_ARIA +# define OPENSSL_NO_ARIA +# endif +# ifndef OPENSSL_NO_ASAN +# define OPENSSL_NO_ASAN +# endif +# ifndef OPENSSL_NO_ASYNC +# define OPENSSL_NO_ASYNC +# endif +# ifndef OPENSSL_NO_AUTOERRINIT +# define OPENSSL_NO_AUTOERRINIT +# endif +# ifndef OPENSSL_NO_AUTOLOAD_CONFIG +# define OPENSSL_NO_AUTOLOAD_CONFIG +# endif +# ifndef OPENSSL_NO_BF +# define OPENSSL_NO_BF +# endif +# ifndef OPENSSL_NO_BLAKE2 +# define OPENSSL_NO_BLAKE2 +# endif +# ifndef OPENSSL_NO_BROTLI +# define OPENSSL_NO_BROTLI +# endif +# ifndef OPENSSL_NO_BROTLI_DYNAMIC +# define OPENSSL_NO_BROTLI_DYNAMIC +# endif +# ifndef OPENSSL_NO_CAMELLIA +# define OPENSSL_NO_CAMELLIA +# endif +# ifndef OPENSSL_NO_CAPIENG +# define OPENSSL_NO_CAPIENG +# endif +# ifndef OPENSSL_NO_CAST +# define OPENSSL_NO_CAST +# endif +# ifndef OPENSSL_NO_CHACHA +# define OPENSSL_NO_CHACHA +# endif +# ifndef OPENSSL_NO_CMP +# define OPENSSL_NO_CMP +# endif +# ifndef OPENSSL_NO_CMS +# define OPENSSL_NO_CMS +# endif +# ifndef OPENSSL_NO_CRMF +# define OPENSSL_NO_CRMF +# endif +# ifndef OPENSSL_NO_CRYPTO_MDEBUG +# define OPENSSL_NO_CRYPTO_MDEBUG +# endif +# ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +# define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +# endif +# ifndef OPENSSL_NO_CT +# define OPENSSL_NO_CT +# endif +# ifndef OPENSSL_NO_DEFAULT_THREAD_POOL +# define OPENSSL_NO_DEFAULT_THREAD_POOL +# endif +# ifndef OPENSSL_NO_DEMOS +# define OPENSSL_NO_DEMOS +# endif +# ifndef OPENSSL_NO_DEPRECATED +# define OPENSSL_NO_DEPRECATED +# endif +# ifndef OPENSSL_NO_DES +# define OPENSSL_NO_DES +# endif +# ifndef OPENSSL_NO_DEVCRYPTOENG +# define OPENSSL_NO_DEVCRYPTOENG +# endif +# ifndef OPENSSL_NO_DGRAM +# define OPENSSL_NO_DGRAM +# endif +# ifndef OPENSSL_NO_DH +# define OPENSSL_NO_DH +# endif +# ifndef OPENSSL_NO_DSA +# define OPENSSL_NO_DSA +# endif +# ifndef OPENSSL_NO_DSO +# define OPENSSL_NO_DSO +# endif +# ifndef OPENSSL_NO_DTLS +# define OPENSSL_NO_DTLS +# endif +# ifndef OPENSSL_NO_DTLS1 +# define OPENSSL_NO_DTLS1 +# endif +# ifndef OPENSSL_NO_DTLS1_METHOD +# define OPENSSL_NO_DTLS1_METHOD +# endif +# ifndef OPENSSL_NO_DTLS1_2 +# define OPENSSL_NO_DTLS1_2 +# endif +# ifndef OPENSSL_NO_DTLS1_2_METHOD +# define OPENSSL_NO_DTLS1_2_METHOD +# endif +# ifndef OPENSSL_NO_EC2M +# define OPENSSL_NO_EC2M +# endif +# ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 +# define OPENSSL_NO_EC_NISTP_64_GCC_128 +# endif +# ifndef OPENSSL_NO_ECX +# define OPENSSL_NO_ECX +# endif +# ifndef OPENSSL_NO_EGD +# define OPENSSL_NO_EGD +# endif +# ifndef OPENSSL_NO_ENGINE +# define OPENSSL_NO_ENGINE +# endif +# ifndef OPENSSL_NO_ERR +# define OPENSSL_NO_ERR +# endif +# ifndef OPENSSL_NO_EXTERNAL_TESTS +# define OPENSSL_NO_EXTERNAL_TESTS +# endif +# ifndef OPENSSL_NO_FILENAMES +# define OPENSSL_NO_FILENAMES +# endif +# ifndef OPENSSL_NO_FIPS_JITTER +# define OPENSSL_NO_FIPS_JITTER +# endif +# ifndef OPENSSL_NO_FIPS_POST +# define OPENSSL_NO_FIPS_POST +# endif +# ifndef OPENSSL_NO_FIPS_SECURITYCHECKS +# define OPENSSL_NO_FIPS_SECURITYCHECKS +# endif +# ifndef OPENSSL_NO_FUZZ_AFL +# define OPENSSL_NO_FUZZ_AFL +# endif +# ifndef OPENSSL_NO_FUZZ_LIBFUZZER +# define OPENSSL_NO_FUZZ_LIBFUZZER +# endif +# ifndef OPENSSL_NO_GOST +# define OPENSSL_NO_GOST +# endif +# ifndef OPENSSL_NO_H3DEMO +# define OPENSSL_NO_H3DEMO +# endif +# ifndef OPENSSL_NO_HQINTEROP +# define OPENSSL_NO_HQINTEROP +# endif +# ifndef OPENSSL_NO_IDEA +# define OPENSSL_NO_IDEA +# endif +# ifndef OPENSSL_NO_JITTER +# define OPENSSL_NO_JITTER +# endif +# ifndef OPENSSL_NO_KTLS +# define OPENSSL_NO_KTLS +# endif +# ifndef OPENSSL_NO_LOADERENG +# define OPENSSL_NO_LOADERENG +# endif +# ifndef OPENSSL_NO_MD2 +# define OPENSSL_NO_MD2 +# endif +# ifndef OPENSSL_NO_MD4 +# define OPENSSL_NO_MD4 +# endif +# ifndef OPENSSL_NO_MDC2 +# define OPENSSL_NO_MDC2 +# endif +# ifndef OPENSSL_NO_ML_DSA +# define OPENSSL_NO_ML_DSA +# endif +# ifndef OPENSSL_NO_ML_KEM +# define OPENSSL_NO_ML_KEM +# endif +# ifndef OPENSSL_NO_MSAN +# define OPENSSL_NO_MSAN +# endif +# ifndef OPENSSL_NO_MULTIBLOCK +# define OPENSSL_NO_MULTIBLOCK +# endif +# ifndef OPENSSL_NO_NEXTPROTONEG +# define OPENSSL_NO_NEXTPROTONEG +# endif +# ifndef OPENSSL_NO_OCB +# define OPENSSL_NO_OCB +# endif +# ifndef OPENSSL_NO_OCSP +# define OPENSSL_NO_OCSP +# endif +# ifndef OPENSSL_NO_PADLOCKENG +# define OPENSSL_NO_PADLOCKENG +# endif +# ifndef OPENSSL_NO_PIE +# define OPENSSL_NO_PIE +# endif +# ifndef OPENSSL_NO_POLY1305 +# define OPENSSL_NO_POLY1305 +# endif +# ifndef OPENSSL_NO_POSIX_IO +# define OPENSSL_NO_POSIX_IO +# endif +# ifndef OPENSSL_NO_PSK +# define OPENSSL_NO_PSK +# endif +# ifndef OPENSSL_NO_QLOG +# define OPENSSL_NO_QLOG +# endif +# ifndef OPENSSL_NO_QUIC +# define OPENSSL_NO_QUIC +# endif +# ifndef OPENSSL_NO_RC2 +# define OPENSSL_NO_RC2 +# endif +# ifndef OPENSSL_NO_RC4 +# define OPENSSL_NO_RC4 +# endif +# ifndef OPENSSL_NO_RC5 +# define OPENSSL_NO_RC5 +# endif +# ifndef OPENSSL_NO_RFC3779 +# define OPENSSL_NO_RFC3779 +# endif +# ifndef OPENSSL_NO_RMD160 +# define OPENSSL_NO_RMD160 +# endif +# ifndef OPENSSL_NO_SCRYPT +# define OPENSSL_NO_SCRYPT +# endif +# ifndef OPENSSL_NO_SCTP +# define OPENSSL_NO_SCTP +# endif +# ifndef OPENSSL_NO_SEED +# define OPENSSL_NO_SEED +# endif +# ifndef OPENSSL_NO_SIPHASH +# define OPENSSL_NO_SIPHASH +# endif +# ifndef OPENSSL_NO_SIV +# define OPENSSL_NO_SIV +# endif +# ifndef OPENSSL_NO_SLH_DSA +# define OPENSSL_NO_SLH_DSA +# endif +# ifndef OPENSSL_NO_SM2 +# define OPENSSL_NO_SM2 +# endif +# ifndef OPENSSL_NO_SM4 +# define OPENSSL_NO_SM4 +# endif +# ifndef OPENSSL_NO_SOCK +# define OPENSSL_NO_SOCK +# endif +# ifndef OPENSSL_NO_SRP +# define OPENSSL_NO_SRP +# endif +# ifndef OPENSSL_NO_SRTP +# define OPENSSL_NO_SRTP +# endif +# ifndef OPENSSL_NO_SSL_TRACE +# define OPENSSL_NO_SSL_TRACE +# endif +# ifndef OPENSSL_NO_SSL3 +# define OPENSSL_NO_SSL3 +# endif +# ifndef OPENSSL_NO_SSL3_METHOD +# define OPENSSL_NO_SSL3_METHOD +# endif +# ifndef OPENSSL_NO_SSLKEYLOG +# define OPENSSL_NO_SSLKEYLOG +# endif +# ifndef OPENSSL_NO_STDIO +# define OPENSSL_NO_STDIO +# endif +# ifndef OPENSSL_NO_TESTS +# define OPENSSL_NO_TESTS +# endif +# ifndef OPENSSL_NO_TFO +# define OPENSSL_NO_TFO +# endif +# ifndef OPENSSL_NO_THREAD_POOL +# define OPENSSL_NO_THREAD_POOL +# endif +# ifndef OPENSSL_NO_TLS_DEPRECATED_EC +# define OPENSSL_NO_TLS_DEPRECATED_EC +# endif +# ifndef OPENSSL_NO_TLS1_3 +# define OPENSSL_NO_TLS1_3 +# endif +# ifndef OPENSSL_NO_TRACE +# define OPENSSL_NO_TRACE +# endif +# ifndef OPENSSL_NO_TS +# define OPENSSL_NO_TS +# endif +# ifndef OPENSSL_NO_UBSAN +# define OPENSSL_NO_UBSAN +# endif +# ifndef OPENSSL_NO_UI_CONSOLE +# define OPENSSL_NO_UI_CONSOLE +# endif +# ifndef OPENSSL_NO_UNIT_TEST +# define OPENSSL_NO_UNIT_TEST +# endif +# ifndef OPENSSL_NO_UNSTABLE_QLOG +# define OPENSSL_NO_UNSTABLE_QLOG +# endif +# ifndef OPENSSL_NO_UPLINK +# define OPENSSL_NO_UPLINK +# endif +# ifndef OPENSSL_NO_WEAK_SSL_CIPHERS +# define OPENSSL_NO_WEAK_SSL_CIPHERS +# endif +# ifndef OPENSSL_NO_WHIRLPOOL +# define OPENSSL_NO_WHIRLPOOL +# endif +# ifndef OPENSSL_NO_WINSTORE +# define OPENSSL_NO_WINSTORE +# endif +# ifndef OPENSSL_NO_ZLIB +# define OPENSSL_NO_ZLIB +# endif +# ifndef OPENSSL_NO_ZLIB_DYNAMIC +# define OPENSSL_NO_ZLIB_DYNAMIC +# endif +# ifndef OPENSSL_NO_ZSTD +# define OPENSSL_NO_ZSTD +# endif +# ifndef OPENSSL_NO_ZSTD_DYNAMIC +# define OPENSSL_NO_ZSTD_DYNAMIC +# endif +# ifndef OPENSSL_NO_DYNAMIC_ENGINE +# define OPENSSL_NO_DYNAMIC_ENGINE +# endif + +/* clang-format on */ /* Generate 80386 code? */ -#undef I386_ONLY +/* clang-format off */ +# undef I386_ONLY +/* clang-format on */ /* * The following are cipher-specific, but are part of the public API. */ -#if !defined (OPENSSL_SYS_UEFI) - #undef BN_LLONG -/* Only one for the following should be defined */ - #undef SIXTY_FOUR_BIT_LONG - #undef SIXTY_FOUR_BIT -#define THIRTY_TWO_BIT +#if !defined(OPENSSL_SYS_UEFI) + /* clang-format off */ +# undef BN_LLONG + /* clang-format on */ + /* Only one for the following should be defined */ + /* clang-format off */ +# undef SIXTY_FOUR_BIT_LONG + /* clang-format on */ + /* clang-format off */ +# undef SIXTY_FOUR_BIT + /* clang-format on */ + /* clang-format off */ +# define THIRTY_TWO_BIT +/* clang-format on */ #endif -#define RC4_INT unsigned int +/* clang-format off */ +# define RC4_INT unsigned int +/* clang-format on */ -#if defined (OPENSSL_NO_COMP) || (defined (OPENSSL_NO_BROTLI) && defined (OPENSSL_NO_ZSTD) && defined (OPENSSL_NO_ZLIB)) +#if defined(OPENSSL_NO_COMP) || (defined(OPENSSL_NO_BROTLI) && defined(OPENSSL_NO_ZSTD) && defined(OPENSSL_NO_ZLIB)) #define OPENSSL_NO_COMP_ALG #else - #undef OPENSSL_NO_COMP_ALG +#undef OPENSSL_NO_COMP_ALG #endif -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h index 7b29acdc0b..f653985f6f 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h @@ -12,21 +12,22 @@ */ #ifndef OPENSSL_CONFIGURATION_H -# define OPENSSL_CONFIGURATION_H -# pragma once +#define OPENSSL_CONFIGURATION_H +#pragma once -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif -# ifdef OPENSSL_ALGORITHM_DEFINES -# error OPENSSL_ALGORITHM_DEFINES no longer supported -# endif +#ifdef OPENSSL_ALGORITHM_DEFINES +#error OPENSSL_ALGORITHM_DEFINES no longer supported +#endif /* * OpenSSL was configured with the following options: */ +/* clang-format off */ # ifndef OPENSSL_SYS_UEFI # define OPENSSL_SYS_UEFI 1 # endif @@ -371,31 +372,44 @@ extern "C" { # define OPENSSL_NO_DYNAMIC_ENGINE # endif +/* clang-format on */ /* Generate 80386 code? */ +/* clang-format off */ # undef I386_ONLY +/* clang-format on */ /* * The following are cipher-specific, but are part of the public API. */ -# if !defined(OPENSSL_SYS_UEFI) +#if !defined(OPENSSL_SYS_UEFI) + /* clang-format off */ # undef BN_LLONG -/* Only one for the following should be defined */ + /* clang-format on */ + /* Only one for the following should be defined */ + /* clang-format off */ # undef SIXTY_FOUR_BIT_LONG + /* clang-format on */ + /* clang-format off */ # undef SIXTY_FOUR_BIT + /* clang-format on */ + /* clang-format off */ # define THIRTY_TWO_BIT -# endif +/* clang-format on */ +#endif +/* clang-format off */ # define RC4_INT unsigned int +/* clang-format on */ -# if defined(OPENSSL_NO_COMP) || (defined(OPENSSL_NO_BROTLI) && defined(OPENSSL_NO_ZSTD) && defined(OPENSSL_NO_ZLIB)) -# define OPENSSL_NO_COMP_ALG -# else -# undef OPENSSL_NO_COMP_ALG -# endif +#if defined(OPENSSL_NO_COMP) || (defined(OPENSSL_NO_BROTLI) && defined(OPENSSL_NO_ZSTD) && defined(OPENSSL_NO_ZLIB)) +#define OPENSSL_NO_COMP_ALG +#else +#undef OPENSSL_NO_COMP_ALG +#endif -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif -#endif /* OPENSSL_CONFIGURATION_H */ +#endif /* OPENSSL_CONFIGURATION_H */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h index c098fb7fb1..7f933a7fe0 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h @@ -12,21 +12,22 @@ */ #ifndef OPENSSL_CONFIGURATION_H -# define OPENSSL_CONFIGURATION_H -# pragma once +#define OPENSSL_CONFIGURATION_H +#pragma once -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif -# ifdef OPENSSL_ALGORITHM_DEFINES -# error OPENSSL_ALGORITHM_DEFINES no longer supported -# endif +#ifdef OPENSSL_ALGORITHM_DEFINES +#error OPENSSL_ALGORITHM_DEFINES no longer supported +#endif /* * OpenSSL was configured with the following options: */ +/* clang-format off */ # ifndef OPENSSL_SYS_UEFI # define OPENSSL_SYS_UEFI 1 # endif @@ -389,31 +390,44 @@ extern "C" { # define OPENSSL_NO_DYNAMIC_ENGINE # endif +/* clang-format on */ /* Generate 80386 code? */ +/* clang-format off */ # undef I386_ONLY +/* clang-format on */ /* * The following are cipher-specific, but are part of the public API. */ -# if !defined(OPENSSL_SYS_UEFI) +#if !defined(OPENSSL_SYS_UEFI) + /* clang-format off */ # undef BN_LLONG -/* Only one for the following should be defined */ + /* clang-format on */ + /* Only one for the following should be defined */ + /* clang-format off */ # undef SIXTY_FOUR_BIT_LONG + /* clang-format on */ + /* clang-format off */ # undef SIXTY_FOUR_BIT + /* clang-format on */ + /* clang-format off */ # define THIRTY_TWO_BIT -# endif +/* clang-format on */ +#endif +/* clang-format off */ # define RC4_INT unsigned int +/* clang-format on */ -# if defined(OPENSSL_NO_COMP) || (defined(OPENSSL_NO_BROTLI) && defined(OPENSSL_NO_ZSTD) && defined(OPENSSL_NO_ZLIB)) -# define OPENSSL_NO_COMP_ALG -# else -# undef OPENSSL_NO_COMP_ALG -# endif +#if defined(OPENSSL_NO_COMP) || (defined(OPENSSL_NO_BROTLI) && defined(OPENSSL_NO_ZSTD) && defined(OPENSSL_NO_ZLIB)) +#define OPENSSL_NO_COMP_ALG +#else +#undef OPENSSL_NO_COMP_ALG +#endif -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif -#endif /* OPENSSL_CONFIGURATION_H */ +#endif /* OPENSSL_CONFIGURATION_H */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/core_names.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/core_names.h index 3ed524600b..e7e7789976 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/core_names.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/core_names.h @@ -9,113 +9,116 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_CORE_NAMES_H -# define OPENSSL_CORE_NAMES_H -# pragma once +#define OPENSSL_CORE_NAMES_H +#pragma once -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif /* OSSL_CIPHER_PARAM_CTS_MODE Values */ -# define OSSL_CIPHER_CTS_MODE_CS1 "CS1" -# define OSSL_CIPHER_CTS_MODE_CS2 "CS2" -# define OSSL_CIPHER_CTS_MODE_CS3 "CS3" +#define OSSL_CIPHER_CTS_MODE_CS1 "CS1" +#define OSSL_CIPHER_CTS_MODE_CS2 "CS2" +#define OSSL_CIPHER_CTS_MODE_CS3 "CS3" /* Known CIPHER names (not a complete list) */ -# define OSSL_CIPHER_NAME_AES_128_GCM_SIV "AES-128-GCM-SIV" -# define OSSL_CIPHER_NAME_AES_192_GCM_SIV "AES-192-GCM-SIV" -# define OSSL_CIPHER_NAME_AES_256_GCM_SIV "AES-256-GCM-SIV" +#define OSSL_CIPHER_NAME_AES_128_GCM_SIV "AES-128-GCM-SIV" +#define OSSL_CIPHER_NAME_AES_192_GCM_SIV "AES-192-GCM-SIV" +#define OSSL_CIPHER_NAME_AES_256_GCM_SIV "AES-256-GCM-SIV" /* Known DIGEST names (not a complete list) */ -# define OSSL_DIGEST_NAME_MD5 "MD5" -# define OSSL_DIGEST_NAME_MD5_SHA1 "MD5-SHA1" -# define OSSL_DIGEST_NAME_SHA1 "SHA1" -# define OSSL_DIGEST_NAME_SHA2_224 "SHA2-224" -# define OSSL_DIGEST_NAME_SHA2_256 "SHA2-256" -# define OSSL_DIGEST_NAME_SHA2_256_192 "SHA2-256/192" -# define OSSL_DIGEST_NAME_SHA2_384 "SHA2-384" -# define OSSL_DIGEST_NAME_SHA2_512 "SHA2-512" -# define OSSL_DIGEST_NAME_SHA2_512_224 "SHA2-512/224" -# define OSSL_DIGEST_NAME_SHA2_512_256 "SHA2-512/256" -# define OSSL_DIGEST_NAME_MD2 "MD2" -# define OSSL_DIGEST_NAME_MD4 "MD4" -# define OSSL_DIGEST_NAME_MDC2 "MDC2" -# define OSSL_DIGEST_NAME_RIPEMD160 "RIPEMD160" -# define OSSL_DIGEST_NAME_SHA3_224 "SHA3-224" -# define OSSL_DIGEST_NAME_SHA3_256 "SHA3-256" -# define OSSL_DIGEST_NAME_SHA3_384 "SHA3-384" -# define OSSL_DIGEST_NAME_SHA3_512 "SHA3-512" -# define OSSL_DIGEST_NAME_KECCAK_KMAC128 "KECCAK-KMAC-128" -# define OSSL_DIGEST_NAME_KECCAK_KMAC256 "KECCAK-KMAC-256" -# define OSSL_DIGEST_NAME_SM3 "SM3" +#define OSSL_DIGEST_NAME_MD5 "MD5" +#define OSSL_DIGEST_NAME_MD5_SHA1 "MD5-SHA1" +#define OSSL_DIGEST_NAME_SHA1 "SHA1" +#define OSSL_DIGEST_NAME_SHA2_224 "SHA2-224" +#define OSSL_DIGEST_NAME_SHA2_256 "SHA2-256" +#define OSSL_DIGEST_NAME_SHA2_256_192 "SHA2-256/192" +#define OSSL_DIGEST_NAME_SHA2_384 "SHA2-384" +#define OSSL_DIGEST_NAME_SHA2_512 "SHA2-512" +#define OSSL_DIGEST_NAME_SHA2_512_224 "SHA2-512/224" +#define OSSL_DIGEST_NAME_SHA2_512_256 "SHA2-512/256" +#define OSSL_DIGEST_NAME_MD2 "MD2" +#define OSSL_DIGEST_NAME_MD4 "MD4" +#define OSSL_DIGEST_NAME_MDC2 "MDC2" +#define OSSL_DIGEST_NAME_RIPEMD160 "RIPEMD160" +#define OSSL_DIGEST_NAME_SHA3_224 "SHA3-224" +#define OSSL_DIGEST_NAME_SHA3_256 "SHA3-256" +#define OSSL_DIGEST_NAME_SHA3_384 "SHA3-384" +#define OSSL_DIGEST_NAME_SHA3_512 "SHA3-512" +#define OSSL_DIGEST_NAME_KECCAK_KMAC128 "KECCAK-KMAC-128" +#define OSSL_DIGEST_NAME_KECCAK_KMAC256 "KECCAK-KMAC-256" +#define OSSL_DIGEST_NAME_SM3 "SM3" /* Known MAC names */ -# define OSSL_MAC_NAME_BLAKE2BMAC "BLAKE2BMAC" -# define OSSL_MAC_NAME_BLAKE2SMAC "BLAKE2SMAC" -# define OSSL_MAC_NAME_CMAC "CMAC" -# define OSSL_MAC_NAME_GMAC "GMAC" -# define OSSL_MAC_NAME_HMAC "HMAC" -# define OSSL_MAC_NAME_KMAC128 "KMAC128" -# define OSSL_MAC_NAME_KMAC256 "KMAC256" -# define OSSL_MAC_NAME_POLY1305 "POLY1305" -# define OSSL_MAC_NAME_SIPHASH "SIPHASH" +#define OSSL_MAC_NAME_BLAKE2BMAC "BLAKE2BMAC" +#define OSSL_MAC_NAME_BLAKE2SMAC "BLAKE2SMAC" +#define OSSL_MAC_NAME_CMAC "CMAC" +#define OSSL_MAC_NAME_GMAC "GMAC" +#define OSSL_MAC_NAME_HMAC "HMAC" +#define OSSL_MAC_NAME_KMAC128 "KMAC128" +#define OSSL_MAC_NAME_KMAC256 "KMAC256" +#define OSSL_MAC_NAME_POLY1305 "POLY1305" +#define OSSL_MAC_NAME_SIPHASH "SIPHASH" /* Known KDF names */ -# define OSSL_KDF_NAME_HKDF "HKDF" -# define OSSL_KDF_NAME_TLS1_3_KDF "TLS13-KDF" -# define OSSL_KDF_NAME_PBKDF1 "PBKDF1" -# define OSSL_KDF_NAME_PBKDF2 "PBKDF2" -# define OSSL_KDF_NAME_SCRYPT "SCRYPT" -# define OSSL_KDF_NAME_SSHKDF "SSHKDF" -# define OSSL_KDF_NAME_SSKDF "SSKDF" -# define OSSL_KDF_NAME_TLS1_PRF "TLS1-PRF" -# define OSSL_KDF_NAME_X942KDF_ASN1 "X942KDF-ASN1" -# define OSSL_KDF_NAME_X942KDF_CONCAT "X942KDF-CONCAT" -# define OSSL_KDF_NAME_X963KDF "X963KDF" -# define OSSL_KDF_NAME_KBKDF "KBKDF" -# define OSSL_KDF_NAME_KRB5KDF "KRB5KDF" -# define OSSL_KDF_NAME_HMACDRBGKDF "HMAC-DRBG-KDF" +#define OSSL_KDF_NAME_HKDF "HKDF" +#define OSSL_KDF_NAME_TLS1_3_KDF "TLS13-KDF" +#define OSSL_KDF_NAME_PBKDF1 "PBKDF1" +#define OSSL_KDF_NAME_PBKDF2 "PBKDF2" +#define OSSL_KDF_NAME_SCRYPT "SCRYPT" +#define OSSL_KDF_NAME_SSHKDF "SSHKDF" +#define OSSL_KDF_NAME_SSKDF "SSKDF" +#define OSSL_KDF_NAME_TLS1_PRF "TLS1-PRF" +#define OSSL_KDF_NAME_X942KDF_ASN1 "X942KDF-ASN1" +#define OSSL_KDF_NAME_X942KDF_CONCAT "X942KDF-CONCAT" +#define OSSL_KDF_NAME_X963KDF "X963KDF" +#define OSSL_KDF_NAME_KBKDF "KBKDF" +#define OSSL_KDF_NAME_KRB5KDF "KRB5KDF" +#define OSSL_KDF_NAME_HMACDRBGKDF "HMAC-DRBG-KDF" /* RSA padding modes */ -# define OSSL_PKEY_RSA_PAD_MODE_NONE "none" -# define OSSL_PKEY_RSA_PAD_MODE_PKCSV15 "pkcs1" -# define OSSL_PKEY_RSA_PAD_MODE_OAEP "oaep" -# define OSSL_PKEY_RSA_PAD_MODE_X931 "x931" -# define OSSL_PKEY_RSA_PAD_MODE_PSS "pss" +#define OSSL_PKEY_RSA_PAD_MODE_NONE "none" +#define OSSL_PKEY_RSA_PAD_MODE_PKCSV15 "pkcs1" +#define OSSL_PKEY_RSA_PAD_MODE_OAEP "oaep" +#define OSSL_PKEY_RSA_PAD_MODE_X931 "x931" +#define OSSL_PKEY_RSA_PAD_MODE_PSS "pss" /* RSA pss padding salt length */ -# define OSSL_PKEY_RSA_PSS_SALT_LEN_DIGEST "digest" -# define OSSL_PKEY_RSA_PSS_SALT_LEN_MAX "max" -# define OSSL_PKEY_RSA_PSS_SALT_LEN_AUTO "auto" -# define OSSL_PKEY_RSA_PSS_SALT_LEN_AUTO_DIGEST_MAX "auto-digestmax" +#define OSSL_PKEY_RSA_PSS_SALT_LEN_DIGEST "digest" +#define OSSL_PKEY_RSA_PSS_SALT_LEN_MAX "max" +#define OSSL_PKEY_RSA_PSS_SALT_LEN_AUTO "auto" +#define OSSL_PKEY_RSA_PSS_SALT_LEN_AUTO_DIGEST_MAX "auto-digestmax" /* OSSL_PKEY_PARAM_EC_ENCODING values */ -# define OSSL_PKEY_EC_ENCODING_EXPLICIT "explicit" -# define OSSL_PKEY_EC_ENCODING_GROUP "named_curve" +#define OSSL_PKEY_EC_ENCODING_EXPLICIT "explicit" +#define OSSL_PKEY_EC_ENCODING_GROUP "named_curve" -# define OSSL_PKEY_EC_POINT_CONVERSION_FORMAT_UNCOMPRESSED "uncompressed" -# define OSSL_PKEY_EC_POINT_CONVERSION_FORMAT_COMPRESSED "compressed" -# define OSSL_PKEY_EC_POINT_CONVERSION_FORMAT_HYBRID "hybrid" +#define OSSL_PKEY_EC_POINT_CONVERSION_FORMAT_UNCOMPRESSED "uncompressed" +#define OSSL_PKEY_EC_POINT_CONVERSION_FORMAT_COMPRESSED "compressed" +#define OSSL_PKEY_EC_POINT_CONVERSION_FORMAT_HYBRID "hybrid" -# define OSSL_PKEY_EC_GROUP_CHECK_DEFAULT "default" -# define OSSL_PKEY_EC_GROUP_CHECK_NAMED "named" -# define OSSL_PKEY_EC_GROUP_CHECK_NAMED_NIST "named-nist" +#define OSSL_PKEY_EC_GROUP_CHECK_DEFAULT "default" +#define OSSL_PKEY_EC_GROUP_CHECK_NAMED "named" +#define OSSL_PKEY_EC_GROUP_CHECK_NAMED_NIST "named-nist" /* PROV_SKEY well known key types */ -# define OSSL_SKEY_TYPE_GENERIC "GENERIC-SECRET" -# define OSSL_SKEY_TYPE_AES "AES" +#define OSSL_SKEY_TYPE_GENERIC "GENERIC-SECRET" +#define OSSL_SKEY_TYPE_AES "AES" /* OSSL_KEM_PARAM_OPERATION values */ -#define OSSL_KEM_PARAM_OPERATION_RSASVE "RSASVE" -#define OSSL_KEM_PARAM_OPERATION_DHKEM "DHKEM" +#define OSSL_KEM_PARAM_OPERATION_RSASVE "RSASVE" +#define OSSL_KEM_PARAM_OPERATION_DHKEM "DHKEM" /* Provider configuration variables */ -#define OSSL_PKEY_RETAIN_SEED "pkey_retain_seed" +#define OSSL_PKEY_RETAIN_SEED "pkey_retain_seed" /* Parameter name definitions - generated by util/perl/OpenSSL/paramnames.pm */ +/* clang-format off */ # define OSSL_ALG_PARAM_ALGORITHM_ID "algorithm-id" # define OSSL_ALG_PARAM_ALGORITHM_ID_PARAMS "algorithm-id-params" # define OSSL_ALG_PARAM_CIPHER "cipher" @@ -567,9 +570,10 @@ extern "C" { # define OSSL_STORE_PARAM_PROPERTIES "properties" # define OSSL_STORE_PARAM_SERIAL "serial" # define OSSL_STORE_PARAM_SUBJECT "subject" +/* clang-format on */ -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/crmf.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/crmf.h index 551394d314..1bdaf21814 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/crmf.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/crmf.h @@ -14,36 +14,38 @@ * CRMF (RFC 4211) implementation by M. Peylo, M. Viljanen, and D. von Oheimb. */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_CRMF_H -# define OPENSSL_CRMF_H +#define OPENSSL_CRMF_H -# include +#include -# ifndef OPENSSL_NO_CRMF -# include -# include -# include -# include /* for GENERAL_NAME etc. */ -# include +#ifndef OPENSSL_NO_CRMF +#include +#include +#include +#include /* for GENERAL_NAME etc. */ +#include /* explicit #includes not strictly needed since implied by the above: */ -# include -# include +#include +#include -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif -# define OSSL_CRMF_POPOPRIVKEY_THISMESSAGE 0 -# define OSSL_CRMF_POPOPRIVKEY_SUBSEQUENTMESSAGE 1 -# define OSSL_CRMF_POPOPRIVKEY_DHMAC 2 -# define OSSL_CRMF_POPOPRIVKEY_AGREEMAC 3 -# define OSSL_CRMF_POPOPRIVKEY_ENCRYPTEDKEY 4 +#define OSSL_CRMF_POPOPRIVKEY_THISMESSAGE 0 +#define OSSL_CRMF_POPOPRIVKEY_SUBSEQUENTMESSAGE 1 +#define OSSL_CRMF_POPOPRIVKEY_DHMAC 2 +#define OSSL_CRMF_POPOPRIVKEY_AGREEMAC 3 +#define OSSL_CRMF_POPOPRIVKEY_ENCRYPTEDKEY 4 -# define OSSL_CRMF_SUBSEQUENTMESSAGE_ENCRCERT 0 -# define OSSL_CRMF_SUBSEQUENTMESSAGE_CHALLENGERESP 1 +#define OSSL_CRMF_SUBSEQUENTMESSAGE_ENCRCERT 0 +#define OSSL_CRMF_SUBSEQUENTMESSAGE_CHALLENGERESP 1 typedef struct ossl_crmf_encryptedvalue_st OSSL_CRMF_ENCRYPTEDVALUE; DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ENCRYPTEDVALUE) @@ -53,6 +55,7 @@ DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ENCRYPTEDKEY) typedef struct ossl_crmf_msg_st OSSL_CRMF_MSG; DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_MSG) DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_MSG) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CRMF_MSG, OSSL_CRMF_MSG, OSSL_CRMF_MSG) #define sk_OSSL_CRMF_MSG_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_CRMF_MSG_sk_type(sk)) #define sk_OSSL_CRMF_MSG_value(sk, idx) ((OSSL_CRMF_MSG *)OPENSSL_sk_value(ossl_check_const_OSSL_CRMF_MSG_sk_type(sk), (idx))) @@ -80,9 +83,11 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CRMF_MSG, OSSL_CRMF_MSG, OSSL_CRMF_MSG) #define sk_OSSL_CRMF_MSG_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_CRMF_MSG) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_CRMF_MSG_sk_type(sk), ossl_check_OSSL_CRMF_MSG_copyfunc_type(copyfunc), ossl_check_OSSL_CRMF_MSG_freefunc_type(freefunc))) #define sk_OSSL_CRMF_MSG_set_cmp_func(sk, cmp) ((sk_OSSL_CRMF_MSG_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_CRMF_MSG_sk_type(sk), ossl_check_OSSL_CRMF_MSG_compfunc_type(cmp))) +/* clang-format on */ typedef struct ossl_crmf_attributetypeandvalue_st OSSL_CRMF_ATTRIBUTETYPEANDVALUE; void OSSL_CRMF_ATTRIBUTETYPEANDVALUE_free(OSSL_CRMF_ATTRIBUTETYPEANDVALUE *v); DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, OSSL_CRMF_ATTRIBUTETYPEANDVALUE, OSSL_CRMF_ATTRIBUTETYPEANDVALUE) #define sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_sk_type(sk)) #define sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_value(sk, idx) ((OSSL_CRMF_ATTRIBUTETYPEANDVALUE *)OPENSSL_sk_value(ossl_check_const_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_sk_type(sk), (idx))) @@ -110,6 +115,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, OSSL_CRMF_ATTRIBUT #define sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_sk_type(sk), ossl_check_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_copyfunc_type(copyfunc), ossl_check_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_freefunc_type(freefunc))) #define sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_set_cmp_func(sk, cmp) ((sk_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_sk_type(sk), ossl_check_OSSL_CRMF_ATTRIBUTETYPEANDVALUE_compfunc_type(cmp))) +/* clang-format on */ typedef struct ossl_crmf_pbmparameter_st OSSL_CRMF_PBMPARAMETER; DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_PBMPARAMETER) @@ -118,6 +124,7 @@ typedef struct ossl_crmf_certrequest_st OSSL_CRMF_CERTREQUEST; typedef struct ossl_crmf_certid_st OSSL_CRMF_CERTID; DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_CERTID) DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_CERTID) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CRMF_CERTID, OSSL_CRMF_CERTID, OSSL_CRMF_CERTID) #define sk_OSSL_CRMF_CERTID_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_CRMF_CERTID_sk_type(sk)) #define sk_OSSL_CRMF_CERTID_value(sk, idx) ((OSSL_CRMF_CERTID *)OPENSSL_sk_value(ossl_check_const_OSSL_CRMF_CERTID_sk_type(sk), (idx))) @@ -145,6 +152,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_CRMF_CERTID, OSSL_CRMF_CERTID, OSSL_CRMF_CERTI #define sk_OSSL_CRMF_CERTID_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_CRMF_CERTID) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_CRMF_CERTID_sk_type(sk), ossl_check_OSSL_CRMF_CERTID_copyfunc_type(copyfunc), ossl_check_OSSL_CRMF_CERTID_freefunc_type(freefunc))) #define sk_OSSL_CRMF_CERTID_set_cmp_func(sk, cmp) ((sk_OSSL_CRMF_CERTID_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_CRMF_CERTID_sk_type(sk), ossl_check_OSSL_CRMF_CERTID_compfunc_type(cmp))) +/* clang-format on */ typedef struct ossl_crmf_pkipublicationinfo_st OSSL_CRMF_PKIPUBLICATIONINFO; DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_PKIPUBLICATIONINFO) @@ -160,119 +168,112 @@ typedef struct ossl_crmf_optionalvalidity_st OSSL_CRMF_OPTIONALVALIDITY; /* crmf_pbm.c */ OSSL_CRMF_PBMPARAMETER *OSSL_CRMF_pbmp_new(OSSL_LIB_CTX *libctx, size_t slen, - int owfnid, size_t itercnt, - int macnid); + int owfnid, size_t itercnt, + int macnid); int OSSL_CRMF_pbm_new(OSSL_LIB_CTX *libctx, const char *propq, - const OSSL_CRMF_PBMPARAMETER *pbmp, - const unsigned char *msg, size_t msglen, - const unsigned char *sec, size_t seclen, - unsigned char **mac, size_t *maclen); + const OSSL_CRMF_PBMPARAMETER *pbmp, + const unsigned char *msg, size_t msglen, + const unsigned char *sec, size_t seclen, + unsigned char **mac, size_t *maclen); /* crmf_lib.c */ int OSSL_CRMF_MSG_set1_regCtrl_regToken(OSSL_CRMF_MSG *msg, - const ASN1_UTF8STRING *tok); + const ASN1_UTF8STRING *tok); ASN1_UTF8STRING *OSSL_CRMF_MSG_get0_regCtrl_regToken(const OSSL_CRMF_MSG *msg); int OSSL_CRMF_MSG_set1_regCtrl_authenticator(OSSL_CRMF_MSG *msg, - const ASN1_UTF8STRING *auth); + const ASN1_UTF8STRING *auth); ASN1_UTF8STRING *OSSL_CRMF_MSG_get0_regCtrl_authenticator(const OSSL_CRMF_MSG *msg); -int -OSSL_CRMF_MSG_PKIPublicationInfo_push0_SinglePubInfo(OSSL_CRMF_PKIPUBLICATIONINFO *pi, - OSSL_CRMF_SINGLEPUBINFO *spi); -# define OSSL_CRMF_PUB_METHOD_DONTCARE 0 -# define OSSL_CRMF_PUB_METHOD_X500 1 -# define OSSL_CRMF_PUB_METHOD_WEB 2 -# define OSSL_CRMF_PUB_METHOD_LDAP 3 +int OSSL_CRMF_MSG_PKIPublicationInfo_push0_SinglePubInfo(OSSL_CRMF_PKIPUBLICATIONINFO *pi, + OSSL_CRMF_SINGLEPUBINFO *spi); +#define OSSL_CRMF_PUB_METHOD_DONTCARE 0 +#define OSSL_CRMF_PUB_METHOD_X500 1 +#define OSSL_CRMF_PUB_METHOD_WEB 2 +#define OSSL_CRMF_PUB_METHOD_LDAP 3 int OSSL_CRMF_MSG_set0_SinglePubInfo(OSSL_CRMF_SINGLEPUBINFO *spi, - int method, GENERAL_NAME *nm); -# define OSSL_CRMF_PUB_ACTION_DONTPUBLISH 0 -# define OSSL_CRMF_PUB_ACTION_PLEASEPUBLISH 1 + int method, GENERAL_NAME *nm); +#define OSSL_CRMF_PUB_ACTION_DONTPUBLISH 0 +#define OSSL_CRMF_PUB_ACTION_PLEASEPUBLISH 1 int OSSL_CRMF_MSG_set_PKIPublicationInfo_action(OSSL_CRMF_PKIPUBLICATIONINFO *pi, - int action); + int action); int OSSL_CRMF_MSG_set1_regCtrl_pkiPublicationInfo(OSSL_CRMF_MSG *msg, - const OSSL_CRMF_PKIPUBLICATIONINFO *pi); + const OSSL_CRMF_PKIPUBLICATIONINFO *pi); OSSL_CRMF_PKIPUBLICATIONINFO *OSSL_CRMF_MSG_get0_regCtrl_pkiPublicationInfo(const OSSL_CRMF_MSG *msg); int OSSL_CRMF_MSG_set1_regCtrl_protocolEncrKey(OSSL_CRMF_MSG *msg, - const X509_PUBKEY *pubkey); + const X509_PUBKEY *pubkey); X509_PUBKEY *OSSL_CRMF_MSG_get0_regCtrl_protocolEncrKey(const OSSL_CRMF_MSG *msg); int OSSL_CRMF_MSG_set1_regCtrl_oldCertID(OSSL_CRMF_MSG *msg, - const OSSL_CRMF_CERTID *cid); + const OSSL_CRMF_CERTID *cid); OSSL_CRMF_CERTID *OSSL_CRMF_MSG_get0_regCtrl_oldCertID(const OSSL_CRMF_MSG *msg); OSSL_CRMF_CERTID *OSSL_CRMF_CERTID_gen(const X509_NAME *issuer, - const ASN1_INTEGER *serial); + const ASN1_INTEGER *serial); int OSSL_CRMF_MSG_set1_regInfo_utf8Pairs(OSSL_CRMF_MSG *msg, - const ASN1_UTF8STRING *utf8pairs); + const ASN1_UTF8STRING *utf8pairs); ASN1_UTF8STRING *OSSL_CRMF_MSG_get0_regInfo_utf8Pairs(const OSSL_CRMF_MSG *msg); int OSSL_CRMF_MSG_set1_regInfo_certReq(OSSL_CRMF_MSG *msg, - const OSSL_CRMF_CERTREQUEST *cr); + const OSSL_CRMF_CERTREQUEST *cr); OSSL_CRMF_CERTREQUEST *OSSL_CRMF_MSG_get0_regInfo_certReq(const OSSL_CRMF_MSG *msg); int OSSL_CRMF_MSG_set0_validity(OSSL_CRMF_MSG *crm, - ASN1_TIME *notBefore, ASN1_TIME *notAfter); + ASN1_TIME *notBefore, ASN1_TIME *notAfter); int OSSL_CRMF_MSG_set_certReqId(OSSL_CRMF_MSG *crm, int rid); int OSSL_CRMF_MSG_get_certReqId(const OSSL_CRMF_MSG *crm); int OSSL_CRMF_MSG_set0_extensions(OSSL_CRMF_MSG *crm, X509_EXTENSIONS *exts); int OSSL_CRMF_MSG_push0_extension(OSSL_CRMF_MSG *crm, X509_EXTENSION *ext); -# define OSSL_CRMF_POPO_NONE -1 -# define OSSL_CRMF_POPO_RAVERIFIED 0 -# define OSSL_CRMF_POPO_SIGNATURE 1 -# define OSSL_CRMF_POPO_KEYENC 2 -# define OSSL_CRMF_POPO_KEYAGREE 3 +#define OSSL_CRMF_POPO_NONE -1 +#define OSSL_CRMF_POPO_RAVERIFIED 0 +#define OSSL_CRMF_POPO_SIGNATURE 1 +#define OSSL_CRMF_POPO_KEYENC 2 +#define OSSL_CRMF_POPO_KEYAGREE 3 int OSSL_CRMF_MSG_create_popo(int meth, OSSL_CRMF_MSG *crm, - EVP_PKEY *pkey, const EVP_MD *digest, - OSSL_LIB_CTX *libctx, const char *propq); + EVP_PKEY *pkey, const EVP_MD *digest, + OSSL_LIB_CTX *libctx, const char *propq); int OSSL_CRMF_MSGS_verify_popo(const OSSL_CRMF_MSGS *reqs, - int rid, int acceptRAVerified, - OSSL_LIB_CTX *libctx, const char *propq); + int rid, int acceptRAVerified, + OSSL_LIB_CTX *libctx, const char *propq); OSSL_CRMF_CERTTEMPLATE *OSSL_CRMF_MSG_get0_tmpl(const OSSL_CRMF_MSG *crm); X509_PUBKEY *OSSL_CRMF_CERTTEMPLATE_get0_publicKey(const OSSL_CRMF_CERTTEMPLATE *tmpl); -const X509_NAME -*OSSL_CRMF_CERTTEMPLATE_get0_subject(const OSSL_CRMF_CERTTEMPLATE *tmpl); -const X509_NAME -*OSSL_CRMF_CERTTEMPLATE_get0_issuer(const OSSL_CRMF_CERTTEMPLATE *tmpl); -const ASN1_INTEGER -*OSSL_CRMF_CERTTEMPLATE_get0_serialNumber(const OSSL_CRMF_CERTTEMPLATE *tmpl); +const X509_NAME *OSSL_CRMF_CERTTEMPLATE_get0_subject(const OSSL_CRMF_CERTTEMPLATE *tmpl); +const X509_NAME *OSSL_CRMF_CERTTEMPLATE_get0_issuer(const OSSL_CRMF_CERTTEMPLATE *tmpl); +const ASN1_INTEGER *OSSL_CRMF_CERTTEMPLATE_get0_serialNumber(const OSSL_CRMF_CERTTEMPLATE *tmpl); X509_EXTENSIONS *OSSL_CRMF_CERTTEMPLATE_get0_extensions(const OSSL_CRMF_CERTTEMPLATE *tmpl); -const X509_NAME -*OSSL_CRMF_CERTID_get0_issuer(const OSSL_CRMF_CERTID *cid); -const ASN1_INTEGER -*OSSL_CRMF_CERTID_get0_serialNumber(const OSSL_CRMF_CERTID *cid); +const X509_NAME *OSSL_CRMF_CERTID_get0_issuer(const OSSL_CRMF_CERTID *cid); +const ASN1_INTEGER *OSSL_CRMF_CERTID_get0_serialNumber(const OSSL_CRMF_CERTID *cid); int OSSL_CRMF_CERTTEMPLATE_fill(OSSL_CRMF_CERTTEMPLATE *tmpl, - EVP_PKEY *pubkey, - const X509_NAME *subject, - const X509_NAME *issuer, - const ASN1_INTEGER *serial); + EVP_PKEY *pubkey, + const X509_NAME *subject, + const X509_NAME *issuer, + const ASN1_INTEGER *serial); X509 *OSSL_CRMF_ENCRYPTEDVALUE_get1_encCert(const OSSL_CRMF_ENCRYPTEDVALUE *ecert, - OSSL_LIB_CTX *libctx, const char *propq, - EVP_PKEY *pkey); + OSSL_LIB_CTX *libctx, const char *propq, + EVP_PKEY *pkey); X509 *OSSL_CRMF_ENCRYPTEDKEY_get1_encCert(const OSSL_CRMF_ENCRYPTEDKEY *ecert, - OSSL_LIB_CTX *libctx, const char *propq, - EVP_PKEY *pkey, unsigned int flags); -unsigned char -*OSSL_CRMF_ENCRYPTEDVALUE_decrypt(const OSSL_CRMF_ENCRYPTEDVALUE *enc, - OSSL_LIB_CTX *libctx, const char *propq, - EVP_PKEY *pkey, int *outlen); + OSSL_LIB_CTX *libctx, const char *propq, + EVP_PKEY *pkey, unsigned int flags); +unsigned char *OSSL_CRMF_ENCRYPTEDVALUE_decrypt(const OSSL_CRMF_ENCRYPTEDVALUE *enc, + OSSL_LIB_CTX *libctx, const char *propq, + EVP_PKEY *pkey, int *outlen); EVP_PKEY *OSSL_CRMF_ENCRYPTEDKEY_get1_pkey(const OSSL_CRMF_ENCRYPTEDKEY *encryptedKey, - X509_STORE *ts, STACK_OF(X509) *extra, EVP_PKEY *pkey, - X509 *cert, ASN1_OCTET_STRING *secret, - OSSL_LIB_CTX *libctx, const char *propq); + X509_STORE *ts, STACK_OF(X509) *extra, EVP_PKEY *pkey, + X509 *cert, ASN1_OCTET_STRING *secret, + OSSL_LIB_CTX *libctx, const char *propq); int OSSL_CRMF_MSG_centralkeygen_requested(const OSSL_CRMF_MSG *crm, const X509_REQ *p10cr); -# ifndef OPENSSL_NO_CMS +#ifndef OPENSSL_NO_CMS OSSL_CRMF_ENCRYPTEDKEY *OSSL_CRMF_ENCRYPTEDKEY_init_envdata(CMS_EnvelopedData *envdata); -# endif +#endif -# ifdef __cplusplus +#ifdef __cplusplus } -# endif -# endif /* !defined(OPENSSL_NO_CRMF) */ +#endif +#endif /* !defined(OPENSSL_NO_CRMF) */ #endif /* !defined(OPENSSL_CRMF_H) */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/crypto.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/crypto.h index bba69ec2e1..89444371c5 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/crypto.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/crypto.h @@ -2,7 +2,7 @@ * WARNING: do not edit! * Generated by Makefile from include/openssl/crypto.h.in * - * Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved * * Licensed under the Apache License 2.0 (the "License"). You may not use @@ -11,60 +11,62 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_CRYPTO_H -# define OPENSSL_CRYPTO_H -# pragma once +#define OPENSSL_CRYPTO_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_CRYPTO_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_CRYPTO_H +#endif -# include -# include +#include +#include -# include +#include -# ifndef OPENSSL_NO_STDIO -# include -# endif +#ifndef OPENSSL_NO_STDIO +#include +#endif -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include -# ifdef CHARSET_EBCDIC -# include -# endif +#ifdef CHARSET_EBCDIC +#include +#endif /* * Resolve problems on some operating systems with symbol names that clash * one way or another */ -# include +#include -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# include -# endif +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#include +#endif -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define SSLeay OpenSSL_version_num -# define SSLeay_version OpenSSL_version -# define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER -# define SSLEAY_VERSION OPENSSL_VERSION -# define SSLEAY_CFLAGS OPENSSL_CFLAGS -# define SSLEAY_BUILT_ON OPENSSL_BUILT_ON -# define SSLEAY_PLATFORM OPENSSL_PLATFORM -# define SSLEAY_DIR OPENSSL_DIR +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define SSLeay OpenSSL_version_num +#define SSLeay_version OpenSSL_version +#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER +#define SSLEAY_VERSION OPENSSL_VERSION +#define SSLEAY_CFLAGS OPENSSL_CFLAGS +#define SSLEAY_BUILT_ON OPENSSL_BUILT_ON +#define SSLEAY_PLATFORM OPENSSL_PLATFORM +#define SSLEAY_DIR OPENSSL_DIR /* * Old type for allocating dynamic locks. No longer used. Use the new thread @@ -74,7 +76,7 @@ typedef struct { int dummy; } CRYPTO_dynlock; -# endif /* OPENSSL_NO_DEPRECATED_1_1_0 */ +#endif /* OPENSSL_NO_DEPRECATED_1_1_0 */ typedef void CRYPTO_RWLOCK; @@ -86,66 +88,68 @@ void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock); int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock); int CRYPTO_atomic_add64(uint64_t *val, uint64_t op, uint64_t *ret, - CRYPTO_RWLOCK *lock); + CRYPTO_RWLOCK *lock); int CRYPTO_atomic_and(uint64_t *val, uint64_t op, uint64_t *ret, - CRYPTO_RWLOCK *lock); + CRYPTO_RWLOCK *lock); int CRYPTO_atomic_or(uint64_t *val, uint64_t op, uint64_t *ret, - CRYPTO_RWLOCK *lock); + CRYPTO_RWLOCK *lock); int CRYPTO_atomic_load(uint64_t *val, uint64_t *ret, CRYPTO_RWLOCK *lock); int CRYPTO_atomic_load_int(int *val, int *ret, CRYPTO_RWLOCK *lock); int CRYPTO_atomic_store(uint64_t *dst, uint64_t val, CRYPTO_RWLOCK *lock); /* No longer needed, so this is a no-op */ -#define OPENSSL_malloc_init() while(0) continue +#define OPENSSL_malloc_init() \ + while (0) \ + continue -# define OPENSSL_malloc(num) \ - CRYPTO_malloc(num, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_zalloc(num) \ - CRYPTO_zalloc(num, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_aligned_alloc(num, alignment, freeptr) \ - CRYPTO_aligned_alloc(num, alignment, freeptr, \ - OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_realloc(addr, num) \ - CRYPTO_realloc(addr, num, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_clear_realloc(addr, old_num, num) \ - CRYPTO_clear_realloc(addr, old_num, num, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_clear_free(addr, num) \ - CRYPTO_clear_free(addr, num, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_free(addr) \ - CRYPTO_free(addr, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_memdup(str, s) \ - CRYPTO_memdup((str), s, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_strdup(str) \ - CRYPTO_strdup(str, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_strndup(str, n) \ - CRYPTO_strndup(str, n, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_secure_malloc(num) \ - CRYPTO_secure_malloc(num, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_secure_zalloc(num) \ - CRYPTO_secure_zalloc(num, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_secure_free(addr) \ - CRYPTO_secure_free(addr, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_secure_clear_free(addr, num) \ - CRYPTO_secure_clear_free(addr, num, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_secure_actual_size(ptr) \ - CRYPTO_secure_actual_size(ptr) +#define OPENSSL_malloc(num) \ + CRYPTO_malloc(num, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_zalloc(num) \ + CRYPTO_zalloc(num, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_aligned_alloc(num, alignment, freeptr) \ + CRYPTO_aligned_alloc(num, alignment, freeptr, \ + OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_realloc(addr, num) \ + CRYPTO_realloc(addr, num, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_clear_realloc(addr, old_num, num) \ + CRYPTO_clear_realloc(addr, old_num, num, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_clear_free(addr, num) \ + CRYPTO_clear_free(addr, num, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_free(addr) \ + CRYPTO_free(addr, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_memdup(str, s) \ + CRYPTO_memdup((str), s, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_strdup(str) \ + CRYPTO_strdup(str, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_strndup(str, n) \ + CRYPTO_strndup(str, n, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_secure_malloc(num) \ + CRYPTO_secure_malloc(num, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_secure_zalloc(num) \ + CRYPTO_secure_zalloc(num, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_secure_free(addr) \ + CRYPTO_secure_free(addr, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_secure_clear_free(addr, num) \ + CRYPTO_secure_clear_free(addr, num, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_secure_actual_size(ptr) \ + CRYPTO_secure_actual_size(ptr) size_t OPENSSL_strlcpy(char *dst, const char *src, size_t siz); size_t OPENSSL_strlcat(char *dst, const char *src, size_t siz); size_t OPENSSL_strnlen(const char *str, size_t maxlen); int OPENSSL_strtoul(const char *str, char **endptr, int base, unsigned long *num); int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlength, - const unsigned char *buf, size_t buflen, - const char sep); + const unsigned char *buf, size_t buflen, + const char sep); char *OPENSSL_buf2hexstr(const unsigned char *buf, long buflen); int OPENSSL_hexstr2buf_ex(unsigned char *buf, size_t buf_n, size_t *buflen, - const char *str, const char sep); + const char *str, const char sep); unsigned char *OPENSSL_hexstr2buf(const char *str, long *buflen); int OPENSSL_hexchar2int(unsigned char c); int OPENSSL_strcasecmp(const char *s1, const char *s2); int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n); -# define OPENSSL_MALLOC_MAX_NELEMS(type) (((1U<<(sizeof(int)*8-1))-1)/sizeof(type)) +#define OPENSSL_MALLOC_MAX_NELEMS(type) (((1U << (sizeof(int) * 8 - 1)) - 1) / sizeof(type)) /* * These functions return the values of OPENSSL_VERSION_MAJOR, @@ -160,32 +164,32 @@ const char *OPENSSL_version_build_metadata(void); unsigned long OpenSSL_version_num(void); const char *OpenSSL_version(int type); -# define OPENSSL_VERSION 0 -# define OPENSSL_CFLAGS 1 -# define OPENSSL_BUILT_ON 2 -# define OPENSSL_PLATFORM 3 -# define OPENSSL_DIR 4 -# define OPENSSL_ENGINES_DIR 5 -# define OPENSSL_VERSION_STRING 6 -# define OPENSSL_FULL_VERSION_STRING 7 -# define OPENSSL_MODULES_DIR 8 -# define OPENSSL_CPU_INFO 9 -# define OPENSSL_WINCTX 10 +#define OPENSSL_VERSION 0 +#define OPENSSL_CFLAGS 1 +#define OPENSSL_BUILT_ON 2 +#define OPENSSL_PLATFORM 3 +#define OPENSSL_DIR 4 +#define OPENSSL_ENGINES_DIR 5 +#define OPENSSL_VERSION_STRING 6 +#define OPENSSL_FULL_VERSION_STRING 7 +#define OPENSSL_MODULES_DIR 8 +#define OPENSSL_CPU_INFO 9 +#define OPENSSL_WINCTX 10 const char *OPENSSL_info(int type); /* * The series starts at 1001 to avoid confusion with the OpenSSL_version * types. */ -# define OPENSSL_INFO_CONFIG_DIR 1001 -# define OPENSSL_INFO_ENGINES_DIR 1002 -# define OPENSSL_INFO_MODULES_DIR 1003 -# define OPENSSL_INFO_DSO_EXTENSION 1004 -# define OPENSSL_INFO_DIR_FILENAME_SEPARATOR 1005 -# define OPENSSL_INFO_LIST_SEPARATOR 1006 -# define OPENSSL_INFO_SEED_SOURCE 1007 -# define OPENSSL_INFO_CPU_SETTINGS 1008 -# define OPENSSL_INFO_WINDOWS_CONTEXT 1009 +#define OPENSSL_INFO_CONFIG_DIR 1001 +#define OPENSSL_INFO_ENGINES_DIR 1002 +#define OPENSSL_INFO_MODULES_DIR 1003 +#define OPENSSL_INFO_DSO_EXTENSION 1004 +#define OPENSSL_INFO_DIR_FILENAME_SEPARATOR 1005 +#define OPENSSL_INFO_LIST_SEPARATOR 1006 +#define OPENSSL_INFO_SEED_SOURCE 1007 +#define OPENSSL_INFO_CPU_SETTINGS 1008 +#define OPENSSL_INFO_WINDOWS_CONTEXT 1009 int OPENSSL_issetugid(void); @@ -194,6 +198,7 @@ struct crypto_ex_data_st { STACK_OF(void) *sk; }; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(void, void, void) #define sk_void_num(sk) OPENSSL_sk_num(ossl_check_const_void_sk_type(sk)) #define sk_void_value(sk, idx) ((void *)OPENSSL_sk_value(ossl_check_const_void_sk_type(sk), (idx))) @@ -221,42 +226,42 @@ SKM_DEFINE_STACK_OF_INTERNAL(void, void, void) #define sk_void_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(void) *)OPENSSL_sk_deep_copy(ossl_check_const_void_sk_type(sk), ossl_check_void_copyfunc_type(copyfunc), ossl_check_void_freefunc_type(freefunc))) #define sk_void_set_cmp_func(sk, cmp) ((sk_void_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_void_sk_type(sk), ossl_check_void_compfunc_type(cmp))) - +/* clang-format on */ /* * Per class, we have a STACK of function pointers. */ -# define CRYPTO_EX_INDEX_SSL 0 -# define CRYPTO_EX_INDEX_SSL_CTX 1 -# define CRYPTO_EX_INDEX_SSL_SESSION 2 -# define CRYPTO_EX_INDEX_X509 3 -# define CRYPTO_EX_INDEX_X509_STORE 4 -# define CRYPTO_EX_INDEX_X509_STORE_CTX 5 -# define CRYPTO_EX_INDEX_DH 6 -# define CRYPTO_EX_INDEX_DSA 7 -# define CRYPTO_EX_INDEX_EC_KEY 8 -# define CRYPTO_EX_INDEX_RSA 9 -# define CRYPTO_EX_INDEX_ENGINE 10 -# define CRYPTO_EX_INDEX_UI 11 -# define CRYPTO_EX_INDEX_BIO 12 -# define CRYPTO_EX_INDEX_APP 13 -# define CRYPTO_EX_INDEX_UI_METHOD 14 -# define CRYPTO_EX_INDEX_RAND_DRBG 15 -# define CRYPTO_EX_INDEX_DRBG CRYPTO_EX_INDEX_RAND_DRBG -# define CRYPTO_EX_INDEX_OSSL_LIB_CTX 16 -# define CRYPTO_EX_INDEX_EVP_PKEY 17 -# define CRYPTO_EX_INDEX__COUNT 18 +#define CRYPTO_EX_INDEX_SSL 0 +#define CRYPTO_EX_INDEX_SSL_CTX 1 +#define CRYPTO_EX_INDEX_SSL_SESSION 2 +#define CRYPTO_EX_INDEX_X509 3 +#define CRYPTO_EX_INDEX_X509_STORE 4 +#define CRYPTO_EX_INDEX_X509_STORE_CTX 5 +#define CRYPTO_EX_INDEX_DH 6 +#define CRYPTO_EX_INDEX_DSA 7 +#define CRYPTO_EX_INDEX_EC_KEY 8 +#define CRYPTO_EX_INDEX_RSA 9 +#define CRYPTO_EX_INDEX_ENGINE 10 +#define CRYPTO_EX_INDEX_UI 11 +#define CRYPTO_EX_INDEX_BIO 12 +#define CRYPTO_EX_INDEX_APP 13 +#define CRYPTO_EX_INDEX_UI_METHOD 14 +#define CRYPTO_EX_INDEX_RAND_DRBG 15 +#define CRYPTO_EX_INDEX_DRBG CRYPTO_EX_INDEX_RAND_DRBG +#define CRYPTO_EX_INDEX_OSSL_LIB_CTX 16 +#define CRYPTO_EX_INDEX_EVP_PKEY 17 +#define CRYPTO_EX_INDEX__COUNT 18 -typedef void CRYPTO_EX_new (void *parent, void *ptr, CRYPTO_EX_DATA *ad, - int idx, long argl, void *argp); -typedef void CRYPTO_EX_free (void *parent, void *ptr, CRYPTO_EX_DATA *ad, - int idx, long argl, void *argp); -typedef int CRYPTO_EX_dup (CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, - void **from_d, int idx, long argl, void *argp); +typedef void CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); +typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); +typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, + void **from_d, int idx, long argl, void *argp); __owur int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, - CRYPTO_EX_new *new_func, - CRYPTO_EX_dup *dup_func, - CRYPTO_EX_free *free_func); + CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, + CRYPTO_EX_free *free_func); /* No longer use an index. */ int CRYPTO_free_ex_index(int class_index, int idx); @@ -266,13 +271,13 @@ int CRYPTO_free_ex_index(int class_index, int idx); */ int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, - const CRYPTO_EX_DATA *from); + const CRYPTO_EX_DATA *from); void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); /* Allocate a single item in the CRYPTO_EX_DATA variable */ int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad, - int idx); + int idx); /* * Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular @@ -281,12 +286,14 @@ int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad, int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val); void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 /* * This function cleans up all "ex_data" state. It mustn't be called under * potential race-conditions. */ -# define CRYPTO_cleanup_all_ex_data() while(0) continue +#define CRYPTO_cleanup_all_ex_data() \ + while (0) \ + continue /* * The old locking functions have been removed completely without compatibility @@ -298,74 +305,74 @@ void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx); * On the other hand, the locking callbacks are no longer used. Consequently, * the callback management functions can be safely replaced with no-op macros. */ -# define CRYPTO_num_locks() (1) -# define CRYPTO_set_locking_callback(func) -# define CRYPTO_get_locking_callback() (NULL) -# define CRYPTO_set_add_lock_callback(func) -# define CRYPTO_get_add_lock_callback() (NULL) +#define CRYPTO_num_locks() (1) +#define CRYPTO_set_locking_callback(func) +#define CRYPTO_get_locking_callback() (NULL) +#define CRYPTO_set_add_lock_callback(func) +#define CRYPTO_get_add_lock_callback() (NULL) /* * These defines where used in combination with the old locking callbacks, * they are not called anymore, but old code that's not called might still * use them. */ -# define CRYPTO_LOCK 1 -# define CRYPTO_UNLOCK 2 -# define CRYPTO_READ 4 -# define CRYPTO_WRITE 8 +#define CRYPTO_LOCK 1 +#define CRYPTO_UNLOCK 2 +#define CRYPTO_READ 4 +#define CRYPTO_WRITE 8 /* This structure is no longer used */ typedef struct crypto_threadid_st { int dummy; } CRYPTO_THREADID; /* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */ -# define CRYPTO_THREADID_set_numeric(id, val) -# define CRYPTO_THREADID_set_pointer(id, ptr) -# define CRYPTO_THREADID_set_callback(threadid_func) (0) -# define CRYPTO_THREADID_get_callback() (NULL) -# define CRYPTO_THREADID_current(id) -# define CRYPTO_THREADID_cmp(a, b) (-1) -# define CRYPTO_THREADID_cpy(dest, src) -# define CRYPTO_THREADID_hash(id) (0UL) +#define CRYPTO_THREADID_set_numeric(id, val) +#define CRYPTO_THREADID_set_pointer(id, ptr) +#define CRYPTO_THREADID_set_callback(threadid_func) (0) +#define CRYPTO_THREADID_get_callback() (NULL) +#define CRYPTO_THREADID_current(id) +#define CRYPTO_THREADID_cmp(a, b) (-1) +#define CRYPTO_THREADID_cpy(dest, src) +#define CRYPTO_THREADID_hash(id) (0UL) -# ifndef OPENSSL_NO_DEPRECATED_1_0_0 -# define CRYPTO_set_id_callback(func) -# define CRYPTO_get_id_callback() (NULL) -# define CRYPTO_thread_id() (0UL) -# endif /* OPENSSL_NO_DEPRECATED_1_0_0 */ +#ifndef OPENSSL_NO_DEPRECATED_1_0_0 +#define CRYPTO_set_id_callback(func) +#define CRYPTO_get_id_callback() (NULL) +#define CRYPTO_thread_id() (0UL) +#endif /* OPENSSL_NO_DEPRECATED_1_0_0 */ -# define CRYPTO_set_dynlock_create_callback(dyn_create_function) -# define CRYPTO_set_dynlock_lock_callback(dyn_lock_function) -# define CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function) -# define CRYPTO_get_dynlock_create_callback() (NULL) -# define CRYPTO_get_dynlock_lock_callback() (NULL) -# define CRYPTO_get_dynlock_destroy_callback() (NULL) -# endif /* OPENSSL_NO_DEPRECATED_1_1_0 */ +#define CRYPTO_set_dynlock_create_callback(dyn_create_function) +#define CRYPTO_set_dynlock_lock_callback(dyn_lock_function) +#define CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function) +#define CRYPTO_get_dynlock_create_callback() (NULL) +#define CRYPTO_get_dynlock_lock_callback() (NULL) +#define CRYPTO_get_dynlock_destroy_callback() (NULL) +#endif /* OPENSSL_NO_DEPRECATED_1_1_0 */ typedef void *(*CRYPTO_malloc_fn)(size_t num, const char *file, int line); typedef void *(*CRYPTO_realloc_fn)(void *addr, size_t num, const char *file, - int line); + int line); typedef void (*CRYPTO_free_fn)(void *addr, const char *file, int line); int CRYPTO_set_mem_functions(CRYPTO_malloc_fn malloc_fn, - CRYPTO_realloc_fn realloc_fn, - CRYPTO_free_fn free_fn); + CRYPTO_realloc_fn realloc_fn, + CRYPTO_free_fn free_fn); void CRYPTO_get_mem_functions(CRYPTO_malloc_fn *malloc_fn, - CRYPTO_realloc_fn *realloc_fn, - CRYPTO_free_fn *free_fn); + CRYPTO_realloc_fn *realloc_fn, + CRYPTO_free_fn *free_fn); OSSL_CRYPTO_ALLOC void *CRYPTO_malloc(size_t num, const char *file, int line); OSSL_CRYPTO_ALLOC void *CRYPTO_zalloc(size_t num, const char *file, int line); OSSL_CRYPTO_ALLOC void *CRYPTO_aligned_alloc(size_t num, size_t align, - void **freeptr, const char *file, - int line); -OSSL_CRYPTO_ALLOC void *CRYPTO_memdup(const void *str, size_t siz, const char *file, int line); -OSSL_CRYPTO_ALLOC char *CRYPTO_strdup(const char *str, const char *file, int line); -OSSL_CRYPTO_ALLOC char *CRYPTO_strndup(const char *str, size_t s, const char *file, int line); + void **freeptr, const char *file, + int line); +void *CRYPTO_memdup(const void *str, size_t siz, const char *file, int line); +char *CRYPTO_strdup(const char *str, const char *file, int line); +char *CRYPTO_strndup(const char *str, size_t s, const char *file, int line); void CRYPTO_free(void *ptr, const char *file, int line); void CRYPTO_clear_free(void *ptr, size_t num, const char *file, int line); void *CRYPTO_realloc(void *addr, size_t num, const char *file, int line); void *CRYPTO_clear_realloc(void *addr, size_t old_num, size_t num, - const char *file, int line); + const char *file, int line); int CRYPTO_secure_malloc_init(size_t sz, size_t minsize); int CRYPTO_secure_malloc_done(void); @@ -373,7 +380,7 @@ OSSL_CRYPTO_ALLOC void *CRYPTO_secure_malloc(size_t num, const char *file, int l OSSL_CRYPTO_ALLOC void *CRYPTO_secure_zalloc(size_t num, const char *file, int line); void CRYPTO_secure_free(void *ptr, const char *file, int line); void CRYPTO_secure_clear_free(void *ptr, size_t num, - const char *file, int line); + const char *file, int line); int CRYPTO_secure_allocated(const void *ptr); int CRYPTO_secure_malloc_initialized(void); size_t CRYPTO_secure_actual_size(void *ptr); @@ -381,77 +388,77 @@ size_t CRYPTO_secure_used(void); void OPENSSL_cleanse(void *ptr, size_t len); -# ifndef OPENSSL_NO_CRYPTO_MDEBUG +#ifndef OPENSSL_NO_CRYPTO_MDEBUG /* * The following can be used to detect memory leaks in the library. If * used, it turns on malloc checking */ -# define CRYPTO_MEM_CHECK_OFF 0x0 /* Control only */ -# define CRYPTO_MEM_CHECK_ON 0x1 /* Control and mode bit */ -# define CRYPTO_MEM_CHECK_ENABLE 0x2 /* Control and mode bit */ -# define CRYPTO_MEM_CHECK_DISABLE 0x3 /* Control only */ +#define CRYPTO_MEM_CHECK_OFF 0x0 /* Control only */ +#define CRYPTO_MEM_CHECK_ON 0x1 /* Control and mode bit */ +#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* Control and mode bit */ +#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* Control only */ /* max allowed length for value of OPENSSL_MALLOC_FAILURES env var. */ -# define CRYPTO_MEM_CHECK_MAX_FS 256 +#define CRYPTO_MEM_CHECK_MAX_FS 256 void CRYPTO_get_alloc_counts(int *mcount, int *rcount, int *fcount); -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define OPENSSL_mem_debug_push(info) \ - CRYPTO_mem_debug_push(info, OPENSSL_FILE, OPENSSL_LINE) -# define OPENSSL_mem_debug_pop() \ - CRYPTO_mem_debug_pop() -# endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define OPENSSL_mem_debug_push(info) \ + CRYPTO_mem_debug_push(info, OPENSSL_FILE, OPENSSL_LINE) +#define OPENSSL_mem_debug_pop() \ + CRYPTO_mem_debug_pop() +#endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 int CRYPTO_set_mem_debug(int flag); OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_ctrl(int mode); OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_debug_push(const char *info, - const char *file, int line); + const char *file, int line); OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_debug_pop(void); OSSL_DEPRECATEDIN_3_0 void CRYPTO_mem_debug_malloc(void *addr, size_t num, - int flag, - const char *file, int line); + int flag, + const char *file, int line); OSSL_DEPRECATEDIN_3_0 void CRYPTO_mem_debug_realloc(void *addr1, void *addr2, - size_t num, int flag, - const char *file, int line); + size_t num, int flag, + const char *file, int line); OSSL_DEPRECATEDIN_3_0 void CRYPTO_mem_debug_free(void *addr, int flag, - const char *file, int line); + const char *file, int line); OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_leaks_cb(int (*cb)(const char *str, size_t len, void *u), - void *u); -# endif -# ifndef OPENSSL_NO_STDIO -# ifndef OPENSSL_NO_DEPRECATED_3_0 + void *u); +#endif +#ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_leaks_fp(FILE *); -# endif -# endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#endif +#endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 int CRYPTO_mem_leaks(BIO *bio); -# endif -# endif /* OPENSSL_NO_CRYPTO_MDEBUG */ +#endif +#endif /* OPENSSL_NO_CRYPTO_MDEBUG */ /* die if we have to */ ossl_noreturn void OPENSSL_die(const char *assertion, const char *file, int line); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define OpenSSLDie(f,l,a) OPENSSL_die((a),(f),(l)) -# endif -# define OPENSSL_assert(e) \ +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define OpenSSLDie(f, l, a) OPENSSL_die((a), (f), (l)) +#endif +#define OPENSSL_assert(e) \ (void)((e) ? 0 : (OPENSSL_die("assertion failed: " #e, OPENSSL_FILE, OPENSSL_LINE), 1)) int OPENSSL_isservice(void); void OPENSSL_init(void); -# ifdef OPENSSL_SYS_UNIX -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifdef OPENSSL_SYS_UNIX +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 void OPENSSL_fork_prepare(void); OSSL_DEPRECATEDIN_3_0 void OPENSSL_fork_parent(void); OSSL_DEPRECATEDIN_3_0 void OPENSSL_fork_child(void); -# endif -# endif +#endif +#endif struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result); int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec); int OPENSSL_gmtime_diff(int *pday, int *psec, - const struct tm *from, const struct tm *to); + const struct tm *from, const struct tm *to); /* * CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal. @@ -460,29 +467,29 @@ int OPENSSL_gmtime_diff(int *pday, int *psec, * into a defined order as the return value when a != b is undefined, other * than to be non-zero. */ -int CRYPTO_memcmp(const void * in_a, const void * in_b, size_t len); +int CRYPTO_memcmp(const void *in_a, const void *in_b, size_t len); /* Standard initialisation options */ -# define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 0x00000001L -# define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0x00000002L -# define OPENSSL_INIT_ADD_ALL_CIPHERS 0x00000004L -# define OPENSSL_INIT_ADD_ALL_DIGESTS 0x00000008L -# define OPENSSL_INIT_NO_ADD_ALL_CIPHERS 0x00000010L -# define OPENSSL_INIT_NO_ADD_ALL_DIGESTS 0x00000020L -# define OPENSSL_INIT_LOAD_CONFIG 0x00000040L -# define OPENSSL_INIT_NO_LOAD_CONFIG 0x00000080L -# define OPENSSL_INIT_ASYNC 0x00000100L -# define OPENSSL_INIT_ENGINE_RDRAND 0x00000200L -# define OPENSSL_INIT_ENGINE_DYNAMIC 0x00000400L -# define OPENSSL_INIT_ENGINE_OPENSSL 0x00000800L -# define OPENSSL_INIT_ENGINE_CRYPTODEV 0x00001000L -# define OPENSSL_INIT_ENGINE_CAPI 0x00002000L -# define OPENSSL_INIT_ENGINE_PADLOCK 0x00004000L -# define OPENSSL_INIT_ENGINE_AFALG 0x00008000L +#define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 0x00000001L +#define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0x00000002L +#define OPENSSL_INIT_ADD_ALL_CIPHERS 0x00000004L +#define OPENSSL_INIT_ADD_ALL_DIGESTS 0x00000008L +#define OPENSSL_INIT_NO_ADD_ALL_CIPHERS 0x00000010L +#define OPENSSL_INIT_NO_ADD_ALL_DIGESTS 0x00000020L +#define OPENSSL_INIT_LOAD_CONFIG 0x00000040L +#define OPENSSL_INIT_NO_LOAD_CONFIG 0x00000080L +#define OPENSSL_INIT_ASYNC 0x00000100L +#define OPENSSL_INIT_ENGINE_RDRAND 0x00000200L +#define OPENSSL_INIT_ENGINE_DYNAMIC 0x00000400L +#define OPENSSL_INIT_ENGINE_OPENSSL 0x00000800L +#define OPENSSL_INIT_ENGINE_CRYPTODEV 0x00001000L +#define OPENSSL_INIT_ENGINE_CAPI 0x00002000L +#define OPENSSL_INIT_ENGINE_PADLOCK 0x00004000L +#define OPENSSL_INIT_ENGINE_AFALG 0x00008000L /* FREE: 0x00010000L */ -# define OPENSSL_INIT_ATFORK 0x00020000L +#define OPENSSL_INIT_ATFORK 0x00020000L /* OPENSSL_INIT_BASE_ONLY 0x00040000L */ -# define OPENSSL_INIT_NO_ATEXIT 0x00080000L +#define OPENSSL_INIT_NO_ATEXIT 0x00080000L /* OPENSSL_INIT flag range 0x03f00000 reserved for OPENSSL_init_ssl() */ /* FREE: 0x04000000L */ /* FREE: 0x08000000L */ @@ -493,10 +500,9 @@ int CRYPTO_memcmp(const void * in_a, const void * in_b, size_t len); /* Max OPENSSL_INIT flag value is 0x80000000 */ /* openssl and dasync not counted as builtin */ -# define OPENSSL_INIT_ENGINE_ALL_BUILTIN \ +#define OPENSSL_INIT_ENGINE_ALL_BUILTIN \ (OPENSSL_INIT_ENGINE_RDRAND | OPENSSL_INIT_ENGINE_DYNAMIC \ - | OPENSSL_INIT_ENGINE_CRYPTODEV | OPENSSL_INIT_ENGINE_CAPI | \ - OPENSSL_INIT_ENGINE_PADLOCK) + | OPENSSL_INIT_ENGINE_CRYPTODEV | OPENSSL_INIT_ENGINE_CAPI | OPENSSL_INIT_ENGINE_PADLOCK) /* Library initialisation functions */ void OPENSSL_cleanup(void); @@ -507,48 +513,48 @@ void OPENSSL_thread_stop_ex(OSSL_LIB_CTX *ctx); /* Low-level control of initialization */ OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void); -# ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_STDIO int OPENSSL_INIT_set_config_filename(OPENSSL_INIT_SETTINGS *settings, - const char *config_filename); + const char *config_filename); void OPENSSL_INIT_set_config_file_flags(OPENSSL_INIT_SETTINGS *settings, - unsigned long flags); + unsigned long flags); int OPENSSL_INIT_set_config_appname(OPENSSL_INIT_SETTINGS *settings, - const char *config_appname); -# endif + const char *config_appname); +#endif void OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *settings); -# if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) -# if defined(_WIN32) -# if defined(BASETYPES) || defined(_WINDEF_H) +#if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) +#if defined(_WIN32) +#if defined(BASETYPES) || defined(_WINDEF_H) /* application has to include in order to use this */ typedef DWORD CRYPTO_THREAD_LOCAL; typedef DWORD CRYPTO_THREAD_ID; typedef LONG CRYPTO_ONCE; -# define CRYPTO_ONCE_STATIC_INIT 0 -# endif -# else -# if defined(__TANDEM) && defined(_SPT_MODEL_) -# define SPT_THREAD_SIGNAL 1 -# define SPT_THREAD_AWARE 1 -# include -# else -# include -# endif +#define CRYPTO_ONCE_STATIC_INIT 0 +#endif +#else +#if defined(__TANDEM) && defined(_SPT_MODEL_) +#define SPT_THREAD_SIGNAL 1 +#define SPT_THREAD_AWARE 1 +#include +#else +#include +#endif typedef pthread_once_t CRYPTO_ONCE; typedef pthread_key_t CRYPTO_THREAD_LOCAL; typedef pthread_t CRYPTO_THREAD_ID; -# define CRYPTO_ONCE_STATIC_INIT PTHREAD_ONCE_INIT -# endif -# endif +#define CRYPTO_ONCE_STATIC_INIT PTHREAD_ONCE_INIT +#endif +#endif -# if !defined(CRYPTO_ONCE_STATIC_INIT) +#if !defined(CRYPTO_ONCE_STATIC_INIT) typedef unsigned int CRYPTO_ONCE; typedef unsigned int CRYPTO_THREAD_LOCAL; typedef unsigned int CRYPTO_THREAD_ID; -# define CRYPTO_ONCE_STATIC_INIT 0 -# endif +#define CRYPTO_ONCE_STATIC_INIT 0 +#endif int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void)); @@ -562,9 +568,9 @@ int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b); OSSL_LIB_CTX *OSSL_LIB_CTX_new(void); OSSL_LIB_CTX *OSSL_LIB_CTX_new_from_dispatch(const OSSL_CORE_HANDLE *handle, - const OSSL_DISPATCH *in); + const OSSL_DISPATCH *in); OSSL_LIB_CTX *OSSL_LIB_CTX_new_child(const OSSL_CORE_HANDLE *handle, - const OSSL_DISPATCH *in); + const OSSL_DISPATCH *in); int OSSL_LIB_CTX_load_config(OSSL_LIB_CTX *ctx, const char *config_file); void OSSL_LIB_CTX_free(OSSL_LIB_CTX *); OSSL_LIB_CTX *OSSL_LIB_CTX_get0_global_default(void); @@ -574,10 +580,9 @@ void OSSL_LIB_CTX_set_conf_diagnostics(OSSL_LIB_CTX *ctx, int value); void OSSL_sleep(uint64_t millis); - void *OSSL_LIB_CTX_get_data(OSSL_LIB_CTX *ctx, int index); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ct.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ct.h index 1193962362..74b60ebe31 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ct.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ct.h @@ -10,35 +10,37 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_CT_H -# define OPENSSL_CT_H -# pragma once +#define OPENSSL_CT_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_CT_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_CT_H +#endif -# include +#include -# ifndef OPENSSL_NO_CT -# include -# include -# include -# include -# ifdef __cplusplus +#ifndef OPENSSL_NO_CT +#include +#include +#include +#include +#ifdef __cplusplus extern "C" { -# endif - +#endif /* Minimum RSA key size, from RFC6962 */ -# define SCT_MIN_RSA_BITS 2048 +#define SCT_MIN_RSA_BITS 2048 /* All hashes are SHA256 in v1 of Certificate Transparency */ -# define CT_V1_HASHLEN SHA256_DIGEST_LENGTH +#define CT_V1_HASHLEN SHA256_DIGEST_LENGTH +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(SCT, SCT, SCT) #define sk_SCT_num(sk) OPENSSL_sk_num(ossl_check_const_SCT_sk_type(sk)) #define sk_SCT_value(sk, idx) ((SCT *)OPENSSL_sk_value(ossl_check_const_SCT_sk_type(sk), (idx))) @@ -92,7 +94,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(CTLOG, CTLOG, CTLOG) #define sk_CTLOG_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(CTLOG) *)OPENSSL_sk_deep_copy(ossl_check_const_CTLOG_sk_type(sk), ossl_check_CTLOG_copyfunc_type(copyfunc), ossl_check_CTLOG_freefunc_type(freefunc))) #define sk_CTLOG_set_cmp_func(sk, cmp) ((sk_CTLOG_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_CTLOG_sk_type(sk), ossl_check_CTLOG_compfunc_type(cmp))) - +/* clang-format on */ typedef enum { CT_LOG_ENTRY_TYPE_NOT_SET = -1, @@ -132,7 +134,7 @@ typedef enum { * with the CT_POLICY_EVAL_CTX. */ CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new_ex(OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); /* * The same as CT_POLICY_EVAL_CTX_new_ex() but the default library @@ -144,7 +146,7 @@ CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void); void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx); /* Gets the peer certificate that the SCTs are for */ -X509* CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx); +X509 *CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx); /* * Sets the certificate associated with the received SCTs. @@ -154,7 +156,7 @@ X509* CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx); int CT_POLICY_EVAL_CTX_set1_cert(CT_POLICY_EVAL_CTX *ctx, X509 *cert); /* Gets the issuer of the aforementioned certificate */ -X509* CT_POLICY_EVAL_CTX_get0_issuer(const CT_POLICY_EVAL_CTX *ctx); +X509 *CT_POLICY_EVAL_CTX_get0_issuer(const CT_POLICY_EVAL_CTX *ctx); /* * Sets the issuer of the certificate associated with the received SCTs. @@ -168,7 +170,7 @@ const CTLOG_STORE *CT_POLICY_EVAL_CTX_get0_log_store(const CT_POLICY_EVAL_CTX *c /* Sets the log store that is in use. It must outlive the CT_POLICY_EVAL_CTX. */ void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx, - CTLOG_STORE *log_store); + CTLOG_STORE *log_store); /* * Gets the time, in milliseconds since the Unix epoch, that will be used as the @@ -200,11 +202,11 @@ SCT *SCT_new(void); * The caller is responsible for calling SCT_free when finished with the SCT. */ SCT *SCT_new_from_base64(unsigned char version, - const char *logid_base64, - ct_log_entry_type_t entry_type, - uint64_t timestamp, - const char *extensions_base64, - const char *signature_base64); + const char *logid_base64, + ct_log_entry_type_t entry_type, + uint64_t timestamp, + const char *extensions_base64, + const char *signature_base64); /* * Frees the SCT and the underlying data structures. @@ -259,7 +261,7 @@ __owur int SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len); * Returns 1 on success, 0 otherwise. */ __owur int SCT_set1_log_id(SCT *sct, const unsigned char *log_id, - size_t log_id_len); + size_t log_id_len); /* * Returns the timestamp for the SCT (epoch time in milliseconds). @@ -305,7 +307,7 @@ void SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len); * Returns 1 on success, 0 otherwise. */ __owur int SCT_set1_extensions(SCT *sct, const unsigned char *ext, - size_t ext_len); + size_t ext_len); /* * Set *sig to point to the signature for the SCT. sig must not be NULL. @@ -325,7 +327,7 @@ void SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len); * Returns 1 on success, 0 otherwise. */ __owur int SCT_set1_signature(SCT *sct, const unsigned char *sig, - size_t sig_len); + size_t sig_len); /* * The origin of this SCT, e.g. TLS extension, OCSP response, etc. @@ -359,7 +361,7 @@ void SCT_print(const SCT *sct, BIO *out, int indent, const CTLOG_STORE *logs); * came from, so that the log names can be printed. */ void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent, - const char *separator, const CTLOG_STORE *logs); + const char *separator, const CTLOG_STORE *logs); /* * Gets the last result of validating this SCT. @@ -384,8 +386,7 @@ __owur int SCT_validate(SCT *sct, const CT_POLICY_EVAL_CTX *ctx); * Returns a negative integer if an error occurs. */ __owur int SCT_LIST_validate(const STACK_OF(SCT) *scts, - CT_POLICY_EVAL_CTX *ctx); - + CT_POLICY_EVAL_CTX *ctx); /********************************* * SCT parsing and serialization * @@ -416,7 +417,7 @@ __owur int i2o_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp); * not defined. */ STACK_OF(SCT) *o2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp, - size_t len); + size_t len); /* * Serialize (to DER format) a stack of SCTs and return the length. @@ -443,7 +444,7 @@ __owur int i2d_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp); * not defined. */ STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp, - long len); + long len); /* * Serialize (to TLS format) an |sct| and write it to |out|. @@ -482,7 +483,7 @@ SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len); * Should be deleted by the caller using CTLOG_free when no longer needed. */ CTLOG *CTLOG_new_ex(EVP_PKEY *public_key, const char *name, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); /* * The same as CTLOG_new_ex except that the default library context and @@ -499,16 +500,16 @@ CTLOG *CTLOG_new(EVP_PKEY *public_key, const char *name); * Should be deleted by the caller using CTLOG_free when no longer needed. */ int CTLOG_new_from_base64_ex(CTLOG **ct_log, const char *pkey_base64, - const char *name, OSSL_LIB_CTX *libctx, - const char *propq); + const char *name, OSSL_LIB_CTX *libctx, + const char *propq); /* * The same as CTLOG_new_from_base64_ex() except that the default * library context and property query string are used. * Returns 1 on success, 0 on failure. */ -int CTLOG_new_from_base64(CTLOG ** ct_log, - const char *pkey_base64, const char *name); +int CTLOG_new_from_base64(CTLOG **ct_log, + const char *pkey_base64, const char *name); /* * Deletes a CT log instance and its fields. @@ -519,7 +520,7 @@ void CTLOG_free(CTLOG *log); const char *CTLOG_get0_name(const CTLOG *log); /* Gets the ID of the CT log */ void CTLOG_get0_log_id(const CTLOG *log, const uint8_t **log_id, - size_t *log_id_len); + size_t *log_id_len); /* Gets the public key of the CT log */ EVP_PKEY *CTLOG_get0_public_key(const CTLOG *log); @@ -551,8 +552,8 @@ void CTLOG_STORE_free(CTLOG_STORE *store); * Returns the CT log, or NULL if no match is found. */ const CTLOG *CTLOG_STORE_get0_log_by_id(const CTLOG_STORE *store, - const uint8_t *log_id, - size_t log_id_len); + const uint8_t *log_id, + size_t log_id_len); /* * Loads a CT log list into a |store| from a |file|. @@ -566,8 +567,8 @@ __owur int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file); */ __owur int CTLOG_STORE_load_default_file(CTLOG_STORE *store); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif -# endif +#endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/err.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/err.h index 8f74f4805b..9370364dd1 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/err.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/err.h @@ -7,52 +7,54 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_ERR_H -# define OPENSSL_ERR_H -# pragma once +#define OPENSSL_ERR_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_ERR_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_ERR_H +#endif -# include +#include -# ifndef OPENSSL_NO_STDIO -# include -# include -# endif +#ifndef OPENSSL_NO_STDIO +#include +#include +#endif -# include -# include -# include -# include +#include +#include +#include +#include -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# ifndef OPENSSL_NO_FILENAMES -# define ERR_PUT_error(l,f,r,fn,ln) ERR_put_error(l,f,r,fn,ln) -# else -# define ERR_PUT_error(l,f,r,fn,ln) ERR_put_error(l,f,r,NULL,0) -# endif -# endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_FILENAMES +#define ERR_PUT_error(l, f, r, fn, ln) ERR_put_error(l, f, r, fn, ln) +#else +#define ERR_PUT_error(l, f, r, fn, ln) ERR_put_error(l, f, r, NULL, 0) +#endif +#endif -# include -# include +#include +#include -# define ERR_TXT_MALLOCED 0x01 -# define ERR_TXT_STRING 0x02 +#define ERR_TXT_MALLOCED 0x01 +#define ERR_TXT_STRING 0x02 -# if !defined(OPENSSL_NO_DEPRECATED_3_0) || defined(OSSL_FORCE_ERR_STATE) -# define ERR_FLAG_MARK 0x01 -# define ERR_FLAG_CLEAR 0x02 +#if !defined(OPENSSL_NO_DEPRECATED_3_0) || defined(OSSL_FORCE_ERR_STATE) +#define ERR_FLAG_MARK 0x01 +#define ERR_FLAG_CLEAR 0x02 -# define ERR_NUM_ERRORS 16 +#define ERR_NUM_ERRORS 16 struct err_state_st { int err_flags[ERR_NUM_ERRORS]; int err_marks[ERR_NUM_ERRORS]; @@ -65,109 +67,109 @@ struct err_state_st { char *err_func[ERR_NUM_ERRORS]; int top, bottom; }; -# endif +#endif /* library */ -# define ERR_LIB_NONE 1 -# define ERR_LIB_SYS 2 -# define ERR_LIB_BN 3 -# define ERR_LIB_RSA 4 -# define ERR_LIB_DH 5 -# define ERR_LIB_EVP 6 -# define ERR_LIB_BUF 7 -# define ERR_LIB_OBJ 8 -# define ERR_LIB_PEM 9 -# define ERR_LIB_DSA 10 -# define ERR_LIB_X509 11 +#define ERR_LIB_NONE 1 +#define ERR_LIB_SYS 2 +#define ERR_LIB_BN 3 +#define ERR_LIB_RSA 4 +#define ERR_LIB_DH 5 +#define ERR_LIB_EVP 6 +#define ERR_LIB_BUF 7 +#define ERR_LIB_OBJ 8 +#define ERR_LIB_PEM 9 +#define ERR_LIB_DSA 10 +#define ERR_LIB_X509 11 /* #define ERR_LIB_METH 12 */ -# define ERR_LIB_ASN1 13 -# define ERR_LIB_CONF 14 -# define ERR_LIB_CRYPTO 15 -# define ERR_LIB_EC 16 -# define ERR_LIB_SSL 20 +#define ERR_LIB_ASN1 13 +#define ERR_LIB_CONF 14 +#define ERR_LIB_CRYPTO 15 +#define ERR_LIB_EC 16 +#define ERR_LIB_SSL 20 /* #define ERR_LIB_SSL23 21 */ /* #define ERR_LIB_SSL2 22 */ /* #define ERR_LIB_SSL3 23 */ /* #define ERR_LIB_RSAREF 30 */ /* #define ERR_LIB_PROXY 31 */ -# define ERR_LIB_BIO 32 -# define ERR_LIB_PKCS7 33 -# define ERR_LIB_X509V3 34 -# define ERR_LIB_PKCS12 35 -# define ERR_LIB_RAND 36 -# define ERR_LIB_DSO 37 -# define ERR_LIB_ENGINE 38 -# define ERR_LIB_OCSP 39 -# define ERR_LIB_UI 40 -# define ERR_LIB_COMP 41 -# define ERR_LIB_ECDSA 42 -# define ERR_LIB_ECDH 43 -# define ERR_LIB_OSSL_STORE 44 -# define ERR_LIB_FIPS 45 -# define ERR_LIB_CMS 46 -# define ERR_LIB_TS 47 -# define ERR_LIB_HMAC 48 +#define ERR_LIB_BIO 32 +#define ERR_LIB_PKCS7 33 +#define ERR_LIB_X509V3 34 +#define ERR_LIB_PKCS12 35 +#define ERR_LIB_RAND 36 +#define ERR_LIB_DSO 37 +#define ERR_LIB_ENGINE 38 +#define ERR_LIB_OCSP 39 +#define ERR_LIB_UI 40 +#define ERR_LIB_COMP 41 +#define ERR_LIB_ECDSA 42 +#define ERR_LIB_ECDH 43 +#define ERR_LIB_OSSL_STORE 44 +#define ERR_LIB_FIPS 45 +#define ERR_LIB_CMS 46 +#define ERR_LIB_TS 47 +#define ERR_LIB_HMAC 48 /* # define ERR_LIB_JPAKE 49 */ -# define ERR_LIB_CT 50 -# define ERR_LIB_ASYNC 51 -# define ERR_LIB_KDF 52 -# define ERR_LIB_SM2 53 -# define ERR_LIB_ESS 54 -# define ERR_LIB_PROP 55 -# define ERR_LIB_CRMF 56 -# define ERR_LIB_PROV 57 -# define ERR_LIB_CMP 58 -# define ERR_LIB_OSSL_ENCODER 59 -# define ERR_LIB_OSSL_DECODER 60 -# define ERR_LIB_HTTP 61 +#define ERR_LIB_CT 50 +#define ERR_LIB_ASYNC 51 +#define ERR_LIB_KDF 52 +#define ERR_LIB_SM2 53 +#define ERR_LIB_ESS 54 +#define ERR_LIB_PROP 55 +#define ERR_LIB_CRMF 56 +#define ERR_LIB_PROV 57 +#define ERR_LIB_CMP 58 +#define ERR_LIB_OSSL_ENCODER 59 +#define ERR_LIB_OSSL_DECODER 60 +#define ERR_LIB_HTTP 61 -# define ERR_LIB_USER 128 +#define ERR_LIB_USER 128 -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define ASN1err(f, r) ERR_raise_data(ERR_LIB_ASN1, (r), NULL) -# define ASYNCerr(f, r) ERR_raise_data(ERR_LIB_ASYNC, (r), NULL) -# define BIOerr(f, r) ERR_raise_data(ERR_LIB_BIO, (r), NULL) -# define BNerr(f, r) ERR_raise_data(ERR_LIB_BN, (r), NULL) -# define BUFerr(f, r) ERR_raise_data(ERR_LIB_BUF, (r), NULL) -# define CMPerr(f, r) ERR_raise_data(ERR_LIB_CMP, (r), NULL) -# define CMSerr(f, r) ERR_raise_data(ERR_LIB_CMS, (r), NULL) -# define COMPerr(f, r) ERR_raise_data(ERR_LIB_COMP, (r), NULL) -# define CONFerr(f, r) ERR_raise_data(ERR_LIB_CONF, (r), NULL) -# define CRMFerr(f, r) ERR_raise_data(ERR_LIB_CRMF, (r), NULL) -# define CRYPTOerr(f, r) ERR_raise_data(ERR_LIB_CRYPTO, (r), NULL) -# define CTerr(f, r) ERR_raise_data(ERR_LIB_CT, (r), NULL) -# define DHerr(f, r) ERR_raise_data(ERR_LIB_DH, (r), NULL) -# define DSAerr(f, r) ERR_raise_data(ERR_LIB_DSA, (r), NULL) -# define DSOerr(f, r) ERR_raise_data(ERR_LIB_DSO, (r), NULL) -# define ECDHerr(f, r) ERR_raise_data(ERR_LIB_ECDH, (r), NULL) -# define ECDSAerr(f, r) ERR_raise_data(ERR_LIB_ECDSA, (r), NULL) -# define ECerr(f, r) ERR_raise_data(ERR_LIB_EC, (r), NULL) -# define ENGINEerr(f, r) ERR_raise_data(ERR_LIB_ENGINE, (r), NULL) -# define ESSerr(f, r) ERR_raise_data(ERR_LIB_ESS, (r), NULL) -# define EVPerr(f, r) ERR_raise_data(ERR_LIB_EVP, (r), NULL) -# define FIPSerr(f, r) ERR_raise_data(ERR_LIB_FIPS, (r), NULL) -# define HMACerr(f, r) ERR_raise_data(ERR_LIB_HMAC, (r), NULL) -# define HTTPerr(f, r) ERR_raise_data(ERR_LIB_HTTP, (r), NULL) -# define KDFerr(f, r) ERR_raise_data(ERR_LIB_KDF, (r), NULL) -# define OBJerr(f, r) ERR_raise_data(ERR_LIB_OBJ, (r), NULL) -# define OCSPerr(f, r) ERR_raise_data(ERR_LIB_OCSP, (r), NULL) -# define OSSL_STOREerr(f, r) ERR_raise_data(ERR_LIB_OSSL_STORE, (r), NULL) -# define PEMerr(f, r) ERR_raise_data(ERR_LIB_PEM, (r), NULL) -# define PKCS12err(f, r) ERR_raise_data(ERR_LIB_PKCS12, (r), NULL) -# define PKCS7err(f, r) ERR_raise_data(ERR_LIB_PKCS7, (r), NULL) -# define PROPerr(f, r) ERR_raise_data(ERR_LIB_PROP, (r), NULL) -# define PROVerr(f, r) ERR_raise_data(ERR_LIB_PROV, (r), NULL) -# define RANDerr(f, r) ERR_raise_data(ERR_LIB_RAND, (r), NULL) -# define RSAerr(f, r) ERR_raise_data(ERR_LIB_RSA, (r), NULL) -# define KDFerr(f, r) ERR_raise_data(ERR_LIB_KDF, (r), NULL) -# define SM2err(f, r) ERR_raise_data(ERR_LIB_SM2, (r), NULL) -# define SSLerr(f, r) ERR_raise_data(ERR_LIB_SSL, (r), NULL) -# define SYSerr(f, r) ERR_raise_data(ERR_LIB_SYS, (r), NULL) -# define TSerr(f, r) ERR_raise_data(ERR_LIB_TS, (r), NULL) -# define UIerr(f, r) ERR_raise_data(ERR_LIB_UI, (r), NULL) -# define X509V3err(f, r) ERR_raise_data(ERR_LIB_X509V3, (r), NULL) -# define X509err(f, r) ERR_raise_data(ERR_LIB_X509, (r), NULL) -# endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define ASN1err(f, r) ERR_raise_data(ERR_LIB_ASN1, (r), NULL) +#define ASYNCerr(f, r) ERR_raise_data(ERR_LIB_ASYNC, (r), NULL) +#define BIOerr(f, r) ERR_raise_data(ERR_LIB_BIO, (r), NULL) +#define BNerr(f, r) ERR_raise_data(ERR_LIB_BN, (r), NULL) +#define BUFerr(f, r) ERR_raise_data(ERR_LIB_BUF, (r), NULL) +#define CMPerr(f, r) ERR_raise_data(ERR_LIB_CMP, (r), NULL) +#define CMSerr(f, r) ERR_raise_data(ERR_LIB_CMS, (r), NULL) +#define COMPerr(f, r) ERR_raise_data(ERR_LIB_COMP, (r), NULL) +#define CONFerr(f, r) ERR_raise_data(ERR_LIB_CONF, (r), NULL) +#define CRMFerr(f, r) ERR_raise_data(ERR_LIB_CRMF, (r), NULL) +#define CRYPTOerr(f, r) ERR_raise_data(ERR_LIB_CRYPTO, (r), NULL) +#define CTerr(f, r) ERR_raise_data(ERR_LIB_CT, (r), NULL) +#define DHerr(f, r) ERR_raise_data(ERR_LIB_DH, (r), NULL) +#define DSAerr(f, r) ERR_raise_data(ERR_LIB_DSA, (r), NULL) +#define DSOerr(f, r) ERR_raise_data(ERR_LIB_DSO, (r), NULL) +#define ECDHerr(f, r) ERR_raise_data(ERR_LIB_ECDH, (r), NULL) +#define ECDSAerr(f, r) ERR_raise_data(ERR_LIB_ECDSA, (r), NULL) +#define ECerr(f, r) ERR_raise_data(ERR_LIB_EC, (r), NULL) +#define ENGINEerr(f, r) ERR_raise_data(ERR_LIB_ENGINE, (r), NULL) +#define ESSerr(f, r) ERR_raise_data(ERR_LIB_ESS, (r), NULL) +#define EVPerr(f, r) ERR_raise_data(ERR_LIB_EVP, (r), NULL) +#define FIPSerr(f, r) ERR_raise_data(ERR_LIB_FIPS, (r), NULL) +#define HMACerr(f, r) ERR_raise_data(ERR_LIB_HMAC, (r), NULL) +#define HTTPerr(f, r) ERR_raise_data(ERR_LIB_HTTP, (r), NULL) +#define KDFerr(f, r) ERR_raise_data(ERR_LIB_KDF, (r), NULL) +#define OBJerr(f, r) ERR_raise_data(ERR_LIB_OBJ, (r), NULL) +#define OCSPerr(f, r) ERR_raise_data(ERR_LIB_OCSP, (r), NULL) +#define OSSL_STOREerr(f, r) ERR_raise_data(ERR_LIB_OSSL_STORE, (r), NULL) +#define PEMerr(f, r) ERR_raise_data(ERR_LIB_PEM, (r), NULL) +#define PKCS12err(f, r) ERR_raise_data(ERR_LIB_PKCS12, (r), NULL) +#define PKCS7err(f, r) ERR_raise_data(ERR_LIB_PKCS7, (r), NULL) +#define PROPerr(f, r) ERR_raise_data(ERR_LIB_PROP, (r), NULL) +#define PROVerr(f, r) ERR_raise_data(ERR_LIB_PROV, (r), NULL) +#define RANDerr(f, r) ERR_raise_data(ERR_LIB_RAND, (r), NULL) +#define RSAerr(f, r) ERR_raise_data(ERR_LIB_RSA, (r), NULL) +#define KDFerr(f, r) ERR_raise_data(ERR_LIB_KDF, (r), NULL) +#define SM2err(f, r) ERR_raise_data(ERR_LIB_SM2, (r), NULL) +#define SSLerr(f, r) ERR_raise_data(ERR_LIB_SSL, (r), NULL) +#define SYSerr(f, r) ERR_raise_data(ERR_LIB_SYS, (r), NULL) +#define TSerr(f, r) ERR_raise_data(ERR_LIB_TS, (r), NULL) +#define UIerr(f, r) ERR_raise_data(ERR_LIB_UI, (r), NULL) +#define X509V3err(f, r) ERR_raise_data(ERR_LIB_X509V3, (r), NULL) +#define X509err(f, r) ERR_raise_data(ERR_LIB_X509, (r), NULL) +#endif /*- * The error code packs differently depending on if it records a system @@ -215,28 +217,28 @@ struct err_state_st { */ /* Macros to help decode recorded system errors */ -# define ERR_SYSTEM_FLAG ((unsigned int)INT_MAX + 1) -# define ERR_SYSTEM_MASK ((unsigned int)INT_MAX) +#define ERR_SYSTEM_FLAG ((unsigned int)INT_MAX + 1) +#define ERR_SYSTEM_MASK ((unsigned int)INT_MAX) /* * Macros to help decode recorded OpenSSL errors * As expressed above, RFLAGS and REASON overlap by one bit to allow * ERR_R_FATAL to use ERR_RFLAG_FATAL as its reason code. */ -# define ERR_LIB_OFFSET 23L -# define ERR_LIB_MASK 0xFF -# define ERR_RFLAGS_OFFSET 18L -# define ERR_RFLAGS_MASK 0x1F -# define ERR_REASON_MASK 0X7FFFFF +#define ERR_LIB_OFFSET 23L +#define ERR_LIB_MASK 0xFF +#define ERR_RFLAGS_OFFSET 18L +#define ERR_RFLAGS_MASK 0x1F +#define ERR_REASON_MASK 0X7FFFFF /* * Reason flags are defined pre-shifted to easily combine with the reason * number. */ -# define ERR_RFLAG_FATAL (0x1 << ERR_RFLAGS_OFFSET) -# define ERR_RFLAG_COMMON (0x2 << ERR_RFLAGS_OFFSET) +#define ERR_RFLAG_FATAL (0x1 << ERR_RFLAGS_OFFSET) +#define ERR_RFLAG_COMMON (0x2 << ERR_RFLAGS_OFFSET) -# define ERR_SYSTEM_ERROR(errcode) (((errcode) & ERR_SYSTEM_FLAG) != 0) +#define ERR_SYSTEM_ERROR(errcode) (((errcode) & ERR_SYSTEM_FLAG) != 0) static ossl_unused ossl_inline int ERR_GET_LIB(unsigned long errcode) { @@ -275,102 +277,102 @@ static ossl_unused ossl_inline int ERR_COMMON_ERROR(unsigned long errcode) * ERR_PACK takes reason flags and reason code combined in |reason|. * ERR_PACK ignores |func|, that parameter is just legacy from pre-3.0 OpenSSL. */ -# define ERR_PACK(lib,func,reason) \ - ( (((unsigned long)(lib) & ERR_LIB_MASK ) << ERR_LIB_OFFSET) | \ - (((unsigned long)(reason) & ERR_REASON_MASK)) ) +#define ERR_PACK(lib, func, reason) \ + ((((unsigned long)(lib) & ERR_LIB_MASK) << ERR_LIB_OFFSET) | (((unsigned long)(reason) & ERR_REASON_MASK))) -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define SYS_F_FOPEN 0 -# define SYS_F_CONNECT 0 -# define SYS_F_GETSERVBYNAME 0 -# define SYS_F_SOCKET 0 -# define SYS_F_IOCTLSOCKET 0 -# define SYS_F_BIND 0 -# define SYS_F_LISTEN 0 -# define SYS_F_ACCEPT 0 -# define SYS_F_WSASTARTUP 0 -# define SYS_F_OPENDIR 0 -# define SYS_F_FREAD 0 -# define SYS_F_GETADDRINFO 0 -# define SYS_F_GETNAMEINFO 0 -# define SYS_F_SETSOCKOPT 0 -# define SYS_F_GETSOCKOPT 0 -# define SYS_F_GETSOCKNAME 0 -# define SYS_F_GETHOSTBYNAME 0 -# define SYS_F_FFLUSH 0 -# define SYS_F_OPEN 0 -# define SYS_F_CLOSE 0 -# define SYS_F_IOCTL 0 -# define SYS_F_STAT 0 -# define SYS_F_FCNTL 0 -# define SYS_F_FSTAT 0 -# define SYS_F_SENDFILE 0 -# endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define SYS_F_FOPEN 0 +#define SYS_F_CONNECT 0 +#define SYS_F_GETSERVBYNAME 0 +#define SYS_F_SOCKET 0 +#define SYS_F_IOCTLSOCKET 0 +#define SYS_F_BIND 0 +#define SYS_F_LISTEN 0 +#define SYS_F_ACCEPT 0 +#define SYS_F_WSASTARTUP 0 +#define SYS_F_OPENDIR 0 +#define SYS_F_FREAD 0 +#define SYS_F_GETADDRINFO 0 +#define SYS_F_GETNAMEINFO 0 +#define SYS_F_SETSOCKOPT 0 +#define SYS_F_GETSOCKOPT 0 +#define SYS_F_GETSOCKNAME 0 +#define SYS_F_GETHOSTBYNAME 0 +#define SYS_F_FFLUSH 0 +#define SYS_F_OPEN 0 +#define SYS_F_CLOSE 0 +#define SYS_F_IOCTL 0 +#define SYS_F_STAT 0 +#define SYS_F_FCNTL 0 +#define SYS_F_FSTAT 0 +#define SYS_F_SENDFILE 0 +#endif /* * All ERR_R_ codes must be combined with ERR_RFLAG_COMMON. */ /* "we came from here" global reason codes, range 1..255 */ -# define ERR_R_SYS_LIB (ERR_LIB_SYS/* 2 */ | ERR_RFLAG_COMMON) -# define ERR_R_BN_LIB (ERR_LIB_BN/* 3 */ | ERR_RFLAG_COMMON) -# define ERR_R_RSA_LIB (ERR_LIB_RSA/* 4 */ | ERR_RFLAG_COMMON) -# define ERR_R_DH_LIB (ERR_LIB_DH/* 5 */ | ERR_RFLAG_COMMON) -# define ERR_R_EVP_LIB (ERR_LIB_EVP/* 6 */ | ERR_RFLAG_COMMON) -# define ERR_R_BUF_LIB (ERR_LIB_BUF/* 7 */ | ERR_RFLAG_COMMON) -# define ERR_R_OBJ_LIB (ERR_LIB_OBJ/* 8 */ | ERR_RFLAG_COMMON) -# define ERR_R_PEM_LIB (ERR_LIB_PEM/* 9 */ | ERR_RFLAG_COMMON) -# define ERR_R_DSA_LIB (ERR_LIB_DSA/* 10 */ | ERR_RFLAG_COMMON) -# define ERR_R_X509_LIB (ERR_LIB_X509/* 11 */ | ERR_RFLAG_COMMON) -# define ERR_R_ASN1_LIB (ERR_LIB_ASN1/* 13 */ | ERR_RFLAG_COMMON) -# define ERR_R_CONF_LIB (ERR_LIB_CONF/* 14 */ | ERR_RFLAG_COMMON) -# define ERR_R_CRYPTO_LIB (ERR_LIB_CRYPTO/* 15 */ | ERR_RFLAG_COMMON) -# define ERR_R_EC_LIB (ERR_LIB_EC/* 16 */ | ERR_RFLAG_COMMON) -# define ERR_R_SSL_LIB (ERR_LIB_SSL/* 20 */ | ERR_RFLAG_COMMON) -# define ERR_R_BIO_LIB (ERR_LIB_BIO/* 32 */ | ERR_RFLAG_COMMON) -# define ERR_R_PKCS7_LIB (ERR_LIB_PKCS7/* 33 */ | ERR_RFLAG_COMMON) -# define ERR_R_X509V3_LIB (ERR_LIB_X509V3/* 34 */ | ERR_RFLAG_COMMON) -# define ERR_R_PKCS12_LIB (ERR_LIB_PKCS12/* 35 */ | ERR_RFLAG_COMMON) -# define ERR_R_RAND_LIB (ERR_LIB_RAND/* 36 */ | ERR_RFLAG_COMMON) -# define ERR_R_DSO_LIB (ERR_LIB_DSO/* 37 */ | ERR_RFLAG_COMMON) -# define ERR_R_ENGINE_LIB (ERR_LIB_ENGINE/* 38 */ | ERR_RFLAG_COMMON) -# define ERR_R_UI_LIB (ERR_LIB_UI/* 40 */ | ERR_RFLAG_COMMON) -# define ERR_R_ECDSA_LIB (ERR_LIB_ECDSA/* 42 */ | ERR_RFLAG_COMMON) -# define ERR_R_OSSL_STORE_LIB (ERR_LIB_OSSL_STORE/* 44 */ | ERR_RFLAG_COMMON) -# define ERR_R_CMS_LIB (ERR_LIB_CMS/* 46 */ | ERR_RFLAG_COMMON) -# define ERR_R_TS_LIB (ERR_LIB_TS/* 47 */ | ERR_RFLAG_COMMON) -# define ERR_R_CT_LIB (ERR_LIB_CT/* 50 */ | ERR_RFLAG_COMMON) -# define ERR_R_PROV_LIB (ERR_LIB_PROV/* 57 */ | ERR_RFLAG_COMMON) -# define ERR_R_ESS_LIB (ERR_LIB_ESS/* 54 */ | ERR_RFLAG_COMMON) -# define ERR_R_CMP_LIB (ERR_LIB_CMP/* 58 */ | ERR_RFLAG_COMMON) -# define ERR_R_OSSL_ENCODER_LIB (ERR_LIB_OSSL_ENCODER/* 59 */ | ERR_RFLAG_COMMON) -# define ERR_R_OSSL_DECODER_LIB (ERR_LIB_OSSL_DECODER/* 60 */ | ERR_RFLAG_COMMON) +#define ERR_R_SYS_LIB (ERR_LIB_SYS /* 2 */ | ERR_RFLAG_COMMON) +#define ERR_R_BN_LIB (ERR_LIB_BN /* 3 */ | ERR_RFLAG_COMMON) +#define ERR_R_RSA_LIB (ERR_LIB_RSA /* 4 */ | ERR_RFLAG_COMMON) +#define ERR_R_DH_LIB (ERR_LIB_DH /* 5 */ | ERR_RFLAG_COMMON) +#define ERR_R_EVP_LIB (ERR_LIB_EVP /* 6 */ | ERR_RFLAG_COMMON) +#define ERR_R_BUF_LIB (ERR_LIB_BUF /* 7 */ | ERR_RFLAG_COMMON) +#define ERR_R_OBJ_LIB (ERR_LIB_OBJ /* 8 */ | ERR_RFLAG_COMMON) +#define ERR_R_PEM_LIB (ERR_LIB_PEM /* 9 */ | ERR_RFLAG_COMMON) +#define ERR_R_DSA_LIB (ERR_LIB_DSA /* 10 */ | ERR_RFLAG_COMMON) +#define ERR_R_X509_LIB (ERR_LIB_X509 /* 11 */ | ERR_RFLAG_COMMON) +#define ERR_R_ASN1_LIB (ERR_LIB_ASN1 /* 13 */ | ERR_RFLAG_COMMON) +#define ERR_R_CONF_LIB (ERR_LIB_CONF /* 14 */ | ERR_RFLAG_COMMON) +#define ERR_R_CRYPTO_LIB (ERR_LIB_CRYPTO /* 15 */ | ERR_RFLAG_COMMON) +#define ERR_R_EC_LIB (ERR_LIB_EC /* 16 */ | ERR_RFLAG_COMMON) +#define ERR_R_SSL_LIB (ERR_LIB_SSL /* 20 */ | ERR_RFLAG_COMMON) +#define ERR_R_BIO_LIB (ERR_LIB_BIO /* 32 */ | ERR_RFLAG_COMMON) +#define ERR_R_PKCS7_LIB (ERR_LIB_PKCS7 /* 33 */ | ERR_RFLAG_COMMON) +#define ERR_R_X509V3_LIB (ERR_LIB_X509V3 /* 34 */ | ERR_RFLAG_COMMON) +#define ERR_R_PKCS12_LIB (ERR_LIB_PKCS12 /* 35 */ | ERR_RFLAG_COMMON) +#define ERR_R_RAND_LIB (ERR_LIB_RAND /* 36 */ | ERR_RFLAG_COMMON) +#define ERR_R_DSO_LIB (ERR_LIB_DSO /* 37 */ | ERR_RFLAG_COMMON) +#define ERR_R_ENGINE_LIB (ERR_LIB_ENGINE /* 38 */ | ERR_RFLAG_COMMON) +#define ERR_R_UI_LIB (ERR_LIB_UI /* 40 */ | ERR_RFLAG_COMMON) +#define ERR_R_ECDSA_LIB (ERR_LIB_ECDSA /* 42 */ | ERR_RFLAG_COMMON) +#define ERR_R_OSSL_STORE_LIB (ERR_LIB_OSSL_STORE /* 44 */ | ERR_RFLAG_COMMON) +#define ERR_R_CMS_LIB (ERR_LIB_CMS /* 46 */ | ERR_RFLAG_COMMON) +#define ERR_R_TS_LIB (ERR_LIB_TS /* 47 */ | ERR_RFLAG_COMMON) +#define ERR_R_CT_LIB (ERR_LIB_CT /* 50 */ | ERR_RFLAG_COMMON) +#define ERR_R_PROV_LIB (ERR_LIB_PROV /* 57 */ | ERR_RFLAG_COMMON) +#define ERR_R_ESS_LIB (ERR_LIB_ESS /* 54 */ | ERR_RFLAG_COMMON) +#define ERR_R_CMP_LIB (ERR_LIB_CMP /* 58 */ | ERR_RFLAG_COMMON) +#define ERR_R_OSSL_ENCODER_LIB (ERR_LIB_OSSL_ENCODER /* 59 */ | ERR_RFLAG_COMMON) +#define ERR_R_OSSL_DECODER_LIB (ERR_LIB_OSSL_DECODER /* 60 */ | ERR_RFLAG_COMMON) /* Other common error codes, range 256..2^ERR_RFLAGS_OFFSET-1 */ -# define ERR_R_FATAL (ERR_RFLAG_FATAL|ERR_RFLAG_COMMON) -# define ERR_R_MALLOC_FAILURE (256|ERR_R_FATAL) -# define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (257|ERR_R_FATAL) -# define ERR_R_PASSED_NULL_PARAMETER (258|ERR_R_FATAL) -# define ERR_R_INTERNAL_ERROR (259|ERR_R_FATAL) -# define ERR_R_DISABLED (260|ERR_R_FATAL) -# define ERR_R_INIT_FAIL (261|ERR_R_FATAL) -# define ERR_R_PASSED_INVALID_ARGUMENT (262|ERR_RFLAG_COMMON) -# define ERR_R_OPERATION_FAIL (263|ERR_R_FATAL) -# define ERR_R_INVALID_PROVIDER_FUNCTIONS (264|ERR_R_FATAL) -# define ERR_R_INTERRUPTED_OR_CANCELLED (265|ERR_RFLAG_COMMON) -# define ERR_R_NESTED_ASN1_ERROR (266|ERR_RFLAG_COMMON) -# define ERR_R_MISSING_ASN1_EOS (267|ERR_RFLAG_COMMON) -# define ERR_R_UNSUPPORTED (268|ERR_RFLAG_COMMON) -# define ERR_R_FETCH_FAILED (269|ERR_RFLAG_COMMON) -# define ERR_R_INVALID_PROPERTY_DEFINITION (270|ERR_RFLAG_COMMON) -# define ERR_R_UNABLE_TO_GET_READ_LOCK (271|ERR_R_FATAL) -# define ERR_R_UNABLE_TO_GET_WRITE_LOCK (272|ERR_R_FATAL) +#define ERR_R_FATAL (ERR_RFLAG_FATAL | ERR_RFLAG_COMMON) +#define ERR_R_MALLOC_FAILURE (256 | ERR_R_FATAL) +#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (257 | ERR_R_FATAL) +#define ERR_R_PASSED_NULL_PARAMETER (258 | ERR_R_FATAL) +#define ERR_R_INTERNAL_ERROR (259 | ERR_R_FATAL) +#define ERR_R_DISABLED (260 | ERR_R_FATAL) +#define ERR_R_INIT_FAIL (261 | ERR_R_FATAL) +#define ERR_R_PASSED_INVALID_ARGUMENT (262 | ERR_RFLAG_COMMON) +#define ERR_R_OPERATION_FAIL (263 | ERR_R_FATAL) +#define ERR_R_INVALID_PROVIDER_FUNCTIONS (264 | ERR_R_FATAL) +#define ERR_R_INTERRUPTED_OR_CANCELLED (265 | ERR_RFLAG_COMMON) +#define ERR_R_NESTED_ASN1_ERROR (266 | ERR_RFLAG_COMMON) +#define ERR_R_MISSING_ASN1_EOS (267 | ERR_RFLAG_COMMON) +#define ERR_R_UNSUPPORTED (268 | ERR_RFLAG_COMMON) +#define ERR_R_FETCH_FAILED (269 | ERR_RFLAG_COMMON) +#define ERR_R_INVALID_PROPERTY_DEFINITION (270 | ERR_RFLAG_COMMON) +#define ERR_R_UNABLE_TO_GET_READ_LOCK (271 | ERR_R_FATAL) +#define ERR_R_UNABLE_TO_GET_WRITE_LOCK (272 | ERR_R_FATAL) typedef struct ERR_string_data_st { unsigned long error; const char *string; } ERR_STRING_DATA; +/* clang-format off */ DEFINE_LHASH_OF_INTERNAL(ERR_STRING_DATA); #define lh_ERR_STRING_DATA_new(hfn, cmp) ((LHASH_OF(ERR_STRING_DATA) *)OPENSSL_LH_set_thunks(OPENSSL_LH_new(ossl_check_ERR_STRING_DATA_lh_hashfunc_type(hfn), ossl_check_ERR_STRING_DATA_lh_compfunc_type(cmp)), lh_ERR_STRING_DATA_hash_thunk, lh_ERR_STRING_DATA_comp_thunk, lh_ERR_STRING_DATA_doall_thunk, lh_ERR_STRING_DATA_doall_arg_thunk)) #define lh_ERR_STRING_DATA_free(lh) OPENSSL_LH_free(ossl_check_ERR_STRING_DATA_lh_type(lh)) @@ -387,9 +389,10 @@ DEFINE_LHASH_OF_INTERNAL(ERR_STRING_DATA); #define lh_ERR_STRING_DATA_set_down_load(lh, dl) OPENSSL_LH_set_down_load(ossl_check_ERR_STRING_DATA_lh_type(lh), dl) #define lh_ERR_STRING_DATA_doall(lh, dfn) OPENSSL_LH_doall(ossl_check_ERR_STRING_DATA_lh_type(lh), ossl_check_ERR_STRING_DATA_lh_doallfunc_type(dfn)) +/* clang-format on */ /* 12 lines and some on an 80 column terminal */ -#define ERR_MAX_DATA_SIZE 1024 +#define ERR_MAX_DATA_SIZE 1024 /* Building blocks */ void ERR_new(void); @@ -398,73 +401,73 @@ void ERR_set_error(int lib, int reason, const char *fmt, ...); void ERR_vset_error(int lib, int reason, const char *fmt, va_list args); /* Main error raising functions */ -# define ERR_raise(lib, reason) ERR_raise_data((lib),(reason),NULL) -# define ERR_raise_data \ - (ERR_new(), \ - ERR_set_debug(OPENSSL_FILE,OPENSSL_LINE,OPENSSL_FUNC), \ - ERR_set_error) +#define ERR_raise(lib, reason) ERR_raise_data((lib), (reason), NULL) +#define ERR_raise_data \ + (ERR_new(), \ + ERR_set_debug(OPENSSL_FILE, OPENSSL_LINE, OPENSSL_FUNC), \ + ERR_set_error) -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 /* Backward compatibility */ -# define ERR_put_error(lib, func, reason, file, line) \ - (ERR_new(), \ - ERR_set_debug((file), (line), OPENSSL_FUNC), \ - ERR_set_error((lib), (reason), NULL)) -# endif +#define ERR_put_error(lib, func, reason, file, line) \ + (ERR_new(), \ + ERR_set_debug((file), (line), OPENSSL_FUNC), \ + ERR_set_error((lib), (reason), NULL)) +#endif void ERR_set_error_data(char *data, int flags); unsigned long ERR_get_error(void); unsigned long ERR_get_error_all(const char **file, int *line, - const char **func, - const char **data, int *flags); -# ifndef OPENSSL_NO_DEPRECATED_3_0 + const char **func, + const char **data, int *flags); +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 unsigned long ERR_get_error_line(const char **file, int *line); OSSL_DEPRECATEDIN_3_0 unsigned long ERR_get_error_line_data(const char **file, int *line, - const char **data, int *flags); + const char **data, int *flags); #endif unsigned long ERR_peek_error(void); unsigned long ERR_peek_error_line(const char **file, int *line); unsigned long ERR_peek_error_func(const char **func); unsigned long ERR_peek_error_data(const char **data, int *flags); unsigned long ERR_peek_error_all(const char **file, int *line, - const char **func, - const char **data, int *flags); -# ifndef OPENSSL_NO_DEPRECATED_3_0 + const char **func, + const char **data, int *flags); +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 unsigned long ERR_peek_error_line_data(const char **file, int *line, - const char **data, int *flags); -# endif + const char **data, int *flags); +#endif unsigned long ERR_peek_last_error(void); unsigned long ERR_peek_last_error_line(const char **file, int *line); unsigned long ERR_peek_last_error_func(const char **func); unsigned long ERR_peek_last_error_data(const char **data, int *flags); unsigned long ERR_peek_last_error_all(const char **file, int *line, - const char **func, - const char **data, int *flags); -# ifndef OPENSSL_NO_DEPRECATED_3_0 + const char **func, + const char **data, int *flags); +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 unsigned long ERR_peek_last_error_line_data(const char **file, int *line, - const char **data, int *flags); -# endif + const char **data, int *flags); +#endif void ERR_clear_error(void); char *ERR_error_string(unsigned long e, char *buf); void ERR_error_string_n(unsigned long e, char *buf, size_t len); const char *ERR_lib_error_string(unsigned long e); -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 const char *ERR_func_error_string(unsigned long e); -# endif +#endif const char *ERR_reason_error_string(unsigned long e); -void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), - void *u); -# ifndef OPENSSL_NO_STDIO +void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), + void *u); +#ifndef OPENSSL_NO_STDIO void ERR_print_errors_fp(FILE *fp); -# endif +#endif void ERR_print_errors(BIO *bp); void ERR_add_error_data(int num, ...); @@ -477,9 +480,11 @@ int ERR_load_strings_const(const ERR_STRING_DATA *str); int ERR_unload_strings(int lib, ERR_STRING_DATA *str); #ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define ERR_load_crypto_strings() \ +#define ERR_load_crypto_strings() \ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL) -# define ERR_free_strings() while(0) continue +#define ERR_free_strings() \ + while (0) \ + continue #endif #ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 void ERR_remove_thread_state(void *); @@ -505,7 +510,7 @@ void OSSL_ERR_STATE_save_to_mark(ERR_STATE *es); void OSSL_ERR_STATE_restore(const ERR_STATE *es); void OSSL_ERR_STATE_free(ERR_STATE *es); -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ess.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ess.h index 573f55c8a4..d3ffed0a65 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ess.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ess.h @@ -10,27 +10,29 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_ESS_H -# define OPENSSL_ESS_H -# pragma once +#define OPENSSL_ESS_H +#pragma once -# include +#include -# include -# include -# include +#include +#include +#include -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif - +#endif typedef struct ESS_issuer_serial ESS_ISSUER_SERIAL; typedef struct ESS_cert_id ESS_CERT_ID; typedef struct ESS_signing_cert ESS_SIGNING_CERT; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ESS_CERT_ID, ESS_CERT_ID, ESS_CERT_ID) #define sk_ESS_CERT_ID_num(sk) OPENSSL_sk_num(ossl_check_const_ESS_CERT_ID_sk_type(sk)) #define sk_ESS_CERT_ID_value(sk, idx) ((ESS_CERT_ID *)OPENSSL_sk_value(ossl_check_const_ESS_CERT_ID_sk_type(sk), (idx))) @@ -58,11 +60,12 @@ SKM_DEFINE_STACK_OF_INTERNAL(ESS_CERT_ID, ESS_CERT_ID, ESS_CERT_ID) #define sk_ESS_CERT_ID_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ESS_CERT_ID) *)OPENSSL_sk_deep_copy(ossl_check_const_ESS_CERT_ID_sk_type(sk), ossl_check_ESS_CERT_ID_copyfunc_type(copyfunc), ossl_check_ESS_CERT_ID_freefunc_type(freefunc))) #define sk_ESS_CERT_ID_set_cmp_func(sk, cmp) ((sk_ESS_CERT_ID_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ESS_CERT_ID_sk_type(sk), ossl_check_ESS_CERT_ID_compfunc_type(cmp))) - +/* clang-format on */ typedef struct ESS_signing_cert_v2_st ESS_SIGNING_CERT_V2; typedef struct ESS_cert_id_v2_st ESS_CERT_ID_V2; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ESS_CERT_ID_V2, ESS_CERT_ID_V2, ESS_CERT_ID_V2) #define sk_ESS_CERT_ID_V2_num(sk) OPENSSL_sk_num(ossl_check_const_ESS_CERT_ID_V2_sk_type(sk)) #define sk_ESS_CERT_ID_V2_value(sk, idx) ((ESS_CERT_ID_V2 *)OPENSSL_sk_value(ossl_check_const_ESS_CERT_ID_V2_sk_type(sk), (idx))) @@ -90,6 +93,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(ESS_CERT_ID_V2, ESS_CERT_ID_V2, ESS_CERT_ID_V2) #define sk_ESS_CERT_ID_V2_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ESS_CERT_ID_V2) *)OPENSSL_sk_deep_copy(ossl_check_const_ESS_CERT_ID_V2_sk_type(sk), ossl_check_ESS_CERT_ID_V2_copyfunc_type(copyfunc), ossl_check_ESS_CERT_ID_V2_freefunc_type(freefunc))) #define sk_ESS_CERT_ID_V2_set_cmp_func(sk, cmp) ((sk_ESS_CERT_ID_V2_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ESS_CERT_ID_V2_sk_type(sk), ossl_check_ESS_CERT_ID_V2_compfunc_type(cmp))) +/* clang-format on */ DECLARE_ASN1_ALLOC_FUNCTIONS(ESS_ISSUER_SERIAL) DECLARE_ASN1_ENCODE_FUNCTIONS_only(ESS_ISSUER_SERIAL, ESS_ISSUER_SERIAL) @@ -110,19 +114,18 @@ DECLARE_ASN1_FUNCTIONS(ESS_SIGNING_CERT_V2) DECLARE_ASN1_DUP_FUNCTION(ESS_SIGNING_CERT_V2) ESS_SIGNING_CERT *OSSL_ESS_signing_cert_new_init(const X509 *signcert, - const STACK_OF(X509) *certs, - int set_issuer_serial); + const STACK_OF(X509) *certs, + int set_issuer_serial); ESS_SIGNING_CERT_V2 *OSSL_ESS_signing_cert_v2_new_init(const EVP_MD *hash_alg, - const X509 *signcert, - const - STACK_OF(X509) *certs, - int set_issuer_serial); + const X509 *signcert, + const STACK_OF(X509) *certs, + int set_issuer_serial); int OSSL_ESS_check_signing_certs(const ESS_SIGNING_CERT *ss, - const ESS_SIGNING_CERT_V2 *ssv2, - const STACK_OF(X509) *chain, - int require_signing_cert); + const ESS_SIGNING_CERT_V2 *ssv2, + const STACK_OF(X509) *chain, + int require_signing_cert); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/fipskey.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/fipskey.h index 80ce3fc462..6dca6ba729 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/fipskey.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/fipskey.h @@ -11,31 +11,37 @@ */ #ifndef OPENSSL_FIPSKEY_H -# define OPENSSL_FIPSKEY_H -# pragma once +#define OPENSSL_FIPSKEY_H +#pragma once -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif /* * The FIPS validation HMAC key, usable as an array initializer. */ +/* clang-format off */ #define FIPS_KEY_ELEMENTS \ 0xf4, 0x55, 0x66, 0x50, 0xac, 0x31, 0xd3, 0x54, 0x61, 0x61, 0x0b, 0xac, 0x4e, 0xd8, 0x1b, 0x1a, 0x18, 0x1b, 0x2d, 0x8a, 0x43, 0xea, 0x28, 0x54, 0xcb, 0xae, 0x22, 0xca, 0x74, 0x56, 0x08, 0x13 +/* clang-format on */ /* * The FIPS validation key, as a string. */ +/* clang-format off */ #define FIPS_KEY_STRING "f4556650ac31d35461610bac4ed81b1a181b2d8a43ea2854cbae22ca74560813" +/* clang-format on */ /* * The FIPS provider vendor name, as a string. */ +/* clang-format off */ #define FIPS_VENDOR "OpenSSL non-compliant FIPS Provider" +/* clang-format on */ -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/lhash.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/lhash.h index 93044eec70..c481f74d96 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/lhash.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/lhash.h @@ -7,40 +7,42 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ /* * Header for dynamic hash table routines Author - Eric Young */ #ifndef OPENSSL_LHASH_H -# define OPENSSL_LHASH_H -# pragma once +#define OPENSSL_LHASH_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_LHASH_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_LHASH_H +#endif -# include -# include -# ifndef OPENSSL_NO_STDIO -# include -# endif +#include +#include +#ifndef OPENSSL_NO_STDIO +#include +#endif -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif typedef struct lhash_node_st OPENSSL_LH_NODE; -typedef int (*OPENSSL_LH_COMPFUNC) (const void *, const void *); -typedef int (*OPENSSL_LH_COMPFUNCTHUNK) (const void *, const void *, OPENSSL_LH_COMPFUNC cfn); -typedef unsigned long (*OPENSSL_LH_HASHFUNC) (const void *); -typedef unsigned long (*OPENSSL_LH_HASHFUNCTHUNK) (const void *, OPENSSL_LH_HASHFUNC hfn); -typedef void (*OPENSSL_LH_DOALL_FUNC) (void *); -typedef void (*OPENSSL_LH_DOALL_FUNC_THUNK) (void *, OPENSSL_LH_DOALL_FUNC doall); -typedef void (*OPENSSL_LH_DOALL_FUNCARG) (void *, void *); -typedef void (*OPENSSL_LH_DOALL_FUNCARG_THUNK) (void *, void *, OPENSSL_LH_DOALL_FUNCARG doall); +typedef int (*OPENSSL_LH_COMPFUNC)(const void *, const void *); +typedef int (*OPENSSL_LH_COMPFUNCTHUNK)(const void *, const void *, OPENSSL_LH_COMPFUNC cfn); +typedef unsigned long (*OPENSSL_LH_HASHFUNC)(const void *); +typedef unsigned long (*OPENSSL_LH_HASHFUNCTHUNK)(const void *, OPENSSL_LH_HASHFUNC hfn); +typedef void (*OPENSSL_LH_DOALL_FUNC)(void *); +typedef void (*OPENSSL_LH_DOALL_FUNC_THUNK)(void *, OPENSSL_LH_DOALL_FUNC doall); +typedef void (*OPENSSL_LH_DOALL_FUNCARG)(void *, void *); +typedef void (*OPENSSL_LH_DOALL_FUNCARG_THUNK)(void *, void *, OPENSSL_LH_DOALL_FUNCARG doall); typedef struct lhash_st OPENSSL_LHASH; /* @@ -53,44 +55,49 @@ typedef struct lhash_st OPENSSL_LHASH; */ /* First: "hash" functions */ -# define DECLARE_LHASH_HASH_FN(name, o_type) \ - unsigned long name##_LHASH_HASH(const void *); -# define IMPLEMENT_LHASH_HASH_FN(name, o_type) \ - unsigned long name##_LHASH_HASH(const void *arg) { \ - const o_type *a = arg; \ - return name##_hash(a); } -# define LHASH_HASH_FN(name) name##_LHASH_HASH +#define DECLARE_LHASH_HASH_FN(name, o_type) \ + unsigned long name##_LHASH_HASH(const void *); +#define IMPLEMENT_LHASH_HASH_FN(name, o_type) \ + unsigned long name##_LHASH_HASH(const void *arg) \ + { \ + const o_type *a = arg; \ + return name##_hash(a); \ + } +#define LHASH_HASH_FN(name) name##_LHASH_HASH /* Second: "compare" functions */ -# define DECLARE_LHASH_COMP_FN(name, o_type) \ - int name##_LHASH_COMP(const void *, const void *); -# define IMPLEMENT_LHASH_COMP_FN(name, o_type) \ - int name##_LHASH_COMP(const void *arg1, const void *arg2) { \ - const o_type *a = arg1; \ - const o_type *b = arg2; \ - return name##_cmp(a,b); } -# define LHASH_COMP_FN(name) name##_LHASH_COMP +#define DECLARE_LHASH_COMP_FN(name, o_type) \ + int name##_LHASH_COMP(const void *, const void *); +#define IMPLEMENT_LHASH_COMP_FN(name, o_type) \ + int name##_LHASH_COMP(const void *arg1, const void *arg2) \ + { \ + const o_type *a = arg1; \ + const o_type *b = arg2; \ + return name##_cmp(a, b); \ + } +#define LHASH_COMP_FN(name) name##_LHASH_COMP /* Fourth: "doall_arg" functions */ -# define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ - void name##_LHASH_DOALL_ARG(void *, void *); -# define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ - void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \ - o_type *a = arg1; \ - a_type *b = arg2; \ - name##_doall_arg(a, b); } -# define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG +#define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ + void name##_LHASH_DOALL_ARG(void *, void *); +#define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ + void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) \ + { \ + o_type *a = arg1; \ + a_type *b = arg2; \ + name##_doall_arg(a, b); \ + } +#define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG - -# define LH_LOAD_MULT 256 +#define LH_LOAD_MULT 256 int OPENSSL_LH_error(OPENSSL_LHASH *lh); OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c); OPENSSL_LHASH *OPENSSL_LH_set_thunks(OPENSSL_LHASH *lh, - OPENSSL_LH_HASHFUNCTHUNK hw, - OPENSSL_LH_COMPFUNCTHUNK cw, - OPENSSL_LH_DOALL_FUNC_THUNK daw, - OPENSSL_LH_DOALL_FUNCARG_THUNK daaw); + OPENSSL_LH_HASHFUNCTHUNK hw, + OPENSSL_LH_COMPFUNCTHUNK cw, + OPENSSL_LH_DOALL_FUNC_THUNK daw, + OPENSSL_LH_DOALL_FUNCARG_THUNK daaw); void OPENSSL_LH_free(OPENSSL_LHASH *lh); void OPENSSL_LH_flush(OPENSSL_LHASH *lh); void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data); @@ -98,239 +105,249 @@ void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data); void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data); void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func); void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, - OPENSSL_LH_DOALL_FUNCARG func, void *arg); + OPENSSL_LH_DOALL_FUNCARG func, void *arg); void OPENSSL_LH_doall_arg_thunk(OPENSSL_LHASH *lh, - OPENSSL_LH_DOALL_FUNCARG_THUNK daaw, - OPENSSL_LH_DOALL_FUNCARG fn, void *arg); + OPENSSL_LH_DOALL_FUNCARG_THUNK daaw, + OPENSSL_LH_DOALL_FUNCARG fn, void *arg); unsigned long OPENSSL_LH_strhash(const char *c); unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh); unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh); void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load); -# ifndef OPENSSL_NO_STDIO -# ifndef OPENSSL_NO_DEPRECATED_3_1 +#ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_DEPRECATED_3_1 OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp); OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp); OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp); -# endif -# endif -# ifndef OPENSSL_NO_DEPRECATED_3_1 +#endif +#endif +#ifndef OPENSSL_NO_DEPRECATED_3_1 OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out); OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out); OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out); -# endif +#endif -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define _LHASH OPENSSL_LHASH -# define LHASH_NODE OPENSSL_LH_NODE -# define lh_error OPENSSL_LH_error -# define lh_new OPENSSL_LH_new -# define lh_free OPENSSL_LH_free -# define lh_insert OPENSSL_LH_insert -# define lh_delete OPENSSL_LH_delete -# define lh_retrieve OPENSSL_LH_retrieve -# define lh_doall OPENSSL_LH_doall -# define lh_doall_arg OPENSSL_LH_doall_arg -# define lh_strhash OPENSSL_LH_strhash -# define lh_num_items OPENSSL_LH_num_items -# ifndef OPENSSL_NO_STDIO -# define lh_stats OPENSSL_LH_stats -# define lh_node_stats OPENSSL_LH_node_stats -# define lh_node_usage_stats OPENSSL_LH_node_usage_stats -# endif -# define lh_stats_bio OPENSSL_LH_stats_bio -# define lh_node_stats_bio OPENSSL_LH_node_stats_bio -# define lh_node_usage_stats_bio OPENSSL_LH_node_usage_stats_bio -# endif +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define _LHASH OPENSSL_LHASH +#define LHASH_NODE OPENSSL_LH_NODE +#define lh_error OPENSSL_LH_error +#define lh_new OPENSSL_LH_new +#define lh_free OPENSSL_LH_free +#define lh_insert OPENSSL_LH_insert +#define lh_delete OPENSSL_LH_delete +#define lh_retrieve OPENSSL_LH_retrieve +#define lh_doall OPENSSL_LH_doall +#define lh_doall_arg OPENSSL_LH_doall_arg +#define lh_strhash OPENSSL_LH_strhash +#define lh_num_items OPENSSL_LH_num_items +#ifndef OPENSSL_NO_STDIO +#define lh_stats OPENSSL_LH_stats +#define lh_node_stats OPENSSL_LH_node_stats +#define lh_node_usage_stats OPENSSL_LH_node_usage_stats +#endif +#define lh_stats_bio OPENSSL_LH_stats_bio +#define lh_node_stats_bio OPENSSL_LH_node_stats_bio +#define lh_node_usage_stats_bio OPENSSL_LH_node_usage_stats_bio +#endif /* Type checking... */ -# define LHASH_OF(type) struct lhash_st_##type +#define LHASH_OF(type) struct lhash_st_##type /* Helper macro for internal use */ -# define DEFINE_LHASH_OF_INTERNAL(type) \ - LHASH_OF(type) { \ - union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; \ - }; \ - typedef int (*lh_##type##_compfunc)(const type *a, const type *b); \ - typedef unsigned long (*lh_##type##_hashfunc)(const type *a); \ - typedef void (*lh_##type##_doallfunc)(type *a); \ - static ossl_inline unsigned long lh_##type##_hash_thunk(const void *data, OPENSSL_LH_HASHFUNC hfn) \ - { \ - unsigned long (*hfn_conv)(const type *) = (unsigned long (*)(const type *))hfn; \ - return hfn_conv((const type *)data); \ - } \ - static ossl_inline int lh_##type##_comp_thunk(const void *da, const void *db, OPENSSL_LH_COMPFUNC cfn) \ - { \ - int (*cfn_conv)(const type *, const type *) = (int (*)(const type *, const type *))cfn; \ - return cfn_conv((const type *)da, (const type *)db); \ - } \ - static ossl_inline void lh_##type##_doall_thunk(void *node, OPENSSL_LH_DOALL_FUNC doall) \ - { \ - void (*doall_conv)(type *) = (void (*)(type *))doall; \ - doall_conv((type *)node); \ - } \ +#define DEFINE_LHASH_OF_INTERNAL(type) \ + LHASH_OF(type) \ + { \ + union lh_##type##_dummy { \ + void *d1; \ + unsigned long d2; \ + int d3; \ + } dummy; \ + }; \ + typedef int (*lh_##type##_compfunc)(const type *a, const type *b); \ + typedef unsigned long (*lh_##type##_hashfunc)(const type *a); \ + typedef void (*lh_##type##_doallfunc)(type * a); \ + static ossl_inline unsigned long lh_##type##_hash_thunk(const void *data, OPENSSL_LH_HASHFUNC hfn) \ + { \ + unsigned long (*hfn_conv)(const type *) = (unsigned long (*)(const type *))hfn; \ + return hfn_conv((const type *)data); \ + } \ + static ossl_inline int lh_##type##_comp_thunk(const void *da, const void *db, OPENSSL_LH_COMPFUNC cfn) \ + { \ + int (*cfn_conv)(const type *, const type *) = (int (*)(const type *, const type *))cfn; \ + return cfn_conv((const type *)da, (const type *)db); \ + } \ + static ossl_inline void lh_##type##_doall_thunk(void *node, OPENSSL_LH_DOALL_FUNC doall) \ + { \ + void (*doall_conv)(type *) = (void (*)(type *))doall; \ + doall_conv((type *)node); \ + } \ static ossl_inline void lh_##type##_doall_arg_thunk(void *node, void *arg, OPENSSL_LH_DOALL_FUNCARG doall) \ - { \ - void (*doall_conv)(type *, void *) = (void (*)(type *, void *))doall; \ - doall_conv((type *)node, arg); \ - } \ - static ossl_unused ossl_inline type *\ - ossl_check_##type##_lh_plain_type(type *ptr) \ - { \ - return ptr; \ - } \ - static ossl_unused ossl_inline const type * \ - ossl_check_const_##type##_lh_plain_type(const type *ptr) \ - { \ - return ptr; \ - } \ - static ossl_unused ossl_inline const OPENSSL_LHASH * \ - ossl_check_const_##type##_lh_type(const LHASH_OF(type) *lh) \ - { \ - return (const OPENSSL_LHASH *)lh; \ - } \ - static ossl_unused ossl_inline OPENSSL_LHASH * \ - ossl_check_##type##_lh_type(LHASH_OF(type) *lh) \ - { \ - return (OPENSSL_LHASH *)lh; \ - } \ - static ossl_unused ossl_inline OPENSSL_LH_COMPFUNC \ - ossl_check_##type##_lh_compfunc_type(lh_##type##_compfunc cmp) \ - { \ - return (OPENSSL_LH_COMPFUNC)cmp; \ - } \ - static ossl_unused ossl_inline OPENSSL_LH_HASHFUNC \ - ossl_check_##type##_lh_hashfunc_type(lh_##type##_hashfunc hfn) \ - { \ - return (OPENSSL_LH_HASHFUNC)hfn; \ - } \ - static ossl_unused ossl_inline OPENSSL_LH_DOALL_FUNC \ - ossl_check_##type##_lh_doallfunc_type(lh_##type##_doallfunc dfn) \ - { \ - return (OPENSSL_LH_DOALL_FUNC)dfn; \ - } \ + { \ + void (*doall_conv)(type *, void *) = (void (*)(type *, void *))doall; \ + doall_conv((type *)node, arg); \ + } \ + static ossl_unused ossl_inline type * \ + ossl_check_##type##_lh_plain_type(type *ptr) \ + { \ + return ptr; \ + } \ + static ossl_unused ossl_inline const type * \ + ossl_check_const_##type##_lh_plain_type(const type *ptr) \ + { \ + return ptr; \ + } \ + static ossl_unused ossl_inline const OPENSSL_LHASH * \ + ossl_check_const_##type##_lh_type(const LHASH_OF(type) *lh) \ + { \ + return (const OPENSSL_LHASH *)lh; \ + } \ + static ossl_unused ossl_inline OPENSSL_LHASH * \ + ossl_check_##type##_lh_type(LHASH_OF(type) *lh) \ + { \ + return (OPENSSL_LHASH *)lh; \ + } \ + static ossl_unused ossl_inline OPENSSL_LH_COMPFUNC \ + ossl_check_##type##_lh_compfunc_type(lh_##type##_compfunc cmp) \ + { \ + return (OPENSSL_LH_COMPFUNC)cmp; \ + } \ + static ossl_unused ossl_inline OPENSSL_LH_HASHFUNC \ + ossl_check_##type##_lh_hashfunc_type(lh_##type##_hashfunc hfn) \ + { \ + return (OPENSSL_LH_HASHFUNC)hfn; \ + } \ + static ossl_unused ossl_inline OPENSSL_LH_DOALL_FUNC \ + ossl_check_##type##_lh_doallfunc_type(lh_##type##_doallfunc dfn) \ + { \ + return (OPENSSL_LH_DOALL_FUNC)dfn; \ + } \ LHASH_OF(type) -# ifndef OPENSSL_NO_DEPRECATED_3_1 -# define DEFINE_LHASH_OF_DEPRECATED(type) \ - static ossl_unused ossl_inline void \ - lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ - { \ - OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \ - } \ - static ossl_unused ossl_inline void \ +#ifndef OPENSSL_NO_DEPRECATED_3_1 +#define DEFINE_LHASH_OF_DEPRECATED(type) \ + static ossl_unused ossl_inline void \ + lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ + { \ + OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \ + } \ + static ossl_unused ossl_inline void \ lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ - { \ + { \ OPENSSL_LH_node_usage_stats_bio((const OPENSSL_LHASH *)lh, out); \ - } \ - static ossl_unused ossl_inline void \ - lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ - { \ - OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \ + } \ + static ossl_unused ossl_inline void \ + lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ + { \ + OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \ } -# else -# define DEFINE_LHASH_OF_DEPRECATED(type) -# endif +#else +#define DEFINE_LHASH_OF_DEPRECATED(type) +#endif -# define DEFINE_LHASH_OF_EX(type) \ - LHASH_OF(type) { \ - union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; \ - }; \ - static unsigned long \ - lh_##type##_hfn_thunk(const void *data, OPENSSL_LH_HASHFUNC hfn) \ - { \ - unsigned long (*hfn_conv)(const type *) = (unsigned long (*)(const type *))hfn; \ - return hfn_conv((const type *)data); \ - } \ - static int lh_##type##_cfn_thunk(const void *da, const void *db, OPENSSL_LH_COMPFUNC cfn) \ - { \ - int (*cfn_conv)(const type *, const type *) = (int (*)(const type *, const type *))cfn; \ - return cfn_conv((const type *)da, (const type *)db); \ - } \ - static ossl_unused ossl_inline void \ - lh_##type##_free(LHASH_OF(type) *lh) \ - { \ - OPENSSL_LH_free((OPENSSL_LHASH *)lh); \ - } \ - static ossl_unused ossl_inline void \ - lh_##type##_flush(LHASH_OF(type) *lh) \ - { \ - OPENSSL_LH_flush((OPENSSL_LHASH *)lh); \ - } \ - static ossl_unused ossl_inline type * \ - lh_##type##_insert(LHASH_OF(type) *lh, type *d) \ - { \ - return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \ - } \ - static ossl_unused ossl_inline type * \ - lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \ - { \ - return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \ - } \ - static ossl_unused ossl_inline type * \ - lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \ - { \ - return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \ - } \ - static ossl_unused ossl_inline int \ - lh_##type##_error(LHASH_OF(type) *lh) \ - { \ - return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \ - } \ - static ossl_unused ossl_inline unsigned long \ - lh_##type##_num_items(LHASH_OF(type) *lh) \ - { \ - return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \ - } \ - static ossl_unused ossl_inline unsigned long \ - lh_##type##_get_down_load(LHASH_OF(type) *lh) \ - { \ - return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \ - } \ - static ossl_unused ossl_inline void \ - lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \ - { \ - OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \ - } \ - static ossl_unused ossl_inline void \ - lh_##type##_doall_thunk(void *node, OPENSSL_LH_DOALL_FUNC doall) \ - { \ - void (*doall_conv)(type *) = (void (*)(type *))doall; \ - doall_conv((type *)node); \ - } \ - static ossl_unused ossl_inline void \ - lh_##type##_doall_arg_thunk(void *node, void *arg, OPENSSL_LH_DOALL_FUNCARG doall) \ - { \ - void (*doall_conv)(type *, void *) = (void (*)(type *, void *))doall; \ - doall_conv((type *)node, arg); \ - } \ - static ossl_unused ossl_inline void \ - lh_##type##_doall(LHASH_OF(type) *lh, void (*doall)(type *)) \ - { \ - OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \ - } \ - static ossl_unused ossl_inline LHASH_OF(type) * \ - lh_##type##_new(unsigned long (*hfn)(const type *), \ - int (*cfn)(const type *, const type *)) \ - { \ +#define DEFINE_LHASH_OF_EX(type) \ + LHASH_OF(type) \ + { \ + union lh_##type##_dummy { \ + void *d1; \ + unsigned long d2; \ + int d3; \ + } dummy; \ + }; \ + static unsigned long \ + lh_##type##_hfn_thunk(const void *data, OPENSSL_LH_HASHFUNC hfn) \ + { \ + unsigned long (*hfn_conv)(const type *) = (unsigned long (*)(const type *))hfn; \ + return hfn_conv((const type *)data); \ + } \ + static int lh_##type##_cfn_thunk(const void *da, const void *db, OPENSSL_LH_COMPFUNC cfn) \ + { \ + int (*cfn_conv)(const type *, const type *) = (int (*)(const type *, const type *))cfn; \ + return cfn_conv((const type *)da, (const type *)db); \ + } \ + static ossl_unused ossl_inline void \ + lh_##type##_free(LHASH_OF(type) *lh) \ + { \ + OPENSSL_LH_free((OPENSSL_LHASH *)lh); \ + } \ + static ossl_unused ossl_inline void \ + lh_##type##_flush(LHASH_OF(type) *lh) \ + { \ + OPENSSL_LH_flush((OPENSSL_LHASH *)lh); \ + } \ + static ossl_unused ossl_inline type * \ + lh_##type##_insert(LHASH_OF(type) *lh, type *d) \ + { \ + return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \ + } \ + static ossl_unused ossl_inline type * \ + lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \ + { \ + return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \ + } \ + static ossl_unused ossl_inline type * \ + lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \ + { \ + return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \ + } \ + static ossl_unused ossl_inline int \ + lh_##type##_error(LHASH_OF(type) *lh) \ + { \ + return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \ + } \ + static ossl_unused ossl_inline unsigned long \ + lh_##type##_num_items(LHASH_OF(type) *lh) \ + { \ + return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \ + } \ + static ossl_unused ossl_inline unsigned long \ + lh_##type##_get_down_load(LHASH_OF(type) *lh) \ + { \ + return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \ + } \ + static ossl_unused ossl_inline void \ + lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \ + { \ + OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \ + } \ + static ossl_unused ossl_inline void \ + lh_##type##_doall_thunk(void *node, OPENSSL_LH_DOALL_FUNC doall) \ + { \ + void (*doall_conv)(type *) = (void (*)(type *))doall; \ + doall_conv((type *)node); \ + } \ + static ossl_unused ossl_inline void \ + lh_##type##_doall_arg_thunk(void *node, void *arg, OPENSSL_LH_DOALL_FUNCARG doall) \ + { \ + void (*doall_conv)(type *, void *) = (void (*)(type *, void *))doall; \ + doall_conv((type *)node, arg); \ + } \ + static ossl_unused ossl_inline void \ + lh_##type##_doall(LHASH_OF(type) *lh, void (*doall)(type *)) \ + { \ + OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \ + } \ + static ossl_unused ossl_inline LHASH_OF(type) * \ + lh_##type##_new(unsigned long (*hfn)(const type *), \ + int (*cfn)(const type *, const type *)) \ + { \ return (LHASH_OF(type) *)OPENSSL_LH_set_thunks(OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn), \ - lh_##type##_hfn_thunk, lh_##type##_cfn_thunk, \ - lh_##type##_doall_thunk, \ - lh_##type##_doall_arg_thunk); \ - } \ - static ossl_unused ossl_inline void \ - lh_##type##_doall_arg(LHASH_OF(type) *lh, \ - void (*doallarg)(type *, void *), void *arg) \ - { \ - OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, \ - (OPENSSL_LH_DOALL_FUNCARG)doallarg, arg); \ - } \ + lh_##type##_hfn_thunk, lh_##type##_cfn_thunk, \ + lh_##type##_doall_thunk, \ + lh_##type##_doall_arg_thunk); \ + } \ + static ossl_unused ossl_inline void \ + lh_##type##_doall_arg(LHASH_OF(type) *lh, \ + void (*doallarg)(type *, void *), void *arg) \ + { \ + OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, \ + (OPENSSL_LH_DOALL_FUNCARG)doallarg, arg); \ + } \ LHASH_OF(type) -# define DEFINE_LHASH_OF(type) \ - DEFINE_LHASH_OF_EX(type); \ +#define DEFINE_LHASH_OF(type) \ + DEFINE_LHASH_OF_EX(type); \ DEFINE_LHASH_OF_DEPRECATED(type) \ LHASH_OF(type) @@ -340,25 +357,26 @@ OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH * #define IMPLEMENT_LHASH_DOALL_ARG(type, argtype) \ int_implement_lhash_doall(type, argtype, type) -#define int_implement_lhash_doall(type, argtype, cbargtype) \ - static ossl_unused ossl_inline void \ +#define int_implement_lhash_doall(type, argtype, cbargtype) \ + static ossl_unused ossl_inline void \ lh_##type##_doall_##argtype##_thunk(void *node, void *arg, OPENSSL_LH_DOALL_FUNCARG fn) \ - { \ - void (*fn_conv)(cbargtype *, argtype *) = (void (*)(cbargtype *, argtype *))fn; \ - fn_conv((cbargtype *)node, (argtype *)arg); \ - } \ - static ossl_unused ossl_inline void \ - lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \ - void (*fn)(cbargtype *, argtype *), \ - argtype *arg) \ - { \ - OPENSSL_LH_doall_arg_thunk((OPENSSL_LHASH *)lh, \ - lh_##type##_doall_##argtype##_thunk, \ - (OPENSSL_LH_DOALL_FUNCARG)fn, \ - (void *)arg); \ - } \ + { \ + void (*fn_conv)(cbargtype *, argtype *) = (void (*)(cbargtype *, argtype *))fn; \ + fn_conv((cbargtype *)node, (argtype *)arg); \ + } \ + static ossl_unused ossl_inline void \ + lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \ + void (*fn)(cbargtype *, argtype *), \ + argtype *arg) \ + { \ + OPENSSL_LH_doall_arg_thunk((OPENSSL_LHASH *)lh, \ + lh_##type##_doall_##argtype##_thunk, \ + (OPENSSL_LH_DOALL_FUNCARG)fn, \ + (void *)arg); \ + } \ LHASH_OF(type) +/* clang-format off */ DEFINE_LHASH_OF_INTERNAL(OPENSSL_STRING); #define lh_OPENSSL_STRING_new(hfn, cmp) ((LHASH_OF(OPENSSL_STRING) *)OPENSSL_LH_set_thunks(OPENSSL_LH_new(ossl_check_OPENSSL_STRING_lh_hashfunc_type(hfn), ossl_check_OPENSSL_STRING_lh_compfunc_type(cmp)), lh_OPENSSL_STRING_hash_thunk, lh_OPENSSL_STRING_comp_thunk, lh_OPENSSL_STRING_doall_thunk, lh_OPENSSL_STRING_doall_arg_thunk)) #define lh_OPENSSL_STRING_free(lh) OPENSSL_LH_free(ossl_check_OPENSSL_STRING_lh_type(lh)) @@ -390,8 +408,9 @@ DEFINE_LHASH_OF_INTERNAL(OPENSSL_CSTRING); #define lh_OPENSSL_CSTRING_set_down_load(lh, dl) OPENSSL_LH_set_down_load(ossl_check_OPENSSL_CSTRING_lh_type(lh), dl) #define lh_OPENSSL_CSTRING_doall(lh, dfn) OPENSSL_LH_doall(ossl_check_OPENSSL_CSTRING_lh_type(lh), ossl_check_OPENSSL_CSTRING_lh_doallfunc_type(dfn)) +/* clang-format on */ -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ocsp.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ocsp.h index b92848ec20..2b68386bd7 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ocsp.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ocsp.h @@ -10,20 +10,22 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_OCSP_H -# define OPENSSL_OCSP_H -# pragma once +#define OPENSSL_OCSP_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_OCSP_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_OCSP_H +#endif -# include -# include -# include +#include +#include +#include /* * These definitions are outside the OPENSSL_NO_OCSP guard because although for @@ -44,47 +46,46 @@ * privilegeWithdrawn (9), * aACompromise (10) } */ -# define OCSP_REVOKED_STATUS_NOSTATUS -1 -# define OCSP_REVOKED_STATUS_UNSPECIFIED 0 -# define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1 -# define OCSP_REVOKED_STATUS_CACOMPROMISE 2 -# define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3 -# define OCSP_REVOKED_STATUS_SUPERSEDED 4 -# define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5 -# define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6 -# define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8 -# define OCSP_REVOKED_STATUS_PRIVILEGEWITHDRAWN 9 -# define OCSP_REVOKED_STATUS_AACOMPROMISE 10 +#define OCSP_REVOKED_STATUS_NOSTATUS -1 +#define OCSP_REVOKED_STATUS_UNSPECIFIED 0 +#define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1 +#define OCSP_REVOKED_STATUS_CACOMPROMISE 2 +#define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3 +#define OCSP_REVOKED_STATUS_SUPERSEDED 4 +#define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5 +#define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6 +#define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8 +#define OCSP_REVOKED_STATUS_PRIVILEGEWITHDRAWN 9 +#define OCSP_REVOKED_STATUS_AACOMPROMISE 10 +#ifndef OPENSSL_NO_OCSP -# ifndef OPENSSL_NO_OCSP +#include +#include +#include +#include -# include -# include -# include -# include - -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif /* Various flags and values */ -# define OCSP_DEFAULT_NONCE_LENGTH 16 +#define OCSP_DEFAULT_NONCE_LENGTH 16 -# define OCSP_NOCERTS 0x1 -# define OCSP_NOINTERN 0x2 -# define OCSP_NOSIGS 0x4 -# define OCSP_NOCHAIN 0x8 -# define OCSP_NOVERIFY 0x10 -# define OCSP_NOEXPLICIT 0x20 -# define OCSP_NOCASIGN 0x40 -# define OCSP_NODELEGATED 0x80 -# define OCSP_NOCHECKS 0x100 -# define OCSP_TRUSTOTHER 0x200 -# define OCSP_RESPID_KEY 0x400 -# define OCSP_NOTIME 0x800 -# define OCSP_PARTIAL_CHAIN 0x1000 +#define OCSP_NOCERTS 0x1 +#define OCSP_NOINTERN 0x2 +#define OCSP_NOSIGS 0x4 +#define OCSP_NOCHAIN 0x8 +#define OCSP_NOVERIFY 0x10 +#define OCSP_NOEXPLICIT 0x20 +#define OCSP_NOCASIGN 0x40 +#define OCSP_NODELEGATED 0x80 +#define OCSP_NOCHECKS 0x100 +#define OCSP_TRUSTOTHER 0x200 +#define OCSP_RESPID_KEY 0x400 +#define OCSP_NOTIME 0x800 +#define OCSP_PARTIAL_CHAIN 0x1000 typedef struct ocsp_cert_id_st OCSP_CERTID; typedef struct ocsp_one_request_st OCSP_ONEREQ; @@ -92,6 +93,7 @@ typedef struct ocsp_req_info_st OCSP_REQINFO; typedef struct ocsp_signature_st OCSP_SIGNATURE; typedef struct ocsp_request_st OCSP_REQUEST; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OCSP_CERTID, OCSP_CERTID, OCSP_CERTID) #define sk_OCSP_CERTID_num(sk) OPENSSL_sk_num(ossl_check_const_OCSP_CERTID_sk_type(sk)) #define sk_OCSP_CERTID_value(sk, idx) ((OCSP_CERTID *)OPENSSL_sk_value(ossl_check_const_OCSP_CERTID_sk_type(sk), (idx))) @@ -145,19 +147,21 @@ SKM_DEFINE_STACK_OF_INTERNAL(OCSP_ONEREQ, OCSP_ONEREQ, OCSP_ONEREQ) #define sk_OCSP_ONEREQ_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OCSP_ONEREQ) *)OPENSSL_sk_deep_copy(ossl_check_const_OCSP_ONEREQ_sk_type(sk), ossl_check_OCSP_ONEREQ_copyfunc_type(copyfunc), ossl_check_OCSP_ONEREQ_freefunc_type(freefunc))) #define sk_OCSP_ONEREQ_set_cmp_func(sk, cmp) ((sk_OCSP_ONEREQ_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OCSP_ONEREQ_sk_type(sk), ossl_check_OCSP_ONEREQ_compfunc_type(cmp))) +/* clang-format on */ -# define OCSP_RESPONSE_STATUS_SUCCESSFUL 0 -# define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1 -# define OCSP_RESPONSE_STATUS_INTERNALERROR 2 -# define OCSP_RESPONSE_STATUS_TRYLATER 3 -# define OCSP_RESPONSE_STATUS_SIGREQUIRED 5 -# define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6 +#define OCSP_RESPONSE_STATUS_SUCCESSFUL 0 +#define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1 +#define OCSP_RESPONSE_STATUS_INTERNALERROR 2 +#define OCSP_RESPONSE_STATUS_TRYLATER 3 +#define OCSP_RESPONSE_STATUS_SIGREQUIRED 5 +#define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6 typedef struct ocsp_resp_bytes_st OCSP_RESPBYTES; -# define V_OCSP_RESPID_NAME 0 -# define V_OCSP_RESPID_KEY 1 +#define V_OCSP_RESPID_NAME 0 +#define V_OCSP_RESPID_KEY 1 +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OCSP_RESPID, OCSP_RESPID, OCSP_RESPID) #define sk_OCSP_RESPID_num(sk) OPENSSL_sk_num(ossl_check_const_OCSP_RESPID_sk_type(sk)) #define sk_OCSP_RESPID_value(sk, idx) ((OCSP_RESPID *)OPENSSL_sk_value(ossl_check_const_OCSP_RESPID_sk_type(sk), (idx))) @@ -185,16 +189,18 @@ SKM_DEFINE_STACK_OF_INTERNAL(OCSP_RESPID, OCSP_RESPID, OCSP_RESPID) #define sk_OCSP_RESPID_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OCSP_RESPID) *)OPENSSL_sk_deep_copy(ossl_check_const_OCSP_RESPID_sk_type(sk), ossl_check_OCSP_RESPID_copyfunc_type(copyfunc), ossl_check_OCSP_RESPID_freefunc_type(freefunc))) #define sk_OCSP_RESPID_set_cmp_func(sk, cmp) ((sk_OCSP_RESPID_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OCSP_RESPID_sk_type(sk), ossl_check_OCSP_RESPID_compfunc_type(cmp))) +/* clang-format on */ typedef struct ocsp_revoked_info_st OCSP_REVOKEDINFO; -# define V_OCSP_CERTSTATUS_GOOD 0 -# define V_OCSP_CERTSTATUS_REVOKED 1 -# define V_OCSP_CERTSTATUS_UNKNOWN 2 +#define V_OCSP_CERTSTATUS_GOOD 0 +#define V_OCSP_CERTSTATUS_REVOKED 1 +#define V_OCSP_CERTSTATUS_UNKNOWN 2 typedef struct ocsp_cert_status_st OCSP_CERTSTATUS; typedef struct ocsp_single_response_st OCSP_SINGLERESP; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OCSP_SINGLERESP, OCSP_SINGLERESP, OCSP_SINGLERESP) #define sk_OCSP_SINGLERESP_num(sk) OPENSSL_sk_num(ossl_check_const_OCSP_SINGLERESP_sk_type(sk)) #define sk_OCSP_SINGLERESP_value(sk, idx) ((OCSP_SINGLERESP *)OPENSSL_sk_value(ossl_check_const_OCSP_SINGLERESP_sk_type(sk), (idx))) @@ -222,6 +228,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OCSP_SINGLERESP, OCSP_SINGLERESP, OCSP_SINGLERESP) #define sk_OCSP_SINGLERESP_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OCSP_SINGLERESP) *)OPENSSL_sk_deep_copy(ossl_check_const_OCSP_SINGLERESP_sk_type(sk), ossl_check_OCSP_SINGLERESP_copyfunc_type(copyfunc), ossl_check_OCSP_SINGLERESP_freefunc_type(freefunc))) #define sk_OCSP_SINGLERESP_set_cmp_func(sk, cmp) ((sk_OCSP_SINGLERESP_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OCSP_SINGLERESP_sk_type(sk), ossl_check_OCSP_SINGLERESP_compfunc_type(cmp))) +/* clang-format on */ typedef struct ocsp_response_data_st OCSP_RESPDATA; @@ -230,76 +237,74 @@ typedef struct ocsp_basic_response_st OCSP_BASICRESP; typedef struct ocsp_crl_id_st OCSP_CRLID; typedef struct ocsp_service_locator_st OCSP_SERVICELOC; -# define PEM_STRING_OCSP_REQUEST "OCSP REQUEST" -# define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE" +#define PEM_STRING_OCSP_REQUEST "OCSP REQUEST" +#define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE" -# define d2i_OCSP_REQUEST_bio(bp,p) ASN1_d2i_bio_of(OCSP_REQUEST,OCSP_REQUEST_new,d2i_OCSP_REQUEST,bp,p) +#define d2i_OCSP_REQUEST_bio(bp, p) ASN1_d2i_bio_of(OCSP_REQUEST, OCSP_REQUEST_new, d2i_OCSP_REQUEST, bp, p) -# define d2i_OCSP_RESPONSE_bio(bp,p) ASN1_d2i_bio_of(OCSP_RESPONSE,OCSP_RESPONSE_new,d2i_OCSP_RESPONSE,bp,p) +#define d2i_OCSP_RESPONSE_bio(bp, p) ASN1_d2i_bio_of(OCSP_RESPONSE, OCSP_RESPONSE_new, d2i_OCSP_RESPONSE, bp, p) -# define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST, \ - bp,(char **)(x),cb,NULL) +#define PEM_read_bio_OCSP_REQUEST(bp, x, cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \ + (d2i_of_void *)d2i_OCSP_REQUEST, PEM_STRING_OCSP_REQUEST, \ + bp, (char **)(x), cb, NULL) -# define PEM_read_bio_OCSP_RESPONSE(bp,x,cb) (OCSP_RESPONSE *)PEM_ASN1_read_bio(\ - (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE, \ - bp,(char **)(x),cb,NULL) +#define PEM_read_bio_OCSP_RESPONSE(bp, x, cb) (OCSP_RESPONSE *)PEM_ASN1_read_bio( \ + (d2i_of_void *)d2i_OCSP_RESPONSE, PEM_STRING_OCSP_RESPONSE, \ + bp, (char **)(x), cb, NULL) -# define PEM_write_bio_OCSP_REQUEST(bp,o) \ - PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\ - bp,(char *)(o), NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_OCSP_REQUEST(bp, o) \ + PEM_ASN1_write_bio((i2d_of_void *)i2d_OCSP_REQUEST, PEM_STRING_OCSP_REQUEST, \ + bp, (char *)(o), NULL, NULL, 0, NULL, NULL) -# define PEM_write_bio_OCSP_RESPONSE(bp,o) \ - PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\ - bp,(char *)(o), NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_OCSP_RESPONSE(bp, o) \ + PEM_ASN1_write_bio((i2d_of_void *)i2d_OCSP_RESPONSE, PEM_STRING_OCSP_RESPONSE, \ + bp, (char *)(o), NULL, NULL, 0, NULL, NULL) -# define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio_of(OCSP_RESPONSE,i2d_OCSP_RESPONSE,bp,o) +#define i2d_OCSP_RESPONSE_bio(bp, o) ASN1_i2d_bio_of(OCSP_RESPONSE, i2d_OCSP_RESPONSE, bp, o) -# define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio_of(OCSP_REQUEST,i2d_OCSP_REQUEST,bp,o) +#define i2d_OCSP_REQUEST_bio(bp, o) ASN1_i2d_bio_of(OCSP_REQUEST, i2d_OCSP_REQUEST, bp, o) -# define ASN1_BIT_STRING_digest(data,type,md,len) \ - ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len) +#define ASN1_BIT_STRING_digest(data, type, md, len) \ + ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING), type, data, md, len) -# define OCSP_CERTSTATUS_dup(cs)\ - (OCSP_CERTSTATUS*)ASN1_dup((i2d_of_void *)i2d_OCSP_CERTSTATUS,\ - (d2i_of_void *)d2i_OCSP_CERTSTATUS,(char *)(cs)) +#define OCSP_CERTSTATUS_dup(cs) \ + (OCSP_CERTSTATUS *)ASN1_dup((i2d_of_void *)i2d_OCSP_CERTSTATUS, \ + (d2i_of_void *)d2i_OCSP_CERTSTATUS, (char *)(cs)) DECLARE_ASN1_DUP_FUNCTION(OCSP_CERTID) OSSL_HTTP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path, - const OCSP_REQUEST *req, int buf_size); + const OCSP_REQUEST *req, int buf_size); OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req); -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 typedef OSSL_HTTP_REQ_CTX OCSP_REQ_CTX; -# define OCSP_REQ_CTX_new(io, buf_size) \ - OSSL_HTTP_REQ_CTX_new(io, io, buf_size) -# define OCSP_REQ_CTX_free OSSL_HTTP_REQ_CTX_free -# define OCSP_REQ_CTX_http(rctx, op, path) \ - (OSSL_HTTP_REQ_CTX_set_expected(rctx, NULL, 1 /* asn1 */, 0, 0) && \ - OSSL_HTTP_REQ_CTX_set_request_line(rctx, strcmp(op, "POST") == 0, \ - NULL, NULL, path)) -# define OCSP_REQ_CTX_add1_header OSSL_HTTP_REQ_CTX_add1_header -# define OCSP_REQ_CTX_i2d(r, it, req) \ - OSSL_HTTP_REQ_CTX_set1_req(r, "application/ocsp-request", it, req) -# define OCSP_REQ_CTX_set1_req(r, req) \ - OCSP_REQ_CTX_i2d(r, ASN1_ITEM_rptr(OCSP_REQUEST), (ASN1_VALUE *)(req)) -# define OCSP_REQ_CTX_nbio OSSL_HTTP_REQ_CTX_nbio -# define OCSP_REQ_CTX_nbio_d2i OSSL_HTTP_REQ_CTX_nbio_d2i -# define OCSP_sendreq_nbio(p, r) \ - OSSL_HTTP_REQ_CTX_nbio_d2i(r, (ASN1_VALUE **)(p), \ - ASN1_ITEM_rptr(OCSP_RESPONSE)) -# define OCSP_REQ_CTX_get0_mem_bio OSSL_HTTP_REQ_CTX_get0_mem_bio -# define OCSP_set_max_response_length OSSL_HTTP_REQ_CTX_set_max_response_length -# endif +#define OCSP_REQ_CTX_new(io, buf_size) \ + OSSL_HTTP_REQ_CTX_new(io, io, buf_size) +#define OCSP_REQ_CTX_free OSSL_HTTP_REQ_CTX_free +#define OCSP_REQ_CTX_http(rctx, op, path) \ + (OSSL_HTTP_REQ_CTX_set_expected(rctx, NULL, 1 /* asn1 */, 0, 0) && OSSL_HTTP_REQ_CTX_set_request_line(rctx, strcmp(op, "POST") == 0, NULL, NULL, path)) +#define OCSP_REQ_CTX_add1_header OSSL_HTTP_REQ_CTX_add1_header +#define OCSP_REQ_CTX_i2d(r, it, req) \ + OSSL_HTTP_REQ_CTX_set1_req(r, "application/ocsp-request", it, req) +#define OCSP_REQ_CTX_set1_req(r, req) \ + OCSP_REQ_CTX_i2d(r, ASN1_ITEM_rptr(OCSP_REQUEST), (ASN1_VALUE *)(req)) +#define OCSP_REQ_CTX_nbio OSSL_HTTP_REQ_CTX_nbio +#define OCSP_REQ_CTX_nbio_d2i OSSL_HTTP_REQ_CTX_nbio_d2i +#define OCSP_sendreq_nbio(p, r) \ + OSSL_HTTP_REQ_CTX_nbio_d2i(r, (ASN1_VALUE **)(p), \ + ASN1_ITEM_rptr(OCSP_RESPONSE)) +#define OCSP_REQ_CTX_get0_mem_bio OSSL_HTTP_REQ_CTX_get0_mem_bio +#define OCSP_set_max_response_length OSSL_HTTP_REQ_CTX_set_max_response_length +#endif OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, const X509 *subject, - const X509 *issuer); + const X509 *issuer); OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, - const X509_NAME *issuerName, - const ASN1_BIT_STRING *issuerKey, - const ASN1_INTEGER *serialNumber); + const X509_NAME *issuerName, + const ASN1_BIT_STRING *issuerKey, + const ASN1_INTEGER *serialNumber); OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid); @@ -312,10 +317,10 @@ int OCSP_request_set1_name(OCSP_REQUEST *req, const X509_NAME *nm); int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert); int OCSP_request_sign(OCSP_REQUEST *req, - X509 *signer, - EVP_PKEY *key, - const EVP_MD *dgst, - STACK_OF(X509) *certs, unsigned long flags); + X509 *signer, + EVP_PKEY *key, + const EVP_MD *dgst, + STACK_OF(X509) *certs, unsigned long flags); int OCSP_response_status(OCSP_RESPONSE *resp); OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp); @@ -324,36 +329,36 @@ const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *bs); const X509_ALGOR *OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *bs); const OCSP_RESPDATA *OCSP_resp_get0_respdata(const OCSP_BASICRESP *bs); int OCSP_resp_get0_signer(OCSP_BASICRESP *bs, X509 **signer, - STACK_OF(X509) *extra_certs); + STACK_OF(X509) *extra_certs); int OCSP_resp_count(OCSP_BASICRESP *bs); OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx); -const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(const OCSP_BASICRESP* bs); +const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(const OCSP_BASICRESP *bs); const STACK_OF(X509) *OCSP_resp_get0_certs(const OCSP_BASICRESP *bs); int OCSP_resp_get0_id(const OCSP_BASICRESP *bs, - const ASN1_OCTET_STRING **pid, - const X509_NAME **pname); + const ASN1_OCTET_STRING **pid, + const X509_NAME **pname); int OCSP_resp_get1_id(const OCSP_BASICRESP *bs, - ASN1_OCTET_STRING **pid, - X509_NAME **pname); + ASN1_OCTET_STRING **pid, + X509_NAME **pname); int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last); int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason, - ASN1_GENERALIZEDTIME **revtime, - ASN1_GENERALIZEDTIME **thisupd, - ASN1_GENERALIZEDTIME **nextupd); + ASN1_GENERALIZEDTIME **revtime, + ASN1_GENERALIZEDTIME **thisupd, + ASN1_GENERALIZEDTIME **nextupd); int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status, - int *reason, - ASN1_GENERALIZEDTIME **revtime, - ASN1_GENERALIZEDTIME **thisupd, - ASN1_GENERALIZEDTIME **nextupd); + int *reason, + ASN1_GENERALIZEDTIME **revtime, + ASN1_GENERALIZEDTIME **thisupd, + ASN1_GENERALIZEDTIME **nextupd); int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd, - ASN1_GENERALIZEDTIME *nextupd, long sec, long maxsec); + ASN1_GENERALIZEDTIME *nextupd, long sec, long maxsec); int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, - X509_STORE *store, unsigned long flags); + X509_STORE *store, unsigned long flags); -# define OCSP_parse_url(url, host, port, path, ssl) \ +#define OCSP_parse_url(url, host, port, path, ssl) \ OSSL_HTTP_parse_url(url, ssl, NULL, host, port, NULL, path, NULL, NULL) int OCSP_id_issuer_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b); @@ -363,29 +368,29 @@ int OCSP_request_onereq_count(OCSP_REQUEST *req); OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i); OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one); int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd, - ASN1_OCTET_STRING **pikeyHash, - ASN1_INTEGER **pserial, OCSP_CERTID *cid); + ASN1_OCTET_STRING **pikeyHash, + ASN1_INTEGER **pserial, OCSP_CERTID *cid); int OCSP_request_is_signed(OCSP_REQUEST *req); OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs); OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp, - OCSP_CERTID *cid, - int status, int reason, - ASN1_TIME *revtime, - ASN1_TIME *thisupd, - ASN1_TIME *nextupd); + OCSP_CERTID *cid, + int status, int reason, + ASN1_TIME *revtime, + ASN1_TIME *thisupd, + ASN1_TIME *nextupd); int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert); int OCSP_basic_sign(OCSP_BASICRESP *brsp, - X509 *signer, EVP_PKEY *key, const EVP_MD *dgst, - STACK_OF(X509) *certs, unsigned long flags); + X509 *signer, EVP_PKEY *key, const EVP_MD *dgst, + STACK_OF(X509) *certs, unsigned long flags); int OCSP_basic_sign_ctx(OCSP_BASICRESP *brsp, - X509 *signer, EVP_MD_CTX *ctx, - STACK_OF(X509) *certs, unsigned long flags); + X509 *signer, EVP_MD_CTX *ctx, + STACK_OF(X509) *certs, unsigned long flags); int OCSP_RESPID_set_by_name(OCSP_RESPID *respid, X509 *cert); int OCSP_RESPID_set_by_key_ex(OCSP_RESPID *respid, X509 *cert, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); int OCSP_RESPID_set_by_key(OCSP_RESPID *respid, X509 *cert); int OCSP_RESPID_match_ex(OCSP_RESPID *respid, X509 *cert, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); int OCSP_RESPID_match(OCSP_RESPID *respid, X509 *cert); X509_EXTENSION *OCSP_crlID_new(const char *url, long *n, char *tim); @@ -399,14 +404,14 @@ X509_EXTENSION *OCSP_url_svcloc_new(const X509_NAME *issuer, const char **urls); int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x); int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos); int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, const ASN1_OBJECT *obj, - int lastpos); + int lastpos); int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos); X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc); X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc); void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, - int *idx); + int *idx); int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit, - unsigned long flags); + unsigned long flags); int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc); int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x); @@ -417,35 +422,35 @@ X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc); X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc); void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx); int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit, - unsigned long flags); + unsigned long flags); int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc); int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x); int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos); int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, const ASN1_OBJECT *obj, - int lastpos); + int lastpos); int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, - int lastpos); + int lastpos); X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc); X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc); void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, - int *idx); + int *idx); int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, - int crit, unsigned long flags); + int crit, unsigned long flags); int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc); int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x); int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos); int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, const ASN1_OBJECT *obj, - int lastpos); + int lastpos); int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, - int lastpos); + int lastpos); X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc); X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc); void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, - int *idx); + int *idx); int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, - int crit, unsigned long flags); + int crit, unsigned long flags); int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc); const OCSP_CERTID *OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *x); @@ -473,11 +478,10 @@ int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST *a, unsigned long flags); int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE *o, unsigned long flags); int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, - X509_STORE *st, unsigned long flags); + X509_STORE *st, unsigned long flags); - -# ifdef __cplusplus +#ifdef __cplusplus } -# endif -# endif /* !defined(OPENSSL_NO_OCSP) */ +#endif +#endif /* !defined(OPENSSL_NO_OCSP) */ #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/opensslv.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/opensslv.h index a19c6250ca..ae8abbefd2 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/opensslv.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/opensslv.h @@ -2,7 +2,7 @@ * WARNING: do not edit! * Generated by Makefile from include/openssl/opensslv.h.in * - * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,12 +11,12 @@ */ #ifndef OPENSSL_OPENSSLV_H -# define OPENSSL_OPENSSLV_H -# pragma once +#define OPENSSL_OPENSSLV_H +#pragma once -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif /* * SECTION 1: VERSION DATA. These will change for each release @@ -27,9 +27,15 @@ extern "C" { * * These macros express version number MAJOR.MINOR.PATCH exactly */ +/* clang-format off */ # define OPENSSL_VERSION_MAJOR 3 +/* clang-format on */ +/* clang-format off */ # define OPENSSL_VERSION_MINOR 5 -# define OPENSSL_VERSION_PATCH 1 +/* clang-format on */ +/* clang-format off */ +# define OPENSSL_VERSION_PATCH 7 +/* clang-format on */ /* * Additional version information @@ -39,10 +45,14 @@ extern "C" { */ /* Could be: #define OPENSSL_VERSION_PRE_RELEASE "-alpha.1" */ +/* clang-format off */ # define OPENSSL_VERSION_PRE_RELEASE "" +/* clang-format on */ /* Could be: #define OPENSSL_VERSION_BUILD_METADATA "+fips" */ /* Could be: #define OPENSSL_VERSION_BUILD_METADATA "+vendor.1" */ +/* clang-format off */ # define OPENSSL_VERSION_BUILD_METADATA "" +/* clang-format on */ /* * Note: The OpenSSL Project will never define OPENSSL_VERSION_BUILD_METADATA @@ -57,14 +67,16 @@ extern "C" { * be related to the API version expressed with the macros above. * This is defined in free form. */ +/* clang-format off */ # define OPENSSL_SHLIB_VERSION 3 +/* clang-format on */ /* * SECTION 2: USEFUL MACROS */ /* For checking general API compatibility when preprocessing */ -# define OPENSSL_VERSION_PREREQ(maj,min) \ +#define OPENSSL_VERSION_PREREQ(maj, min) \ ((OPENSSL_VERSION_MAJOR << 16) + OPENSSL_VERSION_MINOR >= ((maj) << 16) + (min)) /* @@ -74,41 +86,46 @@ extern "C" { * longer variant with OPENSSL_VERSION_PRE_RELEASE_STR and * OPENSSL_VERSION_BUILD_METADATA_STR appended. */ -# define OPENSSL_VERSION_STR "3.5.1" -# define OPENSSL_FULL_VERSION_STR "3.5.1" +/* clang-format off */ +# define OPENSSL_VERSION_STR "3.5.7" +/* clang-format on */ +/* clang-format off */ +# define OPENSSL_FULL_VERSION_STR "3.5.7" +/* clang-format on */ /* * SECTION 3: ADDITIONAL METADATA * * These strings are defined separately to allow them to be parsable. */ -# define OPENSSL_RELEASE_DATE "1 Jul 2025" +/* clang-format off */ +# define OPENSSL_RELEASE_DATE "9 Jun 2026" +/* clang-format on */ /* * SECTION 4: BACKWARD COMPATIBILITY */ -# define OPENSSL_VERSION_TEXT "OpenSSL 3.5.1 1 Jul 2025" +/* clang-format off */ +# define OPENSSL_VERSION_TEXT "OpenSSL 3.5.7 9 Jun 2026" +/* clang-format on */ -/* Synthesize OPENSSL_VERSION_NUMBER with the layout 0xMNN00PPSL */ -# ifdef OPENSSL_VERSION_PRE_RELEASE -# define _OPENSSL_VERSION_PRE_RELEASE 0x0L -# else -# define _OPENSSL_VERSION_PRE_RELEASE 0xfL -# endif +/* clang-format off */ +/* Synthesize OPENSSL_VERSION_NUMBER with the layout 0xMNN00PP0L */ # define OPENSSL_VERSION_NUMBER \ ( (OPENSSL_VERSION_MAJOR<<28) \ |(OPENSSL_VERSION_MINOR<<20) \ |(OPENSSL_VERSION_PATCH<<4) \ - |_OPENSSL_VERSION_PRE_RELEASE ) + |0x0L ) +/* clang-format on */ -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_OPENSSLV_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_OPENSSLV_H +#endif -#endif /* OPENSSL_OPENSSLV_H */ +#endif /* OPENSSL_OPENSSLV_H */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/pkcs12.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/pkcs12.h index 40e26b4515..171fa51498 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/pkcs12.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/pkcs12.h @@ -10,51 +10,53 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_PKCS12_H -# define OPENSSL_PKCS12_H -# pragma once +#define OPENSSL_PKCS12_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_PKCS12_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_PKCS12_H +#endif -# include -# include -# include -# include -# ifndef OPENSSL_NO_STDIO -# include -# endif +#include +#include +#include +#include +#ifndef OPENSSL_NO_STDIO +#include +#endif #ifdef __cplusplus extern "C" { #endif -# define PKCS12_KEY_ID 1 -# define PKCS12_IV_ID 2 -# define PKCS12_MAC_ID 3 +#define PKCS12_KEY_ID 1 +#define PKCS12_IV_ID 2 +#define PKCS12_MAC_ID 3 /* Default iteration count */ -# ifndef PKCS12_DEFAULT_ITER -# define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER -# endif +#ifndef PKCS12_DEFAULT_ITER +#define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER +#endif -# define PKCS12_MAC_KEY_LENGTH 20 +#define PKCS12_MAC_KEY_LENGTH 20 /* The macro is expected to be used only internally. Kept for backwards compatibility. */ -# define PKCS12_SALT_LEN 8 +#define PKCS12_SALT_LEN 8 /* It's not clear if these are actually needed... */ -# define PKCS12_key_gen PKCS12_key_gen_utf8 -# define PKCS12_add_friendlyname PKCS12_add_friendlyname_utf8 +#define PKCS12_key_gen PKCS12_key_gen_utf8 +#define PKCS12_add_friendlyname PKCS12_add_friendlyname_utf8 /* MS key usage constants */ -# define KEY_EX 0x10 -# define KEY_SIG 0x80 +#define KEY_EX 0x10 +#define KEY_SIG 0x80 typedef struct PKCS12_MAC_DATA_st PKCS12_MAC_DATA; @@ -62,6 +64,7 @@ typedef struct PKCS12_st PKCS12; typedef struct PKCS12_SAFEBAG_st PKCS12_SAFEBAG; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(PKCS12_SAFEBAG, PKCS12_SAFEBAG, PKCS12_SAFEBAG) #define sk_PKCS12_SAFEBAG_num(sk) OPENSSL_sk_num(ossl_check_const_PKCS12_SAFEBAG_sk_type(sk)) #define sk_PKCS12_SAFEBAG_value(sk, idx) ((PKCS12_SAFEBAG *)OPENSSL_sk_value(ossl_check_const_PKCS12_SAFEBAG_sk_type(sk), (idx))) @@ -89,45 +92,46 @@ SKM_DEFINE_STACK_OF_INTERNAL(PKCS12_SAFEBAG, PKCS12_SAFEBAG, PKCS12_SAFEBAG) #define sk_PKCS12_SAFEBAG_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(PKCS12_SAFEBAG) *)OPENSSL_sk_deep_copy(ossl_check_const_PKCS12_SAFEBAG_sk_type(sk), ossl_check_PKCS12_SAFEBAG_copyfunc_type(copyfunc), ossl_check_PKCS12_SAFEBAG_freefunc_type(freefunc))) #define sk_PKCS12_SAFEBAG_set_cmp_func(sk, cmp) ((sk_PKCS12_SAFEBAG_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_PKCS12_SAFEBAG_sk_type(sk), ossl_check_PKCS12_SAFEBAG_compfunc_type(cmp))) +/* clang-format on */ typedef struct pkcs12_bag_st PKCS12_BAGS; -# define PKCS12_ERROR 0 -# define PKCS12_OK 1 +#define PKCS12_ERROR 0 +#define PKCS12_OK 1 /* Compatibility macros */ #ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define M_PKCS12_bag_type PKCS12_bag_type -# define M_PKCS12_cert_bag_type PKCS12_cert_bag_type -# define M_PKCS12_crl_bag_type PKCS12_cert_bag_type +#define M_PKCS12_bag_type PKCS12_bag_type +#define M_PKCS12_cert_bag_type PKCS12_cert_bag_type +#define M_PKCS12_crl_bag_type PKCS12_cert_bag_type -# define PKCS12_certbag2x509 PKCS12_SAFEBAG_get1_cert -# define PKCS12_certbag2scrl PKCS12_SAFEBAG_get1_crl -# define PKCS12_bag_type PKCS12_SAFEBAG_get_nid -# define PKCS12_cert_bag_type PKCS12_SAFEBAG_get_bag_nid -# define PKCS12_x5092certbag PKCS12_SAFEBAG_create_cert -# define PKCS12_x509crl2certbag PKCS12_SAFEBAG_create_crl -# define PKCS12_MAKE_KEYBAG PKCS12_SAFEBAG_create0_p8inf -# define PKCS12_MAKE_SHKEYBAG PKCS12_SAFEBAG_create_pkcs8_encrypt +#define PKCS12_certbag2x509 PKCS12_SAFEBAG_get1_cert +#define PKCS12_certbag2scrl PKCS12_SAFEBAG_get1_crl +#define PKCS12_bag_type PKCS12_SAFEBAG_get_nid +#define PKCS12_cert_bag_type PKCS12_SAFEBAG_get_bag_nid +#define PKCS12_x5092certbag PKCS12_SAFEBAG_create_cert +#define PKCS12_x509crl2certbag PKCS12_SAFEBAG_create_crl +#define PKCS12_MAKE_KEYBAG PKCS12_SAFEBAG_create0_p8inf +#define PKCS12_MAKE_SHKEYBAG PKCS12_SAFEBAG_create_pkcs8_encrypt #endif #ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 ASN1_TYPE *PKCS12_get_attr(const PKCS12_SAFEBAG *bag, - int attr_nid); + int attr_nid); #endif ASN1_TYPE *PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid); int PKCS12_mac_present(const PKCS12 *p12); void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac, - const X509_ALGOR **pmacalg, - const ASN1_OCTET_STRING **psalt, - const ASN1_INTEGER **piter, - const PKCS12 *p12); + const X509_ALGOR **pmacalg, + const ASN1_OCTET_STRING **psalt, + const ASN1_INTEGER **piter, + const PKCS12 *p12); const ASN1_TYPE *PKCS12_SAFEBAG_get0_attr(const PKCS12_SAFEBAG *bag, - int attr_nid); + int attr_nid); const ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(const PKCS12_SAFEBAG *bag); int PKCS12_SAFEBAG_get_nid(const PKCS12_SAFEBAG *bag); int PKCS12_SAFEBAG_get_bag_nid(const PKCS12_SAFEBAG *bag); @@ -149,159 +153,159 @@ PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_secret(int type, int vtype, const unsigned PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8); PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8); PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid, - const char *pass, - int passlen, - unsigned char *salt, - int saltlen, int iter, - PKCS8_PRIV_KEY_INFO *p8inf); + const char *pass, + int passlen, + unsigned char *salt, + int saltlen, int iter, + PKCS8_PRIV_KEY_INFO *p8inf); PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt_ex(int pbe_nid, - const char *pass, - int passlen, - unsigned char *salt, - int saltlen, int iter, - PKCS8_PRIV_KEY_INFO *p8inf, - OSSL_LIB_CTX *ctx, - const char *propq); + const char *pass, + int passlen, + unsigned char *salt, + int saltlen, int iter, + PKCS8_PRIV_KEY_INFO *p8inf, + OSSL_LIB_CTX *ctx, + const char *propq); PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, - int nid1, int nid2); + int nid1, int nid2); PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass, - int passlen); + int passlen); PKCS8_PRIV_KEY_INFO *PKCS8_decrypt_ex(const X509_SIG *p8, const char *pass, - int passlen, OSSL_LIB_CTX *ctx, - const char *propq); + int passlen, OSSL_LIB_CTX *ctx, + const char *propq); PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(const PKCS12_SAFEBAG *bag, - const char *pass, int passlen); + const char *pass, int passlen); PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey_ex(const PKCS12_SAFEBAG *bag, - const char *pass, int passlen, - OSSL_LIB_CTX *ctx, - const char *propq); + const char *pass, int passlen, + OSSL_LIB_CTX *ctx, + const char *propq); X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, - const char *pass, int passlen, unsigned char *salt, - int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8); + const char *pass, int passlen, unsigned char *salt, + int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8); X509_SIG *PKCS8_encrypt_ex(int pbe_nid, const EVP_CIPHER *cipher, - const char *pass, int passlen, unsigned char *salt, - int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8, - OSSL_LIB_CTX *ctx, const char *propq); + const char *pass, int passlen, unsigned char *salt, + int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8, + OSSL_LIB_CTX *ctx, const char *propq); X509_SIG *PKCS8_set0_pbe(const char *pass, int passlen, - PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe); + PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe); X509_SIG *PKCS8_set0_pbe_ex(const char *pass, int passlen, - PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe, - OSSL_LIB_CTX *ctx, const char *propq); + PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe, + OSSL_LIB_CTX *ctx, const char *propq); PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk); STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7); PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, - unsigned char *salt, int saltlen, int iter, - STACK_OF(PKCS12_SAFEBAG) *bags); + unsigned char *salt, int saltlen, int iter, + STACK_OF(PKCS12_SAFEBAG) *bags); PKCS7 *PKCS12_pack_p7encdata_ex(int pbe_nid, const char *pass, int passlen, - unsigned char *salt, int saltlen, int iter, - STACK_OF(PKCS12_SAFEBAG) *bags, - OSSL_LIB_CTX *ctx, const char *propq); + unsigned char *salt, int saltlen, int iter, + STACK_OF(PKCS12_SAFEBAG) *bags, + OSSL_LIB_CTX *ctx, const char *propq); STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, - int passlen); + int passlen); int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes); STACK_OF(PKCS7) *PKCS12_unpack_authsafes(const PKCS12 *p12); int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, - int namelen); + int namelen); int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, - int namelen); + int namelen); int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name, - int namelen); + int namelen); int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, - int namelen); + int namelen); int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, - const unsigned char *name, int namelen); + const unsigned char *name, int namelen); int PKCS12_add1_attr_by_NID(PKCS12_SAFEBAG *bag, int nid, int type, - const unsigned char *bytes, int len); + const unsigned char *bytes, int len); int PKCS12_add1_attr_by_txt(PKCS12_SAFEBAG *bag, const char *attrname, int type, - const unsigned char *bytes, int len); + const unsigned char *bytes, int len); int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage); ASN1_TYPE *PKCS12_get_attr_gen(const STACK_OF(X509_ATTRIBUTE) *attrs, - int attr_nid); + int attr_nid); char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag); const STACK_OF(X509_ATTRIBUTE) * PKCS12_SAFEBAG_get0_attrs(const PKCS12_SAFEBAG *bag); void PKCS12_SAFEBAG_set0_attrs(PKCS12_SAFEBAG *bag, STACK_OF(X509_ATTRIBUTE) *attrs); unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor, - const char *pass, int passlen, - const unsigned char *in, int inlen, - unsigned char **data, int *datalen, - int en_de); + const char *pass, int passlen, + const unsigned char *in, int inlen, + unsigned char **data, int *datalen, + int en_de); unsigned char *PKCS12_pbe_crypt_ex(const X509_ALGOR *algor, - const char *pass, int passlen, - const unsigned char *in, int inlen, - unsigned char **data, int *datalen, - int en_de, OSSL_LIB_CTX *libctx, - const char *propq); + const char *pass, int passlen, + const unsigned char *in, int inlen, + unsigned char **data, int *datalen, + int en_de, OSSL_LIB_CTX *libctx, + const char *propq); void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it, - const char *pass, int passlen, - const ASN1_OCTET_STRING *oct, int zbuf); + const char *pass, int passlen, + const ASN1_OCTET_STRING *oct, int zbuf); void *PKCS12_item_decrypt_d2i_ex(const X509_ALGOR *algor, const ASN1_ITEM *it, - const char *pass, int passlen, - const ASN1_OCTET_STRING *oct, int zbuf, - OSSL_LIB_CTX *libctx, - const char *propq); + const char *pass, int passlen, + const ASN1_OCTET_STRING *oct, int zbuf, + OSSL_LIB_CTX *libctx, + const char *propq); ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, - const ASN1_ITEM *it, - const char *pass, int passlen, - void *obj, int zbuf); + const ASN1_ITEM *it, + const char *pass, int passlen, + void *obj, int zbuf); ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt_ex(X509_ALGOR *algor, - const ASN1_ITEM *it, - const char *pass, int passlen, - void *obj, int zbuf, - OSSL_LIB_CTX *ctx, - const char *propq); + const ASN1_ITEM *it, + const char *pass, int passlen, + void *obj, int zbuf, + OSSL_LIB_CTX *ctx, + const char *propq); PKCS12 *PKCS12_init(int mode); PKCS12 *PKCS12_init_ex(int mode, OSSL_LIB_CTX *ctx, const char *propq); int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt, - int saltlen, int id, int iter, int n, - unsigned char *out, const EVP_MD *md_type); + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type); int PKCS12_key_gen_asc_ex(const char *pass, int passlen, unsigned char *salt, - int saltlen, int id, int iter, int n, - unsigned char *out, const EVP_MD *md_type, - OSSL_LIB_CTX *ctx, const char *propq); + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type, + OSSL_LIB_CTX *ctx, const char *propq); int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, - int saltlen, int id, int iter, int n, - unsigned char *out, const EVP_MD *md_type); + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type); int PKCS12_key_gen_uni_ex(unsigned char *pass, int passlen, unsigned char *salt, - int saltlen, int id, int iter, int n, - unsigned char *out, const EVP_MD *md_type, - OSSL_LIB_CTX *ctx, const char *propq); + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type, + OSSL_LIB_CTX *ctx, const char *propq); int PKCS12_key_gen_utf8(const char *pass, int passlen, unsigned char *salt, - int saltlen, int id, int iter, int n, - unsigned char *out, const EVP_MD *md_type); + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type); int PKCS12_key_gen_utf8_ex(const char *pass, int passlen, unsigned char *salt, - int saltlen, int id, int iter, int n, - unsigned char *out, const EVP_MD *md_type, - OSSL_LIB_CTX *ctx, const char *propq); + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type, + OSSL_LIB_CTX *ctx, const char *propq); int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, - ASN1_TYPE *param, const EVP_CIPHER *cipher, - const EVP_MD *md_type, int en_de); + ASN1_TYPE *param, const EVP_CIPHER *cipher, + const EVP_MD *md_type, int en_de); int PKCS12_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, - ASN1_TYPE *param, const EVP_CIPHER *cipher, - const EVP_MD *md_type, int en_de, - OSSL_LIB_CTX *libctx, const char *propq); + ASN1_TYPE *param, const EVP_CIPHER *cipher, + const EVP_MD *md_type, int en_de, + OSSL_LIB_CTX *libctx, const char *propq); int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, - unsigned char *mac, unsigned int *maclen); + unsigned char *mac, unsigned int *maclen); int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen); int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen, - unsigned char *salt, int saltlen, int iter, - const EVP_MD *md_type); + unsigned char *salt, int saltlen, int iter, + const EVP_MD *md_type); int PKCS12_set_pbmac1_pbkdf2(PKCS12 *p12, const char *pass, int passlen, - unsigned char *salt, int saltlen, int iter, - const EVP_MD *md_type, const char *prf_md_name); + unsigned char *salt, int saltlen, int iter, + const EVP_MD *md_type, const char *prf_md_name); int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, - int saltlen, const EVP_MD *md_type); + int saltlen, const EVP_MD *md_type); unsigned char *OPENSSL_asc2uni(const char *asc, int asclen, - unsigned char **uni, int *unilen); + unsigned char **uni, int *unilen); char *OPENSSL_uni2asc(const unsigned char *uni, int unilen); unsigned char *OPENSSL_utf82uni(const char *asc, int asclen, - unsigned char **uni, int *unilen); + unsigned char **uni, int *unilen); char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen); DECLARE_ASN1_FUNCTIONS(PKCS12) @@ -314,53 +318,53 @@ DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES) void PKCS12_PBE_add(void); int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, - STACK_OF(X509) **ca); + STACK_OF(X509) **ca); typedef int PKCS12_create_cb(PKCS12_SAFEBAG *bag, void *cbarg); PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey, - X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, - int iter, int mac_iter, int keytype); + X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, + int iter, int mac_iter, int keytype); PKCS12 *PKCS12_create_ex(const char *pass, const char *name, EVP_PKEY *pkey, - X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, - int iter, int mac_iter, int keytype, - OSSL_LIB_CTX *ctx, const char *propq); + X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, + int iter, int mac_iter, int keytype, + OSSL_LIB_CTX *ctx, const char *propq); PKCS12 *PKCS12_create_ex2(const char *pass, const char *name, EVP_PKEY *pkey, - X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, - int iter, int mac_iter, int keytype, - OSSL_LIB_CTX *ctx, const char *propq, - PKCS12_create_cb *cb, void *cbarg); + X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, + int iter, int mac_iter, int keytype, + OSSL_LIB_CTX *ctx, const char *propq, + PKCS12_create_cb *cb, void *cbarg); PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert); PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags, - EVP_PKEY *key, int key_usage, int iter, - int key_nid, const char *pass); + EVP_PKEY *key, int key_usage, int iter, + int key_nid, const char *pass); PKCS12_SAFEBAG *PKCS12_add_key_ex(STACK_OF(PKCS12_SAFEBAG) **pbags, - EVP_PKEY *key, int key_usage, int iter, - int key_nid, const char *pass, - OSSL_LIB_CTX *ctx, const char *propq); + EVP_PKEY *key, int key_usage, int iter, + int key_nid, const char *pass, + OSSL_LIB_CTX *ctx, const char *propq); PKCS12_SAFEBAG *PKCS12_add_secret(STACK_OF(PKCS12_SAFEBAG) **pbags, - int nid_type, const unsigned char *value, int len); + int nid_type, const unsigned char *value, int len); int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags, - int safe_nid, int iter, const char *pass); + int safe_nid, int iter, const char *pass); int PKCS12_add_safe_ex(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags, - int safe_nid, int iter, const char *pass, - OSSL_LIB_CTX *ctx, const char *propq); + int safe_nid, int iter, const char *pass, + OSSL_LIB_CTX *ctx, const char *propq); PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid); PKCS12 *PKCS12_add_safes_ex(STACK_OF(PKCS7) *safes, int p7_nid, - OSSL_LIB_CTX *ctx, const char *propq); + OSSL_LIB_CTX *ctx, const char *propq); int i2d_PKCS12_bio(BIO *bp, const PKCS12 *p12); -# ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_STDIO int i2d_PKCS12_fp(FILE *fp, const PKCS12 *p12); -# endif +#endif PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12); -# ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_STDIO PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12); -# endif +#endif int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/pkcs7.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/pkcs7.h index 91239d1be4..a88cb93d0a 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/pkcs7.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/pkcs7.h @@ -10,32 +10,33 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_PKCS7_H -# define OPENSSL_PKCS7_H -# pragma once +#define OPENSSL_PKCS7_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_PKCS7_H -# endif - -# include -# include -# include - -# include -# include -# include -# ifndef OPENSSL_NO_STDIO -# include -# endif - -#ifdef __cplusplus -extern "C" { +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_PKCS7_H #endif +#include +#include +#include + +#include +#include +#include +#ifndef OPENSSL_NO_STDIO +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif /*- Encryption_ID DES-CBC @@ -55,7 +56,7 @@ typedef struct pkcs7_issuer_and_serial_st { } PKCS7_ISSUER_AND_SERIAL; typedef struct pkcs7_signer_info_st { - ASN1_INTEGER *version; /* version 1 */ + ASN1_INTEGER *version; /* version 1 */ PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; X509_ALGOR *digest_alg; STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */ @@ -66,6 +67,7 @@ typedef struct pkcs7_signer_info_st { EVP_PKEY *pkey; const PKCS7_CTX *ctx; } PKCS7_SIGNER_INFO; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(PKCS7_SIGNER_INFO, PKCS7_SIGNER_INFO, PKCS7_SIGNER_INFO) #define sk_PKCS7_SIGNER_INFO_num(sk) OPENSSL_sk_num(ossl_check_const_PKCS7_SIGNER_INFO_sk_type(sk)) #define sk_PKCS7_SIGNER_INFO_value(sk, idx) ((PKCS7_SIGNER_INFO *)OPENSSL_sk_value(ossl_check_const_PKCS7_SIGNER_INFO_sk_type(sk), (idx))) @@ -93,15 +95,17 @@ SKM_DEFINE_STACK_OF_INTERNAL(PKCS7_SIGNER_INFO, PKCS7_SIGNER_INFO, PKCS7_SIGNER_ #define sk_PKCS7_SIGNER_INFO_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(PKCS7_SIGNER_INFO) *)OPENSSL_sk_deep_copy(ossl_check_const_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_copyfunc_type(copyfunc), ossl_check_PKCS7_SIGNER_INFO_freefunc_type(freefunc))) #define sk_PKCS7_SIGNER_INFO_set_cmp_func(sk, cmp) ((sk_PKCS7_SIGNER_INFO_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_compfunc_type(cmp))) +/* clang-format on */ typedef struct pkcs7_recip_info_st { - ASN1_INTEGER *version; /* version 0 */ + ASN1_INTEGER *version; /* version 0 */ PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; X509_ALGOR *key_enc_algor; ASN1_OCTET_STRING *enc_key; - X509 *cert; /* get the pub-key from this */ + X509 *cert; /* get the pub-key from this */ const PKCS7_CTX *ctx; } PKCS7_RECIP_INFO; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(PKCS7_RECIP_INFO, PKCS7_RECIP_INFO, PKCS7_RECIP_INFO) #define sk_PKCS7_RECIP_INFO_num(sk) OPENSSL_sk_num(ossl_check_const_PKCS7_RECIP_INFO_sk_type(sk)) #define sk_PKCS7_RECIP_INFO_value(sk, idx) ((PKCS7_RECIP_INFO *)OPENSSL_sk_value(ossl_check_const_PKCS7_RECIP_INFO_sk_type(sk), (idx))) @@ -129,13 +133,13 @@ SKM_DEFINE_STACK_OF_INTERNAL(PKCS7_RECIP_INFO, PKCS7_RECIP_INFO, PKCS7_RECIP_INF #define sk_PKCS7_RECIP_INFO_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(PKCS7_RECIP_INFO) *)OPENSSL_sk_deep_copy(ossl_check_const_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_copyfunc_type(copyfunc), ossl_check_PKCS7_RECIP_INFO_freefunc_type(freefunc))) #define sk_PKCS7_RECIP_INFO_set_cmp_func(sk, cmp) ((sk_PKCS7_RECIP_INFO_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_compfunc_type(cmp))) - +/* clang-format on */ typedef struct pkcs7_signed_st { - ASN1_INTEGER *version; /* version 1 */ + ASN1_INTEGER *version; /* version 1 */ STACK_OF(X509_ALGOR) *md_algs; /* md used */ - STACK_OF(X509) *cert; /* [ 0 ] */ /* name should be 'certificates' */ - STACK_OF(X509_CRL) *crl; /* [ 1 ] */ /* name should be 'crls' */ + STACK_OF(X509) *cert; /* [ 0 ] */ /* name should be 'certificates' */ + STACK_OF(X509_CRL) *crl; /* [ 1 ] */ /* name should be 'crls' */ STACK_OF(PKCS7_SIGNER_INFO) *signer_info; struct pkcs7_st *contents; } PKCS7_SIGNED; @@ -153,30 +157,30 @@ typedef struct pkcs7_enc_content_st { } PKCS7_ENC_CONTENT; typedef struct pkcs7_enveloped_st { - ASN1_INTEGER *version; /* version 0 */ + ASN1_INTEGER *version; /* version 0 */ STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; PKCS7_ENC_CONTENT *enc_data; } PKCS7_ENVELOPE; typedef struct pkcs7_signedandenveloped_st { - ASN1_INTEGER *version; /* version 1 */ + ASN1_INTEGER *version; /* version 1 */ STACK_OF(X509_ALGOR) *md_algs; /* md used */ - STACK_OF(X509) *cert; /* [ 0 ] */ /* name should be 'certificates' */ - STACK_OF(X509_CRL) *crl; /* [ 1 ] */ /* name should be 'crls' */ + STACK_OF(X509) *cert; /* [ 0 ] */ /* name should be 'certificates' */ + STACK_OF(X509_CRL) *crl; /* [ 1 ] */ /* name should be 'crls' */ STACK_OF(PKCS7_SIGNER_INFO) *signer_info; PKCS7_ENC_CONTENT *enc_data; STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; } PKCS7_SIGN_ENVELOPE; typedef struct pkcs7_digest_st { - ASN1_INTEGER *version; /* version 0 */ - X509_ALGOR *md; /* md used */ + ASN1_INTEGER *version; /* version 0 */ + X509_ALGOR *md; /* md used */ struct pkcs7_st *contents; ASN1_OCTET_STRING *digest; } PKCS7_DIGEST; typedef struct pkcs7_encrypted_st { - ASN1_INTEGER *version; /* version 0 */ + ASN1_INTEGER *version; /* version 0 */ PKCS7_ENC_CONTENT *enc_data; } PKCS7_ENCRYPT; @@ -187,10 +191,10 @@ typedef struct pkcs7_st { */ unsigned char *asn1; long length; -# define PKCS7_S_HEADER 0 -# define PKCS7_S_BODY 1 -# define PKCS7_S_TAIL 2 - int state; /* used during processing */ +#define PKCS7_S_HEADER 0 +#define PKCS7_S_BODY 1 +#define PKCS7_S_TAIL 2 + int state; /* used during processing */ int detached; ASN1_OBJECT *type; /* content as defined by the type */ @@ -217,6 +221,7 @@ typedef struct pkcs7_st { } d; PKCS7_CTX ctx; } PKCS7; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(PKCS7, PKCS7, PKCS7) #define sk_PKCS7_num(sk) OPENSSL_sk_num(ossl_check_const_PKCS7_sk_type(sk)) #define sk_PKCS7_value(sk, idx) ((PKCS7 *)OPENSSL_sk_value(ossl_check_const_PKCS7_sk_type(sk), (idx))) @@ -244,73 +249,73 @@ SKM_DEFINE_STACK_OF_INTERNAL(PKCS7, PKCS7, PKCS7) #define sk_PKCS7_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(PKCS7) *)OPENSSL_sk_deep_copy(ossl_check_const_PKCS7_sk_type(sk), ossl_check_PKCS7_copyfunc_type(copyfunc), ossl_check_PKCS7_freefunc_type(freefunc))) #define sk_PKCS7_set_cmp_func(sk, cmp) ((sk_PKCS7_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_PKCS7_sk_type(sk), ossl_check_PKCS7_compfunc_type(cmp))) +/* clang-format on */ +#define PKCS7_OP_SET_DETACHED_SIGNATURE 1 +#define PKCS7_OP_GET_DETACHED_SIGNATURE 2 -# define PKCS7_OP_SET_DETACHED_SIGNATURE 1 -# define PKCS7_OP_GET_DETACHED_SIGNATURE 2 +#define PKCS7_get_signed_attributes(si) ((si)->auth_attr) +#define PKCS7_get_attributes(si) ((si)->unauth_attr) -# define PKCS7_get_signed_attributes(si) ((si)->auth_attr) -# define PKCS7_get_attributes(si) ((si)->unauth_attr) +#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) +#define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted) +#define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped) +#define PKCS7_type_is_signedAndEnveloped(a) \ + (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped) +#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) +#define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest) -# define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) -# define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted) -# define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped) -# define PKCS7_type_is_signedAndEnveloped(a) \ - (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped) -# define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) -# define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest) +#define PKCS7_set_detached(p, v) \ + PKCS7_ctrl(p, PKCS7_OP_SET_DETACHED_SIGNATURE, v, NULL) +#define PKCS7_get_detached(p) \ + PKCS7_ctrl(p, PKCS7_OP_GET_DETACHED_SIGNATURE, 0, NULL) -# define PKCS7_set_detached(p,v) \ - PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL) -# define PKCS7_get_detached(p) \ - PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL) - -# define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7)) +#define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7)) /* S/MIME related flags */ -# define PKCS7_TEXT 0x1 -# define PKCS7_NOCERTS 0x2 -# define PKCS7_NOSIGS 0x4 -# define PKCS7_NOCHAIN 0x8 -# define PKCS7_NOINTERN 0x10 -# define PKCS7_NOVERIFY 0x20 -# define PKCS7_DETACHED 0x40 -# define PKCS7_BINARY 0x80 -# define PKCS7_NOATTR 0x100 -# define PKCS7_NOSMIMECAP 0x200 -# define PKCS7_NOOLDMIMETYPE 0x400 -# define PKCS7_CRLFEOL 0x800 -# define PKCS7_STREAM 0x1000 -# define PKCS7_NOCRL 0x2000 -# define PKCS7_PARTIAL 0x4000 -# define PKCS7_REUSE_DIGEST 0x8000 -# define PKCS7_NO_DUAL_CONTENT 0x10000 +#define PKCS7_TEXT 0x1 +#define PKCS7_NOCERTS 0x2 +#define PKCS7_NOSIGS 0x4 +#define PKCS7_NOCHAIN 0x8 +#define PKCS7_NOINTERN 0x10 +#define PKCS7_NOVERIFY 0x20 +#define PKCS7_DETACHED 0x40 +#define PKCS7_BINARY 0x80 +#define PKCS7_NOATTR 0x100 +#define PKCS7_NOSMIMECAP 0x200 +#define PKCS7_NOOLDMIMETYPE 0x400 +#define PKCS7_CRLFEOL 0x800 +#define PKCS7_STREAM 0x1000 +#define PKCS7_NOCRL 0x2000 +#define PKCS7_PARTIAL 0x4000 +#define PKCS7_REUSE_DIGEST 0x8000 +#define PKCS7_NO_DUAL_CONTENT 0x10000 /* Flags: for compatibility with older code */ -# define SMIME_TEXT PKCS7_TEXT -# define SMIME_NOCERTS PKCS7_NOCERTS -# define SMIME_NOSIGS PKCS7_NOSIGS -# define SMIME_NOCHAIN PKCS7_NOCHAIN -# define SMIME_NOINTERN PKCS7_NOINTERN -# define SMIME_NOVERIFY PKCS7_NOVERIFY -# define SMIME_DETACHED PKCS7_DETACHED -# define SMIME_BINARY PKCS7_BINARY -# define SMIME_NOATTR PKCS7_NOATTR +#define SMIME_TEXT PKCS7_TEXT +#define SMIME_NOCERTS PKCS7_NOCERTS +#define SMIME_NOSIGS PKCS7_NOSIGS +#define SMIME_NOCHAIN PKCS7_NOCHAIN +#define SMIME_NOINTERN PKCS7_NOINTERN +#define SMIME_NOVERIFY PKCS7_NOVERIFY +#define SMIME_DETACHED PKCS7_DETACHED +#define SMIME_BINARY PKCS7_BINARY +#define SMIME_NOATTR PKCS7_NOATTR /* CRLF ASCII canonicalisation */ -# define SMIME_ASCIICRLF 0x80000 +#define SMIME_ASCIICRLF 0x80000 DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL) int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, - const EVP_MD *type, unsigned char *md, - unsigned int *len); -# ifndef OPENSSL_NO_STDIO + const EVP_MD *type, unsigned char *md, + unsigned int *len); +#ifndef OPENSSL_NO_STDIO PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7); int i2d_PKCS7_fp(FILE *fp, const PKCS7 *p7); -# endif +#endif DECLARE_ASN1_DUP_FUNCTION(PKCS7) PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7); int i2d_PKCS7_bio(BIO *bp, const PKCS7 *p7); @@ -341,30 +346,30 @@ int PKCS7_set_type(PKCS7 *p7, int type); int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other); int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data); int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, - const EVP_MD *dgst); + const EVP_MD *dgst); int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si); int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i); int PKCS7_add_certificate(PKCS7 *p7, X509 *cert); int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl); int PKCS7_content_new(PKCS7 *p7, int nid); int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, - BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); + BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, - X509 *signer); + X509 *signer); BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio); int PKCS7_dataFinal(PKCS7 *p7, BIO *bio); BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert); PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, - EVP_PKEY *pkey, const EVP_MD *dgst); + EVP_PKEY *pkey, const EVP_MD *dgst); X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si); int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md); STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7); PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509); void PKCS7_SIGNER_INFO_get0_algs(PKCS7_SIGNER_INFO *si, EVP_PKEY **pk, - X509_ALGOR **pdig, X509_ALGOR **psig); + X509_ALGOR **pdig, X509_ALGOR **psig); void PKCS7_RECIP_INFO_get0_alg(PKCS7_RECIP_INFO *ri, X509_ALGOR **penc); int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri); int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509); @@ -375,48 +380,48 @@ PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx); ASN1_OCTET_STRING *PKCS7_get_octet_string(PKCS7 *p7); ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk); int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int type, - void *data); + void *data); int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, - void *value); + void *value); ASN1_TYPE *PKCS7_get_attribute(const PKCS7_SIGNER_INFO *si, int nid); ASN1_TYPE *PKCS7_get_signed_attribute(const PKCS7_SIGNER_INFO *si, int nid); int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, - STACK_OF(X509_ATTRIBUTE) *sk); + STACK_OF(X509_ATTRIBUTE) *sk); int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, - STACK_OF(X509_ATTRIBUTE) *sk); + STACK_OF(X509_ATTRIBUTE) *sk); PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, - BIO *data, int flags); + BIO *data, int flags); PKCS7 *PKCS7_sign_ex(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, - BIO *data, int flags, OSSL_LIB_CTX *libctx, - const char *propq); + BIO *data, int flags, OSSL_LIB_CTX *libctx, + const char *propq); PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, - X509 *signcert, EVP_PKEY *pkey, - const EVP_MD *md, int flags); + X509 *signcert, EVP_PKEY *pkey, + const EVP_MD *md, int flags); int PKCS7_final(PKCS7 *p7, BIO *data, int flags); int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, - BIO *indata, BIO *out, int flags); + BIO *indata, BIO *out, int flags); STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, - int flags); + int flags); PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, - int flags); + int flags); PKCS7 *PKCS7_encrypt_ex(STACK_OF(X509) *certs, BIO *in, - const EVP_CIPHER *cipher, int flags, - OSSL_LIB_CTX *libctx, const char *propq); + const EVP_CIPHER *cipher, int flags, + OSSL_LIB_CTX *libctx, const char *propq); int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, - int flags); + int flags); int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, - STACK_OF(X509_ALGOR) *cap); + STACK_OF(X509_ALGOR) *cap); STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si); int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg); int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid); int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t); int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si, - const unsigned char *md, int mdlen); + const unsigned char *md, int mdlen); int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags); PKCS7 *SMIME_read_PKCS7_ex(BIO *bio, BIO **bcont, PKCS7 **p7); @@ -424,7 +429,7 @@ PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont); BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/safestack.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/safestack.h index 3266464706..16b6e31506 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/safestack.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/safestack.h @@ -10,173 +10,175 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_SAFESTACK_H -# define OPENSSL_SAFESTACK_H -# pragma once +#define OPENSSL_SAFESTACK_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_SAFESTACK_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_SAFESTACK_H +#endif -# include -# include +#include +#include #ifdef __cplusplus extern "C" { #endif -# define STACK_OF(type) struct stack_st_##type +#define STACK_OF(type) struct stack_st_##type /* Helper macro for internal use */ -# define SKM_DEFINE_STACK_OF_INTERNAL(t1, t2, t3) \ - STACK_OF(t1); \ - typedef int (*sk_##t1##_compfunc)(const t3 * const *a, const t3 *const *b); \ - typedef void (*sk_##t1##_freefunc)(t3 *a); \ - typedef t3 * (*sk_##t1##_copyfunc)(const t3 *a); \ - static ossl_unused ossl_inline t2 *ossl_check_##t1##_type(t2 *ptr) \ - { \ - return ptr; \ - } \ +#define SKM_DEFINE_STACK_OF_INTERNAL(t1, t2, t3) \ + STACK_OF(t1); \ + typedef int (*sk_##t1##_compfunc)(const t3 *const *a, const t3 *const *b); \ + typedef void (*sk_##t1##_freefunc)(t3 * a); \ + typedef t3 *(*sk_##t1##_copyfunc)(const t3 *a); \ + static ossl_unused ossl_inline t2 *ossl_check_##t1##_type(t2 *ptr) \ + { \ + return ptr; \ + } \ static ossl_unused ossl_inline const OPENSSL_STACK *ossl_check_const_##t1##_sk_type(const STACK_OF(t1) *sk) \ - { \ - return (const OPENSSL_STACK *)sk; \ - } \ - static ossl_unused ossl_inline OPENSSL_STACK *ossl_check_##t1##_sk_type(STACK_OF(t1) *sk) \ - { \ - return (OPENSSL_STACK *)sk; \ - } \ - static ossl_unused ossl_inline OPENSSL_sk_compfunc ossl_check_##t1##_compfunc_type(sk_##t1##_compfunc cmp) \ - { \ - return (OPENSSL_sk_compfunc)cmp; \ - } \ - static ossl_unused ossl_inline OPENSSL_sk_copyfunc ossl_check_##t1##_copyfunc_type(sk_##t1##_copyfunc cpy) \ - { \ - return (OPENSSL_sk_copyfunc)cpy; \ - } \ - static ossl_unused ossl_inline OPENSSL_sk_freefunc ossl_check_##t1##_freefunc_type(sk_##t1##_freefunc fr) \ - { \ - return (OPENSSL_sk_freefunc)fr; \ + { \ + return (const OPENSSL_STACK *)sk; \ + } \ + static ossl_unused ossl_inline OPENSSL_STACK *ossl_check_##t1##_sk_type(STACK_OF(t1) *sk) \ + { \ + return (OPENSSL_STACK *)sk; \ + } \ + static ossl_unused ossl_inline OPENSSL_sk_compfunc ossl_check_##t1##_compfunc_type(sk_##t1##_compfunc cmp) \ + { \ + return (OPENSSL_sk_compfunc)cmp; \ + } \ + static ossl_unused ossl_inline OPENSSL_sk_copyfunc ossl_check_##t1##_copyfunc_type(sk_##t1##_copyfunc cpy) \ + { \ + return (OPENSSL_sk_copyfunc)cpy; \ + } \ + static ossl_unused ossl_inline OPENSSL_sk_freefunc ossl_check_##t1##_freefunc_type(sk_##t1##_freefunc fr) \ + { \ + return (OPENSSL_sk_freefunc)fr; \ } -# define SKM_DEFINE_STACK_OF(t1, t2, t3) \ - STACK_OF(t1); \ - typedef int (*sk_##t1##_compfunc)(const t3 * const *a, const t3 *const *b); \ - typedef void (*sk_##t1##_freefunc)(t3 *a); \ - typedef t3 * (*sk_##t1##_copyfunc)(const t3 *a); \ - static ossl_unused ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \ - { \ - return OPENSSL_sk_num((const OPENSSL_STACK *)sk); \ - } \ - static ossl_unused ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \ - { \ - return (t2 *)OPENSSL_sk_value((const OPENSSL_STACK *)sk, idx); \ - } \ - static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \ - { \ - return (STACK_OF(t1) *)OPENSSL_sk_new((OPENSSL_sk_compfunc)compare); \ - } \ - static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \ - { \ - return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \ - } \ - static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_reserve(sk_##t1##_compfunc compare, int n) \ - { \ - return (STACK_OF(t1) *)OPENSSL_sk_new_reserve((OPENSSL_sk_compfunc)compare, n); \ - } \ - static ossl_unused ossl_inline int sk_##t1##_reserve(STACK_OF(t1) *sk, int n) \ - { \ - return OPENSSL_sk_reserve((OPENSSL_STACK *)sk, n); \ - } \ - static ossl_unused ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \ - { \ - OPENSSL_sk_free((OPENSSL_STACK *)sk); \ - } \ - static ossl_unused ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \ - { \ - OPENSSL_sk_zero((OPENSSL_STACK *)sk); \ - } \ - static ossl_unused ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \ - { \ - return (t2 *)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); \ - } \ - static ossl_unused ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \ - { \ - return (t2 *)OPENSSL_sk_delete_ptr((OPENSSL_STACK *)sk, \ - (const void *)ptr); \ - } \ - static ossl_unused ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \ - { \ - return OPENSSL_sk_push((OPENSSL_STACK *)sk, (const void *)ptr); \ - } \ - static ossl_unused ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \ - { \ - return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (const void *)ptr); \ - } \ - static ossl_unused ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \ - { \ - return (t2 *)OPENSSL_sk_pop((OPENSSL_STACK *)sk); \ - } \ - static ossl_unused ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \ - { \ - return (t2 *)OPENSSL_sk_shift((OPENSSL_STACK *)sk); \ - } \ - static ossl_unused ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \ - { \ - OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc)freefunc); \ - } \ - static ossl_unused ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \ - { \ - return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (const void *)ptr, idx); \ - } \ - static ossl_unused ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \ - { \ - return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr); \ - } \ - static ossl_unused ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \ - { \ - return OPENSSL_sk_find((OPENSSL_STACK *)sk, (const void *)ptr); \ - } \ - static ossl_unused ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \ - { \ - return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (const void *)ptr); \ - } \ - static ossl_unused ossl_inline int sk_##t1##_find_all(STACK_OF(t1) *sk, t2 *ptr, int *pnum) \ - { \ - return OPENSSL_sk_find_all((OPENSSL_STACK *)sk, (const void *)ptr, pnum); \ - } \ - static ossl_unused ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \ - { \ - OPENSSL_sk_sort((OPENSSL_STACK *)sk); \ - } \ - static ossl_unused ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \ - { \ - return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \ - } \ - static ossl_unused ossl_inline STACK_OF(t1) * sk_##t1##_dup(const STACK_OF(t1) *sk) \ - { \ - return (STACK_OF(t1) *)OPENSSL_sk_dup((const OPENSSL_STACK *)sk); \ - } \ - static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \ - sk_##t1##_copyfunc copyfunc, \ - sk_##t1##_freefunc freefunc) \ - { \ - return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((const OPENSSL_STACK *)sk, \ - (OPENSSL_sk_copyfunc)copyfunc, \ - (OPENSSL_sk_freefunc)freefunc); \ - } \ +#define SKM_DEFINE_STACK_OF(t1, t2, t3) \ + STACK_OF(t1); \ + typedef int (*sk_##t1##_compfunc)(const t3 *const *a, const t3 *const *b); \ + typedef void (*sk_##t1##_freefunc)(t3 * a); \ + typedef t3 *(*sk_##t1##_copyfunc)(const t3 *a); \ + static ossl_unused ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \ + { \ + return OPENSSL_sk_num((const OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \ + { \ + return (t2 *)OPENSSL_sk_value((const OPENSSL_STACK *)sk, idx); \ + } \ + static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_new((OPENSSL_sk_compfunc)compare); \ + } \ + static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \ + } \ + static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_reserve(sk_##t1##_compfunc compare, int n) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_new_reserve((OPENSSL_sk_compfunc)compare, n); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_reserve(STACK_OF(t1) *sk, int n) \ + { \ + return OPENSSL_sk_reserve((OPENSSL_STACK *)sk, n); \ + } \ + static ossl_unused ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \ + { \ + OPENSSL_sk_free((OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \ + { \ + OPENSSL_sk_zero((OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \ + { \ + return (t2 *)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return (t2 *)OPENSSL_sk_delete_ptr((OPENSSL_STACK *)sk, \ + (const void *)ptr); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_push((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \ + { \ + return (t2 *)OPENSSL_sk_pop((OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \ + { \ + return (t2 *)OPENSSL_sk_shift((OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \ + { \ + OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc)freefunc); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \ + { \ + return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (const void *)ptr, idx); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \ + { \ + return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_find((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_find_all(STACK_OF(t1) *sk, t2 *ptr, int *pnum) \ + { \ + return OPENSSL_sk_find_all((OPENSSL_STACK *)sk, (const void *)ptr, pnum); \ + } \ + static ossl_unused ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \ + { \ + OPENSSL_sk_sort((OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \ + { \ + return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_dup(const STACK_OF(t1) *sk) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_dup((const OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \ + sk_##t1##_copyfunc copyfunc, \ + sk_##t1##_freefunc freefunc) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((const OPENSSL_STACK *)sk, \ + (OPENSSL_sk_copyfunc)copyfunc, \ + (OPENSSL_sk_freefunc)freefunc); \ + } \ static ossl_unused ossl_inline sk_##t1##_compfunc sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, sk_##t1##_compfunc compare) \ - { \ - return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \ + { \ + return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \ } -# define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t) -# define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t) -# define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2) -# define DEFINE_SPECIAL_STACK_OF_CONST(t1, t2) \ - SKM_DEFINE_STACK_OF(t1, const t2, t2) +#define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t) +#define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t) +#define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2) +#define DEFINE_SPECIAL_STACK_OF_CONST(t1, t2) \ + SKM_DEFINE_STACK_OF(t1, const t2, t2) /*- * Strings are special: normally an lhash entry will point to a single @@ -202,6 +204,7 @@ typedef const char *OPENSSL_CSTRING; * chars. So, we have to implement STRING specially for STACK_OF. This is * dealt with in the autogenerated macros below. */ +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OPENSSL_STRING, char, char) #define sk_OPENSSL_STRING_num(sk) OPENSSL_sk_num(ossl_check_const_OPENSSL_STRING_sk_type(sk)) #define sk_OPENSSL_STRING_value(sk, idx) ((char *)OPENSSL_sk_value(ossl_check_const_OPENSSL_STRING_sk_type(sk), (idx))) @@ -255,6 +258,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OPENSSL_CSTRING, const char, char) #define sk_OPENSSL_CSTRING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OPENSSL_CSTRING) *)OPENSSL_sk_deep_copy(ossl_check_const_OPENSSL_CSTRING_sk_type(sk), ossl_check_OPENSSL_CSTRING_copyfunc_type(copyfunc), ossl_check_OPENSSL_CSTRING_freefunc_type(freefunc))) #define sk_OPENSSL_CSTRING_set_cmp_func(sk, cmp) ((sk_OPENSSL_CSTRING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OPENSSL_CSTRING_sk_type(sk), ossl_check_OPENSSL_CSTRING_compfunc_type(cmp))) +/* clang-format on */ #if !defined(OPENSSL_NO_DEPRECATED_3_0) /* @@ -262,6 +266,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OPENSSL_CSTRING, const char, char) * These should also be distinguished from "normal" stacks. */ typedef void *OPENSSL_BLOCK; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OPENSSL_BLOCK, void, void) #define sk_OPENSSL_BLOCK_num(sk) OPENSSL_sk_num(ossl_check_const_OPENSSL_BLOCK_sk_type(sk)) #define sk_OPENSSL_BLOCK_value(sk, idx) ((void *)OPENSSL_sk_value(ossl_check_const_OPENSSL_BLOCK_sk_type(sk), (idx))) @@ -289,9 +294,10 @@ SKM_DEFINE_STACK_OF_INTERNAL(OPENSSL_BLOCK, void, void) #define sk_OPENSSL_BLOCK_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OPENSSL_BLOCK) *)OPENSSL_sk_deep_copy(ossl_check_const_OPENSSL_BLOCK_sk_type(sk), ossl_check_OPENSSL_BLOCK_copyfunc_type(copyfunc), ossl_check_OPENSSL_BLOCK_freefunc_type(freefunc))) #define sk_OPENSSL_BLOCK_set_cmp_func(sk, cmp) ((sk_OPENSSL_BLOCK_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OPENSSL_BLOCK_sk_type(sk), ossl_check_OPENSSL_BLOCK_compfunc_type(cmp))) +/* clang-format on */ #endif -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/srp.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/srp.h index 82808ed382..5a4df171ff 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/srp.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/srp.h @@ -14,36 +14,39 @@ * for the EdelKey project. */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_SRP_H -# define OPENSSL_SRP_H -# pragma once +#define OPENSSL_SRP_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_SRP_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_SRP_H +#endif #include #ifndef OPENSSL_NO_SRP -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 typedef struct SRP_gN_cache_st { char *b64_bn; BIGNUM *bn; } SRP_gN_cache; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(SRP_gN_cache, SRP_gN_cache, SRP_gN_cache) #define sk_SRP_gN_cache_num(sk) OPENSSL_sk_num(ossl_check_const_SRP_gN_cache_sk_type(sk)) #define sk_SRP_gN_cache_value(sk, idx) ((SRP_gN_cache *)OPENSSL_sk_value(ossl_check_const_SRP_gN_cache_sk_type(sk), (idx))) @@ -71,7 +74,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(SRP_gN_cache, SRP_gN_cache, SRP_gN_cache) #define sk_SRP_gN_cache_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRP_gN_cache) *)OPENSSL_sk_deep_copy(ossl_check_const_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_copyfunc_type(copyfunc), ossl_check_SRP_gN_cache_freefunc_type(freefunc))) #define sk_SRP_gN_cache_set_cmp_func(sk, cmp) ((sk_SRP_gN_cache_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_compfunc_type(cmp))) - +/* clang-format on */ typedef struct SRP_user_pwd_st { /* Owned by us. */ @@ -84,6 +87,7 @@ typedef struct SRP_user_pwd_st { /* Owned by us. */ char *info; } SRP_user_pwd; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(SRP_user_pwd, SRP_user_pwd, SRP_user_pwd) #define sk_SRP_user_pwd_num(sk) OPENSSL_sk_num(ossl_check_const_SRP_user_pwd_sk_type(sk)) #define sk_SRP_user_pwd_value(sk, idx) ((SRP_user_pwd *)OPENSSL_sk_value(ossl_check_const_SRP_user_pwd_sk_type(sk), (idx))) @@ -111,6 +115,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(SRP_user_pwd, SRP_user_pwd, SRP_user_pwd) #define sk_SRP_user_pwd_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRP_user_pwd) *)OPENSSL_sk_deep_copy(ossl_check_const_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_copyfunc_type(copyfunc), ossl_check_SRP_user_pwd_freefunc_type(freefunc))) #define sk_SRP_user_pwd_set_cmp_func(sk, cmp) ((sk_SRP_user_pwd_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_compfunc_type(cmp))) +/* clang-format on */ OSSL_DEPRECATEDIN_3_0 SRP_user_pwd *SRP_user_pwd_new(void); @@ -119,17 +124,17 @@ void SRP_user_pwd_free(SRP_user_pwd *user_pwd); OSSL_DEPRECATEDIN_3_0 void SRP_user_pwd_set_gN(SRP_user_pwd *user_pwd, const BIGNUM *g, - const BIGNUM *N); + const BIGNUM *N); OSSL_DEPRECATEDIN_3_0 int SRP_user_pwd_set1_ids(SRP_user_pwd *user_pwd, const char *id, - const char *info); + const char *info); OSSL_DEPRECATEDIN_3_0 int SRP_user_pwd_set0_sv(SRP_user_pwd *user_pwd, BIGNUM *s, BIGNUM *v); typedef struct SRP_VBASE_st { STACK_OF(SRP_user_pwd) *users_pwd; STACK_OF(SRP_gN_cache) *gN_cache; -/* to simulate a user */ + /* to simulate a user */ char *seed_key; const BIGNUM *default_g; const BIGNUM *default_N; @@ -143,6 +148,7 @@ typedef struct SRP_gN_st { const BIGNUM *g; const BIGNUM *N; } SRP_gN; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(SRP_gN, SRP_gN, SRP_gN) #define sk_SRP_gN_num(sk) OPENSSL_sk_num(ossl_check_const_SRP_gN_sk_type(sk)) #define sk_SRP_gN_value(sk, idx) ((SRP_gN *)OPENSSL_sk_value(ossl_check_const_SRP_gN_sk_type(sk), (idx))) @@ -170,7 +176,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(SRP_gN, SRP_gN, SRP_gN) #define sk_SRP_gN_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRP_gN) *)OPENSSL_sk_deep_copy(ossl_check_const_SRP_gN_sk_type(sk), ossl_check_SRP_gN_copyfunc_type(copyfunc), ossl_check_SRP_gN_freefunc_type(freefunc))) #define sk_SRP_gN_set_cmp_func(sk, cmp) ((sk_SRP_gN_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRP_gN_sk_type(sk), ossl_check_SRP_gN_compfunc_type(cmp))) - +/* clang-format on */ OSSL_DEPRECATEDIN_3_0 SRP_VBASE *SRP_VBASE_new(char *seed_key); @@ -188,40 +194,40 @@ SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username); OSSL_DEPRECATEDIN_3_0 char *SRP_create_verifier_ex(const char *user, const char *pass, char **salt, - char **verifier, const char *N, const char *g, - OSSL_LIB_CTX *libctx, const char *propq); + char **verifier, const char *N, const char *g, + OSSL_LIB_CTX *libctx, const char *propq); OSSL_DEPRECATEDIN_3_0 char *SRP_create_verifier(const char *user, const char *pass, char **salt, - char **verifier, const char *N, const char *g); + char **verifier, const char *N, const char *g); OSSL_DEPRECATEDIN_3_0 int SRP_create_verifier_BN_ex(const char *user, const char *pass, BIGNUM **salt, - BIGNUM **verifier, const BIGNUM *N, - const BIGNUM *g, OSSL_LIB_CTX *libctx, - const char *propq); + BIGNUM **verifier, const BIGNUM *N, + const BIGNUM *g, OSSL_LIB_CTX *libctx, + const char *propq); OSSL_DEPRECATEDIN_3_0 int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, - BIGNUM **verifier, const BIGNUM *N, - const BIGNUM *g); + BIGNUM **verifier, const BIGNUM *N, + const BIGNUM *g); -# define SRP_NO_ERROR 0 -# define SRP_ERR_VBASE_INCOMPLETE_FILE 1 -# define SRP_ERR_VBASE_BN_LIB 2 -# define SRP_ERR_OPEN_FILE 3 -# define SRP_ERR_MEMORY 4 +#define SRP_NO_ERROR 0 +#define SRP_ERR_VBASE_INCOMPLETE_FILE 1 +#define SRP_ERR_VBASE_BN_LIB 2 +#define SRP_ERR_OPEN_FILE 3 +#define SRP_ERR_MEMORY 4 -# define DB_srptype 0 -# define DB_srpverifier 1 -# define DB_srpsalt 2 -# define DB_srpid 3 -# define DB_srpgN 4 -# define DB_srpinfo 5 -# undef DB_NUMBER -# define DB_NUMBER 6 +#define DB_srptype 0 +#define DB_srpverifier 1 +#define DB_srpsalt 2 +#define DB_srpid 3 +#define DB_srpgN 4 +#define DB_srpinfo 5 +#undef DB_NUMBER +#define DB_NUMBER 6 -# define DB_SRP_INDEX 'I' -# define DB_SRP_VALID 'V' -# define DB_SRP_REVOKED 'R' -# define DB_SRP_MODIF 'v' +#define DB_SRP_INDEX 'I' +#define DB_SRP_VALID 'V' +#define DB_SRP_REVOKED 'R' +#define DB_SRP_MODIF 'v' /* see srp.c */ OSSL_DEPRECATEDIN_3_0 @@ -232,19 +238,19 @@ SRP_gN *SRP_get_default_gN(const char *id); /* server side .... */ OSSL_DEPRECATEDIN_3_0 BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u, - const BIGNUM *b, const BIGNUM *N); + const BIGNUM *b, const BIGNUM *N); OSSL_DEPRECATEDIN_3_0 BIGNUM *SRP_Calc_B_ex(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g, - const BIGNUM *v, OSSL_LIB_CTX *libctx, const char *propq); + const BIGNUM *v, OSSL_LIB_CTX *libctx, const char *propq); OSSL_DEPRECATEDIN_3_0 BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g, - const BIGNUM *v); + const BIGNUM *v); OSSL_DEPRECATEDIN_3_0 int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N); OSSL_DEPRECATEDIN_3_0 BIGNUM *SRP_Calc_u_ex(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); OSSL_DEPRECATEDIN_3_0 BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N); @@ -252,34 +258,34 @@ BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N); OSSL_DEPRECATEDIN_3_0 BIGNUM *SRP_Calc_x_ex(const BIGNUM *s, const char *user, const char *pass, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); OSSL_DEPRECATEDIN_3_0 BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass); OSSL_DEPRECATEDIN_3_0 BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g); OSSL_DEPRECATEDIN_3_0 BIGNUM *SRP_Calc_client_key_ex(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g, - const BIGNUM *x, const BIGNUM *a, const BIGNUM *u, - OSSL_LIB_CTX *libctx, const char *propq); + const BIGNUM *x, const BIGNUM *a, const BIGNUM *u, + OSSL_LIB_CTX *libctx, const char *propq); OSSL_DEPRECATEDIN_3_0 BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g, - const BIGNUM *x, const BIGNUM *a, const BIGNUM *u); + const BIGNUM *x, const BIGNUM *a, const BIGNUM *u); OSSL_DEPRECATEDIN_3_0 int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N); -# define SRP_MINIMAL_N 1024 +#define SRP_MINIMAL_N 1024 -# endif /* OPENSSL_NO_DEPRECATED_3_0 */ +#endif /* OPENSSL_NO_DEPRECATED_3_0 */ /* This method ignores the configured seed and fails for an unknown user. */ -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username); -# endif +#endif -# ifdef __cplusplus +#ifdef __cplusplus } -# endif -# endif +#endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ssl.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ssl.h index 273b8c3f4b..b4ac504729 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ssl.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ssl.h @@ -2,7 +2,7 @@ * WARNING: do not edit! * Generated by Makefile from include/openssl/ssl.h.in * - * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2026 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved * Copyright 2005 Nokia. All rights reserved. * @@ -12,42 +12,44 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_SSL_H -# define OPENSSL_SSL_H -# pragma once +#define OPENSSL_SSL_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_SSL_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_SSL_H +#endif -# include -# include -# include -# include -# include -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# include -# include -# include -# endif -# include -# include -# include -# include +#include +#include +#include +#include +#include +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#include +#include +#include +#endif +#include +#include +#include +#include -# include -# include -# include -# include -# include -# ifndef OPENSSL_NO_STDIO -# include -# endif +#include +#include +#include +#include +#include +#ifndef OPENSSL_NO_STDIO +#include +#endif -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -56,116 +58,116 @@ extern "C" { * Version 0 - initial version * Version 1 - added the optional peer certificate */ -# define SSL_SESSION_ASN1_VERSION 0x0001 +#define SSL_SESSION_ASN1_VERSION 0x0001 -# define SSL_MAX_SSL_SESSION_ID_LENGTH 32 -# define SSL_MAX_SID_CTX_LENGTH 32 +#define SSL_MAX_SSL_SESSION_ID_LENGTH 32 +#define SSL_MAX_SID_CTX_LENGTH 32 -# define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8) -# define SSL_MAX_KEY_ARG_LENGTH 8 +#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512 / 8) +#define SSL_MAX_KEY_ARG_LENGTH 8 /* SSL_MAX_MASTER_KEY_LENGTH is defined in prov_ssl.h */ /* The maximum number of encrypt/decrypt pipelines we can support */ -# define SSL_MAX_PIPELINES 32 +#define SSL_MAX_PIPELINES 32 /* text strings for the ciphers */ /* These are used to specify which ciphers to use and not to use */ -# define SSL_TXT_LOW "LOW" -# define SSL_TXT_MEDIUM "MEDIUM" -# define SSL_TXT_HIGH "HIGH" -# define SSL_TXT_FIPS "FIPS" +#define SSL_TXT_LOW "LOW" +#define SSL_TXT_MEDIUM "MEDIUM" +#define SSL_TXT_HIGH "HIGH" +#define SSL_TXT_FIPS "FIPS" -# define SSL_TXT_aNULL "aNULL" -# define SSL_TXT_eNULL "eNULL" -# define SSL_TXT_NULL "NULL" +#define SSL_TXT_aNULL "aNULL" +#define SSL_TXT_eNULL "eNULL" +#define SSL_TXT_NULL "NULL" -# define SSL_TXT_kRSA "kRSA" -# define SSL_TXT_kDHr "kDHr"/* this cipher class has been removed */ -# define SSL_TXT_kDHd "kDHd"/* this cipher class has been removed */ -# define SSL_TXT_kDH "kDH"/* this cipher class has been removed */ -# define SSL_TXT_kEDH "kEDH"/* alias for kDHE */ -# define SSL_TXT_kDHE "kDHE" -# define SSL_TXT_kECDHr "kECDHr"/* this cipher class has been removed */ -# define SSL_TXT_kECDHe "kECDHe"/* this cipher class has been removed */ -# define SSL_TXT_kECDH "kECDH"/* this cipher class has been removed */ -# define SSL_TXT_kEECDH "kEECDH"/* alias for kECDHE */ -# define SSL_TXT_kECDHE "kECDHE" -# define SSL_TXT_kPSK "kPSK" -# define SSL_TXT_kRSAPSK "kRSAPSK" -# define SSL_TXT_kECDHEPSK "kECDHEPSK" -# define SSL_TXT_kDHEPSK "kDHEPSK" -# define SSL_TXT_kGOST "kGOST" -# define SSL_TXT_kGOST18 "kGOST18" -# define SSL_TXT_kSRP "kSRP" +#define SSL_TXT_kRSA "kRSA" +#define SSL_TXT_kDHr "kDHr" /* this cipher class has been removed */ +#define SSL_TXT_kDHd "kDHd" /* this cipher class has been removed */ +#define SSL_TXT_kDH "kDH" /* this cipher class has been removed */ +#define SSL_TXT_kEDH "kEDH" /* alias for kDHE */ +#define SSL_TXT_kDHE "kDHE" +#define SSL_TXT_kECDHr "kECDHr" /* this cipher class has been removed */ +#define SSL_TXT_kECDHe "kECDHe" /* this cipher class has been removed */ +#define SSL_TXT_kECDH "kECDH" /* this cipher class has been removed */ +#define SSL_TXT_kEECDH "kEECDH" /* alias for kECDHE */ +#define SSL_TXT_kECDHE "kECDHE" +#define SSL_TXT_kPSK "kPSK" +#define SSL_TXT_kRSAPSK "kRSAPSK" +#define SSL_TXT_kECDHEPSK "kECDHEPSK" +#define SSL_TXT_kDHEPSK "kDHEPSK" +#define SSL_TXT_kGOST "kGOST" +#define SSL_TXT_kGOST18 "kGOST18" +#define SSL_TXT_kSRP "kSRP" -# define SSL_TXT_aRSA "aRSA" -# define SSL_TXT_aDSS "aDSS" -# define SSL_TXT_aDH "aDH"/* this cipher class has been removed */ -# define SSL_TXT_aECDH "aECDH"/* this cipher class has been removed */ -# define SSL_TXT_aECDSA "aECDSA" -# define SSL_TXT_aPSK "aPSK" -# define SSL_TXT_aGOST94 "aGOST94" -# define SSL_TXT_aGOST01 "aGOST01" -# define SSL_TXT_aGOST12 "aGOST12" -# define SSL_TXT_aGOST "aGOST" -# define SSL_TXT_aSRP "aSRP" +#define SSL_TXT_aRSA "aRSA" +#define SSL_TXT_aDSS "aDSS" +#define SSL_TXT_aDH "aDH" /* this cipher class has been removed */ +#define SSL_TXT_aECDH "aECDH" /* this cipher class has been removed */ +#define SSL_TXT_aECDSA "aECDSA" +#define SSL_TXT_aPSK "aPSK" +#define SSL_TXT_aGOST94 "aGOST94" +#define SSL_TXT_aGOST01 "aGOST01" +#define SSL_TXT_aGOST12 "aGOST12" +#define SSL_TXT_aGOST "aGOST" +#define SSL_TXT_aSRP "aSRP" -# define SSL_TXT_DSS "DSS" -# define SSL_TXT_DH "DH" -# define SSL_TXT_DHE "DHE"/* same as "kDHE:-ADH" */ -# define SSL_TXT_EDH "EDH"/* alias for DHE */ -# define SSL_TXT_ADH "ADH" -# define SSL_TXT_RSA "RSA" -# define SSL_TXT_ECDH "ECDH" -# define SSL_TXT_EECDH "EECDH"/* alias for ECDHE" */ -# define SSL_TXT_ECDHE "ECDHE"/* same as "kECDHE:-AECDH" */ -# define SSL_TXT_AECDH "AECDH" -# define SSL_TXT_ECDSA "ECDSA" -# define SSL_TXT_PSK "PSK" -# define SSL_TXT_SRP "SRP" +#define SSL_TXT_DSS "DSS" +#define SSL_TXT_DH "DH" +#define SSL_TXT_DHE "DHE" /* same as "kDHE:-ADH" */ +#define SSL_TXT_EDH "EDH" /* alias for DHE */ +#define SSL_TXT_ADH "ADH" +#define SSL_TXT_RSA "RSA" +#define SSL_TXT_ECDH "ECDH" +#define SSL_TXT_EECDH "EECDH" /* alias for ECDHE" */ +#define SSL_TXT_ECDHE "ECDHE" /* same as "kECDHE:-AECDH" */ +#define SSL_TXT_AECDH "AECDH" +#define SSL_TXT_ECDSA "ECDSA" +#define SSL_TXT_PSK "PSK" +#define SSL_TXT_SRP "SRP" -# define SSL_TXT_DES "DES" -# define SSL_TXT_3DES "3DES" -# define SSL_TXT_RC4 "RC4" -# define SSL_TXT_RC2 "RC2" -# define SSL_TXT_IDEA "IDEA" -# define SSL_TXT_SEED "SEED" -# define SSL_TXT_AES128 "AES128" -# define SSL_TXT_AES256 "AES256" -# define SSL_TXT_AES "AES" -# define SSL_TXT_AES_GCM "AESGCM" -# define SSL_TXT_AES_CCM "AESCCM" -# define SSL_TXT_AES_CCM_8 "AESCCM8" -# define SSL_TXT_CAMELLIA128 "CAMELLIA128" -# define SSL_TXT_CAMELLIA256 "CAMELLIA256" -# define SSL_TXT_CAMELLIA "CAMELLIA" -# define SSL_TXT_CHACHA20 "CHACHA20" -# define SSL_TXT_GOST "GOST89" -# define SSL_TXT_ARIA "ARIA" -# define SSL_TXT_ARIA_GCM "ARIAGCM" -# define SSL_TXT_ARIA128 "ARIA128" -# define SSL_TXT_ARIA256 "ARIA256" -# define SSL_TXT_GOST2012_GOST8912_GOST8912 "GOST2012-GOST8912-GOST8912" -# define SSL_TXT_CBC "CBC" +#define SSL_TXT_DES "DES" +#define SSL_TXT_3DES "3DES" +#define SSL_TXT_RC4 "RC4" +#define SSL_TXT_RC2 "RC2" +#define SSL_TXT_IDEA "IDEA" +#define SSL_TXT_SEED "SEED" +#define SSL_TXT_AES128 "AES128" +#define SSL_TXT_AES256 "AES256" +#define SSL_TXT_AES "AES" +#define SSL_TXT_AES_GCM "AESGCM" +#define SSL_TXT_AES_CCM "AESCCM" +#define SSL_TXT_AES_CCM_8 "AESCCM8" +#define SSL_TXT_CAMELLIA128 "CAMELLIA128" +#define SSL_TXT_CAMELLIA256 "CAMELLIA256" +#define SSL_TXT_CAMELLIA "CAMELLIA" +#define SSL_TXT_CHACHA20 "CHACHA20" +#define SSL_TXT_GOST "GOST89" +#define SSL_TXT_ARIA "ARIA" +#define SSL_TXT_ARIA_GCM "ARIAGCM" +#define SSL_TXT_ARIA128 "ARIA128" +#define SSL_TXT_ARIA256 "ARIA256" +#define SSL_TXT_GOST2012_GOST8912_GOST8912 "GOST2012-GOST8912-GOST8912" +#define SSL_TXT_CBC "CBC" -# define SSL_TXT_MD5 "MD5" -# define SSL_TXT_SHA1 "SHA1" -# define SSL_TXT_SHA "SHA"/* same as "SHA1" */ -# define SSL_TXT_GOST94 "GOST94" -# define SSL_TXT_GOST89MAC "GOST89MAC" -# define SSL_TXT_GOST12 "GOST12" -# define SSL_TXT_GOST89MAC12 "GOST89MAC12" -# define SSL_TXT_SHA256 "SHA256" -# define SSL_TXT_SHA384 "SHA384" +#define SSL_TXT_MD5 "MD5" +#define SSL_TXT_SHA1 "SHA1" +#define SSL_TXT_SHA "SHA" /* same as "SHA1" */ +#define SSL_TXT_GOST94 "GOST94" +#define SSL_TXT_GOST89MAC "GOST89MAC" +#define SSL_TXT_GOST12 "GOST12" +#define SSL_TXT_GOST89MAC12 "GOST89MAC12" +#define SSL_TXT_SHA256 "SHA256" +#define SSL_TXT_SHA384 "SHA384" -# define SSL_TXT_SSLV3 "SSLv3" -# define SSL_TXT_TLSV1 "TLSv1" -# define SSL_TXT_TLSV1_1 "TLSv1.1" -# define SSL_TXT_TLSV1_2 "TLSv1.2" +#define SSL_TXT_SSLV3 "SSLv3" +#define SSL_TXT_TLSV1 "TLSv1" +#define SSL_TXT_TLSV1_1 "TLSv1.1" +#define SSL_TXT_TLSV1_2 "TLSv1.2" -# define SSL_TXT_ALL "ALL" +#define SSL_TXT_ALL "ALL" /*- * COMPLEMENTOF* definitions. These identifiers are used to (de-select) @@ -181,8 +183,8 @@ extern "C" { * DEFAULT gets, as only selection is being done and no sorting as needed * for DEFAULT. */ -# define SSL_TXT_CMPALL "COMPLEMENTOFALL" -# define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT" +#define SSL_TXT_CMPALL "COMPLEMENTOFALL" +#define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT" /* * The following cipher list is used by default. It also is substituted when @@ -191,17 +193,17 @@ extern "C" { * DEPRECATED IN 3.0.0, in favor of OSSL_default_cipher_list() * Update both macro and function simultaneously */ -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define SSL_DEFAULT_CIPHER_LIST "ALL:!COMPLEMENTOFDEFAULT:!eNULL" +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define SSL_DEFAULT_CIPHER_LIST "ALL:!COMPLEMENTOFDEFAULT:!eNULL" /* * This is the default set of TLSv1.3 ciphersuites * DEPRECATED IN 3.0.0, in favor of OSSL_default_ciphersuites() * Update both macro and function simultaneously */ -# define TLS_DEFAULT_CIPHERSUITES "TLS_AES_256_GCM_SHA384:" \ - "TLS_CHACHA20_POLY1305_SHA256:" \ - "TLS_AES_128_GCM_SHA256" -# endif +#define TLS_DEFAULT_CIPHERSUITES "TLS_AES_256_GCM_SHA384:" \ + "TLS_CHACHA20_POLY1305_SHA256:" \ + "TLS_AES_128_GCM_SHA256" +#endif /* * As of OpenSSL 1.0.0, ssl_create_cipher_list() in ssl/ssl_ciph.c always * starts with a reasonable order, and all we have to do for DEFAULT is @@ -210,19 +212,19 @@ extern "C" { */ /* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ -# define SSL_SENT_SHUTDOWN 1 -# define SSL_RECEIVED_SHUTDOWN 2 +#define SSL_SENT_SHUTDOWN 1 +#define SSL_RECEIVED_SHUTDOWN 2 #ifdef __cplusplus } #endif -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif -# define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1 -# define SSL_FILETYPE_PEM X509_FILETYPE_PEM +#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1 +#define SSL_FILETYPE_PEM X509_FILETYPE_PEM /* * This is needed to stop compilers complaining about the 'struct ssl_st *' @@ -243,6 +245,7 @@ typedef struct srtp_protection_profile_st { const char *name; unsigned long id; } SRTP_PROTECTION_PROFILE; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE) #define sk_SRTP_PROTECTION_PROFILE_num(sk) OPENSSL_sk_num(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk)) #define sk_SRTP_PROTECTION_PROFILE_value(sk, idx) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_value(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk), (idx))) @@ -270,74 +273,73 @@ SKM_DEFINE_STACK_OF_INTERNAL(SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE, S #define sk_SRTP_PROTECTION_PROFILE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_deep_copy(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_copyfunc_type(copyfunc), ossl_check_SRTP_PROTECTION_PROFILE_freefunc_type(freefunc))) #define sk_SRTP_PROTECTION_PROFILE_set_cmp_func(sk, cmp) ((sk_SRTP_PROTECTION_PROFILE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp))) - +/* clang-format on */ typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data, - int len, void *arg); + int len, void *arg); typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, - STACK_OF(SSL_CIPHER) *peer_ciphers, - const SSL_CIPHER **cipher, void *arg); + STACK_OF(SSL_CIPHER) *peer_ciphers, + const SSL_CIPHER **cipher, void *arg); /* Extension context codes */ /* This extension is only allowed in TLS */ -#define SSL_EXT_TLS_ONLY 0x00001 +#define SSL_EXT_TLS_ONLY 0x00001 /* This extension is only allowed in DTLS */ -#define SSL_EXT_DTLS_ONLY 0x00002 +#define SSL_EXT_DTLS_ONLY 0x00002 /* Some extensions may be allowed in DTLS but we don't implement them for it */ -#define SSL_EXT_TLS_IMPLEMENTATION_ONLY 0x00004 +#define SSL_EXT_TLS_IMPLEMENTATION_ONLY 0x00004 /* Most extensions are not defined for SSLv3 but EXT_TYPE_renegotiate is */ -#define SSL_EXT_SSL3_ALLOWED 0x00008 +#define SSL_EXT_SSL3_ALLOWED 0x00008 /* Extension is only defined for TLS1.2 and below */ -#define SSL_EXT_TLS1_2_AND_BELOW_ONLY 0x00010 +#define SSL_EXT_TLS1_2_AND_BELOW_ONLY 0x00010 /* Extension is only defined for TLS1.3 and above */ -#define SSL_EXT_TLS1_3_ONLY 0x00020 +#define SSL_EXT_TLS1_3_ONLY 0x00020 /* Ignore this extension during parsing if we are resuming */ -#define SSL_EXT_IGNORE_ON_RESUMPTION 0x00040 -#define SSL_EXT_CLIENT_HELLO 0x00080 +#define SSL_EXT_IGNORE_ON_RESUMPTION 0x00040 +#define SSL_EXT_CLIENT_HELLO 0x00080 /* Really means TLS1.2 or below */ -#define SSL_EXT_TLS1_2_SERVER_HELLO 0x00100 -#define SSL_EXT_TLS1_3_SERVER_HELLO 0x00200 -#define SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS 0x00400 -#define SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST 0x00800 -#define SSL_EXT_TLS1_3_CERTIFICATE 0x01000 -#define SSL_EXT_TLS1_3_NEW_SESSION_TICKET 0x02000 -#define SSL_EXT_TLS1_3_CERTIFICATE_REQUEST 0x04000 -#define SSL_EXT_TLS1_3_CERTIFICATE_COMPRESSION 0x08000 +#define SSL_EXT_TLS1_2_SERVER_HELLO 0x00100 +#define SSL_EXT_TLS1_3_SERVER_HELLO 0x00200 +#define SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS 0x00400 +#define SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST 0x00800 +#define SSL_EXT_TLS1_3_CERTIFICATE 0x01000 +#define SSL_EXT_TLS1_3_NEW_SESSION_TICKET 0x02000 +#define SSL_EXT_TLS1_3_CERTIFICATE_REQUEST 0x04000 +#define SSL_EXT_TLS1_3_CERTIFICATE_COMPRESSION 0x08000 /* When sending a raw public key in a certificate message */ -#define SSL_EXT_TLS1_3_RAW_PUBLIC_KEY 0x10000 +#define SSL_EXT_TLS1_3_RAW_PUBLIC_KEY 0x10000 /* Typedefs for handling custom extensions */ typedef int (*custom_ext_add_cb)(SSL *s, unsigned int ext_type, - const unsigned char **out, size_t *outlen, - int *al, void *add_arg); + const unsigned char **out, size_t *outlen, + int *al, void *add_arg); typedef void (*custom_ext_free_cb)(SSL *s, unsigned int ext_type, - const unsigned char *out, void *add_arg); + const unsigned char *out, void *add_arg); typedef int (*custom_ext_parse_cb)(SSL *s, unsigned int ext_type, - const unsigned char *in, size_t inlen, - int *al, void *parse_arg); - + const unsigned char *in, size_t inlen, + int *al, void *parse_arg); typedef int (*SSL_custom_ext_add_cb_ex)(SSL *s, unsigned int ext_type, - unsigned int context, - const unsigned char **out, - size_t *outlen, X509 *x, - size_t chainidx, - int *al, void *add_arg); + unsigned int context, + const unsigned char **out, + size_t *outlen, X509 *x, + size_t chainidx, + int *al, void *add_arg); typedef void (*SSL_custom_ext_free_cb_ex)(SSL *s, unsigned int ext_type, - unsigned int context, - const unsigned char *out, - void *add_arg); + unsigned int context, + const unsigned char *out, + void *add_arg); typedef int (*SSL_custom_ext_parse_cb_ex)(SSL *s, unsigned int ext_type, - unsigned int context, - const unsigned char *in, - size_t inlen, X509 *x, - size_t chainidx, - int *al, void *parse_arg); + unsigned int context, + const unsigned char *in, + size_t inlen, X509 *x, + size_t chainidx, + int *al, void *parse_arg); /* Typedef for verification callback */ typedef int (*SSL_verify_cb)(int preverify_ok, X509_STORE_CTX *x509_ctx); @@ -345,96 +347,96 @@ typedef int (*SSL_verify_cb)(int preverify_ok, X509_STORE_CTX *x509_ctx); /* Typedef for SSL async callback */ typedef int (*SSL_async_callback_fn)(SSL *s, void *arg); -#define SSL_OP_BIT(n) ((uint64_t)1 << (uint64_t)n) +#define SSL_OP_BIT(n) ((uint64_t)1 << (uint64_t)n) /* * SSL/TLS connection options. */ - /* Disable Extended master secret */ -# define SSL_OP_NO_EXTENDED_MASTER_SECRET SSL_OP_BIT(0) - /* Cleanse plaintext copies of data delivered to the application */ -# define SSL_OP_CLEANSE_PLAINTEXT SSL_OP_BIT(1) - /* Allow initial connection to servers that don't support RI */ -# define SSL_OP_LEGACY_SERVER_CONNECT SSL_OP_BIT(2) - /* Enable support for Kernel TLS */ -# define SSL_OP_ENABLE_KTLS SSL_OP_BIT(3) -# define SSL_OP_TLSEXT_PADDING SSL_OP_BIT(4) -# define SSL_OP_SAFARI_ECDHE_ECDSA_BUG SSL_OP_BIT(6) -# define SSL_OP_IGNORE_UNEXPECTED_EOF SSL_OP_BIT(7) -# define SSL_OP_ALLOW_CLIENT_RENEGOTIATION SSL_OP_BIT(8) -# define SSL_OP_DISABLE_TLSEXT_CA_NAMES SSL_OP_BIT(9) - /* In TLSv1.3 allow a non-(ec)dhe based kex_mode */ -# define SSL_OP_ALLOW_NO_DHE_KEX SSL_OP_BIT(10) - /* - * Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added - * in OpenSSL 0.9.6d. Usually (depending on the application protocol) - * the workaround is not needed. Unfortunately some broken SSL/TLS - * implementations cannot handle it at all, which is why we include it - * in SSL_OP_ALL. Added in 0.9.6e - */ -# define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS SSL_OP_BIT(11) - /* DTLS options */ -# define SSL_OP_NO_QUERY_MTU SSL_OP_BIT(12) - /* Turn on Cookie Exchange (on relevant for servers) */ -# define SSL_OP_COOKIE_EXCHANGE SSL_OP_BIT(13) - /* Don't use RFC4507 ticket extension */ -# define SSL_OP_NO_TICKET SSL_OP_BIT(14) -# ifndef OPENSSL_NO_DTLS1_METHOD - /* - * Use Cisco's version identifier of DTLS_BAD_VER - * (only with deprecated DTLSv1_client_method()) - */ -# define SSL_OP_CISCO_ANYCONNECT SSL_OP_BIT(15) -# endif - /* As server, disallow session resumption on renegotiation */ -# define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION SSL_OP_BIT(16) - /* Don't use compression even if supported */ -# define SSL_OP_NO_COMPRESSION SSL_OP_BIT(17) - /* Permit unsafe legacy renegotiation */ -# define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION SSL_OP_BIT(18) - /* Disable encrypt-then-mac */ -# define SSL_OP_NO_ENCRYPT_THEN_MAC SSL_OP_BIT(19) - /* - * Enable TLSv1.3 Compatibility mode. This is on by default. A future - * version of OpenSSL may have this disabled by default. - */ -# define SSL_OP_ENABLE_MIDDLEBOX_COMPAT SSL_OP_BIT(20) - /* - * Prioritize Chacha20Poly1305 when client does. - * Modifies SSL_OP_CIPHER_SERVER_PREFERENCE - */ -# define SSL_OP_PRIORITIZE_CHACHA SSL_OP_BIT(21) - /* - * Set on servers to choose the cipher according to server's preferences. - */ -# define SSL_OP_CIPHER_SERVER_PREFERENCE SSL_OP_BIT(22) - /* - * If set, a server will allow a client to issue an SSLv3.0 version - * number as latest version supported in the premaster secret, even when - * TLSv1.0 (version 3.1) was announced in the client hello. Normally - * this is forbidden to prevent version rollback attacks. - */ -# define SSL_OP_TLS_ROLLBACK_BUG SSL_OP_BIT(23) - /* - * Switches off automatic TLSv1.3 anti-replay protection for early data. - * This is a server-side option only (no effect on the client). - */ -# define SSL_OP_NO_ANTI_REPLAY SSL_OP_BIT(24) -# define SSL_OP_NO_SSLv3 SSL_OP_BIT(25) -# define SSL_OP_NO_TLSv1 SSL_OP_BIT(26) -# define SSL_OP_NO_TLSv1_2 SSL_OP_BIT(27) -# define SSL_OP_NO_TLSv1_1 SSL_OP_BIT(28) -# define SSL_OP_NO_TLSv1_3 SSL_OP_BIT(29) -# define SSL_OP_NO_DTLSv1 SSL_OP_BIT(26) -# define SSL_OP_NO_DTLSv1_2 SSL_OP_BIT(27) - /* Disallow all renegotiation */ -# define SSL_OP_NO_RENEGOTIATION SSL_OP_BIT(30) - /* - * Make server add server-hello extension from early version of - * cryptopro draft, when GOST ciphersuite is negotiated. Required for - * interoperability with CryptoPro CSP 3.x - */ -# define SSL_OP_CRYPTOPRO_TLSEXT_BUG SSL_OP_BIT(31) +/* Disable Extended master secret */ +#define SSL_OP_NO_EXTENDED_MASTER_SECRET SSL_OP_BIT(0) +/* Cleanse plaintext copies of data delivered to the application */ +#define SSL_OP_CLEANSE_PLAINTEXT SSL_OP_BIT(1) +/* Allow initial connection to servers that don't support RI */ +#define SSL_OP_LEGACY_SERVER_CONNECT SSL_OP_BIT(2) +/* Enable support for Kernel TLS */ +#define SSL_OP_ENABLE_KTLS SSL_OP_BIT(3) +#define SSL_OP_TLSEXT_PADDING SSL_OP_BIT(4) +#define SSL_OP_SAFARI_ECDHE_ECDSA_BUG SSL_OP_BIT(6) +#define SSL_OP_IGNORE_UNEXPECTED_EOF SSL_OP_BIT(7) +#define SSL_OP_ALLOW_CLIENT_RENEGOTIATION SSL_OP_BIT(8) +#define SSL_OP_DISABLE_TLSEXT_CA_NAMES SSL_OP_BIT(9) +/* In TLSv1.3 allow a non-(ec)dhe based kex_mode */ +#define SSL_OP_ALLOW_NO_DHE_KEX SSL_OP_BIT(10) +/* + * Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added + * in OpenSSL 0.9.6d. Usually (depending on the application protocol) + * the workaround is not needed. Unfortunately some broken SSL/TLS + * implementations cannot handle it at all, which is why we include it + * in SSL_OP_ALL. Added in 0.9.6e + */ +#define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS SSL_OP_BIT(11) +/* DTLS options */ +#define SSL_OP_NO_QUERY_MTU SSL_OP_BIT(12) +/* Turn on Cookie Exchange (on relevant for servers) */ +#define SSL_OP_COOKIE_EXCHANGE SSL_OP_BIT(13) +/* Don't use RFC4507 ticket extension */ +#define SSL_OP_NO_TICKET SSL_OP_BIT(14) +#ifndef OPENSSL_NO_DTLS1_METHOD +/* + * Use Cisco's version identifier of DTLS_BAD_VER + * (only with deprecated DTLSv1_client_method()) + */ +#define SSL_OP_CISCO_ANYCONNECT SSL_OP_BIT(15) +#endif +/* As server, disallow session resumption on renegotiation */ +#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION SSL_OP_BIT(16) +/* Don't use compression even if supported */ +#define SSL_OP_NO_COMPRESSION SSL_OP_BIT(17) +/* Permit unsafe legacy renegotiation */ +#define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION SSL_OP_BIT(18) +/* Disable encrypt-then-mac */ +#define SSL_OP_NO_ENCRYPT_THEN_MAC SSL_OP_BIT(19) +/* + * Enable TLSv1.3 Compatibility mode. This is on by default. A future + * version of OpenSSL may have this disabled by default. + */ +#define SSL_OP_ENABLE_MIDDLEBOX_COMPAT SSL_OP_BIT(20) +/* + * Prioritize Chacha20Poly1305 when client does. + * Modifies SSL_OP_CIPHER_SERVER_PREFERENCE + */ +#define SSL_OP_PRIORITIZE_CHACHA SSL_OP_BIT(21) +/* + * Set on servers to choose the cipher according to server's preferences. + */ +#define SSL_OP_CIPHER_SERVER_PREFERENCE SSL_OP_BIT(22) +/* + * If set, a server will allow a client to issue an SSLv3.0 version + * number as latest version supported in the premaster secret, even when + * TLSv1.0 (version 3.1) was announced in the client hello. Normally + * this is forbidden to prevent version rollback attacks. + */ +#define SSL_OP_TLS_ROLLBACK_BUG SSL_OP_BIT(23) +/* + * Switches off automatic TLSv1.3 anti-replay protection for early data. + * This is a server-side option only (no effect on the client). + */ +#define SSL_OP_NO_ANTI_REPLAY SSL_OP_BIT(24) +#define SSL_OP_NO_SSLv3 SSL_OP_BIT(25) +#define SSL_OP_NO_TLSv1 SSL_OP_BIT(26) +#define SSL_OP_NO_TLSv1_2 SSL_OP_BIT(27) +#define SSL_OP_NO_TLSv1_1 SSL_OP_BIT(28) +#define SSL_OP_NO_TLSv1_3 SSL_OP_BIT(29) +#define SSL_OP_NO_DTLSv1 SSL_OP_BIT(26) +#define SSL_OP_NO_DTLSv1_2 SSL_OP_BIT(27) +/* Disallow all renegotiation */ +#define SSL_OP_NO_RENEGOTIATION SSL_OP_BIT(30) +/* + * Make server add server-hello extension from early version of + * cryptopro draft, when GOST ciphersuite is negotiated. Required for + * interoperability with CryptoPro CSP 3.x + */ +#define SSL_OP_CRYPTOPRO_TLSEXT_BUG SSL_OP_BIT(31) /* * Disable RFC8879 certificate compression * SSL_OP_NO_TX_CERTIFICATE_COMPRESSION: don't send compressed certificates, @@ -442,79 +444,79 @@ typedef int (*SSL_async_callback_fn)(SSL *s, void *arg); * SSL_OP_NO_RX_CERTIFICATE_COMPRESSION: don't send the extension, and * subsequently indicating that receiving is not supported */ -# define SSL_OP_NO_TX_CERTIFICATE_COMPRESSION SSL_OP_BIT(32) -# define SSL_OP_NO_RX_CERTIFICATE_COMPRESSION SSL_OP_BIT(33) - /* Enable KTLS TX zerocopy on Linux */ -# define SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE SSL_OP_BIT(34) +#define SSL_OP_NO_TX_CERTIFICATE_COMPRESSION SSL_OP_BIT(32) +#define SSL_OP_NO_RX_CERTIFICATE_COMPRESSION SSL_OP_BIT(33) +/* Enable KTLS TX zerocopy on Linux */ +#define SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE SSL_OP_BIT(34) -#define SSL_OP_PREFER_NO_DHE_KEX SSL_OP_BIT(35) +#define SSL_OP_PREFER_NO_DHE_KEX SSL_OP_BIT(35) /* * Option "collections." */ -# define SSL_OP_NO_SSL_MASK \ - ( SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 \ - | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3 ) -# define SSL_OP_NO_DTLS_MASK \ - ( SSL_OP_NO_DTLSv1 | SSL_OP_NO_DTLSv1_2 ) +#define SSL_OP_NO_SSL_MASK \ + (SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 \ + | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3) +#define SSL_OP_NO_DTLS_MASK \ + (SSL_OP_NO_DTLSv1 | SSL_OP_NO_DTLSv1_2) /* Various bug workarounds that should be rather harmless. */ -# define SSL_OP_ALL \ - ( SSL_OP_CRYPTOPRO_TLSEXT_BUG | SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS \ - | SSL_OP_TLSEXT_PADDING | SSL_OP_SAFARI_ECDHE_ECDSA_BUG ) +#define SSL_OP_ALL \ + (SSL_OP_CRYPTOPRO_TLSEXT_BUG | SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS \ + | SSL_OP_TLSEXT_PADDING | SSL_OP_SAFARI_ECDHE_ECDSA_BUG) /* * OBSOLETE OPTIONS retained for compatibility */ -# define SSL_OP_MICROSOFT_SESS_ID_BUG 0x0 -# define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x0 -# define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x0 -# define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x0 -# define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x0 -# define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x0 -# define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x0 -# define SSL_OP_TLS_D5_BUG 0x0 -# define SSL_OP_TLS_BLOCK_PADDING_BUG 0x0 -# define SSL_OP_SINGLE_ECDH_USE 0x0 -# define SSL_OP_SINGLE_DH_USE 0x0 -# define SSL_OP_EPHEMERAL_RSA 0x0 -# define SSL_OP_NO_SSLv2 0x0 -# define SSL_OP_PKCS1_CHECK_1 0x0 -# define SSL_OP_PKCS1_CHECK_2 0x0 -# define SSL_OP_NETSCAPE_CA_DN_BUG 0x0 -# define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x0 +#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x0 +#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x0 +#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x0 +#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x0 +#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x0 +#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x0 +#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x0 +#define SSL_OP_TLS_D5_BUG 0x0 +#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x0 +#define SSL_OP_SINGLE_ECDH_USE 0x0 +#define SSL_OP_SINGLE_DH_USE 0x0 +#define SSL_OP_EPHEMERAL_RSA 0x0 +#define SSL_OP_NO_SSLv2 0x0 +#define SSL_OP_PKCS1_CHECK_1 0x0 +#define SSL_OP_PKCS1_CHECK_2 0x0 +#define SSL_OP_NETSCAPE_CA_DN_BUG 0x0 +#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x0 /* * Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success * when just a single record has been written): */ -# define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001U +#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001U /* * Make it possible to retry SSL_write() with changed buffer location (buffer * contents must stay the same!); this is not the default to avoid the * misconception that non-blocking SSL_write() behaves like non-blocking * write(): */ -# define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002U +#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002U /* * Never bother the application with retries if the transport is blocking: */ -# define SSL_MODE_AUTO_RETRY 0x00000004U +#define SSL_MODE_AUTO_RETRY 0x00000004U /* Don't attempt to automatically build certificate chain */ -# define SSL_MODE_NO_AUTO_CHAIN 0x00000008U +#define SSL_MODE_NO_AUTO_CHAIN 0x00000008U /* * Save RAM by releasing read and write buffers when they're empty. (SSL3 and * TLS only.) Released buffers are freed. */ -# define SSL_MODE_RELEASE_BUFFERS 0x00000010U +#define SSL_MODE_RELEASE_BUFFERS 0x00000010U /* * Send the current time in the Random fields of the ClientHello and * ServerHello records for compatibility with hypothetical implementations * that require it. */ -# define SSL_MODE_SEND_CLIENTHELLO_TIME 0x00000020U -# define SSL_MODE_SEND_SERVERHELLO_TIME 0x00000040U +#define SSL_MODE_SEND_CLIENTHELLO_TIME 0x00000020U +#define SSL_MODE_SEND_SERVERHELLO_TIME 0x00000040U /* * Send TLS_FALLBACK_SCSV in the ClientHello. To be set only by applications * that reconnect with a downgraded protocol version; see @@ -523,11 +525,11 @@ typedef int (*SSL_async_callback_fn)(SSL *s, void *arg); * fallback retries, following the guidance in * draft-ietf-tls-downgrade-scsv-00. */ -# define SSL_MODE_SEND_FALLBACK_SCSV 0x00000080U +#define SSL_MODE_SEND_FALLBACK_SCSV 0x00000080U /* * Support Asynchronous operation */ -# define SSL_MODE_ASYNC 0x00000100U +#define SSL_MODE_ASYNC 0x00000100U /* * When using DTLS/SCTP, include the terminating zero in the label @@ -540,78 +542,78 @@ typedef int (*SSL_async_callback_fn)(SSL *s, void *arg); * - OpenSSL 1.1.0 series * - OpenSSL 1.1.1 and 1.1.1a */ -# define SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG 0x00000400U +#define SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG 0x00000400U /* Cert related flags */ /* * Many implementations ignore some aspects of the TLS standards such as * enforcing certificate chain algorithms. When this is set we enforce them. */ -# define SSL_CERT_FLAG_TLS_STRICT 0x00000001U +#define SSL_CERT_FLAG_TLS_STRICT 0x00000001U /* Suite B modes, takes same values as certificate verify flags */ -# define SSL_CERT_FLAG_SUITEB_128_LOS_ONLY 0x10000 +#define SSL_CERT_FLAG_SUITEB_128_LOS_ONLY 0x10000 /* Suite B 192 bit only mode */ -# define SSL_CERT_FLAG_SUITEB_192_LOS 0x20000 +#define SSL_CERT_FLAG_SUITEB_192_LOS 0x20000 /* Suite B 128 bit mode allowing 192 bit algorithms */ -# define SSL_CERT_FLAG_SUITEB_128_LOS 0x30000 +#define SSL_CERT_FLAG_SUITEB_128_LOS 0x30000 /* Perform all sorts of protocol violations for testing purposes */ -# define SSL_CERT_FLAG_BROKEN_PROTOCOL 0x10000000 +#define SSL_CERT_FLAG_BROKEN_PROTOCOL 0x10000000 /* Flags for building certificate chains */ /* Treat any existing certificates as untrusted CAs */ -# define SSL_BUILD_CHAIN_FLAG_UNTRUSTED 0x1 +#define SSL_BUILD_CHAIN_FLAG_UNTRUSTED 0x1 /* Don't include root CA in chain */ -# define SSL_BUILD_CHAIN_FLAG_NO_ROOT 0x2 +#define SSL_BUILD_CHAIN_FLAG_NO_ROOT 0x2 /* Just check certificates already there */ -# define SSL_BUILD_CHAIN_FLAG_CHECK 0x4 +#define SSL_BUILD_CHAIN_FLAG_CHECK 0x4 /* Ignore verification errors */ -# define SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR 0x8 +#define SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR 0x8 /* Clear verification errors from queue */ -# define SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR 0x10 +#define SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR 0x10 /* Flags returned by SSL_check_chain */ /* Certificate can be used with this session */ -# define CERT_PKEY_VALID 0x1 +#define CERT_PKEY_VALID 0x1 /* Certificate can also be used for signing */ -# define CERT_PKEY_SIGN 0x2 +#define CERT_PKEY_SIGN 0x2 /* EE certificate signing algorithm OK */ -# define CERT_PKEY_EE_SIGNATURE 0x10 +#define CERT_PKEY_EE_SIGNATURE 0x10 /* CA signature algorithms OK */ -# define CERT_PKEY_CA_SIGNATURE 0x20 +#define CERT_PKEY_CA_SIGNATURE 0x20 /* EE certificate parameters OK */ -# define CERT_PKEY_EE_PARAM 0x40 +#define CERT_PKEY_EE_PARAM 0x40 /* CA certificate parameters OK */ -# define CERT_PKEY_CA_PARAM 0x80 +#define CERT_PKEY_CA_PARAM 0x80 /* Signing explicitly allowed as opposed to SHA1 fallback */ -# define CERT_PKEY_EXPLICIT_SIGN 0x100 +#define CERT_PKEY_EXPLICIT_SIGN 0x100 /* Client CA issuer names match (always set for server cert) */ -# define CERT_PKEY_ISSUER_NAME 0x200 +#define CERT_PKEY_ISSUER_NAME 0x200 /* Cert type matches client types (always set for server cert) */ -# define CERT_PKEY_CERT_TYPE 0x400 +#define CERT_PKEY_CERT_TYPE 0x400 /* Cert chain suitable to Suite B */ -# define CERT_PKEY_SUITEB 0x800 +#define CERT_PKEY_SUITEB 0x800 /* Cert pkey valid for raw public key use */ -# define CERT_PKEY_RPK 0x1000 +#define CERT_PKEY_RPK 0x1000 -# define SSL_CONF_FLAG_CMDLINE 0x1 -# define SSL_CONF_FLAG_FILE 0x2 -# define SSL_CONF_FLAG_CLIENT 0x4 -# define SSL_CONF_FLAG_SERVER 0x8 -# define SSL_CONF_FLAG_SHOW_ERRORS 0x10 -# define SSL_CONF_FLAG_CERTIFICATE 0x20 -# define SSL_CONF_FLAG_REQUIRE_PRIVATE 0x40 +#define SSL_CONF_FLAG_CMDLINE 0x1 +#define SSL_CONF_FLAG_FILE 0x2 +#define SSL_CONF_FLAG_CLIENT 0x4 +#define SSL_CONF_FLAG_SERVER 0x8 +#define SSL_CONF_FLAG_SHOW_ERRORS 0x10 +#define SSL_CONF_FLAG_CERTIFICATE 0x20 +#define SSL_CONF_FLAG_REQUIRE_PRIVATE 0x40 /* Configuration value types */ -# define SSL_CONF_TYPE_UNKNOWN 0x0 -# define SSL_CONF_TYPE_STRING 0x1 -# define SSL_CONF_TYPE_FILE 0x2 -# define SSL_CONF_TYPE_DIR 0x3 -# define SSL_CONF_TYPE_NONE 0x4 -# define SSL_CONF_TYPE_STORE 0x5 +#define SSL_CONF_TYPE_UNKNOWN 0x0 +#define SSL_CONF_TYPE_STRING 0x1 +#define SSL_CONF_TYPE_FILE 0x2 +#define SSL_CONF_TYPE_DIR 0x3 +#define SSL_CONF_TYPE_NONE 0x4 +#define SSL_CONF_TYPE_STORE 0x5 /* Maximum length of the application-controlled segment of a a TLSv1.3 cookie */ -# define SSL_COOKIE_LENGTH 4096 +#define SSL_COOKIE_LENGTH 4096 /* * Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, they @@ -625,68 +627,68 @@ uint64_t SSL_clear_options(SSL *s, uint64_t op); uint64_t SSL_CTX_set_options(SSL_CTX *ctx, uint64_t op); uint64_t SSL_set_options(SSL *s, uint64_t op); -# define SSL_CTX_set_mode(ctx,op) \ - SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL) -# define SSL_CTX_clear_mode(ctx,op) \ - SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_MODE,(op),NULL) -# define SSL_CTX_get_mode(ctx) \ - SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL) -# define SSL_clear_mode(ssl,op) \ - SSL_ctrl((ssl),SSL_CTRL_CLEAR_MODE,(op),NULL) -# define SSL_set_mode(ssl,op) \ - SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL) -# define SSL_get_mode(ssl) \ - SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL) -# define SSL_set_mtu(ssl, mtu) \ - SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL) -# define DTLS_set_link_mtu(ssl, mtu) \ - SSL_ctrl((ssl),DTLS_CTRL_SET_LINK_MTU,(mtu),NULL) -# define DTLS_get_link_min_mtu(ssl) \ - SSL_ctrl((ssl),DTLS_CTRL_GET_LINK_MIN_MTU,0,NULL) +#define SSL_CTX_set_mode(ctx, op) \ + SSL_CTX_ctrl((ctx), SSL_CTRL_MODE, (op), NULL) +#define SSL_CTX_clear_mode(ctx, op) \ + SSL_CTX_ctrl((ctx), SSL_CTRL_CLEAR_MODE, (op), NULL) +#define SSL_CTX_get_mode(ctx) \ + SSL_CTX_ctrl((ctx), SSL_CTRL_MODE, 0, NULL) +#define SSL_clear_mode(ssl, op) \ + SSL_ctrl((ssl), SSL_CTRL_CLEAR_MODE, (op), NULL) +#define SSL_set_mode(ssl, op) \ + SSL_ctrl((ssl), SSL_CTRL_MODE, (op), NULL) +#define SSL_get_mode(ssl) \ + SSL_ctrl((ssl), SSL_CTRL_MODE, 0, NULL) +#define SSL_set_mtu(ssl, mtu) \ + SSL_ctrl((ssl), SSL_CTRL_SET_MTU, (mtu), NULL) +#define DTLS_set_link_mtu(ssl, mtu) \ + SSL_ctrl((ssl), DTLS_CTRL_SET_LINK_MTU, (mtu), NULL) +#define DTLS_get_link_min_mtu(ssl) \ + SSL_ctrl((ssl), DTLS_CTRL_GET_LINK_MIN_MTU, 0, NULL) -# define SSL_get_secure_renegotiation_support(ssl) \ - SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL) +#define SSL_get_secure_renegotiation_support(ssl) \ + SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL) -# define SSL_CTX_set_cert_flags(ctx,op) \ - SSL_CTX_ctrl((ctx),SSL_CTRL_CERT_FLAGS,(op),NULL) -# define SSL_set_cert_flags(s,op) \ - SSL_ctrl((s),SSL_CTRL_CERT_FLAGS,(op),NULL) -# define SSL_CTX_clear_cert_flags(ctx,op) \ - SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL) -# define SSL_clear_cert_flags(s,op) \ - SSL_ctrl((s),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL) +#define SSL_CTX_set_cert_flags(ctx, op) \ + SSL_CTX_ctrl((ctx), SSL_CTRL_CERT_FLAGS, (op), NULL) +#define SSL_set_cert_flags(s, op) \ + SSL_ctrl((s), SSL_CTRL_CERT_FLAGS, (op), NULL) +#define SSL_CTX_clear_cert_flags(ctx, op) \ + SSL_CTX_ctrl((ctx), SSL_CTRL_CLEAR_CERT_FLAGS, (op), NULL) +#define SSL_clear_cert_flags(s, op) \ + SSL_ctrl((s), SSL_CTRL_CLEAR_CERT_FLAGS, (op), NULL) void SSL_CTX_set_msg_callback(SSL_CTX *ctx, - void (*cb) (int write_p, int version, - int content_type, const void *buf, - size_t len, SSL *ssl, void *arg)); + void (*cb)(int write_p, int version, + int content_type, const void *buf, + size_t len, SSL *ssl, void *arg)); void SSL_set_msg_callback(SSL *ssl, - void (*cb) (int write_p, int version, - int content_type, const void *buf, - size_t len, SSL *ssl, void *arg)); -# define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) -# define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) + void (*cb)(int write_p, int version, + int content_type, const void *buf, + size_t len, SSL *ssl, void *arg)); +#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) +#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) -# define SSL_get_extms_support(s) \ - SSL_ctrl((s),SSL_CTRL_GET_EXTMS_SUPPORT,0,NULL) +#define SSL_get_extms_support(s) \ + SSL_ctrl((s), SSL_CTRL_GET_EXTMS_SUPPORT, 0, NULL) -# ifndef OPENSSL_NO_SRP +#ifndef OPENSSL_NO_SRP /* see tls_srp.c */ -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 __owur int SSL_SRP_CTX_init(SSL *s); OSSL_DEPRECATEDIN_3_0 __owur int SSL_CTX_SRP_CTX_init(SSL_CTX *ctx); OSSL_DEPRECATEDIN_3_0 int SSL_SRP_CTX_free(SSL *ctx); OSSL_DEPRECATEDIN_3_0 int SSL_CTX_SRP_CTX_free(SSL_CTX *ctx); OSSL_DEPRECATEDIN_3_0 __owur int SSL_srp_server_param_with_username(SSL *s, - int *ad); + int *ad); OSSL_DEPRECATEDIN_3_0 __owur int SRP_Calc_A_param(SSL *s); -# endif -# endif +#endif +#endif /* 100k max cert list */ -# define SSL_MAX_CERT_LIST_DEFAULT (1024*100) +#define SSL_MAX_CERT_LIST_DEFAULT (1024 * 100) -# define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20) +#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024 * 20) /* * This callback type is used inside SSL_CTX, SSL, and in the functions that @@ -700,174 +702,174 @@ OSSL_DEPRECATEDIN_3_0 __owur int SRP_Calc_A_param(SSL *s); * bytes. The callback can alter this length to be less if desired. It is * also an error for the callback to set the size to zero. */ -typedef int (*GEN_SESSION_CB) (SSL *ssl, unsigned char *id, - unsigned int *id_len); +typedef int (*GEN_SESSION_CB)(SSL *ssl, unsigned char *id, + unsigned int *id_len); -# define SSL_SESS_CACHE_OFF 0x0000 -# define SSL_SESS_CACHE_CLIENT 0x0001 -# define SSL_SESS_CACHE_SERVER 0x0002 -# define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER) -# define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080 +#define SSL_SESS_CACHE_OFF 0x0000 +#define SSL_SESS_CACHE_CLIENT 0x0001 +#define SSL_SESS_CACHE_SERVER 0x0002 +#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_SERVER) +#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080 /* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */ -# define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 -# define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200 -# define SSL_SESS_CACHE_NO_INTERNAL \ - (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE) -# define SSL_SESS_CACHE_UPDATE_TIME 0x0400 +#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 +#define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200 +#define SSL_SESS_CACHE_NO_INTERNAL \ + (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP | SSL_SESS_CACHE_NO_INTERNAL_STORE) +#define SSL_SESS_CACHE_UPDATE_TIME 0x0400 LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx); -# define SSL_CTX_sess_number(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL) -# define SSL_CTX_sess_connect(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL) -# define SSL_CTX_sess_connect_good(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL) -# define SSL_CTX_sess_connect_renegotiate(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL) -# define SSL_CTX_sess_accept(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL) -# define SSL_CTX_sess_accept_renegotiate(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL) -# define SSL_CTX_sess_accept_good(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL) -# define SSL_CTX_sess_hits(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL) -# define SSL_CTX_sess_cb_hits(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL) -# define SSL_CTX_sess_misses(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL) -# define SSL_CTX_sess_timeouts(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL) -# define SSL_CTX_sess_cache_full(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL) +#define SSL_CTX_sess_number(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_NUMBER, 0, NULL) +#define SSL_CTX_sess_connect(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_CONNECT, 0, NULL) +#define SSL_CTX_sess_connect_good(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_CONNECT_GOOD, 0, NULL) +#define SSL_CTX_sess_connect_renegotiate(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_CONNECT_RENEGOTIATE, 0, NULL) +#define SSL_CTX_sess_accept(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_ACCEPT, 0, NULL) +#define SSL_CTX_sess_accept_renegotiate(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_ACCEPT_RENEGOTIATE, 0, NULL) +#define SSL_CTX_sess_accept_good(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_ACCEPT_GOOD, 0, NULL) +#define SSL_CTX_sess_hits(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_HIT, 0, NULL) +#define SSL_CTX_sess_cb_hits(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_CB_HIT, 0, NULL) +#define SSL_CTX_sess_misses(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_MISSES, 0, NULL) +#define SSL_CTX_sess_timeouts(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_TIMEOUTS, 0, NULL) +#define SSL_CTX_sess_cache_full(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SESS_CACHE_FULL, 0, NULL) void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx, - int (*new_session_cb) (struct ssl_st *ssl, - SSL_SESSION *sess)); -int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)) (struct ssl_st *ssl, - SSL_SESSION *sess); + int (*new_session_cb)(struct ssl_st *ssl, + SSL_SESSION *sess)); +int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(struct ssl_st *ssl, + SSL_SESSION *sess); void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx, - void (*remove_session_cb) (struct ssl_ctx_st - *ctx, - SSL_SESSION *sess)); -void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)) (struct ssl_ctx_st *ctx, - SSL_SESSION *sess); + void (*remove_session_cb)(struct ssl_ctx_st + *ctx, + SSL_SESSION *sess)); +void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(struct ssl_ctx_st *ctx, + SSL_SESSION *sess); void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, - SSL_SESSION *(*get_session_cb) (struct ssl_st - *ssl, - const unsigned char - *data, int len, - int *copy)); -SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx)) (struct ssl_st *ssl, - const unsigned char *data, - int len, int *copy); + SSL_SESSION *(*get_session_cb)(struct ssl_st + *ssl, + const unsigned char + *data, + int len, + int *copy)); +SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(struct ssl_st *ssl, + const unsigned char *data, + int len, int *copy); void SSL_CTX_set_info_callback(SSL_CTX *ctx, - void (*cb) (const SSL *ssl, int type, int val)); -void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type, - int val); + void (*cb)(const SSL *ssl, int type, int val)); +void (*SSL_CTX_get_info_callback(SSL_CTX *ctx))(const SSL *ssl, int type, + int val); void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, - int (*client_cert_cb) (SSL *ssl, X509 **x509, - EVP_PKEY **pkey)); -int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx)) (SSL *ssl, X509 **x509, - EVP_PKEY **pkey); -# ifndef OPENSSL_NO_ENGINE + int (*client_cert_cb)(SSL *ssl, X509 **x509, + EVP_PKEY **pkey)); +int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509, + EVP_PKEY **pkey); +#ifndef OPENSSL_NO_ENGINE __owur int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e); -# endif +#endif void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, - int (*app_gen_cookie_cb) (SSL *ssl, - unsigned char - *cookie, - unsigned int - *cookie_len)); + int (*app_gen_cookie_cb)(SSL *ssl, + unsigned char + *cookie, + unsigned int + *cookie_len)); void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, - int (*app_verify_cookie_cb) (SSL *ssl, - const unsigned - char *cookie, - unsigned int - cookie_len)); + int (*app_verify_cookie_cb)(SSL *ssl, + const unsigned char *cookie, + unsigned int + cookie_len)); void SSL_CTX_set_stateless_cookie_generate_cb( SSL_CTX *ctx, - int (*gen_stateless_cookie_cb) (SSL *ssl, - unsigned char *cookie, - size_t *cookie_len)); + int (*gen_stateless_cookie_cb)(SSL *ssl, + unsigned char *cookie, + size_t *cookie_len)); void SSL_CTX_set_stateless_cookie_verify_cb( SSL_CTX *ctx, - int (*verify_stateless_cookie_cb) (SSL *ssl, - const unsigned char *cookie, - size_t cookie_len)); -# ifndef OPENSSL_NO_NEXTPROTONEG + int (*verify_stateless_cookie_cb)(SSL *ssl, + const unsigned char *cookie, + size_t cookie_len)); +#ifndef OPENSSL_NO_NEXTPROTONEG typedef int (*SSL_CTX_npn_advertised_cb_func)(SSL *ssl, - const unsigned char **out, - unsigned int *outlen, - void *arg); + const unsigned char **out, + unsigned int *outlen, + void *arg); void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s, - SSL_CTX_npn_advertised_cb_func cb, - void *arg); -# define SSL_CTX_set_npn_advertised_cb SSL_CTX_set_next_protos_advertised_cb + SSL_CTX_npn_advertised_cb_func cb, + void *arg); +#define SSL_CTX_set_npn_advertised_cb SSL_CTX_set_next_protos_advertised_cb typedef int (*SSL_CTX_npn_select_cb_func)(SSL *s, - unsigned char **out, - unsigned char *outlen, - const unsigned char *in, - unsigned int inlen, - void *arg); + unsigned char **out, + unsigned char *outlen, + const unsigned char *in, + unsigned int inlen, + void *arg); void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s, - SSL_CTX_npn_select_cb_func cb, - void *arg); -# define SSL_CTX_set_npn_select_cb SSL_CTX_set_next_proto_select_cb + SSL_CTX_npn_select_cb_func cb, + void *arg); +#define SSL_CTX_set_npn_select_cb SSL_CTX_set_next_proto_select_cb void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data, - unsigned *len); -# define SSL_get0_npn_negotiated SSL_get0_next_proto_negotiated -# endif + unsigned *len); +#define SSL_get0_npn_negotiated SSL_get0_next_proto_negotiated +#endif __owur int SSL_select_next_proto(unsigned char **out, unsigned char *outlen, - const unsigned char *in, unsigned int inlen, - const unsigned char *client, - unsigned int client_len); + const unsigned char *in, unsigned int inlen, + const unsigned char *client, + unsigned int client_len); -# define OPENSSL_NPN_UNSUPPORTED 0 -# define OPENSSL_NPN_NEGOTIATED 1 -# define OPENSSL_NPN_NO_OVERLAP 2 +#define OPENSSL_NPN_UNSUPPORTED 0 +#define OPENSSL_NPN_NEGOTIATED 1 +#define OPENSSL_NPN_NO_OVERLAP 2 __owur int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos, - unsigned int protos_len); + unsigned int protos_len); __owur int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos, - unsigned int protos_len); + unsigned int protos_len); typedef int (*SSL_CTX_alpn_select_cb_func)(SSL *ssl, - const unsigned char **out, - unsigned char *outlen, - const unsigned char *in, - unsigned int inlen, - void *arg); + const unsigned char **out, + unsigned char *outlen, + const unsigned char *in, + unsigned int inlen, + void *arg); void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, - SSL_CTX_alpn_select_cb_func cb, - void *arg); + SSL_CTX_alpn_select_cb_func cb, + void *arg); void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data, - unsigned int *len); + unsigned int *len); -# ifndef OPENSSL_NO_PSK +#ifndef OPENSSL_NO_PSK /* * the maximum length of the buffer given to callbacks containing the * resulting identity/psk */ -# define PSK_MAX_IDENTITY_LEN 256 -# define PSK_MAX_PSK_LEN 512 +#define PSK_MAX_IDENTITY_LEN 256 +#define PSK_MAX_PSK_LEN 512 typedef unsigned int (*SSL_psk_client_cb_func)(SSL *ssl, - const char *hint, - char *identity, - unsigned int max_identity_len, - unsigned char *psk, - unsigned int max_psk_len); + const char *hint, + char *identity, + unsigned int max_identity_len, + unsigned char *psk, + unsigned int max_psk_len); void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, SSL_psk_client_cb_func cb); void SSL_set_psk_client_callback(SSL *ssl, SSL_psk_client_cb_func cb); typedef unsigned int (*SSL_psk_server_cb_func)(SSL *ssl, - const char *identity, - unsigned char *psk, - unsigned int max_psk_len); + const char *identity, + unsigned char *psk, + unsigned int max_psk_len); void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, SSL_psk_server_cb_func cb); void SSL_set_psk_server_callback(SSL *ssl, SSL_psk_server_cb_func cb); @@ -875,78 +877,78 @@ __owur int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint __owur int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint); const char *SSL_get_psk_identity_hint(const SSL *s); const char *SSL_get_psk_identity(const SSL *s); -# endif +#endif typedef int (*SSL_psk_find_session_cb_func)(SSL *ssl, - const unsigned char *identity, - size_t identity_len, - SSL_SESSION **sess); + const unsigned char *identity, + size_t identity_len, + SSL_SESSION **sess); typedef int (*SSL_psk_use_session_cb_func)(SSL *ssl, const EVP_MD *md, - const unsigned char **id, - size_t *idlen, - SSL_SESSION **sess); + const unsigned char **id, + size_t *idlen, + SSL_SESSION **sess); void SSL_set_psk_find_session_callback(SSL *s, SSL_psk_find_session_cb_func cb); void SSL_CTX_set_psk_find_session_callback(SSL_CTX *ctx, - SSL_psk_find_session_cb_func cb); + SSL_psk_find_session_cb_func cb); void SSL_set_psk_use_session_callback(SSL *s, SSL_psk_use_session_cb_func cb); void SSL_CTX_set_psk_use_session_callback(SSL_CTX *ctx, - SSL_psk_use_session_cb_func cb); + SSL_psk_use_session_cb_func cb); /* Register callbacks to handle custom TLS Extensions for client or server. */ __owur int SSL_CTX_has_client_custom_ext(const SSL_CTX *ctx, - unsigned int ext_type); + unsigned int ext_type); __owur int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx, - unsigned int ext_type, - custom_ext_add_cb add_cb, - custom_ext_free_cb free_cb, - void *add_arg, - custom_ext_parse_cb parse_cb, - void *parse_arg); + unsigned int ext_type, + custom_ext_add_cb add_cb, + custom_ext_free_cb free_cb, + void *add_arg, + custom_ext_parse_cb parse_cb, + void *parse_arg); __owur int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx, - unsigned int ext_type, - custom_ext_add_cb add_cb, - custom_ext_free_cb free_cb, - void *add_arg, - custom_ext_parse_cb parse_cb, - void *parse_arg); + unsigned int ext_type, + custom_ext_add_cb add_cb, + custom_ext_free_cb free_cb, + void *add_arg, + custom_ext_parse_cb parse_cb, + void *parse_arg); __owur int SSL_CTX_add_custom_ext(SSL_CTX *ctx, unsigned int ext_type, - unsigned int context, - SSL_custom_ext_add_cb_ex add_cb, - SSL_custom_ext_free_cb_ex free_cb, - void *add_arg, - SSL_custom_ext_parse_cb_ex parse_cb, - void *parse_arg); + unsigned int context, + SSL_custom_ext_add_cb_ex add_cb, + SSL_custom_ext_free_cb_ex free_cb, + void *add_arg, + SSL_custom_ext_parse_cb_ex parse_cb, + void *parse_arg); __owur int SSL_extension_supported(unsigned int ext_type); -# define SSL_NOTHING 1 -# define SSL_WRITING 2 -# define SSL_READING 3 -# define SSL_X509_LOOKUP 4 -# define SSL_ASYNC_PAUSED 5 -# define SSL_ASYNC_NO_JOBS 6 -# define SSL_CLIENT_HELLO_CB 7 -# define SSL_RETRY_VERIFY 8 +#define SSL_NOTHING 1 +#define SSL_WRITING 2 +#define SSL_READING 3 +#define SSL_X509_LOOKUP 4 +#define SSL_ASYNC_PAUSED 5 +#define SSL_ASYNC_NO_JOBS 6 +#define SSL_CLIENT_HELLO_CB 7 +#define SSL_RETRY_VERIFY 8 /* These will only be used when doing non-blocking IO */ -# define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING) -# define SSL_want_read(s) (SSL_want(s) == SSL_READING) -# define SSL_want_write(s) (SSL_want(s) == SSL_WRITING) -# define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP) -# define SSL_want_retry_verify(s) (SSL_want(s) == SSL_RETRY_VERIFY) -# define SSL_want_async(s) (SSL_want(s) == SSL_ASYNC_PAUSED) -# define SSL_want_async_job(s) (SSL_want(s) == SSL_ASYNC_NO_JOBS) -# define SSL_want_client_hello_cb(s) (SSL_want(s) == SSL_CLIENT_HELLO_CB) +#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING) +#define SSL_want_read(s) (SSL_want(s) == SSL_READING) +#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING) +#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP) +#define SSL_want_retry_verify(s) (SSL_want(s) == SSL_RETRY_VERIFY) +#define SSL_want_async(s) (SSL_want(s) == SSL_ASYNC_PAUSED) +#define SSL_want_async_job(s) (SSL_want(s) == SSL_ASYNC_NO_JOBS) +#define SSL_want_client_hello_cb(s) (SSL_want(s) == SSL_CLIENT_HELLO_CB) -# define SSL_MAC_FLAG_READ_MAC_STREAM 1 -# define SSL_MAC_FLAG_WRITE_MAC_STREAM 2 -# define SSL_MAC_FLAG_READ_MAC_TLSTREE 4 -# define SSL_MAC_FLAG_WRITE_MAC_TLSTREE 8 +#define SSL_MAC_FLAG_READ_MAC_STREAM 1 +#define SSL_MAC_FLAG_WRITE_MAC_STREAM 2 +#define SSL_MAC_FLAG_READ_MAC_TLSTREE 4 +#define SSL_MAC_FLAG_WRITE_MAC_TLSTREE 8 /* * A callback for logging out TLS key material. This callback should log out @@ -980,14 +982,14 @@ uint32_t SSL_get_recv_max_early_data(const SSL *s); } #endif -# include -# include -# include /* This is mostly sslv3 with a few tweaks */ -# include /* Datagram TLS */ -# include /* Support for the use_srtp extension */ -# include +#include +#include +#include /* This is mostly sslv3 with a few tweaks */ +#include /* Datagram TLS */ +#include /* Support for the use_srtp extension */ +#include -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -995,6 +997,7 @@ extern "C" { * These need to be after the above set of includes due to a compiler bug * in VisualStudio 2015 */ +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(SSL_CIPHER, const SSL_CIPHER, SSL_CIPHER) #define sk_SSL_CIPHER_num(sk) OPENSSL_sk_num(ossl_check_const_SSL_CIPHER_sk_type(sk)) #define sk_SSL_CIPHER_value(sk, idx) ((const SSL_CIPHER *)OPENSSL_sk_value(ossl_check_const_SSL_CIPHER_sk_type(sk), (idx))) @@ -1022,26 +1025,27 @@ SKM_DEFINE_STACK_OF_INTERNAL(SSL_CIPHER, const SSL_CIPHER, SSL_CIPHER) #define sk_SSL_CIPHER_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_deep_copy(ossl_check_const_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_copyfunc_type(copyfunc), ossl_check_SSL_CIPHER_freefunc_type(freefunc))) #define sk_SSL_CIPHER_set_cmp_func(sk, cmp) ((sk_SSL_CIPHER_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_compfunc_type(cmp))) +/* clang-format on */ /* compatibility */ -# define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)(arg))) -# define SSL_get_app_data(s) (SSL_get_ex_data(s,0)) -# define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0, \ - (char *)(a))) -# define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0)) -# define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0)) -# define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0, \ - (char *)(arg))) -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define SSL_set_app_data(s, arg) (SSL_set_ex_data(s, 0, (char *)(arg))) +#define SSL_get_app_data(s) (SSL_get_ex_data(s, 0)) +#define SSL_SESSION_set_app_data(s, a) (SSL_SESSION_set_ex_data(s, 0, \ + (char *)(a))) +#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s, 0)) +#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx, 0)) +#define SSL_CTX_set_app_data(ctx, arg) (SSL_CTX_set_ex_data(ctx, 0, \ + (char *)(arg))) +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 void SSL_set_debug(SSL *s, int debug); -# endif +#endif /* TLSv1.3 KeyUpdate message types */ /* -1 used so that this is an invalid value for the on-the-wire protocol */ -#define SSL_KEY_UPDATE_NONE -1 +#define SSL_KEY_UPDATE_NONE -1 /* Values as defined for the on-the-wire protocol */ -#define SSL_KEY_UPDATE_NOT_REQUESTED 0 -#define SSL_KEY_UPDATE_REQUESTED 1 +#define SSL_KEY_UPDATE_NOT_REQUESTED 0 +#define SSL_KEY_UPDATE_REQUESTED 1 /* * The valid handshake states (one for each type message sent and one for each @@ -1120,28 +1124,28 @@ typedef enum { * SSL_CB_ACCEPT_EXIT, SSL_CB_CONNECT_LOOP and SSL_CB_CONNECT_EXIT. */ -# define SSL_ST_CONNECT 0x1000 -# define SSL_ST_ACCEPT 0x2000 +#define SSL_ST_CONNECT 0x1000 +#define SSL_ST_ACCEPT 0x2000 -# define SSL_ST_MASK 0x0FFF +#define SSL_ST_MASK 0x0FFF -# define SSL_CB_LOOP 0x01 -# define SSL_CB_EXIT 0x02 -# define SSL_CB_READ 0x04 -# define SSL_CB_WRITE 0x08 -# define SSL_CB_ALERT 0x4000/* used in callback */ -# define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ) -# define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE) -# define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP) -# define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT) -# define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP) -# define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT) -# define SSL_CB_HANDSHAKE_START 0x10 -# define SSL_CB_HANDSHAKE_DONE 0x20 +#define SSL_CB_LOOP 0x01 +#define SSL_CB_EXIT 0x02 +#define SSL_CB_READ 0x04 +#define SSL_CB_WRITE 0x08 +#define SSL_CB_ALERT 0x4000 /* used in callback */ +#define SSL_CB_READ_ALERT (SSL_CB_ALERT | SSL_CB_READ) +#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT | SSL_CB_WRITE) +#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT | SSL_CB_LOOP) +#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT | SSL_CB_EXIT) +#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT | SSL_CB_LOOP) +#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT | SSL_CB_EXIT) +#define SSL_CB_HANDSHAKE_START 0x10 +#define SSL_CB_HANDSHAKE_DONE 0x20 /* Is the SSL_connection established? */ -# define SSL_in_connect_init(a) (SSL_in_init(a) && !SSL_is_server(a)) -# define SSL_in_accept_init(a) (SSL_in_init(a) && SSL_is_server(a)) +#define SSL_in_connect_init(a) (SSL_in_init(a) && !SSL_is_server(a)) +#define SSL_in_accept_init(a) (SSL_in_init(a) && SSL_is_server(a)) int SSL_in_init(const SSL *s); int SSL_in_before(const SSL *s); int SSL_is_init_finished(const SSL *s); @@ -1150,9 +1154,9 @@ int SSL_is_init_finished(const SSL *s); * The following 3 states are kept in ssl->rlayer.rstate when reads fail, you * should not need these */ -# define SSL_ST_READ_HEADER 0xF0 -# define SSL_ST_READ_BODY 0xF1 -# define SSL_ST_READ_DONE 0xF2 +#define SSL_ST_READ_HEADER 0xF0 +#define SSL_ST_READ_BODY 0xF1 +#define SSL_ST_READ_DONE 0xF2 /*- * Obtain latest Finished message @@ -1167,408 +1171,408 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); * use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 3 options are * 'ored' with SSL_VERIFY_PEER if they are desired */ -# define SSL_VERIFY_NONE 0x00 -# define SSL_VERIFY_PEER 0x01 -# define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 -# define SSL_VERIFY_CLIENT_ONCE 0x04 -# define SSL_VERIFY_POST_HANDSHAKE 0x08 +#define SSL_VERIFY_NONE 0x00 +#define SSL_VERIFY_PEER 0x01 +#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 +#define SSL_VERIFY_CLIENT_ONCE 0x04 +#define SSL_VERIFY_POST_HANDSHAKE 0x08 -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define OpenSSL_add_ssl_algorithms() SSL_library_init() -# define SSLeay_add_ssl_algorithms() SSL_library_init() -# endif +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define OpenSSL_add_ssl_algorithms() SSL_library_init() +#define SSLeay_add_ssl_algorithms() SSL_library_init() +#endif /* More backward compatibility */ -# define SSL_get_cipher(s) \ - SSL_CIPHER_get_name(SSL_get_current_cipher(s)) -# define SSL_get_cipher_bits(s,np) \ - SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np) -# define SSL_get_cipher_version(s) \ - SSL_CIPHER_get_version(SSL_get_current_cipher(s)) -# define SSL_get_cipher_name(s) \ - SSL_CIPHER_get_name(SSL_get_current_cipher(s)) -# define SSL_get_time(a) SSL_SESSION_get_time(a) -# define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b)) -# define SSL_get_timeout(a) SSL_SESSION_get_timeout(a) -# define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b)) +#define SSL_get_cipher(s) \ + SSL_CIPHER_get_name(SSL_get_current_cipher(s)) +#define SSL_get_cipher_bits(s, np) \ + SSL_CIPHER_get_bits(SSL_get_current_cipher(s), np) +#define SSL_get_cipher_version(s) \ + SSL_CIPHER_get_version(SSL_get_current_cipher(s)) +#define SSL_get_cipher_name(s) \ + SSL_CIPHER_get_name(SSL_get_current_cipher(s)) +#define SSL_get_time(a) SSL_SESSION_get_time(a) +#define SSL_set_time(a, b) SSL_SESSION_set_time((a), (b)) +#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a) +#define SSL_set_timeout(a, b) SSL_SESSION_set_timeout((a), (b)) -# define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id) -# define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id) +#define d2i_SSL_SESSION_bio(bp, s_id) ASN1_d2i_bio_of(SSL_SESSION, SSL_SESSION_new, d2i_SSL_SESSION, bp, s_id) +#define i2d_SSL_SESSION_bio(bp, s_id) ASN1_i2d_bio_of(SSL_SESSION, i2d_SSL_SESSION, bp, s_id) DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION) -# define SSL_AD_REASON_OFFSET 1000/* offset to get SSL_R_... value - * from SSL_AD_... */ +#define SSL_AD_REASON_OFFSET 1000 /* offset to get SSL_R_... value \ + * from SSL_AD_... */ /* These alert types are for SSLv3 and TLSv1 */ -# define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY +#define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY /* fatal */ -# define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE +#define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */ -# define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC -# define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED -# define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW +#define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC +#define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED +#define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW /* fatal */ -# define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE +#define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE /* fatal */ -# define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE +#define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE /* Not for TLS */ -# define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE -# define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE -# define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE -# define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED -# define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED -# define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN +#define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE +#define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE +#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE +#define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED +#define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED +#define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN /* fatal */ -# define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER +#define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */ -# define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA +#define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */ -# define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED +#define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */ -# define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR -# define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR +#define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR +#define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR /* fatal */ -# define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION +#define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION /* fatal */ -# define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION +#define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */ -# define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY +#define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY /* fatal */ -# define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR -# define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED -# define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION -# define SSL_AD_MISSING_EXTENSION TLS13_AD_MISSING_EXTENSION -# define SSL_AD_CERTIFICATE_REQUIRED TLS13_AD_CERTIFICATE_REQUIRED -# define SSL_AD_UNSUPPORTED_EXTENSION TLS1_AD_UNSUPPORTED_EXTENSION -# define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE -# define SSL_AD_UNRECOGNIZED_NAME TLS1_AD_UNRECOGNIZED_NAME -# define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE -# define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE +#define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR +#define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED +#define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION +#define SSL_AD_MISSING_EXTENSION TLS13_AD_MISSING_EXTENSION +#define SSL_AD_CERTIFICATE_REQUIRED TLS13_AD_CERTIFICATE_REQUIRED +#define SSL_AD_UNSUPPORTED_EXTENSION TLS1_AD_UNSUPPORTED_EXTENSION +#define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE +#define SSL_AD_UNRECOGNIZED_NAME TLS1_AD_UNRECOGNIZED_NAME +#define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE +#define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE /* fatal */ -# define SSL_AD_UNKNOWN_PSK_IDENTITY TLS1_AD_UNKNOWN_PSK_IDENTITY +#define SSL_AD_UNKNOWN_PSK_IDENTITY TLS1_AD_UNKNOWN_PSK_IDENTITY /* fatal */ -# define SSL_AD_INAPPROPRIATE_FALLBACK TLS1_AD_INAPPROPRIATE_FALLBACK -# define SSL_AD_NO_APPLICATION_PROTOCOL TLS1_AD_NO_APPLICATION_PROTOCOL -# define SSL_ERROR_NONE 0 -# define SSL_ERROR_SSL 1 -# define SSL_ERROR_WANT_READ 2 -# define SSL_ERROR_WANT_WRITE 3 -# define SSL_ERROR_WANT_X509_LOOKUP 4 -# define SSL_ERROR_SYSCALL 5/* look at error stack/return - * value/errno */ -# define SSL_ERROR_ZERO_RETURN 6 -# define SSL_ERROR_WANT_CONNECT 7 -# define SSL_ERROR_WANT_ACCEPT 8 -# define SSL_ERROR_WANT_ASYNC 9 -# define SSL_ERROR_WANT_ASYNC_JOB 10 -# define SSL_ERROR_WANT_CLIENT_HELLO_CB 11 -# define SSL_ERROR_WANT_RETRY_VERIFY 12 +#define SSL_AD_INAPPROPRIATE_FALLBACK TLS1_AD_INAPPROPRIATE_FALLBACK +#define SSL_AD_NO_APPLICATION_PROTOCOL TLS1_AD_NO_APPLICATION_PROTOCOL +#define SSL_ERROR_NONE 0 +#define SSL_ERROR_SSL 1 +#define SSL_ERROR_WANT_READ 2 +#define SSL_ERROR_WANT_WRITE 3 +#define SSL_ERROR_WANT_X509_LOOKUP 4 +#define SSL_ERROR_SYSCALL 5 /* look at error stack/return \ + * value/errno */ +#define SSL_ERROR_ZERO_RETURN 6 +#define SSL_ERROR_WANT_CONNECT 7 +#define SSL_ERROR_WANT_ACCEPT 8 +#define SSL_ERROR_WANT_ASYNC 9 +#define SSL_ERROR_WANT_ASYNC_JOB 10 +#define SSL_ERROR_WANT_CLIENT_HELLO_CB 11 +#define SSL_ERROR_WANT_RETRY_VERIFY 12 -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define SSL_CTRL_SET_TMP_DH 3 -# define SSL_CTRL_SET_TMP_ECDH 4 -# define SSL_CTRL_SET_TMP_DH_CB 6 -# endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define SSL_CTRL_SET_TMP_DH 3 +#define SSL_CTRL_SET_TMP_ECDH 4 +#define SSL_CTRL_SET_TMP_DH_CB 6 +#endif -# define SSL_CTRL_GET_CLIENT_CERT_REQUEST 9 -# define SSL_CTRL_GET_NUM_RENEGOTIATIONS 10 -# define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 11 -# define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 12 -# define SSL_CTRL_GET_FLAGS 13 -# define SSL_CTRL_EXTRA_CHAIN_CERT 14 -# define SSL_CTRL_SET_MSG_CALLBACK 15 -# define SSL_CTRL_SET_MSG_CALLBACK_ARG 16 +#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 9 +#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 10 +#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 11 +#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 12 +#define SSL_CTRL_GET_FLAGS 13 +#define SSL_CTRL_EXTRA_CHAIN_CERT 14 +#define SSL_CTRL_SET_MSG_CALLBACK 15 +#define SSL_CTRL_SET_MSG_CALLBACK_ARG 16 /* only applies to datagram connections */ -# define SSL_CTRL_SET_MTU 17 +#define SSL_CTRL_SET_MTU 17 /* Stats */ -# define SSL_CTRL_SESS_NUMBER 20 -# define SSL_CTRL_SESS_CONNECT 21 -# define SSL_CTRL_SESS_CONNECT_GOOD 22 -# define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23 -# define SSL_CTRL_SESS_ACCEPT 24 -# define SSL_CTRL_SESS_ACCEPT_GOOD 25 -# define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26 -# define SSL_CTRL_SESS_HIT 27 -# define SSL_CTRL_SESS_CB_HIT 28 -# define SSL_CTRL_SESS_MISSES 29 -# define SSL_CTRL_SESS_TIMEOUTS 30 -# define SSL_CTRL_SESS_CACHE_FULL 31 -# define SSL_CTRL_MODE 33 -# define SSL_CTRL_GET_READ_AHEAD 40 -# define SSL_CTRL_SET_READ_AHEAD 41 -# define SSL_CTRL_SET_SESS_CACHE_SIZE 42 -# define SSL_CTRL_GET_SESS_CACHE_SIZE 43 -# define SSL_CTRL_SET_SESS_CACHE_MODE 44 -# define SSL_CTRL_GET_SESS_CACHE_MODE 45 -# define SSL_CTRL_GET_MAX_CERT_LIST 50 -# define SSL_CTRL_SET_MAX_CERT_LIST 51 -# define SSL_CTRL_SET_MAX_SEND_FRAGMENT 52 +#define SSL_CTRL_SESS_NUMBER 20 +#define SSL_CTRL_SESS_CONNECT 21 +#define SSL_CTRL_SESS_CONNECT_GOOD 22 +#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23 +#define SSL_CTRL_SESS_ACCEPT 24 +#define SSL_CTRL_SESS_ACCEPT_GOOD 25 +#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26 +#define SSL_CTRL_SESS_HIT 27 +#define SSL_CTRL_SESS_CB_HIT 28 +#define SSL_CTRL_SESS_MISSES 29 +#define SSL_CTRL_SESS_TIMEOUTS 30 +#define SSL_CTRL_SESS_CACHE_FULL 31 +#define SSL_CTRL_MODE 33 +#define SSL_CTRL_GET_READ_AHEAD 40 +#define SSL_CTRL_SET_READ_AHEAD 41 +#define SSL_CTRL_SET_SESS_CACHE_SIZE 42 +#define SSL_CTRL_GET_SESS_CACHE_SIZE 43 +#define SSL_CTRL_SET_SESS_CACHE_MODE 44 +#define SSL_CTRL_GET_SESS_CACHE_MODE 45 +#define SSL_CTRL_GET_MAX_CERT_LIST 50 +#define SSL_CTRL_SET_MAX_CERT_LIST 51 +#define SSL_CTRL_SET_MAX_SEND_FRAGMENT 52 /* see tls1.h for macros based on these */ -# define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53 -# define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54 -# define SSL_CTRL_SET_TLSEXT_HOSTNAME 55 -# define SSL_CTRL_SET_TLSEXT_DEBUG_CB 56 -# define SSL_CTRL_SET_TLSEXT_DEBUG_ARG 57 -# define SSL_CTRL_GET_TLSEXT_TICKET_KEYS 58 -# define SSL_CTRL_SET_TLSEXT_TICKET_KEYS 59 +#define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53 +#define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54 +#define SSL_CTRL_SET_TLSEXT_HOSTNAME 55 +#define SSL_CTRL_SET_TLSEXT_DEBUG_CB 56 +#define SSL_CTRL_SET_TLSEXT_DEBUG_ARG 57 +#define SSL_CTRL_GET_TLSEXT_TICKET_KEYS 58 +#define SSL_CTRL_SET_TLSEXT_TICKET_KEYS 59 /*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT 60 */ /*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB 61 */ /*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG 62 */ -# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB 63 -# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG 64 -# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE 65 -# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS 66 -# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS 67 -# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS 68 -# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS 69 -# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP 70 -# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP 71 -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB 72 -# endif -# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB 75 -# define SSL_CTRL_SET_SRP_VERIFY_PARAM_CB 76 -# define SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB 77 -# define SSL_CTRL_SET_SRP_ARG 78 -# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME 79 -# define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH 80 -# define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD 81 -# define DTLS_CTRL_GET_TIMEOUT 73 -# define DTLS_CTRL_HANDLE_TIMEOUT 74 -# define SSL_CTRL_GET_RI_SUPPORT 76 -# define SSL_CTRL_CLEAR_MODE 78 -# define SSL_CTRL_SET_NOT_RESUMABLE_SESS_CB 79 -# define SSL_CTRL_GET_EXTRA_CHAIN_CERTS 82 -# define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS 83 -# define SSL_CTRL_CHAIN 88 -# define SSL_CTRL_CHAIN_CERT 89 -# define SSL_CTRL_GET_GROUPS 90 -# define SSL_CTRL_SET_GROUPS 91 -# define SSL_CTRL_SET_GROUPS_LIST 92 -# define SSL_CTRL_GET_SHARED_GROUP 93 -# define SSL_CTRL_SET_SIGALGS 97 -# define SSL_CTRL_SET_SIGALGS_LIST 98 -# define SSL_CTRL_CERT_FLAGS 99 -# define SSL_CTRL_CLEAR_CERT_FLAGS 100 -# define SSL_CTRL_SET_CLIENT_SIGALGS 101 -# define SSL_CTRL_SET_CLIENT_SIGALGS_LIST 102 -# define SSL_CTRL_GET_CLIENT_CERT_TYPES 103 -# define SSL_CTRL_SET_CLIENT_CERT_TYPES 104 -# define SSL_CTRL_BUILD_CERT_CHAIN 105 -# define SSL_CTRL_SET_VERIFY_CERT_STORE 106 -# define SSL_CTRL_SET_CHAIN_CERT_STORE 107 -# define SSL_CTRL_GET_PEER_SIGNATURE_NID 108 -# define SSL_CTRL_GET_PEER_TMP_KEY 109 -# define SSL_CTRL_GET_RAW_CIPHERLIST 110 -# define SSL_CTRL_GET_EC_POINT_FORMATS 111 -# define SSL_CTRL_GET_CHAIN_CERTS 115 -# define SSL_CTRL_SELECT_CURRENT_CERT 116 -# define SSL_CTRL_SET_CURRENT_CERT 117 -# define SSL_CTRL_SET_DH_AUTO 118 -# define DTLS_CTRL_SET_LINK_MTU 120 -# define DTLS_CTRL_GET_LINK_MIN_MTU 121 -# define SSL_CTRL_GET_EXTMS_SUPPORT 122 -# define SSL_CTRL_SET_MIN_PROTO_VERSION 123 -# define SSL_CTRL_SET_MAX_PROTO_VERSION 124 -# define SSL_CTRL_SET_SPLIT_SEND_FRAGMENT 125 -# define SSL_CTRL_SET_MAX_PIPELINES 126 -# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE 127 -# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB 128 -# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG 129 -# define SSL_CTRL_GET_MIN_PROTO_VERSION 130 -# define SSL_CTRL_GET_MAX_PROTO_VERSION 131 -# define SSL_CTRL_GET_SIGNATURE_NID 132 -# define SSL_CTRL_GET_TMP_KEY 133 -# define SSL_CTRL_GET_NEGOTIATED_GROUP 134 -# define SSL_CTRL_GET_IANA_GROUPS 135 -# define SSL_CTRL_SET_RETRY_VERIFY 136 -# define SSL_CTRL_GET_VERIFY_CERT_STORE 137 -# define SSL_CTRL_GET_CHAIN_CERT_STORE 138 -# define SSL_CTRL_GET0_IMPLEMENTED_GROUPS 139 -# define SSL_CTRL_GET_SIGNATURE_NAME 140 -# define SSL_CTRL_GET_PEER_SIGNATURE_NAME 141 -# define SSL_CERT_SET_FIRST 1 -# define SSL_CERT_SET_NEXT 2 -# define SSL_CERT_SET_SERVER 3 -# define DTLSv1_get_timeout(ssl, arg) \ - SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)(arg)) -# define DTLSv1_handle_timeout(ssl) \ - SSL_ctrl(ssl,DTLS_CTRL_HANDLE_TIMEOUT,0, NULL) -# define SSL_num_renegotiations(ssl) \ - SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL) -# define SSL_clear_num_renegotiations(ssl) \ - SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL) -# define SSL_total_renegotiations(ssl) \ - SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL) -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define SSL_CTX_set_tmp_dh(ctx,dh) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)(dh)) -# endif -# define SSL_CTX_set_dh_auto(ctx, onoff) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_DH_AUTO,onoff,NULL) -# define SSL_set_dh_auto(s, onoff) \ - SSL_ctrl(s,SSL_CTRL_SET_DH_AUTO,onoff,NULL) -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define SSL_set_tmp_dh(ssl,dh) \ - SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)(dh)) -# endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh)) -# define SSL_set_tmp_ecdh(ssl,ecdh) \ - SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh)) -# endif -# define SSL_CTX_add_extra_chain_cert(ctx,x509) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)(x509)) -# define SSL_CTX_get_extra_chain_certs(ctx,px509) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,0,px509) -# define SSL_CTX_get_extra_chain_certs_only(ctx,px509) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,1,px509) -# define SSL_CTX_clear_extra_chain_certs(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS,0,NULL) -# define SSL_CTX_set0_chain(ctx,sk) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,0,(char *)(sk)) -# define SSL_CTX_set1_chain(ctx,sk) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,1,(char *)(sk)) -# define SSL_CTX_add0_chain_cert(ctx,x509) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,0,(char *)(x509)) -# define SSL_CTX_add1_chain_cert(ctx,x509) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,1,(char *)(x509)) -# define SSL_CTX_get0_chain_certs(ctx,px509) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERTS,0,px509) -# define SSL_CTX_clear_chain_certs(ctx) \ - SSL_CTX_set0_chain(ctx,NULL) -# define SSL_CTX_build_cert_chain(ctx, flags) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL) -# define SSL_CTX_select_current_cert(ctx,x509) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509)) -# define SSL_CTX_set_current_cert(ctx, op) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CURRENT_CERT, op, NULL) -# define SSL_CTX_set0_verify_cert_store(ctx,st) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st)) -# define SSL_CTX_set1_verify_cert_store(ctx,st) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st)) -# define SSL_CTX_get0_verify_cert_store(ctx,st) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_GET_VERIFY_CERT_STORE,0,(char *)(st)) -# define SSL_CTX_set0_chain_cert_store(ctx,st) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st)) -# define SSL_CTX_set1_chain_cert_store(ctx,st) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st)) -# define SSL_CTX_get0_chain_cert_store(ctx,st) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERT_STORE,0,(char *)(st)) -# define SSL_set0_chain(s,sk) \ - SSL_ctrl(s,SSL_CTRL_CHAIN,0,(char *)(sk)) -# define SSL_set1_chain(s,sk) \ - SSL_ctrl(s,SSL_CTRL_CHAIN,1,(char *)(sk)) -# define SSL_add0_chain_cert(s,x509) \ - SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,0,(char *)(x509)) -# define SSL_add1_chain_cert(s,x509) \ - SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,1,(char *)(x509)) -# define SSL_get0_chain_certs(s,px509) \ - SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERTS,0,px509) -# define SSL_clear_chain_certs(s) \ - SSL_set0_chain(s,NULL) -# define SSL_build_cert_chain(s, flags) \ - SSL_ctrl(s,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL) -# define SSL_select_current_cert(s,x509) \ - SSL_ctrl(s,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509)) -# define SSL_set_current_cert(s,op) \ - SSL_ctrl(s,SSL_CTRL_SET_CURRENT_CERT, op, NULL) -# define SSL_set0_verify_cert_store(s,st) \ - SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st)) -# define SSL_set1_verify_cert_store(s,st) \ - SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st)) -#define SSL_get0_verify_cert_store(s,st) \ - SSL_ctrl(s,SSL_CTRL_GET_VERIFY_CERT_STORE,0,(char *)(st)) -# define SSL_set0_chain_cert_store(s,st) \ - SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st)) -# define SSL_set1_chain_cert_store(s,st) \ - SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st)) -#define SSL_get0_chain_cert_store(s,st) \ - SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERT_STORE,0,(char *)(st)) +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB 63 +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG 64 +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE 65 +#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS 66 +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS 67 +#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS 68 +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS 69 +#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP 70 +#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP 71 +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB 72 +#endif +#define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB 75 +#define SSL_CTRL_SET_SRP_VERIFY_PARAM_CB 76 +#define SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB 77 +#define SSL_CTRL_SET_SRP_ARG 78 +#define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME 79 +#define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH 80 +#define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD 81 +#define DTLS_CTRL_GET_TIMEOUT 73 +#define DTLS_CTRL_HANDLE_TIMEOUT 74 +#define SSL_CTRL_GET_RI_SUPPORT 76 +#define SSL_CTRL_CLEAR_MODE 78 +#define SSL_CTRL_SET_NOT_RESUMABLE_SESS_CB 79 +#define SSL_CTRL_GET_EXTRA_CHAIN_CERTS 82 +#define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS 83 +#define SSL_CTRL_CHAIN 88 +#define SSL_CTRL_CHAIN_CERT 89 +#define SSL_CTRL_GET_GROUPS 90 +#define SSL_CTRL_SET_GROUPS 91 +#define SSL_CTRL_SET_GROUPS_LIST 92 +#define SSL_CTRL_GET_SHARED_GROUP 93 +#define SSL_CTRL_SET_SIGALGS 97 +#define SSL_CTRL_SET_SIGALGS_LIST 98 +#define SSL_CTRL_CERT_FLAGS 99 +#define SSL_CTRL_CLEAR_CERT_FLAGS 100 +#define SSL_CTRL_SET_CLIENT_SIGALGS 101 +#define SSL_CTRL_SET_CLIENT_SIGALGS_LIST 102 +#define SSL_CTRL_GET_CLIENT_CERT_TYPES 103 +#define SSL_CTRL_SET_CLIENT_CERT_TYPES 104 +#define SSL_CTRL_BUILD_CERT_CHAIN 105 +#define SSL_CTRL_SET_VERIFY_CERT_STORE 106 +#define SSL_CTRL_SET_CHAIN_CERT_STORE 107 +#define SSL_CTRL_GET_PEER_SIGNATURE_NID 108 +#define SSL_CTRL_GET_PEER_TMP_KEY 109 +#define SSL_CTRL_GET_RAW_CIPHERLIST 110 +#define SSL_CTRL_GET_EC_POINT_FORMATS 111 +#define SSL_CTRL_GET_CHAIN_CERTS 115 +#define SSL_CTRL_SELECT_CURRENT_CERT 116 +#define SSL_CTRL_SET_CURRENT_CERT 117 +#define SSL_CTRL_SET_DH_AUTO 118 +#define DTLS_CTRL_SET_LINK_MTU 120 +#define DTLS_CTRL_GET_LINK_MIN_MTU 121 +#define SSL_CTRL_GET_EXTMS_SUPPORT 122 +#define SSL_CTRL_SET_MIN_PROTO_VERSION 123 +#define SSL_CTRL_SET_MAX_PROTO_VERSION 124 +#define SSL_CTRL_SET_SPLIT_SEND_FRAGMENT 125 +#define SSL_CTRL_SET_MAX_PIPELINES 126 +#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE 127 +#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB 128 +#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG 129 +#define SSL_CTRL_GET_MIN_PROTO_VERSION 130 +#define SSL_CTRL_GET_MAX_PROTO_VERSION 131 +#define SSL_CTRL_GET_SIGNATURE_NID 132 +#define SSL_CTRL_GET_TMP_KEY 133 +#define SSL_CTRL_GET_NEGOTIATED_GROUP 134 +#define SSL_CTRL_GET_IANA_GROUPS 135 +#define SSL_CTRL_SET_RETRY_VERIFY 136 +#define SSL_CTRL_GET_VERIFY_CERT_STORE 137 +#define SSL_CTRL_GET_CHAIN_CERT_STORE 138 +#define SSL_CTRL_GET0_IMPLEMENTED_GROUPS 139 +#define SSL_CTRL_GET_SIGNATURE_NAME 140 +#define SSL_CTRL_GET_PEER_SIGNATURE_NAME 141 +#define SSL_CERT_SET_FIRST 1 +#define SSL_CERT_SET_NEXT 2 +#define SSL_CERT_SET_SERVER 3 +#define DTLSv1_get_timeout(ssl, arg) \ + SSL_ctrl(ssl, DTLS_CTRL_GET_TIMEOUT, 0, (void *)(arg)) +#define DTLSv1_handle_timeout(ssl) \ + SSL_ctrl(ssl, DTLS_CTRL_HANDLE_TIMEOUT, 0, NULL) +#define SSL_num_renegotiations(ssl) \ + SSL_ctrl((ssl), SSL_CTRL_GET_NUM_RENEGOTIATIONS, 0, NULL) +#define SSL_clear_num_renegotiations(ssl) \ + SSL_ctrl((ssl), SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS, 0, NULL) +#define SSL_total_renegotiations(ssl) \ + SSL_ctrl((ssl), SSL_CTRL_GET_TOTAL_RENEGOTIATIONS, 0, NULL) +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define SSL_CTX_set_tmp_dh(ctx, dh) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, (char *)(dh)) +#endif +#define SSL_CTX_set_dh_auto(ctx, onoff) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_DH_AUTO, onoff, NULL) +#define SSL_set_dh_auto(s, onoff) \ + SSL_ctrl(s, SSL_CTRL_SET_DH_AUTO, onoff, NULL) +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define SSL_set_tmp_dh(ssl, dh) \ + SSL_ctrl(ssl, SSL_CTRL_SET_TMP_DH, 0, (char *)(dh)) +#endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define SSL_CTX_set_tmp_ecdh(ctx, ecdh) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, (char *)(ecdh)) +#define SSL_set_tmp_ecdh(ssl, ecdh) \ + SSL_ctrl(ssl, SSL_CTRL_SET_TMP_ECDH, 0, (char *)(ecdh)) +#endif +#define SSL_CTX_add_extra_chain_cert(ctx, x509) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, (char *)(x509)) +#define SSL_CTX_get_extra_chain_certs(ctx, px509) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_EXTRA_CHAIN_CERTS, 0, px509) +#define SSL_CTX_get_extra_chain_certs_only(ctx, px509) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_EXTRA_CHAIN_CERTS, 1, px509) +#define SSL_CTX_clear_extra_chain_certs(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS, 0, NULL) +#define SSL_CTX_set0_chain(ctx, sk) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_CHAIN, 0, (char *)(sk)) +#define SSL_CTX_set1_chain(ctx, sk) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_CHAIN, 1, (char *)(sk)) +#define SSL_CTX_add0_chain_cert(ctx, x509) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_CHAIN_CERT, 0, (char *)(x509)) +#define SSL_CTX_add1_chain_cert(ctx, x509) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_CHAIN_CERT, 1, (char *)(x509)) +#define SSL_CTX_get0_chain_certs(ctx, px509) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_CHAIN_CERTS, 0, px509) +#define SSL_CTX_clear_chain_certs(ctx) \ + SSL_CTX_set0_chain(ctx, NULL) +#define SSL_CTX_build_cert_chain(ctx, flags) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL) +#define SSL_CTX_select_current_cert(ctx, x509) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SELECT_CURRENT_CERT, 0, (char *)(x509)) +#define SSL_CTX_set_current_cert(ctx, op) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_CURRENT_CERT, op, NULL) +#define SSL_CTX_set0_verify_cert_store(ctx, st) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_VERIFY_CERT_STORE, 0, (char *)(st)) +#define SSL_CTX_set1_verify_cert_store(ctx, st) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_VERIFY_CERT_STORE, 1, (char *)(st)) +#define SSL_CTX_get0_verify_cert_store(ctx, st) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_VERIFY_CERT_STORE, 0, (char *)(st)) +#define SSL_CTX_set0_chain_cert_store(ctx, st) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_CHAIN_CERT_STORE, 0, (char *)(st)) +#define SSL_CTX_set1_chain_cert_store(ctx, st) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_CHAIN_CERT_STORE, 1, (char *)(st)) +#define SSL_CTX_get0_chain_cert_store(ctx, st) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_CHAIN_CERT_STORE, 0, (char *)(st)) +#define SSL_set0_chain(s, sk) \ + SSL_ctrl(s, SSL_CTRL_CHAIN, 0, (char *)(sk)) +#define SSL_set1_chain(s, sk) \ + SSL_ctrl(s, SSL_CTRL_CHAIN, 1, (char *)(sk)) +#define SSL_add0_chain_cert(s, x509) \ + SSL_ctrl(s, SSL_CTRL_CHAIN_CERT, 0, (char *)(x509)) +#define SSL_add1_chain_cert(s, x509) \ + SSL_ctrl(s, SSL_CTRL_CHAIN_CERT, 1, (char *)(x509)) +#define SSL_get0_chain_certs(s, px509) \ + SSL_ctrl(s, SSL_CTRL_GET_CHAIN_CERTS, 0, px509) +#define SSL_clear_chain_certs(s) \ + SSL_set0_chain(s, NULL) +#define SSL_build_cert_chain(s, flags) \ + SSL_ctrl(s, SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL) +#define SSL_select_current_cert(s, x509) \ + SSL_ctrl(s, SSL_CTRL_SELECT_CURRENT_CERT, 0, (char *)(x509)) +#define SSL_set_current_cert(s, op) \ + SSL_ctrl(s, SSL_CTRL_SET_CURRENT_CERT, op, NULL) +#define SSL_set0_verify_cert_store(s, st) \ + SSL_ctrl(s, SSL_CTRL_SET_VERIFY_CERT_STORE, 0, (char *)(st)) +#define SSL_set1_verify_cert_store(s, st) \ + SSL_ctrl(s, SSL_CTRL_SET_VERIFY_CERT_STORE, 1, (char *)(st)) +#define SSL_get0_verify_cert_store(s, st) \ + SSL_ctrl(s, SSL_CTRL_GET_VERIFY_CERT_STORE, 0, (char *)(st)) +#define SSL_set0_chain_cert_store(s, st) \ + SSL_ctrl(s, SSL_CTRL_SET_CHAIN_CERT_STORE, 0, (char *)(st)) +#define SSL_set1_chain_cert_store(s, st) \ + SSL_ctrl(s, SSL_CTRL_SET_CHAIN_CERT_STORE, 1, (char *)(st)) +#define SSL_get0_chain_cert_store(s, st) \ + SSL_ctrl(s, SSL_CTRL_GET_CHAIN_CERT_STORE, 0, (char *)(st)) -# define SSL_get1_groups(s, glist) \ - SSL_ctrl(s,SSL_CTRL_GET_GROUPS,0,(int*)(glist)) -# define SSL_get0_iana_groups(s, plst) \ - SSL_ctrl(s,SSL_CTRL_GET_IANA_GROUPS,0,(uint16_t **)(plst)) -# define SSL_CTX_set1_groups(ctx, glist, glistlen) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS,glistlen,(int *)(glist)) -# define SSL_CTX_set1_groups_list(ctx, s) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(s)) -# define SSL_CTX_get0_implemented_groups(ctx, all, out) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_GET0_IMPLEMENTED_GROUPS, all, \ +#define SSL_get1_groups(s, glist) \ + SSL_ctrl(s, SSL_CTRL_GET_GROUPS, 0, (int *)(glist)) +#define SSL_get0_iana_groups(s, plst) \ + SSL_ctrl(s, SSL_CTRL_GET_IANA_GROUPS, 0, (uint16_t **)(plst)) +#define SSL_CTX_set1_groups(ctx, glist, glistlen) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_GROUPS, glistlen, (int *)(glist)) +#define SSL_CTX_set1_groups_list(ctx, s) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_GROUPS_LIST, 0, (char *)(s)) +#define SSL_CTX_get0_implemented_groups(ctx, all, out) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET0_IMPLEMENTED_GROUPS, all, \ (STACK_OF(OPENSSL_CSTRING) *)(out)) -# define SSL_set1_groups(s, glist, glistlen) \ - SSL_ctrl(s,SSL_CTRL_SET_GROUPS,glistlen,(char *)(glist)) -# define SSL_set1_groups_list(s, str) \ - SSL_ctrl(s,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(str)) -# define SSL_get_shared_group(s, n) \ - SSL_ctrl(s,SSL_CTRL_GET_SHARED_GROUP,n,NULL) -# define SSL_get_negotiated_group(s) \ - SSL_ctrl(s,SSL_CTRL_GET_NEGOTIATED_GROUP,0,NULL) -# define SSL_CTX_set1_sigalgs(ctx, slist, slistlen) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist)) -# define SSL_CTX_set1_sigalgs_list(ctx, s) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(s)) -# define SSL_set1_sigalgs(s, slist, slistlen) \ - SSL_ctrl(s,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist)) -# define SSL_set1_sigalgs_list(s, str) \ - SSL_ctrl(s,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(str)) -# define SSL_CTX_set1_client_sigalgs(ctx, slist, slistlen) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist)) -# define SSL_CTX_set1_client_sigalgs_list(ctx, s) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(s)) -# define SSL_set1_client_sigalgs(s, slist, slistlen) \ - SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist)) -# define SSL_set1_client_sigalgs_list(s, str) \ - SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(str)) -# define SSL_get0_certificate_types(s, clist) \ - SSL_ctrl(s, SSL_CTRL_GET_CLIENT_CERT_TYPES, 0, (char *)(clist)) -# define SSL_CTX_set1_client_certificate_types(ctx, clist, clistlen) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen, \ - (char *)(clist)) -# define SSL_set1_client_certificate_types(s, clist, clistlen) \ - SSL_ctrl(s,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen,(char *)(clist)) -# define SSL_get0_signature_name(s, str) \ - SSL_ctrl(s,SSL_CTRL_GET_SIGNATURE_NAME,0,(1?(str):(const char **)NULL)) -# define SSL_get_signature_nid(s, pn) \ - SSL_ctrl(s,SSL_CTRL_GET_SIGNATURE_NID,0,pn) -# define SSL_get0_peer_signature_name(s, str) \ - SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NAME,0,(1?(str):(const char **)NULL)) -# define SSL_get_peer_signature_nid(s, pn) \ - SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NID,0,pn) -# define SSL_get_peer_tmp_key(s, pk) \ - SSL_ctrl(s,SSL_CTRL_GET_PEER_TMP_KEY,0,pk) -# define SSL_get_tmp_key(s, pk) \ - SSL_ctrl(s,SSL_CTRL_GET_TMP_KEY,0,pk) -# define SSL_get0_raw_cipherlist(s, plst) \ - SSL_ctrl(s,SSL_CTRL_GET_RAW_CIPHERLIST,0,plst) -# define SSL_get0_ec_point_formats(s, plst) \ - SSL_ctrl(s,SSL_CTRL_GET_EC_POINT_FORMATS,0,plst) -# define SSL_CTX_set_min_proto_version(ctx, version) \ - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL) -# define SSL_CTX_set_max_proto_version(ctx, version) \ - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL) -# define SSL_CTX_get_min_proto_version(ctx) \ - SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL) -# define SSL_CTX_get_max_proto_version(ctx) \ - SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL) -# define SSL_set_min_proto_version(s, version) \ - SSL_ctrl(s, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL) -# define SSL_set_max_proto_version(s, version) \ - SSL_ctrl(s, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL) -# define SSL_get_min_proto_version(s) \ - SSL_ctrl(s, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL) -# define SSL_get_max_proto_version(s) \ - SSL_ctrl(s, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL) +#define SSL_set1_groups(s, glist, glistlen) \ + SSL_ctrl(s, SSL_CTRL_SET_GROUPS, glistlen, (char *)(glist)) +#define SSL_set1_groups_list(s, str) \ + SSL_ctrl(s, SSL_CTRL_SET_GROUPS_LIST, 0, (char *)(str)) +#define SSL_get_shared_group(s, n) \ + SSL_ctrl(s, SSL_CTRL_GET_SHARED_GROUP, n, NULL) +#define SSL_get_negotiated_group(s) \ + SSL_ctrl(s, SSL_CTRL_GET_NEGOTIATED_GROUP, 0, NULL) +#define SSL_CTX_set1_sigalgs(ctx, slist, slistlen) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_SIGALGS, slistlen, (int *)(slist)) +#define SSL_CTX_set1_sigalgs_list(ctx, s) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_SIGALGS_LIST, 0, (char *)(s)) +#define SSL_set1_sigalgs(s, slist, slistlen) \ + SSL_ctrl(s, SSL_CTRL_SET_SIGALGS, slistlen, (int *)(slist)) +#define SSL_set1_sigalgs_list(s, str) \ + SSL_ctrl(s, SSL_CTRL_SET_SIGALGS_LIST, 0, (char *)(str)) +#define SSL_CTX_set1_client_sigalgs(ctx, slist, slistlen) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_CLIENT_SIGALGS, slistlen, (int *)(slist)) +#define SSL_CTX_set1_client_sigalgs_list(ctx, s) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_CLIENT_SIGALGS_LIST, 0, (char *)(s)) +#define SSL_set1_client_sigalgs(s, slist, slistlen) \ + SSL_ctrl(s, SSL_CTRL_SET_CLIENT_SIGALGS, slistlen, (int *)(slist)) +#define SSL_set1_client_sigalgs_list(s, str) \ + SSL_ctrl(s, SSL_CTRL_SET_CLIENT_SIGALGS_LIST, 0, (char *)(str)) +#define SSL_get0_certificate_types(s, clist) \ + SSL_ctrl(s, SSL_CTRL_GET_CLIENT_CERT_TYPES, 0, (char *)(clist)) +#define SSL_CTX_set1_client_certificate_types(ctx, clist, clistlen) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_CLIENT_CERT_TYPES, clistlen, \ + (char *)(clist)) +#define SSL_set1_client_certificate_types(s, clist, clistlen) \ + SSL_ctrl(s, SSL_CTRL_SET_CLIENT_CERT_TYPES, clistlen, (char *)(clist)) +#define SSL_get0_signature_name(s, str) \ + SSL_ctrl(s, SSL_CTRL_GET_SIGNATURE_NAME, 0, (1 ? (str) : (const char **)NULL)) +#define SSL_get_signature_nid(s, pn) \ + SSL_ctrl(s, SSL_CTRL_GET_SIGNATURE_NID, 0, pn) +#define SSL_get0_peer_signature_name(s, str) \ + SSL_ctrl(s, SSL_CTRL_GET_PEER_SIGNATURE_NAME, 0, (1 ? (str) : (const char **)NULL)) +#define SSL_get_peer_signature_nid(s, pn) \ + SSL_ctrl(s, SSL_CTRL_GET_PEER_SIGNATURE_NID, 0, pn) +#define SSL_get_peer_tmp_key(s, pk) \ + SSL_ctrl(s, SSL_CTRL_GET_PEER_TMP_KEY, 0, pk) +#define SSL_get_tmp_key(s, pk) \ + SSL_ctrl(s, SSL_CTRL_GET_TMP_KEY, 0, pk) +#define SSL_get0_raw_cipherlist(s, plst) \ + SSL_ctrl(s, SSL_CTRL_GET_RAW_CIPHERLIST, 0, plst) +#define SSL_get0_ec_point_formats(s, plst) \ + SSL_ctrl(s, SSL_CTRL_GET_EC_POINT_FORMATS, 0, plst) +#define SSL_CTX_set_min_proto_version(ctx, version) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL) +#define SSL_CTX_set_max_proto_version(ctx, version) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL) +#define SSL_CTX_get_min_proto_version(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL) +#define SSL_CTX_get_max_proto_version(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL) +#define SSL_set_min_proto_version(s, version) \ + SSL_ctrl(s, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL) +#define SSL_set_max_proto_version(s, version) \ + SSL_ctrl(s, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL) +#define SSL_get_min_proto_version(s) \ + SSL_ctrl(s, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL) +#define SSL_get_max_proto_version(s) \ + SSL_ctrl(s, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL) const char *SSL_get0_group_name(SSL *s); const char *SSL_group_to_name(SSL *s, int id); /* Backwards compatibility, original 1.1.0 names */ -# define SSL_CTRL_GET_SERVER_TMP_KEY \ - SSL_CTRL_GET_PEER_TMP_KEY -# define SSL_get_server_tmp_key(s, pk) \ - SSL_get_peer_tmp_key(s, pk) +#define SSL_CTRL_GET_SERVER_TMP_KEY \ + SSL_CTRL_GET_PEER_TMP_KEY +#define SSL_get_server_tmp_key(s, pk) \ + SSL_get_peer_tmp_key(s, pk) int SSL_set0_tmp_dh_pkey(SSL *s, EVP_PKEY *dhpkey); int SSL_CTX_set0_tmp_dh_pkey(SSL_CTX *ctx, EVP_PKEY *dhpkey); @@ -1577,34 +1581,37 @@ int SSL_CTX_set0_tmp_dh_pkey(SSL_CTX *ctx, EVP_PKEY *dhpkey); * The following symbol names are old and obsolete. They are kept * for compatibility reasons only and should not be used anymore. */ -# define SSL_CTRL_GET_CURVES SSL_CTRL_GET_GROUPS -# define SSL_CTRL_SET_CURVES SSL_CTRL_SET_GROUPS -# define SSL_CTRL_SET_CURVES_LIST SSL_CTRL_SET_GROUPS_LIST -# define SSL_CTRL_GET_SHARED_CURVE SSL_CTRL_GET_SHARED_GROUP +#define SSL_CTRL_GET_CURVES SSL_CTRL_GET_GROUPS +#define SSL_CTRL_SET_CURVES SSL_CTRL_SET_GROUPS +#define SSL_CTRL_SET_CURVES_LIST SSL_CTRL_SET_GROUPS_LIST +#define SSL_CTRL_GET_SHARED_CURVE SSL_CTRL_GET_SHARED_GROUP -# define SSL_get1_curves SSL_get1_groups -# define SSL_CTX_set1_curves SSL_CTX_set1_groups -# define SSL_CTX_set1_curves_list SSL_CTX_set1_groups_list -# define SSL_set1_curves SSL_set1_groups -# define SSL_set1_curves_list SSL_set1_groups_list -# define SSL_get_shared_curve SSL_get_shared_group +#define SSL_get1_curves SSL_get1_groups +#define SSL_CTX_set1_curves SSL_CTX_set1_groups +#define SSL_CTX_set1_curves_list SSL_CTX_set1_groups_list +#define SSL_set1_curves SSL_set1_groups +#define SSL_set1_curves_list SSL_set1_groups_list +#define SSL_get_shared_curve SSL_get_shared_group - -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 /* Provide some compatibility macros for removed functionality. */ -# define SSL_CTX_need_tmp_RSA(ctx) 0 -# define SSL_CTX_set_tmp_rsa(ctx,rsa) 1 -# define SSL_need_tmp_RSA(ssl) 0 -# define SSL_set_tmp_rsa(ssl,rsa) 1 -# define SSL_CTX_set_ecdh_auto(dummy, onoff) ((onoff) != 0) -# define SSL_set_ecdh_auto(dummy, onoff) ((onoff) != 0) +#define SSL_CTX_need_tmp_RSA(ctx) 0 +#define SSL_CTX_set_tmp_rsa(ctx, rsa) 1 +#define SSL_need_tmp_RSA(ssl) 0 +#define SSL_set_tmp_rsa(ssl, rsa) 1 +#define SSL_CTX_set_ecdh_auto(dummy, onoff) ((onoff) != 0) +#define SSL_set_ecdh_auto(dummy, onoff) ((onoff) != 0) /* * We "pretend" to call the callback to avoid warnings about unused static * functions. */ -# define SSL_CTX_set_tmp_rsa_callback(ctx, cb) while(0) (cb)(NULL, 0, 0) -# define SSL_set_tmp_rsa_callback(ssl, cb) while(0) (cb)(NULL, 0, 0) -# endif +#define SSL_CTX_set_tmp_rsa_callback(ctx, cb) \ + while (0) \ + (cb)(NULL, 0, 0) +#define SSL_set_tmp_rsa_callback(ssl, cb) \ + while (0) \ + (cb)(NULL, 0, 0) +#endif __owur const BIO_METHOD *BIO_f_ssl(void); __owur BIO *BIO_new_ssl(SSL_CTX *ctx, int client); __owur BIO *BIO_new_ssl_connect(SSL_CTX *ctx); @@ -1615,7 +1622,7 @@ void BIO_ssl_shutdown(BIO *ssl_bio); __owur int SSL_CTX_set_cipher_list(SSL_CTX *, const char *str); __owur SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth); __owur SSL_CTX *SSL_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq, - const SSL_METHOD *meth); + const SSL_METHOD *meth); int SSL_CTX_up_ref(SSL_CTX *ctx); void SSL_CTX_free(SSL_CTX *); __owur long SSL_CTX_set_timeout(SSL_CTX *ctx, long t); @@ -1654,11 +1661,11 @@ __owur char *SSL_get_shared_ciphers(const SSL *s, char *buf, int size); __owur int SSL_get_read_ahead(const SSL *s); __owur int SSL_pending(const SSL *s); __owur int SSL_has_pending(const SSL *s); -# ifndef OPENSSL_NO_SOCK +#ifndef OPENSSL_NO_SOCK __owur int SSL_set_fd(SSL *s, int fd); __owur int SSL_set_rfd(SSL *s, int fd); __owur int SSL_set_wfd(SSL *s, int fd); -# endif +#endif void SSL_set0_rbio(SSL *s, BIO *rbio); void SSL_set0_wbio(SSL *s, BIO *wbio); void SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio); @@ -1673,32 +1680,31 @@ __owur int SSL_get_verify_depth(const SSL *s); __owur SSL_verify_cb SSL_get_verify_callback(const SSL *s); void SSL_set_verify(SSL *s, int mode, SSL_verify_cb callback); void SSL_set_verify_depth(SSL *s, int depth); -void SSL_set_cert_cb(SSL *s, int (*cb) (SSL *ssl, void *arg), void *arg); -# ifndef OPENSSL_NO_DEPRECATED_3_0 +void SSL_set_cert_cb(SSL *s, int (*cb)(SSL *ssl, void *arg), void *arg); +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 __owur int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa); OSSL_DEPRECATEDIN_3_0 __owur int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, - const unsigned char *d, long len); -# endif + const unsigned char *d, long len); +#endif __owur int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); __owur int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d, - long len); + long len); __owur int SSL_use_certificate(SSL *ssl, X509 *x); __owur int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len); __owur int SSL_use_cert_and_key(SSL *ssl, X509 *x509, EVP_PKEY *privatekey, - STACK_OF(X509) *chain, int override); - + STACK_OF(X509) *chain, int override); /* serverinfo file format versions */ -# define SSL_SERVERINFOV1 1 -# define SSL_SERVERINFOV2 2 +#define SSL_SERVERINFOV1 1 +#define SSL_SERVERINFOV2 2 /* Set serverinfo data for the current active cert. */ __owur int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo, - size_t serverinfo_length); + size_t serverinfo_length); __owur int SSL_CTX_use_serverinfo_ex(SSL_CTX *ctx, unsigned int version, - const unsigned char *serverinfo, - size_t serverinfo_length); + const unsigned char *serverinfo, + size_t serverinfo_length); __owur int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file); #ifndef OPENSSL_NO_DEPRECATED_3_0 @@ -1712,31 +1718,31 @@ __owur int SSL_use_certificate_file(SSL *ssl, const char *file, int type); #ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 __owur int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, - int type); + int type); #endif __owur int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, - int type); + int type); __owur int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, - int type); + int type); /* PEM type */ __owur int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); __owur int SSL_use_certificate_chain_file(SSL *ssl, const char *file); __owur STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file); -__owur STACK_OF(X509_NAME) -*SSL_load_client_CA_file_ex(const char *file, OSSL_LIB_CTX *libctx, - const char *propq); +__owur STACK_OF(X509_NAME) *SSL_load_client_CA_file_ex(const char *file, OSSL_LIB_CTX *libctx, + const char *propq); __owur int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, - const char *file); + const char *file); int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, - const char *dir); + const char *dir); int SSL_add_store_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, - const char *uri); + const char *uri); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define SSL_load_error_strings() \ +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define SSL_load_error_strings() \ OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS \ - | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL) -# endif + | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, \ + NULL) +#endif __owur const char *SSL_state_string(const SSL *s); __owur const char *SSL_rstate_string(const SSL *s); @@ -1760,39 +1766,39 @@ __owur time_t SSL_SESSION_set_time_ex(SSL_SESSION *s, time_t t); __owur const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s); __owur int SSL_SESSION_set1_hostname(SSL_SESSION *s, const char *hostname); void SSL_SESSION_get0_alpn_selected(const SSL_SESSION *s, - const unsigned char **alpn, - size_t *len); + const unsigned char **alpn, + size_t *len); __owur int SSL_SESSION_set1_alpn_selected(SSL_SESSION *s, - const unsigned char *alpn, - size_t len); + const unsigned char *alpn, + size_t len); __owur const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s); __owur int SSL_SESSION_set_cipher(SSL_SESSION *s, const SSL_CIPHER *cipher); __owur int SSL_SESSION_has_ticket(const SSL_SESSION *s); __owur unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s); void SSL_SESSION_get0_ticket(const SSL_SESSION *s, const unsigned char **tick, - size_t *len); + size_t *len); __owur uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *s); __owur int SSL_SESSION_set_max_early_data(SSL_SESSION *s, - uint32_t max_early_data); + uint32_t max_early_data); __owur int SSL_copy_session_id(SSL *to, const SSL *from); __owur X509 *SSL_SESSION_get0_peer(SSL_SESSION *s); __owur int SSL_SESSION_set1_id_context(SSL_SESSION *s, - const unsigned char *sid_ctx, - unsigned int sid_ctx_len); + const unsigned char *sid_ctx, + unsigned int sid_ctx_len); __owur int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid, - unsigned int sid_len); + unsigned int sid_len); __owur int SSL_SESSION_is_resumable(const SSL_SESSION *s); __owur SSL_SESSION *SSL_SESSION_new(void); __owur SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src); const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, - unsigned int *len); + unsigned int *len); const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *s, - unsigned int *len); + unsigned int *len); __owur unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s); -# ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_STDIO int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *ses); -# endif +#endif int SSL_SESSION_print(BIO *fp, const SSL_SESSION *ses); int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x); int SSL_SESSION_up_ref(SSL_SESSION *ses); @@ -1804,22 +1810,22 @@ int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *session); __owur int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb); __owur int SSL_set_generate_session_id(SSL *s, GEN_SESSION_CB cb); __owur int SSL_has_matching_session_id(const SSL *s, - const unsigned char *id, - unsigned int id_len); + const unsigned char *id, + unsigned int id_len); SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, - long length); + long length); SSL_SESSION *d2i_SSL_SESSION_ex(SSL_SESSION **a, const unsigned char **pp, - long length, OSSL_LIB_CTX *libctx, - const char *propq); + long length, OSSL_LIB_CTX *libctx, + const char *propq); -# ifdef OPENSSL_X509_H +#ifdef OPENSSL_X509_H __owur X509 *SSL_get0_peer_certificate(const SSL *s); __owur X509 *SSL_get1_peer_certificate(const SSL *s); /* Deprecated in 3.0.0 */ -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define SSL_get_peer_certificate SSL_get1_peer_certificate -# endif -# endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define SSL_get_peer_certificate SSL_get1_peer_certificate +#endif +#endif __owur STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s); @@ -1829,25 +1835,25 @@ __owur SSL_verify_cb SSL_CTX_get_verify_callback(const SSL_CTX *ctx); void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, SSL_verify_cb callback); void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth); void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, - int (*cb) (X509_STORE_CTX *, void *), - void *arg); -void SSL_CTX_set_cert_cb(SSL_CTX *c, int (*cb) (SSL *ssl, void *arg), - void *arg); -# ifndef OPENSSL_NO_DEPRECATED_3_0 + int (*cb)(X509_STORE_CTX *, void *), + void *arg); +void SSL_CTX_set_cert_cb(SSL_CTX *c, int (*cb)(SSL *ssl, void *arg), + void *arg); +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 __owur int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa); OSSL_DEPRECATEDIN_3_0 __owur int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, - long len); -# endif + long len); +#endif __owur int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); __owur int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, - const unsigned char *d, long len); + const unsigned char *d, long len); __owur int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); __owur int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, - const unsigned char *d); + const unsigned char *d); __owur int SSL_CTX_use_cert_and_key(SSL_CTX *ctx, X509 *x509, EVP_PKEY *privatekey, - STACK_OF(X509) *chain, int override); + STACK_OF(X509) *chain, int override); void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb); void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u); @@ -1862,8 +1868,8 @@ __owur int SSL_CTX_check_private_key(const SSL_CTX *ctx); __owur int SSL_check_private_key(const SSL *ctx); __owur int SSL_CTX_set_session_id_context(SSL_CTX *ctx, - const unsigned char *sid_ctx, - unsigned int sid_ctx_len); + const unsigned char *sid_ctx, + unsigned int sid_ctx_len); SSL *SSL_new(SSL_CTX *ctx); int SSL_up_ref(SSL *s); @@ -1871,7 +1877,7 @@ int SSL_is_dtls(const SSL *s); int SSL_is_tls(const SSL *s); int SSL_is_quic(const SSL *s); __owur int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx, - unsigned int sid_ctx_len); + unsigned int sid_ctx_len); __owur int SSL_CTX_set_purpose(SSL_CTX *ctx, int purpose); __owur int SSL_set_purpose(SSL *ssl, int purpose); @@ -1885,14 +1891,14 @@ void SSL_set_hostflags(SSL *s, unsigned int flags); __owur int SSL_CTX_dane_enable(SSL_CTX *ctx); __owur int SSL_CTX_dane_mtype_set(SSL_CTX *ctx, const EVP_MD *md, - uint8_t mtype, uint8_t ord); + uint8_t mtype, uint8_t ord); __owur int SSL_dane_enable(SSL *s, const char *basedomain); __owur int SSL_dane_tlsa_add(SSL *s, uint8_t usage, uint8_t selector, - uint8_t mtype, const unsigned char *data, size_t dlen); + uint8_t mtype, const unsigned char *data, size_t dlen); __owur int SSL_get0_dane_authority(SSL *s, X509 **mcert, EVP_PKEY **mspki); __owur int SSL_get0_dane_tlsa(SSL *s, uint8_t *usage, uint8_t *selector, - uint8_t *mtype, const unsigned char **data, - size_t *dlen); + uint8_t *mtype, const unsigned char **data, + size_t *dlen); /* * Bridge opacity barrier between libcrypt and libssl, also needed to support * offline testing in test/danetest.c @@ -1912,52 +1918,52 @@ __owur int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm); __owur X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx); __owur X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl); -# ifndef OPENSSL_NO_SRP -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_SRP +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name); OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password); OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength); OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx, - char *(*cb) (SSL *, void *)); + char *(*cb)(SSL *, void *)); OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx, - int (*cb) (SSL *, void *)); + int (*cb)(SSL *, void *)); OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx, - int (*cb) (SSL *, int *, void *)); + int (*cb)(SSL *, int *, void *)); OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg); OSSL_DEPRECATEDIN_3_0 int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g, - BIGNUM *sa, BIGNUM *v, char *info); + BIGNUM *sa, BIGNUM *v, char *info); OSSL_DEPRECATEDIN_3_0 int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass, - const char *grp); + const char *grp); OSSL_DEPRECATEDIN_3_0 __owur BIGNUM *SSL_get_srp_g(SSL *s); OSSL_DEPRECATEDIN_3_0 __owur BIGNUM *SSL_get_srp_N(SSL *s); OSSL_DEPRECATEDIN_3_0 __owur char *SSL_get_srp_username(SSL *s); OSSL_DEPRECATEDIN_3_0 __owur char *SSL_get_srp_userinfo(SSL *s); -# endif -# endif +#endif +#endif /* * ClientHello callback and helpers. */ -# define SSL_CLIENT_HELLO_SUCCESS 1 -# define SSL_CLIENT_HELLO_ERROR 0 -# define SSL_CLIENT_HELLO_RETRY (-1) +#define SSL_CLIENT_HELLO_SUCCESS 1 +#define SSL_CLIENT_HELLO_ERROR 0 +#define SSL_CLIENT_HELLO_RETRY (-1) -typedef int (*SSL_client_hello_cb_fn) (SSL *s, int *al, void *arg); +typedef int (*SSL_client_hello_cb_fn)(SSL *s, int *al, void *arg); void SSL_CTX_set_client_hello_cb(SSL_CTX *c, SSL_client_hello_cb_fn cb, - void *arg); -typedef int (*SSL_new_pending_conn_cb_fn) (SSL_CTX *ctx, SSL *new_ssl, - void *arg); + void *arg); +typedef int (*SSL_new_pending_conn_cb_fn)(SSL_CTX *ctx, SSL *new_ssl, + void *arg); void SSL_CTX_set_new_pending_conn_cb(SSL_CTX *c, SSL_new_pending_conn_cb_fn cb, - void *arg); + void *arg); int SSL_client_hello_isv2(SSL *s); unsigned int SSL_client_hello_get0_legacy_version(SSL *s); @@ -1965,65 +1971,65 @@ size_t SSL_client_hello_get0_random(SSL *s, const unsigned char **out); size_t SSL_client_hello_get0_session_id(SSL *s, const unsigned char **out); size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out); size_t SSL_client_hello_get0_compression_methods(SSL *s, - const unsigned char **out); + const unsigned char **out); int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen); int SSL_client_hello_get_extension_order(SSL *s, uint16_t *exts, - size_t *num_exts); + size_t *num_exts); int SSL_client_hello_get0_ext(SSL *s, unsigned int type, - const unsigned char **out, size_t *outlen); + const unsigned char **out, size_t *outlen); void SSL_certs_clear(SSL *s); void SSL_free(SSL *ssl); -# ifdef OSSL_ASYNC_FD +#ifdef OSSL_ASYNC_FD /* * Windows application developer has to include windows.h to use these. */ __owur int SSL_waiting_for_async(SSL *s); __owur int SSL_get_all_async_fds(SSL *s, OSSL_ASYNC_FD *fds, size_t *numfds); __owur int SSL_get_changed_async_fds(SSL *s, OSSL_ASYNC_FD *addfd, - size_t *numaddfds, OSSL_ASYNC_FD *delfd, - size_t *numdelfds); + size_t *numaddfds, OSSL_ASYNC_FD *delfd, + size_t *numdelfds); __owur int SSL_CTX_set_async_callback(SSL_CTX *ctx, SSL_async_callback_fn callback); __owur int SSL_CTX_set_async_callback_arg(SSL_CTX *ctx, void *arg); __owur int SSL_set_async_callback(SSL *s, SSL_async_callback_fn callback); __owur int SSL_set_async_callback_arg(SSL *s, void *arg); __owur int SSL_get_async_status(SSL *s, int *status); -# endif +#endif __owur int SSL_accept(SSL *ssl); __owur int SSL_stateless(SSL *s); __owur int SSL_connect(SSL *ssl); __owur int SSL_read(SSL *ssl, void *buf, int num); __owur int SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes); -# define SSL_READ_EARLY_DATA_ERROR 0 -# define SSL_READ_EARLY_DATA_SUCCESS 1 -# define SSL_READ_EARLY_DATA_FINISH 2 +#define SSL_READ_EARLY_DATA_ERROR 0 +#define SSL_READ_EARLY_DATA_SUCCESS 1 +#define SSL_READ_EARLY_DATA_FINISH 2 __owur int SSL_read_early_data(SSL *s, void *buf, size_t num, - size_t *readbytes); + size_t *readbytes); __owur int SSL_peek(SSL *ssl, void *buf, int num); __owur int SSL_peek_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes); __owur ossl_ssize_t SSL_sendfile(SSL *s, int fd, off_t offset, size_t size, - int flags); + int flags); __owur int SSL_write(SSL *ssl, const void *buf, int num); __owur int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written); __owur int SSL_write_early_data(SSL *s, const void *buf, size_t num, - size_t *written); + size_t *written); long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg); long SSL_callback_ctrl(SSL *, int, void (*)(void)); long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg); long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void)); -# define SSL_WRITE_FLAG_CONCLUDE (1U << 0) +#define SSL_WRITE_FLAG_CONCLUDE (1U << 0) __owur int SSL_write_ex2(SSL *s, const void *buf, size_t num, - uint64_t flags, - size_t *written); + uint64_t flags, + size_t *written); -# define SSL_EARLY_DATA_NOT_SENT 0 -# define SSL_EARLY_DATA_REJECTED 1 -# define SSL_EARLY_DATA_ACCEPTED 2 +#define SSL_EARLY_DATA_NOT_SENT 0 +#define SSL_EARLY_DATA_REJECTED 1 +#define SSL_EARLY_DATA_ACCEPTED 2 __owur int SSL_get_early_data_status(const SSL *s); @@ -2032,68 +2038,68 @@ __owur const char *SSL_get_version(const SSL *s); __owur int SSL_get_handshake_rtt(const SSL *s, uint64_t *rtt); /* This sets the 'default' SSL version that SSL_new() will create */ -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 __owur int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth); -# endif +#endif -# ifndef OPENSSL_NO_SSL3_METHOD -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_SSL3_METHOD +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_method(void); /* SSLv3 */ OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_server_method(void); OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_client_method(void); -# endif -# endif +#endif +#endif -#define SSLv23_method TLS_method -#define SSLv23_server_method TLS_server_method -#define SSLv23_client_method TLS_client_method +#define SSLv23_method TLS_method +#define SSLv23_server_method TLS_server_method +#define SSLv23_client_method TLS_client_method /* Negotiate highest available SSL/TLS version */ __owur const SSL_METHOD *TLS_method(void); __owur const SSL_METHOD *TLS_server_method(void); __owur const SSL_METHOD *TLS_client_method(void); -# ifndef OPENSSL_NO_TLS1_METHOD -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_TLS1_METHOD +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */ OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_server_method(void); OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_client_method(void); -# endif -# endif +#endif +#endif -# ifndef OPENSSL_NO_TLS1_1_METHOD -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_TLS1_1_METHOD +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_method(void); /* TLSv1.1 */ OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_server_method(void); OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_client_method(void); -# endif -# endif +#endif +#endif -# ifndef OPENSSL_NO_TLS1_2_METHOD -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_TLS1_2_METHOD +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_method(void); /* TLSv1.2 */ OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_server_method(void); OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_client_method(void); -# endif -# endif +#endif +#endif -# ifndef OPENSSL_NO_DTLS1_METHOD -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_DTLS1_METHOD +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_method(void); /* DTLSv1.0 */ OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_server_method(void); OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_client_method(void); -# endif -# endif +#endif +#endif -# ifndef OPENSSL_NO_DTLS1_2_METHOD +#ifndef OPENSSL_NO_DTLS1_2_METHOD /* DTLSv1.2 */ -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_method(void); OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_server_method(void); OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_client_method(void); -# endif -# endif +#endif +#endif __owur const SSL_METHOD *DTLS_method(void); /* DTLS 1.0 and 1.2 */ __owur const SSL_METHOD *DTLS_server_method(void); /* DTLS 1.0 and 1.2 */ @@ -2146,9 +2152,9 @@ void SSL_set_accept_state(SSL *s); __owur long SSL_get_default_timeout(const SSL *s); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define SSL_library_init() OPENSSL_init_ssl(0, NULL) -# endif +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define SSL_library_init() OPENSSL_init_ssl(0, NULL) +#endif __owur char *SSL_CIPHER_description(const SSL_CIPHER *, char *buf, int size); __owur STACK_OF(X509_NAME) *SSL_dup_CA_list(const STACK_OF(X509_NAME) *sk); @@ -2180,17 +2186,17 @@ __owur int SSL_CTX_load_verify_file(SSL_CTX *ctx, const char *CAfile); __owur int SSL_CTX_load_verify_dir(SSL_CTX *ctx, const char *CApath); __owur int SSL_CTX_load_verify_store(SSL_CTX *ctx, const char *CAstore); __owur int SSL_CTX_load_verify_locations(SSL_CTX *ctx, - const char *CAfile, - const char *CApath); -# define SSL_get0_session SSL_get_session/* just peek at pointer */ + const char *CAfile, + const char *CApath); +#define SSL_get0_session SSL_get_session /* just peek at pointer */ __owur SSL_SESSION *SSL_get_session(const SSL *ssl); __owur SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */ __owur SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl); SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx); void SSL_set_info_callback(SSL *ssl, - void (*cb) (const SSL *ssl, int type, int val)); -void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type, - int val); + void (*cb)(const SSL *ssl, int type, int val)); +void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl, int type, + int val); __owur OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl); void SSL_set_verify_result(SSL *ssl, long v); @@ -2198,13 +2204,13 @@ __owur long SSL_get_verify_result(const SSL *ssl); __owur STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s); __owur size_t SSL_get_client_random(const SSL *ssl, unsigned char *out, - size_t outlen); + size_t outlen); __owur size_t SSL_get_server_random(const SSL *ssl, unsigned char *out, - size_t outlen); + size_t outlen); __owur size_t SSL_SESSION_get_master_key(const SSL_SESSION *sess, - unsigned char *out, size_t outlen); + unsigned char *out, size_t outlen); __owur int SSL_SESSION_set1_master_key(SSL_SESSION *sess, - const unsigned char *in, size_t len); + const unsigned char *in, size_t len); uint8_t SSL_SESSION_get_max_fragment_length(const SSL_SESSION *sess); #define SSL_get_ex_new_index(l, p, newf, dupf, freef) \ @@ -2222,61 +2228,61 @@ void *SSL_CTX_get_ex_data(const SSL_CTX *ssl, int idx); __owur int SSL_get_ex_data_X509_STORE_CTX_idx(void); -# define SSL_CTX_sess_set_cache_size(ctx,t) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL) -# define SSL_CTX_sess_get_cache_size(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL) -# define SSL_CTX_set_session_cache_mode(ctx,m) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL) -# define SSL_CTX_get_session_cache_mode(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL) +#define SSL_CTX_sess_set_cache_size(ctx, t) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_SESS_CACHE_SIZE, t, NULL) +#define SSL_CTX_sess_get_cache_size(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_SESS_CACHE_SIZE, 0, NULL) +#define SSL_CTX_set_session_cache_mode(ctx, m) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_SESS_CACHE_MODE, m, NULL) +#define SSL_CTX_get_session_cache_mode(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_SESS_CACHE_MODE, 0, NULL) -# define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx) -# define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m) -# define SSL_CTX_get_read_ahead(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL) -# define SSL_CTX_set_read_ahead(ctx,m) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL) -# define SSL_CTX_get_max_cert_list(ctx) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL) -# define SSL_CTX_set_max_cert_list(ctx,m) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL) -# define SSL_get_max_cert_list(ssl) \ - SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL) -# define SSL_set_max_cert_list(ssl,m) \ - SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL) +#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx) +#define SSL_CTX_set_default_read_ahead(ctx, m) SSL_CTX_set_read_ahead(ctx, m) +#define SSL_CTX_get_read_ahead(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_READ_AHEAD, 0, NULL) +#define SSL_CTX_set_read_ahead(ctx, m) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_READ_AHEAD, m, NULL) +#define SSL_CTX_get_max_cert_list(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MAX_CERT_LIST, 0, NULL) +#define SSL_CTX_set_max_cert_list(ctx, m) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_CERT_LIST, m, NULL) +#define SSL_get_max_cert_list(ssl) \ + SSL_ctrl(ssl, SSL_CTRL_GET_MAX_CERT_LIST, 0, NULL) +#define SSL_set_max_cert_list(ssl, m) \ + SSL_ctrl(ssl, SSL_CTRL_SET_MAX_CERT_LIST, m, NULL) -# define SSL_CTX_set_max_send_fragment(ctx,m) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL) -# define SSL_set_max_send_fragment(ssl,m) \ - SSL_ctrl(ssl,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL) -# define SSL_CTX_set_split_send_fragment(ctx,m) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL) -# define SSL_set_split_send_fragment(ssl,m) \ - SSL_ctrl(ssl,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL) -# define SSL_CTX_set_max_pipelines(ctx,m) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_PIPELINES,m,NULL) -# define SSL_set_max_pipelines(ssl,m) \ - SSL_ctrl(ssl,SSL_CTRL_SET_MAX_PIPELINES,m,NULL) -# define SSL_set_retry_verify(ssl) \ - (SSL_ctrl(ssl,SSL_CTRL_SET_RETRY_VERIFY,0,NULL) > 0) +#define SSL_CTX_set_max_send_fragment(ctx, m) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_SEND_FRAGMENT, m, NULL) +#define SSL_set_max_send_fragment(ssl, m) \ + SSL_ctrl(ssl, SSL_CTRL_SET_MAX_SEND_FRAGMENT, m, NULL) +#define SSL_CTX_set_split_send_fragment(ctx, m) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_SPLIT_SEND_FRAGMENT, m, NULL) +#define SSL_set_split_send_fragment(ssl, m) \ + SSL_ctrl(ssl, SSL_CTRL_SET_SPLIT_SEND_FRAGMENT, m, NULL) +#define SSL_CTX_set_max_pipelines(ctx, m) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PIPELINES, m, NULL) +#define SSL_set_max_pipelines(ssl, m) \ + SSL_ctrl(ssl, SSL_CTRL_SET_MAX_PIPELINES, m, NULL) +#define SSL_set_retry_verify(ssl) \ + (SSL_ctrl(ssl, SSL_CTRL_SET_RETRY_VERIFY, 0, NULL) > 0) void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len); void SSL_set_default_read_buffer_len(SSL *s, size_t len); -# ifndef OPENSSL_NO_DH -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DH +#ifndef OPENSSL_NO_DEPRECATED_3_0 /* NB: the |keylength| is only applicable when is_export is true */ OSSL_DEPRECATEDIN_3_0 void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, - DH *(*dh) (SSL *ssl, int is_export, - int keylength)); + DH *(*dh)(SSL *ssl, int is_export, + int keylength)); OSSL_DEPRECATEDIN_3_0 void SSL_set_tmp_dh_callback(SSL *ssl, - DH *(*dh) (SSL *ssl, int is_export, - int keylength)); -# endif -# endif + DH *(*dh)(SSL *ssl, int is_export, + int keylength)); +#endif +#endif __owur const COMP_METHOD *SSL_get_current_compression(const SSL *s); __owur const COMP_METHOD *SSL_get_current_expansion(const SSL *s); @@ -2285,57 +2291,59 @@ __owur const char *SSL_COMP_get0_name(const SSL_COMP *comp); __owur int SSL_COMP_get_id(const SSL_COMP *comp); STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void); __owur STACK_OF(SSL_COMP) *SSL_COMP_set0_compression_methods(STACK_OF(SSL_COMP) - *meths); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define SSL_COMP_free_compression_methods() while(0) continue -# endif + *meths); +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define SSL_COMP_free_compression_methods() \ + while (0) \ + continue +#endif __owur int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm); const SSL_CIPHER *SSL_CIPHER_find(SSL *ssl, const unsigned char *ptr); int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *c); int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c); int SSL_bytes_to_cipher_list(SSL *s, const unsigned char *bytes, size_t len, - int isv2format, STACK_OF(SSL_CIPHER) **sk, - STACK_OF(SSL_CIPHER) **scsvs); + int isv2format, STACK_OF(SSL_CIPHER) **sk, + STACK_OF(SSL_CIPHER) **scsvs); /* TLS extensions functions */ __owur int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len); __owur int SSL_set_session_ticket_ext_cb(SSL *s, - tls_session_ticket_ext_cb_fn cb, - void *arg); + tls_session_ticket_ext_cb_fn cb, + void *arg); /* Pre-shared secret session resumption functions */ __owur int SSL_set_session_secret_cb(SSL *s, - tls_session_secret_cb_fn session_secret_cb, - void *arg); + tls_session_secret_cb_fn session_secret_cb, + void *arg); void SSL_CTX_set_not_resumable_session_callback(SSL_CTX *ctx, - int (*cb) (SSL *ssl, - int - is_forward_secure)); + int (*cb)(SSL *ssl, + int + is_forward_secure)); void SSL_set_not_resumable_session_callback(SSL *ssl, - int (*cb) (SSL *ssl, - int is_forward_secure)); + int (*cb)(SSL *ssl, + int is_forward_secure)); void SSL_CTX_set_record_padding_callback(SSL_CTX *ctx, - size_t (*cb) (SSL *ssl, int type, - size_t len, void *arg)); + size_t (*cb)(SSL *ssl, int type, + size_t len, void *arg)); void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg); void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx); int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size); int SSL_CTX_set_block_padding_ex(SSL_CTX *ctx, size_t app_block_size, - size_t hs_block_size); + size_t hs_block_size); int SSL_set_record_padding_callback(SSL *ssl, - size_t (*cb) (SSL *ssl, int type, - size_t len, void *arg)); + size_t (*cb)(SSL *ssl, int type, + size_t len, void *arg)); void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg); void *SSL_get_record_padding_callback_arg(const SSL *ssl); int SSL_set_block_padding(SSL *ssl, size_t block_size); int SSL_set_block_padding_ex(SSL *ssl, size_t app_block_size, - size_t hs_block_size); + size_t hs_block_size); int SSL_set_num_tickets(SSL *s, size_t num_tickets); size_t SSL_get_num_tickets(const SSL *s); int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets); @@ -2356,11 +2364,11 @@ __owur int SSL_is_connection(SSL *s); __owur int SSL_is_listener(SSL *ssl); __owur SSL *SSL_get0_listener(SSL *s); -#define SSL_LISTENER_FLAG_NO_VALIDATE (1UL << 1) +#define SSL_LISTENER_FLAG_NO_VALIDATE (1UL << 1) __owur SSL *SSL_new_listener(SSL_CTX *ctx, uint64_t flags); __owur SSL *SSL_new_listener_from(SSL *ssl, uint64_t flags); __owur SSL *SSL_new_from_listener(SSL *ssl, uint64_t flags); -#define SSL_ACCEPT_CONNECTION_NO_BLOCK (1UL << 0) +#define SSL_ACCEPT_CONNECTION_NO_BLOCK (1UL << 0) __owur SSL *SSL_accept_connection(SSL *ssl, uint64_t flags); __owur size_t SSL_get_accept_connection_queue_len(SSL *ssl); __owur int SSL_listen(SSL *ssl); @@ -2369,64 +2377,64 @@ __owur int SSL_is_domain(SSL *s); __owur SSL *SSL_get0_domain(SSL *s); __owur SSL *SSL_new_domain(SSL_CTX *ctx, uint64_t flags); -#define SSL_DOMAIN_FLAG_SINGLE_THREAD (1U << 0) -#define SSL_DOMAIN_FLAG_MULTI_THREAD (1U << 1) -#define SSL_DOMAIN_FLAG_THREAD_ASSISTED (1U << 2) -#define SSL_DOMAIN_FLAG_BLOCKING (1U << 3) -#define SSL_DOMAIN_FLAG_LEGACY_BLOCKING (1U << 4) +#define SSL_DOMAIN_FLAG_SINGLE_THREAD (1U << 0) +#define SSL_DOMAIN_FLAG_MULTI_THREAD (1U << 1) +#define SSL_DOMAIN_FLAG_THREAD_ASSISTED (1U << 2) +#define SSL_DOMAIN_FLAG_BLOCKING (1U << 3) +#define SSL_DOMAIN_FLAG_LEGACY_BLOCKING (1U << 4) __owur int SSL_CTX_set_domain_flags(SSL_CTX *ctx, uint64_t domain_flags); __owur int SSL_CTX_get_domain_flags(const SSL_CTX *ctx, uint64_t *domain_flags); __owur int SSL_get_domain_flags(const SSL *ssl, uint64_t *domain_flags); -#define SSL_STREAM_TYPE_NONE 0 -#define SSL_STREAM_TYPE_READ (1U << 0) -#define SSL_STREAM_TYPE_WRITE (1U << 1) -#define SSL_STREAM_TYPE_BIDI (SSL_STREAM_TYPE_READ | SSL_STREAM_TYPE_WRITE) +#define SSL_STREAM_TYPE_NONE 0 +#define SSL_STREAM_TYPE_READ (1U << 0) +#define SSL_STREAM_TYPE_WRITE (1U << 1) +#define SSL_STREAM_TYPE_BIDI (SSL_STREAM_TYPE_READ | SSL_STREAM_TYPE_WRITE) __owur int SSL_get_stream_type(SSL *s); __owur uint64_t SSL_get_stream_id(SSL *s); __owur int SSL_is_stream_local(SSL *s); -#define SSL_DEFAULT_STREAM_MODE_NONE 0 -#define SSL_DEFAULT_STREAM_MODE_AUTO_BIDI 1 -#define SSL_DEFAULT_STREAM_MODE_AUTO_UNI 2 +#define SSL_DEFAULT_STREAM_MODE_NONE 0 +#define SSL_DEFAULT_STREAM_MODE_AUTO_BIDI 1 +#define SSL_DEFAULT_STREAM_MODE_AUTO_UNI 2 __owur int SSL_set_default_stream_mode(SSL *s, uint32_t mode); -#define SSL_STREAM_FLAG_UNI (1U << 0) -#define SSL_STREAM_FLAG_NO_BLOCK (1U << 1) -#define SSL_STREAM_FLAG_ADVANCE (1U << 2) +#define SSL_STREAM_FLAG_UNI (1U << 0) +#define SSL_STREAM_FLAG_NO_BLOCK (1U << 1) +#define SSL_STREAM_FLAG_ADVANCE (1U << 2) __owur SSL *SSL_new_stream(SSL *s, uint64_t flags); -#define SSL_INCOMING_STREAM_POLICY_AUTO 0 -#define SSL_INCOMING_STREAM_POLICY_ACCEPT 1 -#define SSL_INCOMING_STREAM_POLICY_REJECT 2 +#define SSL_INCOMING_STREAM_POLICY_AUTO 0 +#define SSL_INCOMING_STREAM_POLICY_ACCEPT 1 +#define SSL_INCOMING_STREAM_POLICY_REJECT 2 __owur int SSL_set_incoming_stream_policy(SSL *s, int policy, uint64_t aec); -#define SSL_ACCEPT_STREAM_NO_BLOCK (1U << 0) +#define SSL_ACCEPT_STREAM_NO_BLOCK (1U << 0) __owur SSL *SSL_accept_stream(SSL *s, uint64_t flags); __owur size_t SSL_get_accept_stream_queue_len(SSL *s); -# ifndef OPENSSL_NO_QUIC +#ifndef OPENSSL_NO_QUIC __owur int SSL_inject_net_dgram(SSL *s, const unsigned char *buf, - size_t buf_len, - const BIO_ADDR *peer, - const BIO_ADDR *local); -# endif + size_t buf_len, + const BIO_ADDR *peer, + const BIO_ADDR *local); +#endif typedef struct ssl_shutdown_ex_args_st { - uint64_t quic_error_code; - const char *quic_reason; + uint64_t quic_error_code; + const char *quic_reason; } SSL_SHUTDOWN_EX_ARGS; -#define SSL_SHUTDOWN_FLAG_RAPID (1U << 0) -#define SSL_SHUTDOWN_FLAG_NO_STREAM_FLUSH (1U << 1) -#define SSL_SHUTDOWN_FLAG_NO_BLOCK (1U << 2) -#define SSL_SHUTDOWN_FLAG_WAIT_PEER (1U << 3) +#define SSL_SHUTDOWN_FLAG_RAPID (1U << 0) +#define SSL_SHUTDOWN_FLAG_NO_STREAM_FLUSH (1U << 1) +#define SSL_SHUTDOWN_FLAG_NO_BLOCK (1U << 2) +#define SSL_SHUTDOWN_FLAG_WAIT_PEER (1U << 3) __owur int SSL_shutdown_ex(SSL *ssl, uint64_t flags, - const SSL_SHUTDOWN_EX_ARGS *args, - size_t args_len); + const SSL_SHUTDOWN_EX_ARGS *args, + size_t args_len); __owur int SSL_stream_conclude(SSL *ssl, uint64_t flags); @@ -2435,167 +2443,167 @@ typedef struct ssl_stream_reset_args_st { } SSL_STREAM_RESET_ARGS; __owur int SSL_stream_reset(SSL *ssl, - const SSL_STREAM_RESET_ARGS *args, - size_t args_len); + const SSL_STREAM_RESET_ARGS *args, + size_t args_len); -#define SSL_STREAM_STATE_NONE 0 -#define SSL_STREAM_STATE_OK 1 -#define SSL_STREAM_STATE_WRONG_DIR 2 -#define SSL_STREAM_STATE_FINISHED 3 -#define SSL_STREAM_STATE_RESET_LOCAL 4 -#define SSL_STREAM_STATE_RESET_REMOTE 5 -#define SSL_STREAM_STATE_CONN_CLOSED 6 +#define SSL_STREAM_STATE_NONE 0 +#define SSL_STREAM_STATE_OK 1 +#define SSL_STREAM_STATE_WRONG_DIR 2 +#define SSL_STREAM_STATE_FINISHED 3 +#define SSL_STREAM_STATE_RESET_LOCAL 4 +#define SSL_STREAM_STATE_RESET_REMOTE 5 +#define SSL_STREAM_STATE_CONN_CLOSED 6 __owur int SSL_get_stream_read_state(SSL *ssl); __owur int SSL_get_stream_write_state(SSL *ssl); __owur int SSL_get_stream_read_error_code(SSL *ssl, uint64_t *app_error_code); __owur int SSL_get_stream_write_error_code(SSL *ssl, uint64_t *app_error_code); -#define SSL_CONN_CLOSE_FLAG_LOCAL (1U << 0) -#define SSL_CONN_CLOSE_FLAG_TRANSPORT (1U << 1) +#define SSL_CONN_CLOSE_FLAG_LOCAL (1U << 0) +#define SSL_CONN_CLOSE_FLAG_TRANSPORT (1U << 1) typedef struct ssl_conn_close_info_st { - uint64_t error_code, frame_type; - const char *reason; - size_t reason_len; - uint32_t flags; + uint64_t error_code, frame_type; + const char *reason; + size_t reason_len; + uint32_t flags; } SSL_CONN_CLOSE_INFO; __owur int SSL_get_conn_close_info(SSL *ssl, - SSL_CONN_CLOSE_INFO *info, - size_t info_len); + SSL_CONN_CLOSE_INFO *info, + size_t info_len); -# define SSL_VALUE_CLASS_GENERIC 0 -# define SSL_VALUE_CLASS_FEATURE_REQUEST 1 -# define SSL_VALUE_CLASS_FEATURE_PEER_REQUEST 2 -# define SSL_VALUE_CLASS_FEATURE_NEGOTIATED 3 +#define SSL_VALUE_CLASS_GENERIC 0 +#define SSL_VALUE_CLASS_FEATURE_REQUEST 1 +#define SSL_VALUE_CLASS_FEATURE_PEER_REQUEST 2 +#define SSL_VALUE_CLASS_FEATURE_NEGOTIATED 3 -# define SSL_VALUE_NONE 0 -# define SSL_VALUE_QUIC_STREAM_BIDI_LOCAL_AVAIL 1 -# define SSL_VALUE_QUIC_STREAM_BIDI_REMOTE_AVAIL 2 -# define SSL_VALUE_QUIC_STREAM_UNI_LOCAL_AVAIL 3 -# define SSL_VALUE_QUIC_STREAM_UNI_REMOTE_AVAIL 4 -# define SSL_VALUE_QUIC_IDLE_TIMEOUT 5 -# define SSL_VALUE_EVENT_HANDLING_MODE 6 -# define SSL_VALUE_STREAM_WRITE_BUF_SIZE 7 -# define SSL_VALUE_STREAM_WRITE_BUF_USED 8 -# define SSL_VALUE_STREAM_WRITE_BUF_AVAIL 9 +#define SSL_VALUE_NONE 0 +#define SSL_VALUE_QUIC_STREAM_BIDI_LOCAL_AVAIL 1 +#define SSL_VALUE_QUIC_STREAM_BIDI_REMOTE_AVAIL 2 +#define SSL_VALUE_QUIC_STREAM_UNI_LOCAL_AVAIL 3 +#define SSL_VALUE_QUIC_STREAM_UNI_REMOTE_AVAIL 4 +#define SSL_VALUE_QUIC_IDLE_TIMEOUT 5 +#define SSL_VALUE_EVENT_HANDLING_MODE 6 +#define SSL_VALUE_STREAM_WRITE_BUF_SIZE 7 +#define SSL_VALUE_STREAM_WRITE_BUF_USED 8 +#define SSL_VALUE_STREAM_WRITE_BUF_AVAIL 9 -# define SSL_VALUE_EVENT_HANDLING_MODE_INHERIT 0 -# define SSL_VALUE_EVENT_HANDLING_MODE_IMPLICIT 1 -# define SSL_VALUE_EVENT_HANDLING_MODE_EXPLICIT 2 +#define SSL_VALUE_EVENT_HANDLING_MODE_INHERIT 0 +#define SSL_VALUE_EVENT_HANDLING_MODE_IMPLICIT 1 +#define SSL_VALUE_EVENT_HANDLING_MODE_EXPLICIT 2 int SSL_get_value_uint(SSL *s, uint32_t class_, uint32_t id, uint64_t *v); int SSL_set_value_uint(SSL *s, uint32_t class_, uint32_t id, uint64_t v); -# define SSL_get_generic_value_uint(ssl, id, v) \ +#define SSL_get_generic_value_uint(ssl, id, v) \ SSL_get_value_uint((ssl), SSL_VALUE_CLASS_GENERIC, (id), (v)) -# define SSL_set_generic_value_uint(ssl, id, v) \ +#define SSL_set_generic_value_uint(ssl, id, v) \ SSL_set_value_uint((ssl), SSL_VALUE_CLASS_GENERIC, (id), (v)) -# define SSL_get_feature_request_uint(ssl, id, v) \ +#define SSL_get_feature_request_uint(ssl, id, v) \ SSL_get_value_uint((ssl), SSL_VALUE_CLASS_FEATURE_REQUEST, (id), (v)) -# define SSL_set_feature_request_uint(ssl, id, v) \ +#define SSL_set_feature_request_uint(ssl, id, v) \ SSL_set_value_uint((ssl), SSL_VALUE_CLASS_FEATURE_REQUEST, (id), (v)) -# define SSL_get_feature_peer_request_uint(ssl, id, v) \ +#define SSL_get_feature_peer_request_uint(ssl, id, v) \ SSL_get_value_uint((ssl), SSL_VALUE_CLASS_FEATURE_PEER_REQUEST, (id), (v)) -# define SSL_get_feature_negotiated_uint(ssl, id, v) \ +#define SSL_get_feature_negotiated_uint(ssl, id, v) \ SSL_get_value_uint((ssl), SSL_VALUE_CLASS_FEATURE_NEGOTIATED, (id), (v)) -# define SSL_get_quic_stream_bidi_local_avail(ssl, value) \ +#define SSL_get_quic_stream_bidi_local_avail(ssl, value) \ SSL_get_generic_value_uint((ssl), SSL_VALUE_QUIC_STREAM_BIDI_LOCAL_AVAIL, \ - (value)) -# define SSL_get_quic_stream_bidi_remote_avail(ssl, value) \ + (value)) +#define SSL_get_quic_stream_bidi_remote_avail(ssl, value) \ SSL_get_generic_value_uint((ssl), SSL_VALUE_QUIC_STREAM_BIDI_REMOTE_AVAIL, \ - (value)) -# define SSL_get_quic_stream_uni_local_avail(ssl, value) \ + (value)) +#define SSL_get_quic_stream_uni_local_avail(ssl, value) \ SSL_get_generic_value_uint((ssl), SSL_VALUE_QUIC_STREAM_UNI_LOCAL_AVAIL, \ - (value)) -# define SSL_get_quic_stream_uni_remote_avail(ssl, value) \ + (value)) +#define SSL_get_quic_stream_uni_remote_avail(ssl, value) \ SSL_get_generic_value_uint((ssl), SSL_VALUE_QUIC_STREAM_UNI_REMOTE_AVAIL, \ - (value)) + (value)) -# define SSL_get_event_handling_mode(ssl, value) \ +#define SSL_get_event_handling_mode(ssl, value) \ SSL_get_generic_value_uint((ssl), SSL_VALUE_EVENT_HANDLING_MODE, \ - (value)) -# define SSL_set_event_handling_mode(ssl, value) \ + (value)) +#define SSL_set_event_handling_mode(ssl, value) \ SSL_set_generic_value_uint((ssl), SSL_VALUE_EVENT_HANDLING_MODE, \ - (value)) + (value)) -# define SSL_get_stream_write_buf_size(ssl, value) \ +#define SSL_get_stream_write_buf_size(ssl, value) \ SSL_get_generic_value_uint((ssl), SSL_VALUE_STREAM_WRITE_BUF_SIZE, \ - (value)) -# define SSL_get_stream_write_buf_used(ssl, value) \ + (value)) +#define SSL_get_stream_write_buf_used(ssl, value) \ SSL_get_generic_value_uint((ssl), SSL_VALUE_STREAM_WRITE_BUF_USED, \ - (value)) -# define SSL_get_stream_write_buf_avail(ssl, value) \ + (value)) +#define SSL_get_stream_write_buf_avail(ssl, value) \ SSL_get_generic_value_uint((ssl), SSL_VALUE_STREAM_WRITE_BUF_AVAIL, \ - (value)) + (value)) -# define SSL_POLL_EVENT_NONE 0 +#define SSL_POLL_EVENT_NONE 0 -# define SSL_POLL_EVENT_F (1U << 0) /* F (Failure) */ -# define SSL_POLL_EVENT_EL (1U << 1) /* EL (Exception on Listener) */ -# define SSL_POLL_EVENT_EC (1U << 2) /* EC (Exception on Conn) */ -# define SSL_POLL_EVENT_ECD (1U << 3) /* ECD (Exception on Conn Drained) */ -# define SSL_POLL_EVENT_ER (1U << 4) /* ER (Exception on Read) */ -# define SSL_POLL_EVENT_EW (1U << 5) /* EW (Exception on Write) */ -# define SSL_POLL_EVENT_R (1U << 6) /* R (Readable) */ -# define SSL_POLL_EVENT_W (1U << 7) /* W (Writable) */ -# define SSL_POLL_EVENT_IC (1U << 8) /* IC (Incoming Connection) */ -# define SSL_POLL_EVENT_ISB (1U << 9) /* ISB (Incoming Stream: Bidi) */ -# define SSL_POLL_EVENT_ISU (1U << 10) /* ISU (Incoming Stream: Uni) */ -# define SSL_POLL_EVENT_OSB (1U << 11) /* OSB (Outgoing Stream: Bidi) */ -# define SSL_POLL_EVENT_OSU (1U << 12) /* OSU (Outgoing Stream: Uni) */ +#define SSL_POLL_EVENT_F (1U << 0) /* F (Failure) */ +#define SSL_POLL_EVENT_EL (1U << 1) /* EL (Exception on Listener) */ +#define SSL_POLL_EVENT_EC (1U << 2) /* EC (Exception on Conn) */ +#define SSL_POLL_EVENT_ECD (1U << 3) /* ECD (Exception on Conn Drained) */ +#define SSL_POLL_EVENT_ER (1U << 4) /* ER (Exception on Read) */ +#define SSL_POLL_EVENT_EW (1U << 5) /* EW (Exception on Write) */ +#define SSL_POLL_EVENT_R (1U << 6) /* R (Readable) */ +#define SSL_POLL_EVENT_W (1U << 7) /* W (Writable) */ +#define SSL_POLL_EVENT_IC (1U << 8) /* IC (Incoming Connection) */ +#define SSL_POLL_EVENT_ISB (1U << 9) /* ISB (Incoming Stream: Bidi) */ +#define SSL_POLL_EVENT_ISU (1U << 10) /* ISU (Incoming Stream: Uni) */ +#define SSL_POLL_EVENT_OSB (1U << 11) /* OSB (Outgoing Stream: Bidi) */ +#define SSL_POLL_EVENT_OSU (1U << 12) /* OSU (Outgoing Stream: Uni) */ -# define SSL_POLL_EVENT_RW (SSL_POLL_EVENT_R | SSL_POLL_EVENT_W) -# define SSL_POLL_EVENT_RE (SSL_POLL_EVENT_R | SSL_POLL_EVENT_ER) -# define SSL_POLL_EVENT_WE (SSL_POLL_EVENT_W | SSL_POLL_EVENT_EW) -# define SSL_POLL_EVENT_RWE (SSL_POLL_EVENT_RE | SSL_POLL_EVENT_WE) -# define SSL_POLL_EVENT_E (SSL_POLL_EVENT_EL | SSL_POLL_EVENT_EC \ - | SSL_POLL_EVENT_ER | SSL_POLL_EVENT_EW) -# define SSL_POLL_EVENT_IS (SSL_POLL_EVENT_ISB | SSL_POLL_EVENT_ISU) -# define SSL_POLL_EVENT_ISE (SSL_POLL_EVENT_IS | SSL_POLL_EVENT_EC) -# define SSL_POLL_EVENT_I (SSL_POLL_EVENT_IS | SSL_POLL_EVENT_IC) -# define SSL_POLL_EVENT_OS (SSL_POLL_EVENT_OSB | SSL_POLL_EVENT_OSU) -# define SSL_POLL_EVENT_OSE (SSL_POLL_EVENT_OS | SSL_POLL_EVENT_EC) +#define SSL_POLL_EVENT_RW (SSL_POLL_EVENT_R | SSL_POLL_EVENT_W) +#define SSL_POLL_EVENT_RE (SSL_POLL_EVENT_R | SSL_POLL_EVENT_ER) +#define SSL_POLL_EVENT_WE (SSL_POLL_EVENT_W | SSL_POLL_EVENT_EW) +#define SSL_POLL_EVENT_RWE (SSL_POLL_EVENT_RE | SSL_POLL_EVENT_WE) +#define SSL_POLL_EVENT_E (SSL_POLL_EVENT_EL | SSL_POLL_EVENT_EC \ + | SSL_POLL_EVENT_ER | SSL_POLL_EVENT_EW) +#define SSL_POLL_EVENT_IS (SSL_POLL_EVENT_ISB | SSL_POLL_EVENT_ISU) +#define SSL_POLL_EVENT_ISE (SSL_POLL_EVENT_IS | SSL_POLL_EVENT_EC) +#define SSL_POLL_EVENT_I (SSL_POLL_EVENT_IS | SSL_POLL_EVENT_IC) +#define SSL_POLL_EVENT_OS (SSL_POLL_EVENT_OSB | SSL_POLL_EVENT_OSU) +#define SSL_POLL_EVENT_OSE (SSL_POLL_EVENT_OS | SSL_POLL_EVENT_EC) typedef struct ssl_poll_item_st { BIO_POLL_DESCRIPTOR desc; - uint64_t events, revents; + uint64_t events, revents; } SSL_POLL_ITEM; -# define SSL_POLL_FLAG_NO_HANDLE_EVENTS (1U << 0) +#define SSL_POLL_FLAG_NO_HANDLE_EVENTS (1U << 0) __owur int SSL_poll(SSL_POLL_ITEM *items, - size_t num_items, - size_t stride, - const struct timeval *timeout, - uint64_t flags, - size_t *result_count); + size_t num_items, + size_t stride, + const struct timeval *timeout, + uint64_t flags, + size_t *result_count); static ossl_inline ossl_unused BIO_POLL_DESCRIPTOR SSL_as_poll_descriptor(SSL *s) { BIO_POLL_DESCRIPTOR d; - d.type = BIO_POLL_DESCRIPTOR_TYPE_SSL; + d.type = BIO_POLL_DESCRIPTOR_TYPE_SSL; d.value.ssl = s; return d; } -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define SSL_cache_hit(s) SSL_session_reused(s) -# endif +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define SSL_cache_hit(s) SSL_session_reused(s) +#endif __owur int SSL_session_reused(const SSL *s); __owur int SSL_is_server(const SSL *s); -__owur __owur SSL_CONF_CTX *SSL_CONF_CTX_new(void); +__owur SSL_CONF_CTX *SSL_CONF_CTX_new(void); int SSL_CONF_CTX_finish(SSL_CONF_CTX *cctx); void SSL_CONF_CTX_free(SSL_CONF_CTX *cctx); unsigned int SSL_CONF_CTX_set_flags(SSL_CONF_CTX *cctx, unsigned int flags); __owur unsigned int SSL_CONF_CTX_clear_flags(SSL_CONF_CTX *cctx, - unsigned int flags); + unsigned int flags); __owur int SSL_CONF_CTX_set1_prefix(SSL_CONF_CTX *cctx, const char *pre); void SSL_CONF_CTX_set_ssl(SSL_CONF_CTX *cctx, SSL *ssl); @@ -2609,16 +2617,16 @@ void SSL_add_ssl_module(void); int SSL_config(SSL *s, const char *name); int SSL_CTX_config(SSL_CTX *ctx, const char *name); -# ifndef OPENSSL_NO_SSL_TRACE +#ifndef OPENSSL_NO_SSL_TRACE void SSL_trace(int write_p, int version, int content_type, - const void *buf, size_t len, SSL *ssl, void *arg); -# endif + const void *buf, size_t len, SSL *ssl, void *arg); +#endif -# ifndef OPENSSL_NO_SOCK +#ifndef OPENSSL_NO_SOCK int DTLSv1_listen(SSL *s, BIO_ADDR *client); -# endif +#endif -# ifndef OPENSSL_NO_CT +#ifndef OPENSSL_NO_CT /* * A callback for verifying that the received SCTs are sufficient. @@ -2627,7 +2635,7 @@ int DTLSv1_listen(SSL *s, BIO_ADDR *client); * A connection should be aborted if the SCTs are deemed insufficient. */ typedef int (*ssl_ct_validation_cb)(const CT_POLICY_EVAL_CTX *ctx, - const STACK_OF(SCT) *scts, void *arg); + const STACK_OF(SCT) *scts, void *arg); /* * Sets a |callback| that is invoked upon receipt of ServerHelloDone to validate @@ -2642,14 +2650,14 @@ typedef int (*ssl_ct_validation_cb)(const CT_POLICY_EVAL_CTX *ctx, * will be requested. */ int SSL_set_ct_validation_callback(SSL *s, ssl_ct_validation_cb callback, - void *arg); + void *arg); int SSL_CTX_set_ct_validation_callback(SSL_CTX *ctx, - ssl_ct_validation_cb callback, - void *arg); + ssl_ct_validation_cb callback, + void *arg); #define SSL_disable_ct(s) \ - ((void) SSL_set_validation_callback((s), NULL, NULL)) + ((void)SSL_set_validation_callback((s), NULL, NULL)) #define SSL_CTX_disable_ct(ctx) \ - ((void) SSL_CTX_set_validation_callback((ctx), NULL, NULL)) + ((void)SSL_CTX_set_validation_callback((ctx), NULL, NULL)) /* * The validation type enumerates the available behaviours of the built-in SSL @@ -2714,106 +2722,106 @@ void SSL_CTX_set0_ctlog_store(SSL_CTX *ctx, CTLOG_STORE *logs); */ const CTLOG_STORE *SSL_CTX_get0_ctlog_store(const SSL_CTX *ctx); -# endif /* OPENSSL_NO_CT */ +#endif /* OPENSSL_NO_CT */ /* What the "other" parameter contains in security callback */ /* Mask for type */ -# define SSL_SECOP_OTHER_TYPE 0xffff0000 -# define SSL_SECOP_OTHER_NONE 0 -# define SSL_SECOP_OTHER_CIPHER (1 << 16) -# define SSL_SECOP_OTHER_CURVE (2 << 16) -# define SSL_SECOP_OTHER_DH (3 << 16) -# define SSL_SECOP_OTHER_PKEY (4 << 16) -# define SSL_SECOP_OTHER_SIGALG (5 << 16) -# define SSL_SECOP_OTHER_CERT (6 << 16) +#define SSL_SECOP_OTHER_TYPE 0xffff0000 +#define SSL_SECOP_OTHER_NONE 0 +#define SSL_SECOP_OTHER_CIPHER (1 << 16) +#define SSL_SECOP_OTHER_CURVE (2 << 16) +#define SSL_SECOP_OTHER_DH (3 << 16) +#define SSL_SECOP_OTHER_PKEY (4 << 16) +#define SSL_SECOP_OTHER_SIGALG (5 << 16) +#define SSL_SECOP_OTHER_CERT (6 << 16) /* Indicated operation refers to peer key or certificate */ -# define SSL_SECOP_PEER 0x1000 +#define SSL_SECOP_PEER 0x1000 /* Values for "op" parameter in security callback */ /* Called to filter ciphers */ /* Ciphers client supports */ -# define SSL_SECOP_CIPHER_SUPPORTED (1 | SSL_SECOP_OTHER_CIPHER) +#define SSL_SECOP_CIPHER_SUPPORTED (1 | SSL_SECOP_OTHER_CIPHER) /* Cipher shared by client/server */ -# define SSL_SECOP_CIPHER_SHARED (2 | SSL_SECOP_OTHER_CIPHER) +#define SSL_SECOP_CIPHER_SHARED (2 | SSL_SECOP_OTHER_CIPHER) /* Sanity check of cipher server selects */ -# define SSL_SECOP_CIPHER_CHECK (3 | SSL_SECOP_OTHER_CIPHER) +#define SSL_SECOP_CIPHER_CHECK (3 | SSL_SECOP_OTHER_CIPHER) /* Curves supported by client */ -# define SSL_SECOP_CURVE_SUPPORTED (4 | SSL_SECOP_OTHER_CURVE) +#define SSL_SECOP_CURVE_SUPPORTED (4 | SSL_SECOP_OTHER_CURVE) /* Curves shared by client/server */ -# define SSL_SECOP_CURVE_SHARED (5 | SSL_SECOP_OTHER_CURVE) +#define SSL_SECOP_CURVE_SHARED (5 | SSL_SECOP_OTHER_CURVE) /* Sanity check of curve server selects */ -# define SSL_SECOP_CURVE_CHECK (6 | SSL_SECOP_OTHER_CURVE) +#define SSL_SECOP_CURVE_CHECK (6 | SSL_SECOP_OTHER_CURVE) /* Temporary DH key */ -# define SSL_SECOP_TMP_DH (7 | SSL_SECOP_OTHER_PKEY) +#define SSL_SECOP_TMP_DH (7 | SSL_SECOP_OTHER_PKEY) /* SSL/TLS version */ -# define SSL_SECOP_VERSION (9 | SSL_SECOP_OTHER_NONE) +#define SSL_SECOP_VERSION (9 | SSL_SECOP_OTHER_NONE) /* Session tickets */ -# define SSL_SECOP_TICKET (10 | SSL_SECOP_OTHER_NONE) +#define SSL_SECOP_TICKET (10 | SSL_SECOP_OTHER_NONE) /* Supported signature algorithms sent to peer */ -# define SSL_SECOP_SIGALG_SUPPORTED (11 | SSL_SECOP_OTHER_SIGALG) +#define SSL_SECOP_SIGALG_SUPPORTED (11 | SSL_SECOP_OTHER_SIGALG) /* Shared signature algorithm */ -# define SSL_SECOP_SIGALG_SHARED (12 | SSL_SECOP_OTHER_SIGALG) +#define SSL_SECOP_SIGALG_SHARED (12 | SSL_SECOP_OTHER_SIGALG) /* Sanity check signature algorithm allowed */ -# define SSL_SECOP_SIGALG_CHECK (13 | SSL_SECOP_OTHER_SIGALG) +#define SSL_SECOP_SIGALG_CHECK (13 | SSL_SECOP_OTHER_SIGALG) /* Used to get mask of supported public key signature algorithms */ -# define SSL_SECOP_SIGALG_MASK (14 | SSL_SECOP_OTHER_SIGALG) +#define SSL_SECOP_SIGALG_MASK (14 | SSL_SECOP_OTHER_SIGALG) /* Use to see if compression is allowed */ -# define SSL_SECOP_COMPRESSION (15 | SSL_SECOP_OTHER_NONE) +#define SSL_SECOP_COMPRESSION (15 | SSL_SECOP_OTHER_NONE) /* EE key in certificate */ -# define SSL_SECOP_EE_KEY (16 | SSL_SECOP_OTHER_CERT) +#define SSL_SECOP_EE_KEY (16 | SSL_SECOP_OTHER_CERT) /* CA key in certificate */ -# define SSL_SECOP_CA_KEY (17 | SSL_SECOP_OTHER_CERT) +#define SSL_SECOP_CA_KEY (17 | SSL_SECOP_OTHER_CERT) /* CA digest algorithm in certificate */ -# define SSL_SECOP_CA_MD (18 | SSL_SECOP_OTHER_CERT) +#define SSL_SECOP_CA_MD (18 | SSL_SECOP_OTHER_CERT) /* Peer EE key in certificate */ -# define SSL_SECOP_PEER_EE_KEY (SSL_SECOP_EE_KEY | SSL_SECOP_PEER) +#define SSL_SECOP_PEER_EE_KEY (SSL_SECOP_EE_KEY | SSL_SECOP_PEER) /* Peer CA key in certificate */ -# define SSL_SECOP_PEER_CA_KEY (SSL_SECOP_CA_KEY | SSL_SECOP_PEER) +#define SSL_SECOP_PEER_CA_KEY (SSL_SECOP_CA_KEY | SSL_SECOP_PEER) /* Peer CA digest algorithm in certificate */ -# define SSL_SECOP_PEER_CA_MD (SSL_SECOP_CA_MD | SSL_SECOP_PEER) +#define SSL_SECOP_PEER_CA_MD (SSL_SECOP_CA_MD | SSL_SECOP_PEER) void SSL_set_security_level(SSL *s, int level); __owur int SSL_get_security_level(const SSL *s); void SSL_set_security_callback(SSL *s, - int (*cb) (const SSL *s, const SSL_CTX *ctx, - int op, int bits, int nid, - void *other, void *ex)); -int (*SSL_get_security_callback(const SSL *s)) (const SSL *s, - const SSL_CTX *ctx, int op, - int bits, int nid, void *other, - void *ex); + int (*cb)(const SSL *s, const SSL_CTX *ctx, + int op, int bits, int nid, + void *other, void *ex)); +int (*SSL_get_security_callback(const SSL *s))(const SSL *s, + const SSL_CTX *ctx, int op, + int bits, int nid, void *other, + void *ex); void SSL_set0_security_ex_data(SSL *s, void *ex); __owur void *SSL_get0_security_ex_data(const SSL *s); void SSL_CTX_set_security_level(SSL_CTX *ctx, int level); __owur int SSL_CTX_get_security_level(const SSL_CTX *ctx); void SSL_CTX_set_security_callback(SSL_CTX *ctx, - int (*cb) (const SSL *s, const SSL_CTX *ctx, - int op, int bits, int nid, - void *other, void *ex)); -int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx)) (const SSL *s, - const SSL_CTX *ctx, - int op, int bits, - int nid, - void *other, - void *ex); + int (*cb)(const SSL *s, const SSL_CTX *ctx, + int op, int bits, int nid, + void *other, void *ex)); +int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx))(const SSL *s, + const SSL_CTX *ctx, + int op, int bits, + int nid, + void *other, + void *ex); void SSL_CTX_set0_security_ex_data(SSL_CTX *ctx, void *ex); __owur void *SSL_CTX_get0_security_ex_data(const SSL_CTX *ctx); /* OPENSSL_INIT flag 0x010000 reserved for internal use */ -# define OPENSSL_INIT_NO_LOAD_SSL_STRINGS 0x00100000L -# define OPENSSL_INIT_LOAD_SSL_STRINGS 0x00200000L +#define OPENSSL_INIT_NO_LOAD_SSL_STRINGS 0x00100000L +#define OPENSSL_INIT_LOAD_SSL_STRINGS 0x00200000L -# define OPENSSL_INIT_SSL_DEFAULT \ - (OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS) +#define OPENSSL_INIT_SSL_DEFAULT \ + (OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS) int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings); -# ifndef OPENSSL_NO_UNIT_TEST +#ifndef OPENSSL_NO_UNIT_TEST __owur const struct openssl_ssl_test_functions *SSL_test_functions(void); -# endif +#endif __owur int SSL_free_buffers(SSL *ssl); __owur int SSL_alloc_buffers(SSL *ssl); @@ -2824,44 +2832,44 @@ typedef int SSL_TICKET_STATUS; /* Support for ticket appdata */ /* fatal error, malloc failure */ -# define SSL_TICKET_FATAL_ERR_MALLOC 0 +#define SSL_TICKET_FATAL_ERR_MALLOC 0 /* fatal error, either from parsing or decrypting the ticket */ -# define SSL_TICKET_FATAL_ERR_OTHER 1 +#define SSL_TICKET_FATAL_ERR_OTHER 1 /* No ticket present */ -# define SSL_TICKET_NONE 2 +#define SSL_TICKET_NONE 2 /* Empty ticket present */ -# define SSL_TICKET_EMPTY 3 +#define SSL_TICKET_EMPTY 3 /* the ticket couldn't be decrypted */ -# define SSL_TICKET_NO_DECRYPT 4 +#define SSL_TICKET_NO_DECRYPT 4 /* a ticket was successfully decrypted */ -# define SSL_TICKET_SUCCESS 5 +#define SSL_TICKET_SUCCESS 5 /* same as above but the ticket needs to be renewed */ -# define SSL_TICKET_SUCCESS_RENEW 6 +#define SSL_TICKET_SUCCESS_RENEW 6 /* Return codes for the decrypt session ticket callback */ typedef int SSL_TICKET_RETURN; /* An error occurred */ -#define SSL_TICKET_RETURN_ABORT 0 +#define SSL_TICKET_RETURN_ABORT 0 /* Do not use the ticket, do not send a renewed ticket to the client */ -#define SSL_TICKET_RETURN_IGNORE 1 +#define SSL_TICKET_RETURN_IGNORE 1 /* Do not use the ticket, send a renewed ticket to the client */ -#define SSL_TICKET_RETURN_IGNORE_RENEW 2 +#define SSL_TICKET_RETURN_IGNORE_RENEW 2 /* Use the ticket, do not send a renewed ticket to the client */ -#define SSL_TICKET_RETURN_USE 3 +#define SSL_TICKET_RETURN_USE 3 /* Use the ticket, send a renewed ticket to the client */ -#define SSL_TICKET_RETURN_USE_RENEW 4 +#define SSL_TICKET_RETURN_USE_RENEW 4 typedef int (*SSL_CTX_generate_session_ticket_fn)(SSL *s, void *arg); typedef SSL_TICKET_RETURN (*SSL_CTX_decrypt_session_ticket_fn)(SSL *s, SSL_SESSION *ss, - const unsigned char *keyname, - size_t keyname_length, - SSL_TICKET_STATUS status, - void *arg); + const unsigned char *keyname, + size_t keyname_length, + SSL_TICKET_STATUS status, + void *arg); int SSL_CTX_set_session_ticket_cb(SSL_CTX *ctx, - SSL_CTX_generate_session_ticket_fn gen_cb, - SSL_CTX_decrypt_session_ticket_fn dec_cb, - void *arg); + SSL_CTX_generate_session_ticket_fn gen_cb, + SSL_CTX_decrypt_session_ticket_fn dec_cb, + void *arg); int SSL_SESSION_set1_ticket_appdata(SSL_SESSION *ss, const void *data, size_t len); int SSL_SESSION_get0_ticket_appdata(SSL_SESSION *ss, void **data, size_t *len); @@ -2869,14 +2877,13 @@ typedef unsigned int (*DTLS_timer_cb)(SSL *s, unsigned int timer_us); void DTLS_set_timer_cb(SSL *s, DTLS_timer_cb cb); - typedef int (*SSL_allow_early_data_cb_fn)(SSL *s, void *arg); void SSL_CTX_set_allow_early_data_cb(SSL_CTX *ctx, - SSL_allow_early_data_cb_fn cb, - void *arg); + SSL_allow_early_data_cb_fn cb, + void *arg); void SSL_set_allow_early_data_cb(SSL *s, - SSL_allow_early_data_cb_fn cb, - void *arg); + SSL_allow_early_data_cb_fn cb, + void *arg); /* store the default cipher strings inside the library */ const char *OSSL_default_cipher_list(void); @@ -2891,9 +2898,9 @@ int SSL_CTX_set1_cert_comp_preference(SSL_CTX *ctx, int *algs, size_t len); int SSL_set1_cert_comp_preference(SSL *ssl, int *algs, size_t len); int SSL_CTX_set1_compressed_cert(SSL_CTX *ctx, int algorithm, unsigned char *comp_data, - size_t comp_length, size_t orig_length); + size_t comp_length, size_t orig_length); int SSL_set1_compressed_cert(SSL *ssl, int algorithm, unsigned char *comp_data, - size_t comp_length, size_t orig_length); + size_t comp_length, size_t orig_length); size_t SSL_CTX_get1_compressed_cert(SSL_CTX *ctx, int alg, unsigned char **data, size_t *orig_len); size_t SSL_get1_compressed_cert(SSL *ssl, int alg, unsigned char **data, size_t *orig_len); @@ -2915,19 +2922,19 @@ __owur int SSL_CTX_get0_server_cert_type(const SSL_CTX *s, unsigned char **t, si /* * Protection level. For <= TLSv1.2 only "NONE" and "APPLICATION" are used. */ -# define OSSL_RECORD_PROTECTION_LEVEL_NONE 0 -# define OSSL_RECORD_PROTECTION_LEVEL_EARLY 1 -# define OSSL_RECORD_PROTECTION_LEVEL_HANDSHAKE 2 -# define OSSL_RECORD_PROTECTION_LEVEL_APPLICATION 3 +#define OSSL_RECORD_PROTECTION_LEVEL_NONE 0 +#define OSSL_RECORD_PROTECTION_LEVEL_EARLY 1 +#define OSSL_RECORD_PROTECTION_LEVEL_HANDSHAKE 2 +#define OSSL_RECORD_PROTECTION_LEVEL_APPLICATION 3 int SSL_set_quic_tls_cbs(SSL *s, const OSSL_DISPATCH *qtdis, void *arg); int SSL_set_quic_tls_transport_params(SSL *s, - const unsigned char *params, - size_t params_len); + const unsigned char *params, + size_t params_len); int SSL_set_quic_tls_early_data_enabled(SSL *s, int enabled); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ui.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ui.h index a38e349550..40878b480b 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ui.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/ui.h @@ -10,37 +10,39 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_UI_H -# define OPENSSL_UI_H -# pragma once +#define OPENSSL_UI_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_UI_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_UI_H +#endif -# include +#include -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# include -# endif -# include -# include -# include -# include +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#include +#endif +#include +#include +#include +#include /* For compatibility reasons, the macro OPENSSL_NO_UI is currently retained */ -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# ifdef OPENSSL_NO_UI_CONSOLE -# define OPENSSL_NO_UI -# endif -# endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifdef OPENSSL_NO_UI_CONSOLE +#define OPENSSL_NO_UI +#endif +#endif -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif /* * All the following functions return -1 or NULL on error and in some cases @@ -98,21 +100,21 @@ void UI_free(UI *ui); On success, the all return an index of the added information. That index is useful when retrieving results with UI_get0_result(). */ int UI_add_input_string(UI *ui, const char *prompt, int flags, - char *result_buf, int minsize, int maxsize); + char *result_buf, int minsize, int maxsize); int UI_dup_input_string(UI *ui, const char *prompt, int flags, - char *result_buf, int minsize, int maxsize); + char *result_buf, int minsize, int maxsize); int UI_add_verify_string(UI *ui, const char *prompt, int flags, - char *result_buf, int minsize, int maxsize, - const char *test_buf); + char *result_buf, int minsize, int maxsize, + const char *test_buf); int UI_dup_verify_string(UI *ui, const char *prompt, int flags, - char *result_buf, int minsize, int maxsize, - const char *test_buf); + char *result_buf, int minsize, int maxsize, + const char *test_buf); int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, - const char *ok_chars, const char *cancel_chars, - int flags, char *result_buf); + const char *ok_chars, const char *cancel_chars, + int flags, char *result_buf); int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, - const char *ok_chars, const char *cancel_chars, - int flags, char *result_buf); + const char *ok_chars, const char *cancel_chars, + int flags, char *result_buf); int UI_add_info_string(UI *ui, const char *text); int UI_dup_info_string(UI *ui, const char *text); int UI_add_error_string(UI *ui, const char *text); @@ -120,7 +122,7 @@ int UI_dup_error_string(UI *ui, const char *text); /* These are the possible flags. They can be or'ed together. */ /* Use to have echoing of input */ -# define UI_INPUT_FLAG_ECHO 0x01 +#define UI_INPUT_FLAG_ECHO 0x01 /* * Use a default password. Where that password is found is completely up to * the application, it might for example be in the user data set with @@ -128,7 +130,7 @@ int UI_dup_error_string(UI *ui, const char *text); * each UI being marked with this flag, or the application might get * confused. */ -# define UI_INPUT_FLAG_DEFAULT_PWD 0x02 +#define UI_INPUT_FLAG_DEFAULT_PWD 0x02 /*- * The user of these routines may want to define flags of their own. The core @@ -139,8 +141,8 @@ int UI_dup_error_string(UI *ui, const char *text); * * #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE) * -*/ -# define UI_INPUT_FLAG_USER_BASE 16 + */ +#define UI_INPUT_FLAG_USER_BASE 16 /*- * The following function helps construct a prompt. @@ -160,9 +162,9 @@ int UI_dup_error_string(UI *ui, const char *text); * the value "foo.key", the resulting string is: * * "Enter pass phrase for foo.key:" -*/ + */ char *UI_construct_prompt(UI *ui_method, - const char *phrase_desc, const char *object_name); + const char *phrase_desc, const char *object_name); /* * The following function is used to store a pointer to user-specific data. @@ -197,7 +199,7 @@ int UI_process(UI *ui); * send down an integer, a data pointer or a function pointer, as well as be * used to get information from a UI. */ -int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)); +int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)); /* The commands */ /* @@ -205,19 +207,19 @@ int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)); * OpenSSL error stack before printing any info or added error messages and * before any prompting. */ -# define UI_CTRL_PRINT_ERRORS 1 +#define UI_CTRL_PRINT_ERRORS 1 /* * Check if a UI_process() is possible to do again with the same instance of * a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0 * if not. */ -# define UI_CTRL_IS_REDOABLE 2 +#define UI_CTRL_IS_REDOABLE 2 /* Some methods may use extra data */ -# define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg) -# define UI_get_app_data(s) UI_get_ex_data(s,0) +#define UI_set_app_data(s, arg) UI_set_ex_data(s, 0, arg) +#define UI_get_app_data(s) UI_get_ex_data(s, 0) -# define UI_get_ex_new_index(l, p, newf, dupf, freef) \ +#define UI_get_ex_new_index(l, p, newf, dupf, freef) \ CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, l, p, newf, dupf, freef) int UI_set_ex_data(UI *r, int idx, void *arg); void *UI_get_ex_data(const UI *r, int idx); @@ -228,12 +230,12 @@ const UI_METHOD *UI_get_default_method(void); const UI_METHOD *UI_get_method(UI *ui); const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth); -# ifndef OPENSSL_NO_UI_CONSOLE +#ifndef OPENSSL_NO_UI_CONSOLE /* The method with all the built-in thingies */ UI_METHOD *UI_OpenSSL(void); -# endif +#endif /* * NULL method. Literally does nothing, but may serve as a placeholder @@ -290,6 +292,7 @@ const UI_METHOD *UI_null(void); */ typedef struct ui_string_st UI_STRING; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(UI_STRING, UI_STRING, UI_STRING) #define sk_UI_STRING_num(sk) OPENSSL_sk_num(ossl_check_const_UI_STRING_sk_type(sk)) #define sk_UI_STRING_value(sk, idx) ((UI_STRING *)OPENSSL_sk_value(ossl_check_const_UI_STRING_sk_type(sk), (idx))) @@ -317,6 +320,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(UI_STRING, UI_STRING, UI_STRING) #define sk_UI_STRING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(UI_STRING) *)OPENSSL_sk_deep_copy(ossl_check_const_UI_STRING_sk_type(sk), ossl_check_UI_STRING_copyfunc_type(copyfunc), ossl_check_UI_STRING_freefunc_type(freefunc))) #define sk_UI_STRING_set_cmp_func(sk, cmp) ((sk_UI_STRING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_UI_STRING_sk_type(sk), ossl_check_UI_STRING_compfunc_type(cmp))) +/* clang-format on */ /* * The different types of strings that are currently supported. This is only @@ -324,42 +328,41 @@ SKM_DEFINE_STACK_OF_INTERNAL(UI_STRING, UI_STRING, UI_STRING) */ enum UI_string_types { UIT_NONE = 0, - UIT_PROMPT, /* Prompt for a string */ - UIT_VERIFY, /* Prompt for a string and verify */ - UIT_BOOLEAN, /* Prompt for a yes/no response */ - UIT_INFO, /* Send info to the user */ - UIT_ERROR /* Send an error message to the user */ + UIT_PROMPT, /* Prompt for a string */ + UIT_VERIFY, /* Prompt for a string and verify */ + UIT_BOOLEAN, /* Prompt for a yes/no response */ + UIT_INFO, /* Send info to the user */ + UIT_ERROR /* Send an error message to the user */ }; /* Create and manipulate methods */ UI_METHOD *UI_create_method(const char *name); void UI_destroy_method(UI_METHOD *ui_method); -int UI_method_set_opener(UI_METHOD *method, int (*opener) (UI *ui)); +int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)); int UI_method_set_writer(UI_METHOD *method, - int (*writer) (UI *ui, UI_STRING *uis)); -int UI_method_set_flusher(UI_METHOD *method, int (*flusher) (UI *ui)); + int (*writer)(UI *ui, UI_STRING *uis)); +int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)); int UI_method_set_reader(UI_METHOD *method, - int (*reader) (UI *ui, UI_STRING *uis)); -int UI_method_set_closer(UI_METHOD *method, int (*closer) (UI *ui)); + int (*reader)(UI *ui, UI_STRING *uis)); +int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)); int UI_method_set_data_duplicator(UI_METHOD *method, - void *(*duplicator) (UI *ui, void *ui_data), - void (*destructor)(UI *ui, void *ui_data)); + void *(*duplicator)(UI *ui, void *ui_data), + void (*destructor)(UI *ui, void *ui_data)); int UI_method_set_prompt_constructor(UI_METHOD *method, - char *(*prompt_constructor) (UI *ui, - const char - *phrase_desc, - const char - *object_name)); + char *(*prompt_constructor)(UI *ui, + const char + *phrase_desc, + const char + *object_name)); int UI_method_set_ex_data(UI_METHOD *method, int idx, void *data); -int (*UI_method_get_opener(const UI_METHOD *method)) (UI *); -int (*UI_method_get_writer(const UI_METHOD *method)) (UI *, UI_STRING *); -int (*UI_method_get_flusher(const UI_METHOD *method)) (UI *); -int (*UI_method_get_reader(const UI_METHOD *method)) (UI *, UI_STRING *); -int (*UI_method_get_closer(const UI_METHOD *method)) (UI *); -char *(*UI_method_get_prompt_constructor(const UI_METHOD *method)) - (UI *, const char *, const char *); -void *(*UI_method_get_data_duplicator(const UI_METHOD *method)) (UI *, void *); -void (*UI_method_get_data_destructor(const UI_METHOD *method)) (UI *, void *); +int (*UI_method_get_opener(const UI_METHOD *method))(UI *); +int (*UI_method_get_writer(const UI_METHOD *method))(UI *, UI_STRING *); +int (*UI_method_get_flusher(const UI_METHOD *method))(UI *); +int (*UI_method_get_reader(const UI_METHOD *method))(UI *, UI_STRING *); +int (*UI_method_get_closer(const UI_METHOD *method))(UI *); +char *(*UI_method_get_prompt_constructor(const UI_METHOD *method))(UI *, const char *, const char *); +void *(*UI_method_get_data_duplicator(const UI_METHOD *method))(UI *, void *); +void (*UI_method_get_data_destructor(const UI_METHOD *method))(UI *, void *); const void *UI_method_get_ex_data(const UI_METHOD *method, int idx); /* @@ -395,13 +398,12 @@ int UI_set_result_ex(UI *ui, UI_STRING *uis, const char *result, int len); /* A couple of popular utility functions */ int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, - int verify); + int verify); int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, - int verify); + int verify); UI_METHOD *UI_UTIL_wrap_read_pem_callback(pem_password_cb *cb, int rwflag); - -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509.h index d8e35f9258..b5ebf6f0bb 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509.h @@ -11,44 +11,47 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_X509_H -# define OPENSSL_X509_H -# pragma once +#define OPENSSL_X509_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_X509_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_X509_H +#endif -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# include -# include -# include -# endif +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#include +#include +#include +#endif -# include -# include -# ifndef OPENSSL_NO_STDIO -# include -# endif +#include +#include +#ifndef OPENSSL_NO_STDIO +#include +#endif -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif /* Needed stacks for types defined in other headers */ +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509_NAME, X509_NAME, X509_NAME) #define sk_X509_NAME_num(sk) OPENSSL_sk_num(ossl_check_const_X509_NAME_sk_type(sk)) #define sk_X509_NAME_value(sk, idx) ((X509_NAME *)OPENSSL_sk_value(ossl_check_const_X509_NAME_sk_type(sk), (idx))) @@ -154,16 +157,17 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_CRL, X509_CRL, X509_CRL) #define sk_X509_CRL_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_CRL) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_CRL_sk_type(sk), ossl_check_X509_CRL_copyfunc_type(copyfunc), ossl_check_X509_CRL_freefunc_type(freefunc))) #define sk_X509_CRL_set_cmp_func(sk, cmp) ((sk_X509_CRL_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_CRL_sk_type(sk), ossl_check_X509_CRL_compfunc_type(cmp))) +/* clang-format on */ /* Flags for X509_get_signature_info() */ /* Signature info is valid */ -# define X509_SIG_INFO_VALID 0x1 +#define X509_SIG_INFO_VALID 0x1 /* Signature is suitable for TLS use */ -# define X509_SIG_INFO_TLS 0x2 +#define X509_SIG_INFO_TLS 0x2 -# define X509_FILETYPE_PEM 1 -# define X509_FILETYPE_ASN1 2 -# define X509_FILETYPE_DEFAULT 3 +#define X509_FILETYPE_PEM 1 +#define X509_FILETYPE_ASN1 2 +#define X509_FILETYPE_DEFAULT 3 /*- * : @@ -171,23 +175,23 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_CRL, X509_CRL, X509_CRL) * is 0x80, while bit `7` is 0x01 (the LSB of the integer value), bit `8` is * then the MSB of the second octet, or 0x8000. */ -# define X509v3_KU_DIGITAL_SIGNATURE 0x0080 /* (0) */ -# define X509v3_KU_NON_REPUDIATION 0x0040 /* (1) */ -# define X509v3_KU_KEY_ENCIPHERMENT 0x0020 /* (2) */ -# define X509v3_KU_DATA_ENCIPHERMENT 0x0010 /* (3) */ -# define X509v3_KU_KEY_AGREEMENT 0x0008 /* (4) */ -# define X509v3_KU_KEY_CERT_SIGN 0x0004 /* (5) */ -# define X509v3_KU_CRL_SIGN 0x0002 /* (6) */ -# define X509v3_KU_ENCIPHER_ONLY 0x0001 /* (7) */ -# define X509v3_KU_DECIPHER_ONLY 0x8000 /* (8) */ -# ifndef OPENSSL_NO_DEPRECATED_3_4 -# define X509v3_KU_UNDEF 0xffff /* vestigial, not used */ -# endif +#define X509v3_KU_DIGITAL_SIGNATURE 0x0080 /* (0) */ +#define X509v3_KU_NON_REPUDIATION 0x0040 /* (1) */ +#define X509v3_KU_KEY_ENCIPHERMENT 0x0020 /* (2) */ +#define X509v3_KU_DATA_ENCIPHERMENT 0x0010 /* (3) */ +#define X509v3_KU_KEY_AGREEMENT 0x0008 /* (4) */ +#define X509v3_KU_KEY_CERT_SIGN 0x0004 /* (5) */ +#define X509v3_KU_CRL_SIGN 0x0002 /* (6) */ +#define X509v3_KU_ENCIPHER_ONLY 0x0001 /* (7) */ +#define X509v3_KU_DECIPHER_ONLY 0x8000 /* (8) */ +#ifndef OPENSSL_NO_DEPRECATED_3_4 +#define X509v3_KU_UNDEF 0xffff /* vestigial, not used */ +#endif struct X509_algor_st { ASN1_OBJECT *algorithm; ASN1_TYPE *parameter; -} /* X509_ALGOR */ ; +} /* X509_ALGOR */; typedef STACK_OF(X509_ALGOR) X509_ALGORS; @@ -200,6 +204,7 @@ typedef struct X509_sig_st X509_SIG; typedef struct X509_name_entry_st X509_NAME_ENTRY; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509_NAME_ENTRY, X509_NAME_ENTRY, X509_NAME_ENTRY) #define sk_X509_NAME_ENTRY_num(sk) OPENSSL_sk_num(ossl_check_const_X509_NAME_ENTRY_sk_type(sk)) #define sk_X509_NAME_ENTRY_value(sk, idx) ((X509_NAME_ENTRY *)OPENSSL_sk_value(ossl_check_const_X509_NAME_ENTRY_sk_type(sk), (idx))) @@ -227,10 +232,12 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_NAME_ENTRY, X509_NAME_ENTRY, X509_NAME_ENTRY) #define sk_X509_NAME_ENTRY_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_NAME_ENTRY) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_NAME_ENTRY_sk_type(sk), ossl_check_X509_NAME_ENTRY_copyfunc_type(copyfunc), ossl_check_X509_NAME_ENTRY_freefunc_type(freefunc))) #define sk_X509_NAME_ENTRY_set_cmp_func(sk, cmp) ((sk_X509_NAME_ENTRY_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_NAME_ENTRY_sk_type(sk), ossl_check_X509_NAME_ENTRY_compfunc_type(cmp))) +/* clang-format on */ -# define X509_EX_V_NETSCAPE_HACK 0x8000 -# define X509_EX_V_INIT 0x0001 +#define X509_EX_V_NETSCAPE_HACK 0x8000 +#define X509_EX_V_INIT 0x0001 typedef struct X509_extension_st X509_EXTENSION; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509_EXTENSION, X509_EXTENSION, X509_EXTENSION) #define sk_X509_EXTENSION_num(sk) OPENSSL_sk_num(ossl_check_const_X509_EXTENSION_sk_type(sk)) #define sk_X509_EXTENSION_value(sk, idx) ((X509_EXTENSION *)OPENSSL_sk_value(ossl_check_const_X509_EXTENSION_sk_type(sk), (idx))) @@ -258,8 +265,10 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_EXTENSION, X509_EXTENSION, X509_EXTENSION) #define sk_X509_EXTENSION_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_EXTENSION) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_EXTENSION_sk_type(sk), ossl_check_X509_EXTENSION_copyfunc_type(copyfunc), ossl_check_X509_EXTENSION_freefunc_type(freefunc))) #define sk_X509_EXTENSION_set_cmp_func(sk, cmp) ((sk_X509_EXTENSION_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_EXTENSION_sk_type(sk), ossl_check_X509_EXTENSION_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; typedef struct x509_attributes_st X509_ATTRIBUTE; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509_ATTRIBUTE, X509_ATTRIBUTE, X509_ATTRIBUTE) #define sk_X509_ATTRIBUTE_num(sk) OPENSSL_sk_num(ossl_check_const_X509_ATTRIBUTE_sk_type(sk)) #define sk_X509_ATTRIBUTE_value(sk, idx) ((X509_ATTRIBUTE *)OPENSSL_sk_value(ossl_check_const_X509_ATTRIBUTE_sk_type(sk), (idx))) @@ -287,6 +296,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_ATTRIBUTE, X509_ATTRIBUTE, X509_ATTRIBUTE) #define sk_X509_ATTRIBUTE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_ATTRIBUTE) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_ATTRIBUTE_sk_type(sk), ossl_check_X509_ATTRIBUTE_copyfunc_type(copyfunc), ossl_check_X509_ATTRIBUTE_freefunc_type(freefunc))) #define sk_X509_ATTRIBUTE_set_cmp_func(sk, cmp) ((sk_X509_ATTRIBUTE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_ATTRIBUTE_sk_type(sk), ossl_check_X509_ATTRIBUTE_compfunc_type(cmp))) +/* clang-format on */ typedef struct X509_req_info_st X509_REQ_INFO; typedef struct X509_req_st X509_REQ; typedef struct x509_cert_aux_st X509_CERT_AUX; @@ -294,81 +304,68 @@ typedef struct x509_cinf_st X509_CINF; /* Flags for X509_print_ex() */ -# define X509_FLAG_COMPAT 0 -# define X509_FLAG_NO_HEADER 1L -# define X509_FLAG_NO_VERSION (1L << 1) -# define X509_FLAG_NO_SERIAL (1L << 2) -# define X509_FLAG_NO_SIGNAME (1L << 3) -# define X509_FLAG_NO_ISSUER (1L << 4) -# define X509_FLAG_NO_VALIDITY (1L << 5) -# define X509_FLAG_NO_SUBJECT (1L << 6) -# define X509_FLAG_NO_PUBKEY (1L << 7) -# define X509_FLAG_NO_EXTENSIONS (1L << 8) -# define X509_FLAG_NO_SIGDUMP (1L << 9) -# define X509_FLAG_NO_AUX (1L << 10) -# define X509_FLAG_NO_ATTRIBUTES (1L << 11) -# define X509_FLAG_NO_IDS (1L << 12) -# define X509_FLAG_EXTENSIONS_ONLY_KID (1L << 13) +#define X509_FLAG_COMPAT 0 +#define X509_FLAG_NO_HEADER 1L +#define X509_FLAG_NO_VERSION (1L << 1) +#define X509_FLAG_NO_SERIAL (1L << 2) +#define X509_FLAG_NO_SIGNAME (1L << 3) +#define X509_FLAG_NO_ISSUER (1L << 4) +#define X509_FLAG_NO_VALIDITY (1L << 5) +#define X509_FLAG_NO_SUBJECT (1L << 6) +#define X509_FLAG_NO_PUBKEY (1L << 7) +#define X509_FLAG_NO_EXTENSIONS (1L << 8) +#define X509_FLAG_NO_SIGDUMP (1L << 9) +#define X509_FLAG_NO_AUX (1L << 10) +#define X509_FLAG_NO_ATTRIBUTES (1L << 11) +#define X509_FLAG_NO_IDS (1L << 12) +#define X509_FLAG_EXTENSIONS_ONLY_KID (1L << 13) /* Flags specific to X509_NAME_print_ex() */ /* The field separator information */ -# define XN_FLAG_SEP_MASK (0xf << 16) +#define XN_FLAG_SEP_MASK (0xf << 16) -# define XN_FLAG_COMPAT 0/* Traditional; use old X509_NAME_print */ -# define XN_FLAG_SEP_COMMA_PLUS (1 << 16)/* RFC2253 ,+ */ -# define XN_FLAG_SEP_CPLUS_SPC (2 << 16)/* ,+ spaced: more readable */ -# define XN_FLAG_SEP_SPLUS_SPC (3 << 16)/* ;+ spaced */ -# define XN_FLAG_SEP_MULTILINE (4 << 16)/* One line per field */ +#define XN_FLAG_COMPAT 0 /* Traditional; use old X509_NAME_print */ +#define XN_FLAG_SEP_COMMA_PLUS (1 << 16) /* RFC2253 ,+ */ +#define XN_FLAG_SEP_CPLUS_SPC (2 << 16) /* ,+ spaced: more readable */ +#define XN_FLAG_SEP_SPLUS_SPC (3 << 16) /* ;+ spaced */ +#define XN_FLAG_SEP_MULTILINE (4 << 16) /* One line per field */ -# define XN_FLAG_DN_REV (1 << 20)/* Reverse DN order */ +#define XN_FLAG_DN_REV (1 << 20) /* Reverse DN order */ /* How the field name is shown */ -# define XN_FLAG_FN_MASK (0x3 << 21) +#define XN_FLAG_FN_MASK (0x3 << 21) -# define XN_FLAG_FN_SN 0/* Object short name */ -# define XN_FLAG_FN_LN (1 << 21)/* Object long name */ -# define XN_FLAG_FN_OID (2 << 21)/* Always use OIDs */ -# define XN_FLAG_FN_NONE (3 << 21)/* No field names */ +#define XN_FLAG_FN_SN 0 /* Object short name */ +#define XN_FLAG_FN_LN (1 << 21) /* Object long name */ +#define XN_FLAG_FN_OID (2 << 21) /* Always use OIDs */ +#define XN_FLAG_FN_NONE (3 << 21) /* No field names */ -# define XN_FLAG_SPC_EQ (1 << 23)/* Put spaces round '=' */ +#define XN_FLAG_SPC_EQ (1 << 23) /* Put spaces round '=' */ /* * This determines if we dump fields we don't recognise: RFC2253 requires * this. */ -# define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24) +#define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24) -# define XN_FLAG_FN_ALIGN (1 << 25)/* Align field names to 20 - * characters */ +#define XN_FLAG_FN_ALIGN (1 << 25) /* Align field names to 20 \ + * characters */ /* Complete set of RFC2253 flags */ -# define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \ - XN_FLAG_SEP_COMMA_PLUS | \ - XN_FLAG_DN_REV | \ - XN_FLAG_FN_SN | \ - XN_FLAG_DUMP_UNKNOWN_FIELDS) +#define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | XN_FLAG_SEP_COMMA_PLUS | XN_FLAG_DN_REV | XN_FLAG_FN_SN | XN_FLAG_DUMP_UNKNOWN_FIELDS) /* readable oneline form */ -# define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \ - ASN1_STRFLGS_ESC_QUOTE | \ - XN_FLAG_SEP_CPLUS_SPC | \ - XN_FLAG_SPC_EQ | \ - XN_FLAG_FN_SN) +#define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | ASN1_STRFLGS_ESC_QUOTE | XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_SPC_EQ | XN_FLAG_FN_SN) /* readable multiline form */ -# define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \ - ASN1_STRFLGS_ESC_MSB | \ - XN_FLAG_SEP_MULTILINE | \ - XN_FLAG_SPC_EQ | \ - XN_FLAG_FN_LN | \ - XN_FLAG_FN_ALIGN) +#define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB | XN_FLAG_SEP_MULTILINE | XN_FLAG_SPC_EQ | XN_FLAG_FN_LN | XN_FLAG_FN_ALIGN) typedef struct X509_crl_info_st X509_CRL_INFO; @@ -382,7 +379,7 @@ typedef struct private_key_st { /* used to encrypt and decrypt */ int key_length; char *key_data; - int key_free; /* true if we should auto free key_data */ + int key_free; /* true if we should auto free key_data */ /* expanded version of 'enc_algor' */ EVP_CIPHER_INFO cipher; } X509_PKEY; @@ -395,6 +392,7 @@ typedef struct X509_info_st { int enc_len; char *enc_data; } X509_INFO; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509_INFO, X509_INFO, X509_INFO) #define sk_X509_INFO_num(sk) OPENSSL_sk_num(ossl_check_const_X509_INFO_sk_type(sk)) #define sk_X509_INFO_value(sk, idx) ((X509_INFO *)OPENSSL_sk_value(ossl_check_const_X509_INFO_sk_type(sk), (idx))) @@ -422,6 +420,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_INFO, X509_INFO, X509_INFO) #define sk_X509_INFO_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_INFO) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_INFO_sk_type(sk), ossl_check_X509_INFO_copyfunc_type(copyfunc), ossl_check_X509_INFO_freefunc_type(freefunc))) #define sk_X509_INFO_set_cmp_func(sk, cmp) ((sk_X509_INFO_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_INFO_sk_type(sk), ossl_check_X509_INFO_compfunc_type(cmp))) +/* clang-format on */ /* * The next 2 structures and their 8 routines are used to manipulate Netscape's @@ -429,11 +428,11 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_INFO, X509_INFO, X509_INFO) */ typedef struct Netscape_spkac_st { X509_PUBKEY *pubkey; - ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */ + ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */ } NETSCAPE_SPKAC; typedef struct Netscape_spki_st { - NETSCAPE_SPKAC *spkac; /* signed public key and challenge */ + NETSCAPE_SPKAC *spkac; /* signed public key and challenge */ X509_ALGOR sig_algor; ASN1_BIT_STRING *signature; } NETSCAPE_SPKI; @@ -466,7 +465,7 @@ typedef struct PBE2PARAM_st { } PBE2PARAM; typedef struct PBKDF2PARAM_st { -/* Usually OCTET STRING but could be anything */ + /* Usually OCTET STRING but could be anything */ ASN1_TYPE *salt; ASN1_INTEGER *iter; ASN1_INTEGER *keylength; @@ -478,7 +477,7 @@ typedef struct { X509_ALGOR *messageAuthScheme; } PBMAC1PARAM; -# ifndef OPENSSL_NO_SCRYPT +#ifndef OPENSSL_NO_SCRYPT typedef struct SCRYPT_PARAMS_st { ASN1_OCTET_STRING *salt; ASN1_INTEGER *costParameter; @@ -486,37 +485,35 @@ typedef struct SCRYPT_PARAMS_st { ASN1_INTEGER *parallelizationParameter; ASN1_INTEGER *keyLength; } SCRYPT_PARAMS; -# endif +#endif -#ifdef __cplusplus +#ifdef __cplusplus } #endif -# include -# include +#include +#include -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif -# define X509_EXT_PACK_UNKNOWN 1 -# define X509_EXT_PACK_STRING 2 +#define X509_EXT_PACK_UNKNOWN 1 +#define X509_EXT_PACK_STRING 2 -# define X509_extract_key(x) X509_get_pubkey(x)/*****/ -# define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) -# define X509_name_cmp(a,b) X509_NAME_cmp((a),(b)) +#define X509_extract_key(x) X509_get_pubkey(x) /*****/ +#define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) +#define X509_name_cmp(a, b) X509_NAME_cmp((a), (b)) void X509_CRL_set_default_method(const X509_CRL_METHOD *meth); -X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init) (X509_CRL *crl), - int (*crl_free) (X509_CRL *crl), - int (*crl_lookup) (X509_CRL *crl, - X509_REVOKED **ret, - const - ASN1_INTEGER *serial, - const - X509_NAME *issuer), - int (*crl_verify) (X509_CRL *crl, - EVP_PKEY *pk)); +X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init)(X509_CRL *crl), + int (*crl_free)(X509_CRL *crl), + int (*crl_lookup)(X509_CRL *crl, + X509_REVOKED **ret, + const ASN1_INTEGER *serial, + const X509_NAME *issuer), + int (*crl_verify)(X509_CRL *crl, + EVP_PKEY *pk)); void X509_CRL_METHOD_free(X509_CRL_METHOD *m); void X509_CRL_set_meth_data(X509_CRL *crl, void *dat); @@ -528,7 +525,7 @@ int X509_verify(X509 *a, EVP_PKEY *r); int X509_self_signed(X509 *cert, int verify_signature); int X509_REQ_verify_ex(X509_REQ *a, EVP_PKEY *r, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r); int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); @@ -542,7 +539,7 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki); int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent); int X509_signature_print(BIO *bp, const X509_ALGOR *alg, - const ASN1_STRING *sig); + const ASN1_STRING *sig); int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx); @@ -553,76 +550,76 @@ int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx); int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md); int X509_pubkey_digest(const X509 *data, const EVP_MD *type, - unsigned char *md, unsigned int *len); + unsigned char *md, unsigned int *len); int X509_digest(const X509 *data, const EVP_MD *type, - unsigned char *md, unsigned int *len); + unsigned char *md, unsigned int *len); ASN1_OCTET_STRING *X509_digest_sig(const X509 *cert, - EVP_MD **md_used, int *md_is_fallback); + EVP_MD **md_used, int *md_is_fallback); int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, - unsigned char *md, unsigned int *len); + unsigned char *md, unsigned int *len); int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, - unsigned char *md, unsigned int *len); + unsigned char *md, unsigned int *len); int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, - unsigned char *md, unsigned int *len); + unsigned char *md, unsigned int *len); X509 *X509_load_http(const char *url, BIO *bio, BIO *rbio, int timeout); X509_CRL *X509_CRL_load_http(const char *url, BIO *bio, BIO *rbio, int timeout); -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# include /* OSSL_HTTP_REQ_CTX_nbio_d2i */ -# define X509_http_nbio(rctx, pcert) \ - OSSL_HTTP_REQ_CTX_nbio_d2i(rctx, pcert, ASN1_ITEM_rptr(X509)) -# define X509_CRL_http_nbio(rctx, pcrl) \ - OSSL_HTTP_REQ_CTX_nbio_d2i(rctx, pcrl, ASN1_ITEM_rptr(X509_CRL)) -# endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#include /* OSSL_HTTP_REQ_CTX_nbio_d2i */ +#define X509_http_nbio(rctx, pcert) \ + OSSL_HTTP_REQ_CTX_nbio_d2i(rctx, pcert, ASN1_ITEM_rptr(X509)) +#define X509_CRL_http_nbio(rctx, pcrl) \ + OSSL_HTTP_REQ_CTX_nbio_d2i(rctx, pcrl, ASN1_ITEM_rptr(X509_CRL)) +#endif -# ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_STDIO X509 *d2i_X509_fp(FILE *fp, X509 **x509); int i2d_X509_fp(FILE *fp, const X509 *x509); X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl); int i2d_X509_CRL_fp(FILE *fp, const X509_CRL *crl); X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req); int i2d_X509_REQ_fp(FILE *fp, const X509_REQ *req); -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa); OSSL_DEPRECATEDIN_3_0 int i2d_RSAPrivateKey_fp(FILE *fp, const RSA *rsa); OSSL_DEPRECATEDIN_3_0 RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa); OSSL_DEPRECATEDIN_3_0 int i2d_RSAPublicKey_fp(FILE *fp, const RSA *rsa); OSSL_DEPRECATEDIN_3_0 RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa); OSSL_DEPRECATEDIN_3_0 int i2d_RSA_PUBKEY_fp(FILE *fp, const RSA *rsa); -# endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# ifndef OPENSSL_NO_DSA +#endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DSA OSSL_DEPRECATEDIN_3_0 DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa); OSSL_DEPRECATEDIN_3_0 int i2d_DSA_PUBKEY_fp(FILE *fp, const DSA *dsa); OSSL_DEPRECATEDIN_3_0 DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); OSSL_DEPRECATEDIN_3_0 int i2d_DSAPrivateKey_fp(FILE *fp, const DSA *dsa); -# endif -# endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# ifndef OPENSSL_NO_EC +#endif +#endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_EC OSSL_DEPRECATEDIN_3_0 EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey); OSSL_DEPRECATEDIN_3_0 int i2d_EC_PUBKEY_fp(FILE *fp, const EC_KEY *eckey); OSSL_DEPRECATEDIN_3_0 EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey); OSSL_DEPRECATEDIN_3_0 int i2d_ECPrivateKey_fp(FILE *fp, const EC_KEY *eckey); -# endif /* OPENSSL_NO_EC */ -# endif /* OPENSSL_NO_DEPRECATED_3_0 */ +#endif /* OPENSSL_NO_EC */ +#endif /* OPENSSL_NO_DEPRECATED_3_0 */ X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8); int i2d_PKCS8_fp(FILE *fp, const X509_SIG *p8); X509_PUBKEY *d2i_X509_PUBKEY_fp(FILE *fp, X509_PUBKEY **xpk); int i2d_X509_PUBKEY_fp(FILE *fp, const X509_PUBKEY *xpk); PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, - PKCS8_PRIV_KEY_INFO **p8inf); + PKCS8_PRIV_KEY_INFO **p8inf); int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, const PKCS8_PRIV_KEY_INFO *p8inf); int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, const EVP_PKEY *key); int i2d_PrivateKey_fp(FILE *fp, const EVP_PKEY *pkey); EVP_PKEY *d2i_PrivateKey_ex_fp(FILE *fp, EVP_PKEY **a, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a); int i2d_PUBKEY_fp(FILE *fp, const EVP_PKEY *pkey); EVP_PKEY *d2i_PUBKEY_ex_fp(FILE *fp, EVP_PKEY **a, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); -# endif +#endif X509 *d2i_X509_bio(BIO *bp, X509 **x509); int i2d_X509_bio(BIO *bp, const X509 *x509); @@ -630,47 +627,47 @@ X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl); int i2d_X509_CRL_bio(BIO *bp, const X509_CRL *crl); X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req); int i2d_X509_REQ_bio(BIO *bp, const X509_REQ *req); -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa); OSSL_DEPRECATEDIN_3_0 int i2d_RSAPrivateKey_bio(BIO *bp, const RSA *rsa); OSSL_DEPRECATEDIN_3_0 RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa); OSSL_DEPRECATEDIN_3_0 int i2d_RSAPublicKey_bio(BIO *bp, const RSA *rsa); OSSL_DEPRECATEDIN_3_0 RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa); OSSL_DEPRECATEDIN_3_0 int i2d_RSA_PUBKEY_bio(BIO *bp, const RSA *rsa); -# endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# ifndef OPENSSL_NO_DSA +#endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DSA OSSL_DEPRECATEDIN_3_0 DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa); OSSL_DEPRECATEDIN_3_0 int i2d_DSA_PUBKEY_bio(BIO *bp, const DSA *dsa); OSSL_DEPRECATEDIN_3_0 DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); OSSL_DEPRECATEDIN_3_0 int i2d_DSAPrivateKey_bio(BIO *bp, const DSA *dsa); -# endif -# endif +#endif +#endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# ifndef OPENSSL_NO_EC +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_EC OSSL_DEPRECATEDIN_3_0 EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey); OSSL_DEPRECATEDIN_3_0 int i2d_EC_PUBKEY_bio(BIO *bp, const EC_KEY *eckey); OSSL_DEPRECATEDIN_3_0 EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey); OSSL_DEPRECATEDIN_3_0 int i2d_ECPrivateKey_bio(BIO *bp, const EC_KEY *eckey); -# endif /* OPENSSL_NO_EC */ -# endif /* OPENSSL_NO_DEPRECATED_3_0 */ +#endif /* OPENSSL_NO_EC */ +#endif /* OPENSSL_NO_DEPRECATED_3_0 */ X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8); int i2d_PKCS8_bio(BIO *bp, const X509_SIG *p8); X509_PUBKEY *d2i_X509_PUBKEY_bio(BIO *bp, X509_PUBKEY **xpk); int i2d_X509_PUBKEY_bio(BIO *bp, const X509_PUBKEY *xpk); PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, - PKCS8_PRIV_KEY_INFO **p8inf); + PKCS8_PRIV_KEY_INFO **p8inf); int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, const PKCS8_PRIV_KEY_INFO *p8inf); int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, const EVP_PKEY *key); int i2d_PrivateKey_bio(BIO *bp, const EVP_PKEY *pkey); EVP_PKEY *d2i_PrivateKey_ex_bio(BIO *bp, EVP_PKEY **a, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a); int i2d_PUBKEY_bio(BIO *bp, const EVP_PKEY *pkey); EVP_PKEY *d2i_PUBKEY_ex_bio(BIO *bp, EVP_PKEY **a, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); DECLARE_ASN1_DUP_FUNCTION(X509) @@ -682,9 +679,9 @@ DECLARE_ASN1_DUP_FUNCTION(X509_PUBKEY) DECLARE_ASN1_DUP_FUNCTION(X509_REQ) DECLARE_ASN1_DUP_FUNCTION(X509_REVOKED) int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, - void *pval); + void *pval); void X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype, - const void **ppval, const X509_ALGOR *algor); + const void **ppval, const X509_ALGOR *algor); void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md); int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b); int X509_ALGOR_copy(X509_ALGOR *dest, const X509_ALGOR *src); @@ -695,10 +692,10 @@ DECLARE_ASN1_DUP_FUNCTION(X509_NAME_ENTRY) int X509_cmp_time(const ASN1_TIME *s, time_t *t); int X509_cmp_current_time(const ASN1_TIME *s); int X509_cmp_timeframe(const X509_VERIFY_PARAM *vpm, - const ASN1_TIME *start, const ASN1_TIME *end); + const ASN1_TIME *start, const ASN1_TIME *end); ASN1_TIME *X509_time_adj(ASN1_TIME *s, long adj, time_t *t); ASN1_TIME *X509_time_adj_ex(ASN1_TIME *s, - int offset_day, long offset_sec, time_t *t); + int offset_day, long offset_sec, time_t *t); ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long adj); const char *X509_get_default_cert_area(void); @@ -725,26 +722,26 @@ int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain); long X509_get_pathlen(X509 *x); DECLARE_ASN1_ENCODE_FUNCTIONS_only(EVP_PKEY, PUBKEY) EVP_PKEY *d2i_PUBKEY_ex(EVP_PKEY **a, const unsigned char **pp, long length, - OSSL_LIB_CTX *libctx, const char *propq); -# ifndef OPENSSL_NO_DEPRECATED_3_0 -DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(OSSL_DEPRECATEDIN_3_0,RSA, RSA_PUBKEY) -# endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# ifndef OPENSSL_NO_DSA -DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(OSSL_DEPRECATEDIN_3_0,DSA, DSA_PUBKEY) -# endif -# endif -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# ifndef OPENSSL_NO_EC + OSSL_LIB_CTX *libctx, const char *propq); +#ifndef OPENSSL_NO_DEPRECATED_3_0 +DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSA_PUBKEY) +#endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DSA +DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(OSSL_DEPRECATEDIN_3_0, DSA, DSA_PUBKEY) +#endif +#endif +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_EC DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(OSSL_DEPRECATEDIN_3_0, EC_KEY, EC_PUBKEY) -# endif -# endif +#endif +#endif DECLARE_ASN1_FUNCTIONS(X509_SIG) void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **palg, - const ASN1_OCTET_STRING **pdigest); + const ASN1_OCTET_STRING **pdigest); void X509_SIG_getm(X509_SIG *sig, X509_ALGOR **palg, - ASN1_OCTET_STRING **pdigest); + ASN1_OCTET_STRING **pdigest); DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO) DECLARE_ASN1_FUNCTIONS(X509_REQ) @@ -771,20 +768,20 @@ DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX) CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, l, p, newf, dupf, freef) int X509_set_ex_data(X509 *r, int idx, void *arg); void *X509_get_ex_data(const X509 *r, int idx); -DECLARE_ASN1_ENCODE_FUNCTIONS_only(X509,X509_AUX) +DECLARE_ASN1_ENCODE_FUNCTIONS_only(X509, X509_AUX) int i2d_re_X509_tbs(X509 *x, unsigned char **pp); int X509_SIG_INFO_get(const X509_SIG_INFO *siginf, int *mdnid, int *pknid, - int *secbits, uint32_t *flags); + int *secbits, uint32_t *flags); void X509_SIG_INFO_set(X509_SIG_INFO *siginf, int mdnid, int pknid, - int secbits, uint32_t flags); + int secbits, uint32_t flags); int X509_get_signature_info(X509 *x, int *mdnid, int *pknid, int *secbits, - uint32_t *flags); + uint32_t *flags); void X509_get0_signature(const ASN1_BIT_STRING **psig, - const X509_ALGOR **palg, const X509 *x); + const X509_ALGOR **palg, const X509 *x); int X509_get_signature_nid(const X509 *x); void X509_set0_distinguishing_id(X509 *x, ASN1_OCTET_STRING *d_id); @@ -804,7 +801,7 @@ X509_CRL *X509_CRL_new_ex(OSSL_LIB_CTX *libctx, const char *propq); int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev); int X509_CRL_get0_by_serial(X509_CRL *crl, - X509_REVOKED **ret, const ASN1_INTEGER *serial); + X509_REVOKED **ret, const ASN1_INTEGER *serial); int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x); X509_PKEY *X509_PKEY_new(void); @@ -821,29 +818,29 @@ char *X509_NAME_oneline(const X509_NAME *a, char *buf, int size); #ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *algor1, - ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey); + ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey); OSSL_DEPRECATEDIN_3_0 int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data, - unsigned char *md, unsigned int *len); + unsigned char *md, unsigned int *len); OSSL_DEPRECATEDIN_3_0 int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2, - ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey, - const EVP_MD *type); + ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey, + const EVP_MD *type); #endif int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *data, - unsigned char *md, unsigned int *len); + unsigned char *md, unsigned int *len); int ASN1_item_verify(const ASN1_ITEM *it, const X509_ALGOR *alg, - const ASN1_BIT_STRING *signature, const void *data, - EVP_PKEY *pkey); + const ASN1_BIT_STRING *signature, const void *data, + EVP_PKEY *pkey); int ASN1_item_verify_ctx(const ASN1_ITEM *it, const X509_ALGOR *alg, - const ASN1_BIT_STRING *signature, const void *data, - EVP_MD_CTX *ctx); + const ASN1_BIT_STRING *signature, const void *data, + EVP_MD_CTX *ctx); int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, - ASN1_BIT_STRING *signature, const void *data, - EVP_PKEY *pkey, const EVP_MD *md); + ASN1_BIT_STRING *signature, const void *data, + EVP_PKEY *pkey, const EVP_MD *md); int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, - X509_ALGOR *algor2, ASN1_BIT_STRING *signature, - const void *data, EVP_MD_CTX *ctx); + X509_ALGOR *algor2, ASN1_BIT_STRING *signature, + const void *data, EVP_MD_CTX *ctx); #define X509_VERSION_1 0 #define X509_VERSION_2 1 @@ -858,7 +855,7 @@ int X509_set_issuer_name(X509 *x, const X509_NAME *name); X509_NAME *X509_get_issuer_name(const X509 *a); int X509_set_subject_name(X509 *x, const X509_NAME *name); X509_NAME *X509_get_subject_name(const X509 *a); -const ASN1_TIME * X509_get0_notBefore(const X509 *x); +const ASN1_TIME *X509_get0_notBefore(const X509 *x); ASN1_TIME *X509_getm_notBefore(const X509 *x); int X509_set1_notBefore(X509 *x, const ASN1_TIME *tm); const ASN1_TIME *X509_get0_notAfter(const X509 *x); @@ -868,14 +865,13 @@ int X509_set_pubkey(X509 *x, EVP_PKEY *pkey); int X509_up_ref(X509 *x); int X509_get_signature_type(const X509 *x); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define X509_get_notBefore X509_getm_notBefore -# define X509_get_notAfter X509_getm_notAfter -# define X509_set_notBefore X509_set1_notBefore -# define X509_set_notAfter X509_set1_notAfter +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define X509_get_notBefore X509_getm_notBefore +#define X509_get_notAfter X509_getm_notAfter +#define X509_set_notBefore X509_set1_notBefore +#define X509_set_notAfter X509_set1_notAfter #endif - /* * This one is only used so that a binary form can output, as in * i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), &buf) @@ -883,7 +879,7 @@ int X509_get_signature_type(const X509 *x); X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x); const STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x); void X509_get0_uids(const X509 *x, const ASN1_BIT_STRING **piuid, - const ASN1_BIT_STRING **psuid); + const ASN1_BIT_STRING **psuid); const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x); EVP_PKEY *X509_get0_pubkey(const X509 *x); @@ -897,7 +893,7 @@ int X509_REQ_set_version(X509_REQ *x, long version); X509_NAME *X509_REQ_get_subject_name(const X509_REQ *req); int X509_REQ_set_subject_name(X509_REQ *req, const X509_NAME *name); void X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig, - const X509_ALGOR **palg); + const X509_ALGOR **palg); void X509_REQ_set0_signature(X509_REQ *req, ASN1_BIT_STRING *psig); int X509_REQ_set1_signature_algo(X509_REQ *req, X509_ALGOR *palg); int X509_REQ_get_signature_nid(const X509_REQ *req); @@ -911,24 +907,24 @@ int *X509_REQ_get_extension_nids(void); void X509_REQ_set_extension_nids(int *nids); STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(OSSL_FUTURE_CONST X509_REQ *req); int X509_REQ_add_extensions_nid(X509_REQ *req, - const STACK_OF(X509_EXTENSION) *exts, int nid); + const STACK_OF(X509_EXTENSION) *exts, int nid); int X509_REQ_add_extensions(X509_REQ *req, const STACK_OF(X509_EXTENSION) *ext); int X509_REQ_get_attr_count(const X509_REQ *req); int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid, int lastpos); int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, const ASN1_OBJECT *obj, - int lastpos); + int lastpos); X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc); X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc); int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr); int X509_REQ_add1_attr_by_OBJ(X509_REQ *req, - const ASN1_OBJECT *obj, int type, - const unsigned char *bytes, int len); + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len); int X509_REQ_add1_attr_by_NID(X509_REQ *req, - int nid, int type, - const unsigned char *bytes, int len); + int nid, int type, + const unsigned char *bytes, int len); int X509_REQ_add1_attr_by_txt(X509_REQ *req, - const char *attrname, int type, - const unsigned char *bytes, int len); + const char *attrname, int type, + const unsigned char *bytes, int len); #define X509_CRL_VERSION_1 0 #define X509_CRL_VERSION_2 1 @@ -940,9 +936,9 @@ int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm); int X509_CRL_sort(X509_CRL *crl); int X509_CRL_up_ref(X509_CRL *crl); -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define X509_CRL_set_lastUpdate X509_CRL_set1_lastUpdate -# define X509_CRL_set_nextUpdate X509_CRL_set1_nextUpdate +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define X509_CRL_set_lastUpdate X509_CRL_set1_lastUpdate +#define X509_CRL_set_nextUpdate X509_CRL_set1_nextUpdate #endif long X509_CRL_get_version(const X509_CRL *crl); @@ -956,7 +952,7 @@ X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl); const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl); STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl); void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig, - const X509_ALGOR **palg); + const X509_ALGOR **palg); int X509_CRL_get_signature_nid(const X509_CRL *crl); int i2d_re_X509_CRL_tbs(X509_CRL *req, unsigned char **pp); @@ -968,14 +964,14 @@ const STACK_OF(X509_EXTENSION) * X509_REVOKED_get0_extensions(const X509_REVOKED *r); X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer, - EVP_PKEY *skey, const EVP_MD *md, unsigned int flags); + EVP_PKEY *skey, const EVP_MD *md, unsigned int flags); int X509_REQ_check_private_key(const X509_REQ *req, EVP_PKEY *pkey); int X509_check_private_key(const X509 *cert, const EVP_PKEY *pkey); int X509_chain_check_suiteb(int *perror_depth, - X509 *x, STACK_OF(X509) *chain, - unsigned long flags); + X509 *x, STACK_OF(X509) *chain, + unsigned long flags); int X509_CRL_check_suiteb(X509_CRL *crl, EVP_PKEY *pk, unsigned long flags); void OSSL_STACK_OF_X509_free(STACK_OF(X509) *certs); STACK_OF(X509) *X509_chain_up_ref(STACK_OF(X509) *chain); @@ -989,61 +985,61 @@ unsigned long X509_issuer_name_hash(X509 *a); int X509_subject_name_cmp(const X509 *a, const X509 *b); unsigned long X509_subject_name_hash(X509 *x); -# ifndef OPENSSL_NO_MD5 +#ifndef OPENSSL_NO_MD5 unsigned long X509_issuer_name_hash_old(X509 *a); unsigned long X509_subject_name_hash_old(X509 *x); -# endif +#endif -# define X509_ADD_FLAG_DEFAULT 0 -# define X509_ADD_FLAG_UP_REF 0x1 -# define X509_ADD_FLAG_PREPEND 0x2 -# define X509_ADD_FLAG_NO_DUP 0x4 -# define X509_ADD_FLAG_NO_SS 0x8 +#define X509_ADD_FLAG_DEFAULT 0 +#define X509_ADD_FLAG_UP_REF 0x1 +#define X509_ADD_FLAG_PREPEND 0x2 +#define X509_ADD_FLAG_NO_DUP 0x4 +#define X509_ADD_FLAG_NO_SS 0x8 int X509_add_cert(STACK_OF(X509) *sk, X509 *cert, int flags); int X509_add_certs(STACK_OF(X509) *sk, STACK_OF(X509) *certs, int flags); int X509_cmp(const X509 *a, const X509 *b); int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b); #ifndef OPENSSL_NO_DEPRECATED_3_0 -# define X509_NAME_hash(x) X509_NAME_hash_ex(x, NULL, NULL, NULL) +#define X509_NAME_hash(x) X509_NAME_hash_ex(x, NULL, NULL, NULL) OSSL_DEPRECATEDIN_3_0 int X509_certificate_type(const X509 *x, - const EVP_PKEY *pubkey); + const EVP_PKEY *pubkey); #endif unsigned long X509_NAME_hash_ex(const X509_NAME *x, OSSL_LIB_CTX *libctx, - const char *propq, int *ok); + const char *propq, int *ok); unsigned long X509_NAME_hash_old(const X509_NAME *x); int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b); int X509_CRL_match(const X509_CRL *a, const X509_CRL *b); int X509_aux_print(BIO *out, X509 *x, int indent); -# ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_STDIO int X509_print_ex_fp(FILE *bp, X509 *x, unsigned long nmflag, - unsigned long cflag); + unsigned long cflag); int X509_print_fp(FILE *bp, X509 *x); int X509_CRL_print_fp(FILE *bp, X509_CRL *x); int X509_REQ_print_fp(FILE *bp, X509_REQ *req); int X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, int indent, - unsigned long flags); -# endif + unsigned long flags); +#endif int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase); int X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent, - unsigned long flags); + unsigned long flags); int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflag, - unsigned long cflag); + unsigned long cflag); int X509_print(BIO *bp, X509 *x); int X509_ocspid_print(BIO *bp, X509 *x); int X509_CRL_print_ex(BIO *out, X509_CRL *x, unsigned long nmflag); int X509_CRL_print(BIO *bp, X509_CRL *x); int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, - unsigned long cflag); + unsigned long cflag); int X509_REQ_print(BIO *bp, X509_REQ *req); int X509_NAME_entry_count(const X509_NAME *name); int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid, - char *buf, int len); + char *buf, int len); int X509_NAME_get_text_by_OBJ(const X509_NAME *name, const ASN1_OBJECT *obj, - char *buf, int len); + char *buf, int len); /* * NOTE: you should be passing -1, not 0 as lastpos. The functions that use @@ -1051,55 +1047,55 @@ int X509_NAME_get_text_by_OBJ(const X509_NAME *name, const ASN1_OBJECT *obj, */ int X509_NAME_get_index_by_NID(const X509_NAME *name, int nid, int lastpos); int X509_NAME_get_index_by_OBJ(const X509_NAME *name, const ASN1_OBJECT *obj, - int lastpos); + int lastpos); X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc); X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); int X509_NAME_add_entry(X509_NAME *name, const X509_NAME_ENTRY *ne, - int loc, int set); + int loc, int set); int X509_NAME_add_entry_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, int type, - const unsigned char *bytes, int len, int loc, - int set); + const unsigned char *bytes, int len, int loc, + int set); int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, - const unsigned char *bytes, int len, int loc, - int set); + const unsigned char *bytes, int len, int loc, + int set); X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, - const char *field, int type, - const unsigned char *bytes, - int len); + const char *field, int type, + const unsigned char *bytes, + int len); X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, - int type, - const unsigned char *bytes, - int len); + int type, + const unsigned char *bytes, + int len); int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, - const unsigned char *bytes, int len, int loc, - int set); + const unsigned char *bytes, int len, int loc, + int set); X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, - const ASN1_OBJECT *obj, int type, - const unsigned char *bytes, - int len); + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, + int len); int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, const ASN1_OBJECT *obj); int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, - const unsigned char *bytes, int len); + const unsigned char *bytes, int len); ASN1_OBJECT *X509_NAME_ENTRY_get_object(const X509_NAME_ENTRY *ne); -ASN1_STRING * X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne); +ASN1_STRING *X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne); int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne); int X509_NAME_get0_der(const X509_NAME *nm, const unsigned char **pder, - size_t *pderlen); + size_t *pderlen); int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x); int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, - int nid, int lastpos); + int nid, int lastpos); int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x, - const ASN1_OBJECT *obj, int lastpos); + const ASN1_OBJECT *obj, int lastpos); int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x, - int crit, int lastpos); + int crit, int lastpos); X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc); X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc); STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, - X509_EXTENSION *ex, int loc); + X509_EXTENSION *ex, int loc); STACK_OF(X509_EXTENSION) *X509v3_add_extensions(STACK_OF(X509_EXTENSION) **target, - const STACK_OF(X509_EXTENSION) *exts); + const STACK_OF(X509_EXTENSION) *exts); int X509_get_ext_count(const X509 *x); int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos); @@ -1110,40 +1106,40 @@ X509_EXTENSION *X509_delete_ext(X509 *x, int loc); int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc); void *X509_get_ext_d2i(const X509 *x, int nid, int *crit, int *idx); int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit, - unsigned long flags); + unsigned long flags); int X509_CRL_get_ext_count(const X509_CRL *x); int X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid, int lastpos); int X509_CRL_get_ext_by_OBJ(const X509_CRL *x, const ASN1_OBJECT *obj, - int lastpos); + int lastpos); int X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit, int lastpos); X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc); X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc); void *X509_CRL_get_ext_d2i(const X509_CRL *x, int nid, int *crit, int *idx); int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit, - unsigned long flags); + unsigned long flags); int X509_REVOKED_get_ext_count(const X509_REVOKED *x); int X509_REVOKED_get_ext_by_NID(const X509_REVOKED *x, int nid, int lastpos); int X509_REVOKED_get_ext_by_OBJ(const X509_REVOKED *x, const ASN1_OBJECT *obj, - int lastpos); + int lastpos); int X509_REVOKED_get_ext_by_critical(const X509_REVOKED *x, int crit, - int lastpos); + int lastpos); X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, int loc); X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc); int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc); void *X509_REVOKED_get_ext_d2i(const X509_REVOKED *x, int nid, int *crit, - int *idx); + int *idx); int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit, - unsigned long flags); + unsigned long flags); X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, - int nid, int crit, - ASN1_OCTET_STRING *data); + int nid, int crit, + ASN1_OCTET_STRING *data); X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, - const ASN1_OBJECT *obj, int crit, - ASN1_OCTET_STRING *data); + const ASN1_OBJECT *obj, int crit, + ASN1_OCTET_STRING *data); int X509_EXTENSION_set_object(X509_EXTENSION *ex, const ASN1_OBJECT *obj); int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data); @@ -1153,45 +1149,48 @@ int X509_EXTENSION_get_critical(const X509_EXTENSION *ex); int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x); int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, - int lastpos); + int lastpos); int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, - const ASN1_OBJECT *obj, int lastpos); + const ASN1_OBJECT *obj, int lastpos); X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc); X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc); STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, - X509_ATTRIBUTE *attr); + X509_ATTRIBUTE *attr); STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) - **x, const ASN1_OBJECT *obj, - int type, - const unsigned char *bytes, - int len); + **x, + const ASN1_OBJECT *obj, + int type, + const unsigned char *bytes, + int len); STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) - **x, int nid, int type, - const unsigned char *bytes, - int len); + **x, + int nid, int type, + const unsigned char *bytes, + int len); STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) - **x, const char *attrname, - int type, - const unsigned char *bytes, - int len); + **x, + const char *attrname, + int type, + const unsigned char *bytes, + int len); void *X509at_get0_data_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *x, - const ASN1_OBJECT *obj, int lastpos, int type); + const ASN1_OBJECT *obj, int lastpos, int type); X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, - int atrtype, const void *data, - int len); + int atrtype, const void *data, + int len); X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, - const ASN1_OBJECT *obj, - int atrtype, const void *data, - int len); + const ASN1_OBJECT *obj, + int atrtype, const void *data, + int len); X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr, - const char *atrname, int type, - const unsigned char *bytes, - int len); + const char *atrname, int type, + const unsigned char *bytes, + int len); int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj); int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, - const void *data, int len); + const void *data, int len); void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, int atrtype, - void *data); + void *data); int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr); ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr); ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx); @@ -1199,67 +1198,67 @@ ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx); int EVP_PKEY_get_attr_count(const EVP_PKEY *key); int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid, int lastpos); int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, const ASN1_OBJECT *obj, - int lastpos); + int lastpos); X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc); X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc); int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr); int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key, - const ASN1_OBJECT *obj, int type, - const unsigned char *bytes, int len); + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len); int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key, - int nid, int type, - const unsigned char *bytes, int len); + int nid, int type, + const unsigned char *bytes, int len); int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key, - const char *attrname, int type, - const unsigned char *bytes, int len); + const char *attrname, int type, + const unsigned char *bytes, int len); /* lookup a cert from a X509 STACK */ X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, const X509_NAME *name, - const ASN1_INTEGER *serial); + const ASN1_INTEGER *serial); X509 *X509_find_by_subject(STACK_OF(X509) *sk, const X509_NAME *name); DECLARE_ASN1_FUNCTIONS(PBEPARAM) DECLARE_ASN1_FUNCTIONS(PBE2PARAM) DECLARE_ASN1_FUNCTIONS(PBKDF2PARAM) DECLARE_ASN1_FUNCTIONS(PBMAC1PARAM) -# ifndef OPENSSL_NO_SCRYPT +#ifndef OPENSSL_NO_SCRYPT DECLARE_ASN1_FUNCTIONS(SCRYPT_PARAMS) -# endif +#endif int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, - const unsigned char *salt, int saltlen); + const unsigned char *salt, int saltlen); int PKCS5_pbe_set0_algor_ex(X509_ALGOR *algor, int alg, int iter, - const unsigned char *salt, int saltlen, - OSSL_LIB_CTX *libctx); + const unsigned char *salt, int saltlen, + OSSL_LIB_CTX *libctx); X509_ALGOR *PKCS5_pbe_set(int alg, int iter, - const unsigned char *salt, int saltlen); + const unsigned char *salt, int saltlen); X509_ALGOR *PKCS5_pbe_set_ex(int alg, int iter, - const unsigned char *salt, int saltlen, - OSSL_LIB_CTX *libctx); + const unsigned char *salt, int saltlen, + OSSL_LIB_CTX *libctx); X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, - unsigned char *salt, int saltlen); + unsigned char *salt, int saltlen); X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, - unsigned char *salt, int saltlen, - unsigned char *aiv, int prf_nid); + unsigned char *salt, int saltlen, + unsigned char *aiv, int prf_nid); X509_ALGOR *PKCS5_pbe2_set_iv_ex(const EVP_CIPHER *cipher, int iter, - unsigned char *salt, int saltlen, - unsigned char *aiv, int prf_nid, - OSSL_LIB_CTX *libctx); + unsigned char *salt, int saltlen, + unsigned char *aiv, int prf_nid, + OSSL_LIB_CTX *libctx); #ifndef OPENSSL_NO_SCRYPT X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher, - const unsigned char *salt, int saltlen, - unsigned char *aiv, uint64_t N, uint64_t r, - uint64_t p); + const unsigned char *salt, int saltlen, + unsigned char *aiv, uint64_t N, uint64_t r, + uint64_t p); #endif X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, - int prf_nid, int keylen); + int prf_nid, int keylen); X509_ALGOR *PKCS5_pbkdf2_set_ex(int iter, unsigned char *salt, int saltlen, - int prf_nid, int keylen, - OSSL_LIB_CTX *libctx); + int prf_nid, int keylen, + OSSL_LIB_CTX *libctx); PBKDF2PARAM *PBMAC1_get1_pbkdf2_param(const X509_ALGOR *macalg); /* PKCS#8 utilities */ @@ -1268,36 +1267,35 @@ DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO) EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8); EVP_PKEY *EVP_PKCS82PKEY_ex(const PKCS8_PRIV_KEY_INFO *p8, OSSL_LIB_CTX *libctx, - const char *propq); + const char *propq); PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(const EVP_PKEY *pkey); int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, - int version, int ptype, void *pval, - unsigned char *penc, int penclen); + int version, int ptype, void *pval, + unsigned char *penc, int penclen); int PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, - const unsigned char **pk, int *ppklen, - const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8); + const unsigned char **pk, int *ppklen, + const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8); const STACK_OF(X509_ATTRIBUTE) * PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *p8); int PKCS8_pkey_add1_attr(PKCS8_PRIV_KEY_INFO *p8, X509_ATTRIBUTE *attr); int PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *p8, int nid, int type, - const unsigned char *bytes, int len); + const unsigned char *bytes, int len); int PKCS8_pkey_add1_attr_by_OBJ(PKCS8_PRIV_KEY_INFO *p8, const ASN1_OBJECT *obj, - int type, const unsigned char *bytes, int len); - + int type, const unsigned char *bytes, int len); void X509_PUBKEY_set0_public_key(X509_PUBKEY *pub, - unsigned char *penc, int penclen); + unsigned char *penc, int penclen); int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, - int ptype, void *pval, - unsigned char *penc, int penclen); + int ptype, void *pval, + unsigned char *penc, int penclen); int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, - const unsigned char **pk, int *ppklen, - X509_ALGOR **pa, const X509_PUBKEY *pub); + const unsigned char **pk, int *ppklen, + X509_ALGOR **pa, const X509_PUBKEY *pub); int X509_PUBKEY_eq(const X509_PUBKEY *a, const X509_PUBKEY *b); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509_acert.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509_acert.h index 4eaac6f955..40eec46c90 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509_acert.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509_acert.h @@ -2,7 +2,7 @@ * WARNING: do not edit! * Generated by Makefile from include/openssl/x509_acert.h.in * - * Copyright 2022-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2022-2026 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,15 +10,21 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_X509_ACERT_H -# define OPENSSL_X509_ACERT_H -# pragma once +#define OPENSSL_X509_ACERT_H +#pragma once -# include -# include -# include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif typedef struct X509_acert_st X509_ACERT; typedef struct X509_acert_info_st X509_ACERT_INFO; @@ -34,10 +40,10 @@ DECLARE_ASN1_ALLOC_FUNCTIONS(OSSL_OBJECT_DIGEST_INFO) DECLARE_ASN1_ALLOC_FUNCTIONS(OSSL_ISSUER_SERIAL) DECLARE_ASN1_ALLOC_FUNCTIONS(X509_ACERT_ISSUER_V2FORM) -# ifndef OPENSSL_NO_STDIO +#ifndef OPENSSL_NO_STDIO X509_ACERT *d2i_X509_ACERT_fp(FILE *fp, X509_ACERT **acert); int i2d_X509_ACERT_fp(FILE *fp, const X509_ACERT *acert); -# endif +#endif DECLARE_PEM_rw(X509_ACERT, X509_ACERT) @@ -48,16 +54,16 @@ int X509_ACERT_sign(X509_ACERT *x, EVP_PKEY *pkey, const EVP_MD *md); int X509_ACERT_sign_ctx(X509_ACERT *x, EVP_MD_CTX *ctx); int X509_ACERT_verify(X509_ACERT *a, EVP_PKEY *r); -# define X509_ACERT_VERSION_2 1 +#define X509_ACERT_VERSION_2 1 const GENERAL_NAMES *X509_ACERT_get0_holder_entityName(const X509_ACERT *x); const OSSL_ISSUER_SERIAL *X509_ACERT_get0_holder_baseCertId(const X509_ACERT *x); -const OSSL_OBJECT_DIGEST_INFO * X509_ACERT_get0_holder_digest(const X509_ACERT *x); +const OSSL_OBJECT_DIGEST_INFO *X509_ACERT_get0_holder_digest(const X509_ACERT *x); const X509_NAME *X509_ACERT_get0_issuerName(const X509_ACERT *x); long X509_ACERT_get_version(const X509_ACERT *x); void X509_ACERT_get0_signature(const X509_ACERT *x, - const ASN1_BIT_STRING **psig, - const X509_ALGOR **palg); + const ASN1_BIT_STRING **psig, + const X509_ALGOR **palg); int X509_ACERT_get_signature_nid(const X509_ACERT *x); const X509_ALGOR *X509_ACERT_get0_info_sigalg(const X509_ACERT *x); const ASN1_INTEGER *X509_ACERT_get0_serialNumber(const X509_ACERT *x); @@ -67,38 +73,38 @@ const ASN1_BIT_STRING *X509_ACERT_get0_issuerUID(const X509_ACERT *x); int X509_ACERT_print(BIO *bp, X509_ACERT *x); int X509_ACERT_print_ex(BIO *bp, X509_ACERT *x, unsigned long nmflags, - unsigned long cflag); + unsigned long cflag); int X509_ACERT_get_attr_count(const X509_ACERT *x); int X509_ACERT_get_attr_by_NID(const X509_ACERT *x, int nid, int lastpos); int X509_ACERT_get_attr_by_OBJ(const X509_ACERT *x, const ASN1_OBJECT *obj, - int lastpos); + int lastpos); X509_ATTRIBUTE *X509_ACERT_get_attr(const X509_ACERT *x, int loc); X509_ATTRIBUTE *X509_ACERT_delete_attr(X509_ACERT *x, int loc); void *X509_ACERT_get_ext_d2i(const X509_ACERT *x, int nid, int *crit, int *idx); int X509_ACERT_add1_ext_i2d(X509_ACERT *x, int nid, void *value, int crit, - unsigned long flags); + unsigned long flags); const STACK_OF(X509_EXTENSION) *X509_ACERT_get0_extensions(const X509_ACERT *x); -# define OSSL_OBJECT_DIGEST_INFO_PUBLIC_KEY 0 -# define OSSL_OBJECT_DIGEST_INFO_PUBLIC_KEY_CERT 1 -# define OSSL_OBJECT_DIGEST_INFO_OTHER 2 /* must not be used in RFC 5755 profile */ +#define OSSL_OBJECT_DIGEST_INFO_PUBLIC_KEY 0 +#define OSSL_OBJECT_DIGEST_INFO_PUBLIC_KEY_CERT 1 +#define OSSL_OBJECT_DIGEST_INFO_OTHER 2 /* must not be used in RFC 5755 profile */ int X509_ACERT_set_version(X509_ACERT *x, long version); void X509_ACERT_set0_holder_entityName(X509_ACERT *x, GENERAL_NAMES *name); void X509_ACERT_set0_holder_baseCertId(X509_ACERT *x, OSSL_ISSUER_SERIAL *isss); void X509_ACERT_set0_holder_digest(X509_ACERT *x, - OSSL_OBJECT_DIGEST_INFO *dinfo); + OSSL_OBJECT_DIGEST_INFO *dinfo); int X509_ACERT_add1_attr(X509_ACERT *x, X509_ATTRIBUTE *attr); int X509_ACERT_add1_attr_by_OBJ(X509_ACERT *x, const ASN1_OBJECT *obj, - int type, const void *bytes, int len); + int type, const void *bytes, int len); int X509_ACERT_add1_attr_by_NID(X509_ACERT *x, int nid, int type, - const void *bytes, int len); + const void *bytes, int len); int X509_ACERT_add1_attr_by_txt(X509_ACERT *x, const char *attrname, int type, - const unsigned char *bytes, int len); + const unsigned char *bytes, int len); int X509_ACERT_add_attr_nconf(CONF *conf, const char *section, - X509_ACERT *acert); + X509_ACERT *acert); int X509_ACERT_set1_issuerName(X509_ACERT *x, const X509_NAME *name); int X509_ACERT_set1_serialNumber(X509_ACERT *x, const ASN1_INTEGER *serial); @@ -106,32 +112,33 @@ int X509_ACERT_set1_notBefore(X509_ACERT *x, const ASN1_GENERALIZEDTIME *time); int X509_ACERT_set1_notAfter(X509_ACERT *x, const ASN1_GENERALIZEDTIME *time); void OSSL_OBJECT_DIGEST_INFO_get0_digest(const OSSL_OBJECT_DIGEST_INFO *o, - int *digestedObjectType, - const X509_ALGOR **digestAlgorithm, - const ASN1_BIT_STRING **digest); + int *digestedObjectType, + const X509_ALGOR **digestAlgorithm, + const ASN1_BIT_STRING **digest); int OSSL_OBJECT_DIGEST_INFO_set1_digest(OSSL_OBJECT_DIGEST_INFO *o, - int digestedObjectType, - X509_ALGOR *digestAlgorithm, - ASN1_BIT_STRING *digest); + int digestedObjectType, + X509_ALGOR *digestAlgorithm, + ASN1_BIT_STRING *digest); const X509_NAME *OSSL_ISSUER_SERIAL_get0_issuer(const OSSL_ISSUER_SERIAL *isss); const ASN1_INTEGER *OSSL_ISSUER_SERIAL_get0_serial(const OSSL_ISSUER_SERIAL *isss); const ASN1_BIT_STRING *OSSL_ISSUER_SERIAL_get0_issuerUID(const OSSL_ISSUER_SERIAL *isss); int OSSL_ISSUER_SERIAL_set1_issuer(OSSL_ISSUER_SERIAL *isss, - const X509_NAME *issuer); + const X509_NAME *issuer); int OSSL_ISSUER_SERIAL_set1_serial(OSSL_ISSUER_SERIAL *isss, - const ASN1_INTEGER *serial); + const ASN1_INTEGER *serial); int OSSL_ISSUER_SERIAL_set1_issuerUID(OSSL_ISSUER_SERIAL *isss, - const ASN1_BIT_STRING *uid); + const ASN1_BIT_STRING *uid); -# define OSSL_IETFAS_OCTETS 0 -# define OSSL_IETFAS_OID 1 -# define OSSL_IETFAS_STRING 2 +#define OSSL_IETFAS_OCTETS 0 +#define OSSL_IETFAS_OID 1 +#define OSSL_IETFAS_STRING 2 typedef struct OSSL_IETF_ATTR_SYNTAX_VALUE_st OSSL_IETF_ATTR_SYNTAX_VALUE; typedef struct OSSL_IETF_ATTR_SYNTAX_st OSSL_IETF_ATTR_SYNTAX; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_IETF_ATTR_SYNTAX_VALUE, OSSL_IETF_ATTR_SYNTAX_VALUE, OSSL_IETF_ATTR_SYNTAX_VALUE) #define sk_OSSL_IETF_ATTR_SYNTAX_VALUE_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_IETF_ATTR_SYNTAX_VALUE_sk_type(sk)) #define sk_OSSL_IETF_ATTR_SYNTAX_VALUE_value(sk, idx) ((OSSL_IETF_ATTR_SYNTAX_VALUE *)OPENSSL_sk_value(ossl_check_const_OSSL_IETF_ATTR_SYNTAX_VALUE_sk_type(sk), (idx))) @@ -159,6 +166,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_IETF_ATTR_SYNTAX_VALUE, OSSL_IETF_ATTR_SYNTAX_ #define sk_OSSL_IETF_ATTR_SYNTAX_VALUE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_IETF_ATTR_SYNTAX_VALUE) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_IETF_ATTR_SYNTAX_VALUE_sk_type(sk), ossl_check_OSSL_IETF_ATTR_SYNTAX_VALUE_copyfunc_type(copyfunc), ossl_check_OSSL_IETF_ATTR_SYNTAX_VALUE_freefunc_type(freefunc))) #define sk_OSSL_IETF_ATTR_SYNTAX_VALUE_set_cmp_func(sk, cmp) ((sk_OSSL_IETF_ATTR_SYNTAX_VALUE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_IETF_ATTR_SYNTAX_VALUE_sk_type(sk), ossl_check_OSSL_IETF_ATTR_SYNTAX_VALUE_compfunc_type(cmp))) +/* clang-format on */ DECLARE_ASN1_ITEM(OSSL_IETF_ATTR_SYNTAX_VALUE) DECLARE_ASN1_ALLOC_FUNCTIONS(OSSL_IETF_ATTR_SYNTAX_VALUE) @@ -167,13 +175,13 @@ DECLARE_ASN1_FUNCTIONS(OSSL_IETF_ATTR_SYNTAX) const GENERAL_NAMES * OSSL_IETF_ATTR_SYNTAX_get0_policyAuthority(const OSSL_IETF_ATTR_SYNTAX *a); void OSSL_IETF_ATTR_SYNTAX_set0_policyAuthority(OSSL_IETF_ATTR_SYNTAX *a, - GENERAL_NAMES *names); + GENERAL_NAMES *names); int OSSL_IETF_ATTR_SYNTAX_get_value_num(const OSSL_IETF_ATTR_SYNTAX *a); void *OSSL_IETF_ATTR_SYNTAX_get0_value(const OSSL_IETF_ATTR_SYNTAX *a, - int ind, int *type); + int ind, int *type); int OSSL_IETF_ATTR_SYNTAX_add1_value(OSSL_IETF_ATTR_SYNTAX *a, int type, - void *data); + void *data); int OSSL_IETF_ATTR_SYNTAX_print(BIO *bp, OSSL_IETF_ATTR_SYNTAX *a, int indent); struct TARGET_CERT_st { @@ -184,9 +192,9 @@ struct TARGET_CERT_st { typedef struct TARGET_CERT_st OSSL_TARGET_CERT; -# define OSSL_TGT_TARGET_NAME 0 -# define OSSL_TGT_TARGET_GROUP 1 -# define OSSL_TGT_TARGET_CERT 2 +#define OSSL_TGT_TARGET_NAME 0 +#define OSSL_TGT_TARGET_GROUP 1 +#define OSSL_TGT_TARGET_CERT 2 typedef struct TARGET_st { int type; @@ -200,6 +208,7 @@ typedef struct TARGET_st { typedef STACK_OF(OSSL_TARGET) OSSL_TARGETS; typedef STACK_OF(OSSL_TARGETS) OSSL_TARGETING_INFORMATION; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_TARGET, OSSL_TARGET, OSSL_TARGET) #define sk_OSSL_TARGET_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_TARGET_sk_type(sk)) #define sk_OSSL_TARGET_value(sk, idx) ((OSSL_TARGET *)OPENSSL_sk_value(ossl_check_const_OSSL_TARGET_sk_type(sk), (idx))) @@ -227,7 +236,9 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_TARGET, OSSL_TARGET, OSSL_TARGET) #define sk_OSSL_TARGET_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_TARGET) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_TARGET_sk_type(sk), ossl_check_OSSL_TARGET_copyfunc_type(copyfunc), ossl_check_OSSL_TARGET_freefunc_type(freefunc))) #define sk_OSSL_TARGET_set_cmp_func(sk, cmp) ((sk_OSSL_TARGET_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_TARGET_sk_type(sk), ossl_check_OSSL_TARGET_compfunc_type(cmp))) +/* clang-format on */ +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_TARGETS, OSSL_TARGETS, OSSL_TARGETS) #define sk_OSSL_TARGETS_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_TARGETS_sk_type(sk)) #define sk_OSSL_TARGETS_value(sk, idx) ((OSSL_TARGETS *)OPENSSL_sk_value(ossl_check_const_OSSL_TARGETS_sk_type(sk), (idx))) @@ -255,6 +266,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_TARGETS, OSSL_TARGETS, OSSL_TARGETS) #define sk_OSSL_TARGETS_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_TARGETS) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_TARGETS_sk_type(sk), ossl_check_OSSL_TARGETS_copyfunc_type(copyfunc), ossl_check_OSSL_TARGETS_freefunc_type(freefunc))) #define sk_OSSL_TARGETS_set_cmp_func(sk, cmp) ((sk_OSSL_TARGETS_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_TARGETS_sk_type(sk), ossl_check_OSSL_TARGETS_compfunc_type(cmp))) +/* clang-format on */ DECLARE_ASN1_FUNCTIONS(OSSL_TARGET) DECLARE_ASN1_FUNCTIONS(OSSL_TARGETS) @@ -263,6 +275,7 @@ DECLARE_ASN1_FUNCTIONS(OSSL_TARGETING_INFORMATION) typedef STACK_OF(OSSL_ISSUER_SERIAL) OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX; DECLARE_ASN1_FUNCTIONS(OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_ISSUER_SERIAL, OSSL_ISSUER_SERIAL, OSSL_ISSUER_SERIAL) #define sk_OSSL_ISSUER_SERIAL_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_ISSUER_SERIAL_sk_type(sk)) #define sk_OSSL_ISSUER_SERIAL_value(sk, idx) ((OSSL_ISSUER_SERIAL *)OPENSSL_sk_value(ossl_check_const_OSSL_ISSUER_SERIAL_sk_type(sk), (idx))) @@ -290,5 +303,10 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_ISSUER_SERIAL, OSSL_ISSUER_SERIAL, OSSL_ISSUER #define sk_OSSL_ISSUER_SERIAL_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_ISSUER_SERIAL) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_ISSUER_SERIAL_sk_type(sk), ossl_check_OSSL_ISSUER_SERIAL_copyfunc_type(copyfunc), ossl_check_OSSL_ISSUER_SERIAL_freefunc_type(freefunc))) #define sk_OSSL_ISSUER_SERIAL_set_cmp_func(sk, cmp) ((sk_OSSL_ISSUER_SERIAL_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_ISSUER_SERIAL_sk_type(sk), ossl_check_OSSL_ISSUER_SERIAL_compfunc_type(cmp))) +/* clang-format on */ + +#ifdef __cplusplus +} +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509_vfy.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509_vfy.h index de63bf0184..4743f82bc4 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509_vfy.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509_vfy.h @@ -10,31 +10,33 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_X509_VFY_H -# define OPENSSL_X509_VFY_H -# pragma once +#define OPENSSL_X509_VFY_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_X509_VFY_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_X509_VFY_H +#endif /* * Protect against recursion, x509.h and x509_vfy.h each include the other. */ -# ifndef OPENSSL_X509_H -# include -# endif +#ifndef OPENSSL_X509_H +#include +#endif -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -57,14 +59,16 @@ certificate chain. typedef enum { X509_LU_NONE = 0, - X509_LU_X509, X509_LU_CRL + X509_LU_X509, + X509_LU_CRL } X509_LOOKUP_TYPE; #ifndef OPENSSL_NO_DEPRECATED_1_1_0 -#define X509_LU_RETRY -1 -#define X509_LU_FAIL 0 +#define X509_LU_RETRY -1 +#define X509_LU_FAIL 0 #endif +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509_LOOKUP, X509_LOOKUP, X509_LOOKUP) #define sk_X509_LOOKUP_num(sk) OPENSSL_sk_num(ossl_check_const_X509_LOOKUP_sk_type(sk)) #define sk_X509_LOOKUP_value(sk, idx) ((X509_LOOKUP *)OPENSSL_sk_value(ossl_check_const_X509_LOOKUP_sk_type(sk), (idx))) @@ -144,16 +148,18 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_VERIFY_PARAM, X509_VERIFY_PARAM, X509_VERIFY_P #define sk_X509_VERIFY_PARAM_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_VERIFY_PARAM) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_VERIFY_PARAM_sk_type(sk), ossl_check_X509_VERIFY_PARAM_copyfunc_type(copyfunc), ossl_check_X509_VERIFY_PARAM_freefunc_type(freefunc))) #define sk_X509_VERIFY_PARAM_set_cmp_func(sk, cmp) ((sk_X509_VERIFY_PARAM_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_VERIFY_PARAM_sk_type(sk), ossl_check_X509_VERIFY_PARAM_compfunc_type(cmp))) +/* clang-format on */ /* This is used for a table of trust checking functions */ typedef struct x509_trust_st { int trust; int flags; - int (*check_trust) (struct x509_trust_st *, X509 *, int); + int (*check_trust)(struct x509_trust_st *, X509 *, int); char *name; int arg1; void *arg2; } X509_TRUST; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509_TRUST, X509_TRUST, X509_TRUST) #define sk_X509_TRUST_num(sk) OPENSSL_sk_num(ossl_check_const_X509_TRUST_sk_type(sk)) #define sk_X509_TRUST_value(sk, idx) ((X509_TRUST *)OPENSSL_sk_value(ossl_check_const_X509_TRUST_sk_type(sk), (idx))) @@ -181,42 +187,43 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_TRUST, X509_TRUST, X509_TRUST) #define sk_X509_TRUST_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_TRUST) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_TRUST_sk_type(sk), ossl_check_X509_TRUST_copyfunc_type(copyfunc), ossl_check_X509_TRUST_freefunc_type(freefunc))) #define sk_X509_TRUST_set_cmp_func(sk, cmp) ((sk_X509_TRUST_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_TRUST_sk_type(sk), ossl_check_X509_TRUST_compfunc_type(cmp))) +/* clang-format on */ /* standard trust ids */ -# define X509_TRUST_DEFAULT 0 /* Only valid in purpose settings */ -# define X509_TRUST_COMPAT 1 -# define X509_TRUST_SSL_CLIENT 2 -# define X509_TRUST_SSL_SERVER 3 -# define X509_TRUST_EMAIL 4 -# define X509_TRUST_OBJECT_SIGN 5 -# define X509_TRUST_OCSP_SIGN 6 -# define X509_TRUST_OCSP_REQUEST 7 -# define X509_TRUST_TSA 8 +#define X509_TRUST_DEFAULT 0 /* Only valid in purpose settings */ +#define X509_TRUST_COMPAT 1 +#define X509_TRUST_SSL_CLIENT 2 +#define X509_TRUST_SSL_SERVER 3 +#define X509_TRUST_EMAIL 4 +#define X509_TRUST_OBJECT_SIGN 5 +#define X509_TRUST_OCSP_SIGN 6 +#define X509_TRUST_OCSP_REQUEST 7 +#define X509_TRUST_TSA 8 /* Keep these up to date! */ -# define X509_TRUST_MIN 1 -# define X509_TRUST_MAX 8 +#define X509_TRUST_MIN 1 +#define X509_TRUST_MAX 8 /* trust_flags values */ -# define X509_TRUST_DYNAMIC (1U << 0) -# define X509_TRUST_DYNAMIC_NAME (1U << 1) +#define X509_TRUST_DYNAMIC (1U << 0) +#define X509_TRUST_DYNAMIC_NAME (1U << 1) /* No compat trust if self-signed, preempts "DO_SS" */ -# define X509_TRUST_NO_SS_COMPAT (1U << 2) +#define X509_TRUST_NO_SS_COMPAT (1U << 2) /* Compat trust if no explicit accepted trust EKUs */ -# define X509_TRUST_DO_SS_COMPAT (1U << 3) +#define X509_TRUST_DO_SS_COMPAT (1U << 3) /* Accept "anyEKU" as a wildcard rejection OID and as a wildcard trust OID */ -# define X509_TRUST_OK_ANY_EKU (1U << 4) +#define X509_TRUST_OK_ANY_EKU (1U << 4) /* check_trust return codes */ -# define X509_TRUST_TRUSTED 1 -# define X509_TRUST_REJECTED 2 -# define X509_TRUST_UNTRUSTED 3 +#define X509_TRUST_TRUSTED 1 +#define X509_TRUST_REJECTED 2 +#define X509_TRUST_UNTRUSTED 3 int X509_TRUST_set(int *t, int trust); int X509_TRUST_get_count(void); X509_TRUST *X509_TRUST_get0(int idx); int X509_TRUST_get_by_id(int id); -int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int), - const char *name, int arg1, void *arg2); +int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int), + const char *name, int arg1, void *arg2); void X509_TRUST_cleanup(void); int X509_TRUST_get_flags(const X509_TRUST *xp); char *X509_TRUST_get0_name(const X509_TRUST *xp); @@ -230,15 +237,15 @@ void X509_reject_clear(X509 *x); STACK_OF(ASN1_OBJECT) *X509_get0_trust_objects(X509 *x); STACK_OF(ASN1_OBJECT) *X509_get0_reject_objects(X509 *x); -int (*X509_TRUST_set_default(int (*trust) (int, X509 *, int))) (int, X509 *, - int); +int (*X509_TRUST_set_default(int (*trust)(int, X509 *, int)))(int, X509 *, + int); int X509_check_trust(X509 *x, int id, int flags); int X509_verify_cert(X509_STORE_CTX *ctx); int X509_STORE_CTX_verify(X509_STORE_CTX *ctx); STACK_OF(X509) *X509_build_chain(X509 *target, STACK_OF(X509) *certs, - X509_STORE *store, int with_self_signed, - OSSL_LIB_CTX *libctx, const char *propq); + X509_STORE *store, int with_self_signed, + OSSL_LIB_CTX *libctx, const char *propq); int X509_STORE_set_depth(X509_STORE *store, int depth); @@ -246,243 +253,243 @@ typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *); int X509_STORE_CTX_print_verify_cb(int ok, X509_STORE_CTX *ctx); typedef int (*X509_STORE_CTX_verify_fn)(X509_STORE_CTX *); typedef int (*X509_STORE_CTX_get_issuer_fn)(X509 **issuer, - X509_STORE_CTX *ctx, X509 *x); + X509_STORE_CTX *ctx, X509 *x); typedef int (*X509_STORE_CTX_check_issued_fn)(X509_STORE_CTX *ctx, - X509 *x, X509 *issuer); + X509 *x, X509 *issuer); typedef int (*X509_STORE_CTX_check_revocation_fn)(X509_STORE_CTX *ctx); typedef int (*X509_STORE_CTX_get_crl_fn)(X509_STORE_CTX *ctx, - X509_CRL **crl, X509 *x); + X509_CRL **crl, X509 *x); typedef int (*X509_STORE_CTX_check_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl); typedef int (*X509_STORE_CTX_cert_crl_fn)(X509_STORE_CTX *ctx, - X509_CRL *crl, X509 *x); + X509_CRL *crl, X509 *x); typedef int (*X509_STORE_CTX_check_policy_fn)(X509_STORE_CTX *ctx); typedef STACK_OF(X509) *(*X509_STORE_CTX_lookup_certs_fn)(X509_STORE_CTX *ctx, - const X509_NAME *nm); + const X509_NAME *nm); typedef STACK_OF(X509_CRL) *(*X509_STORE_CTX_lookup_crls_fn)(const X509_STORE_CTX *ctx, - const X509_NAME *nm); + const X509_NAME *nm); typedef int (*X509_STORE_CTX_cleanup_fn)(X509_STORE_CTX *ctx); void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); -# define X509_STORE_CTX_set_app_data(ctx,data) \ - X509_STORE_CTX_set_ex_data(ctx,0,data) -# define X509_STORE_CTX_get_app_data(ctx) \ - X509_STORE_CTX_get_ex_data(ctx,0) +#define X509_STORE_CTX_set_app_data(ctx, data) \ + X509_STORE_CTX_set_ex_data(ctx, 0, data) +#define X509_STORE_CTX_get_app_data(ctx) \ + X509_STORE_CTX_get_ex_data(ctx, 0) -# define X509_L_FILE_LOAD 1 -# define X509_L_ADD_DIR 2 -# define X509_L_ADD_STORE 3 -# define X509_L_LOAD_STORE 4 +#define X509_L_FILE_LOAD 1 +#define X509_L_ADD_DIR 2 +#define X509_L_ADD_STORE 3 +#define X509_L_LOAD_STORE 4 -# define X509_LOOKUP_load_file(x,name,type) \ - X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) +#define X509_LOOKUP_load_file(x, name, type) \ + X509_LOOKUP_ctrl((x), X509_L_FILE_LOAD, (name), (long)(type), NULL) -# define X509_LOOKUP_add_dir(x,name,type) \ - X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) +#define X509_LOOKUP_add_dir(x, name, type) \ + X509_LOOKUP_ctrl((x), X509_L_ADD_DIR, (name), (long)(type), NULL) -# define X509_LOOKUP_add_store(x,name) \ - X509_LOOKUP_ctrl((x),X509_L_ADD_STORE,(name),0,NULL) +#define X509_LOOKUP_add_store(x, name) \ + X509_LOOKUP_ctrl((x), X509_L_ADD_STORE, (name), 0, NULL) -# define X509_LOOKUP_load_store(x,name) \ - X509_LOOKUP_ctrl((x),X509_L_LOAD_STORE,(name),0,NULL) +#define X509_LOOKUP_load_store(x, name) \ + X509_LOOKUP_ctrl((x), X509_L_LOAD_STORE, (name), 0, NULL) -# define X509_LOOKUP_load_file_ex(x, name, type, libctx, propq) \ -X509_LOOKUP_ctrl_ex((x), X509_L_FILE_LOAD, (name), (long)(type), NULL,\ - (libctx), (propq)) +#define X509_LOOKUP_load_file_ex(x, name, type, libctx, propq) \ + X509_LOOKUP_ctrl_ex((x), X509_L_FILE_LOAD, (name), (long)(type), NULL, \ + (libctx), (propq)) -# define X509_LOOKUP_load_store_ex(x, name, libctx, propq) \ -X509_LOOKUP_ctrl_ex((x), X509_L_LOAD_STORE, (name), 0, NULL, \ - (libctx), (propq)) +#define X509_LOOKUP_load_store_ex(x, name, libctx, propq) \ + X509_LOOKUP_ctrl_ex((x), X509_L_LOAD_STORE, (name), 0, NULL, \ + (libctx), (propq)) -# define X509_LOOKUP_add_store_ex(x, name, libctx, propq) \ -X509_LOOKUP_ctrl_ex((x), X509_L_ADD_STORE, (name), 0, NULL, \ - (libctx), (propq)) +#define X509_LOOKUP_add_store_ex(x, name, libctx, propq) \ + X509_LOOKUP_ctrl_ex((x), X509_L_ADD_STORE, (name), 0, NULL, \ + (libctx), (propq)) -# define X509_V_OK 0 -# define X509_V_ERR_UNSPECIFIED 1 -# define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 -# define X509_V_ERR_UNABLE_TO_GET_CRL 3 -# define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 -# define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 -# define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 -# define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 -# define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 -# define X509_V_ERR_CERT_NOT_YET_VALID 9 -# define X509_V_ERR_CERT_HAS_EXPIRED 10 -# define X509_V_ERR_CRL_NOT_YET_VALID 11 -# define X509_V_ERR_CRL_HAS_EXPIRED 12 -# define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 -# define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 -# define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 -# define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 -# define X509_V_ERR_OUT_OF_MEM 17 -# define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 -# define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 -# define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 -# define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 -# define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 -# define X509_V_ERR_CERT_REVOKED 23 -# define X509_V_ERR_NO_ISSUER_PUBLIC_KEY 24 -# define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 -# define X509_V_ERR_INVALID_PURPOSE 26 -# define X509_V_ERR_CERT_UNTRUSTED 27 -# define X509_V_ERR_CERT_REJECTED 28 +#define X509_V_OK 0 +#define X509_V_ERR_UNSPECIFIED 1 +#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 +#define X509_V_ERR_UNABLE_TO_GET_CRL 3 +#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 +#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 +#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 +#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 +#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 +#define X509_V_ERR_CERT_NOT_YET_VALID 9 +#define X509_V_ERR_CERT_HAS_EXPIRED 10 +#define X509_V_ERR_CRL_NOT_YET_VALID 11 +#define X509_V_ERR_CRL_HAS_EXPIRED 12 +#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 +#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 +#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 +#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 +#define X509_V_ERR_OUT_OF_MEM 17 +#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 +#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 +#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 +#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 +#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 +#define X509_V_ERR_CERT_REVOKED 23 +#define X509_V_ERR_NO_ISSUER_PUBLIC_KEY 24 +#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 +#define X509_V_ERR_INVALID_PURPOSE 26 +#define X509_V_ERR_CERT_UNTRUSTED 27 +#define X509_V_ERR_CERT_REJECTED 28 /* These are 'informational' when looking for issuer cert */ -# define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 -# define X509_V_ERR_AKID_SKID_MISMATCH 30 -# define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 -# define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 -# define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 -# define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 -# define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 -# define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 -# define X509_V_ERR_INVALID_NON_CA 37 -# define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 -# define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 -# define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 -# define X509_V_ERR_INVALID_EXTENSION 41 -# define X509_V_ERR_INVALID_POLICY_EXTENSION 42 -# define X509_V_ERR_NO_EXPLICIT_POLICY 43 -# define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 -# define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 -# define X509_V_ERR_UNNESTED_RESOURCE 46 -# define X509_V_ERR_PERMITTED_VIOLATION 47 -# define X509_V_ERR_EXCLUDED_VIOLATION 48 -# define X509_V_ERR_SUBTREE_MINMAX 49 +#define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 +#define X509_V_ERR_AKID_SKID_MISMATCH 30 +#define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 +#define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 +#define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 +#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 +#define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 +#define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 +#define X509_V_ERR_INVALID_NON_CA 37 +#define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 +#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 +#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 +#define X509_V_ERR_INVALID_EXTENSION 41 +#define X509_V_ERR_INVALID_POLICY_EXTENSION 42 +#define X509_V_ERR_NO_EXPLICIT_POLICY 43 +#define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 +#define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 +#define X509_V_ERR_UNNESTED_RESOURCE 46 +#define X509_V_ERR_PERMITTED_VIOLATION 47 +#define X509_V_ERR_EXCLUDED_VIOLATION 48 +#define X509_V_ERR_SUBTREE_MINMAX 49 /* The application is not happy */ -# define X509_V_ERR_APPLICATION_VERIFICATION 50 -# define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 -# define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 -# define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 -# define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 +#define X509_V_ERR_APPLICATION_VERIFICATION 50 +#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 +#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 +#define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 +#define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 /* Another issuer check debug option */ -# define X509_V_ERR_PATH_LOOP 55 +#define X509_V_ERR_PATH_LOOP 55 /* Suite B mode algorithm violation */ -# define X509_V_ERR_SUITE_B_INVALID_VERSION 56 -# define X509_V_ERR_SUITE_B_INVALID_ALGORITHM 57 -# define X509_V_ERR_SUITE_B_INVALID_CURVE 58 -# define X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM 59 -# define X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED 60 -# define X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 61 +#define X509_V_ERR_SUITE_B_INVALID_VERSION 56 +#define X509_V_ERR_SUITE_B_INVALID_ALGORITHM 57 +#define X509_V_ERR_SUITE_B_INVALID_CURVE 58 +#define X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM 59 +#define X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED 60 +#define X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 61 /* Host, email and IP check errors */ -# define X509_V_ERR_HOSTNAME_MISMATCH 62 -# define X509_V_ERR_EMAIL_MISMATCH 63 -# define X509_V_ERR_IP_ADDRESS_MISMATCH 64 +#define X509_V_ERR_HOSTNAME_MISMATCH 62 +#define X509_V_ERR_EMAIL_MISMATCH 63 +#define X509_V_ERR_IP_ADDRESS_MISMATCH 64 /* DANE TLSA errors */ -# define X509_V_ERR_DANE_NO_MATCH 65 +#define X509_V_ERR_DANE_NO_MATCH 65 /* security level errors */ -# define X509_V_ERR_EE_KEY_TOO_SMALL 66 -# define X509_V_ERR_CA_KEY_TOO_SMALL 67 -# define X509_V_ERR_CA_MD_TOO_WEAK 68 +#define X509_V_ERR_EE_KEY_TOO_SMALL 66 +#define X509_V_ERR_CA_KEY_TOO_SMALL 67 +#define X509_V_ERR_CA_MD_TOO_WEAK 68 /* Caller error */ -# define X509_V_ERR_INVALID_CALL 69 +#define X509_V_ERR_INVALID_CALL 69 /* Issuer lookup error */ -# define X509_V_ERR_STORE_LOOKUP 70 +#define X509_V_ERR_STORE_LOOKUP 70 /* Certificate transparency */ -# define X509_V_ERR_NO_VALID_SCTS 71 +#define X509_V_ERR_NO_VALID_SCTS 71 -# define X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION 72 +#define X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION 72 /* OCSP status errors */ -# define X509_V_ERR_OCSP_VERIFY_NEEDED 73 /* Need OCSP verification */ -# define X509_V_ERR_OCSP_VERIFY_FAILED 74 /* Couldn't verify cert through OCSP */ -# define X509_V_ERR_OCSP_CERT_UNKNOWN 75 /* Certificate wasn't recognized by the OCSP responder */ +#define X509_V_ERR_OCSP_VERIFY_NEEDED 73 /* Need OCSP verification */ +#define X509_V_ERR_OCSP_VERIFY_FAILED 74 /* Couldn't verify cert through OCSP */ +#define X509_V_ERR_OCSP_CERT_UNKNOWN 75 /* Certificate wasn't recognized by the OCSP responder */ -# define X509_V_ERR_UNSUPPORTED_SIGNATURE_ALGORITHM 76 -# define X509_V_ERR_SIGNATURE_ALGORITHM_MISMATCH 77 +#define X509_V_ERR_UNSUPPORTED_SIGNATURE_ALGORITHM 76 +#define X509_V_ERR_SIGNATURE_ALGORITHM_MISMATCH 77 /* Errors in case a check in X509_V_FLAG_X509_STRICT mode fails */ -# define X509_V_ERR_SIGNATURE_ALGORITHM_INCONSISTENCY 78 -# define X509_V_ERR_INVALID_CA 79 -# define X509_V_ERR_PATHLEN_INVALID_FOR_NON_CA 80 -# define X509_V_ERR_PATHLEN_WITHOUT_KU_KEY_CERT_SIGN 81 -# define X509_V_ERR_KU_KEY_CERT_SIGN_INVALID_FOR_NON_CA 82 -# define X509_V_ERR_ISSUER_NAME_EMPTY 83 -# define X509_V_ERR_SUBJECT_NAME_EMPTY 84 -# define X509_V_ERR_MISSING_AUTHORITY_KEY_IDENTIFIER 85 -# define X509_V_ERR_MISSING_SUBJECT_KEY_IDENTIFIER 86 -# define X509_V_ERR_EMPTY_SUBJECT_ALT_NAME 87 -# define X509_V_ERR_EMPTY_SUBJECT_SAN_NOT_CRITICAL 88 -# define X509_V_ERR_CA_BCONS_NOT_CRITICAL 89 -# define X509_V_ERR_AUTHORITY_KEY_IDENTIFIER_CRITICAL 90 -# define X509_V_ERR_SUBJECT_KEY_IDENTIFIER_CRITICAL 91 -# define X509_V_ERR_CA_CERT_MISSING_KEY_USAGE 92 -# define X509_V_ERR_EXTENSIONS_REQUIRE_VERSION_3 93 -# define X509_V_ERR_EC_KEY_EXPLICIT_PARAMS 94 -# define X509_V_ERR_RPK_UNTRUSTED 95 +#define X509_V_ERR_SIGNATURE_ALGORITHM_INCONSISTENCY 78 +#define X509_V_ERR_INVALID_CA 79 +#define X509_V_ERR_PATHLEN_INVALID_FOR_NON_CA 80 +#define X509_V_ERR_PATHLEN_WITHOUT_KU_KEY_CERT_SIGN 81 +#define X509_V_ERR_KU_KEY_CERT_SIGN_INVALID_FOR_NON_CA 82 +#define X509_V_ERR_ISSUER_NAME_EMPTY 83 +#define X509_V_ERR_SUBJECT_NAME_EMPTY 84 +#define X509_V_ERR_MISSING_AUTHORITY_KEY_IDENTIFIER 85 +#define X509_V_ERR_MISSING_SUBJECT_KEY_IDENTIFIER 86 +#define X509_V_ERR_EMPTY_SUBJECT_ALT_NAME 87 +#define X509_V_ERR_EMPTY_SUBJECT_SAN_NOT_CRITICAL 88 +#define X509_V_ERR_CA_BCONS_NOT_CRITICAL 89 +#define X509_V_ERR_AUTHORITY_KEY_IDENTIFIER_CRITICAL 90 +#define X509_V_ERR_SUBJECT_KEY_IDENTIFIER_CRITICAL 91 +#define X509_V_ERR_CA_CERT_MISSING_KEY_USAGE 92 +#define X509_V_ERR_EXTENSIONS_REQUIRE_VERSION_3 93 +#define X509_V_ERR_EC_KEY_EXPLICIT_PARAMS 94 +#define X509_V_ERR_RPK_UNTRUSTED 95 /* Certificate verify flags */ -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define X509_V_FLAG_CB_ISSUER_CHECK 0x0 /* Deprecated */ -# endif +#ifndef OPENSSL_NO_DEPRECATED_1_1_0 +#define X509_V_FLAG_CB_ISSUER_CHECK 0x0 /* Deprecated */ +#endif /* Use check time instead of current time */ -# define X509_V_FLAG_USE_CHECK_TIME 0x2 +#define X509_V_FLAG_USE_CHECK_TIME 0x2 /* Lookup CRLs */ -# define X509_V_FLAG_CRL_CHECK 0x4 +#define X509_V_FLAG_CRL_CHECK 0x4 /* Lookup CRLs for whole chain */ -# define X509_V_FLAG_CRL_CHECK_ALL 0x8 +#define X509_V_FLAG_CRL_CHECK_ALL 0x8 /* Ignore unhandled critical extensions */ -# define X509_V_FLAG_IGNORE_CRITICAL 0x10 +#define X509_V_FLAG_IGNORE_CRITICAL 0x10 /* Disable workarounds for broken certificates */ -# define X509_V_FLAG_X509_STRICT 0x20 +#define X509_V_FLAG_X509_STRICT 0x20 /* Enable proxy certificate validation */ -# define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 +#define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 /* Enable policy checking */ -# define X509_V_FLAG_POLICY_CHECK 0x80 +#define X509_V_FLAG_POLICY_CHECK 0x80 /* Policy variable require-explicit-policy */ -# define X509_V_FLAG_EXPLICIT_POLICY 0x100 +#define X509_V_FLAG_EXPLICIT_POLICY 0x100 /* Policy variable inhibit-any-policy */ -# define X509_V_FLAG_INHIBIT_ANY 0x200 +#define X509_V_FLAG_INHIBIT_ANY 0x200 /* Policy variable inhibit-policy-mapping */ -# define X509_V_FLAG_INHIBIT_MAP 0x400 +#define X509_V_FLAG_INHIBIT_MAP 0x400 /* Notify callback that policy is OK */ -# define X509_V_FLAG_NOTIFY_POLICY 0x800 +#define X509_V_FLAG_NOTIFY_POLICY 0x800 /* Extended CRL features such as indirect CRLs, alternate CRL signing keys */ -# define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000 +#define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000 /* Delta CRL support */ -# define X509_V_FLAG_USE_DELTAS 0x2000 +#define X509_V_FLAG_USE_DELTAS 0x2000 /* Check self-signed CA signature */ -# define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 +#define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 /* Use trusted store first */ -# define X509_V_FLAG_TRUSTED_FIRST 0x8000 +#define X509_V_FLAG_TRUSTED_FIRST 0x8000 /* Suite B 128 bit only mode: not normally used */ -# define X509_V_FLAG_SUITEB_128_LOS_ONLY 0x10000 +#define X509_V_FLAG_SUITEB_128_LOS_ONLY 0x10000 /* Suite B 192 bit only mode */ -# define X509_V_FLAG_SUITEB_192_LOS 0x20000 +#define X509_V_FLAG_SUITEB_192_LOS 0x20000 /* Suite B 128 bit mode allowing 192 bit algorithms */ -# define X509_V_FLAG_SUITEB_128_LOS 0x30000 +#define X509_V_FLAG_SUITEB_128_LOS 0x30000 /* Allow partial chains if at least one certificate is in trusted store */ -# define X509_V_FLAG_PARTIAL_CHAIN 0x80000 +#define X509_V_FLAG_PARTIAL_CHAIN 0x80000 /* * If the initial chain is not trusted, do not attempt to build an alternative * chain. Alternate chain checking was introduced in 1.1.0. Setting this flag * will force the behaviour to match that of previous versions. */ -# define X509_V_FLAG_NO_ALT_CHAINS 0x100000 +#define X509_V_FLAG_NO_ALT_CHAINS 0x100000 /* Do not check certificate/CRL validity against current time */ -# define X509_V_FLAG_NO_CHECK_TIME 0x200000 +#define X509_V_FLAG_NO_CHECK_TIME 0x200000 -# define X509_VP_FLAG_DEFAULT 0x1 -# define X509_VP_FLAG_OVERWRITE 0x2 -# define X509_VP_FLAG_RESET_FLAGS 0x4 -# define X509_VP_FLAG_LOCKED 0x8 -# define X509_VP_FLAG_ONCE 0x10 +#define X509_VP_FLAG_DEFAULT 0x1 +#define X509_VP_FLAG_OVERWRITE 0x2 +#define X509_VP_FLAG_RESET_FLAGS 0x4 +#define X509_VP_FLAG_LOCKED 0x8 +#define X509_VP_FLAG_ONCE 0x10 /* Internal use: mask of policy related options */ -# define X509_V_FLAG_POLICY_MASK (X509_V_FLAG_POLICY_CHECK \ - | X509_V_FLAG_EXPLICIT_POLICY \ - | X509_V_FLAG_INHIBIT_ANY \ - | X509_V_FLAG_INHIBIT_MAP) +#define X509_V_FLAG_POLICY_MASK (X509_V_FLAG_POLICY_CHECK \ + | X509_V_FLAG_EXPLICIT_POLICY \ + | X509_V_FLAG_INHIBIT_ANY \ + | X509_V_FLAG_INHIBIT_MAP) int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, X509_LOOKUP_TYPE type, - const X509_NAME *name); + const X509_NAME *name); X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, - X509_LOOKUP_TYPE type, - const X509_NAME *name); + X509_LOOKUP_TYPE type, + const X509_NAME *name); X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, - X509_OBJECT *x); + X509_OBJECT *x); int X509_OBJECT_up_ref_count(X509_OBJECT *a); X509_OBJECT *X509_OBJECT_new(void); void X509_OBJECT_free(X509_OBJECT *a); @@ -500,9 +507,9 @@ STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(const X509_STORE *xs); STACK_OF(X509_OBJECT) *X509_STORE_get1_objects(X509_STORE *xs); STACK_OF(X509) *X509_STORE_get1_all_certs(X509_STORE *xs); STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *xs, - const X509_NAME *nm); + const X509_NAME *nm); STACK_OF(X509_CRL) *X509_STORE_CTX_get1_crls(const X509_STORE_CTX *st, - const X509_NAME *nm); + const X509_NAME *nm); int X509_STORE_set_flags(X509_STORE *xs, unsigned long flags); int X509_STORE_set_purpose(X509_STORE *xs, int purpose); int X509_STORE_set_trust(X509_STORE *xs, int trust); @@ -511,47 +518,47 @@ X509_VERIFY_PARAM *X509_STORE_get0_param(const X509_STORE *xs); void X509_STORE_set_verify(X509_STORE *xs, X509_STORE_CTX_verify_fn verify); #define X509_STORE_set_verify_func(ctx, func) \ - X509_STORE_set_verify((ctx),(func)) + X509_STORE_set_verify((ctx), (func)) void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx, - X509_STORE_CTX_verify_fn verify); + X509_STORE_CTX_verify_fn verify); X509_STORE_CTX_verify_fn X509_STORE_get_verify(const X509_STORE *xs); void X509_STORE_set_verify_cb(X509_STORE *xs, - X509_STORE_CTX_verify_cb verify_cb); -# define X509_STORE_set_verify_cb_func(ctx,func) \ - X509_STORE_set_verify_cb((ctx),(func)) + X509_STORE_CTX_verify_cb verify_cb); +#define X509_STORE_set_verify_cb_func(ctx, func) \ + X509_STORE_set_verify_cb((ctx), (func)) X509_STORE_CTX_verify_cb X509_STORE_get_verify_cb(const X509_STORE *xs); void X509_STORE_set_get_issuer(X509_STORE *xs, - X509_STORE_CTX_get_issuer_fn get_issuer); + X509_STORE_CTX_get_issuer_fn get_issuer); X509_STORE_CTX_get_issuer_fn X509_STORE_get_get_issuer(const X509_STORE *xs); void X509_STORE_set_check_issued(X509_STORE *xs, - X509_STORE_CTX_check_issued_fn check_issued); + X509_STORE_CTX_check_issued_fn check_issued); X509_STORE_CTX_check_issued_fn X509_STORE_get_check_issued(const X509_STORE *s); void X509_STORE_set_check_revocation(X509_STORE *xs, - X509_STORE_CTX_check_revocation_fn check_revocation); + X509_STORE_CTX_check_revocation_fn check_revocation); X509_STORE_CTX_check_revocation_fn - X509_STORE_get_check_revocation(const X509_STORE *xs); +X509_STORE_get_check_revocation(const X509_STORE *xs); void X509_STORE_set_get_crl(X509_STORE *xs, - X509_STORE_CTX_get_crl_fn get_crl); + X509_STORE_CTX_get_crl_fn get_crl); X509_STORE_CTX_get_crl_fn X509_STORE_get_get_crl(const X509_STORE *xs); void X509_STORE_set_check_crl(X509_STORE *xs, - X509_STORE_CTX_check_crl_fn check_crl); + X509_STORE_CTX_check_crl_fn check_crl); X509_STORE_CTX_check_crl_fn X509_STORE_get_check_crl(const X509_STORE *xs); void X509_STORE_set_cert_crl(X509_STORE *xs, - X509_STORE_CTX_cert_crl_fn cert_crl); + X509_STORE_CTX_cert_crl_fn cert_crl); X509_STORE_CTX_cert_crl_fn X509_STORE_get_cert_crl(const X509_STORE *xs); void X509_STORE_set_check_policy(X509_STORE *xs, - X509_STORE_CTX_check_policy_fn check_policy); + X509_STORE_CTX_check_policy_fn check_policy); X509_STORE_CTX_check_policy_fn X509_STORE_get_check_policy(const X509_STORE *s); void X509_STORE_set_lookup_certs(X509_STORE *xs, - X509_STORE_CTX_lookup_certs_fn lookup_certs); + X509_STORE_CTX_lookup_certs_fn lookup_certs); X509_STORE_CTX_lookup_certs_fn X509_STORE_get_lookup_certs(const X509_STORE *s); void X509_STORE_set_lookup_crls(X509_STORE *xs, - X509_STORE_CTX_lookup_crls_fn lookup_crls); + X509_STORE_CTX_lookup_crls_fn lookup_crls); #define X509_STORE_set_lookup_crls_cb(ctx, func) \ X509_STORE_set_lookup_crls((ctx), (func)) X509_STORE_CTX_lookup_crls_fn X509_STORE_get_lookup_crls(const X509_STORE *xs); void X509_STORE_set_cleanup(X509_STORE *xs, - X509_STORE_CTX_cleanup_fn cleanup); + X509_STORE_CTX_cleanup_fn cleanup); X509_STORE_CTX_cleanup_fn X509_STORE_get_cleanup(const X509_STORE *xs); #define X509_STORE_get_ex_new_index(l, p, newf, dupf, freef) \ @@ -566,26 +573,26 @@ int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); void X509_STORE_CTX_free(X509_STORE_CTX *ctx); int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *trust_store, - X509 *target, STACK_OF(X509) *untrusted); + X509 *target, STACK_OF(X509) *untrusted); int X509_STORE_CTX_init_rpk(X509_STORE_CTX *ctx, X509_STORE *trust_store, - EVP_PKEY* rpk); + EVP_PKEY *rpk); void X509_STORE_CTX_set0_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk); void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); X509_STORE *X509_STORE_CTX_get0_store(const X509_STORE_CTX *ctx); X509 *X509_STORE_CTX_get0_cert(const X509_STORE_CTX *ctx); EVP_PKEY *X509_STORE_CTX_get0_rpk(const X509_STORE_CTX *ctx); -STACK_OF(X509)* X509_STORE_CTX_get0_untrusted(const X509_STORE_CTX *ctx); +STACK_OF(X509) *X509_STORE_CTX_get0_untrusted(const X509_STORE_CTX *ctx); void X509_STORE_CTX_set0_untrusted(X509_STORE_CTX *ctx, STACK_OF(X509) *sk); void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, - X509_STORE_CTX_verify_cb verify); + X509_STORE_CTX_verify_cb verify); X509_STORE_CTX_verify_cb X509_STORE_CTX_get_verify_cb(const X509_STORE_CTX *ctx); X509_STORE_CTX_verify_fn X509_STORE_CTX_get_verify(const X509_STORE_CTX *ctx); X509_STORE_CTX_get_issuer_fn X509_STORE_CTX_get_get_issuer(const X509_STORE_CTX *ctx); X509_STORE_CTX_check_issued_fn X509_STORE_CTX_get_check_issued(const X509_STORE_CTX *ctx); X509_STORE_CTX_check_revocation_fn X509_STORE_CTX_get_check_revocation(const X509_STORE_CTX *ctx); void X509_STORE_CTX_set_get_crl(X509_STORE_CTX *ctx, - X509_STORE_CTX_get_crl_fn get_crl); + X509_STORE_CTX_get_crl_fn get_crl); X509_STORE_CTX_get_crl_fn X509_STORE_CTX_get_get_crl(const X509_STORE_CTX *ctx); X509_STORE_CTX_check_crl_fn X509_STORE_CTX_get_check_crl(const X509_STORE_CTX *ctx); X509_STORE_CTX_cert_crl_fn X509_STORE_CTX_get_cert_crl(const X509_STORE_CTX *ctx); @@ -595,16 +602,16 @@ X509_STORE_CTX_lookup_crls_fn X509_STORE_CTX_get_lookup_crls(const X509_STORE_CT X509_STORE_CTX_cleanup_fn X509_STORE_CTX_get_cleanup(const X509_STORE_CTX *ctx); #ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# define X509_STORE_CTX_get_chain X509_STORE_CTX_get0_chain -# define X509_STORE_CTX_set_chain X509_STORE_CTX_set0_untrusted -# define X509_STORE_CTX_trusted_stack X509_STORE_CTX_set0_trusted_stack -# define X509_STORE_get_by_subject X509_STORE_CTX_get_by_subject -# define X509_STORE_get1_certs X509_STORE_CTX_get1_certs -# define X509_STORE_get1_crls X509_STORE_CTX_get1_crls +#define X509_STORE_CTX_get_chain X509_STORE_CTX_get0_chain +#define X509_STORE_CTX_set_chain X509_STORE_CTX_set0_untrusted +#define X509_STORE_CTX_trusted_stack X509_STORE_CTX_set0_trusted_stack +#define X509_STORE_get_by_subject X509_STORE_CTX_get_by_subject +#define X509_STORE_get1_certs X509_STORE_CTX_get1_certs +#define X509_STORE_get1_crls X509_STORE_CTX_get1_crls /* the following macro is misspelled; use X509_STORE_get1_certs instead */ -# define X509_STORE_get1_cert X509_STORE_CTX_get1_certs +#define X509_STORE_get1_cert X509_STORE_CTX_get1_certs /* the following macro is misspelled; use X509_STORE_get1_crls instead */ -# define X509_STORE_get1_crl X509_STORE_CTX_get1_crls +#define X509_STORE_get1_crl X509_STORE_CTX_get1_crls #endif X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *xs, X509_LOOKUP_METHOD *m); @@ -613,66 +620,62 @@ X509_LOOKUP_METHOD *X509_LOOKUP_file(void); X509_LOOKUP_METHOD *X509_LOOKUP_store(void); typedef int (*X509_LOOKUP_ctrl_fn)(X509_LOOKUP *ctx, int cmd, const char *argc, - long argl, char **ret); + long argl, char **ret); typedef int (*X509_LOOKUP_ctrl_ex_fn)( X509_LOOKUP *ctx, int cmd, const char *argc, long argl, char **ret, OSSL_LIB_CTX *libctx, const char *propq); typedef int (*X509_LOOKUP_get_by_subject_fn)(X509_LOOKUP *ctx, - X509_LOOKUP_TYPE type, - const X509_NAME *name, - X509_OBJECT *ret); + X509_LOOKUP_TYPE type, + const X509_NAME *name, + X509_OBJECT *ret); typedef int (*X509_LOOKUP_get_by_subject_ex_fn)(X509_LOOKUP *ctx, - X509_LOOKUP_TYPE type, - const X509_NAME *name, - X509_OBJECT *ret, - OSSL_LIB_CTX *libctx, - const char *propq); + X509_LOOKUP_TYPE type, + const X509_NAME *name, + X509_OBJECT *ret, + OSSL_LIB_CTX *libctx, + const char *propq); typedef int (*X509_LOOKUP_get_by_issuer_serial_fn)(X509_LOOKUP *ctx, - X509_LOOKUP_TYPE type, - const X509_NAME *name, - const ASN1_INTEGER *serial, - X509_OBJECT *ret); + X509_LOOKUP_TYPE type, + const X509_NAME *name, + const ASN1_INTEGER *serial, + X509_OBJECT *ret); typedef int (*X509_LOOKUP_get_by_fingerprint_fn)(X509_LOOKUP *ctx, - X509_LOOKUP_TYPE type, - const unsigned char* bytes, - int len, - X509_OBJECT *ret); + X509_LOOKUP_TYPE type, + const unsigned char *bytes, + int len, + X509_OBJECT *ret); typedef int (*X509_LOOKUP_get_by_alias_fn)(X509_LOOKUP *ctx, - X509_LOOKUP_TYPE type, - const char *str, - int len, - X509_OBJECT *ret); + X509_LOOKUP_TYPE type, + const char *str, + int len, + X509_OBJECT *ret); X509_LOOKUP_METHOD *X509_LOOKUP_meth_new(const char *name); void X509_LOOKUP_meth_free(X509_LOOKUP_METHOD *method); int X509_LOOKUP_meth_set_new_item(X509_LOOKUP_METHOD *method, - int (*new_item) (X509_LOOKUP *ctx)); -int (*X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD* method)) - (X509_LOOKUP *ctx); + int (*new_item)(X509_LOOKUP *ctx)); +int (*X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD *method))(X509_LOOKUP *ctx); int X509_LOOKUP_meth_set_free(X509_LOOKUP_METHOD *method, - void (*free_fn) (X509_LOOKUP *ctx)); -void (*X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD* method)) - (X509_LOOKUP *ctx); + void (*free_fn)(X509_LOOKUP *ctx)); +void (*X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD *method))(X509_LOOKUP *ctx); int X509_LOOKUP_meth_set_init(X509_LOOKUP_METHOD *method, - int (*init) (X509_LOOKUP *ctx)); -int (*X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD* method)) - (X509_LOOKUP *ctx); + int (*init)(X509_LOOKUP *ctx)); +int (*X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD *method))(X509_LOOKUP *ctx); int X509_LOOKUP_meth_set_shutdown(X509_LOOKUP_METHOD *method, - int (*shutdown) (X509_LOOKUP *ctx)); -int (*X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD* method)) - (X509_LOOKUP *ctx); + int (*shutdown)(X509_LOOKUP *ctx)); +int (*X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD *method))(X509_LOOKUP *ctx); int X509_LOOKUP_meth_set_ctrl(X509_LOOKUP_METHOD *method, - X509_LOOKUP_ctrl_fn ctrl_fn); + X509_LOOKUP_ctrl_fn ctrl_fn); X509_LOOKUP_ctrl_fn X509_LOOKUP_meth_get_ctrl(const X509_LOOKUP_METHOD *method); int X509_LOOKUP_meth_set_get_by_subject(X509_LOOKUP_METHOD *method, - X509_LOOKUP_get_by_subject_fn fn); + X509_LOOKUP_get_by_subject_fn fn); X509_LOOKUP_get_by_subject_fn X509_LOOKUP_meth_get_get_by_subject( const X509_LOOKUP_METHOD *method); @@ -687,51 +690,50 @@ X509_LOOKUP_get_by_fingerprint_fn X509_LOOKUP_meth_get_get_by_fingerprint( const X509_LOOKUP_METHOD *method); int X509_LOOKUP_meth_set_get_by_alias(X509_LOOKUP_METHOD *method, - X509_LOOKUP_get_by_alias_fn fn); + X509_LOOKUP_get_by_alias_fn fn); X509_LOOKUP_get_by_alias_fn X509_LOOKUP_meth_get_get_by_alias( const X509_LOOKUP_METHOD *method); - int X509_STORE_add_cert(X509_STORE *xs, X509 *x); int X509_STORE_add_crl(X509_STORE *xs, X509_CRL *x); int X509_STORE_CTX_get_by_subject(const X509_STORE_CTX *vs, - X509_LOOKUP_TYPE type, - const X509_NAME *name, X509_OBJECT *ret); + X509_LOOKUP_TYPE type, + const X509_NAME *name, X509_OBJECT *ret); X509_OBJECT *X509_STORE_CTX_get_obj_by_subject(X509_STORE_CTX *vs, - X509_LOOKUP_TYPE type, - const X509_NAME *name); + X509_LOOKUP_TYPE type, + const X509_NAME *name); int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, - long argl, char **ret); + long argl, char **ret); int X509_LOOKUP_ctrl_ex(X509_LOOKUP *ctx, int cmd, const char *argc, long argl, - char **ret, OSSL_LIB_CTX *libctx, const char *propq); + char **ret, OSSL_LIB_CTX *libctx, const char *propq); int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type); int X509_load_cert_file_ex(X509_LOOKUP *ctx, const char *file, int type, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type); int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type); int X509_load_cert_crl_file_ex(X509_LOOKUP *ctx, const char *file, int type, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method); void X509_LOOKUP_free(X509_LOOKUP *ctx); int X509_LOOKUP_init(X509_LOOKUP *ctx); int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, - const X509_NAME *name, X509_OBJECT *ret); + const X509_NAME *name, X509_OBJECT *ret); int X509_LOOKUP_by_subject_ex(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, - const X509_NAME *name, X509_OBJECT *ret, - OSSL_LIB_CTX *libctx, const char *propq); + const X509_NAME *name, X509_OBJECT *ret, + OSSL_LIB_CTX *libctx, const char *propq); int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, - const X509_NAME *name, - const ASN1_INTEGER *serial, - X509_OBJECT *ret); + const X509_NAME *name, + const ASN1_INTEGER *serial, + X509_OBJECT *ret); int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, - const unsigned char *bytes, int len, - X509_OBJECT *ret); + const unsigned char *bytes, int len, + X509_OBJECT *ret); int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, - const char *str, int len, X509_OBJECT *ret); + const char *str, int len, X509_OBJECT *ret); int X509_LOOKUP_set_method_data(X509_LOOKUP *ctx, void *data); void *X509_LOOKUP_get_method_data(const X509_LOOKUP *ctx); X509_STORE *X509_LOOKUP_get_store(const X509_LOOKUP *ctx); @@ -744,14 +746,14 @@ int X509_STORE_load_locations(X509_STORE *s, const char *file, const char *dir); int X509_STORE_set_default_paths(X509_STORE *xs); int X509_STORE_load_file_ex(X509_STORE *xs, const char *file, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); int X509_STORE_load_store_ex(X509_STORE *xs, const char *store, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); int X509_STORE_load_locations_ex(X509_STORE *xs, - const char *file, const char *dir, - OSSL_LIB_CTX *libctx, const char *propq); + const char *file, const char *dir, + OSSL_LIB_CTX *libctx, const char *propq); int X509_STORE_set_default_paths_ex(X509_STORE *xs, - OSSL_LIB_CTX *libctx, const char *propq); + OSSL_LIB_CTX *libctx, const char *propq); #define X509_STORE_CTX_get_ex_new_index(l, p, newf, dupf, freef) \ CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE_CTX, l, p, newf, dupf, freef) @@ -775,12 +777,12 @@ void X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk); int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose, - int purpose, int trust); + int purpose, int trust); void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags); void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags, - time_t t); + time_t t); void X509_STORE_CTX_set_current_reasons(X509_STORE_CTX *ctx, - unsigned int current_reasons); + unsigned int current_reasons); X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(const X509_STORE_CTX *ctx); int X509_STORE_CTX_get_explicit_policy(const X509_STORE_CTX *ctx); @@ -802,14 +804,14 @@ void X509_STORE_CTX_set0_dane(X509_STORE_CTX *ctx, SSL_DANE *dane); X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void); void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param); int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to, - const X509_VERIFY_PARAM *from); + const X509_VERIFY_PARAM *from); int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, - const X509_VERIFY_PARAM *from); + const X509_VERIFY_PARAM *from); int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name); int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, - unsigned long flags); + unsigned long flags); int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, - unsigned long flags); + unsigned long flags); unsigned long X509_VERIFY_PARAM_get_flags(const X509_VERIFY_PARAM *param); int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose); int X509_VERIFY_PARAM_get_purpose(const X509_VERIFY_PARAM *param); @@ -819,32 +821,32 @@ void X509_VERIFY_PARAM_set_auth_level(X509_VERIFY_PARAM *param, int auth_level); time_t X509_VERIFY_PARAM_get_time(const X509_VERIFY_PARAM *param); void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t); int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, - ASN1_OBJECT *policy); + ASN1_OBJECT *policy); int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param, - STACK_OF(ASN1_OBJECT) *policies); + STACK_OF(ASN1_OBJECT) *policies); int X509_VERIFY_PARAM_set_inh_flags(X509_VERIFY_PARAM *param, - uint32_t flags); + uint32_t flags); uint32_t X509_VERIFY_PARAM_get_inh_flags(const X509_VERIFY_PARAM *param); char *X509_VERIFY_PARAM_get0_host(X509_VERIFY_PARAM *param, int idx); int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, - const char *name, size_t namelen); + const char *name, size_t namelen); int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param, - const char *name, size_t namelen); + const char *name, size_t namelen); void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, - unsigned int flags); + unsigned int flags); unsigned int X509_VERIFY_PARAM_get_hostflags(const X509_VERIFY_PARAM *param); char *X509_VERIFY_PARAM_get0_peername(const X509_VERIFY_PARAM *param); void X509_VERIFY_PARAM_move_peername(X509_VERIFY_PARAM *, X509_VERIFY_PARAM *); char *X509_VERIFY_PARAM_get0_email(X509_VERIFY_PARAM *param); int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, - const char *email, size_t emaillen); + const char *email, size_t emaillen); char *X509_VERIFY_PARAM_get1_ip_asc(X509_VERIFY_PARAM *param); int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, - const unsigned char *ip, size_t iplen); + const unsigned char *ip, size_t iplen); int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, - const char *ipasc); + const char *ipasc); int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param); int X509_VERIFY_PARAM_get_auth_level(const X509_VERIFY_PARAM *param); @@ -857,47 +859,46 @@ const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name); void X509_VERIFY_PARAM_table_cleanup(void); /* Non positive return values are errors */ -#define X509_PCY_TREE_FAILURE -2 /* Failure to satisfy explicit policy */ -#define X509_PCY_TREE_INVALID -1 /* Inconsistent or invalid extensions */ -#define X509_PCY_TREE_INTERNAL 0 /* Internal error, most likely malloc */ +#define X509_PCY_TREE_FAILURE -2 /* Failure to satisfy explicit policy */ +#define X509_PCY_TREE_INVALID -1 /* Inconsistent or invalid extensions */ +#define X509_PCY_TREE_INTERNAL 0 /* Internal error, most likely malloc */ /* * Positive return values form a bit mask, all but the first are internal to * the library and don't appear in results from X509_policy_check(). */ -#define X509_PCY_TREE_VALID 1 /* The policy tree is valid */ -#define X509_PCY_TREE_EMPTY 2 /* The policy tree is empty */ -#define X509_PCY_TREE_EXPLICIT 4 /* Explicit policy required */ +#define X509_PCY_TREE_VALID 1 /* The policy tree is valid */ +#define X509_PCY_TREE_EMPTY 2 /* The policy tree is empty */ +#define X509_PCY_TREE_EXPLICIT 4 /* Explicit policy required */ int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy, - STACK_OF(X509) *certs, - STACK_OF(ASN1_OBJECT) *policy_oids, unsigned int flags); + STACK_OF(X509) *certs, + STACK_OF(ASN1_OBJECT) *policy_oids, unsigned int flags); void X509_policy_tree_free(X509_POLICY_TREE *tree); int X509_policy_tree_level_count(const X509_POLICY_TREE *tree); X509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, - int i); + int i); STACK_OF(X509_POLICY_NODE) - *X509_policy_tree_get0_policies(const X509_POLICY_TREE *tree); +*X509_policy_tree_get0_policies(const X509_POLICY_TREE *tree); STACK_OF(X509_POLICY_NODE) - *X509_policy_tree_get0_user_policies(const X509_POLICY_TREE *tree); +*X509_policy_tree_get0_user_policies(const X509_POLICY_TREE *tree); int X509_policy_level_node_count(X509_POLICY_LEVEL *level); X509_POLICY_NODE *X509_policy_level_get0_node(const X509_POLICY_LEVEL *level, - int i); + int i); const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node); STACK_OF(POLICYQUALINFO) - *X509_policy_node_get0_qualifiers(const X509_POLICY_NODE *node); -const X509_POLICY_NODE - *X509_policy_node_get0_parent(const X509_POLICY_NODE *node); +*X509_policy_node_get0_qualifiers(const X509_POLICY_NODE *node); +const X509_POLICY_NODE *X509_policy_node_get0_parent(const X509_POLICY_NODE *node); -#ifdef __cplusplus +#ifdef __cplusplus } #endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509v3.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509v3.h index 718157ebfa..aebf751052 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509v3.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/x509v3.h @@ -10,24 +10,26 @@ * https://www.openssl.org/source/license.html */ +/* clang-format off */ +/* clang-format on */ #ifndef OPENSSL_X509V3_H -# define OPENSSL_X509V3_H -# pragma once +#define OPENSSL_X509V3_H +#pragma once -# include -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define HEADER_X509V3_H -# endif +#include +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define HEADER_X509V3_H +#endif -# include -# include -# include -# include -# ifndef OPENSSL_NO_STDIO -# include -# endif +#include +#include +#include +#include +#ifndef OPENSSL_NO_STDIO +#include +#endif #ifdef __cplusplus extern "C" { @@ -40,62 +42,61 @@ struct v3_ext_ctx; /* Useful typedefs */ typedef void *(*X509V3_EXT_NEW)(void); -typedef void (*X509V3_EXT_FREE) (void *); +typedef void (*X509V3_EXT_FREE)(void *); typedef void *(*X509V3_EXT_D2I)(void *, const unsigned char **, long); -typedef int (*X509V3_EXT_I2D) (const void *, unsigned char **); -typedef STACK_OF(CONF_VALUE) * - (*X509V3_EXT_I2V) (const struct v3_ext_method *method, void *ext, - STACK_OF(CONF_VALUE) *extlist); +typedef int (*X509V3_EXT_I2D)(const void *, unsigned char **); +typedef STACK_OF(CONF_VALUE) *(*X509V3_EXT_I2V)(const struct v3_ext_method *method, void *ext, + STACK_OF(CONF_VALUE) *extlist); typedef void *(*X509V3_EXT_V2I)(const struct v3_ext_method *method, - struct v3_ext_ctx *ctx, - STACK_OF(CONF_VALUE) *values); + struct v3_ext_ctx *ctx, + STACK_OF(CONF_VALUE) *values); typedef char *(*X509V3_EXT_I2S)(const struct v3_ext_method *method, - void *ext); + void *ext); typedef void *(*X509V3_EXT_S2I)(const struct v3_ext_method *method, - struct v3_ext_ctx *ctx, const char *str); -typedef int (*X509V3_EXT_I2R) (const struct v3_ext_method *method, void *ext, - BIO *out, int indent); + struct v3_ext_ctx *ctx, const char *str); +typedef int (*X509V3_EXT_I2R)(const struct v3_ext_method *method, void *ext, + BIO *out, int indent); typedef void *(*X509V3_EXT_R2I)(const struct v3_ext_method *method, - struct v3_ext_ctx *ctx, const char *str); + struct v3_ext_ctx *ctx, const char *str); /* V3 extension structure */ struct v3_ext_method { int ext_nid; int ext_flags; -/* If this is set the following four fields are ignored */ + /* If this is set the following four fields are ignored */ ASN1_ITEM_EXP *it; -/* Old style ASN1 calls */ + /* Old style ASN1 calls */ X509V3_EXT_NEW ext_new; X509V3_EXT_FREE ext_free; X509V3_EXT_D2I d2i; X509V3_EXT_I2D i2d; -/* The following pair is used for string extensions */ + /* The following pair is used for string extensions */ X509V3_EXT_I2S i2s; X509V3_EXT_S2I s2i; -/* The following pair is used for multi-valued extensions */ + /* The following pair is used for multi-valued extensions */ X509V3_EXT_I2V i2v; X509V3_EXT_V2I v2i; -/* The following are used for raw extensions */ + /* The following are used for raw extensions */ X509V3_EXT_I2R i2r; X509V3_EXT_R2I r2i; - void *usr_data; /* Any extension specific data */ + void *usr_data; /* Any extension specific data */ }; typedef struct X509V3_CONF_METHOD_st { - char *(*get_string) (void *db, const char *section, const char *value); - STACK_OF(CONF_VALUE) *(*get_section) (void *db, const char *section); - void (*free_string) (void *db, char *string); - void (*free_section) (void *db, STACK_OF(CONF_VALUE) *section); + char *(*get_string)(void *db, const char *section, const char *value); + STACK_OF(CONF_VALUE) *(*get_section)(void *db, const char *section); + void (*free_string)(void *db, char *string); + void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section); } X509V3_CONF_METHOD; /* Context specific info for producing X509 v3 extensions*/ struct v3_ext_ctx { -# define X509V3_CTX_TEST 0x1 -# ifndef OPENSSL_NO_DEPRECATED_3_0 -# define CTX_TEST X509V3_CTX_TEST -# endif -# define X509V3_CTX_REPLACE 0x2 +#define X509V3_CTX_TEST 0x1 +#ifndef OPENSSL_NO_DEPRECATED_3_0 +#define CTX_TEST X509V3_CTX_TEST +#endif +#define X509V3_CTX_REPLACE 0x2 int flags; X509 *issuer_cert; X509 *subject_cert; @@ -104,11 +105,12 @@ struct v3_ext_ctx { X509V3_CONF_METHOD *db_meth; void *db; EVP_PKEY *issuer_pkey; -/* Maybe more here */ + /* Maybe more here */ }; typedef struct v3_ext_method X509V3_EXT_METHOD; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509V3_EXT_METHOD, X509V3_EXT_METHOD, X509V3_EXT_METHOD) #define sk_X509V3_EXT_METHOD_num(sk) OPENSSL_sk_num(ossl_check_const_X509V3_EXT_METHOD_sk_type(sk)) #define sk_X509V3_EXT_METHOD_value(sk, idx) ((X509V3_EXT_METHOD *)OPENSSL_sk_value(ossl_check_const_X509V3_EXT_METHOD_sk_type(sk), (idx))) @@ -136,11 +138,12 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509V3_EXT_METHOD, X509V3_EXT_METHOD, X509V3_EXT_ME #define sk_X509V3_EXT_METHOD_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509V3_EXT_METHOD) *)OPENSSL_sk_deep_copy(ossl_check_const_X509V3_EXT_METHOD_sk_type(sk), ossl_check_X509V3_EXT_METHOD_copyfunc_type(copyfunc), ossl_check_X509V3_EXT_METHOD_freefunc_type(freefunc))) #define sk_X509V3_EXT_METHOD_set_cmp_func(sk, cmp) ((sk_X509V3_EXT_METHOD_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509V3_EXT_METHOD_sk_type(sk), ossl_check_X509V3_EXT_METHOD_compfunc_type(cmp))) +/* clang-format on */ /* ext_flags values */ -# define X509V3_EXT_DYNAMIC 0x1 -# define X509V3_EXT_CTX_DEP 0x2 -# define X509V3_EXT_MULTILINE 0x4 +#define X509V3_EXT_DYNAMIC 0x1 +#define X509V3_EXT_CTX_DEP 0x2 +#define X509V3_EXT_MULTILINE 0x4 typedef BIT_STRING_BITNAME ENUMERATED_NAMES; @@ -170,19 +173,19 @@ typedef struct EDIPartyName_st { } EDIPARTYNAME; typedef struct GENERAL_NAME_st { -# define GEN_OTHERNAME 0 -# define GEN_EMAIL 1 -# define GEN_DNS 2 -# define GEN_X400 3 -# define GEN_DIRNAME 4 -# define GEN_EDIPARTY 5 -# define GEN_URI 6 -# define GEN_IPADD 7 -# define GEN_RID 8 +#define GEN_OTHERNAME 0 +#define GEN_EMAIL 1 +#define GEN_DNS 2 +#define GEN_X400 3 +#define GEN_DIRNAME 4 +#define GEN_EDIPARTY 5 +#define GEN_URI 6 +#define GEN_IPADD 7 +#define GEN_RID 8 int type; union { char *ptr; - OTHERNAME *otherName; /* otherName */ + OTHERNAME *otherName; /* otherName */ ASN1_IA5STRING *rfc822Name; ASN1_IA5STRING *dNSName; ASN1_STRING *x400Address; @@ -192,12 +195,12 @@ typedef struct GENERAL_NAME_st { ASN1_OCTET_STRING *iPAddress; ASN1_OBJECT *registeredID; /* Old names */ - ASN1_OCTET_STRING *ip; /* iPAddress */ - X509_NAME *dirn; /* dirn */ - ASN1_IA5STRING *ia5; /* rfc822Name, dNSName, - * uniformResourceIdentifier */ - ASN1_OBJECT *rid; /* registeredID */ - ASN1_TYPE *other; /* x400Address */ + ASN1_OCTET_STRING *ip; /* iPAddress */ + X509_NAME *dirn; /* dirn */ + ASN1_IA5STRING *ia5; /* rfc822Name, dNSName, + * uniformResourceIdentifier */ + ASN1_OBJECT *rid; /* registeredID */ + ASN1_TYPE *other; /* x400Address */ } d; } GENERAL_NAME; @@ -208,6 +211,7 @@ typedef struct ACCESS_DESCRIPTION_st { int GENERAL_NAME_set1_X509_NAME(GENERAL_NAME **tgt, const X509_NAME *src); +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ACCESS_DESCRIPTION, ACCESS_DESCRIPTION, ACCESS_DESCRIPTION) #define sk_ACCESS_DESCRIPTION_num(sk) OPENSSL_sk_num(ossl_check_const_ACCESS_DESCRIPTION_sk_type(sk)) #define sk_ACCESS_DESCRIPTION_value(sk, idx) ((ACCESS_DESCRIPTION *)OPENSSL_sk_value(ossl_check_const_ACCESS_DESCRIPTION_sk_type(sk), (idx))) @@ -261,12 +265,14 @@ SKM_DEFINE_STACK_OF_INTERNAL(GENERAL_NAME, GENERAL_NAME, GENERAL_NAME) #define sk_GENERAL_NAME_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(GENERAL_NAME) *)OPENSSL_sk_deep_copy(ossl_check_const_GENERAL_NAME_sk_type(sk), ossl_check_GENERAL_NAME_copyfunc_type(copyfunc), ossl_check_GENERAL_NAME_freefunc_type(freefunc))) #define sk_GENERAL_NAME_set_cmp_func(sk, cmp) ((sk_GENERAL_NAME_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_GENERAL_NAME_sk_type(sk), ossl_check_GENERAL_NAME_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS; typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE; typedef STACK_OF(ASN1_INTEGER) TLS_FEATURE; typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(GENERAL_NAMES, GENERAL_NAMES, GENERAL_NAMES) #define sk_GENERAL_NAMES_num(sk) OPENSSL_sk_num(ossl_check_const_GENERAL_NAMES_sk_type(sk)) #define sk_GENERAL_NAMES_value(sk, idx) ((GENERAL_NAMES *)OPENSSL_sk_value(ossl_check_const_GENERAL_NAMES_sk_type(sk), (idx))) @@ -294,6 +300,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(GENERAL_NAMES, GENERAL_NAMES, GENERAL_NAMES) #define sk_GENERAL_NAMES_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(GENERAL_NAMES) *)OPENSSL_sk_deep_copy(ossl_check_const_GENERAL_NAMES_sk_type(sk), ossl_check_GENERAL_NAMES_copyfunc_type(copyfunc), ossl_check_GENERAL_NAMES_freefunc_type(freefunc))) #define sk_GENERAL_NAMES_set_cmp_func(sk, cmp) ((sk_GENERAL_NAMES_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_GENERAL_NAMES_sk_type(sk), ossl_check_GENERAL_NAMES_compfunc_type(cmp))) +/* clang-format on */ typedef struct DIST_POINT_NAME_st { int type; @@ -301,24 +308,24 @@ typedef struct DIST_POINT_NAME_st { GENERAL_NAMES *fullname; STACK_OF(X509_NAME_ENTRY) *relativename; } name; -/* If relativename then this contains the full distribution point name */ + /* If relativename then this contains the full distribution point name */ X509_NAME *dpname; } DIST_POINT_NAME; DECLARE_ASN1_DUP_FUNCTION(DIST_POINT_NAME) /* All existing reasons */ -# define CRLDP_ALL_REASONS 0x807f +#define CRLDP_ALL_REASONS 0x807f -# define CRL_REASON_NONE -1 -# define CRL_REASON_UNSPECIFIED 0 -# define CRL_REASON_KEY_COMPROMISE 1 -# define CRL_REASON_CA_COMPROMISE 2 -# define CRL_REASON_AFFILIATION_CHANGED 3 -# define CRL_REASON_SUPERSEDED 4 -# define CRL_REASON_CESSATION_OF_OPERATION 5 -# define CRL_REASON_CERTIFICATE_HOLD 6 -# define CRL_REASON_REMOVE_FROM_CRL 8 -# define CRL_REASON_PRIVILEGE_WITHDRAWN 9 -# define CRL_REASON_AA_COMPROMISE 10 +#define CRL_REASON_NONE -1 +#define CRL_REASON_UNSPECIFIED 0 +#define CRL_REASON_KEY_COMPROMISE 1 +#define CRL_REASON_CA_COMPROMISE 2 +#define CRL_REASON_AFFILIATION_CHANGED 3 +#define CRL_REASON_SUPERSEDED 4 +#define CRL_REASON_CESSATION_OF_OPERATION 5 +#define CRL_REASON_CERTIFICATE_HOLD 6 +#define CRL_REASON_REMOVE_FROM_CRL 8 +#define CRL_REASON_PRIVILEGE_WITHDRAWN 9 +#define CRL_REASON_AA_COMPROMISE 10 struct DIST_POINT_st { DIST_POINT_NAME *distpoint; @@ -327,6 +334,7 @@ struct DIST_POINT_st { int dp_reasons; }; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(DIST_POINT, DIST_POINT, DIST_POINT) #define sk_DIST_POINT_num(sk) OPENSSL_sk_num(ossl_check_const_DIST_POINT_sk_type(sk)) #define sk_DIST_POINT_value(sk, idx) ((DIST_POINT *)OPENSSL_sk_value(ossl_check_const_DIST_POINT_sk_type(sk), (idx))) @@ -354,6 +362,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(DIST_POINT, DIST_POINT, DIST_POINT) #define sk_DIST_POINT_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(DIST_POINT) *)OPENSSL_sk_deep_copy(ossl_check_const_DIST_POINT_sk_type(sk), ossl_check_DIST_POINT_copyfunc_type(copyfunc), ossl_check_DIST_POINT_freefunc_type(freefunc))) #define sk_DIST_POINT_set_cmp_func(sk, cmp) ((sk_DIST_POINT_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_DIST_POINT_sk_type(sk), ossl_check_DIST_POINT_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS; @@ -370,6 +379,7 @@ typedef struct SXNET_ID_st { ASN1_OCTET_STRING *user; } SXNETID; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(SXNETID, SXNETID, SXNETID) #define sk_SXNETID_num(sk) OPENSSL_sk_num(ossl_check_const_SXNETID_sk_type(sk)) #define sk_SXNETID_value(sk, idx) ((SXNETID *)OPENSSL_sk_value(ossl_check_const_SXNETID_sk_type(sk), (idx))) @@ -397,7 +407,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(SXNETID, SXNETID, SXNETID) #define sk_SXNETID_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SXNETID) *)OPENSSL_sk_deep_copy(ossl_check_const_SXNETID_sk_type(sk), ossl_check_SXNETID_copyfunc_type(copyfunc), ossl_check_SXNETID_freefunc_type(freefunc))) #define sk_SXNETID_set_cmp_func(sk, cmp) ((sk_SXNETID_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SXNETID_sk_type(sk), ossl_check_SXNETID_compfunc_type(cmp))) - +/* clang-format on */ typedef struct SXNET_st { ASN1_INTEGER *version; @@ -430,6 +440,7 @@ typedef struct POLICYQUALINFO_st { } d; } POLICYQUALINFO; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(POLICYQUALINFO, POLICYQUALINFO, POLICYQUALINFO) #define sk_POLICYQUALINFO_num(sk) OPENSSL_sk_num(ossl_check_const_POLICYQUALINFO_sk_type(sk)) #define sk_POLICYQUALINFO_value(sk, idx) ((POLICYQUALINFO *)OPENSSL_sk_value(ossl_check_const_POLICYQUALINFO_sk_type(sk), (idx))) @@ -457,13 +468,14 @@ SKM_DEFINE_STACK_OF_INTERNAL(POLICYQUALINFO, POLICYQUALINFO, POLICYQUALINFO) #define sk_POLICYQUALINFO_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(POLICYQUALINFO) *)OPENSSL_sk_deep_copy(ossl_check_const_POLICYQUALINFO_sk_type(sk), ossl_check_POLICYQUALINFO_copyfunc_type(copyfunc), ossl_check_POLICYQUALINFO_freefunc_type(freefunc))) #define sk_POLICYQUALINFO_set_cmp_func(sk, cmp) ((sk_POLICYQUALINFO_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_POLICYQUALINFO_sk_type(sk), ossl_check_POLICYQUALINFO_compfunc_type(cmp))) - +/* clang-format on */ typedef struct POLICYINFO_st { ASN1_OBJECT *policyid; STACK_OF(POLICYQUALINFO) *qualifiers; } POLICYINFO; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(POLICYINFO, POLICYINFO, POLICYINFO) #define sk_POLICYINFO_num(sk) OPENSSL_sk_num(ossl_check_const_POLICYINFO_sk_type(sk)) #define sk_POLICYINFO_value(sk, idx) ((POLICYINFO *)OPENSSL_sk_value(ossl_check_const_POLICYINFO_sk_type(sk), (idx))) @@ -491,6 +503,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(POLICYINFO, POLICYINFO, POLICYINFO) #define sk_POLICYINFO_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(POLICYINFO) *)OPENSSL_sk_deep_copy(ossl_check_const_POLICYINFO_sk_type(sk), ossl_check_POLICYINFO_copyfunc_type(copyfunc), ossl_check_POLICYINFO_freefunc_type(freefunc))) #define sk_POLICYINFO_set_cmp_func(sk, cmp) ((sk_POLICYINFO_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_POLICYINFO_sk_type(sk), ossl_check_POLICYINFO_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES; @@ -499,6 +512,7 @@ typedef struct POLICY_MAPPING_st { ASN1_OBJECT *subjectDomainPolicy; } POLICY_MAPPING; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(POLICY_MAPPING, POLICY_MAPPING, POLICY_MAPPING) #define sk_POLICY_MAPPING_num(sk) OPENSSL_sk_num(ossl_check_const_POLICY_MAPPING_sk_type(sk)) #define sk_POLICY_MAPPING_value(sk, idx) ((POLICY_MAPPING *)OPENSSL_sk_value(ossl_check_const_POLICY_MAPPING_sk_type(sk), (idx))) @@ -526,6 +540,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(POLICY_MAPPING, POLICY_MAPPING, POLICY_MAPPING) #define sk_POLICY_MAPPING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(POLICY_MAPPING) *)OPENSSL_sk_deep_copy(ossl_check_const_POLICY_MAPPING_sk_type(sk), ossl_check_POLICY_MAPPING_copyfunc_type(copyfunc), ossl_check_POLICY_MAPPING_freefunc_type(freefunc))) #define sk_POLICY_MAPPING_set_cmp_func(sk, cmp) ((sk_POLICY_MAPPING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_POLICY_MAPPING_sk_type(sk), ossl_check_POLICY_MAPPING_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS; @@ -535,6 +550,7 @@ typedef struct GENERAL_SUBTREE_st { ASN1_INTEGER *maximum; } GENERAL_SUBTREE; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(GENERAL_SUBTREE, GENERAL_SUBTREE, GENERAL_SUBTREE) #define sk_GENERAL_SUBTREE_num(sk) OPENSSL_sk_num(ossl_check_const_GENERAL_SUBTREE_sk_type(sk)) #define sk_GENERAL_SUBTREE_value(sk, idx) ((GENERAL_SUBTREE *)OPENSSL_sk_value(ossl_check_const_GENERAL_SUBTREE_sk_type(sk), (idx))) @@ -562,6 +578,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(GENERAL_SUBTREE, GENERAL_SUBTREE, GENERAL_SUBTREE) #define sk_GENERAL_SUBTREE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(GENERAL_SUBTREE) *)OPENSSL_sk_deep_copy(ossl_check_const_GENERAL_SUBTREE_sk_type(sk), ossl_check_GENERAL_SUBTREE_copyfunc_type(copyfunc), ossl_check_GENERAL_SUBTREE_freefunc_type(freefunc))) #define sk_GENERAL_SUBTREE_set_cmp_func(sk, cmp) ((sk_GENERAL_SUBTREE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_GENERAL_SUBTREE_sk_type(sk), ossl_check_GENERAL_SUBTREE_compfunc_type(cmp))) +/* clang-format on */ struct NAME_CONSTRAINTS_st { STACK_OF(GENERAL_SUBTREE) *permittedSubtrees; @@ -598,121 +615,124 @@ struct ISSUING_DIST_POINT_st { /* Values in idp_flags field */ /* IDP present */ -# define IDP_PRESENT 0x1 +#define IDP_PRESENT 0x1 /* IDP values inconsistent */ -# define IDP_INVALID 0x2 +#define IDP_INVALID 0x2 /* onlyuser true */ -# define IDP_ONLYUSER 0x4 +#define IDP_ONLYUSER 0x4 /* onlyCA true */ -# define IDP_ONLYCA 0x8 +#define IDP_ONLYCA 0x8 /* onlyattr true */ -# define IDP_ONLYATTR 0x10 +#define IDP_ONLYATTR 0x10 /* indirectCRL true */ -# define IDP_INDIRECT 0x20 +#define IDP_INDIRECT 0x20 /* onlysomereasons present */ -# define IDP_REASONS 0x40 +#define IDP_REASONS 0x40 -# define X509V3_conf_err(val) ERR_add_error_data(6, \ - "section:", (val)->section, \ - ",name:", (val)->name, ",value:", (val)->value) +#define X509V3_conf_err(val) ERR_add_error_data(6, \ + "section:", (val)->section, \ + ",name:", (val)->name, ",value:", (val)->value) -# define X509V3_set_ctx_test(ctx) \ +#define X509V3_set_ctx_test(ctx) \ X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, X509V3_CTX_TEST) -# define X509V3_set_ctx_nodb(ctx) (ctx)->db = NULL; +#define X509V3_set_ctx_nodb(ctx) (ctx)->db = NULL; -# define EXT_BITSTRING(nid, table) { nid, 0, ASN1_ITEM_ref(ASN1_BIT_STRING), \ - 0,0,0,0, \ - 0,0, \ - (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \ - (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \ - NULL, NULL, \ - table} +#define EXT_BITSTRING(nid, table) { nid, 0, ASN1_ITEM_ref(ASN1_BIT_STRING), \ + 0, 0, 0, 0, \ + 0, 0, \ + (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \ + (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \ + NULL, NULL, \ + table } -# define EXT_IA5STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), \ - 0,0,0,0, \ - (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \ - (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \ - 0,0,0,0, \ - NULL} +#define EXT_IA5STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), \ + 0, 0, 0, 0, \ + (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \ + (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \ + 0, 0, 0, 0, \ + NULL } #define EXT_UTF8STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_UTF8STRING), \ - 0,0,0,0, \ - (X509V3_EXT_I2S)i2s_ASN1_UTF8STRING, \ - (X509V3_EXT_S2I)s2i_ASN1_UTF8STRING, \ - 0,0,0,0, \ - NULL} + 0, 0, 0, 0, \ + (X509V3_EXT_I2S)i2s_ASN1_UTF8STRING, \ + (X509V3_EXT_S2I)s2i_ASN1_UTF8STRING, \ + 0, 0, 0, 0, \ + NULL } +/* clang-format off */ # define EXT_END { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +/* clang-format on */ /* X509_PURPOSE stuff */ -# define EXFLAG_BCONS 0x1 -# define EXFLAG_KUSAGE 0x2 -# define EXFLAG_XKUSAGE 0x4 -# define EXFLAG_NSCERT 0x8 +#define EXFLAG_BCONS 0x1 +#define EXFLAG_KUSAGE 0x2 +#define EXFLAG_XKUSAGE 0x4 +#define EXFLAG_NSCERT 0x8 -# define EXFLAG_CA 0x10 -# define EXFLAG_SI 0x20 /* self-issued, maybe not self-signed */ -# define EXFLAG_V1 0x40 -# define EXFLAG_INVALID 0x80 +#define EXFLAG_CA 0x10 +#define EXFLAG_SI 0x20 /* self-issued, maybe not self-signed */ +#define EXFLAG_V1 0x40 +#define EXFLAG_INVALID 0x80 /* EXFLAG_SET is set to indicate that some values have been precomputed */ -# define EXFLAG_SET 0x100 -# define EXFLAG_CRITICAL 0x200 -# define EXFLAG_PROXY 0x400 +#define EXFLAG_SET 0x100 +#define EXFLAG_CRITICAL 0x200 +#define EXFLAG_PROXY 0x400 -# define EXFLAG_INVALID_POLICY 0x800 -# define EXFLAG_FRESHEST 0x1000 -# define EXFLAG_SS 0x2000 /* cert is apparently self-signed */ +#define EXFLAG_INVALID_POLICY 0x800 +#define EXFLAG_FRESHEST 0x1000 +#define EXFLAG_SS 0x2000 /* cert is apparently self-signed */ -# define EXFLAG_BCONS_CRITICAL 0x10000 -# define EXFLAG_AKID_CRITICAL 0x20000 -# define EXFLAG_SKID_CRITICAL 0x40000 -# define EXFLAG_SAN_CRITICAL 0x80000 -# define EXFLAG_NO_FINGERPRINT 0x100000 +#define EXFLAG_BCONS_CRITICAL 0x10000 +#define EXFLAG_AKID_CRITICAL 0x20000 +#define EXFLAG_SKID_CRITICAL 0x40000 +#define EXFLAG_SAN_CRITICAL 0x80000 +#define EXFLAG_NO_FINGERPRINT 0x100000 /* https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.3 */ -# define KU_DIGITAL_SIGNATURE X509v3_KU_DIGITAL_SIGNATURE -# define KU_NON_REPUDIATION X509v3_KU_NON_REPUDIATION -# define KU_KEY_ENCIPHERMENT X509v3_KU_KEY_ENCIPHERMENT -# define KU_DATA_ENCIPHERMENT X509v3_KU_DATA_ENCIPHERMENT -# define KU_KEY_AGREEMENT X509v3_KU_KEY_AGREEMENT -# define KU_KEY_CERT_SIGN X509v3_KU_KEY_CERT_SIGN -# define KU_CRL_SIGN X509v3_KU_CRL_SIGN -# define KU_ENCIPHER_ONLY X509v3_KU_ENCIPHER_ONLY -# define KU_DECIPHER_ONLY X509v3_KU_DECIPHER_ONLY +#define KU_DIGITAL_SIGNATURE X509v3_KU_DIGITAL_SIGNATURE +#define KU_NON_REPUDIATION X509v3_KU_NON_REPUDIATION +#define KU_KEY_ENCIPHERMENT X509v3_KU_KEY_ENCIPHERMENT +#define KU_DATA_ENCIPHERMENT X509v3_KU_DATA_ENCIPHERMENT +#define KU_KEY_AGREEMENT X509v3_KU_KEY_AGREEMENT +#define KU_KEY_CERT_SIGN X509v3_KU_KEY_CERT_SIGN +#define KU_CRL_SIGN X509v3_KU_CRL_SIGN +#define KU_ENCIPHER_ONLY X509v3_KU_ENCIPHER_ONLY +#define KU_DECIPHER_ONLY X509v3_KU_DECIPHER_ONLY -# define NS_SSL_CLIENT 0x80 -# define NS_SSL_SERVER 0x40 -# define NS_SMIME 0x20 -# define NS_OBJSIGN 0x10 -# define NS_SSL_CA 0x04 -# define NS_SMIME_CA 0x02 -# define NS_OBJSIGN_CA 0x01 -# define NS_ANY_CA (NS_SSL_CA|NS_SMIME_CA|NS_OBJSIGN_CA) +#define NS_SSL_CLIENT 0x80 +#define NS_SSL_SERVER 0x40 +#define NS_SMIME 0x20 +#define NS_OBJSIGN 0x10 +#define NS_SSL_CA 0x04 +#define NS_SMIME_CA 0x02 +#define NS_OBJSIGN_CA 0x01 +#define NS_ANY_CA (NS_SSL_CA | NS_SMIME_CA | NS_OBJSIGN_CA) -# define XKU_SSL_SERVER 0x1 -# define XKU_SSL_CLIENT 0x2 -# define XKU_SMIME 0x4 -# define XKU_CODE_SIGN 0x8 -# define XKU_SGC 0x10 /* Netscape or MS Server-Gated Crypto */ -# define XKU_OCSP_SIGN 0x20 -# define XKU_TIMESTAMP 0x40 -# define XKU_DVCS 0x80 -# define XKU_ANYEKU 0x100 +#define XKU_SSL_SERVER 0x1 +#define XKU_SSL_CLIENT 0x2 +#define XKU_SMIME 0x4 +#define XKU_CODE_SIGN 0x8 +#define XKU_SGC 0x10 /* Netscape or MS Server-Gated Crypto */ +#define XKU_OCSP_SIGN 0x20 +#define XKU_TIMESTAMP 0x40 +#define XKU_DVCS 0x80 +#define XKU_ANYEKU 0x100 -# define X509_PURPOSE_DYNAMIC 0x1 -# define X509_PURPOSE_DYNAMIC_NAME 0x2 +#define X509_PURPOSE_DYNAMIC 0x1 +#define X509_PURPOSE_DYNAMIC_NAME 0x2 typedef struct x509_purpose_st { int purpose; - int trust; /* Default trust ID */ + int trust; /* Default trust ID */ int flags; - int (*check_purpose) (const struct x509_purpose_st *, const X509 *, int); + int (*check_purpose)(const struct x509_purpose_st *, const X509 *, int); char *name; char *sname; void *usr_data; } X509_PURPOSE; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509_PURPOSE, X509_PURPOSE, X509_PURPOSE) #define sk_X509_PURPOSE_num(sk) OPENSSL_sk_num(ossl_check_const_X509_PURPOSE_sk_type(sk)) #define sk_X509_PURPOSE_value(sk, idx) ((X509_PURPOSE *)OPENSSL_sk_value(ossl_check_const_X509_PURPOSE_sk_type(sk), (idx))) @@ -740,44 +760,45 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_PURPOSE, X509_PURPOSE, X509_PURPOSE) #define sk_X509_PURPOSE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_PURPOSE) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_PURPOSE_sk_type(sk), ossl_check_X509_PURPOSE_copyfunc_type(copyfunc), ossl_check_X509_PURPOSE_freefunc_type(freefunc))) #define sk_X509_PURPOSE_set_cmp_func(sk, cmp) ((sk_X509_PURPOSE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_PURPOSE_sk_type(sk), ossl_check_X509_PURPOSE_compfunc_type(cmp))) +/* clang-format on */ -# define X509_PURPOSE_DEFAULT_ANY 0 -# define X509_PURPOSE_SSL_CLIENT 1 -# define X509_PURPOSE_SSL_SERVER 2 -# define X509_PURPOSE_NS_SSL_SERVER 3 -# define X509_PURPOSE_SMIME_SIGN 4 -# define X509_PURPOSE_SMIME_ENCRYPT 5 -# define X509_PURPOSE_CRL_SIGN 6 -# define X509_PURPOSE_ANY 7 -# define X509_PURPOSE_OCSP_HELPER 8 -# define X509_PURPOSE_TIMESTAMP_SIGN 9 -# define X509_PURPOSE_CODE_SIGN 10 +#define X509_PURPOSE_DEFAULT_ANY 0 +#define X509_PURPOSE_SSL_CLIENT 1 +#define X509_PURPOSE_SSL_SERVER 2 +#define X509_PURPOSE_NS_SSL_SERVER 3 +#define X509_PURPOSE_SMIME_SIGN 4 +#define X509_PURPOSE_SMIME_ENCRYPT 5 +#define X509_PURPOSE_CRL_SIGN 6 +#define X509_PURPOSE_ANY 7 +#define X509_PURPOSE_OCSP_HELPER 8 +#define X509_PURPOSE_TIMESTAMP_SIGN 9 +#define X509_PURPOSE_CODE_SIGN 10 -# define X509_PURPOSE_MIN 1 -# define X509_PURPOSE_MAX 10 +#define X509_PURPOSE_MIN 1 +#define X509_PURPOSE_MAX 10 /* Flags for X509V3_EXT_print() */ -# define X509V3_EXT_UNKNOWN_MASK (0xfL << 16) +#define X509V3_EXT_UNKNOWN_MASK (0xfL << 16) /* Return error for unknown extensions */ -# define X509V3_EXT_DEFAULT 0 +#define X509V3_EXT_DEFAULT 0 /* Print error for unknown extensions */ -# define X509V3_EXT_ERROR_UNKNOWN (1L << 16) +#define X509V3_EXT_ERROR_UNKNOWN (1L << 16) /* ASN1 parse unknown extensions */ -# define X509V3_EXT_PARSE_UNKNOWN (2L << 16) +#define X509V3_EXT_PARSE_UNKNOWN (2L << 16) /* BIO_dump unknown extensions */ -# define X509V3_EXT_DUMP_UNKNOWN (3L << 16) +#define X509V3_EXT_DUMP_UNKNOWN (3L << 16) /* Flags for X509V3_add1_i2d */ -# define X509V3_ADD_OP_MASK 0xfL -# define X509V3_ADD_DEFAULT 0L -# define X509V3_ADD_APPEND 1L -# define X509V3_ADD_REPLACE 2L -# define X509V3_ADD_REPLACE_EXISTING 3L -# define X509V3_ADD_KEEP_EXISTING 4L -# define X509V3_ADD_DELETE 5L -# define X509V3_ADD_SILENT 0x10 +#define X509V3_ADD_OP_MASK 0xfL +#define X509V3_ADD_DEFAULT 0L +#define X509V3_ADD_APPEND 1L +#define X509V3_ADD_REPLACE 2L +#define X509V3_ADD_REPLACE_EXISTING 3L +#define X509V3_ADD_KEEP_EXISTING 4L +#define X509V3_ADD_DELETE 5L +#define X509V3_ADD_SILENT 0x10 DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS) DECLARE_ASN1_FUNCTIONS(OSSL_BASIC_ATTR_CONSTRAINTS) @@ -789,9 +810,9 @@ DECLARE_ASN1_FUNCTIONS(ISSUER_SIGN_TOOL) int SXNET_add_id_asc(SXNET **psx, const char *zone, const char *user, int userlen); int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, const char *user, - int userlen); + int userlen); int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, const char *user, - int userlen); + int userlen); ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, const char *zone); ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone); @@ -806,30 +827,30 @@ DECLARE_ASN1_DUP_FUNCTION(GENERAL_NAME) int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b); ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, - X509V3_CTX *ctx, - STACK_OF(CONF_VALUE) *nval); + X509V3_CTX *ctx, + STACK_OF(CONF_VALUE) *nval); STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, - ASN1_BIT_STRING *bits, - STACK_OF(CONF_VALUE) *extlist); + ASN1_BIT_STRING *bits, + STACK_OF(CONF_VALUE) *extlist); char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5); ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, - X509V3_CTX *ctx, const char *str); + X509V3_CTX *ctx, const char *str); char *i2s_ASN1_UTF8STRING(X509V3_EXT_METHOD *method, ASN1_UTF8STRING *utf8); ASN1_UTF8STRING *s2i_ASN1_UTF8STRING(X509V3_EXT_METHOD *method, - X509V3_CTX *ctx, const char *str); + X509V3_CTX *ctx, const char *str); STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, - GENERAL_NAME *gen, - STACK_OF(CONF_VALUE) *ret); + GENERAL_NAME *gen, + STACK_OF(CONF_VALUE) *ret); int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen); DECLARE_ASN1_FUNCTIONS(GENERAL_NAMES) STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, - GENERAL_NAMES *gen, - STACK_OF(CONF_VALUE) *extlist); + GENERAL_NAMES *gen, + STACK_OF(CONF_VALUE) *extlist); GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, - X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); DECLARE_ASN1_FUNCTIONS(OTHERNAME) DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME) @@ -837,14 +858,14 @@ int OTHERNAME_cmp(OTHERNAME *a, OTHERNAME *b); void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value); void *GENERAL_NAME_get0_value(const GENERAL_NAME *a, int *ptype); int GENERAL_NAME_set0_othername(GENERAL_NAME *gen, - ASN1_OBJECT *oid, ASN1_TYPE *value); + ASN1_OBJECT *oid, ASN1_TYPE *value); int GENERAL_NAME_get0_otherName(const GENERAL_NAME *gen, - ASN1_OBJECT **poid, ASN1_TYPE **pvalue); + ASN1_OBJECT **poid, ASN1_TYPE **pvalue); char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, - const ASN1_OCTET_STRING *ia5); + const ASN1_OCTET_STRING *ia5); ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, - X509V3_CTX *ctx, const char *str); + X509V3_CTX *ctx, const char *str); DECLARE_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE) int i2a_ACCESS_DESCRIPTION(BIO *bp, const ACCESS_DESCRIPTION *a); @@ -884,75 +905,75 @@ DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS) DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS) GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out, - const X509V3_EXT_METHOD *method, - X509V3_CTX *ctx, int gen_type, - const char *value, int is_nc); + const X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, int gen_type, + const char *value, int is_nc); -# ifdef OPENSSL_CONF_H +#ifdef OPENSSL_CONF_H GENERAL_NAME *v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method, - X509V3_CTX *ctx, CONF_VALUE *cnf); + X509V3_CTX *ctx, CONF_VALUE *cnf); GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out, - const X509V3_EXT_METHOD *method, - X509V3_CTX *ctx, CONF_VALUE *cnf, - int is_nc); + const X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, CONF_VALUE *cnf, + int is_nc); void X509V3_conf_free(CONF_VALUE *val); X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, - const char *value); + const char *value); X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, const char *name, - const char *value); + const char *value); int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, const char *section, - STACK_OF(X509_EXTENSION) **sk); + STACK_OF(X509_EXTENSION) **sk); int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, - X509 *cert); + X509 *cert); int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, - X509_REQ *req); + X509_REQ *req); int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, - X509_CRL *crl); + X509_CRL *crl); X509_EXTENSION *X509V3_EXT_conf_nid(LHASH_OF(CONF_VALUE) *conf, - X509V3_CTX *ctx, int ext_nid, - const char *value); + X509V3_CTX *ctx, int ext_nid, + const char *value); X509_EXTENSION *X509V3_EXT_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, - const char *name, const char *value); + const char *name, const char *value); int X509V3_EXT_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, - const char *section, X509 *cert); + const char *section, X509 *cert); int X509V3_EXT_REQ_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, - const char *section, X509_REQ *req); + const char *section, X509_REQ *req); int X509V3_EXT_CRL_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, - const char *section, X509_CRL *crl); + const char *section, X509_CRL *crl); int X509V3_add_value_bool_nf(const char *name, int asn1_bool, - STACK_OF(CONF_VALUE) **extlist); + STACK_OF(CONF_VALUE) **extlist); int X509V3_get_value_bool(const CONF_VALUE *value, int *asn1_bool); int X509V3_get_value_int(const CONF_VALUE *value, ASN1_INTEGER **aint); void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf); void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH_OF(CONF_VALUE) *lhash); -# endif +#endif char *X509V3_get_string(X509V3_CTX *ctx, const char *name, const char *section); STACK_OF(CONF_VALUE) *X509V3_get_section(X509V3_CTX *ctx, const char *section); void X509V3_string_free(X509V3_CTX *ctx, char *str); void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section); void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject, - X509_REQ *req, X509_CRL *crl, int flags); + X509_REQ *req, X509_CRL *crl, int flags); /* For API backward compatibility, this is separate from X509V3_set_ctx(): */ int X509V3_set_issuer_pkey(X509V3_CTX *ctx, EVP_PKEY *pkey); int X509V3_add_value(const char *name, const char *value, - STACK_OF(CONF_VALUE) **extlist); + STACK_OF(CONF_VALUE) **extlist); int X509V3_add_value_uchar(const char *name, const unsigned char *value, - STACK_OF(CONF_VALUE) **extlist); + STACK_OF(CONF_VALUE) **extlist); int X509V3_add_value_bool(const char *name, int asn1_bool, - STACK_OF(CONF_VALUE) **extlist); + STACK_OF(CONF_VALUE) **extlist); int X509V3_add_value_int(const char *name, const ASN1_INTEGER *aint, - STACK_OF(CONF_VALUE) **extlist); + STACK_OF(CONF_VALUE) **extlist); char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, const ASN1_INTEGER *aint); ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, const char *value); char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, const ASN1_ENUMERATED *aint); char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, - const ASN1_ENUMERATED *aint); + const ASN1_ENUMERATED *aint); int X509V3_EXT_add(X509V3_EXT_METHOD *ext); int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist); int X509V3_EXT_add_alias(int nid_to, int nid_from); @@ -964,28 +985,28 @@ int X509V3_add_standard_extensions(void); STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line); void *X509V3_EXT_d2i(X509_EXTENSION *ext); void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *x, int nid, int *crit, - int *idx); + int *idx); X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc); int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, - int crit, unsigned long flags); + int crit, unsigned long flags); #ifndef OPENSSL_NO_DEPRECATED_1_1_0 /* The new declarations are in crypto.h, but the old ones were here. */ -# define hex_to_string OPENSSL_buf2hexstr -# define string_to_hex OPENSSL_hexstr2buf +#define hex_to_string OPENSSL_buf2hexstr +#define string_to_hex OPENSSL_hexstr2buf #endif void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, - int ml); + int ml); int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, - int indent); + int indent); #ifndef OPENSSL_NO_STDIO int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); #endif int X509V3_extensions_print(BIO *out, const char *title, - const STACK_OF(X509_EXTENSION) *exts, - unsigned long flag, int indent); + const STACK_OF(X509_EXTENSION) *exts, + unsigned long flag, int indent); int X509_check_ca(X509 *x); int X509_check_purpose(X509 *x, int id, int ca); @@ -1009,8 +1030,8 @@ int X509_PURPOSE_get_unused_id(OSSL_LIB_CTX *libctx); int X509_PURPOSE_get_by_sname(const char *sname); int X509_PURPOSE_get_by_id(int id); int X509_PURPOSE_add(int id, int trust, int flags, - int (*ck) (const X509_PURPOSE *, const X509 *, int), - const char *name, const char *sname, void *arg); + int (*ck)(const X509_PURPOSE *, const X509 *, int), + const char *name, const char *sname, void *arg); void X509_PURPOSE_cleanup(void); X509_PURPOSE *X509_PURPOSE_get0(int idx); @@ -1030,38 +1051,39 @@ STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(X509 *x); /* * Always check subject name for host match even if subject alt names present */ -# define X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT 0x1 +#define X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT 0x1 /* Disable wildcard matching for dnsName fields and common name. */ -# define X509_CHECK_FLAG_NO_WILDCARDS 0x2 +#define X509_CHECK_FLAG_NO_WILDCARDS 0x2 /* Wildcards must not match a partial label. */ -# define X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS 0x4 +#define X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS 0x4 /* Allow (non-partial) wildcards to match multiple labels. */ -# define X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS 0x8 +#define X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS 0x8 /* Constraint verifier subdomain patterns to match a single labels. */ -# define X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS 0x10 +#define X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS 0x10 /* Never check the subject CN */ -# define X509_CHECK_FLAG_NEVER_CHECK_SUBJECT 0x20 +#define X509_CHECK_FLAG_NEVER_CHECK_SUBJECT 0x20 /* * Match reference identifiers starting with "." to any sub-domain. * This is a non-public flag, turned on implicitly when the subject * reference identity is a DNS name. */ -# define _X509_CHECK_FLAG_DOT_SUBDOMAINS 0x8000 +#define _X509_CHECK_FLAG_DOT_SUBDOMAINS 0x8000 int X509_check_host(X509 *x, const char *chk, size_t chklen, - unsigned int flags, char **peername); + unsigned int flags, char **peername); int X509_check_email(X509 *x, const char *chk, size_t chklen, - unsigned int flags); + unsigned int flags); int X509_check_ip(X509 *x, const unsigned char *chk, size_t chklen, - unsigned int flags); + unsigned int flags); int X509_check_ip_asc(X509 *x, const char *ipasc, unsigned int flags); ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc); ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc); int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE) *dn_sk, - unsigned long chtype); + unsigned long chtype); void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent); +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(X509_POLICY_NODE, X509_POLICY_NODE, X509_POLICY_NODE) #define sk_X509_POLICY_NODE_num(sk) OPENSSL_sk_num(ossl_check_const_X509_POLICY_NODE_sk_type(sk)) #define sk_X509_POLICY_NODE_value(sk, idx) ((X509_POLICY_NODE *)OPENSSL_sk_value(ossl_check_const_X509_POLICY_NODE_sk_type(sk), (idx))) @@ -1089,15 +1111,15 @@ SKM_DEFINE_STACK_OF_INTERNAL(X509_POLICY_NODE, X509_POLICY_NODE, X509_POLICY_NOD #define sk_X509_POLICY_NODE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_POLICY_NODE) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_POLICY_NODE_sk_type(sk), ossl_check_X509_POLICY_NODE_copyfunc_type(copyfunc), ossl_check_X509_POLICY_NODE_freefunc_type(freefunc))) #define sk_X509_POLICY_NODE_set_cmp_func(sk, cmp) ((sk_X509_POLICY_NODE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_POLICY_NODE_sk_type(sk), ossl_check_X509_POLICY_NODE_compfunc_type(cmp))) - +/* clang-format on */ #ifndef OPENSSL_NO_RFC3779 typedef struct ASRange_st { ASN1_INTEGER *min, *max; } ASRange; -# define ASIdOrRange_id 0 -# define ASIdOrRange_range 1 +#define ASIdOrRange_id 0 +#define ASIdOrRange_range 1 typedef struct ASIdOrRange_st { int type; @@ -1107,6 +1129,7 @@ typedef struct ASIdOrRange_st { } u; } ASIdOrRange; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ASIdOrRange, ASIdOrRange, ASIdOrRange) #define sk_ASIdOrRange_num(sk) OPENSSL_sk_num(ossl_check_const_ASIdOrRange_sk_type(sk)) #define sk_ASIdOrRange_value(sk, idx) ((ASIdOrRange *)OPENSSL_sk_value(ossl_check_const_ASIdOrRange_sk_type(sk), (idx))) @@ -1134,11 +1157,12 @@ SKM_DEFINE_STACK_OF_INTERNAL(ASIdOrRange, ASIdOrRange, ASIdOrRange) #define sk_ASIdOrRange_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASIdOrRange) *)OPENSSL_sk_deep_copy(ossl_check_const_ASIdOrRange_sk_type(sk), ossl_check_ASIdOrRange_copyfunc_type(copyfunc), ossl_check_ASIdOrRange_freefunc_type(freefunc))) #define sk_ASIdOrRange_set_cmp_func(sk, cmp) ((sk_ASIdOrRange_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASIdOrRange_sk_type(sk), ossl_check_ASIdOrRange_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(ASIdOrRange) ASIdOrRanges; -# define ASIdentifierChoice_inherit 0 -# define ASIdentifierChoice_asIdsOrRanges 1 +#define ASIdentifierChoice_inherit 0 +#define ASIdentifierChoice_asIdsOrRanges 1 typedef struct ASIdentifierChoice_st { int type; @@ -1161,8 +1185,8 @@ typedef struct IPAddressRange_st { ASN1_BIT_STRING *min, *max; } IPAddressRange; -# define IPAddressOrRange_addressPrefix 0 -# define IPAddressOrRange_addressRange 1 +#define IPAddressOrRange_addressPrefix 0 +#define IPAddressOrRange_addressRange 1 typedef struct IPAddressOrRange_st { int type; @@ -1172,6 +1196,7 @@ typedef struct IPAddressOrRange_st { } u; } IPAddressOrRange; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(IPAddressOrRange, IPAddressOrRange, IPAddressOrRange) #define sk_IPAddressOrRange_num(sk) OPENSSL_sk_num(ossl_check_const_IPAddressOrRange_sk_type(sk)) #define sk_IPAddressOrRange_value(sk, idx) ((IPAddressOrRange *)OPENSSL_sk_value(ossl_check_const_IPAddressOrRange_sk_type(sk), (idx))) @@ -1199,11 +1224,12 @@ SKM_DEFINE_STACK_OF_INTERNAL(IPAddressOrRange, IPAddressOrRange, IPAddressOrRang #define sk_IPAddressOrRange_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(IPAddressOrRange) *)OPENSSL_sk_deep_copy(ossl_check_const_IPAddressOrRange_sk_type(sk), ossl_check_IPAddressOrRange_copyfunc_type(copyfunc), ossl_check_IPAddressOrRange_freefunc_type(freefunc))) #define sk_IPAddressOrRange_set_cmp_func(sk, cmp) ((sk_IPAddressOrRange_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_IPAddressOrRange_sk_type(sk), ossl_check_IPAddressOrRange_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(IPAddressOrRange) IPAddressOrRanges; -# define IPAddressChoice_inherit 0 -# define IPAddressChoice_addressesOrRanges 1 +#define IPAddressChoice_inherit 0 +#define IPAddressChoice_addressesOrRanges 1 typedef struct IPAddressChoice_st { int type; @@ -1218,6 +1244,7 @@ typedef struct IPAddressFamily_st { IPAddressChoice *ipAddressChoice; } IPAddressFamily; +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(IPAddressFamily, IPAddressFamily, IPAddressFamily) #define sk_IPAddressFamily_num(sk) OPENSSL_sk_num(ossl_check_const_IPAddressFamily_sk_type(sk)) #define sk_IPAddressFamily_value(sk, idx) ((IPAddressFamily *)OPENSSL_sk_value(ossl_check_const_IPAddressFamily_sk_type(sk), (idx))) @@ -1245,7 +1272,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(IPAddressFamily, IPAddressFamily, IPAddressFamily) #define sk_IPAddressFamily_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(IPAddressFamily) *)OPENSSL_sk_deep_copy(ossl_check_const_IPAddressFamily_sk_type(sk), ossl_check_IPAddressFamily_copyfunc_type(copyfunc), ossl_check_IPAddressFamily_freefunc_type(freefunc))) #define sk_IPAddressFamily_set_cmp_func(sk, cmp) ((sk_IPAddressFamily_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_IPAddressFamily_sk_type(sk), ossl_check_IPAddressFamily_compfunc_type(cmp))) - +/* clang-format on */ typedef STACK_OF(IPAddressFamily) IPAddrBlocks; @@ -1257,8 +1284,8 @@ DECLARE_ASN1_FUNCTIONS(IPAddressFamily) /* * API tag for elements of the ASIdentifer SEQUENCE. */ -# define V3_ASID_ASNUM 0 -# define V3_ASID_RDI 1 +#define V3_ASID_ASNUM 0 +#define V3_ASID_RDI 1 /* * AFI values, assigned by IANA. It'd be nice to make the AFI @@ -1266,8 +1293,8 @@ DECLARE_ASN1_FUNCTIONS(IPAddressFamily) * that would need to be defined for other address families for it to * be worth the trouble. */ -# define IANA_AFI_IPV4 1 -# define IANA_AFI_IPV6 2 +#define IANA_AFI_IPV4 1 +#define IANA_AFI_IPV6 2 /* * Utilities to construct and extract values from RFC3779 extensions, @@ -1276,19 +1303,19 @@ DECLARE_ASN1_FUNCTIONS(IPAddressFamily) */ int X509v3_asid_add_inherit(ASIdentifiers *asid, int which); int X509v3_asid_add_id_or_range(ASIdentifiers *asid, int which, - ASN1_INTEGER *min, ASN1_INTEGER *max); + ASN1_INTEGER *min, ASN1_INTEGER *max); int X509v3_addr_add_inherit(IPAddrBlocks *addr, - const unsigned afi, const unsigned *safi); + const unsigned afi, const unsigned *safi); int X509v3_addr_add_prefix(IPAddrBlocks *addr, - const unsigned afi, const unsigned *safi, - unsigned char *a, const int prefixlen); + const unsigned afi, const unsigned *safi, + unsigned char *a, const int prefixlen); int X509v3_addr_add_range(IPAddrBlocks *addr, - const unsigned afi, const unsigned *safi, - unsigned char *min, unsigned char *max); + const unsigned afi, const unsigned *safi, + unsigned char *min, unsigned char *max); unsigned X509v3_addr_get_afi(const IPAddressFamily *f); int X509v3_addr_get_range(IPAddressOrRange *aor, const unsigned afi, - unsigned char *min, unsigned char *max, - const int length); + unsigned char *min, unsigned char *max, + const int length); /* * Canonical forms. @@ -1312,13 +1339,14 @@ int X509v3_addr_subset(IPAddrBlocks *a, IPAddrBlocks *b); int X509v3_asid_validate_path(X509_STORE_CTX *); int X509v3_addr_validate_path(X509_STORE_CTX *); int X509v3_asid_validate_resource_set(STACK_OF(X509) *chain, - ASIdentifiers *ext, - int allow_inheritance); + ASIdentifiers *ext, + int allow_inheritance); int X509v3_addr_validate_resource_set(STACK_OF(X509) *chain, - IPAddrBlocks *ext, int allow_inheritance); + IPAddrBlocks *ext, int allow_inheritance); -#endif /* OPENSSL_NO_RFC3779 */ +#endif /* OPENSSL_NO_RFC3779 */ +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_STRING, ASN1_STRING, ASN1_STRING) #define sk_ASN1_STRING_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_STRING_sk_type(sk)) #define sk_ASN1_STRING_value(sk, idx) ((ASN1_STRING *)OPENSSL_sk_value(ossl_check_const_ASN1_STRING_sk_type(sk), (idx))) @@ -1346,6 +1374,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(ASN1_STRING, ASN1_STRING, ASN1_STRING) #define sk_ASN1_STRING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_STRING) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_STRING_sk_type(sk), ossl_check_ASN1_STRING_copyfunc_type(copyfunc), ossl_check_ASN1_STRING_freefunc_type(freefunc))) #define sk_ASN1_STRING_set_cmp_func(sk, cmp) ((sk_ASN1_STRING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_STRING_sk_type(sk), ossl_check_ASN1_STRING_compfunc_type(cmp))) +/* clang-format on */ /* * Admission Syntax @@ -1358,6 +1387,7 @@ DECLARE_ASN1_FUNCTIONS(NAMING_AUTHORITY) DECLARE_ASN1_FUNCTIONS(PROFESSION_INFO) DECLARE_ASN1_FUNCTIONS(ADMISSIONS) DECLARE_ASN1_FUNCTIONS(ADMISSION_SYNTAX) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(PROFESSION_INFO, PROFESSION_INFO, PROFESSION_INFO) #define sk_PROFESSION_INFO_num(sk) OPENSSL_sk_num(ossl_check_const_PROFESSION_INFO_sk_type(sk)) #define sk_PROFESSION_INFO_value(sk, idx) ((PROFESSION_INFO *)OPENSSL_sk_value(ossl_check_const_PROFESSION_INFO_sk_type(sk), (idx))) @@ -1411,6 +1441,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(ADMISSIONS, ADMISSIONS, ADMISSIONS) #define sk_ADMISSIONS_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ADMISSIONS) *)OPENSSL_sk_deep_copy(ossl_check_const_ADMISSIONS_sk_type(sk), ossl_check_ADMISSIONS_copyfunc_type(copyfunc), ossl_check_ADMISSIONS_freefunc_type(freefunc))) #define sk_ADMISSIONS_set_cmp_func(sk, cmp) ((sk_ADMISSIONS_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ADMISSIONS_sk_type(sk), ossl_check_ADMISSIONS_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(PROFESSION_INFO) PROFESSION_INFOS; const ASN1_OBJECT *NAMING_AUTHORITY_get0_authorityId( @@ -1420,11 +1451,11 @@ const ASN1_IA5STRING *NAMING_AUTHORITY_get0_authorityURL( const ASN1_STRING *NAMING_AUTHORITY_get0_authorityText( const NAMING_AUTHORITY *n); void NAMING_AUTHORITY_set0_authorityId(NAMING_AUTHORITY *n, - ASN1_OBJECT* namingAuthorityId); + ASN1_OBJECT *namingAuthorityId); void NAMING_AUTHORITY_set0_authorityURL(NAMING_AUTHORITY *n, - ASN1_IA5STRING* namingAuthorityUrl); + ASN1_IA5STRING *namingAuthorityUrl); void NAMING_AUTHORITY_set0_authorityText(NAMING_AUTHORITY *n, - ASN1_STRING* namingAuthorityText); + ASN1_STRING *namingAuthorityText); const GENERAL_NAME *ADMISSION_SYNTAX_get0_admissionAuthority( const ADMISSION_SYNTAX *as); @@ -1469,6 +1500,7 @@ DECLARE_ASN1_FUNCTIONS(OSSL_ATTRIBUTES_SYNTAX) typedef STACK_OF(USERNOTICE) OSSL_USER_NOTICE_SYNTAX; DECLARE_ASN1_FUNCTIONS(OSSL_USER_NOTICE_SYNTAX) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(USERNOTICE, USERNOTICE, USERNOTICE) #define sk_USERNOTICE_num(sk) OPENSSL_sk_num(ossl_check_const_USERNOTICE_sk_type(sk)) #define sk_USERNOTICE_value(sk, idx) ((USERNOTICE *)OPENSSL_sk_value(ossl_check_const_USERNOTICE_sk_type(sk), (idx))) @@ -1496,6 +1528,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(USERNOTICE, USERNOTICE, USERNOTICE) #define sk_USERNOTICE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(USERNOTICE) *)OPENSSL_sk_deep_copy(ossl_check_const_USERNOTICE_sk_type(sk), ossl_check_USERNOTICE_copyfunc_type(copyfunc), ossl_check_USERNOTICE_freefunc_type(freefunc))) #define sk_USERNOTICE_set_cmp_func(sk, cmp) ((sk_USERNOTICE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_USERNOTICE_sk_type(sk), ossl_check_USERNOTICE_compfunc_type(cmp))) +/* clang-format on */ typedef struct OSSL_ROLE_SPEC_CERT_ID_st { GENERAL_NAME *roleName; @@ -1506,6 +1539,7 @@ typedef struct OSSL_ROLE_SPEC_CERT_ID_st { DECLARE_ASN1_FUNCTIONS(OSSL_ROLE_SPEC_CERT_ID) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_ROLE_SPEC_CERT_ID, OSSL_ROLE_SPEC_CERT_ID, OSSL_ROLE_SPEC_CERT_ID) #define sk_OSSL_ROLE_SPEC_CERT_ID_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_ROLE_SPEC_CERT_ID_sk_type(sk)) #define sk_OSSL_ROLE_SPEC_CERT_ID_value(sk, idx) ((OSSL_ROLE_SPEC_CERT_ID *)OPENSSL_sk_value(ossl_check_const_OSSL_ROLE_SPEC_CERT_ID_sk_type(sk), (idx))) @@ -1533,6 +1567,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_ROLE_SPEC_CERT_ID, OSSL_ROLE_SPEC_CERT_ID, OSS #define sk_OSSL_ROLE_SPEC_CERT_ID_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_ROLE_SPEC_CERT_ID) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_ROLE_SPEC_CERT_ID_sk_type(sk), ossl_check_OSSL_ROLE_SPEC_CERT_ID_copyfunc_type(copyfunc), ossl_check_OSSL_ROLE_SPEC_CERT_ID_freefunc_type(freefunc))) #define sk_OSSL_ROLE_SPEC_CERT_ID_set_cmp_func(sk, cmp) ((sk_OSSL_ROLE_SPEC_CERT_ID_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_ROLE_SPEC_CERT_ID_sk_type(sk), ossl_check_OSSL_ROLE_SPEC_CERT_ID_compfunc_type(cmp))) +/* clang-format on */ typedef STACK_OF(OSSL_ROLE_SPEC_CERT_ID) OSSL_ROLE_SPEC_CERT_ID_SYNTAX; @@ -1547,8 +1582,8 @@ typedef struct OSSL_INFO_SYNTAX_POINTER_st { OSSL_HASH *hash; } OSSL_INFO_SYNTAX_POINTER; -# define OSSL_INFO_SYNTAX_TYPE_CONTENT 0 -# define OSSL_INFO_SYNTAX_TYPE_POINTER 1 +#define OSSL_INFO_SYNTAX_TYPE_CONTENT 0 +#define OSSL_INFO_SYNTAX_TYPE_POINTER 1 typedef struct OSSL_INFO_SYNTAX_st { int type; @@ -1593,22 +1628,22 @@ typedef struct OSSL_DAY_TIME_BAND_st { OSSL_DAY_TIME *endDayTime; } OSSL_DAY_TIME_BAND; -# define OSSL_NAMED_DAY_TYPE_INT 0 -# define OSSL_NAMED_DAY_TYPE_BIT 1 -# define OSSL_NAMED_DAY_INT_SUN 1 -# define OSSL_NAMED_DAY_INT_MON 2 -# define OSSL_NAMED_DAY_INT_TUE 3 -# define OSSL_NAMED_DAY_INT_WED 4 -# define OSSL_NAMED_DAY_INT_THU 5 -# define OSSL_NAMED_DAY_INT_FRI 6 -# define OSSL_NAMED_DAY_INT_SAT 7 -# define OSSL_NAMED_DAY_BIT_SUN 0 -# define OSSL_NAMED_DAY_BIT_MON 1 -# define OSSL_NAMED_DAY_BIT_TUE 2 -# define OSSL_NAMED_DAY_BIT_WED 3 -# define OSSL_NAMED_DAY_BIT_THU 4 -# define OSSL_NAMED_DAY_BIT_FRI 5 -# define OSSL_NAMED_DAY_BIT_SAT 6 +#define OSSL_NAMED_DAY_TYPE_INT 0 +#define OSSL_NAMED_DAY_TYPE_BIT 1 +#define OSSL_NAMED_DAY_INT_SUN 1 +#define OSSL_NAMED_DAY_INT_MON 2 +#define OSSL_NAMED_DAY_INT_TUE 3 +#define OSSL_NAMED_DAY_INT_WED 4 +#define OSSL_NAMED_DAY_INT_THU 5 +#define OSSL_NAMED_DAY_INT_FRI 6 +#define OSSL_NAMED_DAY_INT_SAT 7 +#define OSSL_NAMED_DAY_BIT_SUN 0 +#define OSSL_NAMED_DAY_BIT_MON 1 +#define OSSL_NAMED_DAY_BIT_TUE 2 +#define OSSL_NAMED_DAY_BIT_WED 3 +#define OSSL_NAMED_DAY_BIT_THU 4 +#define OSSL_NAMED_DAY_BIT_FRI 5 +#define OSSL_NAMED_DAY_BIT_SAT 6 typedef struct OSSL_NAMED_DAY_st { int type; @@ -1618,11 +1653,11 @@ typedef struct OSSL_NAMED_DAY_st { } choice; } OSSL_NAMED_DAY; -# define OSSL_TIME_SPEC_X_DAY_OF_FIRST 0 -# define OSSL_TIME_SPEC_X_DAY_OF_SECOND 1 -# define OSSL_TIME_SPEC_X_DAY_OF_THIRD 2 -# define OSSL_TIME_SPEC_X_DAY_OF_FOURTH 3 -# define OSSL_TIME_SPEC_X_DAY_OF_FIFTH 4 +#define OSSL_TIME_SPEC_X_DAY_OF_FIRST 0 +#define OSSL_TIME_SPEC_X_DAY_OF_SECOND 1 +#define OSSL_TIME_SPEC_X_DAY_OF_THIRD 2 +#define OSSL_TIME_SPEC_X_DAY_OF_FOURTH 3 +#define OSSL_TIME_SPEC_X_DAY_OF_FIFTH 4 typedef struct OSSL_TIME_SPEC_X_DAY_OF_st { int type; @@ -1635,23 +1670,23 @@ typedef struct OSSL_TIME_SPEC_X_DAY_OF_st { } choice; } OSSL_TIME_SPEC_X_DAY_OF; -# define OSSL_TIME_SPEC_DAY_TYPE_INT 0 -# define OSSL_TIME_SPEC_DAY_TYPE_BIT 1 -# define OSSL_TIME_SPEC_DAY_TYPE_DAY_OF 2 -# define OSSL_TIME_SPEC_DAY_BIT_SUN 0 -# define OSSL_TIME_SPEC_DAY_BIT_MON 1 -# define OSSL_TIME_SPEC_DAY_BIT_TUE 2 -# define OSSL_TIME_SPEC_DAY_BIT_WED 3 -# define OSSL_TIME_SPEC_DAY_BIT_THU 4 -# define OSSL_TIME_SPEC_DAY_BIT_FRI 5 -# define OSSL_TIME_SPEC_DAY_BIT_SAT 6 -# define OSSL_TIME_SPEC_DAY_INT_SUN 1 -# define OSSL_TIME_SPEC_DAY_INT_MON 2 -# define OSSL_TIME_SPEC_DAY_INT_TUE 3 -# define OSSL_TIME_SPEC_DAY_INT_WED 4 -# define OSSL_TIME_SPEC_DAY_INT_THU 5 -# define OSSL_TIME_SPEC_DAY_INT_FRI 6 -# define OSSL_TIME_SPEC_DAY_INT_SAT 7 +#define OSSL_TIME_SPEC_DAY_TYPE_INT 0 +#define OSSL_TIME_SPEC_DAY_TYPE_BIT 1 +#define OSSL_TIME_SPEC_DAY_TYPE_DAY_OF 2 +#define OSSL_TIME_SPEC_DAY_BIT_SUN 0 +#define OSSL_TIME_SPEC_DAY_BIT_MON 1 +#define OSSL_TIME_SPEC_DAY_BIT_TUE 2 +#define OSSL_TIME_SPEC_DAY_BIT_WED 3 +#define OSSL_TIME_SPEC_DAY_BIT_THU 4 +#define OSSL_TIME_SPEC_DAY_BIT_FRI 5 +#define OSSL_TIME_SPEC_DAY_BIT_SAT 6 +#define OSSL_TIME_SPEC_DAY_INT_SUN 1 +#define OSSL_TIME_SPEC_DAY_INT_MON 2 +#define OSSL_TIME_SPEC_DAY_INT_TUE 3 +#define OSSL_TIME_SPEC_DAY_INT_WED 4 +#define OSSL_TIME_SPEC_DAY_INT_THU 5 +#define OSSL_TIME_SPEC_DAY_INT_FRI 6 +#define OSSL_TIME_SPEC_DAY_INT_SAT 7 typedef struct OSSL_TIME_SPEC_DAY_st { int type; @@ -1662,14 +1697,14 @@ typedef struct OSSL_TIME_SPEC_DAY_st { } choice; } OSSL_TIME_SPEC_DAY; -# define OSSL_TIME_SPEC_WEEKS_TYPE_ALL 0 -# define OSSL_TIME_SPEC_WEEKS_TYPE_INT 1 -# define OSSL_TIME_SPEC_WEEKS_TYPE_BIT 2 -# define OSSL_TIME_SPEC_BIT_WEEKS_1 0 -# define OSSL_TIME_SPEC_BIT_WEEKS_2 1 -# define OSSL_TIME_SPEC_BIT_WEEKS_3 2 -# define OSSL_TIME_SPEC_BIT_WEEKS_4 3 -# define OSSL_TIME_SPEC_BIT_WEEKS_5 4 +#define OSSL_TIME_SPEC_WEEKS_TYPE_ALL 0 +#define OSSL_TIME_SPEC_WEEKS_TYPE_INT 1 +#define OSSL_TIME_SPEC_WEEKS_TYPE_BIT 2 +#define OSSL_TIME_SPEC_BIT_WEEKS_1 0 +#define OSSL_TIME_SPEC_BIT_WEEKS_2 1 +#define OSSL_TIME_SPEC_BIT_WEEKS_3 2 +#define OSSL_TIME_SPEC_BIT_WEEKS_4 3 +#define OSSL_TIME_SPEC_BIT_WEEKS_5 4 typedef struct OSSL_TIME_SPEC_WEEKS_st { int type; @@ -1680,33 +1715,33 @@ typedef struct OSSL_TIME_SPEC_WEEKS_st { } choice; } OSSL_TIME_SPEC_WEEKS; -# define OSSL_TIME_SPEC_MONTH_TYPE_ALL 0 -# define OSSL_TIME_SPEC_MONTH_TYPE_INT 1 -# define OSSL_TIME_SPEC_MONTH_TYPE_BIT 2 -# define OSSL_TIME_SPEC_INT_MONTH_JAN 1 -# define OSSL_TIME_SPEC_INT_MONTH_FEB 2 -# define OSSL_TIME_SPEC_INT_MONTH_MAR 3 -# define OSSL_TIME_SPEC_INT_MONTH_APR 4 -# define OSSL_TIME_SPEC_INT_MONTH_MAY 5 -# define OSSL_TIME_SPEC_INT_MONTH_JUN 6 -# define OSSL_TIME_SPEC_INT_MONTH_JUL 7 -# define OSSL_TIME_SPEC_INT_MONTH_AUG 8 -# define OSSL_TIME_SPEC_INT_MONTH_SEP 9 -# define OSSL_TIME_SPEC_INT_MONTH_OCT 10 -# define OSSL_TIME_SPEC_INT_MONTH_NOV 11 -# define OSSL_TIME_SPEC_INT_MONTH_DEC 12 -# define OSSL_TIME_SPEC_BIT_MONTH_JAN 0 -# define OSSL_TIME_SPEC_BIT_MONTH_FEB 1 -# define OSSL_TIME_SPEC_BIT_MONTH_MAR 2 -# define OSSL_TIME_SPEC_BIT_MONTH_APR 3 -# define OSSL_TIME_SPEC_BIT_MONTH_MAY 4 -# define OSSL_TIME_SPEC_BIT_MONTH_JUN 5 -# define OSSL_TIME_SPEC_BIT_MONTH_JUL 6 -# define OSSL_TIME_SPEC_BIT_MONTH_AUG 7 -# define OSSL_TIME_SPEC_BIT_MONTH_SEP 8 -# define OSSL_TIME_SPEC_BIT_MONTH_OCT 9 -# define OSSL_TIME_SPEC_BIT_MONTH_NOV 10 -# define OSSL_TIME_SPEC_BIT_MONTH_DEC 11 +#define OSSL_TIME_SPEC_MONTH_TYPE_ALL 0 +#define OSSL_TIME_SPEC_MONTH_TYPE_INT 1 +#define OSSL_TIME_SPEC_MONTH_TYPE_BIT 2 +#define OSSL_TIME_SPEC_INT_MONTH_JAN 1 +#define OSSL_TIME_SPEC_INT_MONTH_FEB 2 +#define OSSL_TIME_SPEC_INT_MONTH_MAR 3 +#define OSSL_TIME_SPEC_INT_MONTH_APR 4 +#define OSSL_TIME_SPEC_INT_MONTH_MAY 5 +#define OSSL_TIME_SPEC_INT_MONTH_JUN 6 +#define OSSL_TIME_SPEC_INT_MONTH_JUL 7 +#define OSSL_TIME_SPEC_INT_MONTH_AUG 8 +#define OSSL_TIME_SPEC_INT_MONTH_SEP 9 +#define OSSL_TIME_SPEC_INT_MONTH_OCT 10 +#define OSSL_TIME_SPEC_INT_MONTH_NOV 11 +#define OSSL_TIME_SPEC_INT_MONTH_DEC 12 +#define OSSL_TIME_SPEC_BIT_MONTH_JAN 0 +#define OSSL_TIME_SPEC_BIT_MONTH_FEB 1 +#define OSSL_TIME_SPEC_BIT_MONTH_MAR 2 +#define OSSL_TIME_SPEC_BIT_MONTH_APR 3 +#define OSSL_TIME_SPEC_BIT_MONTH_MAY 4 +#define OSSL_TIME_SPEC_BIT_MONTH_JUN 5 +#define OSSL_TIME_SPEC_BIT_MONTH_JUL 6 +#define OSSL_TIME_SPEC_BIT_MONTH_AUG 7 +#define OSSL_TIME_SPEC_BIT_MONTH_SEP 8 +#define OSSL_TIME_SPEC_BIT_MONTH_OCT 9 +#define OSSL_TIME_SPEC_BIT_MONTH_NOV 10 +#define OSSL_TIME_SPEC_BIT_MONTH_DEC 11 typedef struct OSSL_TIME_SPEC_MONTH_st { int type; @@ -1725,8 +1760,8 @@ typedef struct OSSL_TIME_PERIOD_st { STACK_OF(ASN1_INTEGER) *years; } OSSL_TIME_PERIOD; -# define OSSL_TIME_SPEC_TIME_TYPE_ABSOLUTE 0 -# define OSSL_TIME_SPEC_TIME_TYPE_PERIODIC 1 +#define OSSL_TIME_SPEC_TIME_TYPE_ABSOLUTE 0 +#define OSSL_TIME_SPEC_TIME_TYPE_PERIODIC 1 typedef struct OSSL_TIME_SPEC_TIME_st { int type; @@ -1754,6 +1789,7 @@ DECLARE_ASN1_FUNCTIONS(OSSL_TIME_SPEC_TIME) DECLARE_ASN1_FUNCTIONS(OSSL_TIME_SPEC) DECLARE_ASN1_FUNCTIONS(OSSL_TIME_PERIOD) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_TIME_PERIOD, OSSL_TIME_PERIOD, OSSL_TIME_PERIOD) #define sk_OSSL_TIME_PERIOD_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_TIME_PERIOD_sk_type(sk)) #define sk_OSSL_TIME_PERIOD_value(sk, idx) ((OSSL_TIME_PERIOD *)OPENSSL_sk_value(ossl_check_const_OSSL_TIME_PERIOD_sk_type(sk), (idx))) @@ -1781,7 +1817,9 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_TIME_PERIOD, OSSL_TIME_PERIOD, OSSL_TIME_PERIO #define sk_OSSL_TIME_PERIOD_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_TIME_PERIOD) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_TIME_PERIOD_sk_type(sk), ossl_check_OSSL_TIME_PERIOD_copyfunc_type(copyfunc), ossl_check_OSSL_TIME_PERIOD_freefunc_type(freefunc))) #define sk_OSSL_TIME_PERIOD_set_cmp_func(sk, cmp) ((sk_OSSL_TIME_PERIOD_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_TIME_PERIOD_sk_type(sk), ossl_check_OSSL_TIME_PERIOD_compfunc_type(cmp))) +/* clang-format on */ +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_DAY_TIME_BAND, OSSL_DAY_TIME_BAND, OSSL_DAY_TIME_BAND) #define sk_OSSL_DAY_TIME_BAND_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_DAY_TIME_BAND_sk_type(sk)) #define sk_OSSL_DAY_TIME_BAND_value(sk, idx) ((OSSL_DAY_TIME_BAND *)OPENSSL_sk_value(ossl_check_const_OSSL_DAY_TIME_BAND_sk_type(sk), (idx))) @@ -1809,6 +1847,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_DAY_TIME_BAND, OSSL_DAY_TIME_BAND, OSSL_DAY_TI #define sk_OSSL_DAY_TIME_BAND_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_DAY_TIME_BAND) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_DAY_TIME_BAND_sk_type(sk), ossl_check_OSSL_DAY_TIME_BAND_copyfunc_type(copyfunc), ossl_check_OSSL_DAY_TIME_BAND_freefunc_type(freefunc))) #define sk_OSSL_DAY_TIME_BAND_set_cmp_func(sk, cmp) ((sk_OSSL_DAY_TIME_BAND_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_DAY_TIME_BAND_sk_type(sk), ossl_check_OSSL_DAY_TIME_BAND_compfunc_type(cmp))) +/* clang-format on */ /* Attribute Type and Value */ typedef struct atav_st { @@ -1826,8 +1865,8 @@ typedef struct ATTRIBUTE_VALUE_MAPPING_st { OSSL_ATAV *remote; } OSSL_ATTRIBUTE_VALUE_MAPPING; -# define OSSL_ATTR_MAP_TYPE 0 -# define OSSL_ATTR_MAP_VALUE 1 +#define OSSL_ATTR_MAP_TYPE 0 +#define OSSL_ATTR_MAP_VALUE 1 typedef struct ATTRIBUTE_MAPPING_st { int type; @@ -1844,6 +1883,7 @@ DECLARE_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_VALUE_MAPPING) DECLARE_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_MAPPING) DECLARE_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_MAPPINGS) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_ATTRIBUTE_MAPPING, OSSL_ATTRIBUTE_MAPPING, OSSL_ATTRIBUTE_MAPPING) #define sk_OSSL_ATTRIBUTE_MAPPING_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_ATTRIBUTE_MAPPING_sk_type(sk)) #define sk_OSSL_ATTRIBUTE_MAPPING_value(sk, idx) ((OSSL_ATTRIBUTE_MAPPING *)OPENSSL_sk_value(ossl_check_const_OSSL_ATTRIBUTE_MAPPING_sk_type(sk), (idx))) @@ -1871,9 +1911,10 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_ATTRIBUTE_MAPPING, OSSL_ATTRIBUTE_MAPPING, OSS #define sk_OSSL_ATTRIBUTE_MAPPING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_ATTRIBUTE_MAPPING) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_ATTRIBUTE_MAPPING_sk_type(sk), ossl_check_OSSL_ATTRIBUTE_MAPPING_copyfunc_type(copyfunc), ossl_check_OSSL_ATTRIBUTE_MAPPING_freefunc_type(freefunc))) #define sk_OSSL_ATTRIBUTE_MAPPING_set_cmp_func(sk, cmp) ((sk_OSSL_ATTRIBUTE_MAPPING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_ATTRIBUTE_MAPPING_sk_type(sk), ossl_check_OSSL_ATTRIBUTE_MAPPING_compfunc_type(cmp))) +/* clang-format on */ -# define OSSL_AAA_ATTRIBUTE_TYPE 0 -# define OSSL_AAA_ATTRIBUTE_VALUES 1 +#define OSSL_AAA_ATTRIBUTE_TYPE 0 +#define OSSL_AAA_ATTRIBUTE_VALUES 1 typedef struct ALLOWED_ATTRIBUTES_CHOICE_st { int type; @@ -1894,6 +1935,7 @@ DECLARE_ASN1_FUNCTIONS(OSSL_ALLOWED_ATTRIBUTES_CHOICE) DECLARE_ASN1_FUNCTIONS(OSSL_ALLOWED_ATTRIBUTES_ITEM) DECLARE_ASN1_FUNCTIONS(OSSL_ALLOWED_ATTRIBUTES_SYNTAX) +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_ALLOWED_ATTRIBUTES_CHOICE, OSSL_ALLOWED_ATTRIBUTES_CHOICE, OSSL_ALLOWED_ATTRIBUTES_CHOICE) #define sk_OSSL_ALLOWED_ATTRIBUTES_CHOICE_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_ALLOWED_ATTRIBUTES_CHOICE_sk_type(sk)) #define sk_OSSL_ALLOWED_ATTRIBUTES_CHOICE_value(sk, idx) ((OSSL_ALLOWED_ATTRIBUTES_CHOICE *)OPENSSL_sk_value(ossl_check_const_OSSL_ALLOWED_ATTRIBUTES_CHOICE_sk_type(sk), (idx))) @@ -1921,7 +1963,9 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_ALLOWED_ATTRIBUTES_CHOICE, OSSL_ALLOWED_ATTRIB #define sk_OSSL_ALLOWED_ATTRIBUTES_CHOICE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_ALLOWED_ATTRIBUTES_CHOICE) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_ALLOWED_ATTRIBUTES_CHOICE_sk_type(sk), ossl_check_OSSL_ALLOWED_ATTRIBUTES_CHOICE_copyfunc_type(copyfunc), ossl_check_OSSL_ALLOWED_ATTRIBUTES_CHOICE_freefunc_type(freefunc))) #define sk_OSSL_ALLOWED_ATTRIBUTES_CHOICE_set_cmp_func(sk, cmp) ((sk_OSSL_ALLOWED_ATTRIBUTES_CHOICE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_ALLOWED_ATTRIBUTES_CHOICE_sk_type(sk), ossl_check_OSSL_ALLOWED_ATTRIBUTES_CHOICE_compfunc_type(cmp))) +/* clang-format on */ +/* clang-format off */ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_ALLOWED_ATTRIBUTES_ITEM, OSSL_ALLOWED_ATTRIBUTES_ITEM, OSSL_ALLOWED_ATTRIBUTES_ITEM) #define sk_OSSL_ALLOWED_ATTRIBUTES_ITEM_num(sk) OPENSSL_sk_num(ossl_check_const_OSSL_ALLOWED_ATTRIBUTES_ITEM_sk_type(sk)) #define sk_OSSL_ALLOWED_ATTRIBUTES_ITEM_value(sk, idx) ((OSSL_ALLOWED_ATTRIBUTES_ITEM *)OPENSSL_sk_value(ossl_check_const_OSSL_ALLOWED_ATTRIBUTES_ITEM_sk_type(sk), (idx))) @@ -1949,6 +1993,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(OSSL_ALLOWED_ATTRIBUTES_ITEM, OSSL_ALLOWED_ATTRIBUT #define sk_OSSL_ALLOWED_ATTRIBUTES_ITEM_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(OSSL_ALLOWED_ATTRIBUTES_ITEM) *)OPENSSL_sk_deep_copy(ossl_check_const_OSSL_ALLOWED_ATTRIBUTES_ITEM_sk_type(sk), ossl_check_OSSL_ALLOWED_ATTRIBUTES_ITEM_copyfunc_type(copyfunc), ossl_check_OSSL_ALLOWED_ATTRIBUTES_ITEM_freefunc_type(freefunc))) #define sk_OSSL_ALLOWED_ATTRIBUTES_ITEM_set_cmp_func(sk, cmp) ((sk_OSSL_ALLOWED_ATTRIBUTES_ITEM_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_OSSL_ALLOWED_ATTRIBUTES_ITEM_sk_type(sk), ossl_check_OSSL_ALLOWED_ATTRIBUTES_ITEM_compfunc_type(cmp))) +/* clang-format on */ typedef struct AA_DIST_POINT_st { DIST_POINT_NAME *distpoint; @@ -1962,7 +2007,7 @@ typedef struct AA_DIST_POINT_st { DECLARE_ASN1_FUNCTIONS(OSSL_AA_DIST_POINT) -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_digests_gen.c b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_digests_gen.c index c075dc9884..65a9ed263e 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_digests_gen.c +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_digests_gen.c @@ -13,6 +13,7 @@ #include "prov/der_digests.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * sigAlgs OBJECT IDENTIFIER ::= { nistAlgorithms 3 } @@ -158,3 +159,4 @@ const unsigned char ossl_der_oid_id_KMACWithSHAKE256[DER_OID_SZ_id_KMACWithSHAKE DER_OID_V_id_KMACWithSHAKE256 }; +/* clang-format on */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ec_gen.c b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ec_gen.c index d4136186fe..8a79f14f3f 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ec_gen.c +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ec_gen.c @@ -13,6 +13,7 @@ #include "prov/der_ec.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * ecdsa-with-SHA1 OBJECT IDENTIFIER ::= { id-ecSigType 1 } @@ -277,3 +278,4 @@ const unsigned char ossl_der_oid_id_ecdsa_with_sha3_512[DER_OID_SZ_id_ecdsa_with DER_OID_V_id_ecdsa_with_sha3_512 }; +/* clang-format on */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ecx_gen.c b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ecx_gen.c index bda7e53f50..8aa515d088 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ecx_gen.c +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ecx_gen.c @@ -13,6 +13,7 @@ #include "prov/der_ecx.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * id-X25519 OBJECT IDENTIFIER ::= { id-edwards-curve-algs 110 } @@ -42,3 +43,4 @@ const unsigned char ossl_der_oid_id_Ed448[DER_OID_SZ_id_Ed448] = { DER_OID_V_id_Ed448 }; +/* clang-format on */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_rsa_gen.c b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_rsa_gen.c index 805f40d61b..744c9317ca 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_rsa_gen.c +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_rsa_gen.c @@ -13,6 +13,7 @@ #include "prov/der_rsa.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * hashAlgs OBJECT IDENTIFIER ::= { nistAlgorithms 2 } @@ -172,3 +173,4 @@ const unsigned char ossl_der_oid_mdc2WithRSASignature[DER_OID_SZ_mdc2WithRSASign DER_OID_V_mdc2WithRSASignature }; +/* clang-format on */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_wrap_gen.c b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_wrap_gen.c index 9913d1a44f..608fee5a99 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_wrap_gen.c +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_wrap_gen.c @@ -13,6 +13,7 @@ #include "prov/der_wrap.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * id-alg-CMS3DESwrap OBJECT IDENTIFIER ::= { @@ -44,3 +45,4 @@ const unsigned char ossl_der_oid_id_aes256_wrap[DER_OID_SZ_id_aes256_wrap] = { DER_OID_V_id_aes256_wrap }; +/* clang-format on */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_digests.h b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_digests.h index c0d857ffde..95b0303a85 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_digests.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_digests.h @@ -13,6 +13,7 @@ #include "internal/der.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * sigAlgs OBJECT IDENTIFIER ::= { nistAlgorithms 3 } @@ -158,3 +159,4 @@ extern const unsigned char ossl_der_oid_id_KMACWithSHAKE128[DER_OID_SZ_id_KMACWi #define DER_OID_SZ_id_KMACWithSHAKE256 11 extern const unsigned char ossl_der_oid_id_KMACWithSHAKE256[DER_OID_SZ_id_KMACWithSHAKE256]; +/* clang-format on */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ec.h b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ec.h index 47cb82cd35..f049acb126 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ec.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ec.h @@ -14,6 +14,7 @@ #include "internal/der.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * ecdsa-with-SHA1 OBJECT IDENTIFIER ::= { id-ecSigType 1 } @@ -278,9 +279,10 @@ extern const unsigned char ossl_der_oid_id_ecdsa_with_sha3_384[DER_OID_SZ_id_ecd #define DER_OID_SZ_id_ecdsa_with_sha3_512 11 extern const unsigned char ossl_der_oid_id_ecdsa_with_sha3_512[DER_OID_SZ_id_ecdsa_with_sha3_512]; +/* clang-format on */ /* Subject Public Key Info */ int ossl_DER_w_algorithmIdentifier_EC(WPACKET *pkt, int cont, EC_KEY *ec); /* Signature */ int ossl_DER_w_algorithmIdentifier_ECDSA_with_MD(WPACKET *pkt, int cont, - EC_KEY *ec, int mdnid); + EC_KEY *ec, int mdnid); diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ecx.h b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ecx.h index ae167d54f2..2aa2b0706d 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ecx.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ecx.h @@ -14,6 +14,7 @@ #include "crypto/ecx.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * id-X25519 OBJECT IDENTIFIER ::= { id-edwards-curve-algs 110 } @@ -43,6 +44,7 @@ extern const unsigned char ossl_der_oid_id_Ed25519[DER_OID_SZ_id_Ed25519]; #define DER_OID_SZ_id_Ed448 5 extern const unsigned char ossl_der_oid_id_Ed448[DER_OID_SZ_id_Ed448]; +/* clang-format on */ int ossl_DER_w_algorithmIdentifier_ED25519(WPACKET *pkt, int cont, ECX_KEY *ec); int ossl_DER_w_algorithmIdentifier_ED448(WPACKET *pkt, int cont, ECX_KEY *ec); diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_rsa.h b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_rsa.h index a4b4c32554..9395022e55 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_rsa.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_rsa.h @@ -14,6 +14,7 @@ #include "internal/der.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * hashAlgs OBJECT IDENTIFIER ::= { nistAlgorithms 2 } @@ -173,15 +174,16 @@ extern const unsigned char ossl_der_oid_ripemd160WithRSAEncryption[DER_OID_SZ_ri #define DER_OID_SZ_mdc2WithRSASignature 7 extern const unsigned char ossl_der_oid_mdc2WithRSASignature[DER_OID_SZ_mdc2WithRSASignature]; +/* clang-format on */ /* PSS parameters */ int ossl_DER_w_RSASSA_PSS_params(WPACKET *pkt, int tag, - const RSA_PSS_PARAMS_30 *pss); + const RSA_PSS_PARAMS_30 *pss); /* Subject Public Key Info */ int ossl_DER_w_algorithmIdentifier_RSA(WPACKET *pkt, int tag, RSA *rsa); int ossl_DER_w_algorithmIdentifier_RSA_PSS(WPACKET *pkt, int tag, - int rsa_type, - const RSA_PSS_PARAMS_30 *pss); + int rsa_type, + const RSA_PSS_PARAMS_30 *pss); /* Signature */ int ossl_DER_w_algorithmIdentifier_MDWithRSAEncryption(WPACKET *pkt, int tag, - int mdnid); + int mdnid); diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_wrap.h b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_wrap.h index 899f4b6687..e2c9a19bca 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_wrap.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_wrap.h @@ -13,6 +13,7 @@ #include "internal/der.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * id-alg-CMS3DESwrap OBJECT IDENTIFIER ::= { @@ -44,3 +45,4 @@ extern const unsigned char ossl_der_oid_id_aes192_wrap[DER_OID_SZ_id_aes192_wrap #define DER_OID_SZ_id_aes256_wrap 11 extern const unsigned char ossl_der_oid_id_aes256_wrap[DER_OID_SZ_id_aes256_wrap]; +/* clang-format on */ From 8f7191fea8ea340d081e9ab8c4d38fdf2d3dc8a3 Mon Sep 17 00:00:00 2001 From: Thamballi Sreelalitha Date: Tue, 16 Jun 2026 14:33:54 +0530 Subject: [PATCH 031/406] CryptoPkg: Update Uncrustify ignore list for openssl-3.5.7 Add configuration-ec-lite.h to UncrustifyCheck IgnoreFiles to fix CI failures. Signed-off-by: Thamballi Sreelalitha --- CryptoPkg/CryptoPkg.ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/CryptoPkg/CryptoPkg.ci.yaml b/CryptoPkg/CryptoPkg.ci.yaml index 9c87a5f5cf..96d6df1e81 100644 --- a/CryptoPkg/CryptoPkg.ci.yaml +++ b/CryptoPkg/CryptoPkg.ci.yaml @@ -117,6 +117,7 @@ "Library/OpensslLib/OpensslGen/include/openssl/cms.h", "Library/OpensslLib/OpensslGen/include/openssl/comp.h", "Library/OpensslLib/OpensslGen/include/openssl/conf.h", + "Library/OpensslLib/OpensslGen/include/openssl/configuration-ec-lite.h", "Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h", "Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h", "Library/OpensslLib/OpensslGen/include/openssl/configuration.h", From 73e13fa0cae2186ec539726629339403f5b747d8 Mon Sep 17 00:00:00 2001 From: Chao Li Date: Wed, 17 Jun 2026 10:42:14 +0800 Subject: [PATCH 032/406] Maintainers: Add LoongArch folder The bot doesn't add the LoongArch maintainers when the */LoongArch folder is changed. Once that directory is added, the bot will automatically add the LoongArch maintainers. Signed-off-by: Chao Li --- Maintainers.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Maintainers.txt b/Maintainers.txt index 2952caea1d..39ede31f93 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -108,6 +108,7 @@ R: Andrei Warkentin [andreiw] LOONGARCH64 F: */LoongArch64/ +F: */LoongArch/ M: Chao Li [kilaterlee] M: Baoqi Zhang [zhangbaoqi-ls] R: Dongyan Qian [MarsDoge] From b9463ca6b6049be80b7d5751dca4a0972eda9b0f Mon Sep 17 00:00:00 2001 From: Chao Li Date: Wed, 17 Jun 2026 10:57:35 +0800 Subject: [PATCH 033/406] Maintainers: Remove maobibo as LoongArchVirt maintainer Removed maobibo as LoongArchVirt maintainer and added Dongyan Qian as the LoongArchVirt reviewer. Signed-off-by: Chao Li --- Maintainers.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maintainers.txt b/Maintainers.txt index 39ede31f93..fe67a289a3 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -602,7 +602,7 @@ R: Andrei Warkentin [andreiw] OvmfPkg: LOONGARCH Qemu Virt Platform F: OvmfPkg/LoongArchVirt M: Chao Li [kilaterlee] -M: Bibo Mao [bibo-mao] +R: Dongyan Qian [MarsDoge] R: Xianglai Li [lixianglai] PcAtChipsetPkg From adc5e8d00941485ddeb185869eb35dd2de08f711 Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Tue, 5 May 2026 19:10:45 -0700 Subject: [PATCH 034/406] BaseTools/GenFds: Propagate Xip flag to FV INF via ,XIP suffix Add Xip attribute to FDF Rule class and parse the Xip keyword in EFI section rules of FDF files. Add XipEnabled attribute to FfsInfStatement that is determined from the applicable FDF Rule's section Xip setting. When generating the FV INF file, append ",XIP" to EFI_FILE_NAME entries for modules whose Rule specifies Xip=TRUE. This enables per-file XIP rebase control in GenFv by communicating which files require XIP rebase directly in the FV INF file format. Signed-off-by: Michael D Kinney --- .../Source/Python/CommonDataClass/FdfClass.py | 1 + BaseTools/Source/Python/GenFds/FdfParser.py | 10 +++++++ .../Source/Python/GenFds/FfsInfStatement.py | 29 +++++++++++++++++++ BaseTools/Source/Python/GenFds/Fv.py | 4 +++ 4 files changed, 44 insertions(+) diff --git a/BaseTools/Source/Python/CommonDataClass/FdfClass.py b/BaseTools/Source/Python/CommonDataClass/FdfClass.py index c8cfdaae32..f765e0a42a 100644 --- a/BaseTools/Source/Python/CommonDataClass/FdfClass.py +++ b/BaseTools/Source/Python/CommonDataClass/FdfClass.py @@ -249,6 +249,7 @@ class RuleClassObject : self.FvFileType = None # for Ffs File Type self.KeyStringList = [] self.KeepReloc = None + self.Xip = False ## Complex rule data in FDF # diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index c41fcdba7b..d8d09946fd 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -3900,6 +3900,16 @@ class FdfParser: raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber) EfiSectionObj.Alignment = self._Token + if self._IsKeyword("Xip"): + if not self._IsToken(TAB_EQUAL_SPLIT): + raise Warning.ExpectedEquals(self.FileName, self.CurrentLineNumber) + if not self._GetNextWord(): + raise Warning.Expected("Xip value (TRUE/FALSE)", self.FileName, self.CurrentLineNumber) + XipValue = self._Token.strip().upper() + if XipValue not in {"TRUE", "FALSE"}: + raise Warning("Invalid Xip value '%s'" % XipValue, self.FileName, self.CurrentLineNumber) + EfiSectionObj.Xip = XipValue + if self._IsKeyword('RELOCS_STRIPPED') or self._IsKeyword('RELOCS_RETAINED'): if self._SectionCouldHaveRelocFlag(EfiSectionObj.SectionType): if self._Token == 'RELOCS_STRIPPED': diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py index 6c837accee..3dbf3746d8 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -71,6 +71,31 @@ class FfsInfStatement(FfsInfStatementClassObject): self.PatchedBinFile = '' self.MacroDict = {} self.Depex = False + self.XipEnabled = False + + @staticmethod + def DetermineXipEnabled(Rule): + """Determine whether XIP is enabled based on a Rule object. + + For a RuleComplexFile, scans SectionList for any section with Xip='TRUE'. + For a RuleSimpleFile or other rule, checks Rule.Xip directly. + + Args: + Rule: A RuleComplexFile or RuleSimpleFile (or similar) object. + + Returns: + bool: True if XIP is enabled for this rule, False otherwise. + """ + if isinstance(Rule, RuleComplexFile.RuleComplexFile): + for Sect in Rule.SectionList: + if hasattr(Sect, 'Xip') and Sect.Xip and Sect.Xip.upper() == 'TRUE': + return True + elif hasattr(Rule, 'Xip') and Rule.Xip: + if isinstance(Rule.Xip, str) and Rule.Xip.upper() == 'TRUE': + return True + elif Rule.Xip is True: + return True + return False ## GetFinalTargetSuffixMap() method # @@ -489,6 +514,10 @@ class FfsInfStatement(FfsInfStatementClassObject): Rule = self.__GetRule__() GenFdsGlobalVariable.VerboseLogger( "Packing binaries from inf file : %s" %self.InfFileName) # + # Determine XIP setting from Rule sections + # + self.XipEnabled = FfsInfStatement.DetermineXipEnabled(Rule) + # # Convert Fv File Type for PI1.1 SMM driver. # if self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER and int(self.PiSpecVersion, 16) >= 0x0001000A: diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py index 16c944a0bd..f522393e6c 100644 --- a/BaseTools/Source/Python/GenFds/Fv.py +++ b/BaseTools/Source/Python/GenFds/Fv.py @@ -127,8 +127,12 @@ class FV (object): FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress, IsMakefile=Flag, FvName=self.UiFvName) FfsFileList.append(FileName) if not Flag: + XipSuffix = "" + if hasattr(FfsFile, 'XipEnabled') and FfsFile.XipEnabled: + XipSuffix = ",XIP" self.FvInfFile.append("EFI_FILE_NAME = " + \ FileName + \ + XipSuffix + \ TAB_LINE_BREAK) if not Flag: FvInfFile = ''.join(self.FvInfFile) From 3ee3b60eb82d52e159641b89d66bcc91a40b84ce Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Tue, 5 May 2026 19:10:45 -0700 Subject: [PATCH 035/406] BaseTools/GenFv: Parse ,XIP suffix for per-file rebase control Update ParseFvInf() to detect and strip ",XIP" suffix from EFI_FILE_NAME values in the FV INF file. Store the per-file XIP flag in the new XipFile[] array in the FV_INFO structure. Add FileIndex parameter to FfsRebase() so it can look up the XIP flag for the current file. When ForceRebase is TRUE, only rebase files that have their XipFile[] entry set to TRUE. Signed-off-by: Michael D Kinney --- BaseTools/Source/C/GenFv/GenFvInternalLib.c | 24 +++++++++++++++++++-- BaseTools/Source/C/GenFv/GenFvInternalLib.h | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c index 3f621d190f..20d16ef80f 100644 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c @@ -142,6 +142,7 @@ Returns: UINTN Number; EFI_STATUS Status; EFI_GUID GuidValue; + CHAR8 *XipFlag; // // Read the FV base address @@ -325,6 +326,16 @@ Returns: Status = FindToken (InfFile, FILES_SECTION_STRING, EFI_FILE_NAME_STRING, Index, Value); if (Status == EFI_SUCCESS) { + // + // Check for ,XIP suffix indicating this file should be rebased + // + XipFlag = strrchr (Value, ','); + if (XipFlag != NULL && stricmp (XipFlag, ",XIP") == 0) { + *XipFlag = '\0'; + FvInfo->XipFile[Number + Index] = TRUE; + } else { + FvInfo->XipFile[Number + Index] = FALSE; + } // // Add the file // @@ -1289,7 +1300,7 @@ Returns: // Rebase the PE or TE image in FileBuffer of FFS file for XIP // Rebase for the debug genfvmap tool // - Status = FfsRebase (FvInfo, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER *) FileBuffer, (UINTN) *VtfFileImage - (UINTN) FvImage->FileImage, FvMapFile); + Status = FfsRebase (FvInfo, Index, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER *) FileBuffer, (UINTN) *VtfFileImage - (UINTN) FvImage->FileImage, FvMapFile); if (EFI_ERROR (Status)) { Error (NULL, 0, 3000, "Invalid", "Could not rebase %s.", FvInfo->FvFiles[Index]); return Status; @@ -1335,7 +1346,7 @@ Returns: // Rebase the PE or TE image in FileBuffer of FFS file for XIP. // Rebase Bs and Rt drivers for the debug genfvmap tool. // - Status = FfsRebase (FvInfo, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER *) FileBuffer, (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage, FvMapFile); + Status = FfsRebase (FvInfo, Index, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER *) FileBuffer, (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage, FvMapFile); if (EFI_ERROR (Status)) { Error (NULL, 0, 3000, "Invalid", "Could not rebase %s.", FvInfo->FvFiles[Index]); return Status; @@ -3377,6 +3388,7 @@ Returns: EFI_STATUS FfsRebase ( IN OUT FV_INFO *FvInfo, + IN UINTN FileIndex, IN CHAR8 *FileName, IN OUT EFI_FFS_FILE_HEADER *FfsFile, IN UINTN XipOffset, @@ -3451,6 +3463,14 @@ Returns: return EFI_SUCCESS; } + // + // If ForceRebase Flag specified to TRUE, only rebase files marked with XIP. + // + if (FvInfo->ForceRebase == 1) { + if (!FvInfo->XipFile[FileIndex]) { + return EFI_SUCCESS; + } + } XipBase = FvInfo->BaseAddress + XipOffset; diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.h b/BaseTools/Source/C/GenFv/GenFvInternalLib.h index 3f8d2e73b0..67970286d8 100644 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.h +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.h @@ -209,6 +209,7 @@ typedef struct { CHAR8 FvName[MAX_LONG_FILE_PATH]; EFI_FV_BLOCK_MAP_ENTRY FvBlocks[MAX_NUMBER_OF_FV_BLOCKS]; CHAR8 FvFiles[MAX_NUMBER_OF_FILES_IN_FV][MAX_LONG_FILE_PATH]; + BOOLEAN XipFile[MAX_NUMBER_OF_FILES_IN_FV]; UINT32 SizeofFvFiles[MAX_NUMBER_OF_FILES_IN_FV]; BOOLEAN IsPiFvImage; INT8 ForceRebase; @@ -329,6 +330,7 @@ CalculateFvSize ( EFI_STATUS FfsRebase ( IN OUT FV_INFO *FvInfo, + IN UINTN FileIndex, IN CHAR8 *FileName, IN OUT EFI_FFS_FILE_HEADER *FfsFile, IN UINTN XipOffset, From 80bf0137c1ef00047769f3ea7b05f93ec9696b1c Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Tue, 5 May 2026 19:54:55 -0700 Subject: [PATCH 036/406] BaseTools/Tests: Add unit and functional tests for XIP rebase Add TestGenFvXip.py with 19 parameterized subtests covering the complete XIP rebase decision matrix: - 11 unit subtests validating DetermineXipEnabled() with RuleComplexFile and RuleSimpleFile objects covering Xip attribute parsing (TRUE/FALSE/None, case insensitive, boolean vs string). - 8 functional subtests that run real edk2 builds with generated DSC/FDF files exercising all ForceRebase/BaseAddress/Xip combinations. Each test verifies: 1. FV INF file contains correct ,XIP suffixes 2. FV map file shows correct rebase status (Fixed Flash Address) 3. PE/COFF ImageBase in the FV binary matches expected value Signed-off-by: Michael D Kinney --- BaseTools/Tests/TestGenFvXip.py | 832 ++++++++++++++++++++++++++++++++ BaseTools/Tests/conftest.py | 17 + 2 files changed, 849 insertions(+) create mode 100644 BaseTools/Tests/TestGenFvXip.py create mode 100644 BaseTools/Tests/conftest.py diff --git a/BaseTools/Tests/TestGenFvXip.py b/BaseTools/Tests/TestGenFvXip.py new file mode 100644 index 0000000000..d7ac971484 --- /dev/null +++ b/BaseTools/Tests/TestGenFvXip.py @@ -0,0 +1,832 @@ +## @file +# Unit and functional tests for GenFv XIP rebase behavior +# +# Tests the ,XIP suffix generation in Python GenFds and the +# ForceRebase/XIP decision logic in C GenFv. +# +# Test Plan Summary: +# +# FfsRebase() in GenFvInternalLib.c decides whether to rebase each PE/COFF +# image in an FV based on three inputs: ForceRebase, BaseAddress, and XipFile[]. +# +# ForceRebase BaseAddress XipFile[] Result +# ----------- ----------- --------- --------------------------------- +# -1 (unset) 0 any No rebase (early return) +# 0 (FALSE) any any No rebase (early return) +# 1 (TRUE) any FALSE No rebase (skip non-XIP file) +# 1 (TRUE) any TRUE Rebase (XIP file selected) +# -1 (unset) != 0 any Rebase ALL files (legacy path) +# +# Unit Tests (TestDetermineXipEnabled): +# 11 parameterized subtests calling FfsInfStatement.DetermineXipEnabled() +# with RuleComplexFile and RuleSimpleFile objects to verify Xip attribute +# parsing (TRUE/FALSE/None, case insensitive, boolean vs string). +# +# Functional Tests (TestFunctionalBuildXipRebase): +# 8 test cases using real edk2 builds with generated DSC/FDF files +# containing a test package (2 PEIMs + 1 DXE driver). Each test +# verifies: +# 1. FV INF file has correct ,XIP suffix on EFI_FILE_NAME entries +# 2. FV map file shows correct rebase status (Fixed Flash Address) +# 3. PE/COFF ImageBase in the FV binary matches expected value +# +# TC1: ForceRebase=unset, Base=0 -> no rebase +# TC2: ForceRebase=unset, Base!=0 -> rebase all (legacy) +# TC3: ForceRebase=FALSE, Base!=0 -> no rebase +# TC4: ForceRebase=TRUE, all Xip=TRUE -> rebase all +# TC5: ForceRebase=TRUE, selective Xip -> rebase only Xip=TRUE +# TC6: ForceRebase=TRUE, no Xip -> no rebase +# TC7: ForceRebase=TRUE, mixed Xip -> rebase Xip=TRUE only +# TC8: ForceRebase=TRUE, Base=0, Xip -> rebase (force overrides) +# +# Copyright (c) 2026, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +import ctypes +import os +import re +import shutil +import subprocess +import sys +import threading +import unittest +from pathlib import Path + +# Add BaseTools Python source to path +_TESTS_DIR = Path(__file__).resolve().parent +_PYTHON_SRC = str(_TESTS_DIR.parent / 'Source' / 'Python') +if _PYTHON_SRC not in sys.path: + sys.path.insert(0, _PYTHON_SRC) + +from GenFds.RuleComplexFile import RuleComplexFile +from GenFds.RuleSimpleFile import RuleSimpleFile +from GenFds.EfiSection import EfiSection +from GenFds.FfsInfStatement import FfsInfStatement +from FirmwareStorageFormat.FvHeader import EFI_FIRMWARE_VOLUME_HEADER +from FirmwareStorageFormat.FfsFileHeader import EFI_FFS_FILE_HEADER +from FirmwareStorageFormat.SectionHeader import ( + EFI_COMMON_SECTION_HEADER, + EFI_SECTION_PE32, +) +from FirmwareStorageFormat.PECOFFHeader import ( + EFI_IMAGE_DOS_HEADER, + EFI_IMAGE_DOS_SIGNATURE, + EFI_IMAGE_NT_HEADERS32, + EFI_IMAGE_NT_HEADERS64, + EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC, + EFI_IMAGE_NT_SIGNATURE, +) + + +class TestDetermineXipEnabled(unittest.TestCase): + """Test FfsInfStatement.DetermineXipEnabled() with real Rule objects. + + This calls the actual production code that determines whether XIP + is enabled based on a Rule object's Xip attribute(s). + """ + + _UNSET = object() # sentinel: do not set the Xip attribute + + # (rule_class, section_xip_list, rule_xip, expected, description) + # + # For RuleComplexFile: + # section_xip_list is a list of Xip values per EfiSection (_UNSET = no attr). + # rule_xip is ignored (_UNSET). + # + # For RuleSimpleFile: + # section_xip_list is None (no SectionList used). + # rule_xip is the value to assign to rule.Xip (_UNSET = leave default). + TEST_CASES = [ + # RuleComplexFile: one section with Xip='TRUE'. + # DetermineXipEnabled iterates SectionList looking for any section with + # Xip set to 'TRUE' (case-insensitive string match). + # A single section set to 'TRUE' should return True (XIP-eligible). + (RuleComplexFile, ['TRUE'], _UNSET, True, + 'Complex: section Xip=TRUE'), + # RuleComplexFile: Xip='true' (lowercase). + # The FDF parser normalizes keywords but DetermineXipEnabled uses + # case-insensitive matching. Verifies 'true' is equivalent to 'TRUE'. + (RuleComplexFile, ['true'], _UNSET, True, + 'Complex: section Xip=true (case insensitive)'), + # RuleComplexFile: one section with Xip='FALSE'. + # An explicit 'FALSE' must not be confused with 'TRUE'. Confirms the + # string 'FALSE' does not accidentally match the 'TRUE' comparison. + (RuleComplexFile, ['FALSE'], _UNSET, False, + 'Complex: section Xip=FALSE'), + # RuleComplexFile: section with no Xip attribute set. + # EfiSection.__init__ does not set Xip by default. Verifies that when + # the FDF rule omits the Xip keyword, DetermineXipEnabled returns False + # without raising an AttributeError. + (RuleComplexFile, [_UNSET], _UNSET, False, + 'Complex: section with no Xip attribute'), + # RuleComplexFile: two sections, only the second has Xip=TRUE. + # DetermineXipEnabled should return True if ANY section in the list has + # Xip=TRUE, not just the first. Tests iteration with Xip=TRUE at index 1. + (RuleComplexFile, [_UNSET, 'TRUE'], _UNSET, True, + 'Complex: multiple sections, one Xip=TRUE'), + # RuleComplexFile: empty SectionList. + # Edge case: a complex rule with no sections should safely return False + # without raising an exception from iterating an empty list. + (RuleComplexFile, [], _UNSET, False, + 'Complex: empty section list'), + # RuleSimpleFile: Xip='TRUE' (string). + # Unlike RuleComplexFile, RuleSimpleFile stores Xip directly on the + # rule object. Verifies the string 'TRUE' path via isinstance check. + (RuleSimpleFile, None, 'TRUE', True, + 'Simple: Xip=TRUE (string)'), + # RuleSimpleFile: Xip=True (Python boolean). + # The FDF parser may set Xip as a boolean True rather than the string + # 'TRUE'. Verifies that a Python boolean True is recognized as XIP. + (RuleSimpleFile, None, True, True, + 'Simple: Xip=True (boolean)'), + # RuleSimpleFile: Xip='FALSE' (string). + # Verifies that an explicit 'FALSE' string causes DetermineXipEnabled + # to return False. Complement of the 'TRUE' string test. + (RuleSimpleFile, None, 'FALSE', False, + 'Simple: Xip=FALSE'), + # RuleSimpleFile: default Xip value from RuleClassObject.__init__. + # When constructed without setting Xip, the default is False (boolean). + # Represents the common case where the FDF rule omits the Xip keyword. + (RuleSimpleFile, None, _UNSET, False, + 'Simple: default Xip (not set)'), + # RuleSimpleFile: Xip=None. + # Edge case: if code or a parser bug sets Xip=None, it should be + # treated as falsy and return False rather than raising a TypeError. + (RuleSimpleFile, None, None, False, + 'Simple: Xip=None'), + ] + + def test_determine_xip_enabled(self) -> None: + """Parameterized test for DetermineXipEnabled with Rule objects.""" + for rule_class, section_xip_list, rule_xip, expected, desc in self.TEST_CASES: + with self.subTest(desc): + rule = rule_class() + if section_xip_list is not None: + # RuleComplexFile: build SectionList + rule.SectionList = [] + for xip_val in section_xip_list: + sect = EfiSection() + if xip_val is not self._UNSET: + sect.Xip = xip_val + rule.SectionList.append(sect) + elif rule_xip is not self._UNSET: + # RuleSimpleFile: set Xip on rule + rule.Xip = rule_xip + self.assertEqual( + FfsInfStatement.DetermineXipEnabled(rule), expected + ) + + +class TestFunctionalBuildXipRebase(unittest.TestCase): + """Functional tests that build with generated DSC/FDF files to exercise + all ForceRebase/BaseAddress/Xip combinations. + + Prerequisites: + - edksetup has been run (sets WORKSPACE and puts build in PATH) + - BaseTools C binaries built (GenFv.exe, etc.) + - A working compiler toolchain (VS2022, GCC5, etc.) + + Each test case verifies: + 1. FV INF file has correct ,XIP suffix on EFI_FILE_NAME entries + 2. FV map file shows correct rebase status (Fixed Flash Address) + 3. PE/COFF ImageBase in the FV binary matches expected value + """ + + WORKSPACE = None + TOOLCHAIN = None + BUILD_AVAILABLE = False + + # Module names in FV file order (matches INF listing in FDF_TEMPLATE) + _MODULE_NAMES = ('TestPeim', 'TestPeim2', 'TestDxeDriver') + + # --- File content constants / templates --- + + DEC_CONTENT = """\ +[Defines] + DEC_SPECIFICATION = 0x00010005 + PACKAGE_NAME = TestXipRebasePkg + PACKAGE_GUID = FC530350-34AA-4498-88F5-BF71987785B2 + PACKAGE_VERSION = 1.0 +""" + + PEIM_C_TEMPLATE = """\ +#include +#include + +EFI_STATUS +EFIAPI +{entry_point} ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{{ + return EFI_SUCCESS; +}} +""" + + PEIM_INF_TEMPLATE = """\ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = {base_name} + FILE_GUID = {file_guid} + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + ENTRY_POINT = {entry_point} + +[Sources] + {source_file} + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + PeimEntryPoint + +[Depex] + TRUE +""" + + DXE_C_SOURCE = """\ +#include +#include + +EFI_STATUS +EFIAPI +TestDxeDriverEntry ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return EFI_SUCCESS; +} +""" + + DXE_INF = """\ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = TestDxeDriver + FILE_GUID = FEC0E1C9-544F-493E-9BD1-91263C7970FC + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = TestDxeDriverEntry + +[Sources] + TestDxeDriver.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + +[Depex] + TRUE +""" + + DSC_CONTENT = """\ +[Defines] + PLATFORM_NAME = TestXipRebase + PLATFORM_GUID = A44E9966-C1A1-47E8-8B21-8B773705DD79 + PLATFORM_VERSION = 1.0 + DSC_SPECIFICATION = 0x00010005 + OUTPUT_DIRECTORY = Build/TestXipRebase + SUPPORTED_ARCHITECTURES = X64 + BUILD_TARGETS = DEBUG + SKUID_IDENTIFIER = DEFAULT + +!include MdePkg/MdeLibs.dsc.inc + +[LibraryClasses] + PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf + +[Components] + TestXipRebasePkg/TestPeim/TestPeim.inf + TestXipRebasePkg/TestPeim2/TestPeim2.inf + TestXipRebasePkg/TestDxeDriver/TestDxeDriver.inf { + + MSFT:*_*_*_DLINK_FLAGS = /ALIGN:4096 /FILEALIGN:4096 + GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x1000 + } +""" + + PEIM2_RULE_TEMPLATE = """ +[Rule.Common.PEIM.PEIM2RULE] + FILE PEIM = $(NAMED_GUID) {{ + PE32 PE32 Align=Auto{peim2_xip_clause} $(INF_OUTPUT)/$(MODULE_NAME).efi + }} +""" + + FDF_TEMPLATE = """\ + +[FV.{fv_name}] +FvNameGuid = 15942B69-82DC-41DC-9F01-D60162870C4A +{base_line}\ +{force_line}\ +BlockSize = 0x10000 +NumBlocks = 0x10 +FvAlignment = 16 +ERASE_POLARITY = 1 +MEMORY_MAPPED = TRUE +STICKY_WRITE = TRUE +LOCK_CAP = TRUE +LOCK_STATUS = TRUE +WRITE_DISABLED_CAP = TRUE +WRITE_ENABLED_CAP = TRUE +WRITE_STATUS = TRUE +WRITE_LOCK_CAP = TRUE +WRITE_LOCK_STATUS = TRUE +READ_DISABLED_CAP = TRUE +READ_ENABLED_CAP = TRUE +READ_STATUS = TRUE +READ_LOCK_CAP = TRUE +READ_LOCK_STATUS = TRUE + +INF TestXipRebasePkg/TestPeim/TestPeim.inf +{peim2_inf_line} +INF TestXipRebasePkg/TestDxeDriver/TestDxeDriver.inf + +[Rule.Common.PEIM] + FILE PEIM = $(NAMED_GUID) {{ + PE32 PE32 Align=Auto{peim1_xip_clause} $(INF_OUTPUT)/$(MODULE_NAME).efi + }} +{peim2_rule}\ +[Rule.Common.DXE_DRIVER] + FILE DRIVER = $(NAMED_GUID) {{ + PE32 PE32{dxe_xip_clause} $(INF_OUTPUT)/$(MODULE_NAME).efi + }} +""" + + @classmethod + def _detect_toolchain(cls) -> str: + """Get toolchain from --toolchain command line option (default: VS2022). + + Returns: + Toolchain tag string (e.g. 'VS2022', 'GCC5'). + """ + for i, arg in enumerate(sys.argv): + if arg == '--toolchain' and i + 1 < len(sys.argv): + return sys.argv[i + 1] + if arg.startswith('--toolchain='): + return arg.split('=', 1)[1] + return 'VS2022' + + @classmethod + def setUpClass(cls) -> None: + cls.WORKSPACE = os.environ.get('WORKSPACE') + if cls.WORKSPACE is None: + return + cls.TOOLCHAIN = cls._detect_toolchain() + try: + result = subprocess.run( + 'build --version', capture_output=True, text=True, + timeout=30, cwd=cls.WORKSPACE, shell=True + ) + cls.BUILD_AVAILABLE = result.returncode == 0 + except (FileNotFoundError, subprocess.TimeoutExpired): + pass + + @classmethod + def tearDownClass(cls) -> None: + """Clean up generated test package directory.""" + if cls.WORKSPACE: + pkg_dir = Path(cls.WORKSPACE, 'TestXipRebasePkg') + if pkg_dir.is_dir(): + shutil.rmtree(pkg_dir, ignore_errors=True) + + def setUp(self) -> None: + if self.WORKSPACE is None: + self.fail("WORKSPACE environment variable is not set. " + "Run edksetup before running tests.") + if not self.BUILD_AVAILABLE: + self.fail("edk2 'build' command not found in PATH. " + "Run edksetup before running tests.") + + # --- Test package generation --- + + def _create_test_package(self) -> str: + """Create a minimal test package with two PEIMs and one DXE driver. + + Returns: + Absolute path to the created package directory. + """ + pkg = Path(self.WORKSPACE, 'TestXipRebasePkg') + pkg.mkdir(parents=True, exist_ok=True) + (pkg / 'TestXipRebasePkg.dec').write_text(self.DEC_CONTENT) + + # Generate PEIM modules from template + for name, guid, entry in [ + ('TestPeim', 'F43835C3-245F-4951-9D35-8684B98328DA', 'TestPeimEntry'), + ('TestPeim2', '816C5A1F-23A8-485F-B005-D565FD01E303', 'TestPeim2Entry'), + ]: + mod = pkg / name + mod.mkdir(parents=True, exist_ok=True) + (mod / f'{name}.c').write_text( + self.PEIM_C_TEMPLATE.format(entry_point=entry)) + (mod / f'{name}.inf').write_text( + self.PEIM_INF_TEMPLATE.format( + base_name=name, file_guid=guid, + entry_point=entry, source_file=f'{name}.c')) + + # DXE driver (different includes/signature, not templated) + dxe = pkg / 'TestDxeDriver' + dxe.mkdir(parents=True, exist_ok=True) + (dxe / 'TestDxeDriver.c').write_text(self.DXE_C_SOURCE) + (dxe / 'TestDxeDriver.inf').write_text(self.DXE_INF) + + return str(pkg) + + def _generate_fdf(self, pkg_dir: str, fv_name: str, + base_address: str | None, force_rebase: str | None, + peim1_xip: str | None, peim2_xip: str | None, + dxe_xip: str | None) -> str: + """Generate an FDF file with the specified FV settings. + + Args: + pkg_dir: Package directory path. + fv_name: Name for the firmware volume. + base_address: Hex string (e.g. '0xFFF00000') or None. + force_rebase: 'TRUE', 'FALSE', or None. + peim1_xip: 'TRUE', 'FALSE', or None (omit Xip keyword). + peim2_xip: 'TRUE', 'FALSE', or None. + dxe_xip: 'TRUE', 'FALSE', or None. + + Returns: + Absolute path to the generated FDF file. + """ + def xip_clause(setting): + return f' Xip={setting}' if setting is not None else '' + + base_line = f'FvBaseAddress = {base_address}\n' if base_address is not None else '' + force_line = f'FvForceRebase = {force_rebase}\n' if force_rebase is not None else '' + + # Use RuleOverride when PEIM2 needs a different Xip than PEIM1 + if peim2_xip != peim1_xip: + peim2_inf_line = 'INF RuleOverride=PEIM2RULE TestXipRebasePkg/TestPeim2/TestPeim2.inf' + peim2_rule = self.PEIM2_RULE_TEMPLATE.format( + peim2_xip_clause=xip_clause(peim2_xip)) + else: + peim2_inf_line = 'INF TestXipRebasePkg/TestPeim2/TestPeim2.inf' + peim2_rule = '' + + fdf_content = self.FDF_TEMPLATE.format( + fv_name=fv_name, base_line=base_line, force_line=force_line, + peim2_inf_line=peim2_inf_line, + peim1_xip_clause=xip_clause(peim1_xip), + peim2_rule=peim2_rule, + dxe_xip_clause=xip_clause(dxe_xip), + ) + + fdf_path = Path(pkg_dir, 'TestXipRebase.fdf') + fdf_path.write_text(fdf_content) + return str(fdf_path) + + def _run_build(self, dsc_path: Path, fdf_path: str) -> tuple[int, str, str]: + """Run the edk2 build command and return (returncode, stdout, stderr). + + When verbose mode is enabled (-v / --verbose), streams build output + in real-time. + + Args: + dsc_path: Path to the DSC platform description file. + fdf_path: Path to the FDF flash description file. + + Returns: + Tuple of (returncode, stdout, stderr) from the build process. + """ + rel_dsc = os.path.relpath(dsc_path, self.WORKSPACE) + rel_fdf = os.path.relpath(fdf_path, self.WORKSPACE) + cmd = ( + f'build -p {rel_dsc} -f {rel_fdf}' + f' -a X64 -b DEBUG -t {self.TOOLCHAIN} --quiet' + ) + + proc = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + text=True, bufsize=1, cwd=self.WORKSPACE, shell=True, + ) + stdout_lines, stderr_lines = [], [] + verbose = '-v' in sys.argv or '--verbose' in sys.argv + + def reader(pipe, sink, stream): + for line in pipe: + if stream: + stream.write(line) + stream.flush() + sink.append(line) + + threads = [ + threading.Thread(target=reader, + args=(proc.stdout, stdout_lines, + sys.stdout if verbose else None)), + threading.Thread(target=reader, + args=(proc.stderr, stderr_lines, + sys.stderr if verbose else None)), + ] + for t in threads: + t.start() + for t in threads: + t.join(timeout=300) + proc.stdout.close() + proc.stderr.close() + proc.wait(timeout=300) + return proc.returncode, ''.join(stdout_lines), ''.join(stderr_lines) + + # --- Verification helpers --- + + def _fv_output_path(self, filename: str) -> Path: + """Return the path to a file in the FV output directory. + + Args: + filename: Name of the file (e.g. 'TESTFV1.Fv', 'TESTFV1.inf'). + + Returns: + Full path to the file under Build/TestXipRebase/DEBUG_/FV/. + """ + return Path( + self.WORKSPACE, 'Build', 'TestXipRebase', + f'DEBUG_{self.TOOLCHAIN}', 'FV', filename + ) + + def _read_fv_file(self, filename: str) -> str | None: + """Read a generated FV output file as text, or None if missing. + + Args: + filename: Name of the file in the FV output directory. + + Returns: + File contents as a string, or None if the file does not exist. + """ + path = self._fv_output_path(filename) + return path.read_text() if path.is_file() else None + + def _check_module_rebased(self, map_content: str, module_name: str, + expect_rebased: bool) -> None: + """Assert a module's rebase status in the FV map file. + + A rebased module has '(Fixed Flash Address, BaseAddress=0x...' in + its map entry. A non-rebased module lacks this marker. + + Args: + map_content: Text content of the FV .map file. + module_name: Module base name to search for (e.g. 'TestPeim'). + expect_rebased: True if the module should have been rebased. + """ + self.assertIsNotNone(map_content, "FV map file not found") + found = bool(re.search( + rf'{re.escape(module_name)}.*\(Fixed Flash Address', + map_content, re.IGNORECASE + )) + verb = "to be" if expect_rebased else "NOT to be" + self.assertEqual( + found, expect_rebased, + f"Expected {module_name} {verb} rebased.\n" + f"Map excerpt: {map_content[:500]}" + ) + + def _get_pe_image_bases(self, fv_name: str) -> list[tuple[int, int]] | None: + """Extract (fv_offset, image_base) for each PE/COFF image in the FV. + + Walks the FV binary using ctypes structures: + EFI_FIRMWARE_VOLUME_HEADER -> EFI_FFS_FILE_HEADER -> + EFI_COMMON_SECTION_HEADER -> EFI_IMAGE_DOS_HEADER -> + EFI_IMAGE_OPTIONAL_HEADER32 / EFI_IMAGE_OPTIONAL_HEADER64. + + Args: + fv_name: Firmware volume name (e.g. 'TESTFV1'). + + Returns: + Sorted list of (fv_offset, image_base) tuples, or None if the + FV file does not exist. + """ + fv_path = self._fv_output_path(f'{fv_name}.Fv') + if not fv_path.is_file(): + return None + + fv_data = fv_path.read_bytes() + fv_hdr = EFI_FIRMWARE_VOLUME_HEADER.from_buffer_copy(fv_data) + ffs_offset = fv_hdr.HeaderLength + results = [] + + # Walk FFS files within the FV + while ffs_offset + ctypes.sizeof(EFI_FFS_FILE_HEADER) <= len(fv_data): + ffs_offset = (ffs_offset + 7) & ~7 # FFS 8-byte alignment + if ffs_offset + ctypes.sizeof(EFI_FFS_FILE_HEADER) > len(fv_data): + break + + ffs_hdr = EFI_FFS_FILE_HEADER.from_buffer_copy(fv_data, ffs_offset) + file_size = ffs_hdr.FFS_FILE_SIZE + if file_size in (0, 0xFFFFFF): + break # End of FFS files or pad + + file_end = ffs_offset + file_size + sect_offset = ffs_offset + ffs_hdr.HeaderLength + + # Walk sections within this FFS file + while sect_offset + ctypes.sizeof(EFI_COMMON_SECTION_HEADER) <= file_end: + sect_offset = (sect_offset + 3) & ~3 # Section 4-byte alignment + if sect_offset + ctypes.sizeof(EFI_COMMON_SECTION_HEADER) > file_end: + break + + sect_hdr = EFI_COMMON_SECTION_HEADER.from_buffer_copy( + fv_data, sect_offset) + sect_size = sect_hdr.SECTION_SIZE + if sect_size == 0: + break + + if sect_hdr.Type == EFI_SECTION_PE32: + pe_offset = sect_offset + sect_hdr.Common_Header_Size() + image_base = self._parse_pe_image_base( + fv_data, pe_offset) + if image_base is not None: + results.append((pe_offset, image_base)) + + sect_offset += sect_size + + ffs_offset += file_size + + results.sort(key=lambda x: x[0]) + return results + + @staticmethod + def _parse_pe_image_base(data: bytes, offset: int) -> int | None: + """Parse ImageBase from a PE/COFF image at the given offset. + + Uses EFI_IMAGE_DOS_HEADER to locate the PE signature, then reads + EFI_IMAGE_NT_HEADERS32 or EFI_IMAGE_NT_HEADERS64 to extract ImageBase. + + Args: + data: Raw bytes of the FV binary. + offset: Byte offset where the PE/COFF image starts. + + Returns: + ImageBase value (int), or None if the image cannot be parsed. + """ + if offset + ctypes.sizeof(EFI_IMAGE_DOS_HEADER) > len(data): + return None + dos_hdr = EFI_IMAGE_DOS_HEADER.from_buffer_copy(data, offset) + if dos_hdr.e_magic != EFI_IMAGE_DOS_SIGNATURE: + return None + + nt_offset = offset + dos_hdr.e_lfanew + + # Read as NT_HEADERS32 first (smaller); check magic to decide format + if nt_offset + ctypes.sizeof(EFI_IMAGE_NT_HEADERS32) > len(data): + return None + nt32 = EFI_IMAGE_NT_HEADERS32.from_buffer_copy(data, nt_offset) + if nt32.Signature != EFI_IMAGE_NT_SIGNATURE: + return None + + if nt32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC: + # PE32+: re-read with the larger NT_HEADERS64 structure + if nt_offset + ctypes.sizeof(EFI_IMAGE_NT_HEADERS64) > len(data): + return None + nt64 = EFI_IMAGE_NT_HEADERS64.from_buffer_copy(data, nt_offset) + return nt64.OptionalHeader.ImageBase + return nt32.OptionalHeader.ImageBase + + def _check_pe_image_base(self, fv_name: str, base_address: str | None, + file_index: int, expect_rebased: bool) -> None: + """Assert that a PE/COFF image in the FV has the correct ImageBase. + + A rebased image has ImageBase = FvBaseAddress + fv_offset. + A non-rebased image retains its link-time ImageBase of 0. + + Args: + fv_name: Firmware volume name (e.g. 'TESTFV1'). + base_address: FvBaseAddress hex string or None. + file_index: Zero-based index of the PE image in FV file order. + expect_rebased: True if the image should have been rebased. + """ + pe_images = self._get_pe_image_bases(fv_name) + self.assertIsNotNone(pe_images, f"Could not read FV for {fv_name}") + self.assertGreater( + len(pe_images), file_index, + f"FV {fv_name} has {len(pe_images)} PE images, need >= {file_index + 1}") + + fv_offset, image_base = pe_images[file_index] + fv_base = int(base_address, 16) if isinstance(base_address, str) else (base_address or 0) + expected = (fv_base + fv_offset) if expect_rebased else 0 + + self.assertEqual( + image_base, expected, + f"File #{file_index} @ FV+0x{fv_offset:X}: " + f"ImageBase=0x{image_base:X}, expected 0x{expected:X}" + f"{'' if expect_rebased else ' (not rebased)'}" + ) + + def _build_and_verify(self, fv_name: str, base_address: str | None, + force_rebase: str | None, peim1_xip: str | None, + peim2_xip: str | None, dxe_xip: str | None, + expect_rebase: tuple[bool, bool, bool]) -> None: + """Build an FV with the given configuration and verify all outputs. + + Args: + fv_name: Firmware volume name. + base_address: FvBaseAddress hex string or None. + force_rebase: FvForceRebase setting ('TRUE', 'FALSE', or None). + peim1_xip: Xip= keyword for TestPeim ('TRUE', 'FALSE', or None). + peim2_xip: Xip= keyword for TestPeim2 ('TRUE', 'FALSE', or None). + dxe_xip: Xip= keyword for TestDxeDriver ('TRUE', 'FALSE', or None). + expect_rebase: Tuple of 3 bools (peim1, peim2, dxe) indicating + whether each module should be rebased. + """ + pkg_dir = self._create_test_package() + dsc_path = Path(pkg_dir, 'TestXipRebase.dsc') + dsc_path.write_text(self.DSC_CONTENT) + fdf_path = self._generate_fdf( + pkg_dir, fv_name, base_address, force_rebase, + peim1_xip, peim2_xip, dxe_xip) + + rc, stdout, stderr = self._run_build(dsc_path, fdf_path) + self.assertEqual(rc, 0, + f"Build failed (rc={rc}).\nstdout:\n{stdout}\nstderr:\n{stderr}") + + # Verify ,XIP suffix count in FV INF file + # (,XIP suffix is present when the FDF rule has Xip=TRUE) + inf_content = self._read_fv_file(f'{fv_name}.inf') + self.assertIsNotNone(inf_content, f"FV INF file not found for {fv_name}") + efi_lines = [l for l in inf_content.splitlines() if 'EFI_FILE_NAME' in l] + xip_count = sum(1 for l in efi_lines if l.rstrip().endswith(',XIP')) + expected_xip = sum(x == 'TRUE' for x in (peim1_xip, peim2_xip, dxe_xip)) + self.assertEqual(xip_count, expected_xip, + f"Expected {expected_xip} ,XIP lines, got {xip_count}.\n" + f"INF content:\n{inf_content}") + + # Verify rebase status in map file and PE/COFF ImageBase in FV binary + map_content = self._read_fv_file(f'{fv_name}.Fv.map') + self.assertIsNotNone(map_content, f"FV map file not found for {fv_name}") + + for idx, (name, rebased) in enumerate( + zip(self._MODULE_NAMES, expect_rebase)): + self._check_module_rebased(map_content, name, rebased) + self._check_pe_image_base(fv_name, base_address, idx, rebased) + + # =================================================================== + # Test case table (matches behavior matrix from test plan header) + # =================================================================== + + # (fv_name, base_address, force_rebase, + # peim1_xip, peim2_xip, dxe_xip, + # (expect_peim1_rebase, expect_peim2_rebase, expect_dxe_rebase), + # description) + TEST_CASES = [ + # TC1: ForceRebase not specified, BaseAddress defaults to 0. + # Early return path: (BaseAddress==0 && ForceRebase==-1). + # No files are rebased. PEIMs have ,XIP suffix (Xip=TRUE in rule). + ('TESTFV1', None, None, 'TRUE', 'TRUE', None, + (False, False, False), 'TC1: ForceRebase=unset, Base=0 -> no rebase'), + # TC2: ForceRebase not specified, BaseAddress!=0. + # Legacy path: (BaseAddress!=0 && ForceRebase==-1). + # ALL files are rebased regardless of XIP status. + ('TESTFV2', '0x00800000', None, 'TRUE', 'TRUE', None, + (True, True, True), 'TC2: ForceRebase=unset, Base!=0 -> rebase all (legacy)'), + # TC3: ForceRebase=FALSE with BaseAddress!=0. + # Early return path: (ForceRebase==0). + # No files are rebased even though all have Xip=TRUE. + ('TESTFV3', '0x00800000', 'FALSE', 'TRUE', 'TRUE', 'TRUE', + (False, False, False), 'TC3: ForceRebase=FALSE -> no rebase'), + # TC4: ForceRebase=TRUE, all three files have Xip=TRUE. + # All files match (ForceRebase==1 && XipFile[i]==TRUE) and are rebased. + ('TESTFV4', '0x00800000', 'TRUE', 'TRUE', 'TRUE', 'TRUE', + (True, True, True), 'TC4: ForceRebase=TRUE, all Xip=TRUE -> rebase all'), + # TC5: ForceRebase=TRUE, PEIMs have Xip=TRUE, DXE has no Xip. + # Selective rebase: PEIMs rebased, DXE skipped. + ('TESTFV5', '0x00800000', 'TRUE', 'TRUE', 'TRUE', None, + (True, True, False), 'TC5: ForceRebase=TRUE, selective Xip -> rebase Xip only'), + # TC6: ForceRebase=TRUE, no files have Xip keyword. + # All files have XipFile==FALSE, so none are rebased. + ('TESTFV6', '0x00800000', 'TRUE', None, None, None, + (False, False, False), 'TC6: ForceRebase=TRUE, no Xip -> no rebase'), + # TC7: ForceRebase=TRUE, PEIM1 has Xip=TRUE, PEIM2 has Xip=FALSE. + # Mixed XIP within same module type via RuleOverride. + # Only PEIM1 is rebased; PEIM2 and DXE are skipped. + ('TESTFV7', '0x00800000', 'TRUE', 'TRUE', 'FALSE', None, + (True, False, False), 'TC7: ForceRebase=TRUE, mixed Xip -> rebase Xip=TRUE only'), + # TC8: ForceRebase=TRUE, BaseAddress=0, PEIMs have Xip=TRUE. + # ForceRebase=TRUE overrides the (BaseAddress==0) early return. + # PEIMs are rebased to offset 0+fv_offset; DXE is skipped (no Xip). + ('TESTFV8', '0x0', 'TRUE', 'TRUE', 'TRUE', None, + (True, True, False), 'TC8: ForceRebase=TRUE, Base=0, Xip -> rebase (force overrides)'), + ] + + def test_xip_rebase_behavior(self) -> None: + """Parameterized test covering all ForceRebase/BaseAddress/Xip combos.""" + for (fv_name, base_address, force_rebase, + peim1_xip, peim2_xip, dxe_xip, + expect_rebase, description) in self.TEST_CASES: + with self.subTest(description): + self._build_and_verify( + fv_name, base_address, force_rebase, + peim1_xip, peim2_xip, dxe_xip, expect_rebase) + + +if __name__ == '__main__': + unittest.main() diff --git a/BaseTools/Tests/conftest.py b/BaseTools/Tests/conftest.py new file mode 100644 index 0000000000..151f21a6b4 --- /dev/null +++ b/BaseTools/Tests/conftest.py @@ -0,0 +1,17 @@ +## @file +# pytest configuration for BaseTools tests +# +# Copyright (c) 2026, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +import pytest + + +def pytest_addoption(parser): + parser.addoption( + "--toolchain", + default="VS2022", + help="EDK II toolchain tag (default: VS2022)" + ) From d6eb4c4965328395582b5f7c54997dad8fcf669c Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Tue, 19 May 2026 12:51:42 -0700 Subject: [PATCH 037/406] BaseTools/GenFds: Allow PE32 section keywords in any order Replace sequential if-statements for Align, Xip, and RELOCS_STRIPPED/RELOCS_RETAINED parsing in _GetEfiSection() with a while-loop that accepts these keywords in any permutation. Previously, specifying Xip before Align in a [Rule] PE32 section caused a Python stack trace. Signed-off-by: Michael D Kinney --- BaseTools/Source/Python/GenFds/FdfParser.py | 51 +++++++++++---------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index d8d09946fd..f61d0f299d 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -3893,33 +3893,34 @@ class FdfParser: raise Warning.Expected("Build number", self.FileName, self.CurrentLineNumber) EfiSectionObj.BuildNum = self._Token - if self._GetAlignment(): - if self._Token not in ALIGNMENTS: - raise Warning("Incorrect alignment '%s'" % self._Token, self.FileName, self.CurrentLineNumber) - if self._Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32) and (not SectionName == BINARY_FILE_TYPE_TE): - raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber) - EfiSectionObj.Alignment = self._Token - - if self._IsKeyword("Xip"): - if not self._IsToken(TAB_EQUAL_SPLIT): - raise Warning.ExpectedEquals(self.FileName, self.CurrentLineNumber) - if not self._GetNextWord(): - raise Warning.Expected("Xip value (TRUE/FALSE)", self.FileName, self.CurrentLineNumber) - XipValue = self._Token.strip().upper() - if XipValue not in {"TRUE", "FALSE"}: - raise Warning("Invalid Xip value '%s'" % XipValue, self.FileName, self.CurrentLineNumber) - EfiSectionObj.Xip = XipValue - - if self._IsKeyword('RELOCS_STRIPPED') or self._IsKeyword('RELOCS_RETAINED'): - if self._SectionCouldHaveRelocFlag(EfiSectionObj.SectionType): - if self._Token == 'RELOCS_STRIPPED': - EfiSectionObj.KeepReloc = False + while True: + if self._GetAlignment(): + if self._Token not in ALIGNMENTS: + raise Warning("Incorrect alignment '%s'" % self._Token, self.FileName, self.CurrentLineNumber) + if self._Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32) and (not SectionName == BINARY_FILE_TYPE_TE): + raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber) + EfiSectionObj.Alignment = self._Token + elif self._IsKeyword("Xip"): + if not self._IsToken(TAB_EQUAL_SPLIT): + raise Warning.ExpectedEquals(self.FileName, self.CurrentLineNumber) + if not self._GetNextWord(): + raise Warning.Expected("Xip value (TRUE/FALSE)", self.FileName, self.CurrentLineNumber) + XipValue = self._Token.strip().upper() + if XipValue not in {"TRUE", "FALSE"}: + raise Warning("Invalid Xip value '%s'" % XipValue, self.FileName, self.CurrentLineNumber) + EfiSectionObj.Xip = XipValue + elif self._IsKeyword('RELOCS_STRIPPED') or self._IsKeyword('RELOCS_RETAINED'): + if self._SectionCouldHaveRelocFlag(EfiSectionObj.SectionType): + if self._Token == 'RELOCS_STRIPPED': + EfiSectionObj.KeepReloc = False + else: + EfiSectionObj.KeepReloc = True + if Obj.KeepReloc is not None and Obj.KeepReloc != EfiSectionObj.KeepReloc: + raise Warning("Section type %s has reloc strip flag conflict with Rule" % EfiSectionObj.SectionType, self.FileName, self.CurrentLineNumber) else: - EfiSectionObj.KeepReloc = True - if Obj.KeepReloc is not None and Obj.KeepReloc != EfiSectionObj.KeepReloc: - raise Warning("Section type %s has reloc strip flag conflict with Rule" % EfiSectionObj.SectionType, self.FileName, self.CurrentLineNumber) + raise Warning("Section type %s could not have reloc strip flag" % EfiSectionObj.SectionType, self.FileName, self.CurrentLineNumber) else: - raise Warning("Section type %s could not have reloc strip flag" % EfiSectionObj.SectionType, self.FileName, self.CurrentLineNumber) + break if self._IsToken(TAB_VALUE_SPLIT): From 2a4022b6ae4652515aa215e00f856f899693a2a3 Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Tue, 19 May 2026 12:51:50 -0700 Subject: [PATCH 038/406] BaseTools/Tests: Add PE32 section keyword order parser tests Add TestFdfParserPe32KeywordOrder test class with 17 parameterized subtests covering all permutations of Align, Xip, and RELOCS_STRIPPED/RELOCS_RETAINED keywords in PE32 section statements. Tests verify pairwise orderings, all 6 three-keyword permutations, single-keyword cases, and Xip=FALSE/RELOCS_RETAINED variants. Signed-off-by: Michael D Kinney --- BaseTools/Tests/TestGenFvXip.py | 157 ++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) diff --git a/BaseTools/Tests/TestGenFvXip.py b/BaseTools/Tests/TestGenFvXip.py index d7ac971484..3991a1a900 100644 --- a/BaseTools/Tests/TestGenFvXip.py +++ b/BaseTools/Tests/TestGenFvXip.py @@ -828,5 +828,162 @@ INF TestXipRebasePkg/TestDxeDriver/TestDxeDriver.inf peim1_xip, peim2_xip, dxe_xip, expect_rebase) +class TestFdfParserPe32KeywordOrder(unittest.TestCase): + """Test that the FDF parser accepts PE32 section keywords in any order. + + The keywords Align, Xip, and RELOCS_STRIPPED/RELOCS_RETAINED should be + accepted in any permutation within a PE32 section statement in a [Rule]. + """ + + @classmethod + def setUpClass(cls): + """Set up environment for FdfParser imports.""" + import tempfile + cls._tmpdir = tempfile.mkdtemp(prefix='fdf_parser_test_') + # Set WORKSPACE so the parser doesn't crash + os.environ.setdefault('WORKSPACE', cls._tmpdir) + from GenFds.GenFdsGlobalVariable import GenFdsGlobalVariable + GenFdsGlobalVariable.WorkSpaceDir = cls._tmpdir + from Common import GlobalData + GlobalData.gFdfParser = None + GlobalData.gWorkspace = cls._tmpdir + + @classmethod + def tearDownClass(cls): + shutil.rmtree(cls._tmpdir, ignore_errors=True) + + def _parse_rule(self, pe32_section_line): + """Parse a [Rule] with the given PE32 section line and return the EfiSection.""" + import tempfile + from GenFds.FdfParser import FdfParser + from Common import GlobalData + + fdf_content = ( + "[Rule.Common.PEIM]\n" + " FILE PEIM = $(NAMED_GUID) {\n" + " " + pe32_section_line + "\n" + " }\n" + ) + fdf_path = os.path.join(self._tmpdir, 'test_order.fdf') + with open(fdf_path, 'w') as f: + f.write(fdf_content) + + parser = FdfParser(fdf_path) + # Manually set up parser state for rule parsing + parser.CurrentLineNumber = 3 + parser.CurrentOffsetWithinLine = 4 + # Re-read the profile to refresh file lines + parser.Profile.FileLinesList = fdf_content.splitlines(True) + + # Create a RuleComplexFile as the container object + from GenFds.RuleComplexFile import RuleComplexFile + obj = RuleComplexFile() + obj.FvFileType = 'PEIM' + obj.KeepReloc = None + obj.SectionList = [] + + result = parser._GetEfiSection(obj) + self.assertTrue(result, f"Parser failed to parse: {pe32_section_line}") + self.assertEqual(len(obj.SectionList), 1) + return obj.SectionList[0] + + # (pe32_line, expected_alignment, expected_xip, expected_keep_reloc, description) + TEST_CASES = [ + # Align before Xip (original supported order) + ('PE32 PE32 Align=8 Xip=TRUE', + '8', 'TRUE', None, + 'Align then Xip'), + # Xip before Align (previously caused stack trace) + ('PE32 PE32 Xip=TRUE Align=8', + '8', 'TRUE', None, + 'Xip then Align'), + # Align before RELOCS_STRIPPED + ('PE32 PE32 Align=16 RELOCS_STRIPPED', + '16', None, False, + 'Align then RELOCS_STRIPPED'), + # RELOCS_STRIPPED before Align + ('PE32 PE32 RELOCS_STRIPPED Align=16', + '16', None, False, + 'RELOCS_STRIPPED then Align'), + # Xip before RELOCS_STRIPPED + ('PE32 PE32 Xip=TRUE RELOCS_STRIPPED', + None, 'TRUE', False, + 'Xip then RELOCS_STRIPPED'), + # RELOCS_STRIPPED before Xip + ('PE32 PE32 RELOCS_STRIPPED Xip=TRUE', + None, 'TRUE', False, + 'RELOCS_STRIPPED then Xip'), + # All three: Align, Xip, RELOCS_STRIPPED + ('PE32 PE32 Align=16 Xip=TRUE RELOCS_STRIPPED', + '16', 'TRUE', False, + 'Align then Xip then RELOCS_STRIPPED'), + # All three: Xip, Align, RELOCS_STRIPPED + ('PE32 PE32 Xip=TRUE Align=16 RELOCS_STRIPPED', + '16', 'TRUE', False, + 'Xip then Align then RELOCS_STRIPPED'), + # All three: RELOCS_STRIPPED, Align, Xip + ('PE32 PE32 RELOCS_STRIPPED Align=16 Xip=TRUE', + '16', 'TRUE', False, + 'RELOCS_STRIPPED then Align then Xip'), + # All three: RELOCS_STRIPPED, Xip, Align + ('PE32 PE32 RELOCS_STRIPPED Xip=TRUE Align=16', + '16', 'TRUE', False, + 'RELOCS_STRIPPED then Xip then Align'), + # All three: Xip, RELOCS_STRIPPED, Align + ('PE32 PE32 Xip=TRUE RELOCS_STRIPPED Align=16', + '16', 'TRUE', False, + 'Xip then RELOCS_STRIPPED then Align'), + # All three: Align, RELOCS_STRIPPED, Xip + ('PE32 PE32 Align=16 RELOCS_STRIPPED Xip=TRUE', + '16', 'TRUE', False, + 'Align then RELOCS_STRIPPED then Xip'), + # Xip=FALSE + ('PE32 PE32 Xip=FALSE Align=8', + '8', 'FALSE', None, + 'Xip=FALSE then Align'), + # RELOCS_RETAINED variant + ('PE32 PE32 Xip=TRUE RELOCS_RETAINED Align=8', + '8', 'TRUE', True, + 'Xip then RELOCS_RETAINED then Align'), + # Only Xip (no Align, no Reloc) + ('PE32 PE32 Xip=TRUE', + None, 'TRUE', None, + 'Xip only'), + # Only Align (no Xip, no Reloc) + ('PE32 PE32 Align=32', + '32', None, None, + 'Align only'), + # Only RELOCS_STRIPPED (no Align, no Xip) + ('PE32 PE32 RELOCS_STRIPPED', + None, None, False, + 'RELOCS_STRIPPED only'), + ] + + def test_pe32_keyword_order(self) -> None: + """Parameterized test verifying PE32 section keywords in any order.""" + for (pe32_line, exp_align, exp_xip, exp_keep_reloc, desc) in self.TEST_CASES: + with self.subTest(desc): + section = self._parse_rule(pe32_line) + self.assertEqual(section.SectionType, 'PE32') + if exp_align is not None: + self.assertEqual(section.Alignment, exp_align) + else: + self.assertIn(section.Alignment, (None, '')) + if exp_xip is not None: + self.assertEqual(section.Xip, exp_xip) + else: + self.assertFalse( + hasattr(section, 'Xip') and section.Xip, + f"Expected no Xip but got {getattr(section, 'Xip', None)}" + ) + if exp_keep_reloc is not None: + self.assertEqual(section.KeepReloc, exp_keep_reloc) + else: + self.assertIsNone( + getattr(section, 'KeepReloc', None), + f"Expected no KeepReloc but got {section.KeepReloc}" + ) + + if __name__ == '__main__': unittest.main() From 57164cdc87cfc42083310062720d0a2eeef92bac Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Tue, 19 May 2026 13:07:19 -0700 Subject: [PATCH 039/406] BaseTools/GenFds: Fix FV attribute parser to allow any keyword order Fix _GetFvAttributes() to return True when it has successfully parsed at least one attribute before encountering a non-attribute keyword. Previously it always returned False on encountering an unrecognized word, even after consuming prior attributes. This caused the outer parsing loop to break prematurely when FvForceRebase, FvBaseAddress, or FvAlignment appeared between FV attribute flags (e.g. between ERASE_POLARITY and MEMORY_MAPPED), resulting in a Python stack trace. Move IsWordToken assignment to after successful attribute parsing and change the early return from 'return False' to 'return IsWordToken'. Signed-off-by: Michael D Kinney --- BaseTools/Source/Python/GenFds/FdfParser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index f61d0f299d..532f354b4d 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -2210,7 +2210,6 @@ class FdfParser: def _GetFvAttributes(self, FvObj): IsWordToken = False while self._GetNextWord(): - IsWordToken = True name = self._Token if name not in {"ERASE_POLARITY", "MEMORY_MAPPED", \ "STICKY_WRITE", "LOCK_CAP", "LOCK_STATUS", "WRITE_ENABLED_CAP", \ @@ -2219,7 +2218,7 @@ class FdfParser: "READ_LOCK_STATUS", "WRITE_LOCK_CAP", "WRITE_LOCK_STATUS", \ "WRITE_POLICY_RELIABLE", "WEAK_ALIGNMENT", "FvUsedSizeEnable"}: self._UndoToken() - return False + return IsWordToken if not self._IsToken(TAB_EQUAL_SPLIT): raise Warning.ExpectedEquals(self.FileName, self.CurrentLineNumber) @@ -2228,6 +2227,7 @@ class FdfParser: raise Warning.Expected("TRUE/FALSE (1/0)", self.FileName, self.CurrentLineNumber) FvObj.FvAttributeDict[name] = self._Token + IsWordToken = True return IsWordToken From 3a1cfddd9a12bcdbbbcd0ff98c87a8747d08e433 Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Tue, 19 May 2026 13:07:27 -0700 Subject: [PATCH 040/406] BaseTools/Tests: Add FV section keyword order parser tests Add TestFdfParserFvKeywordOrder test class with 8 parameterized subtests verifying that FV-level keywords (FvForceRebase, FvBaseAddress, FvAlignment) can be freely interleaved with FV attribute flags in any order within an [FV] section. Signed-off-by: Michael D Kinney --- BaseTools/Tests/TestGenFvXip.py | 115 ++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/BaseTools/Tests/TestGenFvXip.py b/BaseTools/Tests/TestGenFvXip.py index 3991a1a900..b497eae436 100644 --- a/BaseTools/Tests/TestGenFvXip.py +++ b/BaseTools/Tests/TestGenFvXip.py @@ -985,5 +985,120 @@ class TestFdfParserPe32KeywordOrder(unittest.TestCase): ) +class TestFdfParserFvKeywordOrder(unittest.TestCase): + """Test that the FDF parser accepts [FV] keywords in any order. + + FvForceRebase, FvBaseAddress, FvAlignment, and FV attributes like + ERASE_POLARITY, MEMORY_MAPPED should be accepted in any order. + Previously, FvForceRebase between two FV attributes (e.g. between + ERASE_POLARITY and MEMORY_MAPPED) caused a Python stack trace. + """ + + @classmethod + def setUpClass(cls): + """Set up environment for FdfParser imports.""" + import tempfile + cls._tmpdir = tempfile.mkdtemp(prefix='fdf_fv_parser_test_') + os.environ.setdefault('WORKSPACE', cls._tmpdir) + from GenFds.GenFdsGlobalVariable import GenFdsGlobalVariable + GenFdsGlobalVariable.WorkSpaceDir = cls._tmpdir + from Common import GlobalData + GlobalData.gFdfParser = None + GlobalData.gWorkspace = cls._tmpdir + + @classmethod + def tearDownClass(cls): + shutil.rmtree(cls._tmpdir, ignore_errors=True) + + def _parse_fv_section(self, fv_body): + """Parse an [FV] section and return the FV object.""" + from GenFds.FdfParser import FdfParser + from Common import GlobalData + + fdf_content = ( + "[FV.TESTFV]\n" + + fv_body + "\n" + ) + fdf_path = os.path.join(self._tmpdir, 'test_fv_order.fdf') + with open(fdf_path, 'w') as f: + f.write(fdf_content) + + parser = FdfParser(fdf_path) + parser.Profile.FileLinesList = fdf_content.splitlines(True) + # Position parser at start of FV body (line 2, offset 0) + parser.CurrentLineNumber = 2 + parser.CurrentOffsetWithinLine = 0 + + # Create FV object and parse the attributes/keywords + from GenFds.Fv import FV + fv_obj = FV(Name='TESTFV') + + # Use the same while loop the real parser uses + while True: + parser._GetSetStatements(fv_obj) + if not (parser._GetBlockStatement(fv_obj) or + parser._GetFvBaseAddress(fv_obj) or + parser._GetFvForceRebase(fv_obj) or + parser._GetFvAlignment(fv_obj) or + parser._GetFvAttributes(fv_obj) or + parser._GetFvNameGuid(fv_obj) or + parser._GetFvExtEntryStatement(fv_obj) or + parser._GetFvNameString(fv_obj)): + break + + return fv_obj + + # (fv_body, expected_attrs, expected_force_rebase, description) + TEST_CASES = [ + # FvForceRebase after all attributes (original working order) + ("ERASE_POLARITY = 1\nMEMORY_MAPPED = TRUE\nFvForceRebase = TRUE\n", + {'ERASE_POLARITY': '1', 'MEMORY_MAPPED': 'TRUE'}, True, + 'FvForceRebase after all attributes'), + # FvForceRebase before all attributes + ("FvForceRebase = TRUE\nERASE_POLARITY = 1\nMEMORY_MAPPED = TRUE\n", + {'ERASE_POLARITY': '1', 'MEMORY_MAPPED': 'TRUE'}, True, + 'FvForceRebase before all attributes'), + # FvForceRebase between ERASE_POLARITY and MEMORY_MAPPED + ("ERASE_POLARITY = 1\nFvForceRebase = TRUE\nMEMORY_MAPPED = TRUE\n", + {'ERASE_POLARITY': '1', 'MEMORY_MAPPED': 'TRUE'}, True, + 'FvForceRebase between attributes (previously crashed)'), + # FvForceRebase=FALSE between attributes + ("ERASE_POLARITY = 1\nFvForceRebase = FALSE\nMEMORY_MAPPED = TRUE\n", + {'ERASE_POLARITY': '1', 'MEMORY_MAPPED': 'TRUE'}, False, + 'FvForceRebase=FALSE between attributes'), + # Multiple attributes, FvForceRebase in the middle + ("ERASE_POLARITY = 1\nSTICKY_WRITE = TRUE\nFvForceRebase = TRUE\n" + "MEMORY_MAPPED = TRUE\nLOCK_CAP = TRUE\n", + {'ERASE_POLARITY': '1', 'STICKY_WRITE': 'TRUE', + 'MEMORY_MAPPED': 'TRUE', 'LOCK_CAP': 'TRUE'}, True, + 'FvForceRebase in middle of many attributes'), + # FvBaseAddress between attributes + ("ERASE_POLARITY = 1\nFvBaseAddress = 0x00800000\nMEMORY_MAPPED = TRUE\n", + {'ERASE_POLARITY': '1', 'MEMORY_MAPPED': 'TRUE'}, None, + 'FvBaseAddress between attributes'), + # FvAlignment between attributes + ("ERASE_POLARITY = 1\nFvAlignment = 16\nMEMORY_MAPPED = TRUE\n", + {'ERASE_POLARITY': '1', 'MEMORY_MAPPED': 'TRUE'}, None, + 'FvAlignment between attributes'), + # All interleaved: attr, FvForceRebase, attr, FvBaseAddress, attr + ("ERASE_POLARITY = 1\nFvForceRebase = TRUE\nSTICKY_WRITE = TRUE\n" + "FvBaseAddress = 0x00800000\nMEMORY_MAPPED = TRUE\n", + {'ERASE_POLARITY': '1', 'STICKY_WRITE': 'TRUE', 'MEMORY_MAPPED': 'TRUE'}, True, + 'Multiple keywords interleaved with attributes'), + ] + + def test_fv_keyword_order(self) -> None: + """Parameterized test verifying FV keywords accepted in any order.""" + for (fv_body, exp_attrs, exp_force_rebase, desc) in self.TEST_CASES: + with self.subTest(desc): + fv_obj = self._parse_fv_section(fv_body) + for attr_name, attr_val in exp_attrs.items(): + self.assertIn(attr_name, fv_obj.FvAttributeDict, + f"Missing attribute {attr_name}") + self.assertEqual(fv_obj.FvAttributeDict[attr_name], attr_val) + if exp_force_rebase is not None: + self.assertEqual(fv_obj.FvForceRebase, exp_force_rebase) + + if __name__ == '__main__': unittest.main() From d417f3ec344486368fa18912b6bdcb834c1c79cf Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Fri, 12 Jun 2026 07:16:26 -0700 Subject: [PATCH 041/406] MdeModulePkg: Dxe: Skip FV Extraction When FV3 HOB Found Currently, the DXE dispatcher will skip extracting an FV file when an FV2 HOB is found for it, as that indicates pre-DXE extracted it. However, the dispatcher does not check for FV3 HOBs, which also can describe extracted FVs. That can result in extracting the same FV in DXE that is already extracted, which can be a large performance hit. This updates the DXE dispatcher to check for the existence of either an FV2 or FV3 HOB for this FV and skip extracting if either is found. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c index d7c7147edd..4c9df94b3a 100644 --- a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c @@ -901,37 +901,39 @@ CoreAddToDriverList ( /** Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is - described by a EFI_HOB_FIRMWARE_VOLUME2 Hob. + described by a EFI_HOB_FIRMWARE_VOLUME2 or an extracted EFI_HOB_FIRMWARE_VOLUME3 Hob. @param FvNameGuid The FV image guid specified. @param DriverName The driver guid specified. - @retval TRUE This file is found in a EFI_HOB_FIRMWARE_VOLUME2 - Hob. + @retval TRUE This file is found in a EFI_HOB_FIRMWARE_VOLUME2 or + an extracted EFI_HOB_FIRMWARE_VOLUME3 Hob. @retval FALSE Not found. **/ +static BOOLEAN -FvFoundInHobFv2 ( +FvFoundInExtractedFvHob ( IN CONST EFI_GUID *FvNameGuid, IN CONST EFI_GUID *DriverName ) { - EFI_PEI_HOB_POINTERS HobFv2; + EFI_PEI_HOB_POINTERS Hob; - HobFv2.Raw = GetHobList (); - - while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) { - // - // Compare parent FvNameGuid and FileGuid both. - // - if (CompareGuid (DriverName, &HobFv2.FirmwareVolume2->FileName) && - CompareGuid (FvNameGuid, &HobFv2.FirmwareVolume2->FvName)) - { - return TRUE; + for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) { + if (CompareGuid (DriverName, &Hob.FirmwareVolume2->FileName) && + CompareGuid (FvNameGuid, &Hob.FirmwareVolume2->FvName)) + { + return TRUE; + } + } else if ((GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) && Hob.FirmwareVolume3->ExtractedFv) { + if (CompareGuid (DriverName, &Hob.FirmwareVolume3->FileName) && + CompareGuid (FvNameGuid, &Hob.FirmwareVolume3->FvName)) + { + return TRUE; + } } - - HobFv2.Raw = GET_NEXT_HOB (HobFv2); } return FALSE; @@ -1334,7 +1336,7 @@ CoreFwVolEventProtocolNotify ( // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already // been extracted. // - if (FvFoundInHobFv2 (&KnownHandle->FvNameGuid, &NameGuid)) { + if (FvFoundInExtractedFvHob (&KnownHandle->FvNameGuid, &NameGuid)) { continue; } From c3ba0416ce77b561c9d0c3867d99478d175d9432 Mon Sep 17 00:00:00 2001 From: Qihang Gao Date: Wed, 17 Jun 2026 16:39:35 +0800 Subject: [PATCH 042/406] MdeModulePkg/TerminalDxe: Change print level to eliminate interference The debug message introduced by PR#12282 was printed at DEBUG_INFO level, which caused screen corruption in the UEFI Shell when running in DEBUG mode. Change the print level to DEBUG_VERBOSE to keep the Shell output clean during normal DEBUG builds while still retaining the message for verbose debugging scenarios. Signed-off-by: Qihang Gao Cc: Evgenii Shatokhin --- MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c index dcf196cc96..204d599c3d 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c @@ -390,7 +390,7 @@ TerminalConInRegisterKeyNotify ( // protocol. // DEBUG (( - DEBUG_INFO, + DEBUG_VERBOSE, "%a: Attempt to register notifier for the key 0x%04x (scan code 0x%04x) with shift state 0x%08x and toggle state 0x%02x.\n", __func__, KeyData->Key.UnicodeChar, From 12c5ded287fc142380b0f9efab3b6ac47c2d1067 Mon Sep 17 00:00:00 2001 From: Chris Fernald Date: Fri, 19 Jun 2026 12:33:56 -0700 Subject: [PATCH 043/406] FatPkg: Clean any volume caches during exit boot services The current implementation assumes the the caller will perform the necessary cleanup before exiting boot services. This has been observed to drop some cached file writes that occur even before the application calling exit boot services is launched. This commit adds a per-volume pre-ExitBootServices event to flush any dirty caches and perform other cleanup the volume to ensure all write data is persisted and consistent. After the flush, caching will be disabled for the volume in the future to ensure that all subsequent access persists. Signed-off-by: Chris Fernald --- FatPkg/EnhancedFatDxe/Fat.h | 43 +++++++++++++++++ FatPkg/EnhancedFatDxe/Fat.inf | 1 + FatPkg/EnhancedFatDxe/Flush.c | 87 +++++++++++++++++++++++------------ FatPkg/EnhancedFatDxe/Init.c | 24 ++++++++++ FatPkg/EnhancedFatDxe/Misc.c | 78 +++++++++++++++++++++++++++++++ 5 files changed, 204 insertions(+), 29 deletions(-) diff --git a/FatPkg/EnhancedFatDxe/Fat.h b/FatPkg/EnhancedFatDxe/Fat.h index 1e739af82e..664a850514 100644 --- a/FatPkg/EnhancedFatDxe/Fat.h +++ b/FatPkg/EnhancedFatDxe/Fat.h @@ -13,6 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include @@ -388,6 +389,16 @@ struct _FAT_VOLUME { // VOID *CacheBuffer; DISK_CACHE DiskCache[CacheMaxType]; + + // + // Event signaled before ExitBootServices that flushes any dirty caches. + // + EFI_EVENT FlushEvent; + + // + // A flag that disables caching on this volume. + // + BOOLEAN CachingDisabled; }; // @@ -847,6 +858,24 @@ FatIFileClose ( FAT_IFILE *IFile ); +/** + + Write back any dirty FAT metadata and disk-cache pages for the volume to + the underlying media. + + @param Volume - The volume whose dirty cache should be flushed. + @param Task - Point to task instance, may be NULL. + + @retval EFI_SUCCESS - Any dirty caches were flushed. + @return Others - An I/O error occurred while writing back. + +**/ +EFI_STATUS +FatFlushDirtyCache ( + IN FAT_VOLUME *Volume, + IN FAT_TASK *Task + ); + /** Set error status for a specific OFile, reference checking the volume. @@ -2029,3 +2058,17 @@ extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2; extern EFI_LOCK FatFsLock; extern EFI_LOCK FatTaskLock; extern EFI_FILE_PROTOCOL FatFileInterface; + +/** + Notification callback for the pre-ExitBootServices event to flush any dirty caches. + + @param Event - The event that was signaled. + @param Context - The context of the event, which is the FAT_VOLUME for which to flush caches. + +**/ +VOID +EFIAPI +FatOnBeforeExitBootServices ( + IN EFI_EVENT Event, + IN VOID *Context + ); diff --git a/FatPkg/EnhancedFatDxe/Fat.inf b/FatPkg/EnhancedFatDxe/Fat.inf index 9d83dbdac7..55bf424ab6 100644 --- a/FatPkg/EnhancedFatDxe/Fat.inf +++ b/FatPkg/EnhancedFatDxe/Fat.inf @@ -72,6 +72,7 @@ gEfiFileInfoGuid ## SOMETIMES_CONSUMES ## UNDEFINED gEfiFileSystemInfoGuid ## SOMETIMES_CONSUMES ## UNDEFINED gEfiFileSystemVolumeLabelInfoIdGuid ## SOMETIMES_CONSUMES ## UNDEFINED + gEfiEventBeforeExitBootServicesGuid ## CONSUMES ## Event [Protocols] gEfiDiskIoProtocolGuid ## TO_START diff --git a/FatPkg/EnhancedFatDxe/Flush.c b/FatPkg/EnhancedFatDxe/Flush.c index 8c6010328b..a6958af0bb 100644 --- a/FatPkg/EnhancedFatDxe/Flush.c +++ b/FatPkg/EnhancedFatDxe/Flush.c @@ -364,6 +364,57 @@ FatCheckVolumeRef ( /** + Write back any dirty FAT metadata and disk-cache pages for the volume to + the underlying media. + + @param Volume - The volume whose dirty cache should be flushed. + @param Task - Point to task instance, may be NULL. + + @retval EFI_SUCCESS - Any dirty caches were flushed. + @return Others - An I/O error occurred while writing back. + +**/ +EFI_STATUS +FatFlushDirtyCache ( + IN FAT_VOLUME *Volume, + IN FAT_TASK *Task + ) +{ + EFI_STATUS Status; + + if (!Volume->Valid) { + return EFI_SUCCESS; + } + + // + // Update the free hint info. Volume->FreeInfoPos != 0 + // indicates this a FAT32 volume + // + if (Volume->FreeInfoValid && Volume->FatDirty && Volume->FreeInfoPos) { + Status = FatDiskIo (Volume, WriteDisk, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector, Task); + if (EFI_ERROR (Status)) { + return Status; + } + } + + // + // Update that the volume is not dirty + // + if (Volume->FatDirty && (Volume->FatType != Fat12)) { + Volume->FatDirty = FALSE; + Status = FatAccessVolumeDirty (Volume, WriteFat, &Volume->NotDirtyValue); + if (EFI_ERROR (Status)) { + return Status; + } + } + + // + // Flush all dirty cache entries to disk + // + return FatVolumeFlushCache (Volume, Task); +} + +/** Set error status for a specific OFile, reference checking the volume. If volume is already marked as invalid, and all resources are freed after reference checking, the file system protocol is uninstalled and @@ -401,36 +452,14 @@ FatCleanupVolume ( // volume be cleaned up even the volume is invalid. // FatCheckVolumeRef (Volume); - if (Volume->Valid) { - // - // Update the free hint info. Volume->FreeInfoPos != 0 - // indicates this a FAT32 volume - // - if (Volume->FreeInfoValid && Volume->FatDirty && Volume->FreeInfoPos) { - Status = FatDiskIo (Volume, WriteDisk, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector, Task); - if (EFI_ERROR (Status)) { - return Status; - } - } - // - // Update that the volume is not dirty - // - if (Volume->FatDirty && (Volume->FatType != Fat12)) { - Volume->FatDirty = FALSE; - Status = FatAccessVolumeDirty (Volume, WriteFat, &Volume->NotDirtyValue); - if (EFI_ERROR (Status)) { - return Status; - } - } - - // - // Flush all dirty cache entries to disk - // - Status = FatVolumeFlushCache (Volume, Task); - if (EFI_ERROR (Status)) { - return Status; - } + // + // Write back any dirty FAT metadata and disk-cache pages. No-op when the + // volume is no longer Valid. + // + Status = FatFlushDirtyCache (Volume, Task); + if (EFI_ERROR (Status)) { + return Status; } // diff --git a/FatPkg/EnhancedFatDxe/Init.c b/FatPkg/EnhancedFatDxe/Init.c index 9c51ed5b7b..a9dc45e84d 100644 --- a/FatPkg/EnhancedFatDxe/Init.c +++ b/FatPkg/EnhancedFatDxe/Init.c @@ -122,6 +122,30 @@ FatAllocateVolume ( DEBUG ((DEBUG_INIT, "Installed Fat filesystem on %p\n", Handle)); Volume->Valid = TRUE; + // + // Create a pre-ExitBootServices event for this volume to flush any dirty caches so + // they are not lost. before ExitBootServices is required because the underlying + // Block-io and device protocols may not be available later than this. + // + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + FatOnBeforeExitBootServices, + Volume, + &gEfiEventBeforeExitBootServicesGuid, + &Volume->FlushEvent + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_WARN, + "%a: CreateEventEx for pre-ExitBootServices failed (%r), dirty caches will not be flushed on exit!\n", + __func__, + Status + )); + Volume->FlushEvent = NULL; + Status = EFI_SUCCESS; + } + Done: if (EFI_ERROR (Status)) { FatFreeVolume (Volume); diff --git a/FatPkg/EnhancedFatDxe/Misc.c b/FatPkg/EnhancedFatDxe/Misc.c index 68a113fcfd..ea625cf123 100644 --- a/FatPkg/EnhancedFatDxe/Misc.c +++ b/FatPkg/EnhancedFatDxe/Misc.c @@ -331,6 +331,14 @@ FatDiskIo ( // Status = EFI_VOLUME_CORRUPTED; if (Offset + BufferSize <= Volume->VolumeSize) { + if (Volume->CachingDisabled) { + // + // Caching has been turned off for this volume. Convert + // IO mode to raw disk access equivalent. + // + IoMode = (IO_MODE)RAW_ACCESS (IoMode); + } + if (CACHE_ENABLED (IoMode)) { // // Access cache @@ -449,6 +457,68 @@ FatFreeDirEnt ( FreePool (DirEnt); } +/** + Pre-ExitBootServices notification, signaled once per FAT volume. Context + is the FAT_VOLUME this event was created for. This routine will flush any + dirty caches for the volume. + + @param Event - The event that was signaled. + @param Context - The context of the event, which is the FAT_VOLUME for which to flush caches. + +**/ +VOID +EFIAPI + +FatOnBeforeExitBootServices ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + FAT_VOLUME *Volume; + EFI_STATUS Status; + + Volume = (FAT_VOLUME *)Context; + if ((Volume == NULL) || (Volume->Signature != FAT_VOLUME_SIGNATURE)) { + return; + } + + if (!Volume->Valid || Volume->ReadOnly || Volume->DiskError) { + return; + } + + Status = FatAcquireLockOrFail (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "%a: FAT lock busy, skipping flush of %p\n", __func__, Volume->Handle)); + return; + } + + // + // Flush any dirty caches. This will still leave all handles valid in case + // other callback intend on using the file system protocol to flush high + // level data in pre-ExitBootServices. Those callers will just have to + // explicitly flush/close the handles. + // + Status = FatFlushDirtyCache (Volume, NULL); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: FatFlushDirtyCache on %p returned %r\n", + __func__, + Volume->Handle, + Status + )); + } + + // + // Disable caching from this point forward to ensure that any further writes + // don't get dropped. + // + + Volume->CachingDisabled = TRUE; + + FatReleaseLock (); +} + /** Free volume structure (including the contents of directory cache and disk cache). @@ -461,6 +531,14 @@ FatFreeVolume ( IN FAT_VOLUME *Volume ) { + // + // Close the per-volume pre-ExitBootServices event. + // + if (Volume->FlushEvent != NULL) { + gBS->CloseEvent (Volume->FlushEvent); + Volume->FlushEvent = NULL; + } + // // Free disk cache // From 34a3cc89de27dbeacd8b5ceecafaa2c212f87085 Mon Sep 17 00:00:00 2001 From: Kirk Chou Date: Fri, 29 May 2026 00:45:49 +0800 Subject: [PATCH 044/406] BaseTools/Build: Fix arch macro expansion scope in DSC parser Signed-off-by: Kirk Chou --- BaseTools/Source/Python/Workspace/MetaFileParser.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index 512b172352..1880148a6d 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -1400,6 +1400,17 @@ class DscParser(MetaFileParser): self._Scope = [[S1, S2, S3]] # + # Expand macros in arch field for all records so that per-module + # sub-items (e.g. under [Components.$(PEI_ARCH)]) + # resolve correctly, not just the Component record itself. + # + self._Scope[0][0] = ReplaceMacro(self._Scope[0][0], self._Macros) + if '$(' in self._Scope[0][0] and S1 != TAB_ARCH_COMMON: + EdkLogger.warn("Parser", + "Macro in arch field was not resolved. " + "'%s' used in section header is not defined." % S1, + File=self._FileWithError, Line=LineStart) + # # For !include directive, handle it specially, # merge arch and module type in case of duplicate items # @@ -1712,7 +1723,6 @@ class DscParser(MetaFileParser): def __ProcessComponent(self): self._ValueList[0] = ReplaceMacro(self._ValueList[0], self._Macros) - self._Scope[0][0] = ReplaceMacro(self._Scope[0][0], self._Macros) def __ProcessBuildOption(self): self._ValueList = [ReplaceMacro(Value, self._Macros, RaiseError=False) From 7460ab02d7e55e41df7e7a478585681892d54284 Mon Sep 17 00:00:00 2001 From: Qihang Gao Date: Wed, 17 Jun 2026 11:30:35 +0800 Subject: [PATCH 045/406] OvmfPkg/LoongArchVirt: Set default terminal type to TTYTERM Replace the legacy VT100 default with TTYTERM, which is more suitable for modern terminal emulators and command-line utilities. Signed-off-by: Qihang Gao --- OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc index 60907d7939..fc71a80767 100644 --- a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc +++ b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc @@ -22,14 +22,13 @@ BUILD_TARGETS = DEBUG|RELEASE SKUID_IDENTIFIER = DEFAULT FLASH_DEFINITION = OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf - TTY_TERMINAL = FALSE !include LoongArchVirt.fdf.inc # # Defines for default states. These can be changed on the command line. # -D FLAG=VALUE - DEFINE TTY_TERMINAL = FALSE + DEFINE TTY_TERMINAL = TRUE DEFINE SECURE_BOOT_ENABLE = FALSE DEFINE SECURE_BOOT_DEFAULT_KEYS = FALSE DEFINE QEMU_PV_VARS = FALSE @@ -437,6 +436,16 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask | 1 + ## Default Terminal Type + ## 0-PCANSI, 1-VT100, 2-VT100+, 3-UTF8, 4-TTYTERM +!if $(TTY_TERMINAL) == TRUE + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType | 4 + # Set terminal type to TtyTerm, the value encoded is EFI_TTY_TERM_GUID + gUefiOvmfPkgTokenSpaceGuid.PcdTerminalTypeGuidBuffer | {0x80, 0x6d, 0x91, 0x7d, 0xb1, 0x5b, 0x8c, 0x45, 0xa4, 0x8f, 0xe2, 0x5f, 0xdd, 0x51, 0xef, 0x94} +!else + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType | 1 +!endif + ################################################################################ # # Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform From f272dd7ea35b47d282372586c036f2f45a6c9c00 Mon Sep 17 00:00:00 2001 From: Luigi Leonardi Date: Mon, 22 Jun 2026 11:09:42 +0200 Subject: [PATCH 046/406] OvmfPkg/IntelTdx: Move BootManagerMenuApp from NCCFV to DXEFV Commit 03a07cb0f5 moved both UiApp and BootManagerMenuApp to NCCFV to reduce the attack surface for TD guests. However, NCCFV is not discovered when TDX is enabled, which means that EfiBootManagerGetBootManagerMenu() fails to find the BootManagerMenuApp, triggering the assert: [Bds]BootManagerMenu FFS section can not be found, skip its boot option registration ASSERT_EFI_ERROR (Status = Not Found) ASSERT BdsPlatform.c(155): !(((RETURN_STATUS)(Status)) >= 0x8000000000000000ULL) that prevents any any boot option to work. Move BootManagerMenuApp back to DXEFV so the ASSERT is satisfied. Fixes: 03a07cb0f5 ("OvmfPkg/IntelTdx: only add UI to NCCFV") Signed-off-by: Luigi Leonardi --- OvmfPkg/IntelTdx/IntelTdxX64.fdf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.fdf b/OvmfPkg/IntelTdx/IntelTdxX64.fdf index b49838490d..dfc2401631 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.fdf +++ b/OvmfPkg/IntelTdx/IntelTdxX64.fdf @@ -261,6 +261,8 @@ INF OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.inf # INF MdeModulePkg/Universal/SmbiosMeasurementDxe/SmbiosMeasurementDxe.inf +INF MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf + ################################################################################ [FV.NCCFV] @@ -304,7 +306,6 @@ INF OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf INF MdeModulePkg/Logo/LogoDxe.inf INF MdeModulePkg/Application/UiApp/UiApp.inf -INF MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf # # Usb Support From e03fb69e9aad9d8ee501c512c0f1a08d8aa1fa8b Mon Sep 17 00:00:00 2001 From: Sureshkumar Ponnusamy Date: Thu, 18 Jun 2026 16:11:34 -0700 Subject: [PATCH 047/406] MdeModulePkg/Core/Dxe/Gcd: make persistent override special-purpose Fix the GCD memory type selection logic in DXE GCD initialization so persistent memory correctly takes precedence over special-purpose memory when both attributes are present. The existing code/comment said persistent should win, but the condition order allowed special-purpose to overwrite persistent. This change swaps the checks so behavior matches the intended precedence and comment. Signed-off-by: Sureshkumar Ponnusamy --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 7b4d0dc146..e0fd64e604 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -2768,16 +2768,16 @@ CoreInitializeGcdServices ( GcdMemoryType = EfiGcdMemoryTypeReserved; } - if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == EFI_RESOURCE_ATTRIBUTE_PERSISTENT) { - GcdMemoryType = EfiGcdMemoryTypePersistent; - } - // Mark special purpose memory as system memory, if it was system memory in the HOB // However, if this is also marked as persistent, let persistent take precedence if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE) == EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE) { GcdMemoryType = EfiGcdMemoryTypeSystemMemory; } + if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == EFI_RESOURCE_ATTRIBUTE_PERSISTENT) { + GcdMemoryType = EfiGcdMemoryTypePersistent; + } + break; case EFI_RESOURCE_MEMORY_MAPPED_IO: case EFI_RESOURCE_FIRMWARE_DEVICE: From 9714474bf2e7405983674a48ccc1f49130c1fb94 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Mon, 22 Jun 2026 13:19:17 +0000 Subject: [PATCH 048/406] .github: Bump actions/checkout from 6 to 7 Bumps [actions/checkout](https://github.com/actions/checkout) from 6 to 7. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v6...v7) updated-dependencies: - dependency-name: actions/checkout dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major Signed-off-by: Michael Kubacki --- .github/workflows/BuildPlatform.yml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/issue-assignment.yml | 2 +- .github/workflows/issue-triage.yml | 2 +- .github/workflows/pull-request-formatting-validator.yml | 2 +- .github/workflows/request-reviews.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/BuildPlatform.yml b/.github/workflows/BuildPlatform.yml index c37a041bf1..e39c7e2aa3 100644 --- a/.github/workflows/BuildPlatform.yml +++ b/.github/workflows/BuildPlatform.yml @@ -65,7 +65,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v6 + uses: actions/checkout@v7 - run: | git config --global --add safe.directory '*' diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 13f0afbc9b..07d5129388 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -76,7 +76,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@v7 - name: Install Python uses: actions/setup-python@v6 diff --git a/.github/workflows/issue-assignment.yml b/.github/workflows/issue-assignment.yml index 0790d7cfc1..ee59e3f5db 100644 --- a/.github/workflows/issue-assignment.yml +++ b/.github/workflows/issue-assignment.yml @@ -21,7 +21,7 @@ jobs: issues: write steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - name: Remove Labels env: diff --git a/.github/workflows/issue-triage.yml b/.github/workflows/issue-triage.yml index 72b8bc7326..dac52dfa89 100644 --- a/.github/workflows/issue-triage.yml +++ b/.github/workflows/issue-triage.yml @@ -30,7 +30,7 @@ jobs: issues: write steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - name: Parse Issue Form uses: stefanbuck/github-issue-parser@v3 diff --git a/.github/workflows/pull-request-formatting-validator.yml b/.github/workflows/pull-request-formatting-validator.yml index 856813a41d..018943794d 100644 --- a/.github/workflows/pull-request-formatting-validator.yml +++ b/.github/workflows/pull-request-formatting-validator.yml @@ -37,7 +37,7 @@ jobs: # Reduce checkout time with sparse-checkout - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@v7 with: fetch-depth: 1 sparse-checkout: | diff --git a/.github/workflows/request-reviews.yml b/.github/workflows/request-reviews.yml index 2feb713a33..e7e2029a01 100644 --- a/.github/workflows/request-reviews.yml +++ b/.github/workflows/request-reviews.yml @@ -44,7 +44,7 @@ jobs: # - BaseTools/Scripts: Contains the GetMaintainer.py script # - Maintainers.txt: Contains the list of maintainers for the repository - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@v7 with: fetch-depth: 1 sparse-checkout: | From b3d5f2b349041fedc31b0ff1fd4b3719bed33923 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Tue, 20 Jan 2026 20:15:50 -0800 Subject: [PATCH 049/406] EmbeddedPkg: PrePiLib: Fix uninitialized variable warnings In FfsProcessSection(), delete CompressionSectionHeaderSize and move CompressedData to avoid the compiler warning without changing functional behavior. Signed-off-by: Tuan Phan --- EmbeddedPkg/Library/PrePiLib/FwVol.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/PrePiLib/FwVol.c index 6d50daacbe..69c493187b 100644 --- a/EmbeddedPkg/Library/PrePiLib/FwVol.c +++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c @@ -398,19 +398,17 @@ FfsProcessSection ( return EFI_SUCCESS; } else if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) { - CHAR8 *CompressedData; - UINT32 CompressionSectionHeaderSize; VOID *ScratchBuffer; UINT32 ScratchBufferSize; if (Section->Type == EFI_SECTION_COMPRESSION) { + CHAR8 *CompressedData; UINT32 CompressedDataLength; - CompressionSectionHeaderSize = GetCompressionSectionNHeaderSize (Section); - SectionLength = GetSectionNSize (Section); + SectionLength = GetSectionNSize (Section); - CompressedData = (CHAR8 *)((UINTN)(Section) + CompressionSectionHeaderSize); - CompressedDataLength = SectionLength - CompressionSectionHeaderSize; + CompressedData = (CHAR8 *)((UINTN)(Section) + GetCompressionSectionNHeaderSize (Section)); + CompressedDataLength = SectionLength - GetCompressionSectionNHeaderSize (Section); if (GetSectionNCompressionType (Section) != EFI_STANDARD_COMPRESSION) { return EFI_UNSUPPORTED; @@ -468,7 +466,9 @@ FfsProcessSection ( // Call decompress function // if (Section->Type == EFI_SECTION_COMPRESSION) { - CompressedData = (CHAR8 *)((UINTN)(Section) + CompressionSectionHeaderSize); + CHAR8 *CompressedData; + + CompressedData = (CHAR8 *)((UINTN)(Section) + GetCompressionSectionNHeaderSize (Section)); Status = UefiDecompress ( CompressedData, From 1a86701fc09197b2fd6e4d8ae43eb2e4df7c2a07 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Fri, 23 Jan 2026 20:03:51 -0800 Subject: [PATCH 050/406] MdeModulePkg: SpiNorFlashJedecSfdp: Fix uninitialized variable warnings In GetEraseTypeRecord(), ensure ValueToCompare is initialized on all code paths to prevent uninitialized variable warnings. In SpiReadSfdpPtp(), return an error code immediately if any iteration of the for loop fails, otherwise return EFI_SUCCESS on success at the end of function. Signed-off-by: Tuan Phan --- .../Spi/SpiNorFlashJedecSfdp/SpiNorFlashJedecSfdp.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlashJedecSfdp.c b/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlashJedecSfdp.c index 284567d1f4..11bc39d140 100644 --- a/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlashJedecSfdp.c +++ b/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlashJedecSfdp.c @@ -331,12 +331,17 @@ GetEraseTypeRecord ( *EraseTypeRecord = NULL; // - // Initial the comapre value. + // Initial the compare value. // switch (SearchType) { case SearchEraseTypeByType: case SearchEraseTypeByCommand: case SearchEraseTypeBySize: + // + // Although ValueToCompare is not used for these types, it must be + // initialized to avoid "variable may be used uninitialized" compiler warning. + // + ValueToCompare = 0; break; case SearchEraseTypeBySmallestSize: ValueToCompare = (UINT32)-1; @@ -1544,15 +1549,16 @@ SpiReadSfdpPtp ( if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: Fails to read SFDP parameter.\n", __func__)); ASSERT_EFI_ERROR (Status); + return Status; } CurrentBuffer += Length; } else { - break; + return Status; } } - return Status; + return EFI_SUCCESS; } /** From 55834be5d1ee44d9e8a8d885d55b889ecc422d0d Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Fri, 23 Jan 2026 20:20:48 -0800 Subject: [PATCH 051/406] MdeModulePkg: UsbNetwork: Fix uninitialized variable warnings In NetworkCommonDriverStart(), if gPxe is not NULL, TmpPxePointer should be initialized as it is referenced later in the clean up code. Signed-off-by: Tuan Phan --- MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/DriverBinding.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/DriverBinding.c b/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/DriverBinding.c index a2a5b82776..3a672a7793 100644 --- a/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/DriverBinding.c +++ b/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/DriverBinding.c @@ -227,7 +227,6 @@ NetworkCommonDriverStart ( // for alignment adjustment if (gPxe == NULL) { - TmpPxePointer = NULL; TmpPxePointer = AllocateZeroPool (sizeof (PXE_SW_UNDI) + 16); if (!TmpPxePointer) { if (NicDevice != NULL) { @@ -278,6 +277,8 @@ NetworkCommonDriverStart ( PxeStructInit (gPxe); } + } else { + TmpPxePointer = NULL; } NicDevice->NiiProtocol.Id = (UINT64)(UINTN)(gPxe); From 9044d2b33dcc8a3f1d731236e1b88bfe3eae2b38 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Sat, 24 Jan 2026 22:00:19 -0800 Subject: [PATCH 052/406] MdeModulePkg: SdBlockIoPei: Fix uninitialized variable warnings In SdPeimIdentification(), the compiler may inline SdPeimHcRwMmio() because it only performs simple MMIO reads and writes. When inlined, the fourth argument can appear to follow multiple control-flow paths (MMIO read versus MMIO write), which may cause the compiler to report a potential uninitialized variable warning when the value is used later if it was not initialized up front. Add an explicit Status check, consistent with other code in this file, to make the control flow explicit and eliminate the compiler warning. Signed-off-by: Tuan Phan --- MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c b/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c index 774cae35f2..c783a9a699 100644 --- a/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c +++ b/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c @@ -2948,7 +2948,13 @@ SdPeimIdentification ( goto Error; } - SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState); + Status = SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SdPeimIdentification: Executing SdPeimHcRwMmio fails with %r\n", Status)); + Status = EFI_DEVICE_ERROR; + goto Error; + } + if (((PresentState >> 20) & 0xF) != 0) { DEBUG ((DEBUG_ERROR, "SdPeimIdentification: SwitchVoltage fails with PresentState = 0x%x\n", PresentState)); Status = EFI_DEVICE_ERROR; @@ -2960,7 +2966,13 @@ SdPeimIdentification ( MicroSecondDelay (5000); - SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_HOST_CTRL2, TRUE, sizeof (HostCtrl2), &HostCtrl2); + Status = SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_HOST_CTRL2, TRUE, sizeof (HostCtrl2), &HostCtrl2); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SdPeimIdentification: Executing SdPeimHcRwMmio fails with %r\n", Status)); + Status = EFI_DEVICE_ERROR; + goto Error; + } + if ((HostCtrl2 & BIT3) == 0) { DEBUG ((DEBUG_ERROR, "SdPeimIdentification: SwitchVoltage fails with HostCtrl2 = 0x%x\n", HostCtrl2)); Status = EFI_DEVICE_ERROR; @@ -2971,7 +2983,13 @@ SdPeimIdentification ( MicroSecondDelay (1000); - SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState); + Status = SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SdPeimIdentification: Executing SdPeimHcRwMmio fails with %r\n", Status)); + Status = EFI_DEVICE_ERROR; + goto Error; + } + if (((PresentState >> 20) & 0xF) != 0xF) { DEBUG ((DEBUG_ERROR, "SdPeimIdentification: SwitchVoltage fails with PresentState = 0x%x, It should be 0xF\n", PresentState)); Status = EFI_DEVICE_ERROR; From 42b690316cb9d87737b30743bcd8aaa885caba0d Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Tue, 16 Jun 2026 21:29:00 -0700 Subject: [PATCH 053/406] MdeModulePkg: CxlDxe: Fix uninitialized variable warnings In CxlWriteRegblockRegisters() and PciUefiMemReadUInt32Array(), Status is only assigned inside the for loop but is returned after the loop exits, causing an uninitialized variable warning. Return immediately on error to fix this. Signed-off-by: Tuan Phan --- MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.c b/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.c index 64c7190f36..0c9f40e1a5 100644 --- a/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.c +++ b/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.c @@ -82,13 +82,13 @@ PciUefiMemReadUInt32Array ( if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: PciIo read error at 0x%lx: %r \n", __func__, BufferIndex, Status)); - break; + return Status; } Offset += sizeof (UINT32); } - return Status; + return EFI_SUCCESS; } /** @@ -137,13 +137,13 @@ PciUefiMemWriteUInt32Array ( if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: PciIo write error at 0x%lx: %r \n", __func__, BufferIndex, Status)); - break; + return Status; } Offset += sizeof (UINT32); } - return Status; + return EFI_SUCCESS; } /** From 798a16c520da264a38e0e030a16ac052b6bd6463 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Sun, 25 Jan 2026 15:29:42 -0800 Subject: [PATCH 054/406] CryptoPkg: TlsLib: Fix uninitialized variable warnings In TlsSetCipherList(), the OpensslCipher variable is initialized inside an inner loop but accessed outside of that loop, which can lead to uninitialized variable warnings. Fix this issue by moving all accesses to OpensslCipher into the inner loop where it is initialized. Signed-off-by: Tuan Phan --- CryptoPkg/Library/TlsLib/TlsConfig.c | 62 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/CryptoPkg/Library/TlsLib/TlsConfig.c b/CryptoPkg/Library/TlsLib/TlsConfig.c index c21b6f70be..54cfb1a9a8 100644 --- a/CryptoPkg/Library/TlsLib/TlsConfig.c +++ b/CryptoPkg/Library/TlsLib/TlsConfig.c @@ -227,9 +227,38 @@ TlsSetCipherList ( // for (StackIdx = 0; StackIdx < sk_SSL_CIPHER_num (OpensslCipherStack); StackIdx++) { OpensslCipher = sk_SSL_CIPHER_value (OpensslCipherStack, StackIdx); - if (CipherId[Index] == SSL_CIPHER_get_protocol_id (OpensslCipher)) { - break; + if (CipherId[Index] != SSL_CIPHER_get_protocol_id (OpensslCipher)) { + continue; } + + // + // Accumulate cipher name string length into CipherStringSize. If this + // is not the first successful mapping, account for a colon (":") prefix + // too. + // + if (MappedCipherCount > 0) { + Status = SafeUintnAdd (CipherStringSize, 1, &CipherStringSize); + if (EFI_ERROR (Status)) { + Status = EFI_OUT_OF_RESOURCES; + goto FreeMappedCipher; + } + } + + Status = SafeUintnAdd ( + CipherStringSize, + AsciiStrLen (SSL_CIPHER_get_name (OpensslCipher)), + &CipherStringSize + ); + if (EFI_ERROR (Status)) { + Status = EFI_OUT_OF_RESOURCES; + goto FreeMappedCipher; + } + + // + // Record the mapping. + // + MappedCipher[MappedCipherCount++] = OpensslCipher; + break; } if (StackIdx == sk_SSL_CIPHER_num (OpensslCipherStack)) { @@ -245,36 +274,7 @@ TlsSetCipherList ( // preference list of ciphers, thus we can filter it as long as we // don't change the relative order of elements on it. // - continue; } - - // - // Accumulate cipher name string length into CipherStringSize. If this - // is not the first successful mapping, account for a colon (":") prefix - // too. - // - if (MappedCipherCount > 0) { - Status = SafeUintnAdd (CipherStringSize, 1, &CipherStringSize); - if (EFI_ERROR (Status)) { - Status = EFI_OUT_OF_RESOURCES; - goto FreeMappedCipher; - } - } - - Status = SafeUintnAdd ( - CipherStringSize, - AsciiStrLen (SSL_CIPHER_get_name (OpensslCipher)), - &CipherStringSize - ); - if (EFI_ERROR (Status)) { - Status = EFI_OUT_OF_RESOURCES; - goto FreeMappedCipher; - } - - // - // Record the mapping. - // - MappedCipher[MappedCipherCount++] = OpensslCipher; } // From 56723842fd47bfdfd738c981b428ea625d0af35f Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Tue, 10 Feb 2026 15:20:45 -0800 Subject: [PATCH 055/406] NetworkPkg: HttpBootDxe: Fix uninitialized variable warnings In HttpBootGetBootFileCaller(), under the LoadBootFile case, the Status variable is only assigned within a for loop. If the loop is not executed, this results in an uninitialized variable warning when Status is later referenced. Resolve this issue by return Status directly inside the loop. Signed-off-by: Tuan Phan --- NetworkPkg/HttpBootDxe/HttpBootImpl.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe/HttpBootImpl.c index 00f1102eb6..a4f0b3c0f0 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c +++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c @@ -432,8 +432,7 @@ HttpBootGetBootFileCaller ( if (*BufferSize < Private->BootFileSize) { *BufferSize = Private->BootFileSize; *ImageType = Private->ImageType; - Status = EFI_BUFFER_TOO_SMALL; - return Status; + return EFI_BUFFER_TOO_SMALL; } // @@ -448,10 +447,14 @@ HttpBootGetBootFileCaller ( ImageType ); if (!EFI_ERROR (Status) || - ((Status != EFI_TIMEOUT) && (Status != EFI_DEVICE_ERROR)) || - (Retries >= PcdGet32 (PcdMaxHttpResumeRetries))) + ((Status != EFI_TIMEOUT) && (Status != EFI_DEVICE_ERROR))) { - break; + return Status; + } + + if (Retries == PcdGet32 (PcdMaxHttpResumeRetries)) { + DEBUG ((DEBUG_ERROR, "HttpBootGetBootFileCaller: Error downloading NBP file, even after trying to resume %d times.\n", Retries)); + return Status; } // @@ -463,23 +466,22 @@ HttpBootGetBootFileCaller ( HttpIoDestroyIo (&Private->HttpIo); Status = HttpBootCreateHttpIo (Private); if (EFI_ERROR (Status)) { - break; + return Status; } DEBUG ((DEBUG_WARN | DEBUG_INFO, "HttpBootGetBootFileCaller: NBP file download interrupted, will try to resume the operation.\n")); gBS->Stall (1000 * 1000 * PcdGet32 (PcdHttpDelayBetweenResumeRetries)); } - if (EFI_ERROR (Status) && (Retries >= PcdGet32 (PcdMaxHttpResumeRetries))) { - DEBUG ((DEBUG_ERROR, "HttpBootGetBootFileCaller: Error downloading NBP file, even after trying to resume %d times.\n", Retries)); - } - - return Status; + // + // Only reach here if the for loop above is not executed, which means PcdMaxHttpResumeRetries is 0. + // + return EFI_UNSUPPORTED; case GetBootFileError: default: AsciiPrint ("\n Error: Could not retrieve NBP file size from HTTP server.\n"); - return Status; + return EFI_UNSUPPORTED; } } } From 1cb1184b50229406a3a47c3024018795792837f7 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Mon, 15 Jun 2026 11:35:44 -0700 Subject: [PATCH 056/406] NetworkPkg: Ip4Dxe: Fix uninitialized variable warning In Ip4FormExtractConfig(), the Status variable was assigned only within a conditional block but used outside of it, which could lead to an uninitialized variable warning. Fix this by moving the relevant code outside of the conditional block so that Status is always properly initialized before use. Signed-off-by: Tuan Phan --- NetworkPkg/Ip4Dxe/Ip4Config2Nv.c | 114 +++++++++++++++---------------- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/NetworkPkg/Ip4Dxe/Ip4Config2Nv.c b/NetworkPkg/Ip4Dxe/Ip4Config2Nv.c index 86833561e4..a0d5cd04ce 100644 --- a/NetworkPkg/Ip4Dxe/Ip4Config2Nv.c +++ b/NetworkPkg/Ip4Dxe/Ip4Config2Nv.c @@ -891,67 +891,65 @@ Ip4FormExtractConfig ( // // Check Request data in . // - if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gIp4Config2NvDataGuid, mIp4Config2StorageName)) { - IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA)); - if (IfrFormNvData == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Ip4Config2ConvertConfigNvDataToIfrNvData (Ip4Config2Instance, IfrFormNvData); - - if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) { - // - // Request has no request element, construct full request string. - // Allocate and fill a buffer large enough to hold the template - // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator - // - ConfigRequestHdr = HiiConstructConfigHdr (&gIp4Config2NvDataGuid, mIp4Config2StorageName, Private->ChildHandle); - Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); - ConfigRequest = AllocateZeroPool (Size); - if (ConfigRequest == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Failure; - } - - AllocatedRequest = TRUE; - - UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize); - FreePool (ConfigRequestHdr); - } - - // - // Convert buffer data to by helper function BlockToConfig() - // - Status = gHiiConfigRouting->BlockToConfig ( - gHiiConfigRouting, - ConfigRequest, - (UINT8 *)IfrFormNvData, - BufferSize, - &FormResult, - Progress - ); - - FreePool (IfrFormNvData); - - // - // Free the allocated config request string. - // - if (AllocatedRequest) { - FreePool (ConfigRequest); - ConfigRequest = NULL; - } - - if (EFI_ERROR (Status)) { - goto Failure; - } - } - - if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gIp4Config2NvDataGuid, mIp4Config2StorageName)) { - *Results = FormResult; - } else { + if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gIp4Config2NvDataGuid, mIp4Config2StorageName)) { return EFI_NOT_FOUND; } + IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA)); + if (IfrFormNvData == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Ip4Config2ConvertConfigNvDataToIfrNvData (Ip4Config2Instance, IfrFormNvData); + + if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) { + // + // Request has no request element, construct full request string. + // Allocate and fill a buffer large enough to hold the template + // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator + // + ConfigRequestHdr = HiiConstructConfigHdr (&gIp4Config2NvDataGuid, mIp4Config2StorageName, Private->ChildHandle); + Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); + ConfigRequest = AllocateZeroPool (Size); + if (ConfigRequest == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Failure; + } + + AllocatedRequest = TRUE; + + UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize); + FreePool (ConfigRequestHdr); + } + + // + // Convert buffer data to by helper function BlockToConfig() + // + Status = gHiiConfigRouting->BlockToConfig ( + gHiiConfigRouting, + ConfigRequest, + (UINT8 *)IfrFormNvData, + BufferSize, + &FormResult, + Progress + ); + + FreePool (IfrFormNvData); + + // + // Free the allocated config request string. + // + if (AllocatedRequest) { + FreePool (ConfigRequest); + ConfigRequest = NULL; + } + + if (EFI_ERROR (Status)) { + goto Failure; + } + + *Results = FormResult; + Failure: // // Set Progress string to the original request string. From d0b66f1671c6196eab3da23ea9a8346a7289f286 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Tue, 16 Jun 2026 10:18:55 -0700 Subject: [PATCH 057/406] MdePkg: DxeRiscvMpxyLib: Fix uninitialized variable warning In SbiMpxyGetShmemSize(), ShmemSize is not assigned in the failure path, but the caller may still access it. Initialize ShmemSize to zero to fix the uninitialized variable warning. Signed-off-by: Tuan Phan --- MdePkg/Library/DxeRiscvMpxyLib/DxeRiscvMpxy.c | 1 + 1 file changed, 1 insertion(+) diff --git a/MdePkg/Library/DxeRiscvMpxyLib/DxeRiscvMpxy.c b/MdePkg/Library/DxeRiscvMpxyLib/DxeRiscvMpxy.c index e3a0ad3836..36a692498a 100644 --- a/MdePkg/Library/DxeRiscvMpxyLib/DxeRiscvMpxy.c +++ b/MdePkg/Library/DxeRiscvMpxyLib/DxeRiscvMpxy.c @@ -155,6 +155,7 @@ SbiMpxyGetShmemSize ( return EFI_SUCCESS; } + *ShmemSize = 0; return TranslateError (Ret.Error); } From 7da9028ca3f7f55de360c60b3f37b35141d48c1d Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Tue, 20 Jan 2026 20:32:31 -0800 Subject: [PATCH 058/406] MdePkg: CompilerIntrinsicsLib: Add RiscV64 support Add memcpy/memset implementations for RiscV64 as they may be required by compiler during linking when build with the -Os flag. Signed-off-by: Tuan Phan --- MdePkg/MdeLibs.dsc.inc | 8 ++++---- MdePkg/MdePkg.dsc | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/MdePkg/MdeLibs.dsc.inc b/MdePkg/MdeLibs.dsc.inc index b063480df7..91cf2aa3c4 100644 --- a/MdePkg/MdeLibs.dsc.inc +++ b/MdePkg/MdeLibs.dsc.inc @@ -60,12 +60,12 @@ # implements exception handling for SEC and PEI_CORE, it can use StackCheckLib for these phases in its DSC. StackCheckLib|MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf -[LibraryClasses.AARCH64] +[LibraryClasses.AARCH64, LibraryClasses.RISCV64] # - # It is not possible to prevent the AARCH64 compilers from inserting generic intrinsic functions. - # This library provides the intrinsic functions generated by these compilers. + # It is not possible to prevent compilers from inserting generic intrinsic functions. + # This library provides the intrinsic functions generated by compilers. # - # Linking this here as a null library will cause all AARCH64 files to link against it and have + # Linking this here as a null library will cause all files to link against it and have # definitions for the intrinsic functions. # NULL|MdePkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index f58b887d25..cfdd76463c 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -217,6 +217,7 @@ MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointerLib.inf MdePkg/Library/DxeRiscvMpxyLib/DxeRiscvMpxy.inf MdePkg/Library/DxeRiscvRasAgentClientLib/DxeRiscvRasAgentClientLib.inf + MdePkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf [Components.LOONGARCH64] MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServicesTablePointerLibKs0.inf From 370f9021f1ef682c099c1761de077eda38d87dd1 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Wed, 17 Jun 2026 14:34:11 -0700 Subject: [PATCH 059/406] ManageabilityPkg: TransportSsifLib: Fix uninitialized variable warning In SsifWriteRequest(), MiddleCount is only assigned inside an if block but is accessed in a subsequent loop, causing an uninitialized variable warning. Initialize MiddleCount to zero at declaration to fix this. Signed-off-by: Tuan Phan --- .../Library/ManageabilityTransportSsifLib/Common/SsifCommon.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/SsifCommon.c b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/SsifCommon.c index 4ca92a5fd9..597cd7912f 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/SsifCommon.c +++ b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/SsifCommon.c @@ -67,6 +67,7 @@ SsifWriteRequest ( return EFI_INVALID_PARAMETER; } + MiddleCount = 0; IsMultiPartWrite = FALSE; Status = EFI_SUCCESS; From 32e139d51b7a2934a164af809b1fa604402c1db1 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Wed, 17 Jun 2026 14:41:49 -0700 Subject: [PATCH 060/406] ManageabilityPkg: TransportHelperLib: Fix uninitialized variable warning In HelperManageabilityPayLoadDebugPrint(), Page256 is only assigned inside an if block within the while loop but is accessed outside of it, causing an uninitialized variable warning. Initialize Page256 to zero before the while loop to fix this. Signed-off-by: Tuan Phan --- .../BaseManageabilityTransportHelper.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c b/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c index e4d16fa18d..933db4c1d5 100644 --- a/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c +++ b/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c @@ -405,6 +405,7 @@ HelperManageabilityPayLoadDebugPrint ( RemainingBytes = PayloadSize; TotalBytePrinted = 0; + Page256 = 0; while (TRUE) { if (TotalBytePrinted % 256 == 0) { Page256 = (UINT16)TotalBytePrinted / 256; From b62011ce284146c6f0e535b9f48bb3868a38e3a6 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Tue, 20 Jan 2026 20:49:47 -0800 Subject: [PATCH 061/406] BaseTools/tools_def RISCV: Enable -Os optimization Switch GCC RISCV builds to use GCC_ALL_CC_FLAGS so that the -Os compiler flag is applied during compilation. For RiscVVirt target, this reduces DXEFV size by ~30%. Signed-off-by: Tuan Phan --- BaseTools/Conf/tools_def.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index d61c704c92..94d8c1c414 100644 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -996,7 +996,7 @@ DEFINE GCC_AARCH64_DLINK2_FLAGS = DEF(GCCNOLTO_AARCH64_DLINK2_FLAGS) -Wno-e DEFINE GCC_AARCH64_ASLDLINK_FLAGS = DEF(GCCNOLTO_AARCH64_ASLDLINK_FLAGS) DEF(GCC_DLINK_WARNING_FLAGS) DEFINE GCC_ASLCC_FLAGS = DEF(GCCNOLTO_ASLCC_FLAGS) -fno-lto -DEFINE GCC_RISCV_ALL_CC_FLAGS = -g -fshort-wchar -fno-omit-frame-pointer -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -msmall-data-limit=0 +DEFINE GCC_RISCV_ALL_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -fno-omit-frame-pointer -ffunction-sections -fdata-sections -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -msmall-data-limit=0 DEFINE GCC_RISCV_ALL_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x40 DEF(GCC_DLINK_WARNING_FLAGS) DEFINE GCC_RISCV_ALL_DLINK_FLAGS = DEF(GCC_RISCV_ALL_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map DEFINE GCC_RISCV_ALL_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds From b2c33619f76fc3aff547db9ee410c8f91da8395a Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Mon, 18 May 2026 13:08:23 -0700 Subject: [PATCH 062/406] MdeModulePkg: Dxe Core: Update Bin Size Helper Fn In preparation for sharing memory bin logic between PEI and DXE, update CaclulateTotalMemoryBinSizeNeeded() to take gMemoryTypeInformation by reference. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/DxeMain.h | 4 +++- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 31 +++++++++++++++++++------------ MdeModulePkg/Core/Dxe/Mem/Page.c | 4 ++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index 6ead8a0fde..91ae6fa0b4 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -2813,11 +2813,13 @@ CoreInitializeHandleServices ( the alignment requirements. When non-NULL, this will be updated on output to the new top address of the memory bins that must be used to satisfy alignment requirements. + @param MemoryTypeInformation The memory type information array. @return The total memory bin size needed. **/ UINT64 CalculateTotalMemoryBinSizeNeeded ( - IN OUT OPTIONAL EFI_PHYSICAL_ADDRESS *BinTop + IN OUT OPTIONAL EFI_PHYSICAL_ADDRESS *BinTop, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation ); diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index e0fd64e604..6e1f9c8993 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -2174,35 +2174,42 @@ CoreConvertResourceDescriptorHobAttributesToCapabilities ( the alignment requirements. When non-NULL, this will be updated on output to the new top address of the memory bins that must be used to satisfy alignment requirements. + @param MemoryTypeInformation The memory type information array. @return The total memory bin size needed. **/ UINT64 CalculateTotalMemoryBinSizeNeeded ( - IN OUT OPTIONAL EFI_PHYSICAL_ADDRESS *BinTop + IN OUT OPTIONAL EFI_PHYSICAL_ADDRESS *BinTop, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation ) { UINTN Index; UINT64 TotalSize; UINT64 Granularity; + ASSERT (MemoryTypeInformation != NULL); + if (MemoryTypeInformation == NULL) { + return 0; + } + // - // Loop through each memory type in the order specified by the gMemoryTypeInformation[] array + // Loop through each memory type in the order specified by the MemoryTypeInformation[] array // TotalSize = 0; - for (Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; - if ((gMemoryTypeInformation[Index].Type == EfiReservedMemoryType) || - (gMemoryTypeInformation[Index].Type == EfiACPIMemoryNVS) || - (gMemoryTypeInformation[Index].Type == EfiRuntimeServicesCode) || - (gMemoryTypeInformation[Index].Type == EfiRuntimeServicesData)) + if ((MemoryTypeInformation[Index].Type == EfiReservedMemoryType) || + (MemoryTypeInformation[Index].Type == EfiACPIMemoryNVS) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesCode) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesData)) { Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; } - // gMemoryTypeInformation[Index].NumberOfPages is already aligned to the allocation granularity - TotalSize += LShiftU64 (gMemoryTypeInformation[Index].NumberOfPages, EFI_PAGE_SHIFT); + // MemoryTypeInformation[Index].NumberOfPages is already aligned to the allocation granularity + TotalSize += EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); // BinTop is optional if (BinTop == NULL) { @@ -2210,7 +2217,7 @@ CalculateTotalMemoryBinSizeNeeded ( } // Lower the bin top to the next aligned address, taking any padding into account in the size - *BinTop -= (UINTN)LShiftU64 (gMemoryTypeInformation[Index].NumberOfPages, EFI_PAGE_SHIFT); + *BinTop -= EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); TotalSize += (*BinTop & (Granularity - 1)); *BinTop &= ~(Granularity - 1); } @@ -2400,7 +2407,7 @@ CoreInitializeMemoryServices ( } BinTop = ResourceHob->PhysicalStart + ResourceHob->ResourceLength; - if (ResourceHob->ResourceLength >= CalculateTotalMemoryBinSizeNeeded (&BinTop)) { + if (ResourceHob->ResourceLength >= CalculateTotalMemoryBinSizeNeeded (&BinTop, gMemoryTypeInformation)) { MemoryTypeInformationResourceHob = ResourceHob; } } @@ -2414,7 +2421,7 @@ CoreInitializeMemoryServices ( // // Include the total memory bin size needed to make sure memory bin could be allocated successfully. // - MinimalMemorySizeNeeded = MINIMUM_INITIAL_MEMORY_SIZE + CalculateTotalMemoryBinSizeNeeded (NULL); + MinimalMemorySizeNeeded = MINIMUM_INITIAL_MEMORY_SIZE + CalculateTotalMemoryBinSizeNeeded (NULL, gMemoryTypeInformation); // // Find the Resource Descriptor HOB that contains PHIT range EfiFreeMemoryBottom..EfiFreeMemoryTop diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 897848757f..0c659d79b0 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -596,7 +596,7 @@ CoreSetMemoryTypeInformationRange ( // Return if size of the Memory Type Information bins is greater than Length // Top = Start + Length; - Size = CalculateTotalMemoryBinSizeNeeded (&Top); + Size = CalculateTotalMemoryBinSizeNeeded (&Top, gMemoryTypeInformation); if (Size > Length) { return; @@ -725,7 +725,7 @@ CoreAddMemoryDescriptor ( } BaseAddress = 0; - RequiredSize = CalculateTotalMemoryBinSizeNeeded (NULL); + RequiredSize = CalculateTotalMemoryBinSizeNeeded (NULL, gMemoryTypeInformation); if (RequiredSize == 0) { mMemoryTypeInformationInitialized = TRUE; return; From d77628d4c1bf410eb86c5994389a19d9f43de197 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Tue, 12 May 2026 09:48:24 -0700 Subject: [PATCH 063/406] MdeModulePkg: DxeCore: Create PopulateMemoryTypeInformation Helper In preparation for supporting shared memory bin logic in DXE and PEI, create a PopulateMemoryTypeInformation() helper function. This function searches for a Memory Type Information Hob and populates an EFI_MEMORY_TYPE_INFORMATION struct with it. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 163 ++++++++++++++++++++++++-------- 1 file changed, 122 insertions(+), 41 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 6e1f9c8993..6f23bbd9d0 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -134,6 +134,93 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdAllocationTypeNames[] = { "Unknown " // EfiGcdMaxAllocateType }; +/** + Get the Memory Type Information HOB if it exists and populate gMemoryTypeInformation. + + @param MemoryTypeInformation The pointer to the memory type information array to be populated. + + @return EFI_STATUS On EFI_SUCCESS, gMemoryTypeInformation points to the + Memory Type Information. + @return EFI_NOT_FOUND No valid Memory Type Information HOB found. +**/ +EFI_STATUS +EFIAPI +PopulateMemoryTypeInformation ( + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ) +{ + UINTN DataSize; + EFI_MEMORY_TYPE_INFORMATION *EfiMemoryTypeInformation; + EFI_HOB_GUID_TYPE *GuidHob; + UINTN Index; + UINT32 Granularity; + UINTN MaxIndex; + + ASSERT (MemoryTypeInformation != NULL); + if (MemoryTypeInformation == NULL) { + return EFI_INVALID_PARAMETER; + } + + GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid); + if (GuidHob != NULL) { + EfiMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob); + DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob); + + if ((EfiMemoryTypeInformation != NULL) && (DataSize > 0) && (DataSize <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION))) { + CopyMem (MemoryTypeInformation, EfiMemoryTypeInformation, DataSize); + MaxIndex = (DataSize / sizeof (EFI_MEMORY_TYPE_INFORMATION)) - 1; + + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the MemoryTypeInformation[] array is valid + // + if (MemoryTypeInformation[Index].Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + if ((MemoryTypeInformation[Index].Type == EfiReservedMemoryType) || + (MemoryTypeInformation[Index].Type == EfiACPIMemoryNVS) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesCode) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesData)) + { + Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } else { + Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; + } + + // Align the number of pages to the allocation granularity + MemoryTypeInformation[Index].NumberOfPages = (UINT32)EFI_SIZE_TO_PAGES (ALIGN_VALUE (EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages), Granularity)); + } + + // It is guaranteed that DataSize must be > 0 and <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION) + // however, we may have a corrupted HOB that does end in the EfiMaxMemoryType, so we need to terminate the loop + // to not overrun the array. Because we can't trust the HOB data, we will reset it to 0. + if (Index == MaxIndex) { + DEBUG ((DEBUG_WARN, "%a: Corrupted Memory Type Information HOB data\n", __func__)); + goto CleanAndError; + } + } + + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_WARN, "%a: Invalid Memory Type Information HOB data\n", __func__)); + } + +CleanAndError: + // We may have gotten here from a corrupted HOB, ensure all data is set back + // to disabled bins. + for (Index = 0; Index <= EfiMaxMemoryType; Index++) { + MemoryTypeInformation[Index].Type = (UINT32)Index; + MemoryTypeInformation[Index].NumberOfPages = 0; + } + + DEBUG ((DEBUG_WARN, "%a: No Memory Type Information HOB found, S4 resume is likely to fail\n", __func__)); + + return EFI_NOT_FOUND; +} + /** Dump the entire contents if the GCD Memory Space Map using DEBUG() macros when PcdDebugPrintErrorLevel has the DEBUG_GCD bit set. @@ -2312,8 +2399,6 @@ CoreInitializeMemoryServices ( ) { EFI_PEI_HOB_POINTERS Hob; - EFI_MEMORY_TYPE_INFORMATION *EfiMemoryTypeInformation; - UINTN DataSize; BOOLEAN Found; EFI_HOB_HANDOFF_INFO_TABLE *PhitHob; EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; @@ -2327,11 +2412,11 @@ CoreInitializeMemoryServices ( EFI_PHYSICAL_ADDRESS TestedMemoryBaseAddress; UINT64 TestedMemoryLength; EFI_PHYSICAL_ADDRESS HighAddress; - EFI_HOB_GUID_TYPE *GuidHob; UINT32 ReservedCodePageNumber; UINT64 MinimalMemorySizeNeeded; EFI_PHYSICAL_ADDRESS ResourceHobMemoryTop; EFI_PHYSICAL_ADDRESS BinTop; + EFI_STATUS Status; // // Point at the first HOB. This must be the PHIT HOB. @@ -2374,47 +2459,43 @@ CoreInitializeMemoryServices ( // See if a Memory Type Information HOB is available // MemoryTypeInformationResourceHob = NULL; - GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid); - if (GuidHob != NULL) { - EfiMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob); - DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob); - if ((EfiMemoryTypeInformation != NULL) && (DataSize > 0) && (DataSize <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION))) { - CopyMem (&gMemoryTypeInformation, EfiMemoryTypeInformation, DataSize); - - // - // Look for Resource Descriptor HOB with a ResourceType of System Memory - // and an Owner GUID of gEfiMemoryTypeInformationGuid. If more than 1 is - // found, then set MemoryTypeInformationResourceHob to NULL. - // - Count = 0; - for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { - if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { - continue; - } - - ResourceHob = Hob.ResourceDescriptor; - if (!CompareGuid (&ResourceHob->Owner, &gEfiMemoryTypeInformationGuid)) { - continue; - } - - Count++; - if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) { - continue; - } - - if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) { - continue; - } - - BinTop = ResourceHob->PhysicalStart + ResourceHob->ResourceLength; - if (ResourceHob->ResourceLength >= CalculateTotalMemoryBinSizeNeeded (&BinTop, gMemoryTypeInformation)) { - MemoryTypeInformationResourceHob = ResourceHob; - } + Status = PopulateMemoryTypeInformation (gMemoryTypeInformation); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "No Memory Type Information HOB found, S4 resume will likely fail\n")); + } else { + // + // Look for Resource Descriptor HOB with a ResourceType of System Memory + // and an Owner GUID of gEfiMemoryTypeInformationGuid. If more than 1 is + // found, then set MemoryTypeInformationResourceHob to NULL. + // + Count = 0; + for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { + continue; } - if (Count > 1) { - MemoryTypeInformationResourceHob = NULL; + ResourceHob = Hob.ResourceDescriptor; + if (!CompareGuid (&ResourceHob->Owner, &gEfiMemoryTypeInformationGuid)) { + continue; } + + Count++; + if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) { + continue; + } + + if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) { + continue; + } + + BinTop = ResourceHob->PhysicalStart + ResourceHob->ResourceLength; + if (ResourceHob->ResourceLength >= CalculateTotalMemoryBinSizeNeeded (&BinTop, gMemoryTypeInformation)) { + MemoryTypeInformationResourceHob = ResourceHob; + } + } + + if (Count > 1) { + MemoryTypeInformationResourceHob = NULL; } } From 1c8c92b7cc24be5f88b2685b87371facba9bd8ac Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Tue, 12 May 2026 09:52:07 -0700 Subject: [PATCH 064/406] MdeModulePkg: DxeCore: Add GetMemoryTypeInformationResourceHob Helper In preparation for sharing memory bin logic with PEI, create a helper function that finds and validates a resource descriptor HOB owned by gEfiMemoryTypeInformationGuid. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 110 +++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 37 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 6f23bbd9d0..920f972708 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -221,6 +221,74 @@ CleanAndError: return EFI_NOT_FOUND; } +/** + Look for Resource Descriptor HOB with a ResourceType of System Memory + and an Owner GUID of gEfiMemoryTypeInformationGuid. If more than 1 is + found, then return NULL. + + @param HobStart Pointer to the start of the HOB list. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + + @return Non-NULL The pointer to the singular MemoryTypeInformation Resource Descriptor HOB. + @return NULL No valid MemoryTypeInformation Resource Descriptor HOB found. +**/ +EFI_HOB_RESOURCE_DESCRIPTOR * +EFIAPI +GetMemoryTypeInformationResourceHob ( + IN VOID **HobStart, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ) +{ + UINTN Count; + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + EFI_HOB_RESOURCE_DESCRIPTOR *MemoryTypeInformationResourceHob; + EFI_PHYSICAL_ADDRESS BinTop; + + ASSERT (HobStart != NULL); + ASSERT (MemoryTypeInformation != NULL); + if ((HobStart == NULL) || (MemoryTypeInformation == NULL)) { + return NULL; + } + + // + // See if a Memory Type Information HOB is available + // + MemoryTypeInformationResourceHob = NULL; + Count = 0; + for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { + continue; + } + + ResourceHob = Hob.ResourceDescriptor; + if (!CompareGuid (&ResourceHob->Owner, &gEfiMemoryTypeInformationGuid)) { + continue; + } + + Count++; + if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) { + continue; + } + + if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) { + continue; + } + + BinTop = ResourceHob->PhysicalStart + ResourceHob->ResourceLength; + if (ResourceHob->ResourceLength >= CalculateTotalMemoryBinSizeNeeded (&BinTop, MemoryTypeInformation)) { + MemoryTypeInformationResourceHob = ResourceHob; + } + } + + if (Count > 1) { + return NULL; + } + + return MemoryTypeInformationResourceHob; +} + /** Dump the entire contents if the GCD Memory Space Map using DEBUG() macros when PcdDebugPrintErrorLevel has the DEBUG_GCD bit set. @@ -2404,7 +2472,6 @@ CoreInitializeMemoryServices ( EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; EFI_HOB_RESOURCE_DESCRIPTOR *PhitResourceHob; EFI_HOB_RESOURCE_DESCRIPTOR *MemoryTypeInformationResourceHob; - UINTN Count; EFI_PHYSICAL_ADDRESS BaseAddress; UINT64 Length; UINT64 Attributes; @@ -2415,7 +2482,6 @@ CoreInitializeMemoryServices ( UINT32 ReservedCodePageNumber; UINT64 MinimalMemorySizeNeeded; EFI_PHYSICAL_ADDRESS ResourceHobMemoryTop; - EFI_PHYSICAL_ADDRESS BinTop; EFI_STATUS Status; // @@ -2462,43 +2528,13 @@ CoreInitializeMemoryServices ( Status = PopulateMemoryTypeInformation (gMemoryTypeInformation); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_WARN, "No Memory Type Information HOB found, S4 resume will likely fail\n")); - } else { - // - // Look for Resource Descriptor HOB with a ResourceType of System Memory - // and an Owner GUID of gEfiMemoryTypeInformationGuid. If more than 1 is - // found, then set MemoryTypeInformationResourceHob to NULL. - // - Count = 0; - for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { - if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { - continue; - } - - ResourceHob = Hob.ResourceDescriptor; - if (!CompareGuid (&ResourceHob->Owner, &gEfiMemoryTypeInformationGuid)) { - continue; - } - - Count++; - if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) { - continue; - } - - if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) { - continue; - } - - BinTop = ResourceHob->PhysicalStart + ResourceHob->ResourceLength; - if (ResourceHob->ResourceLength >= CalculateTotalMemoryBinSizeNeeded (&BinTop, gMemoryTypeInformation)) { - MemoryTypeInformationResourceHob = ResourceHob; - } - } - - if (Count > 1) { - MemoryTypeInformationResourceHob = NULL; - } } + MemoryTypeInformationResourceHob = GetMemoryTypeInformationResourceHob ( + HobStart, + gMemoryTypeInformation + ); + // // Include the total memory bin size needed to make sure memory bin could be allocated successfully. // From 47e73e61c6eaca1c611c9ba19eb5a92f16139613 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Tue, 12 May 2026 14:18:09 -0700 Subject: [PATCH 065/406] MdeModulePkg: Dxe Core: Add AllocateMemoryBins Helper Fn In preparation for sharing logic with PEI for memory bins, add AllocateMemoryTypeInformationBins(). Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Mem/Page.c | 263 ++++++++++++++++++------------- 1 file changed, 156 insertions(+), 107 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 0c659d79b0..f59128b6a0 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -95,6 +95,156 @@ EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = { // GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALSE; +/** + Allocate memory bins for each memory type as specified in gMemoryTypeInformation. + + If all the memory types cannot be allocated, then all previously allocated + memory types are freed and the function returns. If this function fails, it will log and expect to be called + again when more memory is added to the system. + + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. +**/ +VOID +EFIAPI +AllocateMemoryTypeInformationBins ( + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress + ) +{ + UINTN Index; + EFI_MEMORY_TYPE Type; + EFI_PHYSICAL_ADDRESS BaseAddress; + EFI_PHYSICAL_ADDRESS LastBinAddress; + UINT64 RequiredSize; + + ASSERT (MemoryTypeInformationInitialized != NULL); + ASSERT (MemoryTypeInformation != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (DefaultMaximumAddress != NULL); + + if ((MemoryTypeInformationInitialized == NULL) || + (MemoryTypeInformation == NULL) || + (MemoryTypeStatistics == NULL) || + (DefaultMaximumAddress == NULL)) + { + return; + } + + // + // Check to see if the statistics for the different memory types have already been established + // + if (*MemoryTypeInformationInitialized) { + return; + } + + BaseAddress = 0; + RequiredSize = CalculateTotalMemoryBinSizeNeeded (NULL, MemoryTypeInformation); + if (RequiredSize == 0) { + *MemoryTypeInformationInitialized = TRUE; + return; + } + + // To ensure we get a contiguous range of memory for our bins, we will attempt to allocate + // all of the memory needed in one go. If that works, we can then carve it up into the individual bins. + // Our size is already aligned to the correct granularity, allocate aligned pages to ensure the base address is + // aligned. + BaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAlignedPages ( + EFI_SIZE_TO_PAGES ((UINTN)RequiredSize), + RUNTIME_PAGE_ALLOCATION_GRANULARITY + ); + + if (BaseAddress == 0) { + DEBUG (( + DEBUG_INFO, + "%a: Could not allocate contiguous pages for all memory bins. It will be attempted again when more memory is added.\n", + __func__ + )); + return; + } + + DEBUG (( + DEBUG_INFO, + "%a: Allocated 0x%llx - 0x%llx for memory bins\n", + __func__, + BaseAddress, + BaseAddress + RequiredSize - 1 + )); + + LastBinAddress = BaseAddress + RequiredSize; + *DefaultMaximumAddress = BaseAddress - 1; + + // + // Loop through each memory type in the order specified by the gMemoryTypeInformation[] array + // + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the gMemoryTypeInformation[] array is valid + // + Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); + if ((UINT32)Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + MemoryTypeStatistics[Type].BaseAddress = LastBinAddress - EFI_PAGES_TO_SIZE (MemoryTypeInformation[Index].NumberOfPages); + MemoryTypeStatistics[Type].MaximumAddress = LastBinAddress - 1; + LastBinAddress = MemoryTypeStatistics[Type].BaseAddress; + } + } + + // + // There was enough system memory for all the the memory types were allocated. So, + // those memory areas can be freed for future allocations, and all future memory + // allocations can occur within their respective bins + // + FreeAlignedPages ( + (VOID *)(UINTN)BaseAddress, + EFI_SIZE_TO_PAGES ((UINTN)RequiredSize) + ); + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the MemoryTypeInformation[] array is valid + // + Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); + if ((UINT32)Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + MemoryTypeStatistics[Type].NumberOfPages = MemoryTypeInformation[Index].NumberOfPages; + MemoryTypeInformation[Index].NumberOfPages = 0; + } + } + + // + // If the number of pages reserved for a memory type is 0, then all allocations for that type + // should be in the default range. + // + for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) { + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + if (Type == (EFI_MEMORY_TYPE)MemoryTypeInformation[Index].Type) { + MemoryTypeStatistics[Type].InformationIndex = Index; + } + } + + MemoryTypeStatistics[Type].CurrentNumberOfPages = 0; + if (MemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) { + MemoryTypeStatistics[Type].MaximumAddress = mDefaultMaximumAddress; + } + } + + *MemoryTypeInformationInitialized = TRUE; +} + /** Enter critical section by gaining lock on gMemoryLock. @@ -684,10 +834,6 @@ CoreAddMemoryDescriptor ( ) { EFI_PHYSICAL_ADDRESS End; - UINTN Index; - EFI_PHYSICAL_ADDRESS BaseAddress; - EFI_PHYSICAL_ADDRESS LastBinAddress; - UINT64 RequiredSize; if ((Start & EFI_PAGE_MASK) != 0) { return; @@ -717,110 +863,13 @@ CoreAddMemoryDescriptor ( CoreLoadingFixedAddressHook (); } - // - // Check to see if the statistics for the different memory types have already been established - // - if (mMemoryTypeInformationInitialized) { - return; - } - - BaseAddress = 0; - RequiredSize = CalculateTotalMemoryBinSizeNeeded (NULL, gMemoryTypeInformation); - if (RequiredSize == 0) { - mMemoryTypeInformationInitialized = TRUE; - return; - } - - // To ensure we get a contiguous range of memory for our bins, we will attempt to allocate - // all of the memory needed in one go. If that works, we can then carve it up into the individual bins. - // Our size is already aligned to the correct granularity, allocate aligned pages to ensure the base address is - // aligned. - BaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAlignedPages ( - EFI_SIZE_TO_PAGES ((UINTN)RequiredSize), - RUNTIME_PAGE_ALLOCATION_GRANULARITY - ); - - if (BaseAddress == 0) { - DEBUG (( - DEBUG_INFO, - "%a: Could not allocate contiguous pages for all memory bins. It will be attempted again when more memory is added.\n", - __func__ - )); - return; - } - - DEBUG (( - DEBUG_INFO, - "%a: Allocated 0x%llx - 0x%llx for memory bins\n", - __func__, - BaseAddress, - BaseAddress + RequiredSize - 1 - )); - - LastBinAddress = BaseAddress + RequiredSize; - mDefaultMaximumAddress = BaseAddress - 1; - - // - // Loop through each memory type in the order specified by the gMemoryTypeInformation[] array - // - for (Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - // - // Make sure the memory type in the gMemoryTypeInformation[] array is valid - // - Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[Index].Type); - if ((UINT32)Type > EfiMaxMemoryType) { - continue; - } - - if (gMemoryTypeInformation[Index].NumberOfPages != 0) { - mMemoryTypeStatistics[Type].BaseAddress = LastBinAddress - EFI_PAGES_TO_SIZE (gMemoryTypeInformation[Index].NumberOfPages); - mMemoryTypeStatistics[Type].MaximumAddress = LastBinAddress - 1; - LastBinAddress = mMemoryTypeStatistics[Type].BaseAddress; - } - } - - // - // There was enough system memory for all the the memory types were allocated. So, - // those memory areas can be freed for future allocations, and all future memory - // allocations can occur within their respective bins - // - FreeAlignedPages ( - (VOID *)(UINTN)BaseAddress, - EFI_SIZE_TO_PAGES ((UINTN)RequiredSize) + // Check if we need to allocate the memory bins. This function will immediately return if we have already done so. + AllocateMemoryTypeInformationBins ( + &mMemoryTypeInformationInitialized, + gMemoryTypeInformation, + mMemoryTypeStatistics, + &mDefaultMaximumAddress ); - for (Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - // - // Make sure the memory type in the gMemoryTypeInformation[] array is valid - // - Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[Index].Type); - if ((UINT32)Type > EfiMaxMemoryType) { - continue; - } - - if (gMemoryTypeInformation[Index].NumberOfPages != 0) { - mMemoryTypeStatistics[Type].NumberOfPages = gMemoryTypeInformation[Index].NumberOfPages; - gMemoryTypeInformation[Index].NumberOfPages = 0; - } - } - - // - // If the number of pages reserved for a memory type is 0, then all allocations for that type - // should be in the default range. - // - for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) { - for (Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - if (Type == (EFI_MEMORY_TYPE)gMemoryTypeInformation[Index].Type) { - mMemoryTypeStatistics[Type].InformationIndex = Index; - } - } - - mMemoryTypeStatistics[Type].CurrentNumberOfPages = 0; - if (mMemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) { - mMemoryTypeStatistics[Type].MaximumAddress = mDefaultMaximumAddress; - } - } - - mMemoryTypeInformationInitialized = TRUE; } /** From 6b838a0d44edcf95c4edfa12212e19c7b79ab721 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Tue, 12 May 2026 14:21:29 -0700 Subject: [PATCH 066/406] MdeModulePkg: Dxe Core: Add UpdateMemoryStatistics Helper Fn In preparation for sharing logic with PEI, create a helper function to update the memory bin statistics. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Mem/Page.c | 108 ++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 25 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index f59128b6a0..da89700faa 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -245,6 +245,78 @@ AllocateMemoryTypeInformationBins ( *MemoryTypeInformationInitialized = TRUE; } +/** + Update memory type statistics upon memory allocation and free. + + @param OldType The original memory type of the memory region. + @param NewType The new memory type of the memory region. + @param Start The starting physical address of the memory region. + @param NumberOfPages The number of pages in the memory region. + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeStatistics The memory type statistics array to be updated. + @param MemoryTypeInformation The memory type information array to be updated. + @param DefaultBaseAddress Default bin base address. + @param DefaultMaximumAddress Default bin maximum address. +**/ +VOID +EFIAPI +UpdateMemoryStatistics ( + IN EFI_MEMORY_TYPE OldType, + IN EFI_MEMORY_TYPE NewType, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINTN NumberOfPages, + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_PHYSICAL_ADDRESS DefaultBaseAddress, + IN EFI_PHYSICAL_ADDRESS DefaultMaximumAddress + ) +{ + ASSERT (MemoryTypeInformationInitialized != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (MemoryTypeInformation != NULL); + + if ((MemoryTypeInformationInitialized == NULL) || + (MemoryTypeStatistics == NULL) || + (MemoryTypeInformation == NULL)) + { + return; + } + + if (!*MemoryTypeInformationInitialized) { + return; + } + + // + // Update counters for the number of pages allocated to each memory type + // + if ((UINT32)OldType < EfiMaxMemoryType) { + if (((Start >= MemoryTypeStatistics[OldType].BaseAddress) && (Start <= MemoryTypeStatistics[OldType].MaximumAddress)) || + ((Start >= DefaultBaseAddress) && (Start <= DefaultMaximumAddress))) + { + if (NumberOfPages > MemoryTypeStatistics[OldType].CurrentNumberOfPages) { + MemoryTypeStatistics[OldType].CurrentNumberOfPages = 0; + } else { + MemoryTypeStatistics[OldType].CurrentNumberOfPages -= NumberOfPages; + } + } + } + + if ((UINT32)NewType < EfiMaxMemoryType) { + if (((Start >= MemoryTypeStatistics[NewType].BaseAddress) && (Start <= MemoryTypeStatistics[NewType].MaximumAddress)) || + ((Start >= DefaultBaseAddress) && (Start <= DefaultMaximumAddress))) + { + MemoryTypeStatistics[NewType].CurrentNumberOfPages += NumberOfPages; + if ((MemoryTypeStatistics[NewType].InformationIndex < (UINTN)EfiMaxMemoryType) && + (MemoryTypeStatistics[NewType].CurrentNumberOfPages > MemoryTypeInformation[MemoryTypeStatistics[NewType].InformationIndex].NumberOfPages)) + { + MemoryTypeInformation[MemoryTypeStatistics[NewType].InformationIndex].NumberOfPages = (UINT32)MemoryTypeStatistics[NewType].CurrentNumberOfPages; + } + } + } +} + /** Enter critical section by gaining lock on gMemoryLock. @@ -994,31 +1066,17 @@ CoreConvertPagesEx ( return EFI_NOT_FOUND; } - // - // Update counters for the number of pages allocated to each memory type - // - if ((UINT32)Entry->Type < EfiMaxMemoryType) { - if (((Start >= mMemoryTypeStatistics[Entry->Type].BaseAddress) && (Start <= mMemoryTypeStatistics[Entry->Type].MaximumAddress)) || - ((Start >= mDefaultBaseAddress) && (Start <= mDefaultMaximumAddress))) - { - if (NumberOfPages > mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages) { - mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages = 0; - } else { - mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages -= NumberOfPages; - } - } - } - - if ((UINT32)NewType < EfiMaxMemoryType) { - if (((Start >= mMemoryTypeStatistics[NewType].BaseAddress) && (Start <= mMemoryTypeStatistics[NewType].MaximumAddress)) || - ((Start >= mDefaultBaseAddress) && (Start <= mDefaultMaximumAddress))) - { - mMemoryTypeStatistics[NewType].CurrentNumberOfPages += NumberOfPages; - if (mMemoryTypeStatistics[NewType].CurrentNumberOfPages > gMemoryTypeInformation[mMemoryTypeStatistics[NewType].InformationIndex].NumberOfPages) { - gMemoryTypeInformation[mMemoryTypeStatistics[NewType].InformationIndex].NumberOfPages = (UINT32)mMemoryTypeStatistics[NewType].CurrentNumberOfPages; - } - } - } + UpdateMemoryStatistics ( + Entry->Type, + NewType, + Start, + (UINTN)NumberOfPages, + &mMemoryTypeInformationInitialized, + mMemoryTypeStatistics, + gMemoryTypeInformation, + mDefaultBaseAddress, + mDefaultMaximumAddress + ); } // From 81bec6f0fbf686fa94b193eb16cba4729dfbc98b Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Tue, 12 May 2026 14:27:09 -0700 Subject: [PATCH 067/406] MdeModulePkg: Dxe Core: Prep CoreSetMemoryTypeInformationRange for PEI Migrate CoreSetMemoryTypeInformationRange() to not use globals so it can be used in PEI as well. This temporarily moves the EFI_MEMORY_STATISTICS structure to DxeMain.h so that it can be used in Gcd.c as well as Page.c. This will migrate to a different private header once that is included. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/DxeMain.h | 45 +++++++++++++++- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 6 ++- MdeModulePkg/Core/Dxe/Mem/Page.c | 89 ++++++++++++++++++-------------- 3 files changed, 99 insertions(+), 41 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index 91ae6fa0b4..4cc760febc 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -229,6 +229,19 @@ typedef struct { #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \ CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE) +// +// Entry in an array that keeps track of memory type statistics per memory bin +// +typedef struct { + EFI_PHYSICAL_ADDRESS BaseAddress; + EFI_PHYSICAL_ADDRESS MaximumAddress; + UINT64 CurrentNumberOfPages; + UINT64 NumberOfPages; + UINTN InformationIndex; + BOOLEAN Special; + BOOLEAN Runtime; +} EFI_MEMORY_TYPE_STATISTICS; + // // DXE Core Global Variables // @@ -258,6 +271,10 @@ extern EFI_GUID *gDxeCoreFileName; extern EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage; extern EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1]; +extern BOOLEAN mMemoryTypeInformationInitialized; +extern EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1]; +extern EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress; +extern EFI_PHYSICAL_ADDRESS mDefaultBaseAddress; extern BOOLEAN gDispatcherRunning; extern EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate; @@ -279,10 +296,34 @@ CoreInitializePool ( VOID ); +/** + Sets the preferred memory range to use for the Memory Type Information bins. + This service must be called before fist call to CoreAddMemoryDescriptor(). + + If the location of the Memory Type Information bins has already been + established or the size of the range provides is smaller than all the + Memory Type Information bins, then the range provides is not used. + + @param Start The start address of the Memory Type Information range. + @param Length The size, in bytes, of the Memory Type Information range. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. +**/ VOID +EFIAPI CoreSetMemoryTypeInformationRange ( - IN EFI_PHYSICAL_ADDRESS Start, - IN UINT64 Length + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress ); /** diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 920f972708..90db91365c 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -2754,7 +2754,11 @@ CoreInitializeMemoryServices ( // CoreSetMemoryTypeInformationRange ( MemoryTypeInformationResourceHob->PhysicalStart, - MemoryTypeInformationResourceHob->ResourceLength + MemoryTypeInformationResourceHob->ResourceLength, + gMemoryTypeInformation, + &mMemoryTypeInformationInitialized, + mMemoryTypeStatistics, + &mDefaultMaximumAddress ); } diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index da89700faa..644bea2436 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -11,19 +11,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "HeapGuard.h" #include -// -// Entry for tracking the memory regions for each memory type to coalesce similar memory types -// -typedef struct { - EFI_PHYSICAL_ADDRESS BaseAddress; - EFI_PHYSICAL_ADDRESS MaximumAddress; - UINT64 CurrentNumberOfPages; - UINT64 NumberOfPages; - UINTN InformationIndex; - BOOLEAN Special; - BOOLEAN Runtime; -} EFI_MEMORY_TYPE_STATISTICS; - // // MemoryMap - The current memory map // @@ -786,19 +773,32 @@ CoreLoadingFixedAddressHook ( /** Sets the preferred memory range to use for the Memory Type Information bins. - This service must be called before fist call to CoreAddMemoryDescriptor(). + This service must be called before first call to CoreAddMemoryDescriptor(). If the location of the Memory Type Information bins has already been established or the size of the range provides is smaller than all the Memory Type Information bins, then the range provides is not used. - @param Start The start address of the Memory Type Information range. - @param Length The size, in bytes, of the Memory Type Information range. + @param Start The start address of the Memory Type Information range. + @param Length The size, in bytes, of the Memory Type Information range. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. **/ VOID +EFIAPI CoreSetMemoryTypeInformationRange ( - IN EFI_PHYSICAL_ADDRESS Start, - IN UINT64 Length + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress ) { EFI_PHYSICAL_ADDRESS Top; @@ -806,10 +806,23 @@ CoreSetMemoryTypeInformationRange ( UINTN Index; UINT64 Size; + ASSERT (MemoryTypeInformation != NULL); + ASSERT (MemoryTypeInformationInitialized != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (DefaultMaximumAddress != NULL); + + if ((MemoryTypeInformation == NULL) || + (MemoryTypeInformationInitialized == NULL) || + (MemoryTypeStatistics == NULL) || + (DefaultMaximumAddress == NULL)) + { + return; + } + // // Return if Memory Type Information bin locations have already been set // - if (mMemoryTypeInformationInitialized) { + if (*MemoryTypeInformationInitialized) { DEBUG ((DEBUG_ERROR, "%a: Ignored. Bins already set.\n", __func__)); return; } @@ -818,7 +831,7 @@ CoreSetMemoryTypeInformationRange ( // Return if size of the Memory Type Information bins is greater than Length // Top = Start + Length; - Size = CalculateTotalMemoryBinSizeNeeded (&Top, gMemoryTypeInformation); + Size = CalculateTotalMemoryBinSizeNeeded (&Top, MemoryTypeInformation); if (Size > Length) { return; @@ -828,30 +841,30 @@ CoreSetMemoryTypeInformationRange ( // Loop through each memory type in the order specified by the // gMemoryTypeInformation[] array // - for (Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { // - // Make sure the memory type in the gMemoryTypeInformation[] array is valid + // Make sure the memory type in the MemoryTypeInformation[] array is valid // - Type = (EFI_MEMORY_TYPE)(gMemoryTypeInformation[Index].Type); + Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); if ((UINT32)Type > EfiMaxMemoryType) { continue; } - if (gMemoryTypeInformation[Index].NumberOfPages != 0) { - mMemoryTypeStatistics[Type].MaximumAddress = Top - 1; - Top -= LShiftU64 (gMemoryTypeInformation[Index].NumberOfPages, EFI_PAGE_SHIFT); - mMemoryTypeStatistics[Type].BaseAddress = Top; + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + MemoryTypeStatistics[Type].MaximumAddress = Top - 1; + Top -= EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); + MemoryTypeStatistics[Type].BaseAddress = Top; // // If the current base address is the lowest address so far, then update // the default maximum address // - if (mMemoryTypeStatistics[Type].BaseAddress < mDefaultMaximumAddress) { - mDefaultMaximumAddress = mMemoryTypeStatistics[Type].BaseAddress - 1; + if (MemoryTypeStatistics[Type].BaseAddress < *DefaultMaximumAddress) { + *DefaultMaximumAddress = MemoryTypeStatistics[Type].BaseAddress - 1; } - mMemoryTypeStatistics[Type].NumberOfPages = gMemoryTypeInformation[Index].NumberOfPages; - gMemoryTypeInformation[Index].NumberOfPages = 0; + MemoryTypeStatistics[Type].NumberOfPages = MemoryTypeInformation[Index].NumberOfPages; + MemoryTypeInformation[Index].NumberOfPages = 0; } } @@ -860,15 +873,15 @@ CoreSetMemoryTypeInformationRange ( // allocations for that type should be in the default range. // for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) { - for (Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - if (Type == (EFI_MEMORY_TYPE)gMemoryTypeInformation[Index].Type) { - mMemoryTypeStatistics[Type].InformationIndex = Index; + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + if (Type == (EFI_MEMORY_TYPE)MemoryTypeInformation[Index].Type) { + MemoryTypeStatistics[Type].InformationIndex = Index; } } - mMemoryTypeStatistics[Type].CurrentNumberOfPages = 0; - if (mMemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) { - mMemoryTypeStatistics[Type].MaximumAddress = mDefaultMaximumAddress; + MemoryTypeStatistics[Type].CurrentNumberOfPages = 0; + if (MemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) { + MemoryTypeStatistics[Type].MaximumAddress = *DefaultMaximumAddress; } } @@ -879,7 +892,7 @@ CoreSetMemoryTypeInformationRange ( Start, Start + Length -1 )); - mMemoryTypeInformationInitialized = TRUE; + *MemoryTypeInformationInitialized = TRUE; } /** From b33c1b9f7d00e1b06910385dcfac2174f2f081f9 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Tue, 12 May 2026 14:42:30 -0700 Subject: [PATCH 068/406] MdeModulePkg: Dxe Core: Add Stats Init Helper This adds a helper function to initialize the memory bin statistics as the same logic is repeated in several places. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Mem/Page.c | 81 +++++++++++++++++++------------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 644bea2436..f0b3a91603 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -212,22 +212,7 @@ AllocateMemoryTypeInformationBins ( } } - // - // If the number of pages reserved for a memory type is 0, then all allocations for that type - // should be in the default range. - // - for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) { - for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - if (Type == (EFI_MEMORY_TYPE)MemoryTypeInformation[Index].Type) { - MemoryTypeStatistics[Type].InformationIndex = Index; - } - } - - MemoryTypeStatistics[Type].CurrentNumberOfPages = 0; - if (MemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) { - MemoryTypeStatistics[Type].MaximumAddress = mDefaultMaximumAddress; - } - } + InitializeBinStatisticsFromRange (MemoryTypeInformation, MemoryTypeStatistics, DefaultMaximumAddress); *MemoryTypeInformationInitialized = TRUE; } @@ -304,6 +289,53 @@ UpdateMemoryStatistics ( } } +/** + Helper function to set up the bin statistics with the provided bin range + + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeStatistics The memory type statistics to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. +**/ +STATIC +VOID +InitializeBinStatisticsFromRange ( + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress + ) +{ + EFI_MEMORY_TYPE Type; + UINTN Index; + + ASSERT (MemoryTypeInformation != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (DefaultMaximumAddress != NULL); + + if ((MemoryTypeInformation == NULL) || (MemoryTypeStatistics == NULL) || (DefaultMaximumAddress == NULL)) { + return; + } + + // + // If the number of pages reserved for a memory type is 0, then all + // allocations for that type should be in the default range. + // + for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) { + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + if (Type == (EFI_MEMORY_TYPE)MemoryTypeInformation[Index].Type) { + MemoryTypeStatistics[Type].InformationIndex = Index; + } + } + + MemoryTypeStatistics[Type].CurrentNumberOfPages = 0; + if (MemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) { + MemoryTypeStatistics[Type].MaximumAddress = *DefaultMaximumAddress; + } + } +} + /** Enter critical section by gaining lock on gMemoryLock. @@ -868,22 +900,7 @@ CoreSetMemoryTypeInformationRange ( } } - // - // If the number of pages reserved for a memory type is 0, then all - // allocations for that type should be in the default range. - // - for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) { - for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - if (Type == (EFI_MEMORY_TYPE)MemoryTypeInformation[Index].Type) { - MemoryTypeStatistics[Type].InformationIndex = Index; - } - } - - MemoryTypeStatistics[Type].CurrentNumberOfPages = 0; - if (MemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) { - MemoryTypeStatistics[Type].MaximumAddress = *DefaultMaximumAddress; - } - } + InitializeBinStatisticsFromRange (MemoryTypeInformation, MemoryTypeStatistics, DefaultMaximumAddress); DEBUG (( DEBUG_INFO, From a196ef6db5c77708dde3528dc735494037f16ab3 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Tue, 12 May 2026 14:46:18 -0700 Subject: [PATCH 069/406] MdeModulePkg: Dxe Core: Add Resource Desc Hob Generation This commit adds a parameter to the memory bin allocation function to tell it whether it should create the Resource Descriptor HOB owned by gMemoryTypeInformationGuid. This will be used by PEI to tell DXE where the memory bins are. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Mem/Page.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index f0b3a91603..2775fa0160 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -97,6 +97,10 @@ GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALS information if the provided range is used. @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the provided range is used. + @param CreateHob TRUE to create Memory Type Information Resource HOB after successful + allocation. This is used for PEI Core to report the bins to DXE Core. + DXE Core must set this to FALSE because HOB creation is not supported in + DXE (nor is the information required to be passed to another entity). **/ VOID EFIAPI @@ -104,7 +108,8 @@ AllocateMemoryTypeInformationBins ( IN BOOLEAN *MemoryTypeInformationInitialized, IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, - IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress, + IN BOOLEAN CreateHob ) { UINTN Index; @@ -214,6 +219,19 @@ AllocateMemoryTypeInformationBins ( InitializeBinStatisticsFromRange (MemoryTypeInformation, MemoryTypeStatistics, DefaultMaximumAddress); + if (CreateHob) { + // + // Create a Resource Descriptor HOB to report the Memory Type Information bins to DXE Core + // + BuildResourceDescriptorWithOwnerHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + TESTED_MEMORY_ATTRIBUTES, + BaseAddress, + RequiredSize, + &gEfiMemoryTypeInformationGuid + ); + } + *MemoryTypeInformationInitialized = TRUE; } @@ -966,11 +984,13 @@ CoreAddMemoryDescriptor ( } // Check if we need to allocate the memory bins. This function will immediately return if we have already done so. + // Pass FALSE to indicate we don't need to publish the HOB. AllocateMemoryTypeInformationBins ( &mMemoryTypeInformationInitialized, gMemoryTypeInformation, mMemoryTypeStatistics, - &mDefaultMaximumAddress + &mDefaultMaximumAddress, + FALSE ); } From eab3300622876b674cf22c5c56f899b0a6df1087 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Thu, 18 Jun 2026 09:32:27 -0700 Subject: [PATCH 070/406] MdeModulePkg: Dxe Core: Split Memory Bin Logic Into Separate File This commits splits out logic currently contained in Gcd.c and Page.c to a new file called MemoryBin.c. This is set up in preparation to add support to PEI for memory bins (an S4 resume stability feature). MemoryBin.c takes all global state in as parameters so that DXE core can use globals and PEI core can use HOBs. There is no logic change here, just consolidating the functionality to share with PEI. This was requested not to be a library. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/DxeMain.h | 66 +- MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 222 ------- MdeModulePkg/Core/Dxe/Mem/MemoryBin.c | 646 +++++++++++++++++++ MdeModulePkg/Core/Dxe/Mem/Page.c | 381 ----------- MdeModulePkg/Core/PrivateInclude/MemoryBin.h | 167 +++++ MdeModulePkg/MdeModulePkg.dec | 1 + 7 files changed, 817 insertions(+), 667 deletions(-) create mode 100644 MdeModulePkg/Core/Dxe/Mem/MemoryBin.c create mode 100644 MdeModulePkg/Core/PrivateInclude/MemoryBin.h diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index 4cc760febc..e6b2776325 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -86,6 +86,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +#include + // // attributes for reserved memory before it is promoted to system memory // @@ -229,19 +231,6 @@ typedef struct { #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \ CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE) -// -// Entry in an array that keeps track of memory type statistics per memory bin -// -typedef struct { - EFI_PHYSICAL_ADDRESS BaseAddress; - EFI_PHYSICAL_ADDRESS MaximumAddress; - UINT64 CurrentNumberOfPages; - UINT64 NumberOfPages; - UINTN InformationIndex; - BOOLEAN Special; - BOOLEAN Runtime; -} EFI_MEMORY_TYPE_STATISTICS; - // // DXE Core Global Variables // @@ -296,36 +285,6 @@ CoreInitializePool ( VOID ); -/** - Sets the preferred memory range to use for the Memory Type Information bins. - This service must be called before fist call to CoreAddMemoryDescriptor(). - - If the location of the Memory Type Information bins has already been - established or the size of the range provides is smaller than all the - Memory Type Information bins, then the range provides is not used. - - @param Start The start address of the Memory Type Information range. - @param Length The size, in bytes, of the Memory Type Information range. - @param MemoryTypeInformation The memory type information array to be used to determine - the size of the memory bins. - @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type - information bins have been initialized. - @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin - information if the provided range is used. - @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the - provided range is used. -**/ -VOID -EFIAPI -CoreSetMemoryTypeInformationRange ( - IN EFI_PHYSICAL_ADDRESS Start, - IN UINT64 Length, - IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, - IN BOOLEAN *MemoryTypeInformationInitialized, - IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, - IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress - ); - /** Called to initialize the memory map and add descriptors to the current descriptor list. @@ -2843,24 +2802,3 @@ EFI_STATUS CoreInitializeHandleServices ( VOID ); - -/** - Calculate total memory bin size needed. - - @param BinTop The top address of the memory bins. This is an optional parameter. - When NULL, the returned size meets the alignment requirements as long as - the base address selected also meets the alignment requirements. When - non-NULL, then the returned BinTop value and the returned size both meet - the alignment requirements. When non-NULL, this will be updated on - output to the new top address of the memory bins that must be used to - satisfy alignment requirements. - @param MemoryTypeInformation The memory type information array. - - @return The total memory bin size needed. - -**/ -UINT64 -CalculateTotalMemoryBinSizeNeeded ( - IN OUT OPTIONAL EFI_PHYSICAL_ADDRESS *BinTop, - IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation - ); diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf index 40e7dc8d41..39f92c9bd2 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -48,6 +48,7 @@ Mem/Page.c Mem/MemData.c Mem/Imem.h + Mem/MemoryBin.c Mem/MemoryProfileRecord.c Mem/HeapGuard.c Mem/HeapGuard.h diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 90db91365c..6d66857617 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -134,161 +134,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdAllocationTypeNames[] = { "Unknown " // EfiGcdMaxAllocateType }; -/** - Get the Memory Type Information HOB if it exists and populate gMemoryTypeInformation. - - @param MemoryTypeInformation The pointer to the memory type information array to be populated. - - @return EFI_STATUS On EFI_SUCCESS, gMemoryTypeInformation points to the - Memory Type Information. - @return EFI_NOT_FOUND No valid Memory Type Information HOB found. -**/ -EFI_STATUS -EFIAPI -PopulateMemoryTypeInformation ( - IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation - ) -{ - UINTN DataSize; - EFI_MEMORY_TYPE_INFORMATION *EfiMemoryTypeInformation; - EFI_HOB_GUID_TYPE *GuidHob; - UINTN Index; - UINT32 Granularity; - UINTN MaxIndex; - - ASSERT (MemoryTypeInformation != NULL); - if (MemoryTypeInformation == NULL) { - return EFI_INVALID_PARAMETER; - } - - GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid); - if (GuidHob != NULL) { - EfiMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob); - DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob); - - if ((EfiMemoryTypeInformation != NULL) && (DataSize > 0) && (DataSize <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION))) { - CopyMem (MemoryTypeInformation, EfiMemoryTypeInformation, DataSize); - MaxIndex = (DataSize / sizeof (EFI_MEMORY_TYPE_INFORMATION)) - 1; - - for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - // - // Make sure the memory type in the MemoryTypeInformation[] array is valid - // - if (MemoryTypeInformation[Index].Type > EfiMaxMemoryType) { - continue; - } - - if (MemoryTypeInformation[Index].NumberOfPages != 0) { - if ((MemoryTypeInformation[Index].Type == EfiReservedMemoryType) || - (MemoryTypeInformation[Index].Type == EfiACPIMemoryNVS) || - (MemoryTypeInformation[Index].Type == EfiRuntimeServicesCode) || - (MemoryTypeInformation[Index].Type == EfiRuntimeServicesData)) - { - Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; - } else { - Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; - } - - // Align the number of pages to the allocation granularity - MemoryTypeInformation[Index].NumberOfPages = (UINT32)EFI_SIZE_TO_PAGES (ALIGN_VALUE (EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages), Granularity)); - } - - // It is guaranteed that DataSize must be > 0 and <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION) - // however, we may have a corrupted HOB that does end in the EfiMaxMemoryType, so we need to terminate the loop - // to not overrun the array. Because we can't trust the HOB data, we will reset it to 0. - if (Index == MaxIndex) { - DEBUG ((DEBUG_WARN, "%a: Corrupted Memory Type Information HOB data\n", __func__)); - goto CleanAndError; - } - } - - return EFI_SUCCESS; - } - - DEBUG ((DEBUG_WARN, "%a: Invalid Memory Type Information HOB data\n", __func__)); - } - -CleanAndError: - // We may have gotten here from a corrupted HOB, ensure all data is set back - // to disabled bins. - for (Index = 0; Index <= EfiMaxMemoryType; Index++) { - MemoryTypeInformation[Index].Type = (UINT32)Index; - MemoryTypeInformation[Index].NumberOfPages = 0; - } - - DEBUG ((DEBUG_WARN, "%a: No Memory Type Information HOB found, S4 resume is likely to fail\n", __func__)); - - return EFI_NOT_FOUND; -} - -/** - Look for Resource Descriptor HOB with a ResourceType of System Memory - and an Owner GUID of gEfiMemoryTypeInformationGuid. If more than 1 is - found, then return NULL. - - @param HobStart Pointer to the start of the HOB list. - @param MemoryTypeInformation The memory type information array to be used to determine - the size of the memory bins. - - @return Non-NULL The pointer to the singular MemoryTypeInformation Resource Descriptor HOB. - @return NULL No valid MemoryTypeInformation Resource Descriptor HOB found. -**/ -EFI_HOB_RESOURCE_DESCRIPTOR * -EFIAPI -GetMemoryTypeInformationResourceHob ( - IN VOID **HobStart, - IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation - ) -{ - UINTN Count; - EFI_PEI_HOB_POINTERS Hob; - EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; - EFI_HOB_RESOURCE_DESCRIPTOR *MemoryTypeInformationResourceHob; - EFI_PHYSICAL_ADDRESS BinTop; - - ASSERT (HobStart != NULL); - ASSERT (MemoryTypeInformation != NULL); - if ((HobStart == NULL) || (MemoryTypeInformation == NULL)) { - return NULL; - } - - // - // See if a Memory Type Information HOB is available - // - MemoryTypeInformationResourceHob = NULL; - Count = 0; - for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { - if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { - continue; - } - - ResourceHob = Hob.ResourceDescriptor; - if (!CompareGuid (&ResourceHob->Owner, &gEfiMemoryTypeInformationGuid)) { - continue; - } - - Count++; - if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) { - continue; - } - - if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) { - continue; - } - - BinTop = ResourceHob->PhysicalStart + ResourceHob->ResourceLength; - if (ResourceHob->ResourceLength >= CalculateTotalMemoryBinSizeNeeded (&BinTop, MemoryTypeInformation)) { - MemoryTypeInformationResourceHob = ResourceHob; - } - } - - if (Count > 1) { - return NULL; - } - - return MemoryTypeInformationResourceHob; -} - /** Dump the entire contents if the GCD Memory Space Map using DEBUG() macros when PcdDebugPrintErrorLevel has the DEBUG_GCD bit set. @@ -2319,73 +2164,6 @@ CoreConvertResourceDescriptorHobAttributesToCapabilities ( return Capabilities; } -/** - Calculate total memory bin size needed. - - @param BinTop The top address of the memory bins. This is an optional parameter. - When NULL, the returned size meets the alignment requirements as long as - the base address selected also meets the alignment requirements. When - non-NULL, then the returned BinTop value and the returned size both meet - the alignment requirements. When non-NULL, this will be updated on - output to the new top address of the memory bins that must be used to - satisfy alignment requirements. - @param MemoryTypeInformation The memory type information array. - - @return The total memory bin size needed. - -**/ -UINT64 -CalculateTotalMemoryBinSizeNeeded ( - IN OUT OPTIONAL EFI_PHYSICAL_ADDRESS *BinTop, - IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation - ) -{ - UINTN Index; - UINT64 TotalSize; - UINT64 Granularity; - - ASSERT (MemoryTypeInformation != NULL); - if (MemoryTypeInformation == NULL) { - return 0; - } - - // - // Loop through each memory type in the order specified by the MemoryTypeInformation[] array - // - TotalSize = 0; - for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; - if ((MemoryTypeInformation[Index].Type == EfiReservedMemoryType) || - (MemoryTypeInformation[Index].Type == EfiACPIMemoryNVS) || - (MemoryTypeInformation[Index].Type == EfiRuntimeServicesCode) || - (MemoryTypeInformation[Index].Type == EfiRuntimeServicesData)) - { - Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; - } - - // MemoryTypeInformation[Index].NumberOfPages is already aligned to the allocation granularity - TotalSize += EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); - - // BinTop is optional - if (BinTop == NULL) { - continue; - } - - // Lower the bin top to the next aligned address, taking any padding into account in the size - *BinTop -= EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); - TotalSize += (*BinTop & (Granularity - 1)); - *BinTop &= ~(Granularity - 1); - } - - if (BinTop != NULL) { - // Set *BinTop to the new top of the memory bins. It currently points to the base address of - // the memory bins - *BinTop += TotalSize; - } - - return TotalSize; -} - /** Find the largest region in the specified region that is not covered by an existing memory allocation diff --git a/MdeModulePkg/Core/Dxe/Mem/MemoryBin.c b/MdeModulePkg/Core/Dxe/Mem/MemoryBin.c new file mode 100644 index 0000000000..ce116135c0 --- /dev/null +++ b/MdeModulePkg/Core/Dxe/Mem/MemoryBin.c @@ -0,0 +1,646 @@ +/** @file + + Shared logic between cores to work with memory bins for S4 resume stability. This file is duplicated in PEI Core and + DXE Core until a BaseTools feature comes online to support recommended library instances. Any changes to this file + must also be made in MdeModulePkg/Core/Pei/Memory/MemoryBin.c. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \ + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ + EFI_RESOURCE_ATTRIBUTE_TESTED | \ + EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED | \ + EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED | \ + EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED | \ + EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED | \ + EFI_RESOURCE_ATTRIBUTE_16_BIT_IO | \ + EFI_RESOURCE_ATTRIBUTE_32_BIT_IO | \ + EFI_RESOURCE_ATTRIBUTE_64_BIT_IO | \ + EFI_RESOURCE_ATTRIBUTE_PERSISTENT | \ + EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE ) + +#define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \ + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ + EFI_RESOURCE_ATTRIBUTE_TESTED ) + +/** + Calculate total memory bin size needed. + + @param BinTop The top address of the memory bins. This is an optional parameter. + When NULL, the returned size meets the alignment requirements as long as + the base address selected also meets the alignment requirements. When + non-NULL, then the returned BinTop value and the returned size both meet + the alignment requirements. When non-NULL, this will be updated on + output to the new top address of the memory bins that must be used to + satisfy alignment requirements. + @param MemoryTypeInformation The memory type information array. + + @return The total memory bin size needed. + +**/ +UINT64 +CalculateTotalMemoryBinSizeNeeded ( + IN OUT OPTIONAL EFI_PHYSICAL_ADDRESS *BinTop, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ) +{ + UINTN Index; + UINT64 TotalSize; + UINT64 Granularity; + + ASSERT (MemoryTypeInformation != NULL); + if (MemoryTypeInformation == NULL) { + return 0; + } + + // + // Loop through each memory type in the order specified by the MemoryTypeInformation[] array + // + TotalSize = 0; + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; + if ((MemoryTypeInformation[Index].Type == EfiReservedMemoryType) || + (MemoryTypeInformation[Index].Type == EfiACPIMemoryNVS) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesCode) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesData)) + { + Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + + // MemoryTypeInformation[Index].NumberOfPages is already aligned to the allocation granularity + TotalSize += EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); + + // BinTop is optional + if (BinTop == NULL) { + continue; + } + + // Lower the bin top to the next aligned address, taking any padding into account in the size + *BinTop -= EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); + TotalSize += (*BinTop & (Granularity - 1)); + *BinTop &= ~(Granularity - 1); + } + + if (BinTop != NULL) { + // Set *BinTop to the new top of the memory bins. It currently points to the base address of + // the memory bins + *BinTop += TotalSize; + } + + return TotalSize; +} + +/** + Get the Memory Type Information HOB if it exists and populate gMemoryTypeInformation. + + @param MemoryTypeInformation The pointer to the memory type information array to be populated. + + @return EFI_STATUS On EFI_SUCCESS, gMemoryTypeInformation points to the + Memory Type Information. + @return EFI_NOT_FOUND No valid Memory Type Information HOB found. +**/ +EFI_STATUS +EFIAPI +PopulateMemoryTypeInformation ( + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ) +{ + UINTN DataSize; + EFI_MEMORY_TYPE_INFORMATION *EfiMemoryTypeInformation; + EFI_HOB_GUID_TYPE *GuidHob; + UINTN Index; + UINT32 Granularity; + UINTN MaxIndex; + + ASSERT (MemoryTypeInformation != NULL); + if (MemoryTypeInformation == NULL) { + return EFI_INVALID_PARAMETER; + } + + GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid); + if (GuidHob != NULL) { + EfiMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob); + DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob); + + if ((EfiMemoryTypeInformation != NULL) && (DataSize > 0) && (DataSize <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION))) { + CopyMem (MemoryTypeInformation, EfiMemoryTypeInformation, DataSize); + MaxIndex = (DataSize / sizeof (EFI_MEMORY_TYPE_INFORMATION)) - 1; + + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the MemoryTypeInformation[] array is valid + // + if (MemoryTypeInformation[Index].Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + if ((MemoryTypeInformation[Index].Type == EfiReservedMemoryType) || + (MemoryTypeInformation[Index].Type == EfiACPIMemoryNVS) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesCode) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesData)) + { + Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } else { + Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; + } + + // Align the number of pages to the allocation granularity + MemoryTypeInformation[Index].NumberOfPages = (UINT32)EFI_SIZE_TO_PAGES (ALIGN_VALUE (EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages), Granularity)); + } + + // It is guaranteed that DataSize must be > 0 and <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION) + // however, we may have a corrupted HOB that does end in the EfiMaxMemoryType, so we need to terminate the loop + // to not overrun the array. Because we can't trust the HOB data, we will reset it to 0. + if (Index == MaxIndex) { + DEBUG ((DEBUG_WARN, "%a: Corrupted Memory Type Information HOB data\n", __func__)); + goto CleanAndError; + } + } + + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_WARN, "%a: Invalid Memory Type Information HOB data\n", __func__)); + } + +CleanAndError: + // We may have gotten here from a corrupted HOB, ensure all data is set back + // to disabled bins. + for (Index = 0; Index <= EfiMaxMemoryType; Index++) { + MemoryTypeInformation[Index].Type = (UINT32)Index; + MemoryTypeInformation[Index].NumberOfPages = 0; + } + + DEBUG ((DEBUG_WARN, "%a: No Memory Type Information HOB found, S4 resume is likely to fail\n", __func__)); + + return EFI_NOT_FOUND; +} + +/** + Look for Resource Descriptor HOB with a ResourceType of System Memory + and an Owner GUID of gEfiMemoryTypeInformationGuid. If more than 1 is + found, then return NULL. + + @param HobStart Pointer to the start of the HOB list. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + + @return Non-NULL The pointer to the singular MemoryTypeInformation Resource Descriptor HOB. + @return NULL No valid MemoryTypeInformation Resource Descriptor HOB found. +**/ +EFI_HOB_RESOURCE_DESCRIPTOR * +EFIAPI +GetMemoryTypeInformationResourceHob ( + IN VOID **HobStart, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ) +{ + UINTN Count; + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + EFI_HOB_RESOURCE_DESCRIPTOR *MemoryTypeInformationResourceHob; + EFI_PHYSICAL_ADDRESS BinTop; + + ASSERT (HobStart != NULL); + ASSERT (MemoryTypeInformation != NULL); + if ((HobStart == NULL) || (MemoryTypeInformation == NULL)) { + return NULL; + } + + // + // See if a Memory Type Information HOB is available + // + MemoryTypeInformationResourceHob = NULL; + Count = 0; + for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { + continue; + } + + ResourceHob = Hob.ResourceDescriptor; + if (!CompareGuid (&ResourceHob->Owner, &gEfiMemoryTypeInformationGuid)) { + continue; + } + + Count++; + if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) { + continue; + } + + if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) { + continue; + } + + BinTop = ResourceHob->PhysicalStart + ResourceHob->ResourceLength; + if (ResourceHob->ResourceLength >= CalculateTotalMemoryBinSizeNeeded (&BinTop, MemoryTypeInformation)) { + MemoryTypeInformationResourceHob = ResourceHob; + } + } + + if (Count > 1) { + return NULL; + } + + return MemoryTypeInformationResourceHob; +} + +/** + Helper function to set up the bin statistics with the provided bin range + + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeStatistics The memory type statistics to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. +**/ +STATIC +VOID +InitializeBinStatisticsFromRange ( + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress + ) +{ + EFI_MEMORY_TYPE Type; + UINTN Index; + + ASSERT (MemoryTypeInformation != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (DefaultMaximumAddress != NULL); + + if ((MemoryTypeInformation == NULL) || (MemoryTypeStatistics == NULL) || (DefaultMaximumAddress == NULL)) { + return; + } + + // + // If the number of pages reserved for a memory type is 0, then all + // allocations for that type should be in the default range. + // + for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) { + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + if (Type == (EFI_MEMORY_TYPE)MemoryTypeInformation[Index].Type) { + MemoryTypeStatistics[Type].InformationIndex = Index; + } + } + + MemoryTypeStatistics[Type].CurrentNumberOfPages = 0; + if (MemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) { + MemoryTypeStatistics[Type].MaximumAddress = *DefaultMaximumAddress; + } + } +} + +/** + Sets the preferred memory range to use for the Memory Type Information bins. + This service must be called before first call to CoreAddMemoryDescriptor(). + + If the location of the Memory Type Information bins has already been + established or the size of the range provides is smaller than all the + Memory Type Information bins, then the range provides is not used. + + @param Start The start address of the Memory Type Information range. + @param Length The size, in bytes, of the Memory Type Information range. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. +**/ +VOID +EFIAPI +CoreSetMemoryTypeInformationRange ( + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress + ) +{ + EFI_PHYSICAL_ADDRESS Top; + EFI_MEMORY_TYPE Type; + UINTN Index; + UINT64 Size; + + ASSERT (MemoryTypeInformation != NULL); + ASSERT (MemoryTypeInformationInitialized != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (DefaultMaximumAddress != NULL); + + if ((MemoryTypeInformation == NULL) || + (MemoryTypeInformationInitialized == NULL) || + (MemoryTypeStatistics == NULL) || + (DefaultMaximumAddress == NULL)) + { + return; + } + + // + // Return if Memory Type Information bin locations have already been set + // + if (*MemoryTypeInformationInitialized) { + DEBUG ((DEBUG_ERROR, "%a: Ignored. Bins already set.\n", __func__)); + return; + } + + // + // Return if size of the Memory Type Information bins is greater than Length + // + Top = Start + Length; + Size = CalculateTotalMemoryBinSizeNeeded (&Top, MemoryTypeInformation); + + if (Size > Length) { + return; + } + + // + // Loop through each memory type in the order specified by the + // gMemoryTypeInformation[] array + // + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the MemoryTypeInformation[] array is valid + // + Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); + if ((UINT32)Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + MemoryTypeStatistics[Type].MaximumAddress = Top - 1; + Top -= EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); + MemoryTypeStatistics[Type].BaseAddress = Top; + + // + // If the current base address is the lowest address so far, then update + // the default maximum address + // + if (MemoryTypeStatistics[Type].BaseAddress < *DefaultMaximumAddress) { + *DefaultMaximumAddress = MemoryTypeStatistics[Type].BaseAddress - 1; + } + + MemoryTypeStatistics[Type].NumberOfPages = MemoryTypeInformation[Index].NumberOfPages; + MemoryTypeInformation[Index].NumberOfPages = 0; + } + } + + InitializeBinStatisticsFromRange (MemoryTypeInformation, MemoryTypeStatistics, DefaultMaximumAddress); + + DEBUG (( + DEBUG_INFO, + "%a: Inherited range 0x%llx - 0x%llx for memory bins\n", + __func__, + Start, + Start + Length -1 + )); + *MemoryTypeInformationInitialized = TRUE; +} + +/** + Allocate memory bins for each memory type as specified in gMemoryTypeInformation. + + If all the memory types cannot be allocated, then all previously allocated + memory types are freed and the function returns. If this function fails, it will log and expect to be called + again when more memory is added to the system. + + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. + @param CreateHob TRUE to create Memory Type Information Resource HOB after successful + allocation. This is used for PEI Core to report the bins to DXE Core. + DXE Core must set this to FALSE because HOB creation is not supported in + DXE (nor is the information required to be passed to another entity). +**/ +VOID +EFIAPI +AllocateMemoryTypeInformationBins ( + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress, + IN BOOLEAN CreateHob + ) +{ + UINTN Index; + EFI_MEMORY_TYPE Type; + EFI_PHYSICAL_ADDRESS BaseAddress; + EFI_PHYSICAL_ADDRESS LastBinAddress; + UINT64 RequiredSize; + + ASSERT (MemoryTypeInformationInitialized != NULL); + ASSERT (MemoryTypeInformation != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (DefaultMaximumAddress != NULL); + + if ((MemoryTypeInformationInitialized == NULL) || + (MemoryTypeInformation == NULL) || + (MemoryTypeStatistics == NULL) || + (DefaultMaximumAddress == NULL)) + { + return; + } + + // + // Check to see if the statistics for the different memory types have already been established + // + if (*MemoryTypeInformationInitialized) { + return; + } + + BaseAddress = 0; + RequiredSize = CalculateTotalMemoryBinSizeNeeded (NULL, MemoryTypeInformation); + if (RequiredSize == 0) { + *MemoryTypeInformationInitialized = TRUE; + return; + } + + // To ensure we get a contiguous range of memory for our bins, we will attempt to allocate + // all of the memory needed in one go. If that works, we can then carve it up into the individual bins. + // Our size is already aligned to the correct granularity, allocate aligned pages to ensure the base address is + // aligned. + BaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAlignedPages ( + EFI_SIZE_TO_PAGES ((UINTN)RequiredSize), + RUNTIME_PAGE_ALLOCATION_GRANULARITY + ); + + if (BaseAddress == 0) { + DEBUG (( + DEBUG_INFO, + "%a: Could not allocate contiguous pages for all memory bins. It will be attempted again when more memory is added.\n", + __func__ + )); + return; + } + + DEBUG (( + DEBUG_INFO, + "%a: Allocated 0x%llx - 0x%llx for memory bins\n", + __func__, + BaseAddress, + BaseAddress + RequiredSize - 1 + )); + + LastBinAddress = BaseAddress + RequiredSize; + *DefaultMaximumAddress = BaseAddress - 1; + + // + // Loop through each memory type in the order specified by the gMemoryTypeInformation[] array + // + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the gMemoryTypeInformation[] array is valid + // + Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); + if ((UINT32)Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + MemoryTypeStatistics[Type].BaseAddress = LastBinAddress - EFI_PAGES_TO_SIZE (MemoryTypeInformation[Index].NumberOfPages); + MemoryTypeStatistics[Type].MaximumAddress = LastBinAddress - 1; + LastBinAddress = MemoryTypeStatistics[Type].BaseAddress; + } + } + + // + // There was enough system memory for all the the memory types were allocated. So, + // those memory areas can be freed for future allocations, and all future memory + // allocations can occur within their respective bins + // + FreeAlignedPages ( + (VOID *)(UINTN)BaseAddress, + EFI_SIZE_TO_PAGES ((UINTN)RequiredSize) + ); + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the MemoryTypeInformation[] array is valid + // + Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); + if ((UINT32)Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + MemoryTypeStatistics[Type].NumberOfPages = MemoryTypeInformation[Index].NumberOfPages; + MemoryTypeInformation[Index].NumberOfPages = 0; + } + } + + InitializeBinStatisticsFromRange (MemoryTypeInformation, MemoryTypeStatistics, DefaultMaximumAddress); + + if (CreateHob) { + // + // Create a Resource Descriptor HOB to report the Memory Type Information bins to DXE Core + // + BuildResourceDescriptorWithOwnerHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + TESTED_MEMORY_ATTRIBUTES, + BaseAddress, + RequiredSize, + &gEfiMemoryTypeInformationGuid + ); + } + + *MemoryTypeInformationInitialized = TRUE; +} + +/** + Update memory type statistics upon memory allocation and free. + + @param OldType The original memory type of the memory region. + @param NewType The new memory type of the memory region. + @param Start The starting physical address of the memory region. + @param NumberOfPages The number of pages in the memory region. + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeStatistics The memory type statistics array to be updated. + @param MemoryTypeInformation The memory type information array to be updated. + @param DefaultBaseAddress Default bin base address. + @param DefaultMaximumAddress Default bin maximum address. +**/ +VOID +EFIAPI +UpdateMemoryStatistics ( + IN EFI_MEMORY_TYPE OldType, + IN EFI_MEMORY_TYPE NewType, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINTN NumberOfPages, + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_PHYSICAL_ADDRESS DefaultBaseAddress, + IN EFI_PHYSICAL_ADDRESS DefaultMaximumAddress + ) +{ + ASSERT (MemoryTypeInformationInitialized != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (MemoryTypeInformation != NULL); + + if ((MemoryTypeInformationInitialized == NULL) || + (MemoryTypeStatistics == NULL) || + (MemoryTypeInformation == NULL)) + { + return; + } + + if (!*MemoryTypeInformationInitialized) { + return; + } + + // + // Update counters for the number of pages allocated to each memory type + // + if ((UINT32)OldType < EfiMaxMemoryType) { + if (((Start >= MemoryTypeStatistics[OldType].BaseAddress) && (Start <= MemoryTypeStatistics[OldType].MaximumAddress)) || + ((Start >= DefaultBaseAddress) && (Start <= DefaultMaximumAddress))) + { + if (NumberOfPages > MemoryTypeStatistics[OldType].CurrentNumberOfPages) { + MemoryTypeStatistics[OldType].CurrentNumberOfPages = 0; + } else { + MemoryTypeStatistics[OldType].CurrentNumberOfPages -= NumberOfPages; + } + } + } + + if ((UINT32)NewType < EfiMaxMemoryType) { + if (((Start >= MemoryTypeStatistics[NewType].BaseAddress) && (Start <= MemoryTypeStatistics[NewType].MaximumAddress)) || + ((Start >= DefaultBaseAddress) && (Start <= DefaultMaximumAddress))) + { + MemoryTypeStatistics[NewType].CurrentNumberOfPages += NumberOfPages; + if ((MemoryTypeStatistics[NewType].InformationIndex < (UINTN)EfiMaxMemoryType) && + (MemoryTypeStatistics[NewType].CurrentNumberOfPages > MemoryTypeInformation[MemoryTypeStatistics[NewType].InformationIndex].NumberOfPages)) + { + MemoryTypeInformation[MemoryTypeStatistics[NewType].InformationIndex].NumberOfPages = (UINT32)MemoryTypeStatistics[NewType].CurrentNumberOfPages; + } + } + } +} diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 2775fa0160..22d5bd1336 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -82,278 +82,6 @@ EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = { // GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALSE; -/** - Allocate memory bins for each memory type as specified in gMemoryTypeInformation. - - If all the memory types cannot be allocated, then all previously allocated - memory types are freed and the function returns. If this function fails, it will log and expect to be called - again when more memory is added to the system. - - @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type - information bins have been initialized. - @param MemoryTypeInformation The memory type information array to be used to determine - the size of the memory bins. - @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin - information if the provided range is used. - @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the - provided range is used. - @param CreateHob TRUE to create Memory Type Information Resource HOB after successful - allocation. This is used for PEI Core to report the bins to DXE Core. - DXE Core must set this to FALSE because HOB creation is not supported in - DXE (nor is the information required to be passed to another entity). -**/ -VOID -EFIAPI -AllocateMemoryTypeInformationBins ( - IN BOOLEAN *MemoryTypeInformationInitialized, - IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, - IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, - IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress, - IN BOOLEAN CreateHob - ) -{ - UINTN Index; - EFI_MEMORY_TYPE Type; - EFI_PHYSICAL_ADDRESS BaseAddress; - EFI_PHYSICAL_ADDRESS LastBinAddress; - UINT64 RequiredSize; - - ASSERT (MemoryTypeInformationInitialized != NULL); - ASSERT (MemoryTypeInformation != NULL); - ASSERT (MemoryTypeStatistics != NULL); - ASSERT (DefaultMaximumAddress != NULL); - - if ((MemoryTypeInformationInitialized == NULL) || - (MemoryTypeInformation == NULL) || - (MemoryTypeStatistics == NULL) || - (DefaultMaximumAddress == NULL)) - { - return; - } - - // - // Check to see if the statistics for the different memory types have already been established - // - if (*MemoryTypeInformationInitialized) { - return; - } - - BaseAddress = 0; - RequiredSize = CalculateTotalMemoryBinSizeNeeded (NULL, MemoryTypeInformation); - if (RequiredSize == 0) { - *MemoryTypeInformationInitialized = TRUE; - return; - } - - // To ensure we get a contiguous range of memory for our bins, we will attempt to allocate - // all of the memory needed in one go. If that works, we can then carve it up into the individual bins. - // Our size is already aligned to the correct granularity, allocate aligned pages to ensure the base address is - // aligned. - BaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAlignedPages ( - EFI_SIZE_TO_PAGES ((UINTN)RequiredSize), - RUNTIME_PAGE_ALLOCATION_GRANULARITY - ); - - if (BaseAddress == 0) { - DEBUG (( - DEBUG_INFO, - "%a: Could not allocate contiguous pages for all memory bins. It will be attempted again when more memory is added.\n", - __func__ - )); - return; - } - - DEBUG (( - DEBUG_INFO, - "%a: Allocated 0x%llx - 0x%llx for memory bins\n", - __func__, - BaseAddress, - BaseAddress + RequiredSize - 1 - )); - - LastBinAddress = BaseAddress + RequiredSize; - *DefaultMaximumAddress = BaseAddress - 1; - - // - // Loop through each memory type in the order specified by the gMemoryTypeInformation[] array - // - for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - // - // Make sure the memory type in the gMemoryTypeInformation[] array is valid - // - Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); - if ((UINT32)Type > EfiMaxMemoryType) { - continue; - } - - if (MemoryTypeInformation[Index].NumberOfPages != 0) { - MemoryTypeStatistics[Type].BaseAddress = LastBinAddress - EFI_PAGES_TO_SIZE (MemoryTypeInformation[Index].NumberOfPages); - MemoryTypeStatistics[Type].MaximumAddress = LastBinAddress - 1; - LastBinAddress = MemoryTypeStatistics[Type].BaseAddress; - } - } - - // - // There was enough system memory for all the the memory types were allocated. So, - // those memory areas can be freed for future allocations, and all future memory - // allocations can occur within their respective bins - // - FreeAlignedPages ( - (VOID *)(UINTN)BaseAddress, - EFI_SIZE_TO_PAGES ((UINTN)RequiredSize) - ); - for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - // - // Make sure the memory type in the MemoryTypeInformation[] array is valid - // - Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); - if ((UINT32)Type > EfiMaxMemoryType) { - continue; - } - - if (MemoryTypeInformation[Index].NumberOfPages != 0) { - MemoryTypeStatistics[Type].NumberOfPages = MemoryTypeInformation[Index].NumberOfPages; - MemoryTypeInformation[Index].NumberOfPages = 0; - } - } - - InitializeBinStatisticsFromRange (MemoryTypeInformation, MemoryTypeStatistics, DefaultMaximumAddress); - - if (CreateHob) { - // - // Create a Resource Descriptor HOB to report the Memory Type Information bins to DXE Core - // - BuildResourceDescriptorWithOwnerHob ( - EFI_RESOURCE_SYSTEM_MEMORY, - TESTED_MEMORY_ATTRIBUTES, - BaseAddress, - RequiredSize, - &gEfiMemoryTypeInformationGuid - ); - } - - *MemoryTypeInformationInitialized = TRUE; -} - -/** - Update memory type statistics upon memory allocation and free. - - @param OldType The original memory type of the memory region. - @param NewType The new memory type of the memory region. - @param Start The starting physical address of the memory region. - @param NumberOfPages The number of pages in the memory region. - @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type - information bins have been initialized. - @param MemoryTypeStatistics The memory type statistics array to be updated. - @param MemoryTypeInformation The memory type information array to be updated. - @param DefaultBaseAddress Default bin base address. - @param DefaultMaximumAddress Default bin maximum address. -**/ -VOID -EFIAPI -UpdateMemoryStatistics ( - IN EFI_MEMORY_TYPE OldType, - IN EFI_MEMORY_TYPE NewType, - IN EFI_PHYSICAL_ADDRESS Start, - IN UINTN NumberOfPages, - IN BOOLEAN *MemoryTypeInformationInitialized, - IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, - IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, - IN EFI_PHYSICAL_ADDRESS DefaultBaseAddress, - IN EFI_PHYSICAL_ADDRESS DefaultMaximumAddress - ) -{ - ASSERT (MemoryTypeInformationInitialized != NULL); - ASSERT (MemoryTypeStatistics != NULL); - ASSERT (MemoryTypeInformation != NULL); - - if ((MemoryTypeInformationInitialized == NULL) || - (MemoryTypeStatistics == NULL) || - (MemoryTypeInformation == NULL)) - { - return; - } - - if (!*MemoryTypeInformationInitialized) { - return; - } - - // - // Update counters for the number of pages allocated to each memory type - // - if ((UINT32)OldType < EfiMaxMemoryType) { - if (((Start >= MemoryTypeStatistics[OldType].BaseAddress) && (Start <= MemoryTypeStatistics[OldType].MaximumAddress)) || - ((Start >= DefaultBaseAddress) && (Start <= DefaultMaximumAddress))) - { - if (NumberOfPages > MemoryTypeStatistics[OldType].CurrentNumberOfPages) { - MemoryTypeStatistics[OldType].CurrentNumberOfPages = 0; - } else { - MemoryTypeStatistics[OldType].CurrentNumberOfPages -= NumberOfPages; - } - } - } - - if ((UINT32)NewType < EfiMaxMemoryType) { - if (((Start >= MemoryTypeStatistics[NewType].BaseAddress) && (Start <= MemoryTypeStatistics[NewType].MaximumAddress)) || - ((Start >= DefaultBaseAddress) && (Start <= DefaultMaximumAddress))) - { - MemoryTypeStatistics[NewType].CurrentNumberOfPages += NumberOfPages; - if ((MemoryTypeStatistics[NewType].InformationIndex < (UINTN)EfiMaxMemoryType) && - (MemoryTypeStatistics[NewType].CurrentNumberOfPages > MemoryTypeInformation[MemoryTypeStatistics[NewType].InformationIndex].NumberOfPages)) - { - MemoryTypeInformation[MemoryTypeStatistics[NewType].InformationIndex].NumberOfPages = (UINT32)MemoryTypeStatistics[NewType].CurrentNumberOfPages; - } - } - } -} - -/** - Helper function to set up the bin statistics with the provided bin range - - @param MemoryTypeInformation The memory type information array to be used to determine - the size of the memory bins. - @param MemoryTypeStatistics The memory type statistics to be updated with the memory bin - information if the provided range is used. - @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the - provided range is used. -**/ -STATIC -VOID -InitializeBinStatisticsFromRange ( - IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, - IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, - IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress - ) -{ - EFI_MEMORY_TYPE Type; - UINTN Index; - - ASSERT (MemoryTypeInformation != NULL); - ASSERT (MemoryTypeStatistics != NULL); - ASSERT (DefaultMaximumAddress != NULL); - - if ((MemoryTypeInformation == NULL) || (MemoryTypeStatistics == NULL) || (DefaultMaximumAddress == NULL)) { - return; - } - - // - // If the number of pages reserved for a memory type is 0, then all - // allocations for that type should be in the default range. - // - for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) { - for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - if (Type == (EFI_MEMORY_TYPE)MemoryTypeInformation[Index].Type) { - MemoryTypeStatistics[Type].InformationIndex = Index; - } - } - - MemoryTypeStatistics[Type].CurrentNumberOfPages = 0; - if (MemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) { - MemoryTypeStatistics[Type].MaximumAddress = *DefaultMaximumAddress; - } - } -} - /** Enter critical section by gaining lock on gMemoryLock. @@ -821,115 +549,6 @@ CoreLoadingFixedAddressHook ( return; } -/** - Sets the preferred memory range to use for the Memory Type Information bins. - This service must be called before first call to CoreAddMemoryDescriptor(). - - If the location of the Memory Type Information bins has already been - established or the size of the range provides is smaller than all the - Memory Type Information bins, then the range provides is not used. - - @param Start The start address of the Memory Type Information range. - @param Length The size, in bytes, of the Memory Type Information range. - @param MemoryTypeInformation The memory type information array to be used to determine - the size of the memory bins. - @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type - information bins have been initialized. - @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin - information if the provided range is used. - @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the - provided range is used. -**/ -VOID -EFIAPI -CoreSetMemoryTypeInformationRange ( - IN EFI_PHYSICAL_ADDRESS Start, - IN UINT64 Length, - IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, - IN BOOLEAN *MemoryTypeInformationInitialized, - IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, - IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress - ) -{ - EFI_PHYSICAL_ADDRESS Top; - EFI_MEMORY_TYPE Type; - UINTN Index; - UINT64 Size; - - ASSERT (MemoryTypeInformation != NULL); - ASSERT (MemoryTypeInformationInitialized != NULL); - ASSERT (MemoryTypeStatistics != NULL); - ASSERT (DefaultMaximumAddress != NULL); - - if ((MemoryTypeInformation == NULL) || - (MemoryTypeInformationInitialized == NULL) || - (MemoryTypeStatistics == NULL) || - (DefaultMaximumAddress == NULL)) - { - return; - } - - // - // Return if Memory Type Information bin locations have already been set - // - if (*MemoryTypeInformationInitialized) { - DEBUG ((DEBUG_ERROR, "%a: Ignored. Bins already set.\n", __func__)); - return; - } - - // - // Return if size of the Memory Type Information bins is greater than Length - // - Top = Start + Length; - Size = CalculateTotalMemoryBinSizeNeeded (&Top, MemoryTypeInformation); - - if (Size > Length) { - return; - } - - // - // Loop through each memory type in the order specified by the - // gMemoryTypeInformation[] array - // - for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { - // - // Make sure the memory type in the MemoryTypeInformation[] array is valid - // - Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); - if ((UINT32)Type > EfiMaxMemoryType) { - continue; - } - - if (MemoryTypeInformation[Index].NumberOfPages != 0) { - MemoryTypeStatistics[Type].MaximumAddress = Top - 1; - Top -= EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); - MemoryTypeStatistics[Type].BaseAddress = Top; - - // - // If the current base address is the lowest address so far, then update - // the default maximum address - // - if (MemoryTypeStatistics[Type].BaseAddress < *DefaultMaximumAddress) { - *DefaultMaximumAddress = MemoryTypeStatistics[Type].BaseAddress - 1; - } - - MemoryTypeStatistics[Type].NumberOfPages = MemoryTypeInformation[Index].NumberOfPages; - MemoryTypeInformation[Index].NumberOfPages = 0; - } - } - - InitializeBinStatisticsFromRange (MemoryTypeInformation, MemoryTypeStatistics, DefaultMaximumAddress); - - DEBUG (( - DEBUG_INFO, - "%a: Inherited range 0x%llx - 0x%llx for memory bins\n", - __func__, - Start, - Start + Length -1 - )); - *MemoryTypeInformationInitialized = TRUE; -} - /** Called to initialize the memory map and add descriptors to the current descriptor list. diff --git a/MdeModulePkg/Core/PrivateInclude/MemoryBin.h b/MdeModulePkg/Core/PrivateInclude/MemoryBin.h new file mode 100644 index 0000000000..fd7c12a0db --- /dev/null +++ b/MdeModulePkg/Core/PrivateInclude/MemoryBin.h @@ -0,0 +1,167 @@ +/** @file + Shared logic between cores to work with memory bins for S4 resume stability. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#pragma once + +#include + +// +// Entry in an array that keeps track of memory type statistics per memory bin +// +typedef struct { + EFI_PHYSICAL_ADDRESS BaseAddress; + EFI_PHYSICAL_ADDRESS MaximumAddress; + UINT64 CurrentNumberOfPages; + UINT64 NumberOfPages; + UINTN InformationIndex; + BOOLEAN Special; + BOOLEAN Runtime; +} EFI_MEMORY_TYPE_STATISTICS; + +/** + Calculate total memory bin size needed. + + @param BinTop The top address of the memory bins. This is an optional parameter. + When NULL, the returned size meets the alignment requirements as long as + the base address selected also meets the alignment requirements. When + non-NULL, then the returned BinTop value and the returned size both meet + the alignment requirements. When non-NULL, this will be updated on + output to the new top address of the memory bins that must be used to + satisfy alignment requirements. + @param MemoryTypeInformation The memory type information array. + + @return The total memory bin size needed. + +**/ +UINT64 +CalculateTotalMemoryBinSizeNeeded ( + IN OUT OPTIONAL EFI_PHYSICAL_ADDRESS *BinTop, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ); + +/** + Get the Memory Type Information HOB if it exists and populate gMemoryTypeInformation. + + @param MemoryTypeInformation The pointer to the memory type information array to be populated. + + @return EFI_STATUS On EFI_SUCCESS, gMemoryTypeInformation points to the + Memory Type Information. + @return EFI_NOT_FOUND No valid Memory Type Information HOB found. +**/ +EFI_STATUS +EFIAPI +PopulateMemoryTypeInformation ( + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ); + +/** + Look for Resource Descriptor HOB with a ResourceType of System Memory + and an Owner GUID of gEfiMemoryTypeInformationGuid. If more than 1 is + found, then return NULL. + + @param HobStart Pointer to the start of the HOB list. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + + @return Non-NULL The pointer to the singular MemoryTypeInformation Resource Descriptor HOB. + @return NULL No valid MemoryTypeInformation Resource Descriptor HOB found. +**/ +EFI_HOB_RESOURCE_DESCRIPTOR * +EFIAPI +GetMemoryTypeInformationResourceHob ( + IN VOID **HobStart, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ); + +/** + Sets the preferred memory range to use for the Memory Type Information bins. + This service must be called before fist call to CoreAddMemoryDescriptor(). + + If the location of the Memory Type Information bins has already been + established or the size of the range provides is smaller than all the + Memory Type Information bins, then the range provides is not used. + + @param Start The start address of the Memory Type Information range. + @param Length The size, in bytes, of the Memory Type Information range. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. +**/ +VOID +EFIAPI +CoreSetMemoryTypeInformationRange ( + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress + ); + +/** + Allocate memory bins for each memory type as specified in gMemoryTypeInformation. + + If all the memory types cannot be allocated, then all previously allocated + memory types are freed and the function returns. If this function fails, it will log and expect to be called + again when more memory is added to the system. + + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. + @param CreateHob TRUE to create Memory Type Information Resource HOB after successful + allocation. This is used for PEI Core to report the bins to DXE Core. + DXE Core must set this to FALSE because HOB creation is not supported in + DXE (nor is the information required to be passed to another entity). +**/ +VOID +EFIAPI +AllocateMemoryTypeInformationBins ( + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress, + IN BOOLEAN CreateHob + ); + +/** + Update memory type statistics upon memory allocation and free. + + @param OldType The original memory type of the memory region. + @param NewType The new memory type of the memory region. + @param Start The starting physical address of the memory region. + @param NumberOfPages The number of pages in the memory region. + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeStatistics The memory type statistics array to be updated. + @param MemoryTypeInformation The memory type information array to be updated. + @param DefaultBaseAddress Default bin base address. + @param DefaultMaximumAddress Default bin maximum address. +**/ +VOID +EFIAPI +UpdateMemoryStatistics ( + IN EFI_MEMORY_TYPE OldType, + IN EFI_MEMORY_TYPE NewType, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINTN NumberOfPages, + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_PHYSICAL_ADDRESS DefaultBaseAddress, + IN EFI_PHYSICAL_ADDRESS DefaultMaximumAddress + ); diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 5d7df5f2a8..57b05c3303 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -29,6 +29,7 @@ [Includes.Common.Private] Library/BrotliCustomDecompressLib/brotli/c/include + Core/PrivateInclude [LibraryClasses] ## @libraryclass Defines a set of methods to reset whole system. From 840d07abb15a722f47bfd9151681207246b71573 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Tue, 12 May 2026 15:40:52 -0700 Subject: [PATCH 071/406] MdeModulePkg: Add PCD to Enable Memory Bin Support in PEI This adds a PCD, FALSE by default, that enables the memory bin feature in PEI. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/MdeModulePkg.dec | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 57b05c3303..d7dc740cbb 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -986,6 +986,18 @@ # @Prompt Enable process non-reset capsule image at runtime. gEfiMdeModulePkgTokenSpaceGuid.PcdSupportProcessCapsuleAtRuntime|FALSE|BOOLEAN|0x00010079 + ## Indicates if the PEI memory bins feature is allowed to be enabled. + # TRUE - The PEI memory bins feature is allowed to be enabled. The platform must also produce the + # gEfiMemoryTypeInformationGuid HOB prior to permanent memory installation in order to enroll in the + # feature. + # FALSE - The PEI memory bins feature is not allowed to be enabled. If the gEfiMemoryTypeInformationGuid HOB + # is produced by the platform in PEI, DXE will set up the memory bins. If not, no memory bins will be + # used. + # + # This PCD defaults to FALSE to follow the same behavior prior to the PEI memory bins feature being introduced. + # See MdeModulePkg/Core/MemoryBins.md for more details. + gEfiMdeModulePkgTokenSpaceGuid.PcdPeiMemoryBinsEnable|FALSE|BOOLEAN|0x00010080 + [PcdsFeatureFlag.IA32, PcdsFeatureFlag.AARCH64, PcdsFeatureFlag.LOONGARCH64] gEfiMdeModulePkgTokenSpaceGuid.PcdPciDegradeResourceForOptionRom|FALSE|BOOLEAN|0x0001003a From 2e7aa4810bd3e4008e561f2ea5a9de1dc189c817 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Mon, 30 Mar 2026 10:58:32 -0700 Subject: [PATCH 072/406] MdeModulePkg: PeiCore: Add Memory Bin Support to Post-Mem PEI This commit adds opt-in support for post-mem PEI memory bins. See the README for full details. MemoryBin.c is duplicated to PeiCore per request. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Pei/Memory/MemoryBin.c | 646 ++++++++++++++++++ MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 434 +++++++++--- MdeModulePkg/Core/Pei/PeiMain.h | 19 + MdeModulePkg/Core/Pei/PeiMain.inf | 3 + 4 files changed, 1001 insertions(+), 101 deletions(-) create mode 100644 MdeModulePkg/Core/Pei/Memory/MemoryBin.c diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryBin.c b/MdeModulePkg/Core/Pei/Memory/MemoryBin.c new file mode 100644 index 0000000000..ce116135c0 --- /dev/null +++ b/MdeModulePkg/Core/Pei/Memory/MemoryBin.c @@ -0,0 +1,646 @@ +/** @file + + Shared logic between cores to work with memory bins for S4 resume stability. This file is duplicated in PEI Core and + DXE Core until a BaseTools feature comes online to support recommended library instances. Any changes to this file + must also be made in MdeModulePkg/Core/Pei/Memory/MemoryBin.c. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \ + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ + EFI_RESOURCE_ATTRIBUTE_TESTED | \ + EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED | \ + EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED | \ + EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED | \ + EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED | \ + EFI_RESOURCE_ATTRIBUTE_16_BIT_IO | \ + EFI_RESOURCE_ATTRIBUTE_32_BIT_IO | \ + EFI_RESOURCE_ATTRIBUTE_64_BIT_IO | \ + EFI_RESOURCE_ATTRIBUTE_PERSISTENT | \ + EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE ) + +#define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \ + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ + EFI_RESOURCE_ATTRIBUTE_TESTED ) + +/** + Calculate total memory bin size needed. + + @param BinTop The top address of the memory bins. This is an optional parameter. + When NULL, the returned size meets the alignment requirements as long as + the base address selected also meets the alignment requirements. When + non-NULL, then the returned BinTop value and the returned size both meet + the alignment requirements. When non-NULL, this will be updated on + output to the new top address of the memory bins that must be used to + satisfy alignment requirements. + @param MemoryTypeInformation The memory type information array. + + @return The total memory bin size needed. + +**/ +UINT64 +CalculateTotalMemoryBinSizeNeeded ( + IN OUT OPTIONAL EFI_PHYSICAL_ADDRESS *BinTop, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ) +{ + UINTN Index; + UINT64 TotalSize; + UINT64 Granularity; + + ASSERT (MemoryTypeInformation != NULL); + if (MemoryTypeInformation == NULL) { + return 0; + } + + // + // Loop through each memory type in the order specified by the MemoryTypeInformation[] array + // + TotalSize = 0; + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; + if ((MemoryTypeInformation[Index].Type == EfiReservedMemoryType) || + (MemoryTypeInformation[Index].Type == EfiACPIMemoryNVS) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesCode) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesData)) + { + Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + + // MemoryTypeInformation[Index].NumberOfPages is already aligned to the allocation granularity + TotalSize += EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); + + // BinTop is optional + if (BinTop == NULL) { + continue; + } + + // Lower the bin top to the next aligned address, taking any padding into account in the size + *BinTop -= EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); + TotalSize += (*BinTop & (Granularity - 1)); + *BinTop &= ~(Granularity - 1); + } + + if (BinTop != NULL) { + // Set *BinTop to the new top of the memory bins. It currently points to the base address of + // the memory bins + *BinTop += TotalSize; + } + + return TotalSize; +} + +/** + Get the Memory Type Information HOB if it exists and populate gMemoryTypeInformation. + + @param MemoryTypeInformation The pointer to the memory type information array to be populated. + + @return EFI_STATUS On EFI_SUCCESS, gMemoryTypeInformation points to the + Memory Type Information. + @return EFI_NOT_FOUND No valid Memory Type Information HOB found. +**/ +EFI_STATUS +EFIAPI +PopulateMemoryTypeInformation ( + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ) +{ + UINTN DataSize; + EFI_MEMORY_TYPE_INFORMATION *EfiMemoryTypeInformation; + EFI_HOB_GUID_TYPE *GuidHob; + UINTN Index; + UINT32 Granularity; + UINTN MaxIndex; + + ASSERT (MemoryTypeInformation != NULL); + if (MemoryTypeInformation == NULL) { + return EFI_INVALID_PARAMETER; + } + + GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid); + if (GuidHob != NULL) { + EfiMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob); + DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob); + + if ((EfiMemoryTypeInformation != NULL) && (DataSize > 0) && (DataSize <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION))) { + CopyMem (MemoryTypeInformation, EfiMemoryTypeInformation, DataSize); + MaxIndex = (DataSize / sizeof (EFI_MEMORY_TYPE_INFORMATION)) - 1; + + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the MemoryTypeInformation[] array is valid + // + if (MemoryTypeInformation[Index].Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + if ((MemoryTypeInformation[Index].Type == EfiReservedMemoryType) || + (MemoryTypeInformation[Index].Type == EfiACPIMemoryNVS) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesCode) || + (MemoryTypeInformation[Index].Type == EfiRuntimeServicesData)) + { + Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } else { + Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; + } + + // Align the number of pages to the allocation granularity + MemoryTypeInformation[Index].NumberOfPages = (UINT32)EFI_SIZE_TO_PAGES (ALIGN_VALUE (EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages), Granularity)); + } + + // It is guaranteed that DataSize must be > 0 and <= (EfiMaxMemoryType + 1) * sizeof (EFI_MEMORY_TYPE_INFORMATION) + // however, we may have a corrupted HOB that does end in the EfiMaxMemoryType, so we need to terminate the loop + // to not overrun the array. Because we can't trust the HOB data, we will reset it to 0. + if (Index == MaxIndex) { + DEBUG ((DEBUG_WARN, "%a: Corrupted Memory Type Information HOB data\n", __func__)); + goto CleanAndError; + } + } + + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_WARN, "%a: Invalid Memory Type Information HOB data\n", __func__)); + } + +CleanAndError: + // We may have gotten here from a corrupted HOB, ensure all data is set back + // to disabled bins. + for (Index = 0; Index <= EfiMaxMemoryType; Index++) { + MemoryTypeInformation[Index].Type = (UINT32)Index; + MemoryTypeInformation[Index].NumberOfPages = 0; + } + + DEBUG ((DEBUG_WARN, "%a: No Memory Type Information HOB found, S4 resume is likely to fail\n", __func__)); + + return EFI_NOT_FOUND; +} + +/** + Look for Resource Descriptor HOB with a ResourceType of System Memory + and an Owner GUID of gEfiMemoryTypeInformationGuid. If more than 1 is + found, then return NULL. + + @param HobStart Pointer to the start of the HOB list. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + + @return Non-NULL The pointer to the singular MemoryTypeInformation Resource Descriptor HOB. + @return NULL No valid MemoryTypeInformation Resource Descriptor HOB found. +**/ +EFI_HOB_RESOURCE_DESCRIPTOR * +EFIAPI +GetMemoryTypeInformationResourceHob ( + IN VOID **HobStart, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation + ) +{ + UINTN Count; + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + EFI_HOB_RESOURCE_DESCRIPTOR *MemoryTypeInformationResourceHob; + EFI_PHYSICAL_ADDRESS BinTop; + + ASSERT (HobStart != NULL); + ASSERT (MemoryTypeInformation != NULL); + if ((HobStart == NULL) || (MemoryTypeInformation == NULL)) { + return NULL; + } + + // + // See if a Memory Type Information HOB is available + // + MemoryTypeInformationResourceHob = NULL; + Count = 0; + for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { + continue; + } + + ResourceHob = Hob.ResourceDescriptor; + if (!CompareGuid (&ResourceHob->Owner, &gEfiMemoryTypeInformationGuid)) { + continue; + } + + Count++; + if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) { + continue; + } + + if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) { + continue; + } + + BinTop = ResourceHob->PhysicalStart + ResourceHob->ResourceLength; + if (ResourceHob->ResourceLength >= CalculateTotalMemoryBinSizeNeeded (&BinTop, MemoryTypeInformation)) { + MemoryTypeInformationResourceHob = ResourceHob; + } + } + + if (Count > 1) { + return NULL; + } + + return MemoryTypeInformationResourceHob; +} + +/** + Helper function to set up the bin statistics with the provided bin range + + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeStatistics The memory type statistics to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. +**/ +STATIC +VOID +InitializeBinStatisticsFromRange ( + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress + ) +{ + EFI_MEMORY_TYPE Type; + UINTN Index; + + ASSERT (MemoryTypeInformation != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (DefaultMaximumAddress != NULL); + + if ((MemoryTypeInformation == NULL) || (MemoryTypeStatistics == NULL) || (DefaultMaximumAddress == NULL)) { + return; + } + + // + // If the number of pages reserved for a memory type is 0, then all + // allocations for that type should be in the default range. + // + for (Type = (EFI_MEMORY_TYPE)0; Type < EfiMaxMemoryType; Type++) { + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + if (Type == (EFI_MEMORY_TYPE)MemoryTypeInformation[Index].Type) { + MemoryTypeStatistics[Type].InformationIndex = Index; + } + } + + MemoryTypeStatistics[Type].CurrentNumberOfPages = 0; + if (MemoryTypeStatistics[Type].MaximumAddress == MAX_ALLOC_ADDRESS) { + MemoryTypeStatistics[Type].MaximumAddress = *DefaultMaximumAddress; + } + } +} + +/** + Sets the preferred memory range to use for the Memory Type Information bins. + This service must be called before first call to CoreAddMemoryDescriptor(). + + If the location of the Memory Type Information bins has already been + established or the size of the range provides is smaller than all the + Memory Type Information bins, then the range provides is not used. + + @param Start The start address of the Memory Type Information range. + @param Length The size, in bytes, of the Memory Type Information range. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. +**/ +VOID +EFIAPI +CoreSetMemoryTypeInformationRange ( + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress + ) +{ + EFI_PHYSICAL_ADDRESS Top; + EFI_MEMORY_TYPE Type; + UINTN Index; + UINT64 Size; + + ASSERT (MemoryTypeInformation != NULL); + ASSERT (MemoryTypeInformationInitialized != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (DefaultMaximumAddress != NULL); + + if ((MemoryTypeInformation == NULL) || + (MemoryTypeInformationInitialized == NULL) || + (MemoryTypeStatistics == NULL) || + (DefaultMaximumAddress == NULL)) + { + return; + } + + // + // Return if Memory Type Information bin locations have already been set + // + if (*MemoryTypeInformationInitialized) { + DEBUG ((DEBUG_ERROR, "%a: Ignored. Bins already set.\n", __func__)); + return; + } + + // + // Return if size of the Memory Type Information bins is greater than Length + // + Top = Start + Length; + Size = CalculateTotalMemoryBinSizeNeeded (&Top, MemoryTypeInformation); + + if (Size > Length) { + return; + } + + // + // Loop through each memory type in the order specified by the + // gMemoryTypeInformation[] array + // + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the MemoryTypeInformation[] array is valid + // + Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); + if ((UINT32)Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + MemoryTypeStatistics[Type].MaximumAddress = Top - 1; + Top -= EFI_PAGES_TO_SIZE ((UINTN)MemoryTypeInformation[Index].NumberOfPages); + MemoryTypeStatistics[Type].BaseAddress = Top; + + // + // If the current base address is the lowest address so far, then update + // the default maximum address + // + if (MemoryTypeStatistics[Type].BaseAddress < *DefaultMaximumAddress) { + *DefaultMaximumAddress = MemoryTypeStatistics[Type].BaseAddress - 1; + } + + MemoryTypeStatistics[Type].NumberOfPages = MemoryTypeInformation[Index].NumberOfPages; + MemoryTypeInformation[Index].NumberOfPages = 0; + } + } + + InitializeBinStatisticsFromRange (MemoryTypeInformation, MemoryTypeStatistics, DefaultMaximumAddress); + + DEBUG (( + DEBUG_INFO, + "%a: Inherited range 0x%llx - 0x%llx for memory bins\n", + __func__, + Start, + Start + Length -1 + )); + *MemoryTypeInformationInitialized = TRUE; +} + +/** + Allocate memory bins for each memory type as specified in gMemoryTypeInformation. + + If all the memory types cannot be allocated, then all previously allocated + memory types are freed and the function returns. If this function fails, it will log and expect to be called + again when more memory is added to the system. + + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeInformation The memory type information array to be used to determine + the size of the memory bins. + @param MemoryTypeStatistics The memory type statistics array to be updated with the memory bin + information if the provided range is used. + @param DefaultMaximumAddress A pointer to the default maximum address to be updated if the + provided range is used. + @param CreateHob TRUE to create Memory Type Information Resource HOB after successful + allocation. This is used for PEI Core to report the bins to DXE Core. + DXE Core must set this to FALSE because HOB creation is not supported in + DXE (nor is the information required to be passed to another entity). +**/ +VOID +EFIAPI +AllocateMemoryTypeInformationBins ( + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_PHYSICAL_ADDRESS *DefaultMaximumAddress, + IN BOOLEAN CreateHob + ) +{ + UINTN Index; + EFI_MEMORY_TYPE Type; + EFI_PHYSICAL_ADDRESS BaseAddress; + EFI_PHYSICAL_ADDRESS LastBinAddress; + UINT64 RequiredSize; + + ASSERT (MemoryTypeInformationInitialized != NULL); + ASSERT (MemoryTypeInformation != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (DefaultMaximumAddress != NULL); + + if ((MemoryTypeInformationInitialized == NULL) || + (MemoryTypeInformation == NULL) || + (MemoryTypeStatistics == NULL) || + (DefaultMaximumAddress == NULL)) + { + return; + } + + // + // Check to see if the statistics for the different memory types have already been established + // + if (*MemoryTypeInformationInitialized) { + return; + } + + BaseAddress = 0; + RequiredSize = CalculateTotalMemoryBinSizeNeeded (NULL, MemoryTypeInformation); + if (RequiredSize == 0) { + *MemoryTypeInformationInitialized = TRUE; + return; + } + + // To ensure we get a contiguous range of memory for our bins, we will attempt to allocate + // all of the memory needed in one go. If that works, we can then carve it up into the individual bins. + // Our size is already aligned to the correct granularity, allocate aligned pages to ensure the base address is + // aligned. + BaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAlignedPages ( + EFI_SIZE_TO_PAGES ((UINTN)RequiredSize), + RUNTIME_PAGE_ALLOCATION_GRANULARITY + ); + + if (BaseAddress == 0) { + DEBUG (( + DEBUG_INFO, + "%a: Could not allocate contiguous pages for all memory bins. It will be attempted again when more memory is added.\n", + __func__ + )); + return; + } + + DEBUG (( + DEBUG_INFO, + "%a: Allocated 0x%llx - 0x%llx for memory bins\n", + __func__, + BaseAddress, + BaseAddress + RequiredSize - 1 + )); + + LastBinAddress = BaseAddress + RequiredSize; + *DefaultMaximumAddress = BaseAddress - 1; + + // + // Loop through each memory type in the order specified by the gMemoryTypeInformation[] array + // + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the gMemoryTypeInformation[] array is valid + // + Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); + if ((UINT32)Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + MemoryTypeStatistics[Type].BaseAddress = LastBinAddress - EFI_PAGES_TO_SIZE (MemoryTypeInformation[Index].NumberOfPages); + MemoryTypeStatistics[Type].MaximumAddress = LastBinAddress - 1; + LastBinAddress = MemoryTypeStatistics[Type].BaseAddress; + } + } + + // + // There was enough system memory for all the the memory types were allocated. So, + // those memory areas can be freed for future allocations, and all future memory + // allocations can occur within their respective bins + // + FreeAlignedPages ( + (VOID *)(UINTN)BaseAddress, + EFI_SIZE_TO_PAGES ((UINTN)RequiredSize) + ); + for (Index = 0; MemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + // + // Make sure the memory type in the MemoryTypeInformation[] array is valid + // + Type = (EFI_MEMORY_TYPE)(MemoryTypeInformation[Index].Type); + if ((UINT32)Type > EfiMaxMemoryType) { + continue; + } + + if (MemoryTypeInformation[Index].NumberOfPages != 0) { + MemoryTypeStatistics[Type].NumberOfPages = MemoryTypeInformation[Index].NumberOfPages; + MemoryTypeInformation[Index].NumberOfPages = 0; + } + } + + InitializeBinStatisticsFromRange (MemoryTypeInformation, MemoryTypeStatistics, DefaultMaximumAddress); + + if (CreateHob) { + // + // Create a Resource Descriptor HOB to report the Memory Type Information bins to DXE Core + // + BuildResourceDescriptorWithOwnerHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + TESTED_MEMORY_ATTRIBUTES, + BaseAddress, + RequiredSize, + &gEfiMemoryTypeInformationGuid + ); + } + + *MemoryTypeInformationInitialized = TRUE; +} + +/** + Update memory type statistics upon memory allocation and free. + + @param OldType The original memory type of the memory region. + @param NewType The new memory type of the memory region. + @param Start The starting physical address of the memory region. + @param NumberOfPages The number of pages in the memory region. + @param MemoryTypeInformationInitialized A pointer to a boolean that indicates whether the memory type + information bins have been initialized. + @param MemoryTypeStatistics The memory type statistics array to be updated. + @param MemoryTypeInformation The memory type information array to be updated. + @param DefaultBaseAddress Default bin base address. + @param DefaultMaximumAddress Default bin maximum address. +**/ +VOID +EFIAPI +UpdateMemoryStatistics ( + IN EFI_MEMORY_TYPE OldType, + IN EFI_MEMORY_TYPE NewType, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINTN NumberOfPages, + IN BOOLEAN *MemoryTypeInformationInitialized, + IN EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics, + IN EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation, + IN EFI_PHYSICAL_ADDRESS DefaultBaseAddress, + IN EFI_PHYSICAL_ADDRESS DefaultMaximumAddress + ) +{ + ASSERT (MemoryTypeInformationInitialized != NULL); + ASSERT (MemoryTypeStatistics != NULL); + ASSERT (MemoryTypeInformation != NULL); + + if ((MemoryTypeInformationInitialized == NULL) || + (MemoryTypeStatistics == NULL) || + (MemoryTypeInformation == NULL)) + { + return; + } + + if (!*MemoryTypeInformationInitialized) { + return; + } + + // + // Update counters for the number of pages allocated to each memory type + // + if ((UINT32)OldType < EfiMaxMemoryType) { + if (((Start >= MemoryTypeStatistics[OldType].BaseAddress) && (Start <= MemoryTypeStatistics[OldType].MaximumAddress)) || + ((Start >= DefaultBaseAddress) && (Start <= DefaultMaximumAddress))) + { + if (NumberOfPages > MemoryTypeStatistics[OldType].CurrentNumberOfPages) { + MemoryTypeStatistics[OldType].CurrentNumberOfPages = 0; + } else { + MemoryTypeStatistics[OldType].CurrentNumberOfPages -= NumberOfPages; + } + } + } + + if ((UINT32)NewType < EfiMaxMemoryType) { + if (((Start >= MemoryTypeStatistics[NewType].BaseAddress) && (Start <= MemoryTypeStatistics[NewType].MaximumAddress)) || + ((Start >= DefaultBaseAddress) && (Start <= DefaultMaximumAddress))) + { + MemoryTypeStatistics[NewType].CurrentNumberOfPages += NumberOfPages; + if ((MemoryTypeStatistics[NewType].InformationIndex < (UINTN)EfiMaxMemoryType) && + (MemoryTypeStatistics[NewType].CurrentNumberOfPages > MemoryTypeInformation[MemoryTypeStatistics[NewType].InformationIndex].NumberOfPages)) + { + MemoryTypeInformation[MemoryTypeStatistics[NewType].InformationIndex].NumberOfPages = (UINT32)MemoryTypeStatistics[NewType].CurrentNumberOfPages; + } + } + } +} diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c index 80b2f898b1..5b35657da5 100644 --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c @@ -7,6 +7,100 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "PeiMain.h" +#include +#include + +/** + Initialize memory type information bins based on the memory type information HOB. + + @param[in] PrivateData Pointer to PEI core's private instance data. + @param[in] HobList Pointer to the memory type information HOB. +**/ +STATIC +VOID +InitializeMemoryTypeInformationBins ( + PEI_CORE_INSTANCE *PrivateData, + IN VOID **HobList + ) +{ + EFI_PHYSICAL_ADDRESS BaseBinAddress; + EFI_PHYSICAL_ADDRESS EndBinAddress; + EFI_PEI_HOB_POINTERS Hob; + UINTN Index; + EFI_HOB_RESOURCE_DESCRIPTOR *MemoryTypeInformationResourceHob; + + BaseBinAddress = 0; + EndBinAddress = 0; + + MemoryTypeInformationResourceHob = GetMemoryTypeInformationResourceHob (HobList, PrivateData->MemoryTypeInformation); + + if (MemoryTypeInformationResourceHob != NULL) { + // + // If a Memory Type Information Resource HOB was found, then use the address + // range of the Memory Type Information Resource HOB as the preferred + // address range for the Memory Type Information bins. + // PEI doesn't use the last param here, so we ignore it, but + // the API needs something passed in. + // + CoreSetMemoryTypeInformationRange ( + MemoryTypeInformationResourceHob->PhysicalStart, + MemoryTypeInformationResourceHob->ResourceLength, + PrivateData->MemoryTypeInformation, + &PrivateData->MemoryTypeInformationInitialized, + PrivateData->MemoryTypeStatistics, + &BaseBinAddress + ); + + goto Fixup_PHIT; + } + + // We don't have a Memory Type Information Resource HOB, so we will allocate memory to use for the bins + // and create the HOB ourselves to inform DXE this is where the bins live. + // PEI doesn't use the last param here, so we ignore it, but + // the API needs something passed in. + AllocateMemoryTypeInformationBins ( + &PrivateData->MemoryTypeInformationInitialized, + PrivateData->MemoryTypeInformation, + PrivateData->MemoryTypeStatistics, + &BaseBinAddress, + TRUE + ); + +Fixup_PHIT: + // Set these to 0, ignoring whatever was set here by the memory bin code, PEI doesn't use it + BaseBinAddress = 0; + + // At this point we have set up our memory bins, so we need to fix up the PHIT to reflect the + // new memory allocations. + Hob.Raw = ((EFI_PEI_HOB_POINTERS *)HobList)->Raw; + + if (Hob.Raw == NULL) { + // + // We shouldn't get here, bins won't work without a valid HOB list + // + DEBUG ((DEBUG_ERROR, "%a: No valid HOB list found, can't init memory bins\n", __func__)); + ASSERT (FALSE); + return; + } + + // Find max/min addresses of the bins + for (Index = 0; (EFI_MEMORY_TYPE)Index < EfiMaxMemoryType; Index++) { + if ((PrivateData->MemoryTypeStatistics[Index].NumberOfPages != 0) && (PrivateData->MemoryTypeStatistics[Index].MaximumAddress != 0)) { + if ((PrivateData->MemoryTypeStatistics[Index].BaseAddress < BaseBinAddress) || (BaseBinAddress == 0)) { + BaseBinAddress = PrivateData->MemoryTypeStatistics[Index].BaseAddress; + } + + if (PrivateData->MemoryTypeStatistics[Index].MaximumAddress > EndBinAddress) { + EndBinAddress = PrivateData->MemoryTypeStatistics[Index].MaximumAddress; + } + } + } + + // The bins may or may not intersect the PHIT + if ((Hob.HandoffInformationTable->EfiFreeMemoryTop > BaseBinAddress) && (Hob.HandoffInformationTable->EfiFreeMemoryBottom < EndBinAddress)) { + Hob.HandoffInformationTable->EfiFreeMemoryTop = BaseBinAddress; + } +} /** @@ -27,6 +121,10 @@ InitializeMemoryServices ( IN PEI_CORE_INSTANCE *OldCoreData ) { + VOID *HobList; + EFI_STATUS Status; + EFI_MEMORY_TYPE Type; + PrivateData->SwitchStackSignal = FALSE; // @@ -47,6 +145,67 @@ InitializeMemoryServices ( // Set Ps to point to ServiceTableShadow in Cache // PrivateData->Ps = &(PrivateData->ServiceTableShadow); + } else { + // We have permanent memory now, so we should set up the memory bins if we can. No matter what, initialize the + // structures + PrivateData->MemoryTypeInformationInitialized = FALSE; + PrivateData->MemoryTypeInformation = NULL; + PrivateData->MemoryTypeStatistics = NULL; + + // Check if the platform has opted in to the PEI memory bins feature + if (FeaturePcdGet (PcdPeiMemoryBinsEnable)) { + Status = PeiGetHobList ((CONST EFI_PEI_SERVICES **)&PrivateData->Ps, &HobList); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return; + } + + PrivateData->MemoryTypeInformation = AllocateZeroPool (sizeof (EFI_MEMORY_TYPE_INFORMATION) * (EfiMaxMemoryType + 1)); + PrivateData->MemoryTypeStatistics = AllocateZeroPool (sizeof (EFI_MEMORY_TYPE_STATISTICS) * (EfiMaxMemoryType + 1)); + + if ((PrivateData->MemoryTypeInformation == NULL) || (PrivateData->MemoryTypeStatistics == NULL)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory for PEI memory bins\n", __func__)); + ASSERT (FALSE); + return; + } + + for (Type = 0; Type < EfiMaxMemoryType; Type++) { + PrivateData->MemoryTypeInformation[Type].Type = Type; + + PrivateData->MemoryTypeStatistics[Type].InformationIndex = EfiMaxMemoryType; + + switch (Type) { + case EfiRuntimeServicesCode: + case EfiRuntimeServicesData: + case EfiPalCode: + PrivateData->MemoryTypeStatistics[Type].Runtime = TRUE; + // fall through + case EfiReservedMemoryType: + case EfiACPIReclaimMemory: + case EfiACPIMemoryNVS: + case EfiUnacceptedMemoryType: + PrivateData->MemoryTypeStatistics[Type].Special = TRUE; + break; + default: + break; + } + } + + Status = PopulateMemoryTypeInformation (PrivateData->MemoryTypeInformation); + if (EFI_ERROR (Status)) { + // + // Couldn't find the memory type information HOB, so we can't set up bins + // + DEBUG (( + DEBUG_ERROR, + "Memory Type Information HOB not found during memory services initialization but PCD was set\n" + )); + ASSERT_EFI_ERROR (Status); + return; + } + + InitializeMemoryTypeInformationBins (PrivateData, &HobList); + } } return; @@ -57,9 +216,9 @@ InitializeMemoryServices ( This function registers the found memory configuration with the PEI Foundation. The usage model is that the PEIM that discovers the permanent memory shall invoke this service. - This routine will hold discoveried memory information into PeiCore's private data, - and set SwitchStackSignal flag. After PEIM who discovery memory is dispatched, - PeiDispatcher will migrate temporary memory to permanent memory. + This routine will store discovered memory information into PeiCore's private data, + and set the SwitchStackSignal flag. After the PEIM who discovered memory is dispatched, + the PeiDispatcher will migrate temporary memory to permanent memory. @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation. @param MemoryBegin Start of memory address. @@ -268,13 +427,23 @@ ConvertMemoryAllocationHobs ( **/ VOID InternalBuildMemoryAllocationHob ( - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length, - IN EFI_MEMORY_TYPE MemoryType + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN EFI_MEMORY_TYPE MemoryType ) { EFI_PEI_HOB_POINTERS Hob; EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob; + EFI_STATUS Status; + PEI_CORE_INSTANCE *PrivateData; + + if (PeiServices == NULL) { + ASSERT (PeiServices != NULL); + return; + } + + PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); // // Search unused(freed) memory allocation HOB. @@ -291,30 +460,45 @@ InternalBuildMemoryAllocationHob ( Hob.Raw = GetNextHob (EFI_HOB_TYPE_UNUSED, Hob.Raw); } - if (MemoryAllocationHob != NULL) { - // - // Reuse the unused(freed) memory allocation HOB. - // - MemoryAllocationHob->Header.HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION; - ZeroMem (&(MemoryAllocationHob->AllocDescriptor.Name), sizeof (EFI_GUID)); - MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress = BaseAddress; - MemoryAllocationHob->AllocDescriptor.MemoryLength = Length; - MemoryAllocationHob->AllocDescriptor.MemoryType = MemoryType; - // - // Zero the reserved space to match HOB spec - // - ZeroMem (MemoryAllocationHob->AllocDescriptor.Reserved, sizeof (MemoryAllocationHob->AllocDescriptor.Reserved)); - } else { - // - // No unused(freed) memory allocation HOB found. - // Build memory allocation HOB normally. - // - BuildMemoryAllocationHob ( - BaseAddress, - Length, - MemoryType - ); + // + // If we didn't find a HOB to reuse, then create a new one. + // + if (MemoryAllocationHob == NULL) { + Status = PeiCreateHob (PeiServices, EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16)sizeof (EFI_HOB_MEMORY_ALLOCATION), (VOID **)&MemoryAllocationHob); + if (EFI_ERROR (Status) || (MemoryAllocationHob == NULL)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to create memory allocation HOB Status = %r, MemoryAllocationHob = 0x%llx\n", + __func__, + Status, + MemoryAllocationHob + )); + ASSERT (FALSE); + return; + } } + + MemoryAllocationHob->Header.HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION; + + // + // If we are using PEI memory bins, track this allocation with the Memory Type Information GUID for DXE to consume. + // Otherwise, just produce a HOB with a zeroed GUID. + // + if (PrivateData->MemoryTypeInformationInitialized && (MemoryType < EfiMaxMemoryType) && + (PrivateData->MemoryTypeStatistics[MemoryType].NumberOfPages != 0)) + { + CopyGuid (&(MemoryAllocationHob->AllocDescriptor.Name), &gEfiMemoryTypeInformationGuid); + } else { + ZeroMem (&(MemoryAllocationHob->AllocDescriptor.Name), sizeof (EFI_GUID)); + } + + MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress = BaseAddress; + MemoryAllocationHob->AllocDescriptor.MemoryLength = Length; + MemoryAllocationHob->AllocDescriptor.MemoryType = MemoryType; + // + // Zero the reserved space to match HOB spec + // + ZeroMem (MemoryAllocationHob->AllocDescriptor.Reserved, sizeof (MemoryAllocationHob->AllocDescriptor.Reserved)); } /** @@ -332,6 +516,7 @@ InternalBuildMemoryAllocationHob ( **/ VOID UpdateOrSplitMemoryAllocationHob ( + IN CONST EFI_PEI_SERVICES **PeiServices, IN OUT EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob, IN EFI_PHYSICAL_ADDRESS Memory, IN UINT64 Bytes, @@ -345,6 +530,7 @@ UpdateOrSplitMemoryAllocationHob ( // Last pages need to be split out. // InternalBuildMemoryAllocationHob ( + PeiServices, Memory + Bytes, (MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress + MemoryAllocationHob->AllocDescriptor.MemoryLength) - (Memory + Bytes), MemoryAllocationHob->AllocDescriptor.MemoryType @@ -356,6 +542,7 @@ UpdateOrSplitMemoryAllocationHob ( // First pages need to be split out. // InternalBuildMemoryAllocationHob ( + PeiServices, MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress, Memory - MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress, MemoryAllocationHob->AllocDescriptor.MemoryType @@ -457,10 +644,11 @@ MergeFreeMemoryInMemoryAllocationHob ( **/ EFI_STATUS FindFreeMemoryFromMemoryAllocationHob ( - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN Pages, - IN UINTN Granularity, - OUT EFI_PHYSICAL_ADDRESS *Memory + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, + IN UINTN Granularity, + OUT EFI_PHYSICAL_ADDRESS *Memory ) { EFI_PEI_HOB_POINTERS Hob; @@ -503,7 +691,7 @@ FindFreeMemoryFromMemoryAllocationHob ( } if (MemoryAllocationHob != NULL) { - UpdateOrSplitMemoryAllocationHob (MemoryAllocationHob, BaseAddress, Bytes, MemoryType); + UpdateOrSplitMemoryAllocationHob (PeiServices, MemoryAllocationHob, BaseAddress, Bytes, MemoryType); *Memory = BaseAddress; return EFI_SUCCESS; } else { @@ -511,7 +699,7 @@ FindFreeMemoryFromMemoryAllocationHob ( // // Retry if there are free memory ranges merged. // - return FindFreeMemoryFromMemoryAllocationHob (MemoryType, Pages, Granularity, Memory); + return FindFreeMemoryFromMemoryAllocationHob (PeiServices, MemoryType, Pages, Granularity, Memory); } return EFI_NOT_FOUND; @@ -558,6 +746,7 @@ PeiAllocatePages ( UINTN RemainingMemory; UINTN Granularity; UINTN Padding; + UINTN Index; if ((MemoryType != EfiLoaderCode) && (MemoryType != EfiLoaderData) && @@ -572,6 +761,8 @@ PeiAllocatePages ( return EFI_INVALID_PARAMETER; } + RemainingPages = 0; + Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); @@ -607,82 +798,123 @@ PeiAllocatePages ( FreeMemoryTop = &(PrivateData->FreePhysicalMemoryTop); FreeMemoryBottom = &(PrivateData->PhysicalMemoryBegin); } else { - FreeMemoryTop = &(Hob.HandoffInformationTable->EfiFreeMemoryTop); - FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom); + // if we are in permanent memory and have memory bins, we need to respect them. A maximum address + // of 0 means the memory type is using the default bin, which is the PHIT here. + if (PrivateData->MemoryTypeInformationInitialized && (PrivateData->MemoryTypeStatistics[MemoryType].MaximumAddress != 0)) { + FreeMemoryTop = &(PrivateData->MemoryTypeStatistics[MemoryType].MaximumAddress); + FreeMemoryBottom = &(PrivateData->MemoryTypeStatistics[MemoryType].BaseAddress); + } else { + FreeMemoryTop = &(Hob.HandoffInformationTable->EfiFreeMemoryTop); + FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom); + } } // - // Check to see if on correct boundary for the memory type. - // If not aligned, make the allocation aligned and that we are not trying to allocate page 0, which is used for - // null detection. + // We will attempt up to two times here. + // If we don't have memory bins, we will only attempt to allocate from the PHIT. + // If we have memory bins, we'll attempt to allocate from the appropriate bin first. If that fails we'll try + // allocating from the PHIT. // - Padding = *(FreeMemoryTop) & (Granularity - 1); - if (((UINTN)(*FreeMemoryTop - *FreeMemoryBottom) < Padding) || (*(FreeMemoryTop) - Padding == 0)) { - DEBUG ((DEBUG_ERROR, "AllocatePages failed: Out of space after padding.\n")); - return EFI_OUT_OF_RESOURCES; - } - - *(FreeMemoryTop) -= Padding; - if (Padding >= EFI_PAGE_SIZE) { - // - // Create a memory allocation HOB to cover - // the pages that we will lose to rounding - // - InternalBuildMemoryAllocationHob ( - *(FreeMemoryTop), - Padding & ~(UINTN)EFI_PAGE_MASK, - EfiConventionalMemory - ); - } - + // If allocating from the PHIT fails in either case, we'll then search memory allocation HOBs for free memory. // - // Verify that there is sufficient memory to satisfy the allocation. - // - RemainingMemory = (UINTN)(*FreeMemoryTop - *FreeMemoryBottom); - RemainingPages = (UINTN)(RShiftU64 (RemainingMemory, EFI_PAGE_SHIFT)); - // - // The number of remaining pages needs to be greater than or equal to that of - // the request pages. In addition, there should be enough space left to hold a - // Memory Allocation HOB. - // - Pages = ALIGN_VALUE (Pages, EFI_SIZE_TO_PAGES (Granularity)); - if ((RemainingPages > Pages) || - ((RemainingPages == Pages) && - ((RemainingMemory & EFI_PAGE_MASK) >= sizeof (EFI_HOB_MEMORY_ALLOCATION)))) - { + for (Index = 0; Index < 2; Index++) { // - // Update the PHIT to reflect the memory usage + // Check to see if on correct boundary for the memory type. + // If not aligned, make the allocation aligned and that we are not trying to allocate page 0, which is used for + // null detection. // - *(FreeMemoryTop) -= Pages * EFI_PAGE_SIZE; + Padding = *(FreeMemoryTop) & (Granularity - 1); + if (((UINTN)(*FreeMemoryTop - *FreeMemoryBottom) < Padding) || (*(FreeMemoryTop) - Padding == 0)) { + if ((Index == 0) && PrivateData->MemoryTypeInformationInitialized && (PrivateData->MemoryTypeStatistics[MemoryType].MaximumAddress != 0)) { + // + // Try the default bin before searching memory allocation HOBs + // + FreeMemoryTop = &(Hob.HandoffInformationTable->EfiFreeMemoryTop); + FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom); + continue; + } - // - // Update the value for the caller - // - *Memory = *(FreeMemoryTop); - - // - // Create a memory allocation HOB. - // - InternalBuildMemoryAllocationHob ( - *(FreeMemoryTop), - Pages * EFI_PAGE_SIZE, - MemoryType - ); - - return EFI_SUCCESS; - } else { - // - // Try to find free memory by searching memory allocation HOBs. - // - Status = FindFreeMemoryFromMemoryAllocationHob (MemoryType, Pages, Granularity, Memory); - if (!EFI_ERROR (Status)) { - return Status; + goto NotEnoughFreeMemory; } - DEBUG ((DEBUG_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64)Pages)); - DEBUG ((DEBUG_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64)RemainingPages)); - return EFI_OUT_OF_RESOURCES; + *(FreeMemoryTop) -= Padding; + if (Padding >= EFI_PAGE_SIZE) { + // + // Create a memory allocation HOB to cover + // the pages that we will lose to rounding + // + InternalBuildMemoryAllocationHob ( + PeiServices, + *(FreeMemoryTop), + Padding & ~(UINTN)EFI_PAGE_MASK, + EfiConventionalMemory + ); + } + + // + // Verify that there is sufficient memory to satisfy the allocation. + // + RemainingMemory = (UINTN)(*FreeMemoryTop - *FreeMemoryBottom); + RemainingPages = (UINTN)(RShiftU64 (RemainingMemory, EFI_PAGE_SHIFT)); + // + // The number of remaining pages needs to be greater than or equal to that of + // the request pages. In addition, there should be enough space left to hold a + // Memory Allocation HOB. + // + Pages = ALIGN_VALUE (Pages, EFI_SIZE_TO_PAGES (Granularity)); + if ((RemainingPages > Pages) || + ((RemainingPages == Pages) && + ((RemainingMemory & EFI_PAGE_MASK) >= sizeof (EFI_HOB_MEMORY_ALLOCATION)))) + { + // + // Update the PHIT to reflect the memory usage + // + *(FreeMemoryTop) -= Pages * EFI_PAGE_SIZE; + + // + // Update the value for the caller + // + *Memory = *(FreeMemoryTop); + + // + // Create a memory allocation HOB. + // + InternalBuildMemoryAllocationHob ( + PeiServices, + *(FreeMemoryTop), + Pages * EFI_PAGE_SIZE, + MemoryType + ); + + return EFI_SUCCESS; + } + + // If this was the first allocation attempt, we are using memory bins, and this memory type lands in a bin, + // retry allocation but target the PHIT free region. + if ((Index == 0) && PrivateData->MemoryTypeInformationInitialized && (PrivateData->MemoryTypeStatistics[MemoryType].MaximumAddress != 0)) { + // + // Try to the default bin before searching memory allocation HOBs + // + FreeMemoryTop = &(Hob.HandoffInformationTable->EfiFreeMemoryTop); + FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom); + continue; + } else { + goto NotEnoughFreeMemory; + } } + +NotEnoughFreeMemory: + // + // Try to find free memory by searching memory allocation HOBs. + // + Status = FindFreeMemoryFromMemoryAllocationHob ((CONST EFI_PEI_SERVICES **)PeiServices, MemoryType, Pages, Granularity, Memory); + if (!EFI_ERROR (Status)) { + return Status; + } + + DEBUG ((DEBUG_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64)Pages)); + DEBUG ((DEBUG_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64)RemainingPages)); + return EFI_OUT_OF_RESOURCES; } /** @@ -817,7 +1049,7 @@ PeiFreePages ( } if (MemoryAllocationHob != NULL) { - UpdateOrSplitMemoryAllocationHob (MemoryAllocationHob, Memory, Bytes, EfiConventionalMemory); + UpdateOrSplitMemoryAllocationHob (PeiServices, MemoryAllocationHob, Memory, Bytes, EfiConventionalMemory); FreeMemoryAllocationHob (PrivateData, MemoryAllocationHob); return EFI_SUCCESS; } else { diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMain.h index faba504c45..611998a20c 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.h +++ b/MdeModulePkg/Core/Pei/PeiMain.h @@ -50,6 +50,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include +#include /// /// It is an FFS type extension used for PeiFindFileEx. It indicates current @@ -334,6 +336,23 @@ struct _PEI_CORE_INSTANCE { // Table of delayed dispatch requests // DELAYED_DISPATCH_TABLE *DelayedDispatchTable; + + // + // Whether memory bins are initialized and being used in PEI + // + BOOLEAN MemoryTypeInformationInitialized; + + // + // Memory type information for all memory types. The array index is the memory type. + // This is used for the memory bin feature, if enabled, to track bin sizes. + // + EFI_MEMORY_TYPE_INFORMATION *MemoryTypeInformation; + + // + // Memory type statistics for all memory types. The array index is the memory type. + // This is used for the memory bin feature, if enabled, to track bin locations. + // + EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics; }; /// diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiMain.inf index 27977ea9c0..d172ee74be 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.inf +++ b/MdeModulePkg/Core/Pei/PeiMain.inf @@ -34,6 +34,7 @@ Reset/Reset.c Ppi/Ppi.c PeiMain/PeiMain.c + Memory/MemoryBin.c Memory/MemoryServices.c Image/Image.c Hob/Hob.c @@ -82,6 +83,7 @@ gEdkiiMigratedFvInfoGuid ## SOMETIMES_PRODUCES ## HOB gEdkiiMigrationInfoGuid ## SOMETIMES_CONSUMES ## HOB gEfiDelayedDispatchTableGuid ## SOMETIMES_PRODUCES ## HOB + gEfiMemoryTypeInformationGuid ## SOMETIMES_CONSUMES ## HOB [Ppis] gEfiPeiStatusCodePpiGuid ## SOMETIMES_CONSUMES # PeiReportStatusService is not ready if this PPI doesn't exist @@ -122,6 +124,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdDelayedDispatchMaxDelayUs ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDelayedDispatchCompletionTimeoutUs ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDelayedDispatchMaxEntries ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdPeiMemoryBinsEnable ## CONSUMES # [BootMode] # S3_RESUME ## SOMETIMES_CONSUMES From cf1a2a541e1fa19a0117a952fece30de1928caae Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Thu, 29 Jan 2026 09:51:48 -0800 Subject: [PATCH 073/406] MdeModulePkg: DxeCore: Update Memory Statistics from PEI If memory bins are enabled for PEI, PEI will produce Memory Allocation HOBs marked with gEfiMemoryTypeInformationGuid. If these exist, DXE core will now process the stats from them to have accurate numbers. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 6d66857617..de27f63791 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -2785,6 +2785,21 @@ CoreInitializeGcdServices ( RShiftU64 (MemoryHob->AllocDescriptor.MemoryLength, EFI_PAGE_SHIFT), Descriptor.Capabilities & (~EFI_MEMORY_RUNTIME) ); + + // if this Memory Allocation HOB came from PEI, update the memory bin statistics + if (CompareGuid (&MemoryHob->AllocDescriptor.Name, &gEfiMemoryTypeInformationGuid)) { + UpdateMemoryStatistics ( + EfiConventionalMemory, + MemoryHob->AllocDescriptor.MemoryType, + MemoryHob->AllocDescriptor.MemoryBaseAddress, + EFI_SIZE_TO_PAGES ((UINT32)MemoryHob->AllocDescriptor.MemoryLength), + &mMemoryTypeInformationInitialized, + mMemoryTypeStatistics, + gMemoryTypeInformation, + mDefaultBaseAddress, + mDefaultMaximumAddress + ); + } } } } From 1b39cb1d816a870a44fbeeaaf092773b1b08b179 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Thu, 29 Jan 2026 09:56:38 -0800 Subject: [PATCH 074/406] MdeModulePkg: MemoryBins: Add GoogleTest and README This commit adds unit tests and documentation for the Memory Bin feature. Signed-off-by: Oliver Smith-Denny --- .../Mem/GoogleTest/MemoryBinGoogleTest.cpp | 661 ++++++++++++++++++ .../GoogleTest/MemoryBinGoogleTestHost.inf | 33 + MdeModulePkg/Core/MemoryBins.md | 276 ++++++++ MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 5 + 4 files changed, 975 insertions(+) create mode 100644 MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp create mode 100644 MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTestHost.inf create mode 100644 MdeModulePkg/Core/MemoryBins.md diff --git a/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp b/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp new file mode 100644 index 0000000000..4ac6dcbd42 --- /dev/null +++ b/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp @@ -0,0 +1,661 @@ +/** @file + Unit tests for BaseMemoryBinLib library. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +extern "C" { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + BOOLEAN mMemoryTypeInformationInitialized = FALSE; + + EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = { + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiReservedMemoryType + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderCode + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderData + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiBootServicesCode + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiBootServicesData + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiRuntimeServicesCode + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiRuntimeServicesData + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiConventionalMemory + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiUnusableMemory + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiACPIReclaimMemory + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiACPIMemoryNVS + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIO + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIOPortSpace + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiPalCode + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiPersistentMemory + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiUnacceptedMemoryType + { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiMaxMemoryType + }; + + EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ALLOC_ADDRESS; + EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ALLOC_ADDRESS; + + EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = { + { EfiReservedMemoryType, 0 }, + { EfiLoaderCode, 0 }, + { EfiLoaderData, 0 }, + { EfiBootServicesCode, 0 }, + { EfiBootServicesData, 0 }, + { EfiRuntimeServicesCode, 0 }, + { EfiRuntimeServicesData, 0 }, + { EfiConventionalMemory, 0 }, + { EfiUnusableMemory, 0 }, + { EfiACPIReclaimMemory, 0 }, + { EfiACPIMemoryNVS, 0 }, + { EfiMemoryMappedIO, 0 }, + { EfiMemoryMappedIOPortSpace, 0 }, + { EfiPalCode, 0 }, + { EfiPersistentMemory, 0 }, + { EfiGcdMemoryTypeUnaccepted, 0 }, + { EfiMaxMemoryType, 0 } + }; +} + +using namespace testing; + +class BaseMemoryBinLibTest : public ::testing::Test { +protected: + StrictMock HobLib; + void + SetUp ( + ) override + { + // + // Reset global state before each test + // + mMemoryTypeInformationInitialized = FALSE; + mDefaultMaximumAddress = MAX_ALLOC_ADDRESS; + mDefaultBaseAddress = MAX_ALLOC_ADDRESS; + + for (UINTN i = 0; i < EfiMaxMemoryType + 1; i++) { + gMemoryTypeInformation[i].NumberOfPages = 0; + } + + for (UINTN i = 0; i < EfiMaxMemoryType + 1; i++) { + mMemoryTypeStatistics[i].BaseAddress = 0; + mMemoryTypeStatistics[i].MaximumAddress = MAX_ALLOC_ADDRESS; + mMemoryTypeStatistics[i].CurrentNumberOfPages = 0; + mMemoryTypeStatistics[i].NumberOfPages = 0; + mMemoryTypeStatistics[i].InformationIndex = EfiMaxMemoryType; + } + + mMemoryTypeStatistics[EfiReservedMemoryType].Special = TRUE; + mMemoryTypeStatistics[EfiRuntimeServicesCode].Special = TRUE; + mMemoryTypeStatistics[EfiRuntimeServicesCode].Runtime = TRUE; + mMemoryTypeStatistics[EfiRuntimeServicesData].Special = TRUE; + mMemoryTypeStatistics[EfiRuntimeServicesData].Runtime = TRUE; + mMemoryTypeStatistics[EfiACPIReclaimMemory].Special = TRUE; + mMemoryTypeStatistics[EfiACPIMemoryNVS].Special = TRUE; + mMemoryTypeStatistics[EfiPalCode].Special = TRUE; + mMemoryTypeStatistics[EfiPalCode].Runtime = TRUE; + mMemoryTypeStatistics[EfiUnacceptedMemoryType].Special = TRUE; + } +}; + +// +// Test: CalculateTotalMemoryBinSizeNeeded with no pages allocated +// +TEST_F (BaseMemoryBinLibTest, CalculateTotalMemoryBinSizeNeededReturnsZeroWhenNoPagesAllocated) { + UINT64 TotalSize; + + TotalSize = CalculateTotalMemoryBinSizeNeeded (NULL, gMemoryTypeInformation); + + ASSERT_EQ (TotalSize, (UINT64)0); +} + +// +// Test: CalculateTotalMemoryBinSizeNeeded with pages allocated +// +TEST_F (BaseMemoryBinLibTest, CalculateTotalMemoryBinSizeNeededCalculatesCorrectSize) { + UINT64 TotalSize; + + gMemoryTypeInformation[0].Type = EfiRuntimeServicesCode; + gMemoryTypeInformation[0].NumberOfPages = 10; + gMemoryTypeInformation[1].Type = EfiRuntimeServicesData; + gMemoryTypeInformation[1].NumberOfPages = 20; + gMemoryTypeInformation[2].Type = EfiMaxMemoryType; + + TotalSize = CalculateTotalMemoryBinSizeNeeded (NULL, gMemoryTypeInformation); + + ASSERT_EQ (TotalSize, (UINT64)(30 * EFI_PAGE_SIZE)); +} + +// +// Test: CoreSetMemoryTypeInformationRange initializes bins correctly +// +TEST_F (BaseMemoryBinLibTest, CoreSetMemoryTypeInformationRangeSetsUpBinsCorrectly) { + EFI_PHYSICAL_ADDRESS Start; + UINT64 Length; + + Start = 0x100000; + Length = 0x100000; + + gMemoryTypeInformation[0].Type = EfiRuntimeServicesCode; + gMemoryTypeInformation[0].NumberOfPages = 20; + gMemoryTypeInformation[1].Type = EfiRuntimeServicesData; + gMemoryTypeInformation[1].NumberOfPages = 10; + gMemoryTypeInformation[2].Type = EfiReservedMemoryType; + gMemoryTypeInformation[2].NumberOfPages = 5; + gMemoryTypeInformation[3].Type = EfiACPIReclaimMemory; + gMemoryTypeInformation[3].NumberOfPages = 15; + gMemoryTypeInformation[4].Type = EfiACPIMemoryNVS; + gMemoryTypeInformation[4].NumberOfPages = 25; + gMemoryTypeInformation[5].Type = EfiMaxMemoryType; + + CoreSetMemoryTypeInformationRange (Start, Length, gMemoryTypeInformation, &mMemoryTypeInformationInitialized, mMemoryTypeStatistics, &mDefaultMaximumAddress); + + ASSERT_TRUE (mMemoryTypeInformationInitialized); + + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesCode].NumberOfPages, (UINT32)20); + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesData].NumberOfPages, (UINT32)10); + ASSERT_EQ (mMemoryTypeStatistics[EfiReservedMemoryType].NumberOfPages, (UINT32)5); + ASSERT_EQ (mMemoryTypeStatistics[EfiACPIReclaimMemory].NumberOfPages, (UINT32)15); + ASSERT_EQ (mMemoryTypeStatistics[EfiACPIMemoryNVS].NumberOfPages, (UINT32)25); + + // Confirm contiguous bins + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesData].MaximumAddress + 1, mMemoryTypeStatistics[EfiRuntimeServicesCode].BaseAddress); + ASSERT_EQ (mMemoryTypeStatistics[EfiReservedMemoryType].MaximumAddress + 1, mMemoryTypeStatistics[EfiRuntimeServicesData].BaseAddress); + ASSERT_EQ (mMemoryTypeStatistics[EfiACPIReclaimMemory].MaximumAddress + 1, mMemoryTypeStatistics[EfiReservedMemoryType].BaseAddress); + ASSERT_EQ (mMemoryTypeStatistics[EfiACPIMemoryNVS].MaximumAddress + 1, mMemoryTypeStatistics[EfiACPIReclaimMemory].BaseAddress); +} + +// +// Test: CoreSetMemoryTypeInformationRange rejects insufficient space +// +TEST_F (BaseMemoryBinLibTest, CoreSetMemoryTypeInformationRangeRejectsInsufficientSpace) { + EFI_PHYSICAL_ADDRESS Start; + UINT64 Length; + + Start = 0x100000; + Length = 0x1000; + + gMemoryTypeInformation[0].Type = EfiRuntimeServicesCode; + gMemoryTypeInformation[0].NumberOfPages = 100; // Requires more than 4KB + gMemoryTypeInformation[1].Type = EfiMaxMemoryType; + + CoreSetMemoryTypeInformationRange (Start, Length, gMemoryTypeInformation, &mMemoryTypeInformationInitialized, mMemoryTypeStatistics, &mDefaultMaximumAddress); + + ASSERT_FALSE (mMemoryTypeInformationInitialized); +} + +// +// Test: CoreSetMemoryTypeInformationRange respects already initialized state +// +TEST_F (BaseMemoryBinLibTest, CoreSetMemoryTypeInformationRangeRespectsInitializedState) { + EFI_PHYSICAL_ADDRESS Start; + UINT64 Length; + + mMemoryTypeInformationInitialized = TRUE; + + Start = 0x100000; + Length = 0x100000; + + gMemoryTypeInformation[0].Type = EfiRuntimeServicesCode; + gMemoryTypeInformation[0].NumberOfPages = 10; + mMemoryTypeStatistics[EfiRuntimeServicesCode].BaseAddress = 0x1000; + gMemoryTypeInformation[1].Type = EfiMaxMemoryType; + + CoreSetMemoryTypeInformationRange (Start, Length, gMemoryTypeInformation, &mMemoryTypeInformationInitialized, mMemoryTypeStatistics, &mDefaultMaximumAddress); + + ASSERT_TRUE (mMemoryTypeInformationInitialized); + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesCode].BaseAddress, (EFI_PHYSICAL_ADDRESS)0x1000); +} + +// +// Test: UpdateMemoryStatistics updates in-bin statistics correctly +// +TEST_F (BaseMemoryBinLibTest, UpdateMemoryStatisticsUpdatesInBinCorrectly) { + mMemoryTypeInformationInitialized = TRUE; + + mMemoryTypeStatistics[EfiRuntimeServicesCode].BaseAddress = 0x100000; + mMemoryTypeStatistics[EfiRuntimeServicesCode].MaximumAddress = 0x200000; + mMemoryTypeStatistics[EfiRuntimeServicesCode].InformationIndex = 0; + + gMemoryTypeInformation[0].Type = EfiRuntimeServicesCode; + gMemoryTypeInformation[0].NumberOfPages = 0; + + UpdateMemoryStatistics ( + EfiConventionalMemory, + EfiRuntimeServicesCode, + 0x150000, // Within bin range + 10, + &mMemoryTypeInformationInitialized, + mMemoryTypeStatistics, + gMemoryTypeInformation, + 0x10000, // Just set these outside of the range + 0x20000 + ); + + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesCode].CurrentNumberOfPages, (UINT32)10); +} + +// +// Test: UpdateMemoryStatistics updates out-of-bin statistics correctly +// +TEST_F (BaseMemoryBinLibTest, UpdateMemoryStatisticsUpdatesOutOfBinCorrectly) { + mMemoryTypeInformationInitialized = TRUE; + + mMemoryTypeStatistics[EfiRuntimeServicesCode].BaseAddress = 0x100000; + mMemoryTypeStatistics[EfiRuntimeServicesCode].MaximumAddress = 0x200000; + mMemoryTypeStatistics[EfiRuntimeServicesCode].InformationIndex = 0; + + gMemoryTypeInformation[0].Type = EfiRuntimeServicesCode; + gMemoryTypeInformation[0].NumberOfPages = 0; + + UpdateMemoryStatistics ( + EfiConventionalMemory, + EfiRuntimeServicesCode, + 0x300000, // Outside bin range + 10, + &mMemoryTypeInformationInitialized, + mMemoryTypeStatistics, + gMemoryTypeInformation, + 0x10000, // Just set these outside of the range + 0x20000 + ); + + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesCode].CurrentNumberOfPages, (UINT32)0); +} + +// +// Test: UpdateMemoryStatistics handles freeing memory +// +TEST_F (BaseMemoryBinLibTest, UpdateMemoryStatisticsHandlesFreeingMemory) { + mMemoryTypeInformationInitialized = TRUE; + + mMemoryTypeStatistics[EfiRuntimeServicesCode].BaseAddress = 0x100000; + mMemoryTypeStatistics[EfiRuntimeServicesCode].MaximumAddress = 0x200000; + mMemoryTypeStatistics[EfiRuntimeServicesCode].CurrentNumberOfPages = 20; + mMemoryTypeStatistics[EfiRuntimeServicesCode].InformationIndex = 0; + + gMemoryTypeInformation[0].Type = EfiRuntimeServicesCode; + gMemoryTypeInformation[0].NumberOfPages = 20; + + UpdateMemoryStatistics ( + EfiRuntimeServicesCode, + EfiConventionalMemory, + 0x150000, // Within bin range + 10, + &mMemoryTypeInformationInitialized, + mMemoryTypeStatistics, + gMemoryTypeInformation, + 0x10000, // Just set these outside of the range + 0x20000 + ); + + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesCode].CurrentNumberOfPages, (UINT32)10); +} + +// +// Tests for AllocateMemoryTypeInformationBins +// + +// +// Test: AllocateMemoryTypeInformationBins does nothing when already initialized +// +TEST_F (BaseMemoryBinLibTest, DoesNothingWhenAlreadyInitialized) { + mMemoryTypeInformationInitialized = TRUE; + mMemoryTypeStatistics[EfiRuntimeServicesCode].BaseAddress = 0x1000; + + AllocateMemoryTypeInformationBins (&mMemoryTypeInformationInitialized, gMemoryTypeInformation, mMemoryTypeStatistics, &mDefaultMaximumAddress, FALSE); + + // Should remain unchanged since already initialized + ASSERT_TRUE (mMemoryTypeInformationInitialized); + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesCode].BaseAddress, (EFI_PHYSICAL_ADDRESS)0x1000); +} + +// +// Test: AllocateMemoryTypeInformationBins does nothing when no pages needed +// +TEST_F (BaseMemoryBinLibTest, DoesNothingWhenNoPagesNeeded) { + AllocateMemoryTypeInformationBins (&mMemoryTypeInformationInitialized, gMemoryTypeInformation, mMemoryTypeStatistics, &mDefaultMaximumAddress, FALSE); + + ASSERT_TRUE (mMemoryTypeInformationInitialized); + ASSERT_EQ (mMemoryTypeStatistics[EfiReservedMemoryType].NumberOfPages, (UINT32)0); + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesCode].NumberOfPages, (UINT32)0); + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesData].NumberOfPages, (UINT32)0); + ASSERT_EQ (mMemoryTypeStatistics[EfiACPIReclaimMemory].NumberOfPages, (UINT32)0); + ASSERT_EQ (mMemoryTypeStatistics[EfiACPIMemoryNVS].NumberOfPages, (UINT32)0); +} + +// +// Test: AllocateMemoryTypeInformationBins allocates pages and initializes bins +// +TEST_F (BaseMemoryBinLibTest, AllocatesPagesAndInitializesBins) { + gMemoryTypeInformation[0].Type = EfiRuntimeServicesCode; + gMemoryTypeInformation[0].NumberOfPages = 20; + gMemoryTypeInformation[1].Type = EfiRuntimeServicesData; + gMemoryTypeInformation[1].NumberOfPages = 10; + gMemoryTypeInformation[2].Type = EfiReservedMemoryType; + gMemoryTypeInformation[2].NumberOfPages = 5; + gMemoryTypeInformation[3].Type = EfiACPIReclaimMemory; + gMemoryTypeInformation[3].NumberOfPages = 15; + gMemoryTypeInformation[4].Type = EfiACPIMemoryNVS; + gMemoryTypeInformation[4].NumberOfPages = 25; + gMemoryTypeInformation[5].Type = EfiMaxMemoryType; + + // HOB should not be built in this case + EXPECT_CALL (HobLib, BuildResourceDescriptorWithOwnerHob (_, _, _, _, _)) + .Times (0); + + AllocateMemoryTypeInformationBins (&mMemoryTypeInformationInitialized, gMemoryTypeInformation, mMemoryTypeStatistics, &mDefaultMaximumAddress, FALSE); + + ASSERT_TRUE (mMemoryTypeInformationInitialized); + + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesCode].NumberOfPages, (UINT32)20); + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesData].NumberOfPages, (UINT32)10); + ASSERT_EQ (mMemoryTypeStatistics[EfiReservedMemoryType].NumberOfPages, (UINT32)5); + ASSERT_EQ (mMemoryTypeStatistics[EfiACPIReclaimMemory].NumberOfPages, (UINT32)15); + ASSERT_EQ (mMemoryTypeStatistics[EfiACPIMemoryNVS].NumberOfPages, (UINT32)25); + + // Confirm contiguous bins + ASSERT_EQ (mMemoryTypeStatistics[EfiRuntimeServicesData].MaximumAddress + 1, mMemoryTypeStatistics[EfiRuntimeServicesCode].BaseAddress); + ASSERT_EQ (mMemoryTypeStatistics[EfiReservedMemoryType].MaximumAddress + 1, mMemoryTypeStatistics[EfiRuntimeServicesData].BaseAddress); + ASSERT_EQ (mMemoryTypeStatistics[EfiACPIReclaimMemory].MaximumAddress + 1, mMemoryTypeStatistics[EfiReservedMemoryType].BaseAddress); + ASSERT_EQ (mMemoryTypeStatistics[EfiACPIMemoryNVS].MaximumAddress + 1, mMemoryTypeStatistics[EfiACPIReclaimMemory].BaseAddress); +} + +// +// Test: AllocateMemoryTypeInformationBins creates HOB when requested +// +TEST_F (BaseMemoryBinLibTest, CreatesHobWhenRequested) { + UINT64 TotalPages = 30; + + gMemoryTypeInformation[0].Type = EfiRuntimeServicesCode; + gMemoryTypeInformation[0].NumberOfPages = 10; + gMemoryTypeInformation[1].Type = EfiRuntimeServicesData; + gMemoryTypeInformation[1].NumberOfPages = 20; + gMemoryTypeInformation[2].Type = EfiMaxMemoryType; + + EXPECT_CALL ( + HobLib, + BuildResourceDescriptorWithOwnerHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED, + _, + TotalPages * EFI_PAGE_SIZE, + &gEfiMemoryTypeInformationGuid + ) + ) + .Times (1); + + AllocateMemoryTypeInformationBins (&mMemoryTypeInformationInitialized, gMemoryTypeInformation, mMemoryTypeStatistics, &mDefaultMaximumAddress, TRUE); + + ASSERT_TRUE (mMemoryTypeInformationInitialized); +} + +// +// Test: PopulateMemoryTypeInformation returns NOT_FOUND when Memory Type Information HOB is missing +// +TEST_F (BaseMemoryBinLibTest, ReturnsNotFoundWhenMemoryTypeInformationHobMissing) { + EFI_STATUS Status; + + EXPECT_CALL (HobLib, GetFirstGuidHob (&gEfiMemoryTypeInformationGuid)) + .WillOnce (Return ((VOID *)NULL)); + + Status = PopulateMemoryTypeInformation (gMemoryTypeInformation); + + ASSERT_EQ (Status, EFI_NOT_FOUND); +} + +// +// Test: PopulateMemoryTypeInformation populates from valid HOB +// +TEST_F (BaseMemoryBinLibTest, PopulatesFromValidHob) { + EFI_STATUS Status; + UINT8 GuidHobBuffer[sizeof (EFI_HOB_GUID_TYPE) + sizeof (EFI_MEMORY_TYPE_INFORMATION) * 7]; + EFI_HOB_GUID_TYPE *GuidHob; + EFI_MEMORY_TYPE_INFORMATION *MemTypeInfo; + + ZeroMem (GuidHobBuffer, sizeof (GuidHobBuffer)); + GuidHob = (EFI_HOB_GUID_TYPE *)GuidHobBuffer; + GuidHob->Header.HobType = EFI_HOB_TYPE_GUID_EXTENSION; + GuidHob->Header.HobLength = sizeof (GuidHobBuffer); + CopyGuid (&GuidHob->Name, &gEfiMemoryTypeInformationGuid); + + MemTypeInfo = (EFI_MEMORY_TYPE_INFORMATION *)(GuidHob + 1); + MemTypeInfo[0].Type = EfiReservedMemoryType; + MemTypeInfo[0].NumberOfPages = 5; + MemTypeInfo[1].Type = EfiRuntimeServicesCode; + MemTypeInfo[1].NumberOfPages = 10; + MemTypeInfo[2].Type = EfiRuntimeServicesData; + MemTypeInfo[2].NumberOfPages = 15; + MemTypeInfo[3].Type = EfiACPIReclaimMemory; + MemTypeInfo[3].NumberOfPages = 20; + MemTypeInfo[4].Type = EfiACPIMemoryNVS; + MemTypeInfo[4].NumberOfPages = 25; + MemTypeInfo[5].Type = EfiPalCode; + MemTypeInfo[5].NumberOfPages = 8; + MemTypeInfo[6].Type = EfiMaxMemoryType; + MemTypeInfo[6].NumberOfPages = 0; + + EXPECT_CALL (HobLib, GetFirstGuidHob (&gEfiMemoryTypeInformationGuid)) + .WillOnce (Return ((VOID *)GuidHob)); + + Status = PopulateMemoryTypeInformation (gMemoryTypeInformation); + + ASSERT_EQ (Status, EFI_SUCCESS); + ASSERT_EQ (gMemoryTypeInformation[0].Type, (UINT32)EfiReservedMemoryType); + ASSERT_EQ (gMemoryTypeInformation[0].NumberOfPages, (UINT32)5); + ASSERT_EQ (gMemoryTypeInformation[1].Type, (UINT32)EfiRuntimeServicesCode); + ASSERT_EQ (gMemoryTypeInformation[1].NumberOfPages, (UINT32)10); + ASSERT_EQ (gMemoryTypeInformation[2].Type, (UINT32)EfiRuntimeServicesData); + ASSERT_EQ (gMemoryTypeInformation[2].NumberOfPages, (UINT32)15); + ASSERT_EQ (gMemoryTypeInformation[3].Type, (UINT32)EfiACPIReclaimMemory); + ASSERT_EQ (gMemoryTypeInformation[3].NumberOfPages, (UINT32)20); + ASSERT_EQ (gMemoryTypeInformation[4].Type, (UINT32)EfiACPIMemoryNVS); + ASSERT_EQ (gMemoryTypeInformation[4].NumberOfPages, (UINT32)25); + ASSERT_EQ (gMemoryTypeInformation[5].Type, (UINT32)EfiPalCode); + ASSERT_EQ (gMemoryTypeInformation[5].NumberOfPages, (UINT32)8); +} + +// +// Test: PopulateMemoryTypeInformation zeroes all pages when HOB is corrupted +// (i.e. it does not terminate in an EfiMaxMemoryType entry) +// +TEST_F (BaseMemoryBinLibTest, ZeroesAllPagesWhenHobIsCorrupted) { + EFI_STATUS Status; + UINT8 GuidHobBuffer[sizeof (EFI_HOB_GUID_TYPE) + sizeof (EFI_MEMORY_TYPE_INFORMATION) * 7]; + EFI_HOB_GUID_TYPE *GuidHob; + EFI_MEMORY_TYPE_INFORMATION *MemTypeInfo; + + ZeroMem (GuidHobBuffer, sizeof (GuidHobBuffer)); + GuidHob = (EFI_HOB_GUID_TYPE *)GuidHobBuffer; + GuidHob->Header.HobType = EFI_HOB_TYPE_GUID_EXTENSION; + GuidHob->Header.HobLength = sizeof (GuidHobBuffer); + CopyGuid (&GuidHob->Name, &gEfiMemoryTypeInformationGuid); + + // + // Populate every entry with a valid type and a non-zero page count, but + // deliberately omit the terminating EfiMaxMemoryType entry to corrupt the HOB. + // + MemTypeInfo = (EFI_MEMORY_TYPE_INFORMATION *)(GuidHob + 1); + MemTypeInfo[0].Type = EfiReservedMemoryType; + MemTypeInfo[0].NumberOfPages = 5; + MemTypeInfo[1].Type = EfiRuntimeServicesCode; + MemTypeInfo[1].NumberOfPages = 10; + MemTypeInfo[2].Type = EfiRuntimeServicesData; + MemTypeInfo[2].NumberOfPages = 15; + MemTypeInfo[3].Type = EfiACPIReclaimMemory; + MemTypeInfo[3].NumberOfPages = 20; + MemTypeInfo[4].Type = EfiACPIMemoryNVS; + MemTypeInfo[4].NumberOfPages = 25; + MemTypeInfo[5].Type = EfiPalCode; + MemTypeInfo[5].NumberOfPages = 8; + MemTypeInfo[6].Type = EfiBootServicesData; + MemTypeInfo[6].NumberOfPages = 30; + + EXPECT_CALL (HobLib, GetFirstGuidHob (&gEfiMemoryTypeInformationGuid)) + .WillOnce (Return ((VOID *)GuidHob)); + + Status = PopulateMemoryTypeInformation (gMemoryTypeInformation); + + ASSERT_EQ (Status, EFI_NOT_FOUND); + + // + // Regardless of the page counts present in the corrupted HOB, every entry + // should have been reset to zero pages. + // + for (UINTN Index = 0; gMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + ASSERT_EQ (gMemoryTypeInformation[Index].NumberOfPages, (UINT32)0); + } +} + +// +// Test: GetMemoryTypeInformationResourceHob returns NOT_FOUND when no resource HOB exists +// +TEST_F (BaseMemoryBinLibTest, GetMemoryTypeInformationResourceHobReturnsNotFoundWhenNoResourceHob) { + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + UINT8 HobListBuffer[sizeof (EFI_HOB_HANDOFF_INFO_TABLE) + sizeof (EFI_HOB_GENERIC_HEADER)]; + EFI_HOB_HANDOFF_INFO_TABLE *HandoffHob; + EFI_HOB_GENERIC_HEADER *EndOfHobList; + VOID *HobStart; + + ZeroMem (HobListBuffer, sizeof (HobListBuffer)); + + HandoffHob = (EFI_HOB_HANDOFF_INFO_TABLE *)HobListBuffer; + HandoffHob->Header.HobType = EFI_HOB_TYPE_HANDOFF; + HandoffHob->Header.HobLength = sizeof (EFI_HOB_HANDOFF_INFO_TABLE); + + EndOfHobList = (EFI_HOB_GENERIC_HEADER *)(HandoffHob + 1); + EndOfHobList->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST; + EndOfHobList->HobLength = sizeof (EFI_HOB_GENERIC_HEADER); + + HobStart = (VOID *)HobListBuffer; + + ResourceHob = GetMemoryTypeInformationResourceHob (&HobStart, gMemoryTypeInformation); + + ASSERT_EQ (ResourceHob, NULL); +} + +// +// Test: GetMemoryTypeInformationResourceHob finds matching resource HOB +// +TEST_F (BaseMemoryBinLibTest, GetMemoryTypeInformationResourceHobFindsMatchingHob) { + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + UINT8 HobListBuffer[sizeof (EFI_HOB_HANDOFF_INFO_TABLE) + 3 *sizeof (EFI_HOB_RESOURCE_DESCRIPTOR) + sizeof (EFI_HOB_GENERIC_HEADER)]; + EFI_HOB_HANDOFF_INFO_TABLE *HandoffHob; + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceDescriptor; + EFI_HOB_GENERIC_HEADER *EndOfHobList; + VOID *HobStart; + EFI_GUID OtherGuid = { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 } + }; + + ZeroMem (HobListBuffer, sizeof (HobListBuffer)); + + HandoffHob = (EFI_HOB_HANDOFF_INFO_TABLE *)HobListBuffer; + HandoffHob->Header.HobType = EFI_HOB_TYPE_HANDOFF; + HandoffHob->Header.HobLength = sizeof (EFI_HOB_HANDOFF_INFO_TABLE); + + ResourceDescriptor = (EFI_HOB_RESOURCE_DESCRIPTOR *)(HandoffHob + 1); + ResourceDescriptor->Header.HobType = EFI_HOB_TYPE_RESOURCE_DESCRIPTOR; + ResourceDescriptor->Header.HobLength = sizeof (EFI_HOB_RESOURCE_DESCRIPTOR); + ResourceDescriptor->ResourceType = EFI_RESOURCE_SYSTEM_MEMORY; + CopyGuid (&ResourceDescriptor->Owner, &OtherGuid); + ResourceDescriptor->PhysicalStart = 0x100000; + ResourceDescriptor->ResourceLength = 0x50000; + + ResourceDescriptor = (EFI_HOB_RESOURCE_DESCRIPTOR *)(ResourceDescriptor + 1); + ResourceDescriptor->Header.HobType = EFI_HOB_TYPE_RESOURCE_DESCRIPTOR; + ResourceDescriptor->Header.HobLength = sizeof (EFI_HOB_RESOURCE_DESCRIPTOR); + ResourceDescriptor->ResourceType = EFI_RESOURCE_SYSTEM_MEMORY; + CopyGuid (&ResourceDescriptor->Owner, &gEfiMemoryTypeInformationGuid); + ResourceDescriptor->PhysicalStart = 0x200000; + ResourceDescriptor->ResourceLength = 0x75000; + ResourceDescriptor->ResourceAttribute = EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED; + + ResourceDescriptor = (EFI_HOB_RESOURCE_DESCRIPTOR *)(ResourceDescriptor + 1); + ResourceDescriptor->Header.HobType = EFI_HOB_TYPE_RESOURCE_DESCRIPTOR; + ResourceDescriptor->Header.HobLength = sizeof (EFI_HOB_RESOURCE_DESCRIPTOR); + ResourceDescriptor->ResourceType = EFI_RESOURCE_SYSTEM_MEMORY; + CopyGuid (&ResourceDescriptor->Owner, &OtherGuid); + ResourceDescriptor->PhysicalStart = 0x300000; + ResourceDescriptor->ResourceLength = 0x50000; + + EndOfHobList = (EFI_HOB_GENERIC_HEADER *)(ResourceDescriptor + 1); + EndOfHobList->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST; + EndOfHobList->HobLength = sizeof (EFI_HOB_GENERIC_HEADER); + + HobStart = (VOID *)HobListBuffer; + + ResourceHob = GetMemoryTypeInformationResourceHob (&HobStart, gMemoryTypeInformation); + + ASSERT_EQ (ResourceHob->PhysicalStart, (EFI_PHYSICAL_ADDRESS)0x200000); + ASSERT_EQ (ResourceHob->ResourceLength, (UINT64)0x75000); +} + +// +// Test: GetMemoryTypeInformationResourceHob Fails When Multiple Matching HOBs Exist +// +TEST_F (BaseMemoryBinLibTest, GetMemoryTypeInformationResourceHobFailsWithMultipleMatchingHobs) { + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + UINT8 HobListBuffer[sizeof (EFI_HOB_HANDOFF_INFO_TABLE) + 2 * sizeof (EFI_HOB_RESOURCE_DESCRIPTOR) + sizeof (EFI_HOB_GENERIC_HEADER)]; + EFI_HOB_HANDOFF_INFO_TABLE *HandoffHob; + EFI_HOB_RESOURCE_DESCRIPTOR *FirstMatchingResource; + EFI_HOB_RESOURCE_DESCRIPTOR *SecondMatchingResource; + EFI_HOB_GENERIC_HEADER *EndOfHobList; + VOID *HobStart; + + ZeroMem (HobListBuffer, sizeof (HobListBuffer)); + + HandoffHob = (EFI_HOB_HANDOFF_INFO_TABLE *)HobListBuffer; + HandoffHob->Header.HobType = EFI_HOB_TYPE_HANDOFF; + HandoffHob->Header.HobLength = sizeof (EFI_HOB_HANDOFF_INFO_TABLE); + + // First matching resource HOB + FirstMatchingResource = (EFI_HOB_RESOURCE_DESCRIPTOR *)(HandoffHob + 1); + FirstMatchingResource->Header.HobType = EFI_HOB_TYPE_RESOURCE_DESCRIPTOR; + FirstMatchingResource->Header.HobLength = sizeof (EFI_HOB_RESOURCE_DESCRIPTOR); + FirstMatchingResource->ResourceType = EFI_RESOURCE_SYSTEM_MEMORY; + CopyGuid (&FirstMatchingResource->Owner, &gEfiMemoryTypeInformationGuid); + FirstMatchingResource->PhysicalStart = 0x100000; + FirstMatchingResource->ResourceLength = 0x50000; + FirstMatchingResource->ResourceAttribute = EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED; + + // Second matching resource HOB + SecondMatchingResource = (EFI_HOB_RESOURCE_DESCRIPTOR *)(FirstMatchingResource + 1); + SecondMatchingResource->Header.HobType = EFI_HOB_TYPE_RESOURCE_DESCRIPTOR; + SecondMatchingResource->Header.HobLength = sizeof (EFI_HOB_RESOURCE_DESCRIPTOR); + SecondMatchingResource->ResourceType = EFI_RESOURCE_SYSTEM_MEMORY; + CopyGuid (&SecondMatchingResource->Owner, &gEfiMemoryTypeInformationGuid); + SecondMatchingResource->PhysicalStart = 0x400000; + SecondMatchingResource->ResourceLength = 0x80000; + SecondMatchingResource->ResourceAttribute = EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED; + + EndOfHobList = (EFI_HOB_GENERIC_HEADER *)(SecondMatchingResource + 1); + EndOfHobList->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST; + EndOfHobList->HobLength = sizeof (EFI_HOB_GENERIC_HEADER); + + HobStart = (VOID *)HobListBuffer; + + ResourceHob = GetMemoryTypeInformationResourceHob (&HobStart, gMemoryTypeInformation); + + ASSERT_EQ (ResourceHob, NULL); +} + +int +main ( + int argc, + char *argv[] + ) +{ + testing::InitGoogleTest (&argc, argv); + return RUN_ALL_TESTS (); +} diff --git a/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTestHost.inf b/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTestHost.inf new file mode 100644 index 0000000000..d30482367f --- /dev/null +++ b/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTestHost.inf @@ -0,0 +1,33 @@ +## @file +# Unit tests for the Memory Bin feature +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = MemoryBinGoogleTest + FILE_GUID = 8A3C5C7B-2D4E-4F9A-B1C6-9E8F7D6C5B4A + MODULE_TYPE = HOST_APPLICATION + VERSION_STRING = 1.0 + +[Sources] + MemoryBinGoogleTest.cpp + ../MemoryBin.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + GoogleTestLib + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + HobLib + +[Guids] + gEfiMemoryTypeInformationGuid diff --git a/MdeModulePkg/Core/MemoryBins.md b/MdeModulePkg/Core/MemoryBins.md new file mode 100644 index 0000000000..dc75c8980c --- /dev/null +++ b/MdeModulePkg/Core/MemoryBins.md @@ -0,0 +1,276 @@ +# Memory Bin Feature + +## Table of Contents + +## Background + +The S4 sleep state is the lowest power state defined by the ACPI spec that supports system state restoration. In this +sleep state, the OS or platform FW is responsible for saving the running context in a persistent location. Upon +resumption from S4, this running context needs to be restored to memory and whatever device state is required. Platform +FW is responsible for bringing the system out of S4 and returning to the OS, which generally is the one to restore +system context. Because the OS needs to return the system memory to exactly the state it was before, it must use the +same memory regions as it did the previous boot. In order to do this, UEFI must have the same runtime memory footprint +it did on the previous boot. + +The edk2 memory bin feature is designed to support the S4 sleep state's requirements to keep UEFI's runtime memory +footprint identical between boots of the same FW. + +## Implementation + +### Overview + +There are 5 types of UEFI memory that persist into the OS timeframe: EfiReservedMemoryType, EfiRuntimeServicesCode, +EfiRuntimeServicesData, EfiACPIMemoryNVS, and generally EfiACPIReclaimMemory (the OS is allowed to reclaim this, but +typically does not). edk2 allows a platform to define a memory bin size for each of these memory types, as desired. +Technically, any type can be requested to use a memory bin, but the real use case is for the runtime types. + +The DXE and PEI (if configured) allocators will attempt to allocate all runtime types in the memory bin defined for +them. If the allocation size is too large, it will allocate it elsewhere. Runtime memory may also be allocated by +address outside the bin or reported as a Resource Descriptor HOB; neither of these will land in the memory bin. + +When the EFI_BOOT_SERVICES.GetMemoryMap() API is called, edk2 will examine the memory bin sizes defined by the +platform and create an EFI_MEMORY_MAP descriptor that is the bin size (assuming allocations are lower than the defined +size). This way, any fluctuations in runtime memory usage are covered by the defined bin size, i.e. the bin size is an +overallocation of runtime memory usage which allows for stability during S4 resumes. + +### MemoryBinLib + +MemoryBinLib is the phase agnostic memory bin logic. This logic is shared between DXE core and PEI core to have +standardized memory bin operation. It handles HOB processing and production (for PEI), memory bin setup in the various +forms, and memory statistics. + +### Boot Flow + +A platform opts into either PEI + DXE memory bins or DXE only (the original implementation). A platform may also define +where the memory bin region is. All of these paths are defined below. + +#### Platform Configuration + +A platform opts into the memory bin feature by producing the +[Memory Type Information HOB](https://github.com/tianocore/edk2/blob/HEAD/MdeModulePkg/Include/Guid/MemoryTypeInformation.h). +This HOB defines the type and size of each bin. If this HOB is not produced, no version of memory bins will be used and +runtime allocations will fall wherever the allocator finds space, likely breaking S4 resume. + +A platform can also define where the memory bins should be allocated by creating a resource descriptor HOB with the +owner set to gEfiMemoryTypeInformationGuid. This is recommended as it will create even more stability in the bins by +ensuring they live at a fixed address. + +With the Memory Type Information HOB produced and optionally the Resource Descriptor HOB produced, a platform will opt +into DXE only memory bins. However, it is recommended a platform opt into PEI memory bins as well for greater stability +as post-mem PEI often makes runtime memory allocations; without memory bins in PEI, these either have a high chance of +breaking S4 resume or must be allocated as non-runtime and relocated in DXE to a runtime bin. + +To opt into PEI memory bins a platform must, in any order: + +- Set `gEfiMdeModulePkgTokenSpaceGuid.PcdPeiMemoryBinsEnable` to `TRUE` in their DSC. +- Produce the Memory Type Information HOB in SEC or pre-mem PEI. +- Optionally produce the Resource Descriptor HOB owned by gEfiMemoryTypeInformationGuid in SEC or pre-mem PEI. This must + not be produced post-mem or DXE will ignore the PEI memory bins because of conflicting Resource Descriptor HOBs. + +#### PEI Memory Bins + +##### PEI Setup + +PEI memory bins are enabled in post-mem PEI in order to have memory available for the allocation of the bins. If a +platform allocates any runtime memory before memory is installed, it will not land in the bin and will jeopardize S4 +resume stability. The PEI memory bin feature is only applicable to the PEI_SERVICES.AllocatePages() and +PEI_SERVICES.FreePages() APIs. PEI_SERVICES.AllocatePool() does not have memory types associated with it and per the +PI spec DXE can ignore the EFI_HOB_MEMORY_POOL HOBs this API produces. I.e., PEI pool memory does not persist into DXE +and so therefore cannot persist into the OS runtime and affect S4 stability. + +When permanent memory is discovered, PEI core is relaunched to begin the post-mem PEI phase. When memory services +are initialized post-mem, PEI core will check for `PcdPeiMemoryBinsEnable`, which is the opt in +mechanism to PEI memory bins. If the PCD is not `FALSE`, the memory bin flow will try again in DXE. + +PEI core will next look for the Memory Type Information HOB to get bin types and sizes. If this is found, PEI memory +bins will be enabled. + +The final piece of configuration PEI core looks for is a Resource Descriptor HOB owned by gEfiMemoryTypeInformationGuid. +If one and only one of these HOBs is discovered, PEI core will use this range for the memory bins (if it is large +enough). + +If the Resource Descriptor HOB is not present, PEI core will allocate the memory for the memory bins as one +large contiguous chunk and then split it up amongst the bins. It will then create a Resource Descriptor HOB owned by +gEfiMemoryTypeInformationGuid to tell DXE core where the PEI memory bins are located. + +Finally, PEI core will update the PHIT free memory region to exclude the memory bin region. + +> **Note:** PEI must be very careful in its usage of global writeable variables. Usage of these pre-mem or if PEI Core +> has not been shadowed to memory will generally result in page faults, as flash is write protected. As a result, this +> design does not rely on any writeable global variables for PEI (but retains them in DXE). Instead, the stack based +> PEI_CORE_INSTANCE is given pointers to the relevant structures which are allocated in post-mem PEI in permanent +> memory. This is done to avoid a HOB lookup for every PEI memory allocation while still avoiding global variables. + +##### PEI Operation + +When PEI_SERVICES.AllocatePages() is called, PEI core will attempt to allocate the request in the memory bin, if +defined. If the request fails, PEI core will fall back to its standard allocation mechanism: attempt to allocate from +the PHIT free memory, if there is not enough space, look for a free memory memory allocation HOB. + +When PEI_SERVICES.FreePages() is called, PEI core will free the pages as normal. + +As with allocating from the PHIT HOB, PEI core will only ever walk down the memory range defined in a given bin, that is +new allocations are given the requested size down from the top of the bin and freeing pages does not increase the +available range in the bin. This is done to keep the PEI allocator simple and because most runtime allocations are +expected in DXE. + +PEI core will mark all of the Memory Allocation HOBs for bin types its allocator produces with +gEfiMemoryTypeInformationGuid. This is done so that DXE can use the Memory Allocation HOBs to build bin statistics, +e.g. which allocations landed within a bin and which landed outside of a bin. Updating the Name field of the Memory +Allocation HOB allows DXE Core to distinguish between allocations that PEI Core made and are subject to bin rules and +those that were before the PEI bins were setup; platforms may produce Memory Allocation HOBs to specify static runtime +regions. These should not be included in the bin logic. If PEI Core is not configured to use memory bins, it will not +mark its allocator created Memory Allocation HOBs with the PEI Core GUID. DXE will then ignore all pre-DXE memory +allocations and how they fall into the bins or not. + +#### DXE Memory Bins + +##### DXE Setup + +DXE core is agnostic to whether PEI core set up memory bins or not, it will simply find the relevant HOBs and operate +on them if present, regardless of producer. + +DXE memory bins apply to the EFI_BOOT_SERVICES.AllocatePages() and EFI_BOOT_SERVICES.FreePages() APIs. The Pool APIs +will respect the memory bins, but only because they use the Page APIs under the hood. + +When DXE core initializes memory services, it will look for the Memory Type Information HOB. If this is not present, +bins will not be initialized. It will then look for a Resource Descriptor HOB with owner gEfiMemoryTypeInformationGuid. +If this HOB is present, the DXE memory bins will be at this location. If it is not present, DXE will allocate memory +bins. + +If the Resource Descriptor HOB was present, DXE core will process through the Memory Allocation HOBs that have the +gEfiMemoryTypeInformationGuid to discover if any bin types have been allocated pre-DXE and whether they fall in or out +of the defined bin range. DXE core will seed its memory statistics with this information. See #BDS-Setup for information +on how the memory statistics are used. + +##### DXE Operation + +When EFI_BOOT_SERVICES.AllocatePages() is called, DXE core will attempt to allocate the memory in the defined bin +region. If the allocation succeeds, DXE core will update the memory statistics to indicate the requested number of pages +landed in the bin. If the allocation failed, DXE core will fall back to its standard pattern, attempting to allocate +outside of the bin. It will also update the memory statistics to indicate that the requested number of pages landed +outside of the bin. + +When EFI_BOOT_SERVICES.FreePages() is called, DXE core will free the pages and update the memory statistics to indicate +that the number of pages either in or out of the bin are not being used. + +The DXE allocator is much smarter than the PEI allocator and does account for bin pages freed back and allows them to +be allocated again. + +DXE core will publish the +[gMemoryTypeInformationGuid](https://github.com/tianocore/edk2/blob/HEAD/MdeModulePkg/Include/Guid/MemoryTypeInformation.h#L26) +config table to publish the memory statistics for BDS to consume to +advise a platform on the correct memory bin sizes. See [BDS Advertisement](#bds-advertisement) for more details. + +When EFI_BOOT_SERVICES.GetMemoryMap() is called, DXE core will create a single EFI_MEMORY_DESCRIPTOR for each memory +bin. + +#### BDS Advertisement + +[UefiBootManagerLib](https://github.com/tianocore/edk2/blob/HEAD/MdeModulePkg/Library/UefiBootManagerLib) has a +mechanism to advise a platform on the ideal bin size and location for S4 stability based on the current boot memory +statistics that DXE has collected. + +Just before launching a given boot option, UefiBootManagerLib (generally called BDS for brevity below) consumes the +`gMemoryTypeInformationGuid` config table that DXE core has produced. It reads the currently used bin pages and +compares them against the last used bin pages, using a heuristic to calculate the ideal number of pages for each memory +bin. It then writes the gEfiMemoryTypeInformation.MemoryTypeInformation variable to give the platform each recommended +memory bin size for S4 stability. BDS will optionally reboot the system if the bin size has changed, depending on +[PcdResetOnMemoryTypeInformationChange](https://github.com/tianocore/edk2/blob/HEAD/MdeModulePkg/MdeModulePkg.dec#L1930). + +##### Platform Adjustments + +Prior to post-mem PEI, it is recommended that the platform consume the gEfiMemoryTypeInformation.MemoryTypeInformation +variable if present. Then, the platform can use the BDS recommended values to create the Memory Type Information HOB. + +>**Note:** The recommended path has a dependency on variable reads being available in pre-mem PEI or SEC. Without +> this, the BDS advertisement cannot be acted upon. PEI memory bins may still be used without variable reads in +> pre-mem PEI/SEC, but the greatest chance of S4 resume success will be following the recommended path. + +#### End-to-End Diagrams + +```mermaid +flowchart TD + Start([Boot Start]) --> SecPreMemPEI[SEC/Pre-Memory PEI Phase] + + SecPreMemPEI --> CheckPlatform{Platform Configuration} + + CheckPlatform -->|Produces Memory Type Info HOB| MemTypeHOB[Memory Type Information HOB Created] + + MemTypeHOB --> CheckResourceHOB{Optional: Resource Descriptor HOB?} + + CheckResourceHOB -->|Yes| ResourceHOB[Resource Descriptor HOB
gEfiMemoryTypeInformationGuid] + CheckResourceHOB -->|No| NoResourceHOB[No Resource Descriptor HOB] + + ResourceHOB --> CheckPEIPath{PEI?} + NoResourceHOB --> CheckPEIPath + + CheckPEIPath -->|Yes| MemDiscovered + CheckPEIPath -->|No PEI| DXEOnly[**DXE Only Path**] + + %% PEI + DXE Path + MemDiscovered --> PEICoreRelaunch[PEI Core Relaunched Post-Memory] + PEICoreRelaunch --> CheckPcd{PcdPeiMemoryBinsEnable TRUE?} + + CheckPcd -->|No| DXEOnly[DXE only bins] + CheckPcd -->|Yes| InitPEIBins[Initialize PEI Memory Bins] + + InitPEIBins --> CheckPEIResourceHOB{Resource Descriptor HOB Present?} + + CheckPEIResourceHOB -->|Yes| UsePEIResource[Use Resource HOB Range for Bins] + CheckPEIResourceHOB -->|No| AllocatePEI[Allocate Contiguous Memory for Bins] + + AllocatePEI --> CreatePEIResourceHOB[Create Resource Descriptor HOB
for DXE] + UsePEIResource --> UpdatePHIT1[Update PHIT to Exclude Bin Region] + CreatePEIResourceHOB --> UpdatePHIT1 + + UpdatePHIT1 --> PEIOperation[PEI Operation:
AllocatePages attempts bin first,
falls back to PHIT/free HOBs] + + PEIOperation --> TransitionToDXE[Transition to DXE] + DXEOnly --> TransitionToDXE + + %% DXE Phase Common + TransitionToDXE --> DXEInit[DXE Core Memory Services Init] + + DXEInit --> CheckDXEMemTypeHOB{Memory Type Info HOB Present?} + + CheckDXEMemTypeHOB -->|No| NoBins[No Memory Bins Initialized] + CheckDXEMemTypeHOB -->|Yes| CheckDXEResourceHOB{Resource Descriptor HOB Present?} + + CheckDXEResourceHOB -->|Yes| ProcessMemAlloc[Process Memory Allocation HOBs
Seed Statistics] + CheckDXEResourceHOB -->|No| AllocateDXEBins[Allocate DXE Memory Bins] + + ProcessMemAlloc --> UseDXEResource[Use Resource HOB Range for DXE Bins] + AllocateDXEBins --> DXEOperation + UseDXEResource --> DXEOperation + + DXEOperation[DXE Operation:
AllocatePages/FreePages use bins
Update statistics] + + DXEOperation --> PublishConfig[Publish Config Table] + NoBins --> BDSPhase + + PublishConfig --> BDSPhase[BDS Phase] + + BDSPhase --> ConsumeStats[BDS Consumes Config Table] + ConsumeStats --> CalculateIdeal[Calculate Ideal Bin Size] + CalculateIdeal --> WriteVariable[Write MemoryTypeInformation Variable] + + WriteVariable --> CheckBinChange{Bin Size Changed?} + + CheckBinChange -->|Yes| CheckRebootPCD{PcdResetOnMemoryTypeInformationChange?} + CheckBinChange -->|No| LaunchBootOption + + CheckRebootPCD -->|TRUE| Reboot[System Reboot] + CheckRebootPCD -->|FALSE| LaunchBootOption[Launch Boot Option] + + Reboot --> Start + LaunchBootOption --> GetMemoryMap[GetMemoryMap Called] + GetMemoryMap --> CreateDescriptor[Create EFI_MEMORY_DESCRIPTOR
for Each Bin] + CreateDescriptor --> OSRuntime[OS Runtime] + + style ResourceHOB fill:#d4edda + style NoResourceHOB fill:#f8d7da + style DXEOnly fill:#5c4a1f,color:#fff + style ResourceHOB fill:#1f4a2f,color:#fff + style NoResourceHOB fill:#5a2a2a,color:#fff +``` diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc index c7ea0f9e12..4f04a6dd79 100644 --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc @@ -72,6 +72,11 @@ UefiBootServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf } + MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTestHost.inf { + + HobLib|MdePkg/Test/Mock/Library/GoogleTest/MockHobLib/MockHobLib.inf + } + # # Build HOST_APPLICATION Libraries # From efc3d6a41742dd710f7df861e56f29bbc2beac6e Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Thu, 29 Jan 2026 10:12:40 -0800 Subject: [PATCH 075/406] OvmfPkg: PlatformPei: Add PEI Memory Bin Support This commit enables PEI memory bins in OVMF IA32X64 and OVMF X64. OVMF supports many different boot flows. The variable PEIM is only dispatched when SMM_REQUIRE is TRUE. The early variable store is not set up otherwise. The PlatformPei PEIM requires the variable PPI be available before creating the gEfiMemoryTypeInformationGuid HOB, in order to use the BDS advertised bin sizes. If SMM_REQUIRE is FALSE, it just produces the HOB. PEI Core requires that the gEfiMemoryTypeInformationGuid HOB be produced pre-mem PEI in order to set up the memory bins at the start of post-mem PEI. PlatformPei is also the PEIM that installs permanent memory. As such, a depex on the variable PPI cannot be used, to support the different flows. So, this commit splits the PlatformPei initialization flow into two phases. The first phase completes until memory bin initialization. If that returns success (either because SMM_REQUIRE is FALSE or because the variable PPI was already installed), phase 2 init is completed immediately and no callback is created. If that fails, a callback is created for the variable read PPI and phase 2 initialization is completed after that. Signed-off-by: Oliver Smith-Denny --- OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/PlatformPei/MemTypeInfo.c | 31 +++++++++-- OvmfPkg/PlatformPei/Platform.c | 86 +++++++++++++++++++------------ OvmfPkg/PlatformPei/Platform.h | 8 ++- 5 files changed, 89 insertions(+), 38 deletions(-) diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 0e11c5fba9..aacf6b6f9b 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -497,6 +497,7 @@ gUefiOvmfPkgTokenSpaceGuid.PcdSecureBootSupported|TRUE gEfiMdeModulePkgTokenSpaceGuid.PcdRequireSelfSignedPk|FALSE !endif + gEfiMdeModulePkgTokenSpaceGuid.PcdPeiMemoryBinsEnable|TRUE [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1 diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 2780fe4439..d4b3cff7fd 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -577,6 +577,7 @@ gUefiOvmfPkgTokenSpaceGuid.PcdSecureBootSupported|TRUE gEfiMdeModulePkgTokenSpaceGuid.PcdRequireSelfSignedPk|FALSE !endif + gEfiMdeModulePkgTokenSpaceGuid.PcdPeiMemoryBinsEnable|TRUE [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1 diff --git a/OvmfPkg/PlatformPei/MemTypeInfo.c b/OvmfPkg/PlatformPei/MemTypeInfo.c index dfb1bc37a9..e0e681e7c1 100644 --- a/OvmfPkg/PlatformPei/MemTypeInfo.c +++ b/OvmfPkg/PlatformPei/MemTypeInfo.c @@ -183,10 +183,15 @@ OnReadOnlyVariable2Available ( IN VOID *Ppi ) { + EFI_HOB_GUID_TYPE *GuidHob; + DEBUG ((DEBUG_VERBOSE, "%a\n", __func__)); RefreshMemTypeInfo (Ppi); BuildMemTypeInfoHob (); + GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid); + CompleteInitialization ((EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob), (CONST EFI_PEI_SERVICES **)PeiServices); + return EFI_SUCCESS; } @@ -201,12 +206,13 @@ STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mReadOnlyVariable2Notify = { OnReadOnlyVariable2Available // Notify }; -VOID +EFI_STATUS MemTypeInfoInitialization ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { - EFI_STATUS Status; + EFI_STATUS Status; + EFI_PEI_READ_ONLY_VARIABLE2_PPI *ReadOnlyVariable2; if (!PlatformInfoHob->SmmSmramRequire) { // @@ -214,7 +220,23 @@ MemTypeInfoInitialization ( // the default memory type information HOB right away. // BuildMemTypeInfoHob (); - return; + return EFI_SUCCESS; + } + + Status = PeiServicesLocatePpi ( + &gEfiPeiReadOnlyVariable2PpiGuid, + 0, + NULL, + (VOID **)&ReadOnlyVariable2 + ); + + if (!EFI_ERROR (Status)) { + // + // EFI_PEI_READ_ONLY_VARIABLE2_PPI is already available; use it now. + // + RefreshMemTypeInfo (ReadOnlyVariable2); + BuildMemTypeInfoHob (); + return EFI_SUCCESS; } Status = PeiServicesNotifyPpi (&mReadOnlyVariable2Notify); @@ -228,4 +250,7 @@ MemTypeInfoInitialization ( ASSERT (FALSE); CpuDeadLoop (); } + + // Return that we're not ready yet so that the dispatcher can dispatch the variable PEIM first + return EFI_NOT_READY; } diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 1768a24037..c2085cdd40 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -294,6 +294,50 @@ BuildPlatformInfoHob ( return (EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob); } +VOID +CompleteInitialization ( + IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + PublishPeiMemory (PlatformInfoHob); + + PlatformQemuUc32BaseInitialization (PlatformInfoHob); + + InitializeRamRegions (PlatformInfoHob); + + if (PlatformInfoHob->BootMode != BOOT_ON_S3_RESUME) { + PeiFvInitialization (PlatformInfoHob); + MemMapInitialization (PlatformInfoHob); + NoexecDxeInitialization (PlatformInfoHob); + } + + InstallClearCacheCallback (); + AmdSevInitialize (PlatformInfoHob); + if (PlatformInfoHob->HostBridgeDevId == 0xffff) { + MiscInitializationForMicrovm (PlatformInfoHob); + } else { + MiscInitialization (PlatformInfoHob); + PlatformIdInitialization (PeiServices); + } + + IntelTdxInitialize (); + InstallFeatureControlCallback (PlatformInfoHob); + if (PlatformInfoHob->SmmSmramRequire) { + RelocateSmBase (); + } + + // + // Performed after CoCo (SEV/TDX) initialization to allow the memory + // used to be validated before being used. + // + if (PlatformInfoHob->BootMode != BOOT_ON_S3_RESUME) { + if (!PlatformInfoHob->SmmSmramRequire) { + ReserveEmuVariableNvStore (); + } + } +} + /** Perform Platform PEI initialization. @@ -357,43 +401,17 @@ InitializePlatform ( Q35SmramAtDefaultSmbaseInitialization (PlatformInfoHob); } - PublishPeiMemory (PlatformInfoHob); - - PlatformQemuUc32BaseInitialization (PlatformInfoHob); - - InitializeRamRegions (PlatformInfoHob); - if (PlatformInfoHob->BootMode != BOOT_ON_S3_RESUME) { - PeiFvInitialization (PlatformInfoHob); - MemTypeInfoInitialization (PlatformInfoHob); - MemMapInitialization (PlatformInfoHob); - NoexecDxeInitialization (PlatformInfoHob); - } - - InstallClearCacheCallback (); - AmdSevInitialize (PlatformInfoHob); - if (PlatformInfoHob->HostBridgeDevId == 0xffff) { - MiscInitializationForMicrovm (PlatformInfoHob); - } else { - MiscInitialization (PlatformInfoHob); - PlatformIdInitialization (PeiServices); - } - - IntelTdxInitialize (); - InstallFeatureControlCallback (PlatformInfoHob); - if (PlatformInfoHob->SmmSmramRequire) { - RelocateSmBase (); - } - - // - // Performed after CoCo (SEV/TDX) initialization to allow the memory - // used to be validated before being used. - // - if (PlatformInfoHob->BootMode != BOOT_ON_S3_RESUME) { - if (!PlatformInfoHob->SmmSmramRequire) { - ReserveEmuVariableNvStore (); + Status = MemTypeInfoInitialization (PlatformInfoHob); + if (EFI_ERROR (Status)) { + // Failing here is okay, it just means that the variable read PPI wasn't found, so + // we need to return EFI_SUCCESS here and let the dispatcher dispatch the variable PEIM first + // and then we'll get called back to finish initialization. + return EFI_SUCCESS; } } + CompleteInitialization (PlatformInfoHob, PeiServices); + return EFI_SUCCESS; } diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h index 5ad285ffca..b2967ea933 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -62,7 +62,7 @@ PeiFvInitialization ( IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); -VOID +EFI_STATUS MemTypeInfoInitialization ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); @@ -109,3 +109,9 @@ VOID SevInitializeRam ( VOID ); + +VOID +CompleteInitialization ( + IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob, + IN CONST EFI_PEI_SERVICES **PeiServices + ); From a721a79555c4e9c9fe0a821a985a2d2972e34fad Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Thu, 29 Jan 2026 10:14:46 -0800 Subject: [PATCH 076/406] ArmVirtPkg: MemoryInitPeim: Add PEI Memory Bin Support This commit adds memory bin support to ArmVirtQemu. ArmVirtQemu does not have a PEI variable driver, so it does not attempt to update the bin size or location. The bin sizes are also updated because they were very out of date. Signed-off-by: Oliver Smith-Denny --- ArmVirtPkg/ArmVirt.dsc.inc | 6 +++--- ArmVirtPkg/ArmVirtQemu.dsc | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 240d3eda79..f63181beab 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -378,8 +378,8 @@ DEFINE FD_SIZE_IN_MB = 3 # (the memory used, and the free memory that was prereserved # but not used). # - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0 - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|4 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0x3C gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0 !if $(SECURE_BOOT_ENABLE) == TRUE gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|600 @@ -387,7 +387,7 @@ DEFINE FD_SIZE_IN_MB = 3 gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|1500 !else gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|300 - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|150 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|0x424 gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|1000 !endif gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|12000 diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index fc197cc208..e9eeeafce6 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -147,6 +147,7 @@ gUefiOvmfPkgTokenSpaceGuid.PcdQemuVarsRequire|TRUE gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache|FALSE !endif + gEfiMdeModulePkgTokenSpaceGuid.PcdPeiMemoryBinsEnable|TRUE [PcdsFixedAtBuild.common] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress|0x00000000 From d984c9b63c46784485826a1d9636d46af019d22b Mon Sep 17 00:00:00 2001 From: Qihang Gao Date: Mon, 22 Jun 2026 16:21:34 +0800 Subject: [PATCH 077/406] SecurityPkg/SecureBootConfigDxe: Remove unused variable mImageType Remove mImageType as it is assigned but never used. The definition of struct IMAGE_TYPE is also removed. Signed-off-by: Qihang Gao --- .../SecureBootConfigDxe/SecureBootConfigImpl.c | 7 ++----- .../SecureBootConfigDxe/SecureBootConfigImpl.h | 5 ----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c index f93967f0f2..cde9d4dce6 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c @@ -83,9 +83,8 @@ HASH_TABLE mHash[] = { // UINT32 mPeCoffHeaderOffset = 0; WIN_CERTIFICATE *mCertificate = NULL; -IMAGE_TYPE mImageType; -UINT8 *mImageBase = NULL; -UINTN mImageSize = 0; +UINT8 *mImageBase = NULL; +UINTN mImageSize = 0; UINT8 mImageDigest[MAX_DIGEST_SIZE]; UINTN mImageDigestSize; EFI_GUID mCertType; @@ -1803,7 +1802,6 @@ LoadPeImage ( // // 32-bits Architecture // - mImageType = ImageType_IA32; mSecDataDir = (EFI_IMAGE_SECURITY_DATA_DIRECTORY *)&(NtHeader32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]); } else if ( (NtHeader32->FileHeader.Machine == EFI_IMAGE_MACHINE_IA64) || (NtHeader32->FileHeader.Machine == EFI_IMAGE_MACHINE_X64) @@ -1812,7 +1810,6 @@ LoadPeImage ( // // 64-bits Architecture // - mImageType = ImageType_X64; NtHeader64 = (EFI_IMAGE_NT_HEADERS64 *)(mImageBase + mPeCoffHeaderOffset); mSecDataDir = (EFI_IMAGE_SECURITY_DATA_DIRECTORY *)&(NtHeader64->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]); } else { diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.h b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.h index 54a7b72aec..472e8fe37f 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.h +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.h @@ -159,11 +159,6 @@ typedef struct { UINT32 SizeOfCert; // size of certificate appended } EFI_IMAGE_SECURITY_DATA_DIRECTORY; -typedef enum { - ImageType_IA32, - ImageType_X64 -} IMAGE_TYPE; - /// /// HII specific Vendor Device Path definition. /// From 08258192d44753d79ef15494ab4d7cf671d043ec Mon Sep 17 00:00:00 2001 From: Qihang Gao Date: Mon, 22 Jun 2026 17:42:37 +0800 Subject: [PATCH 078/406] SecurityPkg: Add support for LOONGARCH64 and RISCV64 when parsing PE image If the machine type of PE/COFF image is LOONGARCH64 or RISCV64, the LoadPeImage() should return EFI_SUCCESS. This patch is intended as a preparation for future use of LOONGARCH64 or RISCV64 PE image file. Signed-off-by: Qihang Gao --- .../SecureBootConfigDxe/SecureBootConfigImpl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c index cde9d4dce6..1b3b51eea7 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c @@ -1805,6 +1805,8 @@ LoadPeImage ( mSecDataDir = (EFI_IMAGE_SECURITY_DATA_DIRECTORY *)&(NtHeader32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]); } else if ( (NtHeader32->FileHeader.Machine == EFI_IMAGE_MACHINE_IA64) || (NtHeader32->FileHeader.Machine == EFI_IMAGE_MACHINE_X64) + || (NtHeader32->FileHeader.Machine == EFI_IMAGE_MACHINE_LOONGARCH64) + || (NtHeader32->FileHeader.Machine == EFI_IMAGE_MACHINE_RISCV64) || (NtHeader32->FileHeader.Machine == EFI_IMAGE_MACHINE_AARCH64)) { // From 56cad12011eaca88ccd13fd86b1521c6bc2fa25e Mon Sep 17 00:00:00 2001 From: Vignesh G Date: Wed, 17 Jun 2026 13:22:43 +0530 Subject: [PATCH 079/406] SecurityPkg: Add sanity check for File and FileBuffer inputs Ensure that either File or FileBuffer is provided before proceeding with security verification. If both are NULL, return EFI_INVALID_PARAMETER. This prevents verification from running without a valid input buffer and aligns with the intended design, where File is optional and FileBuffer alone is sufficient. Signed-off-by: Vignesh G --- .../DxeImageVerificationLib/DxeImageVerificationLib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c index 46d39cd96f..f928700008 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -1705,9 +1705,13 @@ DxeImageVerificationHandler ( IsFoundInDatabase = FALSE; // - // Sanity check + // Sanity check: + // Ensure that either File or FileBuffer is provided. + // Return EFI_INVALID_PARAMETER if both are NULL. + // This prevents security verification from proceeding + // when no valid input buffer is available. // - if (File == NULL) { + if ((File == NULL) && (FileBuffer == NULL)) { return EFI_INVALID_PARAMETER; } From c4130fc591f2a85beb92c0ac3135029ec9df9538 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Thu, 18 Jun 2026 13:29:19 -0400 Subject: [PATCH 080/406] .pytool/EccCheck: Report package-relative paths in ECC findings The EccCheck plugin currently reports incorrect paths that are confusing to a user, such as: ``` *file: C:\src\edk2\Build\.pytool\Plugin\EccCheck\MdePkg\Include\ Protocol\AuthenticationInfo.h ``` This is because the EccCheck plugin does not scan the package in place. Before running ECC, it copies the package into `Build/.pytool/Plugin/EccCheck/` and points the ECC tool at that temporary location. As a result, the paths ECC records in its report refer to the temporary copy rather than the file in the actual source tree. This affected two fields that are printed: - The "file:" line is taken from ECC's File column (`row[3]`), which holds the absolute path of the scanned file. It always pointed into the temporary scan directory. - The descriptive message (`row[5]`) paths were prefixed with `Build/.pytool/Plugin/EccCheck/`. The temporary path is an internal build detail and prevents resolution against the actual source file. This change translates the reported paths back to the package-relative path before printing. Signed-off-by: Michael Kubacki --- .pytool/Plugin/EccCheck/EccCheck.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.pytool/Plugin/EccCheck/EccCheck.py b/.pytool/Plugin/EccCheck/EccCheck.py index 57f07e957e..99ed536149 100644 --- a/.pytool/Plugin/EccCheck/EccCheck.py +++ b/.pytool/Plugin/EccCheck/EccCheck.py @@ -34,6 +34,10 @@ class EccCheck(ICiBuildPlugin): LineScopePattern = (r'@@ -\d*\,*\d* \+\d*\,*\d* @@.*') LineNumRange = re.compile(r'@@ -\d*\,*\d* \+(\d*)\,*(\d*) @@.*') + # Sub-directory of the workspace where the package under review is copied + # and scanned by ECC. + BuildTempSubDir = os.path.join('Build', '.pytool', 'Plugin', 'EccCheck') + def GetTestName(self, packagename: str, environment: VarDict) -> tuple: """ Provide the testcase name and classname for use in reporting testclassname: a descriptive string for the testcase can include whitespace @@ -77,7 +81,7 @@ class EccCheck(ICiBuildPlugin): return 0 # Create temp directory - temp_path = os.path.join(workspace_path, 'Build', '.pytool', 'Plugin', 'EccCheck') + temp_path = os.path.join(workspace_path, self.BuildTempSubDir) try: # Delete temp directory if os.path.exists(temp_path): @@ -327,6 +331,8 @@ class EccCheck(ICiBuildPlugin): for i in ecc_diff_range[modify_file]: line_no = int(row[4]) if i[0] <= line_no <= i[1] and row[1] not in ignore_error_code: + row[3] = modify_file + row[5] = row[5].replace(self.BuildTempSubDir + os.sep, '') row[0] = '\nEFI coding style error' row[1] = 'Error code: ' + row[1] row[3] = 'file: ' + row[3] From b3f57868cea5213772328f1188e6fc2311b2dc28 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 3 Feb 2026 17:58:33 -0500 Subject: [PATCH 081/406] NetworkPkg/UefiPxeBcDxe: Initialize IPV4 token in IPV4 branch EfiPxeBcStart() in PxeBcImpl.c has conditional code branches for IPV4 and IPV6. - IPV4 branch should use EFI_IP4_COMPLETION_TOKEN which is Private->IcmpToken. - IPV6 branch should use EFI_IP6_COMPLETION_TOKEN which is Private->Icmp6Token. Right now, the IPv4 branch incorrectly initializes Private->Icmp6Token to EFI_NOT_READY. That is changed to Private->IcmpToken. Signed-off-by: Michael Kubacki --- NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c index 4e37944b43..ffbe345064 100644 --- a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c @@ -193,14 +193,14 @@ EfiPxeBcStart ( // // Create event and set status for token to capture ICMP error message. // - Private->Icmp6Token.Status = EFI_NOT_READY; - Status = gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - PxeBcIcmpErrorUpdate, - Private, - &Private->IcmpToken.Event - ); + Private->IcmpToken.Status = EFI_NOT_READY; + Status = gBS->CreateEvent ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + PxeBcIcmpErrorUpdate, + Private, + &Private->IcmpToken.Event + ); if (EFI_ERROR (Status)) { goto ON_ERROR; } From 6d127c21406c89b50f6c7345f02c2b958660e231 Mon Sep 17 00:00:00 2001 From: Phineas Su Date: Sun, 14 Jun 2026 16:13:01 +0000 Subject: [PATCH 082/406] ManageabilityPkg: Fix IPMI vulnerabilities and memory leak Fix vulnerabilities and a memory leak in the IPMI Blob Transfer driver: - Prevent integer underflow and OOB read by validating response size before accessing CompletionCode, OEN, and CRC. - Prevent buffer overflow by ensuring BMC response size does not exceed the caller's buffer capacity, avoiding potential memory overwriting. - Fix memory leak by freeing IpmiResponseData and IpmiSendData. Additionally, fix unit test failures caused by the changes and pre-existing bugs: - Allocate a safe fixed size (70 bytes) for IpmiResponseData in IpmiBlobTransferSendIpmi to prevent heap overflow if the BMC returns more data than expected. Add validation to check if returned size exceeds this allocation. - Modify IpmiBlobTransferStat and IpmiBlobTransferSessionStat to only copy MetaDataLen bytes of metadata instead of always copying the max size (64 bytes), preventing buffer overflow when caller allocates a smaller buffer. - Add missing ASSERT(FALSE) in IpmiBlobTransferStat parameter validation. - Fix IpmiBlobTransferWriteMeta parameter validation to allow 0-length writes (Data can be NULL when WriteLength is 0), which was causing test failure. - Fix syntax errors in unit tests where arrays were assigned values after declaration using brace-enclosed lists. - Fix sizeof misuse on macros representing size values in unit tests, which caused too small allocations and buffer overflows in mock setups. - Fix queue order in OpenValidResponse test to match the actual call order (GetCount, Enumerate, Open) and free all mock buffers. - Remove unnecessary MockIpmiSubmitCommand calls from invalid buffer tests to prevent mock queue leaks to subsequent tests. - Fix memory leaks of ExpectedMetadata in unit tests by changing them to static arrays. Signed-off-by: Phineas Su --- .../IpmiBlobTransferDxe/IpmiBlobTransferDxe.c | 75 +++- .../UnitTest/IpmiBlobTransferTestUnitTests.c | 327 ++++++++++++------ 2 files changed, 288 insertions(+), 114 deletions(-) diff --git a/ManageabilityPkg/Universal/IpmiBlobTransferDxe/IpmiBlobTransferDxe.c b/ManageabilityPkg/Universal/IpmiBlobTransferDxe/IpmiBlobTransferDxe.c index 62d9d92dd6..02305e30e8 100644 --- a/ManageabilityPkg/Universal/IpmiBlobTransferDxe/IpmiBlobTransferDxe.c +++ b/ManageabilityPkg/Universal/IpmiBlobTransferDxe/IpmiBlobTransferDxe.c @@ -91,6 +91,7 @@ CalculateCrc16Ccitt ( not used. @retval EFI_SUCCESS Successfully sends blob data. + @retval EFI_BUFFER_TOO_SMALL Response buffer too small to hold the response. @retval EFI_OUT_OF_RESOURCES Memory allocation fails. @retval EFI_PROTOCOL_ERROR Communication errors. @retval EFI_CRC_ERROR Data integrity checks fail. @@ -115,6 +116,7 @@ IpmiBlobTransferSendIpmi ( UINT8 *IpmiResponseData; UINT8 *ModifiedResponseData; UINT32 IpmiResponseDataSize; + UINT32 AllocatedResponseSize; IPMI_BLOB_TRANSFER_HEADER Header; if (((SendDataSize > 0) && (SendData == NULL)) || ((ResponseData == NULL) && (((ResponseDataSize != NULL) && (*ResponseDataSize > 0))))) { @@ -168,16 +170,12 @@ IpmiBlobTransferSendIpmi ( DEBUG ((BLOB_TRANSFER_DEBUG, "\n")); DEBUG_CODE_END (); - IpmiResponseDataSize = PROTOCOL_RESPONSE_OVERHEAD; - // - // If expecting data to be returned, we have to also account for the 16 bit CRC - // - if ((ResponseDataSize != NULL) && (*ResponseDataSize > 0)) { - IpmiResponseDataSize += (*ResponseDataSize + sizeof (Crc)); - } + AllocatedResponseSize = PROTOCOL_RESPONSE_OVERHEAD + sizeof (Crc) + BLOB_MAX_DATA_PER_PACKET; + IpmiResponseDataSize = AllocatedResponseSize; IpmiResponseData = AllocateZeroPool (IpmiResponseDataSize); if (IpmiResponseData == NULL) { + FreePool (IpmiSendData); return EFI_OUT_OF_RESOURCES; } @@ -206,9 +204,22 @@ IpmiBlobTransferSendIpmi ( DEBUG_CODE_END (); if (EFI_ERROR (Status)) { + FreePool (IpmiResponseData); return Status; } + if (IpmiResponseDataSize > AllocatedResponseSize) { + DEBUG ((DEBUG_ERROR, "%a: Response size %u exceeds allocated buffer %u\n", __func__, IpmiResponseDataSize, AllocatedResponseSize)); + FreePool (IpmiResponseData); + return EFI_DEVICE_ERROR; + } + + if (IpmiResponseDataSize < sizeof (CompletionCode)) { + DEBUG ((DEBUG_ERROR, "%a: Response too short for Completion Code: %u bytes\n", __func__, IpmiResponseDataSize)); + FreePool (IpmiResponseData); + return EFI_PROTOCOL_ERROR; + } + CompletionCode = *ModifiedResponseData; if (CompletionCode != IPMI_COMP_CODE_NORMAL) { DEBUG ((DEBUG_ERROR, "%a: Returning because CompletionCode = 0x%x\n", __func__, CompletionCode)); @@ -220,6 +231,12 @@ IpmiBlobTransferSendIpmi ( ModifiedResponseData = ModifiedResponseData + sizeof (CompletionCode); IpmiResponseDataSize -= sizeof (CompletionCode); + if (IpmiResponseDataSize < sizeof (OpenBmcOen)) { + DEBUG ((DEBUG_ERROR, "%a: Response too short for OEN: %u bytes\n", __func__, IpmiResponseDataSize)); + FreePool (IpmiResponseData); + return EFI_PROTOCOL_ERROR; + } + // Check OEN code and verify it matches the OpenBMC OEN CopyMem (Oen, ModifiedResponseData, sizeof (OpenBmcOen)); if (CompareMem (Oen, OpenBmcOen, sizeof (OpenBmcOen)) != 0) { @@ -227,7 +244,11 @@ IpmiBlobTransferSendIpmi ( return EFI_PROTOCOL_ERROR; } - if (IpmiResponseDataSize == sizeof (OpenBmcOen)) { + // Strip the OEN, we are done with it now + ModifiedResponseData = ModifiedResponseData + sizeof (Oen); + IpmiResponseDataSize -= sizeof (Oen); + + if (IpmiResponseDataSize == 0) { // // In this case, there was no response data sent. This is not an error. // Some messages do not require a response. @@ -240,9 +261,12 @@ IpmiBlobTransferSendIpmi ( return Status; // Now we need to validate the CRC then send the Response body back } else { - // Strip the OEN, we are done with it now - ModifiedResponseData = ModifiedResponseData + sizeof (Oen); - IpmiResponseDataSize -= sizeof (Oen); + if (IpmiResponseDataSize < sizeof (Crc)) { + DEBUG ((DEBUG_ERROR, "%a: Response too short for CRC: %u bytes\n", __func__, IpmiResponseDataSize)); + FreePool (IpmiResponseData); + return EFI_PROTOCOL_ERROR; + } + // Then validate the Crc CopyMem (&Crc, ModifiedResponseData, sizeof (Crc)); ModifiedResponseData = ModifiedResponseData + sizeof (Crc); @@ -250,6 +274,12 @@ IpmiBlobTransferSendIpmi ( if (Crc == CalculateCrc16Ccitt (ModifiedResponseData, IpmiResponseDataSize)) { if ((ResponseData != NULL) && (ResponseDataSize != NULL)) { + if (IpmiResponseDataSize > *ResponseDataSize) { + DEBUG ((DEBUG_ERROR, "%a: Response too large for buffer: %u > %u\n", __func__, IpmiResponseDataSize, *ResponseDataSize)); + FreePool (IpmiResponseData); + return EFI_BUFFER_TOO_SMALL; + } + CopyMem (ResponseData, ModifiedResponseData, IpmiResponseDataSize); CopyMem (ResponseDataSize, &IpmiResponseDataSize, sizeof (IpmiResponseDataSize)); } @@ -728,8 +758,10 @@ IpmiBlobTransferStat ( UINT8 *ResponseData; UINT32 SendDataSize; UINT32 ResponseDataSize; + UINT8 ActMetaLen; if ((BlobId == NULL) || (BlobState == NULL)) { + ASSERT (FALSE); return EFI_INVALID_PARAMETER; } @@ -757,12 +789,17 @@ IpmiBlobTransferStat ( *Size = ((IPMI_BLOB_TRANSFER_BLOB_STAT_RESPONSE *)ResponseData)->Size; } + ActMetaLen = ((IPMI_BLOB_TRANSFER_BLOB_STAT_RESPONSE *)ResponseData)->MetaDataLen; if (MetadataLength != NULL) { - *MetadataLength = ((IPMI_BLOB_TRANSFER_BLOB_STAT_RESPONSE *)ResponseData)->MetaDataLen; + *MetadataLength = ActMetaLen; } if (Metadata != NULL) { - CopyMem (Metadata, ((IPMI_BLOB_TRANSFER_BLOB_STAT_RESPONSE *)ResponseData)->MetaData, sizeof (((IPMI_BLOB_TRANSFER_BLOB_STAT_RESPONSE *)ResponseData)->MetaData)); + if (ActMetaLen > BLOB_MAX_DATA_PER_PACKET) { + ActMetaLen = BLOB_MAX_DATA_PER_PACKET; + } + + CopyMem (Metadata, ((IPMI_BLOB_TRANSFER_BLOB_STAT_RESPONSE *)ResponseData)->MetaData, ActMetaLen); } } @@ -797,6 +834,7 @@ IpmiBlobTransferSessionStat ( UINT8 *ResponseData; UINT32 SendDataSize; UINT32 ResponseDataSize; + UINT8 ActMetaLen; if (BlobState == NULL) { ASSERT (FALSE); @@ -828,12 +866,17 @@ IpmiBlobTransferSessionStat ( *Size = ((IPMI_BLOB_TRANSFER_BLOB_SESSION_STAT_RESPONSE *)ResponseData)->Size; } + ActMetaLen = ((IPMI_BLOB_TRANSFER_BLOB_SESSION_STAT_RESPONSE *)ResponseData)->MetaDataLen; if (MetadataLength != NULL) { - *MetadataLength = ((IPMI_BLOB_TRANSFER_BLOB_SESSION_STAT_RESPONSE *)ResponseData)->MetaDataLen; + *MetadataLength = ActMetaLen; } if (Metadata != NULL) { - CopyMem (Metadata, ((IPMI_BLOB_TRANSFER_BLOB_SESSION_STAT_RESPONSE *)ResponseData)->MetaData, sizeof (((IPMI_BLOB_TRANSFER_BLOB_SESSION_STAT_RESPONSE *)ResponseData)->MetaData)); + if (ActMetaLen > BLOB_MAX_DATA_PER_PACKET) { + ActMetaLen = BLOB_MAX_DATA_PER_PACKET; + } + + CopyMem (Metadata, ((IPMI_BLOB_TRANSFER_BLOB_SESSION_STAT_RESPONSE *)ResponseData)->MetaData, ActMetaLen); } } @@ -867,7 +910,7 @@ IpmiBlobTransferWriteMeta ( UINT32 SendDataSize; UINT32 ResponseDataSize; - if (Data == NULL) { + if ((WriteLength > 0) && (Data == NULL)) { return EFI_INVALID_PARAMETER; } diff --git a/ManageabilityPkg/Universal/IpmiBlobTransferDxe/UnitTest/IpmiBlobTransferTestUnitTests.c b/ManageabilityPkg/Universal/IpmiBlobTransferDxe/UnitTest/IpmiBlobTransferTestUnitTests.c index 3f38068251..2c471dc685 100644 --- a/ManageabilityPkg/Universal/IpmiBlobTransferDxe/UnitTest/IpmiBlobTransferTestUnitTests.c +++ b/ManageabilityPkg/Universal/IpmiBlobTransferDxe/UnitTest/IpmiBlobTransferTestUnitTests.c @@ -74,11 +74,10 @@ GoodCrc ( IN UNIT_TEST_CONTEXT Context ) { - UINT8 Data[5]; + UINT8 Data[5] = { 0x12, 0x34, 0x56, 0x78, 0x90 }; UINTN DataSize; UINT16 Crc; - Data = { 0x12, 0x34, 0x56, 0x78, 0x90 }; DataSize = sizeof (Data); Crc = CalculateCrc16Ccitt (Data, DataSize); @@ -105,11 +104,10 @@ BadCrc ( IN UNIT_TEST_CONTEXT Context ) { - UINT8 Data[5]; + UINT8 Data[5] = { 0x12, 0x34, 0x56, 0x78, 0x90 }; UINTN DataSize; UINT16 Crc; - Data = { 0x12, 0x34, 0x56, 0x78, 0x90 }; DataSize = sizeof (Data); Crc = CalculateCrc16Ccitt (Data, DataSize); @@ -157,6 +155,177 @@ SendIpmiBadCompletion ( return UNIT_TEST_PASSED; } +/** + @param[in] Context [Optional] An optional parameter that enables: + 1) test-case reuse with varied parameters and + 2) test-case re-entry for Target tests that need a + reboot. This parameter is a VOID* and it is the + responsibility of the test author to ensure that the + contents are well understood by all test cases that may + consume it. + @retval UNIT_TEST_PASSED The Unit test has completed and the test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +SendIpmiResponseTooShort ( + IN UNIT_TEST_CONTEXT Context + ) +{ + VOID *ResponseData; + UINT32 *ResponseDataSize; + EFI_STATUS Status; + UINT32 MockResponseSize = 0; + + // Too short for completion code + MockResponseSize = 0; + ResponseDataSize = (UINT32 *)AllocateZeroPool (sizeof (UINT32)); + + MockIpmiSubmitCommand (NULL, MockResponseSize, EFI_SUCCESS); + + ResponseData = (UINT8 *)AllocateZeroPool (10); + Status = IpmiBlobTransferSendIpmi (IpmiBlobTransferSubcommandGetCount, NULL, 0, ResponseData, ResponseDataSize); + + UT_ASSERT_STATUS_EQUAL (Status, EFI_PROTOCOL_ERROR); + + FreePool (ResponseDataSize); + FreePool (ResponseData); + return UNIT_TEST_PASSED; +} + +/** + @param[in] Context [Optional] An optional parameter that enables: + 1) test-case reuse with varied parameters and + 2) test-case re-entry for Target tests that need a + reboot. This parameter is a VOID* and it is the + responsibility of the test author to ensure that the + contents are well understood by all test cases that may + consume it. + @retval UNIT_TEST_PASSED The Unit test has completed and the test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +SendIpmiResponseTooShortForOen ( + IN UNIT_TEST_CONTEXT Context + ) +{ + VOID *ResponseData; + UINT32 *ResponseDataSize; + EFI_STATUS Status; + VOID *MockResponseResults = NULL; + UINT32 MockResponseSize = 1; + + // Only has completion code, too short for OEN + MockResponseResults = (UINT8 *)AllocateZeroPool (MockResponseSize); + ResponseDataSize = (UINT32 *)AllocateZeroPool (sizeof (UINT32)); + *(UINT8 *)MockResponseResults = 0; // Success completion code + + MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, MockResponseSize, EFI_SUCCESS); + + ResponseData = (UINT8 *)AllocateZeroPool (10); + Status = IpmiBlobTransferSendIpmi (IpmiBlobTransferSubcommandGetCount, NULL, 0, ResponseData, ResponseDataSize); + + UT_ASSERT_STATUS_EQUAL (Status, EFI_PROTOCOL_ERROR); + + FreePool (MockResponseResults); + FreePool (ResponseDataSize); + FreePool (ResponseData); + return UNIT_TEST_PASSED; +} + +/** + @param[in] Context [Optional] An optional parameter that enables: + 1) test-case reuse with varied parameters and + 2) test-case re-entry for Target tests that need a + reboot. This parameter is a VOID* and it is the + responsibility of the test author to ensure that the + contents are well understood by all test cases that may + consume it. + @retval UNIT_TEST_PASSED The Unit test has completed and the test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +SendIpmiResponseTooLarge ( + IN UNIT_TEST_CONTEXT Context + ) +{ + VOID *ResponseData; + UINT32 *ResponseDataSize; + EFI_STATUS Status; + VOID *MockResponseResults = NULL; + UINT8 LargeResponse[] = { + 0x00, // CompletionCode + 0xCF, 0xC2, 0x00, // OpenBMC OEN + 0x00, 0x00, // CRC (doesn't matter as we fail before check) + 0x01, 0x02, 0x03, 0x04 // Data + }; + + // Response says 4 bytes of data, but caller only provides 2 bytes buffer + MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (LargeResponse)); + ResponseDataSize = (UINT32 *)AllocateZeroPool (sizeof (UINT32)); + *ResponseDataSize = 2; // Caller buffer size + CopyMem (MockResponseResults, LargeResponse, sizeof (LargeResponse)); + + // We need valid CRC for it to reach the size check + UINT16 CorrectCrc = CalculateCrc16Ccitt (LargeResponse + 6, 4); + + CopyMem (MockResponseResults + 4, &CorrectCrc, sizeof (UINT16)); + + MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, sizeof (LargeResponse), EFI_SUCCESS); + + ResponseData = (UINT8 *)AllocateZeroPool (*ResponseDataSize); + Status = IpmiBlobTransferSendIpmi (IpmiBlobTransferSubcommandGetCount, NULL, 0, ResponseData, ResponseDataSize); + + UT_ASSERT_STATUS_EQUAL (Status, EFI_BUFFER_TOO_SMALL); + + FreePool (MockResponseResults); + FreePool (ResponseDataSize); + FreePool (ResponseData); + return UNIT_TEST_PASSED; +} + +/** + @param[in] Context [Optional] An optional parameter that enables: + 1) test-case reuse with varied parameters and + 2) test-case re-entry for Target tests that need a + reboot. This parameter is a VOID* and it is the + responsibility of the test author to ensure that the + contents are well understood by all test cases that may + consume it. + @retval UNIT_TEST_PASSED The Unit test has completed and the test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +SendIpmiSubmitCommandError ( + IN UNIT_TEST_CONTEXT Context + ) +{ + VOID *ResponseData; + UINT32 *ResponseDataSize; + EFI_STATUS Status; + + ResponseDataSize = (UINT32 *)AllocateZeroPool (sizeof (UINT32)); + *ResponseDataSize = 10; + + MockIpmiSubmitCommand (NULL, 0, EFI_DEVICE_ERROR); + + ResponseData = (UINT8 *)AllocateZeroPool (*ResponseDataSize); + Status = IpmiBlobTransferSendIpmi (IpmiBlobTransferSubcommandGetCount, NULL, 0, ResponseData, ResponseDataSize); + + UT_ASSERT_STATUS_EQUAL (Status, EFI_DEVICE_ERROR); + + FreePool (ResponseDataSize); + FreePool (ResponseData); + return UNIT_TEST_PASSED; +} + /** @param[in] Context [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and @@ -265,7 +434,7 @@ SendIpmiBadCrcResponse ( EFI_STATUS Status; VOID *MockResponseResults; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (BAD_CRC_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (BAD_CRC_RESPONSE_SIZE); ResponseDataSize = (UINT32 *)AllocateZeroPool (sizeof (UINT32)); CopyMem (MockResponseResults, &BadCrcResponse, BAD_CRC_RESPONSE_SIZE); @@ -315,8 +484,9 @@ SendIpmiValidCountResponse ( EFI_STATUS Status; VOID *MockResponseResults; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_GET_COUNT_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_GET_COUNT_RESPONSE_SIZE); ResponseDataSize = (UINT32 *)AllocateZeroPool (sizeof (UINT32)); + *ResponseDataSize = sizeof (ValidGetCountResponse); CopyMem (MockResponseResults, &ValidGetCountResponse, VALID_GET_COUNT_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_GET_COUNT_RESPONSE_SIZE, EFI_SUCCESS); @@ -357,7 +527,7 @@ GetCountValidCountResponse ( VOID *MockResponseResults; Count = 0; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_GET_COUNT_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_GET_COUNT_RESPONSE_SIZE); CopyMem (MockResponseResults, &ValidGetCountResponse, VALID_GET_COUNT_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_GET_COUNT_RESPONSE_SIZE, EFI_SUCCESS); @@ -404,7 +574,7 @@ EnumerateValidResponse ( CHAR8 *BlobId; VOID *MockResponseResults; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_ENUMERATE_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_ENUMERATE_RESPONSE_SIZE); CopyMem (MockResponseResults, &ValidEnumerateResponse, VALID_ENUMERATE_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_ENUMERATE_RESPONSE_SIZE, EFI_SUCCESS); @@ -441,23 +611,12 @@ EnumerateInvalidBuffer ( IN UNIT_TEST_CONTEXT Context ) { - CHAR8 *BlobId; - EFI_STATUS Status; - VOID *MockResponseResults; - - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_ENUMERATE_RESPONSE_SIZE)); - CopyMem (MockResponseResults, &ValidEnumerateResponse, VALID_ENUMERATE_RESPONSE_SIZE); - - Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_ENUMERATE_RESPONSE_SIZE, EFI_SUCCESS); - if (EFI_ERROR (Status)) { - return UNIT_TEST_ERROR_TEST_FAILED; - } + CHAR8 *BlobId; BlobId = NULL; UT_EXPECT_ASSERT_FAILURE (IpmiBlobTransferEnumerate (0, BlobId), NULL); - FreePool (MockResponseResults); return UNIT_TEST_PASSED; } @@ -509,28 +668,31 @@ OpenValidResponse ( // So we'll push three Ipmi responses in this case // - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_OPEN_RESPONSE_SIZE)); - - CopyMem (MockResponseResults, &ValidOpenResponse, VALID_OPEN_RESPONSE_SIZE); - Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_OPEN_RESPONSE_SIZE, EFI_SUCCESS); - if (EFI_ERROR (Status)) { - return UNIT_TEST_ERROR_TEST_FAILED; - } - - MockResponseResults2 = (UINT8 *)AllocateZeroPool (sizeof (VALID_ENUMERATE_RESPONSE_SIZE)); - CopyMem (MockResponseResults2, &ValidEnumerateResponse, VALID_ENUMERATE_RESPONSE_SIZE); - Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults2, VALID_ENUMERATE_RESPONSE_SIZE, EFI_SUCCESS); - if (EFI_ERROR (Status)) { - return UNIT_TEST_ERROR_TEST_FAILED; - } - - MockResponseResults3 = (UINT8 *)AllocateZeroPool (sizeof (VALID_GET_COUNT_RESPONSE_SIZE)); + // Queue order must be: GetCount, Enumerate, Open + MockResponseResults3 = (UINT8 *)AllocateZeroPool (VALID_GET_COUNT_RESPONSE_SIZE); CopyMem (MockResponseResults3, &ValidGetCountResponse, VALID_GET_COUNT_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults3, VALID_GET_COUNT_RESPONSE_SIZE, EFI_SUCCESS); if (EFI_ERROR (Status)) { return UNIT_TEST_ERROR_TEST_FAILED; } + MockResponseResults2 = (UINT8 *)AllocateZeroPool (VALID_ENUMERATE_RESPONSE_SIZE); + CopyMem (MockResponseResults2, &ValidEnumerateResponse, VALID_ENUMERATE_RESPONSE_SIZE); + Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults2, VALID_ENUMERATE_RESPONSE_SIZE, EFI_SUCCESS); + if (EFI_ERROR (Status)) { + FreePool (MockResponseResults3); + return UNIT_TEST_ERROR_TEST_FAILED; + } + + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_OPEN_RESPONSE_SIZE); + CopyMem (MockResponseResults, &ValidOpenResponse, VALID_OPEN_RESPONSE_SIZE); + Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_OPEN_RESPONSE_SIZE, EFI_SUCCESS); + if (EFI_ERROR (Status)) { + FreePool (MockResponseResults2); + FreePool (MockResponseResults3); + return UNIT_TEST_ERROR_TEST_FAILED; + } + BlobId = "/smbios"; Status = IpmiBlobTransferOpen (BlobId, Flags, &SessionId); @@ -538,6 +700,8 @@ OpenValidResponse ( UT_ASSERT_STATUS_EQUAL (Status, EFI_SUCCESS); UT_ASSERT_EQUAL (SessionId, 3); FreePool (MockResponseResults); + FreePool (MockResponseResults2); + FreePool (MockResponseResults3); return UNIT_TEST_PASSED; } @@ -570,11 +734,10 @@ ReadValidResponse ( { EFI_STATUS Status; UINT8 *ResponseData; - UINT8 ExpectedDataResponse[4]; + UINT8 ExpectedDataResponse[4] = { 0x00, 0x01, 0x02, 0x03 }; VOID *MockResponseResults; - ExpectedDataResponse = { 0x00, 0x01, 0x02, 0x03 }; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_READ_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_READ_RESPONSE_SIZE); CopyMem (MockResponseResults, &ValidReadResponse, VALID_READ_RESPONSE_SIZE); ResponseData = AllocateZeroPool (sizeof (ValidReadResponse)); @@ -610,22 +773,12 @@ ReadInvalidBuffer ( IN UNIT_TEST_CONTEXT Context ) { - UINT8 *ResponseData; - EFI_STATUS Status; - VOID *MockResponseResults; + UINT8 *ResponseData; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_READ_RESPONSE_SIZE)); - CopyMem (MockResponseResults, &ValidReadResponse, VALID_READ_RESPONSE_SIZE); ResponseData = NULL; - Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_READ_RESPONSE_SIZE, EFI_SUCCESS); - if (EFI_ERROR (Status)) { - return UNIT_TEST_ERROR_TEST_FAILED; - } - UT_EXPECT_ASSERT_FAILURE (IpmiBlobTransferRead (0, 0, 4, ResponseData), NULL); - FreePool (MockResponseResults); return UNIT_TEST_PASSED; } @@ -648,11 +801,10 @@ WriteValidResponse ( ) { EFI_STATUS Status; - UINT8 SendData[4]; + UINT8 SendData[4] = { 0x00, 0x01, 0x02, 0x03 }; VOID *MockResponseResults; - SendData = { 0x00, 0x01, 0x02, 0x03 }; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_NODATA_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_NODATA_RESPONSE_SIZE); CopyMem (MockResponseResults, &ValidNoDataResponse, VALID_NODATA_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_NODATA_RESPONSE_SIZE, EFI_SUCCESS); @@ -686,11 +838,10 @@ CommitValidResponse ( ) { EFI_STATUS Status; - UINT8 SendData[4]; + UINT8 SendData[4] = { 0x00, 0x01, 0x02, 0x03 }; VOID *MockResponseResults; - SendData = { 0x00, 0x01, 0x02, 0x03 }; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_NODATA_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_NODATA_RESPONSE_SIZE); CopyMem (MockResponseResults, &ValidNoDataResponse, VALID_NODATA_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_NODATA_RESPONSE_SIZE, EFI_SUCCESS); @@ -726,7 +877,7 @@ CloseValidResponse ( EFI_STATUS Status; VOID *MockResponseResults; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_NODATA_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_NODATA_RESPONSE_SIZE); CopyMem (MockResponseResults, &ValidNoDataResponse, VALID_NODATA_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_NODATA_RESPONSE_SIZE, EFI_SUCCESS); @@ -762,7 +913,7 @@ DeleteValidResponse ( EFI_STATUS Status; VOID *MockResponseResults; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_NODATA_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_NODATA_RESPONSE_SIZE); CopyMem (MockResponseResults, &ValidNoDataResponse, VALID_NODATA_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_NODATA_RESPONSE_SIZE, EFI_SUCCESS); @@ -812,18 +963,17 @@ BlobStatValidResponse ( UINT32 *Size; UINT8 *MetadataLength; UINT8 *Metadata; - UINT8 *ExpectedMetadata; + UINT8 ExpectedMetadata[4] = { 0x06, 0x07, 0x08, 0x09 }; CHAR8 *BlobId; VOID *MockResponseResults; - BlobState = AllocateZeroPool (sizeof (UINT16)); - Size = AllocateZeroPool (sizeof (UINT32)); - BlobId = "BlobId"; - MetadataLength = AllocateZeroPool (sizeof (UINT8)); - Metadata = AllocateZeroPool (4 * sizeof (UINT8)); - ExpectedMetadata = AllocateZeroPool (4 * sizeof (UINT8)); + BlobState = AllocateZeroPool (sizeof (UINT16)); + Size = AllocateZeroPool (sizeof (UINT32)); + BlobId = "BlobId"; + MetadataLength = AllocateZeroPool (sizeof (UINT8)); + Metadata = AllocateZeroPool (4 * sizeof (UINT8)); - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_BLOB_STAT_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_BLOB_STAT_RESPONSE_SIZE); CopyMem (MockResponseResults, &ValidBlobStatResponse, VALID_BLOB_STAT_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_BLOB_STAT_RESPONSE_SIZE, EFI_SUCCESS); @@ -864,23 +1014,12 @@ BlobStatInvalidBuffer ( IN UNIT_TEST_CONTEXT Context ) { - UINT8 *Metadata; - EFI_STATUS Status; - VOID *MockResponseResults; + UINT8 *Metadata; Metadata = NULL; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_BLOB_STAT_RESPONSE_SIZE)); - CopyMem (MockResponseResults, &ValidBlobStatResponse, VALID_BLOB_STAT_RESPONSE_SIZE); - - Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_BLOB_STAT_RESPONSE_SIZE, EFI_SUCCESS); - if (EFI_ERROR (Status)) { - return UNIT_TEST_ERROR_TEST_FAILED; - } - UT_EXPECT_ASSERT_FAILURE (IpmiBlobTransferStat (NULL, 0, 0, 0, Metadata), NULL); - FreePool (MockResponseResults); return UNIT_TEST_PASSED; } @@ -907,16 +1046,15 @@ SessionStatValidResponse ( UINT32 *Size; UINT8 *MetadataLength; UINT8 *Metadata; - UINT8 *ExpectedMetadata; + UINT8 ExpectedMetadata[4] = { 0x06, 0x07, 0x08, 0x09 }; VOID *MockResponseResults; - BlobState = AllocateZeroPool (sizeof (UINT16)); - Size = AllocateZeroPool (sizeof (UINT32)); - MetadataLength = AllocateZeroPool (sizeof (UINT8)); - Metadata = AllocateZeroPool (4 * sizeof (UINT8)); - ExpectedMetadata = AllocateZeroPool (4 * sizeof (UINT8)); + BlobState = AllocateZeroPool (sizeof (UINT16)); + Size = AllocateZeroPool (sizeof (UINT32)); + MetadataLength = AllocateZeroPool (sizeof (UINT8)); + Metadata = AllocateZeroPool (4 * sizeof (UINT8)); - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_BLOB_STAT_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_BLOB_STAT_RESPONSE_SIZE); CopyMem (MockResponseResults, &ValidBlobStatResponse, VALID_BLOB_STAT_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_BLOB_STAT_RESPONSE_SIZE, EFI_SUCCESS); @@ -957,23 +1095,12 @@ SessionStatInvalidBuffer ( IN UNIT_TEST_CONTEXT Context ) { - UINT8 *Metadata; - EFI_STATUS Status; - VOID *MockResponseResults; + UINT8 *Metadata; Metadata = NULL; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_BLOB_STAT_RESPONSE_SIZE)); - CopyMem (MockResponseResults, &ValidBlobStatResponse, VALID_BLOB_STAT_RESPONSE_SIZE); - - Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_BLOB_STAT_RESPONSE_SIZE, EFI_SUCCESS); - if (EFI_ERROR (Status)) { - return UNIT_TEST_ERROR_TEST_FAILED; - } - UT_EXPECT_ASSERT_FAILURE (IpmiBlobTransferSessionStat (0, 0, 0, 0, Metadata), NULL); - FreePool (MockResponseResults); return UNIT_TEST_PASSED; } @@ -998,7 +1125,7 @@ WriteMetaValidResponse ( EFI_STATUS Status; VOID *MockResponseResults; - MockResponseResults = (UINT8 *)AllocateZeroPool (sizeof (VALID_NODATA_RESPONSE_SIZE)); + MockResponseResults = (UINT8 *)AllocateZeroPool (VALID_NODATA_RESPONSE_SIZE); CopyMem (MockResponseResults, &ValidNoDataResponse, VALID_NODATA_RESPONSE_SIZE); Status = MockIpmiSubmitCommand ((UINT8 *)MockResponseResults, VALID_NODATA_RESPONSE_SIZE, EFI_SUCCESS); @@ -1055,6 +1182,10 @@ SetupAndRunUnitTests ( Status = AddTestCase (IpmiBlobTransfer, "Test Bad CRC Calculation", "BadCrc", BadCrc, NULL, NULL, NULL); // IpmiBlobTransferSendIpmi Status = AddTestCase (IpmiBlobTransfer, "Send IPMI returns bad completion", "SendIpmiBadCompletion", SendIpmiBadCompletion, NULL, NULL, NULL); + Status = AddTestCase (IpmiBlobTransfer, "Send IPMI returns response too short", "SendIpmiResponseTooShort", SendIpmiResponseTooShort, NULL, NULL, NULL); + Status = AddTestCase (IpmiBlobTransfer, "Send IPMI returns response too short for OEN", "SendIpmiResponseTooShortForOen", SendIpmiResponseTooShortForOen, NULL, NULL, NULL); + Status = AddTestCase (IpmiBlobTransfer, "Send IPMI returns response too large for buffer", "SendIpmiResponseTooLarge", SendIpmiResponseTooLarge, NULL, NULL, NULL); + Status = AddTestCase (IpmiBlobTransfer, "Send IPMI returns error from SubmitCommand", "SendIpmiSubmitCommandError", SendIpmiSubmitCommandError, NULL, NULL, NULL); Status = AddTestCase (IpmiBlobTransfer, "Send IPMI returns successfully with no data", "SendIpmiNoDataResponse", SendIpmiNoDataResponse, NULL, NULL, NULL); Status = AddTestCase (IpmiBlobTransfer, "Send IPMI returns successfully with bad OEN", "SendIpmiBadOenResponse", SendIpmiBadOenResponse, NULL, NULL, NULL); Status = AddTestCase (IpmiBlobTransfer, "Send IPMI returns successfully with bad CRC", "SendIpmiBadCrcResponse", SendIpmiBadCrcResponse, NULL, NULL, NULL); From 5ac1b95b3e630b05a51d2037106c2774a5cf7370 Mon Sep 17 00:00:00 2001 From: Dongyan Qian Date: Wed, 13 May 2026 15:54:27 +0800 Subject: [PATCH 083/406] MdeModulePkg/PciBusDxe: Scan funcs when func 0 is absent The PCI specification normally requires function 0 to be present before functions 1 through 7 are used. PciBusDxe therefore stops scanning a slot when probing function 0 fails. Some virtualized PCI topologies may expose selected non-zero functions to a guest while function 0 is hidden. Add an opt-in Feature PCD so a platform can continue collecting device information for functions 1 through 7 when function 0 is absent. The default remains FALSE, so existing platform behavior is unchanged unless the platform explicitly enables the PCD. Signed-off-by: Dongyan Qian --- MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf | 1 + .../Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 15 +++++++++++++-- MdeModulePkg/MdeModulePkg.dec | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf index 4de018b2a5..2865dac874 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf @@ -90,6 +90,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdPciBridgeIoAlignmentProbe ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdUnalignedPciIoEnable ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPciDegradeResourceForOptionRom ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdPciScanFuncIfFunc0Absent ## CONSUMES [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdSrIovSystemPageSize ## SOMETIMES_CONSUMES diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c index 9043e8ddc2..296c9de3c6 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c @@ -266,10 +266,21 @@ PciPciDeviceInfoCollector ( ); if (EFI_ERROR (Status) && (Func == 0)) { + if (!FeaturePcdGet (PcdPciScanFuncIfFunc0Absent)) { + // + // Preserve default behavior for physical platforms: go to next + // device if there is no Function 0. + // + break; + } + // - // go to next device if there is no Function 0 + // Some virtualized PCI topologies may let a hypervisor expose + // selected non-zero functions to a guest while Function 0 is absent. + // Some platforms may require probing such functions. + // Keep scanning only when enabled by platform policy. // - break; + continue; } if (!EFI_ERROR (Status)) { diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index d7dc740cbb..fac0f8ebed 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -882,6 +882,12 @@ # @Prompt Enable PCI bridge IO alignment probe. gEfiMdeModulePkgTokenSpaceGuid.PcdPciBridgeIoAlignmentProbe|FALSE|BOOLEAN|0x0001004e + ## Indicates if the PciBus driver scans functions 1..7 when function 0 is absent.
+ # TRUE - PciBus driver scans non-zero functions when Function 0 is absent.
+ # FALSE - PciBus driver skips the device when Function 0 is absent.
+ # @Prompt Enable scanning PCI functions 1..7 without Function 0. + gEfiMdeModulePkgTokenSpaceGuid.PcdPciScanFuncIfFunc0Absent|FALSE|BOOLEAN|0x0001007a + ## Indicates if PEI phase StatusCode will be replayed in DXE phase.

# TRUE - Replays PEI phase StatusCode in DXE phased.
# FALSE - Does not replay PEI phase StatusCode in DXE phase.
From a5fcc0a6ac0acd67c65a5fb2c3b91806251791a5 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Thu, 18 Jun 2026 10:46:48 -0700 Subject: [PATCH 084/406] MdeModulePkg: CxlDxe: Fix IA32 Build Break CxlDxe is currently compiled as part of the MdeModulePkg IA32 CI. When running CI with VS2022 version 14.44.35228.0, the CI build fails with: CxlDxe.lib(CxlDxe.obj) : unresolved external symbol __allmul CxlDxe(CxlDxe.obj) : unresolved external symbol __allshl CxlDxe is not intended to run on IA32 DXE systems, as such systems are legacy, but until edk2 drops build support for IA32 DXE (or at least CI for it), the build needs to work. This fixes the 64 bit multiplication/shifting that occurs in CxlDxe to use the BaseLib functions that avoid the compiler intrinsics. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.c b/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.c index 0c9f40e1a5..731dcab8fb 100644 --- a/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.c +++ b/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.c @@ -60,7 +60,7 @@ PciUefiMemReadUInt32Array ( ) { EFI_STATUS Status; - UINT64 BufferIndex; + UINTN BufferIndex; UINT64 Offset; ASSERT ((SizeInBytes % 4) == 0); @@ -81,7 +81,7 @@ PciUefiMemReadUInt32Array ( ); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: PciIo read error at 0x%lx: %r \n", __func__, BufferIndex, Status)); + DEBUG ((DEBUG_ERROR, "%a: PciIo read error at 0x%lx: %r \n", __func__, (UINT64)BufferIndex, Status)); return Status; } @@ -115,7 +115,7 @@ PciUefiMemWriteUInt32Array ( ) { EFI_STATUS Status; - UINT64 BufferIndex; + UINTN BufferIndex; UINT64 Offset; ASSERT ((SizeInBytes % 4) == 0); @@ -136,7 +136,7 @@ PciUefiMemWriteUInt32Array ( ); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: PciIo write error at 0x%lx: %r \n", __func__, BufferIndex, Status)); + DEBUG ((DEBUG_ERROR, "%a: PciIo write error at 0x%lx: %r \n", __func__, (UINT64)BufferIndex, Status)); return Status; } @@ -303,7 +303,7 @@ CxlDecodeRegblock ( Bar = (UINT8)(Block->OffsetLow.Bits.RegisterBir / 2); Offset = - ((UINT64)Block->OffsetHigh.Bits.RegisterBlockOffsetHigh << 32) | + LShiftU64 ((UINT64)Block->OffsetHigh.Bits.RegisterBlockOffsetHigh, 32) | (Block->OffsetLow.Bits.RegisterBlockOffsetLow << 16); RegisterMap->RegisterType = Block->OffsetLow.Bits.RegisterBlockIdentifier; From 5f389e499c8dcca66b1c5680cb874c7fc50c5859 Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Thu, 18 Sep 2025 16:44:06 +0100 Subject: [PATCH 085/406] CryptoPkg: Enable SHA256 hash in SecCryptLib Enable CryptSha256 hash in SecCryptLib as this is required by Arm CCA. The hash algorithm used by the Arm CCA Realm Extensible Measurement (REM) registers is either SHA256 or SHA512. To enable measurements in the early boot phase enable SHA256 hash algorithm in SecCryptLib. Signed-off-by: Sami Mujawar --- CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf index 130d4709b2..01ce6224ca 100644 --- a/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf @@ -23,7 +23,7 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = IA32 X64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 # [Sources] @@ -32,7 +32,7 @@ Hash/CryptMd5Null.c Hash/CryptSha1Null.c - Hash/CryptSha256Null.c + Hash/CryptSha256.c Hash/CryptSm3Null.c Hash/CryptParallelHashNull.c Hmac/CryptHmacNull.c From 8a6cd66acb952444957e51b52d35a35042cbb59a Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Thu, 18 Sep 2025 16:42:06 +0100 Subject: [PATCH 086/406] SecurityPkg/HashInstanceLibSha256: Remove unused Tpm2CommandLib dependency The HashInstanceLibSha256 library does not call into Tpm2CommandLib. Removing it from the [LibraryClasses] section reduces unnecessary dependencies and avoids potential build issues in non-TPM builds. Also remove the unnecessary include of Tpm2CommandLib.h Signed-off-by: Sami Mujawar --- .../Library/HashInstanceLibSha256/HashInstanceLibSha256.c | 1 - .../Library/HashInstanceLibSha256/HashInstanceLibSha256.inf | 1 - 2 files changed, 2 deletions(-) diff --git a/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c b/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c index 4387740001..f06c702865 100644 --- a/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c +++ b/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c @@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include -#include #include #include #include diff --git a/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf b/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf index a7d1f162bd..72fd1b4405 100644 --- a/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf +++ b/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf @@ -36,6 +36,5 @@ BaseLib BaseMemoryLib DebugLib - Tpm2CommandLib MemoryAllocationLib BaseCryptLib From 96e2af4cc40fd04bcacda8f6dcb461a865e8e72d Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Thu, 18 Jun 2026 11:50:14 -0400 Subject: [PATCH 087/406] ManageabilityPkg: Follow pragma once coding convention Update recent changes in ManageabilityPkg to follow the latest EDK II C Coding Standards Specification (5.3) to use '#pragma once' instead of traditional macro-based include guards in header files. https://tianocore-docs.github.io/edk2-CCodingStandardsSpecification/draft/5_source_files/53_include_files.html#53-include-files Signed-off-by: Michael Kubacki --- .../Include/Library/BasePldmProtocolLib.h | 5 +---- .../Include/Library/ManageabilityTransportHelperLib.h | 5 +---- .../Include/Library/ManageabilityTransportIpmiLib.h | 5 +---- .../Include/Library/ManageabilityTransportLib.h | 5 +---- .../Include/Library/ManageabilityTransportMctpLib.h | 5 +---- .../Include/Library/PlatformBmcReadyLib.h | 5 +---- ManageabilityPkg/Include/Protocol/IpmiBlobTransfer.h | 5 +---- ManageabilityPkg/Include/Protocol/MctpProtocol.h | 5 +---- ManageabilityPkg/Include/Protocol/PldmProtocol.h | 5 +---- .../Include/Protocol/PldmSmbiosTransferProtocol.h | 5 +---- .../ManageabilityTransportKcs.h | 5 +---- .../Dxe/ManageabilityTransportMctp.h | 5 +---- .../Common/ManageabilityTransportSerial.h | 5 +---- .../Common/ManageabilityTransportSsif.h | 5 +---- .../IpmiBlobTransferDxe/InternalIpmiBlobTransfer.h | 11 ++++------- .../IpmiProtocol/Common/IpmiProtocolCommon.h | 5 +---- .../Universal/IpmiProtocol/Pei/IpmiPpiInternal.h | 5 +---- .../MctpProtocol/Common/MctpProtocolCommon.h | 5 +---- .../PldmProtocol/Common/PldmProtocolCommon.h | 5 +---- 19 files changed, 22 insertions(+), 79 deletions(-) diff --git a/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h b/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h index 6706f721f6..2e8fc6faab 100644 --- a/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h +++ b/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef EDKII_PLDM_PROTOCOL_LIB_H_ -#define EDKII_PLDM_PROTOCOL_LIB_H_ +#pragma once /** This function sets the PLDM source terminus and destination terminus @@ -53,5 +52,3 @@ PldmSubmitCommand ( OUT UINT8 *ResponseData, IN OUT UINT32 *ResponseDataSize ); - -#endif diff --git a/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h b/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h index 43852e1e14..e922af858e 100644 --- a/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h +++ b/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_TRANSPORT_HELPER_LIB_H_ -#define MANAGEABILITY_TRANSPORT_HELPER_LIB_H_ +#pragma once #include @@ -211,5 +210,3 @@ IpmiHelperCheckCompletionCode ( OUT CHAR16 **CompletionCodeStr, OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *AdditionalStatus ); - -#endif diff --git a/ManageabilityPkg/Include/Library/ManageabilityTransportIpmiLib.h b/ManageabilityPkg/Include/Library/ManageabilityTransportIpmiLib.h index ac9713514d..50a0b9a3c7 100644 --- a/ManageabilityPkg/Include/Library/ManageabilityTransportIpmiLib.h +++ b/ManageabilityPkg/Include/Library/ManageabilityTransportIpmiLib.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_TRANSPORT_IPMI_LIB_H_ -#define MANAGEABILITY_TRANSPORT_IPMI_LIB_H_ +#pragma once #include @@ -37,5 +36,3 @@ typedef struct { CHAR16 *CompletionCodeString; MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS AdditionalStatus; } MANAGEABILITY_IPMI_COMPLETTION_CODE_MAPPING; - -#endif diff --git a/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h b/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h index 0f21ae3af1..73a0850a2d 100644 --- a/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h +++ b/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h @@ -7,8 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_TRANSPORT_LIB_H_ -#define MANAGEABILITY_TRANSPORT_LIB_H_ +#pragma once #define MANAGEABILITY_TRANSPORT_TOKEN_VERSION_MAJOR 1 #define MANAGEABILITY_TRANSPORT_TOKEN_VERSION_MINOR 0 @@ -372,5 +371,3 @@ struct _MANAGEABILITY_TRANSPORT_FUNCTION_V1_0 { ///< transport and get the ///< response back. }; - -#endif diff --git a/ManageabilityPkg/Include/Library/ManageabilityTransportMctpLib.h b/ManageabilityPkg/Include/Library/ManageabilityTransportMctpLib.h index a8dc8a8519..ab34eea8a1 100644 --- a/ManageabilityPkg/Include/Library/ManageabilityTransportMctpLib.h +++ b/ManageabilityPkg/Include/Library/ManageabilityTransportMctpLib.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_TRANSPORT_MCTP_LIB_H_ -#define MANAGEABILITY_TRANSPORT_MCTP_LIB_H_ +#pragma once #include @@ -55,5 +54,3 @@ typedef struct { #define MCTP_MESSAGE_TAG_OWNER_RESPONSE 0 #define MCTP_PACKET_SEQUENCE_MASK 0x3 - -#endif // MANAGEABILITY_TRANSPORT_MCTP_LIB_H_ diff --git a/ManageabilityPkg/Include/Library/PlatformBmcReadyLib.h b/ManageabilityPkg/Include/Library/PlatformBmcReadyLib.h index 669230fd23..eb764c296b 100644 --- a/ManageabilityPkg/Include/Library/PlatformBmcReadyLib.h +++ b/ManageabilityPkg/Include/Library/PlatformBmcReadyLib.h @@ -6,8 +6,7 @@ **/ -#ifndef PLATFORM_BMC_READY_LIB_H_ -#define PLATFORM_BMC_READY_LIB_H_ +#pragma once /** This function checks whether BMC is ready for transaction or not. @@ -21,5 +20,3 @@ EFIAPI PlatformBmcReady ( VOID ); - -#endif /* PLATFORM_BMC_READY_LIB_H_ */ diff --git a/ManageabilityPkg/Include/Protocol/IpmiBlobTransfer.h b/ManageabilityPkg/Include/Protocol/IpmiBlobTransfer.h index 6ad54dc841..33787de54e 100644 --- a/ManageabilityPkg/Include/Protocol/IpmiBlobTransfer.h +++ b/ManageabilityPkg/Include/Protocol/IpmiBlobTransfer.h @@ -9,8 +9,7 @@ @par https://github.com/openbmc/phosphor-ipmi-blobs/blob/master/README.md **/ -#ifndef EDKII_IPMI_BLOB_TRANSFER_H_ -#define EDKII_IPMI_BLOB_TRANSFER_H_ +#pragma once #include #include @@ -260,5 +259,3 @@ struct _EDKII_IPMI_BLOB_TRANSFER_PROTOCOL { typedef struct _EDKII_IPMI_BLOB_TRANSFER_PROTOCOL EDKII_IPMI_BLOB_TRANSFER_PROTOCOL; extern EFI_GUID gEdkiiIpmiBlobTransferProtocolGuid; - -#endif diff --git a/ManageabilityPkg/Include/Protocol/MctpProtocol.h b/ManageabilityPkg/Include/Protocol/MctpProtocol.h index c96b986c44..e18320be4b 100644 --- a/ManageabilityPkg/Include/Protocol/MctpProtocol.h +++ b/ManageabilityPkg/Include/Protocol/MctpProtocol.h @@ -6,8 +6,7 @@ **/ -#ifndef EDKII_MCTP_PROTOCOL_H_ -#define EDKII_MCTP_PROTOCOL_H_ +#pragma once #include @@ -102,5 +101,3 @@ struct _EDKII_MCTP_PROTOCOL { }; extern EFI_GUID gEdkiiMctpProtocolGuid; - -#endif // EDKII_MCTP_PROTOCOL_H_ diff --git a/ManageabilityPkg/Include/Protocol/PldmProtocol.h b/ManageabilityPkg/Include/Protocol/PldmProtocol.h index 1b815c148e..6de96aecdc 100644 --- a/ManageabilityPkg/Include/Protocol/PldmProtocol.h +++ b/ManageabilityPkg/Include/Protocol/PldmProtocol.h @@ -6,8 +6,7 @@ **/ -#ifndef EDKII_PLDM_PROTOCOL_H_ -#define EDKII_PLDM_PROTOCOL_H_ +#pragma once #include @@ -87,5 +86,3 @@ struct _EDKII_PLDM_PROTOCOL { }; extern EFI_GUID gEdkiiPldmProtocolGuid; - -#endif // EDKII_PLDM_PROTOCOL_H_ diff --git a/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferProtocol.h b/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferProtocol.h index 8e1de55b88..8b35907feb 100644 --- a/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferProtocol.h +++ b/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferProtocol.h @@ -6,8 +6,7 @@ **/ -#ifndef EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_H_ -#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_H_ +#pragma once #include @@ -206,5 +205,3 @@ struct _EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL { }; extern EFI_GUID gEdkiiPldmSmbiosTransferProtocolGuid; - -#endif // EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_H_ diff --git a/ManageabilityPkg/Library/ManageabilityTransportKcsLib/ManageabilityTransportKcs.h b/ManageabilityPkg/Library/ManageabilityTransportKcsLib/ManageabilityTransportKcs.h index 05a6492fc8..8ed28dec1f 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportKcsLib/ManageabilityTransportKcs.h +++ b/ManageabilityPkg/Library/ManageabilityTransportKcsLib/ManageabilityTransportKcs.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_TRANSPORT_KCS_LIB_H_ -#define MANAGEABILITY_TRANSPORT_KCS_LIB_H_ +#pragma once #include @@ -107,5 +106,3 @@ KcsRegisterWrite8 ( MANAGEABILITY_TRANSPORT_HARDWARE_IO Address, UINT8 Value ); - -#endif diff --git a/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.h b/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.h index 1ce0d3a8bc..3915ca4b5b 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.h +++ b/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_TRANSPORT_MCTP_LIB_INTERNAL_H_ -#define MANAGEABILITY_TRANSPORT_MCTP_LIB_INTERNAL_H_ +#pragma once #include @@ -22,5 +21,3 @@ typedef struct { } MANAGEABILITY_TRANSPORT_MCTP; #define MANAGEABILITY_TRANSPORT_MCTP_FROM_LINK(a) CR (a, MANAGEABILITY_TRANSPORT_MCTP, Token, MANAGEABILITY_TRANSPORT_MCTP_SIGNATURE) - -#endif // MANAGEABILITY_TRANSPORT_MCTP_LIB_INTERNAL_H_ diff --git a/ManageabilityPkg/Library/ManageabilityTransportSerialLib/Common/ManageabilityTransportSerial.h b/ManageabilityPkg/Library/ManageabilityTransportSerialLib/Common/ManageabilityTransportSerial.h index ac3ad4862d..87319bbe0b 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportSerialLib/Common/ManageabilityTransportSerial.h +++ b/ManageabilityPkg/Library/ManageabilityTransportSerialLib/Common/ManageabilityTransportSerial.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_TRANSPORT_SERIAL_LIB_H_ -#define MANAGEABILITY_TRANSPORT_SERIAL_LIB_H_ +#pragma once #include #include @@ -89,5 +88,3 @@ SerialTransportSendCommand ( IN OUT UINT32 *ResponseDataSize OPTIONAL, OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *AdditionalStatus ); - -#endif diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/ManageabilityTransportSsif.h b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/ManageabilityTransportSsif.h index 264c801973..c8b1e4f981 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/ManageabilityTransportSsif.h +++ b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/ManageabilityTransportSsif.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_TRANSPORT_SSIF_LIB_H_ -#define MANAGEABILITY_TRANSPORT_SSIF_LIB_H_ +#pragma once #include #include @@ -90,5 +89,3 @@ SsifTransportSendCommand ( IN OUT UINT32 *ResponseDataSize OPTIONAL, OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *AdditionalStatus ); - -#endif diff --git a/ManageabilityPkg/Universal/IpmiBlobTransferDxe/InternalIpmiBlobTransfer.h b/ManageabilityPkg/Universal/IpmiBlobTransferDxe/InternalIpmiBlobTransfer.h index 26ff01781f..dc3441e964 100644 --- a/ManageabilityPkg/Universal/IpmiBlobTransferDxe/InternalIpmiBlobTransfer.h +++ b/ManageabilityPkg/Universal/IpmiBlobTransferDxe/InternalIpmiBlobTransfer.h @@ -8,6 +8,8 @@ **/ +#pragma once + #include #include #include @@ -15,9 +17,6 @@ #include #include -#ifndef INTERNAL_IPMI_BLOB_TRANSFER_H_ -#define INTERNAL_IPMI_BLOB_TRANSFER_H_ - #define PROTOCOL_RESPONSE_OVERHEAD (4 * sizeof (UINT8)) // 1 byte completion code + 3 bytes OEN // Subcommands for this protocol @@ -35,7 +34,7 @@ typedef enum { IpmiBlobTransferSubcommandWriteMeta, } IPMI_BLOB_TRANSFER_SUBCOMMANDS; - #pragma pack(1) +#pragma pack(1) typedef struct { UINT8 Oen[3]; @@ -176,7 +175,7 @@ typedef struct { #define IPMI_BLOB_TRANSFER_BLOB_WRITE_META_RESPONSE NULL - #pragma pack() +#pragma pack() /** Calculate CRC-16-CCITT with poly of 0x1021 @@ -416,5 +415,3 @@ IpmiBlobTransferWriteMeta ( IN UINT8 *Data, IN UINT32 WriteLength ); - -#endif diff --git a/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.h b/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.h index eb92d3d82c..4c5067fc34 100644 --- a/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.h +++ b/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.h @@ -7,8 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_IPMI_COMMON_H_ -#define MANAGEABILITY_IPMI_COMMON_H_ +#pragma once #include #include @@ -122,5 +121,3 @@ CommonIpmiSubmitCommand ( OUT UINT8 *ResponseData OPTIONAL, IN OUT UINT32 *ResponseDataSize OPTIONAL ); - -#endif diff --git a/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h b/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h index 04c1d0d8be..6d64b3ac30 100644 --- a/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h +++ b/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_IPMI_PPI_INTERNAL_H_ -#define MANAGEABILITY_IPMI_PPI_INTERNAL_H_ +#pragma once #include #include @@ -27,5 +26,3 @@ typedef struct { UINT32 TransportMaximumPayload; PEI_IPMI_PPI PeiIpmiPpi; } PEI_IPMI_PPI_INTERNAL; - -#endif // MANAGEABILITY_IPMI_PPI_INTERNAL_H_ diff --git a/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.h b/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.h index 72eded719d..fe70ea274c 100644 --- a/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.h +++ b/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_MCTP_COMMON_H_ -#define MANAGEABILITY_MCTP_COMMON_H_ +#pragma once #include #include @@ -135,5 +134,3 @@ CommonMctpSubmitMessage ( IN UINT32 ResponseTimeout, OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *AdditionalTransferError ); - -#endif diff --git a/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h b/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h index d9f59dd663..cf60d78243 100644 --- a/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h +++ b/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MANAGEABILITY_EDKII_PLDM_COMMON_H_ -#define MANAGEABILITY_EDKII_PLDM_COMMON_H_ +#pragma once #include #include @@ -116,5 +115,3 @@ CommonPldmSubmitCommand ( OUT UINT8 *ResponseData OPTIONAL, IN OUT UINT32 *ResponseDataSize ); - -#endif // MANAGEABILITY_EDKII_PLDM_COMMON_H_ From 16b41f7d023d4977b8ae828da814fe3d6a125200 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Thu, 18 Jun 2026 11:58:39 -0400 Subject: [PATCH 088/406] MdeModulePkg: Follow pragma once coding convention Update recent changes in MdeModulePkg to follow the latest EDK II C Coding Standards Specification (5.3) to use '#pragma once' instead of traditional macro-based include guards in header files. https://tianocore-docs.github.io/edk2-CCodingStandardsSpecification/draft/5_source_files/53_include_files.html#53-include-files Signed-off-by: Michael Kubacki --- MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.h | 5 +---- MdeModulePkg/Include/Protocol/CxlIo.h | 5 +---- .../Mock/Include/GoogleTest/Library/MockTpmMeasurementLib.h | 5 +---- .../Include/GoogleTest/Ppi/MockFirmwareVolumeShadowPpi.h | 5 +---- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.h b/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.h index f4af8af226..3a1e4ba6c3 100644 --- a/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.h +++ b/MdeModulePkg/Bus/Pci/CxlDxe/CxlDxe.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef _EFI_CXLDXE_H_ -#define _EFI_CXLDXE_H_ +#pragma once #include "Protocol/CxlIo.h" #include @@ -329,5 +328,3 @@ CxlDriverBindingStop ( IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer ); - -#endif // _EFI_CXLDXE_H_ diff --git a/MdeModulePkg/Include/Protocol/CxlIo.h b/MdeModulePkg/Include/Protocol/CxlIo.h index 30f9eb05f1..4137f40554 100644 --- a/MdeModulePkg/Include/Protocol/CxlIo.h +++ b/MdeModulePkg/Include/Protocol/CxlIo.h @@ -8,8 +8,7 @@ **/ -#ifndef __CXL_IO_H__ -#define __CXL_IO_H__ +#pragma once #include #include "IndustryStandard/Cxl20.h" @@ -150,5 +149,3 @@ struct _EDKII_CXL_IO_PROTOCOL { }; extern EFI_GUID gEdkiiCxlIoProtocolGuid; - -#endif diff --git a/MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockTpmMeasurementLib.h b/MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockTpmMeasurementLib.h index d63746dca3..45186a9766 100644 --- a/MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockTpmMeasurementLib.h +++ b/MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockTpmMeasurementLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_TPM_MEASUREMENT_LIB_H_ -#define MOCK_TPM_MEASUREMENT_LIB_H_ +#pragma once #include #include @@ -31,5 +30,3 @@ struct MockTpmMeasurementLib { ) ); }; - -#endif // MOCK_TPM_MEASUREMENT_LIB_H_ diff --git a/MdeModulePkg/Test/Mock/Include/GoogleTest/Ppi/MockFirmwareVolumeShadowPpi.h b/MdeModulePkg/Test/Mock/Include/GoogleTest/Ppi/MockFirmwareVolumeShadowPpi.h index fd657be43d..3db7f78d17 100644 --- a/MdeModulePkg/Test/Mock/Include/GoogleTest/Ppi/MockFirmwareVolumeShadowPpi.h +++ b/MdeModulePkg/Test/Mock/Include/GoogleTest/Ppi/MockFirmwareVolumeShadowPpi.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_EDKII_PEI_FIRMWARE_VOLUME_SHADOW_PPI_H_ -#define MOCK_EDKII_PEI_FIRMWARE_VOLUME_SHADOW_PPI_H_ +#pragma once #include #include @@ -37,5 +36,3 @@ MOCK_FUNCTION_DEFINITION (MockPeiFirmwareVolumeShadowPpi, FirmwareVolumeShadow, FirmwareVolumeShadow \ }; \ EDKII_PEI_FIRMWARE_VOLUME_SHADOW_PPI *NAME = &NAME##_INSTANCE; - -#endif From fde4a758fd42a1bf9135147b24c854b41cc5b0bf Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Thu, 18 Jun 2026 11:59:20 -0400 Subject: [PATCH 089/406] MdePkg: Follow pragma once coding convention Update recent changes in MdePkg to follow the latest EDK II C Coding Standards Specification (5.3) to use '#pragma once' instead of traditional macro-based include guards in header files. https://tianocore-docs.github.io/edk2-CCodingStandardsSpecification/draft/5_source_files/53_include_files.html#53-include-files Signed-off-by: Michael Kubacki --- .../Mock/Include/GoogleTest/Library/MockDxeServicesLib.h | 5 +---- .../Include/GoogleTest/Library/MockDxeServicesTableLib.h | 5 +---- MdePkg/Test/Mock/Include/GoogleTest/Library/MockIoLib.h | 5 +---- .../Include/GoogleTest/Library/MockMemoryAllocationLib.h | 5 +---- .../Mock/Include/GoogleTest/Library/MockMmServicesTableLib.h | 5 +---- MdePkg/Test/Mock/Include/GoogleTest/Library/MockPcdLib.h | 5 +---- MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciCf8Lib.h | 5 +---- .../Test/Mock/Include/GoogleTest/Library/MockPciExpressLib.h | 5 +---- MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciLib.h | 5 +---- .../Mock/Include/GoogleTest/Library/MockPerformanceLib.h | 5 +---- .../Test/Mock/Include/GoogleTest/Library/MockSerialPortLib.h | 5 +---- MdePkg/Test/Mock/Include/GoogleTest/Library/MockSmmMemLib.h | 5 +---- .../Mock/Include/GoogleTest/Library/MockSynchronizationLib.h | 5 +---- .../Mock/Include/GoogleTest/Library/MockUefiDevicePathLib.h | 5 +---- .../Mock/Include/GoogleTest/Library/MockUefiRuntimeLib.h | 5 +---- 15 files changed, 15 insertions(+), 60 deletions(-) diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDxeServicesLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDxeServicesLib.h index 1408623b19..c6308cdcff 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDxeServicesLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDxeServicesLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef DXE_SERVICES_LIB_H_ -#define DXE_SERVICES_LIB_H_ +#pragma once #include #include @@ -96,5 +95,3 @@ struct MockDxeServicesLib { ) ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDxeServicesTableLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDxeServicesTableLib.h index 5ed384bc25..b57621ca3e 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDxeServicesTableLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDxeServicesTableLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_DXE_SERVICES_TABLE_LIB_H_ -#define MOCK_DXE_SERVICES_TABLE_LIB_H_ +#pragma once #include #include @@ -27,5 +26,3 @@ struct MockDxeServicesTableLib { () ); }; - -#endif // MOCK_UEFI_DXE_SERVICES_TABLE_LIB_H_ diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockIoLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockIoLib.h index 8e9792a4f2..6e5adc5322 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockIoLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockIoLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_IO_LIB_H_ -#define MOCK_IO_LIB_H_ +#pragma once #include #include @@ -958,5 +957,3 @@ struct MockIoLib { ) ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockMemoryAllocationLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockMemoryAllocationLib.h index 1824241d6c..3c957050da 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockMemoryAllocationLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockMemoryAllocationLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_MEMORY_ALLOCATION_LIB_H_ -#define MOCK_MEMORY_ALLOCATION_LIB_H_ +#pragma once #include #include @@ -162,5 +161,3 @@ struct MockMemoryAllocationLib { (IN VOID *Buffer) ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockMmServicesTableLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockMmServicesTableLib.h index 9ebaba35a1..84aec6846e 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockMmServicesTableLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockMmServicesTableLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_MM_SERVICES_TABLE_LIB_H_ -#define MOCK_MM_SERVICES_TABLE_LIB_H_ +#pragma once #include #include @@ -162,5 +161,3 @@ struct MockMmServicesTableLib { ) ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPcdLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPcdLib.h index 50a17556e6..e61801b175 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPcdLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPcdLib.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_PCD_LIB_H_ -#define MOCK_PCD_LIB_H_ +#pragma once #include #include @@ -296,5 +295,3 @@ struct MockPcdLib { () ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciCf8Lib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciCf8Lib.h index 5a58bb6a18..7a6d6ed5f5 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciCf8Lib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciCf8Lib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_IDS_LIB_H_ -#define MOCK_IDS_LIB_H_ +#pragma once #include #include @@ -314,5 +313,3 @@ struct MockPciCf8Lib { ) ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciExpressLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciExpressLib.h index c2b81c0773..cb011c1dbe 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciExpressLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciExpressLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_PCI_EXPRESS_LIB_H_ -#define MOCK_PCI_EXPRESS_LIB_H_ +#pragma once #include #include @@ -41,5 +40,3 @@ struct MockPciExpressLib { ) ); }; - -#endif //MOCK_PCI_EXPRESS_LIB_H_ diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciLib.h index e06894389a..6ea4a062af 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPciLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_PCI_LIB_H_ -#define MOCK_PCI_LIB_H_ +#pragma once #include #include @@ -123,5 +122,3 @@ struct MockPciLib { ) ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPerformanceLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPerformanceLib.h index 1a38f076f7..2523cee8be 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPerformanceLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockPerformanceLib.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_PERFORMANCE_LIB_H_ -#define MOCK_PERFORMANCE_LIB_H_ +#pragma once #include #include @@ -102,5 +101,3 @@ struct MockPerformanceLib { IN UINT32 Identifier) ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSerialPortLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSerialPortLib.h index f85f33c45d..4707903b64 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSerialPortLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSerialPortLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_SERIAL_PORT_LIB_H_ -#define MOCK_SERIAL_PORT_LIB_H_ +#pragma once #include #include @@ -75,5 +74,3 @@ struct MockSerialPortLib { ) ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSmmMemLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSmmMemLib.h index b41de0acb9..1fa1a5f3d5 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSmmMemLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSmmMemLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_SMM_MEM_LIB_H_ -#define MOCK_SMM_MEM_LIB_H_ +#pragma once #include #include @@ -79,5 +78,3 @@ struct MockSmmMemLib { ) ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSynchronizationLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSynchronizationLib.h index d3e6b07f8e..3548eb4b28 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSynchronizationLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockSynchronizationLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_SYNCHRONIZATION_LIB_H_ -#define MOCK_SYNCHRONIZATION_LIB_H_ +#pragma once #include #include @@ -114,5 +113,3 @@ struct MockSynchronizationLib { ) ); }; - -#endif //MOCK_SYNCHRONIZATION_LIB_H_ diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiDevicePathLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiDevicePathLib.h index 5b3a7180c5..b8068895ff 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiDevicePathLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiDevicePathLib.h @@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_UEFI_DEVICE_PATH_LIB_H_ -#define MOCK_UEFI_DEVICE_PATH_LIB_H_ +#pragma once #include #include @@ -155,5 +154,3 @@ struct MockUefiDevicePathLib { (IN CONST CHAR16 *TextDevicePath) ); }; - -#endif diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeLib.h index e5eb051adb..0d4ddf2e45 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeLib.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef MOCK_UEFI_RUNTIME_LIB_H_ -#define MOCK_UEFI_RUNTIME_LIB_H_ +#pragma once #include #include @@ -152,5 +151,3 @@ struct MockUefiRuntimeLib { OUT UINT64 *MaximumVariableSize) ); }; - -#endif From fd7a2a54889bf2318bc788627d45dccccf752c3f Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Thu, 18 Jun 2026 11:59:48 -0400 Subject: [PATCH 090/406] SecurityPkg: Update Tpm2Ptp.h to follow pragma once coding convention Update Tpm2Ptp.h to follow the latest EDK II C Coding Standards Specification (5.3) to use '#pragma once' instead of traditional macro-based include guards in header files. https://tianocore-docs.github.io/edk2-CCodingStandardsSpecification/draft/5_source_files/53_include_files.html#53-include-files Signed-off-by: Michael Kubacki --- SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.h b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.h index 7061414040..3751c5e5dc 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.h +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.h @@ -6,10 +6,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include +#pragma once -#ifndef TPM2_PTP_H_ -#define TPM2_PTP_H_ +#include /** Dump PTP register information. @@ -82,5 +81,3 @@ DumpTpmOutputBlock ( IN CONST UINT8 *OutputBlock, IN UINT32 CommandCode ); - -#endif // TPM2_PTP_H_ From ddd6cc304ef51b442c7e789aa13f391121df93b8 Mon Sep 17 00:00:00 2001 From: Ashraf Ali S Date: Tue, 23 Jun 2026 16:47:10 +0530 Subject: [PATCH 091/406] Maintainers.txt: Add Ashraf as maintainer to BaseTools Signed-off-by: Ashraf Ali S --- Maintainers.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Maintainers.txt b/Maintainers.txt index fe67a289a3..bd5d133f93 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -183,6 +183,7 @@ F: BaseTools/ W: https://www.tianocore.org/tianocore-wiki.github.io/build-tooling/build-workflows/base_tools.html M: Liming Gao [lgao4] M: Guillermo Antonio Palomino Sosa [gapalomi] +M: Ashraf Ali S [AshrafAliS] R: Yuwei Chen [YuweiChen1110] R: Poncho Figueroa [ponchofigueroa] R: Mike Beaton [mikebeaton] From 4b27e8e20b7e67e76cab6593f21b8adb894bcfcc Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Thu, 18 Jun 2026 11:48:08 -0400 Subject: [PATCH 092/406] BaseTools: Fix MODEL_IDENTIFIER_MACRO_PROGMA typo Fixes typo in the constant name. Signed-off-by: Michael Kubacki --- BaseTools/Source/Python/CommonDataClass/DataClass.py | 4 ++-- BaseTools/Source/Python/Ecc/c.py | 2 +- BaseTools/Source/Python/Eot/c.py | 2 +- BaseTools/Source/Python/UPT/Library/DataType.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/CommonDataClass/DataClass.py b/BaseTools/Source/Python/CommonDataClass/DataClass.py index 6f35bd4c8e..7722fa1bc1 100644 --- a/BaseTools/Source/Python/CommonDataClass/DataClass.py +++ b/BaseTools/Source/Python/CommonDataClass/DataClass.py @@ -41,7 +41,7 @@ MODEL_IDENTIFIER_MACRO_IFDEF = 2012 MODEL_IDENTIFIER_MACRO_IFNDEF = 2013 MODEL_IDENTIFIER_MACRO_DEFINE = 2014 MODEL_IDENTIFIER_MACRO_ENDIF = 2015 -MODEL_IDENTIFIER_MACRO_PROGMA = 2016 +MODEL_IDENTIFIER_MACRO_PRAGMA = 2016 MODEL_IDENTIFIER_FUNCTION_CALLING = 2018 MODEL_IDENTIFIER_TYPEDEF = 2017 MODEL_IDENTIFIER_FUNCTION_DECLARATION = 2019 @@ -133,7 +133,7 @@ MODEL_LIST = [('MODEL_UNKNOWN', MODEL_UNKNOWN), ('MODEL_IDENTIFIER_MACRO_IFNDEF', MODEL_IDENTIFIER_MACRO_IFNDEF), ('MODEL_IDENTIFIER_MACRO_DEFINE', MODEL_IDENTIFIER_MACRO_DEFINE), ('MODEL_IDENTIFIER_MACRO_ENDIF', MODEL_IDENTIFIER_MACRO_ENDIF), - ('MODEL_IDENTIFIER_MACRO_PROGMA', MODEL_IDENTIFIER_MACRO_PROGMA), + ('MODEL_IDENTIFIER_MACRO_PRAGMA', MODEL_IDENTIFIER_MACRO_PRAGMA), ('MODEL_IDENTIFIER_FUNCTION_CALLING', MODEL_IDENTIFIER_FUNCTION_CALLING), ('MODEL_IDENTIFIER_TYPEDEF', MODEL_IDENTIFIER_TYPEDEF), ('MODEL_IDENTIFIER_FUNCTION_DECLARATION', MODEL_IDENTIFIER_FUNCTION_DECLARATION), diff --git a/BaseTools/Source/Python/Ecc/c.py b/BaseTools/Source/Python/Ecc/c.py index a3c6a021ad..6b9adad923 100644 --- a/BaseTools/Source/Python/Ecc/c.py +++ b/BaseTools/Source/Python/Ecc/c.py @@ -75,7 +75,7 @@ def GetIdType(Str): elif List[1] == 'endif': Type = DataClass.MODEL_IDENTIFIER_MACRO_ENDIF elif List[1] == 'pragma': - Type = DataClass.MODEL_IDENTIFIER_MACRO_PROGMA + Type = DataClass.MODEL_IDENTIFIER_MACRO_PRAGMA else: Type = DataClass.MODEL_UNKNOWN return Type diff --git a/BaseTools/Source/Python/Eot/c.py b/BaseTools/Source/Python/Eot/c.py index a85564d600..e02d5a0745 100644 --- a/BaseTools/Source/Python/Eot/c.py +++ b/BaseTools/Source/Python/Eot/c.py @@ -107,7 +107,7 @@ def GetIdType(Str): elif List[1] == 'endif': Type = DataClass.MODEL_IDENTIFIER_MACRO_ENDIF elif List[1] == 'pragma': - Type = DataClass.MODEL_IDENTIFIER_MACRO_PROGMA + Type = DataClass.MODEL_IDENTIFIER_MACRO_PRAGMA else: Type = DataClass.MODEL_UNKNOWN return Type diff --git a/BaseTools/Source/Python/UPT/Library/DataType.py b/BaseTools/Source/Python/UPT/Library/DataType.py index c1776a9441..56ba996227 100644 --- a/BaseTools/Source/Python/UPT/Library/DataType.py +++ b/BaseTools/Source/Python/UPT/Library/DataType.py @@ -885,7 +885,7 @@ MODEL_IDENTIFIER_MACRO_IFDEF = 2012 MODEL_IDENTIFIER_MACRO_IFNDEF = 2013 MODEL_IDENTIFIER_MACRO_DEFINE = 2014 MODEL_IDENTIFIER_MACRO_ENDIF = 2015 -MODEL_IDENTIFIER_MACRO_PROGMA = 2016 +MODEL_IDENTIFIER_MACRO_PRAGMA = 2016 MODEL_IDENTIFIER_FUNCTION_CALLING = 2018 MODEL_IDENTIFIER_TYPEDEF = 2017 MODEL_IDENTIFIER_FUNCTION_DECLARATION = 2019 From 35b5565764ea7be7b2cd69626bf9ae264a4fecf8 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Thu, 18 Jun 2026 11:43:37 -0400 Subject: [PATCH 093/406] BaseTools/Ecc: Add check for traditional include guards Adds a new ECC check, `IncludeFileCheckPragmaOnce` (error code 6006), that flags header files using a traditional `#ifndef`/`#define` include guard and recommends `#pragma once` instead. A guard is detected when a '#ifndef NAME' is immediately followed by a valueless '#define NAME' using the same macro name. Feature macros such as '#define FOO 1' and files already using '#pragma once' are not flagged. The check reports against the parsed preprocessor directive rows in the identifier tables rather than the File table. Those rows carry the actual source line number, whereas File-level findings resolve to "line 1" in the report. This gives an accurate line number, to the EccCheck CI plugin, so it can reconcile findings with the changed line ranges of a commit. It uses the binary extension list and the exception list, consistent with the other include file checks. Signed-off-by: Michael Kubacki --- BaseTools/Source/Python/Ecc/Check.py | 69 ++++++++++++++++++++ BaseTools/Source/Python/Ecc/Configuration.py | 3 + BaseTools/Source/Python/Ecc/EccToolError.py | 2 + BaseTools/Source/Python/Ecc/config.ini | 2 + 4 files changed, 76 insertions(+) diff --git a/BaseTools/Source/Python/Ecc/Check.py b/BaseTools/Source/Python/Ecc/Check.py index e0db6cb142..8edca5d0d6 100644 --- a/BaseTools/Source/Python/Ecc/Check.py +++ b/BaseTools/Source/Python/Ecc/Check.py @@ -575,6 +575,75 @@ class Check(object): def IncludeFileCheck(self): self.IncludeFileCheckData() self.IncludeFileCheckSameName() + self.IncludeFileCheckPragmaOnce() + + # Check whether include files use '#pragma once' instead of a traditional #ifndef/#define include guard + def IncludeFileCheckPragmaOnce(self): + if EccGlobalData.gConfig.IncludeFileCheckPragmaOnce == '1' or EccGlobalData.gConfig.IncludeFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': + EdkLogger.quiet("Checking if header file uses '#pragma once' ...") + + # Build the set of header files to check, indexed by File table ID. + HeaderFileSet = {} + SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('h')""" + for Record in EccGlobalData.gDb.TblFile.Exec(SqlCommand): + if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList: + HeaderFileSet[Record[0]] = Record[1] + if not HeaderFileSet: + return + + # + # The preprocessor directives of each source file are parsed into the + # identifier table(s) with their actual line numbers. Reporting against + # those rows (instead of the File table) gives an accurate line number, + # which is required by the incremental EccCheck plugin that filters + # findings by the changed line ranges of a commit. + # + for IdentifierTable in EccGlobalData.gIdentifierTableList: + SqlCommand = """select ID, Value, BelongsToFile from %s + where Model in (%s, %s, %s) + order by BelongsToFile, StartLine, ID""" \ + % (IdentifierTable, + MODEL_IDENTIFIER_MACRO_IFNDEF, + MODEL_IDENTIFIER_MACRO_DEFINE, + MODEL_IDENTIFIER_MACRO_PRAGMA) + RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) + + # Group the parsed directives by the file they belong to. + FileRecordDict = {} + for Record in RecordSet: + if Record[2] not in HeaderFileSet: + continue + FileRecordDict.setdefault(Record[2], []).append(Record) + + for FileId, Records in FileRecordDict.items(): + Path = mws.relpath(HeaderFileSet[FileId], EccGlobalData.gWorkspace) + if EccGlobalData.gException.IsException(ERROR_INCLUDE_FILE_CHECK_PRAGMA_ONCE, Path): + continue + + # Walk the directives in file order. '#pragma once' makes the file + # compliant. Otherwise a '#ifndef NAME' directly followed by a + # valueless '#define NAME' is treated as a traditional include guard. + PragmaOnceFound = False + GuardRecord = None + PrevIfndef = None + for Record in Records: + Content = Record[1].strip().splitlines()[0].strip() if Record[1].strip() else '' + if re.match(r'#\s*pragma\s+once\b', Content): + PragmaOnceFound = True + break + MatchIfndef = re.match(r'#\s*ifndef\s+(\w+)', Content) + if MatchIfndef: + PrevIfndef = (MatchIfndef.group(1), Record) + continue + MatchDefine = re.match(r'#\s*define\s+(\w+)\s*(//.*|/\*.*)?$', Content) + if MatchDefine and PrevIfndef and MatchDefine.group(1) == PrevIfndef[0]: + GuardRecord = PrevIfndef[1] + break + PrevIfndef = None + + if not PragmaOnceFound and GuardRecord is not None: + OtherMsg = "Include file [%s] uses a traditional #ifndef/#define include guard, please use '#pragma once' instead" % Path + EccGlobalData.gDb.TblReport.Insert(ERROR_INCLUDE_FILE_CHECK_PRAGMA_ONCE, OtherMsg=OtherMsg, BelongsToTable=IdentifierTable, BelongsToItem=GuardRecord[0]) # Check whether having include files with same name def IncludeFileCheckSameName(self): diff --git a/BaseTools/Source/Python/Ecc/Configuration.py b/BaseTools/Source/Python/Ecc/Configuration.py index 974d3c1b1b..b435e98475 100644 --- a/BaseTools/Source/Python/Ecc/Configuration.py +++ b/BaseTools/Source/Python/Ecc/Configuration.py @@ -71,6 +71,7 @@ _ConfigFileToInternalTranslation = { "HeaderCheckFunction":"HeaderCheckFunction", "IncludeFileCheckAll":"IncludeFileCheckAll", "IncludeFileCheckData":"IncludeFileCheckData", + "IncludeFileCheckPragmaOnce":"IncludeFileCheckPragmaOnce", "IncludeFileCheckSameName":"IncludeFileCheckSameName", "MetaDataFileCheckAll":"MetaDataFileCheckAll", "MetaDataFileCheckBinaryInfInFdf":"MetaDataFileCheckBinaryInfInFdf", @@ -243,6 +244,8 @@ class Configuration(object): # Check whether include files contain only public or only private data # Check whether include files NOT contain code or define data variables self.IncludeFileCheckData = 1 + # Check whether include files use '#pragma once' instead of a traditional #ifndef/#define include guard + self.IncludeFileCheckPragmaOnce = 1 ## Declarations and Data Types Checking self.DeclarationDataTypeCheckAll = 0 diff --git a/BaseTools/Source/Python/Ecc/EccToolError.py b/BaseTools/Source/Python/Ecc/EccToolError.py index 1b179fc9a2..6ddfb5e2f7 100644 --- a/BaseTools/Source/Python/Ecc/EccToolError.py +++ b/BaseTools/Source/Python/Ecc/EccToolError.py @@ -45,6 +45,7 @@ ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_3 = 5010 ERROR_INCLUDE_FILE_CHECK_ALL = 6000 ERROR_INCLUDE_FILE_CHECK_DATA = 6004 ERROR_INCLUDE_FILE_CHECK_NAME = 6005 +ERROR_INCLUDE_FILE_CHECK_PRAGMA_ONCE = 6006 ERROR_DECLARATION_DATA_TYPE_CHECK_ALL = 7000 ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE = 7001 @@ -139,6 +140,7 @@ gEccErrorMessage = { ERROR_INCLUDE_FILE_CHECK_ALL : "", ERROR_INCLUDE_FILE_CHECK_DATA : "Include files should contain only public or only private data and cannot contain code or define data variables", ERROR_INCLUDE_FILE_CHECK_NAME : "No permission for the include file with same names", + ERROR_INCLUDE_FILE_CHECK_PRAGMA_ONCE : "Include files should use '#pragma once' instead of a traditional #ifndef/#define include guard", ERROR_DECLARATION_DATA_TYPE_CHECK_ALL : "", ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE : "There should be no use of int, unsigned, char, void, long in any .c, .h or .asl files", diff --git a/BaseTools/Source/Python/Ecc/config.ini b/BaseTools/Source/Python/Ecc/config.ini index 943a87af0a..1f260aa0b8 100644 --- a/BaseTools/Source/Python/Ecc/config.ini +++ b/BaseTools/Source/Python/Ecc/config.ini @@ -137,6 +137,8 @@ IncludeFileCheckSameName = 1 # Check whether include files contain only public or only private data # Check whether include files NOT contain code or define data variables IncludeFileCheckData = 1 +# Check whether include files use '#pragma once' instead of a traditional #ifndef/#define include guard +IncludeFileCheckPragmaOnce = 1 # # Declarations and Data Types Checking From e3e93cf092974c5a27ea7e2f63affc1b52db0106 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao Date: Thu, 18 Jun 2026 16:27:06 +0800 Subject: [PATCH 094/406] MdeModulePkg/PciBusDxe: Fix Mem64 BAR handling in IsPciDeviceRejected() IsPciDeviceRejected() masks BAR value with 0xFFFFFFF0 before testing the type bits (2:1) that mark a 64-bit memory BAR, essentially clears them, making the 64-bit BAR code path unreachable and treated as if it were 32-bit. The function rejects a device when BAR looks unprogrammed by comparing if its size mask equals its value. When a 64-bit BAR is mistaken for a 32-bit one, only its lower part is compared, possibly leading a valid BAR being falsely rejected. For example, a 2G BAR with size mask 0x80000000 at 0x180000000 matches and the device is dropped. This code runs during light enumeration (PciEnumeratorLight), used when PCI resources are already assigned by the platform (e.g. Xen HVM, where hvmloader programs the BARs). The rejected device never receives a PciIo handle, so no driver can bind to it. For example, a virtio-vga with a 64-bit BAR vanishes under OVMF on Xen, leaving the guest with no graphics output. Fix by testing the type bits on the raw BAR value before masking. Signed-off-by: Jiaqing Zhao --- MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c index 296c9de3c6..a0f86f2806 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c @@ -2921,13 +2921,12 @@ IsPciDeviceRejected ( // // Mem Bar // - Mask = 0xFFFFFFF0; - TestValue = TestValue & Mask; - + Mask = 0xFFFFFFF0; if ((TestValue & 0x07) == 0x04) { // // Mem64 or PMem64 // + TestValue = TestValue & Mask; BarOffset += sizeof (UINT32); if ((TestValue != 0) && (TestValue == (OldValue & Mask))) { // @@ -2942,6 +2941,7 @@ IsPciDeviceRejected ( // // Mem32 or PMem32 // + TestValue = TestValue & Mask; if ((TestValue != 0) && (TestValue == (OldValue & Mask))) { return TRUE; } From d1806ae8fa90489822f8f64df605af1aecaa0156 Mon Sep 17 00:00:00 2001 From: Pierre Gondois Date: Fri, 5 Jun 2026 17:26:22 +0200 Subject: [PATCH 095/406] DynamicTablesPkg: Clear output parameter before callback invocation BuildSmbiosTable() and BuildSmbiosTableEx() callback are called with uninitialized pointers which might contain garbage data. If one of these function fails, the exit handler uses these uninitialized fields. Set these uninitialized pointers in the caller function. Signed-off-by: Pierre Gondois --- .../SmbiosTableBuilder.c | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c index 8fea73e4c3..7162d0ef7b 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c @@ -207,16 +207,18 @@ BuildAndInstallMultipleSmbiosTables ( UINTN TableCount; UINTN Index; - TableCount = 0; - Status = Generator->BuildSmbiosTableEx ( - Generator, - TableFactoryProtocol, - SmbiosTableInfo, - CfgMgrProtocol, - &SmbiosTable, - &CmObjToken, - &TableCount - ); + SmbiosTable = NULL; + CmObjToken = NULL; + TableCount = 0; + Status = Generator->BuildSmbiosTableEx ( + Generator, + TableFactoryProtocol, + SmbiosTableInfo, + CfgMgrProtocol, + &SmbiosTable, + &CmObjToken, + &TableCount + ); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, From 4ac0ee3fd0222362e45e281fd7f1ac315c8a894f Mon Sep 17 00:00:00 2001 From: Pierre Gondois Date: Fri, 5 Jun 2026 17:44:09 +0200 Subject: [PATCH 096/406] DynamicTablesPkg/SmbiosType4Lib: Fix processor characteristics description Always set the ProcessorArm64SocId bit for arm64 build and conditionally set the Processor64BitCapable bits for 64-bits architectures. Signed-off-by: Pierre Gondois --- .../Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c index 16f8cb812e..cffc869e5f 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c @@ -469,10 +469,13 @@ BuildSmbiosType4TableEx ( CharacteristicFlags = (PROCESSOR_CHARACTERISTIC_FLAGS *)&SmbiosRecord->ProcessorCharacteristics; #if defined (MDE_CPU_AARCH64) - CharacteristicFlags->Processor64BitCapable = 1; + CharacteristicFlags->ProcessorArm64SocId = 1; #endif CharacteristicFlags->ProcessorMultiCore = (CpuCount > 1) ? 1 : 0; CharacteristicFlags->ProcessorHardwareThread = (ThreadCount > CpuCount) ? 1 : 0; + if (MAX_UINTN == MAX_UINT64) { + CharacteristicFlags->Processor64BitCapable = 1; + } SmbiosRecord->CoreCount = (CpuCount < 256) ? CpuCount : 0xff; SmbiosRecord->CoreCount2 = CpuCount; From 1eab31a2870b1f45e98331143648fdf6cbaf5e77 Mon Sep 17 00:00:00 2001 From: Pierre Gondois Date: Mon, 1 Jun 2026 14:16:01 +0200 Subject: [PATCH 097/406] DynamicTablesPkg/CmObjParser: Add missing fields to CmObjParser The following objects are missing some fields in the CmObjParser: - CM_ARCH_COMMON_PROC_HIERARCHY_INFO - CM_ARCH_COMMON_CACHE_INFO Add them. Signed-off-by: Pierre Gondois --- .../ConfigurationManagerObjectParser.c | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index d5009ec1d9..b7f94410bd 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -330,29 +330,39 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonGenericInterruptParser[] = { /** A parser for EArchCommonObjProcHierarchyInfo. */ STATIC CONST CM_OBJ_PARSER CmArchCommonProcHierarchyInfoParser[] = { - { "Token", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, - { "Flags", 4, "0x%x", NULL }, - { "ParentToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, - { "AcpiIdObjectToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, - { "NoOfPrivateResources", 4, "0x%x", NULL }, - { "PrivateResourcesArrayToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, - { "LpiToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, - { "OverrideNameUidEnabled", 1, "%d", NULL }, - { "OverrideName", 2, "0x%x", NULL }, - { "OverrideUid", 4, "0x%x", NULL } + { "Token", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "Flags", 4, "0x%x", NULL }, + { "ParentToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "AcpiIdObjectToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "NoOfPrivateResources", 4, "0x%x", NULL }, + { "PrivateResourcesArrayToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "LpiToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "OverrideNameUidEnabled", 1, "%d", NULL }, + { "OverrideName", 2, "0x%x", NULL }, + { "OverrideUid", 4, "0x%x", NULL }, + { "ProcessorId", 8, "0x%llx", NULL }, + { "SocketDesignation", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, + { "ProcessorManufacturer", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, + { "ProcessorVersion", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, + { "SerialNumber", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, + { "AssetTag", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, + { "PartNumber", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, + { "SocketType", SMBIOS_MAX_STRING_SIZE, "%a", PrintString } }; /** A parser for EArchCommonObjCacheInfo. */ STATIC CONST CM_OBJ_PARSER CmArchCommonCacheInfoParser[] = { - { "Token", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, - { "NextLevelOfCacheToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, - { "Size", 4, "0x%x", NULL }, - { "NumberOfSets", 4, "0x%x", NULL }, - { "Associativity", 4, "0x%x", NULL }, - { "Attributes", 1, "0x%x", NULL }, - { "LineSize", 2, "0x%x", NULL }, - { "CacheId", 4, "0x%x", NULL }, + { "Token", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "NextLevelOfCacheToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "Size", 4, "0x%x", NULL }, + { "NumberOfSets", 4, "0x%x", NULL }, + { "Associativity", 4, "0x%x", NULL }, + { "Attributes", 1, "0x%x", NULL }, + { "LineSize", 2, "0x%x", NULL }, + { "CacheId", 4, "0x%x", NULL }, + { "Level", 4, "0x%x", NULL }, + { "SocketDesignation", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, }; /** A parser for EArchCommonObjCmRef. From 3ca262e05ca5e0b2674f12e9d73046b26011c40f Mon Sep 17 00:00:00 2001 From: Pierre Gondois Date: Fri, 5 Jun 2026 14:15:14 +0200 Subject: [PATCH 098/406] DynamicTablesPkg/CmObjParser: Fix ArmNamespaceObjectParser order Dmc620 have been added at an incorrect index in the ArmNamespaceObjectParser array. Fix the order. Also, rename: - CmArmObjDmc620PmuSocketInfoParser to: - CmArmDmc620PmuSocketInfoParser to follow the other conventional names. Signed-off-by: Pierre Gondois --- .../TableHelperLib/ConfigurationManagerObjectParser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index b7f94410bd..92f9a0c110 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -409,7 +409,7 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonGenericInitiatorAffinityInfoParser[] = { /** A parser for EArmObjDmc620PmuSocketInfo. */ -STATIC CONST CM_OBJ_PARSER CmArmObjDmc620PmuSocketInfoParser[] = { +STATIC CONST CM_OBJ_PARSER CmArmDmc620PmuSocketInfoParser[] = { { "NumDevices", 1, "0x%x", NULL }, { "Dmc620PmuRegInfoToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, }; @@ -1306,11 +1306,11 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArmNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArmObjIdMappingArray, CmArmIdMappingParser), CM_PARSER_ADD_OBJECT (EArmObjSmmuInterruptArray, CmArchCommonGenericInterruptParser), CM_PARSER_ADD_OBJECT (EArmObjCmn600Info, CmArmCmn600InfoParser), - CM_PARSER_ADD_OBJECT (EArmObjDmc620PmuSocketInfo, CmArmObjDmc620PmuSocketInfoParser), - CM_PARSER_ADD_OBJECT (EArmObjDmc620PmuRegInfo, CmArmDmc620PmuRegInfoParser), CM_PARSER_ADD_OBJECT (EArmObjRmr, CmArmRmrInfoParser), CM_PARSER_ADD_OBJECT (EArmObjMemoryRangeDescriptor, CmArmMemoryRangeDescriptorInfoParser), CM_PARSER_ADD_OBJECT (EArmObjEtInfo, CmArmEtInfo), + CM_PARSER_ADD_OBJECT (EArmObjDmc620PmuSocketInfo, CmArmDmc620PmuSocketInfoParser), + CM_PARSER_ADD_OBJECT (EArmObjDmc620PmuRegInfo, CmArmDmc620PmuRegInfoParser), CM_PARSER_ADD_OBJECT_RESERVED (EArmObjMax) }; From c70de6b4ed9c4525781ba5ba0fee94c237712e54 Mon Sep 17 00:00:00 2001 From: Pierre Gondois Date: Mon, 8 Jun 2026 10:36:38 +0200 Subject: [PATCH 099/406] DynamicTablesPkg/CmObjParser: Use common interrupt parser CmArmDmc620PmuRegInfoParser only parses the interrupt field without parsing the interrupt flags. Fix it. Also make CmArmCmn600InfoParser use the common interrupt parser instead of separately printing the interrupt number and flag. Signed-off-by: Pierre Gondois --- .../ConfigurationManagerObjectParser.c | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index 92f9a0c110..dd97db16f8 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -417,26 +417,32 @@ STATIC CONST CM_OBJ_PARSER CmArmDmc620PmuSocketInfoParser[] = { /** A parser for EArmObjDmc620PmuRegInfo. */ STATIC CONST CM_OBJ_PARSER CmArmDmc620PmuRegInfoParser[] = { - { "BaseAddress", 8, "0x%llx", NULL }, - { "Length", 8, "0x%llx", NULL }, - { "PmuIntr", 4, "0x%x", NULL }, + { "BaseAddress", 8, "0x%llx", NULL }, + { "Length", 8, "0x%llx", NULL }, + { "PmuIntr", sizeof (CM_ARCH_COMMON_GENERIC_INTERRUPT), + NULL, NULL, CmArchCommonGenericInterruptParser, + ARRAY_SIZE (CmArchCommonGenericInterruptParser) }, }; /** A parser for EArmObjCmn600Info. */ STATIC CONST CM_OBJ_PARSER CmArmCmn600InfoParser[] = { - { "PeriphBaseAddress", 8, "0x%llx", NULL }, - { "PeriphBaseAddressLength", 8, "0x%llx", NULL }, - { "RootNodeBaseAddress", 8, "0x%llx", NULL }, - { "DtcCount", 1, "0x%x", NULL }, - { "DtcInterrupt[0]", 4, "0x%x", NULL }, - { "DtcFlags[0]", 4, "0x%x", NULL }, - { "DtcInterrupt[1]", 4, "0x%x", NULL }, - { "DtcFlags[1]", 4, "0x%x", NULL }, - { "DtcInterrupt[2]", 4, "0x%x", NULL }, - { "DtcFlags[2]", 4, "0x%x", NULL }, - { "DtcInterrupt[3]", 4, "0x%x", NULL }, - { "DtcFlags[3]", 4, "0x%x", NULL } + { "PeriphBaseAddress", 8, "0x%llx", NULL }, + { "PeriphBaseAddressLength", 8, "0x%llx", NULL }, + { "RootNodeBaseAddress", 8, "0x%llx", NULL }, + { "DtcCount", 1, "0x%x", NULL }, + { "DtcIntr[0]", sizeof (CM_ARCH_COMMON_GENERIC_INTERRUPT), + NULL, NULL, CmArchCommonGenericInterruptParser, + ARRAY_SIZE (CmArchCommonGenericInterruptParser) }, + { "DtcIntr[1]", sizeof (CM_ARCH_COMMON_GENERIC_INTERRUPT), + NULL, NULL, CmArchCommonGenericInterruptParser, + ARRAY_SIZE (CmArchCommonGenericInterruptParser) }, + { "DtcIntr[2]", sizeof (CM_ARCH_COMMON_GENERIC_INTERRUPT), + NULL, NULL, CmArchCommonGenericInterruptParser, + ARRAY_SIZE (CmArchCommonGenericInterruptParser) }, + { "DtcIntr[3]", sizeof (CM_ARCH_COMMON_GENERIC_INTERRUPT), + NULL, NULL, CmArchCommonGenericInterruptParser, + ARRAY_SIZE (CmArchCommonGenericInterruptParser) }, }; /** A parser for the EFI_ACPI_6_3_GENERIC_ADDRESS_STRUCTURE structure. From 97f069bf30dc821ae2c8f90d2f9c741ad4ee9247 Mon Sep 17 00:00:00 2001 From: Qihang Gao Date: Wed, 29 Apr 2026 15:33:27 +0800 Subject: [PATCH 100/406] RedfishPkg: Remove unnecessary Depex section in library modules Libraries that may be consumed by UEFI_DRIVER should not have depex section for UEFI_DRIVER. The INF specification said: If the Module is a Library, then a [Depex] section is optional. Regarding HiiUtilityLib, RedfishDebugLib and RedfishHttpLib, they don't have additional dependence, so the Depex sections should be removed to ensure no adverse impact on the UEFI_DRIVER. Signed-off-by: Qihang Gao --- RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf | 3 --- RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf | 3 --- RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf | 4 ---- 3 files changed, 10 deletions(-) diff --git a/RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf b/RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf index cab3f8a0ee..a48de5f988 100644 --- a/RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf +++ b/RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf @@ -57,6 +57,3 @@ gEfiUnicodeCollation2ProtocolGuid gEfiRegularExpressionProtocolGuid gEfiUserManagerProtocolGuid - -[Depex] - TRUE diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf index 42ff321b48..b1e21724f2 100644 --- a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf +++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf @@ -38,6 +38,3 @@ [FixedPcd] gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory - -[Depex] - TRUE diff --git a/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf b/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf index fd53b8c2ed..1aa827c3d8 100644 --- a/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf +++ b/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf @@ -37,7 +37,3 @@ [Protocols] gEdkIIRedfishHttpProtocolGuid ## CONSUMES ## - -[depex] - TRUE - From 39d8052bc682cd80c990377be730c8019a38e932 Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Fri, 26 Jun 2026 16:42:56 +0100 Subject: [PATCH 101/406] ShellPkg: Fix SMBIOS Type 26 probe decoding Decode the Type 26 Voltage Probe Location and Status fields according to the SMBIOS 3.9.0 specification, section 7.27, "Voltage Probe (Type 26)". Table 95, "Voltage Probe: Location and Status fields", defines bits 4:0 as the Location field and bits 7:5 as the Status field. smbiosview was decoding these fields in the opposite order, causing the displayed voltage probe location and status to be swapped. Signed-off-by: Varshit Pandya --- .../UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c index d8ea4bead8..cbfb281c99 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c @@ -6,7 +6,7 @@ Copyright (c) 2005 - 2024, Intel Corporation. All rights reserved.
(C) Copyright 2016-2019 Hewlett Packard Enterprise Development LP
Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. - Copyright (c) 2023, Arm Limited. All rights reserved.
+ Copyright (c) 2023-2026, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -5020,7 +5020,7 @@ DisplayVPLocation ( { UINT8 Loc; - Loc = (UINT8)((Key & 0xE0) >> 5); + Loc = (UINT8)(Key & 0x1F); ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_VOLTAGE_PROBE_LOC), gShellDebug1HiiHandle); PRINT_INFO_OPTION (Loc, Option); PRINT_TABLE_ITEM (VPLocationTable, Loc); @@ -5040,7 +5040,7 @@ DisplayVPStatus ( { UINT8 Status; - Status = (UINT8)(Key & 0x1F); + Status = (UINT8)((Key & 0xE0) >> 5); ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_VOLTAGE_PROBE_STATUS), gShellDebug1HiiHandle); PRINT_INFO_OPTION (Status, Option); PRINT_TABLE_ITEM (VPStatusTable, Status); From 4ad28a8588f1ca8e0f448bfdf2e092171d61b742 Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Fri, 26 Jun 2026 16:45:35 +0100 Subject: [PATCH 102/406] ShellPkg: ShellPkg: Fix SMBIOS Type 28 probe labels Use a Temperature Probe specific HII string when displaying the Type 28 Location field in smbiosview. The Type 28 decoder was using the Voltage Probe location label, causing temperature probe records to be displayed with the wrong field name. Signed-off-by: Varshit Pandya --- .../UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c | 4 ++-- .../SmbiosView/SmbiosViewStrings.uni | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c index cbfb281c99..4dce68dccf 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c @@ -5101,7 +5101,7 @@ DisplayTemperatureProbeStatus ( UINT8 Status; Status = (UINT8)((Key & 0xE0) >> 5); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_TEMP_PROBE), gShellDebug1HiiHandle); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_TEMP_PROBE_STATUS), gShellDebug1HiiHandle); PRINT_INFO_OPTION (Status, Option); PRINT_TABLE_ITEM (TemperatureProbeStatusTable, Status); } @@ -5121,7 +5121,7 @@ DisplayTemperatureProbeLoc ( UINT8 Loc; Loc = (UINT8)(Key & 0x1F); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_VOLTAGE_PROBE_LOC), gShellDebug1HiiHandle); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_TEMP_PROBE_LOC), gShellDebug1HiiHandle); PRINT_INFO_OPTION (Loc, Option); PRINT_TABLE_ITEM (TemperatureProbeLocTable, Loc); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni index 10edc12aa7..898a449796 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni @@ -6,6 +6,7 @@ // (C) Copyright 2015-2019 Hewlett Packard Enterprise Development LP
// Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +// Copyright (c) 2026 Arm Limited. All rights reserved.
// SPDX-License-Identifier: BSD-2-Clause-Patent // // Module Name: @@ -452,7 +453,8 @@ #string STR_SMBIOSVIEW_QUERYTABLE_VOLTAGE_PROBE_STATUS #language en-US "Voltage Probe - Status:" #string STR_SMBIOSVIEW_QUERYTABLE_COOLING_DEV_STATUS #language en-US "Cooling Device - Status: " #string STR_SMBIOSVIEW_QUERYTABLE_COOLING_DEV_TYPE #language en-US "Cooling Device - Type: " -#string STR_SMBIOSVIEW_QUERYTABLE_TEMP_PROBE #language en-US "Temperature Probe - Status:" +#string STR_SMBIOSVIEW_QUERYTABLE_TEMP_PROBE_STATUS #language en-US "Temperature Probe - Status:" +#string STR_SMBIOSVIEW_QUERYTABLE_TEMP_PROBE_LOC #language en-US "Temperature Probe - Location:" #string STR_SMBIOSVIEW_QUERYTABLE_ELEC_PROBE_STATUS #language en-US "Electrical Current Probe - Status:" #string STR_SMBIOSVIEW_QUERYTABLE_ELEC_PROBE_LOC #language en-US "Electrical Current Probe - Location:" #string STR_SMBIOSVIEW_QUERYTABLE_MANAGEMENT_DEV_TYPE #language en-US "Management Device Type:" From 4f475ba54293b5da8fe375a9cdf97a5da1464011 Mon Sep 17 00:00:00 2001 From: 20000419 Date: Sat, 18 Apr 2026 22:33:46 +0800 Subject: [PATCH 103/406] SecurityPkg/AuthVariableLib: harden signature list filtering Signed-off-by: 20000419 --- .../Library/AuthVariableLib/AuthService.c | 94 ++++++++++++++++--- .../AuthVariableLib/AuthServiceInternal.h | 4 + 2 files changed, 86 insertions(+), 12 deletions(-) diff --git a/SecurityPkg/Library/AuthVariableLib/AuthService.c b/SecurityPkg/Library/AuthVariableLib/AuthService.c index c6e2241c5b..06adac69e8 100644 --- a/SecurityPkg/Library/AuthVariableLib/AuthService.c +++ b/SecurityPkg/Library/AuthVariableLib/AuthService.c @@ -274,6 +274,7 @@ AuthServiceInternalUpdateVariableWithTimeStamp ( IN EFI_TIME *TimeStamp ) { + EFI_STATUS Status; EFI_STATUS FindStatus; VOID *OrgData; UINTN OrgDataSize; @@ -299,12 +300,15 @@ AuthServiceInternalUpdateVariableWithTimeStamp ( // For variables with formatted as EFI_SIGNATURE_LIST, the driver shall not perform an append of // EFI_SIGNATURE_DATA values that are already part of the existing variable value. // - FilterSignatureList ( - OrgData, - OrgDataSize, - Data, - &DataSize - ); + Status = FilterSignatureList ( + OrgData, + OrgDataSize, + Data, + &DataSize + ); + if (EFI_ERROR (Status)) { + return Status; + } } } @@ -1041,6 +1045,61 @@ ProcessVariable ( return Status; } +/** + Validate that an EFI_SIGNATURE_LIST can be traversed safely. + + This helper performs only the structural checks needed by FilterSignatureList() + before walking list entries. Callers still perform the full semantic validation + through CheckSignatureListFormat(). + + @param[in] SigList Pointer to the EFI_SIGNATURE_LIST header. + @param[in] BufferSize Bytes available starting at SigList. + @param[out] SigCount Number of signature entries in SigList. + + @retval EFI_SUCCESS The signature list layout is self-consistent. + @retval EFI_INVALID_PARAMETER The signature list header is malformed. + +**/ +STATIC +EFI_STATUS +GetSignatureListEntryCount ( + IN EFI_SIGNATURE_LIST *SigList, + IN UINTN BufferSize, + OUT UINTN *SigCount + ) +{ + UINTN HeaderSize; + UINTN PayloadSize; + + if ((SigList == NULL) || (SigCount == NULL)) { + return EFI_INVALID_PARAMETER; + } + + if ((BufferSize < sizeof (EFI_SIGNATURE_LIST)) || + (SigList->SignatureListSize < sizeof (EFI_SIGNATURE_LIST)) || + (SigList->SignatureListSize > BufferSize)) + { + return EFI_INVALID_PARAMETER; + } + + HeaderSize = sizeof (EFI_SIGNATURE_LIST) + SigList->SignatureHeaderSize; + if ((HeaderSize < sizeof (EFI_SIGNATURE_LIST)) || (HeaderSize > SigList->SignatureListSize)) { + return EFI_INVALID_PARAMETER; + } + + if (SigList->SignatureSize == 0) { + return EFI_INVALID_PARAMETER; + } + + PayloadSize = SigList->SignatureListSize - HeaderSize; + if ((PayloadSize % SigList->SignatureSize) != 0) { + return EFI_INVALID_PARAMETER; + } + + *SigCount = PayloadSize / SigList->SignatureSize; + return EFI_SUCCESS; +} + /** Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data. @@ -1049,6 +1108,10 @@ ProcessVariable ( @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST. @param[in, out] NewDataSize Size of NewData buffer. + @retval EFI_SUCCESS Duplicated signatures were filtered successfully. + @retval EFI_INVALID_PARAMETER Input signature list data is malformed. + @retval EFI_OUT_OF_RESOURCES Failed to allocate scratch buffer. + **/ EFI_STATUS FilterSignatureList ( @@ -1088,22 +1151,29 @@ FilterSignatureList ( Tail = TempData; NewCertList = (EFI_SIGNATURE_LIST *)NewData; - while ((*NewDataSize > 0) && (*NewDataSize >= NewCertList->SignatureListSize)) { - NewCert = (EFI_SIGNATURE_DATA *)((UINT8 *)NewCertList + sizeof (EFI_SIGNATURE_LIST) + NewCertList->SignatureHeaderSize); - NewCertCount = (NewCertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - NewCertList->SignatureHeaderSize) / NewCertList->SignatureSize; + while (*NewDataSize > 0) { + Status = GetSignatureListEntryCount (NewCertList, *NewDataSize, &NewCertCount); + if (EFI_ERROR (Status)) { + return Status; + } + NewCert = (EFI_SIGNATURE_DATA *)((UINT8 *)NewCertList + sizeof (EFI_SIGNATURE_LIST) + NewCertList->SignatureHeaderSize); CopiedCount = 0; for (Index = 0; Index < NewCertCount; Index++) { IsNewCert = TRUE; Size = DataSize; CertList = (EFI_SIGNATURE_LIST *)Data; - while ((Size > 0) && (Size >= CertList->SignatureListSize)) { + while (Size > 0) { + Status = GetSignatureListEntryCount (CertList, Size, &CertCount); + if (EFI_ERROR (Status)) { + return Status; + } + if (CompareGuid (&CertList->SignatureType, &NewCertList->SignatureType) && (CertList->SignatureSize == NewCertList->SignatureSize)) { - Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize); - CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize; + Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize); for (Index2 = 0; Index2 < CertCount; Index2++) { // // Iterate each Signature Data in this Signature List. diff --git a/SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h b/SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h index 7e45402594..6d9984d151 100644 --- a/SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h +++ b/SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h @@ -180,6 +180,10 @@ CleanCertsFromDb ( @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST. @param[in, out] NewDataSize Size of NewData buffer. + @retval EFI_SUCCESS Duplicated signatures were filtered successfully. + @retval EFI_INVALID_PARAMETER Input signature list data is malformed. + @retval EFI_OUT_OF_RESOURCES Failed to allocate scratch buffer. + **/ EFI_STATUS FilterSignatureList ( From 23ebccb46c5c9e594fe777fef9ede4de2e4b584d Mon Sep 17 00:00:00 2001 From: Jared Pan Date: Tue, 23 Jun 2026 10:36:15 +0800 Subject: [PATCH 104/406] MdeModulePkg/UsbBusDxe: Improve USB enumerating process The patch enhances the USB enumeration process in EDK2 to improve compatibility with non-standards-compliant devices that may fail during standard enumeration sequences. The suggested solution is based on USB specifications and references implementations from both Linux and Windows environments. [Suggested solution] - Integrated a retry mechanism to sequentially execute enumeration scripts, inspired by the enumeration flows of Windows, Linux, and EDK2. This improves robustness when handling corner-case devices. - Do sanity check while the device report the device descriptor. - AMD XHCI might need to wait for more time while sending the CLEAR_FEATURE reuqest. Signed-off-by: Marlboro Chuang Signed-off-by: Jared Pan --- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h | 11 ++++ MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c | 50 ++++++++++++-- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 76 +++++++++++++++++++--- 3 files changed, 121 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h index 10f4533b5d..ac0cbab359 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h @@ -142,6 +142,16 @@ typedef struct _USB_HUB_API USB_HUB_API; #define USB_BUS_FROM_THIS(a) \ CR(a, USB_BUS, BusId, USB_BUS_SIGNATURE) +#define USB_CONFIG_DESC_DEF_ALLOC_LEN 255 + +typedef enum { + UsbEnumScriptEdk2 = 0, // 0 :EDK2 flow + UsbEnumScriptRsrv = 1, // 1 :Reserved flow - EDK2 + UsbEnumScriptLinux = 2, // 2 :Linux flow + UsbEnumScriptWin = 3, // 3 :Window flow + UsbEnumScriptUnknown = 0xFF, // 0xff:Unknow flow +} USB_ENUM_SCRIPT_TYPE; + // // Used to locate USB_BUS // UsbBusProtocol is the private protocol. @@ -187,6 +197,7 @@ struct _USB_DEVICE { UINT8 ParentPort; // Start at 0 UINT8 Tier; BOOLEAN DisconnectFail; + UINT8 EnumScript; }; // diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c index 8b078e7e49..f0c3cc7ced 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c @@ -611,6 +611,21 @@ UsbGetDevDesc ( if (EFI_ERROR (Status)) { gBS->FreePool (DevDesc); } else { + // Do DevDesc sanity check + if ( (DevDesc->Desc.DescriptorType != USB_DESC_TYPE_DEVICE) + || (DevDesc->Desc.Length != sizeof (EFI_USB_DEVICE_DESCRIPTOR)) + || ( (UsbDev->Speed != EFI_USB_SPEED_SUPER) + && (DevDesc->Desc.MaxPacketSize0 != 8) + && (DevDesc->Desc.MaxPacketSize0 != 16) + && (DevDesc->Desc.MaxPacketSize0 != 32) + && (DevDesc->Desc.MaxPacketSize0 != 64)) + || (DevDesc->Desc.NumConfigurations == 0)) + { + gBS->FreePool (DevDesc); + Status = EFI_DEVICE_ERROR; + return Status; + } + UsbDev->DevDesc = DevDesc; } @@ -751,12 +766,31 @@ UsbGetOneConfig ( EFI_USB_CONFIG_DESCRIPTOR Desc; EFI_STATUS Status; VOID *Buf; + UINT8 BufDesc[USB_CONFIG_DESC_DEF_ALLOC_LEN]; // // First get four bytes which contains the total length // for this configuration. // - Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_CONFIG, Index, 0, &Desc, 8); + switch (UsbDev->EnumScript) { + case UsbEnumScriptWin: + ZeroMem (BufDesc, USB_CONFIG_DESC_DEF_ALLOC_LEN); + Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_CONFIG, Index, 0, BufDesc, USB_CONFIG_DESC_DEF_ALLOC_LEN); + if (!EFI_ERROR (Status)) { + CopyMem (&Desc, BufDesc, sizeof (EFI_USB_CONFIG_DESCRIPTOR)); + } + + break; + case UsbEnumScriptLinux: + Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_CONFIG, Index, 0, &Desc, sizeof (EFI_USB_CONFIG_DESCRIPTOR)); + break; + case UsbEnumScriptRsrv: + case UsbEnumScriptEdk2: + case UsbEnumScriptUnknown: + default: + Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_CONFIG, Index, 0, &Desc, 8); + break; + } if (EFI_ERROR (Status)) { DEBUG (( @@ -784,13 +818,17 @@ UsbGetOneConfig ( return NULL; } - Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_CONFIG, Index, 0, Buf, Desc.TotalLength); + if ((UsbDev->EnumScript == UsbEnumScriptWin) && (Desc.TotalLength <= USB_CONFIG_DESC_DEF_ALLOC_LEN)) { + CopyMem (Buf, BufDesc, Desc.TotalLength); + } else { + Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_CONFIG, Index, 0, Buf, Desc.TotalLength); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "UsbGetOneConfig: failed to get full descript - %r\n", Status)); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "UsbGetOneConfig: failed to get full descript - %r\n", Status)); - FreePool (Buf); - return NULL; + FreePool (Buf); + return NULL; + } } return Buf; diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c index 4b8d01d7fb..82c9a4f9ef 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c @@ -233,6 +233,7 @@ UsbCreateDevice ( Device->ParentIf = ParentIf; Device->ParentPort = ParentPort; Device->Tier = (UINT8)(ParentIf->Device->Tier + 1); + Device->EnumScript = 0; return Device; } @@ -673,6 +674,8 @@ UsbEnumerateNewDev ( UINTN Address; UINT8 Config; EFI_STATUS Status; + EFI_STATUS OriginalStatus; + UINT8 RetryCount; Parent = HubIf->Device; Bus = Parent->Bus; @@ -706,6 +709,9 @@ UsbEnumerateNewDev ( return EFI_OUT_OF_RESOURCES; } + RetryCount = 3; + +DeviceRetry: // // OK, now identify the device speed. After reset, hub // fully knows the actual device speed. @@ -717,9 +723,28 @@ UsbEnumerateNewDev ( goto ON_ERROR; } + // + // RetryCount is used to execute the different enum scripts. + // Current the diffrence is only for getting Configuration Descriptor. + // +--------------------+---+----------------------------------------------------+ + // | UsbEnumScriptWin | 3 | UsbGetOneConfig get the descriptor with 255 bytes | + // +--------------------+---+----------------------------------------------------+ + // | UsbEnumScriptLinux | 2 | UsbGetOneConfig get the descriptor with | + // | | | ConfigurationDescriptor Length. | + // +--------------------+---+----------------------------------------------------+ + // | UsbEnumScriptRsrv | 1 | UsbGetOneConfig get the descriptor with 8 bytes | + // | | | and then get the total length. (Same as Edk2 flow) | + // +--------------------+---+----------------------------------------------------+ + // | UsbEnumScriptEdk2 | 0 | UsbGetOneConfig get the descriptor with 8 bytes | + // | | | and then get the total length. | + // +--------------------+--------------------------------------------------------+ + // + Child->EnumScript = RetryCount; + if (!USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_CONNECTION)) { DEBUG ((DEBUG_ERROR, "UsbEnumerateNewDev: No device present at port %d\n", Port)); - Status = EFI_NOT_FOUND; + Status = EFI_NOT_FOUND; + RetryCount = 0; goto ON_ERROR; } else if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_SUPER_SPEED)) { Child->Speed = EFI_USB_SPEED_SUPER; @@ -773,17 +798,23 @@ UsbEnumerateNewDev ( // ADDRESS state. Address zero is reserved for root hub. // ASSERT (Bus->MaxDevices <= 256); - for (Address = 1; Address < Bus->MaxDevices; Address++) { - if (Bus->Devices[Address] == NULL) { - break; + if (Child->Address == 0) { + for (Address = 1; Address < Bus->MaxDevices; Address++) { + if (Bus->Devices[Address] == NULL) { + break; + } } - } - if (Address >= Bus->MaxDevices) { - DEBUG ((DEBUG_ERROR, "UsbEnumerateNewDev: address pool is full for port %d\n", Port)); + if (Address >= Bus->MaxDevices) { + DEBUG ((DEBUG_ERROR, "UsbEnumerateNewDev: address pool is full for port %d\n", Port)); - Status = EFI_ACCESS_DENIED; - goto ON_ERROR; + Status = EFI_ACCESS_DENIED; + goto ON_ERROR; + } + } else { + Address = Child->Address; + Child->Address = 0; + Bus->Devices[Address] = NULL; } Status = UsbSetAddress (Child, (UINT8)Address); @@ -858,6 +889,31 @@ UsbEnumerateNewDev ( return EFI_SUCCESS; ON_ERROR: + // + // Do the error handling with retry counter. + // + OriginalStatus = Status; + Status = HubApi->GetPortStatus (HubIf, Port, &PortState); + if (EFI_ERROR (Status) || (!USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_CONNECTION))) { + DEBUG ((DEBUG_ERROR, "Device is gone. Don't reset the port\n")); + Status = EFI_NOT_FOUND; + } + + if (!EFI_ERROR (Status) && (RetryCount > 0)) { + RetryCount--; + DEBUG ((DEBUG_INFO, "Reset the port due to Error\n")); + if ((Child != NULL) && (Child->DevDesc != NULL)) { + UsbFreeDevDesc (Child->DevDesc); + Child->DevDesc = NULL; + } + + Status = HubApi->ResetPort (HubIf, Port); + if (!EFI_ERROR (Status)) { + gBS->Stall (USB_WAIT_PORT_STABLE_STALL); + goto DeviceRetry; + } + } + // // If reach here, it means the enumeration process on a given port is interrupted due to error. // The s/w resources, including the assigned address(Address) and the allocated usb device data @@ -872,7 +928,7 @@ ON_ERROR: // // EDKII UHCI/EHCI doesn't get impacted as it's make sense to reserve s/w resource till it gets unplugged. // - return Status; + return OriginalStatus; } /** From 8c0dea946f5187016fc79e723275f9c94024d725 Mon Sep 17 00:00:00 2001 From: Jared Pan Date: Tue, 23 Jun 2026 11:43:07 +0800 Subject: [PATCH 105/406] MdeModulePkg/UsbBusDxe: Manufacturer String Descriptor Caching Certain devices require immediate follow-up commands after reading the LANGID string to fetch Manufacturer, Product, or SerialNumber strings. [Suggested Solution] These strings are now cached after initial retrieval to allow UsbIoGetStringDescriptor() to return them directly, improving efficiency and stability. Signed-off-by: Marlboro Chuang Signed-off-by: Jared Pan --- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h | 2 +- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c | 168 +++++++++++++++++++---- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h | 3 + 3 files changed, 145 insertions(+), 28 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h index ac0cbab359..bc4f7ceb02 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h @@ -289,7 +289,7 @@ struct _USB_HUB_API { USB_HUB_RELEASE Release; }; -#define USB_US_LAND_ID 0x0409 +#define USB_US_LANG_ID 0x0409 #define DEVICE_PATH_LIST_ITEM_SIGNATURE SIGNATURE_32('d','p','l','i') typedef struct _DEVICE_PATH_LIST_ITEM { diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c index f0c3cc7ced..3f55c3a381 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c @@ -114,6 +114,18 @@ UsbFreeDevDesc ( FreePool (DevDesc->Configs); } + if (DevDesc->StrDescManufacturerUS != NULL) { + FreePool (DevDesc->StrDescManufacturerUS); + } + + if (DevDesc->StrDescProductUS != NULL) { + FreePool (DevDesc->StrDescProductUS); + } + + if (DevDesc->StrDescSerialNumberUS != NULL) { + FreePool (DevDesc->StrDescSerialNumberUS); + } + FreePool (DevDesc); } @@ -654,41 +666,93 @@ UsbGetOneString ( EFI_USB_STRING_DESCRIPTOR Desc; EFI_STATUS Status; UINT8 *Buf; + EFI_USB_STRING_DESCRIPTOR *CachedDesc; + + CachedDesc = NULL; // - // First get two bytes which contains the string length. + // If the String is cached and LangId = US, just return the cached string descriptor // - Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_STRING, Index, LangId, &Desc, 2); + if ((LangId == USB_US_LANG_ID) && (Index > 0)) { + Buf = NULL; + + if (Index == UsbDev->DevDesc->Desc.StrManufacturer) { + if (UsbDev->DevDesc->StrDescManufacturerUS != NULL) { + CachedDesc = (EFI_USB_STRING_DESCRIPTOR *)UsbDev->DevDesc->StrDescManufacturerUS; + Buf = AllocateZeroPool (CachedDesc->Length); + CopyMem (Buf, (UINT8 *)CachedDesc, CachedDesc->Length); + } + } else if (Index == UsbDev->DevDesc->Desc.StrProduct) { + if (UsbDev->DevDesc->StrDescProductUS != NULL) { + CachedDesc = (EFI_USB_STRING_DESCRIPTOR *)UsbDev->DevDesc->StrDescProductUS; + Buf = AllocateZeroPool (CachedDesc->Length); + CopyMem (Buf, (UINT8 *)CachedDesc, CachedDesc->Length); + } + } else if (Index == UsbDev->DevDesc->Desc.StrSerialNumber) { + if (UsbDev->DevDesc->StrDescSerialNumberUS != NULL) { + CachedDesc = (EFI_USB_STRING_DESCRIPTOR *)UsbDev->DevDesc->StrDescSerialNumberUS; + Buf = AllocateZeroPool (CachedDesc->Length); + CopyMem (Buf, (UINT8 *)CachedDesc, CachedDesc->Length); + } + } else { + Buf = NULL; + } + + if (Buf != NULL) { + return (EFI_USB_STRING_DESCRIPTOR *)Buf; + } + } // - // Reject if Length even cannot cover itself, or odd because Unicode string byte length should be even. + // Copy the mechanism from Linux Driver to get the better compatibility. see usb_string_sub. // + Buf = AllocateZeroPool (256); + Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_STRING, Index, LangId, Buf, 255); if (EFI_ERROR (Status) || - (Desc.Length < OFFSET_OF (EFI_USB_STRING_DESCRIPTOR, Length) + sizeof (Desc.Length)) || - (Desc.Length % 2 != 0) - ) + (((EFI_USB_STRING_DESCRIPTOR *)Buf)->Length < + OFFSET_OF (EFI_USB_STRING_DESCRIPTOR, Length) + + sizeof (((EFI_USB_STRING_DESCRIPTOR *)Buf)->Length)) || + (((EFI_USB_STRING_DESCRIPTOR *)Buf)->Length % 2 != 0)) { - return NULL; - } - - Buf = AllocateZeroPool (Desc.Length); - - if (Buf == NULL) { - return NULL; - } - - Status = UsbCtrlGetDesc ( - UsbDev, - USB_DESC_TYPE_STRING, - Index, - LangId, - Buf, - Desc.Length - ); - - if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "UsbGetOneString: Get 255 bytes path failed, Status = %r\n", Status)); FreePool (Buf); - return NULL; + Buf = NULL; + + // + // First get two bytes which contains the string length. + // + Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_STRING, Index, LangId, &Desc, 2); + + // + // Reject if Length even cannot cover itself, or odd because Unicode string byte length should be even. + // + if (EFI_ERROR (Status) || + (Desc.Length < OFFSET_OF (EFI_USB_STRING_DESCRIPTOR, Length) + sizeof (Desc.Length)) || + (Desc.Length % 2 != 0) + ) + { + return NULL; + } + + Buf = AllocateZeroPool (Desc.Length); + + if (Buf == NULL) { + return NULL; + } + + Status = UsbCtrlGetDesc ( + UsbDev, + USB_DESC_TYPE_STRING, + Index, + LangId, + Buf, + Desc.Length + ); + + if (EFI_ERROR (Status)) { + FreePool (Buf); + return NULL; + } } return (EFI_USB_STRING_DESCRIPTOR *)Buf; @@ -740,8 +804,58 @@ UsbBuildLangTable ( UsbDev->TotalLangId = (UINT16)Max; -ON_EXIT: + // + // Some SMART Technologies key says that it supports LangId=0 only, but it + // responds to USB_US_LANG_ID (English). This is a workaround for all such keys. + // + if ((UsbDev->TotalLangId == 1) && (UsbDev->LangId[0] == 0)) { + UsbDev->LangId[0] = USB_US_LANG_ID; + } + + // + // Some devices need to get the string immediately after SW get the first String descriptor + // for supported language. + // gBS->FreePool (Desc); + Desc = NULL; + if (UsbDev->DevDesc->Desc.StrManufacturer != 0) { + Desc = UsbGetOneString (UsbDev, UsbDev->DevDesc->Desc.StrManufacturer, UsbDev->LangId[0]); + if ((Desc != NULL) && (UsbDev->LangId[0] == USB_US_LANG_ID)) { + UsbDev->DevDesc->StrDescManufacturerUS = (UINT8 *)Desc; + } else if (Desc != NULL) { + gBS->FreePool (Desc); + } + + Desc = NULL; + } + + if (UsbDev->DevDesc->Desc.StrProduct != 0) { + Desc = UsbGetOneString (UsbDev, UsbDev->DevDesc->Desc.StrProduct, UsbDev->LangId[0]); + if ((Desc != NULL) && (UsbDev->LangId[0] == USB_US_LANG_ID)) { + UsbDev->DevDesc->StrDescProductUS = (UINT8 *)Desc; + } else if (Desc != NULL) { + gBS->FreePool (Desc); + } + + Desc = NULL; + } + + if (UsbDev->DevDesc->Desc.StrSerialNumber != 0) { + Desc = UsbGetOneString (UsbDev, UsbDev->DevDesc->Desc.StrSerialNumber, UsbDev->LangId[0]); + if ((Desc != NULL) && (UsbDev->LangId[0] == USB_US_LANG_ID)) { + UsbDev->DevDesc->StrDescSerialNumberUS = (UINT8 *)Desc; + } else if (Desc != NULL) { + gBS->FreePool (Desc); + } + + Desc = NULL; + } + +ON_EXIT: + if (Desc != NULL) { + gBS->FreePool (Desc); + } + return Status; } diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h index de11ade8ef..9d4540bff9 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h @@ -68,6 +68,9 @@ typedef struct { typedef struct { EFI_USB_DEVICE_DESCRIPTOR Desc; USB_CONFIG_DESC **Configs; + UINT8 *StrDescManufacturerUS; + UINT8 *StrDescProductUS; + UINT8 *StrDescSerialNumberUS; } USB_DEVICE_DESC; /** From 24788b6190abc736d614a7218f72ac7a0f27924a Mon Sep 17 00:00:00 2001 From: Syed Mohammed Nayyar Date: Tue, 2 Jun 2026 12:23:46 +0530 Subject: [PATCH 106/406] NetworkPkg/IScsiDxe: bound value length in IScsiBuildKeyValueList IScsiBuildKeyValueList parses the data segment of a received iSCSI login, text or CHAP response into key=value pairs. After locating '=' within the remaining length, it sets KeyValuePair->Value and calls AsciiStrLen(Value) to measure the value before subtracting it from the remaining length. AsciiStrLen has no length cap, and the data segment copied from the received PDU (AllocatePool(Len) + NetbufQueCopy of the data-segment length) is not guaranteed to be NUL-terminated. A malicious or redirecting target can send a data segment whose final value lacks a trailing NUL (e.g. the 3 bytes "X=Y"), so AsciiStrLen reads past the end of the segment allocation, an attacker-controlled out-of-bounds read. The SafeUint32Sub bound check only runs after the over-read. Replace AsciiStrLen(Value) with AsciiStrnLenS(Value, Len), capping the scan to the bytes remaining from Value onward. An unterminated value then returns Len and the existing SafeUint32Sub rejects the segment. The single change covers all three callers (login redirect, operational parameter negotiation and CHAP). Signed-off-by: Syed Mohammed Nayyar --- NetworkPkg/IScsiDxe/IScsiProto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetworkPkg/IScsiDxe/IScsiProto.c b/NetworkPkg/IScsiDxe/IScsiProto.c index 13394dbfc6..beb63ebc9c 100644 --- a/NetworkPkg/IScsiDxe/IScsiProto.c +++ b/NetworkPkg/IScsiDxe/IScsiProto.c @@ -1922,7 +1922,7 @@ IScsiBuildKeyValueList ( KeyValuePair->Value = Data; - Status = SafeUint32Add ((UINT32)AsciiStrLen (KeyValuePair->Value), 1, &Result); + Status = SafeUint32Add ((UINT32)AsciiStrnLenS (KeyValuePair->Value, Len), 1, &Result); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a Memory Overflow is Detected.\n", __func__)); FreePool (KeyValuePair); From 9a65be14eb21910a21e0a11e0014c1b20a8ee6ef Mon Sep 17 00:00:00 2001 From: Jared Pan Date: Wed, 24 Jun 2026 09:21:47 +0800 Subject: [PATCH 107/406] NetworkPkg/SnpDxe: Fix MAC address passthrough support During SnpUndi32Initialize(), CurrentAddress is unconditionally overwritten with PermanentAddress before UNDI initialization. This causes MAC address passthrough (MacPassthru) to fail, as the NIC's actual current address, which may differ from its permanent address, is lost. After UNDI initialization completes, call PxeGetStnAddr() to read the NIC's station address via the UNDI interface and update CurrentAddress, PermanentAddress, and BroadcastAddress in the mode structure with the values reported by the hardware. The call is added to both initialization paths: the cable-detect success path and the fallback no-cable-detect path. Signed-off-by: Jared Pan --- NetworkPkg/SnpDxe/Initialize.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/NetworkPkg/SnpDxe/Initialize.c b/NetworkPkg/SnpDxe/Initialize.c index ffd914623c..7bbe30ddb9 100644 --- a/NetworkPkg/SnpDxe/Initialize.c +++ b/NetworkPkg/SnpDxe/Initialize.c @@ -188,6 +188,7 @@ SnpUndi32Initialize ( ) { EFI_STATUS EfiStatus; + EFI_STATUS StnAddrStatus; SNP_DRIVER *Snp; EFI_TPL OldTpl; @@ -253,6 +254,11 @@ SnpUndi32Initialize ( // if (Snp->CableDetectSupported) { if (PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) == EFI_SUCCESS) { + StnAddrStatus = PxeGetStnAddr (Snp); + if (EFI_ERROR (StnAddrStatus)) { + DEBUG ((DEBUG_WARN, "%a: failed to refresh station address (%r)\n", __func__, StnAddrStatus)); + } + goto ON_EXIT; } } @@ -273,6 +279,11 @@ SnpUndi32Initialize ( PxeGetStatus (Snp, NULL, FALSE); } + StnAddrStatus = PxeGetStnAddr (Snp); + if (EFI_ERROR (StnAddrStatus)) { + DEBUG ((DEBUG_WARN, "%a: failed to refresh station address (%r)\n", __func__, StnAddrStatus)); + } + ON_EXIT: gBS->RestoreTPL (OldTpl); From f26ba713c6bb26d1581efc84b22e14726b90b6d3 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Wed, 24 Jun 2026 12:59:00 -0700 Subject: [PATCH 108/406] Maintainers.txt: Add Myself as MdeModulePkg/Core Maintainer Add myself as a maintainer of DXE and PEI Core modules. As I am taking on a larger maintenance set, drop my EmulatorPkg maintainership to focus on the new one. Signed-off-by: Oliver Smith-Denny --- Maintainers.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Maintainers.txt b/Maintainers.txt index bd5d133f93..feeb6a8e12 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -217,7 +217,6 @@ M: Abner Chang [changab] EmulatorPkg F: EmulatorPkg/ W: https://www.tianocore.org/tianocore-wiki.github.io/platforms-packages/platform-ports/emulator_pkg.html -M: Oliver Smith-Denny [os-d] M: Andrew Fish [ajfish] M: Michael Kubacki [makubacki] S: Maintained @@ -312,6 +311,7 @@ F: MdeModulePkg/Library/DxeSecurityManagementLib/ F: MdeModulePkg/Universal/PCD/ F: MdeModulePkg/Universal/PlatformDriOverrideDxe/ F: MdeModulePkg/Universal/SecurityStubDxe/SecurityStub.c +M: Oliver Smith-Denny [os-d] R: Liming Gao [lgao4] R: Khalid Ali [khaliid2040] R: Mike Beaton [mikebeaton] @@ -379,6 +379,7 @@ R: Khalid Ali [khaliid2040] MdeModulePkg: Pei Core F: MdeModulePkg/Core/Pei/ +M: Oliver Smith-Denny [os-d] R: Liming Gao [lgao4] R: Khalid Ali [khaliid2040] From 0c2e3373512dfd6ac02215126e032ec41602af24 Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Tue, 23 Jun 2026 20:47:10 +0100 Subject: [PATCH 109/406] DynamicTablesPkg: Add SMBIOS Cooling Device (Type 27) generator Introduce a CM_ARCH_COMMON_COOLING_DEVICE_INFO object to describe cooling devices provided by the platform. The generator creates one SMBIOS Type 27 record for each cooling device object and populates the device type/status, cooling unit group, OEM-defined data, nominal speed, and optional description string. The temperature probe handle is set to 0xFFFF for now because SMBIOS Type 28 Temperature Probe generation is not currently available. Reject non-null temperature probe tokens until Type 28 handle resolution can be added. Add the CM object parser entry and wire the generator into the DynamicTablesPkg build. Signed-off-by: Varshit Pandya --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../Include/ArchCommonNameSpaceObjects.h | 25 + .../ConfigurationManagerObjectParser.c | 15 +- .../SmbiosType27Lib/SmbiosType27Generator.c | 485 ++++++++++++++++++ .../SmbiosType27Lib/SmbiosType27Lib.inf | 29 ++ 5 files changed, 555 insertions(+), 1 deletion(-) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index 6ba3152f3a..3de761edcf 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -115,6 +115,7 @@ DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf # AML Fixup (Arm specific) DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtCmn600LibArm/SsdtCmn600LibArm.inf @@ -165,6 +166,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf } [Components.RISCV64] diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index f63ddc948f..49898c5283 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -83,6 +83,7 @@ typedef enum ArchCommonObjectID { EArchCommonObjPhysicalMemoryArray, ///< 55 - Physical Memory Array Info EArchCommonObjMemoryDeviceInfo, ///< 56 - Memory Device Info EArchCommonObjMemoryArrayMappedAddress, ///< 57 - Memory Array Mapped Address Info + EArchCommonObjCoolingDeviceInfo, ///< 58 - Cooling Device Info EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1464,4 +1465,28 @@ typedef struct CmArchCommonMemoryArrayMappedAddress { UINT8 NumMemDevices; } CM_ARCH_COMMON_MEMORY_ARRAY_MAPPED_ADDRESS; +/** A structure that describes cooling device. + + SMBIOS Specification v3.9.0 Type 27 + + ID: EArchCommonObjCoolingDeviceInfo +**/ +typedef struct CmArchCommonCoolingDeviceInfo { + /// CM Object Token uniquely identifying this cooling device info. + CM_OBJECT_TOKEN Token; + /// CM Object Token uniquely identifying temperature probe associated with this device + CM_OBJECT_TOKEN TemperatureProbeToken; + /// Type and Status of the cooling device + MISC_COOLING_DEVICE_TYPE DeviceTypeAndStatus; + /// Cooling unit group number + UINT8 CoolingUnitGroup; + /// OEM defined information + UINT32 OEMDefined; + /// Nominal speed for the cooling device in revolutions per minute + /// A value of 0x8000 indicates unknown or non-rotating. + UINT16 NominalSpeed; + /// Description of the cooling device + CHAR8 Description[SMBIOS_MAX_STRING_SIZE]; +} CM_ARCH_COMMON_COOLING_DEVICE_INFO; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index dd97db16f8..9443059559 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -1,7 +1,7 @@ /** @file Configuration Manager Object parser. - Copyright (c) 2021 - 2023, ARM Limited. All rights reserved.
+ Copyright (c) 2021 - 2026, ARM Limited. All rights reserved.
Copyright (C) 2024 - 2025 Advanced Micro Devices, Inc. All rights reserved. Copyright (c) 2024 - 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -1223,6 +1223,18 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonMemoryArrayMappedAddressParser[] = { { "NumMemDevices", sizeof (UINT8), "0x%u", NULL }, }; +/** A parser for EArchCommonObjCoolingDeviceInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonCoolingDeviceInfoParser[] = { + { "Token", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "TemperatureProbeToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "DeviceTypeAndStatus", sizeof (MISC_COOLING_DEVICE_TYPE), "0x%x", NULL }, + { "CoolingUnitGroup", sizeof (UINT8), "0x%x", NULL }, + { "OEMDefined", sizeof (UINT32), "0x%x", NULL }, + { "NominalSpeed", sizeof (UINT16), "0x%x", NULL }, + { "Description", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, +}; + /** A parser for Arch Common namespace objects. */ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { @@ -1285,6 +1297,7 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArchCommonObjPhysicalMemoryArray, CmArchCommonPhysicalMemoryArrayParser), CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryDeviceInfo, CmArchCommonMemoryDeviceInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryArrayMappedAddress, CmArchCommonMemoryArrayMappedAddressParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjCoolingDeviceInfo, CmArchCommonCoolingDeviceInfoParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c new file mode 100644 index 0000000000..b1c5900803 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c @@ -0,0 +1,485 @@ +/** @file + SMBIOS Type27 Table Generator. + + @par Reference(s): + - SMBIOS Specification 3.9.0 + + Copyright (c) 2026, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include + +/** SMBIOS Type 27 Cooling Device Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArchCommonObjCoolingDeviceInfo +*/ + +/** + This macro expands to a function that retrieves the Cooling Device + information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjCoolingDeviceInfo, + CM_ARCH_COMMON_COOLING_DEVICE_INFO + ); + +/** + Type 27 records currently expose one string field: Description. +*/ +#define SMBIOS_TYPE27_MAX_STRINGS (1) + +/** + Valid SMBIOS Type 27 Status values are 0x01-0x06. + Valid Device Type values are 0x01-0x09 and 0x10-0x11; + values 0x0A-0x0F are reserved by the SMBIOS specification. +*/ +#define SMBIOS_TYPE27_COOLING_STATUS_MIN 1 +#define SMBIOS_TYPE27_COOLING_STATUS_MAX 6 +#define SMBIOS_TYPE27_COOLING_DEVICE_TYPE_MIN 1 +#define SMBIOS_TYPE27_COOLING_DEVICE_TYPE_MAX 17 +#define SMBIOS_TYPE27_COOLING_DEVICE_TYPE_GAP_MIN 10 +#define SMBIOS_TYPE27_COOLING_DEVICE_TYPE_GAP_MAX 15 + +/** Check whether a Type 27 cooling device status value is valid. + + @param [in] Status Cooling device status value. + + @retval TRUE The status value is valid. + @retval FALSE The status value is invalid. +**/ +STATIC +BOOLEAN +IsValidCoolingDeviceStatus ( + IN UINT8 Status + ) +{ + return (Status >= SMBIOS_TYPE27_COOLING_STATUS_MIN) && + (Status <= SMBIOS_TYPE27_COOLING_STATUS_MAX); +} + +/** Check whether a Type 27 cooling device type value is valid. + + @param [in] Type Cooling device type value. + + @retval TRUE The type value is valid. + @retval FALSE The type value is invalid. +**/ +STATIC +BOOLEAN +IsValidCoolingDeviceType ( + IN UINT8 Type + ) +{ + return ((Type >= SMBIOS_TYPE27_COOLING_DEVICE_TYPE_MIN) && + (Type < SMBIOS_TYPE27_COOLING_DEVICE_TYPE_GAP_MIN)) || + ((Type > SMBIOS_TYPE27_COOLING_DEVICE_TYPE_GAP_MAX) && + (Type <= SMBIOS_TYPE27_COOLING_DEVICE_TYPE_MAX)); +} + +/** + Free any resources allocated when installing SMBIOS Type 27 table. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the SMBIOS table. + @param [in] CmObjectToken Pointer to the CM ObjectToken Array. + @param [in] TableCount Number of SMBIOS tables. + + @retval EFI_SUCCESS Resources were freed successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +FreeSmbiosType27TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + SMBIOS_STRUCTURE **TableList; + + TableList = *Table; + for (Index = 0; Index < TableCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + if (*CmObjectToken != NULL) { + FreePool (*CmObjectToken); + } + + if (TableList != NULL) { + FreePool (TableList); + } + + return EFI_SUCCESS; +} + +/** Construct SMBIOS Type 27 Table describing cooling devices. + + If this function allocates any resources then they must be freed + in the FreeXXXXTableResources function. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the SMBIOS table. + @param [out] CmObjectToken Pointer to the CM Object Token Array. + @param [out] TableCount Number of tables installed. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +BuildSmbiosType27TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + UINTN Index; + UINTN SmbiosRecordSize; + UINT32 CoolingDevCount; + UINT8 Description; + STRING_TABLE StrTable; + SMBIOS_STRUCTURE **TableList; + SMBIOS_TABLE_TYPE27 *SmbiosRecord; + CM_OBJECT_TOKEN *CmObjectList; + CM_ARCH_COMMON_COOLING_DEVICE_INFO *CoolingDevInfo; + + ASSERT (This != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (Table != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL) || (TableCount == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a:Invalid Parameter\n ", __func__)); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + *CmObjectToken = NULL; + *TableCount = 0; + TableList = NULL; + SmbiosRecord = NULL; + CmObjectList = NULL; + + Status = GetEArchCommonObjCoolingDeviceInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &CoolingDevInfo, + &CoolingDevCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get cooling device info. Status = %r\n", + __func__, + Status + )); + return Status; + } + + if (CoolingDevCount == 0) { + DEBUG (( + DEBUG_ERROR, + "%a: No Cooling Device CM Objects found\n", + __func__ + )); + return EFI_NOT_FOUND; + } + + TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRUCTURE *) * CoolingDevCount); + if (TableList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u cooling devices table\n", + __func__, + CoolingDevCount + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitErrorBuildSmbiosType27Table; + } + + CmObjectList = AllocateZeroPool ( + sizeof (CM_OBJECT_TOKEN) * CoolingDevCount + ); + if (CmObjectList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u cooling devices table\n", + __func__, + CoolingDevCount + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitErrorBuildSmbiosType27Table; + } + + Index = 0; + for (Index = 0; Index < CoolingDevCount; Index++) { + Status = StringTableInitialize (&StrTable, SMBIOS_TYPE27_MAX_STRINGS); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to initialize string table for CoolingDevInfo[%u]. Status = %r\n", + __func__, + Index, + Status + )); + goto exitErrorBuildSmbiosType27Table; + } + + Description = 0; + if (CoolingDevInfo[Index].Description[0]) { + Status = StringTableAddString (&StrTable, CoolingDevInfo[Index].Description, &Description); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add Description String %r\n", Status)); + ASSERT (!EFI_ERROR (Status)); + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType27Table; + } + } + + SmbiosRecordSize = sizeof (SMBIOS_TABLE_TYPE27) + StringTableGetStringSetSize (&StrTable); + SmbiosRecord = (SMBIOS_TABLE_TYPE27 *)AllocateZeroPool (SmbiosRecordSize); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType27Table; + } + + // Set up the header + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_COOLING_DEVICE; + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE27); + + // Type 28 is not supported yet. Per the SMBIOS general handle rule, + // use 0xFFFF when the referenced handle is not applicable or does not exist. + // Todo: Once Type 28 generator is implemented this has to be changed to handle it + if (CoolingDevInfo[Index].TemperatureProbeToken != CM_NULL_TOKEN) { + DEBUG (( + DEBUG_ERROR, + "%a: TemperatureProbeToken is unsupported until SMBIOS Type 28 generation is available for CoolingDevInfo[%u]\n", + __func__, + Index + )); + Status = EFI_UNSUPPORTED; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType27Table; + } + + SmbiosRecord->TemperatureProbeHandle = 0xFFFF; + + if (!IsValidCoolingDeviceStatus ( + CoolingDevInfo[Index].DeviceTypeAndStatus.CoolingDeviceStatus + )) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Cooling Device Status 0x%x for CoolingDevInfo[%u]\n", + __func__, + CoolingDevInfo[Index].DeviceTypeAndStatus.CoolingDeviceStatus, + Index + )); + Status = EFI_INVALID_PARAMETER; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType27Table; + } + + if (!IsValidCoolingDeviceType ( + CoolingDevInfo[Index].DeviceTypeAndStatus.CoolingDevice + )) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Cooling Device Type 0x%x for CoolingDevInfo[%u]\n", + __func__, + CoolingDevInfo[Index].DeviceTypeAndStatus.CoolingDevice, + Index + )); + Status = EFI_INVALID_PARAMETER; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType27Table; + } + + SmbiosRecord->DeviceTypeAndStatus = CoolingDevInfo[Index].DeviceTypeAndStatus; + SmbiosRecord->CoolingUnitGroup = CoolingDevInfo[Index].CoolingUnitGroup; + SmbiosRecord->OEMDefined = CoolingDevInfo[Index].OEMDefined; + SmbiosRecord->NominalSpeed = CoolingDevInfo[Index].NominalSpeed; + SmbiosRecord->Description = Description; + + Status = StringTablePublishStringSet ( + &StrTable, + (CHAR8 *)(SmbiosRecord + 1), + SmbiosRecordSize - sizeof (SMBIOS_TABLE_TYPE27) + ); + + if (EFI_ERROR (Status)) { + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType27Table; + } + + StringTableFree (&StrTable); + + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] = CoolingDevInfo[Index].Token; + SmbiosRecord = NULL; + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = CoolingDevCount; + + return EFI_SUCCESS; + +exitErrorBuildSmbiosType27Table: + if (TableList != NULL) { + for (Index = 0; Index < CoolingDevCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + FreePool (TableList); + } + + if (CmObjectList != NULL) { + FreePool (CmObjectList); + } + + if (SmbiosRecord != NULL) { + FreePool (SmbiosRecord); + } + + return Status; +} + +/** The interface for the SMBIOS Type27 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType27Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType27), + // Generator Description + L"SMBIOS.TYPE27.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_COOLING_DEVICE, + NULL, + NULL, + // Build table function. + BuildSmbiosType27TableEx, + // Free function. + FreeSmbiosType27TableEx, +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType27LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType27Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 27: Register Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType27LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType27Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 27: Deregister Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf new file mode 100644 index 0000000000..073df4896e --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf @@ -0,0 +1,29 @@ +## @file +# SMBIOS Type27 Table Generator +# +# Copyright (c) 2026, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType27LibArm + FILE_GUID = 1f38c754-dc37-4b0f-8972-be8f705f7839 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType27LibConstructor + DESTRUCTOR = SmbiosType27LibDestructor + +[Sources] + SmbiosType27Generator.c + +[Packages] + MdePkg/MdePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + DebugLib + MemoryAllocationLib + SmbiosStringTableLib From 5628eaaf38ea25d7cf0726a132ddfa200ad46f4c Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Wed, 24 Jun 2026 15:56:28 +0100 Subject: [PATCH 110/406] DynamicTablesPkg: Add SMBIOS Temperature Probe (Type 28) generator Introduce a CM_ARCH_COMMON_TEMPERATURE_PROBE_INFO object to describe temperature probes provided by the platform. The generator creates one SMBIOS Type 28 record for each temperature probe object and populates the description, location/status, probe limits, resolution, tolerance, accuracy, OEM-defined data, and nominal value. Add the CM object parser entry and wire the generator into the DynamicTablesPkg build. Signed-off-by: Varshit Pandya --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../Include/ArchCommonNameSpaceObjects.h | 45 ++ .../ConfigurationManagerObjectParser.c | 16 + .../SmbiosType28Lib/SmbiosType28Generator.c | 465 ++++++++++++++++++ .../SmbiosType28Lib/SmbiosType28Lib.inf | 29 ++ 5 files changed, 557 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index 3de761edcf..e3e29a7d6c 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -116,6 +116,7 @@ DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf # AML Fixup (Arm specific) DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtCmn600LibArm/SsdtCmn600LibArm.inf @@ -167,6 +168,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf } [Components.RISCV64] diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index 49898c5283..9ccbd43e7b 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -84,6 +84,7 @@ typedef enum ArchCommonObjectID { EArchCommonObjMemoryDeviceInfo, ///< 56 - Memory Device Info EArchCommonObjMemoryArrayMappedAddress, ///< 57 - Memory Array Mapped Address Info EArchCommonObjCoolingDeviceInfo, ///< 58 - Cooling Device Info + EArchCommonObjTemperatureProbeInfo, ///< 59 - Temperature Probe Info EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1489,4 +1490,48 @@ typedef struct CmArchCommonCoolingDeviceInfo { CHAR8 Description[SMBIOS_MAX_STRING_SIZE]; } CM_ARCH_COMMON_COOLING_DEVICE_INFO; +/** A structure that describes a temperature probe. + + SMBIOS Specification v3.9.0 Type 28 + + ID: EArchCommonObjTemperatureProbeInfo +**/ +typedef struct CmArchCommonTemperatureProbeInfo { + /// CM Object Token uniquely identifying this temperature probe. + CM_OBJECT_TOKEN TemperatureProbeToken; + + /// Description of the temperature probe or its location. + CHAR8 Description[SMBIOS_MAX_STRING_SIZE]; + + /// Location and status of the temperature probe. + MISC_TEMPERATURE_PROBE_LOCATION LocationAndStatus; + + /// Maximum value readable by the probe, in 1/10 degrees C. + /// A value of 0x8000 indicates unknown. + UINT16 MaximumValue; + + /// Minimum value readable by the probe, in 1/10 degrees C. + /// A value of 0x8000 indicates unknown. + UINT16 MinimumValue; + + /// Resolution for the probe reading, in 1/1000 degrees C. + /// A value of 0x8000 indicates unknown. + UINT16 Resolution; + + /// Tolerance for the probe reading, plus/minus 1/10 degrees C. + /// A value of 0x8000 indicates unknown. + UINT16 Tolerance; + + /// Accuracy for the probe reading, in plus/minus 1/100 percent. + /// A value of 0x8000 indicates unknown. + UINT16 Accuracy; + + /// OEM- or firmware vendor-specific information. + UINT32 OemDefined; + + /// Nominal temperature value, in 1/10 degrees C. + /// A value of 0x8000 indicates unknown. + UINT16 NominalValue; +} CM_ARCH_COMMON_TEMPERATURE_PROBE_INFO; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index 9443059559..da28b64d20 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -1235,6 +1235,21 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonCoolingDeviceInfoParser[] = { { "Description", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, }; +/** A parser for EArchCommonObjTemperatureProbeInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonTemperatureProbeInfoParser[] = { + { "TemperatureProbeToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "Description", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "LocationAndStatus", sizeof (MISC_TEMPERATURE_PROBE_LOCATION), "0x%x", NULL }, + { "MaximumValue", sizeof (UINT16), "0x%x", NULL }, + { "MinimumValue", sizeof (UINT16), "0x%x", NULL }, + { "Resolution", sizeof (UINT16), "0x%x", NULL }, + { "Tolerance", sizeof (UINT16), "0x%x", NULL }, + { "Accuracy", sizeof (UINT16), "0x%x", NULL }, + { "OEMDefined", sizeof (UINT32), "0x%x", NULL }, + { "NominalValue", sizeof (UINT16), "0x%x", NULL }, +}; + /** A parser for Arch Common namespace objects. */ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { @@ -1298,6 +1313,7 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryDeviceInfo, CmArchCommonMemoryDeviceInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryArrayMappedAddress, CmArchCommonMemoryArrayMappedAddressParser), CM_PARSER_ADD_OBJECT (EArchCommonObjCoolingDeviceInfo, CmArchCommonCoolingDeviceInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjTemperatureProbeInfo, CmArchCommonTemperatureProbeInfoParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Generator.c new file mode 100644 index 0000000000..db664c5afc --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Generator.c @@ -0,0 +1,465 @@ +/** @file + SMBIOS Type28 Table Generator. + + @par Reference(s): + - SMBIOS Specification 3.9.0, Type 28 Temperature Probe + + Copyright (c) 2026, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include + +/** SMBIOS Type 28 Temperature Probe Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArchCommonObjTemperatureProbeInfo +*/ + +/** + This macro expands to a function that retrieves the Temperature Probe + information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjTemperatureProbeInfo, + CM_ARCH_COMMON_TEMPERATURE_PROBE_INFO + ); + +/** + Type 28 records currently expose one string field: Description. +*/ +#define SMBIOS_TYPE28_MAX_STRINGS (1) + +/** + Valid SMBIOS Type 28 Status values are 0x01-0x06. + Valid Location values are 0x01-0x0F. +*/ +#define SMBIOS_TYPE28_PROBE_STATUS_MIN 1 +#define SMBIOS_TYPE28_PROBE_STATUS_MAX 6 +#define SMBIOS_TYPE28_PROBE_LOCATION_MIN 1 +#define SMBIOS_TYPE28_PROBE_LOCATION_MAX 15 + +/** Check whether a Type 28 temperature probe status value is valid. + + @param [in] Status Temperature probe status value. + + @retval TRUE The status value is valid. + @retval FALSE The status value is invalid. +**/ +STATIC +BOOLEAN +IsValidTemperatureProbeStatus ( + IN UINT8 Status + ) +{ + return (Status >= SMBIOS_TYPE28_PROBE_STATUS_MIN) && + (Status <= SMBIOS_TYPE28_PROBE_STATUS_MAX); +} + +/** Check whether a Type 28 temperature probe location value is valid. + + @param [in] Location Temperature probe location value. + + @retval TRUE The location value is valid. + @retval FALSE The location value is invalid. +**/ +STATIC +BOOLEAN +IsValidTemperatureProbeLocation ( + IN UINT8 Location + ) +{ + return (Location >= SMBIOS_TYPE28_PROBE_LOCATION_MIN) && + (Location <= SMBIOS_TYPE28_PROBE_LOCATION_MAX); +} + +/** + Free any resources allocated when installing SMBIOS Type 28 table. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the SMBIOS table. + @param [in] CmObjectToken Pointer to the CM ObjectToken Array. + @param [in] TableCount Number of SMBIOS tables. + + @retval EFI_SUCCESS Resources were freed successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +FreeSmbiosType28TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + SMBIOS_STRUCTURE **TableList; + + TableList = *Table; + for (Index = 0; Index < TableCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + if (*CmObjectToken != NULL) { + FreePool (*CmObjectToken); + } + + if (TableList != NULL) { + FreePool (TableList); + } + + return EFI_SUCCESS; +} + +/** Construct SMBIOS Type 28 Table describing temperature probes. + + If this function allocates any resources then they must be freed + in the FreeXXXXTableResources function. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the SMBIOS table. + @param [out] CmObjectToken Pointer to the CM Object Token Array. + @param [out] TableCount Number of tables installed. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +BuildSmbiosType28TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + UINTN Index; + UINTN SmbiosRecordSize; + UINT32 TempProbeCount; + UINT8 Description; + STRING_TABLE StrTable; + SMBIOS_STRUCTURE **TableList; + SMBIOS_TABLE_TYPE28 *SmbiosRecord; + CM_OBJECT_TOKEN *CmObjectList; + CM_ARCH_COMMON_TEMPERATURE_PROBE_INFO *TempProbeInfo; + + ASSERT (This != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (Table != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL) || (TableCount == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a:Invalid Parameter\n ", __func__)); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + *CmObjectToken = NULL; + *TableCount = 0; + TableList = NULL; + SmbiosRecord = NULL; + CmObjectList = NULL; + + Status = GetEArchCommonObjTemperatureProbeInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &TempProbeInfo, + &TempProbeCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get temperature probe info. Status = %r\n", + __func__, + Status + )); + return Status; + } + + if (TempProbeCount == 0) { + DEBUG (( + DEBUG_ERROR, + "%a: No Temperature Probe CM Objects found\n", + __func__ + )); + return EFI_NOT_FOUND; + } + + TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRUCTURE *) * TempProbeCount); + if (TableList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u temperature probe table\n", + __func__, + TempProbeCount + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitErrorBuildSmbiosType28Table; + } + + CmObjectList = AllocateZeroPool ( + sizeof (CM_OBJECT_TOKEN) * TempProbeCount + ); + if (CmObjectList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u temperature probe table\n", + __func__, + TempProbeCount + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitErrorBuildSmbiosType28Table; + } + + Index = 0; + for (Index = 0; Index < TempProbeCount; Index++) { + Status = StringTableInitialize (&StrTable, SMBIOS_TYPE28_MAX_STRINGS); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to initialize string table for TempProbeInfo[%u]. Status = %r\n", + __func__, + Index, + Status + )); + goto exitErrorBuildSmbiosType28Table; + } + + Description = 0; + if (TempProbeInfo[Index].Description[0]) { + Status = StringTableAddString (&StrTable, TempProbeInfo[Index].Description, &Description); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add Description String %r\n", Status)); + ASSERT (!EFI_ERROR (Status)); + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType28Table; + } + } + + SmbiosRecordSize = sizeof (SMBIOS_TABLE_TYPE28) + StringTableGetStringSetSize (&StrTable); + SmbiosRecord = (SMBIOS_TABLE_TYPE28 *)AllocateZeroPool (SmbiosRecordSize); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType28Table; + } + + // Set up the header + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_TEMPERATURE_PROBE; + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE28); + + if (!IsValidTemperatureProbeStatus ( + TempProbeInfo[Index].LocationAndStatus.TemperatureProbeStatus + )) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Temperature Probe Status 0x%x for TempProbeInfo[%u]\n", + __func__, + TempProbeInfo[Index].LocationAndStatus.TemperatureProbeStatus, + Index + )); + Status = EFI_INVALID_PARAMETER; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType28Table; + } + + if (!IsValidTemperatureProbeLocation ( + TempProbeInfo[Index].LocationAndStatus.TemperatureProbeSite + )) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Temperature Probe Location 0x%x for TempProbeInfo[%u]\n", + __func__, + TempProbeInfo[Index].LocationAndStatus.TemperatureProbeSite, + Index + )); + Status = EFI_INVALID_PARAMETER; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType28Table; + } + + SmbiosRecord->Description = Description; + SmbiosRecord->LocationAndStatus = TempProbeInfo[Index].LocationAndStatus; + SmbiosRecord->MaximumValue = TempProbeInfo[Index].MaximumValue; + SmbiosRecord->MinimumValue = TempProbeInfo[Index].MinimumValue; + SmbiosRecord->Resolution = TempProbeInfo[Index].Resolution; + SmbiosRecord->Tolerance = TempProbeInfo[Index].Tolerance; + SmbiosRecord->Accuracy = TempProbeInfo[Index].Accuracy; + SmbiosRecord->OEMDefined = TempProbeInfo[Index].OemDefined; + SmbiosRecord->NominalValue = TempProbeInfo[Index].NominalValue; + + Status = StringTablePublishStringSet ( + &StrTable, + (CHAR8 *)(SmbiosRecord + 1), + SmbiosRecordSize - sizeof (SMBIOS_TABLE_TYPE28) + ); + if (EFI_ERROR (Status)) { + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType28Table; + } + + StringTableFree (&StrTable); + + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] = TempProbeInfo[Index].TemperatureProbeToken; + SmbiosRecord = NULL; + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = TempProbeCount; + + return EFI_SUCCESS; +exitErrorBuildSmbiosType28Table: + if (TableList != NULL) { + for (Index = 0; Index < TempProbeCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + FreePool (TableList); + } + + if (CmObjectList != NULL) { + FreePool (CmObjectList); + } + + if (SmbiosRecord != NULL) { + FreePool (SmbiosRecord); + } + + return Status; +} + +/** The interface for the SMBIOS Type28 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType28Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType28), + // Generator Description + L"SMBIOS.TYPE28.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_TEMPERATURE_PROBE, + NULL, + NULL, + // Build table function. + BuildSmbiosType28TableEx, + // Free function. + FreeSmbiosType28TableEx, +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType28LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType28Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 28: Register Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType28LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType28Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 28: Deregister Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf new file mode 100644 index 0000000000..52a72aa939 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf @@ -0,0 +1,29 @@ +## @file +# SMBIOS Type28 Table Generator +# +# Copyright (c) 2026, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType28LibArm + FILE_GUID = aeb393de-ec41-48af-8d92-d537fe5239e4 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType28LibConstructor + DESTRUCTOR = SmbiosType28LibDestructor + +[Sources] + SmbiosType28Generator.c + +[Packages] + MdePkg/MdePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + DebugLib + MemoryAllocationLib + SmbiosStringTableLib From d7f133a16428a5d4d1d1021a48d4192cc88a6a13 Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Wed, 24 Jun 2026 15:57:30 +0100 Subject: [PATCH 111/406] DynamicTablesPkg: Link SMBIOS Type 27 to Type 28 probes Use the TemperatureProbeToken in the Cooling Device CM object to resolve the SMBIOS handle of the corresponding Type 28 Temperature Probe record. Set the Type 27 TemperatureProbeHandle field to 0xFFFF when no temperature probe token is provided. Return an error if a non-null token does not resolve to a generated Type 28 record. Signed-off-by: Varshit Pandya --- .../SmbiosType27Lib/SmbiosType27Generator.c | 61 +++++++++++++++---- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c index b1c5900803..48acc82278 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c @@ -26,6 +26,9 @@ Requirements: The following Configuration Manager Object(s) are required by this Generator: - EArchCommonObjCoolingDeviceInfo + - EArchCommonObjTemperatureProbeInfo + Required only when a cooling device provides a non-null + TemperatureProbeToken. */ /** @@ -91,6 +94,46 @@ IsValidCoolingDeviceType ( (Type <= SMBIOS_TYPE27_COOLING_DEVICE_TYPE_MAX)); } +/** Add the Type 28 Temperature Probe handle to the Type 27 record. + + @param [in] TemperatureProbeToken CM token of the temperature probe. + @param [in,out] SmbiosRecord SMBIOS Type 27 record to update. + + @retval EFI_SUCCESS The handle was added. + @retval EFI_NOT_FOUND The temperature probe handle was not found. +**/ +STATIC +EFI_STATUS +AddTemperatureProbeHandle ( + IN CM_OBJECT_TOKEN TemperatureProbeToken, + IN OUT SMBIOS_TABLE_TYPE27 *SmbiosRecord + ) +{ + SMBIOS_HANDLE SmbiosHandle; + + if (TemperatureProbeToken == CM_NULL_TOKEN) { + SmbiosRecord->TemperatureProbeHandle = 0xFFFF; + return EFI_SUCCESS; + } + + SmbiosHandle = FindSmbiosHandleEx ( + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType28), + TemperatureProbeToken + ); + if (SmbiosHandle == SMBIOS_HANDLE_INVALID) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to find Type 28 handle for TemperatureProbeToken 0x%p\n", + __func__, + TemperatureProbeToken + )); + return EFI_NOT_FOUND; + } + + SmbiosRecord->TemperatureProbeHandle = SmbiosHandle; + return EFI_SUCCESS; +} + /** Free any resources allocated when installing SMBIOS Type 27 table. @@ -306,23 +349,15 @@ BuildSmbiosType27TableEx ( SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_COOLING_DEVICE; SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE27); - // Type 28 is not supported yet. Per the SMBIOS general handle rule, - // use 0xFFFF when the referenced handle is not applicable or does not exist. - // Todo: Once Type 28 generator is implemented this has to be changed to handle it - if (CoolingDevInfo[Index].TemperatureProbeToken != CM_NULL_TOKEN) { - DEBUG (( - DEBUG_ERROR, - "%a: TemperatureProbeToken is unsupported until SMBIOS Type 28 generation is available for CoolingDevInfo[%u]\n", - __func__, - Index - )); - Status = EFI_UNSUPPORTED; + Status = AddTemperatureProbeHandle ( + CoolingDevInfo[Index].TemperatureProbeToken, + SmbiosRecord + ); + if (EFI_ERROR (Status)) { StringTableFree (&StrTable); goto exitErrorBuildSmbiosType27Table; } - SmbiosRecord->TemperatureProbeHandle = 0xFFFF; - if (!IsValidCoolingDeviceStatus ( CoolingDevInfo[Index].DeviceTypeAndStatus.CoolingDeviceStatus )) From b6d3ac52d79b6d99d56cd640daebce0313828d1f Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 12 Jun 2026 19:31:02 -0400 Subject: [PATCH 112/406] BaseTools: Remove ShowEnvironment.bat This file: - Has not had a code change in 8 years. - Is not used by any other file in the repository. - Was last updated to support VS2015 which is no longer supported by Microsoft. As part of VS2015 support removal, this file is deleted. Signed-off-by: Michael Kubacki --- BaseTools/Scripts/ShowEnvironment.bat | 169 -------------------------- 1 file changed, 169 deletions(-) delete mode 100755 BaseTools/Scripts/ShowEnvironment.bat diff --git a/BaseTools/Scripts/ShowEnvironment.bat b/BaseTools/Scripts/ShowEnvironment.bat deleted file mode 100755 index 1301d5fcb1..0000000000 --- a/BaseTools/Scripts/ShowEnvironment.bat +++ /dev/null @@ -1,169 +0,0 @@ -@REM @file -@REM Windows batch file to display the Windows environment -@REM -@REM This script will be used to show the current EDK II build environment. -@REM it may be called by the Edk2Setup.bat (that will be renamed to edksetup.bat) or -@REM run as stand-alone application. -@REM -@REM Copyright (c) 2014, Intel Corporation. All rights reserved.
-@REM SPDX-License-Identifier: BSD-2-Clause-Patent -@REM -@echo off -@set SE_SVN_REVISION=$Revision: 8 $ -@set SE_VERSION=0.7.0. -@if "%SCRIPT%"=="EDKSETUP_BAT" goto SkipCmdlineArgumentCheck - -:parse_cmd_line -@if /I "%1"=="-h" @goto Usage -@if /I "%1"=="--help" @goto Usage -@if /I "%1"=="/?" @goto Usage -@if /I "%1"=="-v" @goto Version -@if /I "%1"=="--version" @goto Version - -:Usage -@echo Usage: ShowEnvironment.bat [Options] -@echo Copyright(c) 2014, Intel Corporation. All rights reserved. -@echo. -@echo Options: -@echo --help, -h Print this help screen and exit -@echo --version, -v Print this tool's version and exit -@echo. -@goto End - -:Version -@echo ShowEnvironment.bat Version: %SE_VERSION%%SE_SVN_REVISION:~11,-1% -@echo Copyright(c) 2014, Intel Corporation. All rights reserved. - -:SkipCmdlineArgumentCheck -if defined SRC_CONF @goto SetEnv - -@echo. -@echo ############################################################################# -@if defined WORKSPACE @echo WORKSPACE = %WORKSPACE% -@if not defined WORKSPACE @echo WORKSPACE = Not Set -@if defined PACKAGES_PATH @echo PACKAGES_PATH = %PACKAGES_PATH% -@if defined EDK_TOOLS_PATH @echo EDK_TOOLS_PATH = %EDK_TOOLS_PATH% -@if not defined EDK_TOOLS_PATH @echo EDK_TOOLS_PATH = Not Set -@if defined BASE_TOOLS_PATH @echo BASE_TOOLS_PATH = %BASE_TOOLS_PATH% -@if defined EDK_TOOLS_BIN @echo EDK_TOOLS_BIN = %EDK_TOOLS_BIN% -@if "%NT32PKG%"=="TRUE" ( - @echo. - @echo NOTE: Please configure your build to use the following TOOL_CHAIN_TAG - @echo when building NT32Pkg/Nt32Pkg.dsc - @if defined VCINSTALLDIR @call :CheckVsVer - @set TEST_VS= -) -@if defined HIDE_PATH goto End - - -@echo ############################## PATH ######################################### -@setlocal DisableDelayedExpansion -@set "var=%PATH%" -@set "var=%var:"=""%" -@set "var=%var:^=^^%" -@set "var=%var:&=^&%" -@set "var=%var:|=^|%" -@set "var=%var:<=^<%" -@set "var=%var:>=^>%" -@set "var=%var:;=^;^;%" -@set var=%var:""="% -@set "var=%var:"=""Q%" -@set "var=%var:;;="S"S%" -@set "var=%var:^;^;=;%" -@set "var=%var:""="%" -@setlocal EnableDelayedExpansion -@set "var=!var:"Q=!" -@for %%a in ("!var:"S"S=";"!") do ( - @if "!!"=="" endlocal - @if %%a neq "" echo %%~a -) -@goto End - -:CheckVsVer -@set "TEST_VS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\" -@if "%VSINSTALLDIR%"=="%TEST_VS%" ( - @echo TOOL_CHAIN_TAG = VS2015x86 - @goto :EOF -) -@set "TEST_VS=C:\Program Files\Microsoft Visual Studio 14.0\" -@if "%VSINSTALLDIR%"=="%TEST_VS%" ( - @echo TOOL_CHAIN_TAG = VS2015 - @goto :EOF -) -@goto :EOF - -:SetEnv -@set FIRST_COPY=FALSE -@set MISSING_TARGET_TEMPLATE=FALSE -@set MISSING_TOOLS_DEF_TEMPLATE=FALSE -@set MISSING_BUILD_RULE_TEMPLATE=FALSE -@if not exist "%SRC_CONF%\target.template" @set MISSING_TARGET_TEMPLATE=TRUE -@if not exist "%SRC_CONF%\tools_def.template" @set MISSING_TOOLS_DEF_TEMPLATE=TRUE -@if not exist "%SRC_CONF%\build_rule.template" @set MISSING_BUILD_RULE_TEMPLATE=TRUE - -@if not exist "%WORKSPACE%\Conf\target.txt" ( - @if "%MISSING_TARGET_TEMPLATE%"=="TRUE" @goto MissingTemplates - @echo copying ... target.template to %WORKSPACE%\Conf\target.txt - @copy /Y "%SRC_CONF%\target.template" "%WORKSPACE%\Conf\target.txt" > nul - @set FIRST_COPY=TRUE -) -@if not exist "%WORKSPACE%\Conf\tools_def.txt" ( - @if "%MISSING_TOOLS_DEF_TEMPLATE%"=="TRUE" @goto MissingTemplates - @echo copying ... tools_def.template to %WORKSPACE%\Conf\tools_def.txt - @copy /Y "%SRC_CONF%\tools_def.template" "%WORKSPACE%\Conf\tools_def.txt" > nul - @set FIRST_COPY=TRUE -) -@if not exist "%WORKSPACE%\Conf\build_rule.txt" ( - @if "%MISSING_BUILD_RULE_TEMPLATE%"=="TRUE" @goto MissingTemplates - @echo copying ... build_rule.template to %WORKSPACE%\Conf\build_rule.txt - @copy /Y "%SRC_CONF%\build_rule.template" "%WORKSPACE%\Conf\build_rule.txt" > nul - @set FIRST_COPY=TRUE -) - -@if "%FIRST_COPY%"=="TRUE" @goto End -@if not "%RECONFIG%"=="TRUE" @goto End - -@if "%RECONFIG%"=="TRUE" ( - @echo. - @echo Over-writing the files in the WORKSPACE\Conf directory - @echo using the default template files - @echo. - @if "%MISSING_TARGET_TEMPLATE%"=="TRUE" @goto MissingTemplates - @echo over-write ... target.template to %WORKSPACE%\Conf\target.txt - @copy /Y "%SRC_CONF%\target.template" "%WORKSPACE%\Conf\target.txt" > nul - - @if "%MISSING_TOOLS_DEF_TEMPLATE%"=="TRUE" @goto MissingTemplates - @echo over-write ... tools_def.template to %WORKSPACE%\Conf\tools_def.txt - @copy /Y "%SRC_CONF%\tools_def.template" "%WORKSPACE%\Conf\tools_def.txt" > nul - - @if "%MISSING_BUILD_RULE_TEMPLATE%"=="TRUE" @goto MissingTemplates - @echo over-write ... build_rule.template to %WORKSPACE%\Conf\build_rule.txt - @copy /Y "%SRC_CONF%\build_rule.template" "%WORKSPACE%\Conf\build_rule.txt" > nul - @goto End -) - -:MissingTemplates -@echo. -@if "%RECONFIG%"=="TRUE" @echo ERROR : Reconfig failed -@if "%MISSING_TARGET_TEMPLATE%"=="TRUE" @echo ERROR : Unable to locate: "%SRC_CONF%\target.template" -@if "%MISSING_TOOLS_DEF_TEMPLATE%"=="TRUE" @echo ERROR : Unable to locate: "%SRC_CONF%\tools_def.template" -@if "%MISSING_BUILD_RULE_TEMPLATE%"=="TRUE" @echo ERROR : Unable to locate: "%SRC_CONF%\build_rule.template" -@echo. -@set MISSING_TARGET_TEMPLATE= -@set MISSING_TOOLS_DEF_TEMPLATE= -@set MISSING_BUILD_RULE_TEMPLATE= -@set FIRST_COPY= -@set SE_VERSION= -@set SE_SVN_REVISION= -@if not "%SCRIPT%"=="EDKSETUP_BAT" @echo on -exit /B 1 - -:End -@set MISSING_TARGET_TEMPLATE= -@set MISSING_TOOLS_DEF_TEMPLATE= -@set MISSING_BUILD_RULE_TEMPLATE= -@set FIRST_COPY= -@set SE_VERSION= -@set SE_SVN_REVISION= -@if not "%SCRIPT%"=="EDKSETUP_BAT" @echo on -exit /B 0 From edf045a7aed8df25c4478129b293bd740198367a Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 12 Jun 2026 19:44:45 -0400 Subject: [PATCH 113/406] BaseTools: Remove SetVisualStudio.bat This file has: - Not been updated in 10 years. - Was used to build Nt32Pkg which no longer exists. - Is not needed to currenly build EmulatorPkg. - Was last updated to support Visual Studio 2015, which is no longer supported by Microsoft. It is removed as part of the Visual Studio 2015 removal. Signed-off-by: Michael Kubacki --- BaseTools/Scripts/SetVisualStudio.bat | 82 --------------------------- 1 file changed, 82 deletions(-) delete mode 100755 BaseTools/Scripts/SetVisualStudio.bat diff --git a/BaseTools/Scripts/SetVisualStudio.bat b/BaseTools/Scripts/SetVisualStudio.bat deleted file mode 100755 index fba9f846ef..0000000000 --- a/BaseTools/Scripts/SetVisualStudio.bat +++ /dev/null @@ -1,82 +0,0 @@ -@REM @file -@REM Windows batch file to set up the Microsoft Visual Studio environment -@REM -@REM This script is used to set up one of the Microsoft Visual Studio -@REM environments, VS2015 for -@REM building the Nt32Pkg/Nt32Pkg.dsc emulation environment to run on -@REM an X64 version of Windows. -@REM The system environment variables in this script are set by the -@rem Edk2Setup.bat script (that will be renamed to edksetup.bat). -@REM -@REM This script can also be used to build the Win32 binaries -@REM -@REM Copyright (c) 2014, Intel Corporation. All rights reserved.
-@REM SPDX-License-Identifier: BSD-2-Clause-Patent -@REM -@echo off -@if defined NT32_X64 @goto CheckLatest -@if "%REBUILD_TOOLS%"=="TRUE" @goto RebuildTools - -:CheckLatest -echo. -@if defined VS140COMNTOOLS ( - @set "COMMONTOOLSx64=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64" - @goto SetVs -) -@echo. -@echo No version of Microsoft Visual Studio was found on this system -@echo. -@exit /B 1 - -@REM Set up the X64 environment for building Nt32Pkg/Nt32Pkg.dsc to run on an X64 platform -:SetVs -if exist "%COMMONTOOLSx64%\vcvarsx86_amd64.bat" ( - @call "%COMMONTOOLSx64%\vcvarsx86_amd64.bat" - @if errorlevel 1 ( - @echo. ERROR setting Microsoft Visual Studio %1 - @set COMMONTOOLSx64= - @exit /B 1 - ) -) -if not exist "%COMMONTOOLSx64%\vcvarsx86_amd64.bat" ( - @echo ERROR : This script does not exist: "%COMMONTOOLSx64%\vcvarsx86_amd64.bat" - @set COMMONTOOLSx64= - @exit /B 1 -) -@set COMMONTOOLSx64= -@goto End - -:RebuildTools -@call python "%BASE_TOOLS_PATH%\Scripts\UpdateBuildVersions.py" -@set "BIN_DIR=%EDK_TOOLS_PATH%\Bin\Win32" -if not exist "%BIN_DIR%" @mkdir "%BIN_DIR%" -@echo Removing temporary and binary files -@cd "%BASE_TOOLS_PATH%" -@call nmake cleanall -@echo Rebuilding the EDK II BaseTools -@cd "%BASE_TOOLS_PATH%\Source\C" -@call nmake -nologo -a -f Makefile -@if errorlevel 1 ( -@echo Error building the C-based BaseTools -@cd "%WORKSPACE%" -@exit /B1 -) -@cd %BASE_TOOLS_PATH%\Source\Python -@call nmake -nologo -a -f Makefile -@if errorlevel 1 ( -@echo Error building the Python-based BaseTools -@cd %WORKSPACE% -@exit /B1 -) -@cd %WORKSPACE% - -@goto End - -:VersionNotFound -@echo. -@echo This Microsoft Visual Studio version is in not installed on this system: %1 -@echo. -@exit /B 1 - -:End -@exit /B 0 From 3a9c8cfc30fa1d27295c90234dd61da8c8767c37 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 12 Jun 2026 20:09:21 -0400 Subject: [PATCH 114/406] edksetup.bat: Remove VS2015 support The VS2015 toolchain is being removed from edk2. In preparation, this change removes the toolchain as an option in edksetup.bat. Signed-off-by: Michael Kubacki --- edksetup.bat | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/edksetup.bat b/edksetup.bat index d0b06241e8..857f61534d 100755 --- a/edksetup.bat +++ b/edksetup.bat @@ -139,18 +139,16 @@ if /I "%1"=="VS2026" shift if /I "%1"=="VS2022" shift if /I "%1"=="VS2019" shift if /I "%1"=="VS2017" shift -if /I "%1"=="VS2015" shift if "%1"=="" goto end :Usage @echo. - @echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [Reconfig] [Rebuild] [ForceRebuild] [Mingw-w64] [VS2026] [VS2022] [VS2019] [VS2017] [VS2015]" + @echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [Reconfig] [Rebuild] [ForceRebuild] [Mingw-w64] [VS2026] [VS2022] [VS2019] [VS2017]" @echo. @echo Reconfig Reinstall target.txt, tools_def.txt and build_rule.txt. @echo Rebuild Perform incremental rebuild of BaseTools binaries. @echo ForceRebuild Force a full rebuild of BaseTools binaries. @echo Mingw-w64 Build BaseTools binaries using mingw-w64. - @echo VS2015 Set the env for VS2015 build. @echo VS2017 Set the env for VS2017 build. @echo VS2019 Set the env for VS2019 build. @echo VS2022 Set the env for VS2022 build. From 4b21e5e902280e2df4883a9ccbfe5d2c559a32d3 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 12 Jun 2026 19:44:09 -0400 Subject: [PATCH 115/406] BaseTools: Remove VS2015 support REF: https://github.com/tianocore/edk2/issues/12490 Removes Visual Studio 2015 support from BaseTools since mainstream support ended on October 13, 2020 and extended support ended on October 14, 2025. Signed-off-by: Michael Kubacki --- BaseTools/Conf/tools_def.template | 219 +----------------------------- BaseTools/get_vsvars.bat | 4 - BaseTools/set_vsprefix_envs.bat | 25 ---- BaseTools/toolsetup.bat | 13 +- 4 files changed, 3 insertions(+), 258 deletions(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index 94d8c1c414..5b1c52984e 100644 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -34,20 +34,12 @@ # - Add GENFWHII_FLAGS to fix VS2026 GenFw build issue # - Add -malign-double to IA32 ASLCC_FLAGS # - Add CLANGDWARF support for LoongArch64 +#4.00 - Remove VS2015 support # -#!VERSION=3.07 +#!VERSION=4.00 IDENTIFIER = Default TOOL_CHAIN_CONF -# common path macros -DEFINE VS2015_BIN = ENV(VS2015_PREFIX)Vc\bin -DEFINE VS2015_DLL = ENV(VS2015_PREFIX)Common7\IDE;DEF(VS2015_BIN) -DEFINE VS2015_BINX64 = DEF(VS2015_BIN)\x86_amd64 - -DEFINE VS2015x86_BIN = ENV(VS2015_PREFIX)Vc\bin -DEFINE VS2015x86_DLL = ENV(VS2015_PREFIX)Common7\IDE;DEF(VS2015x86_BIN) -DEFINE VS2015x86_BINX64 = DEF(VS2015x86_BIN)\x86_amd64 - DEFINE VS_HOST = x86 DEFINE VS2017_BIN = ENV(VS2017_PREFIX)bin @@ -82,10 +74,6 @@ DEFINE RC_PATH = ENV(WINSDK_PATH_FOR_RC_EXE)\rc.exe DEFINE WINSDK_BIN = ENV(WINSDK_PREFIX) DEFINE WINSDKx86_BIN = ENV(WINSDKx86_PREFIX) -# Microsoft Visual Studio 2015 Professional Edition -DEFINE WINSDK81_BIN = ENV(WINSDK81_PREFIX)x64 -DEFINE WINSDK81x86_BIN = ENV(WINSDK81x86_PREFIX)x86 - # Microsoft Visual Studio 2017/2019/2022/2026 Professional Edition DEFINE WINSDK10_BIN = ENV(WINSDK10_PREFIX)DEF(VS_HOST) @@ -153,12 +141,6 @@ DEFINE DTC_BIN = ENV(DTC_PREFIX)dtc # # Supported Tool Chains # ===================== -# VS2015 -win32- Requires: -# Microsoft Visual Studio 2015 Professional Edition, Update 3 -# Optional: -# Required to build platforms or ACPI tables: -# Intel(r) ACPI Compiler (iasl.exe) from -# https://acpica.org/downloads # VS2017 -win32- Requires: # Microsoft Visual Studio 2017 version 15.2 (15.4 for ARM64) or later # Optional: @@ -206,12 +188,6 @@ DEFINE DTC_BIN = ENV(DTC_PREFIX)dtc # Required to compile nasm source: # nasm compiler from # NASM -- http://www.nasm.us/ -# VS2015x86 -win64- Requires: -# Microsoft Visual Studio 2015 (x86) Update 3 or above -# Optional: -# Required to build platforms or ACPI tables: -# Intel(r) ACPI Compiler (iasl.exe) from -# https://acpica.org/downloads # #################################################################################### #################################################################################### @@ -251,197 +227,6 @@ DEFINE DTC_BIN = ENV(DTC_PREFIX)dtc # #################################################################################### -#################################################################################### -# -# Microsoft Visual Studio 2015 -# -# VS2015 - Microsoft Visual Studio 2015 Professional Edition with Intel ASL -# ASL - Intel ACPI Source Language Compiler -#################################################################################### -# VS2015 - Microsoft Visual Studio 2015 Professional Edition -*_VS2015_*_*_FAMILY = MSFT - -*_VS2015_*_MAKE_PATH = DEF(VS2015_BIN)\nmake.exe -*_VS2015_*_MAKE_FLAGS = /nologo -*_VS2015_*_RC_PATH = DEF(WINSDK81_BIN)\rc.exe - -*_VS2015_*_SLINK_FLAGS = /NOLOGO /LTCG -*_VS2015_*_APP_FLAGS = /nologo /E /TC -*_VS2015_*_PP_FLAGS = /nologo /E /TC /FIAutoGen.h -*_VS2015_*_VFRPP_FLAGS = /nologo /E /TC /DVFRCOMPILE /FI$(MODULE_NAME)StrDefs.h -*_VS2015_*_DLINK2_FLAGS = -*_VS2015_*_DEPS_FLAGS = DEF(MSFT_DEPS_FLAGS) -*_VS2015_*_GENFWHII_FLAGS = --hiipackage -*_VS2015_*_ASM16_PATH = DEF(VS2015_BIN)\ml.exe - -################## -# ASL definitions -################## -*_VS2015_*_ASL_PATH = DEF(DEFAULT_WIN_ASL_BIN) -*_VS2015_*_ASL_FLAGS = DEF(DEFAULT_WIN_ASL_FLAGS) -*_VS2015_*_ASL_OUTFLAGS = DEF(DEFAULT_WIN_ASL_OUTFLAGS) -*_VS2015_*_ASLCC_FLAGS = DEF(MSFT_ASLCC_FLAGS) -*_VS2015_*_ASLPP_FLAGS = DEF(MSFT_ASLPP_FLAGS) -*_VS2015_*_ASLDLINK_FLAGS = DEF(MSFT_ASLDLINK_FLAGS) - -################## -# IA32 definitions -################## -*_VS2015_IA32_*_DLL = DEF(VS2015_DLL) - -*_VS2015_IA32_CC_PATH = DEF(VS2015_BIN)\cl.exe -*_VS2015_IA32_VFRPP_PATH = DEF(VS2015_BIN)\cl.exe -*_VS2015_IA32_SLINK_PATH = DEF(VS2015_BIN)\lib.exe -*_VS2015_IA32_DLINK_PATH = DEF(VS2015_BIN)\link.exe -*_VS2015_IA32_APP_PATH = DEF(VS2015_BIN)\cl.exe -*_VS2015_IA32_PP_PATH = DEF(VS2015_BIN)\cl.exe -*_VS2015_IA32_ASM_PATH = DEF(VS2015_BIN)\ml.exe -*_VS2015_IA32_ASLCC_PATH = DEF(VS2015_BIN)\cl.exe -*_VS2015_IA32_ASLPP_PATH = DEF(VS2015_BIN)\cl.exe -*_VS2015_IA32_ASLDLINK_PATH = DEF(VS2015_BIN)\link.exe - - DEBUG_VS2015_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Z7 /Gw -RELEASE_VS2015_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gw -NOOPT_VS2015_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Z7 /Od - - DEBUG_VS2015_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi -RELEASE_VS2015_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd -NOOPT_VS2015_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi - - DEBUG_VS2015_IA32_NASM_FLAGS = -Ox -f win32 -g -RELEASE_VS2015_IA32_NASM_FLAGS = -Ox -f win32 -NOOPT_VS2015_IA32_NASM_FLAGS = -O0 -f win32 -g - - DEBUG_VS2015_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG -RELEASE_VS2015_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data -NOOPT_VS2015_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG - -################## -# X64 definitions -################## -*_VS2015_X64_*_DLL = DEF(VS2015_DLL) - -*_VS2015_X64_CC_PATH = DEF(VS2015_BINX64)\cl.exe -*_VS2015_X64_PP_PATH = DEF(VS2015_BINX64)\cl.exe -*_VS2015_X64_APP_PATH = DEF(VS2015_BINX64)\cl.exe -*_VS2015_X64_VFRPP_PATH = DEF(VS2015_BINX64)\cl.exe -*_VS2015_X64_ASM_PATH = DEF(VS2015_BINX64)\ml64.exe -*_VS2015_X64_SLINK_PATH = DEF(VS2015_BINX64)\lib.exe -*_VS2015_X64_DLINK_PATH = DEF(VS2015_BINX64)\link.exe -*_VS2015_X64_ASLCC_PATH = DEF(VS2015_BINX64)\cl.exe -*_VS2015_X64_ASLPP_PATH = DEF(VS2015_BINX64)\cl.exe -*_VS2015_X64_ASLDLINK_PATH = DEF(VS2015_BINX64)\link.exe - - DEBUG_VS2015_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Gw -RELEASE_VS2015_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw -NOOPT_VS2015_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Od - - DEBUG_VS2015_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi -RELEASE_VS2015_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd -NOOPT_VS2015_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi - - DEBUG_VS2015_X64_NASM_FLAGS = -Ox -f win64 -g -RELEASE_VS2015_X64_NASM_FLAGS = -Ox -f win64 -NOOPT_VS2015_X64_NASM_FLAGS = -O0 -f win64 -g - - DEBUG_VS2015_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG -RELEASE_VS2015_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data -NOOPT_VS2015_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG - -#################################################################################### -# VS2015x86 - Microsoft Visual Studio 2015 (x86) professional with Intel ASL -# ASL - Intel ACPI Source Language Compiler (iasl.exe) -#################################################################################### -# VS2015x86 - Microsoft Visual Studio 2015 (x86) professional Edition with Intel ASL -*_VS2015x86_*_*_FAMILY = MSFT - -*_VS2015x86_*_MAKE_PATH = DEF(VS2015x86_BIN)\nmake.exe -*_VS2015x86_*_MAKE_FLAGS = /nologo -*_VS2015x86_*_RC_PATH = DEF(WINSDK81x86_BIN)\rc.exe - -*_VS2015x86_*_SLINK_FLAGS = /NOLOGO /LTCG -*_VS2015x86_*_APP_FLAGS = /nologo /E /TC -*_VS2015x86_*_PP_FLAGS = /nologo /E /TC /FIAutoGen.h -*_VS2015x86_*_VFRPP_FLAGS = /nologo /E /TC /DVFRCOMPILE /FI$(MODULE_NAME)StrDefs.h -*_VS2015x86_*_DLINK2_FLAGS = -*_VS2015x86_*_DEPS_FLAGS = DEF(MSFT_DEPS_FLAGS) -*_VS2015x86_*_GENFWHII_FLAGS = --hiipackage -*_VS2015x86_*_ASM16_PATH = DEF(VS2015x86_BIN)\ml.exe - -################## -# ASL definitions -################## -*_VS2015x86_*_ASL_PATH = DEF(WIN_IASL_BIN) -*_VS2015x86_*_ASL_FLAGS = DEF(DEFAULT_WIN_ASL_FLAGS) -*_VS2015x86_*_ASL_OUTFLAGS = DEF(DEFAULT_WIN_ASL_OUTFLAGS) -*_VS2015x86_*_ASLCC_FLAGS = DEF(MSFT_ASLCC_FLAGS) -*_VS2015x86_*_ASLPP_FLAGS = DEF(MSFT_ASLPP_FLAGS) -*_VS2015x86_*_ASLDLINK_FLAGS = DEF(MSFT_ASLDLINK_FLAGS) - -################## -# IA32 definitions -################## -*_VS2015x86_IA32_*_DLL = DEF(VS2015x86_DLL) - -*_VS2015x86_IA32_CC_PATH = DEF(VS2015x86_BIN)\cl.exe -*_VS2015x86_IA32_VFRPP_PATH = DEF(VS2015x86_BIN)\cl.exe -*_VS2015x86_IA32_ASLCC_PATH = DEF(VS2015x86_BIN)\cl.exe -*_VS2015x86_IA32_ASLPP_PATH = DEF(VS2015x86_BIN)\cl.exe -*_VS2015x86_IA32_SLINK_PATH = DEF(VS2015x86_BIN)\lib.exe -*_VS2015x86_IA32_DLINK_PATH = DEF(VS2015x86_BIN)\link.exe -*_VS2015x86_IA32_ASLDLINK_PATH= DEF(VS2015x86_BIN)\link.exe -*_VS2015x86_IA32_APP_PATH = DEF(VS2015x86_BIN)\cl.exe -*_VS2015x86_IA32_PP_PATH = DEF(VS2015x86_BIN)\cl.exe -*_VS2015x86_IA32_ASM_PATH = DEF(VS2015x86_BIN)\ml.exe - - DEBUG_VS2015x86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Z7 /Gw -RELEASE_VS2015x86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gw -NOOPT_VS2015x86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Z7 /Od - - DEBUG_VS2015x86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi -RELEASE_VS2015x86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd -NOOPT_VS2015x86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi - - DEBUG_VS2015x86_IA32_NASM_FLAGS = -Ox -f win32 -g -RELEASE_VS2015x86_IA32_NASM_FLAGS = -Ox -f win32 -NOOPT_VS2015x86_IA32_NASM_FLAGS = -O0 -f win32 -g - - DEBUG_VS2015x86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG -RELEASE_VS2015x86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data -NOOPT_VS2015x86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG - -################## -# X64 definitions -################## -*_VS2015x86_X64_*_DLL = DEF(VS2015x86_DLL) - -*_VS2015x86_X64_CC_PATH = DEF(VS2015x86_BINX64)\cl.exe -*_VS2015x86_X64_PP_PATH = DEF(VS2015x86_BINX64)\cl.exe -*_VS2015x86_X64_APP_PATH = DEF(VS2015x86_BINX64)\cl.exe -*_VS2015x86_X64_VFRPP_PATH = DEF(VS2015x86_BINX64)\cl.exe -*_VS2015x86_X64_ASLCC_PATH = DEF(VS2015x86_BINX64)\cl.exe -*_VS2015x86_X64_ASLPP_PATH = DEF(VS2015x86_BINX64)\cl.exe -*_VS2015x86_X64_ASM_PATH = DEF(VS2015x86_BINX64)\ml64.exe -*_VS2015x86_X64_SLINK_PATH = DEF(VS2015x86_BINX64)\lib.exe -*_VS2015x86_X64_DLINK_PATH = DEF(VS2015x86_BINX64)\link.exe -*_VS2015x86_X64_ASLDLINK_PATH = DEF(VS2015x86_BINX64)\link.exe - - DEBUG_VS2015x86_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Gw -RELEASE_VS2015x86_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw -NOOPT_VS2015x86_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Od - - DEBUG_VS2015x86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi -RELEASE_VS2015x86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd -NOOPT_VS2015x86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi - - DEBUG_VS2015x86_X64_NASM_FLAGS = -Ox -f win64 -g -RELEASE_VS2015x86_X64_NASM_FLAGS = -Ox -f win64 -NOOPT_VS2015x86_X64_NASM_FLAGS = -O0 -f win64 -g - - DEBUG_VS2015x86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG -RELEASE_VS2015x86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data -NOOPT_VS2015x86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG - #################################################################################### # VS2017 - Microsoft Visual Studio 2017 with Intel ASL # ASL - Intel ACPI Source Language Compiler (iasl.exe) diff --git a/BaseTools/get_vsvars.bat b/BaseTools/get_vsvars.bat index b67e147ee6..87e2a1e4e5 100644 --- a/BaseTools/get_vsvars.bat +++ b/BaseTools/get_vsvars.bat @@ -12,7 +12,6 @@ set SCRIPT_ERROR=0 if "%1"=="" goto main if /I "%1"=="VS2019" goto VS2019Vars if /I "%1"=="VS2017" goto VS2017Vars -if /I "%1"=="VS2015" goto VS2015Vars :set_vsvars if defined VCINSTALLDIR goto :EOF @@ -80,8 +79,5 @@ if defined VCINSTALLDIR goto :done ) if /I "%1"=="VS2017" goto ToolNotInstall - :VS2015Vars - if defined VS140COMNTOOLS (call :read_vsvars "%VS140COMNTOOLS%") else (if /I "%1"=="VS2015" goto ToolNotInstall) - :done set GET_VSVARS_BAT_CHECK_DIR= diff --git a/BaseTools/set_vsprefix_envs.bat b/BaseTools/set_vsprefix_envs.bat index acf2598312..e6bcf33d31 100644 --- a/BaseTools/set_vsprefix_envs.bat +++ b/BaseTools/set_vsprefix_envs.bat @@ -22,7 +22,6 @@ if /I "%1"=="VS2026" goto SetVS2026 if /I "%1"=="VS2022" goto SetVS2022 if /I "%1"=="VS2019" goto SetVS2019 if /I "%1"=="VS2017" goto SetVS2017 -if /I "%1"=="VS2015" goto SetVS2015 if defined VS71COMNTOOLS ( if not defined VS2003_PREFIX ( @@ -30,30 +29,6 @@ if defined VS71COMNTOOLS ( ) ) -:SetVS2015 -if defined VS140COMNTOOLS ( - if not defined VS2015_PREFIX ( - set "VS2015_PREFIX=%VS140COMNTOOLS:~0,-14%" - ) - if not defined WINSDK81_PREFIX ( - if exist "%ProgramFiles%\Windows Kits\8.1\bin" ( - set "WINSDK81_PREFIX=%ProgramFiles%\Windows Kits\8.1\bin\" - ) else if exist "%ProgramFiles(x86)%\Windows Kits\8.1\bin" ( - set "WINSDK81_PREFIX=%ProgramFiles(x86)%\Windows Kits\8.1\bin\" - ) - ) - if not defined WINSDK81x86_PREFIX ( - if exist "%ProgramFiles(x86)%\Windows Kits\8.1\bin" ( - set "WINSDK81x86_PREFIX=%ProgramFiles(x86)%\Windows Kits\8.1\bin\" - ) else if exist "%ProgramFiles%\Windows Kits\8.1\bin" ( - set "WINSDK81x86_PREFIX=%ProgramFiles%\Windows Kits\8.1\bin\" - ) - ) -) else ( - if /I "%1"=="VS2015" goto ToolNotInstall -) -if /I "%1"=="VS2015" goto SetWinDDK - :SetVS2017 if not defined VS150COMNTOOLS ( @REM clear two envs so that vcvars32.bat can run successfully. diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat index b3a778f4f1..3b8486a30a 100755 --- a/BaseTools/toolsetup.bat +++ b/BaseTools/toolsetup.bat @@ -73,12 +73,6 @@ if /I "%1"=="/?" goto Usage set VSTool=VS2017 goto loop ) - if /I "%1"=="VS2015" ( - shift - set VS2015=TRUE - set VSTool=VS2015 - goto loop - ) if "%1"=="" goto setup_workspace if exist %1 ( if not defined BASE_TOOLS_PATH ( @@ -334,9 +328,6 @@ if defined VS2026 ( call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2019 ) else if defined VS2017 ( call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2017 -) else if defined VS2015 ( - call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2015 - call %EDK_TOOLS_PATH%\get_vsvars.bat VS2015 ) else if not defined BASETOOLS_MINGW_BUILD ( call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat call %EDK_TOOLS_PATH%\get_vsvars.bat @@ -590,7 +581,7 @@ endlocal :Usage @echo. - @echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [Mingw-w64] [base_tools_path [edk_tools_path]] [VS2026] [VS2022] [VS2019] [VS2017] [VS2015]" + @echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [Mingw-w64] [base_tools_path [edk_tools_path]] [VS2026] [VS2022] [VS2019] [VS2017]" @echo. @echo base_tools_path BaseTools project path, BASE_TOOLS_PATH will be set to this path. @echo edk_tools_path EDK_TOOLS_PATH will be set to this path. @@ -600,7 +591,6 @@ endlocal @echo whether they have been updated or not. @echo Reconfig Reinstall target.txt, tools_def.txt and build_rule.txt. @echo Mingw-w64 Build BaseTools binaries using mingw-w64. - @echo VS2015 Set the env for VS2015 build. @echo VS2017 Set the env for VS2017 build. @echo VS2019 Set the env for VS2019 build. @echo VS2022 Set the env for VS2022 build. @@ -615,7 +605,6 @@ set VS2026= set VS2022= set VS2019= set VS2017= -set VS2015= set VSTool= set PYTHON_VER_MAJOR= set PYTHON_VER_MINOR= From 13df0bd4639675b12bb9fb00e297bfdbf3250f47 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 12 Jun 2026 19:47:41 -0400 Subject: [PATCH 116/406] CryptoPkg: Remove VS2015 specific compiler flags VS2015 support is being removed in edk2 as it is out of service. Signed-off-by: Michael Kubacki --- CryptoPkg/Library/MbedTlsLib/MbedTlsLib.inf | 8 -------- CryptoPkg/Library/MbedTlsLib/MbedTlsLibFull.inf | 9 --------- CryptoPkg/Library/OpensslLib/OpensslLib.inf | 8 -------- CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf | 8 -------- CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf | 8 -------- CryptoPkg/Library/OpensslLib/OpensslLibFull.inf | 8 -------- CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf | 8 -------- 7 files changed, 57 deletions(-) diff --git a/CryptoPkg/Library/MbedTlsLib/MbedTlsLib.inf b/CryptoPkg/Library/MbedTlsLib/MbedTlsLib.inf index 39ea31a34b..fb30a4e7c7 100644 --- a/CryptoPkg/Library/MbedTlsLib/MbedTlsLib.inf +++ b/CryptoPkg/Library/MbedTlsLib/MbedTlsLib.inf @@ -109,14 +109,6 @@ MSFT:*_*_IA32_CC_FLAGS = /U_WIN32 /DEFI32 /wd4244 /wd4132 /wd4245 /wd4310 /wd4204 /wd4389 MSFT:*_*_X64_CC_FLAGS = /U_WIN32 /DEFI32 /wd4244 /wd4132 /wd4245 /wd4310 /wd4204 /wd4389 - # - # Disable following Visual Studio 2015 compiler warnings brought by mbedtls source, - # so we do not break the build with /WX option: - # C4718: recursive call has no side effects, deleting - # - MSFT:*_VS2015x86_IA32_CC_FLAGS = /wd4718 - MSFT:*_VS2015x86_X64_CC_FLAGS = /wd4718 - INTEL:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 /w INTEL:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 /w diff --git a/CryptoPkg/Library/MbedTlsLib/MbedTlsLibFull.inf b/CryptoPkg/Library/MbedTlsLib/MbedTlsLibFull.inf index e489cadd5d..1d7a39cbe1 100644 --- a/CryptoPkg/Library/MbedTlsLib/MbedTlsLibFull.inf +++ b/CryptoPkg/Library/MbedTlsLib/MbedTlsLibFull.inf @@ -113,15 +113,6 @@ MSFT:*_*_IA32_CC_FLAGS = /U_WIN32 /DEFI32 /wd4244 /wd4132 /wd4245 /wd4310 /wd4204 /wd4389 MSFT:*_*_X64_CC_FLAGS = /U_WIN32 /DEFI32 /wd4244 /wd4132 /wd4245 /wd4310 /wd4204 /wd4389 - - # - # Disable following Visual Studio 2015 compiler warnings brought by mbedtls source, - # so we do not break the build with /WX option: - # C4718: recursive call has no side effects, deleting - # - MSFT:*_VS2015x86_IA32_CC_FLAGS = /wd4718 - MSFT:*_VS2015x86_X64_CC_FLAGS = /wd4718 - INTEL:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 /w INTEL:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 /w diff --git a/CryptoPkg/Library/OpensslLib/OpensslLib.inf b/CryptoPkg/Library/OpensslLib/OpensslLib.inf index 094d4439b1..02513ce2f7 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLib.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLib.inf @@ -756,14 +756,6 @@ MSFT:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4310 /wd4389 /wd4700 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 MSFT:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4306 /wd4310 /wd4700 /wd4389 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 - # - # Disable following Visual Studio 2015 compiler warnings brought by openssl source, - # so we do not break the build with /WX option: - # C4718: recursive call has no side effects, deleting - # - MSFT:*_VS2015x86_IA32_CC_FLAGS = /wd4718 - MSFT:*_VS2015x86_X64_CC_FLAGS = /wd4718 - INTEL:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /w INTEL:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /w diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf index 8e35b0b9bc..b723ec5c6e 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf @@ -2226,14 +2226,6 @@ MSFT:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_IA32) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4310 /wd4389 /wd4700 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 MSFT:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_X64) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4306 /wd4310 /wd4700 /wd4389 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 - # - # Disable following Visual Studio 2015 compiler warnings brought by openssl source, - # so we do not break the build with /WX option: - # C4718: recursive call has no side effects, deleting - # - MSFT:*_VS2015x86_IA32_CC_FLAGS = /wd4718 - MSFT:*_VS2015x86_X64_CC_FLAGS = /wd4718 - INTEL:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_IA32) /w INTEL:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_X64) /w diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf b/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf index 230f82190f..3281a4ea40 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf @@ -706,14 +706,6 @@ MSFT:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4310 /wd4389 /wd4700 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 MSFT:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4306 /wd4310 /wd4700 /wd4389 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 - # - # Disable following Visual Studio 2015 compiler warnings brought by openssl source, - # so we do not break the build with /WX option: - # C4718: recursive call has no side effects, deleting - # - MSFT:*_VS2015x86_IA32_CC_FLAGS = /wd4718 - MSFT:*_VS2015x86_X64_CC_FLAGS = /wd4718 - INTEL:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /w INTEL:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /w diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf b/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf index 52607846a2..8563cdbae7 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf @@ -824,14 +824,6 @@ MSFT:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4310 /wd4389 /wd4700 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 MSFT:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4306 /wd4310 /wd4700 /wd4389 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 - # - # Disable following Visual Studio 2015 compiler warnings brought by openssl source, - # so we do not break the build with /WX option: - # C4718: recursive call has no side effects, deleting - # - MSFT:*_VS2015x86_IA32_CC_FLAGS = /wd4718 - MSFT:*_VS2015x86_X64_CC_FLAGS = /wd4718 - INTEL:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /w INTEL:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_NOASM) /w diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf index fb676fd6ba..1762e81c4f 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf @@ -2421,14 +2421,6 @@ MSFT:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_IA32) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4310 /wd4389 /wd4700 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 MSFT:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_X64) /wd4090 /wd4132 /wd4210 /wd4244 /wd4245 /wd4267 /wd4306 /wd4310 /wd4700 /wd4389 /wd4702 /wd4706 /wd4819 /wd4130 /wd4133 /wd4189 /wd4319 - # - # Disable following Visual Studio 2015 compiler warnings brought by openssl source, - # so we do not break the build with /WX option: - # C4718: recursive call has no side effects, deleting - # - MSFT:*_VS2015x86_IA32_CC_FLAGS = /wd4718 - MSFT:*_VS2015x86_X64_CC_FLAGS = /wd4718 - INTEL:*_*_IA32_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_IA32) /w INTEL:*_*_X64_CC_FLAGS = -U_WIN32 -U_WIN64 -U_MSC_VER -U__ICC $(OPENSSL_FLAGS) $(OPENSSL_FLAGS_X64) /w From f22b20e6aebd5a3c26c7dfab273e1aa954830ed8 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 12 Jun 2026 20:08:06 -0400 Subject: [PATCH 117/406] MdePkg: Generalize VS15 warning comment in ProcessorBind.h The Ia32 and X64 ProcessorBind.h files had comments about VS2015, but the warning is still relevant for newer VS versions, so update the comments to be more general since VS2015 support was removed from the repo recently. Signed-off-by: Michael Kubacki --- MdePkg/Include/Ia32/ProcessorBind.h | 4 ++-- MdePkg/Include/X64/ProcessorBind.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MdePkg/Include/Ia32/ProcessorBind.h b/MdePkg/Include/Ia32/ProcessorBind.h index def521c6ed..4c978e3212 100644 --- a/MdePkg/Include/Ia32/ProcessorBind.h +++ b/MdePkg/Include/Ia32/ProcessorBind.h @@ -89,13 +89,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // This warning is for potentially uninitialized local variable, and it may cause false -// positive issues in VS2015 build +// positive issues in VS build // #pragma warning ( disable : 4701 ) // // This warning is for potentially uninitialized local pointer variable, and it may cause -// false positive issues in VS2015 build +// false positive issues in VS build // #pragma warning ( disable : 4703 ) diff --git a/MdePkg/Include/X64/ProcessorBind.h b/MdePkg/Include/X64/ProcessorBind.h index 04983dd34c..51a5af459a 100644 --- a/MdePkg/Include/X64/ProcessorBind.h +++ b/MdePkg/Include/X64/ProcessorBind.h @@ -89,13 +89,13 @@ // // This warning is for potentially uninitialized local variable, and it may cause false -// positive issues in VS2015 build +// positive issues in VS build // #pragma warning ( disable : 4701 ) // // This warning is for potentially uninitialized local pointer variable, and it may cause -// false positive issues in VS2015 build +// false positive issues in VS build // #pragma warning ( disable : 4703 ) From 12196e96dbeeece1db301a7095c3d89f26c41a3a Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 12 Jun 2026 20:08:41 -0400 Subject: [PATCH 118/406] RedfishPkg: Remove VS2015x86 reference Visual Studio 2015 is out of service and support was recently removed from the repo. To prevent confusion about toolchain support, this commit updates the RedfishPkg Readme to replace the `VS2015x86` reference with `VS2026` (the latest supported VS version). Signed-off-by: Michael Kubacki --- RedfishPkg/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RedfishPkg/Readme.md b/RedfishPkg/Readme.md index 3156c89f02..925f1be0a3 100644 --- a/RedfishPkg/Readme.md +++ b/RedfishPkg/Readme.md @@ -167,7 +167,7 @@ Current RedfishPlatformHostInterfaceLib implementation of BMC-exposed USB NIC ca ## Connect to Redfish Service on EDK2 Emulator Platform 1. Install the WinpCap and copy [SnpNt32Io.dll](https://github.com/tianocore/edk2-NetNt32Io) to the building directory of the Emulator platform. This is the emulated network interface for EDK2 Emulator Platform. ```C - e.g. %WORKSPACE%/Build/EmulatorX64/DEBUG_VS2015x86/X64 + e.g. %WORKSPACE%/Build/EmulatorX64/DEBUG_VS2022/X64 ``` 2. Enable below macros in EmulatorPkg.dsc From b7d780bf131b193a5505c70a41adbc24af949bdb Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 16 Jun 2026 15:06:44 -0400 Subject: [PATCH 119/406] edksetup.bat: Remove VS2017 support The VS2017 toolchain is being removed from edk2. In preparation, this change removes the toolchain as an option in edksetup.bat. Signed-off-by: Michael Kubacki --- edksetup.bat | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/edksetup.bat b/edksetup.bat index 857f61534d..5526c23e84 100755 --- a/edksetup.bat +++ b/edksetup.bat @@ -138,18 +138,16 @@ if /I "%1"=="Mingw-w64" shift if /I "%1"=="VS2026" shift if /I "%1"=="VS2022" shift if /I "%1"=="VS2019" shift -if /I "%1"=="VS2017" shift if "%1"=="" goto end :Usage @echo. - @echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [Reconfig] [Rebuild] [ForceRebuild] [Mingw-w64] [VS2026] [VS2022] [VS2019] [VS2017]" + @echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [Reconfig] [Rebuild] [ForceRebuild] [Mingw-w64] [VS2026] [VS2022] [VS2019]" @echo. @echo Reconfig Reinstall target.txt, tools_def.txt and build_rule.txt. @echo Rebuild Perform incremental rebuild of BaseTools binaries. @echo ForceRebuild Force a full rebuild of BaseTools binaries. @echo Mingw-w64 Build BaseTools binaries using mingw-w64. - @echo VS2017 Set the env for VS2017 build. @echo VS2019 Set the env for VS2019 build. @echo VS2022 Set the env for VS2022 build. @echo VS2026 Set the env for VS2026 build. From 84012d29f77b8009ed01d84e811ccecaeb37ddc1 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 16 Jun 2026 15:07:22 -0400 Subject: [PATCH 120/406] EmulatorPkg: Remove VS2017 Visual Studio solution VS2017 support is being removed from edk2. This Visual Studio solution built the EmulatorPkg host with the VS2017 toolchain (`-t VS2017`), which will no longer exist in tools_def.template. The EmulatorPkg documentation and CI build with VS2022, so the VS2017 solution is removed. Signed-off-by: Michael Kubacki --- EmulatorPkg/Win/VS2017/BuildVS.bat | 3 - EmulatorPkg/Win/VS2017/Win.sln | 25 ----- EmulatorPkg/Win/VS2017/Win.vcxproj | 120 --------------------- EmulatorPkg/Win/VS2017/Win.vcxproj.filters | 50 --------- EmulatorPkg/Win/VS2017/Win.vcxproj.user | 13 --- 5 files changed, 211 deletions(-) delete mode 100644 EmulatorPkg/Win/VS2017/BuildVS.bat delete mode 100644 EmulatorPkg/Win/VS2017/Win.sln delete mode 100644 EmulatorPkg/Win/VS2017/Win.vcxproj delete mode 100644 EmulatorPkg/Win/VS2017/Win.vcxproj.filters delete mode 100644 EmulatorPkg/Win/VS2017/Win.vcxproj.user diff --git a/EmulatorPkg/Win/VS2017/BuildVS.bat b/EmulatorPkg/Win/VS2017/BuildVS.bat deleted file mode 100644 index 6fcf40cc0a..0000000000 --- a/EmulatorPkg/Win/VS2017/BuildVS.bat +++ /dev/null @@ -1,3 +0,0 @@ -cd ../../../ -@call edksetup.bat -build -p EmulatorPkg\EmulatorPkg.dsc -t VS2017 %* diff --git a/EmulatorPkg/Win/VS2017/Win.sln b/EmulatorPkg/Win/VS2017/Win.sln deleted file mode 100644 index 397c5d9b8b..0000000000 --- a/EmulatorPkg/Win/VS2017/Win.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28010.2003 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Win", "Win.vcxproj", "{B4E1783F-FD72-4214-B0F7-69271BAD5DDF}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B4E1783F-FD72-4214-B0F7-69271BAD5DDF}.Debug|x64.ActiveCfg = Debug|x64 - {B4E1783F-FD72-4214-B0F7-69271BAD5DDF}.Debug|x64.Build.0 = Debug|x64 - {B4E1783F-FD72-4214-B0F7-69271BAD5DDF}.Debug|x86.ActiveCfg = Debug|Win32 - {B4E1783F-FD72-4214-B0F7-69271BAD5DDF}.Debug|x86.Build.0 = Debug|Win32 - {B4E1783F-FD72-4214-B0F7-69271BAD5DDF}.Release|x64.ActiveCfg = Release|x64 - {B4E1783F-FD72-4214-B0F7-69271BAD5DDF}.Release|x64.Build.0 = Release|x64 - {B4E1783F-FD72-4214-B0F7-69271BAD5DDF}.Release|x86.ActiveCfg = Release|Win32 - {B4E1783F-FD72-4214-B0F7-69271BAD5DDF}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection -EndGlobal diff --git a/EmulatorPkg/Win/VS2017/Win.vcxproj b/EmulatorPkg/Win/VS2017/Win.vcxproj deleted file mode 100644 index 0f574a8e7f..0000000000 --- a/EmulatorPkg/Win/VS2017/Win.vcxproj +++ /dev/null @@ -1,120 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {B4E1783F-FD72-4214-B0F7-69271BAD5DDF} - MakeFileProj - 8.1 - - - - Makefile - true - v141 - - - Makefile - false - v141 - - - Makefile - true - v141 - - - Makefile - true - v141 - - - - - - - - - - - - - - - - - - - - - BuildVS.bat -a IA32 - BuildVS.bat -a IA32 all - BuildVS.bat -a IA32 clean - ..\..\..\Build\EmulatorIA32\DEBUG_VS2017\ - ..\..\..\Build\EmulatorIA32\DEBUG_VS2017\ - ..\..\..\MdePkg\Include;..\..\..\MdePkg\Include\Ia32;..\..\..\MdeModulePkg\Include;..\..\..\EmulatorPkg\Include;$(IncludePath) - - - BuildVS.bat -a IA32 -b RELEASE - - - BuildVS.bat -a IA32 -b RELEASE all - BuildVS.bat -a IA32 -b RELEASE clean - ..\..\..\Build\EmulatorIA32\DEBUG_VS2017\ - ..\..\..\Build\EmulatorIA32\DEBUG_VS2017\ - ..\..\..\MdePkg\Include;..\..\..\MdePkg\Include\Ia32;..\..\..\MdeModulePkg\Include;..\..\..\EmulatorPkg\Include;$(IncludePath) - - - BuildVS.bat -a X64 - BuildVS.bat -a X64 all - BuildVS.bat -a X64 clean - ..\..\..\Build\EmulatorX64\DEBUG_VS2017\ - ..\..\..\Build\EmulatorX64\DEBUG_VS2017\ - ..\..\..\MdePkg\Include;..\..\..\MdePkg\Include\X64;..\..\..\MdeModulePkg\Include;..\..\..\EmulatorPkg\Include;$(IncludePath) - - - BuildVS.bat -a X64 -b RELEASE - BuildVS.bat -a X64 -b RELEASE all - BuildVS.bat -a X64 -b RELEASE clean - ..\..\Build\EmulatorX64\DEBUG_VS2017\ - ..\..\Build\EmulatorX64\DEBUG_VS2017\ - ..\..\..\MdePkg\Include;..\..\..\MdePkg\Include\X64;..\..\..\MdeModulePkg\Include;..\..\..\EmulatorPkg\Include;$(IncludePath) - - - - - - - - - - - - - - - - - - - - - - diff --git a/EmulatorPkg/Win/VS2017/Win.vcxproj.filters b/EmulatorPkg/Win/VS2017/Win.vcxproj.filters deleted file mode 100644 index 3e176597ba..0000000000 --- a/EmulatorPkg/Win/VS2017/Win.vcxproj.filters +++ /dev/null @@ -1,50 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - - - - \ No newline at end of file diff --git a/EmulatorPkg/Win/VS2017/Win.vcxproj.user b/EmulatorPkg/Win/VS2017/Win.vcxproj.user deleted file mode 100644 index 7ccf83f132..0000000000 --- a/EmulatorPkg/Win/VS2017/Win.vcxproj.user +++ /dev/null @@ -1,13 +0,0 @@ - - - - WinHost.exe - WindowsLocalDebugger - $(ProjectDir)..\..\..\Build\EmulatorIA32\DEBUG_VS2017\IA32\ - - - WinHost.exe - $(ProjectDir)..\..\..\Build\EmulatorX64\DEBUG_VS2017\X64\ - WindowsLocalDebugger - - \ No newline at end of file From 3dc01cce24281c18050d7d5c35244cb61d3fb5eb Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 16 Jun 2026 15:07:14 -0400 Subject: [PATCH 121/406] DynamicTablesPkg: Retarget VS2017 static analysis build option VS2017 support is being removed from edk2. The static analysis (/analyze) build option that suppressed C6305 was scoped to the VS2017 toolchain. This change retargets it to VS2019, which is the oldest Visual Studio toolchain that remains supported. Signed-off-by: Michael Kubacki --- DynamicTablesPkg/DynamicTablesPkg.dsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynamicTablesPkg/DynamicTablesPkg.dsc b/DynamicTablesPkg/DynamicTablesPkg.dsc index e4fcc45f44..ac9bad2a4d 100644 --- a/DynamicTablesPkg/DynamicTablesPkg.dsc +++ b/DynamicTablesPkg/DynamicTablesPkg.dsc @@ -66,5 +66,5 @@ !ifdef STATIC_ANALYSIS # Check all rules # Inhibit C6305: Potential mismatch between sizeof and countof quantities. - *_VS2017_*_CC_FLAGS = /wd6305 /analyze + *_VS2019_*_CC_FLAGS = /wd6305 /analyze !endif From 48a82ffcbd79f575ae8dc39eb99d099290098600 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 16 Jun 2026 15:06:56 -0400 Subject: [PATCH 122/406] BaseTools: Remove VS2017 support Removes Visual Studio 2017 support from BaseTools. Newer toolchains (VS2019, VS2022, and VS2026) are supported in its place. This removes the VS2017 toolchain definitions from tools_def.template, the VS2017 environment setup logic in toolsetup.bat, set_vsprefix_envs.bat, and get_vsvars.bat, and the VS2017 configuration in the WindowsVsToolChain build plugin. Signed-off-by: Michael Kubacki --- BaseTools/Conf/tools_def.template | 134 +----------------- .../WindowsVsToolChain/WindowsVsToolChain.py | 78 +--------- BaseTools/get_vsvars.bat | 18 --- BaseTools/set_vsprefix_envs.bat | 62 -------- BaseTools/toolsetup.bat | 12 +- 5 files changed, 6 insertions(+), 298 deletions(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index 5b1c52984e..791d7e7508 100644 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -35,19 +35,14 @@ # - Add -malign-double to IA32 ASLCC_FLAGS # - Add CLANGDWARF support for LoongArch64 #4.00 - Remove VS2015 support +#4.01 - Remove VS2017 support # -#!VERSION=4.00 +#!VERSION=4.01 IDENTIFIER = Default TOOL_CHAIN_CONF DEFINE VS_HOST = x86 -DEFINE VS2017_BIN = ENV(VS2017_PREFIX)bin -DEFINE VS2017_BIN_HOST = DEF(VS2017_BIN)\HostDEF(VS_HOST)\DEF(VS_HOST) -DEFINE VS2017_BIN_IA32 = DEF(VS2017_BIN)\HostDEF(VS_HOST)\x86 -DEFINE VS2017_BIN_X64 = DEF(VS2017_BIN)\HostDEF(VS_HOST)\x64 -DEFINE VS2017_BIN_AARCH64 = DEF(VS2017_BIN)\HostDEF(VS_HOST)\arm64 - DEFINE VS2019_BIN = ENV(VS2019_PREFIX)bin DEFINE VS2019_BIN_HOST = DEF(VS2019_BIN)\HostDEF(VS_HOST)\DEF(VS_HOST) DEFINE VS2019_BIN_IA32 = DEF(VS2019_BIN)\HostDEF(VS_HOST)\x86 @@ -141,15 +136,6 @@ DEFINE DTC_BIN = ENV(DTC_PREFIX)dtc # # Supported Tool Chains # ===================== -# VS2017 -win32- Requires: -# Microsoft Visual Studio 2017 version 15.2 (15.4 for ARM64) or later -# Optional: -# Required to build platforms or ACPI tables: -# Intel(r) ACPI Compiler (iasl.exe) from -# https://acpica.org/downloads -# Note: -# Building of XIP firmware images for ARM64 is not currently supported (only applications). -# /FILEALIGN:4096 and other changes are needed for ARM64 firmware builds. # VS2019 -win32- Requires: # Microsoft Visual Studio 2019 version 16.2 or later # Optional: @@ -227,122 +213,6 @@ DEFINE DTC_BIN = ENV(DTC_PREFIX)dtc # #################################################################################### -#################################################################################### -# VS2017 - Microsoft Visual Studio 2017 with Intel ASL -# ASL - Intel ACPI Source Language Compiler (iasl.exe) -#################################################################################### -# VS2017 - Microsoft Visual Studio 2017 professional Edition with Intel ASL -*_VS2017_*_*_FAMILY = MSFT -*_VS2017_*_*_DLL = DEF(VS2017_BIN_HOST) - -*_VS2017_*_MAKE_PATH = DEF(VS2017_BIN_HOST)\nmake.exe -*_VS2017_*_MAKE_FLAGS = /nologo -*_VS2017_*_RC_PATH = DEF(RC_PATH) - -*_VS2017_*_SLINK_FLAGS = /NOLOGO /LTCG -*_VS2017_*_APP_FLAGS = /nologo /E /TC -*_VS2017_*_PP_FLAGS = /nologo /E /TC /FIAutoGen.h -*_VS2017_*_VFRPP_FLAGS = /nologo /E /TC /DVFRCOMPILE /FI$(MODULE_NAME)StrDefs.h -*_VS2017_*_DLINK2_FLAGS = /WHOLEARCHIVE -*_VS2017_*_ASM16_PATH = DEF(VS2017_BIN_IA32)\ml.exe -*_VS2017_*_GENFWHII_FLAGS = --hiipackage -*_VS2017_*_DEPS_FLAGS = DEF(MSFT_DEPS_FLAGS) -################## -# ASL definitions -################## -*_VS2017_*_ASL_PATH = DEF(WIN_IASL_BIN) -*_VS2017_*_ASL_FLAGS = DEF(DEFAULT_WIN_ASL_FLAGS) -*_VS2017_*_ASL_OUTFLAGS = DEF(DEFAULT_WIN_ASL_OUTFLAGS) -*_VS2017_*_ASLCC_FLAGS = DEF(MSFT_ASLCC_FLAGS) -*_VS2017_*_ASLPP_FLAGS = DEF(MSFT_ASLPP_FLAGS) -*_VS2017_*_ASLDLINK_FLAGS = DEF(MSFT_ASLDLINK_FLAGS) - -################## -# IA32 definitions -################## -*_VS2017_IA32_CC_PATH = DEF(VS2017_BIN_IA32)\cl.exe -*_VS2017_IA32_VFRPP_PATH = DEF(VS2017_BIN_IA32)\cl.exe -*_VS2017_IA32_ASLCC_PATH = DEF(VS2017_BIN_IA32)\cl.exe -*_VS2017_IA32_ASLPP_PATH = DEF(VS2017_BIN_IA32)\cl.exe -*_VS2017_IA32_SLINK_PATH = DEF(VS2017_BIN_IA32)\lib.exe -*_VS2017_IA32_DLINK_PATH = DEF(VS2017_BIN_IA32)\link.exe -*_VS2017_IA32_ASLDLINK_PATH= DEF(VS2017_BIN_IA32)\link.exe -*_VS2017_IA32_APP_PATH = DEF(VS2017_BIN_IA32)\cl.exe -*_VS2017_IA32_PP_PATH = DEF(VS2017_BIN_IA32)\cl.exe -*_VS2017_IA32_ASM_PATH = DEF(VS2017_BIN_IA32)\ml.exe - - DEBUG_VS2017_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Z7 /Gw -RELEASE_VS2017_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gw -NOOPT_VS2017_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Z7 /Od - - DEBUG_VS2017_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi -RELEASE_VS2017_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd -NOOPT_VS2017_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi - - DEBUG_VS2017_IA32_NASM_FLAGS = -Ox -f win32 -g -RELEASE_VS2017_IA32_NASM_FLAGS = -Ox -f win32 -NOOPT_VS2017_IA32_NASM_FLAGS = -O0 -f win32 -g - - DEBUG_VS2017_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG -RELEASE_VS2017_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data -NOOPT_VS2017_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG - -################## -# X64 definitions -################## -*_VS2017_X64_CC_PATH = DEF(VS2017_BIN_X64)\cl.exe -*_VS2017_X64_PP_PATH = DEF(VS2017_BIN_X64)\cl.exe -*_VS2017_X64_APP_PATH = DEF(VS2017_BIN_X64)\cl.exe -*_VS2017_X64_VFRPP_PATH = DEF(VS2017_BIN_X64)\cl.exe -*_VS2017_X64_ASLCC_PATH = DEF(VS2017_BIN_X64)\cl.exe -*_VS2017_X64_ASLPP_PATH = DEF(VS2017_BIN_X64)\cl.exe -*_VS2017_X64_ASM_PATH = DEF(VS2017_BIN_X64)\ml64.exe -*_VS2017_X64_SLINK_PATH = DEF(VS2017_BIN_X64)\lib.exe -*_VS2017_X64_DLINK_PATH = DEF(VS2017_BIN_X64)\link.exe -*_VS2017_X64_ASLDLINK_PATH = DEF(VS2017_BIN_X64)\link.exe - - DEBUG_VS2017_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Gw -RELEASE_VS2017_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw -NOOPT_VS2017_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Od - - DEBUG_VS2017_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi -RELEASE_VS2017_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd -NOOPT_VS2017_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi - - DEBUG_VS2017_X64_NASM_FLAGS = -Ox -f win64 -g -RELEASE_VS2017_X64_NASM_FLAGS = -Ox -f win64 -NOOPT_VS2017_X64_NASM_FLAGS = -O0 -f win64 -g - - DEBUG_VS2017_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4281 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG -RELEASE_VS2017_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4281 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data -NOOPT_VS2017_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4281 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG - -##################### -# AARCH64 definitions -##################### -*_VS2017_AARCH64_CC_PATH = DEF(VS2017_BIN_AARCH64)\cl.exe -*_VS2017_AARCH64_VFRPP_PATH = DEF(VS2017_BIN_AARCH64)\cl.exe -*_VS2017_AARCH64_SLINK_PATH = DEF(VS2017_BIN_AARCH64)\lib.exe -*_VS2017_AARCH64_DLINK_PATH = DEF(VS2017_BIN_AARCH64)\link.exe -*_VS2017_AARCH64_APP_PATH = DEF(VS2017_BIN_AARCH64)\cl.exe -*_VS2017_AARCH64_PP_PATH = DEF(VS2017_BIN_AARCH64)\cl.exe -*_VS2017_AARCH64_ASM_PATH = DEF(VS2017_BIN_AARCH64)\armasm64.exe -*_VS2017_AARCH64_ASLCC_PATH = DEF(VS2017_BIN_AARCH64)\cl.exe -*_VS2017_AARCH64_ASLPP_PATH = DEF(VS2017_BIN_AARCH64)\cl.exe -*_VS2017_AARCH64_ASLDLINK_PATH = DEF(VS2017_BIN_AARCH64)\link.exe - - DEBUG_VS2017_AARCH64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gw /Oi- -RELEASE_VS2017_AARCH64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gw /Oi- -NOOPT_VS2017_AARCH64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Od /Oi- - - DEBUG_VS2017_AARCH64_ASM_FLAGS = /nologo /g -RELEASE_VS2017_AARCH64_ASM_FLAGS = /nologo -NOOPT_VS2017_AARCH64_ASM_FLAGS = /nologo - - DEBUG_VS2017_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /DRIVER /DEBUG -RELEASE_VS2017_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /DRIVER /MERGE:.rdata=.data -NOOPT_VS2017_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /DRIVER /DEBUG - #################################################################################### # VS2019 - Microsoft Visual Studio 2019 with Intel ASL # ASL - Intel ACPI Source Language Compiler (iasl.exe) diff --git a/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py b/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py index 2e6b60b22a..188ecf21c6 100644 --- a/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py +++ b/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py @@ -1,5 +1,5 @@ # @file WindowsVsToolChain.py -# Plugin to configure the environment for the VS2017, VS2019, VS2022, and VS2026 toolchains +# Plugin to configure the environment for the VS2019, VS2022, and VS2026 toolchains # # This plugin also runs for CLANGPDB toolchain on Windows as that toolchain # leverages nmake from VS and needs to the SDK paths for unit tests @@ -30,86 +30,14 @@ class WindowsVsToolChain(IUefiBuildPlugin): "UCRTVersion", "WindowsLibPath", "WindowsSdkBinPath", "WindowsSdkDir", "WindowsSdkVerBinPath", "WindowsSDKVersion", "WindowsSDKLibVersion", "VCToolsInstallDir", "Path"] - # - # VS2017 - Follow VS2017 where there is potential for many versions of the tools. - # If a specific version is required then the user must set both env variables: - # VS150INSTALLPATH: base install path on system to VC install dir. Here you will find the VC folder, etc - # VS150TOOLVER: version number for the VC compiler tools - # VS2017_PREFIX: path to MSVC compiler folder with trailing slash (can be used instead of two vars above) - # VS2017_HOST: set the host architecture to use for host tools, and host libs, etc - if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2017": - - # check to see if host is configured - # HostType for VS2017 should be (defined in tools_def): - # x86 == 32bit Intel - # x64 == 64bit Intel - # arm64 == 64bit Arm - # - HostType = shell_environment.GetEnvironment().get_shell_var("VS2017_HOST") - if HostType is not None: - HostType = HostType.lower() - self.Logger.info( - f"HOST TYPE defined by environment. Host Type is {HostType}") - else: - HostInfo = GetHostInfo() - if HostInfo.arch == "x86": - if HostInfo.bit == "32": - HostType = "x86" - elif HostInfo.bit == "64": - HostType = "x64" - else: - raise NotImplementedError() - - # VS2017_HOST options are not exactly the same as QueryVcVariables. This translates. - VC_HOST_ARCH_TRANSLATOR = { - "x86": "x86", "x64": "AMD64", "arm64": "not supported"} - - # check to see if full path already configured - if shell_environment.GetEnvironment().get_shell_var("VS2017_PREFIX") != None: - self.Logger.info("VS2017_PREFIX is already set.") - - else: - install_path = self._get_vs_install_path( - "VS2017".lower(), "VS150INSTALLPATH") - vc_ver = self._get_vc_version(install_path, "VS150TOOLVER") - - if install_path is None or vc_ver is None: - self.Logger.error( - "Failed to configure environment for VS2017") - return -1 - - version_aggregator.GetVersionAggregator().ReportVersion( - "Visual Studio Install Path", install_path, version_aggregator.VersionTypes.INFO) - version_aggregator.GetVersionAggregator().ReportVersion( - "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL) - - # make VS2017_PREFIX to align with tools_def.txt - prefix = os.path.join(install_path, "VC", - "Tools", "MSVC", vc_ver) - prefix = prefix + os.path.sep - shell_environment.GetEnvironment().set_shell_var("VS2017_PREFIX", prefix) - shell_environment.GetEnvironment().set_shell_var("VS2017_HOST", HostType) - - shell_env = shell_environment.GetEnvironment() - # Use the tools lib to determine the correct values for the vars that interest us. - vs_vars = locate_tools.QueryVcVariables( - interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType], vs_version="vs2017") - for (k, v) in vs_vars.items(): - shell_env.set_shell_var(k, v) - - # now confirm it exists - if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("VS2017_PREFIX")): - self.Logger.error("Path for VS2017 toolchain is invalid") - return -2 - # # VS2019 - Follow VS2019 where there is potential for many versions of the tools. # If a specific version is required then the user must set both env variables: # VS160INSTALLPATH: base install path on system to VC install dir. Here you will find the VC folder, etc # VS160TOOLVER: version number for the VC compiler tools # VS2019_PREFIX: path to MSVC compiler folder with trailing slash (can be used instead of two vars above) - # VS2017_HOST: set the host architecture to use for host tools, and host libs, etc - elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2019": + # VS2019_HOST: set the host architecture to use for host tools, and host libs, etc + if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2019": # check to see if host is configured # HostType for VS2019 should be (defined in tools_def): diff --git a/BaseTools/get_vsvars.bat b/BaseTools/get_vsvars.bat index 87e2a1e4e5..1ed40758be 100644 --- a/BaseTools/get_vsvars.bat +++ b/BaseTools/get_vsvars.bat @@ -11,7 +11,6 @@ set SCRIPT_ERROR=0 if "%1"=="" goto main if /I "%1"=="VS2019" goto VS2019Vars -if /I "%1"=="VS2017" goto VS2017Vars :set_vsvars if defined VCINSTALLDIR goto :EOF @@ -62,22 +61,5 @@ if defined VCINSTALLDIR goto :done ) if /I "%1"=="VS2019" goto ToolNotInstall - :VS2017Vars - if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( - if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools" ( - call :set_vsvars "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 15,16 - ) else ( - call :set_vsvars "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version 15,16 - ) - ) - if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" ( - if exist "%ProgramFiles%\Microsoft Visual Studio\2017\BuildTools" ( - call :set_vsvars "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 15,16 - ) else ( - call :set_vsvars "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -version 15,16 - ) - ) - if /I "%1"=="VS2017" goto ToolNotInstall - :done set GET_VSVARS_BAT_CHECK_DIR= diff --git a/BaseTools/set_vsprefix_envs.bat b/BaseTools/set_vsprefix_envs.bat index e6bcf33d31..74a4dbf4b2 100644 --- a/BaseTools/set_vsprefix_envs.bat +++ b/BaseTools/set_vsprefix_envs.bat @@ -21,7 +21,6 @@ goto :EOF if /I "%1"=="VS2026" goto SetVS2026 if /I "%1"=="VS2022" goto SetVS2022 if /I "%1"=="VS2019" goto SetVS2019 -if /I "%1"=="VS2017" goto SetVS2017 if defined VS71COMNTOOLS ( if not defined VS2003_PREFIX ( @@ -29,67 +28,6 @@ if defined VS71COMNTOOLS ( ) ) -:SetVS2017 -if not defined VS150COMNTOOLS ( - @REM clear two envs so that vcvars32.bat can run successfully. - set VSINSTALLDIR= - set VCToolsVersion= - if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( - if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools" ( - call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 15,16 > vswhereInfo - for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do ( - if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" - ) - del vswhereInfo - ) else ( - call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version 15,16 > vswhereInfo - for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do ( - if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" - ) - del vswhereInfo - ) - ) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" ( - if exist "%ProgramFiles%\Microsoft Visual Studio\2017\BuildTools" ( - call "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 15,16 > vswhereInfo - for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do ( - if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" - ) - del vswhereInfo - ) else ( - call "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -version 15,16 > vswhereInfo - for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do ( - if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" - ) - del vswhereInfo - ) - ) else ( - if /I "%1"=="VS2017" goto ToolNotInstall - goto SetWinDDK - ) -) - -if defined VCToolsInstallDir ( - if not defined VS2017_PREFIX ( - set "VS2017_PREFIX=%VCToolsInstallDir%" - ) - if not defined WINSDK10_PREFIX ( - if defined WindowsSdkVerBinPath ( - set "WINSDK10_PREFIX=%WindowsSdkVerBinPath%" - ) else if exist "%ProgramFiles(x86)%\Windows Kits\10\bin" ( - set "WINSDK10_PREFIX=%ProgramFiles(x86)%\Windows Kits\10\bin\" - ) else if exist "%ProgramFiles%\Windows Kits\10\bin" ( - set "WINSDK10_PREFIX=%ProgramFiles%\Windows Kits\10\bin\" - ) - ) -) -if not defined WINSDK_PATH_FOR_RC_EXE ( - if defined WINSDK10_PREFIX ( - set "WINSDK_PATH_FOR_RC_EXE=%WINSDK10_PREFIX%x86" - ) -) - -if /I "%1"=="VS2017" goto SetWinDDK - :SetVS2019 if not defined VS160COMNTOOLS ( @REM clear two envs so that vcvars32.bat can run successfully. diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat index 3b8486a30a..3cc8517ae5 100755 --- a/BaseTools/toolsetup.bat +++ b/BaseTools/toolsetup.bat @@ -67,12 +67,6 @@ if /I "%1"=="/?" goto Usage set VSTool=VS2019 goto loop ) - if /I "%1"=="VS2017" ( - shift - set VS2017=TRUE - set VSTool=VS2017 - goto loop - ) if "%1"=="" goto setup_workspace if exist %1 ( if not defined BASE_TOOLS_PATH ( @@ -326,8 +320,6 @@ if defined VS2026 ( call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2022 ) else if defined VS2019 ( call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2019 -) else if defined VS2017 ( - call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2017 ) else if not defined BASETOOLS_MINGW_BUILD ( call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat call %EDK_TOOLS_PATH%\get_vsvars.bat @@ -581,7 +573,7 @@ endlocal :Usage @echo. - @echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [Mingw-w64] [base_tools_path [edk_tools_path]] [VS2026] [VS2022] [VS2019] [VS2017]" + @echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [Mingw-w64] [base_tools_path [edk_tools_path]] [VS2026] [VS2022] [VS2019]" @echo. @echo base_tools_path BaseTools project path, BASE_TOOLS_PATH will be set to this path. @echo edk_tools_path EDK_TOOLS_PATH will be set to this path. @@ -591,7 +583,6 @@ endlocal @echo whether they have been updated or not. @echo Reconfig Reinstall target.txt, tools_def.txt and build_rule.txt. @echo Mingw-w64 Build BaseTools binaries using mingw-w64. - @echo VS2017 Set the env for VS2017 build. @echo VS2019 Set the env for VS2019 build. @echo VS2022 Set the env for VS2022 build. @echo VS2026 Set the env for VS2026 build. @@ -604,7 +595,6 @@ set RECONFIG= set VS2026= set VS2022= set VS2019= -set VS2017= set VSTool= set PYTHON_VER_MAJOR= set PYTHON_VER_MINOR= From 7bd23c60e83d1746a3574b5a855c4689b8d25e9d Mon Sep 17 00:00:00 2001 From: "Michael G.A. Holland" Date: Mon, 22 Jun 2026 08:29:36 -0700 Subject: [PATCH 123/406] CryptoPkg/BaseCryptLib: Add ED448 verification and signature fcns Implemented signature and verification functions for ED448; Updated documentation and unit tests to cover new verification functions Signed-off-by: Michael G.A. Holland --- CryptoPkg/Driver/Crypto.c | 345 +++++++ CryptoPkg/Include/Library/BaseCryptLib.h | 312 +++++- .../Pcd/PcdCryptoServiceFamilyEnable.h | 15 + .../Library/BaseCryptLib/BaseCryptLib.inf | 2 + CryptoPkg/Library/BaseCryptLib/KeyContext.h | 16 + .../Library/BaseCryptLib/PeiCryptLib.inf | 2 + CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c | 138 +++ .../Library/BaseCryptLib/Pem/CryptPemNull.c | 30 + .../Library/BaseCryptLib/Pk/CryptEdDsa.c | 615 ++++++++++++ .../Library/BaseCryptLib/Pk/CryptEdDsaNull.c | 303 ++++++ CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c | 114 +++ .../Library/BaseCryptLib/Pk/CryptX509Null.c | 28 + .../Library/BaseCryptLib/RuntimeCryptLib.inf | 2 + .../Library/BaseCryptLib/SecCryptLib.inf | 2 + .../Library/BaseCryptLib/SmmCryptLib.inf | 2 + .../BaseCryptLib/UnitTestHostBaseCryptLib.inf | 1 + .../BaseCryptLibMbedTls/Pem/CryptPem.c | 30 + .../BaseCryptLibMbedTls/Pem/CryptPemNull.c | 30 + .../BaseCryptLibMbedTls/Pk/CryptEdDsaNull.c | 303 ++++++ .../BaseCryptLibMbedTls/Pk/CryptX509.c | 28 + .../BaseCryptLibMbedTls/Pk/CryptX509Null.c | 28 + .../UnitTestHostBaseCryptLib.inf | 1 + .../BaseCryptLibNull/BaseCryptLibNull.inf | 1 + .../BaseCryptLibNull/Pem/CryptPemNull.c | 30 + .../BaseCryptLibNull/Pk/CryptEdDsaNull.c | 303 ++++++ .../BaseCryptLibNull/Pk/CryptX509Null.c | 28 + .../BaseCryptLibOnProtocolPpi/CryptLib.c | 341 +++++++ .../Library/OpensslLib/OpensslStub/uefiprov.c | 10 + CryptoPkg/Private/Protocol/Crypto.h | 316 +++++- .../BaseCryptLib/BaseCryptLibUnitTests.c | 1 + .../Library/BaseCryptLib/EdDsaTests.c | 923 ++++++++++++++++++ .../Library/BaseCryptLib/TestBaseCryptLib.h | 3 + .../BaseCryptLib/TestBaseCryptLibHost.inf | 1 + .../BaseCryptLib/TestBaseCryptLibShell.inf | 1 + 34 files changed, 4303 insertions(+), 2 deletions(-) create mode 100644 CryptoPkg/Library/BaseCryptLib/KeyContext.h create mode 100644 CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsa.c create mode 100644 CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsaNull.c create mode 100644 CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptEdDsaNull.c create mode 100644 CryptoPkg/Library/BaseCryptLibNull/Pk/CryptEdDsaNull.c create mode 100644 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/EdDsaTests.c diff --git a/CryptoPkg/Driver/Crypto.c b/CryptoPkg/Driver/Crypto.c index 24ef6c159f..c826b1e6bf 100644 --- a/CryptoPkg/Driver/Crypto.c +++ b/CryptoPkg/Driver/Crypto.c @@ -7313,6 +7313,340 @@ CryptoServiceEcDsaVerify ( return CALL_BASECRYPTLIB (Ec.Services.DsaVerify, EcDsaVerify, (EcContext, HashNid, MessageHash, HashSize, Signature, SigSize), FALSE); } +/** + Creates a new EdDSA context by Crypto NID. + + This function allocates and initializes a new EdDSA context for the specified + curve. The context stores the curve NID and will hold an EVP_PKEY structure + after a key is set. The caller must call EdDsaFree() to release the context + when done. + + Before keys can be used for signing or verification, they must be set using + EdDsaSetPrivKey() or EdDsaSetPubKey(). + + If Nid is not a supported EdDSA curve, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the EdDSA curve (e.g., CRYPTO_NID_ED448). + + @retval Pointer to new EdDSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +CryptoServiceEdDsaNewByNid ( + IN UINTN Nid + ) +{ + return CALL_BASECRYPTLIB (EdDsa.Services.NewByNid, EdDsaNewByNid, (Nid), NULL); +} + +/** + Frees an EdDSA context and all associated resources. + + This function releases all memory associated with the EdDSA context, including + the EVP_PKEY structure. After calling this function, the EdDsaContext pointer + should not be used. + + If EdDsaContext is NULL, then this function returns immediately without action. + + @param[in] EdDsaContext Pointer to the EdDSA context to be released. + +**/ +VOID +EFIAPI +CryptoServiceEdDsaFree ( + IN VOID *EdDsaContext + ) +{ + CALL_VOID_BASECRYPTLIB (EdDsa.Services.Free, EdDsaFree, (EdDsaContext)); +} + +/** + Sets the EdDSA private key in the EdDSA context. + + This function imports a raw private key into the EdDSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If EdDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize is 0, then return FALSE. + If PrivateKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE EdDSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +CryptoServiceEdDsaSetPrivKey ( + IN VOID *EdDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + return CALL_BASECRYPTLIB (EdDsa.Services.SetPrivKey, EdDsaSetPrivKey, (EdDsaContext, PrivateKey, PrivateKeySize), FALSE); +} + +/** + Generates the EdDSA public key from the private key. + + This function is a placeholder and always returns TRUE. In practice, OpenSSL + automatically derives the public key when a private key is set using + EdDsaSetPrivKey(), so explicit public key generation is not needed. + + Use EdDsaGetPubKey() to retrieve the public key after setting the private key. + + @param[in] EdDsaContext Pointer to EdDSA context. + @param[out] PublicKey Pointer to buffer for public key (unused). + @param[in] PublicKeySize Size of public key buffer (unused). + + @retval TRUE Always returns TRUE. + +**/ +BOOLEAN +EFIAPI +CryptoServiceEdDsaGeneratePubKey ( + IN VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + return CALL_BASECRYPTLIB (EdDsa.Services.GeneratePubKey, EdDsaGeneratePubKey, (EdDsaContext, PublicKey, PublicKeySize), TRUE); +} + +/** + Sets the EdDSA public key in the EdDSA context. + + This function imports a raw public key into the EdDSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is 0, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE EdDSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +CryptoServiceEdDsaSetPubKey ( + IN VOID *EdDsaContext, + IN CONST UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + return CALL_BASECRYPTLIB (EdDsa.Services.SetPubKey, EdDsaSetPubKey, (EdDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieves the EdDSA public key from the EdDSA context. + + This function extracts the public key from the EdDSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via EdDsaSetPrivKey() or EdDsaSetPubKey()) + before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE EdDSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +CryptoServiceEdDsaGetPubKey ( + IN VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + return CALL_BASECRYPTLIB (EdDsa.Services.GetPubKey, EdDsaGetPubKey, (EdDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieve the Ed-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] EdDsaContext Pointer to new-generated Ed DSA context which contain the retrieved + Ed-Dsa public key component. Use EdDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDsa Public Key was retrieved successfully. + @retval FALSE Fail to retrieve EdDsa public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +CryptoServiceEdDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **EdDsaContext + ) +{ + return CALL_BASECRYPTLIB (EdDsa.Services.GetPublicKeyFromX509, EdDsaGetPublicKeyFromX509, (Cert, CertSize, EdDsaContext), FALSE); +} + +/** + Retrieve the EdDSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contains the retrieved + EdDSA private key component. Use EdDsaFree() function to free the + resource. + + If PemData is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +CryptoServiceEdDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **EdDsaContext + ) +{ + return CALL_BASECRYPTLIB (EdDsa.Services.GetPrivateKeyFromPem, EdDsaGetPrivateKeyFromPem, (PemData, PemSize, Password, EdDsaContext), FALSE); +} + +/** + Generates an EdDSA signature for a given message. + + This function creates an EdDSA signature using the private key stored in the + EdDSA context. EdDSA uses a 'pure' signature scheme where the entire message + is processed directly without pre-computing a hash digest. + + For Ed448, an optional context string can be provided for domain separation. + This allows the same key to be used in different contexts without creating + security vulnerabilities. + + The context must contain a private key (set via EdDsaSetPrivKey() or loaded + from PEM) before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0 or exceeds INT_MAX, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + For Ed448: Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] EdDsaContext Pointer to EdDSA context containing the private key. + @param[in] Context Optional context string for Ed448 domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (114 bytes for Ed448). + + @retval TRUE EdDSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +CryptoServiceEdDsaSign ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + return CALL_BASECRYPTLIB (EdDsa.Services.Sign, EdDsaSign, (EdDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} + +/** + Verifies the EdDSA signature for a given message. + + This function verifies an EdDSA signature against a message using the public key + contained in the EdDSA context. EdDSA signatures use a 'pure' implementation, + meaning the message digest cannot be computed ahead of time - the raw message + data is passed directly to the verification function. + + For Ed448, an optional context string can be provided as additional domain + separation. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + If SigSize does not match expected signature size for the key type, then return FALSE. + For Ed448: Context may be NULL if no context string is used. + + @param[in] EdDsaContext Pointer to EdDSA context containing the public key. + @param[in] Context Optional context string for Ed448 (domain separation). + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the EdDSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + Must be 2 * key_size (114 bytes for Ed448). + + @retval TRUE EdDSA signature verification succeeded. + @retval FALSE EdDSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +CryptoServiceEdDsaVerify ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + return CALL_BASECRYPTLIB (EdDsa.Services.Verify, EdDsaVerify, (EdDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} + const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = { /// Version CryptoServiceGetCryptoVersion, @@ -7642,4 +7976,15 @@ const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = { /// RSA PSS (Continued) CryptoServiceRsaPssSignDigest, CryptoServiceRsaPssVerifyDigest, + /// EdDSA + CryptoServiceEdDsaNewByNid, + CryptoServiceEdDsaFree, + CryptoServiceEdDsaSetPrivKey, + CryptoServiceEdDsaGeneratePubKey, + CryptoServiceEdDsaSetPubKey, + CryptoServiceEdDsaGetPubKey, + CryptoServiceEdDsaGetPublicKeyFromX509, + CryptoServiceEdDsaGetPrivateKeyFromPem, + CryptoServiceEdDsaSign, + CryptoServiceEdDsaVerify, }; diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h b/CryptoPkg/Include/Library/BaseCryptLib.h index f31b7d6160..5e6c0b676b 100644 --- a/CryptoPkg/Include/Library/BaseCryptLib.h +++ b/CryptoPkg/Include/Library/BaseCryptLib.h @@ -4,7 +4,7 @@ primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security functionality enabling. -Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2026, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation. All rights reserved. (c) Copyright 2026 HP Development Company, L.P. SPDX-License-Identifier: BSD-2-Clause-Patent @@ -28,6 +28,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define CRYPTO_NID_SECP521R1 0x0206 #define CRYPTO_NID_BRAINPOOLP512R1 0x03A5 +// EdDSA +#define CRYPTO_NID_ED448 0x0440 + /// /// MD5 digest size in bytes /// @@ -4720,3 +4723,310 @@ EcDsaVerify ( IN CONST UINT8 *Signature, IN UINTN SigSize ); + +/** + Creates a new EdDSA context by Crypto NID. + + This function allocates and initializes a new EdDSA context for the specified + curve. The context stores the curve NID and will hold an EVP_PKEY structure + after a key is set. The caller must call EdDsaFree() to release the context + when done. + + Before keys can be used for signing or verification, they must be set using + EdDsaSetPrivKey() or EdDsaSetPubKey(). + + If Nid is not a supported EdDSA curve, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the EdDSA curve (e.g., CRYPTO_NID_ED448). + + @retval Pointer to new EdDSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +EdDsaNewByNid ( + IN UINTN Nid + ); + +/** + Frees an EdDSA context and all associated resources. + + This function releases all memory associated with the EdDSA context, including + the EVP_PKEY structure. After calling this function, the EdDsaContext pointer + should not be used. + + If EdDsaContext is NULL, then this function returns immediately without action. + + @param[in] EdDsaContext Pointer to the EdDSA context to be released. + +**/ +VOID +EFIAPI +EdDsaFree ( + IN VOID *EdDsaContext + ); + +/** + Sets the EdDSA private key in the EdDSA context. + + This function imports a raw private key into the EdDSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If EdDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize is 0, then return FALSE. + If PrivateKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE EdDSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPrivKey ( + IN VOID *EdDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ); + +/** + Generates the EdDSA public key from the private key. + + This function is a placeholder and always returns TRUE. In practice, OpenSSL + automatically derives the public key when a private key is set using + EdDsaSetPrivKey(), so explicit public key generation is not needed. + + Use EdDsaGetPubKey() to retrieve the public key after setting the private key. + + @param[in] EdDsaContext Pointer to EdDSA context. + @param[out] PublicKey Pointer to buffer for public key (unused). + @param[in] PublicKeySize Size of public key buffer (unused). + + @retval TRUE Always returns TRUE. + +**/ +BOOLEAN +EFIAPI +EdDsaGeneratePubKey ( + IN VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Sets the EdDSA public key in the EdDSA context. + + This function imports a raw public key into the EdDSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is 0, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE EdDSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPubKey ( + IN VOID *EdDsaContext, + IN CONST UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Retrieves the EdDSA public key from the EdDSA context. + + This function extracts the public key from the EdDSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via EdDsaSetPrivKey() or EdDsaSetPubKey()) + before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE EdDSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPubKey ( + IN VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ); + +/** + Generates an EdDSA signature for a given message. + + This function creates an EdDSA signature using the private key stored in the + EdDSA context. EdDSA uses a 'pure' signature scheme where the entire message + is processed directly without pre-computing a hash digest. + + For Ed448, an optional context string can be provided for domain separation. + This allows the same key to be used in different contexts without creating + security vulnerabilities. + + The context must contain a private key (set via EdDsaSetPrivKey() or loaded + from PEM) before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If HashNid is invalid for the curve type, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0 or exceeds INT_MAX, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + For Ed448: Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] EdDsaContext Pointer to EdDSA context containing the private key. + @param[in] HashNid Hash algorithm NID (must match curve requirements). + @param[in] Context Optional context string for Ed448 domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (114 bytes for Ed448). + + @retval TRUE EdDSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +EdDsaSign ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + OUT UINTN *SigSize + ); + +/** + Verifies the EdDSA signature for a given message. + + This function verifies an EdDSA signature against a message using the public key + contained in the EdDSA context. EdDSA signatures use a 'pure' implementation, + meaning the message digest cannot be computed ahead of time - the raw message + data is passed directly to the verification function. + + For Ed448, an optional context string can be provided as additional domain + separation. + + If EdDsaContext is NULL, then return FALSE. + If HashNid is invalid, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + If SigSize does not match expected signature size for the key type, then return FALSE. + For Ed448: Context may be NULL if no context string is used. + + @param[in] EdDsaContext Pointer to EdDSA context containing the public key. + @param[in] HashNid Hash algorithm NID (must match key type requirements). + @param[in] Context Optional context string for Ed448 (domain separation). + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the EdDSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + Must be 2 * key_size (114 bytes for Ed448). + + @retval TRUE EdDSA signature verification succeeded. + @retval FALSE EdDSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +EdDsaVerify ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ); + +/** + Retrieve the EdDSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contains + the retrieved EdDSA private key. Use EdDsaFree() to free. + + @retval TRUE EdDSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **EdDsaContext + ); + +/** + Retrieve the EdDSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contain the retrieved + EdDsa public key component. Use EdDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDsa Public Key was retrieved successfully. + @retval FALSE Fail to retrieve EdDsa public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **EdDsaContext + ); diff --git a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h index 7c5173f180..4e5a679bfa 100644 --- a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h +++ b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h @@ -453,4 +453,19 @@ typedef struct { } Services; UINT32 Family; } Camellia; + union { + struct { + UINT8 NewByNid : 1; + UINT8 Free : 1; + UINT8 SetPrivKey : 1; + UINT8 GeneratePubKey : 1; + UINT8 SetPubKey : 1; + UINT8 GetPubKey : 1; + UINT8 GetPrivateKeyFromPem : 1; + UINT8 GetPublicKeyFromX509 : 1; + UINT8 Sign : 1; + UINT8 Verify : 1; + } Services; + UINT32 Family; + } EdDsa; } PCD_CRYPTO_SERVICE_FAMILY_ENABLE; diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf index 8190968a53..9c0752655d 100644 --- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf @@ -30,6 +30,7 @@ [Sources] InternalCryptLib.h + KeyContext.h Hash/CryptMd5.c Hash/CryptSha1.c Hash/CryptSha256.c @@ -60,6 +61,7 @@ Pk/CryptRsaPss.c Pk/CryptRsaPssSign.c Pk/CryptEc.c + Pk/CryptEdDsa.c Pem/CryptPem.c Bn/CryptBn.c diff --git a/CryptoPkg/Library/BaseCryptLib/KeyContext.h b/CryptoPkg/Library/BaseCryptLib/KeyContext.h new file mode 100644 index 0000000000..7267f413ac --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/KeyContext.h @@ -0,0 +1,16 @@ +/** @file + Key Context structure for EdDsa, ML-DSA and SLH-DSA APIs. + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#pragma once + +#include + +typedef struct { + INT32 Nid; + EVP_PKEY *EvpPkey; +} KEY_CONTEXT; diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf index 355ff6f78a..0f7a441cfa 100644 --- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf @@ -29,6 +29,7 @@ [Sources] InternalCryptLib.h + KeyContext.h Hash/CryptMd5.c Hash/CryptSha1.c Hash/CryptSha256.c @@ -59,6 +60,7 @@ Pk/CryptRsaPss.c Pk/CryptRsaPssSignNull.c Pk/CryptEcNull.c + Pk/CryptEdDsaNull.c Pem/CryptPemNull.c Rand/CryptRandNull.c Bn/CryptBnNull.c diff --git a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c index d64cf3d680..bd0c70d328 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c +++ b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "InternalCryptLib.h" +#include "KeyContext.h" #include /** @@ -44,6 +45,89 @@ PasswordCallback ( } } +/** + Retrieve a private key from PEM-encoded data using OpenSSL BIO. + This helper function creates a memory BIO, writes the PEM data to it, and reads + the private key using OpenSSL's PEM_read_bio_PrivateKey function. It supports + password-protected PEM data. + + @param[in] PemData Pointer to the PEM-encoded key data. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] Pkey Pointer to receive the EVP_PKEY structure containing the private key. + + @retval TRUE Private key was retrieved successfully. + @retval FALSE Failed to create BIO, write data, or read private key. +**/ +STATIC +BOOLEAN +GetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT EVP_PKEY **Pkey + ) +{ + BIO *PemBio; + BOOLEAN Result; + + // Create a memory BIO and write PEM data to it + PemBio = BIO_new (BIO_s_mem ()); + if (PemBio == NULL) { + return FALSE; + } + + if (BIO_write (PemBio, PemData, (int)PemSize) <= 0) { + BIO_free (PemBio); + return FALSE; + } + + Result = FALSE; + + // Read Private Key from encrypted PEM data + *Pkey = PEM_read_bio_PrivateKey (PemBio, NULL, (pem_password_cb *)&PasswordCallback, (void *)Password); + if (*Pkey != NULL) { + Result = TRUE; + } + + // Always free the BIO before returning + BIO_free (PemBio); + return Result; +} + +/** + Allocate and initialize a KEY_CONTEXT structure wrapping an EVP_PKEY. + This helper function allocates a KEY_CONTEXT structure and wraps the provided + EVP_PKEY pointer within it. + + @param[in] Pkey Pointer to an EVP_PKEY structure to be wrapped. + @param[in] Nid The NID representing the type of key (e.g., EVP_PKEY_ED448). + @param[out] Context Pointer to receive the allocated KEY_CONTEXT structure. + + @retval TRUE KEY_CONTEXT was allocated and initialized successfully. + @retval FALSE Memory allocation failed. +**/ +STATIC +BOOLEAN +AllocateKeyContext ( + IN EVP_PKEY *Pkey, + IN INT32 Nid, + OUT VOID **Context + ) +{ + KEY_CONTEXT *Ctx; + + Ctx = (KEY_CONTEXT *)AllocateZeroPool (sizeof (KEY_CONTEXT)); + if (Ctx == NULL) { + return FALSE; + } + + Ctx->EvpPkey = Pkey; + Ctx->Nid = Nid; + *Context = (VOID *)Ctx; + return TRUE; +} + /** Retrieve the RSA Private Key from the password-protected PEM key data. @@ -209,3 +293,57 @@ _Exit: return Status; } + +/** + Retrieve the EdDSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contains the retrieved + EdDSA private key component. Use EdDsaFree() function to free the + resource. + + If PemData is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **EdDsaContext + ) +{ + EVP_PKEY *Pkey; + INT32 Nid; + + // Check input parameters + if ((PemData == NULL) || (EdDsaContext == NULL) || (PemSize > INT_MAX)) { + return FALSE; + } + + // Read PEM data + if (!GetPrivateKeyFromPem (PemData, PemSize, Password, &Pkey)) { + return FALSE; + } + + Nid = EVP_PKEY_id (Pkey); + if (Nid != EVP_PKEY_ED448) { + EVP_PKEY_free (Pkey); + return FALSE; + } + + // Allocate wrapper structure (now consistent with other key types) + if (!AllocateKeyContext (Pkey, Nid, EdDsaContext)) { + EVP_PKEY_free (Pkey); + return FALSE; + } + + return TRUE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c index 4ca9357c96..d7373761de 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c +++ b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c @@ -66,3 +66,33 @@ EcGetPrivateKeyFromPem ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the EdDSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contains the retrieved + EdDSA private key component. Use EdDsaFree() function to free the + resource. + + If PemData is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **EdDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsa.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsa.c new file mode 100644 index 0000000000..106274d603 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsa.c @@ -0,0 +1,615 @@ +/** @file + EdDSA Curve API implementation based on OpenSSL + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "InternalCryptLib.h" +#include "KeyContext.h" +#include +#include + +/** + Get the key size in bytes for an EdDSA curve from its OpenSSL NID. + + This helper function maps OpenSSL curve NIDs to their corresponding key sizes. + For Ed448, the key size is 57 bytes. + + If the NID is not supported, CoordLen is set to 0 and FALSE is returned. + + @param[in] Nid OpenSSL NID of the EdDSA curve (e.g., EVP_PKEY_ED448). + @param[out] CoordLen Pointer to receive the key size in bytes. + + @retval TRUE Key size retrieved successfully. + @retval FALSE Unsupported curve NID. + +**/ +STATIC +BOOLEAN +OpensslNidToKeySize ( + IN UINTN Nid, + OUT UINTN *CoordLen + ) +{ + switch (Nid) { + case EVP_PKEY_ED448: + *CoordLen = 57; + break; + default: + *CoordLen = 0; + return FALSE; + } + + return TRUE; +} + +/** + Convert a Crypto NID to an OpenSSL NID. + + This helper function translates EDK II Crypto library NIDs (e.g., CRYPTO_NID_ED448) + to their corresponding OpenSSL EVP_PKEY NIDs (e.g., EVP_PKEY_ED448). + + If the Crypto NID is not supported, EVP_PKEY_NONE is returned. + + @param[in] CryptoNid EDK II Crypto library NID (e.g., CRYPTO_NID_ED448). + + @retval OpenSSL NID (e.g., EVP_PKEY_ED448) if supported. + @retval EVP_PKEY_NONE if the Crypto NID is unsupported. + +**/ +STATIC +INT32 +CryptoNidToOpensslNid ( + IN UINTN CryptoNid + ) +{ + INT32 Nid; + + switch (CryptoNid) { + case CRYPTO_NID_ED448: + Nid = EVP_PKEY_ED448; + break; + default: + Nid = EVP_PKEY_NONE; + break; + } + + return Nid; +} + +/** + Creates a new EdDSA context by Crypto NID. + + This function allocates and initializes a new EdDSA context for the specified + curve. The context stores the curve NID and will hold an EVP_PKEY structure + after a key is set. The caller must call EdDsaFree() to release the context + when done. + + Before keys can be used for signing or verification, they must be set using + EdDsaSetPrivKey() or EdDsaSetPubKey(). + + If Nid is not a supported EdDSA curve, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the EdDSA curve (e.g., CRYPTO_NID_ED448). + + @retval Pointer to new EdDSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +EdDsaNewByNid ( + IN UINTN Nid + ) +{ + KEY_CONTEXT *Ctx; + INT32 OpensslNid; + + OpensslNid = CryptoNidToOpensslNid (Nid); + if (OpensslNid <= EVP_PKEY_NONE) { + return NULL; + } + + Ctx = (KEY_CONTEXT *)AllocateZeroPool (sizeof (KEY_CONTEXT)); + if (Ctx == NULL) { + return NULL; + } + + Ctx->Nid = OpensslNid; + Ctx->EvpPkey = NULL; + + return (VOID *)Ctx; +} + +/** + Frees an EdDSA context and all associated resources. + + This function releases all memory associated with the EdDSA context, including + the EVP_PKEY structure. After calling this function, the EdDsaContext pointer + should not be used. + + If EdDsaContext is NULL, then this function returns immediately without action. + + @param[in] EdDsaContext Pointer to the EdDSA context to be released. + +**/ +VOID +EFIAPI +EdDsaFree ( + IN VOID *EdDsaContext + ) +{ + KEY_CONTEXT *Ctx; + + if (EdDsaContext == NULL) { + return; + } + + Ctx = (KEY_CONTEXT *)EdDsaContext; + + if (Ctx->EvpPkey != NULL) { + EVP_PKEY_free (Ctx->EvpPkey); + } + + FreePool (Ctx); + + Ctx = NULL; +} + +/** + Sets the EdDSA private key in the EdDSA context. + + This function imports a raw private key into the EdDSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If EdDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize is 0, then return FALSE. + If PrivateKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE EdDSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPrivKey ( + IN VOID *EdDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + KEY_CONTEXT *Ctx; + UINTN FinalPrivateKeySize; + + if ((EdDsaContext == NULL) || (PrivateKey == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)EdDsaContext; + if (Ctx == NULL) { + return FALSE; + } + + if (!OpensslNidToKeySize (Ctx->Nid, &FinalPrivateKeySize)) { + return FALSE; + } + + if (FinalPrivateKeySize != PrivateKeySize) { + return FALSE; + } + + if (Ctx->EvpPkey != NULL) { + EVP_PKEY_free (Ctx->EvpPkey); + Ctx->EvpPkey = NULL; + } + + Ctx->EvpPkey = EVP_PKEY_new_raw_private_key (Ctx->Nid, NULL, PrivateKey, PrivateKeySize); + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + return TRUE; +} + +/** + Extracts the EdDSA public key from the EdDSA context. + + This function retrieves the public key from the EdDSA context and copies it to + the provided buffer. The context must have a key set (either via EdDsaSetPrivKey() + or EdDsaSetPubKey()) before calling this function. OpenSSL automatically derives + the public key when a private key is set. + + The public key is returned in raw binary format (57 bytes for Ed448). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the public key buffer in bytes. + Must match the key size for the curve (57 bytes for Ed448). + + @retval TRUE EdDSA public key extracted successfully. + @retval FALSE Invalid parameters or key extraction failed. + +**/ +BOOLEAN +EFIAPI +EdDsaGeneratePubKey ( + IN VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + return TRUE; +} + +/** + Sets the EdDSA public key in the EdDSA context. + + This function imports a raw public key into the EdDSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is 0, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE EdDSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPubKey ( + IN VOID *EdDsaContext, + IN CONST UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + KEY_CONTEXT *Ctx; + UINTN FinalPublicKeySize; + + if ((EdDsaContext == NULL) || (PublicKey == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)EdDsaContext; + if (Ctx == NULL) { + return FALSE; + } + + if (!OpensslNidToKeySize (Ctx->Nid, &FinalPublicKeySize)) { + return FALSE; + } + + if (FinalPublicKeySize != PublicKeySize) { + return FALSE; + } + + if (Ctx->EvpPkey != NULL) { + EVP_PKEY_free (Ctx->EvpPkey); + Ctx->EvpPkey = NULL; + } + + Ctx->EvpPkey = EVP_PKEY_new_raw_public_key (Ctx->Nid, NULL, PublicKey, PublicKeySize); + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + return TRUE; +} + +/** + Retrieves the EdDSA public key from the EdDSA context. + + This function extracts the public key from the EdDSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via EdDsaSetPrivKey() or EdDsaSetPubKey()) + before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE EdDSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPubKey ( + IN VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + KEY_CONTEXT *Ctx; + INT32 Result; + UINTN FinalPublicKeySize; + + if ((EdDsaContext == NULL) || (PublicKey == NULL) || (PublicKeySize == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)EdDsaContext; + if (Ctx == NULL) { + return FALSE; + } + + if (!OpensslNidToKeySize (Ctx->Nid, &FinalPublicKeySize)) { + return FALSE; + } + + if (*PublicKeySize < FinalPublicKeySize) { + *PublicKeySize = FinalPublicKeySize; + return FALSE; + } + + *PublicKeySize = FinalPublicKeySize; + + Result = EVP_PKEY_get_raw_public_key (Ctx->EvpPkey, PublicKey, PublicKeySize); + if (Result != 1) { + return FALSE; + } + + return TRUE; +} + +/** + Generates an EdDSA signature for a given message. + + This function creates an EdDSA signature using the private key stored in the + EdDSA context. EdDSA uses a 'pure' signature scheme where the entire message + is processed directly without pre-computing a hash digest. + + For Ed448, an optional context string can be provided for domain separation. + This allows the same key to be used in different contexts without creating + security vulnerabilities. + + The context must contain a private key (set via EdDsaSetPrivKey() or loaded + from PEM) before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0 or exceeds INT_MAX, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + For Ed448: Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] EdDsaContext Pointer to EdDSA context containing the private key. + @param[in] Context Optional context string for Ed448 domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (114 bytes for Ed448). + + @retval TRUE EdDSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +EdDsaSign ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + EVP_MD_CTX *SignCtx; + KEY_CONTEXT *Ctx; + INT32 Result; + UINTN HalfSize; + CONST OSSL_PARAM ParamsDefault[] = { + OSSL_PARAM_END + }; + + CONST OSSL_PARAM ParamsEd448[] = { + OSSL_PARAM_octet_string ("context-string", (VOID *)Context, ContextSize), + OSSL_PARAM_END + }; + + if ((EdDsaContext == NULL) || (Message == NULL)) { + return FALSE; + } + + if ((Signature == NULL) && (SigSize == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)EdDsaContext; + if (Ctx == NULL) { + return FALSE; + } + + if (!OpensslNidToKeySize (Ctx->Nid, &HalfSize)) { + return FALSE; + } + + if (*SigSize < (UINTN)(HalfSize * 2)) { + *SigSize = HalfSize * 2; + return FALSE; + } + + *SigSize = HalfSize * 2; + ZeroMem (Signature, *SigSize); + + SignCtx = EVP_MD_CTX_new (); + if (SignCtx == NULL) { + return FALSE; + } + + switch (Ctx->Nid) { + case EVP_PKEY_ED448: + if ((Context == NULL) || (ContextSize == 0)) { + Result = EVP_DigestSignInit_ex (SignCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, ParamsDefault); + } else { + Result = EVP_DigestSignInit_ex (SignCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, ParamsEd448); + } + + break; + default: + return FALSE; + } + + if (Result != 1) { + EVP_MD_CTX_free (SignCtx); + return FALSE; + } + + if (EVP_DigestSign (SignCtx, Signature, SigSize, Message, MessageSize) != 1) { + EVP_MD_CTX_free (SignCtx); + return FALSE; + } + + EVP_MD_CTX_free (SignCtx); + return TRUE; +} + +/** + Verifies the EdDSA signature for a given message. + + This function verifies an EdDSA signature against a message using the public key + contained in the EdDSA context. EdDSA signatures use a 'pure' implementation, + meaning the message digest cannot be computed ahead of time - the raw message + data is passed directly to the verification function. + + For Ed448, an optional context string can be provided as additional domain + separation. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + If SigSize does not match expected signature size for the key type, then return FALSE. + For Ed448: Context may be NULL if no context string is used. + + @param[in] EdDsaContext Pointer to EdDSA context containing the public key. + @param[in] Context Optional context string for Ed448 (domain separation). + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the EdDSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + Must be 2 * key_size (114 bytes for Ed448). + + @retval TRUE EdDSA signature verification succeeded. + @retval FALSE EdDSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +EdDsaVerify ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + EVP_MD_CTX *VerifyCtx; + KEY_CONTEXT *Ctx; + INT32 Result; + UINTN HalfSize; + CONST OSSL_PARAM ParamsDefault[] = { + OSSL_PARAM_END + }; + + CONST OSSL_PARAM ParamsEd448[] = { + OSSL_PARAM_octet_string ("context-string", (VOID *)Context, ContextSize), + OSSL_PARAM_END + }; + + if ((EdDsaContext == NULL) || (Message == NULL) || (Signature == NULL)) { + return FALSE; + } + + if ((SigSize > INT_MAX) || (SigSize == 0)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)EdDsaContext; + if (Ctx == NULL) { + return FALSE; + } + + if (!OpensslNidToKeySize (Ctx->Nid, &HalfSize)) { + return FALSE; + } + + if (SigSize != (UINTN)(HalfSize * 2)) { + return FALSE; + } + + VerifyCtx = EVP_MD_CTX_new (); + if (VerifyCtx == NULL) { + return FALSE; + } + + switch (Ctx->Nid) { + case EVP_PKEY_ED448: + if ((Context == NULL) || (ContextSize == 0)) { + Result = EVP_DigestVerifyInit_ex (VerifyCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, ParamsDefault); + } else { + Result = EVP_DigestVerifyInit_ex (VerifyCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, ParamsEd448); + } + + break; + default: + return FALSE; + } + + if (Result != 1) { + EVP_MD_CTX_free (VerifyCtx); + return FALSE; + } + + if (EVP_DigestVerify (VerifyCtx, Signature, SigSize, Message, MessageSize) != 1) { + EVP_MD_CTX_free (VerifyCtx); + return FALSE; + } + + EVP_MD_CTX_free (VerifyCtx); + return TRUE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsaNull.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsaNull.c new file mode 100644 index 0000000000..d8d06ceb94 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsaNull.c @@ -0,0 +1,303 @@ +/** @file + EdDSA Curve API implementation based on OpenSSL + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +/** + Creates a new EdDSA context by Crypto NID. + + This function allocates and initializes a new EdDSA context for the specified + curve. The context stores the curve NID and will hold an EVP_PKEY structure + after a key is set. The caller must call EdDsaFree() to release the context + when done. + + Before keys can be used for signing or verification, they must be set using + EdDsaSetPrivKey() or EdDsaSetPubKey(). + + If Nid is not a supported EdDSA curve, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the EdDSA curve (e.g., CRYPTO_NID_ED448). + + @retval Pointer to new EdDSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +EdDsaNewByNid ( + IN UINTN Nid + ) +{ + ASSERT (FALSE); + return NULL; +} + +/** + Frees an EdDSA context and all associated resources. + + This function releases all memory associated with the EdDSA context, including + the EVP_PKEY structure. After calling this function, the EdDsaContext pointer + should not be used. + + If EdDsaContext is NULL, then this function returns immediately without action. + + @param[in] EdDsaContext Pointer to the EdDSA context to be released. + +**/ +VOID +EFIAPI +EdDsaFree ( + IN VOID *EdDsaContext + ) +{ + ASSERT (FALSE); +} + +/** + Sets the EdDSA private key in the EdDSA context. + + This function imports a raw private key into the EdDSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If EdDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize is 0, then return FALSE. + If PrivateKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE EdDSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPrivKey ( + IN VOID *EdDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Extracts the EdDSA public key from the EdDSA context. + + This function retrieves the public key from the EdDSA context and copies it to + the provided buffer. The context must have a key set (either via EdDsaSetPrivKey() + or EdDsaSetPubKey()) before calling this function. OpenSSL automatically derives + the public key when a private key is set. + + The public key is returned in raw binary format (57 bytes for Ed448). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the public key buffer in bytes. + Must match the key size for the curve (57 bytes for Ed448). + + @retval TRUE EdDSA public key extracted successfully. + @retval FALSE Invalid parameters or key extraction failed. + +**/ +BOOLEAN +EFIAPI +EdDsaGeneratePubKey ( + IN VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the EdDSA public key in the EdDSA context. + + This function imports a raw public key into the EdDSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is 0, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE EdDSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPubKey ( + IN VOID *EdDsaContext, + IN CONST UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Retrieves the EdDSA public key from the EdDSA context. + + This function extracts the public key from the EdDSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via EdDsaSetPrivKey() or EdDsaSetPubKey()) + before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[in] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE EdDSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPubKey ( + IN VOID *EdDsaContext, + IN UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates an EdDSA signature for a given message. + + This function creates an EdDSA signature using the private key stored in the + EdDSA context. EdDSA uses a 'pure' signature scheme where the entire message + is processed directly without pre-computing a hash digest. + + For Ed448, an optional context string can be provided for domain separation. + This allows the same key to be used in different contexts without creating + security vulnerabilities. + + The context must contain a private key (set via EdDsaSetPrivKey() or loaded + from PEM) before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0 or exceeds INT_MAX, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + For Ed448: Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] EdDsaContext Pointer to EdDSA context containing the private key. + @param[in] Context Optional context string for Ed448 domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (114 bytes for Ed448). + + @retval TRUE EdDSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +EdDsaSign ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Verifies the EdDSA signature for a given message. + + This function verifies an EdDSA signature against a message using the public key + contained in the EdDSA context. EdDSA signatures use a 'pure' implementation, + meaning the message digest cannot be computed ahead of time - the raw message + data is passed directly to the verification function. + + For Ed448, an optional context string can be provided as additional domain + separation. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + If SigSize does not match expected signature size for the key type, then return FALSE. + For Ed448: Context may be NULL if no context string is used. + + @param[in] EdDsaContext Pointer to EdDSA context containing the public key. + @param[in] Context Optional context string for Ed448 (domain separation). + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the EdDSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + Must be 2 * key_size (114 bytes for Ed448). + + @retval TRUE EdDSA signature verification succeeded. + @retval FALSE EdDSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +EdDsaVerify ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c index 9923260e9e..3506956df1 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "InternalCryptLib.h" +#include "KeyContext.h" #include #include #include @@ -962,6 +963,119 @@ _Exit: return Status; } +/** + Retrieve the Ed-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] EdDsaContext Pointer to new-generated Ed DSA context which contain the retrieved + Ed-Dsa public key component. Use EdDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDsa Public Key was retrieved successfully. + @retval FALSE Fail to retrieve EdDsa public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **EdDsaContext + ) +{ + BOOLEAN Status; + EVP_PKEY *Pkey; + EVP_PKEY *DupPkey; + INT32 Nid; + X509 *X509Cert; + KEY_CONTEXT *Ctx; + + // + // Check input parameters. + // + if ((Cert == NULL) || (EdDsaContext == NULL)) { + return FALSE; + } + + // + // If CertSize is 0, return FALSE to be safe. + // + if (CertSize == 0) { + *EdDsaContext = NULL; + return FALSE; + } + + Pkey = NULL; + X509Cert = NULL; + Status = FALSE; + + // + // Read DER-encoded X509 Certificate and Construct X509 object. + // + Status = X509ConstructCertificate (Cert, CertSize, (UINT8 **)&X509Cert); + if (!Status || (X509Cert == NULL)) { + Status = FALSE; + goto _Exit; + } + + // + // Retrieve and check EVP_PKEY data from X509 Certificate. + // + Pkey = X509_get_pubkey (X509Cert); + if (Pkey == NULL) { + Status = FALSE; + goto _Exit; + } + + Nid = EVP_PKEY_id (Pkey); + if (Nid != EVP_PKEY_ED448) { + Status = FALSE; + goto _Exit; + } + + // + // Duplicate EdDSA Context from the retrieved EVP_PKEY. + // + DupPkey = EVP_PKEY_dup (Pkey); + if (DupPkey == NULL) { + Status = FALSE; + goto _Exit; + } + + // + // Allocate KEY_CONTEXT wrapper structure + // + Ctx = (KEY_CONTEXT *)AllocateZeroPool (sizeof (KEY_CONTEXT)); + if (Ctx == NULL) { + EVP_PKEY_free (DupPkey); + Status = FALSE; + goto _Exit; + } + + Ctx->Nid = Nid; + Ctx->EvpPkey = DupPkey; + *EdDsaContext = (VOID *)Ctx; + Status = TRUE; + +_Exit: + // + // Release Resources. + // + if (X509Cert != NULL) { + X509_free (X509Cert); + } + + if (Pkey != NULL) { + EVP_PKEY_free (Pkey); + } + + return Status; +} + /** Retrieve the version from one X.509 certificate. diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c index ae878aad22..125dd40957 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c @@ -321,6 +321,34 @@ EcGetPublicKeyFromX509 ( return FALSE; } +/** + Retrieve the Ed-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] EdDsaContext Pointer to new-generated Ed DSA context which contain the retrieved + Ed-Dsa public key component. Use EdDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDsa Public Key was retrieved successfully. + @retval FALSE Fail to retrieve EdDsa public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **EdDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} + /** Retrieve the version from one X.509 certificate. diff --git a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf index ca19049ea2..3b437c715d 100644 --- a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf @@ -36,6 +36,7 @@ [Sources] InternalCryptLib.h + KeyContext.h Hash/CryptMd5.c Hash/CryptSha1.c Hash/CryptSha256.c @@ -62,6 +63,7 @@ Pk/CryptRsaPssNull.c Pk/CryptRsaPssSignNull.c Pk/CryptEcNull.c + Pk/CryptEdDsaNull.c Pem/CryptPem.c Bn/CryptBnNull.c diff --git a/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf index 01ce6224ca..b3742a1486 100644 --- a/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf @@ -28,6 +28,7 @@ [Sources] InternalCryptLib.h + KeyContext.h Hash/CryptSha512.c Hash/CryptMd5Null.c @@ -56,6 +57,7 @@ Pk/CryptRsaPssNull.c Pk/CryptRsaPssSignNull.c Pk/CryptEcNull.c + Pk/CryptEdDsaNull.c Bn/CryptBnNull.c SysCall/CrtWrapper.c diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf index b09e62aa67..0cb03be53b 100644 --- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf @@ -33,6 +33,7 @@ [Sources] InternalCryptLib.h + KeyContext.h Hash/CryptMd5.c Hash/CryptSha1.c Hash/CryptSha256.c @@ -63,6 +64,7 @@ Pk/CryptRsaPss.c Pk/CryptRsaPssSignNull.c Pk/CryptEc.c + Pk/CryptEdDsa.c Pem/CryptPem.c Bn/CryptBn.c diff --git a/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf index 0c04c678f5..0bc9a68498 100644 --- a/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf @@ -51,6 +51,7 @@ Pk/CryptRsaPssSign.c Bn/CryptBn.c Pk/CryptEc.c + Pk/CryptEdDsa.c SysCall/UnitTestHostCrtWrapper.c diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c index ddcf8f4e73..1aff573979 100644 --- a/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c @@ -136,3 +136,33 @@ EcGetPrivateKeyFromPem ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the EdDSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contains the retrieved + EdDSA private key component. Use EdDsaFree() function to free the + resource. + + If PemData is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **EdDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPemNull.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPemNull.c index b3adf2f7d1..eb9e1274a7 100644 --- a/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPemNull.c +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPemNull.c @@ -67,3 +67,33 @@ EcGetPrivateKeyFromPem ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the EdDSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contains the retrieved + EdDSA private key component. Use EdDsaFree() function to free the + resource. + + If PemData is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **EdDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptEdDsaNull.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptEdDsaNull.c new file mode 100644 index 0000000000..d8d06ceb94 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptEdDsaNull.c @@ -0,0 +1,303 @@ +/** @file + EdDSA Curve API implementation based on OpenSSL + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +/** + Creates a new EdDSA context by Crypto NID. + + This function allocates and initializes a new EdDSA context for the specified + curve. The context stores the curve NID and will hold an EVP_PKEY structure + after a key is set. The caller must call EdDsaFree() to release the context + when done. + + Before keys can be used for signing or verification, they must be set using + EdDsaSetPrivKey() or EdDsaSetPubKey(). + + If Nid is not a supported EdDSA curve, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the EdDSA curve (e.g., CRYPTO_NID_ED448). + + @retval Pointer to new EdDSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +EdDsaNewByNid ( + IN UINTN Nid + ) +{ + ASSERT (FALSE); + return NULL; +} + +/** + Frees an EdDSA context and all associated resources. + + This function releases all memory associated with the EdDSA context, including + the EVP_PKEY structure. After calling this function, the EdDsaContext pointer + should not be used. + + If EdDsaContext is NULL, then this function returns immediately without action. + + @param[in] EdDsaContext Pointer to the EdDSA context to be released. + +**/ +VOID +EFIAPI +EdDsaFree ( + IN VOID *EdDsaContext + ) +{ + ASSERT (FALSE); +} + +/** + Sets the EdDSA private key in the EdDSA context. + + This function imports a raw private key into the EdDSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If EdDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize is 0, then return FALSE. + If PrivateKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE EdDSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPrivKey ( + IN VOID *EdDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Extracts the EdDSA public key from the EdDSA context. + + This function retrieves the public key from the EdDSA context and copies it to + the provided buffer. The context must have a key set (either via EdDsaSetPrivKey() + or EdDsaSetPubKey()) before calling this function. OpenSSL automatically derives + the public key when a private key is set. + + The public key is returned in raw binary format (57 bytes for Ed448). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the public key buffer in bytes. + Must match the key size for the curve (57 bytes for Ed448). + + @retval TRUE EdDSA public key extracted successfully. + @retval FALSE Invalid parameters or key extraction failed. + +**/ +BOOLEAN +EFIAPI +EdDsaGeneratePubKey ( + IN VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the EdDSA public key in the EdDSA context. + + This function imports a raw public key into the EdDSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is 0, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE EdDSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPubKey ( + IN VOID *EdDsaContext, + IN CONST UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Retrieves the EdDSA public key from the EdDSA context. + + This function extracts the public key from the EdDSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via EdDsaSetPrivKey() or EdDsaSetPubKey()) + before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[in] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE EdDSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPubKey ( + IN VOID *EdDsaContext, + IN UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates an EdDSA signature for a given message. + + This function creates an EdDSA signature using the private key stored in the + EdDSA context. EdDSA uses a 'pure' signature scheme where the entire message + is processed directly without pre-computing a hash digest. + + For Ed448, an optional context string can be provided for domain separation. + This allows the same key to be used in different contexts without creating + security vulnerabilities. + + The context must contain a private key (set via EdDsaSetPrivKey() or loaded + from PEM) before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0 or exceeds INT_MAX, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + For Ed448: Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] EdDsaContext Pointer to EdDSA context containing the private key. + @param[in] Context Optional context string for Ed448 domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (114 bytes for Ed448). + + @retval TRUE EdDSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +EdDsaSign ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Verifies the EdDSA signature for a given message. + + This function verifies an EdDSA signature against a message using the public key + contained in the EdDSA context. EdDSA signatures use a 'pure' implementation, + meaning the message digest cannot be computed ahead of time - the raw message + data is passed directly to the verification function. + + For Ed448, an optional context string can be provided as additional domain + separation. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + If SigSize does not match expected signature size for the key type, then return FALSE. + For Ed448: Context may be NULL if no context string is used. + + @param[in] EdDsaContext Pointer to EdDSA context containing the public key. + @param[in] Context Optional context string for Ed448 (domain separation). + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the EdDSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + Must be 2 * key_size (114 bytes for Ed448). + + @retval TRUE EdDSA signature verification succeeded. + @retval FALSE EdDSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +EdDsaVerify ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509.c index e1e33145ed..ac4c59ed79 100644 --- a/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509.c +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509.c @@ -679,6 +679,34 @@ EcGetPublicKeyFromX509 ( return FALSE; } +/** + Retrieve the Ed-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] EdDsaContext Pointer to new-generated Ed DSA context which contain the retrieved + Ed-Dsa public key component. Use EdDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDsa Public Key was retrieved successfully. + @retval FALSE Fail to retrieve EdDsa public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **EdDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} + /** Verify one X509 certificate was issued by the trusted CA. diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509Null.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509Null.c index 3cf9816854..5132e96ea3 100644 --- a/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509Null.c +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509Null.c @@ -321,6 +321,34 @@ EcGetPublicKeyFromX509 ( return FALSE; } +/** + Retrieve the Ed-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] EdDsaContext Pointer to new-generated Ed DSA context which contain the retrieved + Ed-Dsa public key component. Use EdDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDsa Public Key was retrieved successfully. + @retval FALSE Fail to retrieve EdDsa public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **EdDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} + /** Retrieve the version from one X.509 certificate. diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/UnitTestHostBaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLibMbedTls/UnitTestHostBaseCryptLib.inf index b5551a07e8..be075a4642 100644 --- a/CryptoPkg/Library/BaseCryptLibMbedTls/UnitTestHostBaseCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/UnitTestHostBaseCryptLib.inf @@ -53,6 +53,7 @@ Pk/CryptRsaPss.c Pk/CryptRsaPssSign.c Pk/CryptEcNull.c + Pk/CryptEdDsaNull.c Pem/CryptPem.c Bn/CryptBnNull.c Rand/CryptRand.c diff --git a/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf b/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf index d5687d17cc..d6b4d04e82 100644 --- a/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf +++ b/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf @@ -47,6 +47,7 @@ Pk/CryptAuthenticodeNull.c Pk/CryptTsNull.c Pk/CryptEcNull.c + Pk/CryptEdDsaNull.c Pem/CryptPemNull.c Rand/CryptRandNull.c Pk/CryptRsaPssNull.c diff --git a/CryptoPkg/Library/BaseCryptLibNull/Pem/CryptPemNull.c b/CryptoPkg/Library/BaseCryptLibNull/Pem/CryptPemNull.c index 4ca9357c96..d7373761de 100644 --- a/CryptoPkg/Library/BaseCryptLibNull/Pem/CryptPemNull.c +++ b/CryptoPkg/Library/BaseCryptLibNull/Pem/CryptPemNull.c @@ -66,3 +66,33 @@ EcGetPrivateKeyFromPem ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the EdDSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contains the retrieved + EdDSA private key component. Use EdDsaFree() function to free the + resource. + + If PemData is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **EdDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptEdDsaNull.c b/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptEdDsaNull.c new file mode 100644 index 0000000000..d8d06ceb94 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptEdDsaNull.c @@ -0,0 +1,303 @@ +/** @file + EdDSA Curve API implementation based on OpenSSL + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +/** + Creates a new EdDSA context by Crypto NID. + + This function allocates and initializes a new EdDSA context for the specified + curve. The context stores the curve NID and will hold an EVP_PKEY structure + after a key is set. The caller must call EdDsaFree() to release the context + when done. + + Before keys can be used for signing or verification, they must be set using + EdDsaSetPrivKey() or EdDsaSetPubKey(). + + If Nid is not a supported EdDSA curve, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the EdDSA curve (e.g., CRYPTO_NID_ED448). + + @retval Pointer to new EdDSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +EdDsaNewByNid ( + IN UINTN Nid + ) +{ + ASSERT (FALSE); + return NULL; +} + +/** + Frees an EdDSA context and all associated resources. + + This function releases all memory associated with the EdDSA context, including + the EVP_PKEY structure. After calling this function, the EdDsaContext pointer + should not be used. + + If EdDsaContext is NULL, then this function returns immediately without action. + + @param[in] EdDsaContext Pointer to the EdDSA context to be released. + +**/ +VOID +EFIAPI +EdDsaFree ( + IN VOID *EdDsaContext + ) +{ + ASSERT (FALSE); +} + +/** + Sets the EdDSA private key in the EdDSA context. + + This function imports a raw private key into the EdDSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If EdDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize is 0, then return FALSE. + If PrivateKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE EdDSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPrivKey ( + IN VOID *EdDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Extracts the EdDSA public key from the EdDSA context. + + This function retrieves the public key from the EdDSA context and copies it to + the provided buffer. The context must have a key set (either via EdDsaSetPrivKey() + or EdDsaSetPubKey()) before calling this function. OpenSSL automatically derives + the public key when a private key is set. + + The public key is returned in raw binary format (57 bytes for Ed448). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the public key buffer in bytes. + Must match the key size for the curve (57 bytes for Ed448). + + @retval TRUE EdDSA public key extracted successfully. + @retval FALSE Invalid parameters or key extraction failed. + +**/ +BOOLEAN +EFIAPI +EdDsaGeneratePubKey ( + IN VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the EdDSA public key in the EdDSA context. + + This function imports a raw public key into the EdDSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is 0, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE EdDSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPubKey ( + IN VOID *EdDsaContext, + IN CONST UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Retrieves the EdDSA public key from the EdDSA context. + + This function extracts the public key from the EdDSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via EdDsaSetPrivKey() or EdDsaSetPubKey()) + before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[in] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE EdDSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPubKey ( + IN VOID *EdDsaContext, + IN UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates an EdDSA signature for a given message. + + This function creates an EdDSA signature using the private key stored in the + EdDSA context. EdDSA uses a 'pure' signature scheme where the entire message + is processed directly without pre-computing a hash digest. + + For Ed448, an optional context string can be provided for domain separation. + This allows the same key to be used in different contexts without creating + security vulnerabilities. + + The context must contain a private key (set via EdDsaSetPrivKey() or loaded + from PEM) before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0 or exceeds INT_MAX, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + For Ed448: Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] EdDsaContext Pointer to EdDSA context containing the private key. + @param[in] Context Optional context string for Ed448 domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (114 bytes for Ed448). + + @retval TRUE EdDSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +EdDsaSign ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Verifies the EdDSA signature for a given message. + + This function verifies an EdDSA signature against a message using the public key + contained in the EdDSA context. EdDSA signatures use a 'pure' implementation, + meaning the message digest cannot be computed ahead of time - the raw message + data is passed directly to the verification function. + + For Ed448, an optional context string can be provided as additional domain + separation. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + If SigSize does not match expected signature size for the key type, then return FALSE. + For Ed448: Context may be NULL if no context string is used. + + @param[in] EdDsaContext Pointer to EdDSA context containing the public key. + @param[in] Context Optional context string for Ed448 (domain separation). + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the EdDSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + Must be 2 * key_size (114 bytes for Ed448). + + @retval TRUE EdDSA signature verification succeeded. + @retval FALSE EdDSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +EdDsaVerify ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptX509Null.c b/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptX509Null.c index 128fcf1241..d4edcc9649 100644 --- a/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptX509Null.c +++ b/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptX509Null.c @@ -321,6 +321,34 @@ EcGetPublicKeyFromX509 ( return FALSE; } +/** + Retrieve the Ed-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] EdDsaContext Pointer to new-generated Ed DSA context which contain the retrieved + Ed-Dsa public key component. Use EdDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDsa Public Key was retrieved successfully. + @retval FALSE Fail to retrieve EdDsa public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **EdDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} + /** Retrieve the version from one X.509 certificate. diff --git a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c index 21b93883a5..0151d31a12 100644 --- a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c +++ b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c @@ -6329,3 +6329,344 @@ EcDsaVerify ( { CALL_CRYPTO_SERVICE (EcDsaVerify, (EcContext, HashNid, MessageHash, HashSize, Signature, SigSize), FALSE); } + +/** + Creates a new EdDSA context by Crypto NID. + + This function allocates and initializes a new EdDSA context for the specified + curve. The context contains an EVP_PKEY structure initialized with the curve + parameters. The caller must call EdDsaFree() to release the context when done. + + Before keys can be used for signing or verification, they must be set using + EdDsaSetPrivKey() or EdDsaSetPubKey(). + + If Nid is not a supported EdDSA curve, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the EdDSA curve (e.g., CRYPTO_NID_ED448). + + @retval Pointer to new EdDSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +EdDsaNewByNid ( + IN UINTN Nid + ) +{ + CALL_CRYPTO_SERVICE (EdDsaNewByNid, (Nid), NULL); +} + +/** + Frees an EdDSA context and all associated resources. + + This function releases all memory associated with the EdDSA context, including + the EVP_PKEY structure. After calling this function, the EdDsaContext pointer + should not be used. + + If EdDsaContext is NULL, then this function returns immediately without action. + + @param[in] EdDsaContext Pointer to the EdDSA context to be released. + +**/ +VOID +EFIAPI +EdDsaFree ( + IN VOID *EdDsaContext + ) +{ + CALL_VOID_CRYPTO_SERVICE (EdDsaFree, (EdDsaContext)); +} + +/** + Sets the EdDSA private key in the EdDSA context. + + This function imports a raw private key into the EdDSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If EdDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize is 0, then return FALSE. + If PrivateKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE EdDSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPrivKey ( + IN VOID *EdDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + CALL_CRYPTO_SERVICE (EdDsaSetPrivKey, (EdDsaContext, PrivateKey, PrivateKeySize), FALSE); +} + +/** + Extracts the EdDSA public key from the EdDSA context. + + This function retrieves the public key from the EdDSA context and copies it to + the provided buffer. The context must have a key set (either via EdDsaSetPrivKey() + or EdDsaSetPubKey()) before calling this function. OpenSSL automatically derives + the public key when a private key is set. + + The public key is returned in raw binary format (57 bytes for Ed448). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the public key buffer in bytes. + Must match the key size for the curve (57 bytes for Ed448). + + @retval TRUE EdDSA public key extracted successfully. + @retval FALSE Invalid parameters or key extraction failed. + +**/ +BOOLEAN +EFIAPI +EdDsaGeneratePubKey ( + IN VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + CALL_CRYPTO_SERVICE (EdDsaGeneratePubKey, (EdDsaContext, PublicKey, PublicKeySize), TRUE); +} + +/** + Sets the EdDSA public key in the EdDSA context. + + This function imports a raw public key into the EdDSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is 0, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE EdDSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +EdDsaSetPubKey ( + IN VOID *EdDsaContext, + IN CONST UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + CALL_CRYPTO_SERVICE (EdDsaSetPubKey, (EdDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieves the EdDSA public key from the EdDSA context. + + This function extracts the public key from the EdDSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via EdDsaSetPrivKey() or EdDsaSetPubKey()) + before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[in] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE EdDSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPubKey ( + IN VOID *EdDsaContext, + IN UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + CALL_CRYPTO_SERVICE (EdDsaGetPubKey, (EdDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieve the EdDSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contains the retrieved + EdDSA private key component. Use EdDsaFree() function to free the + resource. + + If PemData is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **EdDsaContext + ) +{ + CALL_CRYPTO_SERVICE (EdDsaGetPrivateKeyFromPem, (PemData, PemSize, Password, EdDsaContext), FALSE); +} + +/** + Retrieve the EdDSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contain the retrieved + EdDsa public key component. Use EdDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDsa Public Key was retrieved successfully. + @retval FALSE Fail to retrieve EdDsa public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +EdDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **EdDsaContext + ) +{ + CALL_CRYPTO_SERVICE (EdDsaGetPublicKeyFromX509, (Cert, CertSize, EdDsaContext), FALSE); +} + +/** + Generates an EdDSA signature for a given message. + + This function creates an EdDSA signature using the private key stored in the + EdDSA context. EdDSA uses a 'pure' signature scheme where the entire message + is processed directly without pre-computing a hash digest. + + For Ed448, an optional context string can be provided for domain separation. + This allows the same key to be used in different contexts without creating + security vulnerabilities. + + The context must contain a private key (set via EdDsaSetPrivKey() or loaded + from PEM) before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0 or exceeds INT_MAX, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + For Ed448: Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] EdDsaContext Pointer to EdDSA context containing the private key. + @param[in] Context Optional context string for Ed448 domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (114 bytes for Ed448). + + @retval TRUE EdDSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +EdDsaSign ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + CALL_CRYPTO_SERVICE (EdDsaSign, (EdDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} + +/** + Verifies the EdDSA signature for a given message. + + This function verifies an EdDSA signature against a message using the public key + contained in the EdDSA context. EdDSA signatures use a 'pure' implementation, + meaning the message digest cannot be computed ahead of time - the raw message + data is passed directly to the verification function. + + For Ed448, an optional context string can be provided as additional domain + separation. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + If SigSize does not match expected signature size for the key type, then return FALSE. + For Ed448: Context may be NULL if no context string is used. + + @param[in] EdDsaContext Pointer to EdDSA context containing the public key. + @param[in] Context Optional context string for Ed448 (domain separation). + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the EdDSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + Must be 2 * key_size (114 bytes for Ed448). + + @retval TRUE EdDSA signature verification succeeded. + @retval FALSE EdDSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +EdDsaVerify ( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + CALL_CRYPTO_SERVICE (EdDsaVerify, (EdDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} diff --git a/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c b/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c index d2e47fc7e2..0eece3a337 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c +++ b/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c @@ -120,6 +120,9 @@ static const OSSL_ALGORITHM deflt_digests[] = { { PROV_NAMES_MD5, "provider=default", ossl_md5_functions }, #endif /* OPENSSL_NO_MD5 */ + { PROV_NAMES_SHAKE_128, "provider=default", ossl_shake_128_functions }, + { PROV_NAMES_SHAKE_256, "provider=default", ossl_shake_256_functions }, + { PROV_NAMES_NULL, "provider=default", ossl_nullmd_functions }, { NULL, NULL, NULL } }; @@ -191,6 +194,9 @@ static const OSSL_ALGORITHM deflt_rands[] = { static const OSSL_ALGORITHM deflt_signature[] = { { PROV_NAMES_RSA, "provider=default", ossl_rsa_signature_functions }, #ifndef OPENSSL_NO_EC +#ifndef OPENSSL_NO_ECX + { PROV_NAMES_ED448, "provider=default", ossl_ed448_signature_functions }, +#endif { PROV_NAMES_ECDSA, "provider=default", ossl_ecdsa_signature_functions }, #endif { PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_hmac_signature_functions }, @@ -218,6 +224,10 @@ static const OSSL_ALGORITHM deflt_keymgmt[] = { #ifndef OPENSSL_NO_EC { PROV_NAMES_EC, "provider=default", ossl_ec_keymgmt_functions, PROV_DESCS_EC }, +#ifndef OPENSSL_NO_ECX + { PROV_NAMES_ED448, "provider=default", ossl_ed448_keymgmt_functions, + PROV_DESCS_ED448 }, +#endif #endif { PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_keymgmt_functions, PROV_DESCS_TLS1_PRF_SIGN }, diff --git a/CryptoPkg/Private/Protocol/Crypto.h b/CryptoPkg/Private/Protocol/Crypto.h index e5635bc070..542a9c75d7 100644 --- a/CryptoPkg/Private/Protocol/Crypto.h +++ b/CryptoPkg/Private/Protocol/Crypto.h @@ -21,7 +21,7 @@ /// the EDK II Crypto Protocol is extended, this version define must be /// increased. /// -#define EDKII_CRYPTO_VERSION 24 +#define EDKII_CRYPTO_VERSION 25 /// /// EDK II Crypto Protocol forward declaration @@ -5862,6 +5862,309 @@ BOOLEAN IN UINTN SigSize ); +/** + Creates a new EdDSA context by Crypto NID. + + This function allocates and initializes a new EdDSA context for the specified + curve. The context contains an EVP_PKEY structure initialized with the curve + parameters. The caller must call EdDsaFree() to release the context when done. + + Before keys can be used for signing or verification, they must be set using + EdDsaSetPrivKey() or EdDsaSetPubKey(). + + If Nid is not a supported EdDSA curve, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the EdDSA curve (e.g., CRYPTO_NID_ED448). + + @retval Pointer to new EdDSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +typedef +VOID * +(EFIAPI *EDKII_CRYPTO_ED_DSA_NEW_BY_NID)( + IN UINTN Nid + ); + +/** + Frees an EdDSA context and all associated resources. + + This function releases all memory associated with the EdDSA context, including + the EVP_PKEY structure. After calling this function, the EdDsaContext pointer + should not be used. + + If EdDsaContext is NULL, then this function returns immediately without action. + + @param[in] EdDsaContext Pointer to the EdDSA context to be released. + +**/ +typedef +VOID +(EFIAPI *EDKII_CRYPTO_ED_DSA_FREE)( + IN VOID *EdDsaContext + ); + +/** + Sets the EdDSA private key in the EdDSA context. + + This function imports a raw private key into the EdDSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If EdDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize is 0, then return FALSE. + If PrivateKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE EdDSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ED_DSA_SET_PRIV_KEY)( + IN VOID *EdDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ); + +/** + Generates the EdDSA public key from the private key. + + This function is a placeholder and always returns TRUE. In practice, OpenSSL + automatically derives the public key when a private key is set using + EdDsaSetPrivKey(), so explicit public key generation is not needed. + + Use EdDsaGetPubKey() to retrieve the public key after setting the private key. + + @param[in] EdDsaContext Pointer to EdDSA context. + @param[in] PublicKey Pointer to buffer for public key (unused). + @param[in] PublicKeySize Size of public key buffer (unused). + + @retval TRUE Always returns TRUE. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ED_DSA_GENERATE_PUB_KEY)( + IN VOID *EdDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Sets the EdDSA public key in the EdDSA context. + + This function imports a raw public key into the EdDSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the curve type (57 bytes for Ed448). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is 0, then return FALSE. + If PublicKeySize does not match the expected size for the curve, then return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context created by EdDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE EdDSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ED_DSA_SET_PUB_KEY)( + IN VOID *EdDsaContext, + IN CONST UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Retrieves the EdDSA public key from the EdDSA context. + + This function extracts the public key from the EdDSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via EdDsaSetPrivKey() or EdDsaSetPubKey()) + before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] EdDsaContext Pointer to EdDSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE EdDSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ED_DSA_GET_PUB_KEY)( + IN OUT VOID *EdDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ); + +/** + Retrieve the EdDSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contain the retrieved + EdDsa public key component. Use EdDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDsa Public Key was retrieved successfully. + @retval FALSE Fail to retrieve EdDsa public key from X509 certificate. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ED_DSA_GET_PUBLIC_KEY_FROM_X509)( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **EdDsaContext + ); + +/** + Retrieve the EdDSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] EdDsaContext Pointer to new-generated EdDSA context which contains the retrieved + EdDSA private key component. Use EdDsaFree() function to free the + resource. + + If PemData is NULL, then return FALSE. + If EdDsaContext is NULL, then return FALSE. + + @retval TRUE EdDSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ED_DSA_GET_PRIVATE_KEY_FROM_PEM)( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **EdDsaContext + ); + +/** + Generates an EdDSA signature for a given message. + + This function creates an EdDSA signature using the private key stored in the + EdDSA context. EdDSA uses a 'pure' signature scheme where the entire message + is processed directly without pre-computing a hash digest. + + For Ed448, an optional context string can be provided for domain separation. + This allows the same key to be used in different contexts without creating + security vulnerabilities. + + The context must contain a private key (set via EdDsaSetPrivKey() or loaded + from PEM) before calling this function. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0 or exceeds INT_MAX, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + For Ed448: Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] EdDsaContext Pointer to EdDSA context containing the private key. + @param[in] Context Optional context string for Ed448 domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (114 bytes for Ed448). + + @retval TRUE EdDSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ED_DSA_SIGN)( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ); + +/** + Verifies the EdDSA signature for a given message. + + This function verifies an EdDSA signature against a message using the public key + contained in the EdDSA context. EdDSA signatures use a 'pure' implementation, + meaning the message digest cannot be computed ahead of time - the raw message + data is passed directly to the verification function. + + For Ed448, an optional context string can be provided as additional domain + separation. + + If EdDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + If SigSize does not match expected signature size for the key type, then return FALSE. + For Ed448: Context may be NULL if no context string is used. + + @param[in] EdDsaContext Pointer to EdDSA context containing the public key. + @param[in] Context Optional context string for Ed448 (domain separation). + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the EdDSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + Must be 2 * key_size (114 bytes for Ed448). + + @retval TRUE EdDSA signature verification succeeded. + @retval FALSE EdDSA signature verification failed or invalid parameters. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ED_DSA_VERIFY)( + IN VOID *EdDsaContext, + IN CONST UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ); + /// /// EDK II Crypto Protocol /// @@ -6174,6 +6477,17 @@ struct _EDKII_CRYPTO_PROTOCOL { /// RSA PSS (Continued) EDKII_CRYPTO_RSA_PSS_SIGN_DIGEST RsaPssSignDigest; EDKII_CRYPTO_RSA_PSS_VERIFY_DIGEST RsaPssVerifyDigest; + /// Ed-DSA + EDKII_CRYPTO_ED_DSA_NEW_BY_NID EdDsaNewByNid; + EDKII_CRYPTO_ED_DSA_FREE EdDsaFree; + EDKII_CRYPTO_ED_DSA_SET_PRIV_KEY EdDsaSetPrivKey; + EDKII_CRYPTO_ED_DSA_GENERATE_PUB_KEY EdDsaGeneratePubKey; + EDKII_CRYPTO_ED_DSA_SET_PUB_KEY EdDsaSetPubKey; + EDKII_CRYPTO_ED_DSA_GET_PUB_KEY EdDsaGetPubKey; + EDKII_CRYPTO_ED_DSA_GET_PUBLIC_KEY_FROM_X509 EdDsaGetPublicKeyFromX509; + EDKII_CRYPTO_ED_DSA_GET_PRIVATE_KEY_FROM_PEM EdDsaGetPrivateKeyFromPem; + EDKII_CRYPTO_ED_DSA_SIGN EdDsaSign; + EDKII_CRYPTO_ED_DSA_VERIFY EdDsaVerify; }; extern GUID gEdkiiCryptoProtocolGuid; diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c index 4546843096..f95bf4ff97 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c @@ -29,6 +29,7 @@ SUITE_DESC mSuiteDesc[] = { { "Aead AES Gcm tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mAeadAesGcmTestNum, mAeadAesGcmTest }, { "Bn verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mBnTestNum, mBnTest }, { "EC verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mEcTestNum, mEcTest }, + { "ED-DSA verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mEdDsaTestNum, mEdDsaTest }, { "X509 Verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mX509TestNum, mX509Test }, { "PKCS7 Attach Content tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mPkcs7ContentTestNum, mPkcs7ContentTest }, }; diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/EdDsaTests.c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/EdDsaTests.c new file mode 100644 index 0000000000..77178ba119 --- /dev/null +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/EdDsaTests.c @@ -0,0 +1,923 @@ +/** @file + Application for EdDSA Primitives Validation. + +Copyright (c) 2026, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "TestBaseCryptLib.h" + +#define ED448_KEY_SIZE 57 +#define ED448_SIG_SIZE 114 + +// +// Ed448 Raw Private Key (57 bytes) extracted from DER format +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mEd448TestPrivateKey[ED448_KEY_SIZE] = { + 0x1d, 0x72, 0xe7, 0x9b, 0x46, 0x5f, 0xcb, 0xcc, 0x24, 0x07, 0x2e, 0x20, + 0x92, 0xec, 0xb6, 0xdd, 0x11, 0x68, 0x14, 0x0d, 0x84, 0x1f, 0xf9, 0x8f, + 0x13, 0xe5, 0x73, 0x78, 0xb0, 0x42, 0xb7, 0xe5, 0x90, 0x45, 0xcc, 0x15, + 0x07, 0x41, 0x66, 0x46, 0x6a, 0xef, 0xc9, 0x9e, 0x2d, 0xaa, 0x3f, 0x28, + 0xfd, 0xac, 0x7f, 0x23, 0xe2, 0x15, 0x60, 0xaf, 0x7b +}; + +// +// Ed448 Raw Public Key (57 bytes) - derived from the private key above +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mEd448TestPublicKey[ED448_KEY_SIZE] = { + 0x47, 0xba, 0x8f, 0x77, 0x45, 0x59, 0xee, 0x91, 0x90, 0x52, 0x96, 0x9f, + 0x59, 0xcd, 0xfa, 0xd5, 0x82, 0x00, 0xc1, 0x92, 0x5c, 0x90, 0x58, 0x79, + 0xaa, 0xbd, 0x74, 0xd2, 0x2c, 0x34, 0xe8, 0x1e, 0xce, 0xbb, 0x59, 0x4d, + 0xa9, 0x58, 0xaa, 0x61, 0x86, 0x1c, 0xa3, 0xd6, 0x32, 0x64, 0xda, 0x67, + 0xf7, 0x8b, 0x0e, 0xfa, 0x09, 0xa7, 0x22, 0xfb, 0x80 +}; + +// +// Ed448 X509 Certificate (DER format) matching the test keys +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mEd448TestCert[] = { + 0x30, 0x82, 0x02, 0x3a, 0x30, 0x82, 0x01, 0xba, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x14, 0x3b, 0x44, 0xcc, 0x80, 0x92, 0xfe, 0xa8, 0x1a, 0x35, + 0x97, 0x53, 0x71, 0x2b, 0xe0, 0xf8, 0xed, 0xb5, 0x44, 0x1c, 0x7f, 0x30, + 0x05, 0x06, 0x03, 0x2b, 0x65, 0x71, 0x30, 0x6d, 0x31, 0x0b, 0x30, 0x09, + 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, + 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x09, 0x54, 0x65, 0x73, 0x74, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, + 0x04, 0x07, 0x0c, 0x08, 0x54, 0x65, 0x73, 0x74, 0x43, 0x69, 0x74, 0x79, + 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x54, + 0x65, 0x73, 0x74, 0x4f, 0x72, 0x67, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, + 0x55, 0x04, 0x0b, 0x0c, 0x08, 0x54, 0x65, 0x73, 0x74, 0x55, 0x6e, 0x69, + 0x74, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x09, + 0x45, 0x44, 0x34, 0x34, 0x38, 0x54, 0x65, 0x73, 0x74, 0x30, 0x1e, 0x17, + 0x0d, 0x32, 0x36, 0x30, 0x36, 0x30, 0x32, 0x30, 0x30, 0x35, 0x39, 0x34, + 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x37, 0x30, 0x36, 0x30, 0x32, 0x30, 0x30, + 0x35, 0x39, 0x34, 0x39, 0x5a, 0x30, 0x6d, 0x31, 0x0b, 0x30, 0x09, 0x06, + 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, + 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x09, 0x54, 0x65, 0x73, 0x74, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, + 0x07, 0x0c, 0x08, 0x54, 0x65, 0x73, 0x74, 0x43, 0x69, 0x74, 0x79, 0x31, + 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x54, 0x65, + 0x73, 0x74, 0x4f, 0x72, 0x67, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, + 0x04, 0x0b, 0x0c, 0x08, 0x54, 0x65, 0x73, 0x74, 0x55, 0x6e, 0x69, 0x74, + 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x09, 0x45, + 0x44, 0x34, 0x34, 0x38, 0x54, 0x65, 0x73, 0x74, 0x30, 0x43, 0x30, 0x05, + 0x06, 0x03, 0x2b, 0x65, 0x71, 0x03, 0x3a, 0x00, 0x47, 0xba, 0x8f, 0x77, + 0x45, 0x59, 0xee, 0x91, 0x90, 0x52, 0x96, 0x9f, 0x59, 0xcd, 0xfa, 0xd5, + 0x82, 0x00, 0xc1, 0x92, 0x5c, 0x90, 0x58, 0x79, 0xaa, 0xbd, 0x74, 0xd2, + 0x2c, 0x34, 0xe8, 0x1e, 0xce, 0xbb, 0x59, 0x4d, 0xa9, 0x58, 0xaa, 0x61, + 0x86, 0x1c, 0xa3, 0xd6, 0x32, 0x64, 0xda, 0x67, 0xf7, 0x8b, 0x0e, 0xfa, + 0x09, 0xa7, 0x22, 0xfb, 0x80, 0xa3, 0x53, 0x30, 0x51, 0x30, 0x1d, 0x06, + 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x89, 0xc9, 0x06, 0xf9, + 0x9e, 0xb7, 0xca, 0x87, 0x48, 0x22, 0xf1, 0x19, 0xcb, 0xf8, 0x7b, 0x3d, + 0x80, 0x22, 0xa0, 0xac, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, + 0x18, 0x30, 0x16, 0x80, 0x14, 0x89, 0xc9, 0x06, 0xf9, 0x9e, 0xb7, 0xca, + 0x87, 0x48, 0x22, 0xf1, 0x19, 0xcb, 0xf8, 0x7b, 0x3d, 0x80, 0x22, 0xa0, + 0xac, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, + 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, + 0x71, 0x03, 0x73, 0x00, 0x11, 0x40, 0x03, 0xee, 0xdc, 0xc6, 0x43, 0x45, + 0xf4, 0x31, 0x28, 0x89, 0x5f, 0x3d, 0x89, 0x8f, 0xd6, 0xa8, 0x0a, 0x07, + 0x0b, 0xf5, 0x5f, 0x43, 0xc0, 0xd6, 0xf0, 0xf7, 0xb1, 0x2a, 0xaa, 0x4f, + 0x93, 0xcc, 0x09, 0x6f, 0x19, 0xf6, 0xc5, 0x1c, 0x47, 0xc9, 0x0c, 0xeb, + 0x7f, 0xfe, 0xff, 0x37, 0x48, 0x1f, 0xb0, 0x45, 0x68, 0x6b, 0x92, 0xc3, + 0x80, 0x62, 0x3d, 0xa0, 0x71, 0x96, 0xdf, 0x88, 0x0d, 0x1c, 0x8d, 0x28, + 0xd6, 0xfb, 0xdf, 0x25, 0x3f, 0xfd, 0x78, 0xb2, 0xab, 0xc5, 0x39, 0x40, + 0x83, 0xe2, 0x5e, 0x1b, 0xd4, 0xa6, 0xf8, 0x4d, 0x11, 0xd2, 0xdb, 0x6c, + 0x5b, 0x86, 0x0f, 0x79, 0xc7, 0x44, 0x5b, 0xb3, 0xe0, 0xdb, 0x2f, 0xa9, + 0x83, 0x1f, 0x15, 0x3e, 0x6e, 0x54, 0x42, 0x5c, 0x35, 0x00 +}; + +// +// PEM key data for Ed448 Private key matching the test key above +// This is an unencrypted PKCS#8 format PEM containing mEd448TestPrivateKey +// Format: -----BEGIN PRIVATE KEY----- (not ENCRYPTED) +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mEd448TestPemKey[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x50, + 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x45, 0x63, 0x43, 0x41, 0x51, 0x41, 0x77, + 0x42, 0x51, 0x59, 0x44, 0x4b, 0x32, 0x56, 0x78, 0x42, 0x44, 0x73, 0x45, + 0x4f, 0x52, 0x31, 0x79, 0x35, 0x35, 0x74, 0x47, 0x58, 0x38, 0x76, 0x4d, + 0x4a, 0x41, 0x63, 0x75, 0x49, 0x4a, 0x4c, 0x73, 0x74, 0x74, 0x30, 0x52, + 0x61, 0x42, 0x51, 0x4e, 0x68, 0x42, 0x2f, 0x35, 0x6a, 0x78, 0x50, 0x6c, + 0x63, 0x33, 0x69, 0x77, 0x51, 0x72, 0x66, 0x6c, 0x0a, 0x6b, 0x45, 0x58, + 0x4d, 0x46, 0x51, 0x64, 0x42, 0x5a, 0x6b, 0x5a, 0x71, 0x37, 0x38, 0x6d, + 0x65, 0x4c, 0x61, 0x6f, 0x2f, 0x4b, 0x50, 0x32, 0x73, 0x66, 0x79, 0x50, + 0x69, 0x46, 0x57, 0x43, 0x76, 0x65, 0x77, 0x3d, 0x3d, 0x0a, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, + 0x54, 0x45, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a +}; + +// +// Test message for signing and verification +// +CONST CHAR8 *mEdDsaTestMessage = "Test message for EdDSA signing and verification"; + +VOID *EdDsaContext1; +VOID *EdDsaContext2; + +/** + Prerequisite function for EdDSA tests. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyEdDsaPreReq ( + UNIT_TEST_CONTEXT Context + ) +{ + EdDsaContext1 = NULL; + EdDsaContext2 = NULL; + + return UNIT_TEST_PASSED; +} + +/** + Cleanup function for EdDSA tests. + + @param[in] Context Unit test context. +**/ +VOID +EFIAPI +TestVerifyEdDsaCleanUp ( + UNIT_TEST_CONTEXT Context + ) +{ + if (EdDsaContext1 != NULL) { + EdDsaFree (EdDsaContext1); + EdDsaContext1 = NULL; + } + + if (EdDsaContext2 != NULL) { + EdDsaFree (EdDsaContext2); + EdDsaContext2 = NULL; + } +} + +/** + Validate UEFI-OpenSSL EdDSA Context Creation and Destruction. + + This test validates: + - EdDsaNewByNid creates a valid context for supported curves (Ed448) + - EdDsaNewByNid returns NULL for unsupported/invalid NIDs + - EdDsaFree properly releases context resources + - EdDsaFree handles NULL context gracefully + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyEdDsaNew ( + UNIT_TEST_CONTEXT Context + ) +{ + // + // Test EdDsaNewByNid with Ed448 (supported curve) + // + EdDsaContext1 = EdDsaNewByNid (CRYPTO_NID_ED448); + UT_ASSERT_NOT_NULL (EdDsaContext1); + + // + // Verify the context can be used (set a key to confirm it's valid) + // + BOOLEAN Status; + + Status = EdDsaSetPrivKey ( + EdDsaContext1, + (UINT8 *)mEd448TestPrivateKey, + ED448_KEY_SIZE + ); + UT_ASSERT_TRUE (Status); + + // + // Test EdDsaFree releases the context properly + // + EdDsaFree (EdDsaContext1); + EdDsaContext1 = NULL; + + // + // Test EdDsaNewByNid with CRYPTO_NID_NULL (invalid NID) + // + EdDsaContext2 = EdDsaNewByNid (CRYPTO_NID_NULL); + UT_ASSERT_EQUAL ((UINTN)EdDsaContext2, (UINTN)NULL); + + // + // Test EdDsaNewByNid with unsupported curve NID + // (using an EC curve NID that's not EdDSA) + // + EdDsaContext2 = EdDsaNewByNid (CRYPTO_NID_SECP256R1); + UT_ASSERT_EQUAL ((UINTN)EdDsaContext2, (UINTN)NULL); + + // + // Test EdDsaFree with NULL context (should not crash) + // + EdDsaFree (NULL); + + // + // Test creating multiple contexts simultaneously + // + EdDsaContext1 = EdDsaNewByNid (CRYPTO_NID_ED448); + UT_ASSERT_NOT_NULL (EdDsaContext1); + + EdDsaContext2 = EdDsaNewByNid (CRYPTO_NID_ED448); + UT_ASSERT_NOT_NULL (EdDsaContext2); + + // + // Verify both contexts are independent + // + UT_ASSERT_NOT_EQUAL ((UINTN)EdDsaContext1, (UINTN)EdDsaContext2); + + // + // Clean up both contexts + // + EdDsaFree (EdDsaContext1); + EdDsaContext1 = NULL; + + EdDsaFree (EdDsaContext2); + EdDsaContext2 = NULL; + + return UNIT_TEST_PASSED; +} + +/** + Validate UEFI-OpenSSL EdDSA Key Setting and Getting. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyEdDsaKeySetGet ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 PublicKey[ED448_KEY_SIZE]; + UINTN PublicKeySize; + UINT8 TooSmallBuffer[10]; + UINTN TooSmallSize; + + // + // Create EdDSA context + // + EdDsaContext1 = EdDsaNewByNid (CRYPTO_NID_ED448); + UT_ASSERT_NOT_NULL (EdDsaContext1); + + // + // Test EdDsaSetPrivKey with valid key + // + Status = EdDsaSetPrivKey ( + EdDsaContext1, + (UINT8 *)mEd448TestPrivateKey, + ED448_KEY_SIZE + ); + UT_ASSERT_TRUE (Status); + + // + // Test EdDsaGetPubKey after setting private key + // + PublicKeySize = sizeof (PublicKey); + Status = EdDsaGetPubKey (EdDsaContext1, PublicKey, &PublicKeySize); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (PublicKeySize, ED448_KEY_SIZE); + UT_ASSERT_MEM_EQUAL (PublicKey, mEd448TestPublicKey, ED448_KEY_SIZE); + + // + // Test EdDsaGetPubKey with too small buffer + // + TooSmallSize = sizeof (TooSmallBuffer); + Status = EdDsaGetPubKey (EdDsaContext1, TooSmallBuffer, &TooSmallSize); + UT_ASSERT_FALSE (Status); + UT_ASSERT_EQUAL (TooSmallSize, ED448_KEY_SIZE); + + // + // Clean up context1 + // + EdDsaFree (EdDsaContext1); + EdDsaContext1 = NULL; + + // + // Test EdDsaSetPubKey + // + EdDsaContext2 = EdDsaNewByNid (CRYPTO_NID_ED448); + UT_ASSERT_NOT_NULL (EdDsaContext2); + + Status = EdDsaSetPubKey ( + EdDsaContext2, + (UINT8 *)mEd448TestPublicKey, + ED448_KEY_SIZE + ); + UT_ASSERT_TRUE (Status); + + // + // Test EdDsaGetPubKey after setting public key + // + PublicKeySize = sizeof (PublicKey); + Status = EdDsaGetPubKey (EdDsaContext2, PublicKey, &PublicKeySize); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (PublicKeySize, ED448_KEY_SIZE); + UT_ASSERT_MEM_EQUAL (PublicKey, mEd448TestPublicKey, ED448_KEY_SIZE); + + // + // Test EdDsaSetPrivKey with NULL context + // + Status = EdDsaSetPrivKey (NULL, (UINT8 *)mEd448TestPrivateKey, ED448_KEY_SIZE); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaSetPrivKey with NULL key + // + Status = EdDsaSetPrivKey (EdDsaContext2, NULL, ED448_KEY_SIZE); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaSetPrivKey with wrong size + // + Status = EdDsaSetPrivKey (EdDsaContext2, (UINT8 *)mEd448TestPrivateKey, 32); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaSetPubKey with NULL context + // + Status = EdDsaSetPubKey (NULL, (UINT8 *)mEd448TestPublicKey, ED448_KEY_SIZE); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaSetPubKey with NULL key + // + Status = EdDsaSetPubKey (EdDsaContext2, NULL, ED448_KEY_SIZE); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaSetPubKey with wrong size + // + Status = EdDsaSetPubKey (EdDsaContext2, (UINT8 *)mEd448TestPublicKey, 32); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaGetPubKey with NULL context + // + PublicKeySize = sizeof (PublicKey); + Status = EdDsaGetPubKey (NULL, PublicKey, &PublicKeySize); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaGetPubKey with NULL buffer + // + PublicKeySize = sizeof (PublicKey); + Status = EdDsaGetPubKey (EdDsaContext2, NULL, &PublicKeySize); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaGetPubKey with NULL size + // + Status = EdDsaGetPubKey (EdDsaContext2, PublicKey, NULL); + UT_ASSERT_FALSE (Status); + + return UNIT_TEST_PASSED; +} + +/** + Validate UEFI-OpenSSL EdDSA Signing and Verification. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyEdDsaSignVerify ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 Signature[ED448_SIG_SIZE]; + UINTN SigSize; + UINTN MessageSize; + + MessageSize = AsciiStrLen (mEdDsaTestMessage); + + // + // Create context with private key for signing + // + EdDsaContext1 = EdDsaNewByNid (CRYPTO_NID_ED448); + UT_ASSERT_NOT_NULL (EdDsaContext1); + + Status = EdDsaSetPrivKey ( + EdDsaContext1, + (UINT8 *)mEd448TestPrivateKey, + ED448_KEY_SIZE + ); + UT_ASSERT_TRUE (Status); + + // + // Test EdDsaSign without context string + // + SigSize = sizeof (Signature); + Status = EdDsaSign ( + EdDsaContext1, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (SigSize, ED448_SIG_SIZE); + + // + // Test EdDsaVerify with the same context + // + Status = EdDsaVerify ( + EdDsaContext1, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Create separate context with public key for verification + // + EdDsaContext2 = EdDsaNewByNid (CRYPTO_NID_ED448); + UT_ASSERT_NOT_NULL (EdDsaContext2); + + Status = EdDsaSetPubKey ( + EdDsaContext2, + (UINT8 *)mEd448TestPublicKey, + ED448_KEY_SIZE + ); + UT_ASSERT_TRUE (Status); + + // + // Test EdDsaVerify with separate public key context + // + Status = EdDsaVerify ( + EdDsaContext2, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Test EdDsaVerify with modified message (should fail) + // + UINT8 ModifiedMessage[100]; + + CopyMem (ModifiedMessage, mEdDsaTestMessage, MessageSize); + ModifiedMessage[0] ^= 0xFF; + + Status = EdDsaVerify ( + EdDsaContext2, + NULL, + 0, + ModifiedMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaVerify with modified signature (should fail) + // + Signature[0] ^= 0xFF; + Status = EdDsaVerify ( + EdDsaContext2, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + Signature[0] ^= 0xFF; + + return UNIT_TEST_PASSED; +} + +/** + Validate UEFI-OpenSSL EdDSA Signing and Verification with Context String. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyEdDsaSignVerifyWithContext ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 Signature[ED448_SIG_SIZE]; + UINTN SigSize; + UINTN MessageSize; + CONST CHAR8 *ContextString = "test-context"; + UINTN ContextSize; + + MessageSize = AsciiStrLen (mEdDsaTestMessage); + ContextSize = AsciiStrLen (ContextString); + + // + // Create context with private key + // + EdDsaContext1 = EdDsaNewByNid (CRYPTO_NID_ED448); + UT_ASSERT_NOT_NULL (EdDsaContext1); + + Status = EdDsaSetPrivKey ( + EdDsaContext1, + (UINT8 *)mEd448TestPrivateKey, + ED448_KEY_SIZE + ); + UT_ASSERT_TRUE (Status); + + // + // Test EdDsaSign with context string + // + SigSize = sizeof (Signature); + Status = EdDsaSign ( + EdDsaContext1, + (UINT8 *)ContextString, + ContextSize, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (SigSize, ED448_SIG_SIZE); + + // + // Test EdDsaVerify with matching context string + // + Status = EdDsaVerify ( + EdDsaContext1, + (UINT8 *)ContextString, + ContextSize, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Test EdDsaVerify with different context string (should fail) + // + CONST CHAR8 *WrongContext = "wrong-context"; + + Status = EdDsaVerify ( + EdDsaContext1, + (UINT8 *)WrongContext, + AsciiStrLen (WrongContext), + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaVerify without context string (should fail) + // + Status = EdDsaVerify ( + EdDsaContext1, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + return UNIT_TEST_PASSED; +} + +/** + Validate UEFI-OpenSSL EdDSA Error Cases. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyEdDsaErrorCases ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 Signature[ED448_SIG_SIZE]; + UINTN SigSize; + UINTN MessageSize; + UINT8 TooSmallSig[10]; + UINTN TooSmallSigSize; + + MessageSize = AsciiStrLen (mEdDsaTestMessage); + + // + // Create context + // + EdDsaContext1 = EdDsaNewByNid (CRYPTO_NID_ED448); + UT_ASSERT_NOT_NULL (EdDsaContext1); + + Status = EdDsaSetPrivKey ( + EdDsaContext1, + (UINT8 *)mEd448TestPrivateKey, + ED448_KEY_SIZE + ); + UT_ASSERT_TRUE (Status); + + // + // Test EdDsaSign with NULL context + // + SigSize = sizeof (Signature); + Status = EdDsaSign ( + NULL, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaSign with NULL message + // + SigSize = sizeof (Signature); + Status = EdDsaSign ( + EdDsaContext1, + NULL, + 0, + NULL, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaSign with too small signature buffer + // + TooSmallSigSize = sizeof (TooSmallSig); + Status = EdDsaSign ( + EdDsaContext1, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + TooSmallSig, + &TooSmallSigSize + ); + UT_ASSERT_FALSE (Status); + UT_ASSERT_EQUAL (TooSmallSigSize, ED448_SIG_SIZE); + + // + // Generate valid signature for verification tests + // + SigSize = sizeof (Signature); + Status = EdDsaSign ( + EdDsaContext1, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Test EdDsaVerify with NULL context + // + Status = EdDsaVerify ( + NULL, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaVerify with NULL message + // + Status = EdDsaVerify ( + EdDsaContext1, + NULL, + 0, + NULL, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaVerify with NULL signature + // + Status = EdDsaVerify ( + EdDsaContext1, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + NULL, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaVerify with wrong signature size + // + Status = EdDsaVerify ( + EdDsaContext1, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + 32 + ); + UT_ASSERT_FALSE (Status); + + // + // Test EdDsaVerify with zero signature size + // + Status = EdDsaVerify ( + EdDsaContext1, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + 0 + ); + UT_ASSERT_FALSE (Status); + + return UNIT_TEST_PASSED; +} + +/** + Validate EdDsaGeneratePubKey (placeholder function). + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyEdDsaGeneratePubKey ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 PublicKey[ED448_KEY_SIZE]; + + // + // Create context + // + EdDsaContext1 = EdDsaNewByNid (CRYPTO_NID_ED448); + UT_ASSERT_NOT_NULL (EdDsaContext1); + + // + // EdDsaGeneratePubKey is a placeholder that always returns TRUE + // + Status = EdDsaGeneratePubKey (EdDsaContext1, PublicKey, ED448_KEY_SIZE); + UT_ASSERT_TRUE (Status); + + // + // It should return TRUE even with NULL parameters + // + Status = EdDsaGeneratePubKey (NULL, NULL, 0); + UT_ASSERT_TRUE (Status); + + return UNIT_TEST_PASSED; +} + +/** + Validate EdDSA key retrieval from PEM and X509. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyEdDsaPemX509 ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *EdDsaPrivKey; + VOID *EdDsaPubKey; + UINT8 Signature[ED448_SIG_SIZE]; + UINTN SigSize; + UINTN MessageSize; + + EdDsaPrivKey = NULL; + EdDsaPubKey = NULL; + MessageSize = AsciiStrLen (mEdDsaTestMessage); + + // + // Retrieve EdDsa private key from PEM data. + // + Status = EdDsaGetPrivateKeyFromPem ( + mEd448TestPemKey, + sizeof (mEd448TestPemKey), + NULL, + &EdDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (EdDsaPrivKey); + + // + // Retrieve EdDsa public key from X509 certificate. + // + Status = EdDsaGetPublicKeyFromX509 ( + mEd448TestCert, + sizeof (mEd448TestCert), + &EdDsaPubKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (EdDsaPubKey); + + // + // EdDSA signing with key from PEM + // + SigSize = sizeof (Signature); + Status = EdDsaSign ( + EdDsaPrivKey, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (SigSize, ED448_SIG_SIZE); + + // + // EdDSA verification with key from X509 + // + Status = EdDsaVerify ( + EdDsaPubKey, + NULL, + 0, + (UINT8 *)mEdDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + EdDsaFree (EdDsaPrivKey); + EdDsaFree (EdDsaPubKey); + + return UNIT_TEST_PASSED; +} + +TEST_DESC mEdDsaTest[] = { + // + // -----Description------------------------------------Class-------------------------Function----------------------------Pre-------------------Post--------------------Context + // + { "TestVerifyEdDsaNew()", "CryptoPkg.BaseCryptLib.EdDsa", TestVerifyEdDsaNew, TestVerifyEdDsaPreReq, TestVerifyEdDsaCleanUp, NULL }, + { "TestVerifyEdDsaKeySetGet()", "CryptoPkg.BaseCryptLib.EdDsa", TestVerifyEdDsaKeySetGet, TestVerifyEdDsaPreReq, TestVerifyEdDsaCleanUp, NULL }, + { "TestVerifyEdDsaSignVerify()", "CryptoPkg.BaseCryptLib.EdDsa", TestVerifyEdDsaSignVerify, TestVerifyEdDsaPreReq, TestVerifyEdDsaCleanUp, NULL }, + { "TestVerifyEdDsaSignVerifyWithContext()", "CryptoPkg.BaseCryptLib.EdDsa", TestVerifyEdDsaSignVerifyWithContext, TestVerifyEdDsaPreReq, TestVerifyEdDsaCleanUp, NULL }, + { "TestVerifyEdDsaErrorCases()", "CryptoPkg.BaseCryptLib.EdDsa", TestVerifyEdDsaErrorCases, TestVerifyEdDsaPreReq, TestVerifyEdDsaCleanUp, NULL }, + { "TestVerifyEdDsaGeneratePubKey()", "CryptoPkg.BaseCryptLib.EdDsa", TestVerifyEdDsaGeneratePubKey, TestVerifyEdDsaPreReq, TestVerifyEdDsaCleanUp, NULL }, + { "TestVerifyEdDsaPemX509()", "CryptoPkg.BaseCryptLib.EdDsa", TestVerifyEdDsaPemX509, TestVerifyEdDsaPreReq, TestVerifyEdDsaCleanUp, NULL }, +}; + +UINTN mEdDsaTestNum = ARRAY_SIZE (mEdDsaTest); diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h index 1b079c6546..da4b6d8796 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h @@ -97,6 +97,9 @@ extern TEST_DESC mBnTest[]; extern UINTN mEcTestNum; extern TEST_DESC mEcTest[]; +extern UINTN mEdDsaTestNum; +extern TEST_DESC mEdDsaTest[]; + extern UINTN mX509TestNum; extern TEST_DESC mX509Test[]; diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf index 15dd6efcdc..0ad04eb25f 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf @@ -44,6 +44,7 @@ BnTests.c EcTests.c X509Tests.c + EdDsaTests.c [Packages] MdePkg/MdePkg.dec diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf index 956a887a3d..ca9d6fb6d0 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf @@ -40,6 +40,7 @@ AeadAesGcmTests.c BnTests.c EcTests.c + EdDsaTests.c X509Tests.c Pkcs7AttachedContentTest.c From ae6bf21c8275f7a8541083b60bacdc932d198135 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 21 Apr 2026 22:49:30 -0400 Subject: [PATCH 124/406] .mergify/config.yml: Set update_method to merge Originally, edk2 sought to have mergify use rebases to update PR branches. However, mergify is deprecating pull requests from forks with update_method=rebase and update_bot_account impersonation: Deprecation notice: This pull request comes from a fork and was queued with update_method=rebase and update_bot_account impersonation. This capability will be removed on July 1, 2026. After this date, the merge queue will no longer be able to rebase fork pull requests with this configuration. To avoid disruption, switch to update_method=merge in configuration. To avoid disruption, switch to update_method=merge in your queue rule. This change explicitly sets the update_method to merge per the deprecation guidance. Signed-off-by: Michael Kubacki --- .mergify/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mergify/config.yml b/.mergify/config.yml index 46ca46da26..96314a63eb 100644 --- a/.mergify/config.yml +++ b/.mergify/config.yml @@ -34,7 +34,7 @@ queue_rules: - label=push merge_method: rebase update_bot_account: tianocore-issues - update_method: rebase + update_method: merge pull_request_rules: - name: Automatically merge a PR when all required checks pass and 'push' label is present From 8dab052c576da59759e1c7bda834a47ca281162f Mon Sep 17 00:00:00 2001 From: Qihang Gao Date: Wed, 1 Jul 2026 10:34:48 +0800 Subject: [PATCH 125/406] ShellPkg: Add null pointer checks before dereference In AllocateMemory(), several pointers are used without prior null checks. This may lead to unexpected behavior or system crashes if any of these pointers are NULL. Add explicit null checks for these pointers to ensure safe access and prevent potential null pointer dereferences. Signed-off-by: Qihang Gao --- .../UefiShellDebug1CommandsLib/Compress.c | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c index 3dea3c2f2f..8593a99a1e 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c @@ -184,13 +184,40 @@ AllocateMemory ( VOID ) { - mText = AllocateZeroPool (WNDSIZ * 2 + MAXMATCH); - mLevel = AllocateZeroPool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mLevel)); + mText = AllocateZeroPool (WNDSIZ * 2 + MAXMATCH); + if (mText == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + mLevel = AllocateZeroPool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mLevel)); + if (mLevel == NULL) { + return EFI_OUT_OF_RESOURCES; + } + mChildCount = AllocateZeroPool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mChildCount)); - mPosition = AllocateZeroPool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mPosition)); - mParent = AllocateZeroPool (WNDSIZ * 2 * sizeof (*mParent)); - mPrev = AllocateZeroPool (WNDSIZ * 2 * sizeof (*mPrev)); - mNext = AllocateZeroPool ((MAX_HASH_VAL + 1) * sizeof (*mNext)); + if (mChildCount == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + mPosition = AllocateZeroPool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mPosition)); + if (mPosition == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + mParent = AllocateZeroPool (WNDSIZ * 2 * sizeof (*mParent)); + if (mParent == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + mPrev = AllocateZeroPool (WNDSIZ * 2 * sizeof (*mPrev)); + if (mPrev == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + mNext = AllocateZeroPool ((MAX_HASH_VAL + 1) * sizeof (*mNext)); + if (mNext == NULL) { + return EFI_OUT_OF_RESOURCES; + } mBufSiz = BLKSIZ; mBuf = AllocateZeroPool (mBufSiz); From 7bc6629f400c03970614420366edddecbd0dabcb Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Wed, 1 Jul 2026 11:15:20 +0100 Subject: [PATCH 126/406] ShellPkg: Fix smbiosview Type 26 location/status decode The smbiosview Type 26 Voltage Probe decoder uses the low 5 bits of LocationAndStatus as the probe location and the high 3 bits as the probe status. However, the Type 26 lookup tables were swapped: VPLocationTable contained status strings and VPStatusTable contained location strings. This caused valid records to be displayed as, for example: Voltage Probe - Location: OK Voltage Probe - Status: Processor Swap the table contents so Type 26 output matches the SMBIOS LocationAndStatus bit layout. Signed-off-by: VarshitPandya --- .../SmbiosView/QueryTable.c | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c index 4dce68dccf..9d3219b6eb 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c @@ -3236,33 +3236,6 @@ TABLE_ITEM PBDeviceChemistryTable[] = { }; TABLE_ITEM VPLocationTable[] = { - { - 0x01, - L" Other " - }, - { - 0x02, - L" Unknown " - }, - { - 0x03, - L" OK " - }, - { - 0x04, - L" Non-critical " - }, - { - 0x05, - L" Critical " - }, - { - 0x06, - L" Non-recoverable " - }, -}; - -TABLE_ITEM VPStatusTable[] = { { 0x01, L" Other " @@ -3309,6 +3282,33 @@ TABLE_ITEM VPStatusTable[] = { }, }; +TABLE_ITEM VPStatusTable[] = { + { + 0x01, + L" Other " + }, + { + 0x02, + L" Unknown " + }, + { + 0x03, + L" OK " + }, + { + 0x04, + L" Non-critical " + }, + { + 0x05, + L" Critical " + }, + { + 0x06, + L" Non-recoverable " + }, +}; + TABLE_ITEM CoolingDeviceStatusTable[] = { { 0x01, From c362e91e5600ad3378bff1d75aeae90fdef1e154 Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Wed, 1 Jul 2026 15:36:40 +0100 Subject: [PATCH 127/406] ShellPkg: Add missing smbiosview Type 28 locations Add the missing SMBIOS Type 28 Temperature Probe location decode values to smbiosview. The Type 28 Location field defines values 0x0C through 0x0F for Front Panel Board, Back Panel Board, Power System Board, and Drive Back Plane, but smbiosview only decoded values up to 0x0B. Signed-off-by: VarshitPandya --- .../SmbiosView/QueryTable.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c index 9d3219b6eb..71848259af 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c @@ -3455,6 +3455,22 @@ TABLE_ITEM TemperatureProbeLocTable[] = { 0x0B, L" Add-in Card " }, + { + 0x0C, + L" Front Panel Board " + }, + { + 0x0D, + L" Back Panel Board " + }, + { + 0x0E, + L" Power System Board " + }, + { + 0x0F, + L" Drive Back Plane " + }, }; TABLE_ITEM ECPStatusTable[] = { From 2c82d4ada9fd29554f6b4752c6f576792867331c Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Thu, 25 Jun 2026 14:05:11 +0100 Subject: [PATCH 128/406] DynamicTablesPkg: Add SMBIOS Voltage Probe (Type 26) generator Add a Configuration Manager object and parser for SMBIOS Type 26 Voltage Probe information. Add a Type 26 SMBIOS generator that creates one Voltage Probe structure for each Voltage Probe CM object. The generator validates the probe location and status fields, publishes the optional description string, and registers the generated table with the SMBIOS table factory. Signed-off-by: Varshit Pandya --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../Include/ArchCommonNameSpaceObjects.h | 39 ++ .../ConfigurationManagerObjectParser.c | 16 + .../SmbiosType26Lib/SmbiosType26Generator.c | 465 ++++++++++++++++++ .../SmbiosType26Lib/SmbiosType26Lib.inf | 29 ++ 5 files changed, 551 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index e3e29a7d6c..9e8f7b2022 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -115,6 +115,7 @@ DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf @@ -167,6 +168,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf } diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index 9ccbd43e7b..6980ac697c 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -85,6 +85,7 @@ typedef enum ArchCommonObjectID { EArchCommonObjMemoryArrayMappedAddress, ///< 57 - Memory Array Mapped Address Info EArchCommonObjCoolingDeviceInfo, ///< 58 - Cooling Device Info EArchCommonObjTemperatureProbeInfo, ///< 59 - Temperature Probe Info + EArchCommonObjVoltageProbeInfo, ///< 60 - Voltage Probe Info EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1534,4 +1535,42 @@ typedef struct CmArchCommonTemperatureProbeInfo { UINT16 NominalValue; } CM_ARCH_COMMON_TEMPERATURE_PROBE_INFO; +/** A structure that describes a voltage probe. + + SMBIOS Specification v3.9.0 Type 26 + + ID: EArchCommonObjVoltageProbeInfo +**/ +typedef struct CmArchCommonVoltageProbeInfo { + /// Token identifying this voltage probe CM object. + CM_OBJECT_TOKEN VoltageProbeToken; + + /// String describing the voltage probe or its location. + CHAR8 Description[SMBIOS_MAX_STRING_SIZE]; + + /// Probe location and status encoded as SMBIOS Type 26 Location and Status. + MISC_VOLTAGE_PROBE_LOCATION LocationAndStatus; + + /// Maximum voltage in millivolts, or 0x8000 if unknown. + UINT16 MaximumValue; + + /// Minimum voltage in millivolts, or 0x8000 if unknown. + UINT16 MinimumValue; + + /// Resolution in tenths of millivolts, or 0x8000 if unknown. + UINT16 Resolution; + + /// Tolerance in plus/minus millivolts, or 0x8000 if unknown. + UINT16 Tolerance; + + /// Accuracy in plus/minus 1/100th percent, or 0x8000 if unknown. + UINT16 Accuracy; + + /// OEM- or firmware vendor-specific information. + UINT32 OEMDefined; + + /// Nominal voltage in millivolts, or 0x8000 if unknown. + UINT16 NominalValue; +} CM_ARCH_COMMON_VOLTAGE_PROBE_INFO; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index da28b64d20..435acdee25 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -1250,6 +1250,21 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonTemperatureProbeInfoParser[] = { { "NominalValue", sizeof (UINT16), "0x%x", NULL }, }; +/** A parser for EArchCommonObjVoltageProbeInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonVoltageProbeInfoParser[] = { + { "VoltageProbeToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "Description", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "LocationAndStatus", sizeof (MISC_VOLTAGE_PROBE_LOCATION), "0x%x", NULL }, + { "MaximumValue", sizeof (UINT16), "0x%x", NULL }, + { "MinimumValue", sizeof (UINT16), "0x%x", NULL }, + { "Resolution", sizeof (UINT16), "0x%x", NULL }, + { "Tolerance", sizeof (UINT16), "0x%x", NULL }, + { "Accuracy", sizeof (UINT16), "0x%x", NULL }, + { "OEMDefined", sizeof (UINT32), "0x%x", NULL }, + { "NominalValue", sizeof (UINT16), "0x%x", NULL }, +}; + /** A parser for Arch Common namespace objects. */ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { @@ -1314,6 +1329,7 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryArrayMappedAddress, CmArchCommonMemoryArrayMappedAddressParser), CM_PARSER_ADD_OBJECT (EArchCommonObjCoolingDeviceInfo, CmArchCommonCoolingDeviceInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjTemperatureProbeInfo, CmArchCommonTemperatureProbeInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjVoltageProbeInfo, CmArchCommonVoltageProbeInfoParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Generator.c new file mode 100644 index 0000000000..af617ab4a9 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Generator.c @@ -0,0 +1,465 @@ +/** @file + SMBIOS Type26 Table Generator. + + @par Reference(s): + - SMBIOS Specification 3.9.0 + + Copyright (c) 2026, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include + +/** SMBIOS Type 26 Voltage Probe Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArchCommonObjVoltageProbeInfo +*/ + +/** + This macro expands to a function that retrieves the Voltage Probe + information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjVoltageProbeInfo, + CM_ARCH_COMMON_VOLTAGE_PROBE_INFO + ); + +/** + Type 26 records expose one optional string field: Description. +*/ +#define SMBIOS_TYPE26_MAX_STRINGS (1) + +/** + Valid SMBIOS Type 26 Status values are 0x01-0x06. + Valid Location values are 0x01-0x0B. +*/ +#define SMBIOS_TYPE26_PROBE_STATUS_MIN 1 +#define SMBIOS_TYPE26_PROBE_STATUS_MAX 6 +#define SMBIOS_TYPE26_PROBE_LOCATION_MIN 1 +#define SMBIOS_TYPE26_PROBE_LOCATION_MAX 11 + +/** Check whether a Type 26 voltage probe status value is valid. + + @param [in] Status Voltage probe status value. + + @retval TRUE The status value is valid. + @retval FALSE The status value is invalid. +**/ +STATIC +BOOLEAN +IsValidVoltageProbeStatus ( + IN UINT8 Status + ) +{ + return (Status >= SMBIOS_TYPE26_PROBE_STATUS_MIN) && + (Status <= SMBIOS_TYPE26_PROBE_STATUS_MAX); +} + +/** Check whether a Type 26 voltage probe location value is valid. + + @param [in] Location Voltage probe location value. + + @retval TRUE The location value is valid. + @retval FALSE The location value is invalid. +**/ +STATIC +BOOLEAN +IsValidVoltageProbeLocation ( + IN UINT8 Location + ) +{ + return (Location >= SMBIOS_TYPE26_PROBE_LOCATION_MIN) && + (Location <= SMBIOS_TYPE26_PROBE_LOCATION_MAX); +} + +/** + Free any resources allocated when installing SMBIOS Type 26 table. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the SMBIOS table. + @param [in] CmObjectToken Pointer to the CM ObjectToken Array. + @param [in] TableCount Number of SMBIOS tables. + + @retval EFI_SUCCESS Resources were freed successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +FreeSmbiosType26TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + SMBIOS_STRUCTURE **TableList; + + TableList = *Table; + for (Index = 0; Index < TableCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + if (*CmObjectToken != NULL) { + FreePool (*CmObjectToken); + } + + if (TableList != NULL) { + FreePool (TableList); + } + + return EFI_SUCCESS; +} + +/** Construct SMBIOS Type 26 Table describing voltage probes. + + If this function allocates any resources then they must be freed + in the FreeXXXXTableResources function. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the SMBIOS table. + @param [out] CmObjectToken Pointer to the CM Object Token Array. + @param [out] TableCount Number of tables installed. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +BuildSmbiosType26TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + UINTN Index; + UINTN SmbiosRecordSize; + UINT32 VoltageProbeCount; + UINT8 Description; + STRING_TABLE StrTable; + SMBIOS_STRUCTURE **TableList; + SMBIOS_TABLE_TYPE26 *SmbiosRecord; + CM_OBJECT_TOKEN *CmObjectList; + CM_ARCH_COMMON_VOLTAGE_PROBE_INFO *VoltageProbeInfo; + + ASSERT (This != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (Table != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL) || (TableCount == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + *CmObjectToken = NULL; + *TableCount = 0; + TableList = NULL; + SmbiosRecord = NULL; + CmObjectList = NULL; + + Status = GetEArchCommonObjVoltageProbeInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &VoltageProbeInfo, + &VoltageProbeCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get voltage probe info. Status = %r\n", + __func__, + Status + )); + return Status; + } + + if (VoltageProbeCount == 0) { + DEBUG (( + DEBUG_ERROR, + "%a: No Voltage Probe CM Objects found\n", + __func__ + )); + return EFI_NOT_FOUND; + } + + TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRUCTURE *) * VoltageProbeCount); + if (TableList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u voltage probe table\n", + __func__, + VoltageProbeCount + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitErrorBuildSmbiosType26Table; + } + + CmObjectList = AllocateZeroPool ( + sizeof (CM_OBJECT_TOKEN) * VoltageProbeCount + ); + if (CmObjectList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u voltage probe table\n", + __func__, + VoltageProbeCount + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitErrorBuildSmbiosType26Table; + } + + Index = 0; + for (Index = 0; Index < VoltageProbeCount; Index++) { + Status = StringTableInitialize (&StrTable, SMBIOS_TYPE26_MAX_STRINGS); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to initialize string table for VoltageProbeInfo[%u]. Status = %r\n", + __func__, + Index, + Status + )); + goto exitErrorBuildSmbiosType26Table; + } + + Description = 0; + if (VoltageProbeInfo[Index].Description[0]) { + Status = StringTableAddString (&StrTable, VoltageProbeInfo[Index].Description, &Description); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add Description String %r\n", Status)); + ASSERT (!EFI_ERROR (Status)); + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType26Table; + } + } + + SmbiosRecordSize = sizeof (SMBIOS_TABLE_TYPE26) + StringTableGetStringSetSize (&StrTable); + SmbiosRecord = (SMBIOS_TABLE_TYPE26 *)AllocateZeroPool (SmbiosRecordSize); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType26Table; + } + + // Set up the header + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_VOLTAGE_PROBE; + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE26); + + if (!IsValidVoltageProbeStatus ( + VoltageProbeInfo[Index].LocationAndStatus.VoltageProbeStatus + )) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Voltage Probe Status 0x%x for VoltageProbeInfo[%u]\n", + __func__, + VoltageProbeInfo[Index].LocationAndStatus.VoltageProbeStatus, + Index + )); + Status = EFI_INVALID_PARAMETER; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType26Table; + } + + if (!IsValidVoltageProbeLocation ( + VoltageProbeInfo[Index].LocationAndStatus.VoltageProbeSite + )) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Voltage Probe Location 0x%x for VoltageProbeInfo[%u]\n", + __func__, + VoltageProbeInfo[Index].LocationAndStatus.VoltageProbeSite, + Index + )); + Status = EFI_INVALID_PARAMETER; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType26Table; + } + + SmbiosRecord->Description = Description; + SmbiosRecord->LocationAndStatus = VoltageProbeInfo[Index].LocationAndStatus; + SmbiosRecord->MaximumValue = VoltageProbeInfo[Index].MaximumValue; + SmbiosRecord->MinimumValue = VoltageProbeInfo[Index].MinimumValue; + SmbiosRecord->Resolution = VoltageProbeInfo[Index].Resolution; + SmbiosRecord->Tolerance = VoltageProbeInfo[Index].Tolerance; + SmbiosRecord->Accuracy = VoltageProbeInfo[Index].Accuracy; + SmbiosRecord->OEMDefined = VoltageProbeInfo[Index].OEMDefined; + SmbiosRecord->NominalValue = VoltageProbeInfo[Index].NominalValue; + + Status = StringTablePublishStringSet ( + &StrTable, + (CHAR8 *)(SmbiosRecord + 1), + SmbiosRecordSize - sizeof (SMBIOS_TABLE_TYPE26) + ); + if (EFI_ERROR (Status)) { + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType26Table; + } + + StringTableFree (&StrTable); + + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] = VoltageProbeInfo[Index].VoltageProbeToken; + SmbiosRecord = NULL; + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = VoltageProbeCount; + + return EFI_SUCCESS; +exitErrorBuildSmbiosType26Table: + if (TableList != NULL) { + for (Index = 0; Index < VoltageProbeCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + FreePool (TableList); + } + + if (CmObjectList != NULL) { + FreePool (CmObjectList); + } + + if (SmbiosRecord != NULL) { + FreePool (SmbiosRecord); + } + + return Status; +} + +/** The interface for the SMBIOS Type26 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType26Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType26), + // Generator Description + L"SMBIOS.TYPE26.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_VOLTAGE_PROBE, + NULL, + NULL, + // Build table function. + BuildSmbiosType26TableEx, + // Free function. + FreeSmbiosType26TableEx, +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType26LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType26Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 26: Register Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType26LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType26Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 26: Deregister Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf new file mode 100644 index 0000000000..00cb05e3cd --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf @@ -0,0 +1,29 @@ +## @file +# SMBIOS Type26 Table Generator +# +# Copyright (c) 2026, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType26LibArm + FILE_GUID = 260ddc2e-9e01-4fcc-b85f-85994e69938d + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType26LibConstructor + DESTRUCTOR = SmbiosType26LibDestructor + +[Sources] + SmbiosType26Generator.c + +[Packages] + MdePkg/MdePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + DebugLib + MemoryAllocationLib + SmbiosStringTableLib From dc23931facd2c9ffe6331c1fb81f6b22428890d2 Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Thu, 25 Jun 2026 15:50:29 +0100 Subject: [PATCH 129/406] DynamicTablesPkg: Add SMBIOS Electrical Current Probe (Type 29) generator Add a Configuration Manager object and parser for SMBIOS Type 29 Electrical Current Probe information. Add a Type 29 SMBIOS generator that creates one Electrical Current Probe structure for each Electrical Current Probe CM object. The generator validates the probe location and status fields, publishes the optional description string, and registers the generated table with the SMBIOS table factory. Signed-off-by: Varshit Pandya --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../Include/ArchCommonNameSpaceObjects.h | 39 ++ .../ConfigurationManagerObjectParser.c | 16 + .../SmbiosType29Lib/SmbiosType29Generator.c | 465 ++++++++++++++++++ .../SmbiosType29Lib/SmbiosType29Lib.inf | 29 ++ 5 files changed, 551 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index 9e8f7b2022..1bb2ac6069 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -118,6 +118,7 @@ DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf # AML Fixup (Arm specific) DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtCmn600LibArm/SsdtCmn600LibArm.inf @@ -171,6 +172,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf } [Components.RISCV64] diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index 6980ac697c..a31474e39c 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -86,6 +86,7 @@ typedef enum ArchCommonObjectID { EArchCommonObjCoolingDeviceInfo, ///< 58 - Cooling Device Info EArchCommonObjTemperatureProbeInfo, ///< 59 - Temperature Probe Info EArchCommonObjVoltageProbeInfo, ///< 60 - Voltage Probe Info + EArchCommonObjElectricalCurrentProbeInfo, ///< 61 - Electrical Current Probe Info EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1573,4 +1574,42 @@ typedef struct CmArchCommonVoltageProbeInfo { UINT16 NominalValue; } CM_ARCH_COMMON_VOLTAGE_PROBE_INFO; +/** A structure that describes an electrical current probe. + + SMBIOS Specification v3.9.0 Type 29 + + ID: EArchCommonObjElectricalCurrentProbeInfo +**/ +typedef struct CmArchCommonElectricalCurrentProbeInfo { + /// Token identifying this electrical current probe CM object. + CM_OBJECT_TOKEN ElectricalCurrentProbeToken; + + /// String describing the electrical current probe or its location. + CHAR8 Description[SMBIOS_MAX_STRING_SIZE]; + + /// Probe location and status encoded as SMBIOS Type 29 Location and Status. + MISC_ELECTRICAL_CURRENT_PROBE_LOCATION LocationAndStatus; + + /// Maximum current in milliamperes, or 0x8000 if unknown. + UINT16 MaximumValue; + + /// Minimum current in milliamperes, or 0x8000 if unknown. + UINT16 MinimumValue; + + /// Resolution in tenths of milliamperes, or 0x8000 if unknown. + UINT16 Resolution; + + /// Tolerance in plus/minus milliamperes, or 0x8000 if unknown. + UINT16 Tolerance; + + /// Accuracy in plus/minus 1/100th percent, or 0x8000 if unknown. + UINT16 Accuracy; + + /// OEM- or firmware vendor-specific information. + UINT32 OEMDefined; + + /// Nominal current in milliamperes, or 0x8000 if unknown. + UINT16 NominalValue; +} CM_ARCH_COMMON_ELECTRICAL_CURRENT_PROBE_INFO; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index 435acdee25..1306d7a326 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -1265,6 +1265,21 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonVoltageProbeInfoParser[] = { { "NominalValue", sizeof (UINT16), "0x%x", NULL }, }; +/** A parser for EArchCommonObjElectricalCurrentProbeInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonElectricalCurrentProbeInfoParser[] = { + { "ElectricalCurrentProbeToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "Description", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "LocationAndStatus", sizeof (MISC_ELECTRICAL_CURRENT_PROBE_LOCATION), "0x%x", NULL }, + { "MaximumValue", sizeof (UINT16), "0x%x", NULL }, + { "MinimumValue", sizeof (UINT16), "0x%x", NULL }, + { "Resolution", sizeof (UINT16), "0x%x", NULL }, + { "Tolerance", sizeof (UINT16), "0x%x", NULL }, + { "Accuracy", sizeof (UINT16), "0x%x", NULL }, + { "OEMDefined", sizeof (UINT32), "0x%x", NULL }, + { "NominalValue", sizeof (UINT16), "0x%x", NULL }, +}; + /** A parser for Arch Common namespace objects. */ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { @@ -1330,6 +1345,7 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArchCommonObjCoolingDeviceInfo, CmArchCommonCoolingDeviceInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjTemperatureProbeInfo, CmArchCommonTemperatureProbeInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjVoltageProbeInfo, CmArchCommonVoltageProbeInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjElectricalCurrentProbeInfo, CmArchCommonElectricalCurrentProbeInfoParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Generator.c new file mode 100644 index 0000000000..6790162fcf --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Generator.c @@ -0,0 +1,465 @@ +/** @file + SMBIOS Type29 Table Generator. + + @par Reference(s): + - SMBIOS Specification 3.9.0 + + Copyright (c) 2026, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include + +/** SMBIOS Type 29 Electrical Current Probe Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArchCommonObjElectricalCurrentProbeInfo +*/ + +/** + This macro expands to a function that retrieves the Electrical Current Probe + information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjElectricalCurrentProbeInfo, + CM_ARCH_COMMON_ELECTRICAL_CURRENT_PROBE_INFO + ); + +/** + Type 29 records expose one optional string field: Description. +*/ +#define SMBIOS_TYPE29_MAX_STRINGS (1) + +/** + Valid SMBIOS Type 29 Status values are 0x01-0x06. + Valid Location values are 0x01-0x0B. +*/ +#define SMBIOS_TYPE29_PROBE_STATUS_MIN 1 +#define SMBIOS_TYPE29_PROBE_STATUS_MAX 6 +#define SMBIOS_TYPE29_PROBE_LOCATION_MIN 1 +#define SMBIOS_TYPE29_PROBE_LOCATION_MAX 11 + +/** Check whether a Type 29 electrical current probe status value is valid. + + @param [in] Status Electrical Current probe status value. + + @retval TRUE The status value is valid. + @retval FALSE The status value is invalid. +**/ +STATIC +BOOLEAN +IsValidElectricalCurrentProbeStatus ( + IN UINT8 Status + ) +{ + return (Status >= SMBIOS_TYPE29_PROBE_STATUS_MIN) && + (Status <= SMBIOS_TYPE29_PROBE_STATUS_MAX); +} + +/** Check whether a Type 29 electrical current probe location value is valid. + + @param [in] Location Electrical Current probe location value. + + @retval TRUE The location value is valid. + @retval FALSE The location value is invalid. +**/ +STATIC +BOOLEAN +IsValidElectricalCurrentProbeLocation ( + IN UINT8 Location + ) +{ + return (Location >= SMBIOS_TYPE29_PROBE_LOCATION_MIN) && + (Location <= SMBIOS_TYPE29_PROBE_LOCATION_MAX); +} + +/** + Free any resources allocated when installing SMBIOS Type 29 table. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the SMBIOS table. + @param [in] CmObjectToken Pointer to the CM ObjectToken Array. + @param [in] TableCount Number of SMBIOS tables. + + @retval EFI_SUCCESS Resources were freed successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +FreeSmbiosType29TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + SMBIOS_STRUCTURE **TableList; + + TableList = *Table; + for (Index = 0; Index < TableCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + if (*CmObjectToken != NULL) { + FreePool (*CmObjectToken); + } + + if (TableList != NULL) { + FreePool (TableList); + } + + return EFI_SUCCESS; +} + +/** Construct SMBIOS Type 29 Table describing electrical current probes. + + If this function allocates any resources then they must be freed + in the FreeXXXXTableResources function. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the SMBIOS table. + @param [out] CmObjectToken Pointer to the CM Object Token Array. + @param [out] TableCount Number of tables installed. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +BuildSmbiosType29TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + UINTN Index; + UINTN SmbiosRecordSize; + UINT32 ElectricalCurrentProbeCount; + UINT8 Description; + STRING_TABLE StrTable; + SMBIOS_STRUCTURE **TableList; + SMBIOS_TABLE_TYPE29 *SmbiosRecord; + CM_OBJECT_TOKEN *CmObjectList; + CM_ARCH_COMMON_ELECTRICAL_CURRENT_PROBE_INFO *ElectricalCurrentProbeInfo; + + ASSERT (This != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (Table != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL) || (TableCount == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + *CmObjectToken = NULL; + *TableCount = 0; + TableList = NULL; + SmbiosRecord = NULL; + CmObjectList = NULL; + + Status = GetEArchCommonObjElectricalCurrentProbeInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &ElectricalCurrentProbeInfo, + &ElectricalCurrentProbeCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get electrical current probe info. Status = %r\n", + __func__, + Status + )); + return Status; + } + + if (ElectricalCurrentProbeCount == 0) { + DEBUG (( + DEBUG_ERROR, + "%a: No Electrical Current Probe CM Objects found\n", + __func__ + )); + return EFI_NOT_FOUND; + } + + TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRUCTURE *) * ElectricalCurrentProbeCount); + if (TableList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u electrical current probe table\n", + __func__, + ElectricalCurrentProbeCount + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitErrorBuildSmbiosType29Table; + } + + CmObjectList = AllocateZeroPool ( + sizeof (CM_OBJECT_TOKEN) * ElectricalCurrentProbeCount + ); + if (CmObjectList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u electrical current probe table\n", + __func__, + ElectricalCurrentProbeCount + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitErrorBuildSmbiosType29Table; + } + + Index = 0; + for (Index = 0; Index < ElectricalCurrentProbeCount; Index++) { + Status = StringTableInitialize (&StrTable, SMBIOS_TYPE29_MAX_STRINGS); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to initialize string table for ElectricalCurrentProbeInfo[%u]. Status = %r\n", + __func__, + Index, + Status + )); + goto exitErrorBuildSmbiosType29Table; + } + + Description = 0; + if (ElectricalCurrentProbeInfo[Index].Description[0]) { + Status = StringTableAddString (&StrTable, ElectricalCurrentProbeInfo[Index].Description, &Description); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add Description String %r\n", Status)); + ASSERT (!EFI_ERROR (Status)); + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType29Table; + } + } + + SmbiosRecordSize = sizeof (SMBIOS_TABLE_TYPE29) + StringTableGetStringSetSize (&StrTable); + SmbiosRecord = (SMBIOS_TABLE_TYPE29 *)AllocateZeroPool (SmbiosRecordSize); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType29Table; + } + + // Set up the header + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_ELECTRICAL_CURRENT_PROBE; + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE29); + + if (!IsValidElectricalCurrentProbeStatus ( + ElectricalCurrentProbeInfo[Index].LocationAndStatus.ElectricalCurrentProbeStatus + )) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Electrical Current Probe Status 0x%x for ElectricalCurrentProbeInfo[%u]\n", + __func__, + ElectricalCurrentProbeInfo[Index].LocationAndStatus.ElectricalCurrentProbeStatus, + Index + )); + Status = EFI_INVALID_PARAMETER; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType29Table; + } + + if (!IsValidElectricalCurrentProbeLocation ( + ElectricalCurrentProbeInfo[Index].LocationAndStatus.ElectricalCurrentProbeSite + )) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Electrical Current Probe Location 0x%x for ElectricalCurrentProbeInfo[%u]\n", + __func__, + ElectricalCurrentProbeInfo[Index].LocationAndStatus.ElectricalCurrentProbeSite, + Index + )); + Status = EFI_INVALID_PARAMETER; + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType29Table; + } + + SmbiosRecord->Description = Description; + SmbiosRecord->LocationAndStatus = ElectricalCurrentProbeInfo[Index].LocationAndStatus; + SmbiosRecord->MaximumValue = ElectricalCurrentProbeInfo[Index].MaximumValue; + SmbiosRecord->MinimumValue = ElectricalCurrentProbeInfo[Index].MinimumValue; + SmbiosRecord->Resolution = ElectricalCurrentProbeInfo[Index].Resolution; + SmbiosRecord->Tolerance = ElectricalCurrentProbeInfo[Index].Tolerance; + SmbiosRecord->Accuracy = ElectricalCurrentProbeInfo[Index].Accuracy; + SmbiosRecord->OEMDefined = ElectricalCurrentProbeInfo[Index].OEMDefined; + SmbiosRecord->NominalValue = ElectricalCurrentProbeInfo[Index].NominalValue; + + Status = StringTablePublishStringSet ( + &StrTable, + (CHAR8 *)(SmbiosRecord + 1), + SmbiosRecordSize - sizeof (SMBIOS_TABLE_TYPE29) + ); + if (EFI_ERROR (Status)) { + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType29Table; + } + + StringTableFree (&StrTable); + + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] = ElectricalCurrentProbeInfo[Index].ElectricalCurrentProbeToken; + SmbiosRecord = NULL; + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = ElectricalCurrentProbeCount; + + return EFI_SUCCESS; +exitErrorBuildSmbiosType29Table: + if (TableList != NULL) { + for (Index = 0; Index < ElectricalCurrentProbeCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + FreePool (TableList); + } + + if (CmObjectList != NULL) { + FreePool (CmObjectList); + } + + if (SmbiosRecord != NULL) { + FreePool (SmbiosRecord); + } + + return Status; +} + +/** The interface for the SMBIOS Type29 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType29Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType29), + // Generator Description + L"SMBIOS.TYPE29.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_ELECTRICAL_CURRENT_PROBE, + NULL, + NULL, + // Build table function. + BuildSmbiosType29TableEx, + // Free function. + FreeSmbiosType29TableEx, +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType29LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType29Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 29: Register Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType29LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType29Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 29: Deregister Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf new file mode 100644 index 0000000000..60e58d0cc3 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf @@ -0,0 +1,29 @@ +## @file +# SMBIOS Type29 Table Generator +# +# Copyright (c) 2026, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType29LibArm + FILE_GUID = ba5ca8ef-41c7-4abb-9d14-2d565902811e + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType29LibConstructor + DESTRUCTOR = SmbiosType29LibDestructor + +[Sources] + SmbiosType29Generator.c + +[Packages] + MdePkg/MdePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + DebugLib + MemoryAllocationLib + SmbiosStringTableLib From 019a537496799dbc4cfa3d3c448690ec971faf74 Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Fri, 26 Jun 2026 11:49:34 +0100 Subject: [PATCH 130/406] DynamicTablesPkg: Add SMBIOS System Reset (Type 23) generator Add a Configuration Manager object and parser for SMBIOS Type 23 System Reset information. Add a Type 23 SMBIOS generator that creates the System Reset structure from the System Reset CM object. The generator expects a single CM object, fills the system reset capabilities and watchdog reset fields, and registers the generated table with the SMBIOS table factory. Signed-off-by: Varshit Pandya --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../Include/ArchCommonNameSpaceObjects.h | 27 ++ .../ConfigurationManagerObjectParser.c | 12 + .../SmbiosType23Lib/SmbiosType23Generator.c | 275 ++++++++++++++++++ .../SmbiosType23Lib/SmbiosType23Lib.inf | 29 ++ 5 files changed, 345 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index 1bb2ac6069..75bbfc38ca 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -115,6 +115,7 @@ DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf @@ -169,6 +170,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index a31474e39c..ba26118f6c 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -87,6 +87,7 @@ typedef enum ArchCommonObjectID { EArchCommonObjTemperatureProbeInfo, ///< 59 - Temperature Probe Info EArchCommonObjVoltageProbeInfo, ///< 60 - Voltage Probe Info EArchCommonObjElectricalCurrentProbeInfo, ///< 61 - Electrical Current Probe Info + EArchCommonObjSystemResetInfo, ///< 62 - System Reset Info EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1612,4 +1613,30 @@ typedef struct CmArchCommonElectricalCurrentProbeInfo { UINT16 NominalValue; } CM_ARCH_COMMON_ELECTRICAL_CURRENT_PROBE_INFO; +/** A structure that describes system reset information. + + SMBIOS Specification v3.9.0 Type 23 + + ID: EArchCommonObjSystemResetInfo +**/ +typedef struct CmArchCommonSystemResetInfo { + /// Token identifying this system reset CM object. + CM_OBJECT_TOKEN SystemResetToken; + + /// System reset capability flags as defined by SMBIOS Type 23. + UINT8 Capabilities; + + /// Number of automatic system resets since the last intentional reset. + UINT16 ResetCount; + + /// Number of consecutive automatic reset attempts allowed. + UINT16 ResetLimit; + + /// Watchdog timer interval. + UINT16 TimerInterval; + + /// Timeout value used by the watchdog timer. + UINT16 Timeout; +} CM_ARCH_COMMON_SYSTEM_RESET_INFO; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index 1306d7a326..a91c5d70fb 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -1280,6 +1280,17 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonElectricalCurrentProbeInfoParser[] = { { "NominalValue", sizeof (UINT16), "0x%x", NULL }, }; +/** A parser for EArchCommonObjSystemResetInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonSystemResetInfoParser[] = { + { "SystemResetToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "Capabilities", sizeof (UINT8), "0x%x", NULL }, + { "ResetCount", sizeof (UINT16), "0x%x", NULL }, + { "ResetLimit", sizeof (UINT16), "0x%x", NULL }, + { "TimerInterval", sizeof (UINT16), "0x%x", NULL }, + { "Timeout", sizeof (UINT16), "0x%x", NULL }, +}; + /** A parser for Arch Common namespace objects. */ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { @@ -1346,6 +1357,7 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArchCommonObjTemperatureProbeInfo, CmArchCommonTemperatureProbeInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjVoltageProbeInfo, CmArchCommonVoltageProbeInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjElectricalCurrentProbeInfo, CmArchCommonElectricalCurrentProbeInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjSystemResetInfo, CmArchCommonSystemResetInfoParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Generator.c new file mode 100644 index 0000000000..8aac23684d --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Generator.c @@ -0,0 +1,275 @@ +/** @file + SMBIOS Type23 Table Generator. + + @par Reference(s): + - SMBIOS Specification 3.9.0 + + Copyright (c) 2026, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include + +/** SMBIOS Type 23 System Reset Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArchCommonObjSystemResetInfo +*/ + +/** + This macro expands to a function that retrieves the System Reset + information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjSystemResetInfo, + CM_ARCH_COMMON_SYSTEM_RESET_INFO + ); + +/** + SMBIOS Type 23 Capabilities bits 7:6 are reserved and must be 00b. +*/ +#define SMBIOS_TYPE23_CAPABILITIES_RESERVED_MASK 0xC0 + +/** + Free any resources allocated when installing SMBIOS Type 23 table. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the generated SMBIOS table. + + @retval EFI_SUCCESS Resources were freed successfully. +**/ +STATIC +EFI_STATUS +FreeSmbiosType23Table ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE **CONST Table + ) +{ + FreePool (*Table); + *Table = NULL; + + return EFI_SUCCESS; +} + +/** Construct SMBIOS Type 23 Table describing system reset information. + + If this function allocates any resources then they must be freed + in the FreeSmbiosType23Table function. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the generated SMBIOS table. + @param [out] CmObjectToken Pointer to the CM Object Token for the + generated SMBIOS table. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +BuildSmbiosType23Table ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE **Table, + OUT CM_OBJECT_TOKEN *CONST CmObjectToken + ) +{ + EFI_STATUS Status; + UINT32 SystemResetCount; + SMBIOS_TABLE_TYPE23 *SmbiosRecord; + CM_ARCH_COMMON_SYSTEM_RESET_INFO *SystemResetInfo; + + ASSERT (This != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (Table != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + *CmObjectToken = CM_NULL_TOKEN; + SmbiosRecord = NULL; + + Status = GetEArchCommonObjSystemResetInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &SystemResetInfo, + &SystemResetCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get system reset info. Status = %r\n", + __func__, + Status + )); + return Status; + } + + if (SystemResetCount != 1) { + DEBUG (( + DEBUG_ERROR, + "%a: Expected 1 System Reset CM Object, got %u\n", + __func__, + SystemResetCount + )); + return EFI_INVALID_PARAMETER; + } + + if ((SystemResetInfo[0].Capabilities & SMBIOS_TYPE23_CAPABILITIES_RESERVED_MASK) != 0) { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid System Reset Capabilities 0x%x. Bits 7:6 must be zero.\n", + __func__, + SystemResetInfo[0].Capabilities + )); + return EFI_INVALID_PARAMETER; + } + + SmbiosRecord = (SMBIOS_TABLE_TYPE23 *)AllocateSmbiosRecord ( + sizeof (SMBIOS_TABLE_TYPE23), + NULL + ); + if (SmbiosRecord == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to allocate memory for System Reset table\n", + __func__ + )); + return EFI_OUT_OF_RESOURCES; + } + + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_RESET; + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE23); + + SmbiosRecord->Capabilities = SystemResetInfo[0].Capabilities; + SmbiosRecord->ResetCount = SystemResetInfo[0].ResetCount; + SmbiosRecord->ResetLimit = SystemResetInfo[0].ResetLimit; + SmbiosRecord->TimerInterval = SystemResetInfo[0].TimerInterval; + SmbiosRecord->Timeout = SystemResetInfo[0].Timeout; + + *Table = (SMBIOS_STRUCTURE *)SmbiosRecord; + *CmObjectToken = SystemResetInfo[0].SystemResetToken; + SmbiosRecord = NULL; + + return EFI_SUCCESS; +} + +/** The interface for the SMBIOS Type23 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType23Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType23), + // Generator Description + L"SMBIOS.TYPE23.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_SYSTEM_RESET, + // Build table function. + BuildSmbiosType23Table, + // Free function. + FreeSmbiosType23Table, + NULL, + NULL, +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType23LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType23Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 23: Register Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType23LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType23Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 23: Deregister Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Lib.inf new file mode 100644 index 0000000000..95e612b1ed --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Lib.inf @@ -0,0 +1,29 @@ +## @file +# SMBIOS Type23 Table Generator +# +# Copyright (c) 2026, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType23LibArm + FILE_GUID = 7227274f-7684-4744-bca9-2f8c113dbc72 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType23LibConstructor + DESTRUCTOR = SmbiosType23LibDestructor + +[Sources] + SmbiosType23Generator.c + +[Packages] + MdePkg/MdePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + DebugLib + MemoryAllocationLib + SmbiosStringTableLib From f714e37e3b71ff02ec0b63c9710d679753f9cbb2 Mon Sep 17 00:00:00 2001 From: zhuyunfei Date: Thu, 2 Jul 2026 14:06:32 +0800 Subject: [PATCH 131/406] OvmfPkg/LoongArchVirt: Fix ResetSystemLibConstructor signature and header The ResetSystemLibConstructor was incorrectly declared with EFI_API and a UEFI driver entry point signature (ImageHandle, SystemTable), but it is actually a library constructor that should use EFIAPI and take no arguments (VOID) as per EDK2 library constructor conventions. This mismatch caused compilation errors when enabling TPM2 support for LoongArchVirt. - Add missing include - Replace EFI_API with EFIAPI - Change constructor signature from (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) to (VOID) Signed-off-by: zhuyunfei Signed-off-by: gaoqihang Reviewed-by: qiandongyan Reviewed-by: lichao --- .../Library/ResetSystemAcpiLib/BaseResetSystemAcpiGed.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiGed.c b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiGed.c index a88ed2ace4..405f0e0c63 100644 --- a/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiGed.c +++ b/OvmfPkg/LoongArchVirt/Library/ResetSystemAcpiLib/BaseResetSystemAcpiGed.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "ResetSystemAcpiGed.h" /** @@ -130,10 +131,9 @@ Done: @retval EFI_NOT_FOUND Failed to initialize mPowerManager. **/ EFI_STATUS -EFI_API +EFIAPI ResetSystemLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable + VOID ) { EFI_STATUS Status; From 0809aa4dceb1fafc1aa11de07cb6c8735d77bf9e Mon Sep 17 00:00:00 2001 From: Chao Li Date: Thu, 2 Jul 2026 10:38:48 +0800 Subject: [PATCH 132/406] Maintainers: Add Qihang Gao as reviewer to LoongArch Added Qihang Gao as reviewer for Loongrch Signed-off-by: Chao Li --- Maintainers.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Maintainers.txt b/Maintainers.txt index feeb6a8e12..da1bb4c640 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -113,6 +113,7 @@ M: Chao Li [kilaterlee] M: Baoqi Zhang [zhangbaoqi-ls] R: Dongyan Qian [MarsDoge] R: Xiangdong Meng [AydenMeng] +R: Qihang Gao [EricGao2015] EDK II Continuous Integration: ------------------------------ @@ -606,6 +607,7 @@ F: OvmfPkg/LoongArchVirt M: Chao Li [kilaterlee] R: Dongyan Qian [MarsDoge] R: Xianglai Li [lixianglai] +R: Qihang Gao [EricGao2015] PcAtChipsetPkg F: PcAtChipsetPkg/ From 4ae84e3e876094a3a3dfd824671edb7ceab47b37 Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Thu, 29 May 2025 16:26:50 +0100 Subject: [PATCH 133/406] MdePkg, SecurityPkg, OvmfPkg: Move CCEL table defs to ACPI header Although Table 5.5 "DESCRIPTION_HEADER Signatures for tables defined by ACPI" and the "Links to ACPI-Related Documents" still reference the "Virtual Firmware Confidential Computing Event Log Table," the CCEL table has now been formally included in the ACPI specification, see https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html# description-header-signatures-for-tables-defined-by-acpi The CCEL (CC Event Log) table is defined in the ACPI 6.5 specification, section 5.2.34 "CC Event Log ACPI Table": https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html# cc-event-log-acpi-table Therefore, move the CCEL table and related definitions to the standard ACPI header files and update the relevant code to reflect the structure and macro renaming. Also add the definitions to the ACPI 6.6 headers. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Sami Mujawar --- MdePkg/Include/IndustryStandard/Acpi65.h | 35 +++++++++++++++++ MdePkg/Include/IndustryStandard/Acpi66.h | 35 +++++++++++++++++ MdePkg/Include/Protocol/CcMeasurement.h | 38 +++++-------------- OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c | 15 ++++---- .../DxeTpm2MeasureBootLib.c | 2 +- 5 files changed, 89 insertions(+), 36 deletions(-) diff --git a/MdePkg/Include/IndustryStandard/Acpi65.h b/MdePkg/Include/IndustryStandard/Acpi65.h index 8c8727f7c9..a1fe77e18c 100644 --- a/MdePkg/Include/IndustryStandard/Acpi65.h +++ b/MdePkg/Include/IndustryStandard/Acpi65.h @@ -3069,6 +3069,36 @@ typedef struct { #define EFI_ACPI_6_5_PHAT_RESET_REASON_REASON_POWER_LOSS 0x24 #define EFI_ACPI_6_5_PHAT_RESET_REASON_REASON_POWER_BUTTON 0x25 +/// +/// Confidential Computing Type definitions. +/// +#define EFI_ACPI_6_5_CC_TYPE_NONE 0 +#define EFI_ACPI_6_5_CC_TYPE_SEV 1 +#define EFI_ACPI_6_5_CC_TYPE_TDX 2 +#define EFI_ACPI_6_5_CC_TYPE_APTEE 3 + +/// +/// Confidential Computing Event Log ACPI Table (CCEL). +/// +typedef struct { + EFI_ACPI_DESCRIPTION_HEADER Header; + /// Confidential Computing (CC) type. + UINT8 Type; + /// Confidential Computing (CC) sub type. + UINT8 SubType; + /// Reserved. + UINT16 Reserved; + /// Log Area Minimum Length. + UINT64 Laml; + /// Log Area Start Address. + UINT64 Lasa; +} EFI_ACPI_6_5_CONFIDENTIAL_COMPUTING_EVENT_LOG_TABLE; + +/// +/// CCEL Revision (as defined in ACPI 6.5 spec.) +/// +#define EFI_ACPI_6_5_CONFIDENTIAL_COMPUTING_EVENT_LOG_TABLE_REVISION 0x01 + // // Known table signatures // @@ -3098,6 +3128,11 @@ typedef struct { /// #define EFI_ACPI_6_5_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('B', 'G', 'R', 'T') +/// +/// "CCEL" Confidential Compute Event Log Table +/// +#define EFI_ACPI_6_5_CONFIDENTIAL_COMPUTING_EVENT_LOG_TABLE_SIGNATURE SIGNATURE_32('C', 'C', 'E', 'L') + /// /// "CDIT" Component Distance Information Table /// diff --git a/MdePkg/Include/IndustryStandard/Acpi66.h b/MdePkg/Include/IndustryStandard/Acpi66.h index fcac6433ca..8c419ffebb 100644 --- a/MdePkg/Include/IndustryStandard/Acpi66.h +++ b/MdePkg/Include/IndustryStandard/Acpi66.h @@ -3232,6 +3232,36 @@ typedef struct { #define EFI_ACPI_6_6_RHCT_HART_INFO_NODE_STRUCTURE_VERSION 1 +/// +/// Confidential Computing Type definitions. +/// +#define EFI_ACPI_6_6_CC_TYPE_NONE 0 +#define EFI_ACPI_6_6_CC_TYPE_SEV 1 +#define EFI_ACPI_6_6_CC_TYPE_TDX 2 +#define EFI_ACPI_6_6_CC_TYPE_APTEE 3 + +/// +/// Confidential Computing Event Log ACPI Table (CCEL). +/// +typedef struct { + EFI_ACPI_DESCRIPTION_HEADER Header; + /// Confidential Computing (CC) type. + UINT8 Type; + /// Confidential Computing (CC) sub type. + UINT8 SubType; + /// Reserved. + UINT16 Reserved; + /// Log Area Minimum Length. + UINT64 Laml; + /// Log Area Start Address. + UINT64 Lasa; +} EFI_ACPI_6_6_CONFIDENTIAL_COMPUTING_EVENT_LOG_TABLE; + +/// +/// CCEL Revision (as defined in ACPI 6.6 spec.) +/// +#define EFI_ACPI_6_6_CONFIDENTIAL_COMPUTING_EVENT_LOG_TABLE_REVISION 0x01 + // // Known table signatures // @@ -3261,6 +3291,11 @@ typedef struct { /// #define EFI_ACPI_6_6_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('B', 'G', 'R', 'T') +/// +/// "CCEL" Confidential Compute Event Log Table +/// +#define EFI_ACPI_6_6_CONFIDENTIAL_COMPUTING_EVENT_LOG_TABLE_SIGNATURE SIGNATURE_32('C', 'C', 'E', 'L') + /// /// "CDIT" Component Distance Information Table /// diff --git a/MdePkg/Include/Protocol/CcMeasurement.h b/MdePkg/Include/Protocol/CcMeasurement.h index be70379dc0..af9d8d1bc6 100644 --- a/MdePkg/Include/Protocol/CcMeasurement.h +++ b/MdePkg/Include/Protocol/CcMeasurement.h @@ -16,6 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #pragma once +#include #include #define EFI_CC_MEASUREMENT_PROTOCOL_GUID \ @@ -29,16 +30,18 @@ typedef struct { UINT8 Minor; } EFI_CC_VERSION; -// -// EFI_CC Type/SubType definition -// -#define EFI_CC_TYPE_NONE 0 -#define EFI_CC_TYPE_SEV 1 -#define EFI_CC_TYPE_TDX 2 -#define EFI_CC_TYPE_APTEE 3 +/** + A structure defining the Confidential Computing (CC) type and subtype. + The Type and Subtype field values must match the definitions in the ACPI + specification version 6.5 or later, + e.g. the macros EFI_ACPI_6_5_CC_TYPE_* must be used to populate the + Type field. +*/ typedef struct { + /// Confidential Computing (CC) type. UINT8 Type; + /// Confidential Computing (CC) sub type. UINT8 SubType; } EFI_CC_TYPE; @@ -298,24 +301,3 @@ typedef struct { {0xdd4a4648, 0x2de7, 0x4665, {0x96, 0x4d, 0x21, 0xd9, 0xef, 0x5f, 0xb4, 0x46}} extern EFI_GUID gEfiCcFinalEventsTableGuid; - -// -// Define the CC Measure EventLog ACPI Table -// -#pragma pack(1) - -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - EFI_CC_TYPE CcType; - UINT16 Rsvd; - UINT64 Laml; - UINT64 Lasa; -} EFI_CC_EVENTLOG_ACPI_TABLE; - -#pragma pack() - -// -// Define the signature and revision of CC Measurement EventLog ACPI Table -// -#define EFI_CC_EVENTLOG_ACPI_TABLE_SIGNATURE SIGNATURE_32('C', 'C', 'E', 'L') -#define EFI_CC_EVENTLOG_ACPI_TABLE_REVISION 1 diff --git a/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c b/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c index 44a751d865..b3a69c5802 100644 --- a/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c +++ b/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c @@ -108,20 +108,21 @@ VARIABLE_TYPE mVariableType[] = { { EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageSecurityDatabaseGuid }, }; -EFI_CC_EVENTLOG_ACPI_TABLE mTdxEventlogAcpiTemplate = { +EFI_ACPI_6_5_CONFIDENTIAL_COMPUTING_EVENT_LOG_TABLE mTdxEventlogAcpiTemplate = { { - EFI_CC_EVENTLOG_ACPI_TABLE_SIGNATURE, + EFI_ACPI_6_5_CONFIDENTIAL_COMPUTING_EVENT_LOG_TABLE_SIGNATURE, sizeof (mTdxEventlogAcpiTemplate), - EFI_CC_EVENTLOG_ACPI_TABLE_REVISION, + EFI_ACPI_6_5_CONFIDENTIAL_COMPUTING_EVENT_LOG_TABLE_REVISION, // // Compiler initializes the remaining bytes to 0 // These fields should be filled in production // }, - { EFI_CC_TYPE_TDX, 0 }, // CcType - 0, // rsvd - 0, // laml - 0, // lasa + EFI_ACPI_6_5_CC_TYPE_TDX, // CcType + 0, // CC Sub Type + 0, // Reserved + 0, // laml + 0, // lasa }; EFI_HANDLE mImageHandle; diff --git a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c index acba11d695..9f2eb57e75 100644 --- a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c +++ b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c @@ -548,7 +548,7 @@ GetMeasureBootProtocols ( ZeroMem (&CcProtocolCapability, sizeof (CcProtocolCapability)); CcProtocolCapability.Size = sizeof (CcProtocolCapability); Status = CcProtocol->GetCapability (CcProtocol, &CcProtocolCapability); - if (EFI_ERROR (Status) || (CcProtocolCapability.CcType.Type == EFI_CC_TYPE_NONE)) { + if (EFI_ERROR (Status) || (CcProtocolCapability.CcType.Type == EFI_ACPI_6_5_CC_TYPE_NONE)) { DEBUG ((DEBUG_ERROR, " CcProtocol->GetCapability returns : %x, %r\n", CcProtocolCapability.CcType.Type, Status)); CcProtocol = NULL; } From 4cd01151fc1f6881677d82e6e57e04db02aa7cef Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Wed, 27 May 2026 14:38:55 +0100 Subject: [PATCH 134/406] MdePkg: Define CC type for Arm CCA in CCEL ACPI table The following edk2 Code First proposals introduce support for Arm Confidential Compute Architecture (CCA) in ACPI and UEFI specifications: - [Code First] Add supporting details of Arm Confidential Compute Architecture in ACPI spec (#11384) https://github.com/tianocore/edk2/issues/11384 - [Code First] Add supporting details of Arm Confidential Compute Architecture in UEFI spec (#11383) https://github.com/tianocore/edk2/issues/11383 To support this, define a new CC type for Arm CCA so that CCEL event logs can be properly identified. Signed-off-by: Sami Mujawar --- MdePkg/Include/IndustryStandard/Acpi65.h | 9 +++++---- MdePkg/Include/IndustryStandard/Acpi66.h | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/MdePkg/Include/IndustryStandard/Acpi65.h b/MdePkg/Include/IndustryStandard/Acpi65.h index a1fe77e18c..fc43bdda81 100644 --- a/MdePkg/Include/IndustryStandard/Acpi65.h +++ b/MdePkg/Include/IndustryStandard/Acpi65.h @@ -3072,10 +3072,11 @@ typedef struct { /// /// Confidential Computing Type definitions. /// -#define EFI_ACPI_6_5_CC_TYPE_NONE 0 -#define EFI_ACPI_6_5_CC_TYPE_SEV 1 -#define EFI_ACPI_6_5_CC_TYPE_TDX 2 -#define EFI_ACPI_6_5_CC_TYPE_APTEE 3 +#define EFI_ACPI_6_5_CC_TYPE_NONE 0 +#define EFI_ACPI_6_5_CC_TYPE_SEV 1 +#define EFI_ACPI_6_5_CC_TYPE_TDX 2 +#define EFI_ACPI_6_5_CC_TYPE_APTEE 3 +#define EFI_ACPI_6_5_CC_TYPE_ARMCCA 4 /// /// Confidential Computing Event Log ACPI Table (CCEL). diff --git a/MdePkg/Include/IndustryStandard/Acpi66.h b/MdePkg/Include/IndustryStandard/Acpi66.h index 8c419ffebb..db63ba5fb6 100644 --- a/MdePkg/Include/IndustryStandard/Acpi66.h +++ b/MdePkg/Include/IndustryStandard/Acpi66.h @@ -3235,10 +3235,11 @@ typedef struct { /// /// Confidential Computing Type definitions. /// -#define EFI_ACPI_6_6_CC_TYPE_NONE 0 -#define EFI_ACPI_6_6_CC_TYPE_SEV 1 -#define EFI_ACPI_6_6_CC_TYPE_TDX 2 -#define EFI_ACPI_6_6_CC_TYPE_APTEE 3 +#define EFI_ACPI_6_6_CC_TYPE_NONE 0 +#define EFI_ACPI_6_6_CC_TYPE_SEV 1 +#define EFI_ACPI_6_6_CC_TYPE_TDX 2 +#define EFI_ACPI_6_6_CC_TYPE_APTEE 3 +#define EFI_ACPI_6_6_CC_TYPE_ARMCCA 4 /// /// Confidential Computing Event Log ACPI Table (CCEL). From 3b2350f2c15233aa8f1f89202e183ab4cdf715b2 Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Fri, 26 Sep 2025 14:10:55 +0100 Subject: [PATCH 135/406] MdePkg: Define CC Measurement register to Arm CCA REM mapping The edk2 Code First proposal "[Code First] Add supporting details of Arm Confidential Compute Architecture in UEFI spec" (#11383) https://github.com/tianocore/edk2/issues/11383 introduces a new section 38.4.3 'Arm Confidential Compute Architecture Extension' that defines the mapping between the TPM PCR indices, the CC event log measurement registers and the corresponding Arm CCA measurement registers where: - RIM means Realm Initial Measurement Register and - REM means Realm Extensible Measurement Register. TPM PCR Index | CC Measurement | Arm CCA-measurement | | Register Index | register | ------------------------------------------------------- 0 | 0 | RIM | 1, 7 | 1 | REM[0] | 2~6 | 2 | REM[1] | 8~15 | 3 | REM[2] | Therefore, add these definitions to the CC measurement header file to align with the updated specification. Signed-off-by: Sami Mujawar --- MdePkg/Include/Protocol/CcMeasurement.h | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/MdePkg/Include/Protocol/CcMeasurement.h b/MdePkg/Include/Protocol/CcMeasurement.h index af9d8d1bc6..5d9772ebe9 100644 --- a/MdePkg/Include/Protocol/CcMeasurement.h +++ b/MdePkg/Include/Protocol/CcMeasurement.h @@ -10,6 +10,7 @@ capability. Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.
+Copyright (c) 2025, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -59,6 +60,33 @@ typedef UINT32 EFI_CC_MR_INDEX; #define TDX_MR_INDEX_RTMR2 3 #define TDX_MR_INDEX_RTMR3 4 +/** + Macro definitions for mapping CC Measurement indices to Arm CCA + Realm measurement registers. + + The mapping between the TPM PCR index and the Arm CCA Realm + Extensible measurement as defined by the UEFI specification + in section 38.4.3 Arm Confidential Compute Architecture Extension. + + The following table shows the TPM PCR index mapping and CC event log + measurement register index interpretation for Arm CCA where: + - RIM means Realm Initial Measurement Register and + - REM means Realm Extensible Measurement Register + + TPM PCR Index | CC Measurement | Arm CCA-measurement | + | Register Index | register | + ------------------------------------------------------- + 0 | 0 | RIM | + 1, 7 | 1 | REM[0] | + 2~6 | 2 | REM[1] | + 8~15 | 3 | REM[2] | +*/ +#define ARMCCA_MR_INDEX_0_RIM 0 +#define ARMCCA_MR_INDEX_1_REM0 1 +#define ARMCCA_MR_INDEX_2_REM1 2 +#define ARMCCA_MR_INDEX_3_REM2 3 +#define ARMCCA_MR_INDEX_INVALID 4 + #define EFI_CC_EVENT_LOG_FORMAT_TCG_2 0x00000002 #define EFI_CC_BOOT_HASH_ALG_SHA384 0x00000004 From 5a64d2c5e1b4c51440e335fe0b2c66065082ccc6 Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Thu, 18 Sep 2025 16:48:28 +0100 Subject: [PATCH 136/406] MdePkg: Add SHA-256 and SHA-512 measurement hash algorithm IDs The CCEL (CC Event Log) ACPI table records measurement logs for confidential computing platforms. Each measurement specifies the hash algorithm used, identified by a numeric constant. The edk2 Code First proposal "[Code First] Add supporting details of Arm Confidential Compute Architecture in UEFI spec" (#11383) https://github.com/tianocore/edk2/issues/11383 extends section 38.2 EFI_CC_MEASUREMENT_PROTOCOL to define algorithm IDs for: - SHA-256 (EFI_CC_BOOT_HASH_ALG_SHA256) - SHA-512 (EFI_CC_BOOT_HASH_ALG_SHA512) This enables CC types such as Arm CCA to record and interpret measurements using these hash algorithms. Add these definitions to the CC measurement header file to align with the updated specification. Signed-off-by: Sami Mujawar --- MdePkg/Include/Protocol/CcMeasurement.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MdePkg/Include/Protocol/CcMeasurement.h b/MdePkg/Include/Protocol/CcMeasurement.h index 5d9772ebe9..6d94e75d32 100644 --- a/MdePkg/Include/Protocol/CcMeasurement.h +++ b/MdePkg/Include/Protocol/CcMeasurement.h @@ -88,7 +88,9 @@ typedef UINT32 EFI_CC_MR_INDEX; #define ARMCCA_MR_INDEX_INVALID 4 #define EFI_CC_EVENT_LOG_FORMAT_TCG_2 0x00000002 +#define EFI_CC_BOOT_HASH_ALG_SHA256 0x00000002 #define EFI_CC_BOOT_HASH_ALG_SHA384 0x00000004 +#define EFI_CC_BOOT_HASH_ALG_SHA512 0x00000008 // // This bit is shall be set when an event shall be extended but not logged. From e54671e9ef14ffc440ca515f75543d227f72f3c8 Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Wed, 1 Jul 2026 17:05:09 +0100 Subject: [PATCH 137/406] DynamicTablesPkg: Smbios Memory Device Mapped Address (Type 20) Add an SMBIOS Type 20 generator for Memory Device Mapped Address structures. The generator builds one Type 20 table per Memory Device Mapped Address CM object, validates the address range, encodes extended addresses when the 32-bit address fields cannot represent the range, and maps optional Type 17 and Type 19 CM object references to SMBIOS handles. If either reference token is CM_NULL_TOKEN, the corresponding SMBIOS handle is set to SMBIOS_HANDLE_INVALID. Signed-off-by: Varshit Pandya --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../Include/ArchCommonNameSpaceObjects.h | 29 ++ .../ConfigurationManagerObjectParser.c | 14 + .../SmbiosType20Lib/SmbiosType20Generator.c | 407 ++++++++++++++++++ .../SmbiosType20Lib/SmbiosType20Lib.inf | 34 ++ 5 files changed, 486 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index 75bbfc38ca..47f056bbf0 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -115,6 +115,7 @@ DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf @@ -170,6 +171,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index ba26118f6c..214e919dc3 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -88,6 +88,7 @@ typedef enum ArchCommonObjectID { EArchCommonObjVoltageProbeInfo, ///< 60 - Voltage Probe Info EArchCommonObjElectricalCurrentProbeInfo, ///< 61 - Electrical Current Probe Info EArchCommonObjSystemResetInfo, ///< 62 - System Reset Info + EArchCommonObjMemoryDeviceMappedAddress, ///< 63 - Memory Device Mapped Address Info EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1469,6 +1470,34 @@ typedef struct CmArchCommonMemoryArrayMappedAddress { UINT8 NumMemDevices; } CM_ARCH_COMMON_MEMORY_ARRAY_MAPPED_ADDRESS; +/** A structure that describes a Memory Device Mapped Address. + + SMBIOS Specification v3.9.0 Type 20 + + ID: EArchCommonObjMemoryDeviceMappedAddress +**/ +typedef struct CmArchCommonMemoryDeviceMappedAddress { + /// CM Object Token uniquely identifying this mapped address entry. + CM_OBJECT_TOKEN MemoryDeviceMappedAddressToken; + /// Starting physical address of the mapped memory range. + EFI_PHYSICAL_ADDRESS StartingAddress; + /// Ending physical address of the mapped memory range. + EFI_PHYSICAL_ADDRESS EndingAddress; + /// CM Object Token of the associated Memory Device. + CM_OBJECT_TOKEN MemoryDeviceInfoToken; + /// CM Object Token of the associated Memory Array Mapped Address. + CM_OBJECT_TOKEN MemoryArrayMappedAddressToken; + /// Identifies the position of the referenced memory device in a row. + /// Set to 0xFF if unknown. + UINT8 PartitionRowPosition; + /// Identifies the position of the referenced memory device in an interleave. + /// Set to 0xFF if unknown. + UINT8 InterleavePosition; + /// Number of consecutive rows from the referenced memory device. + /// Set to 0xFF if unknown. + UINT8 InterleavedDataDepth; +} CM_ARCH_COMMON_MEMORY_DEVICE_MAPPED_ADDRESS; + /** A structure that describes cooling device. SMBIOS Specification v3.9.0 Type 27 diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index a91c5d70fb..ab4e45c079 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -1223,6 +1223,19 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonMemoryArrayMappedAddressParser[] = { { "NumMemDevices", sizeof (UINT8), "0x%u", NULL }, }; +/** A parser for EArchCommonObjMemoryDeviceMappedAddress. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonMemoryDeviceMappedAddressParser[] = { + { "MemoryDeviceMappedAddressToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "StartingAddress", sizeof (EFI_PHYSICAL_ADDRESS), "0x%lx", NULL }, + { "EndingAddress", sizeof (EFI_PHYSICAL_ADDRESS), "0x%lx", NULL }, + { "MemoryDeviceInfoToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "MemoryArrayMappedAddressToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "PartitionRowPosition", sizeof (UINT8), "0x%u", NULL }, + { "InterleavePosition", sizeof (UINT8), "0x%u", NULL }, + { "InterleavedDataDepth", sizeof (UINT8), "0x%u", NULL }, +}; + /** A parser for EArchCommonObjCoolingDeviceInfo. */ STATIC CONST CM_OBJ_PARSER CmArchCommonCoolingDeviceInfoParser[] = { @@ -1358,6 +1371,7 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArchCommonObjVoltageProbeInfo, CmArchCommonVoltageProbeInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjElectricalCurrentProbeInfo, CmArchCommonElectricalCurrentProbeInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjSystemResetInfo, CmArchCommonSystemResetInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryDeviceMappedAddress, CmArchCommonMemoryDeviceMappedAddressParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Generator.c new file mode 100644 index 0000000000..3b7d0e8919 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Generator.c @@ -0,0 +1,407 @@ +/** @file + SMBIOS Type20 Table Generator. + + Copyright (c) 2026, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include + +/** SMBIOS Type 20 Memory Device Mapped Address Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArchCommonObjMemoryDeviceMappedAddress + + The following Configuration Manager Object(s) are required when + the corresponding token is not CM_NULL_TOKEN: + - EArchCommonObjMemoryDeviceInfo + - EArchCommonObjMemoryArrayMappedAddress +*/ + +/** + This macro expands to a function that retrieves the Memory Device + Mapped Address information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjMemoryDeviceMappedAddress, + CM_ARCH_COMMON_MEMORY_DEVICE_MAPPED_ADDRESS + ); + +#define EXTENDED_ADDRESS_THRESHOLD (0xFFFFFFFFULL) + +/** + Free any resources allocated when installing SMBIOS Type 20 table. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the SMBIOS table. + @param [in] CmObjectToken Pointer to the CM ObjectToken Array. + @param [in] TableCount Number of SMBIOS tables. + + @retval EFI_SUCCESS Resources freed successfully. +**/ +STATIC +EFI_STATUS +FreeSmbiosType20TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + SMBIOS_STRUCTURE **TableList; + + TableList = *Table; + for (Index = 0; Index < TableCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + if (*CmObjectToken != NULL) { + FreePool (*CmObjectToken); + } + + if (TableList != NULL) { + FreePool (TableList); + } + + return EFI_SUCCESS; +} + +/** Construct SMBIOS Type 20 Table describing memory device mapped addresses. + + If this function allocates any resources then they must be freed + in the FreeSmbiosType20TableEx function. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the SMBIOS table. + @param [out] CmObjectToken Pointer to the CM ObjectToken Array. + @param [out] TableCount Number of SMBIOS tables. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find required information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +BuildSmbiosType20TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CONST CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + UINT32 NumMemDeviceMap; + CM_ARCH_COMMON_MEMORY_DEVICE_MAPPED_ADDRESS *MemoryDeviceMapInfo; + SMBIOS_STRUCTURE **TableList; + CM_OBJECT_TOKEN *CmObjectList; + SMBIOS_TABLE_TYPE20 *SmbiosRecord; + SMBIOS_HANDLE_MAP *HandleMap; + UINT64 StartingAddressKb; + UINT64 EndingAddressKb; + UINTN Index; + + TableList = NULL; + CmObjectList = NULL; + SmbiosRecord = NULL; + + ASSERT (This != NULL); + ASSERT (TableFactoryProtocol != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Table != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (TableFactoryProtocol == NULL) || + (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL) || (TableCount == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + *CmObjectToken = NULL; + *TableCount = 0; + + Status = GetEArchCommonObjMemoryDeviceMappedAddress ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &MemoryDeviceMapInfo, + &NumMemDeviceMap + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Memory Device Mapped Address CM Object. Status = %r\n", + __func__, + Status + )); + return Status; + } + + if (NumMemDeviceMap == 0) { + DEBUG (( + DEBUG_ERROR, + "%a: No Memory Device Mapped Address CM Objects found\n", + __func__ + )); + return EFI_NOT_FOUND; + } + + TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool ( + sizeof (SMBIOS_STRUCTURE *) * NumMemDeviceMap + ); + if (TableList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to allocate memory for %u Memory Device Mapped Address tables\n", + __func__, + NumMemDeviceMap + )); + return EFI_OUT_OF_RESOURCES; + } + + CmObjectList = (CM_OBJECT_TOKEN *)AllocateZeroPool ( + sizeof (CM_OBJECT_TOKEN) * NumMemDeviceMap + ); + if (CmObjectList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to allocate memory for %u CM Object tokens\n", + __func__, + NumMemDeviceMap + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType20TableEx; + } + + for (Index = 0; Index < NumMemDeviceMap; Index++) { + if (MemoryDeviceMapInfo[Index].StartingAddress > MemoryDeviceMapInfo[Index].EndingAddress) { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid address range. StartingAddress = 0x%lx, EndingAddress = 0x%lx\n", + __func__, + MemoryDeviceMapInfo[Index].StartingAddress, + MemoryDeviceMapInfo[Index].EndingAddress + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType20TableEx; + } + + if (MemoryDeviceMapInfo[Index].PartitionRowPosition == 0 ) { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid PartitionRowPosition. Value must not be 0.\n", + __func__ + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType20TableEx; + } + + SmbiosRecord = (SMBIOS_TABLE_TYPE20 *)AllocateSmbiosRecord ( + sizeof (SMBIOS_TABLE_TYPE20), + NULL + ); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType20TableEx; + } + + StartingAddressKb = MemoryDeviceMapInfo[Index].StartingAddress / SIZE_1KB; + EndingAddressKb = MemoryDeviceMapInfo[Index].EndingAddress / SIZE_1KB; + + if ((StartingAddressKb >= EXTENDED_ADDRESS_THRESHOLD) || + (EndingAddressKb >= EXTENDED_ADDRESS_THRESHOLD)) + { + SmbiosRecord->StartingAddress = EXTENDED_ADDRESS_THRESHOLD; + SmbiosRecord->EndingAddress = EXTENDED_ADDRESS_THRESHOLD; + SmbiosRecord->ExtendedStartingAddress = MemoryDeviceMapInfo[Index].StartingAddress; + SmbiosRecord->ExtendedEndingAddress = MemoryDeviceMapInfo[Index].EndingAddress; + } else { + SmbiosRecord->StartingAddress = (UINT32)StartingAddressKb; + SmbiosRecord->EndingAddress = (UINT32)EndingAddressKb; + } + + if (MemoryDeviceMapInfo[Index].MemoryDeviceInfoToken == CM_NULL_TOKEN) { + SmbiosRecord->MemoryDeviceHandle = SMBIOS_HANDLE_INVALID; + } else { + HandleMap = TableFactoryProtocol->GetSmbiosHandle ( + MemoryDeviceMapInfo[Index].MemoryDeviceInfoToken + ); + if (HandleMap == NULL) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get Type 17 SMBIOS Handle\n", __func__)); + Status = EFI_NOT_FOUND; + goto exitBuildSmbiosType20TableEx; + } + + SmbiosRecord->MemoryDeviceHandle = HandleMap->SmbiosTblHandle; + } + + if (MemoryDeviceMapInfo[Index].MemoryArrayMappedAddressToken == CM_NULL_TOKEN) { + SmbiosRecord->MemoryArrayMappedAddressHandle = SMBIOS_HANDLE_INVALID; + } else { + HandleMap = TableFactoryProtocol->GetSmbiosHandle ( + MemoryDeviceMapInfo[Index].MemoryArrayMappedAddressToken + ); + if (HandleMap == NULL) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get Type 19 SMBIOS Handle\n", __func__)); + Status = EFI_NOT_FOUND; + goto exitBuildSmbiosType20TableEx; + } + + SmbiosRecord->MemoryArrayMappedAddressHandle = HandleMap->SmbiosTblHandle; + } + + SmbiosRecord->PartitionRowPosition = MemoryDeviceMapInfo[Index].PartitionRowPosition; + SmbiosRecord->InterleavePosition = MemoryDeviceMapInfo[Index].InterleavePosition; + SmbiosRecord->InterleavedDataDepth = MemoryDeviceMapInfo[Index].InterleavedDataDepth; + + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_MEMORY_DEVICE_MAPPED_ADDRESS; + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE20); + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] = MemoryDeviceMapInfo[Index].MemoryDeviceMappedAddressToken; + + SmbiosRecord = NULL; + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = NumMemDeviceMap; + +exitBuildSmbiosType20TableEx: + if (EFI_ERROR (Status)) { + if (TableList != NULL) { + for (Index = 0; Index < NumMemDeviceMap; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + FreePool (TableList); + } + + if (CmObjectList != NULL) { + FreePool (CmObjectList); + } + } + + if (SmbiosRecord != NULL) { + FreePool (SmbiosRecord); + } + + return Status; +} + +/** The interface for the SMBIOS Type 20 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType20Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType20), + // Generator Description + L"SMBIOS.TYPE20.GENERATOR", + // SMBIOS Table Type + SMBIOS_TYPE_MEMORY_DEVICE_MAPPED_ADDRESS, + NULL, + NULL, + // Build table function Extended. + BuildSmbiosType20TableEx, + // Free function Extended. + FreeSmbiosType20TableEx +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType20LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType20Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 20: Register Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType20LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType20Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 20: Deregister Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Lib.inf new file mode 100644 index 0000000000..6c9ccccd75 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Lib.inf @@ -0,0 +1,34 @@ +## @file +# SMBIOS Type20 Table Generator. +# +# Copyright (c) 2026, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType20LibArm + FILE_GUID = f55bd2c4-a1dd-4d9b-a0bb-47e32389741f + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType20LibConstructor + DESTRUCTOR = SmbiosType20LibDestructor + +[Sources] + SmbiosType20Generator.c + +[Packages] + DynamicTablesPkg/DynamicTablesPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MemoryAllocationLib + SmbiosStringTableLib + +[Protocols] + gEdkiiConfigurationManagerProtocolGuid + gEdkiiDynamicTableFactoryProtocolGuid From ec44a71ba711b326be4f1d0e370a0d67668cdfa8 Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Thu, 30 Apr 2026 15:04:42 +0100 Subject: [PATCH 138/406] ShellPkg/Acpiview: Increase the max supported parsers The RegisterParser() function is failing with error code EFI_OUT_OF_RESOURCES as we have run out of space for registering the ACPI table parsers in mTableParserList[]. Therefore, increase the MAX_ACPI_TABLE_PARSERS to 128. Signed-off-by: Sami Mujawar --- ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.h index fd114bf11c..b0646605cc 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.h @@ -10,7 +10,7 @@ /** The maximum number of ACPI table parsers. */ -#define MAX_ACPI_TABLE_PARSERS 32 +#define MAX_ACPI_TABLE_PARSERS 128 /** An invalid/NULL signature value. */ From f47d5291b99095d6f01f35f18fe7f4d0c276464f Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Fri, 15 May 2026 16:40:54 +0100 Subject: [PATCH 139/406] ShellPkg/Acpiview: Make reserved-field validation common Move the reserved-field validators from MpamParser.c into AcpiParser.c and expose them through AcpiParser.h so they can be reused by multiple Acpiview parsers. Update the AGDI, MPAM and WSMT parsers to use the common helpers for byte-length and bit-length reserved fields. Signed-off-by: Sami Mujawar --- .../UefiShellAcpiViewCommandLib/AcpiParser.c | 47 ++++++++++++++++ .../UefiShellAcpiViewCommandLib/AcpiParser.h | 30 ++++++++++ .../Parsers/Agdi/AgdiParser.c | 27 +-------- .../Parsers/Mpam/MpamParser.c | 55 ------------------- .../Parsers/Wsmt/WsmtParser.c | 35 ++---------- 5 files changed, 83 insertions(+), 111 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c index 728d8b523a..e6a789d853 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c @@ -624,6 +624,53 @@ DumpReservedBits ( DumpReserved (Format, Ptr, ByteLength); } +/** + This function validates reserved fields to check if they are 0. + + @param [in] Ptr Pointer to the start of the field data. + @param [in] Length Length of the field. + @param [in] Context Pointer to context specific information. +**/ +VOID +EFIAPI +ValidateReserved ( + IN UINT8 *Ptr, + IN UINT32 Length, + IN VOID *Context + ) +{ + while (Length > 0) { + if (Ptr[Length - 1] != 0) { + IncrementErrorCount (); + Print (L"\nERROR : Reserved field must be 0\n"); + break; + } + + Length--; + } +} + +/** + This function validates bit-length reserved fields to check if they are 0. + + @param [in] Ptr Pointer to the start of the field data. + @param [in] Length Length of the field. + @param [in] Context Pointer to context specific information. +**/ +VOID +EFIAPI +ValidateReservedBits ( + IN UINT8 *Ptr, + IN UINT32 Length, + IN VOID *Context + ) +{ + UINT32 ByteLength; + + ByteLength = (Length + 7) >> 3; + ValidateReserved (Ptr, ByteLength, Context); +} + /** This function indents and prints the ACPI table Field Name. diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h index b1fe03b01a..9d559b39ea 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h @@ -267,6 +267,36 @@ DumpReservedBits ( IN UINT32 Length ); +/** + This function validates reserved fields to check if they are 0. + + @param [in] Ptr Pointer to the start of the field data. + @param [in] Length Length of the field. + @param [in] Context Pointer to context specific information. +**/ +VOID +EFIAPI +ValidateReserved ( + IN UINT8 *Ptr, + IN UINT32 Length, + IN VOID *Context + ); + +/** + This function validates bit-length reserved fields to check if they are 0. + + @param [in] Ptr Pointer to the start of the field data. + @param [in] Length Length of the field. + @param [in] Context Pointer to context specific information. +**/ +VOID +EFIAPI +ValidateReservedBits ( + IN UINT8 *Ptr, + IN UINT32 Length, + IN VOID *Context + ); + /** This function indents and prints the ACPI table Field Name. diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Agdi/AgdiParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Agdi/AgdiParser.c index 253c83d8c3..8b834a2967 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Agdi/AgdiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Agdi/AgdiParser.c @@ -42,35 +42,12 @@ ValidateSignalingFlags ( } } -/** - Validate that the Reserved field has expected value. - - @param [in] Ptr Pointer to the start of the field data. - @param [in] Length Length of the field. - @param [in] Context Pointer to context specific information e.g. this - could be a pointer to the ACPI table header. -**/ -STATIC -VOID -EFIAPI -ValidateResField ( - IN UINT8 *Ptr, - IN UINT32 Length, - IN VOID *Context - ) -{ - if (*Ptr != 0) { - IncrementErrorCount (); - Print (L"\nERROR: Reserved bits in Flags must be 0"); - } -} - /** An ACPI_PARSER array describing the AGDI Signaling Mode Flags field. **/ STATIC CONST ACPI_PARSER AgdiSignalingModeFlags[] = { - { L"Signaling Mode", 2, 0, L"%u", NULL, NULL, ValidateSignalingFlags, NULL }, - { L"Reserved", 6, 2, L"%u", NULL, NULL, ValidateResField, NULL }, + { L"Signaling Mode", 2, 0, L"%u", NULL, NULL, ValidateSignalingFlags, NULL }, + { L"Reserved", 6, 2, NULL, DumpReservedBits, NULL, ValidateReservedBits, NULL }, }; /** diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Mpam/MpamParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Mpam/MpamParser.c index 3c13de835e..f6b3a35aea 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Mpam/MpamParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Mpam/MpamParser.c @@ -70,61 +70,6 @@ MpamLengthError ( ); } -/** - This function validates reserved fields. Any reserved field within the MPAM - specification must be 0. - - @param [in] Ptr Pointer to the start of the field data. - @param [in] Length Length of the field. - @param [in] Context Pointer to context specific information. For this - particular function, context holds the size of the - reserved field that needs to be validated. -**/ -STATIC -VOID -EFIAPI -ValidateReserved ( - IN UINT8 *Ptr, - IN UINT32 Length, - IN VOID *Context - ) -{ - while (Length > 0) { - if (Ptr[Length-1] != 0) { - IncrementErrorCount (); - Print (L"\nERROR : Reserved field must be 0\n"); - break; - } - - Length--; - } -} - -/** - This function validates bit-length reserved fields. Any reserved field within - the MPAM specification must be 0. - - @param [in] Ptr Pointer to the start of the field data. - @param [in] Length Length of the field. - @param [in] Context Pointer to context specific information. For this - particular function, context holds the size of the - reserved field that needs to be validated. -**/ -STATIC -VOID -EFIAPI -ValidateReservedBits ( - IN UINT8 *Ptr, - IN UINT32 Length, - IN VOID *Context - ) -{ - UINT32 ByteLength; - - ByteLength = (Length + 7) >> 3; - ValidateReserved (Ptr, ByteLength, Context); -} - /** This function validates the MMIO size within the MSC node body for MPAM ACPI table. MPAM ACPI specification states that the MMIO size for an MSC having PCC diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Wsmt/WsmtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Wsmt/WsmtParser.c index 4433c047a4..b700cec49f 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Wsmt/WsmtParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Wsmt/WsmtParser.c @@ -49,41 +49,14 @@ ValidateWsmtProtectionFlag ( } } -/** - This function validates the reserved bits in the WSMT Protection flag. - - @param [in] Ptr Pointer to the start of the buffer. - @param [in] Length Length of the field. - @param [in] Context Pointer to context specific information e.g. this - could be a pointer to the ACPI table header. -**/ -STATIC -VOID -EFIAPI -ValidateReserved ( - IN UINT8 *Ptr, - IN UINT32 Length, - IN VOID *Context - ) -{ - UINT32 ProtectionFlag; - - ProtectionFlag = *(UINT32 *)Ptr; - - if ((ProtectionFlag & 0xFFFFFFF8) != 0) { - IncrementErrorCount (); - Print (L"ERROR: Reserved bits are not zero.\n"); - } -} - /** An ACPI_PARSER array describing the WSMT Protection flag . **/ STATIC CONST ACPI_PARSER WsmtProtectionFlagParser[] = { - { L"FIXED_COMM_BUFFERS ", 1, 0, L"0x%x", NULL, NULL, NULL, NULL }, - { L"COMM_BUFFER_NESTED_PTR_PROTECTION ", 1, 1, L"0x%x", NULL, NULL, NULL, NULL }, - { L"SYSTEM_RESOURCE_PROTECTION ", 1, 2, L"0x%x", NULL, NULL, NULL, NULL }, - { L"Reserved ", 29, 3, L"0x%x", NULL, NULL, ValidateReserved, NULL }, + { L"FIXED_COMM_BUFFERS ", 1, 0, L"0x%x", NULL, NULL, NULL, NULL }, + { L"COMM_BUFFER_NESTED_PTR_PROTECTION ", 1, 1, L"0x%x", NULL, NULL, NULL, NULL }, + { L"SYSTEM_RESOURCE_PROTECTION ", 1, 2, L"0x%x", NULL, NULL, NULL, NULL }, + { L"Reserved ", 29, 3, NULL, DumpReservedBits, NULL, ValidateReservedBits, NULL }, }; /** From a70c8729668f30de067f4b9db2e69baba283856e Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Wed, 14 May 2025 13:26:03 +0100 Subject: [PATCH 140/406] ShellPkg/AcpiView: Add parser for CCEL ACPI table The ACPI 6.5 specification introduces the CCEL (CC Event Log) table in section 5.2.34: https://uefi.org/specs/ACPI/6.5/ 05_ACPI_Software_Programming_Model.html#cc-event-log-acpi-table Extend AcpiView with a parser to decode and display CCEL table contents. This allows users to inspect CCEL tables from the UEFI Shell. Signed-off-by: Sami Mujawar --- .../UefiShellAcpiViewCommandLib/AcpiParser.h | 19 +++ .../Parsers/Ccel/CcelParser.c | 127 ++++++++++++++++++ .../UefiShellAcpiViewCommandLib.c | 1 + .../UefiShellAcpiViewCommandLib.inf | 1 + 4 files changed, 148 insertions(+) create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Ccel/CcelParser.c diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h index 9d559b39ea..34bfceb78e 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h @@ -698,6 +698,25 @@ ParseAcpiBgrt ( IN UINT8 AcpiTableRevision ); +/** + This function parses the ACPI CCEL table. + When trace is enabled this function parses the CCEL table and + traces the ACPI table fields. + + @param [in] Trace If TRUE, trace the ACPI fields. + @param [in] Ptr Pointer to the start of the buffer. + @param [in] AcpiTableLength Length of the ACPI table. + @param [in] AcpiTableRevision Revision of the ACPI table. +**/ +VOID +EFIAPI +ParseAcpiCcel ( + IN BOOLEAN Trace, + IN UINT8 *Ptr, + IN UINT32 AcpiTableLength, + IN UINT8 AcpiTableRevision + ); + /** This function parses the ACPI DBG2 table. When trace is enabled this function parses the DBG2 table and diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Ccel/CcelParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Ccel/CcelParser.c new file mode 100644 index 0000000000..5044182fa7 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Ccel/CcelParser.c @@ -0,0 +1,127 @@ +/** @file + CCEL table parser + + Copyright (c) 2025, Arm Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - ACPI 6.5 Specification - 29 Aug 2022 +**/ + +#include +#include +#include "AcpiParser.h" +#include "AcpiTableParser.h" +#include "AcpiViewConfig.h" + +// Local variables. +STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo; + +/** + Print the CC Type. + + @param [in] Format Optional format string for tracing the data. + @param [in] Ptr Pointer to the start of the buffer. + @param [in] Length Length of the field. +**/ +VOID +EFIAPI +PrintCcType ( + IN CONST CHAR16 *Format OPTIONAL, + IN UINT8 *Ptr, + IN UINT32 Length + ) +{ + UINT8 CcType; + + CcType = *Ptr; + switch (CcType) { + case EFI_ACPI_6_5_CC_TYPE_NONE: + Print (L"CC Type '%u' - None", CcType); + break; + case EFI_ACPI_6_5_CC_TYPE_SEV: + Print (L"CC Type '%u' - SEV", CcType); + break; + case EFI_ACPI_6_5_CC_TYPE_TDX: + Print (L"CC Type '%u' - TDX", CcType); + break; + case EFI_ACPI_6_5_CC_TYPE_APTEE: + Print (L"CC Type '%u' - APTEE", CcType); + break; + case EFI_ACPI_6_5_CC_TYPE_ARMCCA: + Print (L"CC Type '%u' - Arm CCA", CcType); + break; + default: + Print (L"CC Type '%u' - Unknown", CcType); + } // switch +} + +/** + This function validates CC Type field. + + @param [in] Ptr Pointer to the start of the field data. + @param [in] Length Length of the field. + @param [in] Context Pointer to context specific information. +**/ +VOID +EFIAPI +ValidateCcType ( + IN UINT8 *Ptr, + IN UINT32 Length, + IN VOID *Context + ) +{ + UINT8 CcType; + + CcType = *Ptr; + + if (CcType > EFI_ACPI_6_5_CC_TYPE_ARMCCA) { + IncrementErrorCount (); + Print (L"\nERROR : Invalid/Unknown CC Type - %u.\n", CcType); + } +} + +/** + An ACPI_PARSER array describing the ACPI CCEL Table. +**/ +STATIC CONST ACPI_PARSER CcelParser[] = { + PARSE_ACPI_HEADER (&AcpiHdrInfo), + { L"CC Type", 1, 36, L"%d", NULL, NULL, NULL, NULL }, + { L"CC Subtype", 1, 37, L"%d", PrintCcType, NULL, ValidateCcType, NULL }, + { L"Reserved", 2, 38, NULL, DumpReserved, NULL, ValidateReserved, NULL }, + { L"Log Area Minimum Length (LAML)",8, 40, L"0x%lx", NULL, NULL, NULL, NULL }, + { L"Log Area Start Address (LASA)",8, 48, L"0x%lx", NULL, NULL, NULL, NULL } +}; + +/** + This function parses the ACPI CCEL table. + When trace is enabled this function parses the CCEL table and + traces the ACPI table fields. + + @param [in] Trace If TRUE, trace the ACPI fields. + @param [in] Ptr Pointer to the start of the buffer. + @param [in] AcpiTableLength Length of the ACPI table. + @param [in] AcpiTableRevision Revision of the ACPI table. +**/ +VOID +EFIAPI +ParseAcpiCcel ( + IN BOOLEAN Trace, + IN UINT8 *Ptr, + IN UINT32 AcpiTableLength, + IN UINT8 AcpiTableRevision + ) +{ + if (!Trace) { + return; + } + + ParseAcpi ( + TRUE, + 0, + "CCEL", + Ptr, + AcpiTableLength, + PARSER_PARAMS (CcelParser) + ); +} diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c index 12e3940a05..e64888dd30 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c @@ -55,6 +55,7 @@ ACPI_TABLE_PARSER ParserList[] = { { EFI_ACPI_ARM_AGDI_TABLE_SIGNATURE, ParseAcpiAgdi }, { EFI_ACPI_6_4_ARM_PERFORMANCE_MONITORING_UNIT_TABLE_SIGNATURE, ParseAcpiApmt }, { EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE, ParseAcpiBgrt }, + { EFI_ACPI_6_5_CONFIDENTIAL_COMPUTING_EVENT_LOG_TABLE_SIGNATURE, ParseAcpiCcel }, { EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE, ParseAcpiDbg2 }, { EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiDsdt }, diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf index 1a42b73169..8f223a8a4f 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf @@ -33,6 +33,7 @@ Parsers/Agdi/AgdiParser.c Parsers/Apmt/ApmtParser.c Parsers/Bgrt/BgrtParser.c + Parsers/Ccel/CcelParser.c Parsers/Dbg2/Dbg2Parser.c Parsers/Dsdt/DsdtParser.c Parsers/Einj/EinjParser.c From e6b64e84e5d4f8dcbb5e0ff52f322eb5892bff34 Mon Sep 17 00:00:00 2001 From: Oleksandr Tymoshenko Date: Fri, 15 May 2026 23:15:10 +0000 Subject: [PATCH 141/406] DynamicTablesPkg: Fix memory leak in MetaDataObjLib library Clean up all metadata entries when freeing a metadata handle in MetadataFreeHandle. Signed-off-by: Oleksandr Tymoshenko --- .../Include/Library/MetadataObjLib.h | 4 ++-- .../Common/MetadataObjLib/MetadataObj.c | 22 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/DynamicTablesPkg/Include/Library/MetadataObjLib.h b/DynamicTablesPkg/Include/Library/MetadataObjLib.h index 72fcc1e6b0..078a57ce0f 100644 --- a/DynamicTablesPkg/Include/Library/MetadataObjLib.h +++ b/DynamicTablesPkg/Include/Library/MetadataObjLib.h @@ -77,7 +77,7 @@ MetadataInitializeHandle ( /** Free the Metadata Root. - @param[in] Root Root of the Metadata information to free. + @param[in] RootHandle Root of the Metadata information to free. @retval EFI_SUCCESS Success. @retval EFI_INVALID_PARAMETER Invalid parameter. @@ -86,7 +86,7 @@ MetadataInitializeHandle ( EFI_STATUS EFIAPI MetadataFreeHandle ( - IN METADATA_ROOT_HANDLE Root + IN METADATA_ROOT_HANDLE RootHandle ); /** Attach some Metadata to a (Type/Token) pair. diff --git a/DynamicTablesPkg/Library/Common/MetadataObjLib/MetadataObj.c b/DynamicTablesPkg/Library/Common/MetadataObjLib/MetadataObj.c index 20b0609946..2e7f28420d 100644 --- a/DynamicTablesPkg/Library/Common/MetadataObjLib/MetadataObj.c +++ b/DynamicTablesPkg/Library/Common/MetadataObjLib/MetadataObj.c @@ -63,7 +63,7 @@ MetadataInitializeHandle ( /** Free the Metadata Root. - @param[in] Root Root of the Metadata information to free. + @param[in] RootHandle Root of the Metadata information to free. @retval EFI_SUCCESS Success. @retval EFI_INVALID_PARAMETER Invalid parameter. @@ -72,14 +72,32 @@ MetadataInitializeHandle ( EFI_STATUS EFIAPI MetadataFreeHandle ( - IN METADATA_ROOT_HANDLE Root + IN METADATA_ROOT_HANDLE RootHandle ) { + METADATA_ROOT *Root; + METADATA_ENTRY *Entry; + UINT32 Index; + + Root = (METADATA_ROOT *)RootHandle; + if (Root == NULL) { ASSERT (Root != NULL); return EFI_INVALID_PARAMETER; } + for (Index = 0; Index < MetadataTypeMax; Index++) { + while (!IsListEmpty (&Root->MetadataList[Index].List)) { + Entry = (METADATA_ENTRY *)GetFirstNode (&Root->MetadataList[Index].List); + RemoveEntryList (&Entry->List); + if (Entry->Metadata != NULL) { + FreePool (Entry->Metadata); + } + + FreePool (Entry); + } + } + FreePool (Root); return EFI_SUCCESS; } From 734d7c6dc775f4aa54ab59b701926edec559756b Mon Sep 17 00:00:00 2001 From: Oleksandr Tymoshenko Date: Mon, 18 May 2026 21:29:10 +0000 Subject: [PATCH 142/406] MdePkg: Add constants for HMAT structures' fields Add constants for HMAT table's SSLBI and ProximityDoman structures to industry standards headers for Acpi 6.4, 6.5, and 6.6. Co-authored-by: Sophia Wang Signed-off-by: Oleksandr Tymoshenko --- MdePkg/Include/IndustryStandard/Acpi64.h | 34 ++++++++++++++++++++++++ MdePkg/Include/IndustryStandard/Acpi65.h | 34 ++++++++++++++++++++++++ MdePkg/Include/IndustryStandard/Acpi66.h | 34 ++++++++++++++++++++++++ MdePkg/MdePkg.ci.yaml | 3 ++- 4 files changed, 104 insertions(+), 1 deletion(-) diff --git a/MdePkg/Include/IndustryStandard/Acpi64.h b/MdePkg/Include/IndustryStandard/Acpi64.h index 5ea20ba9a2..0b9c3febf9 100644 --- a/MdePkg/Include/IndustryStandard/Acpi64.h +++ b/MdePkg/Include/IndustryStandard/Acpi64.h @@ -2149,6 +2149,40 @@ typedef struct { #define EFI_ACPI_6_4_HMAT_TYPE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO 0x01 #define EFI_ACPI_6_4_HMAT_TYPE_MEMORY_SIDE_CACHE_INFO 0x02 +/// +/// HMAT Memory Proximity Domain Attributes Flags +/// +#define EFI_ACPI_6_4_HMAT_PROXIMITY_DOMAIN_INITIATOR_VALID 1 + +/// +/// HMAT System Locality Latency and Bandwidth Info Flags +/// +#define EFI_ACPI_6_4_HMAT_MEMORY_HIERARCHY_MEMORY 0 +#define EFI_ACPI_6_4_HMAT_MEMORY_HIERARCHY_L1_CACHE 1 +#define EFI_ACPI_6_4_HMAT_MEMORY_HIERARCHY_L2_CACHE 2 +#define EFI_ACPI_6_4_HMAT_MEMORY_HIERARCHY_L3_CACHE 3 + +#define EFI_ACPI_6_4_HMAT_ACCESS_ATTRIBUTES_MIN_TRANSFER_SIZE 0x10 +#define EFI_ACPI_6_4_HMAT_ACCESS_ATTRIBUTES_NON_SEQUENTIAL 0x20 + +/// +/// HMAT System Locality Latency and Bandwidth Info Data Type +/// +/// For Memory Hierarchy == 0 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_ACCESS_LATENCY 0 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_READ_LATENCY 1 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_WRITE_LATENCY 2 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_ACCESS_BANDWIDTH 3 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_READ_BANDWIDTH 4 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_WRITE_BANDWIDTH 5 +/// For Memory Hierarchy == 1, 2, or 3 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_HIT_ACCESS_LATENCY 0 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_HIT_READ_LATENCY 1 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_HIT_WRITE_LATENCY 2 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_HIT_ACCESS_BANDWIDTH 3 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_HIT_READ_BANDWIDTH 4 +#define EFI_ACPI_6_4_HMAT_SSLBI_DATA_TYPE_HIT_WRITE_BANDWIDTH 5 + /// /// HMAT Structure Header /// diff --git a/MdePkg/Include/IndustryStandard/Acpi65.h b/MdePkg/Include/IndustryStandard/Acpi65.h index fc43bdda81..1df92f9858 100644 --- a/MdePkg/Include/IndustryStandard/Acpi65.h +++ b/MdePkg/Include/IndustryStandard/Acpi65.h @@ -2288,6 +2288,40 @@ typedef struct { #define EFI_ACPI_6_5_HMAT_TYPE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO 0x01 #define EFI_ACPI_6_5_HMAT_TYPE_MEMORY_SIDE_CACHE_INFO 0x02 +/// +/// HMAT Memory Proximity Domain Attributes Flags +/// +#define EFI_ACPI_6_5_HMAT_PROXIMITY_DOMAIN_INITIATOR_VALID 1 + +/// +/// HMAT System Locality Latency and Bandwidth Info Flags +/// +#define EFI_ACPI_6_5_HMAT_MEMORY_HIERARCHY_MEMORY 0 +#define EFI_ACPI_6_5_HMAT_MEMORY_HIERARCHY_L1_CACHE 1 +#define EFI_ACPI_6_5_HMAT_MEMORY_HIERARCHY_L2_CACHE 2 +#define EFI_ACPI_6_5_HMAT_MEMORY_HIERARCHY_L3_CACHE 3 + +#define EFI_ACPI_6_5_HMAT_ACCESS_ATTRIBUTES_MIN_TRANSFER_SIZE 0x10 +#define EFI_ACPI_6_5_HMAT_ACCESS_ATTRIBUTES_NON_SEQUENTIAL 0x20 + +/// +/// HMAT System Locality Latency and Bandwidth Info Data Type +/// +/// For Memory Hierarchy == 0 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_ACCESS_LATENCY 0 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_READ_LATENCY 1 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_WRITE_LATENCY 2 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_ACCESS_BANDWIDTH 3 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_READ_BANDWIDTH 4 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_WRITE_BANDWIDTH 5 +/// For Memory Hierarchy == 1, 2, or 3 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_HIT_ACCESS_LATENCY 0 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_HIT_READ_LATENCY 1 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_HIT_WRITE_LATENCY 2 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_HIT_ACCESS_BANDWIDTH 3 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_HIT_READ_BANDWIDTH 4 +#define EFI_ACPI_6_5_HMAT_SSLBI_DATA_TYPE_HIT_WRITE_BANDWIDTH 5 + /// /// HMAT Structure Header /// diff --git a/MdePkg/Include/IndustryStandard/Acpi66.h b/MdePkg/Include/IndustryStandard/Acpi66.h index db63ba5fb6..4b734b9687 100644 --- a/MdePkg/Include/IndustryStandard/Acpi66.h +++ b/MdePkg/Include/IndustryStandard/Acpi66.h @@ -2390,6 +2390,40 @@ typedef struct { #define EFI_ACPI_6_6_HMAT_TYPE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO 0x01 #define EFI_ACPI_6_6_HMAT_TYPE_MEMORY_SIDE_CACHE_INFO 0x02 +/// +/// HMAT Memory Proximity Domain Attributes Flags +/// +#define EFI_ACPI_6_6_HMAT_PROXIMITY_DOMAIN_INITIATOR_VALID 1 + +/// +/// HMAT System Locality Latency and Bandwidth Info Flags +/// +#define EFI_ACPI_6_6_HMAT_MEMORY_HIERARCHY_MEMORY 0 +#define EFI_ACPI_6_6_HMAT_MEMORY_HIERARCHY_L1_CACHE 1 +#define EFI_ACPI_6_6_HMAT_MEMORY_HIERARCHY_L2_CACHE 2 +#define EFI_ACPI_6_6_HMAT_MEMORY_HIERARCHY_L3_CACHE 3 + +#define EFI_ACPI_6_6_HMAT_ACCESS_ATTRIBUTES_MIN_TRANSFER_SIZE 0x10 +#define EFI_ACPI_6_6_HMAT_ACCESS_ATTRIBUTES_NON_SEQUENTIAL 0x20 + +/// +/// HMAT System Locality Latency and Bandwidth Info Data Type +/// +/// For Memory Hierarchy == 0 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_ACCESS_LATENCY 0 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_READ_LATENCY 1 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_WRITE_LATENCY 2 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_ACCESS_BANDWIDTH 3 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_READ_BANDWIDTH 4 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_WRITE_BANDWIDTH 5 +/// For Memory Hierarchy == 1, 2, or 3 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_HIT_ACCESS_LATENCY 0 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_HIT_READ_LATENCY 1 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_HIT_WRITE_LATENCY 2 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_HIT_ACCESS_BANDWIDTH 3 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_HIT_READ_BANDWIDTH 4 +#define EFI_ACPI_6_6_HMAT_SSLBI_DATA_TYPE_HIT_WRITE_BANDWIDTH 5 + /// /// HMAT Structure Header /// diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index cd85c5d037..c686dcbdd9 100644 --- a/MdePkg/MdePkg.ci.yaml +++ b/MdePkg/MdePkg.ci.yaml @@ -219,7 +219,8 @@ "sigle", # SmBios.h "toleremce", # IpmiNetFnStorage.h "unownered", # TcgPhysicalPresence.h - "voilation" # PciExpress*.h + "voilation", # PciExpress*.h + "sslbi" # Acpi*.h ], "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported) From 9782df45fe5eed9ee5d36319917e86f6a88f0ce8 Mon Sep 17 00:00:00 2001 From: Oleksandr Tymoshenko Date: Mon, 18 May 2026 23:25:37 +0000 Subject: [PATCH 143/406] DynamicTablesPkg: Add HMAT generator - Generate HMAT table from ConfigurationManager objects. Co-authored-by: Ryan Heise Co-authored-by: Sophia Wang Signed-off-by: Oleksandr Tymoshenko --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + DynamicTablesPkg/DynamicTablesPkg.ci.yaml | 3 +- DynamicTablesPkg/Include/AcpiTableGenerator.h | 1 + .../Acpi/Common/AcpiHmatLib/AcpiHmatLib.inf | 29 + .../Acpi/Common/AcpiHmatLib/HmatGenerator.c | 751 ++++++++++++++++++ 5 files changed, 785 insertions(+), 1 deletion(-) create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/AcpiHmatLib.inf create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/HmatGenerator.c diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index 47f056bbf0..f9b0fb2dfc 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -38,6 +38,7 @@ DynamicTablesPkg/Library/Acpi/Common/AcpiCedtLib/AcpiCedtLib.inf DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2Lib.inf DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf + DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/AcpiHmatLib.inf DynamicTablesPkg/Library/Acpi/Common/AcpiMcfgLib/AcpiMcfgLib.inf DynamicTablesPkg/Library/Acpi/Common/AcpiPcctLib/AcpiPcctLib.inf DynamicTablesPkg/Library/Acpi/Common/AcpiPpttLib/AcpiPpttLib.inf @@ -137,6 +138,7 @@ NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiCedtLib/AcpiCedtLib.inf NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2Lib.inf NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf + NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/AcpiHmatLib.inf NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiMcfgLib/AcpiMcfgLib.inf NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiPcctLib/AcpiPcctLib.inf NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiPpttLib/AcpiPpttLib.inf diff --git a/DynamicTablesPkg/DynamicTablesPkg.ci.yaml b/DynamicTablesPkg/DynamicTablesPkg.ci.yaml index f553de7b2c..224051cb03 100644 --- a/DynamicTablesPkg/DynamicTablesPkg.ci.yaml +++ b/DynamicTablesPkg/DynamicTablesPkg.ci.yaml @@ -154,7 +154,8 @@ "rintc", "smcbios", "jedec", - "jep" + "jep", + "sslbi" ], # words to extend to the dictionary for this package "IgnoreStandardPaths": [], # Standard Plugin defined paths that # should be ignore diff --git a/DynamicTablesPkg/Include/AcpiTableGenerator.h b/DynamicTablesPkg/Include/AcpiTableGenerator.h index b706e5ca31..0f827d2cac 100755 --- a/DynamicTablesPkg/Include/AcpiTableGenerator.h +++ b/DynamicTablesPkg/Include/AcpiTableGenerator.h @@ -132,6 +132,7 @@ typedef enum StdAcpiTableId { EStdAcpiTableIdSsdtDmc620Pmu, ///< SSDT DMC620 PMU Generator EStdAcpiTableIdHest, ///< Hest Generator EStdAcpiTableIdEinj, ///< EINJ Generator + EStdAcpiTableIdHmat, ///< HMAT Generator EStdAcpiTableIdMax } ESTD_ACPI_TABLE_ID; diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/AcpiHmatLib.inf b/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/AcpiHmatLib.inf new file mode 100644 index 0000000000..754802bc0c --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/AcpiHmatLib.inf @@ -0,0 +1,29 @@ +## @file +# HMAT Table Generator +# +# Copyright (c) 2026, Google LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010019 + BASE_NAME = AcpiHmatLib + FILE_GUID = 1724d37a-fb05-4fe6-bb13-c04a46efe0ac + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = AcpiHmatLibConstructor + DESTRUCTOR = AcpiHmatLibDestructor + +[Sources] + HmatGenerator.c + +[Packages] + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + BaseLib + CmObjHelperLib diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/HmatGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/HmatGenerator.c new file mode 100644 index 0000000000..fe980f1cdc --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/HmatGenerator.c @@ -0,0 +1,751 @@ +/** @file + HMAT Table Generator + + Copyright (c) 2026, Google LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include +#include + +/** Standard HMAT Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArchCommonObjMemoryLatBwInfo + - EArchCommonObjMemoryProximityDomainAttrInfo + - EArchCommonObjProximityDomainInfo + - EArchCommonObjProximityDomainRelationInfo + +*/ + +/** Retrieve the Proximity Domain Info */ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjProximityDomainInfo, + CM_ARCH_COMMON_PROXIMITY_DOMAIN_INFO + ); + +/** Retrieve the Proximity Domain Relation Info. */ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjProximityDomainRelationInfo, + CM_ARCH_COMMON_PROXIMITY_DOMAIN_RELATION_INFO + ); + +/** Retrieve the Proximity Domain Attr Info */ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjMemoryProximityDomainAttrInfo, + CM_ARCH_COMMON_MEMORY_PROXIMITY_DOMAIN_ATTR_INFO + ); + +/** Retrieve the SSLBI Info */ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjMemoryLatBwInfo, + CM_ARCH_COMMON_MEMORY_LAT_BW_INFO + ); + +/** Find an index of the specified domain ID in an array. + + @param [in] DomainId Domain ID to find. + @param [in] DomainIds Pointer to an array with domain IDs. + @param [in] DomainIdCount Number of elements in DomainIds array. + @param [out] DomainIdIndex Pointer where the index of the found ID is stored. + Can be NULL if the actual index doesn't matter. + + @retval EFI_SUCCESS If DomainId was found + @retval EFI_NOT_FOUND If DomainId wasn't found +**/ +STATIC +EFI_STATUS +FindDomainIndex ( + IN UINT32 DomainId, + IN UINT32 *DomainIds, + IN UINTN DomainIdCount, + OUT UINTN *DomainIdIndex OPTIONAL + ) +{ + UINTN Index; + + for (Index = 0; Index < DomainIdCount; Index++) { + if (DomainIds[Index] == DomainId) { + if (DomainIdIndex != NULL) { + *DomainIdIndex = Index; + } + + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** Computes how many bytes are required to hold an ACPI HMAT SSLBI table. + + @param [in] InitiatorProximityDomainCount Number of initiator domains in an SSLBI record. + @param [in] TargetProximityDomainCount Number of target domains in an SSLBI record. + + @retval Bytes required to store SSLBI record. +**/ +STATIC +UINT32 +GetSslbiTableSize ( + IN UINT32 InitiatorProximityDomainCount, + IN UINT32 TargetProximityDomainCount + ) +{ + return sizeof (UINT32) * InitiatorProximityDomainCount + + sizeof (UINT32) * TargetProximityDomainCount + + sizeof (UINT16) * InitiatorProximityDomainCount * TargetProximityDomainCount + + sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO); +} + +/** Populate SSLBI record and return the actual size of the record to caller. + + @param [in] CfgMgrProtocol ConfigurationManager protocol. + @param [in] CmMemLatBwInfo SSLBI record information. + @param [in] CmMemLatBwRelations Array of relations to be populated into SSLBI. + @param [in] CmMemLatBwRelationCount Number of elements in the relations array. + @param [in] ProximityDomainCount Maximum number of proximity domains, used to + sanity check the relations array data. + @param [in, out] MemLatBwInfo SSLBI to be populated. Caller is responsible for + allocating memory area large enough to fit the data. + @param [out] RecordLength Actual size of the SSLBI record in bytes, + header + relations matrix. + + @retval EFI_INVALID_PARAMETER The relations matrix data is not valid: it's either spare + or number of initiators/targets larger than number of domains + in the system. +**/ +STATIC +EFI_STATUS +AddMemLatBwInfo ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST CM_ARCH_COMMON_MEMORY_LAT_BW_INFO *CmMemLatBwInfo, + IN CONST CM_ARCH_COMMON_PROXIMITY_DOMAIN_RELATION_INFO *CmMemLatBwRelations, + IN UINTN CmMemLatBwRelationCount, + IN UINT32 ProximityDomainCount, + IN OUT EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO *MemLatBwInfo, + OUT UINTN *RecordLength + ) +{ + UINTN Index; + UINT32 *InitiatorDomains; + UINT32 InitiatorDomainCount; + UINT32 *TargetDomains; + UINT32 TargetDomainCount; + EFI_STATUS Status; + UINT32 DomainId; + UINTN InitiatorIdx; + UINTN TargetIdx; + UINT16 *Relations; + UINT8 *TablePtr; + + ASSERT (CfgMgrProtocol != NULL); + ASSERT (MemLatBwInfo != NULL); + ASSERT (CmMemLatBwInfo != NULL); + ASSERT (CmMemLatBwRelations != NULL); + ASSERT (CmMemLatBwRelationCount > 0); + ASSERT (ProximityDomainCount > 0); + ASSERT (RecordLength != NULL); + + if (CmMemLatBwRelationCount == 0) { + return EFI_INVALID_PARAMETER; + } + + MemLatBwInfo->Type = EFI_ACPI_6_4_HMAT_TYPE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO; + + CopyMem (&MemLatBwInfo->Flags, &CmMemLatBwInfo->Flags, sizeof (UINT8)); + if ((MemLatBwInfo->Flags.MemoryHierarchy > EFI_ACPI_6_4_HMAT_MEMORY_HIERARCHY_L3_CACHE) || + (MemLatBwInfo->Flags.Reserved != 0)) + { + return EFI_INVALID_PARAMETER; + } + + MemLatBwInfo->DataType = CmMemLatBwInfo->DataType; + MemLatBwInfo->MinTransferSize = CmMemLatBwInfo->MinTransferSize; + MemLatBwInfo->EntryBaseUnit = CmMemLatBwInfo->EntryBaseUnit; + + TablePtr = (UINT8 *)MemLatBwInfo; + + TablePtr += sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO); + InitiatorDomainCount = 0; + InitiatorDomains = (UINT32 *)TablePtr; + + // Append Initiator ProximityDomains. + for (Index = 0; Index < CmMemLatBwRelationCount; Index++) { + Status = GetProximityDomainId ( + CfgMgrProtocol, + 0, + CmMemLatBwRelations[Index].FirstDomainToken, + &DomainId + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + if (FindDomainIndex (DomainId, InitiatorDomains, InitiatorDomainCount, NULL) == EFI_NOT_FOUND) { + if (InitiatorDomainCount >= ProximityDomainCount) { + return EFI_INVALID_PARAMETER; + } + + InitiatorDomains[InitiatorDomainCount] = DomainId; + InitiatorDomainCount++; + } + } + + // Append Target ProximityDomains. + TargetDomainCount = 0; + TargetDomains = InitiatorDomains + InitiatorDomainCount; + for (Index = 0; Index < CmMemLatBwRelationCount; Index++) { + Status = GetProximityDomainId ( + CfgMgrProtocol, + 0, + CmMemLatBwRelations[Index].SecondDomainToken, + &DomainId + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + if (FindDomainIndex (DomainId, TargetDomains, TargetDomainCount, NULL) == EFI_NOT_FOUND) { + if (TargetDomainCount >= ProximityDomainCount) { + return EFI_INVALID_PARAMETER; + } + + TargetDomains[TargetDomainCount] = DomainId; + TargetDomainCount++; + } + } + + DEBUG (( + DEBUG_INFO, + "HMAT: Lat/Bw info table dimensions: %d x %d\n", + InitiatorDomainCount, + TargetDomainCount + )); + + if (InitiatorDomainCount * TargetDomainCount != CmMemLatBwRelationCount) { + DEBUG (( + DEBUG_ERROR, + "HMAT: Lat/Bw info table dimensions %dx%d do not match elements count %d (should be %d)\n", + InitiatorDomainCount, + TargetDomainCount, + CmMemLatBwRelationCount, + InitiatorDomainCount * TargetDomainCount + )); + return EFI_INVALID_PARAMETER; + } + + Relations = (UINT16 *)(TargetDomains + TargetDomainCount); + for (Index = 0; Index < CmMemLatBwRelationCount; Index++) { + Status = GetProximityDomainId ( + CfgMgrProtocol, + 0, + CmMemLatBwRelations[Index].FirstDomainToken, + &DomainId + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + Status = FindDomainIndex (DomainId, InitiatorDomains, InitiatorDomainCount, &InitiatorIdx); + ASSERT_EFI_ERROR (Status); + + Status = GetProximityDomainId ( + CfgMgrProtocol, + 0, + CmMemLatBwRelations[Index].SecondDomainToken, + &DomainId + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + Status = FindDomainIndex (DomainId, TargetDomains, TargetDomainCount, &TargetIdx); + ASSERT_EFI_ERROR (Status); + + if (CmMemLatBwRelations[Index].Relation > MAX_UINT16) { + DEBUG (( + DEBUG_ERROR, + "HMAT: relation value of element %d does not fit in 16 bits: %d\n", + Index, + CmMemLatBwRelations[Index].Relation + )); + return EFI_INVALID_PARAMETER; + } + + Relations[InitiatorIdx * TargetDomainCount + TargetIdx] = CmMemLatBwRelations[Index].Relation & 0xFFFF; + } + + // Update record info + MemLatBwInfo->Length = GetSslbiTableSize (InitiatorDomainCount, TargetDomainCount); + MemLatBwInfo->NumberOfInitiatorProximityDomains = InitiatorDomainCount; + MemLatBwInfo->NumberOfTargetProximityDomains = TargetDomainCount; + *RecordLength = MemLatBwInfo->Length; + + return EFI_SUCCESS; +} + +/** Add the MemProxDomainAttr Information record to the HMAT Table. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager Protocol Interface. + @param [in] MemProximityDomainAttrInfo Pointer to a Proximity Domain Attribute array in an HMAT table. + The caller is responsible for allocating enough memory to fit + the data. + @param [in] CmMemProximityDomainAttrInfo Pointer ConfigurationManager objects array with Domain Attribute data. + @param [in] MemProximityDomainAttrCount Number of entries in CmMemProximityDomainAttrInfo. + + @retval EFI_SUCCESS if attributes were added + @retval error code otherwise +**/ +STATIC +EFI_STATUS +AddMemProximityDomainAttrInfo ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES *MemProximityDomainAttrInfo, + IN CONST CM_ARCH_COMMON_MEMORY_PROXIMITY_DOMAIN_ATTR_INFO *CmMemProximityDomainAttrInfo, + IN UINT32 MemProximityDomainAttrCount + ) +{ + EFI_STATUS Status; + + if (MemProximityDomainAttrCount == 0) { + return EFI_SUCCESS; + } + + ASSERT (MemProximityDomainAttrInfo != NULL); + ASSERT (CmMemProximityDomainAttrInfo != NULL); + + while (MemProximityDomainAttrCount-- != 0) { + MemProximityDomainAttrInfo->Type = EFI_ACPI_6_4_HMAT_TYPE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES; + MemProximityDomainAttrInfo->Length = sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES); + CopyMem (&MemProximityDomainAttrInfo->Flags, &CmMemProximityDomainAttrInfo->Flags, sizeof (UINT16)); + if (MemProximityDomainAttrInfo->Flags.Reserved != 0) { + return EFI_INVALID_PARAMETER; + } + + if (CmMemProximityDomainAttrInfo->InitiatorProximityDomain + == CmMemProximityDomainAttrInfo->MemoryProximityDomain) + { + return EFI_INVALID_PARAMETER; + } + + Status = GetProximityDomainId ( + CfgMgrProtocol, + 0, + CmMemProximityDomainAttrInfo->InitiatorProximityDomain, + &MemProximityDomainAttrInfo->InitiatorProximityDomain + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + Status = GetProximityDomainId ( + CfgMgrProtocol, + 0, + CmMemProximityDomainAttrInfo->MemoryProximityDomain, + &MemProximityDomainAttrInfo->MemoryProximityDomain + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + MemProximityDomainAttrInfo++; + CmMemProximityDomainAttrInfo++; + } + + return EFI_SUCCESS; +} + +/** Free any resources allocated for constructing the table. + + @param [in] This Pointer to the ACPI table generator. + @param [in] AcpiTableInfo Pointer to the ACPI Table Info. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in, out] Table Pointer to ACPI Table. + + @retval EFI_SUCCESS The resources were freed successfully. + @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +FreeHmatTable ( + IN CONST ACPI_TABLE_GENERATOR *CONST This, + IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table + ) +{ + ASSERT (This != NULL); + ASSERT (AcpiTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); + ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); + + if ((Table == NULL) || (*Table == NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: HMAT: Invalid Table Pointer\n")); + ASSERT ((Table != NULL) && (*Table != NULL)); + return EFI_INVALID_PARAMETER; + } + + if (*Table != NULL) { + FreePool (*Table); + *Table = NULL; + } + + return EFI_SUCCESS; +} + +/** Construct the HMAT ACPI table. + + This function invokes the Configuration Manager protocol interface + to get the required hardware information for generating the ACPI + table. + + If this function allocates any resources then they must be freed + in the FreeXXXXTableResourcesEx function. + + @param [in] This Pointer to the ACPI table generator. + @param [in] AcpiTableInfo Pointer to the ACPI table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the generated ACPI table. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +BuildHmatTable ( + IN CONST ACPI_TABLE_GENERATOR *This, + IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table + ) +{ + EFI_STATUS Status; + UINTN TableSize; + UINT32 MemProximityDomainAttrCount; + UINT32 MemLatBwCount; + CM_ARCH_COMMON_MEMORY_PROXIMITY_DOMAIN_ATTR_INFO *MemProximityDomainAttrInfo; + CM_ARCH_COMMON_MEMORY_LAT_BW_INFO *MemLatBwInfos; + CM_ARCH_COMMON_PROXIMITY_DOMAIN_RELATION_INFO *MemLatBwRelations; + CM_ARCH_COMMON_PROXIMITY_DOMAIN_INFO *ProximityDomainInfo; + UINT32 ProximityDomainInfoCount; + UINT32 MemLatBwRelationsCount; + UINTN MemProximityDomainAttrOffset; + UINTN MemLatBwOffset; + UINT32 Index; + UINT64 MaxLatBwSize; + UINTN LatBwEntrySize; + EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER *Hmat; + VOID *FinalTable; + + ASSERT (This != NULL); + ASSERT (AcpiTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Table != NULL); + ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); + ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); + if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) || + (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision)) + { + DEBUG (( + DEBUG_ERROR, + "ERROR: HMAT: Requested table revision = %d, is not supported." + "Supported table revision: Minimum = %d, Maximum = %d\n", + AcpiTableInfo->AcpiTableRevision, + This->MinAcpiTableRevision, + This->AcpiTableRevision + )); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + + Status = GetEArchCommonObjProximityDomainInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &ProximityDomainInfo, + &ProximityDomainInfoCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: HMAT: Failed to get ProximityDomainInfo. Status = %r\n", + Status + )); + goto error_handler; + } + + MemProximityDomainAttrCount = 0; + + Status = GetEArchCommonObjMemoryProximityDomainAttrInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &MemProximityDomainAttrInfo, + &MemProximityDomainAttrCount + ); + + if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: HMAT: Failed to get MemProximityDomain Info. Status = %r\n", + Status + )); + goto error_handler; + } + + MemLatBwCount = 0; + + Status = GetEArchCommonObjMemoryLatBwInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &MemLatBwInfos, + &MemLatBwCount + ); + + if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: HMAT: Failed to get MemLatBwInfo. Status = %r\n", + Status + )); + goto error_handler; + } + + TableSize = sizeof (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER); + + MemProximityDomainAttrOffset = TableSize; + TableSize += + (sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES) * MemProximityDomainAttrCount); + + MemLatBwOffset = TableSize; + + // The largest SSLBI entry is full matrix where all proximity + // domains act as initiators and targets. Go for max case, adjust size later. + MaxLatBwSize = GetSslbiTableSize (ProximityDomainInfoCount, ProximityDomainInfoCount); + TableSize += MemLatBwCount * MaxLatBwSize; + + if (TableSize > MAX_UINT32) { + return EFI_INVALID_PARAMETER; + } + + // Allocate the Buffer for HMAT table + *Table = (EFI_ACPI_DESCRIPTION_HEADER *)AllocateZeroPool (TableSize); + + if (*Table == NULL) { + Status = EFI_OUT_OF_RESOURCES; + DEBUG (( + DEBUG_ERROR, + "ERROR: HMAT: Failed to allocate memory for HMAT Table, Size = %d," \ + " Status = %r\n", + TableSize, + Status + )); + goto error_handler; + } + + Hmat = (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER *)*Table; + + // Build HMAT table. + Status = AddAcpiHeader ( + CfgMgrProtocol, + This, + &Hmat->Header, + AcpiTableInfo, + (UINT32)TableSize + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: HMAT: Failed to add ACPI header. Status = %r\n", + Status + )); + goto error_handler; + } + + Status = AddMemProximityDomainAttrInfo ( + CfgMgrProtocol, + (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES *)((UINT8 *)Hmat + MemProximityDomainAttrOffset), + MemProximityDomainAttrInfo, + MemProximityDomainAttrCount + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to add Proximity Domain Attr structures: %r\n", __func__, Status)); + goto error_handler; + } + + for (Index = 0; Index < MemLatBwCount; Index++) { + Status = GetEArchCommonObjProximityDomainRelationInfo ( + CfgMgrProtocol, + MemLatBwInfos[Index].RelativeDistanceArray, + &MemLatBwRelations, + &MemLatBwRelationsCount + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get relative distances array: %r\n", __func__, Status)); + goto error_handler; + } + + Status = AddMemLatBwInfo ( + CfgMgrProtocol, + &MemLatBwInfos[Index], + MemLatBwRelations, + MemLatBwRelationsCount, + ProximityDomainInfoCount, + (EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO *)((UINT8 *)Hmat + MemLatBwOffset), + &LatBwEntrySize + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to add Lat/Bw info: %r\n", __func__, Status)); + goto error_handler; + } + + MemLatBwOffset += LatBwEntrySize; + } + + // Update header with the actual length of the generated table + // and re-allocate it to an actual size + Hmat->Header.Length = (UINT32)MemLatBwOffset; + FinalTable = AllocateCopyPool (Hmat->Header.Length, *Table); + if (FinalTable == NULL) { + Status = EFI_OUT_OF_RESOURCES; + DEBUG (( + DEBUG_ERROR, + "ERROR: HMAT: Failed to allocate memory for HMAT Table, Size = %d," \ + " Status = %r\n", + Hmat->Header.Length, + Status + )); + goto error_handler; + } + + FreePool (*Table); + *Table = FinalTable; + + return Status; + +error_handler: + if (*Table != NULL) { + FreePool (*Table); + *Table = NULL; + } + + return Status; +} + +/** This macro defines the HMAT Table Generator revision. +*/ +#define HMAT_GENERATOR_REVISION CREATE_REVISION (1, 0) + +/** The interface for the HMAT Table Generator. +*/ +STATIC +CONST +ACPI_TABLE_GENERATOR HmatGenerator = { + // Generator ID + CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdHmat), + // Generator Description + L"ACPI.STD.HMAT.GENERATOR", + // ACPI Table Signature + EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_SIGNATURE, + // ACPI Table Revision supported by this Generator + EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_REVISION, + // Minimum supported ACPI Table Revision + EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_REVISION, + // Creator ID + TABLE_GENERATOR_CREATOR_ID_ARM, + // Creator Revision + HMAT_GENERATOR_REVISION, + // Build table function. Use the extended version instead. + BuildHmatTable, + // Free table function. Use the extended version instead. + FreeHmatTable, + // Extended Build table function. + NULL, + // Extended free function. + NULL +}; + +/** Register the Generator with the ACPI Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +AcpiHmatLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterAcpiTableGenerator (&HmatGenerator); + DEBUG ((DEBUG_INFO, "HMAT: Register Generator. Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** Deregister the Generator from the ACPI Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +AcpiHmatLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterAcpiTableGenerator (&HmatGenerator); + DEBUG ((DEBUG_INFO, "HMAT: Deregister Generator. Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + return Status; +} From 7779b1a0424aa96877b600f227c55039b2a4e10d Mon Sep 17 00:00:00 2001 From: Oleksandr Tymoshenko Date: Mon, 18 May 2026 23:23:07 +0000 Subject: [PATCH 144/406] DynamicTablesPkg: Add HMAT generator tests - Add unit tests for HMAT generator. Co-authored-by: Ryan Heise Signed-off-by: Oleksandr Tymoshenko --- .../GoogleTest/CedtGeneratorGoogleTest.cpp | 11 - .../GoogleTest/HmatGeneratorGoogleTest.cpp | 719 ++++++++++++++++++ .../GoogleTest/HmatGeneratorGoogleTest.inf | 35 + .../Test/DynamicTablesPkgHostTest.dsc | 11 + .../MockConfigurationManagerProtocol.h | 11 + 5 files changed, 776 insertions(+), 11 deletions(-) create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/GoogleTest/HmatGeneratorGoogleTest.cpp create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/GoogleTest/HmatGeneratorGoogleTest.inf diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiCedtLib/GoogleTest/CedtGeneratorGoogleTest.cpp b/DynamicTablesPkg/Library/Acpi/Common/AcpiCedtLib/GoogleTest/CedtGeneratorGoogleTest.cpp index 2754722d56..e4c54b8ba2 100644 --- a/DynamicTablesPkg/Library/Acpi/Common/AcpiCedtLib/GoogleTest/CedtGeneratorGoogleTest.cpp +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiCedtLib/GoogleTest/CedtGeneratorGoogleTest.cpp @@ -78,17 +78,6 @@ using ::testing::DoAll; using ::testing::SetArgPointee; using ::testing::AtLeast; -#define WRAP_ACCESSOR(accessor) \ - [this] \ - (IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *This, \ - IN CONST CM_OBJECT_ID CmObjectId, \ - IN CONST CM_OBJECT_TOKEN Token, \ - IN OUT CM_OBJ_DESCRIPTOR *CmObject \ - ) \ - { \ - return this->accessor(This, CmObjectId, Token, CmObject); \ - } - class CedtGeneratorTest : public ::testing::Test { protected: MockConfigurationManagerProtocol MockConfigMgrProtocol; diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/GoogleTest/HmatGeneratorGoogleTest.cpp b/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/GoogleTest/HmatGeneratorGoogleTest.cpp new file mode 100644 index 0000000000..126820c4a4 --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/GoogleTest/HmatGeneratorGoogleTest.cpp @@ -0,0 +1,719 @@ +/** @file + Unit tests for HMAT Generator + + Copyright (c) 2026, Google LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "Base.h" +#include +#include +#include + +extern "C" { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include "GoogleTest/Protocol/MockConfigurationManagerProtocol.h" + #include "Library/Common/MetadataHandlerLib/MetadataHandler.h" + + EFI_STATUS + EFIAPI + AcpiHmatLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + + EFI_STATUS + EFIAPI + AcpiHmatLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + + // Global generator instance + static ACPI_TABLE_GENERATOR *gHmatGenerator = NULL; + + static METADATA_ROOT_HANDLE mMetadataRoot; + + // C++ wrapper functions for C linkage functions + EFI_STATUS + RegisterAcpiTableGenerator ( + IN CONST ACPI_TABLE_GENERATOR *CONST TableGenerator + ) + { + if (TableGenerator == NULL) { + return EFI_INVALID_PARAMETER; + } + + gHmatGenerator = const_cast(TableGenerator); + return EFI_SUCCESS; + } + + EFI_STATUS + DeregisterAcpiTableGenerator ( + IN CONST ACPI_TABLE_GENERATOR *CONST TableGenerator + ) + { + if (TableGenerator == NULL) { + return EFI_INVALID_PARAMETER; + } + + // Clear the stored generator + gHmatGenerator = NULL; + return EFI_SUCCESS; + } + + METADATA_ROOT_HANDLE + EFIAPI + GetMetadataRoot ( + VOID + ) + { + return mMetadataRoot; + } +} + +using namespace testing; +using ::testing::_; +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::DoAll; +using ::testing::SetArgPointee; +using ::testing::AtLeast; + +class HmatGeneratorTest : public ::testing::Test { +protected: + MockConfigurationManagerProtocol MockConfigMgrProtocol; + CM_STD_OBJ_CONFIGURATION_MANAGER_INFO CfgMgrInfo = { 0 }; + + void + ValidateMemProximityDomainAttrInfo ( + const EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES *Expected, + const EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES *Actual + ) + { + EXPECT_EQ (Actual->Type, Expected->Type); + EXPECT_EQ (Actual->Length, sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES)); + EXPECT_EQ (Actual->Flags.InitiatorProximityDomainValid, Expected->Flags.InitiatorProximityDomainValid); + EXPECT_EQ (Actual->InitiatorProximityDomain, Expected->InitiatorProximityDomain); + EXPECT_EQ (Actual->MemoryProximityDomain, Expected->MemoryProximityDomain); + } + + void + ValidateSSLBI ( + const EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO *ExpectedBase, + const UINT32 *ExpectedInitiatorDomains, + const UINT32 *ExpectedTargetDomains, + const UINT16 *ExpectedLatencyMatrix, + const EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO *Actual + ) + { + EXPECT_EQ (Actual->Type, ExpectedBase->Type); + EXPECT_EQ (Actual->Length, ExpectedBase->Length); + EXPECT_EQ (Actual->Flags.AccessAttributes, ExpectedBase->Flags.AccessAttributes); + EXPECT_EQ (Actual->Flags.MemoryHierarchy, ExpectedBase->Flags.MemoryHierarchy); + EXPECT_EQ (Actual->DataType, ExpectedBase->DataType); + EXPECT_EQ (Actual->NumberOfInitiatorProximityDomains, ExpectedBase->NumberOfInitiatorProximityDomains); + EXPECT_EQ (Actual->NumberOfTargetProximityDomains, ExpectedBase->NumberOfTargetProximityDomains); + EXPECT_EQ (Actual->EntryBaseUnit, ExpectedBase->EntryBaseUnit); + + UINT8 *Ptr = (UINT8 *)Actual; + UINT32 *ActualInitiatorDomains = (UINT32 *)(Ptr + sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO)); + + for (UINT32 i = 0; i < ExpectedBase->NumberOfInitiatorProximityDomains; i++) { + EXPECT_EQ (ActualInitiatorDomains[i], ExpectedInitiatorDomains[i]); + } + + UINT32 *ActualTargetDomains = (UINT32 *)(ActualInitiatorDomains + ExpectedBase->NumberOfInitiatorProximityDomains); + + for (UINT32 i = 0; i < ExpectedBase->NumberOfTargetProximityDomains; i++) { + EXPECT_EQ (ActualTargetDomains[i], ExpectedTargetDomains[i]); + } + + UINT16 *ActualLatencyMatrix = (UINT16 *)(ActualTargetDomains + ExpectedBase->NumberOfTargetProximityDomains); + + for (UINT32 i = 0; i < ExpectedBase->NumberOfInitiatorProximityDomains * ExpectedBase->NumberOfTargetProximityDomains; i++) { + EXPECT_EQ (ActualLatencyMatrix[i], ExpectedLatencyMatrix[i]); + } + } + + void + SetUp ( + ) override + { + // Set up default behavior for GetObject + ON_CALL (MockConfigMgrProtocol, GetObject (_, _, _, _)) + .WillByDefault (Return (EFI_NOT_FOUND)); + + // Set up configuration manager info + CfgMgrInfo.Revision = CREATE_REVISION (1, 0); + CfgMgrInfo.OemId[0] = 'T'; + CfgMgrInfo.OemId[1] = 'E'; + CfgMgrInfo.OemId[2] = 'S'; + CfgMgrInfo.OemId[3] = 'T'; + CfgMgrInfo.OemId[4] = 'M'; + CfgMgrInfo.OemId[5] = 'E'; + + EXPECT_CALL (MockConfigMgrProtocol, GetObject (_, CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo), CM_NULL_TOKEN, _)) + .WillRepeatedly ( + DoAll ( + SetArgPointee<3>( + CM_OBJ_DESCRIPTOR { + CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo), + sizeof (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO), + &CfgMgrInfo, + 1 + } + ), + Return (EFI_SUCCESS) + ) + ); + + EXPECT_CALL ( + MockConfigMgrProtocol, + GetObject ( + _, + CREATE_CM_ARCH_COMMON_OBJECT_ID (EArchCommonObjProximityDomainInfo), + _, + _ + ) + ) + .WillRepeatedly ( + Invoke (WRAP_ACCESSOR (GetProximityDomainInfo)) + ); + + EXPECT_CALL ( + MockConfigMgrProtocol, + GetObject ( + _, + CREATE_CM_ARCH_COMMON_OBJECT_ID (EArchCommonObjMemoryProximityDomainAttrInfo), + CM_NULL_TOKEN, + _ + ) + ) + .WillRepeatedly ( + Invoke (WRAP_ACCESSOR (GetMemProximityDomainAttrInfo)) + ); + + EXPECT_CALL ( + MockConfigMgrProtocol, + GetObject ( + _, + CREATE_CM_ARCH_COMMON_OBJECT_ID (EArchCommonObjMemoryLatBwInfo), + CM_NULL_TOKEN, + _ + ) + ) + .WillRepeatedly ( + Invoke (WRAP_ACCESSOR (GetMemLatBwInfo)) + ); + + EXPECT_CALL ( + MockConfigMgrProtocol, + GetObject ( + _, + CREATE_CM_ARCH_COMMON_OBJECT_ID (EArchCommonObjProximityDomainRelationInfo), + _, + _ + ) + ) + .WillRepeatedly ( + Invoke (WRAP_ACCESSOR (GetProximityDomainRelationInfo)) + ); + + // Initialize the HMAT library with our mock protocol + EXPECT_EQ (AcpiHmatLibConstructor (NULL, NULL), EFI_SUCCESS); + + // Setup common test data with proper initialization + mAcpiTableInfo.TableGeneratorId = CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdHmat); + mAcpiTableInfo.AcpiTableSignature = EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_SIGNATURE; + mAcpiTableInfo.AcpiTableRevision = EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_REVISION; + + MetadataInitializeHandle (&mMetadataRoot); + } + + void + TearDown ( + ) override + { + if (mTableUnderTest != nullptr) { + gHmatGenerator->FreeTableResources ( + gHmatGenerator, + &mAcpiTableInfo, + gConfigurationManagerProtocol, + &mTableUnderTest + ); + } + + // Clean up the HMAT library + AcpiHmatLibDestructor (NULL, NULL); + MetadataFreeHandle (mMetadataRoot); + } + + void + SetupProximityDomainInfo ( + UINT64 ProximityDomainInfoCount + ) + { + mProximityDomainInfo.resize (ProximityDomainInfoCount); + for (UINT64 i = 0; i < ProximityDomainInfoCount; i++) { + mProximityDomainInfo[i].GenerateDomainId = FALSE; + mProximityDomainInfo[i].DomainId = 100 + (UINT32)i; + } + } + + void + SetupMemProximityDomainAttrInfo ( + CM_ARCH_COMMON_MEMORY_PROXIMITY_DOMAIN_ATTR_INFO *MemProximityDomainAttrInfo, + UINT64 MemProximityDomainAttrInfoCount + ) + { + mMemProximityDomainAttrInfo.resize (MemProximityDomainAttrInfoCount); + for (UINT64 i = 0; i < MemProximityDomainAttrInfoCount; i++) { + mMemProximityDomainAttrInfo[i] = MemProximityDomainAttrInfo[i]; + } + } + + void + SetupMemLatBwInfo ( + CM_ARCH_COMMON_MEMORY_LAT_BW_INFO *MemLatBwInfo, + UINT64 MemLatBwInfoCount + ) + { + mMemLatBwInfo.resize (MemLatBwInfoCount); + for (UINT64 i = 0; i < MemLatBwInfoCount; i++) { + mMemLatBwInfo[i] = MemLatBwInfo[i]; + } + } + + void + SetupProximityDomainRelationInfo ( + CM_OBJECT_TOKEN Token, + CM_ARCH_COMMON_PROXIMITY_DOMAIN_RELATION_INFO *Matrix, + UINT64 MatrixCount + ) + { + mProximityDomainRelationInfo[Token].resize (MatrixCount); + for (UINT64 i = 0; i < MatrixCount; i++) { + mProximityDomainRelationInfo[Token][i] = Matrix[i]; + } + } + + EFI_STATUS + GetProximityDomainInfo ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *This, + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token, + IN OUT CM_OBJ_DESCRIPTOR *CmObject + ) + { + UINT32 Index; + + if (CmObject == nullptr) { + return EFI_INVALID_PARAMETER; + } + + if (Token == CM_NULL_TOKEN) { + *CmObject = CM_OBJ_DESCRIPTOR { + CREATE_CM_ARCH_COMMON_OBJECT_ID (EArchCommonObjProximityDomainInfo), + static_cast(sizeof (CM_ARCH_COMMON_PROXIMITY_DOMAIN_INFO) * mProximityDomainInfo.size ()), + mProximityDomainInfo.data (), + static_cast(mProximityDomainInfo.size ()) + }; + + return EFI_SUCCESS; + } + + Index = (UINT32)Token - 1; + if (Index >= mProximityDomainInfo.size ()) { + return EFI_NOT_FOUND; + } + + *CmObject = CM_OBJ_DESCRIPTOR { + CREATE_CM_ARCH_COMMON_OBJECT_ID (EArchCommonObjProximityDomainInfo), + static_cast(sizeof (CM_ARCH_COMMON_PROXIMITY_DOMAIN_INFO)), + &mProximityDomainInfo[Index], + 1 + }; + + return EFI_SUCCESS; + } + + EFI_STATUS + GetMemProximityDomainAttrInfo ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *This, + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token, + IN OUT CM_OBJ_DESCRIPTOR *CmObject + ) + { + if (CmObject == nullptr) { + return EFI_INVALID_PARAMETER; + } + + *CmObject = CM_OBJ_DESCRIPTOR { + CREATE_CM_ARCH_COMMON_OBJECT_ID (EArchCommonObjMemoryProximityDomainAttrInfo), + static_cast(sizeof (CM_ARCH_COMMON_MEMORY_PROXIMITY_DOMAIN_ATTR_INFO) * mMemProximityDomainAttrInfo.size ()), + mMemProximityDomainAttrInfo.data (), + static_cast(mMemProximityDomainAttrInfo.size ()) + }; + + return EFI_SUCCESS; + } + + EFI_STATUS + GetMemLatBwInfo ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *This, + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token, + IN OUT CM_OBJ_DESCRIPTOR *CmObject + ) + { + if (CmObject == nullptr) { + return EFI_INVALID_PARAMETER; + } + + *CmObject = CM_OBJ_DESCRIPTOR { + CREATE_CM_ARCH_COMMON_OBJECT_ID (EArchCommonObjMemoryLatBwInfo), + static_cast(sizeof (CM_ARCH_COMMON_MEMORY_LAT_BW_INFO) * mMemLatBwInfo.size ()), + mMemLatBwInfo.data (), + static_cast(mMemLatBwInfo.size ()) + }; + + return EFI_SUCCESS; + } + + EFI_STATUS + GetProximityDomainRelationInfo ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *This, + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token, + IN OUT CM_OBJ_DESCRIPTOR *CmObject + ) + { + if (CmObject == nullptr) { + return EFI_INVALID_PARAMETER; + } + + auto it = mProximityDomainRelationInfo.find (Token); + + if (it == mProximityDomainRelationInfo.end ()) { + return EFI_NOT_FOUND; + } + + *CmObject = CM_OBJ_DESCRIPTOR { + CREATE_CM_ARCH_COMMON_OBJECT_ID (EArchCommonObjProximityDomainRelationInfo), + static_cast(sizeof (CM_ARCH_COMMON_PROXIMITY_DOMAIN_RELATION_INFO) * it->second.size ()), + it->second.data (), + static_cast(it->second.size ()) + }; + + return EFI_SUCCESS; + } + + CM_STD_OBJ_ACPI_TABLE_INFO mAcpiTableInfo; + std::vector mProximityDomainInfo; + std::vector mMemProximityDomainAttrInfo; + std::vector mMemLatBwInfo; + std::map > mProximityDomainRelationInfo; + EFI_ACPI_DESCRIPTION_HEADER *mTableUnderTest = nullptr; + + CM_ARCH_COMMON_PROXIMITY_DOMAIN_INFO mDefaultProximityDomains[10]; + + CM_ARCH_COMMON_MEMORY_PROXIMITY_DOMAIN_ATTR_INFO mDefaultMemProximity[2] = { + { + .Flags = 0, + .InitiatorProximityDomain = 1, + .MemoryProximityDomain = 2 + }, + { + .Flags = 1, + .InitiatorProximityDomain = 3, + .MemoryProximityDomain = 4 + } + }; + + CM_ARCH_COMMON_MEMORY_LAT_BW_INFO mDefaultMemLatBw[2] = { + { + .Flags = 1, + .DataType = 3, + .MinTransferSize = 24, + .EntryBaseUnit = 2, + .RelativeDistanceArray = 1 + }, + { + .Flags = 1, + .DataType = 3, + .MinTransferSize = 24, + .EntryBaseUnit = 2, + .RelativeDistanceArray = 2 + } + }; + + CM_ARCH_COMMON_PROXIMITY_DOMAIN_RELATION_INFO mDefaultMatrix1[4] = { + { .FirstDomainToken = 1, .SecondDomainToken = 2, .Relation = 100 }, + { .FirstDomainToken = 1, .SecondDomainToken = 4, .Relation = 200 }, + { .FirstDomainToken = 3, .SecondDomainToken = 2, .Relation = 300 }, + { .FirstDomainToken = 3, .SecondDomainToken = 4, .Relation = 400 } + }; + + CM_ARCH_COMMON_PROXIMITY_DOMAIN_RELATION_INFO mDefaultMatrix2[2] = { + { .FirstDomainToken = 1, .SecondDomainToken = 5, .Relation = 1000 }, + { .FirstDomainToken = 1, .SecondDomainToken = 6, .Relation = 2000 }, + }; + + // Invalid relation value, should be in UINT16 range + CM_ARCH_COMMON_PROXIMITY_DOMAIN_RELATION_INFO mInvalidRelMatrix[2] = { + { .FirstDomainToken = 1, .SecondDomainToken = 2, .Relation = 301000 }, + { .FirstDomainToken = 1, .SecondDomainToken = 2, .Relation = 302000 }, + }; +}; + +STATIC +constexpr UINT32 +GetSLLBISize ( + UINT32 InitiatorCount, + UINT32 TargetCount + ) +{ + return sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO) + + InitiatorCount * sizeof (UINT32) + + TargetCount * sizeof (UINT32) + + InitiatorCount * TargetCount * sizeof (UINT16); +} + +constexpr EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES kExpectedMpda[2] = { + { + .Type = 0, + .Length = 40, + .Flags = { + .InitiatorProximityDomainValid = 0 + }, + .InitiatorProximityDomain = 100, + .MemoryProximityDomain = 101, + }, + { + .Type = 0, + .Length = 40, + .Flags = { + .InitiatorProximityDomainValid = 1 + }, + .InitiatorProximityDomain = 102, + .MemoryProximityDomain = 103 + } +}; + +constexpr EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO kExpectedSllbiBase[2] = { + { + .Type = 1, + .Length = GetSLLBISize (2, 2), + .Flags = { + .MemoryHierarchy = 1 + }, + .DataType = 3, + .MinTransferSize = 24, + .NumberOfInitiatorProximityDomains = 2, + .NumberOfTargetProximityDomains = 2, + .EntryBaseUnit = 2 + }, + { + .Type = 1, + .Length = GetSLLBISize (1, 2), + .Flags = { + .MemoryHierarchy = 1 + }, + .DataType = 3, + .MinTransferSize = 24, + .NumberOfInitiatorProximityDomains = 1, + .NumberOfTargetProximityDomains = 2, + .EntryBaseUnit = 2 + } +}; + +constexpr UINT32 kExpectedSllbiInitiators0[2] = { + 100, 102 +}; + +constexpr UINT32 kExpectedSllbiInitiators1[1] = { + 100 +}; + +constexpr UINT32 kExpectedSllbiTargets0[2] = { + 101, 103 +}; + +constexpr UINT32 kExpectedSllbiTargets1[2] = { + 104, 105 +}; + +constexpr UINT16 kExpectedSllbiMatrix0[4] = { 100, 200, 300, 400 +}; + +constexpr UINT16 kExpectedSllbiMatrix1[2] = { 1000, 2000 +}; + +TEST_F (HmatGeneratorTest, NoProximityDomainsTest) { + SetupProximityDomainInfo (4); + SetupMemLatBwInfo (mDefaultMemLatBw, 1); + SetupProximityDomainRelationInfo ((CM_OBJECT_TOKEN)1, mDefaultMatrix1, 4); + EXPECT_EQ ( + gHmatGenerator->BuildAcpiTable ( + gHmatGenerator, + &mAcpiTableInfo, + gConfigurationManagerProtocol, + &mTableUnderTest + ), + EFI_SUCCESS + ); + UINT32 expectedSize = sizeof (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER) + + GetSLLBISize (2, 2); + + EXPECT_EQ (mTableUnderTest->Length, expectedSize); + + UINT8 *mTableUnderTestPtr = (UINT8 *)mTableUnderTest; + + ValidateSSLBI ( + &kExpectedSllbiBase[0], + kExpectedSllbiInitiators0, + kExpectedSllbiTargets0, + kExpectedSllbiMatrix0, + (EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO *)&mTableUnderTestPtr[40] + ); +} + +TEST_F (HmatGeneratorTest, NoLatencyInfoTest) { + SetupProximityDomainInfo (4); + SetupMemProximityDomainAttrInfo (mDefaultMemProximity, 2); + EXPECT_EQ ( + gHmatGenerator->BuildAcpiTable ( + gHmatGenerator, + &mAcpiTableInfo, + gConfigurationManagerProtocol, + &mTableUnderTest + ), + EFI_SUCCESS + ); + UINT32 expectedSize = sizeof (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER) + + 2 * sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES); + + EXPECT_EQ (mTableUnderTest->Length, expectedSize); + UINT8 *tableUnderTestPtr = (UINT8 *)mTableUnderTest; + + UINT32 Idx = sizeof (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER); + + ValidateMemProximityDomainAttrInfo (&kExpectedMpda[0], (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES *)&tableUnderTestPtr[Idx]); + + Idx = sizeof (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER) + + sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES); + ValidateMemProximityDomainAttrInfo (&kExpectedMpda[1], (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES *)&tableUnderTestPtr[Idx]); +} + +TEST_F (HmatGeneratorTest, MismatchedMatrixSizeTest) { + SetupProximityDomainInfo (4); + SetupMemProximityDomainAttrInfo (mDefaultMemProximity, 2); + SetupMemLatBwInfo (mDefaultMemLatBw, 1); + SetupProximityDomainRelationInfo ((CM_OBJECT_TOKEN)1, &mDefaultMatrix1[0], 3); // Should be 4 + EXPECT_EQ ( + gHmatGenerator->BuildAcpiTable ( + gHmatGenerator, + &mAcpiTableInfo, + gConfigurationManagerProtocol, + &mTableUnderTest + ), + EFI_INVALID_PARAMETER + ); +} + +TEST_F (HmatGeneratorTest, InvalidRelationValueTest) { + SetupProximityDomainInfo (4); + SetupMemProximityDomainAttrInfo (mDefaultMemProximity, 2); + SetupMemLatBwInfo (mDefaultMemLatBw, 1); + SetupProximityDomainRelationInfo ((CM_OBJECT_TOKEN)1, &mInvalidRelMatrix[0], 2); + EXPECT_EQ ( + gHmatGenerator->BuildAcpiTable ( + gHmatGenerator, + &mAcpiTableInfo, + gConfigurationManagerProtocol, + &mTableUnderTest + ), + EFI_INVALID_PARAMETER + ); +} + +TEST_F (HmatGeneratorTest, ValidTableTest) { + SetupProximityDomainInfo (7); + SetupMemProximityDomainAttrInfo (mDefaultMemProximity, 2); + SetupMemLatBwInfo (mDefaultMemLatBw, 2); + SetupProximityDomainRelationInfo ((CM_OBJECT_TOKEN)1, mDefaultMatrix1, 4); + SetupProximityDomainRelationInfo ((CM_OBJECT_TOKEN)2, mDefaultMatrix2, 2); + + EXPECT_EQ ( + gHmatGenerator->BuildAcpiTable ( + gHmatGenerator, + &mAcpiTableInfo, + gConfigurationManagerProtocol, + &mTableUnderTest + ), + EFI_SUCCESS + ); + + EXPECT_NE (mTableUnderTest, nullptr); + UINT32 expectedSize = sizeof (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER) + + 2 * sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES) + + GetSLLBISize (2, 2) + + GetSLLBISize (2, 1); + + EXPECT_EQ (mTableUnderTest->Length, expectedSize); + UINT8 *tableUnderTestPtr = (UINT8 *)mTableUnderTest; + + UINT32 Idx = sizeof (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER); + + ValidateMemProximityDomainAttrInfo (&kExpectedMpda[0], (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES *)&tableUnderTestPtr[Idx]); + + Idx = sizeof (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER) + + sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES); + ValidateMemProximityDomainAttrInfo (&kExpectedMpda[1], (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES *)&tableUnderTestPtr[Idx]); + + Idx = sizeof (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER) + + 2 * sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES); + ValidateSSLBI ( + &kExpectedSllbiBase[0], + kExpectedSllbiInitiators0, + kExpectedSllbiTargets0, + kExpectedSllbiMatrix0, + (EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO *)&tableUnderTestPtr[Idx] + ); + + Idx = sizeof (EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_HEADER) + + 2 * sizeof (EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES) + + GetSLLBISize (2, 2); + ValidateSSLBI ( + &kExpectedSllbiBase[1], + kExpectedSllbiInitiators1, + kExpectedSllbiTargets1, + kExpectedSllbiMatrix1, + (EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO *)&tableUnderTestPtr[Idx] + ); +} + +int +main ( + int argc, + char *argv[] + ) +{ + testing::InitGoogleTest (&argc, argv); + return RUN_ALL_TESTS (); +} diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/GoogleTest/HmatGeneratorGoogleTest.inf b/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/GoogleTest/HmatGeneratorGoogleTest.inf new file mode 100644 index 0000000000..9d117d370c --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/GoogleTest/HmatGeneratorGoogleTest.inf @@ -0,0 +1,35 @@ +## @file +# Google Test application for HMAT Generator. +# +# Copyright (c) 2026, Google LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 1.29 + BASE_NAME = HmatGeneratorGoogleTest + FILE_GUID = c78fdb8e-9d00-48fd-b06b-daafc7e947cf + MODULE_TYPE = HOST_APPLICATION + VERSION_STRING = 1.0 + +[Sources] + HmatGeneratorGoogleTest.cpp + ../../../../../Test/Mock/Library/GoogleTest/Protocol/MockConfigurationManagerProtocol.cpp + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + GoogleTestLib + TableHelperLib + CmObjHelperLib + +[Protocols] + gEdkiiConfigurationManagerProtocolGuid ## CONSUMES + +[BuildOptions] + MSFT:*_*_*_CC_FLAGS = /EHsc diff --git a/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc b/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc index 33adde938b..c27cca1ec9 100644 --- a/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc +++ b/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc @@ -25,10 +25,17 @@ AcpiHelperLib|DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelperLib.inf AcpiLib|EmbeddedPkg/Library/AcpiLib/AcpiLib.inf AmlLib|DynamicTablesPkg/Library/Common/AmlLib/AmlLib.inf + CmObjHelperLib|DynamicTablesPkg/Library/Common/CmObjHelperLib/CmObjHelperLib.inf + MetadataHandlerLib|DynamicTablesPkg/Library/Common/MetadataHandlerLib/MetadataHandlerLib.inf + MetadataObjLib|DynamicTablesPkg/Library/Common/MetadataObjLib/MetadataObjLib.inf SsdtSerialPortFixupLib|DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.inf TableHelperLib|DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf [Components] + DynamicTablesPkg/Library/Common/CmObjHelperLib/CmObjHelperLib.inf + DynamicTablesPkg/Library/Common/MetadataHandlerLib/MetadataHandlerLib.inf + DynamicTablesPkg/Library/Common/MetadataObjLib/MetadataObjLib.inf + DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/GoogleTest/Dbg2GeneratorGoogleTest.inf { NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2Lib.inf @@ -37,3 +44,7 @@ NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiCedtLib/AcpiCedtLib.inf } + DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/GoogleTest/HmatGeneratorGoogleTest.inf { + + NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiHmatLib/AcpiHmatLib.inf + } diff --git a/DynamicTablesPkg/Test/Mock/Include/GoogleTest/Protocol/MockConfigurationManagerProtocol.h b/DynamicTablesPkg/Test/Mock/Include/GoogleTest/Protocol/MockConfigurationManagerProtocol.h index 15db832b7c..5c5e07e99c 100644 --- a/DynamicTablesPkg/Test/Mock/Include/GoogleTest/Protocol/MockConfigurationManagerProtocol.h +++ b/DynamicTablesPkg/Test/Mock/Include/GoogleTest/Protocol/MockConfigurationManagerProtocol.h @@ -15,6 +15,17 @@ extern "C" { #include } +#define WRAP_ACCESSOR(accessor) \ + [this] \ + (IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *This, \ + IN CONST CM_OBJECT_ID CmObjectId, \ + IN CONST CM_OBJECT_TOKEN Token, \ + IN OUT CM_OBJ_DESCRIPTOR *CmObject \ + ) \ + { \ + return this->accessor(This, CmObjectId, Token, CmObject); \ + } + struct MockConfigurationManagerProtocol { MOCK_INTERFACE_DECLARATION (MockConfigurationManagerProtocol); From 8756401a027fe81e31ca81dd2d9a77e7557ef219 Mon Sep 17 00:00:00 2001 From: Chao Li Date: Mon, 29 Jun 2026 09:42:23 +0800 Subject: [PATCH 145/406] MdePkg: Add LoongArch64 support for StackCheckLib Added LoongArch64 stack cookie interrupt instance, calling `CpuBreakpoint` to stop the CPU. Signed-off-by: Chao Li Cc: Michael D Kinney Cc: Liming Gao --- .../LoongArch64/StackCookieInterrupt.S | 21 +++++++++++++++++++ .../Library/StackCheckLib/StackCheckLib.inf | 3 +++ 2 files changed, 24 insertions(+) create mode 100644 MdePkg/Library/StackCheckLib/LoongArch64/StackCookieInterrupt.S diff --git a/MdePkg/Library/StackCheckLib/LoongArch64/StackCookieInterrupt.S b/MdePkg/Library/StackCheckLib/LoongArch64/StackCookieInterrupt.S new file mode 100644 index 0000000000..9fe9961e00 --- /dev/null +++ b/MdePkg/Library/StackCheckLib/LoongArch64/StackCookieInterrupt.S @@ -0,0 +1,21 @@ +#------------------------------------------------------------------------------ +# +# LoongArch64/StackCookieInterrupt.S +# +# Copyright (c) 2026, Loongson Technology Corporation Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#------------------------------------------------------------------------------ + +#include +ASM_GLOBAL ASM_PFX(TriggerStackCookieInterrupt) + +#/** +# Calling `CpuBreakpoint` to create a breakpoint to the LoongArch64 exception handle and stop. +#**/ + +ASM_PFX(TriggerStackCookieInterrupt): + bl CpuBreakpoint + jirl $zero, $ra, 0 +.end diff --git a/MdePkg/Library/StackCheckLib/StackCheckLib.inf b/MdePkg/Library/StackCheckLib/StackCheckLib.inf index 8ecb9b638e..d0866099ed 100644 --- a/MdePkg/Library/StackCheckLib/StackCheckLib.inf +++ b/MdePkg/Library/StackCheckLib/StackCheckLib.inf @@ -30,6 +30,9 @@ AArch64/StackCookieInterrupt.S |GCC AArch64/StackCookieInterrupt.asm |MSFT +[Sources.LOONGARCH64] + LoongArch64/StackCookieInterrupt.S | GCC + [Packages] MdePkg/MdePkg.dec From 42fde88a42e66517c6b020a8d1ac6a25951d1193 Mon Sep 17 00:00:00 2001 From: Chao Li Date: Mon, 6 Jul 2026 11:09:10 +0800 Subject: [PATCH 146/406] MdePkg/DynamicStackCookieEntryPointLib: Add LoongArch64 support Added LoongArch64 support. Currently, LoongArch64 doesn't supports TRNG, it uses the `RDTIME` instruction and a xorshif64 alorithms to compose a PRNG(RngLib). It may supports the SE TRNG in the future, and will change to the TRNG when SE support becomes available. Signed-off-by: Chao Li Cc: Michael D Kinney Cc: Liming Gao --- .../DxeCoreEntryPoint.inf | 8 ++- .../LoongArch64/DynamicCookieGcc.S | 71 +++++++++++++++++++ .../StandaloneMmDriverEntryPoint.inf | 8 ++- .../UefiApplicationEntryPoint.inf | 8 ++- .../UefiDriverEntryPoint.inf | 8 ++- 5 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 MdePkg/Library/DynamicStackCookieEntryPointLib/LoongArch64/DynamicCookieGcc.S diff --git a/MdePkg/Library/DynamicStackCookieEntryPointLib/DxeCoreEntryPoint.inf b/MdePkg/Library/DynamicStackCookieEntryPointLib/DxeCoreEntryPoint.inf index ea84987678..71974004e0 100644 --- a/MdePkg/Library/DynamicStackCookieEntryPointLib/DxeCoreEntryPoint.inf +++ b/MdePkg/Library/DynamicStackCookieEntryPointLib/DxeCoreEntryPoint.inf @@ -19,7 +19,7 @@ # -# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 LOONGARCH64 # [Sources] @@ -36,6 +36,9 @@ [Sources.AARCH64] AArch64/DynamicCookieGcc.S | GCC +[Sources.LOONGARCH64] + LoongArch64/DynamicCookieGcc.S | GCC + [Packages] MdePkg/MdePkg.dec @@ -43,3 +46,6 @@ BaseLib DebugLib StackCheckLib + +[LibraryClasses.LOONGARCH64] + RngLib diff --git a/MdePkg/Library/DynamicStackCookieEntryPointLib/LoongArch64/DynamicCookieGcc.S b/MdePkg/Library/DynamicStackCookieEntryPointLib/LoongArch64/DynamicCookieGcc.S new file mode 100644 index 0000000000..1bf04ca952 --- /dev/null +++ b/MdePkg/Library/DynamicStackCookieEntryPointLib/LoongArch64/DynamicCookieGcc.S @@ -0,0 +1,71 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) Microsoft Corporation. +# Copyright (c) 2026, Loongson Technology Corporation Limited. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# Module Name: +# +# DynamicCookieGcc.S +# +# Abstract: +# +# Generates random number through the RdTime instruction on a 64-bit LOONGARCH64 platform +# to store a random value in the GCC __stack_check_guard stack cookie. +# The first byte is 0'd to prevent string copy functions from clobbering +# the stack cookie. +# +# Notes: +# +# Use the RngLib library to get random numbers. LoongArch64 currently does not support like +# `RdRand` or `RNDR` instructions, it can use the `RdTime` and a xorshift64 algorithms to +# generate pseudo-random numbers. +# +#------------------------------------------------------------------------------ + +#include + +ASM_GLOBAL ASM_PFX (_ModuleEntryPoint) + +#------------------------------------------------------------------------------ +# VOID +# EFIAPI +# _ModuleEntryPoint ( +# The parameters are saved to the stack when it calls other functions. +# ) +#------------------------------------------------------------------------------ +ASM_PFX(_ModuleEntryPoint): + addi.d $sp, $sp, -0x20 + st.d $a0, $sp, 0x0 + st.d $a1, $sp, 0x8 + st.d $ra, $sp, 0x10 + + // + // Use the stack to pass parameters. + // + addi.d $a0, $sp, 0x18 + bl GetRandomNumber64 + + // + // Load the random number from the stack. + // + ld.d $t0, $sp, 0x18 + + // + // Zero the first byte of the random value + // + bstrins.d $t0, $zero, 7, 0 + + la.local $t1, __stack_chk_guard + st.d $t0, $t1, 0 + dbar 0 + + ld.d $a0, $sp, 0x0 + ld.d $a1, $sp, 0x8 + ld.d $ra, $sp, 0x10 + addi.d $sp, $sp, 0x20 + +c_entry: + b _CModuleEntryPoint // Jump to the C module entry point + +.end diff --git a/MdePkg/Library/DynamicStackCookieEntryPointLib/StandaloneMmDriverEntryPoint.inf b/MdePkg/Library/DynamicStackCookieEntryPointLib/StandaloneMmDriverEntryPoint.inf index 1d43ce9345..75c22eb5bd 100644 --- a/MdePkg/Library/DynamicStackCookieEntryPointLib/StandaloneMmDriverEntryPoint.inf +++ b/MdePkg/Library/DynamicStackCookieEntryPointLib/StandaloneMmDriverEntryPoint.inf @@ -23,7 +23,7 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = X64 AARCH64 +# VALID_ARCHITECTURES = X64 AARCH64 LOONGARCH64 # [Sources] @@ -40,6 +40,9 @@ [Sources.AARCH64] AArch64/DynamicCookieGcc.S | GCC +[Sources.LOONGARCH64] + LoongArch64/DynamicCookieGcc.S | GCC + [Packages] MdePkg/MdePkg.dec @@ -49,5 +52,8 @@ MmServicesTableLib StackCheckLib +[LibraryClasses.LOONGARCH64] + RngLib + [Protocols] gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES diff --git a/MdePkg/Library/DynamicStackCookieEntryPointLib/UefiApplicationEntryPoint.inf b/MdePkg/Library/DynamicStackCookieEntryPointLib/UefiApplicationEntryPoint.inf index 596303e001..018c797cf6 100644 --- a/MdePkg/Library/DynamicStackCookieEntryPointLib/UefiApplicationEntryPoint.inf +++ b/MdePkg/Library/DynamicStackCookieEntryPointLib/UefiApplicationEntryPoint.inf @@ -18,7 +18,7 @@ LIBRARY_CLASS = UefiApplicationEntryPoint|UEFI_APPLICATION # -# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 LOONGARCH64 # [Sources] @@ -35,6 +35,9 @@ [Sources.AARCH64] AArch64/DynamicCookieGcc.S | GCC +[Sources.LOONGARCH64] + LoongArch64/DynamicCookieGcc.S | GCC + [Packages] MdePkg/MdePkg.dec @@ -43,3 +46,6 @@ DebugLib BaseLib StackCheckLib + +[LibraryClasses.LOONGARCH64] + RngLib diff --git a/MdePkg/Library/DynamicStackCookieEntryPointLib/UefiDriverEntryPoint.inf b/MdePkg/Library/DynamicStackCookieEntryPointLib/UefiDriverEntryPoint.inf index d624c3e1a3..6262b827d6 100644 --- a/MdePkg/Library/DynamicStackCookieEntryPointLib/UefiDriverEntryPoint.inf +++ b/MdePkg/Library/DynamicStackCookieEntryPointLib/UefiDriverEntryPoint.inf @@ -20,7 +20,7 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 LOONGARCH64 # [Sources] @@ -40,12 +40,18 @@ [Sources.AARCH64] AArch64/DynamicCookieGcc.S | GCC +[Sources.LOONGARCH64] + LoongArch64/DynamicCookieGcc.S | GCC + [LibraryClasses] UefiBootServicesTableLib DebugLib BaseLib StackCheckLib +[LibraryClasses.LOONGARCH64] + RngLib + [Protocols] gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES From 3716793e66f9afb336fc365c06b68adb3b397a65 Mon Sep 17 00:00:00 2001 From: Chao Li Date: Mon, 11 May 2026 15:51:09 +0800 Subject: [PATCH 147/406] BaseTools: Enable stack protector for LoongArch64 LoongArch64 GCC or CLANG currently does not support the parameter `-mstack-protector-guard=global`, but if `-fstack-protector` is enabled, the guard is global. The `-mstack-protector-guard` may be get supportted in the next GCC release, possibly GCC17. Signed-off-by: Chao Li Cc: Liming Gao Cc: Guillermo Antonio Palomino Sosa Cc: Yuwei Chen Cc: Poncho Figueroa Cc: Mike Beaton --- BaseTools/Conf/tools_def.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index 791d7e7508..72ca0dfa21 100644 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -586,10 +586,10 @@ NOOPT_*_*_OBJCOPY_ADDDEBUGFLAG = --add-gnu-debuglink="$(DEBUG_DIR)/$(MODULE_ *_*_*_DTCPP_PATH = DEF(DTCPP_BIN) *_*_*_DTC_PATH = DEF(DTC_BIN) -# All supported GCC archs except LOONGARCH64 support -mstack-protector-guard=global, so set that on everything except LOONGARCH64 +# Because LOONGARCH64 supports global stack protector guard by default, it does not support the parameter -mstack-protector-guard=global, and this parameter will be supported in GCC17. So set that on every thing except LOONGARCH64. DEFINE GCC_ALL_CC_COMMON = -g -Os -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common -fstack-protector DEFINE GCC_IA32_X64_CC_FLAGS = -mstack-protector-guard=global -DEFINE GCC_LOONGARCH64_CC_FLAGS = DEF(GCC_ALL_CC_COMMON) -mabi=lp64d -fno-asynchronous-unwind-tables -Wno-address -fno-short-enums -fsigned-char -ffunction-sections -fdata-sections -march=loongarch64 -mno-memcpy -Werror -Wno-maybe-uninitialized -Wno-stringop-overflow -Wno-pointer-to-int-cast -no-pie -fno-stack-protector -mno-explicit-relocs -mno-relax +DEFINE GCC_LOONGARCH64_CC_FLAGS = DEF(GCC_ALL_CC_COMMON) -mabi=lp64d -fno-asynchronous-unwind-tables -Wno-address -fno-short-enums -fsigned-char -ffunction-sections -fdata-sections -march=loongarch64 -mno-memcpy -Werror -Wno-maybe-uninitialized -Wno-stringop-overflow -Wno-pointer-to-int-cast -no-pie -mno-explicit-relocs -mno-relax DEFINE GCC_AARCH64_CC_COMMON = DEF(GCC_ALL_CC_COMMON) -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char -ffunction-sections -fdata-sections -Wno-address -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-pic -fno-pie -ffixed-x18 -mstack-protector-guard=global DEFINE GCC_AARCH64_CC_XIPCOMMON = -mstrict-align -mgeneral-regs-only DEFINE GCC_RISCV64_CC_XIPFLAGS = -mstrict-align -mgeneral-regs-only From c0c8ca0ea0b1b6e185bfd1430640da944d3dbcd2 Mon Sep 17 00:00:00 2001 From: Stanislaw Grams Date: Fri, 3 Jul 2026 13:31:38 +0200 Subject: [PATCH 148/406] OvmfPkg/PlatformInitLib: restore below-4G low memory detection for TDVF Commit 0a0919607c ("OvmfPkg/PlatformInitLib: redefine low memory") narrowed PlatformGetLowMemoryCB() to consider only the first below-4G memory block whose base address is zero. The change was intended to fix SVSM guests, where SVSM caves a chunk out of below-4G RAM and OVMF must not stray into that hole. TDVF, however, reports its below-4G RAM through the TdHob as two adjacent resource descriptors: [0, 0x800000) EFI_RESOURCE_SYSTEM_MEMORY (pre-accepted) [0x800000, ~4G) EFI_RESOURCE_MEMORY_UNACCEPTED PlatformScanE820Tdx() surfaces both as EfiAcpiAddressRangeMemory E820 entries. After 0a0919607c only the first, tiny 8 MiB block is picked up, so PlatformInfoHob->LowMemory becomes 0x800000. In OvmfPkg/PlatformPei/MemDetect.c PublishPeiMemory() this drives: LowerMemorySize = 0x00800000 // LowMemory PeiMemoryCap = 0x04F82000 // ~81 MiB MemoryBase = LowerMemorySize - PeiMemoryCap // UINT32 underflow = 0xFB87E000 Permanent PEI memory is then published at 0xFB87E000, which is not backed by RAM. TemporaryRamMigration()'s first CopyMem into that phantom range (observed as 0xFB898000 in the failing log) faults, tearing down the TD. Fold adjacent below-4G memory blocks into the low-memory span: accept an entry whose base equals the current LowMemory and advance LowMemory by its length. LowMemory starts at zero, so the first accepted block at address 0 still starts the sequence; non-adjacent above-4G or SVSM-carved blocks continue to be skipped (their base does not match LowMemory); and the TDVF accepted+unaccepted pair, which is contiguous, is now grouped correctly. Co-authored-by: Gerd Hoffmann Signed-off-by: Stanislaw Grams --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index 3a2c974e08..611cad9867 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -164,6 +164,10 @@ PlatformGetFirstNonAddressCB ( there are multiple memory blocks below 4G though, because SVSM caves out a chunk of memory for itself. Only the first of these blocks is considered low memory. + + Multiple blocks without gap inbetween are grouped together. + This is required for TDX which has two low memory descriptors + (accepted and unaccepted). **/ STATIC VOID @@ -176,12 +180,12 @@ PlatformGetLowMemoryCB ( return; } - if (E820Entry->BaseAddr != 0) { + if (E820Entry->BaseAddr != PlatformInfoHob->LowMemory) { return; } - DEBUG ((DEBUG_INFO, "%a: LowMemory=0x%Lx\n", __func__, E820Entry->Length)); - PlatformInfoHob->LowMemory = (UINT32)E820Entry->Length; + PlatformInfoHob->LowMemory += (UINT32)E820Entry->Length; + DEBUG ((DEBUG_INFO, "%a: LowMemory=0x%Lx\n", __func__, PlatformInfoHob->LowMemory)); } /** From d8ec67acb701a18e1e32d84b2d0a1689b56b54ab Mon Sep 17 00:00:00 2001 From: VarshitPandya Date: Thu, 2 Jul 2026 18:30:41 +0100 Subject: [PATCH 149/406] DynamicTablesPkg: Smbios Memory Channel (Type 37) Add support for generating SMBIOS Type 37 Memory Channel structures from Configuration Manager data. Introduce the Memory Channel CM object and the associated Memory Channel Device CM object. The channel object describes the Type 37 fixed fields, including channel type, maximum channel load, memory device count, and the token for the device-list object. The device-list object describes each memory device attached to the channel using a device load and a Type 17 Memory Device CM token. Add parser entries for both CM objects and register the Type 37 generator in the DynamicTablesPkg DSC so it is available through the SMBIOS table factory. The Type 37 generator builds one SMBIOS record per Memory Channel CM object. For each channel, it retrieves the referenced Memory Channel Device list, validates the channel type, maximum channel load, device count, device load, and device tokens, resolves each referenced Type 17 CM token to an SMBIOS handle, and emits the variable-length MemoryDevice array in the Type 37 record. This allows platforms to describe memory channels and link them to generated Type 17 Memory Device records through CM tokens instead of hard-coded SMBIOS handles. Signed-off-by: Varshit Pandya --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../Include/ArchCommonNameSpaceObjects.h | 37 ++ .../ConfigurationManagerObjectParser.c | 18 + .../SmbiosType37Lib/SmbiosType37Generator.c | 547 ++++++++++++++++++ .../SmbiosType37Lib/SmbiosType37Lib.inf | 34 ++ 5 files changed, 638 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index f9b0fb2dfc..b8409c1c3a 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -122,6 +122,7 @@ DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf # AML Fixup (Arm specific) DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtCmn600LibArm/SsdtCmn600LibArm.inf @@ -179,6 +180,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf } [Components.RISCV64] diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index 214e919dc3..d3295ce145 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -89,6 +89,8 @@ typedef enum ArchCommonObjectID { EArchCommonObjElectricalCurrentProbeInfo, ///< 61 - Electrical Current Probe Info EArchCommonObjSystemResetInfo, ///< 62 - System Reset Info EArchCommonObjMemoryDeviceMappedAddress, ///< 63 - Memory Device Mapped Address Info + EArchCommonObjMemoryChannelInfo, ///< 64 - Memory Channel Info + EArchCommonObjMemoryChannelDevice, ///< 65 - Memory Channel Device Info EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1498,6 +1500,41 @@ typedef struct CmArchCommonMemoryDeviceMappedAddress { UINT8 InterleavedDataDepth; } CM_ARCH_COMMON_MEMORY_DEVICE_MAPPED_ADDRESS; +/** A structure that describes a Memory Device entry associated with a + Memory Channel. + + SMBIOS Specification v3.9.0 Type 37 + + ID: EArchCommonObjMemoryChannelDevice +**/ +typedef struct CmArchCommonMemoryChannelDevice { + /// The load on the channel represented by the associated memory device. + UINT8 DeviceLoad; + + /// CM Object Token of the associated SMBIOS Type 17 Memory Device. + CM_OBJECT_TOKEN MemoryDeviceInfoToken; +} CM_ARCH_COMMON_MEMORY_CHANNEL_DEVICE; + +/** A structure that describes a Memory Channel. + + SMBIOS Specification v3.9.0 Type 37 + + ID: EArchCommonObjMemoryChannelInfo +**/ +typedef struct CmArchCommonMemoryChannelInfo { + /// CM Object Token uniquely identifying this memory channel. + CM_OBJECT_TOKEN MemoryChannelToken; + + /// Type of the memory channel. + UINT8 ChannelType; + + /// Maximum load supported by the memory channel. + UINT8 MaximumChannelLoad; + + /// Token referencing an array of Memory Channel Device entries. + CM_OBJECT_TOKEN MemoryDeviceListToken; +} CM_ARCH_COMMON_MEMORY_CHANNEL_INFO; + /** A structure that describes cooling device. SMBIOS Specification v3.9.0 Type 27 diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index ab4e45c079..7b3f612866 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -1223,6 +1223,22 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonMemoryArrayMappedAddressParser[] = { { "NumMemDevices", sizeof (UINT8), "0x%u", NULL }, }; +/** A parser for CM_ARCH_COMMON_MEMORY_CHANNEL_DEVICE. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonMemoryChannelDeviceParser[] = { + { "DeviceLoad", sizeof (UINT8), "0x%u", NULL }, + { "MemoryDeviceInfoToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, +}; + +/** A parser for EArchCommonObjMemoryChannelInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonMemoryChannelInfoParser[] = { + { "MemoryChannelToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "ChannelType", sizeof (UINT8), "0x%x", NULL }, + { "MaximumChannelLoad", sizeof (UINT8), "0x%u", NULL }, + { "MemoryDeviceListToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, +}; + /** A parser for EArchCommonObjMemoryDeviceMappedAddress. */ STATIC CONST CM_OBJ_PARSER CmArchCommonMemoryDeviceMappedAddressParser[] = { @@ -1372,6 +1388,8 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArchCommonObjElectricalCurrentProbeInfo, CmArchCommonElectricalCurrentProbeInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjSystemResetInfo, CmArchCommonSystemResetInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryDeviceMappedAddress, CmArchCommonMemoryDeviceMappedAddressParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryChannelInfo, CmArchCommonMemoryChannelInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryChannelDevice, CmArchCommonMemoryChannelDeviceParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Generator.c new file mode 100644 index 0000000000..23b10c933b --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Generator.c @@ -0,0 +1,547 @@ +/** @file + SMBIOS Type37 Table Generator. + + Copyright (c) 2026, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include + +/** SMBIOS Type 37 Memory Channel Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArchCommonObjMemoryChannelInfo + - EArchCommonObjMemoryChannelDevice + + The following Configuration Manager Object(s) are required to resolve + the Memory Device handles: + - EArchCommonObjMemoryDeviceInfo +*/ + +/** + This macro expands to a function that retrieves the Memory Channel + information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjMemoryChannelInfo, + CM_ARCH_COMMON_MEMORY_CHANNEL_INFO + ); + +/** + This macro expands to a function that retrieves the Memory Channel + Device entries from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjMemoryChannelDevice, + CM_ARCH_COMMON_MEMORY_CHANNEL_DEVICE + ); + +/** Construct SMBIOS Type 37 table describing Memory Channel information. + + If this function allocates any resources then they must be freed in + FreeSmbiosType37TableEx(). + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS table factory protocol. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the generated SMBIOS table. + @param [out] CmObjectToken Pointer to the CM object token for the + generated SMBIOS table. + @param [out] TableCount Number of generated SMBIOS tables. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Required CM object is not found. +**/ +STATIC +EFI_STATUS +EFIAPI +BuildSmbiosType37TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + UINT32 NumMemChannels; + UINT32 MemoryChannelDeviceCount; + CM_ARCH_COMMON_MEMORY_CHANNEL_INFO *MemoryChannelInfo; + CM_ARCH_COMMON_MEMORY_CHANNEL_DEVICE *MemoryChannelDevice; + CM_OBJECT_TOKEN *CmObjectList; + SMBIOS_STRUCTURE **TableList; + SMBIOS_TABLE_TYPE37 *SmbiosRecord; + SMBIOS_HANDLE MemoryDeviceHandle; + UINTN Index; + UINTN DeviceIndex; + UINTN RecordSize; + UINTN TotalDeviceLoad; + + TableList = NULL; + CmObjectList = NULL; + SmbiosRecord = NULL; + MemoryChannelDevice = NULL; + MemoryChannelDeviceCount = 0; + TotalDeviceLoad = 0; + + ASSERT (This != NULL); + ASSERT (TableFactoryProtocol != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Table != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (TableFactoryProtocol == NULL) || + (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL) || + (TableCount == NULL)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + *CmObjectToken = NULL; + *TableCount = 0; + + Status = GetEArchCommonObjMemoryChannelInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &MemoryChannelInfo, + &NumMemChannels + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Memory Channel CM Object. Status = %r\n", + __func__, + Status + )); + return Status; + } + + if (NumMemChannels == 0) { + DEBUG (( + DEBUG_ERROR, + "%a: No Memory Channel CM Objects found\n", + __func__ + )); + return EFI_NOT_FOUND; + } + + TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool ( + sizeof (SMBIOS_STRUCTURE *) * NumMemChannels + ); + + if (TableList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to allocate memory for %u Memory Channel tables\n", + __func__, + NumMemChannels + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType37TableEx; + } + + CmObjectList = (CM_OBJECT_TOKEN *)AllocateZeroPool ( + sizeof (CM_OBJECT_TOKEN) * NumMemChannels + ); + if (CmObjectList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to allocate memory for %u CM Object tokens\n", + __func__, + NumMemChannels + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType37TableEx; + } + + for (Index = 0; Index < NumMemChannels; Index++) { + MemoryChannelDevice = NULL; + MemoryChannelDeviceCount = 0; + TotalDeviceLoad = 0; + + if (MemoryChannelInfo[Index].MemoryChannelToken == CM_NULL_TOKEN) { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid MemoryChannelToken for Memory Channel %u\n", + __func__, + Index + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType37TableEx; + } + + if (MemoryChannelInfo[Index].MemoryDeviceListToken == CM_NULL_TOKEN) { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid MemoryDeviceListToken for Memory Channel %u\n", + __func__, + Index + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType37TableEx; + } + + if ((MemoryChannelInfo[Index].ChannelType < MemoryChannelTypeOther) || + (MemoryChannelInfo[Index].ChannelType > MemoryChannelTypeSyncLink)) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid ChannelType 0x%x for Memory Channel %u\n", + __func__, + MemoryChannelInfo[Index].ChannelType, + Index + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType37TableEx; + } + + if (MemoryChannelInfo[Index].MaximumChannelLoad == 0) { + DEBUG (( + DEBUG_ERROR, + "%a: MaximumChannelLoad is zero for Memory Channel %u\n", + __func__, + Index + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType37TableEx; + } + + // + // The Type 37 record contains a variable number of Memory Device + // entries. Fetch the per-channel device list referenced by this + // Memory Channel CM object. + // + Status = GetEArchCommonObjMemoryChannelDevice ( + CfgMgrProtocol, + MemoryChannelInfo[Index].MemoryDeviceListToken, + &MemoryChannelDevice, + &MemoryChannelDeviceCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Memory Channel Device CM Object. Status = %r\n", + __func__, + Status + )); + goto exitBuildSmbiosType37TableEx; + } + + if (MemoryChannelDeviceCount == 0) { + DEBUG (( + DEBUG_ERROR, + "%a: No Memory Channel Device entries for Memory Channel %u\n", + __func__, + Index + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType37TableEx; + } + + if (MemoryChannelDeviceCount > MAX_UINT8) { + DEBUG (( + DEBUG_ERROR, + "%a: Memory Channel Device count %u exceeds SMBIOS Type 37 limit\n", + __func__, + MemoryChannelDeviceCount + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType37TableEx; + } + + // + // SMBIOS_TABLE_TYPE37 already includes one MEMORY_DEVICE entry. + // Add space only for the remaining entries. + // + RecordSize = sizeof (SMBIOS_TABLE_TYPE37) + + ((MemoryChannelDeviceCount - 1) * sizeof (MEMORY_DEVICE)); + + if (RecordSize > MAX_UINT8) { + DEBUG (( + DEBUG_ERROR, + "%a: Type 37 record size %u exceeds SMBIOS header length limit\n", + __func__, + RecordSize + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType37TableEx; + } + + SmbiosRecord = (SMBIOS_TABLE_TYPE37 *)AllocateSmbiosRecord ( + RecordSize, + NULL + ); + + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType37TableEx; + } + + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_MEMORY_CHANNEL; + SmbiosRecord->Hdr.Length = (UINT8)RecordSize; + SmbiosRecord->Hdr.Handle = SMBIOS_HANDLE_PI_RESERVED; + SmbiosRecord->ChannelType = MemoryChannelInfo[Index].ChannelType; + SmbiosRecord->MaximumChannelLoad = MemoryChannelInfo[Index].MaximumChannelLoad; + SmbiosRecord->MemoryDeviceCount = (UINT8)MemoryChannelDeviceCount; + + for (DeviceIndex = 0; DeviceIndex < MemoryChannelDeviceCount; DeviceIndex++) { + if (MemoryChannelDevice[DeviceIndex].DeviceLoad == 0) { + DEBUG (( + DEBUG_ERROR, + "%a: DeviceLoad is zero for Memory Channel %u Device %u\n", + __func__, + Index, + DeviceIndex + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType37TableEx; + } + + if (MemoryChannelDevice[DeviceIndex].MemoryDeviceInfoToken == CM_NULL_TOKEN) { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid MemoryDeviceInfoToken for Memory Channel %u Device %u\n", + __func__, + Index, + DeviceIndex + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType37TableEx; + } + + // + // Type 37 references Type 17 Memory Device records by SMBIOS handle. + // Resolve the CM token to the Type 17 handle generated earlier. + // + MemoryDeviceHandle = TableFactoryProtocol->GetSmbiosHandleEx ( + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType17), + MemoryChannelDevice[DeviceIndex].MemoryDeviceInfoToken + ); + + if (MemoryDeviceHandle == SMBIOS_HANDLE_INVALID) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Type 17 SMBIOS Handle for Memory Channel %u Device %u\n", + __func__, + Index, + DeviceIndex + )); + Status = EFI_NOT_FOUND; + goto exitBuildSmbiosType37TableEx; + } + + TotalDeviceLoad += MemoryChannelDevice[DeviceIndex].DeviceLoad; + + SmbiosRecord->MemoryDevice[DeviceIndex].DeviceLoad = + MemoryChannelDevice[DeviceIndex].DeviceLoad; + + SmbiosRecord->MemoryDevice[DeviceIndex].DeviceHandle = + MemoryDeviceHandle; + } + + // + // Each memory device presents one or more loads to the channel, and + // the sum of all device loads must not exceed the channel maximum. + // + if (TotalDeviceLoad > MemoryChannelInfo[Index].MaximumChannelLoad) { + DEBUG (( + DEBUG_ERROR, + "%a: Total DeviceLoad %u exceeds MaximumChannelLoad %u for Memory Channel %u\n", + __func__, + TotalDeviceLoad, + MemoryChannelInfo[Index].MaximumChannelLoad, + Index + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType37TableEx; + } + + // + // Publish the completed record only after all per-device validation + // and handle resolution has succeeded. + // + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] = MemoryChannelInfo[Index].MemoryChannelToken; + + SmbiosRecord = NULL; + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = NumMemChannels; + +exitBuildSmbiosType37TableEx: + if (EFI_ERROR (Status)) { + if (TableList != NULL) { + for (Index = 0; Index < NumMemChannels; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + FreePool (TableList); + } + + if (CmObjectList != NULL) { + FreePool (CmObjectList); + } + + if (SmbiosRecord != NULL) { + FreePool (SmbiosRecord); + } + } + + return Status; +} + +/** Free any resources allocated for constructing SMBIOS Type 37 table. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS table factory + protocol. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the SMBIOS table. + @param [in] CmObjectToken Pointer to the CM object token. + @param [in] TableCount Number of generated SMBIOS tables. + + @retval EFI_SUCCESS Resources freed successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +FreeSmbiosType37TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + + if ((This == NULL) || (TableFactoryProtocol == NULL) || + (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + if (*Table != NULL) { + for (Index = 0; Index < TableCount; Index++) { + if ((*Table)[Index] != NULL) { + FreePool ((*Table)[Index]); + } + } + + FreePool (*Table); + *Table = NULL; + } + + if (*CmObjectToken != NULL) { + FreePool (*CmObjectToken); + *CmObjectToken = NULL; + } + + return EFI_SUCCESS; +} + +/** The SMBIOS Type 37 Table Generator. +*/ +STATIC CONST SMBIOS_TABLE_GENERATOR SmbiosType37Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType37), + // Generator Description + L"SMBIOS.TYPE37.GENERATOR", + // SMBIOS structure type + SMBIOS_TYPE_MEMORY_CHANNEL, + NULL, + NULL, + // Build table function. + BuildSmbiosType37TableEx, + // Free function. + FreeSmbiosType37TableEx +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType37LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType37Generator); + DEBUG ((DEBUG_INFO, "SMBIOS Type 37: Register Generator. Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType37LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType37Generator); + DEBUG ((DEBUG_INFO, "SMBIOS Type 37: Deregister Generator. Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf new file mode 100644 index 0000000000..299d62d4a6 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf @@ -0,0 +1,34 @@ +## @file +# SMBIOS Type37 Table Generator. +# +# Copyright (c) 2026, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType37LibArm + FILE_GUID = 73d3af03-d975-4678-acd5-cf72fecc207f + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType37LibConstructor + DESTRUCTOR = SmbiosType37LibDestructor + +[Sources] + SmbiosType37Generator.c + +[Packages] + DynamicTablesPkg/DynamicTablesPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MemoryAllocationLib + SmbiosStringTableLib + +[Protocols] + gEdkiiConfigurationManagerProtocolGuid + gEdkiiDynamicTableFactoryProtocolGuid From 65cacd6fcd44423d0cc264b908030b5b329726fa Mon Sep 17 00:00:00 2001 From: Mingjie Shen Date: Sat, 4 Jul 2026 02:23:00 +0000 Subject: [PATCH 150/406] SecurityPkg/DxeTpmMeasureBootLib: Check GPT event size sanitization TcgMeasureGptTable() ignored the return status of TpmSanitizePrimaryHeaderGptEventSize(). On failure the EventSize output is unreliable and was passed straight into AllocateZeroPool() and the subsequent CopyMem() operations, which can result in an incorrectly sized allocation and out-of-bounds access when parsing an untrusted GPT. Check the status and, on error, free the already-allocated PrimaryHeader and EntryPtr buffers and return EFI_DEVICE_ERROR, matching the handling already used in DxeTpm2MeasureBootLib's TcgMeasureGptTable(). Signed-off-by: Mingjie Shen --- .../Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c index ac855b8fbb..6cb5ff25f5 100644 --- a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c +++ b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c @@ -224,7 +224,13 @@ TcgMeasureGptTable ( // // Prepare Data for Measurement // - Status = TpmSanitizePrimaryHeaderGptEventSize (PrimaryHeader, NumberOfPartition, &EventSize); + Status = TpmSanitizePrimaryHeaderGptEventSize (PrimaryHeader, NumberOfPartition, &EventSize); + if (EFI_ERROR (Status)) { + FreePool (PrimaryHeader); + FreePool (EntryPtr); + return EFI_DEVICE_ERROR; + } + TcgEvent = (TCG_PCR_EVENT *)AllocateZeroPool (EventSize); if (TcgEvent == NULL) { FreePool (PrimaryHeader); From 855e63ee5c0e8204d09802eda6c0cf36b4cf8eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C4=81vis=20Mos=C4=81ns?= Date: Sun, 5 Jul 2026 02:08:09 +0300 Subject: [PATCH 151/406] SecurityPkg/Tpm2ServiceFfa.h: fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace `TPM_CRB_FFA_FEAT_NOTIFICATION_TYPE_SHIFT` with `TPM2_FFA_FEAT_NOTIFICATION_TYPE_SHIFT` Fixes #12768 Signed-off-by: Dāvis Mosāns --- SecurityPkg/Include/Guid/Tpm2ServiceFfa.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SecurityPkg/Include/Guid/Tpm2ServiceFfa.h b/SecurityPkg/Include/Guid/Tpm2ServiceFfa.h index 99d44d3947..772501a61f 100644 --- a/SecurityPkg/Include/Guid/Tpm2ServiceFfa.h +++ b/SecurityPkg/Include/Guid/Tpm2ServiceFfa.h @@ -40,9 +40,9 @@ #define TPM_SERVICE_FEATURE_SUPPORT_NOTIFICATION 0xfea70000 #define TPM2_FFA_FEAT_NOTIFICATION_DEST_ID_MASK 0x000000ff #define TPM2_FFA_FEAT_NOTIFICATION_TYPE_SHIFT 16 -#define TPM2_FFA_FEAT_NOTIFICATION_TYPE_MASK (1 << TPM_CRB_FFA_FEAT_NOTIFICATION_TYPE_SHIFT) -#define TPM2_FFA_FEAT_NOTIFICATION_TYPE_GLOBAL (0 << TPM_CRB_FFA_FEAT_NOTIFICATION_TYPE_SHIFT) -#define TPM2_FFA_FEAT_NOTIFICATION_TYPE_PER_VCPU (1 << TPM_CRB_FFA_FEAT_NOTIFICATION_TYPE_SHIFT) +#define TPM2_FFA_FEAT_NOTIFICATION_TYPE_MASK (1 << TPM2_FFA_FEAT_NOTIFICATION_TYPE_SHIFT) +#define TPM2_FFA_FEAT_NOTIFICATION_TYPE_GLOBAL (0 << TPM2_FFA_FEAT_NOTIFICATION_TYPE_SHIFT) +#define TPM2_FFA_FEAT_NOTIFICATION_TYPE_PER_VCPU (1 << TPM2_FFA_FEAT_NOTIFICATION_TYPE_SHIFT) #define TPM2_FFA_START_FUNC_QUALIFIER_COMMAND 0x0 #define TPM2_FFA_START_FUNC_QUALIFIER_LOCALITY 0x1 From b38d9eb7c6299d1bbb46773d261452a11427505b Mon Sep 17 00:00:00 2001 From: Mingjie Shen Date: Thu, 7 May 2026 23:21:43 +0000 Subject: [PATCH 152/406] MdeModulePkg/ArmFfaLib: Use EFI_PAGES_TO_SIZE Replace manual page-size multiplication with EFI_PAGES_TO_SIZE in the ArmFfaLib sources. This commit mimics 3457388 and is generated by the following coccinelle scipt: ```smpl @pages_to_size@ expression PAGE_COUNT; @@ - PcdGet64 (PAGE_COUNT) * EFI_PAGE_SIZE + EFI_PAGES_TO_SIZE (PcdGet64 (PAGE_COUNT)) ``` Tested: - stuart_ci_build -c .pytool/CISettings.py -p MdeModulePkg -a AARCH64 -t DEBUG TOOL_CHAIN_TAG=GCC - stuart_ci_build -c .pytool/CISettings.py -p MdeModulePkg -a AARCH64 -t RELEASE,NO-TARGET TOOL_CHAIN_TAG=GCC Signed-off-by: Mingjie Shen --- MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c | 4 ++-- MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c | 14 +++++++------- .../Library/ArmFfaLib/ArmFfaStandaloneMmRxTxMap.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c index 3cacf5ab04..9c90bcada0 100644 --- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c @@ -1180,8 +1180,8 @@ GetRxTxBufferMinSizeAndAlign ( MaxSize = ((MaxSize == 0) ? MAX_UINTN : (MaxSize * MinAndAlign)); - if ((MinAndAlign > (PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE)) || - (MaxSize < (PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE))) + if ((MinAndAlign > (EFI_PAGES_TO_SIZE (PcdGet64 (PcdFfaTxRxPageCount)))) || + (MaxSize < (EFI_PAGES_TO_SIZE (PcdGet64 (PcdFfaTxRxPageCount))))) { DEBUG (( DEBUG_ERROR, diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c index faaedcf756..69c359f797 100644 --- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c @@ -69,7 +69,7 @@ ArmFfaLibGetRxTxBuffers ( } if (TxBufferSize != NULL) { - *TxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE; + *TxBufferSize = EFI_PAGES_TO_SIZE (PcdGet64 (PcdFfaTxRxPageCount)); } if (RxBuffer != NULL) { @@ -77,7 +77,7 @@ ArmFfaLibGetRxTxBuffers ( } if (RxBufferSize != NULL) { - *RxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE; + *RxBufferSize = EFI_PAGES_TO_SIZE (PcdGet64 (PcdFfaTxRxPageCount)); } return EFI_SUCCESS; @@ -111,7 +111,7 @@ ArmFfaLibRxTxMap ( TxBuffer = (VOID *)(UINTN)PcdGet64 (PcdFfaTxBuffer); RxBuffer = (VOID *)(UINTN)PcdGet64 (PcdFfaRxBuffer); - BufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE; + BufferSize = EFI_PAGES_TO_SIZE (PcdGet64 (PcdFfaTxRxPageCount)); /* * If someone already mapped Rx/Tx Buffers, return EFI_ALREADY_STARTED. @@ -243,9 +243,9 @@ UpdateRxTxBufferInfo ( ) { BufferInfo->TxBufferAddr = PcdGet64 (PcdFfaTxBuffer); - BufferInfo->TxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE; + BufferInfo->TxBufferSize = EFI_PAGES_TO_SIZE (PcdGet64 (PcdFfaTxRxPageCount)); BufferInfo->RxBufferAddr = PcdGet64 (PcdFfaRxBuffer); - BufferInfo->RxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE; + BufferInfo->RxBufferSize = EFI_PAGES_TO_SIZE (PcdGet64 (PcdFfaTxRxPageCount)); } /** @@ -267,7 +267,7 @@ FindRxTxBufferAllocationHob ( UINT64 BufferSize; BufferBase = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFfaTxBuffer); - BufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE * 2; + BufferSize = EFI_PAGES_TO_SIZE (PcdGet64 (PcdFfaTxRxPageCount)) * 2; return GetRxTxBufferAllocationHob (BufferBase, BufferSize, UseGuid); } @@ -327,7 +327,7 @@ RemapFfaRxTxBuffer ( NewBufferBase = (UINTN)RxTxBufferAllocationHob->AllocDescriptor.MemoryBaseAddress + BufferInfo->RemapOffset; NewTxBuffer = NewBufferBase; - NewRxBuffer = NewTxBuffer + (PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE); + NewRxBuffer = NewTxBuffer + (EFI_PAGES_TO_SIZE (PcdGet64 (PcdFfaTxRxPageCount))); ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS)); FfaArgs.Arg0 = ARM_FID_FFA_RXTX_MAP; diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmRxTxMap.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmRxTxMap.c index a3ba05c4d6..8b735050f0 100644 --- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmRxTxMap.c +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmRxTxMap.c @@ -140,7 +140,7 @@ ArmFfaLibRxTxMap ( return EFI_OUT_OF_RESOURCES; } - BufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE; + BufferSize = EFI_PAGES_TO_SIZE (PcdGet64 (PcdFfaTxRxPageCount)); TxBuffer = Buffers; RxBuffer = Buffers + BufferSize; From 2cfd432ac92f58a14331fec2d2b885c795f684db Mon Sep 17 00:00:00 2001 From: Mingjie Shen Date: Wed, 6 May 2026 23:15:46 +0000 Subject: [PATCH 153/406] ArmPkg/Driver: Remove the stale mPartId and duplicate ArmFfaLibRxRelease ArmFfaLibGetPartitionInfo() helper replaces the manual partition info lookup sequence used by FF-A clients: * ArmFfaLibPartitionIdGet() * ArmFfaLibGetRxTxBuffers() * ArmFfaLibPartitionInfoGet(..., FFA_PART_INFO_FLAG_TYPE_DESC, ...) * copy EFI_FFA_PART_INFO_DESC from the RX buffer * ArmFfaLibRxRelease() The collateral evolutions in b80000847a and 96ad9bd397 use the helper as the owner of that sequence. Their callers only consume the copied partition descriptor and do not keep a local partition ID solely for RX buffer release. Commit 8955d8db32 converted MmCommunication to call ArmFfaLibGetPartitionInfo(), but kept caller-side partition ID state and, in PEI, still released the RX buffer after the helper returned. That made the ArmPkg conversion inconsistent with b80000847a and 96ad9bd397, and inconsistent with the helper ownership model. In the ArmFfaLibPartitionInfoGetRegs path, there is no RX buffer to release, while in the RX/TX buffer path, the buffer is already released inside ArmFfaLibGetPartitionInfo(). This patch removes the stale local mPartId state and the remaining caller-side ArmFfaLibRxRelease() from the DXE and PEI MM communication drivers. The callers now match the helper contract: get the descriptor, validate DIRECT_MSG_REQ support, and store the StandaloneMM partition ID. The current version was generated by running the following Coccinelle script on 8955d8db32^, then rebasing the resulting fixup to master. ``` smpl @replace_old_sequence@ typedef EFI_STATUS; identifier Fn; identifier Info, Count, TxBuffer, TxBufferSize, RxBuffer, RxBufferSize; identifier PartId, Status, Size; expression Guid; position p; statement S1, S2; type SizeArgT; @@ EFI_STATUS Fn@p (...) { ... - EFI_FFA_PART_INFO_DESC *Info; + EFI_FFA_PART_INFO_DESC Info; ... - Status = ArmFfaLibPartitionIdGet (&PartId); - if (EFI_ERROR (Status)) S1 ... - Status = ArmFfaLibGetRxTxBuffers ( - &TxBuffer, - &TxBufferSize, - &RxBuffer, - &RxBufferSize - ); - if (EFI_ERROR (Status)) S2 ... - Status = ArmFfaLibPartitionInfoGet ( - Guid, - FFA_PART_INFO_FLAG_TYPE_DESC, - &Count, - (SizeArgT)&Size - ); + Status = ArmFfaLibGetPartitionInfo (Guid, &Info); ... ( - if ((Count != 1) || (Size < sizeof (EFI_FFA_PART_INFO_DESC))) { - ... - } else { - Info = (EFI_FFA_PART_INFO_DESC *)RxBuffer; ... - } | - if ((Count != 1) || (Size < sizeof (EFI_FFA_PART_INFO_DESC))) { - ... - } ... - Info = (EFI_FFA_PART_INFO_DESC *)RxBuffer; ) ... - ArmFfaLibRxRelease (PartId); ... } @part_info_members depends on replace_old_sequence@ identifier replace_old_sequence.Info; identifier Field =~ "^(PartitionId|PartitionProps)$"; @@ - Info->Field + Info.Field @remove_old_variables depends on replace_old_sequence@ identifier replace_old_sequence.Count, replace_old_sequence.TxBuffer; identifier replace_old_sequence.TxBufferSize, replace_old_sequence.RxBuffer, replace_old_sequence.RxBufferSize; identifier replace_old_sequence.PartId; identifier replace_old_sequence.Size; type T; @@ ( - T *TxBuffer; | - UINT64 TxBufferSize; | - T *RxBuffer; | - UINT64 RxBufferSize; | - UINT32 Count; | - UINT32 Size; | - UINT16 PartId; | - static UINT16 PartId; ) ``` Signed-off-by: Mingjie Shen --- .../MmCommunicationDxe/MmCommunication.c | 11 ----------- .../MmCommunicationPei/MmCommunicationPei.c | 17 ++--------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c index b7e45885de..a4ff4848cb 100644 --- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c @@ -32,7 +32,6 @@ // // Partition ID if FF-A support is enabled // -STATIC UINT16 mPartId; STATIC UINT16 mStMmPartId; // @@ -549,16 +548,6 @@ InitializeFfaCommunication ( EFI_STATUS Status; EFI_FFA_PART_INFO_DESC StmmPartInfo; - Status = ArmFfaLibPartitionIdGet (&mPartId); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "Failed to get partition id. Status: %r\n", - Status - )); - return Status; - } - Status = ArmFfaLibGetPartitionInfo (&gEfiMmCommunication2ProtocolGuid, &StmmPartInfo); if (EFI_ERROR (Status)) { DEBUG (( diff --git a/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c b/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c index 00a56a4778..4fc0a45728 100644 --- a/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c +++ b/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c @@ -26,7 +26,6 @@ // // Partition ID if FF-A support is enabled // -STATIC UINT16 mPartId; STATIC UINT16 mStMmPartId; /** @@ -139,16 +138,6 @@ InitializeFfaCommunication ( EFI_STATUS Status; EFI_FFA_PART_INFO_DESC StmmPartInfo; - Status = ArmFfaLibPartitionIdGet (&mPartId); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "Failed to get partition id. Status: %r\n", - Status - )); - return Status; - } - Status = ArmFfaLibGetPartitionInfo (&gEfiMmCommunication2ProtocolGuid, &StmmPartInfo); if (EFI_ERROR (Status)) { DEBUG (( @@ -163,14 +152,12 @@ InitializeFfaCommunication ( if ((StmmPartInfo.PartitionProps & FFA_PART_PROP_RECV_DIRECT_REQ) == 0x00) { Status = EFI_UNSUPPORTED; DEBUG ((DEBUG_ERROR, "StandaloneMm doesn't receive DIRECT_MSG_REQ...\n")); - goto ErrorHandler; + return Status; } mStMmPartId = StmmPartInfo.PartitionId; -ErrorHandler: - ArmFfaLibRxRelease (mPartId); - return Status; + return EFI_SUCCESS; } /** From a62292ba9417514fa91461fad02ba340744b6151 Mon Sep 17 00:00:00 2001 From: Christopher Zurcher Date: Thu, 25 Jun 2026 16:16:00 -0700 Subject: [PATCH 154/406] BaseTools/GenFds: Print INF name on Depex eval failure Signed-off-by: Christopher Zurcher --- BaseTools/Source/Python/GenFds/FfsInfStatement.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py index 3dbf3746d8..b6c57e9e8d 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -159,7 +159,11 @@ class FfsInfStatement(FfsInfStatementClassObject): LibraryInstance[LibName] = LibraryModule DependencyList.append(LibraryModule) if DepexList: - Dpx = DependencyExpression(DepexList, ModuleType, True) + try: + Dpx = DependencyExpression(DepexList, ModuleType, True) + except Exception: + GenFdsGlobalVariable.ErrorLogger("Failed to parse Depex for: %s\n" % self.InfFileName) + raise if len(Dpx.PostfixNotation) != 0: # It means this module has DEPEX self.FinalTargetSuffixMap['.depex'] = [os.path.join(self.EfiOutputPath, self.BaseName) + '.depex'] From c38340a0c198e8e5c07a3820796c624109060b96 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Mon, 22 Jun 2026 07:05:40 -0700 Subject: [PATCH 155/406] MdeModulePkg: Dxe Core: Correct gMemoryTypeInformation Definition Commit 43e306806e3c1ed3ad7e9913492732e893cafa0f added support to DXE Core for EfiUnacceptedMemoryType. However, it incorrectly added EFI_GCD_MEMORY_TYPE_UNACCEPTED to gMemoryTypeInformation, which is the GCD memory type that is associated with EfiUnacceptedMemoryType. All other changes from that PR appear correct. This is corrected to the EFI memory type. The Memory Bin Google Test copied this incorrect definition, so it is updated as well. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp | 2 +- MdeModulePkg/Core/Dxe/Mem/Page.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp b/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp index 4ac6dcbd42..486427bd93 100644 --- a/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp +++ b/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp @@ -63,7 +63,7 @@ extern "C" { { EfiMemoryMappedIOPortSpace, 0 }, { EfiPalCode, 0 }, { EfiPersistentMemory, 0 }, - { EfiGcdMemoryTypeUnaccepted, 0 }, + { EfiUnacceptedMemoryType, 0 }, { EfiMaxMemoryType, 0 } }; } diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 22d5bd1336..2a31b15133 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -72,7 +72,7 @@ EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = { { EfiMemoryMappedIOPortSpace, 0 }, { EfiPalCode, 0 }, { EfiPersistentMemory, 0 }, - { EfiGcdMemoryTypeUnaccepted, 0 }, + { EfiUnacceptedMemoryType, 0 }, { EfiMaxMemoryType, 0 } }; // From b35d53d589ce9a03c268e7d2db617360609817d6 Mon Sep 17 00:00:00 2001 From: Yeoreum Yun Date: Sun, 5 Jul 2026 16:06:50 +0100 Subject: [PATCH 156/406] MdePkg: SMBIOS: add Arm processor specific block structures Add definitions for Arm processor specific block structure and related sub data structure. Signed-off-by: Yeoreum Yun --- MdePkg/Include/IndustryStandard/SmBios.h | 115 +++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/MdePkg/Include/IndustryStandard/SmBios.h b/MdePkg/Include/IndustryStandard/SmBios.h index 5789c98f1f..21892e1b33 100644 --- a/MdePkg/Include/IndustryStandard/SmBios.h +++ b/MdePkg/Include/IndustryStandard/SmBios.h @@ -2896,6 +2896,121 @@ typedef struct { /// } PROCESSOR_SPECIFIC_BLOCK; +#define PROCESSOR_SPECIFIC_MAJOR_VERSION_SHIFT (8) +#define PROCESSOR_SPECIFIC_MAJOR_VERSION_MASK (0xff00) +#define PROCESSOR_SPECIFIC_MINOR_VERSION_SHIFT (0) +#define PROCESSOR_SPECIFIC_MINOR_VERSION_MASK (0x00ff) +#define PROCESSOR_SPECIFIC_VERSION_INFO(major, minor) \ + ((UINT16)((((major) & ((PROCESSOR_SPECIFIC_MAJOR_VERSION_MASK >> \ + PROCESSOR_SPECIFIC_MAJOR_VERSION_SHIFT))) << \ + PROCESSOR_SPECIFIC_MAJOR_VERSION_SHIFT) | \ + (((minor) & PROCESSOR_SPECIFIC_MINOR_VERSION_MASK) << \ + PROCESSOR_SPECIFIC_MINOR_VERSION_SHIFT))) + +/// +/// Arm (AARCH64) processor specific Block. +/// +typedef struct ArmProcSpecificBlock { + /// Revision for processor specific block + UINT16 Revision; + + /// Length of this structure. + UINT8 Length; + + /// Reserved; + UINT8 Reserved0; + + /// Vendor ID. + UINT16 VendorId; + + /// Sub type of Processor specific sub-data. + UINT8 SubType; + + /// Reserved; + UINT8 Reserved1; + + /// + /// Below followed by Arm Processor-specific sub-data + /// +} ARM_PROCESSOR_SPECIFIC_BLOCK; + +/// +/// AArch64 Architecture Data for ArmProcessorSpecificDataSubTypeArch. +/// +typedef struct AArch64ProcessorSpecificSubDataArch { + /// Version for Processor Specific Sub Data (Arch Data). + UINT16 Version; + + /// Length of this structure. + UINT8 Length; + + /// Reserved. + UINT8 Reserved0; + + /// Reserved. + UINT32 Reserved1; + + /// Value of ID_AA64AFR0_EL1. + UINT64 IdAA64Afr0; + + /// Value of ID_AA64AFR1_EL1. + UINT64 IdAA64Afr1; + + /// Value of ID_AA64DFR0_EL1. + UINT64 IdAA64Dfr0; + + /// Value of ID_AA64DFR1_EL1. + UINT64 IdAA64Dfr1; + + /// Value of ID_AA64DFR2_EL1. + UINT64 IdAA64Dfr2; + + /// Value of ID_AA64FPFR0_EL1. + UINT64 IdAA64Fpfr0; + + /// Value of ID_AA64ISAR0_EL1. + UINT64 IdAA64Isar0; + + /// Value of ID_AA64ISAR1_EL1. + UINT64 IdAA64Isar1; + + /// Value of ID_AA64ISAR2_EL1. + UINT64 IdAA64Isar2; + + /// Value of ID_AA64ISAR3_EL1. + UINT64 IdAA64Isar3; + + /// Value of ID_AA64MMFR0_EL1. + UINT64 IdAA64Mmfr0; + + /// Value of ID_AA64MMFR1_EL1. + UINT64 IdAA64Mmfr1; + + /// Value of ID_AA64MMFR2_EL1. + UINT64 IdAA64Mmfr2; + + /// Value of ID_AA64MMFR3_EL1. + UINT64 IdAA64Mmfr3; + + /// Value of ID_AA64MMFR4_EL1. + UINT64 IdAA64Mmfr4; + + /// Value of ID_AA64PFR0_EL1. + UINT64 IdAA64Pfr0; + + /// Value of ID_AA64PFR1_EL1. + UINT64 IdAA64Pfr1; + + /// Value of ID_AA64PFR2_EL1. + UINT64 IdAA64Pfr2; + + /// Value of ID_AA64SMFR0_EL1. + UINT64 IdAA64Smfr0; + + /// Value of ID_AA64ZFR0_EL1. + UINT64 IdAA64Zfr0; +} AARCH64_PROCESSOR_SPECIFIC_SUB_DATA_ARCH; + /// /// Processor Additional Information(Type 44). /// From 071b0778d9ec2d0f5ccfcbcc9c2e3dc841e31da2 Mon Sep 17 00:00:00 2001 From: Yeoreum Yun Date: Sun, 5 Jul 2026 17:14:32 +0100 Subject: [PATCH 157/406] MdePkg: SMBIOS: add x86(x64) processor specific block structure Add definitions for x86 processor specific block structure. Signed-off-by: Yeoreum Yun --- MdePkg/Include/IndustryStandard/SmBios.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/MdePkg/Include/IndustryStandard/SmBios.h b/MdePkg/Include/IndustryStandard/SmBios.h index 21892e1b33..67a1aa487d 100644 --- a/MdePkg/Include/IndustryStandard/SmBios.h +++ b/MdePkg/Include/IndustryStandard/SmBios.h @@ -3011,6 +3011,25 @@ typedef struct AArch64ProcessorSpecificSubDataArch { UINT64 IdAA64Zfr0; } AARCH64_PROCESSOR_SPECIFIC_SUB_DATA_ARCH; +#define X86_PROCESSOR_BLOCK_IDENTIFIER_USE_CONDITION_DATA (0x01) + +/// +/// X86 (X64) processor specific Block. +/// +typedef struct X86ProcessorSpecificBlock { + /// Identifier. + UINT8 BlockIdentifier; + + /// Length of Processor-specific Block + UINT8 BlockLength; + + /// Revision + UINT16 Revision; + + /// Use Condition Attributes + UINT32 UseConditionAttributes; +} X86_PROCESSOR_SPECIFIC_BLOCK; + /// /// Processor Additional Information(Type 44). /// From 143e4441ed678875f8e499ceb0a801df85dd9dce Mon Sep 17 00:00:00 2001 From: Yeoreum Yun Date: Sun, 5 Jul 2026 18:39:48 +0100 Subject: [PATCH 158/406] MdePkg: SMBIOS: add RiscV processor specific block structure Add definitions for RiscV processor specific block structure. Signed-off-by: Yeoreum Yun --- MdePkg/Include/IndustryStandard/SmBios.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/MdePkg/Include/IndustryStandard/SmBios.h b/MdePkg/Include/IndustryStandard/SmBios.h index 67a1aa487d..a26f3d2f8e 100644 --- a/MdePkg/Include/IndustryStandard/SmBios.h +++ b/MdePkg/Include/IndustryStandard/SmBios.h @@ -3030,6 +3030,26 @@ typedef struct X86ProcessorSpecificBlock { UINT32 UseConditionAttributes; } X86_PROCESSOR_SPECIFIC_BLOCK; +/// +/// RiscV processor specific Block. +/// +typedef struct RiscVProcessorSpecificBlock { + /// Revision + UINT16 Revision; + + /// The ID of this RISC-V hart. + UINT64 HartId; + + /// Vendor ID. + UINT64 VendorId; + + /// Machine Architecture ID. + UINT64 ArchId; + + /// Machine Implementation ID. + UINT64 ImplId; +} RISCV_PROCESSOR_SPECIFIC_BLOCK; + /// /// Processor Additional Information(Type 44). /// From 2d7734c7a8b42e2582026ccc3a8465b356987db6 Mon Sep 17 00:00:00 2001 From: Yeoreum Yun Date: Thu, 2 Jul 2026 11:20:52 +0100 Subject: [PATCH 159/406] DynamicTablesPkg: add Type4 record in to SmbiosHandleMap This is preparatory patch for SMBIOS Type 44 record. SMBIOS Type 44 record have a reference handle of SMBIOS Type 4 record. Therefore, register SMBIOS Type 4 record into SmbiosHandleMap with the Socket Processor Hieararchy token. Signed-off-by: Yeoreum Yun --- .../SmbiosType4Lib/SmbiosType4Generator.c | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c index cffc869e5f..462ebeb8f2 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c @@ -177,6 +177,7 @@ BuildSmbiosType4TableEx ( UINTN CpuIndex2; PROCESSOR_STATUS_DATA *StatusData; PROCESSOR_CHARACTERISTIC_FLAGS *CharacteristicFlags; + CM_OBJECT_TOKEN *CmObjectList; UINT32 ProcHierarchyNodeCount; UINT32 CacheStructCount; @@ -213,7 +214,9 @@ BuildSmbiosType4TableEx ( return EFI_INVALID_PARAMETER; } - *Table = NULL; + *Table = NULL; + *CmObjectToken = NULL; + CmObjectList = NULL; // Get the processor hierarchy info and update the processor topology // structure count with Processor Hierarchy Nodes (Type 0) @@ -265,6 +268,18 @@ BuildSmbiosType4TableEx ( return EFI_INVALID_PARAMETER; } + CmObjectList = AllocateZeroPool (sizeof (CM_OBJECT_TOKEN) * SocketCount); + if (CmObjectList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u tokens.\n", + __func__, + SocketCount + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitErrorBuildSmbiosType4Table; + } + TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRUCTURE *) * SocketCount); if (TableList == NULL) { DEBUG (( @@ -497,7 +512,8 @@ BuildSmbiosType4TableEx ( StringTableFree (&StrTable); - TableList[ObjIndex] = (SMBIOS_STRUCTURE *)SmbiosRecord; + TableList[ObjIndex] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[ObjIndex] = ProcHierarchyNodeList[Index].Token; ObjIndex++; ASSERT (ObjIndex <= SocketCount); } @@ -505,7 +521,7 @@ BuildSmbiosType4TableEx ( ASSERT (ObjIndex == SocketCount); *Table = TableList; - *CmObjectToken = NULL; + *CmObjectToken = CmObjectList; *TableCount = SocketCount; return EFI_SUCCESS; @@ -521,6 +537,10 @@ exitErrorBuildSmbiosType4Table: FreePool (TableList); } + if (CmObjectList != NULL) { + FreePool (CmObjectList); + } + return Status; } From 8a501b5d363adee4bcbda8ca74fdac88f8480c40 Mon Sep 17 00:00:00 2001 From: Yeoreum Yun Date: Thu, 2 Jul 2026 11:20:40 +0100 Subject: [PATCH 160/406] DynamicTablesPkg: add arch common data structure for SMBIOS type 44 record Add SMBIOS type 44 relevant information for common to generate SMBIOS type 44 record. Signed-off-by: Yeoreum Yun --- .../Include/ArchCommonNameSpaceObjects.h | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index d3295ce145..759dedc03b 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -19,6 +19,7 @@ #include #include +#include /** The EARCH_COMMON_OBJECT_ID enum describes the Object IDs in the Arch Common Namespace @@ -91,6 +92,7 @@ typedef enum ArchCommonObjectID { EArchCommonObjMemoryDeviceMappedAddress, ///< 63 - Memory Device Mapped Address Info EArchCommonObjMemoryChannelInfo, ///< 64 - Memory Channel Info EArchCommonObjMemoryChannelDevice, ///< 65 - Memory Channel Device Info + EArchCommonObjProcessorSpecificBlockInfo, ///< 66 - Processor specific data Info EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1705,4 +1707,24 @@ typedef struct CmArchCommonSystemResetInfo { UINT16 Timeout; } CM_ARCH_COMMON_SYSTEM_RESET_INFO; +/** A structure that describes processor specific data. + + SMBIOS Specification v3.9.0 Type 44 + + ID: EArchCommonObjProcessorSpecificBlockInfo +**/ +typedef struct CmArchCommonProcessorSpecificBlockInfo { + /// CM Object Token uniquely identifying this processor specific block info. + CM_OBJECT_TOKEN Token; + + /// Relevant Process Hierarchy Socket Token. + CM_OBJECT_TOKEN ProcSocketToken; + + /// Processor Architecture Type. + PROCESSOR_SPECIFIC_BLOCK_ARCH_TYPE ProcArchType; + + /// Token array for architecture specific Processor Data. + CM_OBJECT_TOKEN ArchProcessorSpecificDataToken; +} CM_ARCH_COMMON_PROCESSOR_SPECIFIC_BLOCK_INFO; + #pragma pack() From caac96b38cf6913f5ddc66408dfaec9a17eb3f67 Mon Sep 17 00:00:00 2001 From: Yeoreum Yun Date: Sun, 5 Jul 2026 16:09:43 +0100 Subject: [PATCH 161/406] DynamicTablesPkg: add arm data structure for SMBIOS type 44 record Add SMBIOS type 44 relevant information for arm to generate SMBIOS type 44 record. Signed-off-by: Yeoreum Yun --- .../Include/ArmNameSpaceObjects.h | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/DynamicTablesPkg/Include/ArmNameSpaceObjects.h b/DynamicTablesPkg/Include/ArmNameSpaceObjects.h index a041afebfd..0bdb12a059 100644 --- a/DynamicTablesPkg/Include/ArmNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArmNameSpaceObjects.h @@ -53,6 +53,8 @@ typedef enum ArmObjectID { EArmObjEtInfo, ///< 23 - Embedded Trace Extension/Module Info EArmObjDmc620PmuSocketInfo, ///< 24 - DMC620 Socket Info EArmObjDmc620PmuRegInfo, ///< 25 - DMC620 PMU Reg Info + EArmObjProcessorSpecificBlockInfo, ///< 26 - Processor Specific Block. + EArmObjProcessorSpecificSubDataArchInfo, ///< 27 - Processor Specific Sub Data (ArchData) EArmObjMax } EARM_OBJECT_ID; @@ -777,4 +779,98 @@ typedef struct CmArmEtInfo { ARM_ET_TYPE EtType; } CM_ARM_ET_INFO; +typedef enum ArmProcessorSpecifcDataSubType { + ArmProcessorSpecificDataSubTypeArch, + /// Define vendor type from here. + ArmProcessorSpecificDataSubTypeMax, +} ARM_PROCESSOR_SPECIFIC_DATA_SUB_TYPE; + +/** A structure that describes the processor specific data. + + ID: EArmObjProcessorSpecificBlockInfo +*/ +typedef struct CmArmProcessorSpecificBlockInfo { + /// Revision for processor specific block + UINT16 Revision; + + /// Vendor ID. + UINT16 VendorId; + + /// Sub type of Processor specific block. + ARM_PROCESSOR_SPECIFIC_DATA_SUB_TYPE SubType; + + /// Sub data token relevant to SubType. + CM_OBJECT_TOKEN SubDataToken; +} CM_ARM_PROCESSOR_SPECIFIC_BLOCK_INFO; + +/** A structure that describes the processor specific sub data + (Architecture Data). + + ID: EArmObjProcessorSpecificSubDataArchInfo +*/ +typedef struct CmArmProcessorSpecificSubDataArchInfo { + /// Version for Processor Specific Sub Data (Arch Data). + UINT16 Version; + + /// Value of ID_AA64AFR0_EL1. + UINT64 IdAA64Afr0; + + /// Value of ID_AA64AFR1_EL1. + UINT64 IdAA64Afr1; + + /// Value of ID_AA64DFR0_EL1. + UINT64 IdAA64Dfr0; + + /// Value of ID_AA64DFR1_EL1. + UINT64 IdAA64Dfr1; + + /// Value of ID_AA64DFR2_EL1. + UINT64 IdAA64Dfr2; + + /// Value of ID_AA64FPFR0_EL1. + UINT64 IdAA64Fpfr0; + + /// Value of ID_AA64ISAR0_EL1. + UINT64 IdAA64Isar0; + + /// Value of ID_AA64ISAR1_EL1. + UINT64 IdAA64Isar1; + + /// Value of ID_AA64ISAR2_EL1. + UINT64 IdAA64Isar2; + + /// Value of ID_AA64ISAR3_EL1. + UINT64 IdAA64Isar3; + + /// Value of ID_AA64MMFR0_EL1. + UINT64 IdAA64Mmfr0; + + /// Value of ID_AA64MMFR1_EL1. + UINT64 IdAA64Mmfr1; + + /// Value of ID_AA64MMFR2_EL1. + UINT64 IdAA64Mmfr2; + + /// Value of ID_AA64MMFR3_EL1. + UINT64 IdAA64Mmfr3; + + /// Value of ID_AA64MMFR4_EL1. + UINT64 IdAA64Mmfr4; + + /// Value of ID_AA64PFR0_EL1. + UINT64 IdAA64Pfr0; + + /// Value of ID_AA64PFR1_EL1. + UINT64 IdAA64Pfr1; + + /// Value of ID_AA64PFR2_EL1. + UINT64 IdAA64Pfr2; + + /// Value of ID_AA64SMFR0_EL1. + UINT64 IdAA64Smfr0; + + /// Value of ID_AA64ZFR0_EL1. + UINT64 IdAA64Zfr0; +} CM_ARM_PROCESSOR_SPECIFIC_SUB_DATA_ARCH_INFO; + #pragma pack() From 455b806260c8b17a90e2ccf9aa01dfe58fc4b6f8 Mon Sep 17 00:00:00 2001 From: Yeoreum Yun Date: Sun, 5 Jul 2026 16:11:34 +0100 Subject: [PATCH 162/406] DynamicTablesPkg: add SMBIOS type 44 generator Add Smbios Type 44 generator with the arm processor specific block support. Signed-off-by: Yeoreum Yun --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../Include/SmbiosTableGenerator.h | 6 +- .../SmbiosType44Lib/SmbiosType44Generator.c | 826 ++++++++++++++++++ .../SmbiosType44Lib/SmbiosType44Generator.h | 171 ++++ .../SmbiosType44Lib/SmbiosType44Lib.inf | 33 + 5 files changed, 1035 insertions(+), 3 deletions(-) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index b8409c1c3a..b483ba95f6 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -123,6 +123,7 @@ DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Lib.inf # AML Fixup (Arm specific) DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtCmn600LibArm/SsdtCmn600LibArm.inf @@ -181,6 +182,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Lib.inf } [Components.RISCV64] diff --git a/DynamicTablesPkg/Include/SmbiosTableGenerator.h b/DynamicTablesPkg/Include/SmbiosTableGenerator.h index 9bdc735ef5..70133554da 100644 --- a/DynamicTablesPkg/Include/SmbiosTableGenerator.h +++ b/DynamicTablesPkg/Include/SmbiosTableGenerator.h @@ -70,9 +70,9 @@ typedef enum StdSmbiosTableGeneratorId { EStdSmbiosTableIdType40, EStdSmbiosTableIdType41, EStdSmbiosTableIdType42, - - // IDs 43 - 125 are reserved - + // IDs 43 are reserved + EStdSmbiosTableIdType44 = (EStdSmbiosTableIdType00 + 44), + // IDs 45 - 125 are reserved EStdSmbiosTableIdType126 = (EStdSmbiosTableIdType00 + 126), EStdSmbiosTableIdType127, EStdSmbiosTableIdMax diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c new file mode 100644 index 0000000000..f3050788b5 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c @@ -0,0 +1,826 @@ +/** @file + SMBIOS Type44 Table Generator. + + Copyright (c) 2026, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include + +#include "SmbiosType44Generator.h" + +/** + SMBIOS Type 44 Generator + + Requirements: + The following Configuration Manager Object(s) are used by this Generator: + - EArchCommonObjProcessorSpecificBlockInfo + - EArmObjProcessorSpecificBlockInfo, + - EArmObjProcessorSpecificSubDataArchInfo, +*/ + +/** + This macro expands to a function that retrieves the Error source infomation + information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjProcessorSpecificBlockInfo, + CM_ARCH_COMMON_PROCESSOR_SPECIFIC_BLOCK_INFO + ); + +GET_OBJECT_LIST ( + EObjNameSpaceArm, + EArmObjProcessorSpecificBlockInfo, + CM_ARM_PROCESSOR_SPECIFIC_BLOCK_INFO + ); + +GET_OBJECT_LIST ( + EObjNameSpaceArm, + EArmObjProcessorSpecificSubDataArchInfo, + CM_ARM_PROCESSOR_SPECIFIC_SUB_DATA_ARCH_INFO + ); + +/** Get Arm Processor Specific sub-data CM objects. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] Token Arm Sub Data Token. + @param [out] ArmSubDataOps Arm Sub Data Operation. + + @retval EFI_SUCCESS + @retval Others Failed to initialise +**/ +STATIC +EFI_STATUS +EFIAPI +GetArmSubDataArchCmObj ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CM_OBJECT_TOKEN Token, + OUT ARM_PROCESSOR_SUB_DATA_OPS *ArmSubDataOps + ) +{ + EFI_STATUS Status; + CM_ARM_PROCESSOR_SPECIFIC_SUB_DATA_ARCH_INFO *Data; + UINT32 DataCount; + + Status = GetEArmObjProcessorSpecificSubDataArchInfo ( + CfgMgrProtocol, + Token, + &Data, + &DataCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Arm processor sub-data arch info. Status = %r\n", + __func__, + Status + )); + return Status; + } + + if (DataCount != 1) { + DEBUG (( + DEBUG_ERROR, + "%a: SubData Token (%lx) should be unique. Count = %d\n", + __func__, + Token, + DataCount + )); + return EFI_INVALID_PARAMETER; + } + + ArmSubDataOps->CmObject = Data; + + return EFI_SUCCESS; +} + +/** Get size of Arm processor arch sub-data. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Data. + @param [out] Size Size of Processor Specific sub-data. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +GetSizeofArmSubDataArch ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT UINT32 *Size + ) +{ + CONST CM_ARM_PROCESSOR_SPECIFIC_SUB_DATA_ARCH_INFO *SubData; + + SubData = CmObject; + + switch (SubData->Version) { + case 1: + *Size = sizeof (AARCH64_PROCESSOR_SPECIFIC_SUB_DATA_ARCH); + break; + default: + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** Add Arm Processor Specific sub-data arch into ARM_PROCESSOR_SPECIFIC_BLOCK. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Data. + @param [out] ProcBlock Arm Processor Specific Block. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +AddArmSubDataArch ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT ARM_PROCESSOR_SPECIFIC_BLOCK *ProcBlock + ) +{ + CONST CM_ARM_PROCESSOR_SPECIFIC_SUB_DATA_ARCH_INFO *SubData; + AARCH64_PROCESSOR_SPECIFIC_SUB_DATA_ARCH *ArchData; + + SubData = CmObject; + ArchData = (AARCH64_PROCESSOR_SPECIFIC_SUB_DATA_ARCH *)(ProcBlock + 1); + + ArchData->Version = SubData->Version; + + switch (SubData->Version) { + case 1: + ArchData->Length = sizeof (AARCH64_PROCESSOR_SPECIFIC_SUB_DATA_ARCH); + ArchData->IdAA64Afr0 = SubData->IdAA64Afr0; + ArchData->IdAA64Afr1 = SubData->IdAA64Afr1; + ArchData->IdAA64Dfr0 = SubData->IdAA64Dfr0; + ArchData->IdAA64Dfr1 = SubData->IdAA64Dfr1; + ArchData->IdAA64Dfr2 = SubData->IdAA64Dfr2; + ArchData->IdAA64Fpfr0 = SubData->IdAA64Fpfr0; + ArchData->IdAA64Isar0 = SubData->IdAA64Isar0; + ArchData->IdAA64Isar1 = SubData->IdAA64Isar1; + ArchData->IdAA64Isar2 = SubData->IdAA64Isar2; + ArchData->IdAA64Isar3 = SubData->IdAA64Isar3; + ArchData->IdAA64Mmfr0 = SubData->IdAA64Mmfr0; + ArchData->IdAA64Mmfr1 = SubData->IdAA64Mmfr1; + ArchData->IdAA64Mmfr2 = SubData->IdAA64Mmfr2; + ArchData->IdAA64Mmfr3 = SubData->IdAA64Mmfr3; + ArchData->IdAA64Mmfr4 = SubData->IdAA64Mmfr4; + ArchData->IdAA64Pfr0 = SubData->IdAA64Pfr0; + ArchData->IdAA64Pfr1 = SubData->IdAA64Pfr1; + ArchData->IdAA64Pfr2 = SubData->IdAA64Pfr2; + ArchData->IdAA64Smfr0 = SubData->IdAA64Smfr0; + ArchData->IdAA64Zfr0 = SubData->IdAA64Zfr0; + break; + default: + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** Operation table to handle Arm Processor specific sub data. +**/ +STATIC ARM_PROCESSOR_SUB_DATA_OPS mArmProcSubDataOps[] = { + { + ArmProcessorSpecificDataSubTypeArch, + GetArmSubDataArchCmObj, + GetSizeofArmSubDataArch, + AddArmSubDataArch, + }, +}; + +/** Get Arm Processor Specific Block CM objects. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] Token Processor Specific Block Token. + @param [out] ProcBlockOps Process Specific Block Operation. + + @retval EFI_SUCCESS + @retval Others Failed to initialise +**/ +STATIC +EFI_STATUS +EFIAPI +GetArmProcBlockCmObj ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CM_OBJECT_TOKEN Token, + OUT PROCESSOR_SPECIFIC_BLOCK_OPS *ProcBlockOps + ) +{ + EFI_STATUS Status; + CM_ARM_PROCESSOR_SPECIFIC_BLOCK_INFO *Block; + UINT32 BlockCount; + + Status = GetEArmObjProcessorSpecificBlockInfo ( + CfgMgrProtocol, + Token, + &Block, + &BlockCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Arm processor data info. Status = %r\n", + __func__, + Status + )); + return Status; + } + + ProcBlockOps->CmObject = Block; + + return EFI_SUCCESS; +} + +/** Get size of Arm Processor Specific Block. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Block. + @param [out] Size Size of Processor Specific Block. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +GetSizeofArmProcBlock ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT UINT32 *Size + ) +{ + EFI_STATUS Status; + CONST CM_ARM_PROCESSOR_SPECIFIC_BLOCK_INFO *Block; + UINT32 BlockSize; + ARM_PROCESSOR_SUB_DATA_OPS *SubDataOps; + UINT32 SubDataSize; + + Block = CmObject; + *Size = 0; + BlockSize = 0; + + if (Block->SubType >= ArmProcessorSpecificDataSubTypeMax) { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid sub-data type\n", + __func__ + )); + return EFI_INVALID_PARAMETER; + } + + switch (Block->Revision) { + case PROCESSOR_SPECIFIC_VERSION_INFO (1, 0): + BlockSize += sizeof (ARM_PROCESSOR_SPECIFIC_BLOCK); + break; + default: + DEBUG (( + DEBUG_ERROR, + "%a: Invalid revision for ARM_PROCESSOR_SPECIFIC_BLOCK: 0x%x\n", + __func__, + Block->Revision + )); + return EFI_INVALID_PARAMETER; + } + + SubDataOps = &mArmProcSubDataOps[Block->SubType]; + + Status = SubDataOps->GetProcSubDataCmObj ( + CfgMgrProtocol, + Block->SubDataToken, + SubDataOps + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to Get sub-data cm object: %r\n", + __func__, + Status + )); + return Status; + } + + Status = SubDataOps->GetSizeofProcSubData ( + CfgMgrProtocol, + SubDataOps->CmObject, + &SubDataSize + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to Get sub-data size: %r\n", + __func__, + Status + )); + return Status; + } + + BlockSize += SubDataSize; + *Size = BlockSize; + + return EFI_SUCCESS; +} + +/** Add Arm Processor Specific Block into SMBIOS record. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Block. + @param [out] SmbiosRecord Type 44 Smbios Record. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +AddArmProcBlock ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT SMBIOS_TABLE_TYPE44 *SmbiosRecord + ) +{ + EFI_STATUS Status; + ARM_PROCESSOR_SPECIFIC_BLOCK *ProcBlock; + CONST CM_ARM_PROCESSOR_SPECIFIC_BLOCK_INFO *Block; + ARM_PROCESSOR_SUB_DATA_OPS *SubDataOps; + UINT32 SubDataSize; + + Block = CmObject; + SubDataOps = &mArmProcSubDataOps[Block->SubType]; + ProcBlock = (ARM_PROCESSOR_SPECIFIC_BLOCK *)(SmbiosRecord + 1); + + Status = SubDataOps->GetSizeofProcSubData ( + CfgMgrProtocol, + SubDataOps->CmObject, + &SubDataSize + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to Get sub-data size: %r\n", + __func__, + Status + )); + return Status; + } + + ProcBlock->Revision = Block->Revision; + ProcBlock->Length = sizeof (ARM_PROCESSOR_SPECIFIC_BLOCK) + SubDataSize; + ProcBlock->VendorId = Block->VendorId; + ProcBlock->SubType = Block->SubType; + + return SubDataOps->AddProcSubData ( + CfgMgrProtocol, + SubDataOps->CmObject, + ProcBlock + ); +} + +/** Operation table to handle Processor Specific Block to generate + Smbios Type 44 record. +**/ +STATIC PROCESSOR_SPECIFIC_BLOCK_OPS mProcSpecificBlockOps[] = { + { + ProcessorSpecificBlockArchTypeReserved, + NULL, + NULL, + NULL, + TRUE, + }, + { + ProcessorSpecificBlockArchTypeIa32, + NULL, + NULL, + NULL, + TRUE, + }, + { + ProcessorSpecificBlockArchTypeX64, + NULL, + NULL, + NULL, + TRUE, + }, + { + ProcessorSpecificBlockArchTypeItanium, + NULL, + NULL, + NULL, + TRUE, + }, + { + ProcessorSpecificBlockArchTypeAarch32, + GetArmProcBlockCmObj, + GetSizeofArmProcBlock, + AddArmProcBlock, + ARM_SMBIOS_TYPE44_RECORD_UNSUPPORTED, + }, + { + ProcessorSpecificBlockArchTypeAarch64, + GetArmProcBlockCmObj, + GetSizeofArmProcBlock, + AddArmProcBlock, + ARM_SMBIOS_TYPE44_RECORD_UNSUPPORTED, + }, + { + ProcessorSpecificBlockArchTypeRiscVRV32, + NULL, + NULL, + NULL, + TRUE, + }, + { + ProcessorSpecificBlockArchTypeRiscVRV64, + NULL, + NULL, + NULL, + TRUE, + }, + { + ProcessorSpecificBlockArchTypeRiscVRV128, + NULL, + NULL, + NULL, + TRUE, + }, +}; + +/** Free any resources allocated when installing SMBIOS Type44 table. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the SMBIOS table. + @param [in] CmObjectToken Pointer to the CM ObjectToken Array. + @param [in] TableCount Number of SMBIOS tables. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +FreeSmbiosType44TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + SMBIOS_STRUCTURE **TableList; + + TableList = *Table; + for (Index = 0; Index < TableCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + if (TableList != NULL) { + FreePool (TableList); + } + + return EFI_SUCCESS; +} + +/** Construct SMBIOS Type 44 Table describing Processor Specific Block. + + If this function allocates any resources then they must be freed + in the FreeXXXXTableResources function. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the SMBIOS table. + @param [out] CmObjectToken Pointer to the CM Object Token Array. + @param [out] TableCount Number of tables installed. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +BuildSmbiosType44TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + SMBIOS_STRUCTURE **TableList; + SMBIOS_TABLE_TYPE44 *SmbiosRecord; + UINTN SmbiosRecordSize; + UINT16 Type4Handle; + UINTN Index; + CM_ARCH_COMMON_PROCESSOR_SPECIFIC_BLOCK_INFO *ProcSpecificBlockList; + UINT32 ProcSpecificBlockCount; + PROCESSOR_SPECIFIC_BLOCK_OPS *ProcBlockOps; + UINT32 ProcBlockSize; + + ASSERT (This != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Table != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (TableCount == NULL) || (CmObjectToken == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a:Invalid Paramater\n ", __func__)); + return EFI_INVALID_PARAMETER; + } + + TableList = NULL; + *Table = NULL; + *TableCount = 0; + + Status = GetEArchCommonObjProcessorSpecificBlockInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &ProcSpecificBlockList, + &ProcSpecificBlockCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get processor hierarchy info. Status = %r\n", + __func__, + Status + )); + return EFI_INVALID_PARAMETER; + } + + TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRUCTURE *) * ProcSpecificBlockCount); + if (TableList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u devices table\n", + __func__, + ProcSpecificBlockCount + )); + Status = EFI_OUT_OF_RESOURCES; + goto ErrorHandler; + } + + for (Index = 0; Index < ProcSpecificBlockCount; Index++) { + if (ProcSpecificBlockList[Index].ProcArchType >= ProcessorSpecificBlockArchTypeLoongArch32) { + DEBUG (( + DEBUG_ERROR, + "%a: Unsupported Type: 0x%x\n", + __func__, + ProcSpecificBlockList[Index].ProcArchType + )); + Status = EFI_INVALID_PARAMETER; + goto ErrorHandler; + } + + ProcBlockOps = &mProcSpecificBlockOps[ProcSpecificBlockList[Index].ProcArchType]; + if (ProcBlockOps->Unsupported) { + DEBUG (( + DEBUG_ERROR, + "%a: Unsupported Type: 0x%x\n", + __func__, + ProcSpecificBlockList[Index].ProcArchType + )); + Status = EFI_INVALID_PARAMETER; + goto ErrorHandler; + } + + Type4Handle = FindSmbiosHandleEx ( + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType04), + ProcSpecificBlockList[Index].ProcSocketToken + ); + if (Type4Handle == SMBIOS_HANDLE_INVALID) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get related Type4 Handle. Token: %lx\n", + __func__, + ProcSpecificBlockList[Index].ProcSocketToken + )); + Status = EFI_INVALID_PARAMETER; + goto ErrorHandler; + } + + Status = ProcBlockOps->GetProcBlockCmObj ( + CfgMgrProtocol, + ProcSpecificBlockList[Index].ArchProcessorSpecificDataToken, + ProcBlockOps + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Processor specific data CM object. Token: %lx\n", + __func__, + ProcSpecificBlockList[Index].ArchProcessorSpecificDataToken + )); + goto ErrorHandler; + } + + Status = ProcBlockOps->GetSizeofProcBlock ( + CfgMgrProtocol, + ProcBlockOps->CmObject, + &ProcBlockSize + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Processor specific data size.\n", + __func__ + )); + goto ErrorHandler; + } + + // Include the empty string table. + SmbiosRecordSize = sizeof (SMBIOS_TABLE_TYPE44) + ProcBlockSize + 2; + + SmbiosRecord = AllocateZeroPool (SmbiosRecordSize); + if (SmbiosRecord == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to allocate SmbiosRecord.\n", + __func__ + )); + Status = EFI_OUT_OF_RESOURCES; + goto ErrorHandler; + } + + // Set up the header + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_ADDITIONAL_INFORMATION; + SmbiosRecord->Hdr.Length = SmbiosRecordSize - 2; + SmbiosRecord->RefHandle = Type4Handle; + SmbiosRecord->ProcessorSpecificBlock.ProcessorArchType = ProcSpecificBlockList[Index].ProcArchType; + SmbiosRecord->ProcessorSpecificBlock.Length = ProcBlockSize; + + Status = ProcBlockOps->AddProcBlock ( + CfgMgrProtocol, + ProcBlockOps->CmObject, + SmbiosRecord + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to add Processor Specific Data into SmbiosRecord Status=%r.\n", + __func__, + Status + )); + FreePool (SmbiosRecord); + goto ErrorHandler; + } + + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + } + + ASSERT (Index == ProcSpecificBlockCount); + + *Table = TableList; + *CmObjectToken = NULL; + *TableCount = ProcSpecificBlockCount; + + return EFI_SUCCESS; + +ErrorHandler: + if (TableList != NULL) { + while (Index-- != 0) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + FreePool (TableList); + } + + return Status; +} + +/** The interface for the SMBIOS Type4 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType44Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType44), + // Generator Description + L"SMBIOS.TYPE44.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_PROCESSOR_ADDITIONAL_INFORMATION, + NULL, + NULL, + // Build table function. + BuildSmbiosType44TableEx, + // Free function. + FreeSmbiosType44TableEx, +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType44LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType44Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 44: Register Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType44LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType44Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 44: Deregister Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h new file mode 100644 index 0000000000..c35a316e96 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h @@ -0,0 +1,171 @@ +/** @file + + Copyright (c) 2026, Arm Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object + - Std or STD - Standard +**/ + +#pragma once + +#if !defined (MDE_CPU_AARCH64) +#define ARM_SMBIOS_TYPE44_RECORD_UNSUPPORTED TRUE +#else +#define ARM_SMBIOS_TYPE44_RECORD_UNSUPPORTED FALSE +#endif + +typedef struct ArmProcessorSubDataOps ARM_PROCESSOR_SUB_DATA_OPS; +typedef struct ProcessorSpecificBlockOps PROCESSOR_SPECIFIC_BLOCK_OPS; + +/** Get Arm Processor Specific sub-data CM objects. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] Token Arm Sub Data Token. + @param [out] ArmSubDataOps Arm Sub Data Operation. + + @retval EFI_SUCCESS + @retval Others Failed to initialise +**/ +typedef +EFI_STATUS +(EFIAPI *GET_ARM_PROCESSOR_SUB_DATA_CM_OBJ)( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CM_OBJECT_TOKEN Token, + OUT ARM_PROCESSOR_SUB_DATA_OPS *ArmSubDataOps + ); + +/** Get size of Arm Processor Specific sub-data. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Data. + @param [out] Size Size of Processor Specific Data or SubData. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +typedef +EFI_STATUS +(EFIAPI *GET_SIZE_OF_ARM_PROCESSOR_SUB_DATA)( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT UINT32 *Size + ); + +/** Add Arm Processor Specific sub-data into ARM_PROCESSOR_SPECIFIC_DATA. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific sub-data. + @param [out] ProcBlock Arm Processor Specific Block. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +typedef +EFI_STATUS +(EFIAPI *ADD_ARM_PROCESSOR_SUB_DATA)( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT ARM_PROCESSOR_SPECIFIC_BLOCK *ProcBlock + ); + +/** Get Architecture Processor Specific Data CM objects. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] Token Processor Specific Block Token. + @param [out] ProcBlockOps Process Specific Block Operation. + + @retval EFI_SUCCESS + @retval Others Failed to initialise +**/ +typedef +EFI_STATUS +(EFIAPI *GET_PROCESSOR_SPECIFIC_BLOCK_CM_OBJ)( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CM_OBJECT_TOKEN Token, + OUT PROCESSOR_SPECIFIC_BLOCK_OPS *ProcBlockOps + ); + +/** Get size of Processor Specific Block. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Data. + @param [out] Size Size of Processor Specific Data. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +typedef +EFI_STATUS +(EFIAPI *GET_SIZE_OF_PROCESSOR_SPECIFIC_BLOCK)( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT UINT32 *Size + ); + +/** Add Processor Specific Block into SMBIOS record. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Data. + @param [out] SmbiosRecord Type 44 Smbios Record. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +typedef +EFI_STATUS +(EFIAPI *ADD_PROCESSOR_SPECIFIC_BLOCK)( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT SMBIOS_TABLE_TYPE44 *SmbiosRecord + ); + +/** A structure that describes operation relevant error source. +*/ +typedef struct ArmProcessorSubDataOps { + /// Processor Specific Block Arch Type. + ARM_PROCESSOR_SPECIFIC_DATA_SUB_TYPE SubDataType; + + /// Get CM objects for Process Specific Data. + GET_ARM_PROCESSOR_SUB_DATA_CM_OBJ GetProcSubDataCmObj; + + /// Get size of Process Specific Data. + GET_SIZE_OF_ARM_PROCESSOR_SUB_DATA GetSizeofProcSubData; + + /// Add Error source to HEST + ADD_ARM_PROCESSOR_SUB_DATA AddProcSubData; + + /// Architecture Processor Specific Data CM object. + VOID *CmObject; +} ARM_PROCESSOR_SUB_DATA_OPS; + +/** A structure that describes operation relevant error source. +*/ +typedef struct ProcessorSpecificBlockOps { + /// Processor Specific Block Arch Type. + PROCESSOR_SPECIFIC_BLOCK_ARCH_TYPE ArchType; + + /// Get CM objects for Process Specific Data. + GET_PROCESSOR_SPECIFIC_BLOCK_CM_OBJ GetProcBlockCmObj; + + /// Get size of Process Specific Data. + GET_SIZE_OF_PROCESSOR_SPECIFIC_BLOCK GetSizeofProcBlock; + + /// Add Error source to HEST + ADD_PROCESSOR_SPECIFIC_BLOCK AddProcBlock; + + /// If FALSE, generate sub-tables for this error source type. + BOOLEAN Unsupported; + + /// Architecture Processor Specific Data CM object. + VOID *CmObject; +} PROCESSOR_SPECIFIC_BLOCK_OPS; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Lib.inf new file mode 100644 index 0000000000..4026a555bf --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Lib.inf @@ -0,0 +1,33 @@ +## @file +# SMBIOS Type44 Table Generator +# +# Copyright (c) 2026, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType44Lib + FILE_GUID = a2b7a71c-789e-11f1-a2e6-f708b60945d7 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType44LibConstructor + DESTRUCTOR = SmbiosType44LibDestructor + +[Sources] + SmbiosType44Generator.c + SmbiosType44Generator.h + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + SmbiosStringTableLib From be3aeb7c333c573901aee43fe2980a4aab0a645d Mon Sep 17 00:00:00 2001 From: Yeoreum Yun Date: Sun, 5 Jul 2026 18:31:58 +0100 Subject: [PATCH 163/406] DynamicTablesPkg: add SMBIOS type 44 for x86(x64) Add Smbios Type 44 generator for the x86(x64) processor specific block support. Signed-off-by: Yeoreum Yun --- .../Include/X64NameSpaceObjects.h | 19 ++- .../SmbiosType44Lib/SmbiosType44Generator.c | 159 ++++++++++++++++-- .../SmbiosType44Lib/SmbiosType44Generator.h | 6 + 3 files changed, 171 insertions(+), 13 deletions(-) diff --git a/DynamicTablesPkg/Include/X64NameSpaceObjects.h b/DynamicTablesPkg/Include/X64NameSpaceObjects.h index d820cb6afc..fb303828cd 100644 --- a/DynamicTablesPkg/Include/X64NameSpaceObjects.h +++ b/DynamicTablesPkg/Include/X64NameSpaceObjects.h @@ -58,7 +58,8 @@ typedef enum X64ObjectID { EX64ObjErrSourceIa32CorrectedMachineCheckInfo, ///< 21 - IA-32 Architecture Corrected Machine Check Error Source info EX64ObjErrSourceIa32DeferredMachineCheckInfo, ///< 22 - IA-32 Architecture Deferred Machine Check Error Source info EX64ObjErrSourceIa32NmiInfo, ///< 23 - IA-32 Architecture Non-Maskable Interrupt - EX64ObjMax ///< 24 - Maximum Object ID + EX64ObjProcessorSpecificBlockInfo, ///< 24 - X86 (X64) Processor Specific Block info + EX64ObjMax ///< 25 - Maximum Object ID } EX64_OBJECT_ID; /** A structure that describes the @@ -434,4 +435,20 @@ typedef struct CmX64Ia32ErrSourceNmiInfo { UINT32 MaxRawDataLength; } CM_X64_ERROR_SOURCE_IA32_NMI_INFO; +/** + A structure that describes X86 (X64) Processor Specific Block Information. + + ID: EX64ObjProcessorSpecificBlockInfo + */ +typedef struct CmX64ProcessorSpecificBlockInfo { + /// Identifier. + UINT8 BlockIdentifier; + + /// Revision + UINT16 Revision; + + /// Use Condition Attributes + UINT32 UseConditionAttributes; +} CM_X64_PROCESSOR_SPECIFIC_BLOCK_INFO; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c index f3050788b5..f617928e58 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c @@ -55,6 +55,12 @@ GET_OBJECT_LIST ( CM_ARM_PROCESSOR_SPECIFIC_SUB_DATA_ARCH_INFO ); +GET_OBJECT_LIST ( + EObjNameSpaceX64, + EX64ObjProcessorSpecificBlockInfo, + CM_X64_PROCESSOR_SPECIFIC_BLOCK_INFO + ); + /** Get Arm Processor Specific sub-data CM objects. @param [in] CfgMgrProtocol Pointer to the Configuration Manager @@ -258,6 +264,51 @@ GetArmProcBlockCmObj ( return EFI_SUCCESS; } +/** Get x86 (x64) Processor Specific Block CM objects. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] Token Processor Specific Block Token. + @param [out] ProcBlockOps Process Specific Block Operation. + + @retval EFI_SUCCESS + @retval Others Failed to initialise +**/ +STATIC +EFI_STATUS +EFIAPI +GetX64ProcBlockCmObj ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CM_OBJECT_TOKEN Token, + OUT PROCESSOR_SPECIFIC_BLOCK_OPS *ProcBlockOps + ) +{ + EFI_STATUS Status; + CM_X64_PROCESSOR_SPECIFIC_BLOCK_INFO *Block; + UINT32 BlockCount; + + Status = GetEX64ObjProcessorSpecificBlockInfo ( + CfgMgrProtocol, + Token, + &Block, + &BlockCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get X64 processor data info. Status = %r\n", + __func__, + Status + )); + return Status; + } + + ProcBlockOps->CmObject = Block; + + return EFI_SUCCESS; +} + /** Get size of Arm Processor Specific Block. @param [in] CfgMgrProtocol Pointer to the Configuration Manager @@ -348,6 +399,57 @@ GetSizeofArmProcBlock ( return EFI_SUCCESS; } +/** Get size of x86 (x64) Processor Specific Block. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Block. + @param [out] Size Size of Processor Specific Block. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +GetSizeofX64ProcBlock ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT UINT32 *Size + ) +{ + CONST CM_X64_PROCESSOR_SPECIFIC_BLOCK_INFO *Block; + + Block = CmObject; + *Size = 0; + + if (Block->BlockIdentifier == X86_PROCESSOR_BLOCK_IDENTIFIER_USE_CONDITION_DATA) { + switch (Block->Revision) { + case PROCESSOR_SPECIFIC_VERSION_INFO (1, 0): + *Size = sizeof (X86_PROCESSOR_SPECIFIC_BLOCK); + break; + default: + DEBUG (( + DEBUG_ERROR, + "%a: Invalid revision for USE_CONDITION_DATA block.: 0x%x\n", + __func__, + Block->Revision + )); + return EFI_INVALID_PARAMETER; + } + } else { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Block Identifier: 0x%x\n", + __func__, + Block->BlockIdentifier + )); + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + /** Add Arm Processor Specific Block into SMBIOS record. @param [in] CfgMgrProtocol Pointer to the Configuration Manager @@ -404,6 +506,39 @@ AddArmProcBlock ( ); } +/** Add x86 (x64) Processor Specific Block into SMBIOS record. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Block. + @param [out] SmbiosRecord Type 44 Smbios Record. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +AddX64ProcBlock ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT SMBIOS_TABLE_TYPE44 *SmbiosRecord + ) +{ + X86_PROCESSOR_SPECIFIC_BLOCK *ProcBlock; + CONST CM_X64_PROCESSOR_SPECIFIC_BLOCK_INFO *Block; + + Block = CmObject; + ProcBlock = (X86_PROCESSOR_SPECIFIC_BLOCK *)(SmbiosRecord + 1); + + ProcBlock->BlockIdentifier = Block->BlockIdentifier; + ProcBlock->BlockLength = sizeof (X86_PROCESSOR_SPECIFIC_BLOCK); + ProcBlock->Revision = Block->Revision; + ProcBlock->UseConditionAttributes = Block->UseConditionAttributes; + + return EFI_SUCCESS; +} + /** Operation table to handle Processor Specific Block to generate Smbios Type 44 record. **/ @@ -417,24 +552,24 @@ STATIC PROCESSOR_SPECIFIC_BLOCK_OPS mProcSpecificBlockOps[] = { }, { ProcessorSpecificBlockArchTypeIa32, - NULL, - NULL, - NULL, - TRUE, + GetX64ProcBlockCmObj, + GetSizeofX64ProcBlock, + AddX64ProcBlock, + X86_SMBIOS_TYPE44_RECORD_UNSUPPORTED, }, { ProcessorSpecificBlockArchTypeX64, - NULL, - NULL, - NULL, - TRUE, + GetX64ProcBlockCmObj, + GetSizeofX64ProcBlock, + AddX64ProcBlock, + X86_SMBIOS_TYPE44_RECORD_UNSUPPORTED, }, { ProcessorSpecificBlockArchTypeItanium, - NULL, - NULL, - NULL, - TRUE, + GetX64ProcBlockCmObj, + GetSizeofX64ProcBlock, + AddX64ProcBlock, + X86_SMBIOS_TYPE44_RECORD_UNSUPPORTED, }, { ProcessorSpecificBlockArchTypeAarch32, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h index c35a316e96..3a54dbdf04 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h @@ -18,6 +18,12 @@ #define ARM_SMBIOS_TYPE44_RECORD_UNSUPPORTED FALSE #endif +#if !defined (MDE_CPU_X64) && !defined (MDE_CPU_IA32) +#define X86_SMBIOS_TYPE44_RECORD_UNSUPPORTED TRUE +#else +#define X86_SMBIOS_TYPE44_RECORD_UNSUPPORTED FALSE +#endif + typedef struct ArmProcessorSubDataOps ARM_PROCESSOR_SUB_DATA_OPS; typedef struct ProcessorSpecificBlockOps PROCESSOR_SPECIFIC_BLOCK_OPS; From d7d5ddef074f3d1295370deaef52aad43ed95dab Mon Sep 17 00:00:00 2001 From: Yeoreum Yun Date: Sun, 5 Jul 2026 18:55:10 +0100 Subject: [PATCH 164/406] DynamicTablesPkg: add SMBIOS type 44 for risc-v Add Smbios Type 44 generator for the risc-v processor specific block support. Signed-off-by: Yeoreum Yun --- .../Include/RiscVNameSpaceObjects.h | 23 +++ .../SmbiosType44Lib/SmbiosType44Generator.c | 150 ++++++++++++++++-- .../SmbiosType44Lib/SmbiosType44Generator.h | 6 + 3 files changed, 167 insertions(+), 12 deletions(-) diff --git a/DynamicTablesPkg/Include/RiscVNameSpaceObjects.h b/DynamicTablesPkg/Include/RiscVNameSpaceObjects.h index 48a3b31b2d..0685dba1c4 100644 --- a/DynamicTablesPkg/Include/RiscVNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/RiscVNameSpaceObjects.h @@ -39,6 +39,7 @@ typedef enum RiscVObjectID { ERiscVObjCmoInfo, ///< 6 - RISC-V CMO Info ERiscVObjMmuInfo, ///< 7 - RISC-V MMU Type Info ERiscVObjTimerInfo, ///< 8 - RISC-V Timer Type Info + ERiscVObjProcessorSpecificBlockInfo, ///< 9 - RISC-V Processor Specific Block Info ERiscVObjMax } ERISCV_OBJECT_ID; @@ -262,4 +263,26 @@ typedef struct CmRiscVTimerInfo { UINT64 TimeBaseFrequency; } CM_RISCV_TIMER_INFO; +/** A structure that describes the + Processor Specific Block for Smbios type 44 record. + + ID: ERiscVObjProcessorSpecificBlockInfo +*/ +typedef struct CmRiscVProcessorSpecificBlockInfo { + /// Revision + UINT16 Revision; + + /// The ID of this RISC-V hart. + UINT64 HartId; + + /// Vendor ID. + UINT64 VendorId; + + /// Machine Architecture ID. + UINT64 ArchId; + + /// Machine Implementation ID. + UINT64 ImplId; +} CM_RISCV_PROCESSOR_SPECIFIC_BLOCK_INFO; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c index f617928e58..f130ef5f0f 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c @@ -61,6 +61,12 @@ GET_OBJECT_LIST ( CM_X64_PROCESSOR_SPECIFIC_BLOCK_INFO ); +GET_OBJECT_LIST ( + EObjNameSpaceRiscV, + ERiscVObjProcessorSpecificBlockInfo, + CM_RISCV_PROCESSOR_SPECIFIC_BLOCK_INFO + ); + /** Get Arm Processor Specific sub-data CM objects. @param [in] CfgMgrProtocol Pointer to the Configuration Manager @@ -309,6 +315,51 @@ GetX64ProcBlockCmObj ( return EFI_SUCCESS; } +/** Get RiscV Processor Specific Block CM objects. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] Token Processor Specific Block Token. + @param [out] ProcBlockOps Process Specific Block Operation. + + @retval EFI_SUCCESS + @retval Others Failed to initialise +**/ +STATIC +EFI_STATUS +EFIAPI +GetRiscVProcBlockCmObj ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CM_OBJECT_TOKEN Token, + OUT PROCESSOR_SPECIFIC_BLOCK_OPS *ProcBlockOps + ) +{ + EFI_STATUS Status; + CM_RISCV_PROCESSOR_SPECIFIC_BLOCK_INFO *Block; + UINT32 BlockCount; + + Status = GetERiscVObjProcessorSpecificBlockInfo ( + CfgMgrProtocol, + Token, + &Block, + &BlockCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get risc-v processor data info. Status = %r\n", + __func__, + Status + )); + return Status; + } + + ProcBlockOps->CmObject = Block; + + return EFI_SUCCESS; +} + /** Get size of Arm Processor Specific Block. @param [in] CfgMgrProtocol Pointer to the Configuration Manager @@ -450,6 +501,47 @@ GetSizeofX64ProcBlock ( return EFI_SUCCESS; } +/** Get size of RiscV Processor Specific Block. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Block. + @param [out] Size Size of Processor Specific Block. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +GetSizeofRiscVProcBlock ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT UINT32 *Size + ) +{ + CONST CM_RISCV_PROCESSOR_SPECIFIC_BLOCK_INFO *Block; + + Block = CmObject; + *Size = 0; + + switch (Block->Revision) { + case PROCESSOR_SPECIFIC_VERSION_INFO (1, 0): + *Size = sizeof (RISCV_PROCESSOR_SPECIFIC_BLOCK); + break; + default: + DEBUG (( + DEBUG_ERROR, + "%a: Invalid revision for risc-v block.: 0x%x\n", + __func__, + Block->Revision + )); + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + /** Add Arm Processor Specific Block into SMBIOS record. @param [in] CfgMgrProtocol Pointer to the Configuration Manager @@ -539,6 +631,40 @@ AddX64ProcBlock ( return EFI_SUCCESS; } +/** Add risc-v Processor Specific Block into SMBIOS record. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] CmObject CM object of Processor Specific Block. + @param [out] SmbiosRecord Type 44 Smbios Record. + + @retval EFI_SUCCESS + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +AddRiscVProcBlock ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CONST VOID *CmObject, + OUT SMBIOS_TABLE_TYPE44 *SmbiosRecord + ) +{ + RISCV_PROCESSOR_SPECIFIC_BLOCK *ProcBlock; + CONST CM_RISCV_PROCESSOR_SPECIFIC_BLOCK_INFO *Block; + + Block = CmObject; + ProcBlock = (RISCV_PROCESSOR_SPECIFIC_BLOCK *)(SmbiosRecord + 1); + + ProcBlock->Revision = Block->Revision; + ProcBlock->HartId = Block->HartId; + ProcBlock->VendorId = Block->VendorId; + ProcBlock->ArchId = Block->ArchId; + ProcBlock->ImplId = Block->ImplId; + + return EFI_SUCCESS; +} + /** Operation table to handle Processor Specific Block to generate Smbios Type 44 record. **/ @@ -587,24 +713,24 @@ STATIC PROCESSOR_SPECIFIC_BLOCK_OPS mProcSpecificBlockOps[] = { }, { ProcessorSpecificBlockArchTypeRiscVRV32, - NULL, - NULL, - NULL, - TRUE, + GetRiscVProcBlockCmObj, + GetSizeofRiscVProcBlock, + AddRiscVProcBlock, + RISCV_SMBIOS_TYPE44_RECORD_UNSUPPORTED, }, { ProcessorSpecificBlockArchTypeRiscVRV64, - NULL, - NULL, - NULL, - TRUE, + GetRiscVProcBlockCmObj, + GetSizeofRiscVProcBlock, + AddRiscVProcBlock, + RISCV_SMBIOS_TYPE44_RECORD_UNSUPPORTED, }, { ProcessorSpecificBlockArchTypeRiscVRV128, - NULL, - NULL, - NULL, - TRUE, + GetRiscVProcBlockCmObj, + GetSizeofRiscVProcBlock, + AddRiscVProcBlock, + RISCV_SMBIOS_TYPE44_RECORD_UNSUPPORTED, }, }; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h index 3a54dbdf04..05a654a9f2 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.h @@ -24,6 +24,12 @@ #define X86_SMBIOS_TYPE44_RECORD_UNSUPPORTED FALSE #endif +#if !defined (MDE_CPU_RISCV64) +#define RISCV_SMBIOS_TYPE44_RECORD_UNSUPPORTED TRUE +#else +#define RISCV_SMBIOS_TYPE44_RECORD_UNSUPPORTED FALSE +#endif + typedef struct ArmProcessorSubDataOps ARM_PROCESSOR_SUB_DATA_OPS; typedef struct ProcessorSpecificBlockOps PROCESSOR_SPECIFIC_BLOCK_OPS; From 49cbe1d43877b8f0784e2fe87b5a55b3fbe60bb2 Mon Sep 17 00:00:00 2001 From: zhuyunfei Date: Thu, 2 Jul 2026 19:28:26 +0800 Subject: [PATCH 165/406] OvmfPkg/LoongArchVirt: Add TPM support in platform description files Add library mappings, PCDs, and component entries for Tcg2Pei, Tcg2ConfigPei, Tcg2PlatformPei, Tcg2Dxe, and Tcg2ConfigDxe when TPM2_ENABLE is TRUE. Also include the corresponding firmware volume sections. Signed-off-by: zhuyunfei Signed-off-by: gaoqihang Reviewed-by: qiandongyan Reviewed-by: lichao --- OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc | 78 ++++++++++++++++++++- OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf | 15 ++++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc index fc71a80767..7b49e53d65 100644 --- a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc +++ b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc @@ -149,7 +149,16 @@ SerializeVariablesLib | OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf CustomizedDisplayLib | MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf DebugPrintErrorLevelLib | MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf - TpmMeasurementLib | MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tpm2HelpLib|SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf + Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf + TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf + TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/PeiDxeTpmPlatformHierarchyLib.inf +!else + TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf + TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLibNull/PeiDxeTpmPlatformHierarchyLib.inf +!endif !if $(SECURE_BOOT_ENABLE) == TRUE PlatformSecureLib | OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf AuthVariableLib | SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf @@ -240,6 +249,10 @@ QemuFwCfgLib | OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgMmioPeiLib.inf PlatformHookLib | OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf PerformanceLib | MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf +!if $(TPM2_ENABLE) == TRUE + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf +!endif [LibraryClasses.common.PEIM] HobLib | MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -259,6 +272,10 @@ CpuMmuInitLib | OvmfPkg/LoongArchVirt/Library/CpuMmuInitLib/CpuMmuInitLib.inf MpInitLib | UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf PlatformHookLib | OvmfPkg/LoongArchVirt/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf +!if $(TPM2_ENABLE) == TRUE + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf +!endif [LibraryClasses.common.DXE_CORE] HobLib | MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf @@ -315,6 +332,9 @@ PciPcdProducerLib | OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf AcpiPlatformLib | OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf MpInitLib | UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf +!endif [LibraryClasses.common.UEFI_APPLICATION] PcdLib | MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -487,12 +507,28 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion|0x0300 gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0 gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|TRUE + # + # TPM2 support + # +!if $(TPM2_ENABLE) == TRUE + gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress|0x0 + gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid|{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} + gEfiSecurityPkgTokenSpaceGuid.PcdTpm2HashMask|0 +!endif [PcdsDynamicHii] gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|3 - +!if $(TPM2_CONFIG_ENABLE) == TRUE + gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer|L"TCG2_VERSION"|gTcg2ConfigFormSetGuid|0x0|"1.3"|NV,BS + gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableRev|L"TCG2_VERSION"|gTcg2ConfigFormSetGuid|0x8|3|NV,BS +!endif [PcdsPatchableInModule.common] gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x0 +!if $(TPM2_ENABLE) == FALSE + # make this PCD patchable instead of dynamic when TPM support is not enabled + # this permits setting the PCD in unreachable code without pulling in dynamic PCD support + gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress|0x0 +!endif [Components] @@ -500,6 +536,24 @@ # SEC Phase modules # OvmfPkg/LoongArchVirt/Sec/SecMain.inf +!if $(TPM2_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { + + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + NULL|SecurityPkg/Library/HashInstanceLibSha384/HashInstanceLibSha384.inf + NULL|SecurityPkg/Library/HashInstanceLibSha512/HashInstanceLibSha512.inf + NULL|SecurityPkg/Library/HashInstanceLibSm3/HashInstanceLibSm3.inf + } + SecurityPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.inf { + + TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/PeiDxeTpmPlatformHierarchyLib.inf + } + OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +!endif # # PEI Phase modules @@ -747,3 +801,23 @@ gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } + + # + # TPM2 support + # +!if $(TPM2_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + NULL|SecurityPkg/Library/HashInstanceLibSha384/HashInstanceLibSha384.inf + NULL|SecurityPkg/Library/HashInstanceLibSha512/HashInstanceLibSha512.inf + NULL|SecurityPkg/Library/HashInstanceLibSm3/HashInstanceLibSm3.inf + } +!if $(TPM2_CONFIG_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf +!endif +!endif diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf index 5f584aa129..f11cb8e553 100644 --- a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf +++ b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf @@ -210,6 +210,15 @@ INF ShellPkg/Application/Shell/Shell.inf INF MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf INF ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf +# +# TPM support +# +!if $(TPM2_ENABLE) == TRUE + INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +!if $(TPM2_CONFIG_ENABLE) == TRUE + INF SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf +!endif +!endif ##################################################################################################### [FV.FVMAIN_COMPACT] FvNameGuid = af8c3fe8-9ce8-4548-884a-e3f4dd91f040 @@ -249,6 +258,12 @@ INF OvmfPkg/LoongArchVirt/Sec/SecMain.inf INF MdeModulePkg/Core/Pei/PeiMain.inf INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf INF OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf + +!if $(TPM2_ENABLE) == TRUE + INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf + INF SecurityPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.inf + INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +!endif INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf INF MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.inf From f49f209c4f4c8b817d290f78e785099e8c51589f Mon Sep 17 00:00:00 2001 From: zhuyunfei Date: Thu, 2 Jul 2026 19:31:39 +0800 Subject: [PATCH 166/406] OvmfPkg/LoongArchVirt: Add TPM platform PEI support Implement SetupTPMResources() in PlatformPei to: - Parse QEMU FDT for 'tcg,tpm-tis-mmio' node - Translate MMIO address via platform-bus ranges - Create MMIO resource HOB and set PcdTpmBaseAddress - Install gOvmfTpmDiscoveredPpi to trigger Tcg2ConfigPei Also add SecurityPkg.dec dependency and required PPI/PCD references, and add LOONGARCH64 depex for Tcg2ConfigPei. Signed-off-by: zhuyunfei Signed-off-by: gaoqihang Reviewed-by: qiandongyan Reviewed-by: lichao --- OvmfPkg/LoongArchVirt/PlatformPei/Platform.c | 187 +++++++++++++++++- .../LoongArchVirt/PlatformPei/PlatformPei.inf | 3 + OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 5 +- 3 files changed, 190 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/Platform.c b/OvmfPkg/LoongArchVirt/PlatformPei/Platform.c index 8d7149e458..eae5030561 100644 --- a/OvmfPkg/LoongArchVirt/PlatformPei/Platform.c +++ b/OvmfPkg/LoongArchVirt/PlatformPei/Platform.c @@ -58,6 +58,12 @@ CONST EFI_PEI_PPI_DESCRIPTOR mPpiListBootMode = { STATIC EFI_BOOT_MODE mBootMode = BOOT_WITH_FULL_CONFIGURATION; +CONST EFI_PEI_PPI_DESCRIPTOR mTpm2DiscoveredPpi = { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gOvmfTpmDiscoveredPpiGuid, + NULL +}; + /** Create system type memory range hand off block. @@ -311,6 +317,185 @@ ReportSystemMemorySize ( )); } +/** + Set up TPM resources from FDT. + + @param FdtBase Fdt base address + +**/ +STATIC +VOID +SetupTPMResources ( + VOID *FdtBase + ) +{ + INT32 Node, Prev; + INT32 Parent, Depth; + CONST CHAR8 *Compatible; + CONST CHAR8 *CompItem; + INT32 Len; + INT32 RangesLen; + CONST UINT8 *RegProp; + CONST UINT32 *RangesProp; + UINT64 TpmBase; + UINT64 TpmBaseSize; + + // + // Empty TpmBaseSize indicates no TPM found. + // + TpmBase = 0; + TpmBaseSize = 0; + + // + // Set Parent to suppress incorrect compiler/analyzer warnings. + // + Parent = 0; + + DEBUG (( + DEBUG_INFO, + "%a: FdtBase=%p, FdtCheckHeader=%d\n", + __func__, + FdtBase, + FdtCheckHeader (FdtBase) + )); + + for (Prev = Depth = 0; ; Prev = Node) { + Node = FdtNextNode (FdtBase, Prev, &Depth); + if (Node < 0) { + DEBUG (( + DEBUG_INFO, + "%a: FdtNextNode returned %d, stopping\n", + __func__, + Node + )); + break; + } + + if (Depth == 1) { + Parent = Node; + } + + Compatible = FdtGetProp (FdtBase, Node, "compatible", &Len); + if (Compatible != NULL) { + DEBUG (( + DEBUG_INFO, + "%a: depth=%d node=%d compat=%a (len=%d)\n", + __func__, + Depth, + Node, + Compatible, + Len + )); + } else { + DEBUG (( + DEBUG_INFO, + "%a: depth=%d node=%d (no compatible)\n", + __func__, + Depth, + Node + )); + } + + // + // Iterate over the NULL-separated items in the compatible string + // + for (CompItem = Compatible; CompItem != NULL && CompItem < Compatible + Len; + CompItem += 1 + AsciiStrLen (CompItem)) + { + if (AsciiStrCmp (CompItem, "tcg,tpm-tis-mmio") == 0) { + DEBUG (( + DEBUG_INFO, + "%a: found tpm node at depth %d\n", + __func__, + Depth + )); + RegProp = FdtGetProp (FdtBase, Node, "reg", &Len); + DEBUG (( + DEBUG_INFO, + "%a: reg len=%d\n", + __func__, + Len + )); + ASSERT (Len == 8 || Len == 16); + if (Len == 8) { + TpmBase = Fdt32ToCpu (*(UINT32 *)RegProp); + TpmBaseSize = Fdt32ToCpu (*(UINT32 *)((UINT8 *)RegProp + 4)); + } else if (Len == 16) { + TpmBase = Fdt64ToCpu (ReadUnaligned64 ((UINT64 *)RegProp)); + TpmBaseSize = Fdt64ToCpu (ReadUnaligned64 ((UINT64 *)((UINT8 *)RegProp + 8))); + } + + if (Depth > 1) { + // + // QEMU/mach-virt may put the TPM on the platform bus, in which case + // we have to take its 'ranges' property into account to translate the + // MMIO address. This consists of a + // tuple, where the child base and the size use the same number of + // cells as the 'reg' property above, and the parent base uses 2 cells + // + RangesProp = FdtGetProp (FdtBase, Parent, "ranges", &RangesLen); + ASSERT (RangesProp != NULL); + + // + // a plain 'ranges' attribute without a value implies a 1:1 mapping + // + if (RangesLen != 0) { + // + // assume a single translated range with 2 cells for the parent base + // + if (RangesLen != Len + 2 * sizeof (UINT32)) { + DEBUG (( + DEBUG_WARN, + "%a: 'ranges' property has unexpected size %d\n", + __func__, + RangesLen + )); + break; + } + + if (Len == 8) { + TpmBase -= Fdt32ToCpu (RangesProp[0]); + } else { + TpmBase -= Fdt64ToCpu (ReadUnaligned64 ((UINT64 *)RangesProp)); + } + + // + // advance RangesProp to the parent bus address + // + RangesProp = (UINT32 *)((UINT8 *)RangesProp + Len / 2); + TpmBase += Fdt64ToCpu (ReadUnaligned64 ((UINT64 *)RangesProp)); + } + } + + break; + } + } + } + + DEBUG (( + DEBUG_INFO, + "%a: TpmBase=0x%lx TpmBaseSize=0x%lx\n", + __func__, + TpmBase, + TpmBaseSize + )); + + if (TpmBaseSize > 0) { + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_MAPPED_IO, + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED, + TpmBase, + ALIGN_VALUE (TpmBaseSize, EFI_PAGE_SIZE) + ); + + ASSERT_EFI_ERROR ((EFI_STATUS)PcdSet64S (PcdTpmBaseAddress, TpmBase)); + PeiServicesInstallPpi (&mTpm2DiscoveredPpi); + } +} + /** Perform Platform PEI initialization. @@ -351,7 +536,7 @@ InitializePlatform ( MiscInitialization (); AddFdtHob (); - + SetupTPMResources ((VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress)); // // Initialization MMU // diff --git a/OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf b/OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf index 01281a7e47..0104e98dc7 100644 --- a/OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/LoongArchVirt/PlatformPei/PlatformPei.inf @@ -30,9 +30,11 @@ MdeModulePkg/MdeModulePkg.dec OvmfPkg/OvmfPkg.dec UefiCpuPkg/UefiCpuPkg.dec + SecurityPkg/SecurityPkg.dec [Ppis] gEfiPeiMasterBootModePpiGuid + gOvmfTpmDiscoveredPpiGuid [Guids] gEfiMemoryTypeInformationGuid @@ -58,6 +60,7 @@ gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeAllocationPadding gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask + gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase diff --git a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf index a26f35b236..81c890b691 100644 --- a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +++ b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf @@ -50,8 +50,5 @@ [Depex.IA32, Depex.X64] gOvmfTpmMmioAccessiblePpiGuid -[Depex.AARCH64] - gOvmfTpmDiscoveredPpiGuid - -[Depex.RISCV64] +[Depex.AARCH64, Depex.RISCV64, Depex.LOONGARCH64] gOvmfTpmDiscoveredPpiGuid From a7d88f37ec5ccb9d5de6636f116a8a0866435551 Mon Sep 17 00:00:00 2001 From: Mike Beaton Date: Wed, 8 Jul 2026 21:54:36 +0100 Subject: [PATCH 167/406] Maintainers: Remove myself as reviewer for now Signed-off-by: Mike Beaton --- Maintainers.txt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Maintainers.txt b/Maintainers.txt index da1bb4c640..c7a5c4d2e5 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -187,7 +187,6 @@ M: Guillermo Antonio Palomino Sosa [gapalo M: Ashraf Ali S [AshrafAliS] R: Yuwei Chen [YuweiChen1110] R: Poncho Figueroa [ponchofigueroa] -R: Mike Beaton [mikebeaton] BaseTools: Plugins F: BaseTools/Plugin/ @@ -286,7 +285,6 @@ F: MdeModulePkg/Universal/DriverHealthManagerDxe/ F: MdeModulePkg/Universal/LoadFileOnFv2/ F: MdeModulePkg/Universal/SecurityStubDxe/Defer3rdPartyImageLoad.* R: Dandan Bi [dandanbi] -R: Mike Beaton [mikebeaton] MdeModulePkg: Core services (PEI, DXE and Runtime) modules F: MdeModulePkg/*Mem*/ @@ -315,7 +313,6 @@ F: MdeModulePkg/Universal/SecurityStubDxe/SecurityStub.c M: Oliver Smith-Denny [os-d] R: Liming Gao [lgao4] R: Khalid Ali [khaliid2040] -R: Mike Beaton [mikebeaton] MdeModulePkg: Device and Peripheral modules F: MdeModulePkg/*PciHostBridge*/ @@ -367,7 +364,6 @@ F: MdeModulePkg/Universal/DisplayEngineDxe/ F: MdeModulePkg/Universal/DriverSampleDxe/ F: MdeModulePkg/Universal/SetupBrowserDxe/ R: Dandan Bi [dandanbi] -R: Mike Beaton [mikebeaton] MdeModulePkg: Management Mode (MM, SMM) modules F: MdeModulePkg/*Smi*/ @@ -398,7 +394,6 @@ F: MdeModulePkg/Include/Guid/SystemNvDataGuid.h F: MdeModulePkg/Include/Protocol/SwapAddressRange.h F: MdeModulePkg/Universal/FaultTolerantWrite*/ R: Liming Gao [lgao4] -R: Mike Beaton [mikebeaton] MdeModulePkg: Universal Payload definitions F: MdeModulePkg/Include/UniversalPayload/ @@ -492,7 +487,6 @@ F: NetworkPkg/ W: https://www.tianocore.org/tianocore-wiki.github.io/platforms-packages/core-packages/network_pkg.html R: Saloni Kasbekar [SaloniKasbekar] R: Zachary Clark-williams [Zclarkwilliams] -R: Mike Beaton [mikebeaton] OvmfPkg F: OvmfPkg/ @@ -500,7 +494,6 @@ W: http://www.tianocore.org/ovmf/ M: Ard Biesheuvel [ardbiesheuvel] M: Jiewen Yao [jyao1] R: Gerd Hoffmann [kraxel] -R: Mike Beaton [mikebeaton] S: Maintained OvmfPkg: bhyve-related modules From 550171fac5f8a01a15de59ae46d206ac027554fe Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Mon, 6 Jul 2026 11:15:35 -0400 Subject: [PATCH 168/406] BREAKING-CHANGES.md: Add initial file RFC 0003 - "Breaking Change and Release Process for EDK II" defined a new process for how breaking changes are tracked and documented in EDK II. This commit adds an empty BREAKING-CHANGES.md file to the root of the EDK II repository with sections for the current and next two stable tags so the file can be updated in accordance with the RFC. I add myself as a reviewer of the file to monitor the initial set of updates against the RFC process. Signed-off-by: Michael Kubacki --- BREAKING-CHANGES.md | 79 +++++++++++++++++++++++++++++++++++++++++++++ Maintainers.txt | 4 +++ 2 files changed, 83 insertions(+) create mode 100644 BREAKING-CHANGES.md diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md new file mode 100644 index 0000000000..4191162a37 --- /dev/null +++ b/BREAKING-CHANGES.md @@ -0,0 +1,79 @@ +# EDK II Breaking Changes + +This file is the in-tree record of breaking changes in EDK II. Each breaking change has a single entry that is added +in the pull request that introduces the change and updated in any later pull request that changes its state. The file +is organized by stable tag milestone with most recent first. + +For the full process, including the breaking change taxonomy, deprecation timeline, required entry content, and GitHub +issue requirements, see the [Breaking Change and Release Process for EDK II](https://raw.githubusercontent.com/tianocore/tianocore-wiki.github.io/refs/heads/main/rfc/text/0003-edk2-breaking-change-and-release-process.md) +RFC. + +## edk2-stable202702 + +- Milestone: [edk2-stable202702](https://github.com/tianocore/edk2/milestone/7) + +### edk2-stable202702: Source-Level Breaking Changes + +#### edk2-stable202702: Changes with Removal + +None + +#### edk2-stable202702: Changes without Removal + +None + +### edk2-stable202702: Behavioral Breaking Changes + +None + +### edk2-stable202702: Build-System Breaking Changes + +None + +--- + +## edk2-stable202611 + +- Milestone: [edk2-stable202611](https://github.com/tianocore/edk2/milestone/6) + +### edk2-stable202611: Source-Level Breaking Changes + +#### edk2-stable202611: Changes with Removal + +None + +#### edk2-stable202611: Changes without Removal + +None + +### edk2-stable202611: Behavioral Breaking Changes + +None + +### edk2-stable202611: Build-System Breaking Changes + +None + +--- + +## edk2-stable202608 + +- Milestone: [edk2-stable202608](https://github.com/tianocore/edk2/milestone/5) + +### edk2-stable202608: Source-Level Breaking Changes + +#### edk2-stable202608: Changes with Removal + +None + +#### edk2-stable202608: Changes without Removal + +None + +### edk2-stable202608: Behavioral Breaking Changes + +None + +### edk2-stable202608: Build-System Breaking Changes + +None diff --git a/Maintainers.txt b/Maintainers.txt index c7a5c4d2e5..2fcb84e8f1 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -150,6 +150,10 @@ R: Liming Gao [lgao4] EDK II Contributed Files: ------------------------- +Breaking Changes Documentation +F: BREAKING-CHANGES.md +R: Michael Kubacki [makubacki] + VS Code PR Dashboard Notebook F: contrib/PullRequests.github-issues M: Michael Kubacki [makubacki] From 0b68bfa540da9e360632dcc85417369acc382ea7 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Mon, 6 Jul 2026 11:48:06 -0400 Subject: [PATCH 169/406] .github: Add RFC 0003 Breaking Change and Release Process files Adds the GitHub issue template files for the EDK II Breaking Change and Release Process, as well as a link to the process in the pull request template. Signed-off-by: Michael Kubacki --- .../breaking_change_deprecation.yml | 32 ++++++++++++ .../breaking_change_removal.yml | 31 +++++++++++ .../breaking_change_tracking.yml | 51 +++++++++++++++++++ .github/pull_request_template.md | 1 + 4 files changed, 115 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/breaking_change_deprecation.yml create mode 100644 .github/ISSUE_TEMPLATE/breaking_change_removal.yml create mode 100644 .github/ISSUE_TEMPLATE/breaking_change_tracking.yml diff --git a/.github/ISSUE_TEMPLATE/breaking_change_deprecation.yml b/.github/ISSUE_TEMPLATE/breaking_change_deprecation.yml new file mode 100644 index 0000000000..714ff86f23 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/breaking_change_deprecation.yml @@ -0,0 +1,32 @@ +# TianoCore edk2 GitHub Breaking Change Deprecation Issue Template +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +name: 💥 Breaking Change (Deprecation) +description: Subissue tracking the start of the deprecation active period for a breaking change +title: "[Breaking Change Deprecation]: " +labels: ["impact:breaking-change", "deprecation:active"] + +body: + - type: markdown + attributes: + value: | + 👋 This is a subissue of a breaking change Tracking Issue, following the + [Breaking Change and Release Process for EDK II](https://raw.githubusercontent.com/tianocore/tianocore-wiki.github.io/refs/heads/main/rfc/text/0003-edk2-breaking-change-and-release-process.md). + + It tracks the start of the deprecation active period. It is closed when the deprecation PR merges and the + compatibility window opens. Detailed documentation for the change lives only in the `BREAKING-CHANGES.md` + entry. + + - type: textarea + id: special_notes + attributes: + label: Special Notes + description: | + Any special notes about the deprecation portion of the process (for example, details about how the affected + item is marked as deprecated). If there are no special notes, enter exactly: `Breaking change process issue.` + value: "Breaking change process issue." + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/breaking_change_removal.yml b/.github/ISSUE_TEMPLATE/breaking_change_removal.yml new file mode 100644 index 0000000000..7b0912e32f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/breaking_change_removal.yml @@ -0,0 +1,31 @@ +# TianoCore edk2 GitHub Breaking Change Removal Issue Template +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +name: 💥 Breaking Change (Removal) +description: Subissue tracking the eventual removal of a deprecated item +title: "[Breaking Change Removal]: <title>" +labels: ["impact:breaking-change", "deprecation:removal"] + +body: + - type: markdown + attributes: + value: | + 👋 This is a subissue of a breaking change Tracking Issue, following the + [Breaking Change and Release Process for EDK II](https://raw.githubusercontent.com/tianocore/tianocore-wiki.github.io/refs/heads/main/rfc/text/0003-edk2-breaking-change-and-release-process.md). + + It tracks the eventual removal of the deprecated item. It is closed when the item is removed from the + codebase. Detailed documentation for the change lives only in the `BREAKING-CHANGES.md` entry. + + - type: textarea + id: special_notes + attributes: + label: Special Notes + description: | + Any special notes about the removal portion of the process. If there are no special notes, enter exactly: + `Breaking change process issue.` + value: "Breaking change process issue." + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/breaking_change_tracking.yml b/.github/ISSUE_TEMPLATE/breaking_change_tracking.yml new file mode 100644 index 0000000000..807be1aadc --- /dev/null +++ b/.github/ISSUE_TEMPLATE/breaking_change_tracking.yml @@ -0,0 +1,51 @@ +# TianoCore edk2 GitHub Breaking Change Tracking Issue Template +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +name: 💥 Breaking Change (Tracking) +description: Central tracking issue for a breaking change +title: "[Breaking Change Tracking]: <title>" +labels: ["impact:breaking-change", "deprecation:tracking"] + +body: + - type: markdown + attributes: + value: | + 👋 Use this issue to track a breaking change following the + [Breaking Change and Release Process for EDK II](https://raw.githubusercontent.com/tianocore/tianocore-wiki.github.io/refs/heads/main/rfc/text/0003-edk2-breaking-change-and-release-process.md). + + **Read that process before filing this issue.** + + This is the central Tracking Issue. The Deprecation Issue and Removal Issue (when applicable) are created as + subissues of this one. The detailed documentation for the change (motivation, what replaces it, migration + guidance, removal target, etc.) is described in the `BREAKING-CHANGES.md` entry and should not be duplicated + here. + + - type: textarea + id: summary + attributes: + label: Summary + description: A high-level summary of the breaking change (a few sentences). + validations: + required: true + + - type: input + id: breaking_changes_entry + attributes: + label: BREAKING-CHANGES.md Entry + description: Link to the corresponding entry in `BREAKING-CHANGES.md`. May be updated after issue creation. + placeholder: https://github.com/tianocore/edk2/blob/master/BREAKING-CHANGES.md#<anchor> + validations: + required: true + + - type: textarea + id: additional_info + attributes: + label: Additional Information + description: | + Any other relevant information that is not already captured in the `BREAKING-CHANGES.md` entry. Do not + duplicate content from that entry here. + validations: + required: false diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 3ecabed46b..6f9b3bef5f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -11,6 +11,7 @@ - [ ] Breaking change? - **Breaking change** - Does this PR cause a break in build or boot behavior? - Examples: Does it add a new library class or move a module to a different repo. + - If checked, follow the [Breaking Change and Release Process](https://raw.githubusercontent.com/tianocore/tianocore-wiki.github.io/refs/heads/main/rfc/text/0003-edk2-breaking-change-and-release-process.md). - [ ] Impacts security? - **Security** - Does this PR have a direct security impact? - Examples: Crypto algorithm change or buffer overflow fix. From 17ea1f35996f863ee71df04fbd9059d25bce8c56 Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Mon, 6 Jul 2026 11:38:09 -0400 Subject: [PATCH 170/406] CONTRIBUTING.md: Add breaking change process link Adds a reference to the Breaking Change and Release Process for EDK II in CONTRIBUTING.md, so that contributors are aware of the process when introducing breaking changes. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0a85f28a35..e1fc3cb26b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,3 +3,7 @@ Contributor documentation is maintained on the wiki: [EDK II Development Process](https://www.tianocore.org/tianocore-wiki.github.io/development/contribution-guides/edk_ii_development_process.html) + +Introducing a breaking change? Follow the +[Breaking Change and Release Process for EDK II](https://raw.githubusercontent.com/tianocore/tianocore-wiki.github.io/refs/heads/main/rfc/text/0003-edk2-breaking-change-and-release-process.md) +and record it in [`BREAKING-CHANGES.md`](BREAKING-CHANGES.md). From 10aef94c8b963099ece9c1a8dea5dfd1ea095730 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Wed, 8 Jul 2026 16:54:08 +0200 Subject: [PATCH 171/406] DynamicTablesPkg: Move CheckAddressSpaceFields() to AmlUtility.c Move the CheckAddressSpaceFields() function to AmlUtility.c to allow other files to re-use it. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../AmlLib/CodeGen/AmlResourceDataCodeGen.c | 73 +------------------ .../Library/Common/AmlLib/Utils/AmlUtility.c | 71 ++++++++++++++++++ .../Library/Common/AmlLib/Utils/AmlUtility.h | 30 ++++++++ 3 files changed, 102 insertions(+), 72 deletions(-) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c index 2984a65ad8..4b5e100209 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c @@ -20,6 +20,7 @@ #include <Api/AmlApiHelper.h> #include <Tree/AmlNode.h> #include <ResourceData/AmlResourceData.h> +#include <Utils/AmlUtility.h> /** If ParentNode is not NULL, append RdNode. If NewRdNode is not NULL, update its value to RdNode. @@ -216,78 +217,6 @@ AddressSpaceGeneralFlags ( (IsMaxFixed ? BIT3 : 0); } -/** Check Address Space Descriptor Fields. - - Cf. ACPI 6.4 Table 6.44: - "Valid Combination of Address Space Descriptor Fields" - - See ACPI 6.4 spec, s19.6.36 for more. - - @param [in] IsMinFixed Minimum address is fixed. - @param [in] IsMaxFixed Maximum address is fixed. - @param [in] AddressGranularity Address granularity. - @param [in] AddressMinimum Minimum address. - @param [in] AddressMaximum Maximum address. - @param [in] AddressTranslation Address translation. - @param [in] RangeLength Range length. - - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_INVALID_PARAMETER Invalid parameter. -**/ -STATIC -EFI_STATUS -EFIAPI -CheckAddressSpaceFields ( - IN BOOLEAN IsMinFixed, - IN BOOLEAN IsMaxFixed, - IN UINT64 AddressGranularity, - IN UINT64 AddressMinimum, - IN UINT64 AddressMaximum, - IN UINT64 AddressTranslation, - IN UINT64 RangeLength - ) -{ - if ((AddressMinimum > AddressMaximum) || - (RangeLength > (AddressMaximum - AddressMinimum + 1)) || - ((AddressGranularity != 0) && - (((AddressGranularity + 1) & AddressGranularity) != 0))) - { - ASSERT (0); - return EFI_INVALID_PARAMETER; - } - - if (RangeLength != 0) { - if (IsMinFixed ^ IsMaxFixed) { - ASSERT (0); - return EFI_INVALID_PARAMETER; - } else if (IsMinFixed && - IsMaxFixed && - (AddressGranularity != 0) && - ((AddressMaximum - AddressMinimum + 1) != RangeLength)) - { - ASSERT (0); - return EFI_INVALID_PARAMETER; - } - } else { - if (IsMinFixed && IsMaxFixed) { - ASSERT (0); - return EFI_INVALID_PARAMETER; - } else if (IsMinFixed && - ((AddressMinimum & AddressGranularity) != 0)) - { - ASSERT (0); - return EFI_INVALID_PARAMETER; - } else if (IsMaxFixed && - (((AddressMaximum + 1) & AddressGranularity) != 0)) - { - ASSERT (0); - return EFI_INVALID_PARAMETER; - } - } - - return EFI_SUCCESS; -} - /** Code generation for the "DWordSpace ()" ASL function. The Resource Data effectively created is a DWord Address Space Resource diff --git a/DynamicTablesPkg/Library/Common/AmlLib/Utils/AmlUtility.c b/DynamicTablesPkg/Library/Common/AmlLib/Utils/AmlUtility.c index 811b7d2202..c38e0b8fe4 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/Utils/AmlUtility.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/Utils/AmlUtility.c @@ -1009,3 +1009,74 @@ AmlSetRdListCheckSum ( return Status; } + +/** Check Address Space Descriptor Fields. + + Cf. ACPI 6.4 Table 6.44: + "Valid Combination of Address Space Descriptor Fields" + + See ACPI 6.4 spec, s19.6.36 for more. + + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +CheckAddressSpaceFields ( + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT64 AddressGranularity, + IN UINT64 AddressMinimum, + IN UINT64 AddressMaximum, + IN UINT64 AddressTranslation, + IN UINT64 RangeLength + ) +{ + if ((AddressMinimum > AddressMaximum) || + (RangeLength > (AddressMaximum - AddressMinimum + 1)) || + ((AddressGranularity != 0) && + (((AddressGranularity + 1) & AddressGranularity) != 0))) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if (RangeLength != 0) { + if (IsMinFixed ^ IsMaxFixed) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } else if (IsMinFixed && + IsMaxFixed && + (AddressGranularity != 0) && + ((AddressMaximum - AddressMinimum + 1) != RangeLength)) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + } else { + if (IsMinFixed && IsMaxFixed) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } else if (IsMinFixed && + ((AddressMinimum & AddressGranularity) != 0)) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } else if (IsMaxFixed && + (((AddressMaximum + 1) & AddressGranularity) != 0)) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + } + + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/Library/Common/AmlLib/Utils/AmlUtility.h b/DynamicTablesPkg/Library/Common/AmlLib/Utils/AmlUtility.h index fd05390a8e..ce76414d1b 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/Utils/AmlUtility.h +++ b/DynamicTablesPkg/Library/Common/AmlLib/Utils/AmlUtility.h @@ -137,3 +137,33 @@ AmlSetRdListCheckSum ( IN AML_OBJECT_NODE *BufferOpNode, IN UINT8 CheckSum ); + +/** Check Address Space Descriptor Fields. + + Cf. ACPI 6.4 Table 6.44: + "Valid Combination of Address Space Descriptor Fields" + + See ACPI 6.4 spec, s19.6.36 for more. + + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +CheckAddressSpaceFields ( + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT64 AddressGranularity, + IN UINT64 AddressMinimum, + IN UINT64 AddressMaximum, + IN UINT64 AddressTranslation, + IN UINT64 RangeLength + ); From d3a7acfff9d73ebb41e59d550f236a07d2c8c631 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Wed, 8 Jul 2026 17:09:05 +0200 Subject: [PATCH 172/406] DynamicTablesPkg: Check Rd Address Space field combination Some combination of fields of Rd Address Space descriptors are not valid. Check them when updating a Rd Address Space descriptor. Cf. ACPI 6.4 Table 6.44: "Valid Combination of Address Space Descriptor Fields" Also check that the input length is not 0 to avoid potential integer underflow. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../Common/AmlLib/Api/AmlResourceDataApi.c | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlResourceDataApi.c b/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlResourceDataApi.c index d261adb6b8..9801ef6163 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlResourceDataApi.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlResourceDataApi.c @@ -20,6 +20,12 @@ #include <AmlInclude.h> #include <Api/AmlApiHelper.h> #include <CodeGen/AmlResourceDataCodeGen.h> +#include <Utils/AmlUtility.h> + +/* Macros to read General flags of a Resource Data Address Descriptors */ +#define IS_RD_ADDR_POS_DECODE(GenFlag) (((GenFlag) & BIT1) == 0) +#define IS_RD_ADDR_MIN_FIXED(GenFlag) (((GenFlag) & BIT2) == BIT2) +#define IS_RD_ADDR_MAX_FIXED(GenFlag) (((GenFlag) & BIT3) == BIT3) /** Update the first interrupt of an Interrupt resource data node. @@ -271,7 +277,8 @@ AmlUpdateRdQWord ( AML_RD_BUILD_LARGE_DESC_ID ( ACPI_LARGE_QWORD_ADDRESS_SPACE_DESCRIPTOR_NAME ) - ))) + )) || + (BaseAddressLength == 0)) { ASSERT (0); return EFI_INVALID_PARAMETER; @@ -313,6 +320,20 @@ AmlUpdateRdQWord ( RdQWord->AddrRangeMax = BaseAddress + BaseAddressLength - 1; RdQWord->AddrLen = BaseAddressLength; + Status = CheckAddressSpaceFields ( + IS_RD_ADDR_MIN_FIXED (RdQWord->GenFlag), + IS_RD_ADDR_MAX_FIXED (RdQWord->GenFlag), + RdQWord->AddrSpaceGranularity, + RdQWord->AddrRangeMin, + RdQWord->AddrRangeMax, + RdQWord->AddrTranslationOffset, + RdQWord->AddrLen + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + // Update Base Address Resource Data node. Status = AmlUpdateDataNode ( QWordRdNode, From dce4c57471175023588d6e3c5754620ea65c5efe Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Wed, 8 Jul 2026 15:53:32 +0200 Subject: [PATCH 173/406] DynamicTablesPkg: Add AmlUpdateRdDWord() and AmlUpdateRdWord() Add the following functions to the AmlResourceDataApi: - AmlUpdateRdDWord() - AmlUpdateRdWord() Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../Include/Library/AmlLib/AmlLib.h | 42 ++++ .../Common/AmlLib/Api/AmlResourceDataApi.c | 218 ++++++++++++++++++ 2 files changed, 260 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h index 0bfb0808d3..1e7642523d 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -538,6 +538,48 @@ AmlUpdateRdInterrupt ( IN UINT32 Irq ); +/** Update the base address and length of a DWord resource data node. + + @ingroup UserApis + + @param [in] DWordRdNode Pointer a DWord resource data + node. + @param [in] BaseAddress Base address. + @param [in] BaseAddressLength Base address length. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Out of resources. +**/ +EFI_STATUS +EFIAPI +AmlUpdateRdDWord ( + IN AML_DATA_NODE_HANDLE DWordRdNode, + IN UINT32 BaseAddress, + IN UINT32 BaseAddressLength + ); + +/** Update the base address and length of a Word resource data node. + + @ingroup UserApis + + @param [in] WordRdNode Pointer a Word resource data + node. + @param [in] BaseAddress Base address. + @param [in] BaseAddressLength Base address length. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Out of resources. +**/ +EFI_STATUS +EFIAPI +AmlUpdateRdWord ( + IN AML_DATA_NODE_HANDLE WordRdNode, + IN UINT16 BaseAddress, + IN UINT16 BaseAddressLength + ); + /** Update the base address and length of a QWord resource data node. @ingroup UserApis diff --git a/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlResourceDataApi.c b/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlResourceDataApi.c index 9801ef6163..5f994be090 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlResourceDataApi.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlResourceDataApi.c @@ -352,3 +352,221 @@ error_handler: return Status; } + +/** Update the base address and length of a DWord resource data node. + + @param [in] DWordRdNode Pointer a DWord resource data + node. + @param [in] BaseAddress Base address. + @param [in] BaseAddressLength Base address length. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Out of resources. +**/ +EFI_STATUS +EFIAPI +AmlUpdateRdDWord ( + IN AML_DATA_NODE_HANDLE DWordRdNode, + IN UINT32 BaseAddress, + IN UINT32 BaseAddressLength + ) +{ + EFI_STATUS Status; + EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR *RdDWord; + + UINT8 *QueryBuffer; + UINT32 QueryBufferSize; + + if ((DWordRdNode == NULL) || + (AmlGetNodeType ((AML_NODE_HANDLE)DWordRdNode) != EAmlNodeData) || + (!AmlNodeHasDataType (DWordRdNode, EAmlNodeDataTypeResourceData)) || + (!AmlNodeHasRdDataType ( + DWordRdNode, + AML_RD_BUILD_LARGE_DESC_ID ( + ACPI_LARGE_DWORD_ADDRESS_SPACE_DESCRIPTOR_NAME + ) + )) || + (BaseAddressLength == 0)) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Get the size of the DWordRdNode's buffer. + Status = AmlGetDataNodeBuffer ( + DWordRdNode, + NULL, + &QueryBufferSize + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Allocate a buffer to fetch the data. + QueryBuffer = AllocatePool (QueryBufferSize); + if (QueryBuffer == NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + // Get the data. + Status = AmlGetDataNodeBuffer ( + DWordRdNode, + QueryBuffer, + &QueryBufferSize + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + RdDWord = (EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR *)QueryBuffer; + + // Update the Base Address and Length. + RdDWord->AddrRangeMin = BaseAddress; + RdDWord->AddrRangeMax = BaseAddress + BaseAddressLength - 1; + RdDWord->AddrLen = BaseAddressLength; + + Status = CheckAddressSpaceFields ( + IS_RD_ADDR_MIN_FIXED (RdDWord->GenFlag), + IS_RD_ADDR_MAX_FIXED (RdDWord->GenFlag), + RdDWord->AddrSpaceGranularity, + RdDWord->AddrRangeMin, + RdDWord->AddrRangeMax, + RdDWord->AddrTranslationOffset, + RdDWord->AddrLen + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + // Update Base Address Resource Data node. + Status = AmlUpdateDataNode ( + DWordRdNode, + EAmlNodeDataTypeResourceData, + QueryBuffer, + QueryBufferSize + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + } + +error_handler: + if (QueryBuffer != NULL) { + FreePool (QueryBuffer); + } + + return Status; +} + +/** Update the base address and length of a Word resource data node. + + @param [in] WordRdNode Pointer a Word resource data + node. + @param [in] BaseAddress Base address. + @param [in] BaseAddressLength Base address length. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Out of resources. +**/ +EFI_STATUS +EFIAPI +AmlUpdateRdWord ( + IN AML_DATA_NODE_HANDLE WordRdNode, + IN UINT16 BaseAddress, + IN UINT16 BaseAddressLength + ) +{ + EFI_STATUS Status; + EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR *RdWord; + + UINT8 *QueryBuffer; + UINT32 QueryBufferSize; + + if ((WordRdNode == NULL) || + (AmlGetNodeType ((AML_NODE_HANDLE)WordRdNode) != EAmlNodeData) || + (!AmlNodeHasDataType (WordRdNode, EAmlNodeDataTypeResourceData)) || + (!AmlNodeHasRdDataType ( + WordRdNode, + AML_RD_BUILD_LARGE_DESC_ID ( + ACPI_LARGE_WORD_ADDRESS_SPACE_DESCRIPTOR_NAME + ) + )) || + (BaseAddressLength == 0)) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Get the size of the WordRdNode's buffer. + Status = AmlGetDataNodeBuffer ( + WordRdNode, + NULL, + &QueryBufferSize + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Allocate a buffer to fetch the data. + QueryBuffer = AllocatePool (QueryBufferSize); + if (QueryBuffer == NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + // Get the data. + Status = AmlGetDataNodeBuffer ( + WordRdNode, + QueryBuffer, + &QueryBufferSize + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + RdWord = (EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR *)QueryBuffer; + + // Update the Base Address and Length. + RdWord->AddrRangeMin = BaseAddress; + RdWord->AddrRangeMax = BaseAddress + BaseAddressLength - 1; + RdWord->AddrLen = BaseAddressLength; + + Status = CheckAddressSpaceFields ( + IS_RD_ADDR_MIN_FIXED (RdWord->GenFlag), + IS_RD_ADDR_MAX_FIXED (RdWord->GenFlag), + RdWord->AddrSpaceGranularity, + RdWord->AddrRangeMin, + RdWord->AddrRangeMax, + RdWord->AddrTranslationOffset, + RdWord->AddrLen + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + // Update Base Address Resource Data node. + Status = AmlUpdateDataNode ( + WordRdNode, + EAmlNodeDataTypeResourceData, + QueryBuffer, + QueryBufferSize + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + } + +error_handler: + if (QueryBuffer != NULL) { + FreePool (QueryBuffer); + } + + return Status; +} From f9e3f928198f48afcedb720e881458280e510f6c Mon Sep 17 00:00:00 2001 From: Mingjie Shen <shen497@purdue.edu> Date: Mon, 4 May 2026 20:54:12 +0000 Subject: [PATCH 174/406] BaseTools/Plugin/CodeQL: Update CodeQL CLI to v2.25.3 Update CodeQL external dependency definitions to v2.25.3 for generic, Linux, and Windows archives, including refreshed SHA256 hashes from the release metadata. Pin the codeql/cpp-queries query pack to version 1.6.1, as specified in the qlpack.yml at: https://github.com/github/codeql/blob/codeql-cli/v2.25.3/cpp/ql/src/qlpack.yml Signed-off-by: Mingjie Shen <shen497@purdue.edu> --- BaseTools/Plugin/CodeQL/CodeQlQueries.qls | 2 +- BaseTools/Plugin/CodeQL/codeqlcli_ext_dep.yaml | 6 +++--- BaseTools/Plugin/CodeQL/codeqlcli_linux_ext_dep.yaml | 6 +++--- BaseTools/Plugin/CodeQL/codeqlcli_windows_ext_dep.yaml | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/BaseTools/Plugin/CodeQL/CodeQlQueries.qls b/BaseTools/Plugin/CodeQL/CodeQlQueries.qls index 0da9baf95d..e965c5ed75 100644 --- a/BaseTools/Plugin/CodeQL/CodeQlQueries.qls +++ b/BaseTools/Plugin/CodeQL/CodeQlQueries.qls @@ -2,7 +2,7 @@ - description: C++ queries - queries: '.' - from: codeql/cpp-queries@1.1.0 + from: codeql/cpp-queries@1.6.1 ########################################################################################## # Queries diff --git a/BaseTools/Plugin/CodeQL/codeqlcli_ext_dep.yaml b/BaseTools/Plugin/CodeQL/codeqlcli_ext_dep.yaml index 3be80cb647..b2920e42bf 100644 --- a/BaseTools/Plugin/CodeQL/codeqlcli_ext_dep.yaml +++ b/BaseTools/Plugin/CodeQL/codeqlcli_ext_dep.yaml @@ -23,9 +23,9 @@ "scope": "codeql-ext-dep", "type": "web", "name": "codeql_cli", - "source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.18.1/codeql.zip", - "version": "2.18.1", - "sha256": "815f71c1a46e76f9dafdec26c2a4bab7ea4019a3773e91e39253e2d21cf792a2", + "source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.25.3/codeql.zip", + "version": "2.25.3", + "sha256": "0982c5ba0a96deb69b7a14e68d21f3efb5dd89a820e092a4f2a8212f428095c5", "compression_type": "zip", "internal_path": "/codeql/", "flags": ["set_shell_var", ], diff --git a/BaseTools/Plugin/CodeQL/codeqlcli_linux_ext_dep.yaml b/BaseTools/Plugin/CodeQL/codeqlcli_linux_ext_dep.yaml index e3fd40c2e1..718abbb1bd 100644 --- a/BaseTools/Plugin/CodeQL/codeqlcli_linux_ext_dep.yaml +++ b/BaseTools/Plugin/CodeQL/codeqlcli_linux_ext_dep.yaml @@ -21,9 +21,9 @@ "scope": "codeql-linux-ext-dep", "type": "web", "name": "codeql_linux_cli", - "source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.18.1/codeql-linux64.zip", - "version": "2.18.1", - "sha256": "1547f4a3b509474404daf2e4b821f71cd93462ec45322d9124c2b04e3d52c771", + "source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.25.3/codeql-linux64.zip", + "version": "2.25.3", + "sha256": "db69739e2a480128e1d96d96611129be12ad62a324529754ccdc529b850043a7", "compression_type": "zip", "internal_path": "/codeql/", "flags": ["set_shell_var", ], diff --git a/BaseTools/Plugin/CodeQL/codeqlcli_windows_ext_dep.yaml b/BaseTools/Plugin/CodeQL/codeqlcli_windows_ext_dep.yaml index 5e6add84f4..c0e4e3ea79 100644 --- a/BaseTools/Plugin/CodeQL/codeqlcli_windows_ext_dep.yaml +++ b/BaseTools/Plugin/CodeQL/codeqlcli_windows_ext_dep.yaml @@ -21,9 +21,9 @@ "scope": "codeql-windows-ext-dep", "type": "web", "name": "codeql_windows_cli", - "source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.18.1/codeql-win64.zip", - "version": "2.18.1", - "sha256": "eb69c9ce40142904965ca3f2491c989f12747d74358385e2e94c427b4324201c", + "source": "https://github.com/github/codeql-cli-binaries/releases/download/v2.25.3/codeql-win64.zip", + "version": "2.25.3", + "sha256": "268950c5ca1444bb8439ecdb20e60be9080ba0d786c5a690871251a4b7677647", "compression_type": "zip", "internal_path": "/codeql/", "flags": ["set_shell_var", ], From 927c7b1d819fed9fa718a793f5da3b376dd6eacc Mon Sep 17 00:00:00 2001 From: Mingjie Shen <shen497@purdue.edu> Date: Mon, 4 May 2026 21:16:39 +0000 Subject: [PATCH 175/406] BaseTools/Plugin/CodeQL: Add CodeQL version update script Add a maintenance script that updates the CodeQL CLI dependency YAML files and CodeQlQueries.qls together. The script refreshes the CLI version, release digests, and cpp query pack pin from the GitHub release metadata and the corresponding qlpack.yml in the CodeQL CLI release branch. Add comments to the CodeQL CLI dependency YAML files that direct maintainers to use the script for future version updates. Signed-off-by: Mingjie Shen <shen497@purdue.edu> --- .../Plugin/CodeQL/CodeQlVersionUpdate.py | 315 ++++++++++++++++++ .../Plugin/CodeQL/codeqlcli_ext_dep.yaml | 4 + .../CodeQL/codeqlcli_linux_ext_dep.yaml | 4 + .../CodeQL/codeqlcli_windows_ext_dep.yaml | 4 + 4 files changed, 327 insertions(+) create mode 100644 BaseTools/Plugin/CodeQL/CodeQlVersionUpdate.py diff --git a/BaseTools/Plugin/CodeQL/CodeQlVersionUpdate.py b/BaseTools/Plugin/CodeQL/CodeQlVersionUpdate.py new file mode 100644 index 0000000000..e492435b53 --- /dev/null +++ b/BaseTools/Plugin/CodeQL/CodeQlVersionUpdate.py @@ -0,0 +1,315 @@ +#!/usr/bin/env python3 +""" +@file CodeQlVersionUpdate.py + +Update CodeQL CLI dependencies and the CodeQL query pack version. + +This maintainer-only helper updates the pinned CodeQL CLI release and the +corresponding CodeQL C/C++ query pack version used by the EDK II BaseTools +CodeQL plugin. The CodeQL plugin does not invoke this script automatically. + +Audience +-------- +EDK II BaseTools CodeQL plugin maintainers. Developers who build with the +CodeQL plugin enabled, or who review CodeQL analysis results, do not need to +run this script. + +Usage +----- +Run this script manually from a local checkout: + + # Update to the latest published CodeQL CLI release. + python3 BaseTools/Plugin/CodeQL/CodeQlVersionUpdate.py + + # Update to a specific CodeQL CLI version. + python3 BaseTools/Plugin/CodeQL/CodeQlVersionUpdate.py --codeql-version 2.25.3 + +Then review and commit the resulting file changes. + +Updated files +------------- + - BaseTools/Plugin/CodeQL/codeqlcli_ext_dep.yaml + - BaseTools/Plugin/CodeQL/codeqlcli_linux_ext_dep.yaml + - BaseTools/Plugin/CodeQL/codeqlcli_windows_ext_dep.yaml + - BaseTools/Plugin/CodeQL/CodeQlQueries.qls + +Data sources +------------ +- SHA256 digests are read from GitHub release metadata. +- The codeql/cpp-queries version is read from qlpack.yml in the corresponding + CodeQL CLI branch. + +Release metadata note +--------------------- +This script depends on GitHub release-asset digests being present in the +release metadata. GitHub started exposing those digests on 2025-06-03: +https://github.blog/changelog/2025-06-03-releases-now-expose-digests-for-release-assets/ +Releases published before that change may not have `digest` values in the API. + +Copyright (c) 2026, Purdue University. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent +""" + +from __future__ import annotations + +import argparse +import json +import re +import sys +import urllib.error +import urllib.request +from pathlib import Path +from typing import Dict + + +SCRIPT_DIR = Path(__file__).resolve().parent + +EXT_DEP_FILES = { + "codeql.zip": SCRIPT_DIR / "codeqlcli_ext_dep.yaml", + "codeql-linux64.zip": SCRIPT_DIR / "codeqlcli_linux_ext_dep.yaml", + "codeql-win64.zip": SCRIPT_DIR / "codeqlcli_windows_ext_dep.yaml", +} +QUERY_FILE = SCRIPT_DIR / "CodeQlQueries.qls" + +HTTP_TIMEOUT_SECONDS = 30 + +def _http_get(url: str) -> bytes: + req = urllib.request.Request(url, headers={"User-Agent": "edk2-codeql-updater"}) + with urllib.request.urlopen(req, timeout=HTTP_TIMEOUT_SECONDS) as resp: + return resp.read() + + +def _http_get_json(url: str) -> dict: + return json.loads(_http_get(url).decode("utf-8")) + + +def _http_get_text(url: str) -> str: + return _http_get(url).decode("utf-8") + + +def _extract_sha256_from_text(text: str) -> str: + # Expected content is either "<sha256>" or "<sha256> <filename>". + token = text.strip().split()[0] + if not re.fullmatch(r"[0-9a-fA-F]{64}", token): + raise ValueError(f"Invalid sha256 text content: {text.strip()!r}") + return token.lower() + + +def fetch_latest_codeql_version() -> str: + latest_release_url = ( + "https://api.github.com/repos/github/codeql-cli-binaries/releases/latest" + ) + latest_release = _http_get_json(latest_release_url) + tag_name = latest_release.get("tag_name") or "" + if not isinstance(tag_name, str) or not tag_name: + raise ValueError("Unable to determine latest CodeQL version from GitHub") + return tag_name.lstrip("v") + + +def fetch_release_sha256_map(codeql_version: str) -> Dict[str, str]: + release_url = ( + "https://api.github.com/repos/github/codeql-cli-binaries/releases/tags/" + f"v{codeql_version}" + ) + release = _http_get_json(release_url) + assets = {asset["name"]: asset for asset in release.get("assets", [])} + + sha_map: Dict[str, str] = {} + for asset_name in EXT_DEP_FILES: + asset = assets.get(asset_name) + if asset is None: + raise KeyError( + f"Release v{codeql_version} does not include required asset: {asset_name}" + ) + + digest = asset.get("digest") or "" + if digest.startswith("sha256:"): + sha_map[asset_name] = digest.split(":", 1)[1].lower() + continue + + sha_asset = assets.get(f"{asset_name}.checksum.txt") + if sha_asset: + sha_text = _http_get_text(sha_asset["browser_download_url"]) + sha_map[asset_name] = _extract_sha256_from_text(sha_text) + continue + + raise KeyError( + f"Unable to find SHA256 for {asset_name} in release v{codeql_version}" + ) + + return sha_map + + +def fetch_cpp_queries_version(codeql_version: str) -> str: + qlpack_url = ( + "https://raw.githubusercontent.com/github/codeql/" + f"codeql-cli/v{codeql_version}/cpp/ql/src/qlpack.yml" + ) + qlpack_text = _http_get_text(qlpack_url) + + # qlpack.yml for cpp queries uses: + # name: codeql/cpp-queries + # version: <pack version> + if "name: codeql/cpp-queries" not in qlpack_text: + raise ValueError( + f"Unable to validate cpp queries pack in qlpack.yml for v{codeql_version}" + ) + + match = re.search(r"(?m)^\s*version:\s*([0-9A-Za-z.\-_]+)\s*$", qlpack_text) + if not match: + raise ValueError( + f"Unable to parse codeql/cpp-queries version for v{codeql_version}" + ) + return match.group(1) + + +def read_text(path: Path) -> str: + with path.open("r", encoding="utf-8", newline="") as f: + return f.read() + + +def detect_newline_style(text: str) -> str: + if "\r\n" in text: + return "\r\n" + return "\n" + + +def normalize_newlines(text: str, newline: str) -> str: + normalized = text.replace("\r\n", "\n") + if newline == "\r\n": + return normalized.replace("\n", "\r\n") + return normalized + + +def write_text(path: Path, text: str) -> None: + path.write_text(text, encoding="utf-8", newline="") + + +def replace_or_fail(pattern: str, replacement: str, text: str, path: Path) -> str: + new_text, count = re.subn(pattern, replacement, text, count=1, flags=re.MULTILINE) + if count != 1: + raise ValueError(f"Expected one match for pattern {pattern!r} in {path}") + return new_text + + +def update_ext_dep_file(path: Path, asset_name: str, codeql_version: str, sha256: str) -> bool: + original = read_text(path) + newline_style = detect_newline_style(original) + text = original + source_url = ( + "https://github.com/github/codeql-cli-binaries/releases/download/" + f"v{codeql_version}/{asset_name}" + ) + + text = replace_or_fail( + r'("source"\s*:\s*")[^"]+(")', + rf'\g<1>{source_url}\g<2>', + text, + path, + ) + text = replace_or_fail( + r'("version"\s*:\s*")[^"]+(")', + rf'\g<1>{codeql_version}\g<2>', + text, + path, + ) + text = replace_or_fail( + r'("sha256"\s*:\s*")[0-9a-fA-F]{64}(")', + rf'\g<1>{sha256}\g<2>', + text, + path, + ) + + if text != original: + write_text(path, normalize_newlines(text, newline_style)) + return True + return False + + +def update_queries_file(path: Path, cpp_queries_version: str) -> bool: + original = read_text(path) + newline_style = detect_newline_style(original) + text = replace_or_fail( + r"(from:\s*codeql/cpp-queries@)[0-9A-Za-z.\-_]+", + rf"\g<1>{cpp_queries_version}", + original, + path, + ) + if text != original: + write_text(path, normalize_newlines(text, newline_style)) + return True + return False + + +def parse_args() -> argparse.Namespace: + parser = argparse.ArgumentParser( + description="Update CodeQL CLI versions and cpp query pack version." + ) + parser.add_argument( + "--codeql-version", + help=( + "CodeQL CLI version (for example: 2.24.1). If omitted, the latest " + "published release is used." + ), + ) + parser.add_argument( + "--dry-run", + action="store_true", + help="Calculate and print updates without writing files.", + ) + return parser.parse_args() + + +def main() -> int: + args = parse_args() + + try: + codeql_version = ( + args.codeql_version.lstrip("v") + if args.codeql_version + else fetch_latest_codeql_version() + ) + + sha_map: Dict[str, str] = fetch_release_sha256_map(codeql_version) + + for asset_name, sha in sha_map.items(): + if not re.fullmatch(r"[0-9a-f]{64}", sha): + raise ValueError(f"Invalid SHA256 value for {asset_name}: {sha}") + + cpp_queries_version = fetch_cpp_queries_version(codeql_version) + + print(f"CodeQL version: v{codeql_version}") + print(f"codeql/cpp-queries version: {cpp_queries_version}") + for asset_name in sorted(sha_map): + print(f"{asset_name} sha256: {sha_map[asset_name]}") + + if args.dry_run: + print("Dry run: no files were modified.") + return 0 + + changed_files = [] + for asset_name, path in EXT_DEP_FILES.items(): + if update_ext_dep_file(path, asset_name, codeql_version, sha_map[asset_name]): + changed_files.append(path) + if update_queries_file(QUERY_FILE, cpp_queries_version): + changed_files.append(QUERY_FILE) + + if changed_files: + print("Updated files:") + for path in changed_files: + print(f" - {path}") + else: + print("No file changes were necessary.") + return 0 + + except urllib.error.HTTPError as err: + print(f"HTTP error while fetching release data: {err}", file=sys.stderr) + except (urllib.error.URLError, TimeoutError) as err: + print(f"Network error while fetching release data: {err}", file=sys.stderr) + except (KeyError, ValueError) as err: + print(f"Error: {err}", file=sys.stderr) + return 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/BaseTools/Plugin/CodeQL/codeqlcli_ext_dep.yaml b/BaseTools/Plugin/CodeQL/codeqlcli_ext_dep.yaml index b2920e42bf..e9e3a021dc 100644 --- a/BaseTools/Plugin/CodeQL/codeqlcli_ext_dep.yaml +++ b/BaseTools/Plugin/CodeQL/codeqlcli_ext_dep.yaml @@ -10,6 +10,10 @@ # # ****VERSION UPDATE INSTRUCTIONS**** # +# Use BaseTools/Plugin/CodeQL/CodeQlVersionUpdate.py to update this file, +# the platform-specific CodeQL CLI dependency files, and CodeQlQueries.qls together. +# The script refreshes the CLI version, release digests, and cpp query pack pin. +# # When updating the CodeQL CLI used here, update the corresponding codeql/cpp-queries version in CodeQlQueries.qls. # Visit the `qlpack.yml` in the release branch for the CodeQL CLI to get the version to use there. For example, the # CodeQL CLI 2.18.1 file is https://github.com/github/codeql/blob/codeql-cli-2.18.1/cpp/ql/src/qlpack.yml and the diff --git a/BaseTools/Plugin/CodeQL/codeqlcli_linux_ext_dep.yaml b/BaseTools/Plugin/CodeQL/codeqlcli_linux_ext_dep.yaml index 718abbb1bd..de74e01f6a 100644 --- a/BaseTools/Plugin/CodeQL/codeqlcli_linux_ext_dep.yaml +++ b/BaseTools/Plugin/CodeQL/codeqlcli_linux_ext_dep.yaml @@ -8,6 +8,10 @@ # # ****VERSION UPDATE INSTRUCTIONS**** # +# Use BaseTools/Plugin/CodeQL/CodeQlVersionUpdate.py to update this file, +# the platform-specific CodeQL CLI dependency files, and CodeQlQueries.qls together. +# The script refreshes the CLI version, release digests, and cpp query pack pin. +# # When updating the CodeQL CLI used here, update the corresponding codeql/cpp-queries version in CodeQlQueries.qls. # Visit the `qlpack.yml` in the release branch for the CodeQL CLI to get the version to use there. For example, the # CodeQL CLI 2.18.1 file is https://github.com/github/codeql/blob/codeql-cli-2.18.1/cpp/ql/src/qlpack.yml and the diff --git a/BaseTools/Plugin/CodeQL/codeqlcli_windows_ext_dep.yaml b/BaseTools/Plugin/CodeQL/codeqlcli_windows_ext_dep.yaml index c0e4e3ea79..66223f3eb5 100644 --- a/BaseTools/Plugin/CodeQL/codeqlcli_windows_ext_dep.yaml +++ b/BaseTools/Plugin/CodeQL/codeqlcli_windows_ext_dep.yaml @@ -8,6 +8,10 @@ # # ****VERSION UPDATE INSTRUCTIONS**** # +# Use BaseTools/Plugin/CodeQL/CodeQlVersionUpdate.py to update this file, +# the platform-specific CodeQL CLI dependency files, and CodeQlQueries.qls together. +# The script refreshes the CLI version, release digests, and cpp query pack pin. +# # When updating the CodeQL CLI used here, update the corresponding codeql/cpp-queries version in CodeQlQueries.qls. # Visit the `qlpack.yml` in the release branch for the CodeQL CLI to get the version to use there. For example, the # CodeQL CLI 2.18.1 file is https://github.com/github/codeql/blob/codeql-cli-2.18.1/cpp/ql/src/qlpack.yml and the From 6a6ec8a228b6dd99f9a52a78c2a4c82be9b73ec8 Mon Sep 17 00:00:00 2001 From: Nickle Wang <nicklew@nvidia.com> Date: Thu, 25 Jun 2026 21:10:36 +0800 Subject: [PATCH 176/406] RedfishPkg/RedfishHttpDxe: report Redfish communication time Add the support of reporting Redfish communication time between BIOS and BMC. This helps to debug the issue of long boot time. This debug function is default disabled, so it won't add extra time during Redfish communication on regular boot. Signed-off-by: Nickle Wang <nicklew@nvidia.com> --- RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h | 20 +++++++------ RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf | 3 +- .../RedfishHttpDxe/RedfishHttpOperation.c | 30 +++++++++++++++++++ RedfishPkg/RedfishPkg.dsc | 3 +- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h b/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h index a0d6acecba..3731edc0f6 100644 --- a/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h +++ b/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h @@ -1,7 +1,7 @@ /** @file Definitions of RedfishHttpDxe - Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent @@ -25,17 +25,19 @@ #include <Library/RedfishDebugLib.h> #include <Library/ReportStatusCodeLib.h> #include <Library/PrintLib.h> +#include <Library/TimerLib.h> #include <Protocol/Http.h> #include <Protocol/EdkIIRedfishHttpProtocol.h> #include <Protocol/EdkIIRedfishCredential2.h> #include <Protocol/RestEx.h> -#define REDFISH_HTTP_CACHE_LIST_SIZE 0x80 -#define REDFISH_ERROR_MSG_MAX 128 -#define REDFISH_DEBUG_STRING_LENGTH 200 -#define REDFISH_HOST_NAME_MAX 64 // IPv6 maximum length (39) + "https://" (8) + port number (maximum 5) -#define REDFISH_HTTP_ERROR_REPORT "Redfish HTTP %a failure(0x%x): %s" -#define REDFISH_HTTP_CACHE_DEBUG DEBUG_MANAGEABILITY -#define REDFISH_HTTP_CACHE_DEBUG_DUMP DEBUG_MANAGEABILITY -#define REDFISH_HTTP_CACHE_DEBUG_REQUEST DEBUG_MANAGEABILITY +#define REDFISH_HTTP_CACHE_LIST_SIZE 0x80 +#define REDFISH_ERROR_MSG_MAX 128 +#define REDFISH_DEBUG_STRING_LENGTH 200 +#define REDFISH_HOST_NAME_MAX 64 // IPv6 maximum length (39) + "https://" (8) + port number (maximum 5) +#define REDFISH_HTTP_ERROR_REPORT "Redfish HTTP %a failure(0x%x): %s" +#define REDFISH_HTTP_CACHE_DEBUG DEBUG_MANAGEABILITY +#define REDFISH_HTTP_CACHE_DEBUG_DUMP DEBUG_MANAGEABILITY +#define REDFISH_HTTP_CACHE_DEBUG_REQUEST DEBUG_MANAGEABILITY +#define REDFISH_HTTP_RESPONSE_TIME_DEBUG_ENABLED 0x0 diff --git a/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf b/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf index 784ac4cac2..cbf37c274a 100644 --- a/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf +++ b/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf @@ -3,7 +3,7 @@ # EdkIIRedfishHttpProtocol to EDK2 Redfish Feature # drivers for HTTP operation. # -# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -47,6 +47,7 @@ PrintLib RedfishDebugLib ReportStatusCodeLib + TimerLib UefiBootServicesTableLib UefiDriverEntryPoint UefiLib diff --git a/RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c b/RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c index 998f3dd531..609534f5a4 100644 --- a/RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c +++ b/RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c @@ -10,6 +10,19 @@ #include "RedfishHttpOperation.h" #include "RedfishHttpData.h" +/** + Return HTTP method in ASCII string. Caller does not need + to free returned string buffer. + + @param[in] Method HTTP method. + + @retval CHAR8 * Method in string. +**/ +CHAR8 * +HttpMethodToString ( + IN EFI_HTTP_METHOD Method + ); + /** This function copies all headers in SrcHeaders to DstHeaders. It's call responsibility to release returned DstHeaders. @@ -640,6 +653,13 @@ HttpSendReceive ( EFI_HTTP_HEADER *XAuthTokenHeader; CHAR8 *HttpContentEncoding; + #if REDFISH_HTTP_RESPONSE_TIME_DEBUG_ENABLED + UINT64 StartNs; + UINT64 EndNs; + UINT64 ElapsedNs; + + #endif + if ((Service == NULL) || IS_EMPTY_STRING (Uri) || (Response == NULL)) { return EFI_INVALID_PARAMETER; } @@ -661,6 +681,10 @@ HttpSendReceive ( return EFI_PROTOCOL_ERROR; } + #if REDFISH_HTTP_RESPONSE_TIME_DEBUG_ENABLED + StartNs = GetTimeInNanoSecond (GetPerformanceCounter ()); + #endif + // // call RESTEx to get response from REST service. // @@ -669,6 +693,12 @@ HttpSendReceive ( DEBUG ((DEBUG_ERROR, "%a: %s SendReceive failure: %r\n", __func__, Uri, RestExStatus)); } + #if REDFISH_HTTP_RESPONSE_TIME_DEBUG_ENABLED + EndNs = GetTimeInNanoSecond (GetPerformanceCounter ()); + ElapsedNs = EndNs - StartNs; + DEBUG ((DEBUG_ERROR, "%a: %a %s takes: %ld us\n", __func__, HttpMethodToString (Method), Uri, (ElapsedNs / 1000))); + #endif + // // Return status code, headers and payload to caller as much as possible even when RestEx returns failure. // diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc index fd7ac6525a..712ae0b29e 100644 --- a/RedfishPkg/RedfishPkg.dsc +++ b/RedfishPkg/RedfishPkg.dsc @@ -4,7 +4,7 @@ # Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.<BR> # (C) Copyright 2021 Hewlett-Packard Enterprise Development LP. # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. -# Copyright (c) 2023-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -48,6 +48,7 @@ ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf RedfishPlatformWantedDeviceLib|RedfishPkg/Library/RedfishPlatformWantedDeviceLibNull/RedfishPlatformWantedDeviceLibNull.inf + TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf # NULL instance of IPMI related library. IpmiLib|MdeModulePkg/Library/BaseIpmiLibNull/BaseIpmiLibNull.inf From 11ba2716bae587398fadc900a61dd1ad5e291cc7 Mon Sep 17 00:00:00 2001 From: Benjamin Doron <benjamin.doron@9elements.com> Date: Thu, 31 Jul 2025 12:51:45 -0400 Subject: [PATCH 177/406] UefiCpuPkg/BaseArchSupportLib: Include what you use This fixes compiler errors on AARCH64. Signed-off-by: Benjamin Doron <benjamin.doron@9elements.com> --- UefiCpuPkg/Library/BaseArchSupportLib/BaseArchSupportLib.inf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UefiCpuPkg/Library/BaseArchSupportLib/BaseArchSupportLib.inf b/UefiCpuPkg/Library/BaseArchSupportLib/BaseArchSupportLib.inf index db8635a471..fdbf4956d9 100644 --- a/UefiCpuPkg/Library/BaseArchSupportLib/BaseArchSupportLib.inf +++ b/UefiCpuPkg/Library/BaseArchSupportLib/BaseArchSupportLib.inf @@ -28,3 +28,6 @@ [LibraryClasses] BaseLib + +[LibraryClasses.AARCH64] + ArmLib From 50418424a0e9b23f883ca7b9af61dd1bd5edd6b7 Mon Sep 17 00:00:00 2001 From: Benjamin Doron <benjamin.doron@9elements.com> Date: Mon, 4 Aug 2025 13:35:55 -0400 Subject: [PATCH 178/406] UefiPayloadPkg: Fix AARCH64's ResetSystemLib class definition This library class is called ResetSystemLib, not EfiResetSystemLib. Fix this, making resets generated by UEFI and through the runtime service work as expected. Signed-off-by: Benjamin Doron <benjamin.doron@9elements.com> --- UefiPayloadPkg/UefiPayloadPkg.dsc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index e9986e00ec..5e228ba04a 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -426,11 +426,12 @@ ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf ArmLib|MdePkg/Library/ArmLib/ArmBaseLib.inf ArmMmuLib|UefiCpuPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf + ArmMonitorLib|ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf ArmSmcLib|MdePkg/Library/ArmSmcLib/ArmSmcLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf - EfiResetSystemLib|ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.inf + ResetSystemLib|ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.inf PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf PL011UartClockLib|ArmPlatformPkg/Library/PL011UartClockLib/PL011UartClockLib.inf SerialPortLib|ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf From 049dc848c4b94b9eb003eb744ccfd519104bbefb Mon Sep 17 00:00:00 2001 From: Mingjie Shen <shen497@purdue.edu> Date: Wed, 8 Jul 2026 01:01:40 +0000 Subject: [PATCH 179/406] MdeModulePkg: Fix incorrect EfiPciWidth* enum literals In arguments of EFI_PCI_IO_PROTOCOL member functions, replace the EfiPciWidth* enum literals from EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH with the matching EfiPciIoWidth* values from EFI_PCI_IO_PROTOCOL_WIDTH. This keeps the call sites aligned with the protocol they actually use. The old values were copied from EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL code, so they obscured the intent of the calls and relied on an explicit cast. This mimics commit 8ba64a9a9417 ("UefiPayloadPkg: Fix build failure with CLANGPDB"). Generated by coccinelle script. ``` smpl @initialize:python@ @@ def to_pci_io_width(name): return name.replace("EfiPciWidth", "EfiPciIoWidth", 1) @normalize@ typedef EFI_PCI_IO_PROTOCOL; typedef EDKII_PCI_DEVICE_PPI; type T =~ "^EFI_PCI_IO_PROTOCOL_WIDTH$"; EFI_PCI_IO_PROTOCOL *x; EDKII_PCI_DEVICE_PPI *y; identifier bad =~ "EfiPciWidth(Uint|FifoUint|FillUint)(8|16|32|64)"; identifier top_op =~ "^(PollMem|PollIo|CopyMem)$"; identifier space =~ "^(Mem|Io|Pci)$"; identifier rw =~ "^(Read|Write)$"; fresh identifier good = script:python(bad) { to_pci_io_width(bad) }; expression first; expression list rest; @@ ( x->top_op | y->PciIo.top_op | x->space.rw | y->PciIo.space.rw ) ( first, - (T)bad + good , rest ) ``` Verified with: - `build -p MdeModulePkg/MdeModulePkg.dsc -m MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf -a IA32 -b DEBUG -t GCC` - `build -p MdeModulePkg/MdeModulePkg.dsc -m MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf -a X64 -b DEBUG -t GCC` Signed-off-by: Mingjie Shen <shen497@purdue.edu> --- MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c index ba14ccbc30..c290884110 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -598,7 +598,7 @@ RomDecode ( Value32 = RomBar | 0x1; PciIo->Pci.Write ( PciIo, - (EFI_PCI_IO_PROTOCOL_WIDTH)EfiPciWidthUint32, + EfiPciIoWidthUint32, RomBarIndex, 1, &Value32 @@ -630,7 +630,7 @@ RomDecode ( Value32 = 0xFFFFFFFE; PciIo->Pci.Write ( PciIo, - (EFI_PCI_IO_PROTOCOL_WIDTH)EfiPciWidthUint32, + EfiPciIoWidthUint32, RomBarIndex, 1, &Value32 From 96c9f8f372eca22539a2e12f8d3d90b9f34eea6e Mon Sep 17 00:00:00 2001 From: Mingjie Shen <shen497@purdue.edu> Date: Wed, 8 Jul 2026 01:01:46 +0000 Subject: [PATCH 180/406] UefiPayloadPkg: Fix incorrect EfiPciWidth* enum literals In arguments of EFI_PCI_IO_PROTOCOL member functions, replace the EfiPciWidth* enum literals from EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH with the matching EfiPciIoWidth* values from EFI_PCI_IO_PROTOCOL_WIDTH. This keeps the call sites aligned with the protocol they actually use. The old values were copied from EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL code, so they obscured the intent of the calls and relied on an explicit cast. This mimics commit 8ba64a9a9417 ("UefiPayloadPkg: Fix build failure with CLANGPDB"). Generated by coccinelle script. ``` smpl @initialize:python@ @@ def to_pci_io_width(name): return name.replace("EfiPciWidth", "EfiPciIoWidth", 1) @normalize@ typedef EFI_PCI_IO_PROTOCOL; typedef EDKII_PCI_DEVICE_PPI; type T =~ "^EFI_PCI_IO_PROTOCOL_WIDTH$"; EFI_PCI_IO_PROTOCOL *x; EDKII_PCI_DEVICE_PPI *y; identifier bad =~ "EfiPciWidth(Uint|FifoUint|FillUint)(8|16|32|64)"; identifier top_op =~ "^(PollMem|PollIo|CopyMem)$"; identifier space =~ "^(Mem|Io|Pci)$"; identifier rw =~ "^(Read|Write)$"; fresh identifier good = script:python(bad) { to_pci_io_width(bad) }; expression first; expression list rest; @@ ( x->top_op | y->PciIo.top_op | x->space.rw | y->PciIo.space.rw ) ( first, - (T)bad + good , rest ) ``` Verified with: - `build -p UefiPayloadPkg/UefiPayloadPkg.dsc -a IA32 -a X64 -b DEBUG -t GCC -D BOOTLOADER=SBL` - temporary IA32 PEIM harness that compiled X86_BuildFdtLib.c Signed-off-by: Mingjie Shen <shen497@purdue.edu> --- UefiPayloadPkg/Library/BuildFdtLib/X86_BuildFdtLib.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/UefiPayloadPkg/Library/BuildFdtLib/X86_BuildFdtLib.c b/UefiPayloadPkg/Library/BuildFdtLib/X86_BuildFdtLib.c index 4b6f6e636d..0d474f2b0d 100644 --- a/UefiPayloadPkg/Library/BuildFdtLib/X86_BuildFdtLib.c +++ b/UefiPayloadPkg/Library/BuildFdtLib/X86_BuildFdtLib.c @@ -700,7 +700,7 @@ BuildFdtForPciRootBridge ( if (!EFI_ERROR (Status)) { Status = mPciDevicePpi->PciIo.Pci.Read ( &mPciDevicePpi->PciIo, - (EFI_PCI_IO_PROTOCOL_WIDTH)EfiPciWidthUint16, + EfiPciIoWidthUint16, PCI_VENDOR_ID_OFFSET, sizeof (PciData.Hdr.VendorId), &(PciData.Hdr.VendorId) @@ -708,7 +708,7 @@ BuildFdtForPciRootBridge ( Status = mPciDevicePpi->PciIo.Pci.Read ( &mPciDevicePpi->PciIo, - (EFI_PCI_IO_PROTOCOL_WIDTH)EfiPciWidthUint16, + EfiPciIoWidthUint16, PCI_DEVICE_ID_OFFSET, sizeof (PciData.Hdr.DeviceId), &(PciData.Hdr.DeviceId) @@ -716,7 +716,7 @@ BuildFdtForPciRootBridge ( Status = mPciDevicePpi->PciIo.Pci.Read ( &mPciDevicePpi->PciIo, - (EFI_PCI_IO_PROTOCOL_WIDTH)EfiPciWidthUint8, + EfiPciIoWidthUint8, PCI_REVISION_ID_OFFSET, sizeof (PciData.Hdr.RevisionID), &(PciData.Hdr.RevisionID) @@ -724,7 +724,7 @@ BuildFdtForPciRootBridge ( Status = mPciDevicePpi->PciIo.Pci.Read ( &mPciDevicePpi->PciIo, - (EFI_PCI_IO_PROTOCOL_WIDTH)EfiPciWidthUint16, + EfiPciIoWidthUint16, PCI_SVID_OFFSET, sizeof (PciData.Device.SubsystemVendorID), &(PciData.Device.SubsystemVendorID) @@ -732,7 +732,7 @@ BuildFdtForPciRootBridge ( Status = mPciDevicePpi->PciIo.Pci.Read ( &mPciDevicePpi->PciIo, - (EFI_PCI_IO_PROTOCOL_WIDTH)EfiPciWidthUint16, + EfiPciIoWidthUint16, PCI_SID_OFFSET, sizeof (PciData.Device.SubsystemID), &(PciData.Device.SubsystemID) From 0f07c187d016bd63098a5bf3e2b12c51ca9d4bb3 Mon Sep 17 00:00:00 2001 From: "Michael G.A. Holland" <michael.holland@intel.com> Date: Wed, 1 Jul 2026 15:20:56 -0700 Subject: [PATCH 181/406] CryptoPkg/BaseCryptLib: Add ML-DSA Support Created ML-DSA API functions to configure public and private keys for ML-DSA algorithm. This will allow users to sign and verify with ML-DSA. Unit tests were add to confirm operation of the API. Signed-off-by: Michael G.A. Holland <michael.holland@intel.com> --- CryptoPkg/Driver/Crypto.c | 258 ++ CryptoPkg/Include/Library/BaseCryptLib.h | 302 +++ .../Pcd/PcdCryptoServiceFamilyEnable.h | 15 + .../Library/BaseCryptLib/BaseCryptLib.inf | 1 + .../Library/BaseCryptLib/PeiCryptLib.inf | 1 + CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c | 112 + .../Library/BaseCryptLib/Pem/CryptPemNull.c | 29 + .../Library/BaseCryptLib/Pk/CryptMlDsa.c | 692 ++++++ .../Library/BaseCryptLib/Pk/CryptMlDsaNull.c | 291 +++ CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c | 170 ++ .../Library/BaseCryptLib/Pk/CryptX509Null.c | 28 + .../Library/BaseCryptLib/RuntimeCryptLib.inf | 1 + .../Library/BaseCryptLib/SecCryptLib.inf | 1 + .../Library/BaseCryptLib/SmmCryptLib.inf | 1 + .../BaseCryptLib/UnitTestHostBaseCryptLib.inf | 1 + .../BaseCryptLibMbedTls/Pem/CryptPemNull.c | 29 + .../BaseCryptLibMbedTls/Pk/CryptMlDsaNull.c | 291 +++ .../BaseCryptLibMbedTls/Pk/CryptX509.c | 28 + .../BaseCryptLibMbedTls/Pk/CryptX509Null.c | 28 + .../BaseCryptLibNull/Pem/CryptPemNull.c | 29 + .../BaseCryptLibNull/Pk/CryptMlDsaNull.c | 291 +++ .../BaseCryptLibNull/Pk/CryptX509Null.c | 28 + .../BaseCryptLibOnProtocolPpi/CryptLib.c | 328 +++ .../X64-GCC/crypto/bn/rsaz-2k-avxifma.s | 1138 ++++++++- .../X64-GCC/crypto/bn/rsaz-3k-avxifma.s | 1746 +++++++++++++- .../X64-GCC/crypto/bn/rsaz-4k-avxifma.s | 1900 ++++++++++++++- .../X64-MSFT/crypto/bn/rsaz-2k-avxifma.nasm | 1343 ++++++++++- .../X64-MSFT/crypto/bn/rsaz-3k-avxifma.nasm | 1947 ++++++++++++++- .../X64-MSFT/crypto/bn/rsaz-4k-avxifma.nasm | 2101 ++++++++++++++++- .../include/openssl/configuration-ec.h | 3 - .../include/openssl/configuration-noec.h | 3 - .../providers/common/der/der_ml_dsa_gen.c | 2 + .../common/include/prov/der_ml_dsa.h | 2 + CryptoPkg/Library/OpensslLib/OpensslLib.inf | 14 + .../Library/OpensslLib/OpensslLibAccel.inf | 42 + .../Library/OpensslLib/OpensslLibCrypto.inf | 14 + .../Library/OpensslLib/OpensslLibFull.inf | 14 + .../OpensslLib/OpensslLibFullAccel.inf | 42 + .../Library/OpensslLib/OpensslStub/uefiprov.c | 7 + CryptoPkg/Library/OpensslLib/configure.py | 3 +- CryptoPkg/Private/Protocol/Crypto.h | 307 ++- .../BaseCryptLib/BaseCryptLibUnitTests.c | 1 + .../Library/BaseCryptLib/MlDsaTestVectors.h | 1238 ++++++++++ .../Library/BaseCryptLib/MlDsaTests.c | 1655 +++++++++++++ .../Library/BaseCryptLib/TestBaseCryptLib.h | 3 + .../BaseCryptLib/TestBaseCryptLibHost.inf | 1 + .../BaseCryptLib/TestBaseCryptLibShell.inf | 1 + 47 files changed, 16442 insertions(+), 40 deletions(-) create mode 100644 CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsa.c create mode 100644 CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsaNull.c create mode 100644 CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptMlDsaNull.c create mode 100644 CryptoPkg/Library/BaseCryptLibNull/Pk/CryptMlDsaNull.c create mode 100644 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/MlDsaTestVectors.h create mode 100644 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/MlDsaTests.c diff --git a/CryptoPkg/Driver/Crypto.c b/CryptoPkg/Driver/Crypto.c index c826b1e6bf..f6c4d8ebc5 100644 --- a/CryptoPkg/Driver/Crypto.c +++ b/CryptoPkg/Driver/Crypto.c @@ -7647,6 +7647,253 @@ CryptoServiceEdDsaVerify ( return CALL_BASECRYPTLIB (EdDsa.Services.Verify, EdDsaVerify, (EdDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); } +/** + Creates a new ML-DSA context by Crypto NID. + + This function allocates and initializes a new ML-DSA context for the specified + ML-DSA variant. The context contains an EVP_PKEY structure initialized with the + ML-DSA parameters. The caller must call MlDsaFree() to release the context when done. + + Before keys can be used for signing or verification, they must be set using + MlDsaSetPrivKey() or MlDsaSetPubKey(). + + @param[in] Nid Crypto NID of the ML-DSA variant (e.g., CRYPTO_NID_ML_DSA_87). + + @retval Pointer to new ML-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +CryptoServiceMlDsaNewByNid ( + IN UINTN Nid + ) +{ + return CALL_BASECRYPTLIB (MlDsa.Services.NewByNid, MlDsaNewByNid, (Nid), NULL); +} + +/** + Frees an ML-DSA context and all associated resources. + + This function releases all memory associated with the ML-DSA context, including + the EVP_PKEY structure. After calling this function, the MlDsaContext pointer + should not be used. + + If MlDsaContext is NULL, then this function returns immediately without action. + + @param[in] MlDsaContext Pointer to the ML-DSA context to be released. + +**/ +VOID +EFIAPI +CryptoServiceMlDsaFree ( + IN VOID *MlDsaContext + ) +{ + CALL_VOID_BASECRYPTLIB (MlDsa.Services.Free, MlDsaFree, (MlDsaContext)); +} + +/** + Sets the ML-DSA private key in the ML-DSA context. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE ML-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +CryptoServiceMlDsaSetPrivKey ( + IN VOID *MlDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + return CALL_BASECRYPTLIB (MlDsa.Services.SetPrivKey, MlDsaSetPrivKey, (MlDsaContext, PrivateKey, PrivateKeySize), FALSE); +} + +/** + Generates and retrieves the public key from a private key context. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +CryptoServiceMlDsaGeneratePubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + return CALL_BASECRYPTLIB (MlDsa.Services.GeneratePubKey, MlDsaGeneratePubKey, (MlDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Sets the ML-DSA public key in the ML-DSA context. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE ML-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +CryptoServiceMlDsaSetPubKey ( + IN VOID *MlDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + return CALL_BASECRYPTLIB (MlDsa.Services.SetPubKey, MlDsaSetPubKey, (MlDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieves the ML-DSA public key from the ML-DSA context. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE ML-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +CryptoServiceMlDsaGetPubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + return CALL_BASECRYPTLIB (MlDsa.Services.GetPubKey, MlDsaGetPubKey, (MlDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieve the ML-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contain the retrieved + ML-DSA public key component. Use MlDsaFree() function to free the + resource. + + @retval TRUE ML-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve ML-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +CryptoServiceMlDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **MlDsaContext + ) +{ + return CALL_BASECRYPTLIB (MlDsa.Services.GetPublicKeyFromX509, MlDsaGetPublicKeyFromX509, (Cert, CertSize, MlDsaContext), FALSE); +} + +/** + Retrieve the ML-DSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contains + the retrieved ML-DSA private key. Use MlDsaFree() to free. + + @retval TRUE ML-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +CryptoServiceMlDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **MlDsaContext + ) +{ + return CALL_BASECRYPTLIB (MlDsa.Services.GetPrivateKeyFromPem, MlDsaGetPrivateKeyFromPem, (PemData, PemSize, Password, MlDsaContext), FALSE); +} + +/** + Generates an ML-DSA signature for a given message. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature. + + @retval TRUE ML-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +CryptoServiceMlDsaSign ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + return CALL_BASECRYPTLIB (MlDsa.Services.Sign, MlDsaSign, (MlDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} + +/** + Verifies the ML-DSA signature for a given message. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the ML-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE ML-DSA signature verification succeeded. + @retval FALSE ML-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +CryptoServiceMlDsaVerify ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + return CALL_BASECRYPTLIB (MlDsa.Services.Verify, MlDsaVerify, (MlDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} + const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = { /// Version CryptoServiceGetCryptoVersion, @@ -7987,4 +8234,15 @@ const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = { CryptoServiceEdDsaGetPrivateKeyFromPem, CryptoServiceEdDsaSign, CryptoServiceEdDsaVerify, + /// ML-DSA + CryptoServiceMlDsaNewByNid, + CryptoServiceMlDsaFree, + CryptoServiceMlDsaSetPrivKey, + CryptoServiceMlDsaGeneratePubKey, + CryptoServiceMlDsaSetPubKey, + CryptoServiceMlDsaGetPubKey, + CryptoServiceMlDsaGetPublicKeyFromX509, + CryptoServiceMlDsaGetPrivateKeyFromPem, + CryptoServiceMlDsaSign, + CryptoServiceMlDsaVerify, }; diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h b/CryptoPkg/Include/Library/BaseCryptLib.h index 5e6c0b676b..801001c6c1 100644 --- a/CryptoPkg/Include/Library/BaseCryptLib.h +++ b/CryptoPkg/Include/Library/BaseCryptLib.h @@ -31,6 +31,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // EdDSA #define CRYPTO_NID_ED448 0x0440 +// ML-DSA +#define CRYPTO_NID_ML_DSA_87 0x05B3 + /// /// MD5 digest size in bytes /// @@ -5030,3 +5033,302 @@ EdDsaGetPublicKeyFromX509 ( IN UINTN CertSize, OUT VOID **EdDsaContext ); + +/** + Creates a new ML-DSA context by Crypto NID. + + This function allocates and initializes a new ML-DSA context for the specified + ML-DSA variant. The context is created with no key material; the EVP_PKEY + structure is set to NULL. The caller must call MlDsaFree() to release the + context when done. + + Before keys can be used for signing or verification, they must be set using + MlDsaSetPrivKey() or MlDsaSetPubKey(). + + If Nid is not a supported ML-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the ML-DSA variant (e.g., CRYPTO_NID_ML_DSA_87). + + @retval Pointer to new ML-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +MlDsaNewByNid ( + IN UINTN Nid + ); + +/** + Frees an ML-DSA context and all associated resources. + + This function releases all memory associated with the ML-DSA context, including + the EVP_PKEY structure. After calling this function, the MlDsaContext pointer + should not be used. + + If MlDsaContext is NULL, then this function returns immediately without action. + + @param[in] MlDsaContext Pointer to the ML-DSA context to be released. + +**/ +VOID +EFIAPI +MlDsaFree ( + IN VOID *MlDsaContext + ); + +/** + Retrieves the ML-DSA public key from the ML-DSA context. + + This function extracts the public key from the ML-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via MlDsaSetPrivKey() or MlDsaSetPubKey()) + before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE ML-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ); + +/** + Sets the ML-DSA public key in the ML-DSA context. + + This function imports a raw public key into the ML-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (2592 bytes for ML-DSA-87). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE ML-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPubKey ( + IN VOID *MlDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Sets the ML-DSA private key in the ML-DSA context. + + This function imports a raw private key into the ML-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (4896 bytes for ML-DSA-87). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If MlDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE ML-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPrivKey ( + IN VOID *MlDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ); + +/** + Generates and retrieves the public key from a private key context. + + This function extracts the public key from an ML-DSA context that contains + a private key. It is equivalent to calling MlDsaGetPubKey() but is provided + for API consistency with other cryptographic implementations. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +MlDsaGeneratePubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Generates an ML-DSA signature for a given message. + + This function creates an ML-DSA signature using the private key stored in the + ML-DSA context. ML-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + If SigSize buffer is too small, SigSize is updated with required size and return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (4627 bytes for ML-DSA-87). + + @retval TRUE ML-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +MlDsaSign ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ); + +/** + Verifies the ML-DSA signature for a given message. + + This function verifies an ML-DSA signature against a message using the public key + contained in the ML-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via MlDsaSetPrivKey() + or MlDsaSetPubKey() before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the ML-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE ML-DSA signature verification succeeded. + @retval FALSE ML-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +MlDsaVerify ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ); + +/** + Retrieve the ML-DSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contains + the retrieved ML-DSA private key. Use MlDsaFree() to free. + + @retval TRUE ML-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **MlDsaContext + ); + +/** + Retrieve the ML-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contain the retrieved + ML-DSA public key component. Use MlDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @retval TRUE ML-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve ML-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **MlDsaContext + ); diff --git a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h index 4e5a679bfa..56701f2202 100644 --- a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h +++ b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h @@ -468,4 +468,19 @@ typedef struct { } Services; UINT32 Family; } EdDsa; + union { + struct { + UINT8 NewByNid : 1; + UINT8 Free : 1; + UINT8 SetPrivKey : 1; + UINT8 GeneratePubKey : 1; + UINT8 SetPubKey : 1; + UINT8 GetPubKey : 1; + UINT8 GetPublicKeyFromX509 : 1; + UINT8 GetPrivateKeyFromPem : 1; + UINT8 Sign : 1; + UINT8 Verify : 1; + } Services; + UINT32 Family; + } MlDsa; } PCD_CRYPTO_SERVICE_FAMILY_ENABLE; diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf index 9c0752655d..f3d22f7173 100644 --- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf @@ -62,6 +62,7 @@ Pk/CryptRsaPssSign.c Pk/CryptEc.c Pk/CryptEdDsa.c + Pk/CryptMlDsa.c Pem/CryptPem.c Bn/CryptBn.c diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf index 0f7a441cfa..2cf4cab6f9 100644 --- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf @@ -61,6 +61,7 @@ Pk/CryptRsaPssSignNull.c Pk/CryptEcNull.c Pk/CryptEdDsaNull.c + Pk/CryptMlDsaNull.c Pem/CryptPemNull.c Rand/CryptRandNull.c Bn/CryptBnNull.c diff --git a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c index bd0c70d328..eb333abce0 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c +++ b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c @@ -128,6 +128,63 @@ AllocateKeyContext ( return TRUE; } +/** + Convert an ML-DSA type name string to an OpenSSL NID. + + This helper function translates ML-DSA type name strings (e.g., "ML-DSA-87") + to their corresponding OpenSSL EVP_PKEY NIDs (e.g., EVP_PKEY_ML_DSA_87). + + If the type name is not recognized, EVP_PKEY_NONE is returned. + + @param[in] TypeName ML-DSA type name string (e.g., "ML-DSA-87"). + + @retval OpenSSL NID (e.g., EVP_PKEY_ML_DSA_87) if recognized. + @retval EVP_PKEY_NONE if the type name is not recognized. + +**/ +STATIC +INT32 +MlDsaTypeNameToNid ( + IN CONST CHAR8 *TypeName + ) +{ + INT32 Nid; + + if (AsciiStrCmp (TypeName, "ML-DSA-87") == 0) { + Nid = EVP_PKEY_ML_DSA_87; + } else { + Nid = EVP_PKEY_NONE; + } + + return Nid; +} + +/** + Check if the given NID is supported for ML-DSA. + + This helper function checks if the provided NID corresponds to a supported + ML-DSA type. Currently, only EVP_PKEY_ML_DSA_87 is supported. + + @param[in] Nid The NID to check. + + @retval TRUE The NID is supported for ML-DSA. + @retval FALSE The NID is not supported for ML-DSA. + +**/ +STATIC +BOOLEAN +IsMlDsaNidSupported ( + IN INT32 Nid + ) +{ + switch (Nid) { + case EVP_PKEY_ML_DSA_87: + return TRUE; + default: + return FALSE; + } +} + /** Retrieve the RSA Private Key from the password-protected PEM key data. @@ -347,3 +404,58 @@ EdDsaGetPrivateKeyFromPem ( return TRUE; } + +/** + Retrieve the ML-DSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contains + the retrieved ML-DSA private key. Use MlDsaFree() to free. + + @retval TRUE ML-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **MlDsaContext + ) +{ + EVP_PKEY *Pkey; + INT32 Nid; + + // + // Check input parameters. + // + if ((PemData == NULL) || (MlDsaContext == NULL) || (PemSize > INT_MAX)) { + return FALSE; + } + + // Read PEM data + if (!GetPrivateKeyFromPem (PemData, PemSize, Password, &Pkey)) { + return FALSE; + } + + Nid = MlDsaTypeNameToNid (EVP_PKEY_get0_type_name (Pkey)); + if (!IsMlDsaNidSupported (Nid)) { + EVP_PKEY_free (Pkey); + return FALSE; + } + + // Allocate wrapper structure (now consistent with other key types) + if (!AllocateKeyContext (Pkey, Nid, MlDsaContext)) { + EVP_PKEY_free (Pkey); + return FALSE; + } + + return TRUE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c index d7373761de..134e511f7f 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c +++ b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c @@ -96,3 +96,32 @@ EdDsaGetPrivateKeyFromPem ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the ML-DSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contains + the retrieved ML-DSA private key. Use MlDsaFree() to free. + + @retval TRUE ML-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **MlDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsa.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsa.c new file mode 100644 index 0000000000..45ea241148 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsa.c @@ -0,0 +1,692 @@ +/** @file + ML-DSA API implementation based on OpenSSL + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "InternalCryptLib.h" +#include "KeyContext.h" +#include <openssl/core_names.h> +#include <openssl/crypto.h> +#include <openssl/evp.h> +#include <openssl/param_build.h> + +/** + Get the public key size in bytes for an ML-DSA variant from its OpenSSL NID. + + This helper function maps OpenSSL ML-DSA NIDs to their corresponding public key sizes. + For ML-DSA-87, the public key size is 2592 bytes. + + If the NID is not supported, PubKeySize is set to 0 and FALSE is returned. + + @param[in] Nid OpenSSL NID of the ML-DSA variant (e.g., EVP_PKEY_ML_DSA_87). + @param[out] PubKeySize Pointer to receive the public key size in bytes. + + @retval TRUE Public key size retrieved successfully. + @retval FALSE Unsupported ML-DSA NID. + +**/ +STATIC +BOOLEAN +OpensslNidToPubKeySize ( + IN UINTN Nid, + OUT UINTN *PubKeySize + ) +{ + switch (Nid) { + case EVP_PKEY_ML_DSA_87: + *PubKeySize = 2592; + break; + default: + *PubKeySize = 0; + return FALSE; + } + + return TRUE; +} + +/** + Get the private key size in bytes for an ML-DSA variant from its OpenSSL NID. + + This helper function maps OpenSSL ML-DSA NIDs to their corresponding private key sizes. + For ML-DSA-87, the private key size is 4896 bytes. + + If the NID is not supported, PrivKeySize is set to 0 and FALSE is returned. + + @param[in] Nid OpenSSL NID of the ML-DSA variant (e.g., EVP_PKEY_ML_DSA_87). + @param[out] PrivKeySize Pointer to receive the private key size in bytes. + + @retval TRUE Private key size retrieved successfully. + @retval FALSE Unsupported ML-DSA NID. + +**/ +STATIC +BOOLEAN +OpensslNidToPrivKeySize ( + IN UINTN Nid, + OUT UINTN *PrivKeySize + ) +{ + switch (Nid) { + case EVP_PKEY_ML_DSA_87: + *PrivKeySize = 4896; + break; + default: + *PrivKeySize = 0; + return FALSE; + } + + return TRUE; +} + +/** + Get the signature size in bytes for an ML-DSA variant from its OpenSSL NID. + + This helper function maps OpenSSL ML-DSA NIDs to their corresponding signature sizes. + For ML-DSA-87, the signature size is 4627 bytes. + + If the NID is not supported, SignatureSize is set to 0 and FALSE is returned. + + @param[in] Nid OpenSSL NID of the ML-DSA variant (e.g., EVP_PKEY_ML_DSA_87). + @param[out] SignatureSize Pointer to receive the signature size in bytes. + + @retval TRUE Signature size retrieved successfully. + @retval FALSE Unsupported ML-DSA NID. + +**/ +STATIC +BOOLEAN +OpensslNidToSignatureSize ( + IN UINTN Nid, + OUT UINTN *SignatureSize + ) +{ + switch (Nid) { + case EVP_PKEY_ML_DSA_87: + *SignatureSize = 4627; + break; + default: + *SignatureSize = 0; + return FALSE; + } + + return TRUE; +} + +/** + Convert a Crypto NID to an OpenSSL NID. + + This helper function translates EDK II Crypto library NIDs (e.g., CRYPTO_NID_ML_DSA_87) + to their corresponding OpenSSL EVP_PKEY NIDs (e.g., EVP_PKEY_ML_DSA_87). + + If the Crypto NID is not supported, EVP_PKEY_NONE is returned. + + @param[in] CryptoNid EDK II Crypto library NID (e.g., CRYPTO_NID_ML_DSA_87). + + @retval OpenSSL NID (e.g., EVP_PKEY_ML_DSA_87) if supported. + @retval EVP_PKEY_NONE if the Crypto NID is unsupported. + +**/ +STATIC +INT32 +CryptoNidToOpensslNid ( + IN UINTN CryptoNid + ) +{ + INT32 Nid; + + switch (CryptoNid) { + case CRYPTO_NID_ML_DSA_87: + Nid = EVP_PKEY_ML_DSA_87; + break; + default: + Nid = EVP_PKEY_NONE; + break; + } + + return Nid; +} + +/** + Convert an ML-DSA type name string to an OpenSSL NID. + + This helper function translates ML-DSA type name strings (e.g., "ML-DSA-87") + to their corresponding OpenSSL EVP_PKEY NIDs (e.g., EVP_PKEY_ML_DSA_87). + + If the type name is not recognized, EVP_PKEY_NONE is returned. + + @param[in] TypeName ML-DSA type name string (e.g., "ML-DSA-87"). + + @retval OpenSSL NID (e.g., EVP_PKEY_ML_DSA_87) if recognized. + @retval EVP_PKEY_NONE if the type name is not recognized. + +**/ +STATIC +INT32 +MlDsaTypeNameToNid ( + IN CONST CHAR8 *TypeName + ) +{ + INT32 Nid; + + if (AsciiStrCmp (TypeName, "ML-DSA-87") == 0) { + Nid = EVP_PKEY_ML_DSA_87; + } else { + Nid = EVP_PKEY_NONE; + } + + return Nid; +} + +/** + Creates a new ML-DSA context by Crypto NID. + + This function allocates and initializes a new ML-DSA context for the specified + ML-DSA variant. The context is created with no key material; the EVP_PKEY + structure is set to NULL. The caller must call MlDsaFree() to release the + context when done. + + Before keys can be used for signing or verification, they must be set using + MlDsaSetPrivKey() or MlDsaSetPubKey(). + + If Nid is not a supported ML-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the ML-DSA variant (e.g., CRYPTO_NID_ML_DSA_87). + + @retval Pointer to new ML-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +MlDsaNewByNid ( + IN UINTN Nid + ) +{ + KEY_CONTEXT *Ctx; + INT32 OpensslNid; + + OpensslNid = CryptoNidToOpensslNid (Nid); + if (OpensslNid <= EVP_PKEY_NONE) { + return NULL; + } + + Ctx = (KEY_CONTEXT *)AllocateZeroPool (sizeof (KEY_CONTEXT)); + if (Ctx == NULL) { + return NULL; + } + + Ctx->Nid = OpensslNid; + Ctx->EvpPkey = NULL; + + return (VOID *)Ctx; +} + +/** + Frees an ML-DSA context and all associated resources. + + This function releases all memory associated with the ML-DSA context, including + the EVP_PKEY structure. After calling this function, the MlDsaContext pointer + should not be used. + + If MlDsaContext is NULL, then this function returns immediately without action. + + @param[in] MlDsaContext Pointer to the ML-DSA context to be released. + +**/ +VOID +EFIAPI +MlDsaFree ( + IN VOID *MlDsaContext + ) +{ + KEY_CONTEXT *Ctx; + + if (MlDsaContext == NULL) { + return; + } + + Ctx = (KEY_CONTEXT *)MlDsaContext; + + if (Ctx->EvpPkey != NULL) { + EVP_PKEY_free (Ctx->EvpPkey); + } + + FreePool (Ctx); +} + +/** + Sets the ML-DSA private key in the ML-DSA context. + + This function imports a raw private key into the ML-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (4896 bytes for ML-DSA-87). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If MlDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE ML-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPrivKey ( + IN VOID *MlDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + KEY_CONTEXT *Ctx; + UINTN FinalPrivateKeySize; + + if ((MlDsaContext == NULL) || (PrivateKey == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)MlDsaContext; + + if (!OpensslNidToPrivKeySize (Ctx->Nid, &FinalPrivateKeySize)) { + return FALSE; + } + + if (FinalPrivateKeySize != PrivateKeySize) { + return FALSE; + } + + if (Ctx->EvpPkey != NULL) { + EVP_PKEY_free (Ctx->EvpPkey); + Ctx->EvpPkey = NULL; + } + + Ctx->EvpPkey = EVP_PKEY_new_raw_private_key (Ctx->Nid, NULL, PrivateKey, PrivateKeySize); + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + return TRUE; +} + +/** + Generates and retrieves the public key from a private key context. + + This function extracts the public key from an ML-DSA context that contains + a private key. It is equivalent to calling MlDsaGetPubKey() but is provided + for API consistency with other cryptographic implementations. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +MlDsaGeneratePubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + return FALSE; +} + +/** + Sets the ML-DSA public key in the ML-DSA context. + + This function imports a raw public key into the ML-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (2592 bytes for ML-DSA-87). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE ML-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPubKey ( + IN VOID *MlDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + KEY_CONTEXT *Ctx; + UINTN FinalPublicKeySize; + + if ((MlDsaContext == NULL) || (PublicKey == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)MlDsaContext; + + if (!OpensslNidToPubKeySize (Ctx->Nid, &FinalPublicKeySize)) { + return FALSE; + } + + if (FinalPublicKeySize != PublicKeySize) { + return FALSE; + } + + if (Ctx->EvpPkey != NULL) { + EVP_PKEY_free (Ctx->EvpPkey); + Ctx->EvpPkey = NULL; + } + + Ctx->EvpPkey = EVP_PKEY_new_raw_public_key (Ctx->Nid, NULL, PublicKey, PublicKeySize); + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + return TRUE; +} + +/** + Retrieves the ML-DSA public key from the ML-DSA context. + + This function extracts the public key from the ML-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via MlDsaSetPrivKey() or MlDsaSetPubKey()) + before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE ML-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + KEY_CONTEXT *Ctx; + INT32 Result; + UINTN FinalPublicKeySize; + + if ((MlDsaContext == NULL) || (PublicKeySize == NULL)) { + return FALSE; + } + + if (PublicKey == NULL) { + *PublicKeySize = 0; + return FALSE; + } + + Ctx = (KEY_CONTEXT *)MlDsaContext; + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + if (!OpensslNidToPubKeySize (Ctx->Nid, &FinalPublicKeySize)) { + return FALSE; + } + + if (*PublicKeySize < FinalPublicKeySize) { + *PublicKeySize = FinalPublicKeySize; + return FALSE; + } + + *PublicKeySize = FinalPublicKeySize; + + Result = EVP_PKEY_get_raw_public_key (Ctx->EvpPkey, PublicKey, PublicKeySize); + if (Result != 1) { + return FALSE; + } + + return TRUE; +} + +/** + Generates an ML-DSA signature for a given message. + + This function creates an ML-DSA signature using the private key stored in the + ML-DSA context. ML-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + If SigSize buffer is too small, SigSize is updated with required size and return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (4627 bytes for ML-DSA-87). + + @retval TRUE ML-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +MlDsaSign ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + KEY_CONTEXT *Ctx; + EVP_MD_CTX *SignCtx; + INT32 Result; + UINTN FinalSigSize; + OSSL_PARAM Params[2]; + OSSL_PARAM ParamsDefault[1]; + + if ((MlDsaContext == NULL) || (Message == NULL)) { + return FALSE; + } + + if ((Signature == NULL) || (SigSize == NULL)) { + return FALSE; + } + + if ((ContextSize > 0) && (Context == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)MlDsaContext; + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + if (!OpensslNidToSignatureSize (Ctx->Nid, &FinalSigSize)) { + return FALSE; + } + + if (*SigSize < FinalSigSize) { + *SigSize = FinalSigSize; + return FALSE; + } + + *SigSize = FinalSigSize; + ZeroMem (Signature, *SigSize); + + Params[0] = OSSL_PARAM_construct_octet_string (OSSL_SIGNATURE_PARAM_CONTEXT_STRING, (VOID *)Context, ContextSize); + Params[1] = OSSL_PARAM_construct_end (); + + Result = FALSE; + SignCtx = EVP_MD_CTX_new (); + if (SignCtx == NULL) { + return FALSE; + } + + if (ContextSize == 0) { + ParamsDefault[0] = OSSL_PARAM_construct_end (); + Result = EVP_DigestSignInit_ex (SignCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, ParamsDefault); + } else { + Result = EVP_DigestSignInit_ex (SignCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, Params); + } + + if (Result != 1) { + EVP_MD_CTX_free (SignCtx); + return FALSE; + } + + Result = EVP_DigestSign (SignCtx, Signature, SigSize, Message, MessageSize); + if (Result != 1) { + EVP_MD_CTX_free (SignCtx); + return FALSE; + } + + EVP_MD_CTX_free (SignCtx); + return TRUE; +} + +/** + Verifies the ML-DSA signature for a given message. + + This function verifies an ML-DSA signature against a message using the public key + contained in the ML-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via MlDsaSetPrivKey() + or MlDsaSetPubKey() before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the ML-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE ML-DSA signature verification succeeded. + @retval FALSE ML-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +MlDsaVerify ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + KEY_CONTEXT *Ctx; + EVP_MD_CTX *VerifyCtx; + INT32 OpensslNid; + UINTN FinalSigSize; + INT32 Result; + OSSL_PARAM Params[2]; + OSSL_PARAM ParamsDefault[1]; + + if ((MlDsaContext == NULL) || (Message == NULL) || (Signature == NULL)) { + return FALSE; + } + + if ((SigSize > INT_MAX) || (SigSize == 0)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)MlDsaContext; + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + OpensslNid = MlDsaTypeNameToNid (EVP_PKEY_get0_type_name (Ctx->EvpPkey)); + if (!OpensslNidToSignatureSize (OpensslNid, &FinalSigSize)) { + return FALSE; + } + + if (SigSize != FinalSigSize) { + return FALSE; + } + + Params[0] = OSSL_PARAM_construct_octet_string (OSSL_SIGNATURE_PARAM_CONTEXT_STRING, (VOID *)Context, ContextSize); + Params[1] = OSSL_PARAM_construct_end (); + + VerifyCtx = EVP_MD_CTX_new (); + if (VerifyCtx == NULL) { + return FALSE; + } + + if (ContextSize == 0) { + ParamsDefault[0] = OSSL_PARAM_construct_end (); + Result = EVP_DigestVerifyInit_ex (VerifyCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, ParamsDefault); + } else { + Result = EVP_DigestVerifyInit_ex (VerifyCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, Params); + } + + if (Result != 1) { + EVP_MD_CTX_free (VerifyCtx); + return FALSE; + } + + Result = EVP_DigestVerify (VerifyCtx, Signature, SigSize, Message, MessageSize); + if (Result != 1) { + EVP_MD_CTX_free (VerifyCtx); + return FALSE; + } + + EVP_MD_CTX_free (VerifyCtx); + return TRUE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsaNull.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsaNull.c new file mode 100644 index 0000000000..2e443fb25a --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsaNull.c @@ -0,0 +1,291 @@ +/** @file + ML-DSA API implementation based on OpenSSL + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/BaseCryptLib.h> +#include <Library/DebugLib.h> + +/** + Creates a new ML-DSA context by Crypto NID. + + This function allocates and initializes a new ML-DSA context for the specified + ML-DSA variant. The context is created with no key material; the EVP_PKEY + structure is set to NULL. The caller must call MlDsaFree() to release the + context when done. + + Before keys can be used for signing or verification, they must be set using + MlDsaSetPrivKey() or MlDsaSetPubKey(). + + If Nid is not a supported ML-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the ML-DSA variant (e.g., CRYPTO_NID_ML_DSA_87). + + @retval Pointer to new ML-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +MlDsaNewByNid ( + IN UINTN Nid + ) +{ + ASSERT (FALSE); + return NULL; +} + +/** + Frees an ML-DSA context and all associated resources. + + This function releases all memory associated with the ML-DSA context, including + the EVP_PKEY structure. After calling this function, the MlDsaContext pointer + should not be used. + + If MlDsaContext is NULL, then this function returns immediately without action. + + @param[in] MlDsaContext Pointer to the ML-DSA context to be released. + +**/ +VOID +EFIAPI +MlDsaFree ( + IN VOID *MlDsaContext + ) +{ + ASSERT (FALSE); +} + +/** + Retrieves the ML-DSA public key from the ML-DSA context. + + This function extracts the public key from the ML-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via MlDsaSetPrivKey() or MlDsaSetPubKey()) + before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE ML-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the ML-DSA public key in the ML-DSA context. + + This function imports a raw public key into the ML-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (2592 bytes for ML-DSA-87). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE ML-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPubKey ( + IN VOID *MlDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the ML-DSA private key in the ML-DSA context. + + This function imports a raw private key into the ML-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (4896 bytes for ML-DSA-87). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If MlDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE ML-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPrivKey ( + IN VOID *MlDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates and retrieves the public key from a private key context. + + This function extracts the public key from an ML-DSA context that contains + a private key. It is equivalent to calling MlDsaGetPubKey() but is provided + for API consistency with other cryptographic implementations. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +MlDsaGeneratePubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates an ML-DSA signature for a given message. + + This function creates an ML-DSA signature using the private key stored in the + ML-DSA context. ML-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + If SigSize buffer is too small, SigSize is updated with required size and return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (4627 bytes for ML-DSA-87). + + @retval TRUE ML-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +MlDsaSign ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Verifies the ML-DSA signature for a given message. + + This function verifies an ML-DSA signature against a message using the public key + contained in the ML-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via MlDsaSetPrivKey() + or MlDsaSetPubKey() before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the ML-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE ML-DSA signature verification succeeded. + @retval FALSE ML-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +MlDsaVerify ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c index 3506956df1..7ae6df3d13 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c @@ -25,6 +25,63 @@ static CONST UINT8 mOidBasicConstraints[] = OID_BASIC_CONSTRAINTS; #define CRYPTO_ASN1_TAG_PC_MASK 0x20 #define CRYPTO_ASN1_TAG_VALUE_MASK 0x1F +/** + Convert an ML-DSA type name string to an OpenSSL NID. + + This helper function translates ML-DSA type name strings (e.g., "ML-DSA-87") + to their corresponding OpenSSL EVP_PKEY NIDs (e.g., EVP_PKEY_ML_DSA_87). + + If the type name is not recognized, EVP_PKEY_NONE is returned. + + @param[in] TypeName ML-DSA type name string (e.g., "ML-DSA-87"). + + @retval OpenSSL NID (e.g., EVP_PKEY_ML_DSA_87) if recognized. + @retval EVP_PKEY_NONE if the type name is not recognized. + +**/ +STATIC +INT32 +MlDsaTypeNameToNid ( + IN CONST CHAR8 *TypeName + ) +{ + INT32 Nid; + + if (AsciiStrCmp (TypeName, "ML-DSA-87") == 0) { + Nid = EVP_PKEY_ML_DSA_87; + } else { + Nid = EVP_PKEY_NONE; + } + + return Nid; +} + +/** + Check if the given NID is supported for ML-DSA. + + This helper function checks if the provided NID corresponds to a supported + ML-DSA type. Currently, only EVP_PKEY_ML_DSA_87 is supported. + + @param[in] Nid The NID to check. + + @retval TRUE The NID is supported for ML-DSA. + @retval FALSE The NID is not supported for ML-DSA. + +**/ +STATIC +BOOLEAN +IsMlDsaNidSupported ( + IN INT32 Nid + ) +{ + switch (Nid) { + case EVP_PKEY_ML_DSA_87: + return TRUE; + default: + return FALSE; + } +} + /** Construct a X509 object from DER-encoded certificate data. @@ -1076,6 +1133,119 @@ _Exit: return Status; } +/** + Retrieve the ML-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] MlDsaContext Pointer to new-generated ML DSA context which contain the retrieved + ML-DSA public key component. Use MlDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @retval TRUE ML-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve ML-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **MlDsaContext + ) +{ + BOOLEAN Status; + EVP_PKEY *Pkey; + EVP_PKEY *DupPkey; + INT32 Nid; + X509 *X509Cert; + KEY_CONTEXT *Ctx; + + if ((Cert == NULL) || (MlDsaContext == NULL)) { + return FALSE; + } + + // + // If CertSize is 0, return FALSE to be safe. + // + if (CertSize == 0) { + *MlDsaContext = NULL; + return FALSE; + } + + Pkey = NULL; + X509Cert = NULL; + Status = FALSE; + + // + // Read DER-encoded X509 Certificate and Construct X509 object. + // + Status = X509ConstructCertificate (Cert, CertSize, (UINT8 **)&X509Cert); + if (!Status || (X509Cert == NULL)) { + Status = FALSE; + goto _Exit; + } + + // + // Retrieve and check EVP_PKEY data from X509 Certificate. + // + Pkey = X509_get_pubkey (X509Cert); + if (Pkey == NULL) { + Status = FALSE; + goto _Exit; + } + + // + // Check if the retrieved EVP_PKEY is one supported ML-DSA key type. + // + Nid = MlDsaTypeNameToNid (EVP_PKEY_get0_type_name (Pkey)); + if (!IsMlDsaNidSupported (Nid)) { + Status = FALSE; + goto _Exit; + } + + // + // Duplicate EdDSA Context from the retrieved EVP_PKEY. + // + DupPkey = EVP_PKEY_dup (Pkey); + if (DupPkey == NULL) { + Status = FALSE; + goto _Exit; + } + + // + // Allocate KEY_CONTEXT wrapper structure + // + Ctx = (KEY_CONTEXT *)AllocateZeroPool (sizeof (KEY_CONTEXT)); + if (Ctx == NULL) { + EVP_PKEY_free (DupPkey); + Status = FALSE; + goto _Exit; + } + + Ctx->Nid = Nid; + Ctx->EvpPkey = DupPkey; + *MlDsaContext = (VOID *)Ctx; + Status = TRUE; + +_Exit: + // + // Release Resources. + // + if (X509Cert != NULL) { + X509_free (X509Cert); + } + + if (Pkey != NULL) { + EVP_PKEY_free (Pkey); + } + + return Status; +} + /** Retrieve the version from one X.509 certificate. diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c index 125dd40957..4d247383a5 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c @@ -777,3 +777,31 @@ X509GetExtendedBasicConstraints ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the ML-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contain the retrieved + ML-DSA public key component. Use MlDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @retval TRUE ML-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve ML-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **MlDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf index 3b437c715d..e104036245 100644 --- a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf @@ -64,6 +64,7 @@ Pk/CryptRsaPssSignNull.c Pk/CryptEcNull.c Pk/CryptEdDsaNull.c + Pk/CryptMlDsaNull.c Pem/CryptPem.c Bn/CryptBnNull.c diff --git a/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf index b3742a1486..fd3a102f54 100644 --- a/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf @@ -58,6 +58,7 @@ Pk/CryptRsaPssSignNull.c Pk/CryptEcNull.c Pk/CryptEdDsaNull.c + Pk/CryptMlDsaNull.c Bn/CryptBnNull.c SysCall/CrtWrapper.c diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf index 0cb03be53b..ee5a5647ec 100644 --- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf @@ -65,6 +65,7 @@ Pk/CryptRsaPssSignNull.c Pk/CryptEc.c Pk/CryptEdDsa.c + Pk/CryptMlDsa.c Pem/CryptPem.c Bn/CryptBn.c diff --git a/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf index 0bc9a68498..216ffd8435 100644 --- a/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf @@ -52,6 +52,7 @@ Bn/CryptBn.c Pk/CryptEc.c Pk/CryptEdDsa.c + Pk/CryptMlDsa.c SysCall/UnitTestHostCrtWrapper.c diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPemNull.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPemNull.c index eb9e1274a7..abdcc2d160 100644 --- a/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPemNull.c +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPemNull.c @@ -97,3 +97,32 @@ EdDsaGetPrivateKeyFromPem ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the ML-DSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contains + the retrieved ML-DSA private key. Use MlDsaFree() to free. + + @retval TRUE ML-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **MlDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptMlDsaNull.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptMlDsaNull.c new file mode 100644 index 0000000000..2e443fb25a --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptMlDsaNull.c @@ -0,0 +1,291 @@ +/** @file + ML-DSA API implementation based on OpenSSL + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/BaseCryptLib.h> +#include <Library/DebugLib.h> + +/** + Creates a new ML-DSA context by Crypto NID. + + This function allocates and initializes a new ML-DSA context for the specified + ML-DSA variant. The context is created with no key material; the EVP_PKEY + structure is set to NULL. The caller must call MlDsaFree() to release the + context when done. + + Before keys can be used for signing or verification, they must be set using + MlDsaSetPrivKey() or MlDsaSetPubKey(). + + If Nid is not a supported ML-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the ML-DSA variant (e.g., CRYPTO_NID_ML_DSA_87). + + @retval Pointer to new ML-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +MlDsaNewByNid ( + IN UINTN Nid + ) +{ + ASSERT (FALSE); + return NULL; +} + +/** + Frees an ML-DSA context and all associated resources. + + This function releases all memory associated with the ML-DSA context, including + the EVP_PKEY structure. After calling this function, the MlDsaContext pointer + should not be used. + + If MlDsaContext is NULL, then this function returns immediately without action. + + @param[in] MlDsaContext Pointer to the ML-DSA context to be released. + +**/ +VOID +EFIAPI +MlDsaFree ( + IN VOID *MlDsaContext + ) +{ + ASSERT (FALSE); +} + +/** + Retrieves the ML-DSA public key from the ML-DSA context. + + This function extracts the public key from the ML-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via MlDsaSetPrivKey() or MlDsaSetPubKey()) + before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE ML-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the ML-DSA public key in the ML-DSA context. + + This function imports a raw public key into the ML-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (2592 bytes for ML-DSA-87). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE ML-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPubKey ( + IN VOID *MlDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the ML-DSA private key in the ML-DSA context. + + This function imports a raw private key into the ML-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (4896 bytes for ML-DSA-87). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If MlDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE ML-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPrivKey ( + IN VOID *MlDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates and retrieves the public key from a private key context. + + This function extracts the public key from an ML-DSA context that contains + a private key. It is equivalent to calling MlDsaGetPubKey() but is provided + for API consistency with other cryptographic implementations. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +MlDsaGeneratePubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates an ML-DSA signature for a given message. + + This function creates an ML-DSA signature using the private key stored in the + ML-DSA context. ML-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + If SigSize buffer is too small, SigSize is updated with required size and return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (4627 bytes for ML-DSA-87). + + @retval TRUE ML-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +MlDsaSign ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Verifies the ML-DSA signature for a given message. + + This function verifies an ML-DSA signature against a message using the public key + contained in the ML-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via MlDsaSetPrivKey() + or MlDsaSetPubKey() before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the ML-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE ML-DSA signature verification succeeded. + @retval FALSE ML-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +MlDsaVerify ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509.c index ac4c59ed79..85a4934b12 100644 --- a/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509.c +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509.c @@ -707,6 +707,34 @@ EdDsaGetPublicKeyFromX509 ( return FALSE; } +/** + Retrieve the ML-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contain the retrieved + ML-DSA public key component. Use MlDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @retval TRUE ML-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve ML-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **MlDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} + /** Verify one X509 certificate was issued by the trusted CA. diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509Null.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509Null.c index 5132e96ea3..6474c03761 100644 --- a/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509Null.c +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Pk/CryptX509Null.c @@ -777,3 +777,31 @@ X509GetExtendedBasicConstraints ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the ML-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contain the retrieved + ML-DSA public key component. Use MlDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @retval TRUE ML-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve ML-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **MlDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibNull/Pem/CryptPemNull.c b/CryptoPkg/Library/BaseCryptLibNull/Pem/CryptPemNull.c index d7373761de..134e511f7f 100644 --- a/CryptoPkg/Library/BaseCryptLibNull/Pem/CryptPemNull.c +++ b/CryptoPkg/Library/BaseCryptLibNull/Pem/CryptPemNull.c @@ -96,3 +96,32 @@ EdDsaGetPrivateKeyFromPem ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the ML-DSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contains + the retrieved ML-DSA private key. Use MlDsaFree() to free. + + @retval TRUE ML-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **MlDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptMlDsaNull.c b/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptMlDsaNull.c new file mode 100644 index 0000000000..2e443fb25a --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptMlDsaNull.c @@ -0,0 +1,291 @@ +/** @file + ML-DSA API implementation based on OpenSSL + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/BaseCryptLib.h> +#include <Library/DebugLib.h> + +/** + Creates a new ML-DSA context by Crypto NID. + + This function allocates and initializes a new ML-DSA context for the specified + ML-DSA variant. The context is created with no key material; the EVP_PKEY + structure is set to NULL. The caller must call MlDsaFree() to release the + context when done. + + Before keys can be used for signing or verification, they must be set using + MlDsaSetPrivKey() or MlDsaSetPubKey(). + + If Nid is not a supported ML-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the ML-DSA variant (e.g., CRYPTO_NID_ML_DSA_87). + + @retval Pointer to new ML-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +MlDsaNewByNid ( + IN UINTN Nid + ) +{ + ASSERT (FALSE); + return NULL; +} + +/** + Frees an ML-DSA context and all associated resources. + + This function releases all memory associated with the ML-DSA context, including + the EVP_PKEY structure. After calling this function, the MlDsaContext pointer + should not be used. + + If MlDsaContext is NULL, then this function returns immediately without action. + + @param[in] MlDsaContext Pointer to the ML-DSA context to be released. + +**/ +VOID +EFIAPI +MlDsaFree ( + IN VOID *MlDsaContext + ) +{ + ASSERT (FALSE); +} + +/** + Retrieves the ML-DSA public key from the ML-DSA context. + + This function extracts the public key from the ML-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via MlDsaSetPrivKey() or MlDsaSetPubKey()) + before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE ML-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the ML-DSA public key in the ML-DSA context. + + This function imports a raw public key into the ML-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (2592 bytes for ML-DSA-87). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE ML-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPubKey ( + IN VOID *MlDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the ML-DSA private key in the ML-DSA context. + + This function imports a raw private key into the ML-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (4896 bytes for ML-DSA-87). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If MlDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE ML-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPrivKey ( + IN VOID *MlDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates and retrieves the public key from a private key context. + + This function extracts the public key from an ML-DSA context that contains + a private key. It is equivalent to calling MlDsaGetPubKey() but is provided + for API consistency with other cryptographic implementations. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +MlDsaGeneratePubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates an ML-DSA signature for a given message. + + This function creates an ML-DSA signature using the private key stored in the + ML-DSA context. ML-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + If SigSize buffer is too small, SigSize is updated with required size and return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (4627 bytes for ML-DSA-87). + + @retval TRUE ML-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +MlDsaSign ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Verifies the ML-DSA signature for a given message. + + This function verifies an ML-DSA signature against a message using the public key + contained in the ML-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via MlDsaSetPrivKey() + or MlDsaSetPubKey() before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the ML-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE ML-DSA signature verification succeeded. + @retval FALSE ML-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +MlDsaVerify ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptX509Null.c b/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptX509Null.c index d4edcc9649..1457bad9cf 100644 --- a/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptX509Null.c +++ b/CryptoPkg/Library/BaseCryptLibNull/Pk/CryptX509Null.c @@ -777,3 +777,31 @@ X509GetExtendedBasicConstraints ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the ML-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contain the retrieved + ML-DSA public key component. Use MlDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @retval TRUE ML-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve ML-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **MlDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c index 0151d31a12..5a1d1cb81e 100644 --- a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c +++ b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c @@ -6670,3 +6670,331 @@ EdDsaVerify ( { CALL_CRYPTO_SERVICE (EdDsaVerify, (EdDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); } + +/** + Creates a new ML-DSA context by Crypto NID. + + This function allocates and initializes a new ML-DSA context for the specified + ML-DSA variant. The context is created with no key material; the EVP_PKEY + structure is set to NULL. The caller must call MlDsaFree() to release the + context when done. + + Before keys can be used for signing or verification, they must be set using + MlDsaSetPrivKey() or MlDsaSetPubKey(). + + If Nid is not a supported ML-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the ML-DSA variant (e.g., CRYPTO_NID_ML_DSA_87). + + @retval Pointer to new ML-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +MlDsaNewByNid ( + IN UINTN Nid + ) +{ + CALL_CRYPTO_SERVICE (MlDsaNewByNid, (Nid), NULL); +} + +/** + Frees an ML-DSA context and all associated resources. + + This function releases all memory associated with the ML-DSA context, including + the EVP_PKEY structure. After calling this function, the MlDsaContext pointer + should not be used. + + If MlDsaContext is NULL, then this function returns immediately without action. + + @param[in] MlDsaContext Pointer to the ML-DSA context to be released. + +**/ +VOID +EFIAPI +MlDsaFree ( + IN VOID *MlDsaContext + ) +{ + CALL_VOID_CRYPTO_SERVICE (MlDsaFree, (MlDsaContext)); +} + +/** + Sets the ML-DSA private key in the ML-DSA context. + + This function imports a raw private key into the ML-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (4896 bytes for ML-DSA-87). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If MlDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE ML-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPrivKey ( + IN VOID *MlDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + CALL_CRYPTO_SERVICE (MlDsaSetPrivKey, (MlDsaContext, PrivateKey, PrivateKeySize), FALSE); +} + +/** + Generates and retrieves the public key from a private key context. + + This function extracts the public key from an ML-DSA context that contains + a private key. It is equivalent to calling MlDsaGetPubKey() but is provided + for API consistency with other cryptographic implementations. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +MlDsaGeneratePubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + CALL_CRYPTO_SERVICE (MlDsaGeneratePubKey, (MlDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Sets the ML-DSA public key in the ML-DSA context. + + This function imports a raw public key into the ML-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (2592 bytes for ML-DSA-87). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE ML-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +MlDsaSetPubKey ( + IN VOID *MlDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + CALL_CRYPTO_SERVICE (MlDsaSetPubKey, (MlDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieves the ML-DSA public key from the ML-DSA context. + + This function extracts the public key from the ML-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via MlDsaSetPrivKey() or MlDsaSetPubKey()) + before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE ML-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPubKey ( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + CALL_CRYPTO_SERVICE (MlDsaGetPubKey, (MlDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieve the ML-DSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contains + the retrieved ML-DSA private key. Use MlDsaFree() to free. + + @retval TRUE ML-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **MlDsaContext + ) +{ + CALL_CRYPTO_SERVICE (MlDsaGetPrivateKeyFromPem, (PemData, PemSize, Password, MlDsaContext), FALSE); +} + +/** + Retrieve the ML-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contains the retrieved + ML-DSA public key component. Use MlDsaFree() to free the resource. + + If Cert is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @retval TRUE ML-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve ML-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +MlDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **MlDsaContext + ) +{ + CALL_CRYPTO_SERVICE (MlDsaGetPublicKeyFromX509, (Cert, CertSize, MlDsaContext), FALSE); +} + +/** + Generates an ML-DSA signature for a given message. + + This function creates an ML-DSA signature using the private key stored in the + ML-DSA context. ML-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via MlDsaSetPrivKey()) before + calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + If SigSize buffer is too small, SigSize is updated with required size and return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (4627 bytes for ML-DSA-87). + + @retval TRUE ML-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +MlDsaSign ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + CALL_CRYPTO_SERVICE (MlDsaSign, (MlDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} + +/** + Verifies the ML-DSA signature for a given message. + + This function verifies an ML-DSA signature against a message using the public key + contained in the ML-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via MlDsaSetPrivKey() + or MlDsaSetPubKey() before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the ML-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE ML-DSA signature verification succeeded. + @retval FALSE ML-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +MlDsaVerify ( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + CALL_CRYPTO_SERVICE (MlDsaVerify, (MlDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-2k-avxifma.s b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-2k-avxifma.s index 6d4ec6f80e..e12c689d2d 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-2k-avxifma.s +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-2k-avxifma.s @@ -2,21 +2,1149 @@ .globl ossl_rsaz_avxifma_eligible .type ossl_rsaz_avxifma_eligible,@function +.align 32 ossl_rsaz_avxifma_eligible: + movl OPENSSL_ia32cap_P+20(%rip),%ecx xorl %eax,%eax + andl $8388608,%ecx + cmpl $8388608,%ecx + cmovel %ecx,%eax .byte 0xf3,0xc3 .size ossl_rsaz_avxifma_eligible, .-ossl_rsaz_avxifma_eligible +.text .globl ossl_rsaz_amm52x20_x1_avxifma256 -.globl ossl_rsaz_amm52x20_x2_avxifma256 -.globl ossl_extract_multiplier_2x20_win5_avx .type ossl_rsaz_amm52x20_x1_avxifma256,@function +.align 32 ossl_rsaz_amm52x20_x1_avxifma256: -ossl_rsaz_amm52x20_x2_avxifma256: -ossl_extract_multiplier_2x20_win5_avx: -.byte 0x0f,0x0b +.cfi_startproc +.byte 243,15,30,250 + pushq %rbx +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbx,-16 + pushq %rbp +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbp,-24 + pushq %r12 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r12,-32 + pushq %r13 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r13,-40 + pushq %r14 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r14,-48 + pushq %r15 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r15,-56 +.Lossl_rsaz_amm52x20_x1_avxifma256_body: + + + vpxor %ymm0,%ymm0,%ymm0 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + vmovapd %ymm0,%ymm8 + + xorl %r9d,%r9d + + movq %rdx,%r11 + movq $0xfffffffffffff,%rax + + + movl $5,%ebx + +.align 32 +.Lloop5: + movq 0(%r11),%r13 + + vpbroadcastq 0(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -168(%rsp),%rsp +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm8 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm8 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm5,32(%rsp) + vmovdqu %ymm6,64(%rsp) + vmovdqu %ymm7,96(%rsp) + vmovdqu %ymm8,128(%rsp) + movq $0,160(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm5 + vmovdqu 72(%rsp),%ymm6 + vmovdqu 104(%rsp),%ymm7 + vmovdqu 136(%rsp),%ymm8 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm8 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm8 + leaq 168(%rsp),%rsp + movq 8(%r11),%r13 + + vpbroadcastq 8(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -168(%rsp),%rsp +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm8 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm8 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm5,32(%rsp) + vmovdqu %ymm6,64(%rsp) + vmovdqu %ymm7,96(%rsp) + vmovdqu %ymm8,128(%rsp) + movq $0,160(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm5 + vmovdqu 72(%rsp),%ymm6 + vmovdqu 104(%rsp),%ymm7 + vmovdqu 136(%rsp),%ymm8 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm8 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm8 + leaq 168(%rsp),%rsp + movq 16(%r11),%r13 + + vpbroadcastq 16(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -168(%rsp),%rsp +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm8 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm8 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm5,32(%rsp) + vmovdqu %ymm6,64(%rsp) + vmovdqu %ymm7,96(%rsp) + vmovdqu %ymm8,128(%rsp) + movq $0,160(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm5 + vmovdqu 72(%rsp),%ymm6 + vmovdqu 104(%rsp),%ymm7 + vmovdqu 136(%rsp),%ymm8 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm8 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm8 + leaq 168(%rsp),%rsp + movq 24(%r11),%r13 + + vpbroadcastq 24(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -168(%rsp),%rsp +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm8 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm8 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm5,32(%rsp) + vmovdqu %ymm6,64(%rsp) + vmovdqu %ymm7,96(%rsp) + vmovdqu %ymm8,128(%rsp) + movq $0,160(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm5 + vmovdqu 72(%rsp),%ymm6 + vmovdqu 104(%rsp),%ymm7 + vmovdqu 136(%rsp),%ymm8 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm8 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm8 + leaq 168(%rsp),%rsp + leaq 32(%r11),%r11 + decl %ebx + jne .Lloop5 + + vmovq %r9,%xmm0 + vpbroadcastq %xmm0,%ymm0 + vpblendd $3,%ymm0,%ymm3,%ymm3 + + + + vpsrlq $52,%ymm3,%ymm0 + vpsrlq $52,%ymm5,%ymm1 + vpsrlq $52,%ymm6,%ymm2 + vpsrlq $52,%ymm7,%ymm13 + vpsrlq $52,%ymm8,%ymm14 + + + vpermq $144,%ymm14,%ymm14 + vpermq $3,%ymm13,%ymm15 + vblendpd $1,%ymm15,%ymm14,%ymm14 + + vpermq $144,%ymm13,%ymm13 + vpermq $3,%ymm2,%ymm15 + vblendpd $1,%ymm15,%ymm13,%ymm13 + + vpermq $144,%ymm2,%ymm2 + vpermq $3,%ymm1,%ymm15 + vblendpd $1,%ymm15,%ymm2,%ymm2 + + vpermq $144,%ymm1,%ymm1 + vpermq $3,%ymm0,%ymm15 + vblendpd $1,%ymm15,%ymm1,%ymm1 + + vpermq $144,%ymm0,%ymm0 + vpand .Lhigh64x3(%rip),%ymm0,%ymm0 + + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + + + vpaddq %ymm0,%ymm3,%ymm3 + vpaddq %ymm1,%ymm5,%ymm5 + vpaddq %ymm2,%ymm6,%ymm6 + vpaddq %ymm13,%ymm7,%ymm7 + vpaddq %ymm14,%ymm8,%ymm8 + + + + vpcmpgtq .Lmask52x4(%rip),%ymm3,%ymm0 + vpcmpgtq .Lmask52x4(%rip),%ymm5,%ymm1 + vpcmpgtq .Lmask52x4(%rip),%ymm6,%ymm2 + vpcmpgtq .Lmask52x4(%rip),%ymm7,%ymm13 + vpcmpgtq .Lmask52x4(%rip),%ymm8,%ymm14 + vmovmskpd %ymm0,%r14d + vmovmskpd %ymm1,%r13d + vmovmskpd %ymm2,%r12d + vmovmskpd %ymm13,%r11d + vmovmskpd %ymm14,%r10d + + + vpcmpeqq .Lmask52x4(%rip),%ymm3,%ymm0 + vpcmpeqq .Lmask52x4(%rip),%ymm5,%ymm1 + vpcmpeqq .Lmask52x4(%rip),%ymm6,%ymm2 + vpcmpeqq .Lmask52x4(%rip),%ymm7,%ymm13 + vpcmpeqq .Lmask52x4(%rip),%ymm8,%ymm14 + vmovmskpd %ymm0,%r9d + vmovmskpd %ymm1,%r8d + vmovmskpd %ymm2,%ebx + vmovmskpd %ymm13,%ecx + vmovmskpd %ymm14,%edx + + + + shlb $4,%r13b + orb %r13b,%r14b + shlb $4,%r11b + orb %r11b,%r12b + + addb %r14b,%r14b + adcb %r12b,%r12b + adcb %r10b,%r10b + + shlb $4,%r8b + orb %r8b,%r9b + shlb $4,%cl + orb %cl,%bl + + addb %r9b,%r14b + adcb %bl,%r12b + adcb %dl,%r10b + + xorb %r9b,%r14b + xorb %bl,%r12b + xorb %dl,%r10b + + leaq .Lkmasklut(%rip),%rdx + + movb %r14b,%r13b + andq $0xf,%r14 + vpsubq .Lmask52x4(%rip),%ymm3,%ymm0 + shlq $5,%r14 + vmovapd (%rdx,%r14,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm3,%ymm3 + + shrb $4,%r13b + andq $0xf,%r13 + vpsubq .Lmask52x4(%rip),%ymm5,%ymm0 + shlq $5,%r13 + vmovapd (%rdx,%r13,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm5,%ymm5 + + movb %r12b,%r11b + andq $0xf,%r12 + vpsubq .Lmask52x4(%rip),%ymm6,%ymm0 + shlq $5,%r12 + vmovapd (%rdx,%r12,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm6,%ymm6 + + shrb $4,%r11b + andq $0xf,%r11 + vpsubq .Lmask52x4(%rip),%ymm7,%ymm0 + shlq $5,%r11 + vmovapd (%rdx,%r11,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm7,%ymm7 + + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm8,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm8,%ymm8 + + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + + vmovdqu %ymm3,0(%rdi) + vmovdqu %ymm5,32(%rdi) + vmovdqu %ymm6,64(%rdi) + vmovdqu %ymm7,96(%rdi) + vmovdqu %ymm8,128(%rdi) + + vzeroupper + movq 0(%rsp),%r15 +.cfi_restore %r15 + movq 8(%rsp),%r14 +.cfi_restore %r14 + movq 16(%rsp),%r13 +.cfi_restore %r13 + movq 24(%rsp),%r12 +.cfi_restore %r12 + movq 32(%rsp),%rbp +.cfi_restore %rbp + movq 40(%rsp),%rbx +.cfi_restore %rbx + leaq 48(%rsp),%rsp +.cfi_adjust_cfa_offset -48 +.Lossl_rsaz_amm52x20_x1_avxifma256_epilogue: .byte 0xf3,0xc3 +.cfi_endproc .size ossl_rsaz_amm52x20_x1_avxifma256, .-ossl_rsaz_amm52x20_x1_avxifma256 +.section .rodata +.align 32 +.Lmask52x4: +.quad 0xfffffffffffff +.quad 0xfffffffffffff +.quad 0xfffffffffffff +.quad 0xfffffffffffff +.Lhigh64x3: +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.Lkmasklut: + +.quad 0x0 +.quad 0x0 +.quad 0x0 +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 +.quad 0x0 + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 + +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0x0 +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.text + +.globl ossl_rsaz_amm52x20_x2_avxifma256 +.type ossl_rsaz_amm52x20_x2_avxifma256,@function +.align 32 +ossl_rsaz_amm52x20_x2_avxifma256: +.cfi_startproc +.byte 243,15,30,250 + pushq %rbx +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbx,-16 + pushq %rbp +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbp,-24 + pushq %r12 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r12,-32 + pushq %r13 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r13,-40 + pushq %r14 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r14,-48 + pushq %r15 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r15,-56 +.Lossl_rsaz_amm52x20_x2_avxifma256_body: + + + vpxor %ymm0,%ymm0,%ymm0 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + vmovapd %ymm0,%ymm8 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm9 + vmovapd %ymm0,%ymm10 + vmovapd %ymm0,%ymm11 + vmovapd %ymm0,%ymm12 + + xorl %r9d,%r9d + xorl %r15d,%r15d + + movq %rdx,%r11 + movq $0xfffffffffffff,%rax + + movl $20,%ebx + +.align 32 +.Lloop20: + movq 0(%r11),%r13 + + vpbroadcastq 0(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq (%r8),%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -168(%rsp),%rsp +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm8 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm8 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm5,32(%rsp) + vmovdqu %ymm6,64(%rsp) + vmovdqu %ymm7,96(%rsp) + vmovdqu %ymm8,128(%rsp) + movq $0,160(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm5 + vmovdqu 72(%rsp),%ymm6 + vmovdqu 104(%rsp),%ymm7 + vmovdqu 136(%rsp),%ymm8 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm8 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm8 + leaq 168(%rsp),%rsp + movq 160(%r11),%r13 + + vpbroadcastq 160(%r11),%ymm1 + movq 160(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r15 + movq %r12,%r10 + adcq $0,%r10 + + movq 8(%r8),%r13 + imulq %r15,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 160(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r15 + adcq %r12,%r10 + + shrq $52,%r15 + salq $12,%r10 + orq %r10,%r15 + + leaq -168(%rsp),%rsp +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52luq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52luq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52luq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52luq 288(%rcx),%ymm2,%ymm12 + + + vmovdqu %ymm4,0(%rsp) + vmovdqu %ymm9,32(%rsp) + vmovdqu %ymm10,64(%rsp) + vmovdqu %ymm11,96(%rsp) + vmovdqu %ymm12,128(%rsp) + movq $0,160(%rsp) + + vmovdqu 8(%rsp),%ymm4 + vmovdqu 40(%rsp),%ymm9 + vmovdqu 72(%rsp),%ymm10 + vmovdqu 104(%rsp),%ymm11 + vmovdqu 136(%rsp),%ymm12 + + addq 8(%rsp),%r15 + +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52huq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52huq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52huq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52huq 288(%rcx),%ymm2,%ymm12 + leaq 168(%rsp),%rsp + leaq 8(%r11),%r11 + decl %ebx + jne .Lloop20 + + vmovq %r9,%xmm0 + vpbroadcastq %xmm0,%ymm0 + vpblendd $3,%ymm0,%ymm3,%ymm3 + + + + vpsrlq $52,%ymm3,%ymm0 + vpsrlq $52,%ymm5,%ymm1 + vpsrlq $52,%ymm6,%ymm2 + vpsrlq $52,%ymm7,%ymm13 + vpsrlq $52,%ymm8,%ymm14 + + + vpermq $144,%ymm14,%ymm14 + vpermq $3,%ymm13,%ymm15 + vblendpd $1,%ymm15,%ymm14,%ymm14 + + vpermq $144,%ymm13,%ymm13 + vpermq $3,%ymm2,%ymm15 + vblendpd $1,%ymm15,%ymm13,%ymm13 + + vpermq $144,%ymm2,%ymm2 + vpermq $3,%ymm1,%ymm15 + vblendpd $1,%ymm15,%ymm2,%ymm2 + + vpermq $144,%ymm1,%ymm1 + vpermq $3,%ymm0,%ymm15 + vblendpd $1,%ymm15,%ymm1,%ymm1 + + vpermq $144,%ymm0,%ymm0 + vpand .Lhigh64x3(%rip),%ymm0,%ymm0 + + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + + + vpaddq %ymm0,%ymm3,%ymm3 + vpaddq %ymm1,%ymm5,%ymm5 + vpaddq %ymm2,%ymm6,%ymm6 + vpaddq %ymm13,%ymm7,%ymm7 + vpaddq %ymm14,%ymm8,%ymm8 + + + + vpcmpgtq .Lmask52x4(%rip),%ymm3,%ymm0 + vpcmpgtq .Lmask52x4(%rip),%ymm5,%ymm1 + vpcmpgtq .Lmask52x4(%rip),%ymm6,%ymm2 + vpcmpgtq .Lmask52x4(%rip),%ymm7,%ymm13 + vpcmpgtq .Lmask52x4(%rip),%ymm8,%ymm14 + vmovmskpd %ymm0,%r14d + vmovmskpd %ymm1,%r13d + vmovmskpd %ymm2,%r12d + vmovmskpd %ymm13,%r11d + vmovmskpd %ymm14,%r10d + + + vpcmpeqq .Lmask52x4(%rip),%ymm3,%ymm0 + vpcmpeqq .Lmask52x4(%rip),%ymm5,%ymm1 + vpcmpeqq .Lmask52x4(%rip),%ymm6,%ymm2 + vpcmpeqq .Lmask52x4(%rip),%ymm7,%ymm13 + vpcmpeqq .Lmask52x4(%rip),%ymm8,%ymm14 + vmovmskpd %ymm0,%r9d + vmovmskpd %ymm1,%r8d + vmovmskpd %ymm2,%ebx + vmovmskpd %ymm13,%ecx + vmovmskpd %ymm14,%edx + + + + shlb $4,%r13b + orb %r13b,%r14b + shlb $4,%r11b + orb %r11b,%r12b + + addb %r14b,%r14b + adcb %r12b,%r12b + adcb %r10b,%r10b + + shlb $4,%r8b + orb %r8b,%r9b + shlb $4,%cl + orb %cl,%bl + + addb %r9b,%r14b + adcb %bl,%r12b + adcb %dl,%r10b + + xorb %r9b,%r14b + xorb %bl,%r12b + xorb %dl,%r10b + + leaq .Lkmasklut(%rip),%rdx + + movb %r14b,%r13b + andq $0xf,%r14 + vpsubq .Lmask52x4(%rip),%ymm3,%ymm0 + shlq $5,%r14 + vmovapd (%rdx,%r14,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm3,%ymm3 + + shrb $4,%r13b + andq $0xf,%r13 + vpsubq .Lmask52x4(%rip),%ymm5,%ymm0 + shlq $5,%r13 + vmovapd (%rdx,%r13,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm5,%ymm5 + + movb %r12b,%r11b + andq $0xf,%r12 + vpsubq .Lmask52x4(%rip),%ymm6,%ymm0 + shlq $5,%r12 + vmovapd (%rdx,%r12,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm6,%ymm6 + + shrb $4,%r11b + andq $0xf,%r11 + vpsubq .Lmask52x4(%rip),%ymm7,%ymm0 + shlq $5,%r11 + vmovapd (%rdx,%r11,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm7,%ymm7 + + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm8,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm8,%ymm8 + + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + + vmovq %r15,%xmm0 + vpbroadcastq %xmm0,%ymm0 + vpblendd $3,%ymm0,%ymm4,%ymm4 + + + + vpsrlq $52,%ymm4,%ymm0 + vpsrlq $52,%ymm9,%ymm1 + vpsrlq $52,%ymm10,%ymm2 + vpsrlq $52,%ymm11,%ymm13 + vpsrlq $52,%ymm12,%ymm14 + + + vpermq $144,%ymm14,%ymm14 + vpermq $3,%ymm13,%ymm15 + vblendpd $1,%ymm15,%ymm14,%ymm14 + + vpermq $144,%ymm13,%ymm13 + vpermq $3,%ymm2,%ymm15 + vblendpd $1,%ymm15,%ymm13,%ymm13 + + vpermq $144,%ymm2,%ymm2 + vpermq $3,%ymm1,%ymm15 + vblendpd $1,%ymm15,%ymm2,%ymm2 + + vpermq $144,%ymm1,%ymm1 + vpermq $3,%ymm0,%ymm15 + vblendpd $1,%ymm15,%ymm1,%ymm1 + + vpermq $144,%ymm0,%ymm0 + vpand .Lhigh64x3(%rip),%ymm0,%ymm0 + + + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + vpand .Lmask52x4(%rip),%ymm11,%ymm11 + vpand .Lmask52x4(%rip),%ymm12,%ymm12 + + + vpaddq %ymm0,%ymm4,%ymm4 + vpaddq %ymm1,%ymm9,%ymm9 + vpaddq %ymm2,%ymm10,%ymm10 + vpaddq %ymm13,%ymm11,%ymm11 + vpaddq %ymm14,%ymm12,%ymm12 + + + + vpcmpgtq .Lmask52x4(%rip),%ymm4,%ymm0 + vpcmpgtq .Lmask52x4(%rip),%ymm9,%ymm1 + vpcmpgtq .Lmask52x4(%rip),%ymm10,%ymm2 + vpcmpgtq .Lmask52x4(%rip),%ymm11,%ymm13 + vpcmpgtq .Lmask52x4(%rip),%ymm12,%ymm14 + vmovmskpd %ymm0,%r14d + vmovmskpd %ymm1,%r13d + vmovmskpd %ymm2,%r12d + vmovmskpd %ymm13,%r11d + vmovmskpd %ymm14,%r10d + + + vpcmpeqq .Lmask52x4(%rip),%ymm4,%ymm0 + vpcmpeqq .Lmask52x4(%rip),%ymm9,%ymm1 + vpcmpeqq .Lmask52x4(%rip),%ymm10,%ymm2 + vpcmpeqq .Lmask52x4(%rip),%ymm11,%ymm13 + vpcmpeqq .Lmask52x4(%rip),%ymm12,%ymm14 + vmovmskpd %ymm0,%r9d + vmovmskpd %ymm1,%r8d + vmovmskpd %ymm2,%ebx + vmovmskpd %ymm13,%ecx + vmovmskpd %ymm14,%edx + + + + shlb $4,%r13b + orb %r13b,%r14b + shlb $4,%r11b + orb %r11b,%r12b + + addb %r14b,%r14b + adcb %r12b,%r12b + adcb %r10b,%r10b + + shlb $4,%r8b + orb %r8b,%r9b + shlb $4,%cl + orb %cl,%bl + + addb %r9b,%r14b + adcb %bl,%r12b + adcb %dl,%r10b + + xorb %r9b,%r14b + xorb %bl,%r12b + xorb %dl,%r10b + + leaq .Lkmasklut(%rip),%rdx + + movb %r14b,%r13b + andq $0xf,%r14 + vpsubq .Lmask52x4(%rip),%ymm4,%ymm0 + shlq $5,%r14 + vmovapd (%rdx,%r14,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm4,%ymm4 + + shrb $4,%r13b + andq $0xf,%r13 + vpsubq .Lmask52x4(%rip),%ymm9,%ymm0 + shlq $5,%r13 + vmovapd (%rdx,%r13,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm9,%ymm9 + + movb %r12b,%r11b + andq $0xf,%r12 + vpsubq .Lmask52x4(%rip),%ymm10,%ymm0 + shlq $5,%r12 + vmovapd (%rdx,%r12,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm10,%ymm10 + + shrb $4,%r11b + andq $0xf,%r11 + vpsubq .Lmask52x4(%rip),%ymm11,%ymm0 + shlq $5,%r11 + vmovapd (%rdx,%r11,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm11,%ymm11 + + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm12,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm12,%ymm12 + + + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + vpand .Lmask52x4(%rip),%ymm11,%ymm11 + vpand .Lmask52x4(%rip),%ymm12,%ymm12 + + vmovdqu %ymm3,0(%rdi) + vmovdqu %ymm5,32(%rdi) + vmovdqu %ymm6,64(%rdi) + vmovdqu %ymm7,96(%rdi) + vmovdqu %ymm8,128(%rdi) + + vmovdqu %ymm4,160(%rdi) + vmovdqu %ymm9,192(%rdi) + vmovdqu %ymm10,224(%rdi) + vmovdqu %ymm11,256(%rdi) + vmovdqu %ymm12,288(%rdi) + + vzeroupper + movq 0(%rsp),%r15 +.cfi_restore %r15 + movq 8(%rsp),%r14 +.cfi_restore %r14 + movq 16(%rsp),%r13 +.cfi_restore %r13 + movq 24(%rsp),%r12 +.cfi_restore %r12 + movq 32(%rsp),%rbp +.cfi_restore %rbp + movq 40(%rsp),%rbx +.cfi_restore %rbx + leaq 48(%rsp),%rsp +.cfi_adjust_cfa_offset -48 +.Lossl_rsaz_amm52x20_x2_avxifma256_epilogue: + .byte 0xf3,0xc3 +.cfi_endproc +.size ossl_rsaz_amm52x20_x2_avxifma256, .-ossl_rsaz_amm52x20_x2_avxifma256 +.text + +.align 32 +.globl ossl_extract_multiplier_2x20_win5_avx +.type ossl_extract_multiplier_2x20_win5_avx,@function +ossl_extract_multiplier_2x20_win5_avx: +.cfi_startproc +.byte 243,15,30,250 + vmovapd .Lones(%rip),%ymm14 + vmovq %rdx,%xmm10 + vpbroadcastq %xmm10,%ymm12 + vmovq %rcx,%xmm10 + vpbroadcastq %xmm10,%ymm13 + leaq 10240(%rsi),%rax + + + vpxor %xmm0,%xmm0,%xmm0 + vmovapd %ymm0,%ymm11 + vmovapd %ymm0,%ymm1 + vmovapd %ymm0,%ymm2 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + vmovapd %ymm0,%ymm8 + vmovapd %ymm0,%ymm9 + +.align 32 +.Lloop: + vpcmpeqq %ymm11,%ymm12,%ymm15 + vmovdqu 0(%rsi),%ymm10 + vblendvpd %ymm15,%ymm10,%ymm0,%ymm0 + vmovdqu 32(%rsi),%ymm10 + vblendvpd %ymm15,%ymm10,%ymm1,%ymm1 + vmovdqu 64(%rsi),%ymm10 + vblendvpd %ymm15,%ymm10,%ymm2,%ymm2 + vmovdqu 96(%rsi),%ymm10 + vblendvpd %ymm15,%ymm10,%ymm3,%ymm3 + vmovdqu 128(%rsi),%ymm10 + vblendvpd %ymm15,%ymm10,%ymm4,%ymm4 + vpcmpeqq %ymm11,%ymm13,%ymm15 + vmovdqu 160(%rsi),%ymm10 + vblendvpd %ymm15,%ymm10,%ymm5,%ymm5 + vmovdqu 192(%rsi),%ymm10 + vblendvpd %ymm15,%ymm10,%ymm6,%ymm6 + vmovdqu 224(%rsi),%ymm10 + vblendvpd %ymm15,%ymm10,%ymm7,%ymm7 + vmovdqu 256(%rsi),%ymm10 + vblendvpd %ymm15,%ymm10,%ymm8,%ymm8 + vmovdqu 288(%rsi),%ymm10 + vblendvpd %ymm15,%ymm10,%ymm9,%ymm9 + vpaddq %ymm14,%ymm11,%ymm11 + addq $320,%rsi + cmpq %rsi,%rax + jne .Lloop + vmovdqu %ymm0,0(%rdi) + vmovdqu %ymm1,32(%rdi) + vmovdqu %ymm2,64(%rdi) + vmovdqu %ymm3,96(%rdi) + vmovdqu %ymm4,128(%rdi) + vmovdqu %ymm5,160(%rdi) + vmovdqu %ymm6,192(%rdi) + vmovdqu %ymm7,224(%rdi) + vmovdqu %ymm8,256(%rdi) + vmovdqu %ymm9,288(%rdi) + vzeroupper + .byte 0xf3,0xc3 +.cfi_endproc +.size ossl_extract_multiplier_2x20_win5_avx, .-ossl_extract_multiplier_2x20_win5_avx +.section .rodata +.align 32 +.Lones: +.quad 1,1,1,1 +.Lzeros: +.quad 0,0,0,0 .section ".note.gnu.property", "a" .p2align 3 .long 1f - 0f diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-3k-avxifma.s b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-3k-avxifma.s index 21efa262d1..1ea20ad1e1 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-3k-avxifma.s +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-3k-avxifma.s @@ -1,15 +1,1751 @@ .text .globl ossl_rsaz_amm52x30_x1_avxifma256 -.globl ossl_rsaz_amm52x30_x2_avxifma256 -.globl ossl_extract_multiplier_2x30_win5_avx .type ossl_rsaz_amm52x30_x1_avxifma256,@function +.align 32 ossl_rsaz_amm52x30_x1_avxifma256: -ossl_rsaz_amm52x30_x2_avxifma256: -ossl_extract_multiplier_2x30_win5_avx: -.byte 0x0f,0x0b +.cfi_startproc +.byte 243,15,30,250 + pushq %rbx +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbx,-16 + pushq %rbp +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbp,-24 + pushq %r12 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r12,-32 + pushq %r13 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r13,-40 + pushq %r14 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r14,-48 + pushq %r15 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r15,-56 + + vpxor %ymm0,%ymm0,%ymm0 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + vmovapd %ymm0,%ymm8 + vmovapd %ymm0,%ymm9 + vmovapd %ymm0,%ymm10 + + xorl %r9d,%r9d + + movq %rdx,%r11 + movq $0xfffffffffffff,%rax + + + movl $7,%ebx + +.align 32 +.Lloop7: + movq 0(%r11),%r13 + + vpbroadcastq 0(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -264(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + movq $0,256(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 + + leaq 264(%rsp),%rsp + movq 8(%r11),%r13 + + vpbroadcastq 8(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -264(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + movq $0,256(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 + + leaq 264(%rsp),%rsp + movq 16(%r11),%r13 + + vpbroadcastq 16(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -264(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + movq $0,256(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 + + leaq 264(%rsp),%rsp + movq 24(%r11),%r13 + + vpbroadcastq 24(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -264(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + movq $0,256(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 + + leaq 264(%rsp),%rsp + leaq 32(%r11),%r11 + decl %ebx + jne .Lloop7 + movq 0(%r11),%r13 + + vpbroadcastq 0(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -264(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + movq $0,256(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 + + leaq 264(%rsp),%rsp + movq 8(%r11),%r13 + + vpbroadcastq 8(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -264(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + movq $0,256(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 + + leaq 264(%rsp),%rsp + + vmovq %r9,%xmm0 + vpbroadcastq %xmm0,%ymm0 + vpblendd $3,%ymm0,%ymm3,%ymm3 + + + + vpsrlq $52,%ymm3,%ymm0 + vpsrlq $52,%ymm4,%ymm1 + vpsrlq $52,%ymm5,%ymm2 + vpsrlq $52,%ymm6,%ymm11 + vpsrlq $52,%ymm7,%ymm12 + vpsrlq $52,%ymm8,%ymm13 + vpsrlq $52,%ymm9,%ymm14 + vpsrlq $52,%ymm10,%ymm15 + + leaq -32(%rsp),%rsp + vmovupd %ymm3,(%rsp) + + + vpermq $144,%ymm15,%ymm15 + vpermq $3,%ymm14,%ymm3 + vblendpd $1,%ymm3,%ymm15,%ymm15 + + vpermq $144,%ymm14,%ymm14 + vpermq $3,%ymm13,%ymm3 + vblendpd $1,%ymm3,%ymm14,%ymm14 + + vpermq $144,%ymm13,%ymm13 + vpermq $3,%ymm12,%ymm3 + vblendpd $1,%ymm3,%ymm13,%ymm13 + + vpermq $144,%ymm12,%ymm12 + vpermq $3,%ymm11,%ymm3 + vblendpd $1,%ymm3,%ymm12,%ymm12 + + vpermq $144,%ymm11,%ymm11 + vpermq $3,%ymm2,%ymm3 + vblendpd $1,%ymm3,%ymm11,%ymm11 + + vpermq $144,%ymm2,%ymm2 + vpermq $3,%ymm1,%ymm3 + vblendpd $1,%ymm3,%ymm2,%ymm2 + + vpermq $144,%ymm1,%ymm1 + vpermq $3,%ymm0,%ymm3 + vblendpd $1,%ymm3,%ymm1,%ymm1 + + vpermq $144,%ymm0,%ymm0 + vpand .Lhigh64x3(%rip),%ymm0,%ymm0 + + vmovupd (%rsp),%ymm3 + leaq 32(%rsp),%rsp + + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + + + vpaddq %ymm0,%ymm3,%ymm3 + vpaddq %ymm1,%ymm4,%ymm4 + vpaddq %ymm2,%ymm5,%ymm5 + vpaddq %ymm11,%ymm6,%ymm6 + vpaddq %ymm12,%ymm7,%ymm7 + vpaddq %ymm13,%ymm8,%ymm8 + vpaddq %ymm14,%ymm9,%ymm9 + vpaddq %ymm15,%ymm10,%ymm10 + + + + vpcmpgtq .Lmask52x4(%rip),%ymm3,%ymm0 + vpcmpgtq .Lmask52x4(%rip),%ymm4,%ymm1 + vmovmskpd %ymm0,%r14d + vmovmskpd %ymm1,%r13d + shlb $4,%r13b + orb %r13b,%r14b + + vpcmpgtq .Lmask52x4(%rip),%ymm5,%ymm2 + vpcmpgtq .Lmask52x4(%rip),%ymm6,%ymm11 + vmovmskpd %ymm2,%r13d + vmovmskpd %ymm11,%r12d + shlb $4,%r12b + orb %r12b,%r13b + + vpcmpgtq .Lmask52x4(%rip),%ymm7,%ymm12 + vpcmpgtq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm12,%r12d + vmovmskpd %ymm13,%r11d + shlb $4,%r11b + orb %r11b,%r12b + + vpcmpgtq .Lmask52x4(%rip),%ymm9,%ymm14 + vpcmpgtq .Lmask52x4(%rip),%ymm10,%ymm15 + vmovmskpd %ymm14,%r11d + vmovmskpd %ymm15,%r10d + shlb $4,%r10b + orb %r10b,%r11b + + addb %r14b,%r14b + adcb %r13b,%r13b + adcb %r12b,%r12b + adcb %r11b,%r11b + + + vpcmpeqq .Lmask52x4(%rip),%ymm3,%ymm0 + vpcmpeqq .Lmask52x4(%rip),%ymm4,%ymm1 + vmovmskpd %ymm0,%r9d + vmovmskpd %ymm1,%r8d + shlb $4,%r8b + orb %r8b,%r9b + + vpcmpeqq .Lmask52x4(%rip),%ymm5,%ymm2 + vpcmpeqq .Lmask52x4(%rip),%ymm6,%ymm11 + vmovmskpd %ymm2,%r8d + vmovmskpd %ymm11,%edx + shlb $4,%dl + orb %dl,%r8b + + vpcmpeqq .Lmask52x4(%rip),%ymm7,%ymm12 + vpcmpeqq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm12,%edx + vmovmskpd %ymm13,%ecx + shlb $4,%cl + orb %cl,%dl + + vpcmpeqq .Lmask52x4(%rip),%ymm9,%ymm14 + vpcmpeqq .Lmask52x4(%rip),%ymm10,%ymm15 + vmovmskpd %ymm14,%ecx + vmovmskpd %ymm15,%ebx + shlb $4,%bl + orb %bl,%cl + + addb %r9b,%r14b + adcb %r8b,%r13b + adcb %dl,%r12b + adcb %cl,%r11b + + xorb %r9b,%r14b + xorb %r8b,%r13b + xorb %dl,%r12b + xorb %cl,%r11b + + leaq .Lkmasklut(%rip),%rdx + + movb %r14b,%r10b + andq $0xf,%r14 + vpsubq .Lmask52x4(%rip),%ymm3,%ymm0 + shlq $5,%r14 + vmovapd (%rdx,%r14,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm3,%ymm3 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm4,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm4,%ymm4 + + movb %r13b,%r10b + andq $0xf,%r13 + vpsubq .Lmask52x4(%rip),%ymm5,%ymm0 + shlq $5,%r13 + vmovapd (%rdx,%r13,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm5,%ymm5 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm6,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm6,%ymm6 + + movb %r12b,%r10b + andq $0xf,%r12 + vpsubq .Lmask52x4(%rip),%ymm7,%ymm0 + shlq $5,%r12 + vmovapd (%rdx,%r12,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm7,%ymm7 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm8,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm8,%ymm8 + + movb %r11b,%r10b + andq $0xf,%r11 + vpsubq .Lmask52x4(%rip),%ymm9,%ymm0 + shlq $5,%r11 + vmovapd (%rdx,%r11,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm9,%ymm9 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm10,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm10,%ymm10 + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + + vmovdqu %ymm3,0(%rdi) + vmovdqu %ymm4,32(%rdi) + vmovdqu %ymm5,64(%rdi) + vmovdqu %ymm6,96(%rdi) + vmovdqu %ymm7,128(%rdi) + vmovdqu %ymm8,160(%rdi) + vmovdqu %ymm9,192(%rdi) + vmovdqu %ymm10,224(%rdi) + + vzeroupper + leaq (%rsp),%rax +.cfi_def_cfa_register %rax + movq 0(%rax),%r15 +.cfi_restore %r15 + movq 8(%rax),%r14 +.cfi_restore %r14 + movq 16(%rax),%r13 +.cfi_restore %r13 + movq 24(%rax),%r12 +.cfi_restore %r12 + movq 32(%rax),%rbp +.cfi_restore %rbp + movq 40(%rax),%rbx +.cfi_restore %rbx + leaq 48(%rax),%rsp +.cfi_def_cfa %rsp,8 +.Lossl_rsaz_amm52x30_x1_avxifma256_epilogue: .byte 0xf3,0xc3 +.cfi_endproc .size ossl_rsaz_amm52x30_x1_avxifma256, .-ossl_rsaz_amm52x30_x1_avxifma256 +.section .rodata +.align 32 +.Lmask52x4: +.quad 0xfffffffffffff +.quad 0xfffffffffffff +.quad 0xfffffffffffff +.quad 0xfffffffffffff +.Lhigh64x3: +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.Lkmasklut: + +.quad 0x0 +.quad 0x0 +.quad 0x0 +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 +.quad 0x0 + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 + +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0x0 +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.text + +.globl ossl_rsaz_amm52x30_x2_avxifma256 +.type ossl_rsaz_amm52x30_x2_avxifma256,@function +.align 32 +ossl_rsaz_amm52x30_x2_avxifma256: +.cfi_startproc +.byte 243,15,30,250 + pushq %rbx +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbx,-16 + pushq %rbp +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbp,-24 + pushq %r12 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r12,-32 + pushq %r13 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r13,-40 + pushq %r14 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r14,-48 + pushq %r15 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r15,-56 + + vpxor %ymm0,%ymm0,%ymm0 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + vmovapd %ymm0,%ymm8 + vmovapd %ymm0,%ymm9 + vmovapd %ymm0,%ymm10 + + xorl %r9d,%r9d + + movq %rdx,%r11 + movq $0xfffffffffffff,%rax + + movl $30,%ebx + +.align 32 +.Lloop30: + movq 0(%r11),%r13 + + vpbroadcastq 0(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq (%r8),%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -264(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + movq $0,256(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 + + leaq 264(%rsp),%rsp + leaq 8(%r11),%r11 + decl %ebx + jne .Lloop30 + + pushq %r11 + pushq %rsi + pushq %rcx + pushq %r8 + + vmovq %r9,%xmm0 + vpbroadcastq %xmm0,%ymm0 + vpblendd $3,%ymm0,%ymm3,%ymm3 + + + + vpsrlq $52,%ymm3,%ymm0 + vpsrlq $52,%ymm4,%ymm1 + vpsrlq $52,%ymm5,%ymm2 + vpsrlq $52,%ymm6,%ymm11 + vpsrlq $52,%ymm7,%ymm12 + vpsrlq $52,%ymm8,%ymm13 + vpsrlq $52,%ymm9,%ymm14 + vpsrlq $52,%ymm10,%ymm15 + + leaq -32(%rsp),%rsp + vmovupd %ymm3,(%rsp) + + + vpermq $144,%ymm15,%ymm15 + vpermq $3,%ymm14,%ymm3 + vblendpd $1,%ymm3,%ymm15,%ymm15 + + vpermq $144,%ymm14,%ymm14 + vpermq $3,%ymm13,%ymm3 + vblendpd $1,%ymm3,%ymm14,%ymm14 + + vpermq $144,%ymm13,%ymm13 + vpermq $3,%ymm12,%ymm3 + vblendpd $1,%ymm3,%ymm13,%ymm13 + + vpermq $144,%ymm12,%ymm12 + vpermq $3,%ymm11,%ymm3 + vblendpd $1,%ymm3,%ymm12,%ymm12 + + vpermq $144,%ymm11,%ymm11 + vpermq $3,%ymm2,%ymm3 + vblendpd $1,%ymm3,%ymm11,%ymm11 + + vpermq $144,%ymm2,%ymm2 + vpermq $3,%ymm1,%ymm3 + vblendpd $1,%ymm3,%ymm2,%ymm2 + + vpermq $144,%ymm1,%ymm1 + vpermq $3,%ymm0,%ymm3 + vblendpd $1,%ymm3,%ymm1,%ymm1 + + vpermq $144,%ymm0,%ymm0 + vpand .Lhigh64x3(%rip),%ymm0,%ymm0 + + vmovupd (%rsp),%ymm3 + leaq 32(%rsp),%rsp + + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + + + vpaddq %ymm0,%ymm3,%ymm3 + vpaddq %ymm1,%ymm4,%ymm4 + vpaddq %ymm2,%ymm5,%ymm5 + vpaddq %ymm11,%ymm6,%ymm6 + vpaddq %ymm12,%ymm7,%ymm7 + vpaddq %ymm13,%ymm8,%ymm8 + vpaddq %ymm14,%ymm9,%ymm9 + vpaddq %ymm15,%ymm10,%ymm10 + + + + vpcmpgtq .Lmask52x4(%rip),%ymm3,%ymm0 + vpcmpgtq .Lmask52x4(%rip),%ymm4,%ymm1 + vmovmskpd %ymm0,%r14d + vmovmskpd %ymm1,%r13d + shlb $4,%r13b + orb %r13b,%r14b + + vpcmpgtq .Lmask52x4(%rip),%ymm5,%ymm2 + vpcmpgtq .Lmask52x4(%rip),%ymm6,%ymm11 + vmovmskpd %ymm2,%r13d + vmovmskpd %ymm11,%r12d + shlb $4,%r12b + orb %r12b,%r13b + + vpcmpgtq .Lmask52x4(%rip),%ymm7,%ymm12 + vpcmpgtq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm12,%r12d + vmovmskpd %ymm13,%r11d + shlb $4,%r11b + orb %r11b,%r12b + + vpcmpgtq .Lmask52x4(%rip),%ymm9,%ymm14 + vpcmpgtq .Lmask52x4(%rip),%ymm10,%ymm15 + vmovmskpd %ymm14,%r11d + vmovmskpd %ymm15,%r10d + shlb $4,%r10b + orb %r10b,%r11b + + addb %r14b,%r14b + adcb %r13b,%r13b + adcb %r12b,%r12b + adcb %r11b,%r11b + + + vpcmpeqq .Lmask52x4(%rip),%ymm3,%ymm0 + vpcmpeqq .Lmask52x4(%rip),%ymm4,%ymm1 + vmovmskpd %ymm0,%r9d + vmovmskpd %ymm1,%r8d + shlb $4,%r8b + orb %r8b,%r9b + + vpcmpeqq .Lmask52x4(%rip),%ymm5,%ymm2 + vpcmpeqq .Lmask52x4(%rip),%ymm6,%ymm11 + vmovmskpd %ymm2,%r8d + vmovmskpd %ymm11,%edx + shlb $4,%dl + orb %dl,%r8b + + vpcmpeqq .Lmask52x4(%rip),%ymm7,%ymm12 + vpcmpeqq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm12,%edx + vmovmskpd %ymm13,%ecx + shlb $4,%cl + orb %cl,%dl + + vpcmpeqq .Lmask52x4(%rip),%ymm9,%ymm14 + vpcmpeqq .Lmask52x4(%rip),%ymm10,%ymm15 + vmovmskpd %ymm14,%ecx + vmovmskpd %ymm15,%ebx + shlb $4,%bl + orb %bl,%cl + + addb %r9b,%r14b + adcb %r8b,%r13b + adcb %dl,%r12b + adcb %cl,%r11b + + xorb %r9b,%r14b + xorb %r8b,%r13b + xorb %dl,%r12b + xorb %cl,%r11b + + leaq .Lkmasklut(%rip),%rdx + + movb %r14b,%r10b + andq $0xf,%r14 + vpsubq .Lmask52x4(%rip),%ymm3,%ymm0 + shlq $5,%r14 + vmovapd (%rdx,%r14,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm3,%ymm3 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm4,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm4,%ymm4 + + movb %r13b,%r10b + andq $0xf,%r13 + vpsubq .Lmask52x4(%rip),%ymm5,%ymm0 + shlq $5,%r13 + vmovapd (%rdx,%r13,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm5,%ymm5 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm6,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm6,%ymm6 + + movb %r12b,%r10b + andq $0xf,%r12 + vpsubq .Lmask52x4(%rip),%ymm7,%ymm0 + shlq $5,%r12 + vmovapd (%rdx,%r12,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm7,%ymm7 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm8,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm8,%ymm8 + + movb %r11b,%r10b + andq $0xf,%r11 + vpsubq .Lmask52x4(%rip),%ymm9,%ymm0 + shlq $5,%r11 + vmovapd (%rdx,%r11,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm9,%ymm9 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm10,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm10,%ymm10 + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + popq %r8 + popq %rcx + popq %rsi + popq %r11 + + vmovdqu %ymm3,0(%rdi) + vmovdqu %ymm4,32(%rdi) + vmovdqu %ymm5,64(%rdi) + vmovdqu %ymm6,96(%rdi) + vmovdqu %ymm7,128(%rdi) + vmovdqu %ymm8,160(%rdi) + vmovdqu %ymm9,192(%rdi) + vmovdqu %ymm10,224(%rdi) + + xorl %r9d,%r9d + + leaq 16(%r11),%r11 + movq $0xfffffffffffff,%rax + + movl $30,%ebx + + vpxor %ymm0,%ymm0,%ymm0 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + vmovapd %ymm0,%ymm8 + vmovapd %ymm0,%ymm9 + vmovapd %ymm0,%ymm10 +.align 32 +.Lloop40: + movq 0(%r11),%r13 + + vpbroadcastq 0(%r11),%ymm1 + movq 256(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq 8(%r8),%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 256(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -264(%rsp),%rsp + +{vex} vpmadd52luq 256(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 288(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 320(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 352(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 384(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 416(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 448(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 480(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52luq 256(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 288(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 320(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 352(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 384(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 416(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 448(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 480(%rcx),%ymm2,%ymm10 + + + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + movq $0,256(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 256(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 288(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 320(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 352(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 384(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 416(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 448(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 480(%rsi),%ymm1,%ymm10 + +{vex} vpmadd52huq 256(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 288(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 320(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 352(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 384(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 416(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 448(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 480(%rcx),%ymm2,%ymm10 + + leaq 264(%rsp),%rsp + leaq 8(%r11),%r11 + decl %ebx + jne .Lloop40 + + vmovq %r9,%xmm0 + vpbroadcastq %xmm0,%ymm0 + vpblendd $3,%ymm0,%ymm3,%ymm3 + + + + vpsrlq $52,%ymm3,%ymm0 + vpsrlq $52,%ymm4,%ymm1 + vpsrlq $52,%ymm5,%ymm2 + vpsrlq $52,%ymm6,%ymm11 + vpsrlq $52,%ymm7,%ymm12 + vpsrlq $52,%ymm8,%ymm13 + vpsrlq $52,%ymm9,%ymm14 + vpsrlq $52,%ymm10,%ymm15 + + leaq -32(%rsp),%rsp + vmovupd %ymm3,(%rsp) + + + vpermq $144,%ymm15,%ymm15 + vpermq $3,%ymm14,%ymm3 + vblendpd $1,%ymm3,%ymm15,%ymm15 + + vpermq $144,%ymm14,%ymm14 + vpermq $3,%ymm13,%ymm3 + vblendpd $1,%ymm3,%ymm14,%ymm14 + + vpermq $144,%ymm13,%ymm13 + vpermq $3,%ymm12,%ymm3 + vblendpd $1,%ymm3,%ymm13,%ymm13 + + vpermq $144,%ymm12,%ymm12 + vpermq $3,%ymm11,%ymm3 + vblendpd $1,%ymm3,%ymm12,%ymm12 + + vpermq $144,%ymm11,%ymm11 + vpermq $3,%ymm2,%ymm3 + vblendpd $1,%ymm3,%ymm11,%ymm11 + + vpermq $144,%ymm2,%ymm2 + vpermq $3,%ymm1,%ymm3 + vblendpd $1,%ymm3,%ymm2,%ymm2 + + vpermq $144,%ymm1,%ymm1 + vpermq $3,%ymm0,%ymm3 + vblendpd $1,%ymm3,%ymm1,%ymm1 + + vpermq $144,%ymm0,%ymm0 + vpand .Lhigh64x3(%rip),%ymm0,%ymm0 + + vmovupd (%rsp),%ymm3 + leaq 32(%rsp),%rsp + + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + + + vpaddq %ymm0,%ymm3,%ymm3 + vpaddq %ymm1,%ymm4,%ymm4 + vpaddq %ymm2,%ymm5,%ymm5 + vpaddq %ymm11,%ymm6,%ymm6 + vpaddq %ymm12,%ymm7,%ymm7 + vpaddq %ymm13,%ymm8,%ymm8 + vpaddq %ymm14,%ymm9,%ymm9 + vpaddq %ymm15,%ymm10,%ymm10 + + + + vpcmpgtq .Lmask52x4(%rip),%ymm3,%ymm0 + vpcmpgtq .Lmask52x4(%rip),%ymm4,%ymm1 + vmovmskpd %ymm0,%r14d + vmovmskpd %ymm1,%r13d + shlb $4,%r13b + orb %r13b,%r14b + + vpcmpgtq .Lmask52x4(%rip),%ymm5,%ymm2 + vpcmpgtq .Lmask52x4(%rip),%ymm6,%ymm11 + vmovmskpd %ymm2,%r13d + vmovmskpd %ymm11,%r12d + shlb $4,%r12b + orb %r12b,%r13b + + vpcmpgtq .Lmask52x4(%rip),%ymm7,%ymm12 + vpcmpgtq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm12,%r12d + vmovmskpd %ymm13,%r11d + shlb $4,%r11b + orb %r11b,%r12b + + vpcmpgtq .Lmask52x4(%rip),%ymm9,%ymm14 + vpcmpgtq .Lmask52x4(%rip),%ymm10,%ymm15 + vmovmskpd %ymm14,%r11d + vmovmskpd %ymm15,%r10d + shlb $4,%r10b + orb %r10b,%r11b + + addb %r14b,%r14b + adcb %r13b,%r13b + adcb %r12b,%r12b + adcb %r11b,%r11b + + + vpcmpeqq .Lmask52x4(%rip),%ymm3,%ymm0 + vpcmpeqq .Lmask52x4(%rip),%ymm4,%ymm1 + vmovmskpd %ymm0,%r9d + vmovmskpd %ymm1,%r8d + shlb $4,%r8b + orb %r8b,%r9b + + vpcmpeqq .Lmask52x4(%rip),%ymm5,%ymm2 + vpcmpeqq .Lmask52x4(%rip),%ymm6,%ymm11 + vmovmskpd %ymm2,%r8d + vmovmskpd %ymm11,%edx + shlb $4,%dl + orb %dl,%r8b + + vpcmpeqq .Lmask52x4(%rip),%ymm7,%ymm12 + vpcmpeqq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm12,%edx + vmovmskpd %ymm13,%ecx + shlb $4,%cl + orb %cl,%dl + + vpcmpeqq .Lmask52x4(%rip),%ymm9,%ymm14 + vpcmpeqq .Lmask52x4(%rip),%ymm10,%ymm15 + vmovmskpd %ymm14,%ecx + vmovmskpd %ymm15,%ebx + shlb $4,%bl + orb %bl,%cl + + addb %r9b,%r14b + adcb %r8b,%r13b + adcb %dl,%r12b + adcb %cl,%r11b + + xorb %r9b,%r14b + xorb %r8b,%r13b + xorb %dl,%r12b + xorb %cl,%r11b + + leaq .Lkmasklut(%rip),%rdx + + movb %r14b,%r10b + andq $0xf,%r14 + vpsubq .Lmask52x4(%rip),%ymm3,%ymm0 + shlq $5,%r14 + vmovapd (%rdx,%r14,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm3,%ymm3 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm4,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm4,%ymm4 + + movb %r13b,%r10b + andq $0xf,%r13 + vpsubq .Lmask52x4(%rip),%ymm5,%ymm0 + shlq $5,%r13 + vmovapd (%rdx,%r13,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm5,%ymm5 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm6,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm6,%ymm6 + + movb %r12b,%r10b + andq $0xf,%r12 + vpsubq .Lmask52x4(%rip),%ymm7,%ymm0 + shlq $5,%r12 + vmovapd (%rdx,%r12,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm7,%ymm7 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm8,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm8,%ymm8 + + movb %r11b,%r10b + andq $0xf,%r11 + vpsubq .Lmask52x4(%rip),%ymm9,%ymm0 + shlq $5,%r11 + vmovapd (%rdx,%r11,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm9,%ymm9 + + shrb $4,%r10b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm10,%ymm0 + shlq $5,%r10 + vmovapd (%rdx,%r10,1),%ymm2 + vblendvpd %ymm2,%ymm0,%ymm10,%ymm10 + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + + vmovdqu %ymm3,256(%rdi) + vmovdqu %ymm4,288(%rdi) + vmovdqu %ymm5,320(%rdi) + vmovdqu %ymm6,352(%rdi) + vmovdqu %ymm7,384(%rdi) + vmovdqu %ymm8,416(%rdi) + vmovdqu %ymm9,448(%rdi) + vmovdqu %ymm10,480(%rdi) + + vzeroupper + leaq (%rsp),%rax +.cfi_def_cfa_register %rax + movq 0(%rax),%r15 +.cfi_restore %r15 + movq 8(%rax),%r14 +.cfi_restore %r14 + movq 16(%rax),%r13 +.cfi_restore %r13 + movq 24(%rax),%r12 +.cfi_restore %r12 + movq 32(%rax),%rbp +.cfi_restore %rbp + movq 40(%rax),%rbx +.cfi_restore %rbx + leaq 48(%rax),%rsp +.cfi_def_cfa %rsp,8 +.Lossl_rsaz_amm52x30_x2_avxifma256_epilogue: + .byte 0xf3,0xc3 +.cfi_endproc +.size ossl_rsaz_amm52x30_x2_avxifma256, .-ossl_rsaz_amm52x30_x2_avxifma256 +.text + +.align 32 +.globl ossl_extract_multiplier_2x30_win5_avx +.type ossl_extract_multiplier_2x30_win5_avx,@function +ossl_extract_multiplier_2x30_win5_avx: +.cfi_startproc +.byte 243,15,30,250 + vmovapd .Lones(%rip),%ymm12 + vmovq %rdx,%xmm8 + vpbroadcastq %xmm8,%ymm10 + vmovq %rcx,%xmm8 + vpbroadcastq %xmm8,%ymm11 + leaq 16384(%rsi),%rax + + + vpxor %xmm0,%xmm0,%xmm0 + vmovapd %ymm0,%ymm9 + vmovapd %ymm0,%ymm1 + vmovapd %ymm0,%ymm2 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + +.align 32 +.Lloop: + vpcmpeqq %ymm9,%ymm10,%ymm13 + vmovdqu 0(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm0,%ymm0 + vmovdqu 32(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm1,%ymm1 + vmovdqu 64(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm2,%ymm2 + vmovdqu 96(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm3,%ymm3 + vmovdqu 128(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm4,%ymm4 + vmovdqu 160(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm5,%ymm5 + vmovdqu 192(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm6,%ymm6 + vmovdqu 224(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm7,%ymm7 + vpaddq %ymm12,%ymm9,%ymm9 + addq $512,%rsi + cmpq %rsi,%rax + jne .Lloop + vmovdqu %ymm0,0(%rdi) + vmovdqu %ymm1,32(%rdi) + vmovdqu %ymm2,64(%rdi) + vmovdqu %ymm3,96(%rdi) + vmovdqu %ymm4,128(%rdi) + vmovdqu %ymm5,160(%rdi) + vmovdqu %ymm6,192(%rdi) + vmovdqu %ymm7,224(%rdi) + leaq -16384(%rax),%rsi + + + vpxor %xmm0,%xmm0,%xmm0 + vmovapd %ymm0,%ymm9 + vmovapd %ymm0,%ymm0 + vmovapd %ymm0,%ymm1 + vmovapd %ymm0,%ymm2 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + +.align 32 +.Lloop_8_15: + vpcmpeqq %ymm9,%ymm11,%ymm13 + vmovdqu 256(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm0,%ymm0 + vmovdqu 288(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm1,%ymm1 + vmovdqu 320(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm2,%ymm2 + vmovdqu 352(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm3,%ymm3 + vmovdqu 384(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm4,%ymm4 + vmovdqu 416(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm5,%ymm5 + vmovdqu 448(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm6,%ymm6 + vmovdqu 480(%rsi),%ymm8 + + vblendvpd %ymm13,%ymm8,%ymm7,%ymm7 + vpaddq %ymm12,%ymm9,%ymm9 + addq $512,%rsi + cmpq %rsi,%rax + jne .Lloop_8_15 + vmovdqu %ymm0,256(%rdi) + vmovdqu %ymm1,288(%rdi) + vmovdqu %ymm2,320(%rdi) + vmovdqu %ymm3,352(%rdi) + vmovdqu %ymm4,384(%rdi) + vmovdqu %ymm5,416(%rdi) + vmovdqu %ymm6,448(%rdi) + vmovdqu %ymm7,480(%rdi) + vzeroupper + + .byte 0xf3,0xc3 +.cfi_endproc +.size ossl_extract_multiplier_2x30_win5_avx, .-ossl_extract_multiplier_2x30_win5_avx +.section .rodata +.align 32 +.Lones: +.quad 1,1,1,1 +.Lzeros: +.quad 0,0,0,0 .section ".note.gnu.property", "a" .p2align 3 .long 1f - 0f diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-4k-avxifma.s b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-4k-avxifma.s index 297f30d512..6d59af4afb 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-4k-avxifma.s +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-GCC/crypto/bn/rsaz-4k-avxifma.s @@ -1,15 +1,1905 @@ .text .globl ossl_rsaz_amm52x40_x1_avxifma256 -.globl ossl_rsaz_amm52x40_x2_avxifma256 -.globl ossl_extract_multiplier_2x40_win5_avx .type ossl_rsaz_amm52x40_x1_avxifma256,@function +.align 32 ossl_rsaz_amm52x40_x1_avxifma256: -ossl_rsaz_amm52x40_x2_avxifma256: -ossl_extract_multiplier_2x40_win5_avx: -.byte 0x0f,0x0b +.cfi_startproc +.byte 243,15,30,250 + pushq %rbx +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbx,-16 + pushq %rbp +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbp,-24 + pushq %r12 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r12,-32 + pushq %r13 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r13,-40 + pushq %r14 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r14,-48 + pushq %r15 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r15,-56 + + vpxor %ymm0,%ymm0,%ymm0 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + vmovapd %ymm0,%ymm8 + vmovapd %ymm0,%ymm9 + vmovapd %ymm0,%ymm10 + vmovapd %ymm0,%ymm11 + vmovapd %ymm0,%ymm12 + + xorl %r9d,%r9d + + movq %rdx,%r11 + movq $0xfffffffffffff,%rax + + + movl $10,%ebx + +.align 32 +.Lloop10: + movq 0(%r11),%r13 + + vpbroadcastq 0(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -328(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52luq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52luq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52luq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52luq 288(%rcx),%ymm2,%ymm12 + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + vmovdqu %ymm11,256(%rsp) + vmovdqu %ymm12,288(%rsp) + movq $0,320(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + vmovdqu 264(%rsp),%ymm11 + vmovdqu 296(%rsp),%ymm12 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52huq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52huq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52huq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52huq 288(%rcx),%ymm2,%ymm12 + leaq 328(%rsp),%rsp + movq 8(%r11),%r13 + + vpbroadcastq 8(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -328(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52luq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52luq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52luq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52luq 288(%rcx),%ymm2,%ymm12 + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + vmovdqu %ymm11,256(%rsp) + vmovdqu %ymm12,288(%rsp) + movq $0,320(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + vmovdqu 264(%rsp),%ymm11 + vmovdqu 296(%rsp),%ymm12 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52huq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52huq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52huq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52huq 288(%rcx),%ymm2,%ymm12 + leaq 328(%rsp),%rsp + movq 16(%r11),%r13 + + vpbroadcastq 16(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -328(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52luq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52luq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52luq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52luq 288(%rcx),%ymm2,%ymm12 + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + vmovdqu %ymm11,256(%rsp) + vmovdqu %ymm12,288(%rsp) + movq $0,320(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + vmovdqu 264(%rsp),%ymm11 + vmovdqu 296(%rsp),%ymm12 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52huq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52huq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52huq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52huq 288(%rcx),%ymm2,%ymm12 + leaq 328(%rsp),%rsp + movq 24(%r11),%r13 + + vpbroadcastq 24(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq %r8,%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -328(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52luq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52luq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52luq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52luq 288(%rcx),%ymm2,%ymm12 + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + vmovdqu %ymm11,256(%rsp) + vmovdqu %ymm12,288(%rsp) + movq $0,320(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + vmovdqu 264(%rsp),%ymm11 + vmovdqu 296(%rsp),%ymm12 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52huq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52huq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52huq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52huq 288(%rcx),%ymm2,%ymm12 + leaq 328(%rsp),%rsp + leaq 32(%r11),%r11 + decl %ebx + jne .Lloop10 + + vmovq %r9,%xmm0 + vpbroadcastq %xmm0,%ymm0 + vpblendd $3,%ymm0,%ymm3,%ymm3 + + leaq -640(%rsp),%rsp + vmovupd %ymm3,0(%rsp) + vmovupd %ymm4,32(%rsp) + vmovupd %ymm5,64(%rsp) + vmovupd %ymm6,96(%rsp) + vmovupd %ymm7,128(%rsp) + vmovupd %ymm8,160(%rsp) + vmovupd %ymm9,192(%rsp) + vmovupd %ymm10,224(%rsp) + vmovupd %ymm11,256(%rsp) + vmovupd %ymm12,288(%rsp) + + + + vpsrlq $52,%ymm3,%ymm3 + vpsrlq $52,%ymm4,%ymm4 + vpsrlq $52,%ymm5,%ymm5 + vpsrlq $52,%ymm6,%ymm6 + vpsrlq $52,%ymm7,%ymm7 + vpsrlq $52,%ymm8,%ymm8 + vpsrlq $52,%ymm9,%ymm9 + vpsrlq $52,%ymm10,%ymm10 + vpsrlq $52,%ymm11,%ymm11 + vpsrlq $52,%ymm12,%ymm12 + + + vpermq $144,%ymm12,%ymm12 + vpermq $3,%ymm11,%ymm13 + vblendpd $1,%ymm13,%ymm12,%ymm12 + + vpermq $144,%ymm11,%ymm11 + vpermq $3,%ymm10,%ymm13 + vblendpd $1,%ymm13,%ymm11,%ymm11 + + vpermq $144,%ymm10,%ymm10 + vpermq $3,%ymm9,%ymm13 + vblendpd $1,%ymm13,%ymm10,%ymm10 + + vpermq $144,%ymm9,%ymm9 + vpermq $3,%ymm8,%ymm13 + vblendpd $1,%ymm13,%ymm9,%ymm9 + + vpermq $144,%ymm8,%ymm8 + vpermq $3,%ymm7,%ymm13 + vblendpd $1,%ymm13,%ymm8,%ymm8 + + vpermq $144,%ymm7,%ymm7 + vpermq $3,%ymm6,%ymm13 + vblendpd $1,%ymm13,%ymm7,%ymm7 + + vpermq $144,%ymm6,%ymm6 + vpermq $3,%ymm5,%ymm13 + vblendpd $1,%ymm13,%ymm6,%ymm6 + + vpermq $144,%ymm5,%ymm5 + vpermq $3,%ymm4,%ymm13 + vblendpd $1,%ymm13,%ymm5,%ymm5 + + vpermq $144,%ymm4,%ymm4 + vpermq $3,%ymm3,%ymm13 + vblendpd $1,%ymm13,%ymm4,%ymm4 + + vpermq $144,%ymm3,%ymm3 + vpand .Lhigh64x3(%rip),%ymm3,%ymm3 + + vmovupd %ymm3,320(%rsp) + vmovupd %ymm4,352(%rsp) + vmovupd %ymm5,384(%rsp) + vmovupd %ymm6,416(%rsp) + vmovupd %ymm7,448(%rsp) + vmovupd %ymm8,480(%rsp) + vmovupd %ymm9,512(%rsp) + vmovupd %ymm10,544(%rsp) + vmovupd %ymm11,576(%rsp) + vmovupd %ymm12,608(%rsp) + + vmovupd 0(%rsp),%ymm3 + vmovupd 32(%rsp),%ymm4 + vmovupd 64(%rsp),%ymm5 + vmovupd 96(%rsp),%ymm6 + vmovupd 128(%rsp),%ymm7 + vmovupd 160(%rsp),%ymm8 + vmovupd 192(%rsp),%ymm9 + vmovupd 224(%rsp),%ymm10 + vmovupd 256(%rsp),%ymm11 + vmovupd 288(%rsp),%ymm12 + + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + vpand .Lmask52x4(%rip),%ymm11,%ymm11 + vpand .Lmask52x4(%rip),%ymm12,%ymm12 + + + vpaddq 320(%rsp),%ymm3,%ymm3 + vpaddq 352(%rsp),%ymm4,%ymm4 + vpaddq 384(%rsp),%ymm5,%ymm5 + vpaddq 416(%rsp),%ymm6,%ymm6 + vpaddq 448(%rsp),%ymm7,%ymm7 + vpaddq 480(%rsp),%ymm8,%ymm8 + vpaddq 512(%rsp),%ymm9,%ymm9 + vpaddq 544(%rsp),%ymm10,%ymm10 + vpaddq 576(%rsp),%ymm11,%ymm11 + vpaddq 608(%rsp),%ymm12,%ymm12 + + leaq 640(%rsp),%rsp + + + + vpcmpgtq .Lmask52x4(%rip),%ymm3,%ymm13 + vmovmskpd %ymm13,%r14d + vpcmpgtq .Lmask52x4(%rip),%ymm4,%ymm13 + vmovmskpd %ymm13,%r13d + shlb $4,%r13b + orb %r13b,%r14b + + vpcmpgtq .Lmask52x4(%rip),%ymm5,%ymm13 + vmovmskpd %ymm13,%r13d + vpcmpgtq .Lmask52x4(%rip),%ymm6,%ymm13 + vmovmskpd %ymm13,%r12d + shlb $4,%r12b + orb %r12b,%r13b + + vpcmpgtq .Lmask52x4(%rip),%ymm7,%ymm13 + vmovmskpd %ymm13,%r12d + vpcmpgtq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm13,%r11d + shlb $4,%r11b + orb %r11b,%r12b + + vpcmpgtq .Lmask52x4(%rip),%ymm9,%ymm13 + vmovmskpd %ymm13,%r11d + vpcmpgtq .Lmask52x4(%rip),%ymm10,%ymm13 + vmovmskpd %ymm13,%r10d + shlb $4,%r10b + orb %r10b,%r11b + + vpcmpgtq .Lmask52x4(%rip),%ymm11,%ymm13 + vmovmskpd %ymm13,%r10d + vpcmpgtq .Lmask52x4(%rip),%ymm12,%ymm13 + vmovmskpd %ymm13,%r9d + shlb $4,%r9b + orb %r9b,%r10b + + addb %r14b,%r14b + adcb %r13b,%r13b + adcb %r12b,%r12b + adcb %r11b,%r11b + adcb %r10b,%r10b + + + vpcmpeqq .Lmask52x4(%rip),%ymm3,%ymm13 + vmovmskpd %ymm13,%r9d + vpcmpeqq .Lmask52x4(%rip),%ymm4,%ymm13 + vmovmskpd %ymm13,%r8d + shlb $4,%r8b + orb %r8b,%r9b + + vpcmpeqq .Lmask52x4(%rip),%ymm5,%ymm13 + vmovmskpd %ymm13,%r8d + vpcmpeqq .Lmask52x4(%rip),%ymm6,%ymm13 + vmovmskpd %ymm13,%edx + shlb $4,%dl + orb %dl,%r8b + + vpcmpeqq .Lmask52x4(%rip),%ymm7,%ymm13 + vmovmskpd %ymm13,%edx + vpcmpeqq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm13,%ecx + shlb $4,%cl + orb %cl,%dl + + vpcmpeqq .Lmask52x4(%rip),%ymm9,%ymm13 + vmovmskpd %ymm13,%ecx + vpcmpeqq .Lmask52x4(%rip),%ymm10,%ymm13 + vmovmskpd %ymm13,%ebx + shlb $4,%bl + orb %bl,%cl + + vpcmpeqq .Lmask52x4(%rip),%ymm11,%ymm13 + vmovmskpd %ymm13,%ebx + vpcmpeqq .Lmask52x4(%rip),%ymm12,%ymm13 + vmovmskpd %ymm13,%eax + shlb $4,%al + orb %al,%bl + + addb %r9b,%r14b + adcb %r8b,%r13b + adcb %dl,%r12b + adcb %cl,%r11b + adcb %bl,%r10b + + xorb %r9b,%r14b + xorb %r8b,%r13b + xorb %dl,%r12b + xorb %cl,%r11b + xorb %bl,%r10b + + pushq %r9 + pushq %r8 + + leaq .Lkmasklut(%rip),%r8 + + movb %r14b,%r9b + andq $0xf,%r14 + vpsubq .Lmask52x4(%rip),%ymm3,%ymm13 + shlq $5,%r14 + vmovapd (%r8,%r14,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm3,%ymm3 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm4,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm4,%ymm4 + + movb %r13b,%r9b + andq $0xf,%r13 + vpsubq .Lmask52x4(%rip),%ymm5,%ymm13 + shlq $5,%r13 + vmovapd (%r8,%r13,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm5,%ymm5 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm6,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm6,%ymm6 + + movb %r12b,%r9b + andq $0xf,%r12 + vpsubq .Lmask52x4(%rip),%ymm7,%ymm13 + shlq $5,%r12 + vmovapd (%r8,%r12,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm7,%ymm7 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm8,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm8,%ymm8 + + movb %r11b,%r9b + andq $0xf,%r11 + vpsubq .Lmask52x4(%rip),%ymm9,%ymm13 + shlq $5,%r11 + vmovapd (%r8,%r11,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm9,%ymm9 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm10,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm10,%ymm10 + + movb %r10b,%r9b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm11,%ymm13 + shlq $5,%r10 + vmovapd (%r8,%r10,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm11,%ymm11 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm12,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm12,%ymm12 + + popq %r8 + popq %r9 + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + vpand .Lmask52x4(%rip),%ymm11,%ymm11 + vpand .Lmask52x4(%rip),%ymm12,%ymm12 + + vmovdqu %ymm3,0(%rdi) + vmovdqu %ymm4,32(%rdi) + vmovdqu %ymm5,64(%rdi) + vmovdqu %ymm6,96(%rdi) + vmovdqu %ymm7,128(%rdi) + vmovdqu %ymm8,160(%rdi) + vmovdqu %ymm9,192(%rdi) + vmovdqu %ymm10,224(%rdi) + vmovdqu %ymm11,256(%rdi) + vmovdqu %ymm12,288(%rdi) + + vzeroupper + leaq (%rsp),%rax +.cfi_def_cfa_register %rax + movq 0(%rax),%r15 +.cfi_restore %r15 + movq 8(%rax),%r14 +.cfi_restore %r14 + movq 16(%rax),%r13 +.cfi_restore %r13 + movq 24(%rax),%r12 +.cfi_restore %r12 + movq 32(%rax),%rbp +.cfi_restore %rbp + movq 40(%rax),%rbx +.cfi_restore %rbx + leaq 48(%rax),%rsp +.cfi_def_cfa %rsp,8 +.Lossl_rsaz_amm52x40_x1_avxifma256_epilogue: + .byte 0xf3,0xc3 +.cfi_endproc .size ossl_rsaz_amm52x40_x1_avxifma256, .-ossl_rsaz_amm52x40_x1_avxifma256 +.section .rodata +.align 32 +.Lmask52x4: +.quad 0xfffffffffffff +.quad 0xfffffffffffff +.quad 0xfffffffffffff +.quad 0xfffffffffffff +.Lhigh64x3: +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.Lkmasklut: + +.quad 0x0 +.quad 0x0 +.quad 0x0 +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 +.quad 0x0 + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 + +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 + +.quad 0x0 +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff + +.quad 0x0 +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff + +.quad 0x0 +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff + +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.quad 0xffffffffffffffff +.text + +.globl ossl_rsaz_amm52x40_x2_avxifma256 +.type ossl_rsaz_amm52x40_x2_avxifma256,@function +.align 32 +ossl_rsaz_amm52x40_x2_avxifma256: +.cfi_startproc +.byte 243,15,30,250 + pushq %rbx +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbx,-16 + pushq %rbp +.cfi_adjust_cfa_offset 8 +.cfi_offset %rbp,-24 + pushq %r12 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r12,-32 + pushq %r13 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r13,-40 + pushq %r14 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r14,-48 + pushq %r15 +.cfi_adjust_cfa_offset 8 +.cfi_offset %r15,-56 + + vpxor %ymm0,%ymm0,%ymm0 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + vmovapd %ymm0,%ymm8 + vmovapd %ymm0,%ymm9 + vmovapd %ymm0,%ymm10 + vmovapd %ymm0,%ymm11 + vmovapd %ymm0,%ymm12 + + xorl %r9d,%r9d + + movq %rdx,%r11 + movq $0xfffffffffffff,%rax + + movl $40,%ebx + +.align 32 +.Lloop40: + movq 0(%r11),%r13 + + vpbroadcastq 0(%r11),%ymm1 + movq 0(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq (%r8),%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 0(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -328(%rsp),%rsp + +{vex} vpmadd52luq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52luq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52luq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52luq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52luq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52luq 288(%rcx),%ymm2,%ymm12 + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + vmovdqu %ymm11,256(%rsp) + vmovdqu %ymm12,288(%rsp) + movq $0,320(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + vmovdqu 264(%rsp),%ymm11 + vmovdqu 296(%rsp),%ymm12 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 0(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 32(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 64(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 96(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 128(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 160(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 192(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 224(%rsi),%ymm1,%ymm10 +{vex} vpmadd52huq 256(%rsi),%ymm1,%ymm11 +{vex} vpmadd52huq 288(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52huq 0(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 32(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 64(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 96(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 128(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 160(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 192(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 224(%rcx),%ymm2,%ymm10 +{vex} vpmadd52huq 256(%rcx),%ymm2,%ymm11 +{vex} vpmadd52huq 288(%rcx),%ymm2,%ymm12 + leaq 328(%rsp),%rsp + leaq 8(%r11),%r11 + decl %ebx + jne .Lloop40 + + pushq %r11 + pushq %rsi + pushq %rcx + pushq %r8 + + vmovq %r9,%xmm0 + vpbroadcastq %xmm0,%ymm0 + vpblendd $3,%ymm0,%ymm3,%ymm3 + + leaq -640(%rsp),%rsp + vmovupd %ymm3,0(%rsp) + vmovupd %ymm4,32(%rsp) + vmovupd %ymm5,64(%rsp) + vmovupd %ymm6,96(%rsp) + vmovupd %ymm7,128(%rsp) + vmovupd %ymm8,160(%rsp) + vmovupd %ymm9,192(%rsp) + vmovupd %ymm10,224(%rsp) + vmovupd %ymm11,256(%rsp) + vmovupd %ymm12,288(%rsp) + + + + vpsrlq $52,%ymm3,%ymm3 + vpsrlq $52,%ymm4,%ymm4 + vpsrlq $52,%ymm5,%ymm5 + vpsrlq $52,%ymm6,%ymm6 + vpsrlq $52,%ymm7,%ymm7 + vpsrlq $52,%ymm8,%ymm8 + vpsrlq $52,%ymm9,%ymm9 + vpsrlq $52,%ymm10,%ymm10 + vpsrlq $52,%ymm11,%ymm11 + vpsrlq $52,%ymm12,%ymm12 + + + vpermq $144,%ymm12,%ymm12 + vpermq $3,%ymm11,%ymm13 + vblendpd $1,%ymm13,%ymm12,%ymm12 + + vpermq $144,%ymm11,%ymm11 + vpermq $3,%ymm10,%ymm13 + vblendpd $1,%ymm13,%ymm11,%ymm11 + + vpermq $144,%ymm10,%ymm10 + vpermq $3,%ymm9,%ymm13 + vblendpd $1,%ymm13,%ymm10,%ymm10 + + vpermq $144,%ymm9,%ymm9 + vpermq $3,%ymm8,%ymm13 + vblendpd $1,%ymm13,%ymm9,%ymm9 + + vpermq $144,%ymm8,%ymm8 + vpermq $3,%ymm7,%ymm13 + vblendpd $1,%ymm13,%ymm8,%ymm8 + + vpermq $144,%ymm7,%ymm7 + vpermq $3,%ymm6,%ymm13 + vblendpd $1,%ymm13,%ymm7,%ymm7 + + vpermq $144,%ymm6,%ymm6 + vpermq $3,%ymm5,%ymm13 + vblendpd $1,%ymm13,%ymm6,%ymm6 + + vpermq $144,%ymm5,%ymm5 + vpermq $3,%ymm4,%ymm13 + vblendpd $1,%ymm13,%ymm5,%ymm5 + + vpermq $144,%ymm4,%ymm4 + vpermq $3,%ymm3,%ymm13 + vblendpd $1,%ymm13,%ymm4,%ymm4 + + vpermq $144,%ymm3,%ymm3 + vpand .Lhigh64x3(%rip),%ymm3,%ymm3 + + vmovupd %ymm3,320(%rsp) + vmovupd %ymm4,352(%rsp) + vmovupd %ymm5,384(%rsp) + vmovupd %ymm6,416(%rsp) + vmovupd %ymm7,448(%rsp) + vmovupd %ymm8,480(%rsp) + vmovupd %ymm9,512(%rsp) + vmovupd %ymm10,544(%rsp) + vmovupd %ymm11,576(%rsp) + vmovupd %ymm12,608(%rsp) + + vmovupd 0(%rsp),%ymm3 + vmovupd 32(%rsp),%ymm4 + vmovupd 64(%rsp),%ymm5 + vmovupd 96(%rsp),%ymm6 + vmovupd 128(%rsp),%ymm7 + vmovupd 160(%rsp),%ymm8 + vmovupd 192(%rsp),%ymm9 + vmovupd 224(%rsp),%ymm10 + vmovupd 256(%rsp),%ymm11 + vmovupd 288(%rsp),%ymm12 + + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + vpand .Lmask52x4(%rip),%ymm11,%ymm11 + vpand .Lmask52x4(%rip),%ymm12,%ymm12 + + + vpaddq 320(%rsp),%ymm3,%ymm3 + vpaddq 352(%rsp),%ymm4,%ymm4 + vpaddq 384(%rsp),%ymm5,%ymm5 + vpaddq 416(%rsp),%ymm6,%ymm6 + vpaddq 448(%rsp),%ymm7,%ymm7 + vpaddq 480(%rsp),%ymm8,%ymm8 + vpaddq 512(%rsp),%ymm9,%ymm9 + vpaddq 544(%rsp),%ymm10,%ymm10 + vpaddq 576(%rsp),%ymm11,%ymm11 + vpaddq 608(%rsp),%ymm12,%ymm12 + + leaq 640(%rsp),%rsp + + + + vpcmpgtq .Lmask52x4(%rip),%ymm3,%ymm13 + vmovmskpd %ymm13,%r14d + vpcmpgtq .Lmask52x4(%rip),%ymm4,%ymm13 + vmovmskpd %ymm13,%r13d + shlb $4,%r13b + orb %r13b,%r14b + + vpcmpgtq .Lmask52x4(%rip),%ymm5,%ymm13 + vmovmskpd %ymm13,%r13d + vpcmpgtq .Lmask52x4(%rip),%ymm6,%ymm13 + vmovmskpd %ymm13,%r12d + shlb $4,%r12b + orb %r12b,%r13b + + vpcmpgtq .Lmask52x4(%rip),%ymm7,%ymm13 + vmovmskpd %ymm13,%r12d + vpcmpgtq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm13,%r11d + shlb $4,%r11b + orb %r11b,%r12b + + vpcmpgtq .Lmask52x4(%rip),%ymm9,%ymm13 + vmovmskpd %ymm13,%r11d + vpcmpgtq .Lmask52x4(%rip),%ymm10,%ymm13 + vmovmskpd %ymm13,%r10d + shlb $4,%r10b + orb %r10b,%r11b + + vpcmpgtq .Lmask52x4(%rip),%ymm11,%ymm13 + vmovmskpd %ymm13,%r10d + vpcmpgtq .Lmask52x4(%rip),%ymm12,%ymm13 + vmovmskpd %ymm13,%r9d + shlb $4,%r9b + orb %r9b,%r10b + + addb %r14b,%r14b + adcb %r13b,%r13b + adcb %r12b,%r12b + adcb %r11b,%r11b + adcb %r10b,%r10b + + + vpcmpeqq .Lmask52x4(%rip),%ymm3,%ymm13 + vmovmskpd %ymm13,%r9d + vpcmpeqq .Lmask52x4(%rip),%ymm4,%ymm13 + vmovmskpd %ymm13,%r8d + shlb $4,%r8b + orb %r8b,%r9b + + vpcmpeqq .Lmask52x4(%rip),%ymm5,%ymm13 + vmovmskpd %ymm13,%r8d + vpcmpeqq .Lmask52x4(%rip),%ymm6,%ymm13 + vmovmskpd %ymm13,%edx + shlb $4,%dl + orb %dl,%r8b + + vpcmpeqq .Lmask52x4(%rip),%ymm7,%ymm13 + vmovmskpd %ymm13,%edx + vpcmpeqq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm13,%ecx + shlb $4,%cl + orb %cl,%dl + + vpcmpeqq .Lmask52x4(%rip),%ymm9,%ymm13 + vmovmskpd %ymm13,%ecx + vpcmpeqq .Lmask52x4(%rip),%ymm10,%ymm13 + vmovmskpd %ymm13,%ebx + shlb $4,%bl + orb %bl,%cl + + vpcmpeqq .Lmask52x4(%rip),%ymm11,%ymm13 + vmovmskpd %ymm13,%ebx + vpcmpeqq .Lmask52x4(%rip),%ymm12,%ymm13 + vmovmskpd %ymm13,%eax + shlb $4,%al + orb %al,%bl + + addb %r9b,%r14b + adcb %r8b,%r13b + adcb %dl,%r12b + adcb %cl,%r11b + adcb %bl,%r10b + + xorb %r9b,%r14b + xorb %r8b,%r13b + xorb %dl,%r12b + xorb %cl,%r11b + xorb %bl,%r10b + + pushq %r9 + pushq %r8 + + leaq .Lkmasklut(%rip),%r8 + + movb %r14b,%r9b + andq $0xf,%r14 + vpsubq .Lmask52x4(%rip),%ymm3,%ymm13 + shlq $5,%r14 + vmovapd (%r8,%r14,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm3,%ymm3 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm4,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm4,%ymm4 + + movb %r13b,%r9b + andq $0xf,%r13 + vpsubq .Lmask52x4(%rip),%ymm5,%ymm13 + shlq $5,%r13 + vmovapd (%r8,%r13,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm5,%ymm5 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm6,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm6,%ymm6 + + movb %r12b,%r9b + andq $0xf,%r12 + vpsubq .Lmask52x4(%rip),%ymm7,%ymm13 + shlq $5,%r12 + vmovapd (%r8,%r12,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm7,%ymm7 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm8,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm8,%ymm8 + + movb %r11b,%r9b + andq $0xf,%r11 + vpsubq .Lmask52x4(%rip),%ymm9,%ymm13 + shlq $5,%r11 + vmovapd (%r8,%r11,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm9,%ymm9 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm10,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm10,%ymm10 + + movb %r10b,%r9b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm11,%ymm13 + shlq $5,%r10 + vmovapd (%r8,%r10,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm11,%ymm11 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm12,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm12,%ymm12 + + popq %r8 + popq %r9 + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + vpand .Lmask52x4(%rip),%ymm11,%ymm11 + vpand .Lmask52x4(%rip),%ymm12,%ymm12 + + popq %r8 + popq %rcx + popq %rsi + popq %r11 + + vmovdqu %ymm3,0(%rdi) + vmovdqu %ymm4,32(%rdi) + vmovdqu %ymm5,64(%rdi) + vmovdqu %ymm6,96(%rdi) + vmovdqu %ymm7,128(%rdi) + vmovdqu %ymm8,160(%rdi) + vmovdqu %ymm9,192(%rdi) + vmovdqu %ymm10,224(%rdi) + vmovdqu %ymm11,256(%rdi) + vmovdqu %ymm12,288(%rdi) + + xorl %r9d,%r9d + + movq $0xfffffffffffff,%rax + + movl $40,%ebx + + vpxor %ymm0,%ymm0,%ymm0 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + vmovapd %ymm0,%ymm8 + vmovapd %ymm0,%ymm9 + vmovapd %ymm0,%ymm10 + vmovapd %ymm0,%ymm11 + vmovapd %ymm0,%ymm12 +.align 32 +.Lloop40_1: + movq 0(%r11),%r13 + + vpbroadcastq 0(%r11),%ymm1 + movq 320(%rsi),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + movq %r12,%r10 + adcq $0,%r10 + + movq 8(%r8),%r13 + imulq %r9,%r13 + andq %rax,%r13 + + vmovq %r13,%xmm2 + vpbroadcastq %xmm2,%ymm2 + movq 320(%rcx),%rdx + mulxq %r13,%r13,%r12 + addq %r13,%r9 + adcq %r12,%r10 + + shrq $52,%r9 + salq $12,%r10 + orq %r10,%r9 + + leaq -328(%rsp),%rsp + +{vex} vpmadd52luq 320(%rsi),%ymm1,%ymm3 +{vex} vpmadd52luq 352(%rsi),%ymm1,%ymm4 +{vex} vpmadd52luq 384(%rsi),%ymm1,%ymm5 +{vex} vpmadd52luq 416(%rsi),%ymm1,%ymm6 +{vex} vpmadd52luq 448(%rsi),%ymm1,%ymm7 +{vex} vpmadd52luq 480(%rsi),%ymm1,%ymm8 +{vex} vpmadd52luq 512(%rsi),%ymm1,%ymm9 +{vex} vpmadd52luq 544(%rsi),%ymm1,%ymm10 +{vex} vpmadd52luq 576(%rsi),%ymm1,%ymm11 +{vex} vpmadd52luq 608(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52luq 320(%rcx),%ymm2,%ymm3 +{vex} vpmadd52luq 352(%rcx),%ymm2,%ymm4 +{vex} vpmadd52luq 384(%rcx),%ymm2,%ymm5 +{vex} vpmadd52luq 416(%rcx),%ymm2,%ymm6 +{vex} vpmadd52luq 448(%rcx),%ymm2,%ymm7 +{vex} vpmadd52luq 480(%rcx),%ymm2,%ymm8 +{vex} vpmadd52luq 512(%rcx),%ymm2,%ymm9 +{vex} vpmadd52luq 544(%rcx),%ymm2,%ymm10 +{vex} vpmadd52luq 576(%rcx),%ymm2,%ymm11 +{vex} vpmadd52luq 608(%rcx),%ymm2,%ymm12 + vmovdqu %ymm3,0(%rsp) + vmovdqu %ymm4,32(%rsp) + vmovdqu %ymm5,64(%rsp) + vmovdqu %ymm6,96(%rsp) + vmovdqu %ymm7,128(%rsp) + vmovdqu %ymm8,160(%rsp) + vmovdqu %ymm9,192(%rsp) + vmovdqu %ymm10,224(%rsp) + vmovdqu %ymm11,256(%rsp) + vmovdqu %ymm12,288(%rsp) + movq $0,320(%rsp) + + vmovdqu 8(%rsp),%ymm3 + vmovdqu 40(%rsp),%ymm4 + vmovdqu 72(%rsp),%ymm5 + vmovdqu 104(%rsp),%ymm6 + vmovdqu 136(%rsp),%ymm7 + vmovdqu 168(%rsp),%ymm8 + vmovdqu 200(%rsp),%ymm9 + vmovdqu 232(%rsp),%ymm10 + vmovdqu 264(%rsp),%ymm11 + vmovdqu 296(%rsp),%ymm12 + + addq 8(%rsp),%r9 + +{vex} vpmadd52huq 320(%rsi),%ymm1,%ymm3 +{vex} vpmadd52huq 352(%rsi),%ymm1,%ymm4 +{vex} vpmadd52huq 384(%rsi),%ymm1,%ymm5 +{vex} vpmadd52huq 416(%rsi),%ymm1,%ymm6 +{vex} vpmadd52huq 448(%rsi),%ymm1,%ymm7 +{vex} vpmadd52huq 480(%rsi),%ymm1,%ymm8 +{vex} vpmadd52huq 512(%rsi),%ymm1,%ymm9 +{vex} vpmadd52huq 544(%rsi),%ymm1,%ymm10 +{vex} vpmadd52huq 576(%rsi),%ymm1,%ymm11 +{vex} vpmadd52huq 608(%rsi),%ymm1,%ymm12 + +{vex} vpmadd52huq 320(%rcx),%ymm2,%ymm3 +{vex} vpmadd52huq 352(%rcx),%ymm2,%ymm4 +{vex} vpmadd52huq 384(%rcx),%ymm2,%ymm5 +{vex} vpmadd52huq 416(%rcx),%ymm2,%ymm6 +{vex} vpmadd52huq 448(%rcx),%ymm2,%ymm7 +{vex} vpmadd52huq 480(%rcx),%ymm2,%ymm8 +{vex} vpmadd52huq 512(%rcx),%ymm2,%ymm9 +{vex} vpmadd52huq 544(%rcx),%ymm2,%ymm10 +{vex} vpmadd52huq 576(%rcx),%ymm2,%ymm11 +{vex} vpmadd52huq 608(%rcx),%ymm2,%ymm12 + leaq 328(%rsp),%rsp + leaq 8(%r11),%r11 + decl %ebx + jne .Lloop40_1 + + vmovq %r9,%xmm0 + vpbroadcastq %xmm0,%ymm0 + vpblendd $3,%ymm0,%ymm3,%ymm3 + + leaq -640(%rsp),%rsp + vmovupd %ymm3,0(%rsp) + vmovupd %ymm4,32(%rsp) + vmovupd %ymm5,64(%rsp) + vmovupd %ymm6,96(%rsp) + vmovupd %ymm7,128(%rsp) + vmovupd %ymm8,160(%rsp) + vmovupd %ymm9,192(%rsp) + vmovupd %ymm10,224(%rsp) + vmovupd %ymm11,256(%rsp) + vmovupd %ymm12,288(%rsp) + + + + vpsrlq $52,%ymm3,%ymm3 + vpsrlq $52,%ymm4,%ymm4 + vpsrlq $52,%ymm5,%ymm5 + vpsrlq $52,%ymm6,%ymm6 + vpsrlq $52,%ymm7,%ymm7 + vpsrlq $52,%ymm8,%ymm8 + vpsrlq $52,%ymm9,%ymm9 + vpsrlq $52,%ymm10,%ymm10 + vpsrlq $52,%ymm11,%ymm11 + vpsrlq $52,%ymm12,%ymm12 + + + vpermq $144,%ymm12,%ymm12 + vpermq $3,%ymm11,%ymm13 + vblendpd $1,%ymm13,%ymm12,%ymm12 + + vpermq $144,%ymm11,%ymm11 + vpermq $3,%ymm10,%ymm13 + vblendpd $1,%ymm13,%ymm11,%ymm11 + + vpermq $144,%ymm10,%ymm10 + vpermq $3,%ymm9,%ymm13 + vblendpd $1,%ymm13,%ymm10,%ymm10 + + vpermq $144,%ymm9,%ymm9 + vpermq $3,%ymm8,%ymm13 + vblendpd $1,%ymm13,%ymm9,%ymm9 + + vpermq $144,%ymm8,%ymm8 + vpermq $3,%ymm7,%ymm13 + vblendpd $1,%ymm13,%ymm8,%ymm8 + + vpermq $144,%ymm7,%ymm7 + vpermq $3,%ymm6,%ymm13 + vblendpd $1,%ymm13,%ymm7,%ymm7 + + vpermq $144,%ymm6,%ymm6 + vpermq $3,%ymm5,%ymm13 + vblendpd $1,%ymm13,%ymm6,%ymm6 + + vpermq $144,%ymm5,%ymm5 + vpermq $3,%ymm4,%ymm13 + vblendpd $1,%ymm13,%ymm5,%ymm5 + + vpermq $144,%ymm4,%ymm4 + vpermq $3,%ymm3,%ymm13 + vblendpd $1,%ymm13,%ymm4,%ymm4 + + vpermq $144,%ymm3,%ymm3 + vpand .Lhigh64x3(%rip),%ymm3,%ymm3 + + vmovupd %ymm3,320(%rsp) + vmovupd %ymm4,352(%rsp) + vmovupd %ymm5,384(%rsp) + vmovupd %ymm6,416(%rsp) + vmovupd %ymm7,448(%rsp) + vmovupd %ymm8,480(%rsp) + vmovupd %ymm9,512(%rsp) + vmovupd %ymm10,544(%rsp) + vmovupd %ymm11,576(%rsp) + vmovupd %ymm12,608(%rsp) + + vmovupd 0(%rsp),%ymm3 + vmovupd 32(%rsp),%ymm4 + vmovupd 64(%rsp),%ymm5 + vmovupd 96(%rsp),%ymm6 + vmovupd 128(%rsp),%ymm7 + vmovupd 160(%rsp),%ymm8 + vmovupd 192(%rsp),%ymm9 + vmovupd 224(%rsp),%ymm10 + vmovupd 256(%rsp),%ymm11 + vmovupd 288(%rsp),%ymm12 + + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + vpand .Lmask52x4(%rip),%ymm11,%ymm11 + vpand .Lmask52x4(%rip),%ymm12,%ymm12 + + + vpaddq 320(%rsp),%ymm3,%ymm3 + vpaddq 352(%rsp),%ymm4,%ymm4 + vpaddq 384(%rsp),%ymm5,%ymm5 + vpaddq 416(%rsp),%ymm6,%ymm6 + vpaddq 448(%rsp),%ymm7,%ymm7 + vpaddq 480(%rsp),%ymm8,%ymm8 + vpaddq 512(%rsp),%ymm9,%ymm9 + vpaddq 544(%rsp),%ymm10,%ymm10 + vpaddq 576(%rsp),%ymm11,%ymm11 + vpaddq 608(%rsp),%ymm12,%ymm12 + + leaq 640(%rsp),%rsp + + + + vpcmpgtq .Lmask52x4(%rip),%ymm3,%ymm13 + vmovmskpd %ymm13,%r14d + vpcmpgtq .Lmask52x4(%rip),%ymm4,%ymm13 + vmovmskpd %ymm13,%r13d + shlb $4,%r13b + orb %r13b,%r14b + + vpcmpgtq .Lmask52x4(%rip),%ymm5,%ymm13 + vmovmskpd %ymm13,%r13d + vpcmpgtq .Lmask52x4(%rip),%ymm6,%ymm13 + vmovmskpd %ymm13,%r12d + shlb $4,%r12b + orb %r12b,%r13b + + vpcmpgtq .Lmask52x4(%rip),%ymm7,%ymm13 + vmovmskpd %ymm13,%r12d + vpcmpgtq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm13,%r11d + shlb $4,%r11b + orb %r11b,%r12b + + vpcmpgtq .Lmask52x4(%rip),%ymm9,%ymm13 + vmovmskpd %ymm13,%r11d + vpcmpgtq .Lmask52x4(%rip),%ymm10,%ymm13 + vmovmskpd %ymm13,%r10d + shlb $4,%r10b + orb %r10b,%r11b + + vpcmpgtq .Lmask52x4(%rip),%ymm11,%ymm13 + vmovmskpd %ymm13,%r10d + vpcmpgtq .Lmask52x4(%rip),%ymm12,%ymm13 + vmovmskpd %ymm13,%r9d + shlb $4,%r9b + orb %r9b,%r10b + + addb %r14b,%r14b + adcb %r13b,%r13b + adcb %r12b,%r12b + adcb %r11b,%r11b + adcb %r10b,%r10b + + + vpcmpeqq .Lmask52x4(%rip),%ymm3,%ymm13 + vmovmskpd %ymm13,%r9d + vpcmpeqq .Lmask52x4(%rip),%ymm4,%ymm13 + vmovmskpd %ymm13,%r8d + shlb $4,%r8b + orb %r8b,%r9b + + vpcmpeqq .Lmask52x4(%rip),%ymm5,%ymm13 + vmovmskpd %ymm13,%r8d + vpcmpeqq .Lmask52x4(%rip),%ymm6,%ymm13 + vmovmskpd %ymm13,%edx + shlb $4,%dl + orb %dl,%r8b + + vpcmpeqq .Lmask52x4(%rip),%ymm7,%ymm13 + vmovmskpd %ymm13,%edx + vpcmpeqq .Lmask52x4(%rip),%ymm8,%ymm13 + vmovmskpd %ymm13,%ecx + shlb $4,%cl + orb %cl,%dl + + vpcmpeqq .Lmask52x4(%rip),%ymm9,%ymm13 + vmovmskpd %ymm13,%ecx + vpcmpeqq .Lmask52x4(%rip),%ymm10,%ymm13 + vmovmskpd %ymm13,%ebx + shlb $4,%bl + orb %bl,%cl + + vpcmpeqq .Lmask52x4(%rip),%ymm11,%ymm13 + vmovmskpd %ymm13,%ebx + vpcmpeqq .Lmask52x4(%rip),%ymm12,%ymm13 + vmovmskpd %ymm13,%eax + shlb $4,%al + orb %al,%bl + + addb %r9b,%r14b + adcb %r8b,%r13b + adcb %dl,%r12b + adcb %cl,%r11b + adcb %bl,%r10b + + xorb %r9b,%r14b + xorb %r8b,%r13b + xorb %dl,%r12b + xorb %cl,%r11b + xorb %bl,%r10b + + pushq %r9 + pushq %r8 + + leaq .Lkmasklut(%rip),%r8 + + movb %r14b,%r9b + andq $0xf,%r14 + vpsubq .Lmask52x4(%rip),%ymm3,%ymm13 + shlq $5,%r14 + vmovapd (%r8,%r14,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm3,%ymm3 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm4,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm4,%ymm4 + + movb %r13b,%r9b + andq $0xf,%r13 + vpsubq .Lmask52x4(%rip),%ymm5,%ymm13 + shlq $5,%r13 + vmovapd (%r8,%r13,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm5,%ymm5 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm6,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm6,%ymm6 + + movb %r12b,%r9b + andq $0xf,%r12 + vpsubq .Lmask52x4(%rip),%ymm7,%ymm13 + shlq $5,%r12 + vmovapd (%r8,%r12,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm7,%ymm7 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm8,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm8,%ymm8 + + movb %r11b,%r9b + andq $0xf,%r11 + vpsubq .Lmask52x4(%rip),%ymm9,%ymm13 + shlq $5,%r11 + vmovapd (%r8,%r11,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm9,%ymm9 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm10,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm10,%ymm10 + + movb %r10b,%r9b + andq $0xf,%r10 + vpsubq .Lmask52x4(%rip),%ymm11,%ymm13 + shlq $5,%r10 + vmovapd (%r8,%r10,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm11,%ymm11 + + shrb $4,%r9b + andq $0xf,%r9 + vpsubq .Lmask52x4(%rip),%ymm12,%ymm13 + shlq $5,%r9 + vmovapd (%r8,%r9,1),%ymm14 + vblendvpd %ymm14,%ymm13,%ymm12,%ymm12 + + popq %r8 + popq %r9 + + vpand .Lmask52x4(%rip),%ymm3,%ymm3 + vpand .Lmask52x4(%rip),%ymm4,%ymm4 + vpand .Lmask52x4(%rip),%ymm5,%ymm5 + vpand .Lmask52x4(%rip),%ymm6,%ymm6 + vpand .Lmask52x4(%rip),%ymm7,%ymm7 + vpand .Lmask52x4(%rip),%ymm8,%ymm8 + vpand .Lmask52x4(%rip),%ymm9,%ymm9 + + vpand .Lmask52x4(%rip),%ymm10,%ymm10 + vpand .Lmask52x4(%rip),%ymm11,%ymm11 + vpand .Lmask52x4(%rip),%ymm12,%ymm12 + + vmovdqu %ymm3,320(%rdi) + vmovdqu %ymm4,352(%rdi) + vmovdqu %ymm5,384(%rdi) + vmovdqu %ymm6,416(%rdi) + vmovdqu %ymm7,448(%rdi) + vmovdqu %ymm8,480(%rdi) + vmovdqu %ymm9,512(%rdi) + vmovdqu %ymm10,544(%rdi) + vmovdqu %ymm11,576(%rdi) + vmovdqu %ymm12,608(%rdi) + + vzeroupper + leaq (%rsp),%rax +.cfi_def_cfa_register %rax + movq 0(%rax),%r15 +.cfi_restore %r15 + movq 8(%rax),%r14 +.cfi_restore %r14 + movq 16(%rax),%r13 +.cfi_restore %r13 + movq 24(%rax),%r12 +.cfi_restore %r12 + movq 32(%rax),%rbp +.cfi_restore %rbp + movq 40(%rax),%rbx +.cfi_restore %rbx + leaq 48(%rax),%rsp +.cfi_def_cfa %rsp,8 +.Lossl_rsaz_amm52x40_x2_avxifma256_epilogue: + .byte 0xf3,0xc3 +.cfi_endproc +.size ossl_rsaz_amm52x40_x2_avxifma256, .-ossl_rsaz_amm52x40_x2_avxifma256 +.text + +.align 32 +.globl ossl_extract_multiplier_2x40_win5_avx +.type ossl_extract_multiplier_2x40_win5_avx,@function +ossl_extract_multiplier_2x40_win5_avx: +.cfi_startproc +.byte 243,15,30,250 + vmovapd .Lones(%rip),%ymm14 + vmovq %rdx,%xmm10 + vpbroadcastq %xmm10,%ymm12 + vmovq %rcx,%xmm10 + vpbroadcastq %xmm10,%ymm13 + leaq 20480(%rsi),%rax + + + movq %rsi,%r10 + + + vpxor %xmm0,%xmm0,%xmm0 + vmovapd %ymm0,%ymm1 + vmovapd %ymm0,%ymm2 + vmovapd %ymm0,%ymm3 + vmovapd %ymm0,%ymm4 + vmovapd %ymm0,%ymm5 + vmovapd %ymm0,%ymm6 + vmovapd %ymm0,%ymm7 + vmovapd %ymm0,%ymm8 + vmovapd %ymm0,%ymm9 + vpxor %ymm11,%ymm11,%ymm11 +.align 32 +.Lloop_0: + vpcmpeqq %ymm11,%ymm12,%ymm15 + vmovdqu 0(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm0,%ymm0 + vmovdqu 32(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm1,%ymm1 + vmovdqu 64(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm2,%ymm2 + vmovdqu 96(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm3,%ymm3 + vmovdqu 128(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm4,%ymm4 + vmovdqu 160(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm5,%ymm5 + vmovdqu 192(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm6,%ymm6 + vmovdqu 224(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm7,%ymm7 + vmovdqu 256(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm8,%ymm8 + vmovdqu 288(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm9,%ymm9 + vpaddq %ymm14,%ymm11,%ymm11 + addq $640,%rsi + cmpq %rsi,%rax + jne .Lloop_0 + vmovdqu %ymm0,0(%rdi) + vmovdqu %ymm1,32(%rdi) + vmovdqu %ymm2,64(%rdi) + vmovdqu %ymm3,96(%rdi) + vmovdqu %ymm4,128(%rdi) + vmovdqu %ymm5,160(%rdi) + vmovdqu %ymm6,192(%rdi) + vmovdqu %ymm7,224(%rdi) + vmovdqu %ymm8,256(%rdi) + vmovdqu %ymm9,288(%rdi) + movq %r10,%rsi + vpxor %ymm11,%ymm11,%ymm11 +.align 32 +.Lloop_320: + vpcmpeqq %ymm11,%ymm13,%ymm15 + vmovdqu 320(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm0,%ymm0 + vmovdqu 352(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm1,%ymm1 + vmovdqu 384(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm2,%ymm2 + vmovdqu 416(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm3,%ymm3 + vmovdqu 448(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm4,%ymm4 + vmovdqu 480(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm5,%ymm5 + vmovdqu 512(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm6,%ymm6 + vmovdqu 544(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm7,%ymm7 + vmovdqu 576(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm8,%ymm8 + vmovdqu 608(%rsi),%ymm10 + + vblendvpd %ymm15,%ymm10,%ymm9,%ymm9 + vpaddq %ymm14,%ymm11,%ymm11 + addq $640,%rsi + cmpq %rsi,%rax + jne .Lloop_320 + vmovdqu %ymm0,320(%rdi) + vmovdqu %ymm1,352(%rdi) + vmovdqu %ymm2,384(%rdi) + vmovdqu %ymm3,416(%rdi) + vmovdqu %ymm4,448(%rdi) + vmovdqu %ymm5,480(%rdi) + vmovdqu %ymm6,512(%rdi) + vmovdqu %ymm7,544(%rdi) + vmovdqu %ymm8,576(%rdi) + vmovdqu %ymm9,608(%rdi) + vzeroupper + + .byte 0xf3,0xc3 +.cfi_endproc +.size ossl_extract_multiplier_2x40_win5_avx, .-ossl_extract_multiplier_2x40_win5_avx +.section .rodata +.align 32 +.Lones: +.quad 1,1,1,1 +.Lzeros: +.quad 0,0,0,0 .section ".note.gnu.property", "a" .p2align 3 .long 1f - 0f diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-2k-avxifma.nasm b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-2k-avxifma.nasm index 8da9e018a1..53d7d6c9b4 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-2k-avxifma.nasm +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-2k-avxifma.nasm @@ -4,21 +4,1352 @@ default rel %define ZMMWORD section .text code align=64 - +EXTERN OPENSSL_ia32cap_P global ossl_rsaz_avxifma_eligible +ALIGN 32 ossl_rsaz_avxifma_eligible: + mov ecx,DWORD[((OPENSSL_ia32cap_P+20))] xor eax,eax + and ecx,8388608 + cmp ecx,8388608 + cmove eax,ecx DB 0F3h,0C3h ;repret +section .text code align=64 + global ossl_rsaz_amm52x20_x1_avxifma256 -global ossl_rsaz_amm52x20_x2_avxifma256 -global ossl_extract_multiplier_2x20_win5_avx +ALIGN 32 ossl_rsaz_amm52x20_x1_avxifma256: -ossl_rsaz_amm52x20_x2_avxifma256: -ossl_extract_multiplier_2x20_win5_avx: -DB 0x0f,0x0b + mov QWORD[8+rsp],rdi ;WIN64 prologue + mov QWORD[16+rsp],rsi + mov rax,rsp +$L$SEH_begin_ossl_rsaz_amm52x20_x1_avxifma256: + mov rdi,rcx + mov rsi,rdx + mov rdx,r8 + mov rcx,r9 + mov r8,QWORD[40+rsp] + + + +DB 243,15,30,250 + push rbx + + push rbp + + push r12 + + push r13 + + push r14 + + push r15 + + push rsi + push rdi + lea rsp,[((-168))+rsp] + vmovapd XMMWORD[rsp],xmm6 + vmovapd XMMWORD[16+rsp],xmm7 + vmovapd XMMWORD[32+rsp],xmm8 + vmovapd XMMWORD[48+rsp],xmm9 + vmovapd XMMWORD[64+rsp],xmm10 + vmovapd XMMWORD[80+rsp],xmm11 + vmovapd XMMWORD[96+rsp],xmm12 + vmovapd XMMWORD[112+rsp],xmm13 + vmovapd XMMWORD[128+rsp],xmm14 + vmovapd XMMWORD[144+rsp],xmm15 +$L$ossl_rsaz_amm52x20_x1_avxifma256_body: + + + vpxor ymm0,ymm0,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + vmovapd ymm8,ymm0 + + xor r9d,r9d + + mov r11,rdx + mov rax,0xfffffffffffff + + + mov ebx,5 + +ALIGN 32 +$L$loop5: + mov r13,QWORD[r11] + + vpbroadcastq ymm1,QWORD[r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-168))+rsp] +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[128+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[128+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm5 + vmovdqu YMMWORD[64+rsp],ymm6 + vmovdqu YMMWORD[96+rsp],ymm7 + vmovdqu YMMWORD[128+rsp],ymm8 + mov QWORD[160+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm5,YMMWORD[40+rsp] + vmovdqu ymm6,YMMWORD[72+rsp] + vmovdqu ymm7,YMMWORD[104+rsp] + vmovdqu ymm8,YMMWORD[136+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[128+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[128+rcx] + lea rsp,[168+rsp] + mov r13,QWORD[8+r11] + + vpbroadcastq ymm1,QWORD[8+r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-168))+rsp] +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[128+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[128+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm5 + vmovdqu YMMWORD[64+rsp],ymm6 + vmovdqu YMMWORD[96+rsp],ymm7 + vmovdqu YMMWORD[128+rsp],ymm8 + mov QWORD[160+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm5,YMMWORD[40+rsp] + vmovdqu ymm6,YMMWORD[72+rsp] + vmovdqu ymm7,YMMWORD[104+rsp] + vmovdqu ymm8,YMMWORD[136+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[128+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[128+rcx] + lea rsp,[168+rsp] + mov r13,QWORD[16+r11] + + vpbroadcastq ymm1,QWORD[16+r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-168))+rsp] +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[128+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[128+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm5 + vmovdqu YMMWORD[64+rsp],ymm6 + vmovdqu YMMWORD[96+rsp],ymm7 + vmovdqu YMMWORD[128+rsp],ymm8 + mov QWORD[160+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm5,YMMWORD[40+rsp] + vmovdqu ymm6,YMMWORD[72+rsp] + vmovdqu ymm7,YMMWORD[104+rsp] + vmovdqu ymm8,YMMWORD[136+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[128+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[128+rcx] + lea rsp,[168+rsp] + mov r13,QWORD[24+r11] + + vpbroadcastq ymm1,QWORD[24+r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-168))+rsp] +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[128+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[128+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm5 + vmovdqu YMMWORD[64+rsp],ymm6 + vmovdqu YMMWORD[96+rsp],ymm7 + vmovdqu YMMWORD[128+rsp],ymm8 + mov QWORD[160+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm5,YMMWORD[40+rsp] + vmovdqu ymm6,YMMWORD[72+rsp] + vmovdqu ymm7,YMMWORD[104+rsp] + vmovdqu ymm8,YMMWORD[136+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[128+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[128+rcx] + lea rsp,[168+rsp] + lea r11,[32+r11] + dec ebx + jne NEAR $L$loop5 + + vmovq xmm0,r9 + vpbroadcastq ymm0,xmm0 + vpblendd ymm3,ymm3,ymm0,3 + + + + vpsrlq ymm0,ymm3,52 + vpsrlq ymm1,ymm5,52 + vpsrlq ymm2,ymm6,52 + vpsrlq ymm13,ymm7,52 + vpsrlq ymm14,ymm8,52 + + + vpermq ymm14,ymm14,144 + vpermq ymm15,ymm13,3 + vblendpd ymm14,ymm14,ymm15,1 + + vpermq ymm13,ymm13,144 + vpermq ymm15,ymm2,3 + vblendpd ymm13,ymm13,ymm15,1 + + vpermq ymm2,ymm2,144 + vpermq ymm15,ymm1,3 + vblendpd ymm2,ymm2,ymm15,1 + + vpermq ymm1,ymm1,144 + vpermq ymm15,ymm0,3 + vblendpd ymm1,ymm1,ymm15,1 + + vpermq ymm0,ymm0,144 + vpand ymm0,ymm0,YMMWORD[$L$high64x3] + + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + + + vpaddq ymm3,ymm3,ymm0 + vpaddq ymm5,ymm5,ymm1 + vpaddq ymm6,ymm6,ymm2 + vpaddq ymm7,ymm7,ymm13 + vpaddq ymm8,ymm8,ymm14 + + + + vpcmpgtq ymm0,ymm3,YMMWORD[$L$mask52x4] + vpcmpgtq ymm1,ymm5,YMMWORD[$L$mask52x4] + vpcmpgtq ymm2,ymm6,YMMWORD[$L$mask52x4] + vpcmpgtq ymm13,ymm7,YMMWORD[$L$mask52x4] + vpcmpgtq ymm14,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd r14d,ymm0 + vmovmskpd r13d,ymm1 + vmovmskpd r12d,ymm2 + vmovmskpd r11d,ymm13 + vmovmskpd r10d,ymm14 + + + vpcmpeqq ymm0,ymm3,YMMWORD[$L$mask52x4] + vpcmpeqq ymm1,ymm5,YMMWORD[$L$mask52x4] + vpcmpeqq ymm2,ymm6,YMMWORD[$L$mask52x4] + vpcmpeqq ymm13,ymm7,YMMWORD[$L$mask52x4] + vpcmpeqq ymm14,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm0 + vmovmskpd r8d,ymm1 + vmovmskpd ebx,ymm2 + vmovmskpd ecx,ymm13 + vmovmskpd edx,ymm14 + + + + shl r13b,4 + or r14b,r13b + shl r11b,4 + or r12b,r11b + + add r14b,r14b + adc r12b,r12b + adc r10b,r10b + + shl r8b,4 + or r9b,r8b + shl cl,4 + or bl,cl + + add r14b,r9b + adc r12b,bl + adc r10b,dl + + xor r14b,r9b + xor r12b,bl + xor r10b,dl + + lea rdx,[$L$kmasklut] + + mov r13b,r14b + and r14,0xf + vpsubq ymm0,ymm3,YMMWORD[$L$mask52x4] + shl r14,5 + vmovapd ymm2,YMMWORD[r14*1+rdx] + vblendvpd ymm3,ymm3,ymm0,ymm2 + + shr r13b,4 + and r13,0xf + vpsubq ymm0,ymm5,YMMWORD[$L$mask52x4] + shl r13,5 + vmovapd ymm2,YMMWORD[r13*1+rdx] + vblendvpd ymm5,ymm5,ymm0,ymm2 + + mov r11b,r12b + and r12,0xf + vpsubq ymm0,ymm6,YMMWORD[$L$mask52x4] + shl r12,5 + vmovapd ymm2,YMMWORD[r12*1+rdx] + vblendvpd ymm6,ymm6,ymm0,ymm2 + + shr r11b,4 + and r11,0xf + vpsubq ymm0,ymm7,YMMWORD[$L$mask52x4] + shl r11,5 + vmovapd ymm2,YMMWORD[r11*1+rdx] + vblendvpd ymm7,ymm7,ymm0,ymm2 + + and r10,0xf + vpsubq ymm0,ymm8,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm8,ymm8,ymm0,ymm2 + + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + + vmovdqu YMMWORD[rdi],ymm3 + vmovdqu YMMWORD[32+rdi],ymm5 + vmovdqu YMMWORD[64+rdi],ymm6 + vmovdqu YMMWORD[96+rdi],ymm7 + vmovdqu YMMWORD[128+rdi],ymm8 + + vzeroupper + vmovapd xmm6,XMMWORD[rsp] + vmovapd xmm7,XMMWORD[16+rsp] + vmovapd xmm8,XMMWORD[32+rsp] + vmovapd xmm9,XMMWORD[48+rsp] + vmovapd xmm10,XMMWORD[64+rsp] + vmovapd xmm11,XMMWORD[80+rsp] + vmovapd xmm12,XMMWORD[96+rsp] + vmovapd xmm13,XMMWORD[112+rsp] + vmovapd xmm14,XMMWORD[128+rsp] + vmovapd xmm15,XMMWORD[144+rsp] + lea rsp,[168+rsp] + pop rdi + pop rsi + mov r15,QWORD[rsp] + + mov r14,QWORD[8+rsp] + + mov r13,QWORD[16+rsp] + + mov r12,QWORD[24+rsp] + + mov rbp,QWORD[32+rsp] + + mov rbx,QWORD[40+rsp] + + lea rsp,[48+rsp] + +$L$ossl_rsaz_amm52x20_x1_avxifma256_epilogue: + mov rdi,QWORD[8+rsp] ;WIN64 epilogue + mov rsi,QWORD[16+rsp] DB 0F3h,0C3h ;repret +$L$SEH_end_ossl_rsaz_amm52x20_x1_avxifma256: +section .rdata rdata align=32 +ALIGN 32 +$L$mask52x4: + DQ 0xfffffffffffff + DQ 0xfffffffffffff + DQ 0xfffffffffffff + DQ 0xfffffffffffff +$L$high64x3: + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff +$L$kmasklut: + + DQ 0x0 + DQ 0x0 + DQ 0x0 + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + DQ 0x0 + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0x0 + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff +section .text code align=64 + + +global ossl_rsaz_amm52x20_x2_avxifma256 + +ALIGN 32 +ossl_rsaz_amm52x20_x2_avxifma256: + mov QWORD[8+rsp],rdi ;WIN64 prologue + mov QWORD[16+rsp],rsi + mov rax,rsp +$L$SEH_begin_ossl_rsaz_amm52x20_x2_avxifma256: + mov rdi,rcx + mov rsi,rdx + mov rdx,r8 + mov rcx,r9 + mov r8,QWORD[40+rsp] + + + +DB 243,15,30,250 + push rbx + + push rbp + + push r12 + + push r13 + + push r14 + + push r15 + + push rsi + push rdi + lea rsp,[((-168))+rsp] + vmovapd XMMWORD[rsp],xmm6 + vmovapd XMMWORD[16+rsp],xmm7 + vmovapd XMMWORD[32+rsp],xmm8 + vmovapd XMMWORD[48+rsp],xmm9 + vmovapd XMMWORD[64+rsp],xmm10 + vmovapd XMMWORD[80+rsp],xmm11 + vmovapd XMMWORD[96+rsp],xmm12 + vmovapd XMMWORD[112+rsp],xmm13 + vmovapd XMMWORD[128+rsp],xmm14 + vmovapd XMMWORD[144+rsp],xmm15 +$L$ossl_rsaz_amm52x20_x2_avxifma256_body: + + + vpxor ymm0,ymm0,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + vmovapd ymm8,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm9,ymm0 + vmovapd ymm10,ymm0 + vmovapd ymm11,ymm0 + vmovapd ymm12,ymm0 + + xor r9d,r9d + xor r15d,r15d + + mov r11,rdx + mov rax,0xfffffffffffff + + mov ebx,20 + +ALIGN 32 +$L$loop20: + mov r13,QWORD[r11] + + vpbroadcastq ymm1,QWORD[r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,QWORD[r8] + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-168))+rsp] +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[128+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[128+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm5 + vmovdqu YMMWORD[64+rsp],ymm6 + vmovdqu YMMWORD[96+rsp],ymm7 + vmovdqu YMMWORD[128+rsp],ymm8 + mov QWORD[160+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm5,YMMWORD[40+rsp] + vmovdqu ymm6,YMMWORD[72+rsp] + vmovdqu ymm7,YMMWORD[104+rsp] + vmovdqu ymm8,YMMWORD[136+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[128+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[128+rcx] + lea rsp,[168+rsp] + mov r13,QWORD[160+r11] + + vpbroadcastq ymm1,QWORD[160+r11] + mov rdx,QWORD[160+rsi] + mulx r12,r13,r13 + add r15,r13 + mov r10,r12 + adc r10,0 + + mov r13,QWORD[8+r8] + imul r13,r15 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[160+rcx] + mulx r12,r13,r13 + add r15,r13 + adc r10,r12 + + shr r15,52 + sal r10,12 + or r15,r10 + + lea rsp,[((-168))+rsp] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52luq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52luq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52luq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52luq ymm12,ymm2,YMMWORD[288+rcx] + + + vmovdqu YMMWORD[rsp],ymm4 + vmovdqu YMMWORD[32+rsp],ymm9 + vmovdqu YMMWORD[64+rsp],ymm10 + vmovdqu YMMWORD[96+rsp],ymm11 + vmovdqu YMMWORD[128+rsp],ymm12 + mov QWORD[160+rsp],0 + + vmovdqu ymm4,YMMWORD[8+rsp] + vmovdqu ymm9,YMMWORD[40+rsp] + vmovdqu ymm10,YMMWORD[72+rsp] + vmovdqu ymm11,YMMWORD[104+rsp] + vmovdqu ymm12,YMMWORD[136+rsp] + + add r15,QWORD[8+rsp] + +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52huq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52huq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52huq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52huq ymm12,ymm2,YMMWORD[288+rcx] + lea rsp,[168+rsp] + lea r11,[8+r11] + dec ebx + jne NEAR $L$loop20 + + vmovq xmm0,r9 + vpbroadcastq ymm0,xmm0 + vpblendd ymm3,ymm3,ymm0,3 + + + + vpsrlq ymm0,ymm3,52 + vpsrlq ymm1,ymm5,52 + vpsrlq ymm2,ymm6,52 + vpsrlq ymm13,ymm7,52 + vpsrlq ymm14,ymm8,52 + + + vpermq ymm14,ymm14,144 + vpermq ymm15,ymm13,3 + vblendpd ymm14,ymm14,ymm15,1 + + vpermq ymm13,ymm13,144 + vpermq ymm15,ymm2,3 + vblendpd ymm13,ymm13,ymm15,1 + + vpermq ymm2,ymm2,144 + vpermq ymm15,ymm1,3 + vblendpd ymm2,ymm2,ymm15,1 + + vpermq ymm1,ymm1,144 + vpermq ymm15,ymm0,3 + vblendpd ymm1,ymm1,ymm15,1 + + vpermq ymm0,ymm0,144 + vpand ymm0,ymm0,YMMWORD[$L$high64x3] + + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + + + vpaddq ymm3,ymm3,ymm0 + vpaddq ymm5,ymm5,ymm1 + vpaddq ymm6,ymm6,ymm2 + vpaddq ymm7,ymm7,ymm13 + vpaddq ymm8,ymm8,ymm14 + + + + vpcmpgtq ymm0,ymm3,YMMWORD[$L$mask52x4] + vpcmpgtq ymm1,ymm5,YMMWORD[$L$mask52x4] + vpcmpgtq ymm2,ymm6,YMMWORD[$L$mask52x4] + vpcmpgtq ymm13,ymm7,YMMWORD[$L$mask52x4] + vpcmpgtq ymm14,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd r14d,ymm0 + vmovmskpd r13d,ymm1 + vmovmskpd r12d,ymm2 + vmovmskpd r11d,ymm13 + vmovmskpd r10d,ymm14 + + + vpcmpeqq ymm0,ymm3,YMMWORD[$L$mask52x4] + vpcmpeqq ymm1,ymm5,YMMWORD[$L$mask52x4] + vpcmpeqq ymm2,ymm6,YMMWORD[$L$mask52x4] + vpcmpeqq ymm13,ymm7,YMMWORD[$L$mask52x4] + vpcmpeqq ymm14,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm0 + vmovmskpd r8d,ymm1 + vmovmskpd ebx,ymm2 + vmovmskpd ecx,ymm13 + vmovmskpd edx,ymm14 + + + + shl r13b,4 + or r14b,r13b + shl r11b,4 + or r12b,r11b + + add r14b,r14b + adc r12b,r12b + adc r10b,r10b + + shl r8b,4 + or r9b,r8b + shl cl,4 + or bl,cl + + add r14b,r9b + adc r12b,bl + adc r10b,dl + + xor r14b,r9b + xor r12b,bl + xor r10b,dl + + lea rdx,[$L$kmasklut] + + mov r13b,r14b + and r14,0xf + vpsubq ymm0,ymm3,YMMWORD[$L$mask52x4] + shl r14,5 + vmovapd ymm2,YMMWORD[r14*1+rdx] + vblendvpd ymm3,ymm3,ymm0,ymm2 + + shr r13b,4 + and r13,0xf + vpsubq ymm0,ymm5,YMMWORD[$L$mask52x4] + shl r13,5 + vmovapd ymm2,YMMWORD[r13*1+rdx] + vblendvpd ymm5,ymm5,ymm0,ymm2 + + mov r11b,r12b + and r12,0xf + vpsubq ymm0,ymm6,YMMWORD[$L$mask52x4] + shl r12,5 + vmovapd ymm2,YMMWORD[r12*1+rdx] + vblendvpd ymm6,ymm6,ymm0,ymm2 + + shr r11b,4 + and r11,0xf + vpsubq ymm0,ymm7,YMMWORD[$L$mask52x4] + shl r11,5 + vmovapd ymm2,YMMWORD[r11*1+rdx] + vblendvpd ymm7,ymm7,ymm0,ymm2 + + and r10,0xf + vpsubq ymm0,ymm8,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm8,ymm8,ymm0,ymm2 + + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + + vmovq xmm0,r15 + vpbroadcastq ymm0,xmm0 + vpblendd ymm4,ymm4,ymm0,3 + + + + vpsrlq ymm0,ymm4,52 + vpsrlq ymm1,ymm9,52 + vpsrlq ymm2,ymm10,52 + vpsrlq ymm13,ymm11,52 + vpsrlq ymm14,ymm12,52 + + + vpermq ymm14,ymm14,144 + vpermq ymm15,ymm13,3 + vblendpd ymm14,ymm14,ymm15,1 + + vpermq ymm13,ymm13,144 + vpermq ymm15,ymm2,3 + vblendpd ymm13,ymm13,ymm15,1 + + vpermq ymm2,ymm2,144 + vpermq ymm15,ymm1,3 + vblendpd ymm2,ymm2,ymm15,1 + + vpermq ymm1,ymm1,144 + vpermq ymm15,ymm0,3 + vblendpd ymm1,ymm1,ymm15,1 + + vpermq ymm0,ymm0,144 + vpand ymm0,ymm0,YMMWORD[$L$high64x3] + + + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + vpand ymm11,ymm11,YMMWORD[$L$mask52x4] + vpand ymm12,ymm12,YMMWORD[$L$mask52x4] + + + vpaddq ymm4,ymm4,ymm0 + vpaddq ymm9,ymm9,ymm1 + vpaddq ymm10,ymm10,ymm2 + vpaddq ymm11,ymm11,ymm13 + vpaddq ymm12,ymm12,ymm14 + + + + vpcmpgtq ymm0,ymm4,YMMWORD[$L$mask52x4] + vpcmpgtq ymm1,ymm9,YMMWORD[$L$mask52x4] + vpcmpgtq ymm2,ymm10,YMMWORD[$L$mask52x4] + vpcmpgtq ymm13,ymm11,YMMWORD[$L$mask52x4] + vpcmpgtq ymm14,ymm12,YMMWORD[$L$mask52x4] + vmovmskpd r14d,ymm0 + vmovmskpd r13d,ymm1 + vmovmskpd r12d,ymm2 + vmovmskpd r11d,ymm13 + vmovmskpd r10d,ymm14 + + + vpcmpeqq ymm0,ymm4,YMMWORD[$L$mask52x4] + vpcmpeqq ymm1,ymm9,YMMWORD[$L$mask52x4] + vpcmpeqq ymm2,ymm10,YMMWORD[$L$mask52x4] + vpcmpeqq ymm13,ymm11,YMMWORD[$L$mask52x4] + vpcmpeqq ymm14,ymm12,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm0 + vmovmskpd r8d,ymm1 + vmovmskpd ebx,ymm2 + vmovmskpd ecx,ymm13 + vmovmskpd edx,ymm14 + + + + shl r13b,4 + or r14b,r13b + shl r11b,4 + or r12b,r11b + + add r14b,r14b + adc r12b,r12b + adc r10b,r10b + + shl r8b,4 + or r9b,r8b + shl cl,4 + or bl,cl + + add r14b,r9b + adc r12b,bl + adc r10b,dl + + xor r14b,r9b + xor r12b,bl + xor r10b,dl + + lea rdx,[$L$kmasklut] + + mov r13b,r14b + and r14,0xf + vpsubq ymm0,ymm4,YMMWORD[$L$mask52x4] + shl r14,5 + vmovapd ymm2,YMMWORD[r14*1+rdx] + vblendvpd ymm4,ymm4,ymm0,ymm2 + + shr r13b,4 + and r13,0xf + vpsubq ymm0,ymm9,YMMWORD[$L$mask52x4] + shl r13,5 + vmovapd ymm2,YMMWORD[r13*1+rdx] + vblendvpd ymm9,ymm9,ymm0,ymm2 + + mov r11b,r12b + and r12,0xf + vpsubq ymm0,ymm10,YMMWORD[$L$mask52x4] + shl r12,5 + vmovapd ymm2,YMMWORD[r12*1+rdx] + vblendvpd ymm10,ymm10,ymm0,ymm2 + + shr r11b,4 + and r11,0xf + vpsubq ymm0,ymm11,YMMWORD[$L$mask52x4] + shl r11,5 + vmovapd ymm2,YMMWORD[r11*1+rdx] + vblendvpd ymm11,ymm11,ymm0,ymm2 + + and r10,0xf + vpsubq ymm0,ymm12,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm12,ymm12,ymm0,ymm2 + + + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + vpand ymm11,ymm11,YMMWORD[$L$mask52x4] + vpand ymm12,ymm12,YMMWORD[$L$mask52x4] + + vmovdqu YMMWORD[rdi],ymm3 + vmovdqu YMMWORD[32+rdi],ymm5 + vmovdqu YMMWORD[64+rdi],ymm6 + vmovdqu YMMWORD[96+rdi],ymm7 + vmovdqu YMMWORD[128+rdi],ymm8 + + vmovdqu YMMWORD[160+rdi],ymm4 + vmovdqu YMMWORD[192+rdi],ymm9 + vmovdqu YMMWORD[224+rdi],ymm10 + vmovdqu YMMWORD[256+rdi],ymm11 + vmovdqu YMMWORD[288+rdi],ymm12 + + vzeroupper + vmovapd xmm6,XMMWORD[rsp] + vmovapd xmm7,XMMWORD[16+rsp] + vmovapd xmm8,XMMWORD[32+rsp] + vmovapd xmm9,XMMWORD[48+rsp] + vmovapd xmm10,XMMWORD[64+rsp] + vmovapd xmm11,XMMWORD[80+rsp] + vmovapd xmm12,XMMWORD[96+rsp] + vmovapd xmm13,XMMWORD[112+rsp] + vmovapd xmm14,XMMWORD[128+rsp] + vmovapd xmm15,XMMWORD[144+rsp] + lea rsp,[168+rsp] + pop rdi + pop rsi + mov r15,QWORD[rsp] + + mov r14,QWORD[8+rsp] + + mov r13,QWORD[16+rsp] + + mov r12,QWORD[24+rsp] + + mov rbp,QWORD[32+rsp] + + mov rbx,QWORD[40+rsp] + + lea rsp,[48+rsp] + +$L$ossl_rsaz_amm52x20_x2_avxifma256_epilogue: + mov rdi,QWORD[8+rsp] ;WIN64 epilogue + mov rsi,QWORD[16+rsp] + DB 0F3h,0C3h ;repret + +$L$SEH_end_ossl_rsaz_amm52x20_x2_avxifma256: +section .text code align=64 + + +ALIGN 32 +global ossl_extract_multiplier_2x20_win5_avx + +ossl_extract_multiplier_2x20_win5_avx: + +DB 243,15,30,250 + push rsi + push rdi + lea rsp,[((-168))+rsp] + vmovapd XMMWORD[rsp],xmm6 + vmovapd XMMWORD[16+rsp],xmm7 + vmovapd XMMWORD[32+rsp],xmm8 + vmovapd XMMWORD[48+rsp],xmm9 + vmovapd XMMWORD[64+rsp],xmm10 + vmovapd XMMWORD[80+rsp],xmm11 + vmovapd XMMWORD[96+rsp],xmm12 + vmovapd XMMWORD[112+rsp],xmm13 + vmovapd XMMWORD[128+rsp],xmm14 + vmovapd XMMWORD[144+rsp],xmm15 + vmovapd ymm14,YMMWORD[$L$ones] + vmovq xmm10,r8 + vpbroadcastq ymm12,xmm10 + vmovq xmm10,r9 + vpbroadcastq ymm13,xmm10 + lea rax,[10240+rdx] + + + vpxor xmm0,xmm0,xmm0 + vmovapd ymm11,ymm0 + vmovapd ymm1,ymm0 + vmovapd ymm2,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + vmovapd ymm8,ymm0 + vmovapd ymm9,ymm0 + +ALIGN 32 +$L$loop: + vpcmpeqq ymm15,ymm12,ymm11 + vmovdqu ymm10,YMMWORD[rdx] + vblendvpd ymm0,ymm0,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[32+rdx] + vblendvpd ymm1,ymm1,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[64+rdx] + vblendvpd ymm2,ymm2,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[96+rdx] + vblendvpd ymm3,ymm3,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[128+rdx] + vblendvpd ymm4,ymm4,ymm10,ymm15 + vpcmpeqq ymm15,ymm13,ymm11 + vmovdqu ymm10,YMMWORD[160+rdx] + vblendvpd ymm5,ymm5,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[192+rdx] + vblendvpd ymm6,ymm6,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[224+rdx] + vblendvpd ymm7,ymm7,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[256+rdx] + vblendvpd ymm8,ymm8,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[288+rdx] + vblendvpd ymm9,ymm9,ymm10,ymm15 + vpaddq ymm11,ymm11,ymm14 + add rdx,320 + cmp rax,rdx + jne NEAR $L$loop + vmovdqu YMMWORD[rcx],ymm0 + vmovdqu YMMWORD[32+rcx],ymm1 + vmovdqu YMMWORD[64+rcx],ymm2 + vmovdqu YMMWORD[96+rcx],ymm3 + vmovdqu YMMWORD[128+rcx],ymm4 + vmovdqu YMMWORD[160+rcx],ymm5 + vmovdqu YMMWORD[192+rcx],ymm6 + vmovdqu YMMWORD[224+rcx],ymm7 + vmovdqu YMMWORD[256+rcx],ymm8 + vmovdqu YMMWORD[288+rcx],ymm9 + vzeroupper + vmovapd xmm6,XMMWORD[rsp] + vmovapd xmm7,XMMWORD[16+rsp] + vmovapd xmm8,XMMWORD[32+rsp] + vmovapd xmm9,XMMWORD[48+rsp] + vmovapd xmm10,XMMWORD[64+rsp] + vmovapd xmm11,XMMWORD[80+rsp] + vmovapd xmm12,XMMWORD[96+rsp] + vmovapd xmm13,XMMWORD[112+rsp] + vmovapd xmm14,XMMWORD[128+rsp] + vmovapd xmm15,XMMWORD[144+rsp] + lea rsp,[168+rsp] + pop rdi + pop rsi + DB 0F3h,0C3h ;repret + + +section .rdata rdata align=32 +ALIGN 32 +$L$ones: + DQ 1,1,1,1 +$L$zeros: + DQ 0,0,0,0 +EXTERN __imp_RtlVirtualUnwind + +ALIGN 16 +rsaz_def_handler: + push rsi + push rdi + push rbx + push rbp + push r12 + push r13 + push r14 + push r15 + pushfq + sub rsp,64 + + mov rax,QWORD[120+r8] + mov rbx,QWORD[248+r8] + + mov rsi,QWORD[8+r9] + mov r11,QWORD[56+r9] + + mov r10d,DWORD[r11] + lea r10,[r10*1+rsi] + cmp rbx,r10 + jb NEAR $L$common_seh_tail + + mov rax,QWORD[152+r8] + + mov r10d,DWORD[4+r11] + lea r10,[r10*1+rsi] + cmp rbx,r10 + jae NEAR $L$common_seh_tail + + lea rax,[48+rax] + + mov rbx,QWORD[((-8))+rax] + mov rbp,QWORD[((-16))+rax] + mov r12,QWORD[((-24))+rax] + mov r13,QWORD[((-32))+rax] + mov r14,QWORD[((-40))+rax] + mov r15,QWORD[((-48))+rax] + mov QWORD[144+r8],rbx + mov QWORD[160+r8],rbp + mov QWORD[216+r8],r12 + mov QWORD[224+r8],r13 + mov QWORD[232+r8],r14 + mov QWORD[240+r8],r15 + +$L$common_seh_tail: + mov rdi,QWORD[8+rax] + mov rsi,QWORD[16+rax] + mov QWORD[152+r8],rax + mov QWORD[168+r8],rsi + mov QWORD[176+r8],rdi + + mov rdi,QWORD[40+r9] + mov rsi,r8 + mov ecx,154 + DD 0xa548f3fc + + mov rsi,r9 + xor rcx,rcx + mov rdx,QWORD[8+rsi] + mov r8,QWORD[rsi] + mov r9,QWORD[16+rsi] + mov r10,QWORD[40+rsi] + lea r11,[56+rsi] + lea r12,[24+rsi] + mov QWORD[32+rsp],r10 + mov QWORD[40+rsp],r11 + mov QWORD[48+rsp],r12 + mov QWORD[56+rsp],rcx + call QWORD[__imp_RtlVirtualUnwind] + + mov eax,1 + add rsp,64 + popfq + pop r15 + pop r14 + pop r13 + pop r12 + pop rbp + pop rbx + pop rdi + pop rsi + DB 0F3h,0C3h ;repret + + +section .pdata rdata align=4 +ALIGN 4 + DD $L$SEH_begin_ossl_rsaz_amm52x20_x1_avxifma256 wrt ..imagebase + DD $L$SEH_end_ossl_rsaz_amm52x20_x1_avxifma256 wrt ..imagebase + DD $L$SEH_info_ossl_rsaz_amm52x20_x1_avxifma256 wrt ..imagebase + + DD $L$SEH_begin_ossl_rsaz_amm52x20_x2_avxifma256 wrt ..imagebase + DD $L$SEH_end_ossl_rsaz_amm52x20_x2_avxifma256 wrt ..imagebase + DD $L$SEH_info_ossl_rsaz_amm52x20_x2_avxifma256 wrt ..imagebase + +section .xdata rdata align=8 +ALIGN 8 +$L$SEH_info_ossl_rsaz_amm52x20_x1_avxifma256: +DB 9,0,0,0 + DD rsaz_def_handler wrt ..imagebase + DD $L$ossl_rsaz_amm52x20_x1_avxifma256_body wrt ..imagebase,$L$ossl_rsaz_amm52x20_x1_avxifma256_epilogue wrt ..imagebase +$L$SEH_info_ossl_rsaz_amm52x20_x2_avxifma256: +DB 9,0,0,0 + DD rsaz_def_handler wrt ..imagebase + DD $L$ossl_rsaz_amm52x20_x2_avxifma256_body wrt ..imagebase,$L$ossl_rsaz_amm52x20_x2_avxifma256_epilogue wrt ..imagebase diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-3k-avxifma.nasm b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-3k-avxifma.nasm index 082edb8030..b54c93683f 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-3k-avxifma.nasm +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-3k-avxifma.nasm @@ -6,12 +6,1949 @@ section .text code align=64 global ossl_rsaz_amm52x30_x1_avxifma256 -global ossl_rsaz_amm52x30_x2_avxifma256 -global ossl_extract_multiplier_2x30_win5_avx +ALIGN 32 ossl_rsaz_amm52x30_x1_avxifma256: -ossl_rsaz_amm52x30_x2_avxifma256: -ossl_extract_multiplier_2x30_win5_avx: -DB 0x0f,0x0b + mov QWORD[8+rsp],rdi ;WIN64 prologue + mov QWORD[16+rsp],rsi + mov rax,rsp +$L$SEH_begin_ossl_rsaz_amm52x30_x1_avxifma256: + mov rdi,rcx + mov rsi,rdx + mov rdx,r8 + mov rcx,r9 + mov r8,QWORD[40+rsp] + + + +DB 243,15,30,250 + push rbx + + push rbp + + push r12 + + push r13 + + push r14 + + push r15 + + lea rsp,[((-168))+rsp] + vmovapd XMMWORD[rsp],xmm6 + vmovapd XMMWORD[16+rsp],xmm7 + vmovapd XMMWORD[32+rsp],xmm8 + vmovapd XMMWORD[48+rsp],xmm9 + vmovapd XMMWORD[64+rsp],xmm10 + vmovapd XMMWORD[80+rsp],xmm11 + vmovapd XMMWORD[96+rsp],xmm12 + vmovapd XMMWORD[112+rsp],xmm13 + vmovapd XMMWORD[128+rsp],xmm14 + vmovapd XMMWORD[144+rsp],xmm15 +$L$ossl_rsaz_amm52x30_x1_avxifma256_body: + + vpxor ymm0,ymm0,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + vmovapd ymm8,ymm0 + vmovapd ymm9,ymm0 + vmovapd ymm10,ymm0 + + xor r9d,r9d + + mov r11,rdx + mov rax,0xfffffffffffff + + + mov ebx,7 + +ALIGN 32 +$L$loop7: + mov r13,QWORD[r11] + + vpbroadcastq ymm1,QWORD[r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-264))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + mov QWORD[256+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] + + lea rsp,[264+rsp] + mov r13,QWORD[8+r11] + + vpbroadcastq ymm1,QWORD[8+r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-264))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + mov QWORD[256+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] + + lea rsp,[264+rsp] + mov r13,QWORD[16+r11] + + vpbroadcastq ymm1,QWORD[16+r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-264))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + mov QWORD[256+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] + + lea rsp,[264+rsp] + mov r13,QWORD[24+r11] + + vpbroadcastq ymm1,QWORD[24+r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-264))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + mov QWORD[256+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] + + lea rsp,[264+rsp] + lea r11,[32+r11] + dec ebx + jne NEAR $L$loop7 + mov r13,QWORD[r11] + + vpbroadcastq ymm1,QWORD[r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-264))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + mov QWORD[256+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] + + lea rsp,[264+rsp] + mov r13,QWORD[8+r11] + + vpbroadcastq ymm1,QWORD[8+r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-264))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + mov QWORD[256+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] + + lea rsp,[264+rsp] + + vmovq xmm0,r9 + vpbroadcastq ymm0,xmm0 + vpblendd ymm3,ymm3,ymm0,3 + + + + vpsrlq ymm0,ymm3,52 + vpsrlq ymm1,ymm4,52 + vpsrlq ymm2,ymm5,52 + vpsrlq ymm11,ymm6,52 + vpsrlq ymm12,ymm7,52 + vpsrlq ymm13,ymm8,52 + vpsrlq ymm14,ymm9,52 + vpsrlq ymm15,ymm10,52 + + lea rsp,[((-32))+rsp] + vmovupd YMMWORD[rsp],ymm3 + + + vpermq ymm15,ymm15,144 + vpermq ymm3,ymm14,3 + vblendpd ymm15,ymm15,ymm3,1 + + vpermq ymm14,ymm14,144 + vpermq ymm3,ymm13,3 + vblendpd ymm14,ymm14,ymm3,1 + + vpermq ymm13,ymm13,144 + vpermq ymm3,ymm12,3 + vblendpd ymm13,ymm13,ymm3,1 + + vpermq ymm12,ymm12,144 + vpermq ymm3,ymm11,3 + vblendpd ymm12,ymm12,ymm3,1 + + vpermq ymm11,ymm11,144 + vpermq ymm3,ymm2,3 + vblendpd ymm11,ymm11,ymm3,1 + + vpermq ymm2,ymm2,144 + vpermq ymm3,ymm1,3 + vblendpd ymm2,ymm2,ymm3,1 + + vpermq ymm1,ymm1,144 + vpermq ymm3,ymm0,3 + vblendpd ymm1,ymm1,ymm3,1 + + vpermq ymm0,ymm0,144 + vpand ymm0,ymm0,YMMWORD[$L$high64x3] + + vmovupd ymm3,YMMWORD[rsp] + lea rsp,[32+rsp] + + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + + + vpaddq ymm3,ymm3,ymm0 + vpaddq ymm4,ymm4,ymm1 + vpaddq ymm5,ymm5,ymm2 + vpaddq ymm6,ymm6,ymm11 + vpaddq ymm7,ymm7,ymm12 + vpaddq ymm8,ymm8,ymm13 + vpaddq ymm9,ymm9,ymm14 + vpaddq ymm10,ymm10,ymm15 + + + + vpcmpgtq ymm0,ymm3,YMMWORD[$L$mask52x4] + vpcmpgtq ymm1,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r14d,ymm0 + vmovmskpd r13d,ymm1 + shl r13b,4 + or r14b,r13b + + vpcmpgtq ymm2,ymm5,YMMWORD[$L$mask52x4] + vpcmpgtq ymm11,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd r13d,ymm2 + vmovmskpd r12d,ymm11 + shl r12b,4 + or r13b,r12b + + vpcmpgtq ymm12,ymm7,YMMWORD[$L$mask52x4] + vpcmpgtq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd r12d,ymm12 + vmovmskpd r11d,ymm13 + shl r11b,4 + or r12b,r11b + + vpcmpgtq ymm14,ymm9,YMMWORD[$L$mask52x4] + vpcmpgtq ymm15,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd r11d,ymm14 + vmovmskpd r10d,ymm15 + shl r10b,4 + or r11b,r10b + + add r14b,r14b + adc r13b,r13b + adc r12b,r12b + adc r11b,r11b + + + vpcmpeqq ymm0,ymm3,YMMWORD[$L$mask52x4] + vpcmpeqq ymm1,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm0 + vmovmskpd r8d,ymm1 + shl r8b,4 + or r9b,r8b + + vpcmpeqq ymm2,ymm5,YMMWORD[$L$mask52x4] + vpcmpeqq ymm11,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd r8d,ymm2 + vmovmskpd edx,ymm11 + shl dl,4 + or r8b,dl + + vpcmpeqq ymm12,ymm7,YMMWORD[$L$mask52x4] + vpcmpeqq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd edx,ymm12 + vmovmskpd ecx,ymm13 + shl cl,4 + or dl,cl + + vpcmpeqq ymm14,ymm9,YMMWORD[$L$mask52x4] + vpcmpeqq ymm15,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd ecx,ymm14 + vmovmskpd ebx,ymm15 + shl bl,4 + or cl,bl + + add r14b,r9b + adc r13b,r8b + adc r12b,dl + adc r11b,cl + + xor r14b,r9b + xor r13b,r8b + xor r12b,dl + xor r11b,cl + + lea rdx,[$L$kmasklut] + + mov r10b,r14b + and r14,0xf + vpsubq ymm0,ymm3,YMMWORD[$L$mask52x4] + shl r14,5 + vmovapd ymm2,YMMWORD[r14*1+rdx] + vblendvpd ymm3,ymm3,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm4,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm4,ymm4,ymm0,ymm2 + + mov r10b,r13b + and r13,0xf + vpsubq ymm0,ymm5,YMMWORD[$L$mask52x4] + shl r13,5 + vmovapd ymm2,YMMWORD[r13*1+rdx] + vblendvpd ymm5,ymm5,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm6,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm6,ymm6,ymm0,ymm2 + + mov r10b,r12b + and r12,0xf + vpsubq ymm0,ymm7,YMMWORD[$L$mask52x4] + shl r12,5 + vmovapd ymm2,YMMWORD[r12*1+rdx] + vblendvpd ymm7,ymm7,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm8,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm8,ymm8,ymm0,ymm2 + + mov r10b,r11b + and r11,0xf + vpsubq ymm0,ymm9,YMMWORD[$L$mask52x4] + shl r11,5 + vmovapd ymm2,YMMWORD[r11*1+rdx] + vblendvpd ymm9,ymm9,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm10,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm10,ymm10,ymm0,ymm2 + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + + vmovdqu YMMWORD[rdi],ymm3 + vmovdqu YMMWORD[32+rdi],ymm4 + vmovdqu YMMWORD[64+rdi],ymm5 + vmovdqu YMMWORD[96+rdi],ymm6 + vmovdqu YMMWORD[128+rdi],ymm7 + vmovdqu YMMWORD[160+rdi],ymm8 + vmovdqu YMMWORD[192+rdi],ymm9 + vmovdqu YMMWORD[224+rdi],ymm10 + + vzeroupper + lea rax,[rsp] + + vmovapd xmm6,XMMWORD[rax] + vmovapd xmm7,XMMWORD[16+rax] + vmovapd xmm8,XMMWORD[32+rax] + vmovapd xmm9,XMMWORD[48+rax] + vmovapd xmm10,XMMWORD[64+rax] + vmovapd xmm11,XMMWORD[80+rax] + vmovapd xmm12,XMMWORD[96+rax] + vmovapd xmm13,XMMWORD[112+rax] + vmovapd xmm14,XMMWORD[128+rax] + vmovapd xmm15,XMMWORD[144+rax] + lea rax,[168+rsp] + mov r15,QWORD[rax] + + mov r14,QWORD[8+rax] + + mov r13,QWORD[16+rax] + + mov r12,QWORD[24+rax] + + mov rbp,QWORD[32+rax] + + mov rbx,QWORD[40+rax] + + lea rsp,[48+rax] + +$L$ossl_rsaz_amm52x30_x1_avxifma256_epilogue: + mov rdi,QWORD[8+rsp] ;WIN64 epilogue + mov rsi,QWORD[16+rsp] DB 0F3h,0C3h ;repret +$L$SEH_end_ossl_rsaz_amm52x30_x1_avxifma256: +section .rdata rdata align=32 +ALIGN 32 +$L$mask52x4: + DQ 0xfffffffffffff + DQ 0xfffffffffffff + DQ 0xfffffffffffff + DQ 0xfffffffffffff +$L$high64x3: + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff +$L$kmasklut: + + DQ 0x0 + DQ 0x0 + DQ 0x0 + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + DQ 0x0 + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0x0 + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff +section .text code align=64 + + +global ossl_rsaz_amm52x30_x2_avxifma256 + +ALIGN 32 +ossl_rsaz_amm52x30_x2_avxifma256: + mov QWORD[8+rsp],rdi ;WIN64 prologue + mov QWORD[16+rsp],rsi + mov rax,rsp +$L$SEH_begin_ossl_rsaz_amm52x30_x2_avxifma256: + mov rdi,rcx + mov rsi,rdx + mov rdx,r8 + mov rcx,r9 + mov r8,QWORD[40+rsp] + + + +DB 243,15,30,250 + push rbx + + push rbp + + push r12 + + push r13 + + push r14 + + push r15 + + lea rsp,[((-168))+rsp] + vmovapd XMMWORD[rsp],xmm6 + vmovapd XMMWORD[16+rsp],xmm7 + vmovapd XMMWORD[32+rsp],xmm8 + vmovapd XMMWORD[48+rsp],xmm9 + vmovapd XMMWORD[64+rsp],xmm10 + vmovapd XMMWORD[80+rsp],xmm11 + vmovapd XMMWORD[96+rsp],xmm12 + vmovapd XMMWORD[112+rsp],xmm13 + vmovapd XMMWORD[128+rsp],xmm14 + vmovapd XMMWORD[144+rsp],xmm15 +$L$ossl_rsaz_amm52x30_x2_avxifma256_body: + + vpxor ymm0,ymm0,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + vmovapd ymm8,ymm0 + vmovapd ymm9,ymm0 + vmovapd ymm10,ymm0 + + xor r9d,r9d + + mov r11,rdx + mov rax,0xfffffffffffff + + mov ebx,30 + +ALIGN 32 +$L$loop30: + mov r13,QWORD[r11] + + vpbroadcastq ymm1,QWORD[r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,QWORD[r8] + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-264))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + mov QWORD[256+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] + + lea rsp,[264+rsp] + lea r11,[8+r11] + dec ebx + jne NEAR $L$loop30 + + push r11 + push rsi + push rcx + push r8 + + vmovq xmm0,r9 + vpbroadcastq ymm0,xmm0 + vpblendd ymm3,ymm3,ymm0,3 + + + + vpsrlq ymm0,ymm3,52 + vpsrlq ymm1,ymm4,52 + vpsrlq ymm2,ymm5,52 + vpsrlq ymm11,ymm6,52 + vpsrlq ymm12,ymm7,52 + vpsrlq ymm13,ymm8,52 + vpsrlq ymm14,ymm9,52 + vpsrlq ymm15,ymm10,52 + + lea rsp,[((-32))+rsp] + vmovupd YMMWORD[rsp],ymm3 + + + vpermq ymm15,ymm15,144 + vpermq ymm3,ymm14,3 + vblendpd ymm15,ymm15,ymm3,1 + + vpermq ymm14,ymm14,144 + vpermq ymm3,ymm13,3 + vblendpd ymm14,ymm14,ymm3,1 + + vpermq ymm13,ymm13,144 + vpermq ymm3,ymm12,3 + vblendpd ymm13,ymm13,ymm3,1 + + vpermq ymm12,ymm12,144 + vpermq ymm3,ymm11,3 + vblendpd ymm12,ymm12,ymm3,1 + + vpermq ymm11,ymm11,144 + vpermq ymm3,ymm2,3 + vblendpd ymm11,ymm11,ymm3,1 + + vpermq ymm2,ymm2,144 + vpermq ymm3,ymm1,3 + vblendpd ymm2,ymm2,ymm3,1 + + vpermq ymm1,ymm1,144 + vpermq ymm3,ymm0,3 + vblendpd ymm1,ymm1,ymm3,1 + + vpermq ymm0,ymm0,144 + vpand ymm0,ymm0,YMMWORD[$L$high64x3] + + vmovupd ymm3,YMMWORD[rsp] + lea rsp,[32+rsp] + + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + + + vpaddq ymm3,ymm3,ymm0 + vpaddq ymm4,ymm4,ymm1 + vpaddq ymm5,ymm5,ymm2 + vpaddq ymm6,ymm6,ymm11 + vpaddq ymm7,ymm7,ymm12 + vpaddq ymm8,ymm8,ymm13 + vpaddq ymm9,ymm9,ymm14 + vpaddq ymm10,ymm10,ymm15 + + + + vpcmpgtq ymm0,ymm3,YMMWORD[$L$mask52x4] + vpcmpgtq ymm1,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r14d,ymm0 + vmovmskpd r13d,ymm1 + shl r13b,4 + or r14b,r13b + + vpcmpgtq ymm2,ymm5,YMMWORD[$L$mask52x4] + vpcmpgtq ymm11,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd r13d,ymm2 + vmovmskpd r12d,ymm11 + shl r12b,4 + or r13b,r12b + + vpcmpgtq ymm12,ymm7,YMMWORD[$L$mask52x4] + vpcmpgtq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd r12d,ymm12 + vmovmskpd r11d,ymm13 + shl r11b,4 + or r12b,r11b + + vpcmpgtq ymm14,ymm9,YMMWORD[$L$mask52x4] + vpcmpgtq ymm15,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd r11d,ymm14 + vmovmskpd r10d,ymm15 + shl r10b,4 + or r11b,r10b + + add r14b,r14b + adc r13b,r13b + adc r12b,r12b + adc r11b,r11b + + + vpcmpeqq ymm0,ymm3,YMMWORD[$L$mask52x4] + vpcmpeqq ymm1,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm0 + vmovmskpd r8d,ymm1 + shl r8b,4 + or r9b,r8b + + vpcmpeqq ymm2,ymm5,YMMWORD[$L$mask52x4] + vpcmpeqq ymm11,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd r8d,ymm2 + vmovmskpd edx,ymm11 + shl dl,4 + or r8b,dl + + vpcmpeqq ymm12,ymm7,YMMWORD[$L$mask52x4] + vpcmpeqq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd edx,ymm12 + vmovmskpd ecx,ymm13 + shl cl,4 + or dl,cl + + vpcmpeqq ymm14,ymm9,YMMWORD[$L$mask52x4] + vpcmpeqq ymm15,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd ecx,ymm14 + vmovmskpd ebx,ymm15 + shl bl,4 + or cl,bl + + add r14b,r9b + adc r13b,r8b + adc r12b,dl + adc r11b,cl + + xor r14b,r9b + xor r13b,r8b + xor r12b,dl + xor r11b,cl + + lea rdx,[$L$kmasklut] + + mov r10b,r14b + and r14,0xf + vpsubq ymm0,ymm3,YMMWORD[$L$mask52x4] + shl r14,5 + vmovapd ymm2,YMMWORD[r14*1+rdx] + vblendvpd ymm3,ymm3,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm4,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm4,ymm4,ymm0,ymm2 + + mov r10b,r13b + and r13,0xf + vpsubq ymm0,ymm5,YMMWORD[$L$mask52x4] + shl r13,5 + vmovapd ymm2,YMMWORD[r13*1+rdx] + vblendvpd ymm5,ymm5,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm6,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm6,ymm6,ymm0,ymm2 + + mov r10b,r12b + and r12,0xf + vpsubq ymm0,ymm7,YMMWORD[$L$mask52x4] + shl r12,5 + vmovapd ymm2,YMMWORD[r12*1+rdx] + vblendvpd ymm7,ymm7,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm8,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm8,ymm8,ymm0,ymm2 + + mov r10b,r11b + and r11,0xf + vpsubq ymm0,ymm9,YMMWORD[$L$mask52x4] + shl r11,5 + vmovapd ymm2,YMMWORD[r11*1+rdx] + vblendvpd ymm9,ymm9,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm10,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm10,ymm10,ymm0,ymm2 + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + pop r8 + pop rcx + pop rsi + pop r11 + + vmovdqu YMMWORD[rdi],ymm3 + vmovdqu YMMWORD[32+rdi],ymm4 + vmovdqu YMMWORD[64+rdi],ymm5 + vmovdqu YMMWORD[96+rdi],ymm6 + vmovdqu YMMWORD[128+rdi],ymm7 + vmovdqu YMMWORD[160+rdi],ymm8 + vmovdqu YMMWORD[192+rdi],ymm9 + vmovdqu YMMWORD[224+rdi],ymm10 + + xor r9d,r9d + + lea r11,[16+r11] + mov rax,0xfffffffffffff + + mov ebx,30 + + vpxor ymm0,ymm0,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + vmovapd ymm8,ymm0 + vmovapd ymm9,ymm0 + vmovapd ymm10,ymm0 +ALIGN 32 +$L$loop40: + mov r13,QWORD[r11] + + vpbroadcastq ymm1,QWORD[r11] + mov rdx,QWORD[256+rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,QWORD[8+r8] + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[256+rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-264))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[288+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[320+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[352+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[384+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[416+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[448+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[480+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[288+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[320+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[352+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[384+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[416+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[448+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[480+rcx] + + + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + mov QWORD[256+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[288+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[320+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[352+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[384+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[416+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[448+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[480+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[288+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[320+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[352+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[384+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[416+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[448+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[480+rcx] + + lea rsp,[264+rsp] + lea r11,[8+r11] + dec ebx + jne NEAR $L$loop40 + + vmovq xmm0,r9 + vpbroadcastq ymm0,xmm0 + vpblendd ymm3,ymm3,ymm0,3 + + + + vpsrlq ymm0,ymm3,52 + vpsrlq ymm1,ymm4,52 + vpsrlq ymm2,ymm5,52 + vpsrlq ymm11,ymm6,52 + vpsrlq ymm12,ymm7,52 + vpsrlq ymm13,ymm8,52 + vpsrlq ymm14,ymm9,52 + vpsrlq ymm15,ymm10,52 + + lea rsp,[((-32))+rsp] + vmovupd YMMWORD[rsp],ymm3 + + + vpermq ymm15,ymm15,144 + vpermq ymm3,ymm14,3 + vblendpd ymm15,ymm15,ymm3,1 + + vpermq ymm14,ymm14,144 + vpermq ymm3,ymm13,3 + vblendpd ymm14,ymm14,ymm3,1 + + vpermq ymm13,ymm13,144 + vpermq ymm3,ymm12,3 + vblendpd ymm13,ymm13,ymm3,1 + + vpermq ymm12,ymm12,144 + vpermq ymm3,ymm11,3 + vblendpd ymm12,ymm12,ymm3,1 + + vpermq ymm11,ymm11,144 + vpermq ymm3,ymm2,3 + vblendpd ymm11,ymm11,ymm3,1 + + vpermq ymm2,ymm2,144 + vpermq ymm3,ymm1,3 + vblendpd ymm2,ymm2,ymm3,1 + + vpermq ymm1,ymm1,144 + vpermq ymm3,ymm0,3 + vblendpd ymm1,ymm1,ymm3,1 + + vpermq ymm0,ymm0,144 + vpand ymm0,ymm0,YMMWORD[$L$high64x3] + + vmovupd ymm3,YMMWORD[rsp] + lea rsp,[32+rsp] + + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + + + vpaddq ymm3,ymm3,ymm0 + vpaddq ymm4,ymm4,ymm1 + vpaddq ymm5,ymm5,ymm2 + vpaddq ymm6,ymm6,ymm11 + vpaddq ymm7,ymm7,ymm12 + vpaddq ymm8,ymm8,ymm13 + vpaddq ymm9,ymm9,ymm14 + vpaddq ymm10,ymm10,ymm15 + + + + vpcmpgtq ymm0,ymm3,YMMWORD[$L$mask52x4] + vpcmpgtq ymm1,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r14d,ymm0 + vmovmskpd r13d,ymm1 + shl r13b,4 + or r14b,r13b + + vpcmpgtq ymm2,ymm5,YMMWORD[$L$mask52x4] + vpcmpgtq ymm11,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd r13d,ymm2 + vmovmskpd r12d,ymm11 + shl r12b,4 + or r13b,r12b + + vpcmpgtq ymm12,ymm7,YMMWORD[$L$mask52x4] + vpcmpgtq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd r12d,ymm12 + vmovmskpd r11d,ymm13 + shl r11b,4 + or r12b,r11b + + vpcmpgtq ymm14,ymm9,YMMWORD[$L$mask52x4] + vpcmpgtq ymm15,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd r11d,ymm14 + vmovmskpd r10d,ymm15 + shl r10b,4 + or r11b,r10b + + add r14b,r14b + adc r13b,r13b + adc r12b,r12b + adc r11b,r11b + + + vpcmpeqq ymm0,ymm3,YMMWORD[$L$mask52x4] + vpcmpeqq ymm1,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm0 + vmovmskpd r8d,ymm1 + shl r8b,4 + or r9b,r8b + + vpcmpeqq ymm2,ymm5,YMMWORD[$L$mask52x4] + vpcmpeqq ymm11,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd r8d,ymm2 + vmovmskpd edx,ymm11 + shl dl,4 + or r8b,dl + + vpcmpeqq ymm12,ymm7,YMMWORD[$L$mask52x4] + vpcmpeqq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd edx,ymm12 + vmovmskpd ecx,ymm13 + shl cl,4 + or dl,cl + + vpcmpeqq ymm14,ymm9,YMMWORD[$L$mask52x4] + vpcmpeqq ymm15,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd ecx,ymm14 + vmovmskpd ebx,ymm15 + shl bl,4 + or cl,bl + + add r14b,r9b + adc r13b,r8b + adc r12b,dl + adc r11b,cl + + xor r14b,r9b + xor r13b,r8b + xor r12b,dl + xor r11b,cl + + lea rdx,[$L$kmasklut] + + mov r10b,r14b + and r14,0xf + vpsubq ymm0,ymm3,YMMWORD[$L$mask52x4] + shl r14,5 + vmovapd ymm2,YMMWORD[r14*1+rdx] + vblendvpd ymm3,ymm3,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm4,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm4,ymm4,ymm0,ymm2 + + mov r10b,r13b + and r13,0xf + vpsubq ymm0,ymm5,YMMWORD[$L$mask52x4] + shl r13,5 + vmovapd ymm2,YMMWORD[r13*1+rdx] + vblendvpd ymm5,ymm5,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm6,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm6,ymm6,ymm0,ymm2 + + mov r10b,r12b + and r12,0xf + vpsubq ymm0,ymm7,YMMWORD[$L$mask52x4] + shl r12,5 + vmovapd ymm2,YMMWORD[r12*1+rdx] + vblendvpd ymm7,ymm7,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm8,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm8,ymm8,ymm0,ymm2 + + mov r10b,r11b + and r11,0xf + vpsubq ymm0,ymm9,YMMWORD[$L$mask52x4] + shl r11,5 + vmovapd ymm2,YMMWORD[r11*1+rdx] + vblendvpd ymm9,ymm9,ymm0,ymm2 + + shr r10b,4 + and r10,0xf + vpsubq ymm0,ymm10,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm2,YMMWORD[r10*1+rdx] + vblendvpd ymm10,ymm10,ymm0,ymm2 + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + + vmovdqu YMMWORD[256+rdi],ymm3 + vmovdqu YMMWORD[288+rdi],ymm4 + vmovdqu YMMWORD[320+rdi],ymm5 + vmovdqu YMMWORD[352+rdi],ymm6 + vmovdqu YMMWORD[384+rdi],ymm7 + vmovdqu YMMWORD[416+rdi],ymm8 + vmovdqu YMMWORD[448+rdi],ymm9 + vmovdqu YMMWORD[480+rdi],ymm10 + + vzeroupper + lea rax,[rsp] + + vmovapd xmm6,XMMWORD[rax] + vmovapd xmm7,XMMWORD[16+rax] + vmovapd xmm8,XMMWORD[32+rax] + vmovapd xmm9,XMMWORD[48+rax] + vmovapd xmm10,XMMWORD[64+rax] + vmovapd xmm11,XMMWORD[80+rax] + vmovapd xmm12,XMMWORD[96+rax] + vmovapd xmm13,XMMWORD[112+rax] + vmovapd xmm14,XMMWORD[128+rax] + vmovapd xmm15,XMMWORD[144+rax] + lea rax,[168+rsp] + mov r15,QWORD[rax] + + mov r14,QWORD[8+rax] + + mov r13,QWORD[16+rax] + + mov r12,QWORD[24+rax] + + mov rbp,QWORD[32+rax] + + mov rbx,QWORD[40+rax] + + lea rsp,[48+rax] + +$L$ossl_rsaz_amm52x30_x2_avxifma256_epilogue: + mov rdi,QWORD[8+rsp] ;WIN64 epilogue + mov rsi,QWORD[16+rsp] + DB 0F3h,0C3h ;repret + +$L$SEH_end_ossl_rsaz_amm52x30_x2_avxifma256: +section .text code align=64 + + +ALIGN 32 +global ossl_extract_multiplier_2x30_win5_avx + +ossl_extract_multiplier_2x30_win5_avx: + +DB 243,15,30,250 + push rsi + push rdi + lea rsp,[((-168))+rsp] + vmovapd XMMWORD[rsp],xmm6 + vmovapd XMMWORD[16+rsp],xmm7 + vmovapd XMMWORD[32+rsp],xmm8 + vmovapd XMMWORD[48+rsp],xmm9 + vmovapd XMMWORD[64+rsp],xmm10 + vmovapd XMMWORD[80+rsp],xmm11 + vmovapd XMMWORD[96+rsp],xmm12 + vmovapd XMMWORD[112+rsp],xmm13 + vmovapd XMMWORD[128+rsp],xmm14 + vmovapd XMMWORD[144+rsp],xmm15 + vmovapd ymm12,YMMWORD[$L$ones] + vmovq xmm8,r8 + vpbroadcastq ymm10,xmm8 + vmovq xmm8,r9 + vpbroadcastq ymm11,xmm8 + lea rax,[16384+rdx] + + + vpxor xmm0,xmm0,xmm0 + vmovapd ymm9,ymm0 + vmovapd ymm1,ymm0 + vmovapd ymm2,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + +ALIGN 32 +$L$loop: + vpcmpeqq ymm13,ymm10,ymm9 + vmovdqu ymm8,YMMWORD[rdx] + + vblendvpd ymm0,ymm0,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[32+rdx] + + vblendvpd ymm1,ymm1,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[64+rdx] + + vblendvpd ymm2,ymm2,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[96+rdx] + + vblendvpd ymm3,ymm3,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[128+rdx] + + vblendvpd ymm4,ymm4,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[160+rdx] + + vblendvpd ymm5,ymm5,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[192+rdx] + + vblendvpd ymm6,ymm6,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[224+rdx] + + vblendvpd ymm7,ymm7,ymm8,ymm13 + vpaddq ymm9,ymm9,ymm12 + add rdx,512 + cmp rax,rdx + jne NEAR $L$loop + vmovdqu YMMWORD[rcx],ymm0 + vmovdqu YMMWORD[32+rcx],ymm1 + vmovdqu YMMWORD[64+rcx],ymm2 + vmovdqu YMMWORD[96+rcx],ymm3 + vmovdqu YMMWORD[128+rcx],ymm4 + vmovdqu YMMWORD[160+rcx],ymm5 + vmovdqu YMMWORD[192+rcx],ymm6 + vmovdqu YMMWORD[224+rcx],ymm7 + lea rdx,[((-16384))+rax] + + + vpxor xmm0,xmm0,xmm0 + vmovapd ymm9,ymm0 + vmovapd ymm0,ymm0 + vmovapd ymm1,ymm0 + vmovapd ymm2,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + +ALIGN 32 +$L$loop_8_15: + vpcmpeqq ymm13,ymm11,ymm9 + vmovdqu ymm8,YMMWORD[256+rdx] + + vblendvpd ymm0,ymm0,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[288+rdx] + + vblendvpd ymm1,ymm1,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[320+rdx] + + vblendvpd ymm2,ymm2,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[352+rdx] + + vblendvpd ymm3,ymm3,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[384+rdx] + + vblendvpd ymm4,ymm4,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[416+rdx] + + vblendvpd ymm5,ymm5,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[448+rdx] + + vblendvpd ymm6,ymm6,ymm8,ymm13 + vmovdqu ymm8,YMMWORD[480+rdx] + + vblendvpd ymm7,ymm7,ymm8,ymm13 + vpaddq ymm9,ymm9,ymm12 + add rdx,512 + cmp rax,rdx + jne NEAR $L$loop_8_15 + vmovdqu YMMWORD[256+rcx],ymm0 + vmovdqu YMMWORD[288+rcx],ymm1 + vmovdqu YMMWORD[320+rcx],ymm2 + vmovdqu YMMWORD[352+rcx],ymm3 + vmovdqu YMMWORD[384+rcx],ymm4 + vmovdqu YMMWORD[416+rcx],ymm5 + vmovdqu YMMWORD[448+rcx],ymm6 + vmovdqu YMMWORD[480+rcx],ymm7 + vzeroupper + vmovapd xmm6,XMMWORD[rsp] + vmovapd xmm7,XMMWORD[16+rsp] + vmovapd xmm8,XMMWORD[32+rsp] + vmovapd xmm9,XMMWORD[48+rsp] + vmovapd xmm10,XMMWORD[64+rsp] + vmovapd xmm11,XMMWORD[80+rsp] + vmovapd xmm12,XMMWORD[96+rsp] + vmovapd xmm13,XMMWORD[112+rsp] + vmovapd xmm14,XMMWORD[128+rsp] + vmovapd xmm15,XMMWORD[144+rsp] + lea rsp,[168+rsp] + pop rdi + pop rsi + + DB 0F3h,0C3h ;repret + + +section .rdata rdata align=32 +ALIGN 32 +$L$ones: + DQ 1,1,1,1 +$L$zeros: + DQ 0,0,0,0 +EXTERN __imp_RtlVirtualUnwind + +ALIGN 16 +rsaz_avx_handler: + push rsi + push rdi + push rbx + push rbp + push r12 + push r13 + push r14 + push r15 + pushfq + sub rsp,64 + + mov rax,QWORD[120+r8] + mov rbx,QWORD[248+r8] + + mov rsi,QWORD[8+r9] + mov r11,QWORD[56+r9] + + mov r10d,DWORD[r11] + lea r10,[r10*1+rsi] + cmp rbx,r10 + jb NEAR $L$common_seh_tail + + mov r10d,DWORD[4+r11] + lea r10,[r10*1+rsi] + cmp rbx,r10 + jae NEAR $L$common_seh_tail + + mov rax,QWORD[152+r8] + + lea rsi,[rax] + lea rdi,[512+r8] + mov ecx,20 + DD 0xa548f3fc + + lea rax,[216+rax] + + mov rbx,QWORD[((-8))+rax] + mov rbp,QWORD[((-16))+rax] + mov r12,QWORD[((-24))+rax] + mov r13,QWORD[((-32))+rax] + mov r14,QWORD[((-40))+rax] + mov r15,QWORD[((-48))+rax] + mov QWORD[144+r8],rbx + mov QWORD[160+r8],rbp + mov QWORD[216+r8],r12 + mov QWORD[224+r8],r13 + mov QWORD[232+r8],r14 + mov QWORD[240+r8],r15 + +$L$common_seh_tail: + mov rdi,QWORD[8+rax] + mov rsi,QWORD[16+rax] + mov QWORD[152+r8],rax + mov QWORD[168+r8],rsi + mov QWORD[176+r8],rdi + + mov rdi,QWORD[40+r9] + mov rsi,r8 + mov ecx,154 + DD 0xa548f3fc + + mov rsi,r9 + xor rcx,rcx + mov rdx,QWORD[8+rsi] + mov r8,QWORD[rsi] + mov r9,QWORD[16+rsi] + mov r10,QWORD[40+rsi] + lea r11,[56+rsi] + lea r12,[24+rsi] + mov QWORD[32+rsp],r10 + mov QWORD[40+rsp],r11 + mov QWORD[48+rsp],r12 + mov QWORD[56+rsp],rcx + call QWORD[__imp_RtlVirtualUnwind] + + mov eax,1 + add rsp,64 + popfq + pop r15 + pop r14 + pop r13 + pop r12 + pop rbp + pop rbx + pop rdi + pop rsi + DB 0F3h,0C3h ;repret + + +section .pdata rdata align=4 +ALIGN 4 + DD $L$SEH_begin_ossl_rsaz_amm52x30_x1_avxifma256 wrt ..imagebase + DD $L$SEH_end_ossl_rsaz_amm52x30_x1_avxifma256 wrt ..imagebase + DD $L$SEH_info_ossl_rsaz_amm52x30_x1_avxifma256 wrt ..imagebase + + DD $L$SEH_begin_ossl_rsaz_amm52x30_x2_avxifma256 wrt ..imagebase + DD $L$SEH_end_ossl_rsaz_amm52x30_x2_avxifma256 wrt ..imagebase + DD $L$SEH_info_ossl_rsaz_amm52x30_x2_avxifma256 wrt ..imagebase + +section .xdata rdata align=8 +ALIGN 8 +$L$SEH_info_ossl_rsaz_amm52x30_x1_avxifma256: +DB 9,0,0,0 + DD rsaz_avx_handler wrt ..imagebase + DD $L$ossl_rsaz_amm52x30_x1_avxifma256_body wrt ..imagebase,$L$ossl_rsaz_amm52x30_x1_avxifma256_epilogue wrt ..imagebase +$L$SEH_info_ossl_rsaz_amm52x30_x2_avxifma256: +DB 9,0,0,0 + DD rsaz_avx_handler wrt ..imagebase + DD $L$ossl_rsaz_amm52x30_x2_avxifma256_body wrt ..imagebase,$L$ossl_rsaz_amm52x30_x2_avxifma256_epilogue wrt ..imagebase diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-4k-avxifma.nasm b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-4k-avxifma.nasm index 50b17ffafc..3ce5ac9410 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-4k-avxifma.nasm +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/X64-MSFT/crypto/bn/rsaz-4k-avxifma.nasm @@ -6,12 +6,2103 @@ section .text code align=64 global ossl_rsaz_amm52x40_x1_avxifma256 -global ossl_rsaz_amm52x40_x2_avxifma256 -global ossl_extract_multiplier_2x40_win5_avx +ALIGN 32 ossl_rsaz_amm52x40_x1_avxifma256: -ossl_rsaz_amm52x40_x2_avxifma256: -ossl_extract_multiplier_2x40_win5_avx: -DB 0x0f,0x0b + mov QWORD[8+rsp],rdi ;WIN64 prologue + mov QWORD[16+rsp],rsi + mov rax,rsp +$L$SEH_begin_ossl_rsaz_amm52x40_x1_avxifma256: + mov rdi,rcx + mov rsi,rdx + mov rdx,r8 + mov rcx,r9 + mov r8,QWORD[40+rsp] + + + +DB 243,15,30,250 + push rbx + + push rbp + + push r12 + + push r13 + + push r14 + + push r15 + + lea rsp,[((-168))+rsp] + vmovapd XMMWORD[rsp],xmm6 + vmovapd XMMWORD[16+rsp],xmm7 + vmovapd XMMWORD[32+rsp],xmm8 + vmovapd XMMWORD[48+rsp],xmm9 + vmovapd XMMWORD[64+rsp],xmm10 + vmovapd XMMWORD[80+rsp],xmm11 + vmovapd XMMWORD[96+rsp],xmm12 + vmovapd XMMWORD[112+rsp],xmm13 + vmovapd XMMWORD[128+rsp],xmm14 + vmovapd XMMWORD[144+rsp],xmm15 +$L$ossl_rsaz_amm52x40_x1_avxifma256_body: + + vpxor ymm0,ymm0,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + vmovapd ymm8,ymm0 + vmovapd ymm9,ymm0 + vmovapd ymm10,ymm0 + vmovapd ymm11,ymm0 + vmovapd ymm12,ymm0 + + xor r9d,r9d + + mov r11,rdx + mov rax,0xfffffffffffff + + + mov ebx,10 + +ALIGN 32 +$L$loop10: + mov r13,QWORD[r11] + + vpbroadcastq ymm1,QWORD[r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-328))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52luq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52luq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52luq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52luq ymm12,ymm2,YMMWORD[288+rcx] + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + vmovdqu YMMWORD[256+rsp],ymm11 + vmovdqu YMMWORD[288+rsp],ymm12 + mov QWORD[320+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + vmovdqu ymm11,YMMWORD[264+rsp] + vmovdqu ymm12,YMMWORD[296+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52huq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52huq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52huq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52huq ymm12,ymm2,YMMWORD[288+rcx] + lea rsp,[328+rsp] + mov r13,QWORD[8+r11] + + vpbroadcastq ymm1,QWORD[8+r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-328))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52luq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52luq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52luq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52luq ymm12,ymm2,YMMWORD[288+rcx] + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + vmovdqu YMMWORD[256+rsp],ymm11 + vmovdqu YMMWORD[288+rsp],ymm12 + mov QWORD[320+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + vmovdqu ymm11,YMMWORD[264+rsp] + vmovdqu ymm12,YMMWORD[296+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52huq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52huq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52huq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52huq ymm12,ymm2,YMMWORD[288+rcx] + lea rsp,[328+rsp] + mov r13,QWORD[16+r11] + + vpbroadcastq ymm1,QWORD[16+r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-328))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52luq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52luq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52luq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52luq ymm12,ymm2,YMMWORD[288+rcx] + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + vmovdqu YMMWORD[256+rsp],ymm11 + vmovdqu YMMWORD[288+rsp],ymm12 + mov QWORD[320+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + vmovdqu ymm11,YMMWORD[264+rsp] + vmovdqu ymm12,YMMWORD[296+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52huq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52huq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52huq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52huq ymm12,ymm2,YMMWORD[288+rcx] + lea rsp,[328+rsp] + mov r13,QWORD[24+r11] + + vpbroadcastq ymm1,QWORD[24+r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,r8 + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-328))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52luq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52luq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52luq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52luq ymm12,ymm2,YMMWORD[288+rcx] + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + vmovdqu YMMWORD[256+rsp],ymm11 + vmovdqu YMMWORD[288+rsp],ymm12 + mov QWORD[320+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + vmovdqu ymm11,YMMWORD[264+rsp] + vmovdqu ymm12,YMMWORD[296+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52huq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52huq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52huq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52huq ymm12,ymm2,YMMWORD[288+rcx] + lea rsp,[328+rsp] + lea r11,[32+r11] + dec ebx + jne NEAR $L$loop10 + + vmovq xmm0,r9 + vpbroadcastq ymm0,xmm0 + vpblendd ymm3,ymm3,ymm0,3 + + lea rsp,[((-640))+rsp] + vmovupd YMMWORD[rsp],ymm3 + vmovupd YMMWORD[32+rsp],ymm4 + vmovupd YMMWORD[64+rsp],ymm5 + vmovupd YMMWORD[96+rsp],ymm6 + vmovupd YMMWORD[128+rsp],ymm7 + vmovupd YMMWORD[160+rsp],ymm8 + vmovupd YMMWORD[192+rsp],ymm9 + vmovupd YMMWORD[224+rsp],ymm10 + vmovupd YMMWORD[256+rsp],ymm11 + vmovupd YMMWORD[288+rsp],ymm12 + + + + vpsrlq ymm3,ymm3,52 + vpsrlq ymm4,ymm4,52 + vpsrlq ymm5,ymm5,52 + vpsrlq ymm6,ymm6,52 + vpsrlq ymm7,ymm7,52 + vpsrlq ymm8,ymm8,52 + vpsrlq ymm9,ymm9,52 + vpsrlq ymm10,ymm10,52 + vpsrlq ymm11,ymm11,52 + vpsrlq ymm12,ymm12,52 + + + vpermq ymm12,ymm12,144 + vpermq ymm13,ymm11,3 + vblendpd ymm12,ymm12,ymm13,1 + + vpermq ymm11,ymm11,144 + vpermq ymm13,ymm10,3 + vblendpd ymm11,ymm11,ymm13,1 + + vpermq ymm10,ymm10,144 + vpermq ymm13,ymm9,3 + vblendpd ymm10,ymm10,ymm13,1 + + vpermq ymm9,ymm9,144 + vpermq ymm13,ymm8,3 + vblendpd ymm9,ymm9,ymm13,1 + + vpermq ymm8,ymm8,144 + vpermq ymm13,ymm7,3 + vblendpd ymm8,ymm8,ymm13,1 + + vpermq ymm7,ymm7,144 + vpermq ymm13,ymm6,3 + vblendpd ymm7,ymm7,ymm13,1 + + vpermq ymm6,ymm6,144 + vpermq ymm13,ymm5,3 + vblendpd ymm6,ymm6,ymm13,1 + + vpermq ymm5,ymm5,144 + vpermq ymm13,ymm4,3 + vblendpd ymm5,ymm5,ymm13,1 + + vpermq ymm4,ymm4,144 + vpermq ymm13,ymm3,3 + vblendpd ymm4,ymm4,ymm13,1 + + vpermq ymm3,ymm3,144 + vpand ymm3,ymm3,YMMWORD[$L$high64x3] + + vmovupd YMMWORD[320+rsp],ymm3 + vmovupd YMMWORD[352+rsp],ymm4 + vmovupd YMMWORD[384+rsp],ymm5 + vmovupd YMMWORD[416+rsp],ymm6 + vmovupd YMMWORD[448+rsp],ymm7 + vmovupd YMMWORD[480+rsp],ymm8 + vmovupd YMMWORD[512+rsp],ymm9 + vmovupd YMMWORD[544+rsp],ymm10 + vmovupd YMMWORD[576+rsp],ymm11 + vmovupd YMMWORD[608+rsp],ymm12 + + vmovupd ymm3,YMMWORD[rsp] + vmovupd ymm4,YMMWORD[32+rsp] + vmovupd ymm5,YMMWORD[64+rsp] + vmovupd ymm6,YMMWORD[96+rsp] + vmovupd ymm7,YMMWORD[128+rsp] + vmovupd ymm8,YMMWORD[160+rsp] + vmovupd ymm9,YMMWORD[192+rsp] + vmovupd ymm10,YMMWORD[224+rsp] + vmovupd ymm11,YMMWORD[256+rsp] + vmovupd ymm12,YMMWORD[288+rsp] + + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + vpand ymm11,ymm11,YMMWORD[$L$mask52x4] + vpand ymm12,ymm12,YMMWORD[$L$mask52x4] + + + vpaddq ymm3,ymm3,YMMWORD[320+rsp] + vpaddq ymm4,ymm4,YMMWORD[352+rsp] + vpaddq ymm5,ymm5,YMMWORD[384+rsp] + vpaddq ymm6,ymm6,YMMWORD[416+rsp] + vpaddq ymm7,ymm7,YMMWORD[448+rsp] + vpaddq ymm8,ymm8,YMMWORD[480+rsp] + vpaddq ymm9,ymm9,YMMWORD[512+rsp] + vpaddq ymm10,ymm10,YMMWORD[544+rsp] + vpaddq ymm11,ymm11,YMMWORD[576+rsp] + vpaddq ymm12,ymm12,YMMWORD[608+rsp] + + lea rsp,[640+rsp] + + + + vpcmpgtq ymm13,ymm3,YMMWORD[$L$mask52x4] + vmovmskpd r14d,ymm13 + vpcmpgtq ymm13,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r13d,ymm13 + shl r13b,4 + or r14b,r13b + + vpcmpgtq ymm13,ymm5,YMMWORD[$L$mask52x4] + vmovmskpd r13d,ymm13 + vpcmpgtq ymm13,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd r12d,ymm13 + shl r12b,4 + or r13b,r12b + + vpcmpgtq ymm13,ymm7,YMMWORD[$L$mask52x4] + vmovmskpd r12d,ymm13 + vpcmpgtq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd r11d,ymm13 + shl r11b,4 + or r12b,r11b + + vpcmpgtq ymm13,ymm9,YMMWORD[$L$mask52x4] + vmovmskpd r11d,ymm13 + vpcmpgtq ymm13,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd r10d,ymm13 + shl r10b,4 + or r11b,r10b + + vpcmpgtq ymm13,ymm11,YMMWORD[$L$mask52x4] + vmovmskpd r10d,ymm13 + vpcmpgtq ymm13,ymm12,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm13 + shl r9b,4 + or r10b,r9b + + add r14b,r14b + adc r13b,r13b + adc r12b,r12b + adc r11b,r11b + adc r10b,r10b + + + vpcmpeqq ymm13,ymm3,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm13 + vpcmpeqq ymm13,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r8d,ymm13 + shl r8b,4 + or r9b,r8b + + vpcmpeqq ymm13,ymm5,YMMWORD[$L$mask52x4] + vmovmskpd r8d,ymm13 + vpcmpeqq ymm13,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd edx,ymm13 + shl dl,4 + or r8b,dl + + vpcmpeqq ymm13,ymm7,YMMWORD[$L$mask52x4] + vmovmskpd edx,ymm13 + vpcmpeqq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd ecx,ymm13 + shl cl,4 + or dl,cl + + vpcmpeqq ymm13,ymm9,YMMWORD[$L$mask52x4] + vmovmskpd ecx,ymm13 + vpcmpeqq ymm13,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd ebx,ymm13 + shl bl,4 + or cl,bl + + vpcmpeqq ymm13,ymm11,YMMWORD[$L$mask52x4] + vmovmskpd ebx,ymm13 + vpcmpeqq ymm13,ymm12,YMMWORD[$L$mask52x4] + vmovmskpd eax,ymm13 + shl al,4 + or bl,al + + add r14b,r9b + adc r13b,r8b + adc r12b,dl + adc r11b,cl + adc r10b,bl + + xor r14b,r9b + xor r13b,r8b + xor r12b,dl + xor r11b,cl + xor r10b,bl + + push r9 + push r8 + + lea r8,[$L$kmasklut] + + mov r9b,r14b + and r14,0xf + vpsubq ymm13,ymm3,YMMWORD[$L$mask52x4] + shl r14,5 + vmovapd ymm14,YMMWORD[r14*1+r8] + vblendvpd ymm3,ymm3,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm4,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm4,ymm4,ymm13,ymm14 + + mov r9b,r13b + and r13,0xf + vpsubq ymm13,ymm5,YMMWORD[$L$mask52x4] + shl r13,5 + vmovapd ymm14,YMMWORD[r13*1+r8] + vblendvpd ymm5,ymm5,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm6,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm6,ymm6,ymm13,ymm14 + + mov r9b,r12b + and r12,0xf + vpsubq ymm13,ymm7,YMMWORD[$L$mask52x4] + shl r12,5 + vmovapd ymm14,YMMWORD[r12*1+r8] + vblendvpd ymm7,ymm7,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm8,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm8,ymm8,ymm13,ymm14 + + mov r9b,r11b + and r11,0xf + vpsubq ymm13,ymm9,YMMWORD[$L$mask52x4] + shl r11,5 + vmovapd ymm14,YMMWORD[r11*1+r8] + vblendvpd ymm9,ymm9,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm10,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm10,ymm10,ymm13,ymm14 + + mov r9b,r10b + and r10,0xf + vpsubq ymm13,ymm11,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm14,YMMWORD[r10*1+r8] + vblendvpd ymm11,ymm11,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm12,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm12,ymm12,ymm13,ymm14 + + pop r8 + pop r9 + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + vpand ymm11,ymm11,YMMWORD[$L$mask52x4] + vpand ymm12,ymm12,YMMWORD[$L$mask52x4] + + vmovdqu YMMWORD[rdi],ymm3 + vmovdqu YMMWORD[32+rdi],ymm4 + vmovdqu YMMWORD[64+rdi],ymm5 + vmovdqu YMMWORD[96+rdi],ymm6 + vmovdqu YMMWORD[128+rdi],ymm7 + vmovdqu YMMWORD[160+rdi],ymm8 + vmovdqu YMMWORD[192+rdi],ymm9 + vmovdqu YMMWORD[224+rdi],ymm10 + vmovdqu YMMWORD[256+rdi],ymm11 + vmovdqu YMMWORD[288+rdi],ymm12 + + vzeroupper + lea rax,[rsp] + + vmovapd xmm6,XMMWORD[rax] + vmovapd xmm7,XMMWORD[16+rax] + vmovapd xmm8,XMMWORD[32+rax] + vmovapd xmm9,XMMWORD[48+rax] + vmovapd xmm10,XMMWORD[64+rax] + vmovapd xmm11,XMMWORD[80+rax] + vmovapd xmm12,XMMWORD[96+rax] + vmovapd xmm13,XMMWORD[112+rax] + vmovapd xmm14,XMMWORD[128+rax] + vmovapd xmm15,XMMWORD[144+rax] + lea rax,[168+rsp] + mov r15,QWORD[rax] + + mov r14,QWORD[8+rax] + + mov r13,QWORD[16+rax] + + mov r12,QWORD[24+rax] + + mov rbp,QWORD[32+rax] + + mov rbx,QWORD[40+rax] + + lea rsp,[48+rax] + +$L$ossl_rsaz_amm52x40_x1_avxifma256_epilogue: + + mov rdi,QWORD[8+rsp] ;WIN64 epilogue + mov rsi,QWORD[16+rsp] DB 0F3h,0C3h ;repret +$L$SEH_end_ossl_rsaz_amm52x40_x1_avxifma256: +section .rdata rdata align=32 +ALIGN 32 +$L$mask52x4: + DQ 0xfffffffffffff + DQ 0xfffffffffffff + DQ 0xfffffffffffff + DQ 0xfffffffffffff +$L$high64x3: + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff +$L$kmasklut: + + DQ 0x0 + DQ 0x0 + DQ 0x0 + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + DQ 0x0 + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + + DQ 0x0 + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + + DQ 0x0 + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + + DQ 0x0 + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff + DQ 0xffffffffffffffff +section .text code align=64 + + +global ossl_rsaz_amm52x40_x2_avxifma256 + +ALIGN 32 +ossl_rsaz_amm52x40_x2_avxifma256: + mov QWORD[8+rsp],rdi ;WIN64 prologue + mov QWORD[16+rsp],rsi + mov rax,rsp +$L$SEH_begin_ossl_rsaz_amm52x40_x2_avxifma256: + mov rdi,rcx + mov rsi,rdx + mov rdx,r8 + mov rcx,r9 + mov r8,QWORD[40+rsp] + + + +DB 243,15,30,250 + push rbx + + push rbp + + push r12 + + push r13 + + push r14 + + push r15 + + lea rsp,[((-168))+rsp] + vmovapd XMMWORD[rsp],xmm6 + vmovapd XMMWORD[16+rsp],xmm7 + vmovapd XMMWORD[32+rsp],xmm8 + vmovapd XMMWORD[48+rsp],xmm9 + vmovapd XMMWORD[64+rsp],xmm10 + vmovapd XMMWORD[80+rsp],xmm11 + vmovapd XMMWORD[96+rsp],xmm12 + vmovapd XMMWORD[112+rsp],xmm13 + vmovapd XMMWORD[128+rsp],xmm14 + vmovapd XMMWORD[144+rsp],xmm15 +$L$ossl_rsaz_amm52x40_x2_avxifma256_body: + + vpxor ymm0,ymm0,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + vmovapd ymm8,ymm0 + vmovapd ymm9,ymm0 + vmovapd ymm10,ymm0 + vmovapd ymm11,ymm0 + vmovapd ymm12,ymm0 + + xor r9d,r9d + + mov r11,rdx + mov rax,0xfffffffffffff + + mov ebx,40 + +ALIGN 32 +$L$loop40: + mov r13,QWORD[r11] + + vpbroadcastq ymm1,QWORD[r11] + mov rdx,QWORD[rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,QWORD[r8] + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-328))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52luq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52luq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52luq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52luq ymm12,ymm2,YMMWORD[288+rcx] + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + vmovdqu YMMWORD[256+rsp],ymm11 + vmovdqu YMMWORD[288+rsp],ymm12 + mov QWORD[320+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + vmovdqu ymm11,YMMWORD[264+rsp] + vmovdqu ymm12,YMMWORD[296+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[32+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[64+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[96+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[128+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[160+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[192+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[224+rsi] +{vex} vpmadd52huq ymm11,ymm1,YMMWORD[256+rsi] +{vex} vpmadd52huq ymm12,ymm1,YMMWORD[288+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[32+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[64+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[96+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[128+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[160+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[192+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[224+rcx] +{vex} vpmadd52huq ymm11,ymm2,YMMWORD[256+rcx] +{vex} vpmadd52huq ymm12,ymm2,YMMWORD[288+rcx] + lea rsp,[328+rsp] + lea r11,[8+r11] + dec ebx + jne NEAR $L$loop40 + + push r11 + push rsi + push rcx + push r8 + + vmovq xmm0,r9 + vpbroadcastq ymm0,xmm0 + vpblendd ymm3,ymm3,ymm0,3 + + lea rsp,[((-640))+rsp] + vmovupd YMMWORD[rsp],ymm3 + vmovupd YMMWORD[32+rsp],ymm4 + vmovupd YMMWORD[64+rsp],ymm5 + vmovupd YMMWORD[96+rsp],ymm6 + vmovupd YMMWORD[128+rsp],ymm7 + vmovupd YMMWORD[160+rsp],ymm8 + vmovupd YMMWORD[192+rsp],ymm9 + vmovupd YMMWORD[224+rsp],ymm10 + vmovupd YMMWORD[256+rsp],ymm11 + vmovupd YMMWORD[288+rsp],ymm12 + + + + vpsrlq ymm3,ymm3,52 + vpsrlq ymm4,ymm4,52 + vpsrlq ymm5,ymm5,52 + vpsrlq ymm6,ymm6,52 + vpsrlq ymm7,ymm7,52 + vpsrlq ymm8,ymm8,52 + vpsrlq ymm9,ymm9,52 + vpsrlq ymm10,ymm10,52 + vpsrlq ymm11,ymm11,52 + vpsrlq ymm12,ymm12,52 + + + vpermq ymm12,ymm12,144 + vpermq ymm13,ymm11,3 + vblendpd ymm12,ymm12,ymm13,1 + + vpermq ymm11,ymm11,144 + vpermq ymm13,ymm10,3 + vblendpd ymm11,ymm11,ymm13,1 + + vpermq ymm10,ymm10,144 + vpermq ymm13,ymm9,3 + vblendpd ymm10,ymm10,ymm13,1 + + vpermq ymm9,ymm9,144 + vpermq ymm13,ymm8,3 + vblendpd ymm9,ymm9,ymm13,1 + + vpermq ymm8,ymm8,144 + vpermq ymm13,ymm7,3 + vblendpd ymm8,ymm8,ymm13,1 + + vpermq ymm7,ymm7,144 + vpermq ymm13,ymm6,3 + vblendpd ymm7,ymm7,ymm13,1 + + vpermq ymm6,ymm6,144 + vpermq ymm13,ymm5,3 + vblendpd ymm6,ymm6,ymm13,1 + + vpermq ymm5,ymm5,144 + vpermq ymm13,ymm4,3 + vblendpd ymm5,ymm5,ymm13,1 + + vpermq ymm4,ymm4,144 + vpermq ymm13,ymm3,3 + vblendpd ymm4,ymm4,ymm13,1 + + vpermq ymm3,ymm3,144 + vpand ymm3,ymm3,YMMWORD[$L$high64x3] + + vmovupd YMMWORD[320+rsp],ymm3 + vmovupd YMMWORD[352+rsp],ymm4 + vmovupd YMMWORD[384+rsp],ymm5 + vmovupd YMMWORD[416+rsp],ymm6 + vmovupd YMMWORD[448+rsp],ymm7 + vmovupd YMMWORD[480+rsp],ymm8 + vmovupd YMMWORD[512+rsp],ymm9 + vmovupd YMMWORD[544+rsp],ymm10 + vmovupd YMMWORD[576+rsp],ymm11 + vmovupd YMMWORD[608+rsp],ymm12 + + vmovupd ymm3,YMMWORD[rsp] + vmovupd ymm4,YMMWORD[32+rsp] + vmovupd ymm5,YMMWORD[64+rsp] + vmovupd ymm6,YMMWORD[96+rsp] + vmovupd ymm7,YMMWORD[128+rsp] + vmovupd ymm8,YMMWORD[160+rsp] + vmovupd ymm9,YMMWORD[192+rsp] + vmovupd ymm10,YMMWORD[224+rsp] + vmovupd ymm11,YMMWORD[256+rsp] + vmovupd ymm12,YMMWORD[288+rsp] + + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + vpand ymm11,ymm11,YMMWORD[$L$mask52x4] + vpand ymm12,ymm12,YMMWORD[$L$mask52x4] + + + vpaddq ymm3,ymm3,YMMWORD[320+rsp] + vpaddq ymm4,ymm4,YMMWORD[352+rsp] + vpaddq ymm5,ymm5,YMMWORD[384+rsp] + vpaddq ymm6,ymm6,YMMWORD[416+rsp] + vpaddq ymm7,ymm7,YMMWORD[448+rsp] + vpaddq ymm8,ymm8,YMMWORD[480+rsp] + vpaddq ymm9,ymm9,YMMWORD[512+rsp] + vpaddq ymm10,ymm10,YMMWORD[544+rsp] + vpaddq ymm11,ymm11,YMMWORD[576+rsp] + vpaddq ymm12,ymm12,YMMWORD[608+rsp] + + lea rsp,[640+rsp] + + + + vpcmpgtq ymm13,ymm3,YMMWORD[$L$mask52x4] + vmovmskpd r14d,ymm13 + vpcmpgtq ymm13,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r13d,ymm13 + shl r13b,4 + or r14b,r13b + + vpcmpgtq ymm13,ymm5,YMMWORD[$L$mask52x4] + vmovmskpd r13d,ymm13 + vpcmpgtq ymm13,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd r12d,ymm13 + shl r12b,4 + or r13b,r12b + + vpcmpgtq ymm13,ymm7,YMMWORD[$L$mask52x4] + vmovmskpd r12d,ymm13 + vpcmpgtq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd r11d,ymm13 + shl r11b,4 + or r12b,r11b + + vpcmpgtq ymm13,ymm9,YMMWORD[$L$mask52x4] + vmovmskpd r11d,ymm13 + vpcmpgtq ymm13,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd r10d,ymm13 + shl r10b,4 + or r11b,r10b + + vpcmpgtq ymm13,ymm11,YMMWORD[$L$mask52x4] + vmovmskpd r10d,ymm13 + vpcmpgtq ymm13,ymm12,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm13 + shl r9b,4 + or r10b,r9b + + add r14b,r14b + adc r13b,r13b + adc r12b,r12b + adc r11b,r11b + adc r10b,r10b + + + vpcmpeqq ymm13,ymm3,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm13 + vpcmpeqq ymm13,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r8d,ymm13 + shl r8b,4 + or r9b,r8b + + vpcmpeqq ymm13,ymm5,YMMWORD[$L$mask52x4] + vmovmskpd r8d,ymm13 + vpcmpeqq ymm13,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd edx,ymm13 + shl dl,4 + or r8b,dl + + vpcmpeqq ymm13,ymm7,YMMWORD[$L$mask52x4] + vmovmskpd edx,ymm13 + vpcmpeqq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd ecx,ymm13 + shl cl,4 + or dl,cl + + vpcmpeqq ymm13,ymm9,YMMWORD[$L$mask52x4] + vmovmskpd ecx,ymm13 + vpcmpeqq ymm13,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd ebx,ymm13 + shl bl,4 + or cl,bl + + vpcmpeqq ymm13,ymm11,YMMWORD[$L$mask52x4] + vmovmskpd ebx,ymm13 + vpcmpeqq ymm13,ymm12,YMMWORD[$L$mask52x4] + vmovmskpd eax,ymm13 + shl al,4 + or bl,al + + add r14b,r9b + adc r13b,r8b + adc r12b,dl + adc r11b,cl + adc r10b,bl + + xor r14b,r9b + xor r13b,r8b + xor r12b,dl + xor r11b,cl + xor r10b,bl + + push r9 + push r8 + + lea r8,[$L$kmasklut] + + mov r9b,r14b + and r14,0xf + vpsubq ymm13,ymm3,YMMWORD[$L$mask52x4] + shl r14,5 + vmovapd ymm14,YMMWORD[r14*1+r8] + vblendvpd ymm3,ymm3,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm4,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm4,ymm4,ymm13,ymm14 + + mov r9b,r13b + and r13,0xf + vpsubq ymm13,ymm5,YMMWORD[$L$mask52x4] + shl r13,5 + vmovapd ymm14,YMMWORD[r13*1+r8] + vblendvpd ymm5,ymm5,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm6,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm6,ymm6,ymm13,ymm14 + + mov r9b,r12b + and r12,0xf + vpsubq ymm13,ymm7,YMMWORD[$L$mask52x4] + shl r12,5 + vmovapd ymm14,YMMWORD[r12*1+r8] + vblendvpd ymm7,ymm7,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm8,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm8,ymm8,ymm13,ymm14 + + mov r9b,r11b + and r11,0xf + vpsubq ymm13,ymm9,YMMWORD[$L$mask52x4] + shl r11,5 + vmovapd ymm14,YMMWORD[r11*1+r8] + vblendvpd ymm9,ymm9,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm10,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm10,ymm10,ymm13,ymm14 + + mov r9b,r10b + and r10,0xf + vpsubq ymm13,ymm11,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm14,YMMWORD[r10*1+r8] + vblendvpd ymm11,ymm11,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm12,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm12,ymm12,ymm13,ymm14 + + pop r8 + pop r9 + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + vpand ymm11,ymm11,YMMWORD[$L$mask52x4] + vpand ymm12,ymm12,YMMWORD[$L$mask52x4] + + pop r8 + pop rcx + pop rsi + pop r11 + + vmovdqu YMMWORD[rdi],ymm3 + vmovdqu YMMWORD[32+rdi],ymm4 + vmovdqu YMMWORD[64+rdi],ymm5 + vmovdqu YMMWORD[96+rdi],ymm6 + vmovdqu YMMWORD[128+rdi],ymm7 + vmovdqu YMMWORD[160+rdi],ymm8 + vmovdqu YMMWORD[192+rdi],ymm9 + vmovdqu YMMWORD[224+rdi],ymm10 + vmovdqu YMMWORD[256+rdi],ymm11 + vmovdqu YMMWORD[288+rdi],ymm12 + + xor r9d,r9d + + mov rax,0xfffffffffffff + + mov ebx,40 + + vpxor ymm0,ymm0,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + vmovapd ymm8,ymm0 + vmovapd ymm9,ymm0 + vmovapd ymm10,ymm0 + vmovapd ymm11,ymm0 + vmovapd ymm12,ymm0 +ALIGN 32 +$L$loop40_1: + mov r13,QWORD[r11] + + vpbroadcastq ymm1,QWORD[r11] + mov rdx,QWORD[320+rsi] + mulx r12,r13,r13 + add r9,r13 + mov r10,r12 + adc r10,0 + + mov r13,QWORD[8+r8] + imul r13,r9 + and r13,rax + + vmovq xmm2,r13 + vpbroadcastq ymm2,xmm2 + mov rdx,QWORD[320+rcx] + mulx r12,r13,r13 + add r9,r13 + adc r10,r12 + + shr r9,52 + sal r10,12 + or r9,r10 + + lea rsp,[((-328))+rsp] + +{vex} vpmadd52luq ymm3,ymm1,YMMWORD[320+rsi] +{vex} vpmadd52luq ymm4,ymm1,YMMWORD[352+rsi] +{vex} vpmadd52luq ymm5,ymm1,YMMWORD[384+rsi] +{vex} vpmadd52luq ymm6,ymm1,YMMWORD[416+rsi] +{vex} vpmadd52luq ymm7,ymm1,YMMWORD[448+rsi] +{vex} vpmadd52luq ymm8,ymm1,YMMWORD[480+rsi] +{vex} vpmadd52luq ymm9,ymm1,YMMWORD[512+rsi] +{vex} vpmadd52luq ymm10,ymm1,YMMWORD[544+rsi] +{vex} vpmadd52luq ymm11,ymm1,YMMWORD[576+rsi] +{vex} vpmadd52luq ymm12,ymm1,YMMWORD[608+rsi] + +{vex} vpmadd52luq ymm3,ymm2,YMMWORD[320+rcx] +{vex} vpmadd52luq ymm4,ymm2,YMMWORD[352+rcx] +{vex} vpmadd52luq ymm5,ymm2,YMMWORD[384+rcx] +{vex} vpmadd52luq ymm6,ymm2,YMMWORD[416+rcx] +{vex} vpmadd52luq ymm7,ymm2,YMMWORD[448+rcx] +{vex} vpmadd52luq ymm8,ymm2,YMMWORD[480+rcx] +{vex} vpmadd52luq ymm9,ymm2,YMMWORD[512+rcx] +{vex} vpmadd52luq ymm10,ymm2,YMMWORD[544+rcx] +{vex} vpmadd52luq ymm11,ymm2,YMMWORD[576+rcx] +{vex} vpmadd52luq ymm12,ymm2,YMMWORD[608+rcx] + vmovdqu YMMWORD[rsp],ymm3 + vmovdqu YMMWORD[32+rsp],ymm4 + vmovdqu YMMWORD[64+rsp],ymm5 + vmovdqu YMMWORD[96+rsp],ymm6 + vmovdqu YMMWORD[128+rsp],ymm7 + vmovdqu YMMWORD[160+rsp],ymm8 + vmovdqu YMMWORD[192+rsp],ymm9 + vmovdqu YMMWORD[224+rsp],ymm10 + vmovdqu YMMWORD[256+rsp],ymm11 + vmovdqu YMMWORD[288+rsp],ymm12 + mov QWORD[320+rsp],0 + + vmovdqu ymm3,YMMWORD[8+rsp] + vmovdqu ymm4,YMMWORD[40+rsp] + vmovdqu ymm5,YMMWORD[72+rsp] + vmovdqu ymm6,YMMWORD[104+rsp] + vmovdqu ymm7,YMMWORD[136+rsp] + vmovdqu ymm8,YMMWORD[168+rsp] + vmovdqu ymm9,YMMWORD[200+rsp] + vmovdqu ymm10,YMMWORD[232+rsp] + vmovdqu ymm11,YMMWORD[264+rsp] + vmovdqu ymm12,YMMWORD[296+rsp] + + add r9,QWORD[8+rsp] + +{vex} vpmadd52huq ymm3,ymm1,YMMWORD[320+rsi] +{vex} vpmadd52huq ymm4,ymm1,YMMWORD[352+rsi] +{vex} vpmadd52huq ymm5,ymm1,YMMWORD[384+rsi] +{vex} vpmadd52huq ymm6,ymm1,YMMWORD[416+rsi] +{vex} vpmadd52huq ymm7,ymm1,YMMWORD[448+rsi] +{vex} vpmadd52huq ymm8,ymm1,YMMWORD[480+rsi] +{vex} vpmadd52huq ymm9,ymm1,YMMWORD[512+rsi] +{vex} vpmadd52huq ymm10,ymm1,YMMWORD[544+rsi] +{vex} vpmadd52huq ymm11,ymm1,YMMWORD[576+rsi] +{vex} vpmadd52huq ymm12,ymm1,YMMWORD[608+rsi] + +{vex} vpmadd52huq ymm3,ymm2,YMMWORD[320+rcx] +{vex} vpmadd52huq ymm4,ymm2,YMMWORD[352+rcx] +{vex} vpmadd52huq ymm5,ymm2,YMMWORD[384+rcx] +{vex} vpmadd52huq ymm6,ymm2,YMMWORD[416+rcx] +{vex} vpmadd52huq ymm7,ymm2,YMMWORD[448+rcx] +{vex} vpmadd52huq ymm8,ymm2,YMMWORD[480+rcx] +{vex} vpmadd52huq ymm9,ymm2,YMMWORD[512+rcx] +{vex} vpmadd52huq ymm10,ymm2,YMMWORD[544+rcx] +{vex} vpmadd52huq ymm11,ymm2,YMMWORD[576+rcx] +{vex} vpmadd52huq ymm12,ymm2,YMMWORD[608+rcx] + lea rsp,[328+rsp] + lea r11,[8+r11] + dec ebx + jne NEAR $L$loop40_1 + + vmovq xmm0,r9 + vpbroadcastq ymm0,xmm0 + vpblendd ymm3,ymm3,ymm0,3 + + lea rsp,[((-640))+rsp] + vmovupd YMMWORD[rsp],ymm3 + vmovupd YMMWORD[32+rsp],ymm4 + vmovupd YMMWORD[64+rsp],ymm5 + vmovupd YMMWORD[96+rsp],ymm6 + vmovupd YMMWORD[128+rsp],ymm7 + vmovupd YMMWORD[160+rsp],ymm8 + vmovupd YMMWORD[192+rsp],ymm9 + vmovupd YMMWORD[224+rsp],ymm10 + vmovupd YMMWORD[256+rsp],ymm11 + vmovupd YMMWORD[288+rsp],ymm12 + + + + vpsrlq ymm3,ymm3,52 + vpsrlq ymm4,ymm4,52 + vpsrlq ymm5,ymm5,52 + vpsrlq ymm6,ymm6,52 + vpsrlq ymm7,ymm7,52 + vpsrlq ymm8,ymm8,52 + vpsrlq ymm9,ymm9,52 + vpsrlq ymm10,ymm10,52 + vpsrlq ymm11,ymm11,52 + vpsrlq ymm12,ymm12,52 + + + vpermq ymm12,ymm12,144 + vpermq ymm13,ymm11,3 + vblendpd ymm12,ymm12,ymm13,1 + + vpermq ymm11,ymm11,144 + vpermq ymm13,ymm10,3 + vblendpd ymm11,ymm11,ymm13,1 + + vpermq ymm10,ymm10,144 + vpermq ymm13,ymm9,3 + vblendpd ymm10,ymm10,ymm13,1 + + vpermq ymm9,ymm9,144 + vpermq ymm13,ymm8,3 + vblendpd ymm9,ymm9,ymm13,1 + + vpermq ymm8,ymm8,144 + vpermq ymm13,ymm7,3 + vblendpd ymm8,ymm8,ymm13,1 + + vpermq ymm7,ymm7,144 + vpermq ymm13,ymm6,3 + vblendpd ymm7,ymm7,ymm13,1 + + vpermq ymm6,ymm6,144 + vpermq ymm13,ymm5,3 + vblendpd ymm6,ymm6,ymm13,1 + + vpermq ymm5,ymm5,144 + vpermq ymm13,ymm4,3 + vblendpd ymm5,ymm5,ymm13,1 + + vpermq ymm4,ymm4,144 + vpermq ymm13,ymm3,3 + vblendpd ymm4,ymm4,ymm13,1 + + vpermq ymm3,ymm3,144 + vpand ymm3,ymm3,YMMWORD[$L$high64x3] + + vmovupd YMMWORD[320+rsp],ymm3 + vmovupd YMMWORD[352+rsp],ymm4 + vmovupd YMMWORD[384+rsp],ymm5 + vmovupd YMMWORD[416+rsp],ymm6 + vmovupd YMMWORD[448+rsp],ymm7 + vmovupd YMMWORD[480+rsp],ymm8 + vmovupd YMMWORD[512+rsp],ymm9 + vmovupd YMMWORD[544+rsp],ymm10 + vmovupd YMMWORD[576+rsp],ymm11 + vmovupd YMMWORD[608+rsp],ymm12 + + vmovupd ymm3,YMMWORD[rsp] + vmovupd ymm4,YMMWORD[32+rsp] + vmovupd ymm5,YMMWORD[64+rsp] + vmovupd ymm6,YMMWORD[96+rsp] + vmovupd ymm7,YMMWORD[128+rsp] + vmovupd ymm8,YMMWORD[160+rsp] + vmovupd ymm9,YMMWORD[192+rsp] + vmovupd ymm10,YMMWORD[224+rsp] + vmovupd ymm11,YMMWORD[256+rsp] + vmovupd ymm12,YMMWORD[288+rsp] + + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + vpand ymm11,ymm11,YMMWORD[$L$mask52x4] + vpand ymm12,ymm12,YMMWORD[$L$mask52x4] + + + vpaddq ymm3,ymm3,YMMWORD[320+rsp] + vpaddq ymm4,ymm4,YMMWORD[352+rsp] + vpaddq ymm5,ymm5,YMMWORD[384+rsp] + vpaddq ymm6,ymm6,YMMWORD[416+rsp] + vpaddq ymm7,ymm7,YMMWORD[448+rsp] + vpaddq ymm8,ymm8,YMMWORD[480+rsp] + vpaddq ymm9,ymm9,YMMWORD[512+rsp] + vpaddq ymm10,ymm10,YMMWORD[544+rsp] + vpaddq ymm11,ymm11,YMMWORD[576+rsp] + vpaddq ymm12,ymm12,YMMWORD[608+rsp] + + lea rsp,[640+rsp] + + + + vpcmpgtq ymm13,ymm3,YMMWORD[$L$mask52x4] + vmovmskpd r14d,ymm13 + vpcmpgtq ymm13,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r13d,ymm13 + shl r13b,4 + or r14b,r13b + + vpcmpgtq ymm13,ymm5,YMMWORD[$L$mask52x4] + vmovmskpd r13d,ymm13 + vpcmpgtq ymm13,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd r12d,ymm13 + shl r12b,4 + or r13b,r12b + + vpcmpgtq ymm13,ymm7,YMMWORD[$L$mask52x4] + vmovmskpd r12d,ymm13 + vpcmpgtq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd r11d,ymm13 + shl r11b,4 + or r12b,r11b + + vpcmpgtq ymm13,ymm9,YMMWORD[$L$mask52x4] + vmovmskpd r11d,ymm13 + vpcmpgtq ymm13,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd r10d,ymm13 + shl r10b,4 + or r11b,r10b + + vpcmpgtq ymm13,ymm11,YMMWORD[$L$mask52x4] + vmovmskpd r10d,ymm13 + vpcmpgtq ymm13,ymm12,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm13 + shl r9b,4 + or r10b,r9b + + add r14b,r14b + adc r13b,r13b + adc r12b,r12b + adc r11b,r11b + adc r10b,r10b + + + vpcmpeqq ymm13,ymm3,YMMWORD[$L$mask52x4] + vmovmskpd r9d,ymm13 + vpcmpeqq ymm13,ymm4,YMMWORD[$L$mask52x4] + vmovmskpd r8d,ymm13 + shl r8b,4 + or r9b,r8b + + vpcmpeqq ymm13,ymm5,YMMWORD[$L$mask52x4] + vmovmskpd r8d,ymm13 + vpcmpeqq ymm13,ymm6,YMMWORD[$L$mask52x4] + vmovmskpd edx,ymm13 + shl dl,4 + or r8b,dl + + vpcmpeqq ymm13,ymm7,YMMWORD[$L$mask52x4] + vmovmskpd edx,ymm13 + vpcmpeqq ymm13,ymm8,YMMWORD[$L$mask52x4] + vmovmskpd ecx,ymm13 + shl cl,4 + or dl,cl + + vpcmpeqq ymm13,ymm9,YMMWORD[$L$mask52x4] + vmovmskpd ecx,ymm13 + vpcmpeqq ymm13,ymm10,YMMWORD[$L$mask52x4] + vmovmskpd ebx,ymm13 + shl bl,4 + or cl,bl + + vpcmpeqq ymm13,ymm11,YMMWORD[$L$mask52x4] + vmovmskpd ebx,ymm13 + vpcmpeqq ymm13,ymm12,YMMWORD[$L$mask52x4] + vmovmskpd eax,ymm13 + shl al,4 + or bl,al + + add r14b,r9b + adc r13b,r8b + adc r12b,dl + adc r11b,cl + adc r10b,bl + + xor r14b,r9b + xor r13b,r8b + xor r12b,dl + xor r11b,cl + xor r10b,bl + + push r9 + push r8 + + lea r8,[$L$kmasklut] + + mov r9b,r14b + and r14,0xf + vpsubq ymm13,ymm3,YMMWORD[$L$mask52x4] + shl r14,5 + vmovapd ymm14,YMMWORD[r14*1+r8] + vblendvpd ymm3,ymm3,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm4,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm4,ymm4,ymm13,ymm14 + + mov r9b,r13b + and r13,0xf + vpsubq ymm13,ymm5,YMMWORD[$L$mask52x4] + shl r13,5 + vmovapd ymm14,YMMWORD[r13*1+r8] + vblendvpd ymm5,ymm5,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm6,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm6,ymm6,ymm13,ymm14 + + mov r9b,r12b + and r12,0xf + vpsubq ymm13,ymm7,YMMWORD[$L$mask52x4] + shl r12,5 + vmovapd ymm14,YMMWORD[r12*1+r8] + vblendvpd ymm7,ymm7,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm8,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm8,ymm8,ymm13,ymm14 + + mov r9b,r11b + and r11,0xf + vpsubq ymm13,ymm9,YMMWORD[$L$mask52x4] + shl r11,5 + vmovapd ymm14,YMMWORD[r11*1+r8] + vblendvpd ymm9,ymm9,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm10,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm10,ymm10,ymm13,ymm14 + + mov r9b,r10b + and r10,0xf + vpsubq ymm13,ymm11,YMMWORD[$L$mask52x4] + shl r10,5 + vmovapd ymm14,YMMWORD[r10*1+r8] + vblendvpd ymm11,ymm11,ymm13,ymm14 + + shr r9b,4 + and r9,0xf + vpsubq ymm13,ymm12,YMMWORD[$L$mask52x4] + shl r9,5 + vmovapd ymm14,YMMWORD[r9*1+r8] + vblendvpd ymm12,ymm12,ymm13,ymm14 + + pop r8 + pop r9 + + vpand ymm3,ymm3,YMMWORD[$L$mask52x4] + vpand ymm4,ymm4,YMMWORD[$L$mask52x4] + vpand ymm5,ymm5,YMMWORD[$L$mask52x4] + vpand ymm6,ymm6,YMMWORD[$L$mask52x4] + vpand ymm7,ymm7,YMMWORD[$L$mask52x4] + vpand ymm8,ymm8,YMMWORD[$L$mask52x4] + vpand ymm9,ymm9,YMMWORD[$L$mask52x4] + + vpand ymm10,ymm10,YMMWORD[$L$mask52x4] + vpand ymm11,ymm11,YMMWORD[$L$mask52x4] + vpand ymm12,ymm12,YMMWORD[$L$mask52x4] + + vmovdqu YMMWORD[320+rdi],ymm3 + vmovdqu YMMWORD[352+rdi],ymm4 + vmovdqu YMMWORD[384+rdi],ymm5 + vmovdqu YMMWORD[416+rdi],ymm6 + vmovdqu YMMWORD[448+rdi],ymm7 + vmovdqu YMMWORD[480+rdi],ymm8 + vmovdqu YMMWORD[512+rdi],ymm9 + vmovdqu YMMWORD[544+rdi],ymm10 + vmovdqu YMMWORD[576+rdi],ymm11 + vmovdqu YMMWORD[608+rdi],ymm12 + + vzeroupper + lea rax,[rsp] + + vmovapd xmm6,XMMWORD[rax] + vmovapd xmm7,XMMWORD[16+rax] + vmovapd xmm8,XMMWORD[32+rax] + vmovapd xmm9,XMMWORD[48+rax] + vmovapd xmm10,XMMWORD[64+rax] + vmovapd xmm11,XMMWORD[80+rax] + vmovapd xmm12,XMMWORD[96+rax] + vmovapd xmm13,XMMWORD[112+rax] + vmovapd xmm14,XMMWORD[128+rax] + vmovapd xmm15,XMMWORD[144+rax] + lea rax,[168+rsp] + mov r15,QWORD[rax] + + mov r14,QWORD[8+rax] + + mov r13,QWORD[16+rax] + + mov r12,QWORD[24+rax] + + mov rbp,QWORD[32+rax] + + mov rbx,QWORD[40+rax] + + lea rsp,[48+rax] + +$L$ossl_rsaz_amm52x40_x2_avxifma256_epilogue: + mov rdi,QWORD[8+rsp] ;WIN64 epilogue + mov rsi,QWORD[16+rsp] + DB 0F3h,0C3h ;repret + +$L$SEH_end_ossl_rsaz_amm52x40_x2_avxifma256: +section .text code align=64 + + +ALIGN 32 +global ossl_extract_multiplier_2x40_win5_avx + +ossl_extract_multiplier_2x40_win5_avx: + +DB 243,15,30,250 + push rsi + push rdi + lea rsp,[((-168))+rsp] + vmovapd XMMWORD[rsp],xmm6 + vmovapd XMMWORD[16+rsp],xmm7 + vmovapd XMMWORD[32+rsp],xmm8 + vmovapd XMMWORD[48+rsp],xmm9 + vmovapd XMMWORD[64+rsp],xmm10 + vmovapd XMMWORD[80+rsp],xmm11 + vmovapd XMMWORD[96+rsp],xmm12 + vmovapd XMMWORD[112+rsp],xmm13 + vmovapd XMMWORD[128+rsp],xmm14 + vmovapd XMMWORD[144+rsp],xmm15 + vmovapd ymm14,YMMWORD[$L$ones] + vmovq xmm10,r8 + vpbroadcastq ymm12,xmm10 + vmovq xmm10,r9 + vpbroadcastq ymm13,xmm10 + lea rax,[20480+rdx] + + + mov r10,rdx + + + vpxor xmm0,xmm0,xmm0 + vmovapd ymm1,ymm0 + vmovapd ymm2,ymm0 + vmovapd ymm3,ymm0 + vmovapd ymm4,ymm0 + vmovapd ymm5,ymm0 + vmovapd ymm6,ymm0 + vmovapd ymm7,ymm0 + vmovapd ymm8,ymm0 + vmovapd ymm9,ymm0 + vpxor ymm11,ymm11,ymm11 +ALIGN 32 +$L$loop_0: + vpcmpeqq ymm15,ymm12,ymm11 + vmovdqu ymm10,YMMWORD[rdx] + + vblendvpd ymm0,ymm0,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[32+rdx] + + vblendvpd ymm1,ymm1,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[64+rdx] + + vblendvpd ymm2,ymm2,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[96+rdx] + + vblendvpd ymm3,ymm3,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[128+rdx] + + vblendvpd ymm4,ymm4,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[160+rdx] + + vblendvpd ymm5,ymm5,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[192+rdx] + + vblendvpd ymm6,ymm6,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[224+rdx] + + vblendvpd ymm7,ymm7,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[256+rdx] + + vblendvpd ymm8,ymm8,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[288+rdx] + + vblendvpd ymm9,ymm9,ymm10,ymm15 + vpaddq ymm11,ymm11,ymm14 + add rdx,640 + cmp rax,rdx + jne NEAR $L$loop_0 + vmovdqu YMMWORD[rcx],ymm0 + vmovdqu YMMWORD[32+rcx],ymm1 + vmovdqu YMMWORD[64+rcx],ymm2 + vmovdqu YMMWORD[96+rcx],ymm3 + vmovdqu YMMWORD[128+rcx],ymm4 + vmovdqu YMMWORD[160+rcx],ymm5 + vmovdqu YMMWORD[192+rcx],ymm6 + vmovdqu YMMWORD[224+rcx],ymm7 + vmovdqu YMMWORD[256+rcx],ymm8 + vmovdqu YMMWORD[288+rcx],ymm9 + mov rdx,r10 + vpxor ymm11,ymm11,ymm11 +ALIGN 32 +$L$loop_320: + vpcmpeqq ymm15,ymm13,ymm11 + vmovdqu ymm10,YMMWORD[320+rdx] + + vblendvpd ymm0,ymm0,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[352+rdx] + + vblendvpd ymm1,ymm1,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[384+rdx] + + vblendvpd ymm2,ymm2,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[416+rdx] + + vblendvpd ymm3,ymm3,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[448+rdx] + + vblendvpd ymm4,ymm4,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[480+rdx] + + vblendvpd ymm5,ymm5,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[512+rdx] + + vblendvpd ymm6,ymm6,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[544+rdx] + + vblendvpd ymm7,ymm7,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[576+rdx] + + vblendvpd ymm8,ymm8,ymm10,ymm15 + vmovdqu ymm10,YMMWORD[608+rdx] + + vblendvpd ymm9,ymm9,ymm10,ymm15 + vpaddq ymm11,ymm11,ymm14 + add rdx,640 + cmp rax,rdx + jne NEAR $L$loop_320 + vmovdqu YMMWORD[320+rcx],ymm0 + vmovdqu YMMWORD[352+rcx],ymm1 + vmovdqu YMMWORD[384+rcx],ymm2 + vmovdqu YMMWORD[416+rcx],ymm3 + vmovdqu YMMWORD[448+rcx],ymm4 + vmovdqu YMMWORD[480+rcx],ymm5 + vmovdqu YMMWORD[512+rcx],ymm6 + vmovdqu YMMWORD[544+rcx],ymm7 + vmovdqu YMMWORD[576+rcx],ymm8 + vmovdqu YMMWORD[608+rcx],ymm9 + vzeroupper + vmovapd xmm6,XMMWORD[rsp] + vmovapd xmm7,XMMWORD[16+rsp] + vmovapd xmm8,XMMWORD[32+rsp] + vmovapd xmm9,XMMWORD[48+rsp] + vmovapd xmm10,XMMWORD[64+rsp] + vmovapd xmm11,XMMWORD[80+rsp] + vmovapd xmm12,XMMWORD[96+rsp] + vmovapd xmm13,XMMWORD[112+rsp] + vmovapd xmm14,XMMWORD[128+rsp] + vmovapd xmm15,XMMWORD[144+rsp] + lea rsp,[168+rsp] + pop rdi + pop rsi + + DB 0F3h,0C3h ;repret + + +section .rdata rdata align=32 +ALIGN 32 +$L$ones: + DQ 1,1,1,1 +$L$zeros: + DQ 0,0,0,0 +EXTERN __imp_RtlVirtualUnwind + +ALIGN 16 +rsaz_avx_handler: + push rsi + push rdi + push rbx + push rbp + push r12 + push r13 + push r14 + push r15 + pushfq + sub rsp,64 + + mov rax,QWORD[120+r8] + mov rbx,QWORD[248+r8] + + mov rsi,QWORD[8+r9] + mov r11,QWORD[56+r9] + + mov r10d,DWORD[r11] + lea r10,[r10*1+rsi] + cmp rbx,r10 + jb NEAR $L$common_seh_tail + + mov r10d,DWORD[4+r11] + lea r10,[r10*1+rsi] + cmp rbx,r10 + jae NEAR $L$common_seh_tail + + mov rax,QWORD[152+r8] + + lea rsi,[rax] + lea rdi,[512+r8] + mov ecx,20 + DD 0xa548f3fc + + lea rax,[216+rax] + + mov rbx,QWORD[((-8))+rax] + mov rbp,QWORD[((-16))+rax] + mov r12,QWORD[((-24))+rax] + mov r13,QWORD[((-32))+rax] + mov r14,QWORD[((-40))+rax] + mov r15,QWORD[((-48))+rax] + mov QWORD[144+r8],rbx + mov QWORD[160+r8],rbp + mov QWORD[216+r8],r12 + mov QWORD[224+r8],r13 + mov QWORD[232+r8],r14 + mov QWORD[240+r8],r15 + +$L$common_seh_tail: + mov rdi,QWORD[8+rax] + mov rsi,QWORD[16+rax] + mov QWORD[152+r8],rax + mov QWORD[168+r8],rsi + mov QWORD[176+r8],rdi + + mov rdi,QWORD[40+r9] + mov rsi,r8 + mov ecx,154 + DD 0xa548f3fc + + mov rsi,r9 + xor rcx,rcx + mov rdx,QWORD[8+rsi] + mov r8,QWORD[rsi] + mov r9,QWORD[16+rsi] + mov r10,QWORD[40+rsi] + lea r11,[56+rsi] + lea r12,[24+rsi] + mov QWORD[32+rsp],r10 + mov QWORD[40+rsp],r11 + mov QWORD[48+rsp],r12 + mov QWORD[56+rsp],rcx + call QWORD[__imp_RtlVirtualUnwind] + + mov eax,1 + add rsp,64 + popfq + pop r15 + pop r14 + pop r13 + pop r12 + pop rbp + pop rbx + pop rdi + pop rsi + DB 0F3h,0C3h ;repret + + +section .pdata rdata align=4 +ALIGN 4 + DD $L$SEH_begin_ossl_rsaz_amm52x40_x1_avxifma256 wrt ..imagebase + DD $L$SEH_end_ossl_rsaz_amm52x40_x1_avxifma256 wrt ..imagebase + DD $L$SEH_info_ossl_rsaz_amm52x40_x1_avxifma256 wrt ..imagebase + + DD $L$SEH_begin_ossl_rsaz_amm52x40_x2_avxifma256 wrt ..imagebase + DD $L$SEH_end_ossl_rsaz_amm52x40_x2_avxifma256 wrt ..imagebase + DD $L$SEH_info_ossl_rsaz_amm52x40_x2_avxifma256 wrt ..imagebase + +section .xdata rdata align=8 +ALIGN 8 +$L$SEH_info_ossl_rsaz_amm52x40_x1_avxifma256: +DB 9,0,0,0 + DD rsaz_avx_handler wrt ..imagebase + DD $L$ossl_rsaz_amm52x40_x1_avxifma256_body wrt ..imagebase,$L$ossl_rsaz_amm52x40_x1_avxifma256_epilogue wrt ..imagebase +$L$SEH_info_ossl_rsaz_amm52x40_x2_avxifma256: +DB 9,0,0,0 + DD rsaz_avx_handler wrt ..imagebase + DD $L$ossl_rsaz_amm52x40_x2_avxifma256_body wrt ..imagebase,$L$ossl_rsaz_amm52x40_x2_avxifma256_epilogue wrt ..imagebase diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h index f653985f6f..a93829e440 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h @@ -206,9 +206,6 @@ extern "C" { # ifndef OPENSSL_NO_MDC2 # define OPENSSL_NO_MDC2 # endif -# ifndef OPENSSL_NO_ML_DSA -# define OPENSSL_NO_ML_DSA -# endif # ifndef OPENSSL_NO_ML_KEM # define OPENSSL_NO_ML_KEM # endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h index 7f933a7fe0..a42bd1b4c9 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h @@ -224,9 +224,6 @@ extern "C" { # ifndef OPENSSL_NO_MDC2 # define OPENSSL_NO_MDC2 # endif -# ifndef OPENSSL_NO_ML_DSA -# define OPENSSL_NO_ML_DSA -# endif # ifndef OPENSSL_NO_ML_KEM # define OPENSSL_NO_ML_KEM # endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ml_dsa_gen.c b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ml_dsa_gen.c index d4c6cfc61e..0a38912128 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ml_dsa_gen.c +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_ml_dsa_gen.c @@ -13,6 +13,7 @@ #include "prov/der_ml_dsa.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * id-ml-dsa-44 OBJECT IDENTIFIER ::= { sigAlgs 17 } @@ -35,3 +36,4 @@ const unsigned char ossl_der_oid_id_ml_dsa_87[DER_OID_SZ_id_ml_dsa_87] = { DER_OID_V_id_ml_dsa_87 }; +/* clang-format on */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ml_dsa.h b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ml_dsa.h index 636054f781..4a202ee0bd 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ml_dsa.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_ml_dsa.h @@ -14,6 +14,7 @@ #include "crypto/ml_dsa.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * id-ml-dsa-44 OBJECT IDENTIFIER ::= { sigAlgs 17 } @@ -36,5 +37,6 @@ extern const unsigned char ossl_der_oid_id_ml_dsa_65[DER_OID_SZ_id_ml_dsa_65]; #define DER_OID_SZ_id_ml_dsa_87 11 extern const unsigned char ossl_der_oid_id_ml_dsa_87[DER_OID_SZ_id_ml_dsa_87]; +/* clang-format on */ int ossl_DER_w_algorithmIdentifier_ML_DSA(WPACKET *pkt, int tag, ML_DSA_KEY *key); diff --git a/CryptoPkg/Library/OpensslLib/OpensslLib.inf b/CryptoPkg/Library/OpensslLib/OpensslLib.inf index 02513ce2f7..66df768cf5 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLib.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLib.inf @@ -363,6 +363,14 @@ $(OPENSSL_PATH)/crypto/md5/md5_dgst.c $(OPENSSL_PATH)/crypto/md5/md5_one.c $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_encoders.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key_compress.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_matrix.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_ntt.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_params.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sample.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sign.c $(OPENSSL_PATH)/crypto/modes/cbc128.c $(OPENSSL_PATH)/crypto/modes/ccm128.c $(OPENSSL_PATH)/crypto/modes/cfb128.c @@ -607,6 +615,8 @@ $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_common_codecs.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_dsa_codecs.c $(OPENSSL_PATH)/providers/implementations/exchange/dh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/kdf_exch.c $(OPENSSL_PATH)/providers/implementations/kdfs/argon2.c @@ -626,6 +636,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/dh_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c @@ -642,11 +653,13 @@ $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_unix.c $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_win.c $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c $(OPENSSL_GEN_PATH)/crypto/params_idx.c + $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c @@ -660,6 +673,7 @@ $(OPENSSL_PATH)/providers/implementations/digests/digestcommon.c $(OPENSSL_PATH)/ssl/record/methods/tls_pad.c $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf index b723ec5c6e..4ba73af89c 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf @@ -383,6 +383,14 @@ $(OPENSSL_PATH)/crypto/md5/md5_dgst.c $(OPENSSL_PATH)/crypto/md5/md5_one.c $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_encoders.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key_compress.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_matrix.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_ntt.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_params.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sample.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sign.c $(OPENSSL_PATH)/crypto/modes/cbc128.c $(OPENSSL_PATH)/crypto/modes/ccm128.c $(OPENSSL_PATH)/crypto/modes/cfb128.c @@ -627,6 +635,8 @@ $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_common_codecs.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_dsa_codecs.c $(OPENSSL_PATH)/providers/implementations/exchange/dh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/kdf_exch.c $(OPENSSL_PATH)/providers/implementations/kdfs/argon2.c @@ -646,6 +656,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/dh_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c @@ -662,11 +673,13 @@ $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_unix.c $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_win.c $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c $(OPENSSL_GEN_PATH)/crypto/params_idx.c + $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c @@ -680,6 +693,7 @@ $(OPENSSL_PATH)/providers/implementations/digests/digestcommon.c $(OPENSSL_PATH)/ssl/record/methods/tls_pad.c $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c @@ -1088,6 +1102,14 @@ $(OPENSSL_PATH)/crypto/md5/md5_dgst.c $(OPENSSL_PATH)/crypto/md5/md5_one.c $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_encoders.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key_compress.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_matrix.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_ntt.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_params.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sample.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sign.c $(OPENSSL_PATH)/crypto/modes/cbc128.c $(OPENSSL_PATH)/crypto/modes/ccm128.c $(OPENSSL_PATH)/crypto/modes/cfb128.c @@ -1331,6 +1353,8 @@ $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_common_codecs.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_dsa_codecs.c $(OPENSSL_PATH)/providers/implementations/exchange/dh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/kdf_exch.c $(OPENSSL_PATH)/providers/implementations/kdfs/argon2.c @@ -1350,6 +1374,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/dh_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c @@ -1366,11 +1391,13 @@ $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_unix.c $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_win.c $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c $(OPENSSL_GEN_PATH)/crypto/params_idx.c + $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c @@ -1384,6 +1411,7 @@ $(OPENSSL_PATH)/providers/implementations/digests/digestcommon.c $(OPENSSL_PATH)/ssl/record/methods/tls_pad.c $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c @@ -1813,6 +1841,14 @@ $(OPENSSL_PATH)/crypto/md5/md5_dgst.c $(OPENSSL_PATH)/crypto/md5/md5_one.c $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_encoders.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key_compress.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_matrix.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_ntt.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_params.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sample.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sign.c $(OPENSSL_PATH)/crypto/modes/cbc128.c $(OPENSSL_PATH)/crypto/modes/ccm128.c $(OPENSSL_PATH)/crypto/modes/cfb128.c @@ -2056,6 +2092,8 @@ $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_common_codecs.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_dsa_codecs.c $(OPENSSL_PATH)/providers/implementations/exchange/dh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/kdf_exch.c $(OPENSSL_PATH)/providers/implementations/kdfs/argon2.c @@ -2075,6 +2113,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/dh_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c @@ -2091,11 +2130,13 @@ $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_unix.c $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_win.c $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c $(OPENSSL_GEN_PATH)/crypto/params_idx.c + $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c @@ -2109,6 +2150,7 @@ $(OPENSSL_PATH)/providers/implementations/digests/digestcommon.c $(OPENSSL_PATH)/ssl/record/methods/tls_pad.c $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf b/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf index 3281a4ea40..d09d2b6ad8 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf @@ -364,6 +364,14 @@ $(OPENSSL_PATH)/crypto/md5/md5_dgst.c $(OPENSSL_PATH)/crypto/md5/md5_one.c $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_encoders.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key_compress.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_matrix.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_ntt.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_params.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sample.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sign.c $(OPENSSL_PATH)/crypto/modes/cbc128.c $(OPENSSL_PATH)/crypto/modes/ccm128.c $(OPENSSL_PATH)/crypto/modes/cfb128.c @@ -608,6 +616,8 @@ $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_common_codecs.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_dsa_codecs.c $(OPENSSL_PATH)/providers/implementations/exchange/dh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/kdf_exch.c $(OPENSSL_PATH)/providers/implementations/kdfs/argon2.c @@ -627,6 +637,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/dh_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c @@ -643,11 +654,13 @@ $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_unix.c $(OPENSSL_PATH)/providers/implementations/rands/seeding/rand_win.c $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c $(OPENSSL_GEN_PATH)/crypto/params_idx.c + $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c @@ -661,6 +674,7 @@ $(OPENSSL_PATH)/providers/implementations/digests/digestcommon.c $(OPENSSL_PATH)/ssl/record/methods/tls_pad.c $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c # Autogenerated files list ends here diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf b/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf index 8563cdbae7..07e8e729d5 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf @@ -415,6 +415,14 @@ $(OPENSSL_PATH)/crypto/md5/md5_dgst.c $(OPENSSL_PATH)/crypto/md5/md5_one.c $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_encoders.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key_compress.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_matrix.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_ntt.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_params.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sample.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sign.c $(OPENSSL_PATH)/crypto/modes/cbc128.c $(OPENSSL_PATH)/crypto/modes/ccm128.c $(OPENSSL_PATH)/crypto/modes/cfb128.c @@ -661,6 +669,8 @@ $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_common_codecs.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_dsa_codecs.c $(OPENSSL_PATH)/providers/implementations/exchange/dh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/ecdh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/ecx_exch.c @@ -687,6 +697,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/ecx_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c @@ -706,6 +717,7 @@ $(OPENSSL_PATH)/providers/implementations/signature/ecdsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/eddsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c @@ -714,6 +726,7 @@ $(OPENSSL_PATH)/providers/common/der/der_ec_key.c $(OPENSSL_PATH)/providers/common/der/der_ec_sig.c $(OPENSSL_PATH)/providers/common/der/der_ecx_key.c + $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c @@ -729,6 +742,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ec_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ecx_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf index 1762e81c4f..3812eb6b68 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf @@ -431,6 +431,14 @@ $(OPENSSL_PATH)/crypto/md5/md5_dgst.c $(OPENSSL_PATH)/crypto/md5/md5_one.c $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_encoders.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key_compress.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_matrix.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_ntt.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_params.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sample.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sign.c $(OPENSSL_PATH)/crypto/modes/cbc128.c $(OPENSSL_PATH)/crypto/modes/ccm128.c $(OPENSSL_PATH)/crypto/modes/cfb128.c @@ -677,6 +685,8 @@ $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_common_codecs.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_dsa_codecs.c $(OPENSSL_PATH)/providers/implementations/exchange/dh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/ecdh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/ecx_exch.c @@ -703,6 +713,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/ecx_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c @@ -722,6 +733,7 @@ $(OPENSSL_PATH)/providers/implementations/signature/ecdsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/eddsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c @@ -730,6 +742,7 @@ $(OPENSSL_PATH)/providers/common/der/der_ec_key.c $(OPENSSL_PATH)/providers/common/der/der_ec_sig.c $(OPENSSL_PATH)/providers/common/der/der_ecx_key.c + $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c @@ -745,6 +758,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ec_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ecx_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c @@ -1200,6 +1214,14 @@ $(OPENSSL_PATH)/crypto/md5/md5_dgst.c $(OPENSSL_PATH)/crypto/md5/md5_one.c $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_encoders.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key_compress.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_matrix.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_ntt.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_params.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sample.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sign.c $(OPENSSL_PATH)/crypto/modes/cbc128.c $(OPENSSL_PATH)/crypto/modes/ccm128.c $(OPENSSL_PATH)/crypto/modes/cfb128.c @@ -1445,6 +1467,8 @@ $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_common_codecs.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_dsa_codecs.c $(OPENSSL_PATH)/providers/implementations/exchange/dh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/ecdh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/ecx_exch.c @@ -1471,6 +1495,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/ecx_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c @@ -1490,6 +1515,7 @@ $(OPENSSL_PATH)/providers/implementations/signature/ecdsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/eddsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c @@ -1498,6 +1524,7 @@ $(OPENSSL_PATH)/providers/common/der/der_ec_key.c $(OPENSSL_PATH)/providers/common/der/der_ec_sig.c $(OPENSSL_PATH)/providers/common/der/der_ecx_key.c + $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c @@ -1513,6 +1540,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ec_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ecx_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c @@ -1991,6 +2019,14 @@ $(OPENSSL_PATH)/crypto/md5/md5_dgst.c $(OPENSSL_PATH)/crypto/md5/md5_one.c $(OPENSSL_PATH)/crypto/md5/md5_sha1.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_encoders.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_key_compress.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_matrix.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_ntt.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_params.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sample.c + $(OPENSSL_PATH)/crypto/ml_dsa/ml_dsa_sign.c $(OPENSSL_PATH)/crypto/modes/cbc128.c $(OPENSSL_PATH)/crypto/modes/ccm128.c $(OPENSSL_PATH)/crypto/modes/cfb128.c @@ -2236,6 +2272,8 @@ $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_pvk2key.c $(OPENSSL_PATH)/providers/implementations/encode_decode/decode_spki2typespki.c $(OPENSSL_PATH)/providers/implementations/encode_decode/endecoder_common.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_common_codecs.c + $(OPENSSL_PATH)/providers/implementations/encode_decode/ml_dsa_codecs.c $(OPENSSL_PATH)/providers/implementations/exchange/dh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/ecdh_exch.c $(OPENSSL_PATH)/providers/implementations/exchange/ecx_exch.c @@ -2262,6 +2300,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/ecx_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/kdf_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c @@ -2281,6 +2320,7 @@ $(OPENSSL_PATH)/providers/implementations/signature/ecdsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/eddsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c @@ -2289,6 +2329,7 @@ $(OPENSSL_PATH)/providers/common/der/der_ec_key.c $(OPENSSL_PATH)/providers/common/der/der_ec_sig.c $(OPENSSL_PATH)/providers/common/der/der_ecx_key.c + $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c @@ -2304,6 +2345,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ec_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ecx_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c diff --git a/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c b/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c index 0eece3a337..ef4d4375ab 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c +++ b/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c @@ -200,6 +200,9 @@ static const OSSL_ALGORITHM deflt_signature[] = { { PROV_NAMES_ECDSA, "provider=default", ossl_ecdsa_signature_functions }, #endif { PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_hmac_signature_functions }, +#ifndef OPENSSL_NO_ML_DSA + { PROV_NAMES_ML_DSA_87, "provider=default", ossl_ml_dsa_87_signature_functions }, +#endif { NULL, NULL, NULL } }; @@ -235,6 +238,10 @@ static const OSSL_ALGORITHM deflt_keymgmt[] = { PROV_DESCS_HKDF_SIGN }, { PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_keymgmt_functions, PROV_DESCS_HMAC_SIGN }, +#ifndef OPENSSL_NO_ML_DSA + { PROV_NAMES_ML_DSA_87, "provider=default", ossl_ml_dsa_87_keymgmt_functions, + PROV_DESCS_ML_DSA_87 }, +#endif { NULL, NULL, NULL } }; diff --git a/CryptoPkg/Library/OpensslLib/configure.py b/CryptoPkg/Library/OpensslLib/configure.py index d82eb98d2d..e92fc721b1 100755 --- a/CryptoPkg/Library/OpensslLib/configure.py +++ b/CryptoPkg/Library/OpensslLib/configure.py @@ -51,7 +51,6 @@ def openssl_configure(openssldir, target, ec = True, lite = True): 'no-module', 'no-md4', 'no-mdc2', - 'no-ml-dsa', 'no-ml-kem', 'no-multiblock', 'no-nextprotoneg', @@ -94,7 +93,7 @@ def openssl_configure(openssldir, target, ec = True, lite = True): if not ec: cmdline += [ 'no-ec', 'no-camellia', 'no-cmac' ] if lite: - cmdline += [ 'no-camellia', 'no-dh', 'no-ecx'] + cmdline += [ 'no-camellia', 'no-dh', 'no-ecx', 'no-ml-dsa' ] print('') print(f'# -*- configure openssl for {target} (ec={ec}, lite={lite}) -*-') rc = subprocess.run(cmdline, cwd = openssldir, diff --git a/CryptoPkg/Private/Protocol/Crypto.h b/CryptoPkg/Private/Protocol/Crypto.h index 542a9c75d7..3b6190362c 100644 --- a/CryptoPkg/Private/Protocol/Crypto.h +++ b/CryptoPkg/Private/Protocol/Crypto.h @@ -21,7 +21,7 @@ /// the EDK II Crypto Protocol is extended, this version define must be /// increased. /// -#define EDKII_CRYPTO_VERSION 25 +#define EDKII_CRYPTO_VERSION 26 /// /// EDK II Crypto Protocol forward declaration @@ -6165,6 +6165,300 @@ BOOLEAN IN UINTN SigSize ); +/** + Creates a new ML-DSA context by Crypto NID. + + This function allocates and initializes a new ML-DSA context for the specified + ML-DSA variant. The context contains an EVP_PKEY structure initialized with the + ML-DSA parameters. The caller must call MlDsaFree() to release the context when done. + + Before keys can be used for signing or verification, they must be set using + MlDsaSetPrivKey() or MlDsaSetPubKey(). + + If Nid is not a supported ML-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the ML-DSA variant (e.g., CRYPTO_NID_ML_DSA_87). + + @retval Pointer to new ML-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +typedef +VOID * +(EFIAPI *EDKII_CRYPTO_ML_DSA_NEW_BY_NID)( + IN UINTN Nid + ); + +/** + Frees an ML-DSA context and all associated resources. + + This function releases all memory associated with the ML-DSA context, including + the EVP_PKEY structure. After calling this function, the MlDsaContext pointer + should not be used. + + If MlDsaContext is NULL, then this function returns immediately without action. + + @param[in] MlDsaContext Pointer to the ML-DSA context to be released. + +**/ +typedef +VOID +(EFIAPI *EDKII_CRYPTO_ML_DSA_FREE)( + IN VOID *MlDsaContext + ); + +/** + Retrieves the ML-DSA public key from the ML-DSA context. + + This function extracts the public key from the ML-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via MlDsaSetPrivKey() or MlDsaSetPubKey()) + before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE ML-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ML_DSA_GET_PUB_KEY)( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ); + +/** + Sets the ML-DSA public key in the ML-DSA context. + + This function imports a raw public key into the ML-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (2592 bytes for ML-DSA-87). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If MlDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is 0, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE ML-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ML_DSA_SET_PUB_KEY)( + IN VOID *MlDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Sets the ML-DSA private key in the ML-DSA context. + + This function imports a raw private key into the ML-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the ML-DSA variant (4896 bytes for ML-DSA-87). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If MlDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize is 0, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] MlDsaContext Pointer to ML-DSA context created by MlDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE ML-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ML_DSA_SET_PRIV_KEY)( + IN VOID *MlDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ); + +/** + Generates and retrieves the public key from a private key context. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ML_DSA_GENERATE_PUB_KEY)( + IN VOID *MlDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Retrieve the ML-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contain the retrieved + ML-DSA public key component. Use MlDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @retval TRUE ML-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve ML-DSA public key from X509 certificate. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ML_DSA_GET_PUBLIC_KEY_FROM_X509)( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **MlDsaContext + ); + +/** + Retrieve the ML-DSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] MlDsaContext Pointer to new-generated ML-DSA context which contains the retrieved + ML-DSA private key component. Use MlDsaFree() function to free the + resource. + + If PemData is NULL, then return FALSE. + If MlDsaContext is NULL, then return FALSE. + + @retval TRUE ML-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ML_DSA_GET_PRIVATE_KEY_FROM_PEM)( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **MlDsaContext + ); + +/** + Generates an ML-DSA signature for a given message. + + This function creates an ML-DSA signature using the private key stored in the + ML-DSA context. ML-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via MlDsaSetPrivKey() or loaded + from PEM) before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0 or exceeds INT_MAX, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] MlDsaContext Pointer to ML-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (4627 bytes for ML-DSA-87). + + @retval TRUE ML-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ML_DSA_SIGN)( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ); + +/** + Verifies the ML-DSA signature for a given message. + + This function verifies an ML-DSA signature against a message using the public key + contained in the ML-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via MlDsaSetPrivKey() + or MlDsaSetPubKey() before calling this function. + + If MlDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + If SigSize does not match expected signature size for the variant, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] MlDsaContext Pointer to ML-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the ML-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + Must match variant size (4627 bytes for ML-DSA-87). + + @retval TRUE ML-DSA signature verification succeeded. + @retval FALSE ML-DSA signature verification failed or invalid parameters. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_ML_DSA_VERIFY)( + IN VOID *MlDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ); + /// /// EDK II Crypto Protocol /// @@ -6488,6 +6782,17 @@ struct _EDKII_CRYPTO_PROTOCOL { EDKII_CRYPTO_ED_DSA_GET_PRIVATE_KEY_FROM_PEM EdDsaGetPrivateKeyFromPem; EDKII_CRYPTO_ED_DSA_SIGN EdDsaSign; EDKII_CRYPTO_ED_DSA_VERIFY EdDsaVerify; + /// ML-DSA + EDKII_CRYPTO_ML_DSA_NEW_BY_NID MlDsaNewByNid; + EDKII_CRYPTO_ML_DSA_FREE MlDsaFree; + EDKII_CRYPTO_ML_DSA_SET_PRIV_KEY MlDsaSetPrivKey; + EDKII_CRYPTO_ML_DSA_GENERATE_PUB_KEY MlDsaGeneratePubKey; + EDKII_CRYPTO_ML_DSA_SET_PUB_KEY MlDsaSetPubKey; + EDKII_CRYPTO_ML_DSA_GET_PUB_KEY MlDsaGetPubKey; + EDKII_CRYPTO_ML_DSA_GET_PUBLIC_KEY_FROM_X509 MlDsaGetPublicKeyFromX509; + EDKII_CRYPTO_ML_DSA_GET_PRIVATE_KEY_FROM_PEM MlDsaGetPrivateKeyFromPem; + EDKII_CRYPTO_ML_DSA_SIGN MlDsaSign; + EDKII_CRYPTO_ML_DSA_VERIFY MlDsaVerify; }; extern GUID gEdkiiCryptoProtocolGuid; diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c index f95bf4ff97..8ce8acdb4f 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c @@ -30,6 +30,7 @@ SUITE_DESC mSuiteDesc[] = { { "Bn verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mBnTestNum, mBnTest }, { "EC verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mEcTestNum, mEcTest }, { "ED-DSA verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mEdDsaTestNum, mEdDsaTest }, + { "ML-DSA verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mMlDsaTestNum, mMlDsaTest }, { "X509 Verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mX509TestNum, mX509Test }, { "PKCS7 Attach Content tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mPkcs7ContentTestNum, mPkcs7ContentTest }, }; diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/MlDsaTestVectors.h b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/MlDsaTestVectors.h new file mode 100644 index 0000000000..dd3608b8c3 --- /dev/null +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/MlDsaTestVectors.h @@ -0,0 +1,1238 @@ +/** @file + ML-DSA Test Vectors + + This file contains test vectors for ML-DSA-87 cryptographic operations. + The vectors include: + - mMlDsa87TestCert: X.509 DER certificate containing ML-DSA-87 public key + - mMlDsa87TestPemKey: PEM-encoded ML-DSA-87 private key + + IMPORTANT: These test vectors form a MATCHING KEY PAIR. The certificate + was generated from the private key in the PEM file, ensuring that: + - Signatures created with the private key can be verified with the public key + - Test operations using both keys will succeed + + Generated: 2026-07-01 + OpenSSL Version: 3.5.5 + +Copyright (c) 2026, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +// PEM key size: 6774 bytes +// DER cert size: 7650 bytes + +// +// mldsa87_cert.der as C array +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mMlDsa87TestCert[] = { + 0x30, 0x82, 0x1d, 0xde, 0x30, 0x82, 0x0b, 0xb5, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x14, 0x38, 0xcf, 0x9f, 0xae, 0x89, 0xda, 0x7a, 0x0e, 0x8b, + 0xc0, 0xdf, 0xc1, 0xb4, 0x52, 0x5b, 0x1c, 0x99, 0xdd, 0x12, 0x3c, 0x30, + 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x13, + 0x30, 0x6f, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, + 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, + 0x0c, 0x09, 0x54, 0x65, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, + 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x08, 0x54, 0x65, + 0x73, 0x74, 0x43, 0x69, 0x74, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, + 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4f, 0x72, 0x67, + 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x08, 0x54, + 0x65, 0x73, 0x74, 0x55, 0x6e, 0x69, 0x74, 0x31, 0x14, 0x30, 0x12, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0b, 0x4d, 0x4c, 0x44, 0x53, 0x41, 0x38, + 0x37, 0x54, 0x65, 0x73, 0x74, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x36, 0x30, + 0x37, 0x30, 0x31, 0x31, 0x34, 0x32, 0x37, 0x31, 0x32, 0x5a, 0x17, 0x0d, + 0x32, 0x37, 0x30, 0x37, 0x30, 0x31, 0x31, 0x34, 0x32, 0x37, 0x31, 0x32, + 0x5a, 0x30, 0x6f, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, + 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, + 0x08, 0x0c, 0x09, 0x54, 0x65, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, + 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x08, 0x54, + 0x65, 0x73, 0x74, 0x43, 0x69, 0x74, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, + 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4f, 0x72, + 0x67, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x08, + 0x54, 0x65, 0x73, 0x74, 0x55, 0x6e, 0x69, 0x74, 0x31, 0x14, 0x30, 0x12, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0b, 0x4d, 0x4c, 0x44, 0x53, 0x41, + 0x38, 0x37, 0x54, 0x65, 0x73, 0x74, 0x30, 0x82, 0x0a, 0x32, 0x30, 0x0b, + 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x13, 0x03, + 0x82, 0x0a, 0x21, 0x00, 0x93, 0xc8, 0x44, 0x6b, 0x36, 0x23, 0x79, 0x73, + 0x6a, 0x20, 0xf3, 0xd1, 0x72, 0xa2, 0xca, 0x58, 0x53, 0x62, 0x7e, 0x43, + 0x77, 0x4e, 0x2c, 0xb8, 0xbd, 0x8d, 0xd5, 0xe7, 0x98, 0xb1, 0xa1, 0x71, + 0xcb, 0x96, 0xc3, 0x64, 0xb3, 0x1e, 0xf3, 0x06, 0x7e, 0x7b, 0x33, 0x52, + 0x6e, 0xc0, 0xc7, 0x83, 0xb7, 0x65, 0x24, 0x17, 0x4e, 0x83, 0xb1, 0xc3, + 0x7a, 0x27, 0xc8, 0x78, 0x62, 0x5e, 0x13, 0xe7, 0x68, 0x5e, 0xf9, 0xc7, + 0xcf, 0xac, 0xf8, 0x07, 0xb8, 0xa0, 0x9b, 0x43, 0x22, 0x06, 0x66, 0x9c, + 0xe0, 0xc7, 0xca, 0x3e, 0x10, 0x7c, 0x15, 0x5c, 0xcc, 0xef, 0x85, 0x29, + 0xd5, 0x67, 0x9f, 0x9c, 0x42, 0xf3, 0xdf, 0x85, 0x67, 0xfe, 0xad, 0x87, + 0x8f, 0x64, 0xa0, 0x46, 0x74, 0x58, 0x66, 0xa3, 0x53, 0xec, 0xc3, 0xab, + 0xd4, 0xe7, 0xe8, 0xa6, 0xfa, 0xb5, 0x3c, 0x1a, 0x4d, 0x09, 0xe2, 0x8c, + 0xeb, 0x81, 0x39, 0xc4, 0x19, 0x4f, 0x7f, 0xbc, 0x9c, 0xb4, 0x1c, 0x80, + 0x7b, 0x46, 0x16, 0x79, 0x67, 0xf1, 0xcc, 0xcf, 0xb9, 0x72, 0xc1, 0x01, + 0x47, 0x5b, 0x2e, 0x42, 0x2a, 0xb0, 0x79, 0x57, 0xd2, 0xeb, 0x41, 0x07, + 0xd0, 0xd7, 0x3c, 0xc3, 0x27, 0xbc, 0xff, 0x1e, 0xa5, 0x98, 0x89, 0xef, + 0x34, 0x2c, 0x27, 0x19, 0x2a, 0x2d, 0xdb, 0x89, 0xd2, 0x30, 0x5e, 0xc2, + 0x47, 0x2d, 0xa7, 0x9d, 0x7a, 0xa5, 0x25, 0xb8, 0x50, 0x58, 0x53, 0xfd, + 0x27, 0x12, 0x6e, 0x86, 0x65, 0x1e, 0xb6, 0x07, 0x3c, 0x44, 0x99, 0x56, + 0x7a, 0xa9, 0x41, 0x2c, 0x97, 0xb0, 0x1c, 0x96, 0xa1, 0xc1, 0x67, 0x72, + 0xa8, 0x3c, 0x1c, 0xf2, 0x1c, 0x06, 0x0d, 0x58, 0x5b, 0xf9, 0x49, 0xe1, + 0xa6, 0xf6, 0x24, 0xfe, 0x53, 0xcf, 0xfa, 0x5f, 0x38, 0xfe, 0xa8, 0x25, + 0x21, 0x8a, 0xfc, 0x05, 0x15, 0x83, 0x54, 0xac, 0xae, 0xc3, 0x61, 0x0f, + 0x73, 0xca, 0xd8, 0xae, 0x34, 0x77, 0x59, 0x9f, 0x36, 0xca, 0xe3, 0x69, + 0x25, 0xef, 0x09, 0xd0, 0xdc, 0xa8, 0x5b, 0x21, 0x93, 0xc7, 0x48, 0x09, + 0xef, 0x20, 0x18, 0x52, 0x78, 0x4b, 0xe6, 0x84, 0xa5, 0xb3, 0xd1, 0x8d, + 0x2f, 0x93, 0xb0, 0x78, 0xbc, 0x6c, 0xe7, 0xc3, 0x29, 0xfc, 0xe9, 0xd8, + 0xbe, 0xd1, 0x7c, 0x5b, 0xc2, 0x0b, 0x0b, 0xc2, 0xa0, 0xef, 0xb8, 0x82, + 0x6c, 0x00, 0x5a, 0x33, 0xe7, 0x8e, 0x84, 0x81, 0x6e, 0x61, 0x99, 0xa7, + 0x79, 0x4f, 0x0b, 0x56, 0x5b, 0x09, 0x9a, 0x26, 0xca, 0xc8, 0xa6, 0xd7, + 0xd2, 0x37, 0x9c, 0x73, 0xa7, 0xec, 0xfb, 0x63, 0x3b, 0x78, 0x5f, 0xd3, + 0x9b, 0x82, 0xce, 0xc3, 0xea, 0x91, 0x30, 0xe6, 0x4a, 0xd7, 0xd2, 0x6c, + 0x1f, 0x63, 0xda, 0x0d, 0x47, 0x91, 0x18, 0x72, 0x78, 0x8e, 0xb7, 0x38, + 0xff, 0x7b, 0xb7, 0x60, 0x02, 0x07, 0xfc, 0x64, 0xd3, 0x36, 0xf5, 0xd5, + 0x73, 0x18, 0x93, 0xe0, 0xa6, 0x84, 0xf7, 0x89, 0x86, 0xf3, 0xc7, 0xc2, + 0xc7, 0x86, 0x59, 0xc5, 0x99, 0x00, 0x75, 0xb3, 0x38, 0x8d, 0x36, 0x57, + 0x94, 0x71, 0x76, 0xad, 0x55, 0x2d, 0x4d, 0x7d, 0xde, 0xb3, 0x79, 0xd4, + 0xf7, 0xb4, 0xd4, 0x14, 0x64, 0x5d, 0x29, 0x61, 0xe0, 0x2f, 0x4d, 0xc4, + 0x48, 0x95, 0x82, 0x32, 0xac, 0x12, 0x64, 0xde, 0xa1, 0x13, 0xf6, 0x59, + 0x66, 0x8f, 0x00, 0x64, 0xf2, 0x36, 0x2d, 0x45, 0x44, 0x3f, 0xf3, 0xcb, + 0x2e, 0xa7, 0x18, 0xc6, 0x96, 0x60, 0xf3, 0x87, 0xc7, 0xa7, 0x6c, 0x90, + 0x22, 0xb6, 0x87, 0xec, 0xd5, 0xaa, 0xad, 0x05, 0x35, 0x6b, 0x36, 0xb3, + 0x82, 0x03, 0x51, 0x8e, 0x82, 0x2d, 0xfc, 0x39, 0xe5, 0x35, 0x51, 0xfb, + 0xb9, 0x3a, 0x69, 0x4f, 0x8c, 0x3d, 0xd9, 0x55, 0x72, 0x59, 0x3d, 0x91, + 0x09, 0x28, 0x94, 0x3f, 0x8e, 0xab, 0xbc, 0xb7, 0x32, 0xad, 0xf9, 0xf9, + 0x31, 0x9a, 0xa7, 0x1b, 0x1e, 0x92, 0x6e, 0xa5, 0x6d, 0xc3, 0x39, 0xca, + 0x63, 0xbb, 0x45, 0x0a, 0x38, 0x93, 0xbe, 0x1d, 0x59, 0x65, 0xea, 0x1e, + 0x53, 0x0e, 0xe1, 0x8c, 0x85, 0xcf, 0x9a, 0x3e, 0xdb, 0xca, 0xb5, 0xfc, + 0x0b, 0xd4, 0xe8, 0x6e, 0xb7, 0x0d, 0xe8, 0x6a, 0x13, 0x81, 0xda, 0xfe, + 0x0d, 0x12, 0x1c, 0xb8, 0x5d, 0xf2, 0xdf, 0x86, 0xe4, 0x88, 0x62, 0x77, + 0x22, 0xe9, 0x4e, 0x30, 0x6c, 0x9e, 0xfd, 0x4d, 0x17, 0x0a, 0xdd, 0x09, + 0xd8, 0x1d, 0x2a, 0x24, 0xdd, 0xc9, 0xf7, 0xaf, 0x74, 0x7a, 0x35, 0x38, + 0xa2, 0x3f, 0xae, 0x56, 0x04, 0x94, 0xdf, 0xc7, 0xbf, 0xe6, 0x29, 0x8a, + 0x78, 0xa5, 0xed, 0x54, 0x0d, 0x47, 0x6f, 0xad, 0x2f, 0x05, 0x18, 0x5c, + 0x67, 0x4b, 0xaa, 0xc4, 0xfb, 0xc1, 0x08, 0x8b, 0x0f, 0x9c, 0x38, 0x75, + 0x86, 0xb8, 0xb0, 0x90, 0x75, 0xfc, 0x3e, 0xd0, 0x23, 0x5c, 0x2b, 0x18, + 0x8d, 0xdf, 0x29, 0xfe, 0x72, 0xfb, 0x37, 0x77, 0x27, 0x01, 0xdc, 0xed, + 0xd3, 0x89, 0x9e, 0x4c, 0xa7, 0x33, 0x99, 0xc3, 0x04, 0x71, 0x52, 0x7e, + 0xd8, 0xd7, 0x15, 0x98, 0x69, 0x69, 0xda, 0x57, 0xdd, 0xb9, 0x28, 0x80, + 0xab, 0xf0, 0x3d, 0xbe, 0xee, 0xdf, 0x73, 0x76, 0x4b, 0x4e, 0xed, 0x16, + 0xc6, 0x91, 0x0c, 0xcf, 0x88, 0x64, 0x68, 0xbe, 0x03, 0x1b, 0x5b, 0xd7, + 0x93, 0x4f, 0x2d, 0x2b, 0x2f, 0xed, 0x96, 0x3d, 0xfa, 0x1c, 0x1b, 0x91, + 0xe9, 0xdc, 0xd6, 0x79, 0x9f, 0xe2, 0x99, 0x46, 0x14, 0x73, 0x40, 0xa9, + 0x04, 0xc6, 0x15, 0xab, 0xd4, 0xba, 0x3a, 0xf5, 0x91, 0xa4, 0x2c, 0x0d, + 0x07, 0xba, 0x07, 0x8e, 0xd0, 0x27, 0xec, 0x63, 0x40, 0x53, 0xb0, 0x85, + 0xaa, 0xc4, 0x31, 0x72, 0x42, 0xe4, 0x73, 0xad, 0x1d, 0xa4, 0x49, 0x71, + 0x83, 0x4a, 0xfa, 0x41, 0xd2, 0x3f, 0x3e, 0x0f, 0x58, 0x55, 0x99, 0xf2, + 0xaa, 0x6b, 0x6c, 0x84, 0x32, 0xf9, 0xee, 0x72, 0x9e, 0x59, 0xa3, 0x73, + 0xc0, 0x34, 0x1b, 0x5a, 0x04, 0x42, 0x11, 0x35, 0x19, 0xf9, 0x5b, 0x9b, + 0x18, 0x9f, 0x4f, 0x1d, 0xee, 0x96, 0xeb, 0x43, 0x3b, 0xf9, 0x0c, 0x8a, + 0xeb, 0x0c, 0x8c, 0x19, 0x51, 0x6a, 0x12, 0xe5, 0x58, 0x3e, 0x26, 0xb8, + 0x22, 0x3b, 0xa8, 0x85, 0x6e, 0xb6, 0x51, 0xaa, 0x96, 0xd9, 0x84, 0x74, + 0x6c, 0xa2, 0x48, 0xe9, 0x84, 0xba, 0x25, 0xfa, 0xbb, 0x56, 0x81, 0xaa, + 0xd4, 0x8d, 0xa7, 0xb6, 0x58, 0xc2, 0x6d, 0x30, 0xb5, 0xbf, 0xef, 0xaa, + 0xfb, 0x7d, 0x21, 0x7e, 0xc9, 0x34, 0x11, 0x34, 0xdb, 0x62, 0xf2, 0x94, + 0x6d, 0x4c, 0xdc, 0x64, 0x5d, 0xf0, 0x3f, 0x8f, 0xf0, 0x5e, 0xbb, 0x95, + 0x7b, 0x11, 0x22, 0x26, 0xbf, 0x30, 0x21, 0xe2, 0xe2, 0x60, 0x9e, 0x04, + 0xd4, 0x4b, 0x3f, 0xcf, 0x14, 0xec, 0x6c, 0xff, 0x5a, 0x9d, 0x6b, 0xd8, + 0x3c, 0x8c, 0xce, 0xad, 0x54, 0x57, 0x33, 0x57, 0xb6, 0x9d, 0x2f, 0x38, + 0x23, 0x43, 0xb3, 0x50, 0xf6, 0x57, 0x31, 0x77, 0x55, 0xb1, 0x03, 0xaf, + 0x65, 0x37, 0x02, 0xcd, 0xd3, 0x27, 0x74, 0x45, 0x67, 0x8b, 0x0e, 0xd7, + 0xec, 0xd3, 0xf0, 0xdc, 0x3f, 0xf0, 0x7c, 0x8a, 0x97, 0x12, 0x7f, 0x75, + 0x74, 0xe1, 0x17, 0x02, 0x1b, 0xa3, 0xde, 0xa5, 0xaa, 0xbe, 0x80, 0x41, + 0x99, 0x76, 0xe7, 0xcb, 0x1b, 0xb6, 0xfe, 0x4a, 0x8f, 0x6c, 0xbb, 0x04, + 0xe5, 0x5a, 0x09, 0x8b, 0xc9, 0xa8, 0x07, 0x81, 0x5d, 0x1a, 0x69, 0xc9, + 0x48, 0x7d, 0xe0, 0xca, 0x65, 0xcc, 0x8f, 0x62, 0x5c, 0x32, 0x35, 0xc0, + 0x3f, 0x6e, 0x8a, 0x0d, 0xba, 0xc1, 0x45, 0x04, 0xde, 0x2c, 0xbc, 0x8e, + 0xb7, 0x5e, 0x96, 0xbd, 0xb0, 0x79, 0xce, 0xd9, 0x38, 0x8f, 0x4e, 0xab, + 0xa6, 0xd9, 0xb6, 0x74, 0x78, 0xdd, 0x1c, 0x0b, 0xdc, 0x4d, 0xa8, 0xee, + 0x2d, 0x55, 0xcc, 0xdf, 0x73, 0xde, 0x61, 0x5f, 0x9e, 0x6f, 0x7c, 0xec, + 0xb3, 0xa6, 0xef, 0x88, 0x6a, 0xae, 0x68, 0xb8, 0xd4, 0x93, 0x48, 0x7f, + 0xa3, 0x00, 0x76, 0xa5, 0x0d, 0x43, 0xd0, 0xc1, 0x35, 0xf5, 0x97, 0x37, + 0xf7, 0x65, 0xf2, 0xf7, 0xf6, 0x16, 0x3e, 0x06, 0x89, 0x07, 0x0b, 0xed, + 0x22, 0x94, 0xb9, 0x87, 0xfa, 0x49, 0x0c, 0xe5, 0x23, 0xec, 0xac, 0x4a, + 0x75, 0x44, 0xb5, 0x25, 0x1d, 0x13, 0xb6, 0xa4, 0xe3, 0x44, 0xb5, 0xe6, + 0x8c, 0x84, 0xd8, 0x6e, 0xe1, 0x9c, 0x46, 0x52, 0xb9, 0xb4, 0x70, 0x7c, + 0x35, 0x07, 0x53, 0x4f, 0x25, 0x13, 0xef, 0xa6, 0x1e, 0xa6, 0x05, 0x31, + 0xe2, 0x1c, 0xbe, 0x42, 0x22, 0x9d, 0x3d, 0xf6, 0xb7, 0x7e, 0x8d, 0x1c, + 0xc5, 0xfb, 0xc9, 0x75, 0x35, 0x68, 0x89, 0x40, 0x7d, 0xf7, 0x6e, 0x5f, + 0x41, 0x25, 0x9c, 0x0f, 0x55, 0x5e, 0x09, 0xb9, 0xa7, 0x8a, 0x88, 0x26, + 0x6e, 0x27, 0x6c, 0x78, 0x89, 0xcf, 0xb0, 0x54, 0x02, 0x77, 0xd3, 0xe5, + 0xb2, 0x96, 0xd7, 0x02, 0x3f, 0x9a, 0xf3, 0xc1, 0xbf, 0x7c, 0xad, 0x17, + 0xe0, 0xcd, 0x11, 0xa1, 0x37, 0x64, 0x9f, 0xd3, 0xdb, 0xf8, 0xfd, 0x94, + 0xc4, 0xd1, 0xe8, 0x0d, 0xb7, 0x3f, 0xa8, 0x68, 0x42, 0xd8, 0x12, 0xaf, + 0xf6, 0x83, 0xce, 0x0f, 0x4c, 0x45, 0xe8, 0xa9, 0x74, 0x99, 0x10, 0x01, + 0x79, 0x5f, 0xa7, 0xfd, 0x11, 0x5d, 0x71, 0x47, 0xa2, 0x44, 0x62, 0xa8, + 0x4b, 0x39, 0x64, 0x75, 0x02, 0xeb, 0x1f, 0x6a, 0x6f, 0xe8, 0xb6, 0xb9, + 0x59, 0x8d, 0x6c, 0x05, 0x67, 0x31, 0x5f, 0xe3, 0x16, 0x99, 0xd8, 0x49, + 0xe6, 0xbc, 0x18, 0xad, 0x01, 0xc7, 0xa9, 0xc2, 0x59, 0xa5, 0x28, 0xe4, + 0x61, 0x71, 0x8c, 0xb9, 0xa1, 0xff, 0x98, 0x30, 0x4d, 0x69, 0xd7, 0xd4, + 0x60, 0xa1, 0xe0, 0xfa, 0x84, 0x66, 0xb6, 0xe8, 0xc8, 0x09, 0x6a, 0x05, + 0x37, 0x1c, 0x3a, 0x42, 0x25, 0xcd, 0x43, 0x67, 0xef, 0x8b, 0xe6, 0x4c, + 0xca, 0xa7, 0x07, 0x9b, 0x04, 0x38, 0xb7, 0xae, 0x7a, 0xa9, 0x92, 0x5c, + 0x0f, 0x95, 0x13, 0x9c, 0x16, 0x3d, 0x18, 0x37, 0x3a, 0x86, 0xfc, 0x8d, + 0x86, 0x0d, 0xd7, 0x77, 0x08, 0x42, 0x1f, 0xc8, 0x78, 0x91, 0x2f, 0x4a, + 0x89, 0xdb, 0x0a, 0xa7, 0x2d, 0xfd, 0x74, 0x88, 0x33, 0x1c, 0xc1, 0x9b, + 0x0c, 0x6c, 0x97, 0x10, 0x03, 0xcb, 0xbe, 0x86, 0x1f, 0xe7, 0x42, 0x2f, + 0x22, 0x9f, 0x4f, 0xfa, 0xc9, 0x01, 0x1f, 0xea, 0xed, 0x06, 0xb5, 0x2a, + 0x11, 0x05, 0x65, 0xf9, 0x56, 0x0b, 0xf0, 0xd6, 0x01, 0xb8, 0xfd, 0xaa, + 0x93, 0x4b, 0xf0, 0x02, 0x58, 0x32, 0x2e, 0xd2, 0x70, 0x1e, 0x85, 0xf0, + 0xbd, 0x5e, 0x43, 0xdc, 0xaf, 0xc7, 0x1d, 0xd3, 0xf3, 0x02, 0x68, 0x1f, + 0xd1, 0x50, 0x9a, 0x90, 0xff, 0x21, 0xcf, 0x58, 0xc4, 0x23, 0xfe, 0x9b, + 0xf9, 0x6e, 0x92, 0x6f, 0x16, 0x91, 0xfd, 0x8c, 0x62, 0xfb, 0x96, 0x1d, + 0xf0, 0xe1, 0xb0, 0xac, 0xfc, 0xb2, 0xa8, 0xd5, 0x46, 0x8b, 0x0a, 0x21, + 0x76, 0xe5, 0x77, 0xe9, 0xc0, 0x0a, 0xcf, 0x96, 0x98, 0x22, 0xa1, 0xe0, + 0x70, 0x69, 0x98, 0x93, 0x09, 0x9c, 0xd9, 0xd2, 0x6f, 0xb9, 0xcf, 0x05, + 0x37, 0xff, 0xee, 0x0d, 0x1c, 0xc5, 0x65, 0xd8, 0xfb, 0xf2, 0xdf, 0xfb, + 0x30, 0xee, 0x4a, 0xb6, 0x5c, 0x65, 0x24, 0x7f, 0x90, 0x05, 0x0a, 0x81, + 0xe3, 0xab, 0x07, 0x56, 0x54, 0x80, 0x5d, 0x1e, 0xd6, 0x2b, 0xa4, 0x79, + 0xcc, 0x3a, 0x15, 0xbe, 0x11, 0x7c, 0x3b, 0x2e, 0x74, 0xb1, 0x8b, 0x3d, + 0x19, 0xb9, 0xeb, 0xab, 0x67, 0x87, 0x36, 0x82, 0x3a, 0x79, 0x89, 0xa0, + 0x4c, 0x84, 0x24, 0x83, 0xbb, 0x42, 0xde, 0xab, 0x40, 0xef, 0x42, 0x03, + 0xc3, 0x88, 0xcc, 0x7d, 0x1a, 0x70, 0x0a, 0xcb, 0x94, 0xdb, 0xb4, 0x73, + 0x51, 0xa5, 0x43, 0xc5, 0xe0, 0xd1, 0x36, 0xb4, 0x88, 0x52, 0x4a, 0x7b, + 0xfd, 0x87, 0x80, 0xe4, 0x8f, 0x07, 0x29, 0x77, 0x88, 0xe7, 0xc5, 0x2b, + 0x82, 0x07, 0x49, 0xd7, 0x2d, 0x76, 0xb3, 0x7f, 0x3d, 0x7e, 0x35, 0x36, + 0x5a, 0xe7, 0xb6, 0xa5, 0x3b, 0xc4, 0xa2, 0xfc, 0xe6, 0xdf, 0xb0, 0x0d, + 0xdd, 0xd0, 0x8b, 0xa1, 0x21, 0x63, 0x37, 0xf7, 0xd3, 0xa8, 0x81, 0x67, + 0x16, 0x68, 0x55, 0x9d, 0xa5, 0x68, 0xf0, 0x19, 0x51, 0x24, 0x90, 0xd0, + 0x02, 0x72, 0x9d, 0xbf, 0xb0, 0xc0, 0x70, 0xbc, 0xac, 0x13, 0xcc, 0x8a, + 0x59, 0x8f, 0x67, 0xba, 0x3c, 0x83, 0x16, 0x06, 0xbf, 0xa2, 0x47, 0x32, + 0x21, 0x24, 0x03, 0xca, 0x36, 0x29, 0x31, 0xac, 0x3b, 0x6a, 0x2a, 0x67, + 0xf7, 0xd2, 0x43, 0x9e, 0xfa, 0x7d, 0x83, 0x7e, 0x91, 0x81, 0x06, 0x4b, + 0x11, 0x86, 0x29, 0x3b, 0xab, 0xf3, 0x12, 0x38, 0x6a, 0xa8, 0xa7, 0xb0, + 0x22, 0xf5, 0xa0, 0x83, 0xf6, 0xaa, 0x48, 0x1c, 0x09, 0x3b, 0xbc, 0x64, + 0xd9, 0x6b, 0x0f, 0x9c, 0x88, 0xeb, 0xfa, 0xb2, 0x64, 0x4e, 0xae, 0xd8, + 0x1e, 0xb3, 0x23, 0xf3, 0x18, 0x35, 0x7d, 0x65, 0x7f, 0x38, 0x4c, 0x1a, + 0xa0, 0x2e, 0xc8, 0x2f, 0x09, 0x91, 0x80, 0x40, 0x20, 0x40, 0x3e, 0x02, + 0xde, 0xd1, 0x4c, 0x2f, 0x6a, 0xa7, 0x95, 0x65, 0x98, 0x68, 0x3a, 0xfa, + 0xfc, 0x25, 0x7a, 0x2a, 0x7e, 0x1c, 0xa9, 0x78, 0x28, 0xd3, 0x04, 0xc5, + 0x51, 0x6d, 0x9a, 0x1b, 0x63, 0x79, 0xeb, 0x1d, 0x39, 0x9d, 0x23, 0x02, + 0x55, 0xd1, 0x13, 0x91, 0x17, 0xdf, 0xcf, 0x7f, 0x56, 0x0e, 0x46, 0x08, + 0x79, 0x03, 0xc4, 0xb8, 0x40, 0xe2, 0x57, 0x9f, 0x45, 0xda, 0x83, 0x2a, + 0xf5, 0x59, 0x09, 0x66, 0xd6, 0x15, 0xb3, 0x38, 0x43, 0x74, 0x79, 0x70, + 0x28, 0x17, 0x2f, 0xf7, 0x8e, 0xe9, 0x83, 0x56, 0xe0, 0x43, 0xdd, 0x46, + 0x7b, 0x99, 0x58, 0x6d, 0xd7, 0x38, 0x09, 0x92, 0x85, 0x96, 0xad, 0x2b, + 0xbe, 0x0f, 0x30, 0xe5, 0xbf, 0x18, 0x31, 0x40, 0x00, 0xc3, 0xdf, 0x62, + 0x7b, 0x81, 0x46, 0x50, 0x04, 0xf3, 0x04, 0x95, 0xa1, 0xb5, 0x6b, 0xcc, + 0x9f, 0x25, 0x91, 0xd4, 0x92, 0xfc, 0xe6, 0x5b, 0x7c, 0x9b, 0x41, 0xf1, + 0x00, 0x76, 0x00, 0x32, 0xc3, 0x12, 0xdf, 0xf4, 0x22, 0x8c, 0x22, 0xc2, + 0xa3, 0xfb, 0x33, 0xfe, 0xcc, 0x95, 0x8c, 0x5e, 0x4f, 0xfc, 0xfc, 0xfe, + 0x93, 0x07, 0xc9, 0x32, 0xd5, 0x7d, 0x86, 0x50, 0x84, 0x9e, 0x9c, 0x21, + 0xe6, 0x54, 0xe6, 0x8a, 0xac, 0xf1, 0x23, 0x58, 0xb0, 0x94, 0x6b, 0x8c, + 0xc9, 0x21, 0x72, 0xcc, 0x3e, 0x43, 0x67, 0xc4, 0x0f, 0x09, 0xa9, 0x08, + 0xff, 0xd6, 0xf5, 0x2f, 0xf7, 0xba, 0x6b, 0x63, 0x27, 0x8b, 0x2c, 0x87, + 0x5b, 0xd3, 0x42, 0x65, 0x0a, 0xa6, 0xaa, 0xe9, 0xd4, 0xbe, 0xfe, 0xbd, + 0x8a, 0x4f, 0x77, 0x37, 0xf4, 0x28, 0x50, 0xaf, 0x06, 0x66, 0x59, 0xd0, + 0x17, 0x7c, 0xf3, 0x7c, 0xdd, 0x73, 0x45, 0x9c, 0xb2, 0x69, 0xd2, 0x7c, + 0x21, 0x8e, 0x07, 0x4f, 0xf5, 0x49, 0xfc, 0xcf, 0x91, 0x2b, 0xdc, 0x28, + 0x0c, 0x36, 0xa7, 0x3d, 0xb7, 0x6f, 0xf8, 0xef, 0x7a, 0xef, 0x84, 0x38, + 0xba, 0x25, 0x73, 0x98, 0x10, 0x11, 0x38, 0x8d, 0xee, 0xbf, 0x3b, 0x7a, + 0x8e, 0x75, 0x91, 0x1a, 0x18, 0xec, 0x7d, 0xb8, 0x4b, 0xbd, 0x0e, 0x99, + 0xba, 0xfc, 0x61, 0xff, 0xa5, 0x03, 0x4b, 0xd9, 0x09, 0x9e, 0xfa, 0xfc, + 0x58, 0xb2, 0xa3, 0x92, 0x5b, 0xb8, 0x34, 0x7a, 0x15, 0xe6, 0x93, 0xed, + 0x14, 0x72, 0xc9, 0x8d, 0x49, 0x93, 0x94, 0x9e, 0x62, 0x27, 0xdd, 0x1e, + 0xb6, 0xae, 0x4d, 0xf0, 0x9d, 0x10, 0xb2, 0x45, 0x73, 0xfa, 0x92, 0x14, + 0xd4, 0x5d, 0xda, 0xf2, 0x5b, 0xfb, 0x50, 0xad, 0x37, 0x82, 0x5c, 0x6f, + 0xf9, 0x2b, 0x9c, 0x13, 0x6f, 0x59, 0xa6, 0xed, 0x34, 0xb1, 0x1f, 0x49, + 0x77, 0x4d, 0x74, 0x7a, 0xfb, 0x4a, 0xd4, 0xae, 0x82, 0x2d, 0x9f, 0x5d, + 0xaf, 0xd4, 0xd6, 0xad, 0x32, 0x43, 0x8e, 0x0e, 0x09, 0x63, 0xbf, 0xce, + 0xe9, 0x2c, 0xa3, 0x95, 0xe1, 0x22, 0x71, 0x60, 0xf1, 0xb4, 0xda, 0xa3, + 0xb0, 0x04, 0x08, 0x04, 0x6c, 0xc8, 0x4b, 0x8a, 0x5c, 0x13, 0x94, 0xf6, + 0xd4, 0x38, 0xc8, 0xa5, 0x8b, 0xc5, 0x35, 0xc5, 0x70, 0x25, 0x3b, 0x5e, + 0x9b, 0x5f, 0xbc, 0x46, 0xbd, 0x91, 0x17, 0x4b, 0x39, 0x0d, 0xe2, 0x89, + 0x70, 0x58, 0xec, 0x17, 0x1a, 0xdb, 0x4e, 0xdd, 0x0c, 0xfd, 0x9d, 0x3c, + 0xd2, 0xd5, 0x23, 0xa5, 0xea, 0x8f, 0xe2, 0x80, 0xf4, 0xe3, 0x16, 0x55, + 0x31, 0x34, 0x36, 0xdb, 0xca, 0x13, 0x53, 0xac, 0xb1, 0x0f, 0xd7, 0x23, + 0xa7, 0x79, 0x31, 0x2d, 0xea, 0x61, 0x4a, 0x48, 0xbf, 0x26, 0x44, 0x58, + 0xce, 0xd6, 0x27, 0x61, 0x04, 0xe0, 0xc3, 0xf3, 0x96, 0xeb, 0x14, 0xa2, + 0x70, 0x42, 0x79, 0x8a, 0x43, 0x23, 0x41, 0x6e, 0xb3, 0x47, 0x56, 0x6b, + 0xdf, 0x22, 0x89, 0xb6, 0xca, 0xee, 0x11, 0xaa, 0x94, 0x86, 0x66, 0x59, + 0x4a, 0x13, 0xde, 0x45, 0x27, 0xb2, 0x89, 0x77, 0x0b, 0x85, 0xa9, 0x54, + 0xba, 0xfd, 0x27, 0xae, 0x11, 0xee, 0xb3, 0xd8, 0x61, 0x36, 0x40, 0xf5, + 0x17, 0x5b, 0x0f, 0xcb, 0x40, 0x0a, 0xc4, 0xc9, 0xac, 0xcf, 0x1c, 0x8d, + 0xe6, 0x1d, 0xed, 0x5e, 0x1c, 0xd5, 0xd6, 0x29, 0xa4, 0x85, 0x0d, 0xc0, + 0xb5, 0x06, 0x3c, 0x14, 0xab, 0x50, 0x8b, 0x41, 0x9a, 0xca, 0x4a, 0xb5, + 0x2c, 0x9a, 0x09, 0xba, 0x9b, 0xb0, 0x69, 0x93, 0x37, 0x7d, 0xaa, 0x15, + 0xf5, 0x13, 0x89, 0x16, 0xae, 0xfc, 0x8a, 0x67, 0x82, 0x68, 0x0f, 0x97, + 0x19, 0xa4, 0xd6, 0xd3, 0x79, 0x0d, 0x31, 0x9d, 0x9b, 0x17, 0x18, 0x66, + 0x76, 0x2f, 0xbc, 0xd5, 0x4b, 0x84, 0xa7, 0xd7, 0x64, 0xfd, 0x30, 0x6c, + 0x9d, 0xc8, 0x48, 0xd4, 0xe9, 0xa2, 0x56, 0xd6, 0x97, 0xc5, 0x7c, 0x9f, + 0xfc, 0x40, 0xa7, 0x8d, 0x7d, 0x0b, 0xa8, 0xc7, 0x79, 0xa9, 0xdb, 0x50, + 0xb4, 0x6c, 0x7a, 0xd7, 0x41, 0x00, 0x6e, 0x13, 0x8d, 0x0c, 0x58, 0x34, + 0x14, 0x47, 0x5f, 0x1a, 0x03, 0x0b, 0x14, 0x86, 0x5d, 0x96, 0x71, 0xd2, + 0x9a, 0xbd, 0xe6, 0x94, 0xd6, 0x60, 0x53, 0xac, 0xba, 0x76, 0x8e, 0x32, + 0x36, 0xe0, 0x52, 0x76, 0xa5, 0x40, 0xbe, 0x25, 0xdc, 0x77, 0xf7, 0x7f, + 0xf8, 0x93, 0x51, 0xd1, 0x76, 0x26, 0x9c, 0xb2, 0x97, 0x74, 0x80, 0xe5, + 0x01, 0x74, 0x8b, 0x66, 0x47, 0x37, 0x34, 0x46, 0x23, 0xab, 0x68, 0xcc, + 0x0d, 0x42, 0xb5, 0x98, 0x52, 0x10, 0xc8, 0x2d, 0x35, 0x6e, 0x9b, 0x41, + 0x19, 0x48, 0x78, 0x21, 0x51, 0xa6, 0x07, 0x6a, 0x66, 0xaa, 0xeb, 0x0b, + 0x8f, 0x62, 0xd6, 0x96, 0xda, 0xcf, 0xb6, 0x1e, 0x0f, 0x51, 0x54, 0xed, + 0xbe, 0x91, 0xc4, 0x34, 0xd1, 0x13, 0xcf, 0x49, 0xda, 0xa2, 0x93, 0x76, + 0x4a, 0x70, 0x34, 0xf3, 0xc2, 0x64, 0xcc, 0x76, 0x1d, 0x8e, 0x85, 0xb2, + 0x36, 0xb1, 0x71, 0xea, 0x9e, 0x70, 0x77, 0x6d, 0x29, 0x9c, 0x03, 0x20, + 0xb2, 0x6f, 0x2a, 0x73, 0x27, 0x3b, 0x13, 0x64, 0x95, 0xc6, 0x81, 0x50, + 0x4a, 0x3c, 0x5f, 0x1b, 0x74, 0xa9, 0xd6, 0x9f, 0xaf, 0xff, 0xb1, 0x02, + 0xe7, 0xfc, 0x18, 0xe7, 0x7c, 0x91, 0x99, 0xf7, 0x38, 0xe5, 0xb3, 0x09, + 0xb0, 0xbd, 0x08, 0x7e, 0xa3, 0x53, 0x30, 0x51, 0x30, 0x1d, 0x06, 0x03, + 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x60, 0xae, 0x6e, 0xa9, 0x6c, + 0x4d, 0x25, 0xdd, 0x9a, 0x4b, 0xa0, 0x2f, 0x22, 0x03, 0x63, 0x79, 0x1a, + 0xd6, 0xe3, 0xde, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, + 0x30, 0x16, 0x80, 0x14, 0x60, 0xae, 0x6e, 0xa9, 0x6c, 0x4d, 0x25, 0xdd, + 0x9a, 0x4b, 0xa0, 0x2f, 0x22, 0x03, 0x63, 0x79, 0x1a, 0xd6, 0xe3, 0xde, + 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, + 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, + 0x01, 0x65, 0x03, 0x04, 0x03, 0x13, 0x03, 0x82, 0x12, 0x14, 0x00, 0xb7, + 0x93, 0x7e, 0xaa, 0x87, 0x38, 0xa6, 0xb8, 0x34, 0xe6, 0xc9, 0xbc, 0x64, + 0xf5, 0x8a, 0x71, 0xc5, 0x97, 0x85, 0xfb, 0xd4, 0xe4, 0x3a, 0xbc, 0x59, + 0xbb, 0xd5, 0x67, 0xfb, 0xc8, 0xc4, 0x92, 0xea, 0x16, 0xf4, 0x03, 0x09, + 0xe4, 0xed, 0x99, 0x60, 0x12, 0xfe, 0x41, 0x75, 0xbe, 0x67, 0x48, 0x14, + 0x97, 0x2f, 0xf1, 0xbe, 0x71, 0xd9, 0x2a, 0xda, 0xab, 0x2b, 0xdb, 0x7d, + 0x6a, 0xc0, 0x96, 0x1e, 0x3e, 0x8f, 0x11, 0x49, 0xfd, 0xe1, 0xf5, 0xe0, + 0x38, 0x93, 0x5c, 0x38, 0x74, 0xeb, 0xbb, 0xfc, 0xac, 0x33, 0x59, 0xdb, + 0xbc, 0x1a, 0xed, 0xbe, 0x08, 0x41, 0x2d, 0x31, 0xe0, 0x1b, 0x1b, 0x10, + 0x62, 0x6b, 0x19, 0x17, 0xce, 0x7a, 0xe6, 0xf0, 0xd8, 0x12, 0x2d, 0x95, + 0x5a, 0x4e, 0x32, 0xb6, 0xfa, 0xe3, 0xec, 0x7d, 0xde, 0xbb, 0x18, 0xe0, + 0xba, 0x35, 0xb9, 0x46, 0xc8, 0x84, 0x9d, 0xad, 0x0b, 0x71, 0x95, 0x33, + 0xe8, 0xdb, 0xb8, 0x38, 0xbe, 0x63, 0xdc, 0xd2, 0x71, 0xcb, 0x1f, 0x03, + 0x75, 0x45, 0x4c, 0xec, 0x45, 0xc8, 0x64, 0xa5, 0x79, 0x16, 0xfd, 0x23, + 0x11, 0x5c, 0x1c, 0xe1, 0x97, 0x25, 0x13, 0x26, 0x11, 0x2e, 0x06, 0xba, + 0x0e, 0x74, 0x65, 0x62, 0x09, 0xba, 0xa0, 0x8c, 0xa0, 0x8f, 0xc6, 0x3a, + 0x92, 0x90, 0x8d, 0x9c, 0x02, 0x16, 0xa6, 0x47, 0x5a, 0xa5, 0x52, 0xdc, + 0x59, 0x4d, 0xe7, 0x7e, 0xa5, 0x6c, 0x95, 0x8b, 0xed, 0x5f, 0xc1, 0xfb, + 0x21, 0x4a, 0xa0, 0x11, 0x09, 0xdf, 0x47, 0xdb, 0x2d, 0x37, 0x34, 0xda, + 0xc2, 0x5b, 0x8d, 0x05, 0xb6, 0xa8, 0x16, 0x89, 0x6c, 0x90, 0x27, 0x3f, + 0x70, 0x7b, 0xf8, 0xf5, 0xf6, 0x1e, 0x6c, 0xe6, 0x0a, 0xe0, 0x06, 0x14, + 0x86, 0x04, 0xd4, 0x5b, 0xef, 0xd2, 0xab, 0x0b, 0x6c, 0xcc, 0xbb, 0x85, + 0x76, 0xab, 0x80, 0x8a, 0x8b, 0x87, 0xe7, 0x10, 0xd7, 0xc1, 0x86, 0x1f, + 0x1e, 0x9e, 0xfd, 0x50, 0x07, 0x44, 0x3e, 0x76, 0x3a, 0xc1, 0xd6, 0xb8, + 0x95, 0x19, 0xb3, 0x41, 0xa9, 0x7b, 0x61, 0xca, 0x0c, 0x4a, 0x7c, 0x83, + 0xf7, 0xe3, 0x4c, 0x03, 0x9d, 0x5f, 0x2e, 0x8b, 0x7e, 0x5d, 0xa5, 0x4a, + 0x6e, 0x6d, 0x69, 0xab, 0xf9, 0xfe, 0x45, 0xbe, 0x44, 0x8e, 0xc5, 0xde, + 0x6f, 0x2e, 0x44, 0x33, 0x5f, 0x05, 0xbf, 0xf0, 0x41, 0xb8, 0xa8, 0x84, + 0xe0, 0xee, 0x6a, 0xd9, 0x3b, 0xf1, 0x20, 0x7b, 0xf2, 0x53, 0x56, 0xb0, + 0x29, 0x15, 0x5b, 0xec, 0xd6, 0x91, 0xde, 0xcd, 0xc1, 0xbb, 0xde, 0x53, + 0x8a, 0x4a, 0x8a, 0x65, 0xe2, 0xd0, 0xca, 0xa2, 0x6b, 0x69, 0xbe, 0xad, + 0x7c, 0xe5, 0x32, 0x48, 0x1d, 0x5c, 0x39, 0xa2, 0x94, 0xd2, 0x44, 0xc7, + 0x9b, 0xcb, 0x96, 0x4e, 0x17, 0xd7, 0x87, 0x42, 0x67, 0x6d, 0x7e, 0x98, + 0x3f, 0x3e, 0xfa, 0x96, 0x6f, 0x43, 0x70, 0x34, 0x23, 0x42, 0x36, 0x2e, + 0x2b, 0x91, 0x03, 0xf1, 0x5a, 0xea, 0x08, 0xa0, 0x62, 0x45, 0x93, 0x04, + 0x1d, 0xcc, 0xe3, 0x23, 0x1d, 0x98, 0xe3, 0xab, 0x9c, 0x43, 0x3f, 0x73, + 0xca, 0x3c, 0x77, 0xe3, 0x8d, 0x92, 0xd2, 0xdf, 0x17, 0x7e, 0x13, 0xf0, + 0xbb, 0xea, 0x6e, 0x00, 0x9c, 0xf8, 0x19, 0x3f, 0xd8, 0x6e, 0x6e, 0xe0, + 0xc0, 0x95, 0xe9, 0xaa, 0x4c, 0xe0, 0x3d, 0x18, 0xf5, 0xc7, 0x0d, 0x8d, + 0x0a, 0xfb, 0x77, 0xc2, 0xad, 0xde, 0x62, 0xdc, 0x29, 0x68, 0x98, 0x6b, + 0x9d, 0x8d, 0xfb, 0xe1, 0x50, 0x5e, 0x5e, 0xe5, 0x70, 0x24, 0x61, 0xbd, + 0xf9, 0x5b, 0xe8, 0xb1, 0xc0, 0x35, 0x7c, 0x20, 0x00, 0x81, 0x68, 0x6e, + 0x25, 0xbe, 0x87, 0x2d, 0x7d, 0x75, 0x8a, 0xcf, 0x86, 0x45, 0xa8, 0x76, + 0xb2, 0x48, 0xa4, 0x87, 0xd8, 0xbc, 0x11, 0x7c, 0x24, 0x14, 0xec, 0x2a, + 0xae, 0x4c, 0x69, 0xbb, 0x72, 0x25, 0x95, 0xb8, 0xc2, 0xc3, 0x3a, 0x07, + 0xbc, 0x39, 0xd2, 0xe4, 0x75, 0x30, 0xfe, 0x60, 0x0d, 0x05, 0x90, 0x94, + 0xd7, 0xa7, 0x85, 0x72, 0xb8, 0xf5, 0x8f, 0x6c, 0x75, 0xf0, 0xaa, 0xe7, + 0x47, 0x3e, 0x1c, 0x19, 0xf3, 0xea, 0x61, 0x8e, 0xa4, 0xb9, 0xff, 0xb6, + 0xa4, 0x8a, 0x09, 0x45, 0xb1, 0xd6, 0xbc, 0x9c, 0x4b, 0xdc, 0x77, 0x04, + 0xb6, 0x91, 0x2e, 0xf6, 0x78, 0x78, 0xe4, 0x70, 0xf3, 0x79, 0x81, 0xbb, + 0x6b, 0x88, 0x2a, 0x46, 0x44, 0x65, 0x5e, 0x12, 0x9d, 0x34, 0x9a, 0xac, + 0x7c, 0x8b, 0x9e, 0x5f, 0xbc, 0x71, 0x0b, 0xef, 0x39, 0x03, 0x37, 0x40, + 0x9a, 0xf7, 0xdf, 0x43, 0x12, 0x74, 0x3d, 0x4c, 0x9c, 0xdb, 0x4d, 0xb0, + 0x09, 0x94, 0x05, 0xe8, 0xb1, 0xdd, 0x06, 0x66, 0x5b, 0x09, 0x40, 0x56, + 0x9b, 0x9a, 0x56, 0x04, 0x41, 0xfe, 0x74, 0xa3, 0xd1, 0xb6, 0xb3, 0x91, + 0x84, 0x5d, 0xf4, 0xda, 0xef, 0x38, 0x60, 0x96, 0x30, 0x6e, 0x89, 0x03, + 0xf2, 0x8a, 0x08, 0x08, 0x66, 0xe3, 0xe1, 0x85, 0x56, 0x15, 0xd4, 0xb1, + 0x6d, 0xee, 0x5a, 0x7f, 0xb0, 0xc2, 0xfb, 0x8c, 0xf8, 0xc7, 0x33, 0xc9, + 0x06, 0x7a, 0x63, 0xf2, 0x50, 0x93, 0xc4, 0x4f, 0x99, 0x5f, 0xcd, 0xf8, + 0xc3, 0x55, 0x48, 0x92, 0x8a, 0xcc, 0x42, 0xb1, 0xe0, 0xd1, 0x94, 0xe2, + 0x70, 0xd3, 0x92, 0xcb, 0x08, 0xd9, 0xd0, 0xdb, 0x56, 0x53, 0xf4, 0x55, + 0xc4, 0xbc, 0x1e, 0xc8, 0x07, 0xb1, 0xf1, 0xb2, 0x0f, 0xf8, 0xb1, 0xa2, + 0x7d, 0xe7, 0x0b, 0x05, 0x47, 0xfa, 0x50, 0xc5, 0xdc, 0x40, 0x0e, 0xa1, + 0xe8, 0xc5, 0x17, 0xaa, 0x70, 0x57, 0xac, 0xf2, 0x6d, 0xf0, 0x04, 0xa3, + 0xce, 0x31, 0x53, 0x21, 0x23, 0xe4, 0x68, 0x12, 0xe9, 0x28, 0x0e, 0x54, + 0xbc, 0xd5, 0x1f, 0x13, 0xe0, 0x16, 0xbb, 0x1b, 0xca, 0x06, 0x28, 0x32, + 0x1c, 0x20, 0x61, 0xea, 0x94, 0xfb, 0xef, 0xe8, 0xf7, 0xb2, 0xb8, 0x1f, + 0x6a, 0x38, 0xcc, 0x26, 0x1d, 0xb8, 0x24, 0x25, 0x67, 0xad, 0xf7, 0x1b, + 0x27, 0x66, 0xad, 0x55, 0xd6, 0x96, 0x2d, 0xd2, 0xb7, 0xd5, 0xc7, 0xb8, + 0x83, 0x3c, 0x61, 0x97, 0x5f, 0x59, 0x68, 0x61, 0x73, 0x55, 0xb4, 0x04, + 0xd8, 0xce, 0x77, 0xaf, 0x96, 0x2f, 0x44, 0xb7, 0x23, 0x8e, 0x96, 0xad, + 0x9d, 0x10, 0xd0, 0x92, 0x2c, 0x75, 0xb4, 0x25, 0xe8, 0x0b, 0xc8, 0xf4, + 0x34, 0x03, 0x81, 0x92, 0x4d, 0x6a, 0xe2, 0x26, 0x36, 0x39, 0xf2, 0x68, + 0x47, 0x2f, 0xd3, 0xb8, 0x15, 0xc0, 0x22, 0x71, 0x9c, 0xed, 0x41, 0x58, + 0x1e, 0x7f, 0x3f, 0xc0, 0xee, 0xea, 0x8d, 0x32, 0x87, 0x26, 0x7d, 0x37, + 0x46, 0xfa, 0x52, 0xf3, 0x59, 0xb2, 0x5a, 0xf8, 0x5f, 0x45, 0xe1, 0x1e, + 0x41, 0x4d, 0xf1, 0x09, 0x95, 0x2b, 0xae, 0x2b, 0x08, 0x5d, 0xf3, 0x55, + 0x7c, 0x4a, 0xf1, 0xae, 0x4f, 0xe7, 0x71, 0x6d, 0x40, 0xc5, 0x03, 0x3f, + 0x28, 0xf4, 0xd6, 0xaa, 0xf7, 0x1f, 0x97, 0x91, 0x58, 0xf6, 0x2f, 0x19, + 0xd5, 0xf2, 0xea, 0x46, 0xc4, 0x67, 0xcb, 0x4e, 0x4d, 0x44, 0x6b, 0x6e, + 0x16, 0xec, 0x54, 0x77, 0x00, 0x35, 0xc2, 0x0e, 0x6f, 0x45, 0xe5, 0xbc, + 0xef, 0xdd, 0x1c, 0xa5, 0x35, 0x29, 0x0c, 0x8b, 0xbd, 0x33, 0x37, 0xc6, + 0x1c, 0x02, 0x9f, 0x63, 0x59, 0xb7, 0x61, 0x4d, 0x8f, 0x98, 0x29, 0x3a, + 0x7b, 0x70, 0xae, 0xbd, 0xbe, 0x81, 0xdd, 0xe9, 0x04, 0xc9, 0xf9, 0xa4, + 0xa9, 0xe0, 0xae, 0x0f, 0xff, 0x70, 0x42, 0x02, 0x6a, 0x41, 0xdc, 0xd3, + 0x49, 0x17, 0x6b, 0x0a, 0x9a, 0x92, 0x58, 0x73, 0x04, 0x5e, 0x40, 0xcb, + 0x17, 0xd5, 0x4a, 0x10, 0xa6, 0xa2, 0x6a, 0x64, 0xf9, 0x17, 0x5a, 0xf3, + 0x60, 0x10, 0xb7, 0x97, 0x54, 0x9e, 0x7d, 0x1c, 0x0e, 0x3a, 0x9d, 0x1c, + 0x0e, 0xf9, 0x15, 0xc0, 0x5d, 0xbb, 0x0c, 0x44, 0x8a, 0xbf, 0x6c, 0x16, + 0x44, 0xf6, 0x8a, 0x27, 0xce, 0x5c, 0x7c, 0xcb, 0x52, 0x7e, 0x7a, 0xd7, + 0x2c, 0xff, 0x6b, 0x0e, 0x6a, 0xa4, 0xd9, 0x2d, 0x13, 0x8a, 0x25, 0x5c, + 0xa0, 0x37, 0x4c, 0xc7, 0xcd, 0x6d, 0x2e, 0xdc, 0x6c, 0xfa, 0x13, 0xf3, + 0x56, 0xa9, 0x58, 0xb5, 0x4b, 0x7c, 0xca, 0x07, 0xa7, 0xe9, 0x6b, 0x14, + 0x10, 0x0e, 0x3e, 0x4c, 0x79, 0xaa, 0x32, 0x7e, 0xa5, 0x4e, 0x36, 0x0a, + 0xc6, 0x4c, 0x23, 0xce, 0x1e, 0x29, 0xfe, 0xa4, 0x1b, 0xd2, 0x85, 0x81, + 0x0f, 0xb9, 0xa1, 0x7c, 0x4b, 0x40, 0x33, 0xf8, 0x98, 0x12, 0x39, 0x80, + 0xe0, 0xc3, 0xb1, 0xe3, 0xe0, 0x6a, 0x39, 0xd3, 0xfd, 0x66, 0x4b, 0x84, + 0x74, 0xc1, 0x25, 0x75, 0x5b, 0x45, 0xbf, 0xca, 0xb6, 0x5f, 0x35, 0xf5, + 0xb9, 0x4a, 0x32, 0xdb, 0x1d, 0x4e, 0x90, 0x1a, 0xec, 0x84, 0xa8, 0x4b, + 0x33, 0x29, 0x2d, 0xab, 0x95, 0x35, 0xa2, 0x86, 0x67, 0xd7, 0xd8, 0xb8, + 0xbd, 0x65, 0xdc, 0x88, 0x63, 0x5b, 0xe1, 0x43, 0x33, 0x52, 0xea, 0x4e, + 0xc4, 0x87, 0xa6, 0x58, 0xf9, 0xf3, 0x7a, 0x98, 0x02, 0x7e, 0x9c, 0x36, + 0x86, 0x2c, 0xaf, 0x73, 0xe9, 0x3e, 0xc7, 0xa4, 0xf9, 0x47, 0x2e, 0x4d, + 0x01, 0xc4, 0x28, 0xac, 0xe2, 0x06, 0x47, 0x1c, 0xea, 0x33, 0x9f, 0xa5, + 0x2e, 0x40, 0x42, 0xbe, 0x79, 0x4d, 0x32, 0xf3, 0x75, 0xe5, 0x15, 0xb3, + 0xa6, 0x9e, 0x6f, 0xe9, 0x28, 0x66, 0xf6, 0xaf, 0x6b, 0x3d, 0x9c, 0x0a, + 0xf3, 0x78, 0xb7, 0x22, 0xab, 0x61, 0x9a, 0x1d, 0x38, 0x6b, 0xf0, 0x6c, + 0x02, 0xf9, 0x0e, 0x0d, 0x92, 0x3c, 0x13, 0x50, 0xca, 0xa1, 0xc3, 0xcc, + 0xb5, 0x1a, 0x6a, 0x1f, 0xfd, 0xaf, 0x46, 0x01, 0x01, 0x04, 0xc6, 0x70, + 0x70, 0x75, 0x05, 0x2f, 0xb5, 0x70, 0x07, 0xbd, 0x12, 0x5a, 0x25, 0x49, + 0x61, 0x9c, 0x33, 0x34, 0x75, 0xfb, 0x78, 0x1e, 0x41, 0xa5, 0x36, 0x76, + 0x13, 0x69, 0x00, 0xf7, 0x97, 0x80, 0xf3, 0xeb, 0x44, 0xfe, 0x9a, 0xf6, + 0x03, 0x0c, 0xaa, 0xdc, 0xde, 0xfe, 0x75, 0xd6, 0x5a, 0xa8, 0xa9, 0xc9, + 0x3b, 0xd3, 0xee, 0x4f, 0x46, 0x4a, 0xb6, 0x01, 0xaf, 0xaf, 0xd7, 0xc7, + 0xde, 0x75, 0x6d, 0xaa, 0x57, 0x0c, 0x5d, 0x08, 0xda, 0xb9, 0xed, 0x07, + 0xed, 0xbb, 0xcf, 0xda, 0x95, 0x09, 0x15, 0xd7, 0x96, 0x8b, 0x21, 0xe0, + 0xfe, 0x14, 0x48, 0xa5, 0xfc, 0xbb, 0xf3, 0x51, 0xa1, 0x7b, 0xc3, 0x55, + 0xa0, 0x22, 0x4d, 0x4f, 0xcf, 0x8e, 0xcd, 0x48, 0xe4, 0x0c, 0xfe, 0x1f, + 0x8c, 0xe8, 0x34, 0x56, 0x4d, 0xd5, 0xa6, 0x48, 0x6c, 0x10, 0xf3, 0x49, + 0xaf, 0x0e, 0x0f, 0x45, 0x4d, 0x82, 0xdf, 0xed, 0xd5, 0x8b, 0x8b, 0xfd, + 0xad, 0xb6, 0x8d, 0x1f, 0x68, 0x12, 0x92, 0xcf, 0xee, 0x90, 0x18, 0x7f, + 0x30, 0x05, 0xb1, 0x0e, 0x53, 0xf5, 0x7d, 0x77, 0x0f, 0xdf, 0x5b, 0xe4, + 0x7b, 0x6f, 0xdb, 0x19, 0xfd, 0x9b, 0x1d, 0xae, 0xc3, 0xc1, 0xbf, 0x25, + 0x19, 0x7a, 0xb2, 0x7a, 0x3a, 0x7e, 0xd7, 0x5f, 0x4c, 0xbe, 0xf6, 0x08, + 0x40, 0x93, 0xf4, 0x6b, 0x66, 0xf0, 0x5b, 0x77, 0xe5, 0xf7, 0x2d, 0xf0, + 0x3c, 0x01, 0x07, 0x1d, 0xaf, 0x2f, 0x8d, 0xb8, 0x7b, 0x63, 0x6b, 0xf2, + 0x64, 0xe8, 0x49, 0xac, 0xbb, 0x24, 0x27, 0x2a, 0x7d, 0x06, 0xaa, 0x02, + 0x93, 0x4a, 0xa1, 0x19, 0x55, 0x39, 0x48, 0x9c, 0xce, 0xe6, 0xa4, 0xc0, + 0x40, 0x9b, 0xb0, 0x2b, 0xbc, 0xfb, 0xe8, 0x4e, 0x85, 0xbf, 0x48, 0x9d, + 0x08, 0x91, 0x9f, 0x18, 0xda, 0xd3, 0x94, 0x3a, 0x3a, 0x9c, 0xfc, 0xce, + 0xc6, 0xdc, 0xb7, 0x67, 0x41, 0x8f, 0x13, 0xfb, 0x2c, 0xbb, 0xc6, 0x98, + 0xf8, 0x5e, 0x28, 0x4d, 0x9c, 0x3b, 0x9f, 0xa6, 0x93, 0x29, 0xa0, 0x73, + 0xbf, 0xcb, 0x0d, 0xfe, 0x63, 0xb4, 0x85, 0x45, 0x4a, 0x55, 0xa5, 0x9d, + 0xfd, 0x1b, 0x8f, 0xdf, 0x71, 0x57, 0x8e, 0x14, 0x65, 0x65, 0x0a, 0xa9, + 0x07, 0xef, 0x31, 0xc0, 0xee, 0xe7, 0xe4, 0x4a, 0x4b, 0x4d, 0x1b, 0x13, + 0xdb, 0x4f, 0x18, 0x88, 0x8e, 0x81, 0xaa, 0xbf, 0xd1, 0x6d, 0x42, 0x84, + 0x01, 0x53, 0xef, 0x91, 0x73, 0x6e, 0x1f, 0x40, 0x39, 0x67, 0x89, 0xda, + 0x6c, 0xa9, 0x70, 0xed, 0xd6, 0xa3, 0xdd, 0x2c, 0x33, 0xcd, 0x72, 0xb4, + 0x9f, 0x2f, 0x42, 0x8d, 0x49, 0xb6, 0xe9, 0x09, 0x39, 0xc9, 0xce, 0x17, + 0xf6, 0x95, 0x04, 0x8f, 0xcf, 0xdd, 0xb7, 0xe6, 0x17, 0x4d, 0xe3, 0xb2, + 0x3d, 0xe8, 0xca, 0x97, 0x0f, 0x2b, 0xa1, 0xad, 0xaf, 0x91, 0x95, 0xa8, + 0xa3, 0x1f, 0x49, 0x71, 0xa4, 0x4a, 0x44, 0xc5, 0xdb, 0x2b, 0x34, 0x36, + 0x85, 0x49, 0x78, 0x83, 0xc2, 0xa2, 0x3d, 0x79, 0x3d, 0x3f, 0x20, 0x38, + 0x3e, 0xf3, 0xea, 0x72, 0x71, 0x55, 0xd0, 0x7e, 0x9a, 0xd2, 0x60, 0x90, + 0xe5, 0x41, 0x68, 0xbc, 0xd5, 0x12, 0x4f, 0xc4, 0x76, 0xe8, 0x58, 0x97, + 0x5e, 0x2a, 0x33, 0xa4, 0x07, 0x29, 0x84, 0xa8, 0x70, 0x34, 0xee, 0x0e, + 0x05, 0x1e, 0xb1, 0x46, 0x30, 0x10, 0xbf, 0x2b, 0x08, 0x79, 0xf5, 0x4d, + 0x6c, 0x4c, 0xa3, 0xb7, 0xfd, 0x59, 0x85, 0x1c, 0x40, 0xd1, 0x17, 0xef, + 0x24, 0x47, 0xd4, 0xee, 0x67, 0xe7, 0x2f, 0xb5, 0x30, 0x70, 0xd2, 0xda, + 0x13, 0xb1, 0x5d, 0x42, 0xa5, 0xe6, 0x60, 0xda, 0xb9, 0xd2, 0x8e, 0x1f, + 0x43, 0x4a, 0x5e, 0x10, 0xd5, 0xae, 0x37, 0xfa, 0xfb, 0xb9, 0x7b, 0x28, + 0x2d, 0x6b, 0xdf, 0x18, 0x71, 0x2f, 0x33, 0x14, 0xb3, 0x23, 0x31, 0x7a, + 0x2d, 0x92, 0xdf, 0xba, 0x1d, 0x65, 0x08, 0xee, 0x45, 0x07, 0xb1, 0x18, + 0x61, 0x82, 0x47, 0xf9, 0x35, 0xa9, 0x11, 0xc7, 0xcf, 0xf9, 0xa0, 0x5b, + 0x7b, 0x4d, 0x3f, 0xac, 0xfb, 0x00, 0x50, 0x28, 0xf0, 0x96, 0x5c, 0xd7, + 0x6d, 0x1e, 0x0e, 0x14, 0xe8, 0x29, 0xfd, 0xf8, 0x56, 0xb3, 0x85, 0x8d, + 0xdc, 0x6a, 0xb5, 0xb7, 0x74, 0x72, 0x79, 0x50, 0x17, 0xa3, 0x81, 0x48, + 0x03, 0x9b, 0xe2, 0x0b, 0x78, 0x83, 0xd1, 0x24, 0x42, 0x95, 0x89, 0xed, + 0xb7, 0x4e, 0x8a, 0xcd, 0xf5, 0x1b, 0x11, 0x7a, 0x94, 0x67, 0x83, 0xce, + 0x3b, 0xf0, 0x91, 0x9a, 0xd6, 0x62, 0xae, 0x52, 0x20, 0x3c, 0x24, 0xaf, + 0xa2, 0xb7, 0x71, 0x45, 0x56, 0x60, 0x8d, 0x6d, 0x84, 0x1f, 0xcc, 0x0c, + 0x7c, 0x0e, 0xa0, 0x79, 0xbd, 0x0b, 0x6e, 0x42, 0x3e, 0xfb, 0x3a, 0x88, + 0xa3, 0x36, 0x4d, 0x8d, 0x52, 0xe7, 0x6b, 0xfb, 0x81, 0x47, 0x5f, 0x86, + 0x2d, 0xa7, 0x87, 0xb0, 0x26, 0xb0, 0x0f, 0xb1, 0xe9, 0x24, 0xe1, 0x13, + 0x7f, 0x33, 0x9c, 0x8a, 0x23, 0x0b, 0x0a, 0x7d, 0xc6, 0xd6, 0xe3, 0x87, + 0xdd, 0x8f, 0x05, 0xf1, 0x18, 0xed, 0x74, 0x0f, 0x9f, 0x32, 0x16, 0x4a, + 0xbd, 0x44, 0x7f, 0x09, 0x90, 0x4a, 0x40, 0xf3, 0xdc, 0x92, 0x3b, 0x62, + 0xdc, 0x98, 0x58, 0x7b, 0xeb, 0x30, 0x80, 0xde, 0x0c, 0x27, 0x7c, 0x2b, + 0x4a, 0xa6, 0xb9, 0x1e, 0x22, 0xc6, 0x78, 0x84, 0xf5, 0x56, 0x36, 0x7f, + 0x94, 0x2f, 0x45, 0x95, 0xfa, 0x42, 0x8f, 0x1f, 0x98, 0xdb, 0x8e, 0xf0, + 0x9c, 0x88, 0x04, 0x8c, 0x60, 0xa9, 0x41, 0x52, 0x22, 0xe3, 0xc2, 0x28, + 0xbd, 0x98, 0x71, 0x93, 0x22, 0x23, 0xc0, 0x6d, 0xd0, 0x62, 0x9b, 0x3f, + 0xbc, 0x98, 0x7d, 0x30, 0x5c, 0x5c, 0x6a, 0xfc, 0x03, 0x31, 0x5a, 0x6f, + 0xe0, 0xd8, 0x69, 0x71, 0x62, 0x6e, 0x0f, 0x7f, 0x35, 0x52, 0xee, 0xe5, + 0x6a, 0xa0, 0xb1, 0x80, 0x3c, 0xbf, 0x99, 0x10, 0x70, 0x25, 0xe2, 0xc5, + 0x12, 0xa4, 0xb0, 0xcd, 0x52, 0x3d, 0xf0, 0xaa, 0x9f, 0xc6, 0x5a, 0xd3, + 0xef, 0x6a, 0xf6, 0xd4, 0x68, 0x85, 0x52, 0xec, 0xaf, 0x8d, 0x55, 0x4d, + 0x06, 0x28, 0xf1, 0x9b, 0x1d, 0xd1, 0x78, 0x3c, 0xc4, 0x93, 0xa2, 0xdf, + 0xeb, 0xdd, 0xe9, 0x09, 0xee, 0x5c, 0x16, 0xfe, 0xd3, 0x23, 0xb7, 0x24, + 0x15, 0x39, 0x19, 0x8c, 0xd9, 0xf7, 0x3c, 0xad, 0x8e, 0x05, 0x6d, 0x46, + 0xb6, 0x90, 0x91, 0x87, 0x26, 0x09, 0xb9, 0x29, 0x88, 0x65, 0x73, 0xe5, + 0x03, 0xca, 0xd6, 0xe4, 0x50, 0x94, 0x26, 0x2d, 0x0e, 0x20, 0x6a, 0x63, + 0x84, 0xee, 0x1f, 0x21, 0xcd, 0x4f, 0x86, 0x37, 0xfc, 0x11, 0xdf, 0x17, + 0x74, 0xbd, 0xf1, 0x39, 0xf6, 0xee, 0xbc, 0xec, 0xe8, 0x01, 0x17, 0x6a, + 0x11, 0x1d, 0x86, 0x48, 0xa0, 0x6e, 0xd6, 0xfe, 0x1d, 0x7b, 0x93, 0x2b, + 0xb2, 0xc4, 0xaf, 0xd3, 0xf9, 0xd6, 0xc4, 0xe0, 0x87, 0x3c, 0xaf, 0xfe, + 0xfe, 0xcf, 0xf9, 0x44, 0x4f, 0xb1, 0xe3, 0xde, 0x5f, 0xe9, 0x89, 0xc3, + 0xbe, 0x23, 0x34, 0x2b, 0x32, 0x8e, 0x5d, 0x9f, 0x96, 0x87, 0x7f, 0xf2, + 0x2e, 0x10, 0xc6, 0xef, 0xb8, 0x6d, 0xee, 0x01, 0xb5, 0x16, 0xd4, 0x25, + 0x7c, 0x06, 0x89, 0x2a, 0x84, 0x80, 0xfd, 0xbc, 0x4a, 0x67, 0xa1, 0x9d, + 0xc8, 0xba, 0x1a, 0xc3, 0x12, 0x3c, 0x51, 0x92, 0xf3, 0xd7, 0xf5, 0x78, + 0xcb, 0x62, 0xa7, 0xff, 0xd9, 0x68, 0xd4, 0x3a, 0x62, 0xb9, 0x83, 0x3c, + 0xb6, 0x46, 0x50, 0xea, 0xca, 0x08, 0x01, 0x4c, 0xc0, 0x82, 0x41, 0x8d, + 0x06, 0x3b, 0x55, 0x56, 0x26, 0x00, 0xca, 0x23, 0x2f, 0x3e, 0x08, 0xd9, + 0xc2, 0x4d, 0x26, 0xda, 0x49, 0xee, 0xb2, 0xbc, 0x89, 0xb6, 0x8f, 0xa5, + 0x37, 0x38, 0x6e, 0x79, 0x94, 0x07, 0x2a, 0x56, 0x43, 0x23, 0xf5, 0xb0, + 0x97, 0x5e, 0x3f, 0xd7, 0x7f, 0xa3, 0xdb, 0x02, 0xdd, 0xb9, 0x62, 0x65, + 0x14, 0x46, 0xba, 0x08, 0xf0, 0x2f, 0x7e, 0xde, 0x5a, 0xb5, 0x58, 0x1d, + 0x04, 0x49, 0x5f, 0xd6, 0xd2, 0x29, 0x01, 0x81, 0xea, 0x9e, 0xdf, 0xe2, + 0x66, 0xbe, 0x24, 0x2d, 0xb5, 0x38, 0x19, 0x44, 0x70, 0x49, 0x17, 0xb2, + 0x00, 0x7a, 0x75, 0x27, 0xf7, 0x47, 0xca, 0x54, 0xc9, 0x6a, 0x6b, 0x06, + 0xd0, 0x13, 0xb5, 0x3d, 0x02, 0x4b, 0x84, 0xa4, 0xe8, 0x67, 0x90, 0xac, + 0xa8, 0xfc, 0x68, 0x03, 0x4d, 0xbc, 0x61, 0xf5, 0x82, 0xdb, 0x85, 0xd9, + 0x76, 0xba, 0xb5, 0xea, 0x34, 0x9a, 0x2d, 0x89, 0xa5, 0x19, 0x5f, 0xfa, + 0xbe, 0x6b, 0xab, 0x5d, 0x88, 0x12, 0x9b, 0xaa, 0xfd, 0xd7, 0x6d, 0x7d, + 0x3f, 0xfa, 0x54, 0x8d, 0x44, 0xe8, 0x62, 0x3c, 0x08, 0xd6, 0x7a, 0x38, + 0xbb, 0x74, 0xdd, 0xad, 0x5c, 0x24, 0x91, 0x19, 0x28, 0x15, 0xea, 0x97, + 0x7e, 0xa4, 0x44, 0xaa, 0xb6, 0x43, 0x70, 0xda, 0xab, 0x06, 0x46, 0x78, + 0x79, 0x65, 0x3c, 0x79, 0xe1, 0x74, 0x70, 0xce, 0x5c, 0x02, 0x2e, 0x19, + 0xb0, 0xbb, 0x34, 0x38, 0xe8, 0xe5, 0xec, 0x33, 0x3a, 0x93, 0xcf, 0x7d, + 0x16, 0x9a, 0xcb, 0x52, 0x3b, 0xe6, 0xa9, 0xb6, 0x14, 0xc3, 0x6e, 0x52, + 0xe9, 0x7b, 0x05, 0x82, 0x76, 0x04, 0xaf, 0xff, 0x22, 0x8a, 0xc9, 0xdd, + 0x84, 0x1e, 0x30, 0x1f, 0x3d, 0x3a, 0x3d, 0xd0, 0x8a, 0x3c, 0x7a, 0x80, + 0xf6, 0x34, 0x24, 0x5f, 0x69, 0xaf, 0x93, 0x98, 0xb8, 0xc3, 0xa2, 0xc8, + 0x45, 0x38, 0x79, 0x3b, 0x1e, 0x33, 0x48, 0xcc, 0xa4, 0x14, 0x60, 0x1a, + 0x71, 0x2c, 0xc4, 0x6a, 0x07, 0x94, 0x51, 0x00, 0xa6, 0xe1, 0xa7, 0xb1, + 0x83, 0xa8, 0xbf, 0x9e, 0xc0, 0xae, 0xae, 0xef, 0x44, 0xf0, 0x5b, 0x6a, + 0xdd, 0x1f, 0x92, 0x52, 0xf9, 0x70, 0xd5, 0x22, 0xc3, 0x6d, 0xe5, 0x3e, + 0xba, 0xdb, 0x3c, 0x0b, 0x13, 0x8f, 0x67, 0xb2, 0x1d, 0xda, 0x8b, 0xe8, + 0xeb, 0xd1, 0x87, 0x5e, 0xc0, 0x53, 0xe6, 0xad, 0x17, 0xcc, 0x61, 0x0e, + 0xc5, 0x04, 0x15, 0x40, 0x0d, 0x34, 0xf9, 0x58, 0xde, 0xa8, 0x3b, 0x16, + 0x12, 0x86, 0xf3, 0x85, 0xf6, 0x6e, 0x5b, 0x35, 0x53, 0xca, 0xcf, 0x4f, + 0xae, 0xda, 0x17, 0x61, 0xd1, 0x53, 0x6d, 0xa9, 0x73, 0x37, 0xee, 0x3d, + 0xde, 0xaf, 0x98, 0x22, 0xdb, 0xfc, 0x29, 0xe5, 0x8f, 0x0a, 0x13, 0x52, + 0x06, 0xa0, 0x86, 0xc5, 0x34, 0xe6, 0xcc, 0x84, 0x6c, 0xb0, 0x4d, 0x4b, + 0xba, 0x93, 0x7d, 0xcc, 0x74, 0xb2, 0x18, 0x60, 0xa2, 0x9f, 0x61, 0xf6, + 0x6d, 0x23, 0xd1, 0xd1, 0x37, 0xc5, 0xbe, 0x5f, 0xef, 0xb6, 0x49, 0xb8, + 0xc3, 0x06, 0x0f, 0x33, 0x6a, 0x5d, 0xc2, 0x86, 0xe6, 0x0b, 0xc7, 0x92, + 0x84, 0xd0, 0x97, 0x44, 0x4c, 0x84, 0x7e, 0xab, 0x9d, 0x3f, 0xc6, 0x77, + 0x0c, 0x5f, 0x9b, 0xd6, 0x10, 0x7a, 0x74, 0x69, 0x31, 0xed, 0x22, 0x40, + 0x99, 0x92, 0x23, 0xcb, 0x2b, 0x3f, 0xcf, 0xdb, 0xfa, 0x87, 0x92, 0x27, + 0x9d, 0xfd, 0x6a, 0x3e, 0xb6, 0x56, 0x44, 0x00, 0xb4, 0x75, 0xf9, 0xad, + 0x4f, 0xb4, 0xa5, 0x9b, 0x50, 0xf7, 0x52, 0x15, 0x27, 0x52, 0x45, 0x35, + 0xb8, 0x07, 0xc3, 0x82, 0x75, 0x27, 0xec, 0x7c, 0xd0, 0x12, 0x56, 0x56, + 0xb3, 0x58, 0x28, 0xbc, 0xb3, 0x57, 0x56, 0xd1, 0xdf, 0xbc, 0xdc, 0x2c, + 0x26, 0x7f, 0x6a, 0x15, 0x7f, 0xe6, 0x67, 0x9c, 0xa1, 0x9d, 0xb4, 0x76, + 0xb8, 0xc7, 0x24, 0x7d, 0xe4, 0x07, 0xc7, 0xd5, 0xc8, 0x58, 0xbc, 0xe1, + 0x42, 0x0c, 0xd1, 0x69, 0x18, 0xb2, 0x54, 0x73, 0x24, 0xd0, 0xea, 0x59, + 0xc1, 0x75, 0x5a, 0xbb, 0x36, 0x2c, 0x7a, 0x4b, 0x83, 0x1f, 0x97, 0xa2, + 0x57, 0x78, 0x66, 0xee, 0xa5, 0x06, 0x67, 0x9a, 0x03, 0xa0, 0xc2, 0xfd, + 0x89, 0x2c, 0x36, 0x62, 0x5c, 0x2e, 0x69, 0x9e, 0xb3, 0x87, 0x38, 0xde, + 0xce, 0xc2, 0xf9, 0x42, 0x80, 0x5d, 0x9e, 0xbc, 0xda, 0xbd, 0x4a, 0x53, + 0x94, 0x46, 0xce, 0xa2, 0x8c, 0xdd, 0xca, 0x4c, 0xbd, 0x5c, 0x2b, 0x40, + 0x09, 0x93, 0x24, 0xac, 0xcc, 0x27, 0xc7, 0x70, 0x0f, 0x2e, 0xc1, 0x5b, + 0x33, 0x83, 0x8c, 0x84, 0xd7, 0xf0, 0x35, 0xab, 0xf6, 0x99, 0xc6, 0x36, + 0x2c, 0xc3, 0x31, 0x38, 0xd2, 0x4f, 0x81, 0x2a, 0xcf, 0x58, 0x6c, 0x04, + 0xee, 0xc2, 0xe9, 0x4a, 0x13, 0x11, 0x30, 0xe6, 0x2f, 0xf9, 0xcc, 0xfa, + 0x50, 0x0a, 0xba, 0xdb, 0x6f, 0xb6, 0xfb, 0xe6, 0x65, 0xaf, 0x31, 0x89, + 0xdb, 0x3f, 0xf3, 0x40, 0xa6, 0xcf, 0xa7, 0x75, 0x6a, 0x73, 0x14, 0xfe, + 0x3c, 0x80, 0x7a, 0xd4, 0xda, 0x36, 0x6f, 0x29, 0x73, 0x13, 0x7b, 0xad, + 0x8c, 0xd2, 0xcc, 0x67, 0x66, 0x2e, 0xbe, 0xde, 0x83, 0x41, 0x3f, 0x1f, + 0x2a, 0x49, 0xab, 0x3a, 0x32, 0xf4, 0x45, 0xfe, 0xc6, 0xa2, 0x8b, 0x2d, + 0x1c, 0x7b, 0x5a, 0x26, 0x9a, 0x3c, 0x81, 0x15, 0x3d, 0x1a, 0xfa, 0x4d, + 0xad, 0x07, 0x56, 0xff, 0x3d, 0xdc, 0xdb, 0x30, 0xec, 0x29, 0x20, 0x96, + 0x6f, 0xf8, 0xce, 0xc5, 0xfc, 0x0b, 0x1a, 0x81, 0x72, 0x03, 0x05, 0x26, + 0xd7, 0x85, 0x02, 0x4c, 0x39, 0x0e, 0xa1, 0x71, 0x01, 0x9b, 0xe0, 0xbd, + 0xd3, 0xe4, 0xd8, 0xc9, 0xba, 0xaf, 0x64, 0xcf, 0x82, 0xb5, 0x7d, 0x25, + 0x70, 0xc1, 0xc5, 0x95, 0x90, 0x43, 0x1e, 0x3c, 0xb9, 0xbc, 0x26, 0x1e, + 0xae, 0x10, 0x0e, 0x88, 0xe4, 0xe7, 0x20, 0xba, 0xb9, 0x10, 0x50, 0x17, + 0x24, 0x50, 0x5e, 0x55, 0xb4, 0x97, 0xad, 0x39, 0x8e, 0x16, 0x6f, 0x6f, + 0x83, 0xd1, 0x22, 0xa9, 0x90, 0xc4, 0xe3, 0x1e, 0x61, 0xba, 0x95, 0x96, + 0xe0, 0xac, 0xc9, 0x77, 0x92, 0xc3, 0xa5, 0x40, 0x9b, 0xd2, 0x1f, 0x5e, + 0x51, 0x5e, 0x28, 0xe7, 0x66, 0xe8, 0x95, 0x93, 0x12, 0xe8, 0x0c, 0x01, + 0x6d, 0xbf, 0xe9, 0x25, 0xee, 0xa6, 0xd6, 0x76, 0x17, 0xf6, 0xdc, 0xfb, + 0xfb, 0xd9, 0x44, 0x93, 0x18, 0x8d, 0x9d, 0x68, 0x8f, 0xa1, 0x16, 0x7a, + 0x88, 0xdc, 0xa6, 0xb1, 0xb1, 0xf3, 0xd7, 0x12, 0xd4, 0x71, 0x65, 0xfb, + 0x44, 0x65, 0xbf, 0xa9, 0x77, 0x2d, 0xd4, 0x7d, 0x17, 0x94, 0x7a, 0x36, + 0x39, 0x67, 0xff, 0x84, 0x20, 0x91, 0x66, 0xbb, 0x11, 0x85, 0xbf, 0x61, + 0xb7, 0x6e, 0x1f, 0xfb, 0xac, 0x2f, 0x96, 0xad, 0x4d, 0x48, 0x49, 0xc1, + 0xa6, 0x4e, 0xee, 0xb5, 0x56, 0x2f, 0xc9, 0x56, 0x27, 0x02, 0xa8, 0x4e, + 0xf5, 0x50, 0x2a, 0x71, 0x5a, 0xe3, 0xbb, 0xeb, 0xf4, 0xaf, 0x70, 0x3b, + 0x35, 0xce, 0x67, 0xb7, 0x0b, 0x17, 0xe5, 0x09, 0x6b, 0x6d, 0xf3, 0x06, + 0xd2, 0x99, 0xf1, 0x06, 0x2d, 0xc8, 0x64, 0x09, 0x41, 0x46, 0xd2, 0xef, + 0x60, 0xca, 0x77, 0x51, 0x22, 0x1f, 0xd0, 0x05, 0x97, 0x35, 0xd6, 0x85, + 0xf9, 0xb8, 0x4e, 0x3b, 0x5c, 0x74, 0x23, 0x35, 0x44, 0x02, 0x82, 0x0a, + 0xe8, 0x20, 0x06, 0xaf, 0x91, 0xdb, 0x34, 0xc6, 0xfa, 0x1d, 0xe8, 0x6c, + 0xa5, 0xb7, 0x90, 0x08, 0x40, 0x70, 0xf7, 0x2c, 0x23, 0x9f, 0x6a, 0x81, + 0x11, 0xe3, 0xc0, 0x34, 0xa7, 0x19, 0x6c, 0xb4, 0xc3, 0xbb, 0xd8, 0x8d, + 0xac, 0xa1, 0x95, 0x06, 0x56, 0x59, 0xac, 0x85, 0x1e, 0xe6, 0x75, 0x62, + 0xb9, 0x9f, 0x89, 0x04, 0xfc, 0x75, 0x15, 0x67, 0x9f, 0x13, 0xa5, 0x7e, + 0x46, 0xe5, 0x52, 0x15, 0x6d, 0x65, 0x33, 0x61, 0xb4, 0x67, 0x5b, 0x99, + 0x39, 0x58, 0x45, 0x0d, 0x9d, 0xcb, 0x29, 0x71, 0x25, 0x1f, 0x4d, 0xa3, + 0xd8, 0xd4, 0x73, 0x34, 0xd3, 0x94, 0x64, 0x2d, 0x9a, 0xbe, 0x80, 0xbc, + 0xad, 0x88, 0x96, 0x8a, 0x0c, 0xc3, 0xf4, 0x93, 0xfc, 0x59, 0x32, 0xc6, + 0x4d, 0xac, 0x63, 0xda, 0xfd, 0x12, 0x38, 0xa4, 0xb9, 0xd5, 0x76, 0x60, + 0xa3, 0x07, 0x1d, 0x0c, 0xd9, 0x75, 0xf9, 0x25, 0x85, 0x3d, 0xf2, 0xfa, + 0x1f, 0xf7, 0x12, 0xe1, 0x62, 0x3c, 0xd6, 0xc8, 0x22, 0x27, 0xf0, 0x72, + 0x4c, 0xa2, 0x11, 0xb0, 0x6d, 0xc9, 0xb6, 0xb5, 0x09, 0x21, 0x25, 0xb3, + 0x25, 0x8e, 0x95, 0x3c, 0xc3, 0xd8, 0xcf, 0xa1, 0xee, 0x70, 0x5f, 0x1f, + 0xb2, 0x05, 0xa9, 0xb6, 0x8f, 0xa0, 0xf9, 0x2b, 0x86, 0xf3, 0x1d, 0xe4, + 0x80, 0x1a, 0xde, 0xc1, 0x2c, 0x30, 0xba, 0x3f, 0x2a, 0xad, 0x57, 0xe6, + 0x02, 0x28, 0xd1, 0x59, 0x68, 0x7c, 0x95, 0x9e, 0x24, 0xc2, 0x56, 0x65, + 0x50, 0x6a, 0x51, 0xf5, 0xfa, 0xa9, 0x70, 0xa7, 0x00, 0x55, 0x63, 0x09, + 0x0e, 0xa0, 0x27, 0xf2, 0xed, 0xfc, 0xa6, 0xed, 0x83, 0x04, 0x9d, 0x70, + 0x9c, 0x92, 0x1f, 0x9b, 0x6e, 0xe1, 0x15, 0x3b, 0xac, 0x22, 0x8f, 0x69, + 0xe7, 0x78, 0x45, 0xb5, 0x0f, 0xd4, 0x0f, 0xb6, 0x30, 0x29, 0xa3, 0x10, + 0x85, 0x99, 0xb6, 0xa6, 0xb8, 0xce, 0x8d, 0x85, 0xca, 0x29, 0x2f, 0xb9, + 0x55, 0xb6, 0x18, 0x8c, 0x34, 0xe9, 0x90, 0x99, 0x9c, 0x03, 0xc5, 0x06, + 0x71, 0xa1, 0x8e, 0xcd, 0x25, 0x70, 0x6b, 0x07, 0x57, 0x1e, 0x15, 0x66, + 0x7e, 0x6e, 0x9a, 0xe6, 0x89, 0xd9, 0xa6, 0x77, 0x91, 0x10, 0xd1, 0x9c, + 0xef, 0xfa, 0x5b, 0x84, 0x5f, 0xe3, 0xe5, 0x87, 0xd0, 0x40, 0xf0, 0x40, + 0x87, 0xb3, 0x7f, 0x73, 0x67, 0xcd, 0x19, 0x72, 0x73, 0x39, 0x9b, 0x1e, + 0xd5, 0xe2, 0x5a, 0x0f, 0x97, 0x9c, 0xfe, 0x54, 0xa5, 0x54, 0x65, 0x45, + 0x64, 0x40, 0x49, 0x50, 0xc1, 0xc5, 0x19, 0x6c, 0x6c, 0xe4, 0xa4, 0x97, + 0x3f, 0x73, 0xdb, 0xfe, 0x0b, 0xbe, 0x1f, 0x45, 0xdb, 0xb3, 0x5f, 0x3b, + 0xa3, 0x9f, 0x37, 0xc6, 0x9f, 0x65, 0xc6, 0x95, 0xe1, 0xe1, 0xc1, 0x40, + 0x16, 0x19, 0x6d, 0x74, 0x95, 0x82, 0xf5, 0x4a, 0x41, 0xe2, 0x83, 0x4d, + 0x6f, 0xad, 0x78, 0x74, 0x26, 0xc1, 0x5e, 0x49, 0xb6, 0x19, 0x3b, 0xb0, + 0x86, 0xce, 0xeb, 0x19, 0xd8, 0x95, 0x79, 0xdd, 0x50, 0x00, 0xc7, 0x0c, + 0x40, 0x87, 0x62, 0xae, 0x56, 0x65, 0x83, 0xcd, 0x9d, 0xcc, 0x19, 0xad, + 0xc4, 0x46, 0x8c, 0x21, 0xee, 0x77, 0x00, 0x51, 0x7a, 0x0b, 0x09, 0xa6, + 0x9a, 0x02, 0x5a, 0xbc, 0x56, 0x14, 0x58, 0x5f, 0x6e, 0x33, 0x92, 0xe8, + 0x46, 0xf8, 0x89, 0x9a, 0xe5, 0x44, 0x8f, 0x62, 0x37, 0x11, 0xd5, 0x08, + 0x81, 0xb0, 0x2b, 0xce, 0xf6, 0xe9, 0x32, 0x48, 0x2a, 0x47, 0xad, 0x7c, + 0x10, 0x25, 0x93, 0xf1, 0x42, 0x1e, 0xf6, 0x52, 0x62, 0x23, 0x8f, 0x9f, + 0x48, 0xa1, 0x76, 0x83, 0x79, 0x0b, 0x6b, 0x57, 0x4d, 0x66, 0xa4, 0x53, + 0xa5, 0x98, 0x41, 0xcc, 0x36, 0xa4, 0x48, 0x83, 0x06, 0x14, 0x9d, 0xbe, + 0xe8, 0x97, 0xe8, 0xf5, 0x46, 0x6d, 0x73, 0xd9, 0xd9, 0x30, 0xf0, 0xc9, + 0x3f, 0x94, 0xaf, 0xc0, 0x62, 0xed, 0xfd, 0x02, 0x8d, 0x62, 0xbf, 0xb3, + 0x0e, 0xe8, 0x9b, 0xc1, 0x3c, 0x68, 0x15, 0x7c, 0xe1, 0xbc, 0x6a, 0xe0, + 0xe1, 0xa0, 0x8f, 0x56, 0x49, 0x71, 0xed, 0x55, 0xa4, 0xb6, 0xba, 0x97, + 0x96, 0xea, 0xf1, 0xd4, 0x54, 0x7a, 0x51, 0x22, 0x51, 0x60, 0x40, 0xd7, + 0x1e, 0x63, 0x76, 0xca, 0x4d, 0x47, 0x5a, 0xec, 0xf7, 0x61, 0xd1, 0xe5, + 0x04, 0x50, 0x41, 0xb5, 0xa8, 0xdf, 0x90, 0xc3, 0xa1, 0xfc, 0xcb, 0x02, + 0x0c, 0x7f, 0x2a, 0xda, 0x7d, 0x18, 0xad, 0x72, 0x6c, 0x66, 0x02, 0xb3, + 0x34, 0xba, 0x80, 0x26, 0xe0, 0x73, 0xd6, 0xe2, 0x61, 0x25, 0x1c, 0x92, + 0xd9, 0x72, 0x40, 0x2e, 0x14, 0x9b, 0x2b, 0xab, 0xc0, 0x11, 0xe5, 0xdf, + 0x27, 0xc5, 0xe8, 0x4b, 0xd9, 0x0f, 0x2e, 0xb1, 0x4d, 0xad, 0x09, 0x9c, + 0x80, 0x20, 0xab, 0x0c, 0xa6, 0x1d, 0xd9, 0x4a, 0x82, 0x9a, 0x7f, 0x88, + 0x4e, 0x05, 0x3a, 0xb7, 0x0a, 0x1f, 0x87, 0xad, 0x67, 0xa2, 0x41, 0x05, + 0x90, 0xdf, 0xb8, 0xc5, 0xa1, 0x89, 0xc5, 0xe0, 0x4c, 0xf6, 0x87, 0x10, + 0xd8, 0xc8, 0x32, 0x71, 0x17, 0xd6, 0x68, 0xfc, 0xdc, 0xc7, 0xe6, 0xd4, + 0xe8, 0x27, 0xb5, 0x48, 0x89, 0x89, 0xa2, 0x5e, 0x7f, 0x53, 0x85, 0xba, + 0x0a, 0x3f, 0x2c, 0x27, 0x9f, 0xd9, 0xf6, 0x5c, 0x97, 0x4b, 0x42, 0x3e, + 0xda, 0x74, 0xe0, 0xa2, 0x01, 0x41, 0x73, 0xad, 0xc5, 0x3b, 0x29, 0x07, + 0xda, 0xb5, 0x76, 0xca, 0x5e, 0x1d, 0x1e, 0xed, 0x70, 0x33, 0xf3, 0xaa, + 0xde, 0x0b, 0xf5, 0x0a, 0xbf, 0xc8, 0x5a, 0x52, 0x1f, 0xf6, 0xf1, 0x11, + 0xc9, 0xa9, 0xf4, 0xf2, 0xfc, 0xc0, 0x59, 0x70, 0x19, 0xe6, 0x98, 0x38, + 0x0d, 0x35, 0xf1, 0xe4, 0x40, 0xdf, 0x38, 0x02, 0x92, 0xcb, 0x3b, 0xc2, + 0x74, 0x41, 0x41, 0xa0, 0xc4, 0x2c, 0xc2, 0xf9, 0xc3, 0x75, 0xa6, 0x98, + 0xd2, 0x80, 0x8c, 0x7b, 0xb1, 0xae, 0xc2, 0xd4, 0xbc, 0xce, 0x2f, 0xe0, + 0xff, 0x99, 0xb0, 0xd4, 0x9f, 0xd2, 0x3e, 0xad, 0x02, 0x1e, 0x3d, 0xfd, + 0x34, 0x2b, 0x19, 0x0e, 0xeb, 0xc2, 0x0e, 0x3d, 0x7b, 0xcb, 0x4c, 0x98, + 0x77, 0x0c, 0xcf, 0xf2, 0xee, 0x3f, 0xe9, 0x01, 0x83, 0xf4, 0x63, 0xcc, + 0x13, 0xa1, 0x23, 0xb1, 0x3d, 0x4a, 0x61, 0xea, 0x2b, 0x62, 0x07, 0x46, + 0x1a, 0x03, 0x3b, 0x88, 0x02, 0xc9, 0x93, 0x70, 0x96, 0x7f, 0xbe, 0x5e, + 0xbd, 0x66, 0xd2, 0xa1, 0xe2, 0xc1, 0xbc, 0xc5, 0x1b, 0x2b, 0x59, 0x7e, + 0x65, 0x33, 0x1d, 0xc4, 0x43, 0x57, 0x00, 0x89, 0x3b, 0x1f, 0xb6, 0xb7, + 0x4c, 0xa6, 0x18, 0x9c, 0xa2, 0x6c, 0xbf, 0x2d, 0x70, 0xd3, 0x73, 0x6b, + 0xfc, 0x90, 0x09, 0xd9, 0x97, 0xfb, 0xfc, 0x45, 0x22, 0x35, 0xa2, 0x51, + 0x03, 0x64, 0xc2, 0xfd, 0xc1, 0x85, 0xec, 0x81, 0x66, 0x58, 0x31, 0xee, + 0x00, 0x6d, 0x22, 0x4c, 0x59, 0xcf, 0x07, 0x78, 0x88, 0x39, 0xc0, 0x29, + 0x67, 0xf9, 0x3d, 0x59, 0xb0, 0x0b, 0x45, 0x7d, 0x1f, 0xe7, 0x19, 0x26, + 0x4f, 0xfc, 0xd3, 0x4c, 0x43, 0x2c, 0x14, 0xd2, 0x10, 0x97, 0xee, 0xcf, + 0x3c, 0x51, 0x8f, 0xfd, 0x4d, 0x12, 0xf4, 0xda, 0xe8, 0xa1, 0xa6, 0x89, + 0x46, 0xfe, 0xc3, 0x1f, 0x22, 0x6a, 0x62, 0xb5, 0x90, 0xe5, 0x9b, 0xc2, + 0xbe, 0x77, 0x81, 0x78, 0x33, 0x0a, 0x5c, 0x2e, 0x3e, 0x55, 0xbf, 0x34, + 0xe5, 0x8a, 0x32, 0x4c, 0xf0, 0xff, 0xd2, 0x6e, 0xf4, 0x92, 0x04, 0x75, + 0x97, 0x7b, 0x18, 0xa2, 0xd5, 0x7c, 0xe1, 0xef, 0xed, 0x2e, 0x0c, 0xeb, + 0xa9, 0x4f, 0xd1, 0x7f, 0x8d, 0xe5, 0xd7, 0xe2, 0xf1, 0x66, 0x01, 0xf7, + 0x80, 0xe2, 0x4c, 0x33, 0x4a, 0x68, 0x5b, 0x8f, 0xd7, 0x75, 0x6a, 0xe5, + 0xe6, 0x95, 0x2d, 0xa0, 0x44, 0xf7, 0xb7, 0x7e, 0x6f, 0x21, 0x64, 0xd6, + 0x24, 0x15, 0x70, 0xce, 0x9b, 0x8d, 0x3b, 0x21, 0x47, 0x84, 0xd7, 0x43, + 0xc3, 0x34, 0xda, 0xc2, 0x69, 0x2b, 0x6b, 0xbd, 0xc7, 0x65, 0xe0, 0x74, + 0xb9, 0x71, 0xe3, 0x34, 0xde, 0x74, 0x8c, 0xeb, 0xa8, 0x55, 0xb6, 0x32, + 0x3d, 0x70, 0x2b, 0xf8, 0x32, 0xa6, 0xc3, 0xaf, 0x41, 0x7d, 0x13, 0x95, + 0x2e, 0xb1, 0x03, 0xd4, 0x2e, 0x2c, 0x3d, 0x5c, 0x18, 0x05, 0x0a, 0x06, + 0x71, 0x62, 0x2f, 0x1a, 0xc1, 0x45, 0xf2, 0x28, 0x7e, 0xeb, 0xaf, 0x64, + 0xcb, 0xff, 0xe9, 0xb5, 0xa5, 0x35, 0x0d, 0x16, 0xe6, 0x9e, 0xd7, 0x9d, + 0x85, 0x27, 0x68, 0x12, 0xd0, 0xaf, 0xfe, 0xea, 0x0f, 0xdb, 0x99, 0xc1, + 0xc4, 0xfe, 0x51, 0xa3, 0x00, 0xfc, 0x12, 0x11, 0xb0, 0xfc, 0x7a, 0x32, + 0x34, 0x45, 0x05, 0xd9, 0x03, 0xda, 0x6b, 0x58, 0x29, 0x2f, 0x5a, 0xbc, + 0x57, 0x9d, 0x6a, 0x17, 0x2e, 0x26, 0xa8, 0xdb, 0xbb, 0x95, 0x40, 0xbd, + 0xe9, 0x55, 0x85, 0x19, 0x1a, 0xad, 0xaf, 0x67, 0x8f, 0x27, 0x1e, 0xbe, + 0x47, 0xc5, 0x8a, 0x55, 0x09, 0x97, 0xcc, 0x58, 0x3f, 0x8e, 0xa5, 0x26, + 0xb1, 0x61, 0xd6, 0xfa, 0x31, 0xb7, 0x16, 0x75, 0x46, 0x27, 0x78, 0x83, + 0x93, 0x4b, 0x62, 0xde, 0x64, 0x02, 0x1d, 0xfa, 0x1b, 0xce, 0x51, 0x43, + 0xec, 0x17, 0x6a, 0x60, 0x99, 0x8c, 0xdc, 0xb7, 0xa6, 0x32, 0x8d, 0x31, + 0x1e, 0x3d, 0xeb, 0xe2, 0x56, 0xf7, 0xa0, 0x79, 0xee, 0x75, 0x88, 0xa1, + 0xb8, 0x61, 0x68, 0x38, 0xde, 0x69, 0x36, 0x0d, 0x30, 0x84, 0xc4, 0x0c, + 0x30, 0x95, 0xad, 0xb3, 0xf9, 0x06, 0x23, 0x91, 0xe3, 0x04, 0x3a, 0x4b, + 0x56, 0x63, 0xb5, 0xb7, 0xd0, 0xe9, 0x0a, 0x3a, 0x3f, 0x73, 0x7d, 0xc4, + 0x14, 0x1c, 0x47, 0x4e, 0x5c, 0xac, 0xb8, 0x39, 0x42, 0x88, 0x93, 0xa2, + 0xc3, 0xc5, 0xd1, 0x04, 0x0b, 0x4f, 0x6e, 0x8f, 0xb5, 0xbb, 0xc4, 0xd9, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0a, + 0x0e, 0x17, 0x1d, 0x24, 0x2c, 0x35 +}; + +// +// mldsa87_private.pem as C array +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mMlDsa87TestPemKey[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x50, + 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x54, 0x58, 0x67, 0x49, 0x42, + 0x41, 0x44, 0x41, 0x4c, 0x42, 0x67, 0x6c, 0x67, 0x68, 0x6b, 0x67, 0x42, + 0x5a, 0x51, 0x4d, 0x45, 0x41, 0x78, 0x4d, 0x45, 0x67, 0x68, 0x4e, 0x4b, + 0x4d, 0x49, 0x49, 0x54, 0x52, 0x67, 0x51, 0x67, 0x4a, 0x65, 0x49, 0x6e, + 0x45, 0x2b, 0x78, 0x6f, 0x48, 0x4a, 0x66, 0x30, 0x4f, 0x50, 0x4e, 0x6f, + 0x69, 0x64, 0x59, 0x51, 0x45, 0x78, 0x67, 0x57, 0x0a, 0x4e, 0x48, 0x7a, + 0x2b, 0x39, 0x4b, 0x46, 0x4e, 0x6c, 0x42, 0x51, 0x6d, 0x6e, 0x67, 0x6a, + 0x54, 0x6a, 0x39, 0x77, 0x45, 0x67, 0x68, 0x4d, 0x67, 0x6b, 0x38, 0x68, + 0x45, 0x61, 0x7a, 0x59, 0x6a, 0x65, 0x58, 0x4e, 0x71, 0x49, 0x50, 0x50, + 0x52, 0x63, 0x71, 0x4c, 0x4b, 0x57, 0x46, 0x4e, 0x69, 0x66, 0x6b, 0x4e, + 0x33, 0x54, 0x69, 0x79, 0x34, 0x76, 0x59, 0x33, 0x56, 0x35, 0x35, 0x69, + 0x78, 0x0a, 0x6f, 0x58, 0x47, 0x73, 0x32, 0x69, 0x55, 0x72, 0x6e, 0x55, + 0x32, 0x42, 0x62, 0x4b, 0x62, 0x30, 0x43, 0x2b, 0x6a, 0x76, 0x36, 0x53, + 0x4c, 0x67, 0x79, 0x44, 0x67, 0x6d, 0x66, 0x32, 0x73, 0x65, 0x36, 0x4a, + 0x51, 0x64, 0x62, 0x64, 0x4d, 0x72, 0x30, 0x55, 0x30, 0x73, 0x64, 0x78, + 0x52, 0x68, 0x58, 0x75, 0x64, 0x70, 0x41, 0x42, 0x2b, 0x34, 0x6d, 0x43, + 0x6e, 0x4b, 0x56, 0x36, 0x51, 0x74, 0x0a, 0x74, 0x4c, 0x67, 0x63, 0x30, + 0x31, 0x78, 0x35, 0x79, 0x33, 0x37, 0x58, 0x2b, 0x47, 0x4c, 0x38, 0x79, + 0x65, 0x4c, 0x74, 0x4b, 0x2b, 0x61, 0x44, 0x39, 0x6d, 0x75, 0x41, 0x44, + 0x76, 0x45, 0x33, 0x34, 0x68, 0x65, 0x35, 0x46, 0x66, 0x46, 0x4a, 0x55, + 0x7a, 0x46, 0x57, 0x30, 0x69, 0x66, 0x31, 0x69, 0x41, 0x66, 0x39, 0x70, + 0x33, 0x68, 0x44, 0x4f, 0x4b, 0x6c, 0x4e, 0x67, 0x55, 0x33, 0x68, 0x0a, + 0x35, 0x75, 0x34, 0x62, 0x43, 0x59, 0x56, 0x68, 0x67, 0x49, 0x41, 0x49, + 0x77, 0x33, 0x41, 0x4c, 0x68, 0x32, 0x6b, 0x49, 0x6f, 0x45, 0x44, 0x53, + 0x71, 0x47, 0x6a, 0x62, 0x51, 0x69, 0x58, 0x42, 0x41, 0x43, 0x7a, 0x63, + 0x4f, 0x49, 0x49, 0x42, 0x6c, 0x55, 0x77, 0x4d, 0x42, 0x59, 0x4b, 0x44, + 0x45, 0x69, 0x72, 0x61, 0x6c, 0x44, 0x45, 0x43, 0x46, 0x59, 0x6f, 0x45, + 0x53, 0x53, 0x59, 0x62, 0x0a, 0x42, 0x57, 0x77, 0x43, 0x6f, 0x43, 0x48, + 0x63, 0x68, 0x47, 0x67, 0x5a, 0x74, 0x59, 0x6e, 0x62, 0x6b, 0x6b, 0x51, + 0x67, 0x79, 0x41, 0x6c, 0x45, 0x6f, 0x47, 0x69, 0x4d, 0x41, 0x6a, 0x49, + 0x5a, 0x47, 0x45, 0x54, 0x42, 0x51, 0x6b, 0x33, 0x69, 0x4e, 0x6b, 0x4c, + 0x4c, 0x51, 0x47, 0x5a, 0x41, 0x67, 0x69, 0x55, 0x5a, 0x52, 0x41, 0x6c, + 0x49, 0x77, 0x6d, 0x69, 0x51, 0x68, 0x42, 0x43, 0x6b, 0x0a, 0x71, 0x47, + 0x6b, 0x4b, 0x4a, 0x6b, 0x69, 0x41, 0x4e, 0x41, 0x54, 0x68, 0x49, 0x69, + 0x4b, 0x4b, 0x47, 0x45, 0x4b, 0x67, 0x6b, 0x43, 0x55, 0x51, 0x4e, 0x57, + 0x33, 0x4a, 0x52, 0x41, 0x71, 0x4b, 0x4d, 0x6b, 0x7a, 0x62, 0x4f, 0x48, + 0x47, 0x49, 0x4e, 0x49, 0x59, 0x6a, 0x52, 0x49, 0x71, 0x68, 0x71, 0x47, + 0x45, 0x51, 0x42, 0x47, 0x72, 0x55, 0x49, 0x69, 0x71, 0x67, 0x67, 0x48, + 0x44, 0x67, 0x0a, 0x4b, 0x41, 0x5a, 0x4b, 0x74, 0x6b, 0x41, 0x63, 0x68, + 0x59, 0x32, 0x42, 0x6f, 0x48, 0x47, 0x62, 0x73, 0x49, 0x33, 0x4a, 0x73, + 0x48, 0x41, 0x55, 0x41, 0x34, 0x43, 0x44, 0x45, 0x6f, 0x70, 0x61, 0x67, + 0x6b, 0x55, 0x42, 0x4d, 0x6f, 0x77, 0x4c, 0x41, 0x69, 0x35, 0x4b, 0x4a, + 0x45, 0x70, 0x51, 0x78, 0x6f, 0x46, 0x59, 0x67, 0x47, 0x6b, 0x44, 0x49, + 0x43, 0x70, 0x51, 0x73, 0x49, 0x58, 0x55, 0x0a, 0x77, 0x6f, 0x30, 0x6b, + 0x75, 0x53, 0x51, 0x45, 0x42, 0x55, 0x6f, 0x68, 0x70, 0x69, 0x56, 0x53, + 0x49, 0x69, 0x33, 0x69, 0x47, 0x4a, 0x45, 0x5a, 0x46, 0x32, 0x4c, 0x4d, + 0x4d, 0x47, 0x6e, 0x4a, 0x70, 0x69, 0x46, 0x68, 0x69, 0x47, 0x55, 0x52, + 0x4b, 0x57, 0x6b, 0x59, 0x70, 0x32, 0x6d, 0x43, 0x67, 0x6d, 0x31, 0x62, + 0x6c, 0x47, 0x46, 0x42, 0x49, 0x45, 0x41, 0x55, 0x6d, 0x46, 0x47, 0x45, + 0x0a, 0x74, 0x43, 0x55, 0x4d, 0x43, 0x47, 0x78, 0x41, 0x41, 0x44, 0x47, + 0x62, 0x4e, 0x67, 0x49, 0x6b, 0x45, 0x77, 0x4c, 0x53, 0x4e, 0x45, 0x30, + 0x6a, 0x42, 0x49, 0x44, 0x44, 0x42, 0x45, 0x34, 0x69, 0x4e, 0x67, 0x78, + 0x45, 0x41, 0x6d, 0x4c, 0x69, 0x6f, 0x6f, 0x43, 0x42, 0x67, 0x67, 0x53, + 0x44, 0x52, 0x47, 0x59, 0x4a, 0x67, 0x7a, 0x41, 0x4c, 0x4a, 0x59, 0x59, + 0x67, 0x70, 0x56, 0x46, 0x67, 0x0a, 0x4e, 0x6f, 0x35, 0x63, 0x74, 0x69, + 0x47, 0x53, 0x51, 0x45, 0x77, 0x63, 0x4d, 0x41, 0x72, 0x68, 0x70, 0x49, + 0x57, 0x52, 0x6f, 0x67, 0x77, 0x4d, 0x41, 0x45, 0x46, 0x4c, 0x67, 0x67, + 0x51, 0x59, 0x51, 0x6b, 0x57, 0x4d, 0x4f, 0x49, 0x70, 0x68, 0x4f, 0x41, + 0x49, 0x41, 0x68, 0x6f, 0x77, 0x4b, 0x67, 0x34, 0x42, 0x61, 0x4a, 0x6f, + 0x6b, 0x4d, 0x68, 0x52, 0x45, 0x6b, 0x78, 0x45, 0x42, 0x69, 0x0a, 0x42, + 0x6b, 0x45, 0x4c, 0x6f, 0x57, 0x51, 0x53, 0x75, 0x59, 0x30, 0x4c, 0x4a, + 0x55, 0x57, 0x5a, 0x6b, 0x67, 0x42, 0x4a, 0x52, 0x6d, 0x77, 0x4d, 0x6c, + 0x32, 0x30, 0x5a, 0x68, 0x32, 0x6b, 0x6a, 0x42, 0x79, 0x49, 0x6a, 0x4b, + 0x59, 0x51, 0x51, 0x67, 0x67, 0x67, 0x44, 0x49, 0x70, 0x49, 0x44, 0x46, + 0x70, 0x41, 0x4c, 0x4b, 0x45, 0x72, 0x61, 0x51, 0x43, 0x37, 0x55, 0x77, + 0x45, 0x55, 0x52, 0x0a, 0x67, 0x30, 0x30, 0x5a, 0x68, 0x69, 0x51, 0x5a, + 0x70, 0x79, 0x55, 0x52, 0x47, 0x58, 0x43, 0x45, 0x46, 0x49, 0x70, 0x4d, + 0x71, 0x49, 0x33, 0x44, 0x45, 0x4a, 0x4a, 0x4b, 0x4a, 0x6e, 0x43, 0x62, + 0x4a, 0x45, 0x4c, 0x69, 0x67, 0x47, 0x44, 0x4c, 0x4b, 0x45, 0x35, 0x52, + 0x53, 0x49, 0x46, 0x67, 0x4a, 0x49, 0x67, 0x6a, 0x42, 0x32, 0x70, 0x4d, + 0x45, 0x41, 0x45, 0x4a, 0x43, 0x43, 0x49, 0x4a, 0x0a, 0x6f, 0x44, 0x42, + 0x49, 0x6c, 0x49, 0x6b, 0x6b, 0x4e, 0x53, 0x79, 0x4c, 0x6f, 0x6b, 0x32, + 0x4b, 0x41, 0x41, 0x46, 0x45, 0x6b, 0x43, 0x6d, 0x49, 0x79, 0x41, 0x78, + 0x69, 0x43, 0x45, 0x46, 0x61, 0x41, 0x70, 0x44, 0x5a, 0x4d, 0x41, 0x32, + 0x59, 0x4f, 0x41, 0x70, 0x55, 0x4a, 0x47, 0x62, 0x44, 0x53, 0x41, 0x35, + 0x59, 0x73, 0x6a, 0x44, 0x53, 0x4e, 0x69, 0x69, 0x4d, 0x78, 0x41, 0x51, + 0x44, 0x0a, 0x75, 0x55, 0x78, 0x5a, 0x4e, 0x69, 0x4c, 0x54, 0x4f, 0x42, + 0x41, 0x55, 0x68, 0x6b, 0x77, 0x42, 0x52, 0x49, 0x42, 0x6b, 0x78, 0x49, + 0x77, 0x69, 0x6d, 0x43, 0x30, 0x67, 0x51, 0x47, 0x70, 0x42, 0x49, 0x4a, + 0x48, 0x62, 0x78, 0x43, 0x6c, 0x4d, 0x41, 0x6a, 0x46, 0x4b, 0x42, 0x49, + 0x51, 0x49, 0x6c, 0x59, 0x7a, 0x68, 0x42, 0x4a, 0x47, 0x44, 0x41, 0x4a, + 0x42, 0x55, 0x52, 0x70, 0x4c, 0x42, 0x0a, 0x45, 0x67, 0x44, 0x4a, 0x45, + 0x49, 0x6a, 0x52, 0x45, 0x45, 0x44, 0x4a, 0x4d, 0x6d, 0x41, 0x4c, 0x6b, + 0x32, 0x78, 0x67, 0x77, 0x68, 0x44, 0x51, 0x78, 0x49, 0x6d, 0x52, 0x49, + 0x69, 0x6f, 0x4a, 0x6f, 0x6f, 0x55, 0x49, 0x6c, 0x32, 0x69, 0x52, 0x6b, + 0x6b, 0x78, 0x51, 0x4a, 0x45, 0x4b, 0x6a, 0x71, 0x43, 0x77, 0x4a, 0x4e, + 0x55, 0x6e, 0x54, 0x4d, 0x45, 0x51, 0x6b, 0x45, 0x55, 0x68, 0x61, 0x0a, + 0x4d, 0x49, 0x4b, 0x41, 0x78, 0x46, 0x45, 0x6b, 0x41, 0x6d, 0x67, 0x54, + 0x45, 0x6f, 0x33, 0x52, 0x70, 0x42, 0x44, 0x62, 0x74, 0x6f, 0x55, 0x51, + 0x46, 0x67, 0x56, 0x5a, 0x42, 0x45, 0x44, 0x67, 0x4d, 0x47, 0x57, 0x51, + 0x4d, 0x41, 0x30, 0x43, 0x42, 0x42, 0x4a, 0x43, 0x43, 0x43, 0x6f, 0x67, + 0x79, 0x59, 0x68, 0x54, 0x73, 0x6b, 0x6b, 0x63, 0x52, 0x6e, 0x44, 0x67, + 0x41, 0x6d, 0x6a, 0x43, 0x0a, 0x51, 0x6b, 0x32, 0x4c, 0x51, 0x41, 0x5a, + 0x6a, 0x43, 0x43, 0x55, 0x63, 0x43, 0x55, 0x5a, 0x55, 0x6c, 0x69, 0x53, + 0x54, 0x49, 0x49, 0x36, 0x44, 0x52, 0x49, 0x70, 0x5a, 0x41, 0x67, 0x56, + 0x45, 0x77, 0x47, 0x45, 0x44, 0x79, 0x43, 0x56, 0x44, 0x41, 0x47, 0x77, + 0x4d, 0x68, 0x69, 0x51, 0x45, 0x4a, 0x52, 0x49, 0x62, 0x47, 0x57, 0x77, + 0x6b, 0x4f, 0x47, 0x30, 0x4b, 0x73, 0x6d, 0x33, 0x42, 0x0a, 0x6c, 0x6d, + 0x6a, 0x55, 0x69, 0x41, 0x30, 0x4b, 0x42, 0x79, 0x59, 0x53, 0x52, 0x79, + 0x67, 0x43, 0x53, 0x42, 0x44, 0x61, 0x75, 0x43, 0x6d, 0x53, 0x67, 0x4a, + 0x43, 0x45, 0x51, 0x49, 0x55, 0x49, 0x49, 0x77, 0x46, 0x61, 0x79, 0x45, + 0x51, 0x67, 0x77, 0x45, 0x56, 0x5a, 0x78, 0x6b, 0x55, 0x61, 0x4a, 0x6b, + 0x6b, 0x43, 0x4b, 0x56, 0x42, 0x61, 0x70, 0x69, 0x6b, 0x54, 0x52, 0x6d, + 0x67, 0x41, 0x0a, 0x4a, 0x7a, 0x44, 0x53, 0x6c, 0x43, 0x6d, 0x4c, 0x45, + 0x6c, 0x43, 0x68, 0x6d, 0x41, 0x67, 0x61, 0x6c, 0x45, 0x56, 0x6b, 0x6b, + 0x6a, 0x41, 0x49, 0x78, 0x5a, 0x41, 0x41, 0x41, 0x6d, 0x6a, 0x4c, 0x51, + 0x6a, 0x46, 0x67, 0x42, 0x6f, 0x49, 0x69, 0x6c, 0x77, 0x6b, 0x44, 0x45, + 0x79, 0x61, 0x59, 0x51, 0x6f, 0x71, 0x68, 0x43, 0x44, 0x46, 0x45, 0x51, + 0x69, 0x4c, 0x62, 0x45, 0x42, 0x4b, 0x61, 0x0a, 0x49, 0x4a, 0x44, 0x62, + 0x53, 0x44, 0x49, 0x4c, 0x68, 0x6f, 0x42, 0x4b, 0x4d, 0x41, 0x55, 0x4a, + 0x74, 0x6e, 0x43, 0x44, 0x69, 0x45, 0x7a, 0x69, 0x51, 0x4a, 0x47, 0x63, + 0x4e, 0x45, 0x51, 0x41, 0x4e, 0x6a, 0x45, 0x4b, 0x78, 0x6b, 0x30, 0x54, + 0x41, 0x35, 0x4c, 0x59, 0x4d, 0x6d, 0x37, 0x61, 0x49, 0x49, 0x58, 0x4d, + 0x6f, 0x69, 0x52, 0x59, 0x47, 0x4a, 0x4b, 0x6a, 0x41, 0x67, 0x51, 0x67, + 0x0a, 0x51, 0x51, 0x67, 0x45, 0x47, 0x41, 0x37, 0x6b, 0x42, 0x49, 0x57, + 0x61, 0x51, 0x44, 0x49, 0x55, 0x4e, 0x45, 0x62, 0x63, 0x73, 0x45, 0x58, + 0x44, 0x52, 0x6e, 0x45, 0x6a, 0x6c, 0x78, 0x42, 0x69, 0x4e, 0x6b, 0x45, + 0x43, 0x68, 0x30, 0x48, 0x6b, 0x43, 0x44, 0x41, 0x59, 0x4d, 0x55, 0x55, + 0x4b, 0x45, 0x49, 0x68, 0x41, 0x67, 0x68, 0x44, 0x44, 0x51, 0x43, 0x44, + 0x59, 0x46, 0x45, 0x67, 0x5a, 0x0a, 0x52, 0x55, 0x4a, 0x54, 0x68, 0x69, + 0x41, 0x69, 0x68, 0x33, 0x47, 0x52, 0x6f, 0x44, 0x47, 0x67, 0x45, 0x6f, + 0x55, 0x61, 0x4e, 0x43, 0x32, 0x6b, 0x67, 0x45, 0x55, 0x49, 0x45, 0x32, + 0x6d, 0x44, 0x6f, 0x41, 0x77, 0x49, 0x6c, 0x70, 0x47, 0x4a, 0x75, 0x47, + 0x58, 0x61, 0x49, 0x42, 0x4b, 0x49, 0x73, 0x67, 0x57, 0x4b, 0x67, 0x6a, + 0x44, 0x68, 0x4e, 0x43, 0x42, 0x4d, 0x42, 0x69, 0x51, 0x4a, 0x0a, 0x46, + 0x30, 0x70, 0x59, 0x77, 0x6b, 0x32, 0x51, 0x4e, 0x6f, 0x59, 0x41, 0x4e, + 0x48, 0x4a, 0x42, 0x45, 0x67, 0x45, 0x43, 0x74, 0x32, 0x67, 0x67, 0x68, + 0x6d, 0x41, 0x51, 0x70, 0x6f, 0x7a, 0x42, 0x4e, 0x49, 0x53, 0x59, 0x68, + 0x6c, 0x47, 0x49, 0x4b, 0x41, 0x35, 0x53, 0x52, 0x6f, 0x6f, 0x59, 0x42, + 0x77, 0x62, 0x68, 0x49, 0x6c, 0x45, 0x67, 0x46, 0x47, 0x67, 0x59, 0x69, + 0x51, 0x56, 0x59, 0x0a, 0x45, 0x41, 0x43, 0x43, 0x41, 0x47, 0x47, 0x49, + 0x4d, 0x6a, 0x48, 0x69, 0x51, 0x49, 0x32, 0x68, 0x4d, 0x46, 0x41, 0x67, + 0x4a, 0x34, 0x6b, 0x68, 0x68, 0x31, 0x46, 0x55, 0x49, 0x67, 0x43, 0x68, + 0x6c, 0x6e, 0x48, 0x68, 0x69, 0x4a, 0x42, 0x5a, 0x49, 0x41, 0x57, 0x51, + 0x68, 0x67, 0x56, 0x59, 0x6c, 0x6b, 0x54, 0x4b, 0x74, 0x45, 0x53, 0x6b, + 0x47, 0x49, 0x79, 0x54, 0x52, 0x70, 0x47, 0x4d, 0x0a, 0x70, 0x69, 0x6c, + 0x52, 0x53, 0x45, 0x34, 0x4a, 0x43, 0x59, 0x30, 0x6b, 0x45, 0x53, 0x53, + 0x52, 0x45, 0x46, 0x49, 0x63, 0x6b, 0x53, 0x42, 0x49, 0x53, 0x4a, 0x44, + 0x68, 0x52, 0x43, 0x51, 0x44, 0x68, 0x51, 0x6a, 0x69, 0x71, 0x42, 0x42, + 0x53, 0x41, 0x47, 0x31, 0x62, 0x6c, 0x6e, 0x48, 0x59, 0x78, 0x41, 0x55, + 0x54, 0x4f, 0x57, 0x30, 0x52, 0x41, 0x4a, 0x46, 0x41, 0x42, 0x45, 0x42, + 0x55, 0x0a, 0x4d, 0x47, 0x78, 0x49, 0x74, 0x67, 0x30, 0x61, 0x73, 0x6b, + 0x30, 0x69, 0x6c, 0x77, 0x51, 0x5a, 0x74, 0x67, 0x42, 0x45, 0x68, 0x42, + 0x47, 0x67, 0x41, 0x45, 0x44, 0x44, 0x68, 0x6d, 0x46, 0x42, 0x6d, 0x45, + 0x30, 0x53, 0x42, 0x30, 0x6c, 0x61, 0x70, 0x6d, 0x6b, 0x43, 0x6b, 0x53, + 0x6b, 0x4a, 0x74, 0x34, 0x79, 0x59, 0x43, 0x43, 0x62, 0x62, 0x4e, 0x45, + 0x36, 0x62, 0x6c, 0x6d, 0x77, 0x44, 0x0a, 0x49, 0x32, 0x4a, 0x4a, 0x79, + 0x43, 0x55, 0x4c, 0x67, 0x69, 0x6c, 0x44, 0x52, 0x43, 0x44, 0x4d, 0x78, + 0x6d, 0x77, 0x68, 0x45, 0x67, 0x55, 0x49, 0x6f, 0x6c, 0x41, 0x4c, 0x46, + 0x79, 0x71, 0x59, 0x4b, 0x41, 0x42, 0x51, 0x73, 0x6d, 0x78, 0x55, 0x43, + 0x49, 0x70, 0x53, 0x41, 0x6c, 0x4a, 0x42, 0x70, 0x43, 0x45, 0x44, 0x4a, + 0x67, 0x33, 0x63, 0x70, 0x41, 0x6b, 0x69, 0x46, 0x45, 0x55, 0x42, 0x0a, + 0x47, 0x55, 0x6e, 0x6a, 0x46, 0x41, 0x31, 0x55, 0x49, 0x47, 0x6b, 0x4b, + 0x42, 0x45, 0x55, 0x54, 0x4a, 0x77, 0x61, 0x41, 0x74, 0x49, 0x46, 0x4c, + 0x49, 0x6d, 0x49, 0x63, 0x78, 0x6d, 0x33, 0x51, 0x73, 0x68, 0x47, 0x43, + 0x46, 0x6d, 0x34, 0x45, 0x43, 0x49, 0x34, 0x43, 0x4f, 0x43, 0x37, 0x4c, + 0x42, 0x69, 0x30, 0x42, 0x4a, 0x53, 0x55, 0x52, 0x79, 0x52, 0x47, 0x51, + 0x71, 0x43, 0x45, 0x4d, 0x0a, 0x51, 0x56, 0x42, 0x4c, 0x47, 0x45, 0x33, + 0x5a, 0x6f, 0x67, 0x77, 0x49, 0x77, 0x34, 0x6a, 0x43, 0x6f, 0x69, 0x41, + 0x61, 0x73, 0x67, 0x53, 0x44, 0x73, 0x49, 0x58, 0x41, 0x78, 0x6b, 0x6b, + 0x6a, 0x4a, 0x31, 0x49, 0x52, 0x4e, 0x59, 0x31, 0x6b, 0x52, 0x49, 0x37, + 0x55, 0x6c, 0x47, 0x45, 0x5a, 0x49, 0x59, 0x49, 0x43, 0x68, 0x59, 0x51, + 0x4c, 0x74, 0x30, 0x58, 0x51, 0x73, 0x67, 0x46, 0x55, 0x0a, 0x49, 0x41, + 0x71, 0x4a, 0x70, 0x49, 0x32, 0x43, 0x6c, 0x45, 0x57, 0x4a, 0x41, 0x69, + 0x47, 0x69, 0x6b, 0x6f, 0x6b, 0x4a, 0x4b, 0x46, 0x49, 0x52, 0x43, 0x41, + 0x33, 0x6b, 0x51, 0x6d, 0x30, 0x6a, 0x6c, 0x49, 0x32, 0x41, 0x77, 0x43, + 0x44, 0x41, 0x4f, 0x46, 0x45, 0x4d, 0x78, 0x6b, 0x51, 0x6b, 0x74, 0x46, + 0x42, 0x52, 0x77, 0x67, 0x42, 0x44, 0x78, 0x42, 0x47, 0x62, 0x51, 0x69, + 0x77, 0x45, 0x0a, 0x45, 0x32, 0x6d, 0x49, 0x6f, 0x43, 0x47, 0x63, 0x73, + 0x49, 0x53, 0x45, 0x53, 0x47, 0x56, 0x6a, 0x43, 0x45, 0x71, 0x67, 0x45, + 0x69, 0x78, 0x44, 0x69, 0x48, 0x41, 0x44, 0x46, 0x78, 0x49, 0x49, 0x51, + 0x6c, 0x41, 0x55, 0x68, 0x34, 0x55, 0x6b, 0x51, 0x6f, 0x54, 0x61, 0x6c, + 0x70, 0x42, 0x59, 0x46, 0x6d, 0x6f, 0x41, 0x46, 0x43, 0x70, 0x41, 0x4a, + 0x49, 0x6f, 0x52, 0x4e, 0x41, 0x58, 0x4d, 0x0a, 0x4f, 0x45, 0x6f, 0x54, + 0x51, 0x43, 0x44, 0x45, 0x52, 0x41, 0x44, 0x54, 0x73, 0x4a, 0x44, 0x6a, + 0x4a, 0x6d, 0x4b, 0x4c, 0x73, 0x6d, 0x79, 0x6b, 0x52, 0x6d, 0x49, 0x5a, + 0x52, 0x6b, 0x45, 0x4a, 0x4a, 0x6f, 0x51, 0x69, 0x45, 0x57, 0x77, 0x6a, + 0x45, 0x43, 0x34, 0x4c, 0x6f, 0x6b, 0x67, 0x69, 0x4e, 0x49, 0x4c, 0x62, + 0x6b, 0x6b, 0x48, 0x49, 0x4a, 0x41, 0x69, 0x63, 0x4e, 0x4a, 0x42, 0x68, + 0x0a, 0x6c, 0x69, 0x77, 0x69, 0x73, 0x6b, 0x32, 0x4a, 0x41, 0x6f, 0x41, + 0x6b, 0x79, 0x57, 0x47, 0x5a, 0x4d, 0x6a, 0x41, 0x4a, 0x77, 0x70, 0x45, + 0x68, 0x4f, 0x48, 0x47, 0x45, 0x78, 0x6b, 0x42, 0x4c, 0x6d, 0x41, 0x32, + 0x6b, 0x68, 0x45, 0x58, 0x6b, 0x73, 0x47, 0x54, 0x4b, 0x41, 0x49, 0x41, + 0x4d, 0x71, 0x49, 0x69, 0x67, 0x41, 0x46, 0x48, 0x4b, 0x53, 0x49, 0x47, + 0x52, 0x43, 0x43, 0x62, 0x68, 0x0a, 0x46, 0x6f, 0x55, 0x55, 0x7a, 0x67, + 0x44, 0x57, 0x56, 0x49, 0x42, 0x4b, 0x32, 0x34, 0x48, 0x75, 0x36, 0x55, + 0x4f, 0x63, 0x43, 0x31, 0x66, 0x6a, 0x63, 0x75, 0x64, 0x41, 0x64, 0x49, + 0x4f, 0x66, 0x71, 0x47, 0x58, 0x72, 0x72, 0x54, 0x4a, 0x55, 0x36, 0x37, + 0x74, 0x4c, 0x63, 0x36, 0x6e, 0x75, 0x5a, 0x73, 0x63, 0x66, 0x65, 0x30, + 0x57, 0x51, 0x31, 0x53, 0x79, 0x73, 0x49, 0x42, 0x45, 0x62, 0x0a, 0x52, + 0x58, 0x6c, 0x4a, 0x31, 0x42, 0x69, 0x71, 0x4e, 0x62, 0x32, 0x55, 0x56, + 0x50, 0x50, 0x6f, 0x69, 0x30, 0x42, 0x36, 0x55, 0x61, 0x4a, 0x43, 0x4d, + 0x70, 0x59, 0x77, 0x33, 0x64, 0x42, 0x48, 0x6a, 0x36, 0x30, 0x5a, 0x62, + 0x65, 0x32, 0x53, 0x46, 0x5a, 0x44, 0x59, 0x6c, 0x4a, 0x4a, 0x49, 0x7a, + 0x33, 0x54, 0x56, 0x63, 0x69, 0x77, 0x2b, 0x77, 0x6a, 0x4d, 0x54, 0x7a, + 0x6a, 0x4e, 0x66, 0x0a, 0x4d, 0x43, 0x65, 0x7a, 0x57, 0x34, 0x72, 0x62, + 0x77, 0x69, 0x79, 0x37, 0x46, 0x66, 0x50, 0x58, 0x6d, 0x6a, 0x58, 0x65, + 0x6b, 0x34, 0x6f, 0x4e, 0x58, 0x33, 0x4e, 0x4d, 0x5a, 0x41, 0x42, 0x64, + 0x6d, 0x65, 0x76, 0x69, 0x55, 0x4f, 0x5a, 0x6e, 0x58, 0x69, 0x4b, 0x67, + 0x53, 0x6f, 0x36, 0x4b, 0x45, 0x6f, 0x63, 0x58, 0x6c, 0x6d, 0x4a, 0x6b, + 0x6d, 0x79, 0x4f, 0x58, 0x48, 0x6d, 0x66, 0x70, 0x0a, 0x4a, 0x48, 0x37, + 0x67, 0x57, 0x4e, 0x61, 0x69, 0x64, 0x4c, 0x67, 0x35, 0x6f, 0x35, 0x4e, + 0x59, 0x51, 0x4b, 0x44, 0x33, 0x34, 0x4f, 0x6f, 0x6b, 0x49, 0x62, 0x31, + 0x51, 0x32, 0x35, 0x33, 0x79, 0x4f, 0x74, 0x4a, 0x46, 0x4c, 0x35, 0x54, + 0x34, 0x74, 0x7a, 0x61, 0x4d, 0x30, 0x48, 0x77, 0x71, 0x71, 0x49, 0x72, + 0x49, 0x64, 0x2b, 0x74, 0x32, 0x7a, 0x70, 0x69, 0x6e, 0x6b, 0x35, 0x2f, + 0x61, 0x0a, 0x45, 0x55, 0x4c, 0x36, 0x2b, 0x31, 0x48, 0x55, 0x70, 0x46, + 0x67, 0x46, 0x34, 0x52, 0x4f, 0x4a, 0x6b, 0x7a, 0x41, 0x59, 0x6a, 0x73, + 0x34, 0x4f, 0x70, 0x57, 0x63, 0x64, 0x47, 0x61, 0x63, 0x37, 0x73, 0x33, + 0x57, 0x6b, 0x65, 0x37, 0x4d, 0x4a, 0x42, 0x4b, 0x43, 0x61, 0x74, 0x31, + 0x43, 0x44, 0x51, 0x4e, 0x41, 0x33, 0x64, 0x4d, 0x69, 0x43, 0x56, 0x6f, + 0x6d, 0x43, 0x36, 0x42, 0x62, 0x45, 0x0a, 0x4d, 0x4b, 0x6b, 0x46, 0x47, + 0x2f, 0x38, 0x70, 0x44, 0x43, 0x34, 0x32, 0x52, 0x46, 0x43, 0x50, 0x2f, + 0x64, 0x30, 0x38, 0x6c, 0x32, 0x47, 0x72, 0x72, 0x6b, 0x6d, 0x52, 0x43, + 0x66, 0x6f, 0x67, 0x6c, 0x53, 0x32, 0x6e, 0x79, 0x2f, 0x78, 0x61, 0x47, + 0x54, 0x59, 0x58, 0x2b, 0x46, 0x79, 0x47, 0x4f, 0x4d, 0x32, 0x45, 0x72, + 0x4d, 0x69, 0x6f, 0x57, 0x63, 0x46, 0x39, 0x42, 0x45, 0x58, 0x6d, 0x0a, + 0x59, 0x31, 0x75, 0x31, 0x70, 0x72, 0x7a, 0x6e, 0x2f, 0x30, 0x58, 0x2f, + 0x4e, 0x35, 0x34, 0x6d, 0x33, 0x79, 0x5a, 0x39, 0x72, 0x59, 0x66, 0x6d, + 0x4c, 0x4d, 0x71, 0x4a, 0x76, 0x62, 0x36, 0x74, 0x38, 0x36, 0x38, 0x54, + 0x77, 0x6b, 0x41, 0x31, 0x67, 0x64, 0x55, 0x39, 0x46, 0x67, 0x55, 0x72, + 0x32, 0x2f, 0x64, 0x2b, 0x48, 0x44, 0x36, 0x74, 0x6c, 0x32, 0x66, 0x46, + 0x4e, 0x63, 0x6e, 0x34, 0x0a, 0x30, 0x4b, 0x58, 0x43, 0x62, 0x75, 0x46, + 0x43, 0x2b, 0x73, 0x44, 0x61, 0x36, 0x30, 0x7a, 0x5a, 0x44, 0x5a, 0x6f, + 0x6a, 0x4e, 0x6d, 0x54, 0x71, 0x4b, 0x6e, 0x50, 0x32, 0x47, 0x43, 0x33, + 0x68, 0x4e, 0x2f, 0x6f, 0x6c, 0x51, 0x4d, 0x6e, 0x6e, 0x30, 0x64, 0x48, + 0x6d, 0x52, 0x6e, 0x6d, 0x4f, 0x73, 0x58, 0x7a, 0x71, 0x51, 0x62, 0x45, + 0x58, 0x42, 0x69, 0x48, 0x62, 0x57, 0x52, 0x76, 0x48, 0x0a, 0x52, 0x51, + 0x4a, 0x47, 0x56, 0x76, 0x69, 0x2b, 0x4c, 0x5a, 0x77, 0x48, 0x65, 0x2b, + 0x2b, 0x48, 0x6b, 0x6c, 0x4f, 0x45, 0x6b, 0x6d, 0x30, 0x58, 0x44, 0x57, + 0x47, 0x2b, 0x4b, 0x74, 0x6d, 0x51, 0x55, 0x77, 0x4d, 0x48, 0x76, 0x4e, + 0x63, 0x39, 0x33, 0x6b, 0x75, 0x77, 0x4c, 0x4e, 0x68, 0x72, 0x57, 0x6e, + 0x6b, 0x46, 0x73, 0x44, 0x32, 0x35, 0x46, 0x6b, 0x76, 0x67, 0x4c, 0x51, + 0x62, 0x72, 0x0a, 0x68, 0x72, 0x39, 0x73, 0x38, 0x76, 0x38, 0x6f, 0x30, + 0x32, 0x34, 0x46, 0x65, 0x58, 0x47, 0x74, 0x33, 0x72, 0x45, 0x43, 0x68, + 0x48, 0x6c, 0x36, 0x75, 0x48, 0x66, 0x34, 0x35, 0x63, 0x30, 0x36, 0x7a, + 0x78, 0x6b, 0x78, 0x59, 0x77, 0x36, 0x6a, 0x63, 0x33, 0x52, 0x42, 0x69, + 0x4c, 0x62, 0x70, 0x2f, 0x57, 0x6d, 0x4c, 0x74, 0x70, 0x44, 0x79, 0x32, + 0x6d, 0x44, 0x4d, 0x68, 0x47, 0x30, 0x4b, 0x0a, 0x4c, 0x6c, 0x6a, 0x79, + 0x4f, 0x61, 0x4d, 0x67, 0x42, 0x6e, 0x6d, 0x30, 0x6b, 0x38, 0x4d, 0x67, + 0x47, 0x69, 0x74, 0x44, 0x68, 0x49, 0x59, 0x55, 0x32, 0x64, 0x48, 0x62, + 0x31, 0x67, 0x42, 0x4c, 0x35, 0x75, 0x2b, 0x6c, 0x4a, 0x63, 0x47, 0x45, + 0x31, 0x46, 0x45, 0x36, 0x45, 0x69, 0x73, 0x5a, 0x2b, 0x51, 0x49, 0x43, + 0x37, 0x44, 0x61, 0x4c, 0x6f, 0x6c, 0x67, 0x48, 0x35, 0x6c, 0x74, 0x69, + 0x0a, 0x30, 0x2f, 0x75, 0x6b, 0x35, 0x2f, 0x36, 0x64, 0x6a, 0x71, 0x69, + 0x44, 0x4f, 0x31, 0x4e, 0x4a, 0x70, 0x71, 0x69, 0x47, 0x4a, 0x72, 0x32, + 0x73, 0x4c, 0x7a, 0x49, 0x6c, 0x5a, 0x4d, 0x51, 0x7a, 0x63, 0x69, 0x64, + 0x6b, 0x6d, 0x52, 0x34, 0x65, 0x57, 0x33, 0x39, 0x72, 0x4a, 0x35, 0x2b, + 0x51, 0x66, 0x77, 0x75, 0x64, 0x30, 0x63, 0x4e, 0x6e, 0x5a, 0x6c, 0x6e, + 0x68, 0x49, 0x39, 0x5a, 0x65, 0x0a, 0x36, 0x54, 0x42, 0x6c, 0x56, 0x62, + 0x61, 0x49, 0x38, 0x33, 0x49, 0x2f, 0x67, 0x37, 0x47, 0x4d, 0x64, 0x57, + 0x30, 0x59, 0x67, 0x37, 0x6c, 0x6d, 0x2b, 0x62, 0x4a, 0x73, 0x44, 0x2b, + 0x68, 0x78, 0x69, 0x73, 0x44, 0x46, 0x68, 0x65, 0x49, 0x68, 0x75, 0x68, + 0x51, 0x44, 0x42, 0x5a, 0x50, 0x36, 0x71, 0x67, 0x43, 0x55, 0x6b, 0x36, + 0x5a, 0x53, 0x35, 0x30, 0x70, 0x75, 0x66, 0x41, 0x68, 0x6c, 0x0a, 0x41, + 0x65, 0x33, 0x34, 0x34, 0x59, 0x55, 0x2b, 0x53, 0x77, 0x44, 0x47, 0x6a, + 0x39, 0x4a, 0x54, 0x2b, 0x53, 0x41, 0x65, 0x49, 0x47, 0x71, 0x62, 0x4a, + 0x4e, 0x79, 0x69, 0x58, 0x6c, 0x38, 0x45, 0x65, 0x44, 0x36, 0x38, 0x4f, + 0x5a, 0x42, 0x66, 0x45, 0x59, 0x5a, 0x73, 0x2f, 0x4e, 0x34, 0x79, 0x4d, + 0x50, 0x75, 0x50, 0x77, 0x46, 0x38, 0x54, 0x6a, 0x49, 0x4f, 0x52, 0x61, + 0x6a, 0x77, 0x68, 0x0a, 0x6f, 0x72, 0x41, 0x57, 0x6c, 0x2b, 0x6e, 0x58, + 0x75, 0x6a, 0x66, 0x44, 0x36, 0x63, 0x71, 0x75, 0x66, 0x56, 0x54, 0x70, + 0x67, 0x66, 0x38, 0x55, 0x4f, 0x6a, 0x54, 0x38, 0x30, 0x45, 0x6c, 0x59, + 0x66, 0x69, 0x35, 0x4c, 0x68, 0x34, 0x38, 0x79, 0x69, 0x33, 0x48, 0x6d, + 0x65, 0x54, 0x74, 0x46, 0x51, 0x30, 0x4a, 0x37, 0x79, 0x75, 0x2f, 0x30, + 0x46, 0x66, 0x79, 0x4b, 0x55, 0x36, 0x44, 0x39, 0x0a, 0x4b, 0x4a, 0x6d, + 0x50, 0x47, 0x69, 0x52, 0x6f, 0x54, 0x4e, 0x75, 0x30, 0x55, 0x59, 0x44, + 0x39, 0x69, 0x47, 0x55, 0x5a, 0x6a, 0x32, 0x45, 0x59, 0x32, 0x57, 0x46, + 0x61, 0x2b, 0x58, 0x48, 0x37, 0x6f, 0x54, 0x71, 0x45, 0x6b, 0x64, 0x6c, + 0x77, 0x59, 0x7a, 0x78, 0x4b, 0x77, 0x2f, 0x69, 0x30, 0x76, 0x35, 0x45, + 0x4b, 0x76, 0x6b, 0x62, 0x66, 0x52, 0x72, 0x79, 0x6c, 0x77, 0x73, 0x69, + 0x59, 0x0a, 0x78, 0x72, 0x68, 0x75, 0x50, 0x2b, 0x77, 0x78, 0x77, 0x70, + 0x61, 0x4c, 0x49, 0x58, 0x39, 0x44, 0x7a, 0x64, 0x73, 0x45, 0x78, 0x37, + 0x34, 0x63, 0x33, 0x53, 0x4f, 0x4b, 0x44, 0x70, 0x50, 0x75, 0x4e, 0x34, + 0x57, 0x6d, 0x4a, 0x6d, 0x56, 0x6d, 0x4c, 0x41, 0x70, 0x67, 0x45, 0x6d, + 0x39, 0x63, 0x34, 0x45, 0x76, 0x43, 0x50, 0x34, 0x33, 0x4f, 0x36, 0x59, + 0x4f, 0x71, 0x4e, 0x64, 0x64, 0x67, 0x0a, 0x78, 0x71, 0x4b, 0x74, 0x55, + 0x62, 0x58, 0x4d, 0x74, 0x6c, 0x46, 0x44, 0x45, 0x6b, 0x62, 0x5a, 0x6b, + 0x7a, 0x6a, 0x33, 0x69, 0x57, 0x37, 0x30, 0x4e, 0x5a, 0x79, 0x47, 0x64, + 0x4c, 0x71, 0x71, 0x2b, 0x71, 0x6c, 0x4f, 0x47, 0x58, 0x4e, 0x56, 0x70, + 0x6a, 0x45, 0x42, 0x69, 0x65, 0x36, 0x75, 0x2b, 0x74, 0x36, 0x7a, 0x46, + 0x74, 0x4c, 0x74, 0x43, 0x38, 0x52, 0x38, 0x6d, 0x51, 0x39, 0x35, 0x0a, + 0x70, 0x63, 0x6c, 0x66, 0x6f, 0x73, 0x57, 0x4c, 0x34, 0x71, 0x71, 0x34, + 0x76, 0x6a, 0x74, 0x44, 0x42, 0x55, 0x54, 0x41, 0x6b, 0x73, 0x64, 0x43, + 0x59, 0x78, 0x48, 0x79, 0x36, 0x2f, 0x57, 0x45, 0x72, 0x54, 0x2f, 0x63, + 0x70, 0x39, 0x77, 0x4a, 0x57, 0x57, 0x37, 0x41, 0x32, 0x66, 0x77, 0x4c, + 0x58, 0x31, 0x6c, 0x51, 0x74, 0x45, 0x42, 0x5a, 0x6f, 0x42, 0x4a, 0x6f, + 0x51, 0x48, 0x7a, 0x57, 0x0a, 0x34, 0x77, 0x78, 0x31, 0x6c, 0x52, 0x6d, + 0x33, 0x7a, 0x52, 0x54, 0x53, 0x53, 0x4d, 0x77, 0x76, 0x46, 0x56, 0x75, + 0x5a, 0x39, 0x67, 0x55, 0x35, 0x47, 0x32, 0x6d, 0x55, 0x49, 0x34, 0x66, + 0x4a, 0x4b, 0x63, 0x42, 0x49, 0x69, 0x59, 0x51, 0x51, 0x4c, 0x4b, 0x57, + 0x46, 0x77, 0x38, 0x42, 0x2f, 0x6e, 0x6c, 0x4e, 0x45, 0x4f, 0x6f, 0x35, + 0x76, 0x73, 0x64, 0x41, 0x37, 0x56, 0x71, 0x59, 0x47, 0x0a, 0x37, 0x52, + 0x69, 0x35, 0x66, 0x36, 0x45, 0x76, 0x64, 0x45, 0x44, 0x4d, 0x65, 0x72, + 0x44, 0x69, 0x74, 0x42, 0x41, 0x69, 0x2b, 0x66, 0x58, 0x6b, 0x6e, 0x55, + 0x4b, 0x4d, 0x49, 0x4f, 0x32, 0x6a, 0x6b, 0x74, 0x47, 0x42, 0x51, 0x47, + 0x68, 0x56, 0x48, 0x6c, 0x79, 0x68, 0x56, 0x4d, 0x30, 0x4e, 0x6e, 0x76, + 0x70, 0x51, 0x53, 0x48, 0x47, 0x4b, 0x68, 0x6a, 0x78, 0x63, 0x56, 0x37, + 0x6a, 0x42, 0x0a, 0x71, 0x5a, 0x42, 0x4d, 0x7a, 0x6a, 0x2b, 0x2f, 0x5a, + 0x6d, 0x69, 0x74, 0x4d, 0x66, 0x72, 0x41, 0x6e, 0x57, 0x44, 0x31, 0x41, + 0x71, 0x75, 0x6d, 0x61, 0x73, 0x33, 0x66, 0x38, 0x4c, 0x6b, 0x78, 0x75, + 0x4e, 0x59, 0x34, 0x56, 0x4f, 0x43, 0x31, 0x78, 0x31, 0x59, 0x63, 0x2b, + 0x79, 0x6b, 0x54, 0x56, 0x38, 0x32, 0x76, 0x74, 0x47, 0x47, 0x42, 0x39, + 0x62, 0x64, 0x4b, 0x70, 0x4f, 0x4a, 0x45, 0x0a, 0x4b, 0x6d, 0x6f, 0x4e, + 0x30, 0x61, 0x46, 0x75, 0x68, 0x48, 0x2b, 0x38, 0x30, 0x6f, 0x33, 0x64, + 0x33, 0x36, 0x6d, 0x4a, 0x4a, 0x2b, 0x62, 0x51, 0x69, 0x36, 0x6e, 0x6d, + 0x51, 0x39, 0x6a, 0x69, 0x59, 0x62, 0x65, 0x55, 0x53, 0x32, 0x5a, 0x31, + 0x45, 0x50, 0x45, 0x58, 0x33, 0x62, 0x58, 0x62, 0x52, 0x57, 0x69, 0x47, + 0x45, 0x68, 0x35, 0x7a, 0x49, 0x4f, 0x52, 0x41, 0x2f, 0x79, 0x73, 0x33, + 0x0a, 0x34, 0x76, 0x62, 0x66, 0x48, 0x6d, 0x53, 0x5a, 0x53, 0x46, 0x4c, + 0x6a, 0x79, 0x4b, 0x35, 0x47, 0x70, 0x41, 0x4f, 0x4f, 0x52, 0x55, 0x74, + 0x65, 0x4b, 0x68, 0x65, 0x4b, 0x53, 0x69, 0x51, 0x53, 0x2f, 0x31, 0x4f, + 0x70, 0x59, 0x4d, 0x68, 0x77, 0x69, 0x59, 0x76, 0x71, 0x69, 0x39, 0x73, + 0x6b, 0x53, 0x33, 0x75, 0x74, 0x38, 0x58, 0x69, 0x4e, 0x63, 0x39, 0x6f, + 0x58, 0x4e, 0x5a, 0x51, 0x70, 0x0a, 0x64, 0x45, 0x31, 0x48, 0x78, 0x43, + 0x31, 0x6e, 0x59, 0x34, 0x70, 0x7a, 0x2f, 0x38, 0x66, 0x72, 0x4d, 0x61, + 0x4c, 0x75, 0x4f, 0x58, 0x65, 0x58, 0x35, 0x4a, 0x75, 0x78, 0x54, 0x56, + 0x45, 0x36, 0x5a, 0x6d, 0x4e, 0x6e, 0x66, 0x37, 0x56, 0x4c, 0x44, 0x46, + 0x53, 0x42, 0x6c, 0x72, 0x49, 0x4c, 0x78, 0x74, 0x59, 0x73, 0x76, 0x67, + 0x41, 0x44, 0x73, 0x4a, 0x47, 0x66, 0x50, 0x45, 0x58, 0x32, 0x0a, 0x6c, + 0x59, 0x56, 0x57, 0x6d, 0x70, 0x5a, 0x63, 0x37, 0x55, 0x34, 0x45, 0x4a, + 0x6a, 0x62, 0x51, 0x4f, 0x34, 0x46, 0x2f, 0x4c, 0x6d, 0x30, 0x71, 0x35, + 0x33, 0x77, 0x70, 0x52, 0x39, 0x64, 0x68, 0x77, 0x51, 0x70, 0x4c, 0x5a, + 0x58, 0x43, 0x69, 0x52, 0x55, 0x73, 0x64, 0x75, 0x76, 0x6e, 0x70, 0x5a, + 0x33, 0x58, 0x72, 0x2f, 0x58, 0x61, 0x2b, 0x61, 0x6e, 0x63, 0x2f, 0x4e, + 0x52, 0x69, 0x6f, 0x0a, 0x55, 0x32, 0x30, 0x74, 0x67, 0x41, 0x6a, 0x7a, + 0x7a, 0x7a, 0x52, 0x37, 0x4b, 0x4b, 0x41, 0x54, 0x75, 0x76, 0x43, 0x70, + 0x78, 0x71, 0x53, 0x51, 0x2f, 0x30, 0x6d, 0x6c, 0x4f, 0x70, 0x33, 0x67, + 0x6e, 0x37, 0x58, 0x41, 0x7a, 0x50, 0x76, 0x54, 0x2f, 0x38, 0x36, 0x31, + 0x67, 0x4a, 0x6c, 0x54, 0x38, 0x46, 0x36, 0x71, 0x36, 0x37, 0x62, 0x6c, + 0x75, 0x4b, 0x77, 0x36, 0x37, 0x70, 0x33, 0x78, 0x0a, 0x45, 0x2b, 0x71, + 0x63, 0x46, 0x78, 0x6f, 0x56, 0x46, 0x6f, 0x30, 0x65, 0x52, 0x46, 0x73, + 0x64, 0x72, 0x76, 0x64, 0x71, 0x56, 0x66, 0x2f, 0x2f, 0x36, 0x58, 0x61, + 0x4b, 0x70, 0x43, 0x39, 0x6a, 0x69, 0x33, 0x49, 0x50, 0x6e, 0x56, 0x61, + 0x45, 0x49, 0x51, 0x5a, 0x4b, 0x6d, 0x72, 0x63, 0x38, 0x58, 0x7a, 0x47, + 0x4f, 0x61, 0x36, 0x39, 0x54, 0x61, 0x58, 0x38, 0x44, 0x58, 0x63, 0x59, + 0x5a, 0x0a, 0x2f, 0x77, 0x31, 0x39, 0x43, 0x48, 0x33, 0x39, 0x34, 0x44, + 0x75, 0x4b, 0x59, 0x78, 0x2f, 0x72, 0x63, 0x57, 0x37, 0x4a, 0x66, 0x43, + 0x4e, 0x70, 0x77, 0x42, 0x4e, 0x76, 0x34, 0x73, 0x54, 0x59, 0x52, 0x58, + 0x45, 0x67, 0x48, 0x39, 0x4d, 0x52, 0x76, 0x30, 0x53, 0x70, 0x71, 0x43, + 0x54, 0x59, 0x4c, 0x58, 0x56, 0x63, 0x31, 0x36, 0x4c, 0x44, 0x6d, 0x30, + 0x38, 0x61, 0x41, 0x7a, 0x57, 0x4a, 0x0a, 0x61, 0x55, 0x34, 0x53, 0x31, + 0x6e, 0x57, 0x51, 0x63, 0x53, 0x44, 0x68, 0x58, 0x77, 0x79, 0x6a, 0x43, + 0x4f, 0x62, 0x56, 0x37, 0x31, 0x6d, 0x6d, 0x4d, 0x4a, 0x72, 0x5a, 0x66, + 0x52, 0x4f, 0x4c, 0x30, 0x31, 0x59, 0x32, 0x61, 0x35, 0x41, 0x72, 0x71, + 0x49, 0x30, 0x51, 0x68, 0x6c, 0x61, 0x71, 0x78, 0x56, 0x79, 0x32, 0x66, + 0x58, 0x31, 0x44, 0x45, 0x63, 0x50, 0x30, 0x65, 0x36, 0x4a, 0x71, 0x0a, + 0x34, 0x63, 0x45, 0x6f, 0x38, 0x54, 0x67, 0x46, 0x69, 0x74, 0x75, 0x72, + 0x64, 0x4f, 0x63, 0x49, 0x31, 0x67, 0x62, 0x30, 0x71, 0x66, 0x50, 0x6e, + 0x38, 0x4a, 0x59, 0x4a, 0x44, 0x67, 0x50, 0x71, 0x33, 0x6a, 0x62, 0x7a, + 0x47, 0x35, 0x35, 0x48, 0x4e, 0x76, 0x32, 0x55, 0x51, 0x53, 0x39, 0x68, + 0x48, 0x55, 0x72, 0x42, 0x4b, 0x77, 0x48, 0x4d, 0x61, 0x4a, 0x38, 0x52, + 0x73, 0x6a, 0x46, 0x4b, 0x0a, 0x37, 0x42, 0x33, 0x51, 0x52, 0x65, 0x32, + 0x78, 0x34, 0x77, 0x42, 0x72, 0x6d, 0x59, 0x46, 0x50, 0x35, 0x57, 0x42, + 0x7a, 0x58, 0x61, 0x4e, 0x54, 0x45, 0x6e, 0x48, 0x6b, 0x42, 0x54, 0x4e, + 0x78, 0x48, 0x5a, 0x51, 0x41, 0x6d, 0x73, 0x36, 0x65, 0x45, 0x6d, 0x4d, + 0x73, 0x61, 0x31, 0x33, 0x49, 0x67, 0x7a, 0x32, 0x71, 0x66, 0x63, 0x48, + 0x4a, 0x54, 0x43, 0x75, 0x46, 0x68, 0x35, 0x76, 0x70, 0x0a, 0x6e, 0x51, + 0x6b, 0x39, 0x4c, 0x4f, 0x2b, 0x56, 0x30, 0x6d, 0x38, 0x78, 0x70, 0x46, + 0x64, 0x35, 0x66, 0x78, 0x4c, 0x53, 0x41, 0x4d, 0x48, 0x5a, 0x6e, 0x68, + 0x49, 0x75, 0x6f, 0x48, 0x74, 0x4d, 0x32, 0x30, 0x50, 0x59, 0x4d, 0x4b, + 0x65, 0x56, 0x47, 0x37, 0x44, 0x4b, 0x38, 0x75, 0x4f, 0x74, 0x30, 0x67, + 0x65, 0x65, 0x66, 0x56, 0x52, 0x2b, 0x66, 0x55, 0x2b, 0x57, 0x4f, 0x4d, + 0x64, 0x77, 0x0a, 0x49, 0x37, 0x53, 0x68, 0x72, 0x6b, 0x70, 0x7a, 0x39, + 0x2f, 0x59, 0x47, 0x4c, 0x33, 0x39, 0x4d, 0x4b, 0x2f, 0x36, 0x59, 0x73, + 0x4b, 0x7a, 0x73, 0x45, 0x6e, 0x36, 0x6b, 0x2b, 0x53, 0x43, 0x55, 0x7a, + 0x30, 0x7a, 0x38, 0x42, 0x2f, 0x42, 0x48, 0x78, 0x52, 0x39, 0x72, 0x47, + 0x54, 0x49, 0x39, 0x43, 0x4a, 0x58, 0x45, 0x67, 0x67, 0x4f, 0x51, 0x50, + 0x34, 0x41, 0x51, 0x4b, 0x6d, 0x58, 0x43, 0x0a, 0x6b, 0x57, 0x5a, 0x43, + 0x48, 0x39, 0x51, 0x4d, 0x4d, 0x50, 0x36, 0x6c, 0x68, 0x30, 0x63, 0x51, + 0x73, 0x59, 0x41, 0x55, 0x31, 0x76, 0x44, 0x51, 0x65, 0x59, 0x5a, 0x35, + 0x35, 0x51, 0x77, 0x68, 0x71, 0x62, 0x32, 0x6e, 0x42, 0x54, 0x4e, 0x49, + 0x78, 0x43, 0x6f, 0x52, 0x43, 0x44, 0x6d, 0x50, 0x39, 0x75, 0x33, 0x4e, + 0x32, 0x64, 0x61, 0x38, 0x74, 0x51, 0x62, 0x4e, 0x50, 0x6b, 0x6a, 0x36, + 0x0a, 0x51, 0x45, 0x67, 0x76, 0x71, 0x74, 0x4a, 0x55, 0x59, 0x49, 0x77, + 0x52, 0x6e, 0x31, 0x2f, 0x72, 0x43, 0x4d, 0x78, 0x31, 0x52, 0x6f, 0x75, + 0x45, 0x4b, 0x71, 0x54, 0x44, 0x42, 0x4f, 0x30, 0x67, 0x76, 0x78, 0x42, + 0x56, 0x34, 0x33, 0x7a, 0x79, 0x6f, 0x59, 0x44, 0x76, 0x64, 0x53, 0x4a, + 0x6c, 0x4b, 0x61, 0x34, 0x62, 0x55, 0x75, 0x4f, 0x63, 0x63, 0x66, 0x52, + 0x32, 0x51, 0x6a, 0x2b, 0x6a, 0x0a, 0x33, 0x4e, 0x2f, 0x73, 0x56, 0x4d, + 0x55, 0x67, 0x52, 0x48, 0x38, 0x61, 0x62, 0x51, 0x37, 0x75, 0x34, 0x39, + 0x30, 0x57, 0x5a, 0x4f, 0x62, 0x50, 0x45, 0x50, 0x48, 0x4a, 0x71, 0x30, + 0x66, 0x73, 0x6c, 0x65, 0x68, 0x35, 0x76, 0x44, 0x50, 0x63, 0x50, 0x33, + 0x45, 0x4f, 0x41, 0x42, 0x41, 0x4d, 0x79, 0x46, 0x2f, 0x49, 0x42, 0x6d, + 0x50, 0x4f, 0x47, 0x63, 0x73, 0x65, 0x71, 0x7a, 0x50, 0x68, 0x0a, 0x63, + 0x6c, 0x5a, 0x6e, 0x36, 0x32, 0x75, 0x77, 0x48, 0x43, 0x52, 0x48, 0x69, + 0x4d, 0x55, 0x7a, 0x59, 0x65, 0x56, 0x64, 0x69, 0x69, 0x73, 0x6f, 0x65, + 0x72, 0x57, 0x34, 0x69, 0x4a, 0x55, 0x4b, 0x45, 0x4d, 0x45, 0x68, 0x73, + 0x36, 0x6f, 0x55, 0x42, 0x77, 0x69, 0x70, 0x66, 0x75, 0x36, 0x52, 0x4f, + 0x57, 0x4a, 0x77, 0x45, 0x53, 0x31, 0x4c, 0x4e, 0x6f, 0x43, 0x6e, 0x38, + 0x31, 0x42, 0x32, 0x0a, 0x34, 0x41, 0x55, 0x5a, 0x74, 0x7a, 0x54, 0x4b, + 0x4d, 0x50, 0x6a, 0x75, 0x38, 0x6b, 0x55, 0x47, 0x52, 0x4d, 0x47, 0x58, + 0x35, 0x47, 0x37, 0x65, 0x59, 0x78, 0x58, 0x6a, 0x44, 0x64, 0x38, 0x59, + 0x64, 0x53, 0x32, 0x4c, 0x4a, 0x71, 0x55, 0x47, 0x74, 0x59, 0x76, 0x56, + 0x72, 0x63, 0x75, 0x72, 0x74, 0x4b, 0x37, 0x6e, 0x6a, 0x56, 0x41, 0x52, + 0x44, 0x74, 0x36, 0x2f, 0x6b, 0x69, 0x46, 0x64, 0x0a, 0x4d, 0x41, 0x67, + 0x48, 0x51, 0x69, 0x52, 0x63, 0x44, 0x4e, 0x2f, 0x69, 0x59, 0x6e, 0x79, + 0x4b, 0x66, 0x76, 0x48, 0x4d, 0x6e, 0x56, 0x49, 0x56, 0x44, 0x68, 0x69, + 0x78, 0x6b, 0x4e, 0x41, 0x34, 0x6f, 0x56, 0x42, 0x49, 0x39, 0x2f, 0x39, + 0x76, 0x39, 0x4d, 0x73, 0x6a, 0x63, 0x52, 0x76, 0x76, 0x79, 0x4d, 0x4e, + 0x47, 0x4f, 0x2f, 0x6c, 0x37, 0x6f, 0x42, 0x72, 0x45, 0x72, 0x6c, 0x4b, + 0x49, 0x0a, 0x42, 0x69, 0x67, 0x51, 0x63, 0x54, 0x6b, 0x52, 0x65, 0x73, + 0x68, 0x62, 0x50, 0x4d, 0x6e, 0x51, 0x74, 0x72, 0x58, 0x33, 0x61, 0x53, + 0x79, 0x51, 0x49, 0x36, 0x47, 0x66, 0x53, 0x50, 0x2f, 0x76, 0x73, 0x57, + 0x52, 0x71, 0x47, 0x57, 0x70, 0x51, 0x61, 0x71, 0x57, 0x38, 0x70, 0x6b, + 0x48, 0x6b, 0x6c, 0x64, 0x75, 0x79, 0x77, 0x79, 0x47, 0x65, 0x42, 0x4f, + 0x66, 0x62, 0x34, 0x2f, 0x35, 0x2f, 0x0a, 0x53, 0x4d, 0x31, 0x77, 0x75, + 0x66, 0x6a, 0x59, 0x79, 0x56, 0x56, 0x41, 0x36, 0x4e, 0x69, 0x49, 0x34, + 0x78, 0x7a, 0x62, 0x31, 0x47, 0x47, 0x50, 0x67, 0x39, 0x6f, 0x2b, 0x57, + 0x55, 0x63, 0x2b, 0x6d, 0x51, 0x4e, 0x2f, 0x57, 0x75, 0x31, 0x6f, 0x32, + 0x4f, 0x5a, 0x69, 0x62, 0x61, 0x45, 0x37, 0x71, 0x63, 0x57, 0x50, 0x72, + 0x33, 0x4c, 0x7a, 0x42, 0x31, 0x43, 0x44, 0x64, 0x42, 0x48, 0x2b, 0x0a, + 0x6f, 0x74, 0x65, 0x74, 0x47, 0x77, 0x51, 0x43, 0x70, 0x4b, 0x67, 0x78, + 0x72, 0x79, 0x66, 0x66, 0x43, 0x79, 0x30, 0x62, 0x57, 0x44, 0x72, 0x52, + 0x66, 0x37, 0x69, 0x71, 0x74, 0x6d, 0x32, 0x52, 0x4f, 0x4b, 0x63, 0x4d, + 0x46, 0x37, 0x65, 0x49, 0x69, 0x39, 0x77, 0x59, 0x66, 0x44, 0x53, 0x4f, + 0x6e, 0x44, 0x63, 0x30, 0x39, 0x4a, 0x76, 0x64, 0x72, 0x72, 0x6d, 0x46, + 0x51, 0x50, 0x69, 0x4e, 0x0a, 0x63, 0x4c, 0x75, 0x74, 0x4d, 0x44, 0x74, + 0x34, 0x37, 0x48, 0x41, 0x47, 0x37, 0x6c, 0x4b, 0x31, 0x45, 0x68, 0x72, + 0x4f, 0x79, 0x78, 0x37, 0x32, 0x6c, 0x2f, 0x71, 0x55, 0x78, 0x51, 0x68, + 0x53, 0x68, 0x59, 0x50, 0x2f, 0x4d, 0x74, 0x6b, 0x31, 0x52, 0x4e, 0x73, + 0x51, 0x43, 0x77, 0x4e, 0x53, 0x33, 0x54, 0x68, 0x33, 0x78, 0x65, 0x49, + 0x62, 0x4b, 0x65, 0x42, 0x6b, 0x4d, 0x4b, 0x65, 0x58, 0x0a, 0x55, 0x4d, + 0x52, 0x73, 0x37, 0x74, 0x51, 0x32, 0x61, 0x7a, 0x54, 0x7a, 0x6d, 0x75, + 0x74, 0x74, 0x46, 0x59, 0x59, 0x73, 0x58, 0x31, 0x59, 0x42, 0x74, 0x42, + 0x76, 0x51, 0x67, 0x58, 0x46, 0x77, 0x4d, 0x58, 0x7a, 0x6e, 0x70, 0x41, + 0x42, 0x58, 0x54, 0x55, 0x6c, 0x77, 0x43, 0x79, 0x4f, 0x4d, 0x71, 0x47, + 0x71, 0x31, 0x6c, 0x59, 0x78, 0x33, 0x6d, 0x64, 0x76, 0x6b, 0x66, 0x6b, + 0x47, 0x78, 0x0a, 0x6e, 0x2f, 0x34, 0x36, 0x4e, 0x47, 0x42, 0x72, 0x34, + 0x4c, 0x35, 0x62, 0x34, 0x73, 0x36, 0x6a, 0x51, 0x73, 0x33, 0x75, 0x4c, + 0x43, 0x6e, 0x50, 0x77, 0x55, 0x34, 0x62, 0x58, 0x71, 0x70, 0x4d, 0x66, + 0x41, 0x51, 0x75, 0x64, 0x66, 0x56, 0x74, 0x74, 0x62, 0x64, 0x58, 0x69, + 0x38, 0x62, 0x71, 0x4c, 0x45, 0x75, 0x41, 0x68, 0x66, 0x63, 0x72, 0x53, + 0x50, 0x59, 0x56, 0x64, 0x65, 0x54, 0x6a, 0x0a, 0x66, 0x41, 0x55, 0x59, + 0x68, 0x31, 0x45, 0x6e, 0x4e, 0x2b, 0x62, 0x77, 0x67, 0x48, 0x4a, 0x50, + 0x6d, 0x70, 0x77, 0x33, 0x70, 0x50, 0x68, 0x4e, 0x73, 0x6c, 0x66, 0x4c, + 0x56, 0x5a, 0x52, 0x46, 0x2b, 0x37, 0x39, 0x31, 0x37, 0x55, 0x55, 0x6e, + 0x75, 0x4b, 0x49, 0x56, 0x6b, 0x5a, 0x39, 0x6e, 0x56, 0x63, 0x35, 0x58, + 0x39, 0x75, 0x59, 0x63, 0x4a, 0x33, 0x32, 0x69, 0x63, 0x55, 0x37, 0x37, + 0x0a, 0x72, 0x72, 0x31, 0x4d, 0x62, 0x65, 0x68, 0x2f, 0x53, 0x7a, 0x64, + 0x39, 0x61, 0x39, 0x56, 0x47, 0x71, 0x6b, 0x6d, 0x51, 0x53, 0x7a, 0x76, + 0x6c, 0x38, 0x33, 0x67, 0x32, 0x43, 0x79, 0x68, 0x6a, 0x72, 0x78, 0x63, + 0x4e, 0x53, 0x7a, 0x56, 0x30, 0x53, 0x5a, 0x7a, 0x45, 0x30, 0x2f, 0x31, + 0x42, 0x2f, 0x42, 0x45, 0x38, 0x2b, 0x59, 0x67, 0x39, 0x64, 0x4d, 0x79, + 0x36, 0x66, 0x41, 0x54, 0x33, 0x0a, 0x70, 0x54, 0x6c, 0x4b, 0x2f, 0x71, + 0x45, 0x74, 0x6f, 0x64, 0x37, 0x71, 0x45, 0x42, 0x69, 0x6a, 0x52, 0x39, + 0x4a, 0x6a, 0x71, 0x47, 0x56, 0x63, 0x36, 0x62, 0x55, 0x38, 0x48, 0x46, + 0x35, 0x6d, 0x43, 0x49, 0x70, 0x75, 0x6f, 0x7a, 0x62, 0x50, 0x45, 0x65, + 0x6d, 0x41, 0x33, 0x67, 0x76, 0x41, 0x44, 0x77, 0x34, 0x62, 0x52, 0x30, + 0x65, 0x6c, 0x34, 0x35, 0x78, 0x69, 0x48, 0x48, 0x7a, 0x31, 0x0a, 0x64, + 0x4b, 0x34, 0x30, 0x54, 0x6b, 0x39, 0x53, 0x46, 0x4a, 0x5a, 0x50, 0x74, + 0x35, 0x64, 0x65, 0x6e, 0x74, 0x2f, 0x6a, 0x61, 0x6d, 0x4d, 0x62, 0x49, + 0x50, 0x34, 0x49, 0x42, 0x63, 0x49, 0x48, 0x49, 0x2b, 0x39, 0x6d, 0x78, + 0x4a, 0x4b, 0x44, 0x4a, 0x35, 0x4f, 0x69, 0x47, 0x58, 0x49, 0x33, 0x6f, + 0x45, 0x33, 0x65, 0x5a, 0x4b, 0x6f, 0x33, 0x74, 0x67, 0x6e, 0x5a, 0x2f, + 0x46, 0x33, 0x66, 0x0a, 0x2b, 0x78, 0x38, 0x63, 0x55, 0x6b, 0x76, 0x30, + 0x69, 0x47, 0x4c, 0x44, 0x5a, 0x6b, 0x6a, 0x52, 0x6e, 0x49, 0x5a, 0x43, + 0x56, 0x30, 0x32, 0x52, 0x44, 0x30, 0x2f, 0x67, 0x58, 0x33, 0x74, 0x58, + 0x72, 0x4e, 0x68, 0x37, 0x75, 0x34, 0x65, 0x56, 0x77, 0x55, 0x55, 0x67, + 0x7a, 0x65, 0x4a, 0x59, 0x42, 0x6b, 0x42, 0x52, 0x77, 0x33, 0x35, 0x4f, + 0x78, 0x6f, 0x57, 0x4f, 0x51, 0x2b, 0x71, 0x34, 0x0a, 0x6e, 0x68, 0x77, + 0x32, 0x43, 0x30, 0x6e, 0x30, 0x6c, 0x75, 0x39, 0x4f, 0x61, 0x30, 0x49, + 0x36, 0x6e, 0x6c, 0x7a, 0x4a, 0x32, 0x7a, 0x61, 0x49, 0x67, 0x50, 0x32, + 0x56, 0x61, 0x6e, 0x39, 0x41, 0x6e, 0x5a, 0x6e, 0x52, 0x77, 0x4d, 0x51, + 0x71, 0x34, 0x50, 0x58, 0x52, 0x76, 0x69, 0x49, 0x47, 0x2b, 0x4b, 0x50, + 0x76, 0x57, 0x6e, 0x42, 0x43, 0x39, 0x48, 0x36, 0x57, 0x51, 0x74, 0x68, + 0x4a, 0x0a, 0x66, 0x30, 0x63, 0x77, 0x36, 0x53, 0x50, 0x64, 0x2b, 0x43, + 0x72, 0x72, 0x76, 0x6e, 0x4d, 0x64, 0x30, 0x46, 0x49, 0x31, 0x5a, 0x6c, + 0x30, 0x45, 0x4d, 0x6a, 0x4b, 0x35, 0x4b, 0x53, 0x47, 0x59, 0x4c, 0x69, + 0x52, 0x4e, 0x51, 0x4e, 0x6b, 0x5a, 0x70, 0x67, 0x37, 0x6c, 0x35, 0x6f, + 0x4a, 0x73, 0x63, 0x55, 0x58, 0x41, 0x36, 0x48, 0x32, 0x2b, 0x78, 0x54, + 0x6d, 0x4e, 0x50, 0x61, 0x79, 0x38, 0x0a, 0x4a, 0x48, 0x4d, 0x38, 0x70, + 0x7a, 0x61, 0x41, 0x35, 0x54, 0x36, 0x6f, 0x64, 0x64, 0x30, 0x76, 0x75, + 0x64, 0x6a, 0x71, 0x4c, 0x71, 0x2f, 0x30, 0x56, 0x34, 0x36, 0x67, 0x63, + 0x4c, 0x78, 0x36, 0x56, 0x57, 0x68, 0x50, 0x6c, 0x35, 0x38, 0x63, 0x6d, + 0x31, 0x43, 0x73, 0x5a, 0x4e, 0x6d, 0x41, 0x38, 0x54, 0x54, 0x4b, 0x2b, + 0x52, 0x39, 0x52, 0x42, 0x63, 0x45, 0x38, 0x4c, 0x76, 0x63, 0x34, 0x0a, + 0x74, 0x61, 0x73, 0x57, 0x4f, 0x35, 0x31, 0x30, 0x48, 0x79, 0x57, 0x5a, + 0x32, 0x68, 0x4b, 0x65, 0x4d, 0x72, 0x4e, 0x6b, 0x51, 0x4f, 0x59, 0x7a, + 0x45, 0x47, 0x39, 0x6e, 0x34, 0x34, 0x39, 0x38, 0x4d, 0x79, 0x4d, 0x54, + 0x55, 0x4a, 0x62, 0x65, 0x71, 0x55, 0x4a, 0x78, 0x2f, 0x42, 0x32, 0x6a, + 0x39, 0x6c, 0x38, 0x31, 0x59, 0x49, 0x52, 0x46, 0x54, 0x39, 0x65, 0x36, + 0x30, 0x38, 0x78, 0x78, 0x0a, 0x52, 0x66, 0x33, 0x66, 0x62, 0x72, 0x6f, + 0x66, 0x4f, 0x58, 0x75, 0x32, 0x55, 0x6b, 0x6f, 0x34, 0x32, 0x55, 0x66, + 0x2f, 0x5a, 0x73, 0x49, 0x57, 0x54, 0x57, 0x49, 0x36, 0x46, 0x63, 0x58, + 0x6b, 0x32, 0x74, 0x39, 0x74, 0x2b, 0x66, 0x74, 0x74, 0x2b, 0x38, 0x39, + 0x56, 0x70, 0x33, 0x6a, 0x47, 0x6a, 0x47, 0x47, 0x6b, 0x68, 0x4c, 0x76, + 0x78, 0x4d, 0x58, 0x49, 0x32, 0x48, 0x39, 0x39, 0x37, 0x0a, 0x6b, 0x44, + 0x6d, 0x43, 0x67, 0x6b, 0x68, 0x5a, 0x30, 0x31, 0x70, 0x6c, 0x34, 0x53, + 0x44, 0x5a, 0x54, 0x53, 0x35, 0x6b, 0x72, 0x62, 0x51, 0x2f, 0x37, 0x36, + 0x45, 0x30, 0x75, 0x72, 0x52, 0x53, 0x7a, 0x65, 0x41, 0x32, 0x5a, 0x62, + 0x79, 0x6c, 0x46, 0x54, 0x70, 0x56, 0x66, 0x6f, 0x48, 0x78, 0x75, 0x44, + 0x72, 0x43, 0x4d, 0x65, 0x4d, 0x52, 0x75, 0x54, 0x78, 0x38, 0x63, 0x76, + 0x4e, 0x58, 0x0a, 0x72, 0x42, 0x34, 0x30, 0x6b, 0x72, 0x59, 0x44, 0x55, + 0x4f, 0x41, 0x35, 0x5a, 0x2f, 0x38, 0x53, 0x78, 0x51, 0x42, 0x78, 0x61, + 0x6f, 0x71, 0x62, 0x59, 0x6a, 0x69, 0x55, 0x70, 0x43, 0x44, 0x56, 0x73, + 0x67, 0x54, 0x46, 0x4f, 0x70, 0x79, 0x48, 0x71, 0x39, 0x7a, 0x66, 0x6b, + 0x6a, 0x49, 0x55, 0x39, 0x39, 0x41, 0x68, 0x49, 0x39, 0x6e, 0x7a, 0x46, + 0x65, 0x66, 0x39, 0x4b, 0x31, 0x6f, 0x76, 0x0a, 0x59, 0x47, 0x32, 0x52, + 0x39, 0x72, 0x54, 0x72, 0x55, 0x48, 0x59, 0x50, 0x35, 0x70, 0x6a, 0x73, + 0x59, 0x47, 0x2f, 0x61, 0x4d, 0x2b, 0x46, 0x41, 0x7a, 0x6d, 0x4c, 0x76, + 0x66, 0x2f, 0x6a, 0x75, 0x79, 0x55, 0x59, 0x47, 0x77, 0x55, 0x4c, 0x58, + 0x34, 0x42, 0x4c, 0x5a, 0x6c, 0x61, 0x63, 0x66, 0x6a, 0x52, 0x64, 0x38, + 0x6c, 0x7a, 0x66, 0x67, 0x39, 0x63, 0x45, 0x77, 0x51, 0x67, 0x46, 0x41, + 0x0a, 0x64, 0x30, 0x4a, 0x48, 0x30, 0x62, 0x2b, 0x58, 0x2b, 0x66, 0x4e, + 0x73, 0x38, 0x71, 0x36, 0x77, 0x76, 0x53, 0x68, 0x4f, 0x32, 0x43, 0x39, + 0x70, 0x56, 0x36, 0x78, 0x54, 0x6e, 0x5a, 0x39, 0x71, 0x65, 0x2f, 0x7a, + 0x4c, 0x77, 0x37, 0x52, 0x69, 0x44, 0x6d, 0x68, 0x51, 0x6f, 0x2f, 0x62, + 0x34, 0x62, 0x35, 0x54, 0x74, 0x4a, 0x7a, 0x67, 0x56, 0x36, 0x37, 0x41, + 0x75, 0x4a, 0x47, 0x74, 0x48, 0x0a, 0x51, 0x4b, 0x7a, 0x77, 0x37, 0x46, + 0x2b, 0x6f, 0x7a, 0x65, 0x74, 0x46, 0x37, 0x50, 0x34, 0x38, 0x2b, 0x36, + 0x54, 0x68, 0x39, 0x4d, 0x6f, 0x4e, 0x51, 0x71, 0x2f, 0x30, 0x46, 0x47, + 0x43, 0x4a, 0x65, 0x71, 0x53, 0x73, 0x72, 0x49, 0x41, 0x41, 0x4e, 0x53, + 0x65, 0x2b, 0x4d, 0x43, 0x79, 0x37, 0x48, 0x35, 0x67, 0x73, 0x78, 0x4c, + 0x32, 0x56, 0x6a, 0x55, 0x5a, 0x37, 0x5a, 0x39, 0x32, 0x31, 0x0a, 0x79, + 0x6f, 0x59, 0x32, 0x64, 0x30, 0x50, 0x46, 0x38, 0x72, 0x38, 0x52, 0x31, + 0x35, 0x55, 0x4e, 0x6f, 0x71, 0x57, 0x45, 0x4a, 0x55, 0x72, 0x75, 0x43, + 0x70, 0x50, 0x75, 0x2f, 0x6e, 0x2f, 0x6e, 0x50, 0x78, 0x6d, 0x4d, 0x68, + 0x30, 0x42, 0x6e, 0x57, 0x73, 0x33, 0x74, 0x68, 0x78, 0x79, 0x68, 0x78, + 0x6f, 0x74, 0x32, 0x78, 0x6b, 0x42, 0x6c, 0x38, 0x72, 0x30, 0x61, 0x36, + 0x4a, 0x59, 0x70, 0x0a, 0x33, 0x77, 0x78, 0x42, 0x68, 0x6c, 0x4e, 0x66, + 0x71, 0x63, 0x4d, 0x61, 0x50, 0x57, 0x55, 0x6e, 0x67, 0x63, 0x31, 0x76, + 0x4e, 0x66, 0x37, 0x51, 0x4b, 0x79, 0x34, 0x33, 0x6c, 0x42, 0x75, 0x48, + 0x43, 0x68, 0x7a, 0x4a, 0x79, 0x71, 0x59, 0x69, 0x37, 0x4c, 0x73, 0x4d, + 0x78, 0x71, 0x7a, 0x78, 0x63, 0x50, 0x66, 0x4f, 0x52, 0x39, 0x49, 0x6c, + 0x70, 0x52, 0x6a, 0x33, 0x79, 0x58, 0x69, 0x57, 0x0a, 0x66, 0x47, 0x73, + 0x45, 0x51, 0x63, 0x4d, 0x6b, 0x6b, 0x59, 0x4f, 0x6c, 0x30, 0x56, 0x4f, + 0x74, 0x62, 0x4b, 0x6e, 0x49, 0x43, 0x72, 0x65, 0x52, 0x2b, 0x71, 0x43, + 0x2f, 0x4e, 0x63, 0x4e, 0x58, 0x34, 0x49, 0x32, 0x68, 0x63, 0x57, 0x38, + 0x31, 0x4a, 0x61, 0x5a, 0x42, 0x56, 0x6b, 0x48, 0x43, 0x36, 0x62, 0x46, + 0x6a, 0x6f, 0x59, 0x61, 0x4e, 0x66, 0x6b, 0x4a, 0x4d, 0x53, 0x54, 0x63, + 0x5a, 0x0a, 0x5a, 0x53, 0x72, 0x73, 0x66, 0x37, 0x6e, 0x5a, 0x48, 0x45, + 0x58, 0x46, 0x47, 0x68, 0x65, 0x36, 0x4b, 0x61, 0x6b, 0x30, 0x44, 0x77, + 0x46, 0x53, 0x48, 0x68, 0x36, 0x47, 0x34, 0x62, 0x36, 0x55, 0x33, 0x78, + 0x32, 0x2b, 0x78, 0x75, 0x50, 0x4a, 0x54, 0x48, 0x6b, 0x74, 0x59, 0x66, + 0x65, 0x6d, 0x37, 0x54, 0x79, 0x6e, 0x56, 0x30, 0x5a, 0x6d, 0x4e, 0x36, + 0x46, 0x78, 0x33, 0x67, 0x64, 0x35, 0x0a, 0x6e, 0x43, 0x4a, 0x78, 0x6c, + 0x2b, 0x30, 0x4b, 0x4d, 0x36, 0x37, 0x65, 0x76, 0x63, 0x33, 0x75, 0x6c, + 0x42, 0x68, 0x4f, 0x58, 0x2b, 0x4a, 0x48, 0x78, 0x64, 0x70, 0x4e, 0x79, + 0x62, 0x37, 0x73, 0x77, 0x7a, 0x6e, 0x48, 0x56, 0x36, 0x6d, 0x77, 0x43, + 0x71, 0x58, 0x7a, 0x52, 0x52, 0x68, 0x32, 0x79, 0x32, 0x37, 0x34, 0x2f, + 0x31, 0x43, 0x59, 0x6b, 0x50, 0x65, 0x45, 0x4f, 0x44, 0x6e, 0x58, 0x0a, + 0x49, 0x6d, 0x2b, 0x43, 0x79, 0x68, 0x48, 0x53, 0x43, 0x32, 0x75, 0x38, + 0x6a, 0x4a, 0x71, 0x73, 0x34, 0x6c, 0x71, 0x50, 0x37, 0x2f, 0x6e, 0x77, + 0x4b, 0x31, 0x39, 0x58, 0x7a, 0x6c, 0x54, 0x4f, 0x59, 0x55, 0x35, 0x65, + 0x73, 0x44, 0x51, 0x7a, 0x50, 0x39, 0x76, 0x4a, 0x37, 0x2f, 0x72, 0x48, + 0x73, 0x57, 0x37, 0x46, 0x4f, 0x46, 0x78, 0x6d, 0x57, 0x6c, 0x42, 0x30, + 0x77, 0x66, 0x4a, 0x4f, 0x0a, 0x6b, 0x44, 0x73, 0x75, 0x53, 0x4f, 0x71, + 0x46, 0x4a, 0x4f, 0x38, 0x6d, 0x53, 0x49, 0x6d, 0x5a, 0x41, 0x4a, 0x4b, + 0x4b, 0x34, 0x51, 0x33, 0x56, 0x7a, 0x4a, 0x36, 0x41, 0x56, 0x53, 0x4d, + 0x57, 0x49, 0x59, 0x6c, 0x42, 0x6c, 0x75, 0x7a, 0x74, 0x6e, 0x6e, 0x77, + 0x30, 0x53, 0x4f, 0x78, 0x70, 0x66, 0x39, 0x6c, 0x63, 0x58, 0x6c, 0x48, + 0x43, 0x78, 0x66, 0x42, 0x71, 0x30, 0x65, 0x45, 0x64, 0x0a, 0x58, 0x73, + 0x50, 0x4f, 0x52, 0x2f, 0x47, 0x72, 0x32, 0x57, 0x51, 0x43, 0x4f, 0x78, + 0x43, 0x41, 0x45, 0x36, 0x44, 0x6f, 0x67, 0x43, 0x47, 0x74, 0x79, 0x30, + 0x61, 0x38, 0x37, 0x4f, 0x34, 0x48, 0x4e, 0x4a, 0x4c, 0x76, 0x51, 0x42, + 0x65, 0x4b, 0x59, 0x42, 0x69, 0x55, 0x4d, 0x58, 0x4b, 0x4d, 0x79, 0x72, + 0x75, 0x6a, 0x33, 0x67, 0x31, 0x38, 0x58, 0x4c, 0x58, 0x66, 0x2f, 0x59, + 0x6e, 0x5a, 0x0a, 0x50, 0x61, 0x35, 0x67, 0x52, 0x66, 0x52, 0x6a, 0x70, + 0x56, 0x71, 0x73, 0x69, 0x47, 0x41, 0x39, 0x43, 0x54, 0x5a, 0x79, 0x57, + 0x4c, 0x68, 0x65, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, + 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b, 0x45, 0x59, + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a +}; diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/MlDsaTests.c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/MlDsaTests.c new file mode 100644 index 0000000000..e84856dd6a --- /dev/null +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/MlDsaTests.c @@ -0,0 +1,1655 @@ +/** @file + Application for ML-DSA Primitives Validation. + + This file contains unit tests for the ML-DSA (Module-Lattice-Based Digital Signature Algorithm) + cryptographic functions defined in CryptMlDsa.c. ML-DSA is a post-quantum digital signature + scheme based on the CRYSTALS-Dilithium algorithm and standardized in FIPS 204. + + The test vectors are provided in MlDsaTestVectors.h which contains: + - mMlDsa87TestCert[] - X.509 DER certificate with ML-DSA-87 public key + - mMlDsa87TestPemKey[] - PEM-encoded ML-DSA-87 private key + + The test structure mirrors EdDsaTests.c and validates: + - Context creation and destruction (MlDsaNewByNid, MlDsaFree) + - Key setting and retrieval error cases (MlDsaSetPrivKey, MlDsaSetPubKey, MlDsaGetPubKey) + - Signature generation and verification via PEM/X509 (TestVerifyMlDsaPemX509) + - Error handling for invalid inputs + + NOTE: TestVerifyMlDsaSignVerify() and TestVerifyMlDsaSignVerifyWithContext() are + currently skipped as they require raw key arrays. The main signing/verification test + is TestVerifyMlDsaPemX509() which uses real PEM and X509 test vectors. + +Copyright (c) 2026, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "TestBaseCryptLib.h" + +#define ML_DSA_87_PRIVATE_KEY_SIZE 4896 +#define ML_DSA_87_PUBLIC_KEY_SIZE 2592 +#define ML_DSA_87_SIGNATURE_SIZE 4627 +#define ML_DSA_MAX_CONTEXT_SIZE 255 + +// +// ML-DSA-87 test vectors - include generated certificate and PEM key +// +#include "MlDsaTestVectors.h" + +// +// Test message for signing and verification +// +CONST CHAR8 *mMlDsaTestMessage = "Test message for ML-DSA signing and verification"; + +// +// Optional context string for domain separation +// +CONST CHAR8 *mMlDsaTestContext = "ML-DSA test context"; + +VOID *MlDsaContext1; +VOID *MlDsaContext2; + +/** + Prerequisite function for ML-DSA tests. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaPreReq ( + UNIT_TEST_CONTEXT Context + ) +{ + MlDsaContext1 = NULL; + MlDsaContext2 = NULL; + + return UNIT_TEST_PASSED; +} + +/** + Cleanup function for ML-DSA tests. + + @param[in] Context Unit test context. +**/ +VOID +EFIAPI +TestVerifyMlDsaCleanUp ( + UNIT_TEST_CONTEXT Context + ) +{ + if (MlDsaContext1 != NULL) { + MlDsaFree (MlDsaContext1); + MlDsaContext1 = NULL; + } + + if (MlDsaContext2 != NULL) { + MlDsaFree (MlDsaContext2); + MlDsaContext2 = NULL; + } +} + +/** + Validate UEFI-OpenSSL ML-DSA Context Creation. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaNew ( + UNIT_TEST_CONTEXT Context + ) +{ + // + // Test MlDsaNewByNid with ML-DSA-87 + // + MlDsaContext1 = MlDsaNewByNid (CRYPTO_NID_ML_DSA_87); + UT_ASSERT_NOT_NULL (MlDsaContext1); + + // + // Test MlDsaNewByNid with invalid NID + // + MlDsaContext2 = MlDsaNewByNid (CRYPTO_NID_NULL); + UT_ASSERT_EQUAL ((UINTN)MlDsaContext2, (UINTN)NULL); + + // + // Test MlDsaFree + // + MlDsaFree (MlDsaContext1); + MlDsaContext1 = NULL; + + // + // Test MlDsaFree with NULL (should not crash) + // + MlDsaFree (NULL); + + return UNIT_TEST_PASSED; +} + +/** + Validate UEFI-OpenSSL ML-DSA Key Setting and Getting. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaKeySetGet ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 PublicKey[ML_DSA_87_PUBLIC_KEY_SIZE]; + UINTN PublicKeySize; + UINT8 TooSmallBuffer[10]; + UINTN TooSmallSize; + + // + // Create ML-DSA context + // + MlDsaContext1 = MlDsaNewByNid (CRYPTO_NID_ML_DSA_87); + UT_ASSERT_NOT_NULL (MlDsaContext1); + + // + // Test MlDsaGetPubKey with too small buffer (before key is set) + // + TooSmallSize = sizeof (TooSmallBuffer); + Status = MlDsaGetPubKey (MlDsaContext1, TooSmallBuffer, &TooSmallSize); + UT_ASSERT_FALSE (Status); + UT_ASSERT_NOT_EQUAL (TooSmallSize, ML_DSA_87_PUBLIC_KEY_SIZE); + + // + // Test MlDsaSetPrivKey with NULL context + // + Status = MlDsaSetPrivKey (NULL, (UINT8 *)mMlDsa87TestPemKey, 100); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaSetPrivKey with NULL key + // + Status = MlDsaSetPrivKey (MlDsaContext1, NULL, ML_DSA_87_PRIVATE_KEY_SIZE); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaSetPrivKey with wrong size + // + Status = MlDsaSetPrivKey (MlDsaContext1, (UINT8 *)mMlDsa87TestPemKey, 32); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaSetPubKey with NULL context + // + Status = MlDsaSetPubKey (NULL, (UINT8 *)mMlDsa87TestCert, 100); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaSetPubKey with NULL key + // + Status = MlDsaSetPubKey (MlDsaContext1, NULL, ML_DSA_87_PUBLIC_KEY_SIZE); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaSetPubKey with wrong size + // + Status = MlDsaSetPubKey (MlDsaContext1, (UINT8 *)mMlDsa87TestCert, 32); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaGetPubKey with NULL context + // + PublicKeySize = sizeof (PublicKey); + Status = MlDsaGetPubKey (NULL, PublicKey, &PublicKeySize); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaGetPubKey with NULL size + // + Status = MlDsaGetPubKey (MlDsaContext1, PublicKey, NULL); + UT_ASSERT_FALSE (Status); + + // + // Clean up context + // + MlDsaFree (MlDsaContext1); + MlDsaContext1 = NULL; + + return UNIT_TEST_PASSED; +} + +/** + Validate ML-DSA error cases. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaErrorCases ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 Signature[ML_DSA_87_SIGNATURE_SIZE]; + UINTN SigSize; + UINT8 TooSmallBuffer[10]; + UINTN TooSmallSize; + + // + // Create ML-DSA context + // + MlDsaContext1 = MlDsaNewByNid (CRYPTO_NID_ML_DSA_87); + UT_ASSERT_NOT_NULL (MlDsaContext1); + + // + // Test MlDsaSign with NULL context + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + NULL, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + AsciiStrLen (mMlDsaTestMessage), + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaSign with NULL message + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + MlDsaContext1, + NULL, + 0, + NULL, + 0, + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaSign with too small buffer + // + TooSmallSize = sizeof (TooSmallBuffer); + Status = MlDsaSign ( + MlDsaContext1, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + AsciiStrLen (mMlDsaTestMessage), + TooSmallBuffer, + &TooSmallSize + ); + UT_ASSERT_FALSE (Status); + UT_ASSERT_NOT_EQUAL (TooSmallSize, sizeof (Signature)); + + // + // Test MlDsaVerify with NULL context + // + Status = MlDsaVerify ( + NULL, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + AsciiStrLen (mMlDsaTestMessage), + Signature, + sizeof (Signature) + ); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaVerify with NULL message + // + Status = MlDsaVerify ( + MlDsaContext1, + NULL, + 0, + NULL, + 0, + Signature, + sizeof (Signature) + ); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaVerify with NULL signature + // + Status = MlDsaVerify ( + MlDsaContext1, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + AsciiStrLen (mMlDsaTestMessage), + NULL, + sizeof (Signature) + ); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaVerify with zero signature size + // + Status = MlDsaVerify ( + MlDsaContext1, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + AsciiStrLen (mMlDsaTestMessage), + Signature, + 0 + ); + UT_ASSERT_FALSE (Status); + + return UNIT_TEST_PASSED; +} + +/** + Validate ML-DSA key retrieval from PEM and X509. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaPemX509 ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *MlDsaPrivKey; + VOID *MlDsaPubKey; + UINT8 Signature[ML_DSA_87_SIGNATURE_SIZE]; + UINTN SigSize; + UINTN MessageSize; + + MlDsaPrivKey = NULL; + MlDsaPubKey = NULL; + MessageSize = AsciiStrLen (mMlDsaTestMessage); + + // + // Retrieve ML-DSA private key from PEM data. + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &MlDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (MlDsaPrivKey); + + // + // Retrieve ML-DSA public key from X509 certificate. + // + Status = MlDsaGetPublicKeyFromX509 ( + mMlDsa87TestCert, + sizeof (mMlDsa87TestCert), + &MlDsaPubKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (MlDsaPubKey); + + // + // ML-DSA signing with key from PEM (no context string) + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + MlDsaPrivKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (SigSize, ML_DSA_87_SIGNATURE_SIZE); + + // + // ML-DSA verification with key from X509 + // + Status = MlDsaVerify ( + MlDsaPubKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + MlDsaFree (MlDsaPrivKey); + MlDsaFree (MlDsaPubKey); + + return UNIT_TEST_PASSED; +} + +/** + Validate ML-DSA signing and verification with context string. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaSignVerifyWithContext ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *MlDsaPrivKey; + VOID *MlDsaPubKey; + UINT8 Signature[ML_DSA_87_SIGNATURE_SIZE]; + UINTN SigSize; + UINTN MessageSize; + UINTN ContextSize; + + MlDsaPrivKey = NULL; + MlDsaPubKey = NULL; + MessageSize = AsciiStrLen (mMlDsaTestMessage); + ContextSize = AsciiStrLen (mMlDsaTestContext); + + // + // Retrieve ML-DSA private key from PEM data. + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &MlDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (MlDsaPrivKey); + + // + // Retrieve ML-DSA public key from X509 certificate. + // + Status = MlDsaGetPublicKeyFromX509 ( + mMlDsa87TestCert, + sizeof (mMlDsa87TestCert), + &MlDsaPubKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (MlDsaPubKey); + + // + // ML-DSA signing with context string + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + MlDsaPrivKey, + (UINT8 *)mMlDsaTestContext, + ContextSize, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (SigSize, ML_DSA_87_SIGNATURE_SIZE); + + // + // ML-DSA verification with matching context string + // + Status = MlDsaVerify ( + MlDsaPubKey, + (UINT8 *)mMlDsaTestContext, + ContextSize, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // ML-DSA verification should fail with mismatched context string + // + Status = MlDsaVerify ( + MlDsaPubKey, + (UINT8 *)"Different context", + AsciiStrLen ("Different context"), + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // ML-DSA verification should fail with no context when signature used context + // + Status = MlDsaVerify ( + MlDsaPubKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + MlDsaFree (MlDsaPrivKey); + MlDsaFree (MlDsaPubKey); + + return UNIT_TEST_PASSED; +} + +/** + Validate ML-DSA public key extraction and generation. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaGetPubKey ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *MlDsaPrivKey; + UINT8 PublicKey[ML_DSA_87_PUBLIC_KEY_SIZE]; + UINTN PublicKeySize; + + MlDsaPrivKey = NULL; + + // + // Retrieve ML-DSA private key from PEM data. + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &MlDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (MlDsaPrivKey); + + // + // Get public key from private key context + // + PublicKeySize = sizeof (PublicKey); + Status = MlDsaGetPubKey ( + MlDsaPrivKey, + PublicKey, + &PublicKeySize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (PublicKeySize, ML_DSA_87_PUBLIC_KEY_SIZE); + + // + // Verify the public key buffer is not all zeros + // + BOOLEAN AllZeros; + UINTN Index; + + AllZeros = TRUE; + for (Index = 0; Index < PublicKeySize; Index++) { + if (PublicKey[Index] != 0) { + AllZeros = FALSE; + break; + } + } + + UT_ASSERT_FALSE (AllZeros); + + MlDsaFree (MlDsaPrivKey); + + return UNIT_TEST_PASSED; +} + +/** + Validate ML-DSA signature verification fails with tampered data. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaTamperedData ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *MlDsaPrivKey; + VOID *MlDsaPubKey; + UINT8 Signature[ML_DSA_87_SIGNATURE_SIZE]; + UINT8 TamperedSignature[ML_DSA_87_SIGNATURE_SIZE]; + CHAR8 TamperedMessage[100]; + UINTN SigSize; + UINTN MessageSize; + + MlDsaPrivKey = NULL; + MlDsaPubKey = NULL; + MessageSize = AsciiStrLen (mMlDsaTestMessage); + + // + // Retrieve ML-DSA private key from PEM data. + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &MlDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (MlDsaPrivKey); + + // + // Retrieve ML-DSA public key from X509 certificate. + // + Status = MlDsaGetPublicKeyFromX509 ( + mMlDsa87TestCert, + sizeof (mMlDsa87TestCert), + &MlDsaPubKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (MlDsaPubKey); + + // + // Generate valid signature + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + MlDsaPrivKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Verify original signature works + // + Status = MlDsaVerify ( + MlDsaPubKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Test with tampered message (should fail) + // + AsciiStrCpyS (TamperedMessage, sizeof (TamperedMessage), mMlDsaTestMessage); + TamperedMessage[0] = 'X'; + Status = MlDsaVerify ( + MlDsaPubKey, + NULL, + 0, + (UINT8 *)TamperedMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test with tampered signature (should fail) + // + CopyMem (TamperedSignature, Signature, sizeof (Signature)); + TamperedSignature[0] ^= 0x01; + Status = MlDsaVerify ( + MlDsaPubKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + TamperedSignature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test with wrong signature size (should fail) + // + Status = MlDsaVerify ( + MlDsaPubKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + SigSize - 1 + ); + UT_ASSERT_FALSE (Status); + + MlDsaFree (MlDsaPrivKey); + MlDsaFree (MlDsaPubKey); + + return UNIT_TEST_PASSED; +} + +/** + Validate ML-DSA PEM loading error cases. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaPemErrors ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *MlDsaKey; + + MlDsaKey = NULL; + + // + // Test MlDsaGetPrivateKeyFromPem with NULL PEM data + // + Status = MlDsaGetPrivateKeyFromPem ( + NULL, + 100, + NULL, + &MlDsaKey + ); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaGetPrivateKeyFromPem with NULL context pointer + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + NULL + ); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaGetPrivateKeyFromPem with invalid PEM data + // + Status = MlDsaGetPrivateKeyFromPem ( + (UINT8 *)"Invalid PEM data", + 16, + NULL, + &MlDsaKey + ); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaGetPublicKeyFromX509 with NULL certificate + // + Status = MlDsaGetPublicKeyFromX509 ( + NULL, + 100, + &MlDsaKey + ); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaGetPublicKeyFromX509 with NULL context pointer + // + Status = MlDsaGetPublicKeyFromX509 ( + mMlDsa87TestCert, + sizeof (mMlDsa87TestCert), + NULL + ); + UT_ASSERT_FALSE (Status); + + // + // Test MlDsaGetPublicKeyFromX509 with invalid certificate data + // + Status = MlDsaGetPublicKeyFromX509 ( + (UINT8 *)"Invalid cert data", + 17, + &MlDsaKey + ); + UT_ASSERT_FALSE (Status); + + return UNIT_TEST_PASSED; +} + +/** + Validate ML-DSA operations on context without keys. + + This test validates that operations fail properly when no key is set. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaNoKeyOperations ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 Signature[ML_DSA_87_SIGNATURE_SIZE]; + UINT8 PublicKey[ML_DSA_87_PUBLIC_KEY_SIZE]; + UINTN SigSize; + UINTN PublicKeySize; + + // + // Create context without setting any key + // + MlDsaContext1 = MlDsaNewByNid (CRYPTO_NID_ML_DSA_87); + UT_ASSERT_NOT_NULL (MlDsaContext1); + + // + // MlDsaSign should fail when EvpPkey is NULL + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + MlDsaContext1, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + AsciiStrLen (mMlDsaTestMessage), + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // MlDsaVerify should fail when EvpPkey is NULL + // + Status = MlDsaVerify ( + MlDsaContext1, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + AsciiStrLen (mMlDsaTestMessage), + Signature, + sizeof (Signature) + ); + UT_ASSERT_FALSE (Status); + + // + // MlDsaGetPubKey should fail when EvpPkey is NULL + // + PublicKeySize = sizeof (PublicKey); + Status = MlDsaGetPubKey ( + MlDsaContext1, + PublicKey, + &PublicKeySize + ); + UT_ASSERT_FALSE (Status); + + MlDsaFree (MlDsaContext1); + MlDsaContext1 = NULL; + + return UNIT_TEST_PASSED; +} + +/** + Validate ML-DSA context string parameter validation. + + This test validates the check: (ContextSize > 0) && (Context == NULL). + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaInvalidContextParams ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *MlDsaPrivKey; + VOID *MlDsaPubKey; + UINT8 Signature[ML_DSA_87_SIGNATURE_SIZE]; + UINTN SigSize; + UINTN MessageSize; + + MlDsaPrivKey = NULL; + MlDsaPubKey = NULL; + MessageSize = AsciiStrLen (mMlDsaTestMessage); + + // + // Get valid keys + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &MlDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + + Status = MlDsaGetPublicKeyFromX509 ( + mMlDsa87TestCert, + sizeof (mMlDsa87TestCert), + &MlDsaPubKey + ); + UT_ASSERT_TRUE (Status); + + // + // Test MlDsaSign with NULL Context but ContextSize > 0 (invalid combination) + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + MlDsaPrivKey, + NULL, + 10, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Generate valid signature for verify test + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + MlDsaPrivKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Test MlDsaVerify with NULL Context but ContextSize > 0 (invalid combination) + // + Status = MlDsaVerify ( + MlDsaPubKey, + NULL, + 5, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + MlDsaFree (MlDsaPrivKey); + MlDsaFree (MlDsaPubKey); + + return UNIT_TEST_PASSED; +} + +/** + Validate MlDsaGetPubKey with NULL buffer parameter. + + This test validates that NULL PublicKey buffer returns FALSE and sets size to 0. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaGetPubKeyNullBuffer ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *MlDsaPrivKey; + UINTN PublicKeySize; + + MlDsaPrivKey = NULL; + + // + // Get valid private key + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &MlDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + + // + // Test MlDsaGetPubKey with NULL buffer + // Should return FALSE and set PublicKeySize to 0 + // + PublicKeySize = 9999; + Status = MlDsaGetPubKey ( + MlDsaPrivKey, + NULL, + &PublicKeySize + ); + UT_ASSERT_FALSE (Status); + UT_ASSERT_EQUAL (PublicKeySize, 0); + + MlDsaFree (MlDsaPrivKey); + + return UNIT_TEST_PASSED; +} + +/** + Validate ML-DSA signature size exact match validation. + + This test validates that MlDsaVerify properly validates signature size. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaSignatureSizeExact ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *MlDsaPrivKey; + VOID *MlDsaPubKey; + UINT8 Signature[ML_DSA_87_SIGNATURE_SIZE]; + UINTN SigSize; + UINTN MessageSize; + + MlDsaPrivKey = NULL; + MlDsaPubKey = NULL; + MessageSize = AsciiStrLen (mMlDsaTestMessage); + + // + // Get valid keys + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &MlDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + + Status = MlDsaGetPublicKeyFromX509 ( + mMlDsa87TestCert, + sizeof (mMlDsa87TestCert), + &MlDsaPubKey + ); + UT_ASSERT_TRUE (Status); + + // + // Generate valid signature + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + MlDsaPrivKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (SigSize, ML_DSA_87_SIGNATURE_SIZE); + + // + // Verify with exact size - should succeed + // + Status = MlDsaVerify ( + MlDsaPubKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + ML_DSA_87_SIGNATURE_SIZE + ); + UT_ASSERT_TRUE (Status); + + // + // Verify with size + 1 - should fail + // + Status = MlDsaVerify ( + MlDsaPubKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + ML_DSA_87_SIGNATURE_SIZE + 1 + ); + UT_ASSERT_FALSE (Status); + + // + // Verify with size - 1 - should fail + // + Status = MlDsaVerify ( + MlDsaPubKey, + NULL, + 0, + (UINT8 *)mMlDsaTestMessage, + MessageSize, + Signature, + ML_DSA_87_SIGNATURE_SIZE - 1 + ); + UT_ASSERT_FALSE (Status); + + MlDsaFree (MlDsaPrivKey); + MlDsaFree (MlDsaPubKey); + + return UNIT_TEST_PASSED; +} + +/** + Test ML-DSA context lifecycle with multiple allocations. + + Tests proper resource management including multiple successive allocations, + cleanup verification, and null pointer safety. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaContextLifecycle ( + UNIT_TEST_CONTEXT Context + ) +{ + VOID *TempCtx1; + VOID *TempCtx2; + VOID *TempCtx3; + + // + // Test creating multiple contexts + // + TempCtx1 = MlDsaNewByNid (CRYPTO_NID_ML_DSA_87); + UT_ASSERT_NOT_NULL (TempCtx1); + + TempCtx2 = MlDsaNewByNid (CRYPTO_NID_ML_DSA_87); + UT_ASSERT_NOT_NULL (TempCtx2); + + TempCtx3 = MlDsaNewByNid (CRYPTO_NID_ML_DSA_87); + UT_ASSERT_NOT_NULL (TempCtx3); + + // + // Free in different order + // + MlDsaFree (TempCtx2); + MlDsaFree (TempCtx1); + MlDsaFree (TempCtx3); + + // + // Double-free safety (should not crash) + // + MlDsaFree (NULL); + MlDsaFree (NULL); + + return UNIT_TEST_PASSED; +} + +/** + Test ML-DSA empty message signing and verification. + + Tests edge case of zero-length messages. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaEmptyMessage ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *PrivKey; + VOID *PubKey; + UINT8 Signature[ML_DSA_87_SIGNATURE_SIZE]; + UINTN SigSize; + UINT8 EmptyMsg[1]; + + PrivKey = NULL; + PubKey = NULL; + + // + // Load keys + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &PrivKey + ); + UT_ASSERT_TRUE (Status); + + Status = MlDsaGetPublicKeyFromX509 ( + mMlDsa87TestCert, + sizeof (mMlDsa87TestCert), + &PubKey + ); + UT_ASSERT_TRUE (Status); + + // + // Sign empty message - should fail with NULL message + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + PrivKey, + NULL, + 0, + NULL, + 0, + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Sign with valid pointer but zero size - should succeed + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + PrivKey, + NULL, + 0, + EmptyMsg, + 0, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Verify the zero-length message signature + // + Status = MlDsaVerify ( + PubKey, + NULL, + 0, + EmptyMsg, + 0, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + MlDsaFree (PrivKey); + MlDsaFree (PubKey); + + return UNIT_TEST_PASSED; +} + +/** + Test ML-DSA maximum length context string. + + Tests the maximum allowed context string size per FIPS 204. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaMaxContextString ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *PrivKey; + VOID *PubKey; + UINT8 Signature[ML_DSA_87_SIGNATURE_SIZE]; + UINTN SigSize; + UINT8 MaxContext[ML_DSA_MAX_CONTEXT_SIZE]; + UINTN Index; + + PrivKey = NULL; + PubKey = NULL; + + // + // Fill context with pattern + // + for (Index = 0; Index < ML_DSA_MAX_CONTEXT_SIZE; Index++) { + MaxContext[Index] = (UINT8)(Index & 0xFF); + } + + // + // Load keys + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &PrivKey + ); + UT_ASSERT_TRUE (Status); + + Status = MlDsaGetPublicKeyFromX509 ( + mMlDsa87TestCert, + sizeof (mMlDsa87TestCert), + &PubKey + ); + UT_ASSERT_TRUE (Status); + + // + // Sign with maximum context + // + SigSize = sizeof (Signature); + Status = MlDsaSign ( + PrivKey, + MaxContext, + ML_DSA_MAX_CONTEXT_SIZE, + (UINT8 *)mMlDsaTestMessage, + AsciiStrLen (mMlDsaTestMessage), + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Verify with matching context + // + Status = MlDsaVerify ( + PubKey, + MaxContext, + ML_DSA_MAX_CONTEXT_SIZE, + (UINT8 *)mMlDsaTestMessage, + AsciiStrLen (mMlDsaTestMessage), + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Verify should fail with one byte different + // + MaxContext[0] ^= 1; + Status = MlDsaVerify ( + PubKey, + MaxContext, + ML_DSA_MAX_CONTEXT_SIZE, + (UINT8 *)mMlDsaTestMessage, + AsciiStrLen (mMlDsaTestMessage), + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + MlDsaFree (PrivKey); + MlDsaFree (PubKey); + + return UNIT_TEST_PASSED; +} + +/** + Test ML-DSA key replacement in context. + + Tests that replacing keys properly frees old key and sets new key. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaKeyReplacement ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *PrivKey; + UINT8 PublicKey1[ML_DSA_87_PUBLIC_KEY_SIZE]; + UINT8 PublicKey2[ML_DSA_87_PUBLIC_KEY_SIZE]; + UINTN PubKeySize; + + PrivKey = NULL; + + // + // Load first key + // + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &PrivKey + ); + UT_ASSERT_TRUE (Status); + + // + // Get public key + // + PubKeySize = sizeof (PublicKey1); + Status = MlDsaGetPubKey (PrivKey, PublicKey1, &PubKeySize); + UT_ASSERT_TRUE (Status); + + // + // Now replace with a public-only key + // + MlDsaContext1 = MlDsaNewByNid (CRYPTO_NID_ML_DSA_87); + UT_ASSERT_NOT_NULL (MlDsaContext1); + + Status = MlDsaSetPubKey (MlDsaContext1, PublicKey1, ML_DSA_87_PUBLIC_KEY_SIZE); + UT_ASSERT_TRUE (Status); + + // + // Replace with same public key again (tests EVP_PKEY_free path) + // + Status = MlDsaSetPubKey (MlDsaContext1, PublicKey1, ML_DSA_87_PUBLIC_KEY_SIZE); + UT_ASSERT_TRUE (Status); + + // + // Verify we can still get the key + // + PubKeySize = sizeof (PublicKey2); + Status = MlDsaGetPubKey (MlDsaContext1, PublicKey2, &PubKeySize); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (PubKeySize, ML_DSA_87_PUBLIC_KEY_SIZE); + + MlDsaFree (PrivKey); + MlDsaFree (MlDsaContext1); + MlDsaContext1 = NULL; + + return UNIT_TEST_PASSED; +} + +/** + Test ML-DSA multiple signatures with same key. + + Tests that the same key can generate multiple signatures. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaMultipleSignatures ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *PrivKey; + VOID *PubKey; + UINT8 Sig1[ML_DSA_87_SIGNATURE_SIZE]; + UINT8 Sig2[ML_DSA_87_SIGNATURE_SIZE]; + UINT8 Sig3[ML_DSA_87_SIGNATURE_SIZE]; + UINTN SigSize; + CHAR8 *Msg1 = "First message"; + CHAR8 *Msg2 = "Second message"; + CHAR8 *Msg3 = "Third message"; + + PrivKey = NULL; + PubKey = NULL; + + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &PrivKey + ); + UT_ASSERT_TRUE (Status); + + Status = MlDsaGetPublicKeyFromX509 ( + mMlDsa87TestCert, + sizeof (mMlDsa87TestCert), + &PubKey + ); + UT_ASSERT_TRUE (Status); + + // + // Generate three different signatures + // + SigSize = sizeof (Sig1); + Status = MlDsaSign (PrivKey, NULL, 0, (UINT8 *)Msg1, AsciiStrLen (Msg1), Sig1, &SigSize); + UT_ASSERT_TRUE (Status); + + SigSize = sizeof (Sig2); + Status = MlDsaSign (PrivKey, NULL, 0, (UINT8 *)Msg2, AsciiStrLen (Msg2), Sig2, &SigSize); + UT_ASSERT_TRUE (Status); + + SigSize = sizeof (Sig3); + Status = MlDsaSign (PrivKey, NULL, 0, (UINT8 *)Msg3, AsciiStrLen (Msg3), Sig3, &SigSize); + UT_ASSERT_TRUE (Status); + + // + // Verify all three with correct messages + // + Status = MlDsaVerify (PubKey, NULL, 0, (UINT8 *)Msg1, AsciiStrLen (Msg1), Sig1, sizeof (Sig1)); + UT_ASSERT_TRUE (Status); + + Status = MlDsaVerify (PubKey, NULL, 0, (UINT8 *)Msg2, AsciiStrLen (Msg2), Sig2, sizeof (Sig2)); + UT_ASSERT_TRUE (Status); + + Status = MlDsaVerify (PubKey, NULL, 0, (UINT8 *)Msg3, AsciiStrLen (Msg3), Sig3, sizeof (Sig3)); + UT_ASSERT_TRUE (Status); + + // + // Cross-verify should fail (wrong message/signature pairs) + // + Status = MlDsaVerify (PubKey, NULL, 0, (UINT8 *)Msg1, AsciiStrLen (Msg1), Sig2, sizeof (Sig2)); + UT_ASSERT_FALSE (Status); + + Status = MlDsaVerify (PubKey, NULL, 0, (UINT8 *)Msg2, AsciiStrLen (Msg2), Sig3, sizeof (Sig3)); + UT_ASSERT_FALSE (Status); + + MlDsaFree (PrivKey); + MlDsaFree (PubKey); + + return UNIT_TEST_PASSED; +} + +/** + Test ML-DSA GetPubKey called multiple times. + + Tests that repeated calls to GetPubKey return consistent results. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifyMlDsaGetPubKeyRepeated ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *PrivKey; + UINT8 PubKey1[ML_DSA_87_PUBLIC_KEY_SIZE]; + UINT8 PubKey2[ML_DSA_87_PUBLIC_KEY_SIZE]; + UINT8 PubKey3[ML_DSA_87_PUBLIC_KEY_SIZE]; + UINTN Size1, Size2, Size3; + + PrivKey = NULL; + + Status = MlDsaGetPrivateKeyFromPem ( + mMlDsa87TestPemKey, + sizeof (mMlDsa87TestPemKey), + NULL, + &PrivKey + ); + UT_ASSERT_TRUE (Status); + + // + // Get public key three times + // + Size1 = sizeof (PubKey1); + Status = MlDsaGetPubKey (PrivKey, PubKey1, &Size1); + UT_ASSERT_TRUE (Status); + + Size2 = sizeof (PubKey2); + Status = MlDsaGetPubKey (PrivKey, PubKey2, &Size2); + UT_ASSERT_TRUE (Status); + + Size3 = sizeof (PubKey3); + Status = MlDsaGetPubKey (PrivKey, PubKey3, &Size3); + UT_ASSERT_TRUE (Status); + + // + // All should be identical + // + UT_ASSERT_EQUAL (Size1, Size2); + UT_ASSERT_EQUAL (Size2, Size3); + UT_ASSERT_MEM_EQUAL (PubKey1, PubKey2, Size1); + UT_ASSERT_MEM_EQUAL (PubKey2, PubKey3, Size2); + + MlDsaFree (PrivKey); + + return UNIT_TEST_PASSED; +} + +TEST_DESC mMlDsaTest[] = { + // + // -----Description------------------------------------Class-------------------------Function----------------------------Pre-------------------Post--------------------Context + // + { "TestVerifyMlDsaNew()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaNew, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaKeySetGet()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaKeySetGet, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaErrorCases()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaErrorCases, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaPemX509()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaPemX509, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaSignVerifyWithContext()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaSignVerifyWithContext, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaGetPubKey()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaGetPubKey, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaTamperedData()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaTamperedData, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaPemErrors()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaPemErrors, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaNoKeyOperations()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaNoKeyOperations, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaInvalidContextParams()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaInvalidContextParams, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaGetPubKeyNullBuffer()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaGetPubKeyNullBuffer, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaSignatureSizeExact()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaSignatureSizeExact, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaContextLifecycle()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaContextLifecycle, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaEmptyMessage()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaEmptyMessage, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaMaxContextString()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaMaxContextString, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaKeyReplacement()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaKeyReplacement, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaMultipleSignatures()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaMultipleSignatures, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, + { "TestVerifyMlDsaGetPubKeyRepeated()", "CryptoPkg.BaseCryptLib.MlDsa", TestVerifyMlDsaGetPubKeyRepeated, TestVerifyMlDsaPreReq, TestVerifyMlDsaCleanUp, NULL }, +}; + +UINTN mMlDsaTestNum = ARRAY_SIZE (mMlDsaTest); diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h index da4b6d8796..393d1e4760 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h @@ -100,6 +100,9 @@ extern TEST_DESC mEcTest[]; extern UINTN mEdDsaTestNum; extern TEST_DESC mEdDsaTest[]; +extern UINTN mMlDsaTestNum; +extern TEST_DESC mMlDsaTest[]; + extern UINTN mX509TestNum; extern TEST_DESC mX509Test[]; diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf index 0ad04eb25f..d8d6d6248e 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf @@ -45,6 +45,7 @@ EcTests.c X509Tests.c EdDsaTests.c + MlDsaTests.c [Packages] MdePkg/MdePkg.dec diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf index ca9d6fb6d0..6dc37f1a61 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf @@ -41,6 +41,7 @@ BnTests.c EcTests.c EdDsaTests.c + MlDsaTests.c X509Tests.c Pkcs7AttachedContentTest.c From bc15a87b74e70ebcbb2428bf9d0d87265c018e84 Mon Sep 17 00:00:00 2001 From: abuthahirm <abuthahirm@ami.com> Date: Thu, 30 Apr 2026 16:59:03 +0530 Subject: [PATCH 182/406] NetworkPkg/Dhcp6Dxe: Defensively check for NULL Config in Dhcp6UpdateIaInfo Replace the ASSERT (Instance->Config != NULL) in Dhcp6UpdateIaInfo with an explicit NULL check that returns EFI_DEVICE_ERROR. Also add a complementary guard in Dhcp6GenerateIaCb alongside the existing check for Instance->IaCb.Ia. These are defensive changes to prevent potential NULL pointer dereferences. Signed-off-by: Abuthahir M <abuthahirm@ami.com> --- NetworkPkg/Dhcp6Dxe/Dhcp6Io.c | 4 +++- NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c b/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c index 79a67796ee..4dc3844854 100644 --- a/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c +++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c @@ -538,7 +538,9 @@ Dhcp6UpdateIaInfo ( T1 = 0; T2 = 0; - ASSERT (Instance->Config != NULL); + if (Instance->Config == NULL) { + return EFI_DEVICE_ERROR; + } // OptionLen is the length of the Options excluding the DHCP header. // Length of the EFI_DHCP6_PACKET from the first byte of the Header field to the last diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c b/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c index f72bc93a68..9eb1bdd350 100644 --- a/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c +++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c @@ -1335,7 +1335,7 @@ Dhcp6GenerateIaCb ( UINT32 IaSize; EFI_DHCP6_IA *Ia; - if (Instance->IaCb.Ia == NULL) { + if ((Instance->IaCb.Ia == NULL) || (Instance->Config == NULL)) { return EFI_DEVICE_ERROR; } From d21677e0bcc3b811d896e231775ef64584348470 Mon Sep 17 00:00:00 2001 From: abuthahirm <abuthahirm@ami.com> Date: Thu, 30 Apr 2026 16:59:13 +0530 Subject: [PATCH 183/406] NetworkPkg/Ip6Dxe: Move neighbor table cleanup before MNP teardown In Ip6CleanService, Ip6FreeNeighborEntry may attempt to send packets via MNP. Defensively move the neighbor table cleanup to occur before MNP teardown so that the MNP child handle and its resources remain valid during neighbor entry cleanup. Signed-off-by: Abuthahir M <abuthahirm@ami.com> --- NetworkPkg/Ip6Dxe/Ip6Driver.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/NetworkPkg/Ip6Dxe/Ip6Driver.c b/NetworkPkg/Ip6Dxe/Ip6Driver.c index cbe011dad4..ff690fbc1b 100644 --- a/NetworkPkg/Ip6Dxe/Ip6Driver.c +++ b/NetworkPkg/Ip6Dxe/Ip6Driver.c @@ -190,6 +190,14 @@ Ip6CleanService ( Ip6CleanPrefixListTable (IpSb, &IpSb->OnlinkPrefix); Ip6CleanPrefixListTable (IpSb, &IpSb->AutonomousPrefix); + // + // Free the Neighbor Discovery resources before MNP teardown. + // + while (!IsListEmpty (&IpSb->NeighborTable)) { + NeighborCache = NET_LIST_HEAD (&IpSb->NeighborTable, IP6_NEIGHBOR_ENTRY, Link); + Ip6FreeNeighborEntry (IpSb, NeighborCache, FALSE, TRUE, EFI_SUCCESS, NULL, NULL); + } + if (IpSb->RouteTable != NULL) { Ip6CleanRouteTable (IpSb->RouteTable); IpSb->RouteTable = NULL; @@ -231,14 +239,6 @@ Ip6CleanService ( gBS->CloseEvent (IpSb->RecvRequest.MnpToken.Event); } - // - // Free the Neighbor Discovery resources - // - while (!IsListEmpty (&IpSb->NeighborTable)) { - NeighborCache = NET_LIST_HEAD (&IpSb->NeighborTable, IP6_NEIGHBOR_ENTRY, Link); - Ip6FreeNeighborEntry (IpSb, NeighborCache, FALSE, TRUE, EFI_SUCCESS, NULL, NULL); - } - return EFI_SUCCESS; } From a589f6fe03f417f0a1db265dfc42fe2a6595dc1b Mon Sep 17 00:00:00 2001 From: abuthahirm <abuthahirm@ami.com> Date: Thu, 30 Apr 2026 16:59:22 +0530 Subject: [PATCH 184/406] NetworkPkg/Ip6Dxe: Add NULL check for InterfaceId before dereference In Ip6ProcessRouterAdvertise, IpSb->InterfaceId is dereferenced in CopyMem to form a stateless address. Add a guard to ensure IpSb->InterfaceId is not NULL before entering the block, preventing a potential NULL pointer dereference. Signed-off-by: Abuthahir M <abuthahirm@ami.com> --- NetworkPkg/Ip6Dxe/Ip6Nd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/NetworkPkg/Ip6Dxe/Ip6Nd.c b/NetworkPkg/Ip6Dxe/Ip6Nd.c index aa5770134e..dd38db8e8c 100644 --- a/NetworkPkg/Ip6Dxe/Ip6Nd.c +++ b/NetworkPkg/Ip6Dxe/Ip6Nd.c @@ -2277,6 +2277,7 @@ Ip6ProcessRouterAdvertise ( // if ((PrefixList == NULL) && (PrefixOption.ValidLifetime != 0) && + (IpSb->InterfaceId != NULL) && (PrefixOption.PrefixLength + IpSb->InterfaceIdLen * 8 == 128) ) { From 7442655403aacaff7e4d7f0b1bafaefa6c781c2b Mon Sep 17 00:00:00 2001 From: abuthahirm <abuthahirm@ami.com> Date: Thu, 30 Apr 2026 16:59:33 +0530 Subject: [PATCH 185/406] NetworkPkg/UefiPxeBcDxe: Fix CopyMem destination in PxeBcDhcp6CallBack When caching the DHCPv6 discover packet to Mode->DhcpDiscover in PxeBcDhcp6CallBack, the destination was incorrectly specified as Mode->DhcpDiscover.Dhcpv4 (the DHCPv4 union member). Change it to Mode->DhcpDiscover to correctly reference the union and avoid type confusion when copying a DHCPv6 packet. Signed-off-by: Abuthahir M <abuthahirm@ami.com> --- NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c index 804335a2b4..c0aff8ac27 100644 --- a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c @@ -2053,7 +2053,7 @@ PxeBcDhcp6CallBack ( // // Cache the dhcp discover packet to mode data directly. // - CopyMem (&Mode->DhcpDiscover.Dhcpv4, &Packet->Dhcp6, Packet->Length); + CopyMem (&Mode->DhcpDiscover.Dhcpv6, &Packet->Dhcp6, Packet->Length); break; case Dhcp6RcvdAdvertise: From fe89a63da49a4052e124a86a2860a8d29761d60f Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Mon, 11 May 2026 17:15:57 -0700 Subject: [PATCH 186/406] OvmfPkg: MmControlPei: Fix QEMU does not send MMI to all cores Because there was no negotiation, the SMM controller from QEMU will not broadcast the SMI to all cores, causing only the BSP getting interrupted into MMI. This change fixed the issue by invoking the negotiation routine and program the register to enable broadcasting. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- OvmfPkg/SmmControl2Dxe/MmControlPei.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/OvmfPkg/SmmControl2Dxe/MmControlPei.c b/OvmfPkg/SmmControl2Dxe/MmControlPei.c index 8feac62e32..3290b639c5 100644 --- a/OvmfPkg/SmmControl2Dxe/MmControlPei.c +++ b/OvmfPkg/SmmControl2Dxe/MmControlPei.c @@ -185,6 +185,7 @@ MmControlPeiEntryPoint ( UINT32 PmBase; UINT32 SmiEnableVal; EFI_STATUS Status; + BOOLEAN NegotiationSuccessful; // // This module should only be included if SMRAM support is required. @@ -244,6 +245,13 @@ MmControlPeiEntryPoint ( goto FatalError; } + // + // QEMU can inject SMIs in different ways, negotiate our preferences. + // + NegotiationSuccessful = NegotiateSmiFeatures (); + + ASSERT (NegotiationSuccessful); + // // We have no pointers to convert to virtual addresses. The handle itself // doesn't matter, as protocol services are not accessible at runtime. From 0347d3b7113ef215e0f19a38206703e86a4e5d1b Mon Sep 17 00:00:00 2001 From: Michael D Kinney <michael.d.kinney@intel.com> Date: Tue, 14 Jul 2026 13:23:03 -0700 Subject: [PATCH 187/406] BaseTools/GenFv: Preserve legacy rebase behavior when Xip is unused Add XipFileCount to FV_INFO to track how many files have the ,XIP suffix. Update FfsRebase() to only apply selective XIP rebase when XipFileCount > 0. When no files have the ,XIP suffix (XipFileCount == 0), preserve the legacy ForceRebase=TRUE behavior of rebasing all files. This maintains backward compatibility for existing platforms that use FvForceRebase=TRUE without any Xip rules. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> --- BaseTools/Source/C/GenFv/GenFvInternalLib.c | 7 +++++-- BaseTools/Source/C/GenFv/GenFvInternalLib.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c index 20d16ef80f..8f844c2bbb 100644 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c @@ -333,6 +333,7 @@ Returns: if (XipFlag != NULL && stricmp (XipFlag, ",XIP") == 0) { *XipFlag = '\0'; FvInfo->XipFile[Number + Index] = TRUE; + FvInfo->XipFileCount++; } else { FvInfo->XipFile[Number + Index] = FALSE; } @@ -3464,10 +3465,12 @@ Returns: } // - // If ForceRebase Flag specified to TRUE, only rebase files marked with XIP. + // If ForceRebase Flag specified to TRUE and at least one file has XIP flag, + // use selective rebase: only rebase files marked with XIP. + // If no files have XIP flag, preserve legacy behavior: rebase all files. // if (FvInfo->ForceRebase == 1) { - if (!FvInfo->XipFile[FileIndex]) { + if (FvInfo->XipFileCount > 0 && !FvInfo->XipFile[FileIndex]) { return EFI_SUCCESS; } } diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.h b/BaseTools/Source/C/GenFv/GenFvInternalLib.h index 67970286d8..8f391701d8 100644 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.h +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.h @@ -210,6 +210,7 @@ typedef struct { EFI_FV_BLOCK_MAP_ENTRY FvBlocks[MAX_NUMBER_OF_FV_BLOCKS]; CHAR8 FvFiles[MAX_NUMBER_OF_FILES_IN_FV][MAX_LONG_FILE_PATH]; BOOLEAN XipFile[MAX_NUMBER_OF_FILES_IN_FV]; + UINT32 XipFileCount; UINT32 SizeofFvFiles[MAX_NUMBER_OF_FILES_IN_FV]; BOOLEAN IsPiFvImage; INT8 ForceRebase; From ae023dbe9952cef22a108bf247605030d0c60b50 Mon Sep 17 00:00:00 2001 From: Michael D Kinney <michael.d.kinney@intel.com> Date: Tue, 14 Jul 2026 13:23:10 -0700 Subject: [PATCH 188/406] BaseTools/Tests: Update TC6 for backward-compatible rebase behavior Update the test decision matrix and TC6 expected result to reflect the backward-compatible ForceRebase logic: when ForceRebase=TRUE and no files have the ,XIP suffix (XipFileCount==0), all files are rebased using the legacy behavior rather than skipping all files. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> --- BaseTools/Tests/TestGenFvXip.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/BaseTools/Tests/TestGenFvXip.py b/BaseTools/Tests/TestGenFvXip.py index b497eae436..5a4ad154b3 100644 --- a/BaseTools/Tests/TestGenFvXip.py +++ b/BaseTools/Tests/TestGenFvXip.py @@ -9,13 +9,14 @@ # FfsRebase() in GenFvInternalLib.c decides whether to rebase each PE/COFF # image in an FV based on three inputs: ForceRebase, BaseAddress, and XipFile[]. # -# ForceRebase BaseAddress XipFile[] Result -# ----------- ----------- --------- --------------------------------- -# -1 (unset) 0 any No rebase (early return) -# 0 (FALSE) any any No rebase (early return) -# 1 (TRUE) any FALSE No rebase (skip non-XIP file) -# 1 (TRUE) any TRUE Rebase (XIP file selected) -# -1 (unset) != 0 any Rebase ALL files (legacy path) +# ForceRebase BaseAddress XipFileCount XipFile[] Result +# ----------- ----------- ------------ --------- --------------------------------- +# -1 (unset) 0 any any No rebase (early return) +# 0 (FALSE) any any any No rebase (early return) +# 1 (TRUE) any 0 any Rebase ALL files (legacy compat) +# 1 (TRUE) any > 0 FALSE No rebase (skip non-XIP file) +# 1 (TRUE) any > 0 TRUE Rebase (XIP file selected) +# -1 (unset) != 0 any any Rebase ALL files (legacy path) # # Unit Tests (TestDetermineXipEnabled): # 11 parameterized subtests calling FfsInfStatement.DetermineXipEnabled() @@ -35,7 +36,7 @@ # TC3: ForceRebase=FALSE, Base!=0 -> no rebase # TC4: ForceRebase=TRUE, all Xip=TRUE -> rebase all # TC5: ForceRebase=TRUE, selective Xip -> rebase only Xip=TRUE -# TC6: ForceRebase=TRUE, no Xip -> no rebase +# TC6: ForceRebase=TRUE, no Xip -> rebase all (legacy compat) # TC7: ForceRebase=TRUE, mixed Xip -> rebase Xip=TRUE only # TC8: ForceRebase=TRUE, Base=0, Xip -> rebase (force overrides) # @@ -802,9 +803,9 @@ INF TestXipRebasePkg/TestDxeDriver/TestDxeDriver.inf ('TESTFV5', '0x00800000', 'TRUE', 'TRUE', 'TRUE', None, (True, True, False), 'TC5: ForceRebase=TRUE, selective Xip -> rebase Xip only'), # TC6: ForceRebase=TRUE, no files have Xip keyword. - # All files have XipFile==FALSE, so none are rebased. + # XipFileCount==0, so legacy behavior is preserved: rebase all files. ('TESTFV6', '0x00800000', 'TRUE', None, None, None, - (False, False, False), 'TC6: ForceRebase=TRUE, no Xip -> no rebase'), + (True, True, True), 'TC6: ForceRebase=TRUE, no Xip -> rebase all (legacy compat)'), # TC7: ForceRebase=TRUE, PEIM1 has Xip=TRUE, PEIM2 has Xip=FALSE. # Mixed XIP within same module type via RuleOverride. # Only PEIM1 is rebased; PEIM2 and DXE are skipped. From ef2996c667869dd36debd0004d7a6c813e523b05 Mon Sep 17 00:00:00 2001 From: Alexander Gryanko <xpahos@gmail.com> Date: Tue, 8 Jul 2025 14:35:51 +0300 Subject: [PATCH 189/406] MdePkg: added mock for InstallConfigurationTable InstallConfigurationTable is used in the AddImageExeInfo call and is necessary for outputting information about the binary file in case of an error. Mock has been added for the DxeImageVerificationHandler subroutine. Signed-off-by: Alexander Gryanko <xpahos@gmail.com> --- .../Library/MockUefiBootServicesTableLib.h | 7 ++ .../MockUefiBootServicesTableLib.cpp | 91 ++++++++++--------- 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h index b9cb7586c0..c94a9a9f49 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h @@ -100,4 +100,11 @@ struct MockUefiBootServicesTableLib { IN EFI_HANDLE AgentHandle, IN EFI_HANDLE ControllerHandle) ); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + gBS_InstallConfigurationTable, + (IN EFI_GUID *Guid, + IN VOID *Table) + ); }; diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp index 64df07e514..04d0ee52cc 100644 --- a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp @@ -16,53 +16,54 @@ MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_CreateEventEx, 6, EF MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_LocateDevicePath, 3, EFIAPI); MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_OpenProtocol, 6, EFIAPI); MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_CloseProtocol, 4, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_InstallConfigurationTable, 2, EFIAPI); static EFI_BOOT_SERVICES LocalBs = { - { 0, 0, 0, 0, 0 }, // EFI_TABLE_HEADER - NULL, // EFI_RAISE_TPL - NULL, // EFI_RESTORE_TPL - NULL, // EFI_ALLOCATE_PAGES - NULL, // EFI_FREE_PAGES - gBS_GetMemoryMap, // EFI_GET_MEMORY_MAP - NULL, // EFI_ALLOCATE_POOL - NULL, // EFI_FREE_POOL - gBS_CreateEvent, // EFI_CREATE_EVENT - NULL, // EFI_SET_TIMER - NULL, // EFI_WAIT_FOR_EVENT - NULL, // EFI_SIGNAL_EVENT - gBS_CloseEvent, // EFI_CLOSE_EVENT - NULL, // EFI_CHECK_EVENT - NULL, // EFI_INSTALL_PROTOCOL_INTERFACE - NULL, // EFI_REINSTALL_PROTOCOL_INTERFACE - NULL, // EFI_UNINSTALL_PROTOCOL_INTERFACE - gBS_HandleProtocol, // EFI_HANDLE_PROTOCOL - NULL, // VOID - NULL, // EFI_REGISTER_PROTOCOL_NOTIFY - NULL, // EFI_LOCATE_HANDLE - gBS_LocateDevicePath, // EFI_LOCATE_DEVICE_PATH - NULL, // EFI_INSTALL_CONFIGURATION_TABLE - NULL, // EFI_IMAGE_LOAD - NULL, // EFI_IMAGE_START - NULL, // EFI_EXIT - NULL, // EFI_IMAGE_UNLOAD - NULL, // EFI_EXIT_BOOT_SERVICES - NULL, // EFI_GET_NEXT_MONOTONIC_COUNT - NULL, // EFI_STALL - NULL, // EFI_SET_WATCHDOG_TIMER - NULL, // EFI_CONNECT_CONTROLLER - NULL, // EFI_DISCONNECT_CONTROLLER - gBS_OpenProtocol, // EFI_OPEN_PROTOCOL - gBS_CloseProtocol, // EFI_CLOSE_PROTOCOL - NULL, // EFI_OPEN_PROTOCOL_INFORMATION - NULL, // EFI_PROTOCOLS_PER_HANDLE - NULL, // EFI_LOCATE_HANDLE_BUFFER - gBS_LocateProtocol, // EFI_LOCATE_PROTOCOL - NULL, // EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES - NULL, // EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES - NULL, // EFI_CALCULATE_CRC32 - NULL, // EFI_COPY_MEM - NULL, // EFI_SET_MEM - gBS_CreateEventEx // EFI_CREATE_EVENT_EX + { 0, 0, 0, 0, 0 }, // EFI_TABLE_HEADER + NULL, // EFI_RAISE_TPL + NULL, // EFI_RESTORE_TPL + NULL, // EFI_ALLOCATE_PAGES + NULL, // EFI_FREE_PAGES + gBS_GetMemoryMap, // EFI_GET_MEMORY_MAP + NULL, // EFI_ALLOCATE_POOL + NULL, // EFI_FREE_POOL + gBS_CreateEvent, // EFI_CREATE_EVENT + NULL, // EFI_SET_TIMER + NULL, // EFI_WAIT_FOR_EVENT + NULL, // EFI_SIGNAL_EVENT + gBS_CloseEvent, // EFI_CLOSE_EVENT + NULL, // EFI_CHECK_EVENT + NULL, // EFI_INSTALL_PROTOCOL_INTERFACE + NULL, // EFI_REINSTALL_PROTOCOL_INTERFACE + NULL, // EFI_UNINSTALL_PROTOCOL_INTERFACE + gBS_HandleProtocol, // EFI_HANDLE_PROTOCOL + NULL, // VOID + NULL, // EFI_REGISTER_PROTOCOL_NOTIFY + NULL, // EFI_LOCATE_HANDLE + gBS_LocateDevicePath, // EFI_LOCATE_DEVICE_PATH + gBS_InstallConfigurationTable, // EFI_INSTALL_CONFIGURATION_TABLE + NULL, // EFI_IMAGE_LOAD + NULL, // EFI_IMAGE_START + NULL, // EFI_EXIT + NULL, // EFI_IMAGE_UNLOAD + NULL, // EFI_EXIT_BOOT_SERVICES + NULL, // EFI_GET_NEXT_MONOTONIC_COUNT + NULL, // EFI_STALL + NULL, // EFI_SET_WATCHDOG_TIMER + NULL, // EFI_CONNECT_CONTROLLER + NULL, // EFI_DISCONNECT_CONTROLLER + gBS_OpenProtocol, // EFI_OPEN_PROTOCOL + gBS_CloseProtocol, // EFI_CLOSE_PROTOCOL + NULL, // EFI_OPEN_PROTOCOL_INFORMATION + NULL, // EFI_PROTOCOLS_PER_HANDLE + NULL, // EFI_LOCATE_HANDLE_BUFFER + gBS_LocateProtocol, // EFI_LOCATE_PROTOCOL + NULL, // EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES + NULL, // EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES + NULL, // EFI_CALCULATE_CRC32 + NULL, // EFI_COPY_MEM + NULL, // EFI_SET_MEM + gBS_CreateEventEx // EFI_CREATE_EVENT_EX }; extern "C" { From 7668d8854f8e7033868a22e6714a69b879b5d18d Mon Sep 17 00:00:00 2001 From: Alexander Gryanko <xpahos@gmail.com> Date: Tue, 8 Jul 2025 14:36:33 +0300 Subject: [PATCH 190/406] SecurityPkg: added image verification test using DB hash The part of DxeImageVerificationHandler responsible for verifying the image location source has already been implemented. This commit implements tests for verifying images in cases where the image has no signature, but there is a hash record for this file in DB/DBX. Signed-off-by: Alexander Gryanko <xpahos@gmail.com> --- .../DxeImageVerificationLibGoogleTest.cpp | 557 +++++++++++++++++- .../DxeImageVerificationLibGoogleTest.h | 5 + .../GoogleTest/binfiles/README.md | 89 +++ .../GoogleTest/binfiles/UnsignedCOFF.h | 123 ++++ SecurityPkg/SecurityPkg.ci.yaml | 4 +- 5 files changed, 764 insertions(+), 14 deletions(-) create mode 100644 SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/README.md create mode 100644 SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/UnsignedCOFF.h diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.cpp b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.cpp index 325c3f5007..73569e033f 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.cpp +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.cpp @@ -5,22 +5,227 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include <Library/GoogleTestLib.h> +#include <GoogleTest/Library/MockDevicePathLib.h> +#include <GoogleTest/Library/MockUefiBootServicesTableLib.h> #include <GoogleTest/Library/MockUefiLib.h> #include <GoogleTest/Library/MockUefiRuntimeServicesTableLib.h> -#include <GoogleTest/Library/MockUefiBootServicesTableLib.h> -#include <GoogleTest/Library/MockDevicePathLib.h> +#include <Library/GoogleTestLib.h> extern "C" { - #include <Uefi.h> + #include "Library/MemoryAllocationLib.h" #include <Library/BaseLib.h> #include <Library/DebugLib.h> + #include <Uefi.h> #include "DxeImageVerificationLibGoogleTest.h" } ////////////////////////////////////////////////////////////////////////////// -class CheckImageTypeResult : public ::testing::Test { +void +PrepareCertList ( + UINTN Size, + UINTN BufferSize, + CONST EFI_GUID *SignatureType, + CONST UINT8 *Src, + EFI_SIGNATURE_LIST *Dst + ) +{ + Dst->SignatureListSize = (UINT32)BufferSize; + Dst->SignatureSize = (UINT32)(sizeof (EFI_SIGNATURE_DATA) - 1 + Size); + Dst->SignatureHeaderSize = 0; + CopyGuid (&Dst->SignatureType, SignatureType); + + EFI_SIGNATURE_DATA *Data = (EFI_SIGNATURE_DATA *)(Dst + 1); + + CopyGuid (&Data->SignatureOwner, &gEfiGlobalVariableGuid); + CopyMem (&Data->SignatureData[0], Src, Size); +} + +void +ExpectBeforeHashCheck ( + MockUefiBootServicesTableLib &BsMock, + MockDevicePathLib &DevicePathMock, + MockUefiRuntimeServicesTableLib &RtServicesMock + ) +{ + // Skip all checks that are called before hash verification. This also applies + // to signed binary files, as no additional mocks are needed before the + // signature verification starts. + + // Do not allocate on stack + static UINT8 SetupMode = SECURE_BOOT_MODE_ENABLE; + + EXPECT_CALL (BsMock, gBS_LocateDevicePath) + .Times (3) + .WillRepeatedly (testing::Return (EFI_NOT_FOUND)); + EXPECT_CALL (DevicePathMock, IsDevicePathEndType) + .WillOnce (testing::Return ((BOOLEAN)TRUE)); + + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_SECURE_BOOT_MODE_NAME), + BufferEq (&gEfiGlobalVariableGuid, sizeof (EFI_GUID)), + testing::NotNull (), + testing::Pointee (testing::Eq (sizeof (SetupMode))), + testing::NotNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (sizeof (SetupMode)), + SetArgBuffer<4> (&SetupMode, sizeof (SetupMode)), + testing::Return (EFI_SUCCESS) + ) + ); +} + +void +ExpectHashCheckSkip ( + MockUefiRuntimeServicesTableLib &RtServicesMock, + int n + ) +{ + // Here, the cycle and WillOnce are used because InSequence must be specified + // in the main function. When using InSequence, Times will retire. + for (int i = 0; i < n; i++) { + // Return ‘not found’ for DBx to exit from the first + // IsSignatureFoundInDatabase + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq ( + &gEfiImageSecurityDatabaseGuid, + sizeof (EFI_GUID) + ), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce (testing::Return (EFI_NOT_FOUND)); + + // IsFound is false, EFI_NOT_FOUND will proceed to the next algorithm + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE), + BufferEq ( + &gEfiImageSecurityDatabaseGuid, + sizeof (EFI_GUID) + ), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce (testing::Return (EFI_NOT_FOUND)); + } +} + +template <size_t N> +void +ExpectHashDBValue ( + MockUefiRuntimeServicesTableLib &RtServicesMock, + UINT8 (&CertListBuffer)[N], + UINTN BufferSize + ) +{ + // Return ‘not found’ for DBx to exit from the first + // IsSignatureFoundInDatabase + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce (testing::Return (EFI_NOT_FOUND)); + + // Second call of IsSignatureFoundInDatabase for DB + // Get Size + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (BufferSize), + testing::Return (EFI_BUFFER_TOO_SMALL) + ) + ); + + // Return hash + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)BufferSize)), + testing::NotNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (BufferSize), + SetArgBuffer<4> (&CertListBuffer[0], BufferSize), + testing::Return (EFI_SUCCESS) + ) + ); + + // Hash verification does't exit the loop upon the first match + EXPECT_CALL (RtServicesMock, gRT_GetVariable) + .Times (testing::AnyNumber ()) + .WillRepeatedly (testing::Return (EFI_NOT_FOUND)); +} + +EFI_STATUS +MockInstallConfigurationTable ( + EFI_GUID *Guid, + VOID *Table + ) +{ + if (Table != NULL) { + FreePool (Table); + } + + return EFI_SUCCESS; +} + +void +ExpectFailureJump ( + MockDevicePathLib &DevicePathMock, + MockUefiLib &UefiMock, + MockUefiBootServicesTableLib &BsMock + ) +{ + EXPECT_CALL (DevicePathMock, ConvertDevicePathToText) + .WillRepeatedly (testing::Return ((CHAR16 *)NULL)); + + EXPECT_CALL (UefiMock, EfiGetSystemConfigurationTable) + .WillRepeatedly (testing::Return (EFI_SUCCESS)); + + EXPECT_CALL (DevicePathMock, GetDevicePathSize) + .WillRepeatedly (testing::Return ((UINTN)0)); + + EXPECT_CALL (BsMock, gBS_InstallConfigurationTable) + .WillRepeatedly (testing::Invoke (MockInstallConfigurationTable)); +} + +////////////////////////////////////////////////////////////////////////////// +class CheckImageTypeResult : public ::testing::Test +{ public: EFI_DEVICE_PATH_PROTOCOL File; @@ -49,7 +254,13 @@ protected: TEST_F (CheckImageTypeResult, ImageTypeVerifySanity) { // Sanity check - Status = DxeImageVerificationHandler (AuthenticationStatus, NULL, FileBuffer, FileSize, BootPolicy); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + NULL, + FileBuffer, + FileSize, + BootPolicy + ); EXPECT_EQ (Status, EFI_INVALID_PARAMETER); } @@ -59,12 +270,18 @@ TEST_F (CheckImageTypeResult, ImageTypeVerifyImageFromFv) { EXPECT_CALL (BsMock, gBS_OpenProtocol) .WillRepeatedly (testing::Return (EFI_SUCCESS)); - Status = DxeImageVerificationHandler (AuthenticationStatus, &File, FileBuffer, FileSize, BootPolicy); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); EXPECT_EQ (Status, EFI_SUCCESS); } TEST_F (CheckImageTypeResult, ImageTypeVerifyImageFromOptionRom) { - auto TestFunc = [&](EFI_STATUS ExpectedStatus) { + auto TestFunc = [&] (EFI_STATUS ExpectedStatus) { EXPECT_CALL (BsMock, gBS_LocateDevicePath) .Times (3) .WillRepeatedly (testing::Return (EFI_NOT_FOUND)); @@ -77,7 +294,13 @@ TEST_F (CheckImageTypeResult, ImageTypeVerifyImageFromOptionRom) { EXPECT_CALL (DevicePathMock, DevicePathSubType) .WillOnce (testing::Return ((UINT8)MEDIA_RELATIVE_OFFSET_RANGE_DP)); - Status = DxeImageVerificationHandler (AuthenticationStatus, &File, FileBuffer, FileSize, BootPolicy); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); EXPECT_EQ (Status, ExpectedStatus); }; @@ -88,7 +311,7 @@ TEST_F (CheckImageTypeResult, ImageTypeVerifyImageFromOptionRom) { } TEST_F (CheckImageTypeResult, ImageTypeVerifyImageFromRemovableMedia) { - auto TestFunc = [&](EFI_STATUS ExpectedStatus) { + auto TestFunc = [&] (EFI_STATUS ExpectedStatus) { EXPECT_CALL (BsMock, gBS_LocateDevicePath) .Times (3) .WillRepeatedly (testing::Return (EFI_NOT_FOUND)); @@ -99,7 +322,13 @@ TEST_F (CheckImageTypeResult, ImageTypeVerifyImageFromRemovableMedia) { EXPECT_CALL (DevicePathMock, DevicePathSubType) .WillOnce (testing::Return ((UINT8)MSG_MAC_ADDR_DP)); - Status = DxeImageVerificationHandler (AuthenticationStatus, &File, FileBuffer, FileSize, BootPolicy); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); EXPECT_EQ (Status, ExpectedStatus); }; @@ -110,13 +339,19 @@ TEST_F (CheckImageTypeResult, ImageTypeVerifyImageFromRemovableMedia) { } TEST_F (CheckImageTypeResult, ImageTypeVerifyImageFromFixedMedia) { - auto TestFunc = [&](EFI_STATUS ExpectedStatus) { + auto TestFunc = [&] (EFI_STATUS ExpectedStatus) { EXPECT_CALL (BsMock, gBS_LocateDevicePath) .WillOnce (testing::Return (EFI_NOT_FOUND)) .WillOnce (testing::Return (EFI_NOT_FOUND)) .WillOnce (testing::Return (EFI_SUCCESS)); - Status = DxeImageVerificationHandler (AuthenticationStatus, &File, FileBuffer, FileSize, BootPolicy); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); EXPECT_EQ (Status, ExpectedStatus); }; @@ -126,6 +361,302 @@ TEST_F (CheckImageTypeResult, ImageTypeVerifyImageFromFixedMedia) { TestFunc (EFI_ACCESS_DENIED); } +////////////////////////////////////////////////////////////////////////////// +class CheckUnsignedImage : public ::testing::Test +{ +public: + EFI_DEVICE_PATH_PROTOCOL File; + +protected: + MockUefiRuntimeServicesTableLib RtServicesMock; + MockUefiBootServicesTableLib BsMock; + MockDevicePathLib DevicePathMock; + MockUefiLib UefiMock; + + EFI_STATUS Status; + + UINT32 AuthenticationStatus; + VOID *FileBuffer; + UINTN FileSize; + BOOLEAN BootPolicy; + + virtual void + SetUp ( + ) + { + AuthenticationStatus = 0; + FileBuffer = NULL; + FileSize = 0; + BootPolicy = FALSE; + } +}; + +TEST_F (CheckUnsignedImage, HashNormalFlow) { + constexpr UINTN Hash512Size = sizeof (images::UnsignedCOFFSha512); + constexpr UINTN Hash384Size = sizeof (images::UnsignedCOFFSha384); + constexpr UINTN Hash256Size = sizeof (images::UnsignedCOFFSha256); + constexpr UINTN Hash1Size = sizeof (images::UnsignedCOFFSha1); + + constexpr UINTN Hash512BufferSize = sizeof (EFI_SIGNATURE_LIST) + + sizeof (EFI_SIGNATURE_DATA) - 1 + + Hash512Size; + constexpr UINTN Hash384BufferSize = sizeof (EFI_SIGNATURE_LIST) + + sizeof (EFI_SIGNATURE_DATA) - 1 + + Hash384Size; + constexpr UINTN Hash256BufferSize = sizeof (EFI_SIGNATURE_LIST) + + sizeof (EFI_SIGNATURE_DATA) - 1 + + Hash256Size; + constexpr UINTN Hash1BufferSize = + sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + Hash1Size; + + UINT8 Hash512CertListBuffer[Hash512BufferSize] = { 0 }; + UINT8 Hash384CertListBuffer[Hash384BufferSize] = { 0 }; + UINT8 Hash256CertListBuffer[Hash256BufferSize] = { 0 }; + UINT8 Hash1CertListBuffer[Hash1BufferSize] = { 0 }; + + PrepareCertList ( + Hash512Size, + Hash512BufferSize, + &gEfiCertSha512Guid, + &images::UnsignedCOFFSha512[0], + (EFI_SIGNATURE_LIST *)&Hash512CertListBuffer + ); + + { + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match + // all calls. + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + ExpectHashDBValue<Hash512BufferSize> ( + RtServicesMock, + Hash512CertListBuffer, + Hash512BufferSize + ); + + FileBuffer = (VOID *)&images::UnsignedCOFF; + FileSize = sizeof (images::UnsignedCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_SUCCESS); + } + + PrepareCertList ( + Hash384Size, + Hash384BufferSize, + &gEfiCertSha384Guid, + &images::UnsignedCOFFSha384[0], + (EFI_SIGNATURE_LIST *)&Hash384CertListBuffer + ); + + { + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match + // all calls. + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + // Skip SHA512 check + ExpectHashCheckSkip (RtServicesMock, 1); + + // SHA384 check + ExpectHashDBValue<Hash384BufferSize> ( + RtServicesMock, + Hash384CertListBuffer, + Hash384BufferSize + ); + + FileBuffer = (VOID *)&images::UnsignedCOFF; + FileSize = sizeof (images::UnsignedCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_SUCCESS); + } + + PrepareCertList ( + Hash256Size, + Hash256BufferSize, + &gEfiCertSha256Guid, + &images::UnsignedCOFFSha256[0], + (EFI_SIGNATURE_LIST *)&Hash256CertListBuffer + ); + + { + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match + // all calls. + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + // Skip SHA512, SHA384 check + ExpectHashCheckSkip (RtServicesMock, 2); + + // SHA256 check + ExpectHashDBValue<Hash256BufferSize> ( + RtServicesMock, + Hash256CertListBuffer, + Hash256BufferSize + ); + + FileBuffer = (VOID *)&images::UnsignedCOFF; + FileSize = sizeof (images::UnsignedCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_SUCCESS); + } + + PrepareCertList ( + Hash1Size, + Hash1BufferSize, + &gEfiCertSha1Guid, + &images::UnsignedCOFFSha1[0], + (EFI_SIGNATURE_LIST *)&Hash1CertListBuffer + ); + + { + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match + // all calls. + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + // Skip SHA512, SHA384, SHA256 check + ExpectHashCheckSkip (RtServicesMock, 3); + + ExpectHashDBValue<Hash1BufferSize> ( + RtServicesMock, + Hash1CertListBuffer, + Hash1BufferSize + ); + + // Last check. No need to loop. + FileBuffer = (VOID *)&images::UnsignedCOFF; + FileSize = sizeof (images::UnsignedCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_SUCCESS); + } +} + +TEST_F (CheckUnsignedImage, HashNoDBRecods) { + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match + // all calls. + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + // Skip SHA512, SHA384, SHA256, SHA1 check + ExpectHashCheckSkip (RtServicesMock, 4); + + ExpectFailureJump (DevicePathMock, UefiMock, BsMock); + + // Last check. No need to loop. + FileBuffer = (VOID *)&images::UnsignedCOFF; + FileSize = sizeof (images::UnsignedCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_ACCESS_DENIED); +} + +TEST_F (CheckUnsignedImage, HashFoundDBx) { + constexpr UINTN Size = sizeof (images::UnsignedCOFFSha512); + constexpr UINTN BufferSize = + sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + Size; + + UINT8 CertListBuffer[BufferSize] = { 0 }; + + PrepareCertList ( + Size, + BufferSize, + &gEfiCertSha512Guid, + &images::UnsignedCOFFSha512[0], + (EFI_SIGNATURE_LIST *)&CertListBuffer + ); + + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match + // all calls. + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + // DBx routines + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (BufferSize), + testing::Return (EFI_BUFFER_TOO_SMALL) + ) + ); + + // Return hash + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)BufferSize)), + testing::NotNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (BufferSize), + SetArgBuffer<4> (&CertListBuffer[0], BufferSize), + testing::Return (EFI_SUCCESS) + ) + ); + + ExpectFailureJump (DevicePathMock, UefiMock, BsMock); + + // Last check. No need to loop. + FileBuffer = (VOID *)&images::UnsignedCOFF; + FileSize = sizeof (images::UnsignedCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_ACCESS_DENIED); +} + int main ( int argc, diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.h b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.h index 76f974c86a..0f9781c9b7 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.h +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.h @@ -7,6 +7,11 @@ #pragma once +#include <Library/BaseMemoryLib.h> +#include <Guid/ImageAuthentication.h> + +#include "binfiles/UnsignedCOFF.h" + /** Provide verification service for signed images, which include both signature validation and platform policy control. For signature types, both UEFI WIN_CERTIFICATE_UEFI_GUID and diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/README.md b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/README.md new file mode 100644 index 0000000000..9dd89ee286 --- /dev/null +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/README.md @@ -0,0 +1,89 @@ +### How to reproduce the binary file + +1. Apply the following patch. +2. Make adjustments if you are using non OvmfPkgIa32X64 file to build binary files. +3. Please use the following [guide](https://github.com/tianocore/tianocore.github.io/wiki/How-to-build-OVMF) for building OVMF. +4. Check the `Build` directory. + +``` +From c41a1a8c2cab120df9409685877e92f1ce755167 Mon Sep 17 00:00:00 2001 +From: Alexander Gryanko <xpahos@gmail.com> +Date: Tue, 23 Sep 2025 01:44:27 +0300 +Subject: [PATCH] Empty file example + +--- + OvmfPkg/Empty/Empty.c | 13 +++++++++++++ + OvmfPkg/Empty/Empty.inf | 28 ++++++++++++++++++++++++++++ + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + + 3 files changed, 42 insertions(+) + create mode 100644 OvmfPkg/Empty/Empty.c + create mode 100644 OvmfPkg/Empty/Empty.inf + +diff --git a/OvmfPkg/Empty/Empty.c b/OvmfPkg/Empty/Empty.c +new file mode 100644 +index 0000000000..3e448367bc +--- /dev/null ++++ b/OvmfPkg/Empty/Empty.c +@@ -0,0 +1,13 @@ ++#include <Uefi.h> ++#include <Library/UefiLib.h> ++#include <Library/UefiBootServicesTableLib.h> ++ ++EFI_STATUS ++EFIAPI ++EmptyPoint ( ++ IN EFI_HANDLE ImageHandle, ++ IN EFI_SYSTEM_TABLE *SystemTable ++) ++{ ++ return EFI_SUCCESS; ++} +diff --git a/OvmfPkg/Empty/Empty.inf b/OvmfPkg/Empty/Empty.inf +new file mode 100644 +index 0000000000..e98ab6ff56 +--- /dev/null ++++ b/OvmfPkg/Empty/Empty.inf +@@ -0,0 +1,28 @@ ++## @file ++# Enroll default PK, KEK, db, dbx. ++# ++# Copyright (C) 2014-2019, Red Hat, Inc. ++# ++# SPDX-License-Identifier: BSD-2-Clause-Patent ++## ++ ++[Defines] ++ INF_VERSION = 1.28 ++ BASE_NAME = EmptyFile ++ FILE_GUID = FF089297-5305-43B5-8FA8-08A10ACEB552 ++ MODULE_TYPE = UEFI_APPLICATION ++ VERSION_STRING = 0.1 ++ ENTRY_POINT = EmptyPoint ++ ++[Sources] ++ Empty.c ++ ++[Packages] ++ OvmfPkg/OvmfPkg.dec ++ MdePkg/MdePkg.dec ++ ++[LibraryClasses] ++ UefiApplicationEntryPoint ++ UefiBootServicesTableLib ++ UefiLib ++ +diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc +index 06fc031ab4..27e1b7f223 100644 +--- a/OvmfPkg/OvmfPkgIa32X64.dsc ++++ b/OvmfPkg/OvmfPkgIa32X64.dsc +@@ -969,6 +969,7 @@ + } + !endif + ++ OvmfPkg/Empty/Empty.inf + # + # TPM support + # +-- +2.39.5 (Apple Git-154) +``` diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/UnsignedCOFF.h b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/UnsignedCOFF.h new file mode 100644 index 0000000000..235ea03e7a --- /dev/null +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/UnsignedCOFF.h @@ -0,0 +1,123 @@ +/** @file + Unit tests for the implementation of DxeImageVerificationLib. + + Copyright (c) 2025, Yandex. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#pragma once + +namespace images { +const UINT8 UnsignedCOFF[992] = { + 0x4D, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x50, 0x45, 0x00, 0x00, 0x64, 0x86, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x22, 0x20, + 0x0B, 0x02, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x58, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x03, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x60, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2E, 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0xA3, 0x01, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x60, 0x2E, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0xC0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x4C, 0x89, 0xC0, + 0x48, 0x89, 0xCF, 0x48, 0x87, 0xD1, 0xF3, 0xAA, 0x48, 0x89, 0xD0, 0x5F, + 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0xCC, 0xCC, 0xCC, 0xCC, 0x56, 0x57, 0x48, 0x89, 0xD6, 0x48, 0x89, 0xCF, + 0x4E, 0x8D, 0x4C, 0x06, 0xFF, 0x48, 0x39, 0xFE, 0x48, 0x89, 0xF8, 0x73, + 0x05, 0x49, 0x39, 0xF9, 0x73, 0x10, 0x4C, 0x89, 0xC1, 0x49, 0x83, 0xE0, + 0x07, 0x48, 0xC1, 0xE9, 0x03, 0xF3, 0x48, 0xA5, 0xEB, 0x09, 0x4C, 0x89, + 0xCE, 0x4A, 0x8D, 0x7C, 0x07, 0xFF, 0xFD, 0x4C, 0x89, 0xC1, 0xF3, 0xA4, + 0xFC, 0x5F, 0x5E, 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, 0x57, 0x51, 0x48, 0x31, + 0xC0, 0x48, 0x89, 0xCF, 0x48, 0x89, 0xD1, 0x48, 0xC1, 0xE9, 0x03, 0x48, + 0x83, 0xE2, 0x07, 0xF3, 0x48, 0xAB, 0x89, 0xD1, 0xF3, 0xAA, 0x58, 0x5F, + 0xC3, 0xCC, 0xCC, 0xCC, 0x55, 0x48, 0x89, 0xE5, 0x41, 0x57, 0x41, 0x56, + 0x41, 0x55, 0x41, 0x54, 0x53, 0x56, 0x57, 0x49, 0x89, 0xCB, 0x49, 0x89, + 0xD4, 0x4D, 0x89, 0xC5, 0x4D, 0x89, 0xCE, 0x4C, 0x8B, 0x7C, 0x24, 0x68, + 0xB8, 0x00, 0x00, 0x00, 0x00, 0x48, 0x31, 0xC9, 0xB9, 0xCC, 0xFF, 0x00, + 0x00, 0x45, 0x31, 0xD2, 0x31, 0xDB, 0x31, 0xF6, 0x31, 0xFF, 0x31, 0xD2, + 0x31, 0xED, 0x45, 0x31, 0xC0, 0x45, 0x31, 0xC9, 0x66, 0x0F, 0x01, 0xCC, + 0x48, 0x85, 0xC0, 0x75, 0x10, 0x4C, 0x89, 0xD0, 0x4C, 0x8B, 0x4C, 0x24, + 0x70, 0x4D, 0x85, 0xC9, 0x74, 0x03, 0x4D, 0x89, 0x19, 0x31, 0xDB, 0x31, + 0xF6, 0x31, 0xFF, 0x31, 0xC9, 0x31, 0xD2, 0x45, 0x31, 0xC0, 0x45, 0x31, + 0xC9, 0x45, 0x31, 0xD2, 0x45, 0x31, 0xDB, 0x5F, 0x5E, 0x5B, 0x41, 0x5C, + 0x41, 0x5D, 0x41, 0x5E, 0x41, 0x5F, 0x5D, 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, + 0x55, 0x48, 0x89, 0xE5, 0x41, 0x57, 0x41, 0x56, 0x41, 0x55, 0x41, 0x54, + 0x53, 0x56, 0x57, 0x48, 0x89, 0xC8, 0x48, 0x89, 0xD1, 0x4C, 0x89, 0xC2, + 0x4D, 0x89, 0xC8, 0x66, 0x0F, 0x01, 0xCC, 0x48, 0x85, 0xC0, 0x75, 0x27, + 0x4C, 0x8B, 0x64, 0x24, 0x68, 0x4D, 0x85, 0xE4, 0x74, 0x1D, 0x49, 0x89, + 0x0C, 0x24, 0x49, 0x89, 0x54, 0x24, 0x08, 0x4D, 0x89, 0x44, 0x24, 0x10, + 0x4D, 0x89, 0x4C, 0x24, 0x18, 0x4D, 0x89, 0x54, 0x24, 0x20, 0x4D, 0x89, + 0x5C, 0x24, 0x28, 0x5F, 0x5E, 0x5B, 0x41, 0x5C, 0x41, 0x5D, 0x41, 0x5E, + 0x41, 0x5F, 0x5D, 0xC3, 0x48, 0x83, 0xEC, 0x28, 0x48, 0x89, 0xD1, 0xB0, + 0x87, 0x66, 0xBA, 0xFB, 0x03, 0xEE, 0x31, 0xC0, 0x66, 0xBA, 0xF9, 0x03, + 0xEE, 0xB0, 0x01, 0x66, 0xBA, 0xF8, 0x03, 0xEE, 0xB0, 0x07, 0x66, 0xBA, + 0xFB, 0x03, 0xEE, 0x48, 0x8B, 0x41, 0x60, 0x48, 0x89, 0x05, 0x4A, 0x00, + 0x00, 0x00, 0x48, 0x8D, 0x0D, 0x33, 0x00, 0x00, 0x00, 0x4C, 0x8D, 0x05, + 0x44, 0x00, 0x00, 0x00, 0x31, 0xD2, 0xFF, 0x90, 0x40, 0x01, 0x00, 0x00, + 0x31, 0xC0, 0x48, 0x83, 0xC4, 0x28, 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0x4E, 0xBE, 0x79, 0x03, 0x06, 0xD7, 0x7D, 0x43, 0xB0, 0x37, 0xED, 0xB8, + 0x2F, 0xB7, 0x72, 0xA4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +const UINT8 UnsignedCOFFSha1[20] = { + 0x81, 0x11, 0xc6, 0x9e, 0xb7, 0x34, 0x07, 0x22, 0x1a, 0x28, 0x84, 0xdc, + 0x18, 0x59, 0x05, 0xd0, 0xe3, 0x6c, 0x39, 0x1b +}; + +const UINT8 UnsignedCOFFSha256[32] = { + 0x88, 0x99, 0x8e, 0xb1, 0x3c, 0xa8, 0x1d, 0x26, 0x28, 0xd3, 0x0c, 0xab, + 0x66, 0xf6, 0x70, 0x09, 0x81, 0x87, 0x66, 0xaa, 0xa4, 0x70, 0x2b, 0xd4, + 0xee, 0xad, 0x8f, 0xdc, 0xa3, 0x8a, 0xb1, 0x89 +}; + +const UINT8 UnsignedCOFFSha384[48] = { + 0x77, 0x33, 0x4a, 0x0b, 0x0c, 0x61, 0xa5, 0x12, 0xde, 0xe4, 0x30, 0x2d, + 0x77, 0x1f, 0x59, 0x24, 0xbd, 0xd5, 0xc6, 0xb2, 0x0e, 0x31, 0x8e, 0xe5, + 0x51, 0xb9, 0x91, 0x01, 0xfd, 0xbd, 0x51, 0xd5, 0x16, 0xf2, 0x4d, 0x9c, + 0xd2, 0x48, 0x58, 0xc0, 0xc5, 0xd1, 0x95, 0xfb, 0x61, 0xca, 0x4d, 0xc0 +}; + +const UINT8 UnsignedCOFFSha512[64] = { + 0x41, 0x55, 0xee, 0x56, 0x1d, 0xbe, 0x29, 0x3a, 0x69, 0xda, 0xf8, 0xd3, + 0x68, 0xe5, 0x5c, 0xd7, 0xf7, 0xb6, 0x87, 0x2a, 0x26, 0xbd, 0xb0, 0x11, + 0x6f, 0x43, 0x3e, 0x0d, 0xd9, 0xa4, 0x2b, 0x9b, 0x02, 0x59, 0x28, 0x8e, + 0x08, 0x71, 0xc4, 0xde, 0x6a, 0xb4, 0xba, 0xf2, 0xb9, 0xe4, 0xf7, 0x83, + 0xc3, 0x8b, 0xa3, 0x68, 0x83, 0x26, 0x67, 0x7c, 0xf8, 0xf3, 0x91, 0xdf, + 0xfe, 0xd1, 0x2a, 0x59 +}; +} diff --git a/SecurityPkg/SecurityPkg.ci.yaml b/SecurityPkg/SecurityPkg.ci.yaml index 79ae94c0c6..d54903293c 100644 --- a/SecurityPkg/SecurityPkg.ci.yaml +++ b/SecurityPkg/SecurityPkg.ci.yaml @@ -31,7 +31,9 @@ "Library/Tpm2CommandLib/Tpm2NVStorage.c", "DeviceSecurity/SpdmLib/Include", "DeviceSecurity/SpdmLib/libspdm", - "DeviceSecurity/OsStub" + "DeviceSecurity/OsStub", + # Ignore test binary files in headers + "Library/DxeImageVerificationLib/GoogleTest" ] }, "CompilerPlugin": { From 1dc6b5e3dd6dfb9da2d1a8b6cc3d3ef851765eae Mon Sep 17 00:00:00 2001 From: Alexander Gryanko <xpahos@gmail.com> Date: Sat, 7 Mar 2026 01:45:57 +0300 Subject: [PATCH 191/406] SecurityPkg: added image verification tests for signed images Previous changes introduced tests for unsigned images verified by hash entries in DB/DBX. This commit adds tests covering verification of signed images, including certificate chain validation as well as cases where image hashes are checked against entries in DB/DBX. Signed-off-by: Alexander Gryanko <xpahos@gmail.com> --- .../DxeImageVerificationLibGoogleTest.cpp | 973 +++++++++++++++++- .../DxeImageVerificationLibGoogleTest.h | 86 +- .../GoogleTest/binfiles/CertGuidCOFF.h | 245 +++++ .../GoogleTest/binfiles/PkcsCOFF.h | 244 +++++ .../GoogleTest/binfiles/README.md | 9 + .../GoogleTest/binfiles/TestCert.pem | 19 + .../GoogleTest/binfiles/TestCertCOFF.h | 79 ++ .../GoogleTest/binfiles/TestKey.pem | 28 + 8 files changed, 1632 insertions(+), 51 deletions(-) create mode 100644 SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/CertGuidCOFF.h create mode 100644 SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/PkcsCOFF.h create mode 100644 SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestCert.pem create mode 100644 SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestCertCOFF.h create mode 100644 SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestKey.pem diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.cpp b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.cpp index 73569e033f..fa0928d7e7 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.cpp +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.cpp @@ -196,6 +196,7 @@ MockInstallConfigurationTable ( VOID *Table ) { + // LeakSanitizer workaround for AddImageExeInfo if (Table != NULL) { FreePool (Table); } @@ -223,6 +224,297 @@ ExpectFailureJump ( .WillRepeatedly (testing::Invoke (MockInstallConfigurationTable)); } +template <size_t N, size_t M> +void +ExpectForbiddenByDBxHash ( + MockUefiRuntimeServicesTableLib &RtServicesMock, + UINT8 (&CertListBuffer)[N], + UINTN BufferSize, + UINT8 (&HashListBuffer)[M], + UINTN HashBufferSize + ) +{ + // Signature DBx check - EFI_NOT_FOUND + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce (testing::Return (EFI_NOT_FOUND)); + + // IsAllowedByDb - DB size check + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (BufferSize), + testing::Return (EFI_BUFFER_TOO_SMALL) + ) + ); + + // IsAllowedByDb - DB data (X509 certs entries) + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)BufferSize)), + testing::NotNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (BufferSize), + SetArgBuffer<4> (&CertListBuffer[0], BufferSize), + testing::Return (EFI_SUCCESS) + ) + ); + + // IsAllowedByDb DBx check root cert revoked + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce (testing::Return (EFI_NOT_FOUND)); + + // IsSignatureFoundInDatabase prepare buffer + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (HashBufferSize), + testing::Return (EFI_BUFFER_TOO_SMALL) + ) + ); + + // IsSignatureFoundInDatabase prohibit hash + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)HashBufferSize)), + testing::NotNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (HashBufferSize), + SetArgBuffer<4> (&HashListBuffer[0], HashBufferSize), + testing::Return (EFI_SUCCESS) + ) + ); + + EXPECT_CALL (RtServicesMock, gRT_GetVariable) + .Times (testing::AnyNumber ()) + .WillRepeatedly (testing::Return (EFI_NOT_FOUND)); +} + +template <size_t N> +void +ExpectNoSignatureHashDBValue ( + MockUefiRuntimeServicesTableLib &RtServicesMock, + UINT8 (&HashCertListBuffer)[N], + UINTN HashBufferSize + ) +{ + // Signature DBx check - EFI_NOT_FOUND + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce (testing::Return (EFI_NOT_FOUND)); + + // IsAllowedByDb - DB size check + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE), + BufferEq ( + &gEfiImageSecurityDatabaseGuid, + sizeof (EFI_GUID) + ), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (HashBufferSize), + testing::Return (EFI_BUFFER_TOO_SMALL) + ) + ); + + // IsAllowedByDb - DB data (hash entries, no X509 certs) + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE), + BufferEq ( + &gEfiImageSecurityDatabaseGuid, + sizeof (EFI_GUID) + ), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)HashBufferSize)), + testing::NotNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (HashBufferSize), + SetArgBuffer<4> (&HashCertListBuffer[0], HashBufferSize), + testing::Return (EFI_SUCCESS) + ) + ); + + // IsAllowedByDb (DBX) - NOT FOUND + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce (testing::Return (EFI_NOT_FOUND)); + + // IsSignatureFoundInDatabase (DBX) - NOT FOUND + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce (testing::Return (EFI_NOT_FOUND)); + + // IsSignatureFoundInDatabase (DB) - size check + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (HashBufferSize), + testing::Return (EFI_BUFFER_TOO_SMALL) + ) + ); + + // IsSignatureFoundInDatabase (DB) - data (hash found) + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)HashBufferSize)), + testing::NotNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (HashBufferSize), + SetArgBuffer<4> (&HashCertListBuffer[0], HashBufferSize), + testing::Return (EFI_SUCCESS) + ) + ); + + EXPECT_CALL (RtServicesMock, gRT_GetVariable) + .Times (testing::AnyNumber ()) + .WillRepeatedly (testing::Return (EFI_NOT_FOUND)); +} + +template <size_t N> +void +ExpectCertForbiddenByDbx ( + MockUefiRuntimeServicesTableLib &RtServicesMock, + UINT8 (&CertListBuffer)[N], + UINTN BufferSize + ) +{ + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)0)), + testing::IsNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (BufferSize), + testing::Return (EFI_BUFFER_TOO_SMALL) + ) + ); + + EXPECT_CALL ( + RtServicesMock, + gRT_GetVariable ( + Char16StrEq (EFI_IMAGE_SECURITY_DATABASE1), + BufferEq (&gEfiImageSecurityDatabaseGuid, sizeof (EFI_GUID)), + testing::IsNull (), + testing::Pointee (testing::Eq ((UINTN)BufferSize)), + testing::NotNull () + ) + ) + .WillOnce ( + testing::DoAll ( + testing::SetArgPointee<3> (BufferSize), + SetArgBuffer<4> (&CertListBuffer[0], BufferSize), + testing::Return (EFI_SUCCESS) + ) + ); +} + ////////////////////////////////////////////////////////////////////////////// class CheckImageTypeResult : public ::testing::Test { @@ -423,8 +715,8 @@ TEST_F (CheckUnsignedImage, HashNormalFlow) { ); { - // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match - // all calls. + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will + // match all calls. testing::InSequence s; ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); @@ -456,8 +748,8 @@ TEST_F (CheckUnsignedImage, HashNormalFlow) { ); { - // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match - // all calls. + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will + // match all calls. testing::InSequence s; ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); @@ -493,8 +785,8 @@ TEST_F (CheckUnsignedImage, HashNormalFlow) { ); { - // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match - // all calls. + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will + // match all calls. testing::InSequence s; ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); @@ -530,8 +822,8 @@ TEST_F (CheckUnsignedImage, HashNormalFlow) { ); { - // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match - // all calls. + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will + // match all calls. testing::InSequence s; ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); @@ -560,8 +852,8 @@ TEST_F (CheckUnsignedImage, HashNormalFlow) { } TEST_F (CheckUnsignedImage, HashNoDBRecods) { - // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match - // all calls. + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will + // match all calls. testing::InSequence s; ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); @@ -599,8 +891,8 @@ TEST_F (CheckUnsignedImage, HashFoundDBx) { (EFI_SIGNATURE_LIST *)&CertListBuffer ); - // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will match - // all calls. + // Do not delete this. Otherwise, GetVariable from ExpectHashDBValue will + // match all calls. testing::InSequence s; ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); @@ -657,6 +949,663 @@ TEST_F (CheckUnsignedImage, HashFoundDBx) { EXPECT_EQ (Status, EFI_ACCESS_DENIED); } +////////////////////////////////////////////////////////////////////////////// +class CheckSignedImage : public ::testing::Test +{ +public: + EFI_DEVICE_PATH_PROTOCOL File; + +protected: + MockUefiRuntimeServicesTableLib RtServicesMock; + MockUefiBootServicesTableLib BsMock; + MockDevicePathLib DevicePathMock; + MockUefiLib UefiMock; + + EFI_STATUS Status; + + UINT32 AuthenticationStatus; + VOID *FileBuffer; + UINTN FileSize; + BOOLEAN BootPolicy; + + virtual void + SetUp ( + ) + { + AuthenticationStatus = 0; + FileBuffer = NULL; + FileSize = 0; + BootPolicy = FALSE; + } +}; + +TEST_F (CheckSignedImage, NormalFlowPkcs7) { + constexpr UINTN CertSize = sizeof (certs::TestCertDer); + constexpr UINTN BufferSize = + sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + CertSize; + + UINT8 CertListBuffer[BufferSize] = { 0 }; + + PrepareCertList ( + CertSize, + BufferSize, + &gEfiCertX509Guid, + &certs::TestCertDer[0], + (EFI_SIGNATURE_LIST *)&CertListBuffer + ); + + // Do not delete this. Otherwise, GetVariable from ExpectSignatureFoundInDb + // will match all calls. + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + ExpectHashDBValue<BufferSize> (RtServicesMock, CertListBuffer, BufferSize); + + FileBuffer = (VOID *)&images::PkcsCOFF; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_SUCCESS); +} + +TEST_F (CheckSignedImage, NormalFlowUefiGuid) { + constexpr UINTN CertSize = sizeof (certs::TestCertDer); + constexpr UINTN BufferSize = + sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + CertSize; + + UINT8 CertListBuffer[BufferSize] = { 0 }; + + PrepareCertList ( + CertSize, + BufferSize, + &gEfiCertX509Guid, + &certs::TestCertDer[0], + (EFI_SIGNATURE_LIST *)&CertListBuffer + ); + + // Do not delete this. Otherwise, GetVariable from ExpectSignatureFoundInDb + // will match all calls. + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + ExpectHashDBValue<BufferSize> (RtServicesMock, CertListBuffer, BufferSize); + + FileBuffer = (VOID *)&images::CertGuidCOFF; + FileSize = sizeof (images::CertGuidCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_SUCCESS); +} + +TEST_F (CheckSignedImage, NormalFlowTwoCerts) { + constexpr UINTN CertSize = sizeof (certs::TestCertDer); + constexpr UINTN SignatureDataSize = sizeof (EFI_GUID) + CertSize; + constexpr UINTN BufferSize = + sizeof (EFI_SIGNATURE_LIST) + (SignatureDataSize * 2); + + UINT8 CertListBuffer[BufferSize] = { 0 }; + + UINT8 InvalidCert[CertSize] = { 0 }; + + CopyMem (InvalidCert, certs::TestCertDer, CertSize); + InvalidCert[0] = 0xAA; + + EFI_SIGNATURE_LIST *CertList = (EFI_SIGNATURE_LIST *)&CertListBuffer; + + CertList->SignatureListSize = (UINT32)BufferSize; + CertList->SignatureHeaderSize = 0; + CertList->SignatureSize = (UINT32)SignatureDataSize; + CopyGuid (&CertList->SignatureType, &gEfiCertX509Guid); + + EFI_SIGNATURE_DATA *Cert1 = (EFI_SIGNATURE_DATA *)(CertList + 1); + + CopyGuid (&Cert1->SignatureOwner, &gEfiGlobalVariableGuid); + CopyMem (Cert1->SignatureData, InvalidCert, CertSize); + + EFI_SIGNATURE_DATA *Cert2 = (EFI_SIGNATURE_DATA *)((UINT8 *)Cert1 + SignatureDataSize); + + CopyGuid (&Cert2->SignatureOwner, &gEfiGlobalVariableGuid); + CopyMem (Cert2->SignatureData, certs::TestCertDer, CertSize); + + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + ExpectHashDBValue<BufferSize> (RtServicesMock, CertListBuffer, BufferSize); + + FileBuffer = (VOID *)&images::PkcsCOFF; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + + EXPECT_EQ (Status, EFI_SUCCESS); +} + +void +UpdatePeAuthCodeHash ( + UINT8 *PkcsCopy, + UINT32 HashType, + CONST UINT8 *HashValue, + UINTN HashSize + ) +{ + constexpr UINTN HashOidOffset = 0x408; // AuthData(0x3e8) + 32 + constexpr UINTN HashTagOffset = 0x470; // AuthData + 132 + constexpr UINTN HashValueOffset = 0x472; // AuthData + 134 + + static const UINT8 OidSha1[] = { 0x2B, 0x0E, 0x03, 0x02, 0x1A }; + static const UINT8 OidSha256[] = { 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 }; + static const UINT8 OidSha384[] = { 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 }; + static const UINT8 OidSha512[] = { 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 }; + + const UINT8 *Oid; + UINTN OidLength; + + switch (HashType) { + case HASHALG_SHA1: + Oid = OidSha1; + OidLength = sizeof (OidSha1); + break; + case HASHALG_SHA256: + Oid = OidSha256; + OidLength = sizeof (OidSha256); + break; + case HASHALG_SHA384: + Oid = OidSha384; + OidLength = sizeof (OidSha384); + break; + case HASHALG_SHA512: + Oid = OidSha512; + OidLength = sizeof (OidSha512); + break; + default: + return; + } + + CopyMem (PkcsCopy + HashOidOffset, Oid, OidLength); + PkcsCopy[HashTagOffset] = 0x04; // ASN.1 Octet(value 0x04) string + PkcsCopy[HashTagOffset + 1] = (UINT8)HashSize; + CopyMem (PkcsCopy + HashValueOffset, HashValue, HashSize); +} + +TEST_F (CheckSignedImage, NormalFlowPkcsNoCertHashAllowed) { + constexpr UINTN Hash512Size = sizeof (images::PkcsCOFFSha512); + constexpr UINTN Hash384Size = sizeof (images::PkcsCOFFSha384); + constexpr UINTN Hash256Size = sizeof (images::PkcsCOFFSha256); + constexpr UINTN Hash1Size = sizeof (images::PkcsCOFFSha1); + + constexpr UINTN Hash512BufferSize = sizeof (EFI_SIGNATURE_LIST) + + sizeof (EFI_SIGNATURE_DATA) - 1 + + Hash512Size; + constexpr UINTN Hash384BufferSize = sizeof (EFI_SIGNATURE_LIST) + + sizeof (EFI_SIGNATURE_DATA) - 1 + + Hash384Size; + constexpr UINTN Hash256BufferSize = sizeof (EFI_SIGNATURE_LIST) + + sizeof (EFI_SIGNATURE_DATA) - 1 + + Hash256Size; + constexpr UINTN Hash1BufferSize = + sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + Hash1Size; + + UINT8 Hash512CertListBuffer[Hash512BufferSize] = { 0 }; + UINT8 Hash384CertListBuffer[Hash384BufferSize] = { 0 }; + UINT8 Hash256CertListBuffer[Hash256BufferSize] = { 0 }; + UINT8 Hash1CertListBuffer[Hash1BufferSize] = { 0 }; + + UINT8 PkcsSha1Copy[sizeof (images::PkcsCOFF)]; + UINT8 PkcsSha256Copy[sizeof (images::PkcsCOFF)]; + UINT8 PkcsSha384Copy[sizeof (images::PkcsCOFF)]; + UINT8 PkcsSha512Copy[sizeof (images::PkcsCOFF)]; + + CopyMem (PkcsSha1Copy, images::PkcsCOFF, sizeof (images::PkcsCOFF)); + CopyMem (PkcsSha256Copy, images::PkcsCOFF, sizeof (images::PkcsCOFF)); + CopyMem (PkcsSha384Copy, images::PkcsCOFF, sizeof (images::PkcsCOFF)); + CopyMem (PkcsSha512Copy, images::PkcsCOFF, sizeof (images::PkcsCOFF)); + + UpdatePeAuthCodeHash (PkcsSha1Copy, HASHALG_SHA1, images::PkcsCOFFSha1, Hash1Size); + UpdatePeAuthCodeHash (PkcsSha256Copy, HASHALG_SHA256, images::PkcsCOFFSha256, Hash256Size); + UpdatePeAuthCodeHash (PkcsSha384Copy, HASHALG_SHA384, images::PkcsCOFFSha384, Hash384Size); + UpdatePeAuthCodeHash (PkcsSha512Copy, HASHALG_SHA512, images::PkcsCOFFSha512, Hash512Size); + + PrepareCertList ( + Hash512Size, + Hash512BufferSize, + &gEfiCertSha512Guid, + &images::PkcsCOFFSha512[0], + (EFI_SIGNATURE_LIST *)&Hash512CertListBuffer + ); + + { + testing::InSequence s; + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + ExpectNoSignatureHashDBValue<Hash512BufferSize> ( + RtServicesMock, + Hash512CertListBuffer, + Hash512BufferSize + ); + + FileBuffer = (VOID *)&PkcsSha512Copy; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_SUCCESS); + } + + PrepareCertList ( + Hash384Size, + Hash384BufferSize, + &gEfiCertSha384Guid, + &images::PkcsCOFFSha384[0], + (EFI_SIGNATURE_LIST *)&Hash384CertListBuffer + ); + + { + testing::InSequence s; + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + ExpectNoSignatureHashDBValue<Hash384BufferSize> ( + RtServicesMock, + Hash384CertListBuffer, + Hash384BufferSize + ); + + FileBuffer = (VOID *)&PkcsSha384Copy; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_SUCCESS); + } + + PrepareCertList ( + Hash256Size, + Hash256BufferSize, + &gEfiCertSha256Guid, + &images::PkcsCOFFSha256[0], + (EFI_SIGNATURE_LIST *)&Hash256CertListBuffer + ); + + { + testing::InSequence s; + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + ExpectNoSignatureHashDBValue<Hash256BufferSize> ( + RtServicesMock, + Hash256CertListBuffer, + Hash256BufferSize + ); + + FileBuffer = (VOID *)&PkcsSha256Copy; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_SUCCESS); + } + + PrepareCertList ( + Hash1Size, + Hash1BufferSize, + &gEfiCertSha1Guid, + &images::PkcsCOFFSha1[0], + (EFI_SIGNATURE_LIST *)&Hash1CertListBuffer + ); + + { + testing::InSequence s; + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + ExpectNoSignatureHashDBValue<Hash1BufferSize> ( + RtServicesMock, + Hash1CertListBuffer, + Hash1BufferSize + ); + + FileBuffer = (VOID *)&PkcsSha1Copy; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_SUCCESS); + } +} + +TEST_F (CheckSignedImage, ForbiddenByDbxPkcs7Sign) { + constexpr UINTN CertSize = sizeof (certs::TestCertDer); + constexpr UINTN BufferSize = + sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + CertSize; + + UINT8 CertListBuffer[BufferSize] = { 0 }; + + PrepareCertList ( + CertSize, + BufferSize, + &gEfiCertX509Guid, + &certs::TestCertDer[0], + (EFI_SIGNATURE_LIST *)&CertListBuffer + ); + + // Do not delete this. Otherwise, GetVariable from ExpectCertForbiddenByDbx + // will match all calls. + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + ExpectCertForbiddenByDbx<BufferSize> ( + RtServicesMock, + CertListBuffer, + BufferSize + ); + + ExpectFailureJump (DevicePathMock, UefiMock, BsMock); + + FileBuffer = (VOID *)&images::PkcsCOFF; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_ACCESS_DENIED); +} + +TEST_F (CheckSignedImage, ForbiddenByDbxUefiGuidSign) { + constexpr UINTN CertSize = sizeof (certs::TestCertDer); + constexpr UINTN BufferSize = + sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + CertSize; + + UINT8 CertListBuffer[BufferSize] = { 0 }; + + PrepareCertList ( + CertSize, + BufferSize, + &gEfiCertX509Guid, + &certs::TestCertDer[0], + (EFI_SIGNATURE_LIST *)&CertListBuffer + ); + + // Do not delete this. Otherwise, GetVariable from ExpectCertForbiddenByDbx + // will match all calls. + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + ExpectCertForbiddenByDbx<BufferSize> ( + RtServicesMock, + CertListBuffer, + BufferSize + ); + + ExpectFailureJump (DevicePathMock, UefiMock, BsMock); + + FileBuffer = (VOID *)&images::CertGuidCOFF; + FileSize = sizeof (images::CertGuidCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_ACCESS_DENIED); +} + +TEST_F (CheckSignedImage, NoCertPkcs7SignNoHash) { + // This test also covers the code path for when a perfectly valid signature is + // missing from the 'db' variable, resulting in the error: "Image is signed + // but signature is not allowed by DB and %s hash of image is not found in + // DB/DBX." + constexpr UINTN CertSize = sizeof (certs::TestCertDer); + constexpr UINTN BufferSize = + sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + CertSize; + + UINT8 InvalidCert[CertSize] = { 0 }; + + CopyMem (InvalidCert, images::PkcsCOFF, CertSize); + + InvalidCert[0] = 0xAA; + + UINT8 CertListBuffer[BufferSize] = { 0 }; + + PrepareCertList ( + CertSize, + BufferSize, + &gEfiCertX509Guid, + InvalidCert, + (EFI_SIGNATURE_LIST *)&CertListBuffer + ); + + testing::InSequence s; + + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + + ExpectHashDBValue<BufferSize> (RtServicesMock, CertListBuffer, BufferSize); + + ExpectFailureJump (DevicePathMock, UefiMock, BsMock); + + FileBuffer = (VOID *)&images::PkcsCOFF; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_ACCESS_DENIED); +} + +TEST_F (CheckSignedImage, ForbiddenByDBxHash) { + constexpr UINTN CertSize = sizeof (certs::TestCertDer); + constexpr UINTN Hash512Size = sizeof (images::PkcsCOFFSha512); + constexpr UINTN Hash384Size = sizeof (images::PkcsCOFFSha384); + constexpr UINTN Hash256Size = sizeof (images::PkcsCOFFSha256); + constexpr UINTN Hash1Size = sizeof (images::PkcsCOFFSha1); + + constexpr UINTN BufferSize = + sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + CertSize; + constexpr UINTN Hash512BufferSize = sizeof (EFI_SIGNATURE_LIST) + + sizeof (EFI_SIGNATURE_DATA) - 1 + + Hash512Size; + constexpr UINTN Hash384BufferSize = sizeof (EFI_SIGNATURE_LIST) + + sizeof (EFI_SIGNATURE_DATA) - 1 + + Hash384Size; + constexpr UINTN Hash256BufferSize = sizeof (EFI_SIGNATURE_LIST) + + sizeof (EFI_SIGNATURE_DATA) - 1 + + Hash256Size; + constexpr UINTN Hash1BufferSize = + sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + Hash1Size; + + UINT8 CertListBuffer[BufferSize] = { 0 }; + UINT8 Hash512CertListBuffer[Hash512BufferSize] = { 0 }; + UINT8 Hash384CertListBuffer[Hash384BufferSize] = { 0 }; + UINT8 Hash256CertListBuffer[Hash256BufferSize] = { 0 }; + UINT8 Hash1CertListBuffer[Hash1BufferSize] = { 0 }; + + UINT8 PkcsSha1Copy[sizeof (images::PkcsCOFF)]; + UINT8 PkcsSha256Copy[sizeof (images::PkcsCOFF)]; + UINT8 PkcsSha384Copy[sizeof (images::PkcsCOFF)]; + UINT8 PkcsSha512Copy[sizeof (images::PkcsCOFF)]; + + CopyMem (PkcsSha1Copy, images::PkcsCOFF, sizeof (images::PkcsCOFF)); + CopyMem (PkcsSha256Copy, images::PkcsCOFF, sizeof (images::PkcsCOFF)); + CopyMem (PkcsSha384Copy, images::PkcsCOFF, sizeof (images::PkcsCOFF)); + CopyMem (PkcsSha512Copy, images::PkcsCOFF, sizeof (images::PkcsCOFF)); + + UpdatePeAuthCodeHash (PkcsSha1Copy, HASHALG_SHA1, images::PkcsCOFFSha1, Hash1Size); + UpdatePeAuthCodeHash (PkcsSha256Copy, HASHALG_SHA256, images::PkcsCOFFSha256, Hash256Size); + UpdatePeAuthCodeHash (PkcsSha384Copy, HASHALG_SHA384, images::PkcsCOFFSha384, Hash384Size); + UpdatePeAuthCodeHash (PkcsSha512Copy, HASHALG_SHA512, images::PkcsCOFFSha512, Hash512Size); + + PrepareCertList ( + CertSize, + BufferSize, + &gEfiCertX509Guid, + certs::TestCertDer, + (EFI_SIGNATURE_LIST *)&CertListBuffer + ); + + PrepareCertList ( + Hash512Size, + Hash512BufferSize, + &gEfiCertSha512Guid, + &images::PkcsCOFFSha512[0], + (EFI_SIGNATURE_LIST *)&Hash512CertListBuffer + ); + + { + testing::InSequence s; + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + ExpectForbiddenByDBxHash<BufferSize, Hash512BufferSize> ( + RtServicesMock, + CertListBuffer, + BufferSize, + Hash512CertListBuffer, + Hash512BufferSize + ); + ExpectFailureJump (DevicePathMock, UefiMock, BsMock); + + FileBuffer = (VOID *)&PkcsSha512Copy; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_ACCESS_DENIED); + } + + PrepareCertList ( + Hash384Size, + Hash384BufferSize, + &gEfiCertSha384Guid, + &images::PkcsCOFFSha384[0], + (EFI_SIGNATURE_LIST *)&Hash384CertListBuffer + ); + + { + testing::InSequence s; + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + ExpectForbiddenByDBxHash<BufferSize, Hash384BufferSize> ( + RtServicesMock, + CertListBuffer, + BufferSize, + Hash384CertListBuffer, + Hash384BufferSize + ); + ExpectFailureJump (DevicePathMock, UefiMock, BsMock); + + FileBuffer = (VOID *)&PkcsSha384Copy; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_ACCESS_DENIED); + } + + PrepareCertList ( + Hash256Size, + Hash256BufferSize, + &gEfiCertSha256Guid, + &images::PkcsCOFFSha256[0], + (EFI_SIGNATURE_LIST *)&Hash256CertListBuffer + ); + + { + testing::InSequence s; + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + ExpectForbiddenByDBxHash<BufferSize, Hash256BufferSize> ( + RtServicesMock, + CertListBuffer, + BufferSize, + Hash256CertListBuffer, + Hash256BufferSize + ); + ExpectFailureJump (DevicePathMock, UefiMock, BsMock); + + FileBuffer = (VOID *)&PkcsSha256Copy; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_ACCESS_DENIED); + } + + PrepareCertList ( + Hash1Size, + Hash1BufferSize, + &gEfiCertSha1Guid, + &images::PkcsCOFFSha1[0], + (EFI_SIGNATURE_LIST *)&Hash1CertListBuffer + ); + + { + testing::InSequence s; + ExpectBeforeHashCheck (BsMock, DevicePathMock, RtServicesMock); + ExpectForbiddenByDBxHash<BufferSize, Hash1BufferSize> ( + RtServicesMock, + CertListBuffer, + BufferSize, + Hash1CertListBuffer, + Hash1BufferSize + ); + ExpectFailureJump (DevicePathMock, UefiMock, BsMock); + + FileBuffer = (VOID *)&PkcsSha1Copy; + FileSize = sizeof (images::PkcsCOFF); + Status = DxeImageVerificationHandler ( + AuthenticationStatus, + &File, + FileBuffer, + FileSize, + BootPolicy + ); + EXPECT_EQ (Status, EFI_ACCESS_DENIED); + } +} + int main ( int argc, diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.h b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.h index 0f9781c9b7..d16d150565 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.h +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/DxeImageVerificationLibGoogleTest.h @@ -1,77 +1,80 @@ /** @file Unit tests for the implementation of DxeImageVerificationLib. - Copyright (c) 2025, Yandex. All rights reserved. + Copyright (c) 2026, Yandex. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #pragma once -#include <Library/BaseMemoryLib.h> #include <Guid/ImageAuthentication.h> +#include <Library/BaseMemoryLib.h> +#include "binfiles/CertGuidCOFF.h" +#include "binfiles/PkcsCOFF.h" +#include "binfiles/TestCertCOFF.h" #include "binfiles/UnsignedCOFF.h" /** - Provide verification service for signed images, which include both signature validation - and platform policy control. For signature types, both UEFI WIN_CERTIFICATE_UEFI_GUID and - MSFT Authenticode type signatures are supported. + Provide verification service for signed images, which include both signature +validation and platform policy control. For signature types, both UEFI +WIN_CERTIFICATE_UEFI_GUID and MSFT Authenticode type signatures are supported. In this implementation, only verify external executables when in USER MODE. Executables from FV is bypass, so pass in AuthenticationStatus is ignored. The image verification policy is: If the image is signed, - At least one valid signature or at least one hash value of the image must match a record - in the security database "db", and no valid signature nor any hash value of the image may - be reflected in the security database "dbx". + At least one valid signature or at least one hash value of the image must +match a record in the security database "db", and no valid signature nor any +hash value of the image may be reflected in the security database "dbx". Otherwise, the image is not signed, - The hash value of the image must match a record in the security database "db", and - not be reflected in the security data base "dbx". + The hash value of the image must match a record in the security database +"db", and not be reflected in the security data base "dbx". Caution: This function may receive untrusted input. - PE/COFF image is external input, so this function will validate its data structure - within this image buffer before use. + PE/COFF image is external input, so this function will validate its data +structure within this image buffer before use. @param[in] AuthenticationStatus - This is the authentication status returned from the security - measurement services for the input file. - @param[in] File This is a pointer to the device path of the file that is - being dispatched. This will optionally be used for logging. + This is the authentication status returned from the +security measurement services for the input file. + @param[in] File This is a pointer to the device path of the file that +is being dispatched. This will optionally be used for logging. @param[in] FileBuffer File buffer matches the input file device path. - @param[in] FileSize Size of File buffer matches the input file device path. - @param[in] BootPolicy A boot policy that was used to call LoadImage() UEFI service. + @param[in] FileSize Size of File buffer matches the input file device +path. + @param[in] BootPolicy A boot policy that was used to call LoadImage() UEFI +service. @retval EFI_SUCCESS The file specified by DevicePath and non-NULL - FileBuffer did authenticate, and the platform policy dictates - that the DXE Foundation may use the file. - @retval EFI_SUCCESS The device path specified by NULL device path DevicePath - and non-NULL FileBuffer did authenticate, and the platform - policy dictates that the DXE Foundation may execute the image in - FileBuffer. - @retval EFI_SECURITY_VIOLATION The file specified by File did not authenticate, and - the platform policy dictates that File should be placed - in the untrusted state. The image has been added to the file - execution table. - @retval EFI_ACCESS_DENIED The file specified by File and FileBuffer did not - authenticate, and the platform policy dictates that the DXE - Foundation may not use File. The image has - been added to the file execution table. + FileBuffer did authenticate, and the platform +policy dictates that the DXE Foundation may use the file. + @retval EFI_SUCCESS The device path specified by NULL device path +DevicePath and non-NULL FileBuffer did authenticate, and the platform policy +dictates that the DXE Foundation may execute the image in FileBuffer. + @retval EFI_SECURITY_VIOLATION The file specified by File did not +authenticate, and the platform policy dictates that File should be placed in the +untrusted state. The image has been added to the file execution table. + @retval EFI_ACCESS_DENIED The file specified by File and FileBuffer did +not authenticate, and the platform policy dictates that the DXE Foundation may +not use File. The image has been added to the file execution table. **/ EFI_STATUS EFIAPI DxeImageVerificationHandler ( - IN UINT32 AuthenticationStatus, - IN CONST EFI_DEVICE_PATH_PROTOCOL *File OPTIONAL, - IN VOID *FileBuffer, - IN UINTN FileSize, - IN BOOLEAN BootPolicy + IN UINT32 AuthenticationStatus, + IN CONST EFI_DEVICE_PATH_PROTOCOL *File OPTIONAL, + IN VOID *FileBuffer, + IN UINTN FileSize, + IN BOOLEAN BootPolicy ); // -// The DxeImageVerificationLib.h file has dependencies on Pi/PiFirmwareVolume.h and Pi/PiFirmwareFile.h. -// These macros are copied from the header file to prevent PiPei.h from being included in HOST_APPLICATION. +// The DxeImageVerificationLib.h file has dependencies on Pi/PiFirmwareVolume.h +// and Pi/PiFirmwareFile.h. These macros are copied from the header file to +// prevent PiPei.h from being included in HOST_APPLICATION. // // @@ -79,3 +82,8 @@ DxeImageVerificationHandler ( // #define ALWAYS_EXECUTE 0x00000000 #define NEVER_EXECUTE 0x00000001 + +#define HASHALG_SHA1 0x00000000 +#define HASHALG_SHA256 0x00000002 +#define HASHALG_SHA384 0x00000003 +#define HASHALG_SHA512 0x00000004 diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/CertGuidCOFF.h b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/CertGuidCOFF.h new file mode 100644 index 0000000000..902c2e1fe9 --- /dev/null +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/CertGuidCOFF.h @@ -0,0 +1,245 @@ +/** @file + Unit tests for the implementation of DxeImageVerificationLib. + + Copyright (c) 2025, Yandex. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#pragma once + +namespace images { +const UINT8 CertGuidCOFF[2456] = { + 0x4D, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x50, 0x45, 0x00, 0x00, 0x64, 0x86, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x22, 0x20, + 0x0B, 0x02, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x58, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x03, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x45, 0x21, 0x00, 0x00, 0x0A, 0x00, 0x60, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xE0, 0x03, 0x00, 0x00, 0xB8, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2E, 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0xA3, 0x01, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x60, 0x2E, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0xC0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x4C, 0x89, 0xC0, + 0x48, 0x89, 0xCF, 0x48, 0x87, 0xD1, 0xF3, 0xAA, 0x48, 0x89, 0xD0, 0x5F, + 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0xCC, 0xCC, 0xCC, 0xCC, 0x56, 0x57, 0x48, 0x89, 0xD6, 0x48, 0x89, 0xCF, + 0x4E, 0x8D, 0x4C, 0x06, 0xFF, 0x48, 0x39, 0xFE, 0x48, 0x89, 0xF8, 0x73, + 0x05, 0x49, 0x39, 0xF9, 0x73, 0x10, 0x4C, 0x89, 0xC1, 0x49, 0x83, 0xE0, + 0x07, 0x48, 0xC1, 0xE9, 0x03, 0xF3, 0x48, 0xA5, 0xEB, 0x09, 0x4C, 0x89, + 0xCE, 0x4A, 0x8D, 0x7C, 0x07, 0xFF, 0xFD, 0x4C, 0x89, 0xC1, 0xF3, 0xA4, + 0xFC, 0x5F, 0x5E, 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, 0x57, 0x51, 0x48, 0x31, + 0xC0, 0x48, 0x89, 0xCF, 0x48, 0x89, 0xD1, 0x48, 0xC1, 0xE9, 0x03, 0x48, + 0x83, 0xE2, 0x07, 0xF3, 0x48, 0xAB, 0x89, 0xD1, 0xF3, 0xAA, 0x58, 0x5F, + 0xC3, 0xCC, 0xCC, 0xCC, 0x55, 0x48, 0x89, 0xE5, 0x41, 0x57, 0x41, 0x56, + 0x41, 0x55, 0x41, 0x54, 0x53, 0x56, 0x57, 0x49, 0x89, 0xCB, 0x49, 0x89, + 0xD4, 0x4D, 0x89, 0xC5, 0x4D, 0x89, 0xCE, 0x4C, 0x8B, 0x7C, 0x24, 0x68, + 0xB8, 0x00, 0x00, 0x00, 0x00, 0x48, 0x31, 0xC9, 0xB9, 0xCC, 0xFF, 0x00, + 0x00, 0x45, 0x31, 0xD2, 0x31, 0xDB, 0x31, 0xF6, 0x31, 0xFF, 0x31, 0xD2, + 0x31, 0xED, 0x45, 0x31, 0xC0, 0x45, 0x31, 0xC9, 0x66, 0x0F, 0x01, 0xCC, + 0x48, 0x85, 0xC0, 0x75, 0x10, 0x4C, 0x89, 0xD0, 0x4C, 0x8B, 0x4C, 0x24, + 0x70, 0x4D, 0x85, 0xC9, 0x74, 0x03, 0x4D, 0x89, 0x19, 0x31, 0xDB, 0x31, + 0xF6, 0x31, 0xFF, 0x31, 0xC9, 0x31, 0xD2, 0x45, 0x31, 0xC0, 0x45, 0x31, + 0xC9, 0x45, 0x31, 0xD2, 0x45, 0x31, 0xDB, 0x5F, 0x5E, 0x5B, 0x41, 0x5C, + 0x41, 0x5D, 0x41, 0x5E, 0x41, 0x5F, 0x5D, 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, + 0x55, 0x48, 0x89, 0xE5, 0x41, 0x57, 0x41, 0x56, 0x41, 0x55, 0x41, 0x54, + 0x53, 0x56, 0x57, 0x48, 0x89, 0xC8, 0x48, 0x89, 0xD1, 0x4C, 0x89, 0xC2, + 0x4D, 0x89, 0xC8, 0x66, 0x0F, 0x01, 0xCC, 0x48, 0x85, 0xC0, 0x75, 0x27, + 0x4C, 0x8B, 0x64, 0x24, 0x68, 0x4D, 0x85, 0xE4, 0x74, 0x1D, 0x49, 0x89, + 0x0C, 0x24, 0x49, 0x89, 0x54, 0x24, 0x08, 0x4D, 0x89, 0x44, 0x24, 0x10, + 0x4D, 0x89, 0x4C, 0x24, 0x18, 0x4D, 0x89, 0x54, 0x24, 0x20, 0x4D, 0x89, + 0x5C, 0x24, 0x28, 0x5F, 0x5E, 0x5B, 0x41, 0x5C, 0x41, 0x5D, 0x41, 0x5E, + 0x41, 0x5F, 0x5D, 0xC3, 0x48, 0x83, 0xEC, 0x28, 0x48, 0x89, 0xD1, 0xB0, + 0x87, 0x66, 0xBA, 0xFB, 0x03, 0xEE, 0x31, 0xC0, 0x66, 0xBA, 0xF9, 0x03, + 0xEE, 0xB0, 0x01, 0x66, 0xBA, 0xF8, 0x03, 0xEE, 0xB0, 0x07, 0x66, 0xBA, + 0xFB, 0x03, 0xEE, 0x48, 0x8B, 0x41, 0x60, 0x48, 0x89, 0x05, 0x4A, 0x00, + 0x00, 0x00, 0x48, 0x8D, 0x0D, 0x33, 0x00, 0x00, 0x00, 0x4C, 0x8D, 0x05, + 0x44, 0x00, 0x00, 0x00, 0x31, 0xD2, 0xFF, 0x90, 0x40, 0x01, 0x00, 0x00, + 0x31, 0xC0, 0x48, 0x83, 0xC4, 0x28, 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0x4E, 0xBE, 0x79, 0x03, 0x06, 0xD7, 0x7D, 0x43, 0xB0, 0x37, 0xED, 0xB8, + 0x2F, 0xB7, 0x72, 0xA4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8, 0x05, 0x00, 0x00, + 0x00, 0x02, 0xF1, 0x0E, 0x9D, 0xD2, 0xAF, 0x4A, 0xDF, 0x68, 0xEE, 0x49, + 0x8A, 0xA9, 0x34, 0x7D, 0x37, 0x56, 0x65, 0xA7, 0x30, 0x82, 0x05, 0x96, + 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02, 0xA0, + 0x82, 0x05, 0x87, 0x30, 0x82, 0x05, 0x83, 0x02, 0x01, 0x01, 0x31, 0x0F, + 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, + 0x01, 0x05, 0x00, 0x30, 0x79, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, + 0x82, 0x37, 0x02, 0x01, 0x04, 0xA0, 0x6B, 0x30, 0x69, 0x30, 0x34, 0x06, + 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x0F, 0x30, + 0x26, 0x03, 0x02, 0x07, 0x80, 0xA0, 0x20, 0xA2, 0x1E, 0x80, 0x1C, 0x00, + 0x3C, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x4F, 0x00, 0x62, 0x00, 0x73, 0x00, + 0x6F, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x74, 0x00, 0x65, 0x00, 0x3E, 0x00, + 0x3E, 0x00, 0x3E, 0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, + 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20, 0x88, 0x99, + 0x8E, 0xB1, 0x3C, 0xA8, 0x1D, 0x26, 0x28, 0xD3, 0x0C, 0xAB, 0x66, 0xF6, + 0x70, 0x09, 0x81, 0x87, 0x66, 0xAA, 0xA4, 0x70, 0x2B, 0xD4, 0xEE, 0xAD, + 0x8F, 0xDC, 0xA3, 0x8A, 0xB1, 0x89, 0xA0, 0x82, 0x03, 0x0B, 0x30, 0x82, + 0x03, 0x07, 0x30, 0x82, 0x01, 0xEF, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, + 0x14, 0x74, 0xE2, 0xFB, 0x91, 0xA1, 0x48, 0xDA, 0xB7, 0x96, 0x6B, 0x09, + 0xD6, 0x09, 0x5A, 0xD5, 0x51, 0xC9, 0x10, 0xD0, 0xBF, 0x30, 0x0D, 0x06, + 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, + 0x30, 0x13, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, + 0x08, 0x54, 0x65, 0x73, 0x74, 0x20, 0x4B, 0x65, 0x79, 0x30, 0x1E, 0x17, + 0x0D, 0x32, 0x36, 0x30, 0x32, 0x32, 0x32, 0x31, 0x36, 0x32, 0x37, 0x31, + 0x35, 0x5A, 0x17, 0x0D, 0x32, 0x37, 0x30, 0x32, 0x32, 0x32, 0x31, 0x36, + 0x32, 0x37, 0x31, 0x35, 0x5A, 0x30, 0x13, 0x31, 0x11, 0x30, 0x0F, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0C, 0x08, 0x54, 0x65, 0x73, 0x74, 0x20, 0x4B, + 0x65, 0x79, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, + 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, + 0x0F, 0x00, 0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xD1, + 0xE2, 0xF1, 0xAF, 0xE1, 0x76, 0x71, 0x06, 0x0D, 0xF1, 0x03, 0xC5, 0xDE, + 0x7A, 0x51, 0xE5, 0xEC, 0xF1, 0xD6, 0xF4, 0xDB, 0x28, 0x5A, 0x07, 0x99, + 0x6E, 0x5D, 0xC7, 0xFD, 0x6B, 0x71, 0x5C, 0x71, 0x5A, 0xD5, 0xFB, 0x17, + 0xA1, 0x94, 0xC1, 0x35, 0xF5, 0x95, 0xBB, 0x37, 0x30, 0x3E, 0x2B, 0x91, + 0x1C, 0x04, 0xBE, 0xC1, 0x3F, 0x90, 0xEC, 0x30, 0x77, 0xD8, 0x66, 0x24, + 0xCF, 0x61, 0x02, 0xC4, 0x03, 0xF9, 0x17, 0x7B, 0xCC, 0x7F, 0x75, 0xA1, + 0x7A, 0x20, 0x6B, 0x8B, 0x28, 0x39, 0xE6, 0xF9, 0x54, 0x7A, 0x70, 0x8D, + 0xE6, 0x48, 0xB4, 0x6C, 0x57, 0x0D, 0xEA, 0x95, 0x5A, 0xF0, 0xDA, 0xAD, + 0x72, 0x5F, 0xC6, 0xF1, 0xC7, 0xA8, 0x3C, 0xE1, 0xCA, 0xD5, 0xF5, 0x68, + 0xCF, 0xE4, 0x2A, 0xB1, 0x29, 0xE5, 0x04, 0xEC, 0xFF, 0x37, 0x10, 0x83, + 0x8E, 0xAD, 0x03, 0xE7, 0x0A, 0x92, 0xEE, 0xE7, 0x4A, 0x5A, 0x5F, 0xE2, + 0x12, 0x94, 0x91, 0x7A, 0x16, 0xB8, 0x80, 0x93, 0x5E, 0x48, 0xCE, 0xCF, + 0x64, 0x89, 0x36, 0xFD, 0xBC, 0x0E, 0xA1, 0xCF, 0xF4, 0x81, 0x3F, 0x71, + 0x0C, 0x26, 0x20, 0x63, 0xD2, 0x2A, 0x67, 0x70, 0x39, 0x81, 0x39, 0x11, + 0x4B, 0x3D, 0x9D, 0x9D, 0x7A, 0x66, 0x79, 0x43, 0x72, 0xCD, 0x39, 0xF4, + 0x91, 0x31, 0x47, 0x57, 0x2E, 0x89, 0x2D, 0xE2, 0x37, 0xE9, 0x50, 0x3C, + 0x38, 0x7F, 0x7D, 0x53, 0x28, 0x6A, 0xAA, 0x65, 0x9A, 0xB4, 0xDB, 0x61, + 0x1A, 0x8F, 0x8C, 0x42, 0x3B, 0xA3, 0x1E, 0xB7, 0xC7, 0x11, 0x81, 0x33, + 0xE6, 0xFB, 0x5E, 0x83, 0xC9, 0x4F, 0x7D, 0x9B, 0xAC, 0x20, 0x69, 0x2B, + 0xF7, 0x14, 0xBB, 0x7A, 0xF5, 0x76, 0x3B, 0xEC, 0xDD, 0x55, 0xFD, 0x98, + 0xAF, 0xEB, 0xFF, 0x2A, 0x36, 0xED, 0xB1, 0x63, 0x6D, 0x30, 0x7B, 0xDC, + 0x57, 0xC4, 0xC3, 0x02, 0x03, 0x01, 0x00, 0x01, 0xA3, 0x53, 0x30, 0x51, + 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x6F, + 0xDC, 0xE4, 0xE1, 0x4D, 0x01, 0x0C, 0x6E, 0x61, 0xBC, 0x14, 0x5F, 0x38, + 0x82, 0x70, 0xDA, 0x3D, 0x9E, 0x03, 0xEF, 0x30, 0x1F, 0x06, 0x03, 0x55, + 0x1D, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x6F, 0xDC, 0xE4, 0xE1, + 0x4D, 0x01, 0x0C, 0x6E, 0x61, 0xBC, 0x14, 0x5F, 0x38, 0x82, 0x70, 0xDA, + 0x3D, 0x9E, 0x03, 0xEF, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x01, + 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF, 0x30, 0x0D, 0x06, + 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, + 0x03, 0x82, 0x01, 0x01, 0x00, 0x8D, 0x39, 0x79, 0x05, 0x5E, 0x65, 0x0B, + 0xA5, 0xF7, 0x1F, 0x03, 0x78, 0x82, 0x73, 0xDB, 0x71, 0xE4, 0xC5, 0x2A, + 0x63, 0x14, 0xF7, 0x04, 0x04, 0x08, 0x29, 0xDB, 0xCB, 0x58, 0xF8, 0xAD, + 0xB9, 0x5E, 0x08, 0xD9, 0xBB, 0xD6, 0xAE, 0xC8, 0x46, 0xE4, 0xE0, 0x74, + 0xD1, 0x97, 0xFE, 0xD7, 0x63, 0x6E, 0xD2, 0x26, 0xB6, 0xC0, 0xD7, 0xB5, + 0x66, 0x80, 0xDC, 0xFF, 0x71, 0x22, 0xAE, 0x53, 0x84, 0x3C, 0x25, 0x20, + 0x60, 0x35, 0x3E, 0xEA, 0x6C, 0x59, 0x69, 0xE9, 0xA6, 0x93, 0xC4, 0xD9, + 0x1A, 0x3F, 0xC9, 0x6C, 0x79, 0xD1, 0xC0, 0x62, 0xC1, 0xF7, 0xBC, 0x8C, + 0x6C, 0x31, 0x60, 0x7F, 0xCB, 0x15, 0xE9, 0x31, 0xB4, 0x69, 0x64, 0x12, + 0xF5, 0x00, 0x8B, 0x19, 0x96, 0xEE, 0x1D, 0xB1, 0x7D, 0x2D, 0x9F, 0x50, + 0xA6, 0xC8, 0x33, 0x59, 0xA9, 0x38, 0x0C, 0xB1, 0x65, 0x25, 0xA2, 0x67, + 0x72, 0x9E, 0xC2, 0xDC, 0xAC, 0x8F, 0xEF, 0x29, 0x47, 0xF6, 0xF0, 0x91, + 0x5D, 0x0C, 0x65, 0x9A, 0x01, 0x19, 0x57, 0xB1, 0xE6, 0xCE, 0x7A, 0xB0, + 0xA6, 0x86, 0x39, 0x3F, 0x91, 0x37, 0x31, 0xB9, 0xDE, 0x82, 0x81, 0xA5, + 0x2F, 0xEB, 0xBE, 0xC6, 0x9E, 0xDD, 0x27, 0x77, 0x64, 0x7E, 0x94, 0x82, + 0x11, 0xE2, 0xBB, 0xD8, 0xD3, 0x78, 0xC8, 0x3A, 0x48, 0x76, 0x82, 0x8B, + 0x9E, 0x71, 0xDC, 0xA1, 0x95, 0x60, 0x6F, 0x6A, 0xAE, 0xF9, 0xB7, 0xEB, + 0xA2, 0x4B, 0x2C, 0xAB, 0x3C, 0xC2, 0x10, 0x28, 0xE2, 0x7D, 0x22, 0xC3, + 0xA1, 0x53, 0x0E, 0xD9, 0x0C, 0xBA, 0x25, 0xB8, 0x21, 0x6C, 0x7C, 0x0F, + 0xC3, 0x85, 0x6F, 0x1F, 0x9D, 0x85, 0x49, 0x37, 0xA8, 0x5C, 0xE5, 0xDE, + 0x88, 0x20, 0x60, 0xB7, 0x7F, 0xF2, 0x33, 0xEA, 0xDA, 0xDD, 0x62, 0x7B, + 0x02, 0x6B, 0x09, 0x08, 0xA3, 0x7C, 0x30, 0xA2, 0x0D, 0x31, 0x82, 0x01, + 0xE1, 0x30, 0x82, 0x01, 0xDD, 0x02, 0x01, 0x01, 0x30, 0x2B, 0x30, 0x13, + 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x08, 0x54, + 0x65, 0x73, 0x74, 0x20, 0x4B, 0x65, 0x79, 0x02, 0x14, 0x74, 0xE2, 0xFB, + 0x91, 0xA1, 0x48, 0xDA, 0xB7, 0x96, 0x6B, 0x09, 0xD6, 0x09, 0x5A, 0xD5, + 0x51, 0xC9, 0x10, 0xD0, 0xBF, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, + 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0xA0, 0x81, 0x88, 0x30, + 0x19, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x03, + 0x31, 0x0C, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, + 0x01, 0x04, 0x30, 0x1C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, + 0x01, 0x09, 0x05, 0x31, 0x0F, 0x17, 0x0D, 0x32, 0x36, 0x30, 0x32, 0x32, + 0x32, 0x31, 0x36, 0x33, 0x31, 0x34, 0x31, 0x5A, 0x30, 0x1C, 0x06, 0x0A, + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x0B, 0x31, 0x0E, + 0x30, 0x0C, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, + 0x01, 0x15, 0x30, 0x2F, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, + 0x01, 0x09, 0x04, 0x31, 0x22, 0x04, 0x20, 0x50, 0x2E, 0x24, 0xC3, 0x82, + 0x92, 0x4F, 0xCB, 0x0E, 0x2C, 0x92, 0xED, 0xCA, 0x95, 0x54, 0x95, 0xDB, + 0x05, 0xFE, 0x51, 0x03, 0x65, 0x5A, 0x3D, 0xEE, 0xAD, 0x1C, 0xC0, 0xAF, + 0x9D, 0xF4, 0xFB, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 0x01, 0x00, 0x3E, 0x33, + 0xA4, 0x75, 0x91, 0x7E, 0x2B, 0xD6, 0x73, 0x46, 0xBB, 0xF0, 0x36, 0xF0, + 0x80, 0x20, 0x3E, 0x75, 0x0B, 0x75, 0x49, 0x27, 0x72, 0x2E, 0x13, 0x9D, + 0xC6, 0xAA, 0xEC, 0xDC, 0xAC, 0x3A, 0x9A, 0x7A, 0x04, 0x7A, 0xA9, 0x0F, + 0x98, 0x21, 0xD0, 0x7E, 0x8B, 0x6B, 0x63, 0xF7, 0xF3, 0x5E, 0xFB, 0x5A, + 0xE0, 0x0B, 0xB8, 0xE2, 0x2A, 0x5F, 0x3C, 0xCD, 0x7E, 0xDC, 0x3A, 0xFA, + 0x57, 0x55, 0x95, 0xE8, 0x1D, 0x75, 0x14, 0x7A, 0x6B, 0x66, 0x6B, 0xBF, + 0xAD, 0xC9, 0x7C, 0xC5, 0xF6, 0x32, 0x21, 0x3A, 0xAD, 0x7E, 0x70, 0x88, + 0xED, 0x23, 0xC5, 0x5E, 0xC1, 0x60, 0xDA, 0x5B, 0xFB, 0x8F, 0x9E, 0xD8, + 0xD8, 0xBE, 0x72, 0x74, 0x10, 0x32, 0xA2, 0xE8, 0xBB, 0x19, 0xD7, 0xC2, + 0xCC, 0x55, 0x45, 0x58, 0xC3, 0x27, 0x47, 0x05, 0x82, 0x5B, 0x4E, 0x3B, + 0x54, 0x5E, 0xE2, 0xB8, 0x1B, 0xAB, 0xB5, 0xE6, 0xA3, 0x68, 0x41, 0x68, + 0x32, 0xDD, 0x7F, 0x4D, 0x3E, 0x80, 0xBA, 0x63, 0xCD, 0x70, 0xAA, 0x0A, + 0x1B, 0xAD, 0xD6, 0x46, 0xAF, 0xED, 0xB7, 0xA1, 0xFB, 0xC5, 0x6E, 0x85, + 0x42, 0xE0, 0x4E, 0x46, 0xB9, 0x12, 0xEF, 0xD1, 0xBA, 0x54, 0xDD, 0xE4, + 0x5B, 0xE0, 0xD0, 0x45, 0x81, 0xC0, 0x01, 0xFA, 0x31, 0x21, 0x06, 0xCD, + 0x7D, 0xBB, 0xD6, 0x7F, 0x87, 0x2B, 0x79, 0xD7, 0x2A, 0x62, 0xEC, 0x85, + 0xAF, 0x97, 0xAC, 0xED, 0xF9, 0x73, 0x26, 0xDC, 0x49, 0x88, 0xB7, 0x2A, + 0xFD, 0x47, 0x7B, 0xC9, 0xEB, 0xAC, 0x59, 0x7B, 0x8C, 0xCA, 0x53, 0x04, + 0x93, 0xE7, 0xEC, 0x52, 0xE8, 0xB7, 0xFD, 0x96, 0xAB, 0x4F, 0xA5, 0x6A, + 0x84, 0x59, 0xAD, 0x62, 0x86, 0x06, 0xBE, 0xA6, 0x68, 0x39, 0x07, 0x9B, + 0x8B, 0x49, 0xC1, 0x4E, 0xCD, 0xF1, 0x7B, 0x1E, 0x61, 0x63, 0x15, 0xFE, + 0x4E, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +const UINT8 CertGuidCOFFSha1[20] = { + 0x81, 0x11, 0xc6, 0x9e, 0xb7, 0x34, 0x07, 0x22, 0x1a, 0x28, 0x84, 0xdc, + 0x18, 0x59, 0x05, 0xd0, 0xe3, 0x6c, 0x39, 0x1b +}; + +const UINT8 CertGuidCOFFSha256[32] = { + 0x88, 0x99, 0x8e, 0xb1, 0x3c, 0xa8, 0x1d, 0x26, 0x28, 0xd3, 0x0c, 0xab, + 0x66, 0xf6, 0x70, 0x09, 0x81, 0x87, 0x66, 0xaa, 0xa4, 0x70, 0x2b, 0xd4, + 0xee, 0xad, 0x8f, 0xdc, 0xa3, 0x8a, 0xb1, 0x89 +}; + +const UINT8 CertGuidCOFFSha384[48] = { + 0x77, 0x33, 0x4a, 0x0b, 0x0c, 0x61, 0xa5, 0x12, 0xde, 0xe4, 0x30, 0x2d, + 0x77, 0x1f, 0x59, 0x24, 0xbd, 0xd5, 0xc6, 0xb2, 0x0e, 0x31, 0x8e, 0xe5, + 0x51, 0xb9, 0x91, 0x01, 0xfd, 0xbd, 0x51, 0xd5, 0x16, 0xf2, 0x4d, 0x9c, + 0xd2, 0x48, 0x58, 0xc0, 0xc5, 0xd1, 0x95, 0xfb, 0x61, 0xca, 0x4d, 0xc0 +}; + +const UINT8 CertGuidCOFFSha512[64] = { + 0x41, 0x55, 0xee, 0x56, 0x1d, 0xbe, 0x29, 0x3a, 0x69, 0xda, 0xf8, 0xd3, + 0x68, 0xe5, 0x5c, 0xd7, 0xf7, 0xb6, 0x87, 0x2a, 0x26, 0xbd, 0xb0, 0x11, + 0x6f, 0x43, 0x3e, 0x0d, 0xd9, 0xa4, 0x2b, 0x9b, 0x02, 0x59, 0x28, 0x8e, + 0x08, 0x71, 0xc4, 0xde, 0x6a, 0xb4, 0xba, 0xf2, 0xb9, 0xe4, 0xf7, 0x83, + 0xc3, 0x8b, 0xa3, 0x68, 0x83, 0x26, 0x67, 0x7c, 0xf8, 0xf3, 0x91, 0xdf, + 0xfe, 0xd1, 0x2a, 0x59 +}; +} diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/PkcsCOFF.h b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/PkcsCOFF.h new file mode 100644 index 0000000000..88298b5013 --- /dev/null +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/PkcsCOFF.h @@ -0,0 +1,244 @@ +/** @file + Unit tests for the implementation of DxeImageVerificationLib. + + Copyright (c) 2026, Yandex. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#pragma once + +namespace images { +const UINT8 PkcsCOFF[2440] = { + 0x4D, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x50, 0x45, 0x00, 0x00, 0x64, 0x86, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x22, 0x20, + 0x0B, 0x02, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x58, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x03, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x45, 0x21, 0x00, 0x00, 0x0A, 0x00, 0x60, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xE0, 0x03, 0x00, 0x00, 0xA8, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2E, 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0xA3, 0x01, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x60, 0x2E, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0xC0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x4C, 0x89, 0xC0, + 0x48, 0x89, 0xCF, 0x48, 0x87, 0xD1, 0xF3, 0xAA, 0x48, 0x89, 0xD0, 0x5F, + 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0xCC, 0xCC, 0xCC, 0xCC, 0x56, 0x57, 0x48, 0x89, 0xD6, 0x48, 0x89, 0xCF, + 0x4E, 0x8D, 0x4C, 0x06, 0xFF, 0x48, 0x39, 0xFE, 0x48, 0x89, 0xF8, 0x73, + 0x05, 0x49, 0x39, 0xF9, 0x73, 0x10, 0x4C, 0x89, 0xC1, 0x49, 0x83, 0xE0, + 0x07, 0x48, 0xC1, 0xE9, 0x03, 0xF3, 0x48, 0xA5, 0xEB, 0x09, 0x4C, 0x89, + 0xCE, 0x4A, 0x8D, 0x7C, 0x07, 0xFF, 0xFD, 0x4C, 0x89, 0xC1, 0xF3, 0xA4, + 0xFC, 0x5F, 0x5E, 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, 0x57, 0x51, 0x48, 0x31, + 0xC0, 0x48, 0x89, 0xCF, 0x48, 0x89, 0xD1, 0x48, 0xC1, 0xE9, 0x03, 0x48, + 0x83, 0xE2, 0x07, 0xF3, 0x48, 0xAB, 0x89, 0xD1, 0xF3, 0xAA, 0x58, 0x5F, + 0xC3, 0xCC, 0xCC, 0xCC, 0x55, 0x48, 0x89, 0xE5, 0x41, 0x57, 0x41, 0x56, + 0x41, 0x55, 0x41, 0x54, 0x53, 0x56, 0x57, 0x49, 0x89, 0xCB, 0x49, 0x89, + 0xD4, 0x4D, 0x89, 0xC5, 0x4D, 0x89, 0xCE, 0x4C, 0x8B, 0x7C, 0x24, 0x68, + 0xB8, 0x00, 0x00, 0x00, 0x00, 0x48, 0x31, 0xC9, 0xB9, 0xCC, 0xFF, 0x00, + 0x00, 0x45, 0x31, 0xD2, 0x31, 0xDB, 0x31, 0xF6, 0x31, 0xFF, 0x31, 0xD2, + 0x31, 0xED, 0x45, 0x31, 0xC0, 0x45, 0x31, 0xC9, 0x66, 0x0F, 0x01, 0xCC, + 0x48, 0x85, 0xC0, 0x75, 0x10, 0x4C, 0x89, 0xD0, 0x4C, 0x8B, 0x4C, 0x24, + 0x70, 0x4D, 0x85, 0xC9, 0x74, 0x03, 0x4D, 0x89, 0x19, 0x31, 0xDB, 0x31, + 0xF6, 0x31, 0xFF, 0x31, 0xC9, 0x31, 0xD2, 0x45, 0x31, 0xC0, 0x45, 0x31, + 0xC9, 0x45, 0x31, 0xD2, 0x45, 0x31, 0xDB, 0x5F, 0x5E, 0x5B, 0x41, 0x5C, + 0x41, 0x5D, 0x41, 0x5E, 0x41, 0x5F, 0x5D, 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, + 0x55, 0x48, 0x89, 0xE5, 0x41, 0x57, 0x41, 0x56, 0x41, 0x55, 0x41, 0x54, + 0x53, 0x56, 0x57, 0x48, 0x89, 0xC8, 0x48, 0x89, 0xD1, 0x4C, 0x89, 0xC2, + 0x4D, 0x89, 0xC8, 0x66, 0x0F, 0x01, 0xCC, 0x48, 0x85, 0xC0, 0x75, 0x27, + 0x4C, 0x8B, 0x64, 0x24, 0x68, 0x4D, 0x85, 0xE4, 0x74, 0x1D, 0x49, 0x89, + 0x0C, 0x24, 0x49, 0x89, 0x54, 0x24, 0x08, 0x4D, 0x89, 0x44, 0x24, 0x10, + 0x4D, 0x89, 0x4C, 0x24, 0x18, 0x4D, 0x89, 0x54, 0x24, 0x20, 0x4D, 0x89, + 0x5C, 0x24, 0x28, 0x5F, 0x5E, 0x5B, 0x41, 0x5C, 0x41, 0x5D, 0x41, 0x5E, + 0x41, 0x5F, 0x5D, 0xC3, 0x48, 0x83, 0xEC, 0x28, 0x48, 0x89, 0xD1, 0xB0, + 0x87, 0x66, 0xBA, 0xFB, 0x03, 0xEE, 0x31, 0xC0, 0x66, 0xBA, 0xF9, 0x03, + 0xEE, 0xB0, 0x01, 0x66, 0xBA, 0xF8, 0x03, 0xEE, 0xB0, 0x07, 0x66, 0xBA, + 0xFB, 0x03, 0xEE, 0x48, 0x8B, 0x41, 0x60, 0x48, 0x89, 0x05, 0x4A, 0x00, + 0x00, 0x00, 0x48, 0x8D, 0x0D, 0x33, 0x00, 0x00, 0x00, 0x4C, 0x8D, 0x05, + 0x44, 0x00, 0x00, 0x00, 0x31, 0xD2, 0xFF, 0x90, 0x40, 0x01, 0x00, 0x00, + 0x31, 0xC0, 0x48, 0x83, 0xC4, 0x28, 0xC3, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, + 0x4E, 0xBE, 0x79, 0x03, 0x06, 0xD7, 0x7D, 0x43, 0xB0, 0x37, 0xED, 0xB8, + 0x2F, 0xB7, 0x72, 0xA4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA8, 0x05, 0x00, 0x00, + 0x00, 0x02, 0x02, 0x00, 0x30, 0x82, 0x05, 0x96, 0x06, 0x09, 0x2A, 0x86, + 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02, 0xA0, 0x82, 0x05, 0x87, 0x30, + 0x82, 0x05, 0x83, 0x02, 0x01, 0x01, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x09, + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x30, + 0x79, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, + 0x04, 0xA0, 0x6B, 0x30, 0x69, 0x30, 0x34, 0x06, 0x0A, 0x2B, 0x06, 0x01, + 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x0F, 0x30, 0x26, 0x03, 0x02, 0x07, + 0x80, 0xA0, 0x20, 0xA2, 0x1E, 0x80, 0x1C, 0x00, 0x3C, 0x00, 0x3C, 0x00, + 0x3C, 0x00, 0x4F, 0x00, 0x62, 0x00, 0x73, 0x00, 0x6F, 0x00, 0x6C, 0x00, + 0x65, 0x00, 0x74, 0x00, 0x65, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x3E, 0x30, + 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, + 0x02, 0x01, 0x05, 0x00, 0x04, 0x20, 0x88, 0x99, 0x8E, 0xB1, 0x3C, 0xA8, + 0x1D, 0x26, 0x28, 0xD3, 0x0C, 0xAB, 0x66, 0xF6, 0x70, 0x09, 0x81, 0x87, + 0x66, 0xAA, 0xA4, 0x70, 0x2B, 0xD4, 0xEE, 0xAD, 0x8F, 0xDC, 0xA3, 0x8A, + 0xB1, 0x89, 0xA0, 0x82, 0x03, 0x0B, 0x30, 0x82, 0x03, 0x07, 0x30, 0x82, + 0x01, 0xEF, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x74, 0xE2, 0xFB, + 0x91, 0xA1, 0x48, 0xDA, 0xB7, 0x96, 0x6B, 0x09, 0xD6, 0x09, 0x5A, 0xD5, + 0x51, 0xC9, 0x10, 0xD0, 0xBF, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, + 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, 0x13, 0x31, 0x11, + 0x30, 0x0F, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x08, 0x54, 0x65, 0x73, + 0x74, 0x20, 0x4B, 0x65, 0x79, 0x30, 0x1E, 0x17, 0x0D, 0x32, 0x36, 0x30, + 0x32, 0x32, 0x32, 0x31, 0x36, 0x32, 0x37, 0x31, 0x35, 0x5A, 0x17, 0x0D, + 0x32, 0x37, 0x30, 0x32, 0x32, 0x32, 0x31, 0x36, 0x32, 0x37, 0x31, 0x35, + 0x5A, 0x30, 0x13, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x04, 0x03, + 0x0C, 0x08, 0x54, 0x65, 0x73, 0x74, 0x20, 0x4B, 0x65, 0x79, 0x30, 0x82, + 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, + 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82, + 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xD1, 0xE2, 0xF1, 0xAF, 0xE1, + 0x76, 0x71, 0x06, 0x0D, 0xF1, 0x03, 0xC5, 0xDE, 0x7A, 0x51, 0xE5, 0xEC, + 0xF1, 0xD6, 0xF4, 0xDB, 0x28, 0x5A, 0x07, 0x99, 0x6E, 0x5D, 0xC7, 0xFD, + 0x6B, 0x71, 0x5C, 0x71, 0x5A, 0xD5, 0xFB, 0x17, 0xA1, 0x94, 0xC1, 0x35, + 0xF5, 0x95, 0xBB, 0x37, 0x30, 0x3E, 0x2B, 0x91, 0x1C, 0x04, 0xBE, 0xC1, + 0x3F, 0x90, 0xEC, 0x30, 0x77, 0xD8, 0x66, 0x24, 0xCF, 0x61, 0x02, 0xC4, + 0x03, 0xF9, 0x17, 0x7B, 0xCC, 0x7F, 0x75, 0xA1, 0x7A, 0x20, 0x6B, 0x8B, + 0x28, 0x39, 0xE6, 0xF9, 0x54, 0x7A, 0x70, 0x8D, 0xE6, 0x48, 0xB4, 0x6C, + 0x57, 0x0D, 0xEA, 0x95, 0x5A, 0xF0, 0xDA, 0xAD, 0x72, 0x5F, 0xC6, 0xF1, + 0xC7, 0xA8, 0x3C, 0xE1, 0xCA, 0xD5, 0xF5, 0x68, 0xCF, 0xE4, 0x2A, 0xB1, + 0x29, 0xE5, 0x04, 0xEC, 0xFF, 0x37, 0x10, 0x83, 0x8E, 0xAD, 0x03, 0xE7, + 0x0A, 0x92, 0xEE, 0xE7, 0x4A, 0x5A, 0x5F, 0xE2, 0x12, 0x94, 0x91, 0x7A, + 0x16, 0xB8, 0x80, 0x93, 0x5E, 0x48, 0xCE, 0xCF, 0x64, 0x89, 0x36, 0xFD, + 0xBC, 0x0E, 0xA1, 0xCF, 0xF4, 0x81, 0x3F, 0x71, 0x0C, 0x26, 0x20, 0x63, + 0xD2, 0x2A, 0x67, 0x70, 0x39, 0x81, 0x39, 0x11, 0x4B, 0x3D, 0x9D, 0x9D, + 0x7A, 0x66, 0x79, 0x43, 0x72, 0xCD, 0x39, 0xF4, 0x91, 0x31, 0x47, 0x57, + 0x2E, 0x89, 0x2D, 0xE2, 0x37, 0xE9, 0x50, 0x3C, 0x38, 0x7F, 0x7D, 0x53, + 0x28, 0x6A, 0xAA, 0x65, 0x9A, 0xB4, 0xDB, 0x61, 0x1A, 0x8F, 0x8C, 0x42, + 0x3B, 0xA3, 0x1E, 0xB7, 0xC7, 0x11, 0x81, 0x33, 0xE6, 0xFB, 0x5E, 0x83, + 0xC9, 0x4F, 0x7D, 0x9B, 0xAC, 0x20, 0x69, 0x2B, 0xF7, 0x14, 0xBB, 0x7A, + 0xF5, 0x76, 0x3B, 0xEC, 0xDD, 0x55, 0xFD, 0x98, 0xAF, 0xEB, 0xFF, 0x2A, + 0x36, 0xED, 0xB1, 0x63, 0x6D, 0x30, 0x7B, 0xDC, 0x57, 0xC4, 0xC3, 0x02, + 0x03, 0x01, 0x00, 0x01, 0xA3, 0x53, 0x30, 0x51, 0x30, 0x1D, 0x06, 0x03, + 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x6F, 0xDC, 0xE4, 0xE1, 0x4D, + 0x01, 0x0C, 0x6E, 0x61, 0xBC, 0x14, 0x5F, 0x38, 0x82, 0x70, 0xDA, 0x3D, + 0x9E, 0x03, 0xEF, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x1D, 0x23, 0x04, 0x18, + 0x30, 0x16, 0x80, 0x14, 0x6F, 0xDC, 0xE4, 0xE1, 0x4D, 0x01, 0x0C, 0x6E, + 0x61, 0xBC, 0x14, 0x5F, 0x38, 0x82, 0x70, 0xDA, 0x3D, 0x9E, 0x03, 0xEF, + 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, + 0x30, 0x03, 0x01, 0x01, 0xFF, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, + 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, + 0x00, 0x8D, 0x39, 0x79, 0x05, 0x5E, 0x65, 0x0B, 0xA5, 0xF7, 0x1F, 0x03, + 0x78, 0x82, 0x73, 0xDB, 0x71, 0xE4, 0xC5, 0x2A, 0x63, 0x14, 0xF7, 0x04, + 0x04, 0x08, 0x29, 0xDB, 0xCB, 0x58, 0xF8, 0xAD, 0xB9, 0x5E, 0x08, 0xD9, + 0xBB, 0xD6, 0xAE, 0xC8, 0x46, 0xE4, 0xE0, 0x74, 0xD1, 0x97, 0xFE, 0xD7, + 0x63, 0x6E, 0xD2, 0x26, 0xB6, 0xC0, 0xD7, 0xB5, 0x66, 0x80, 0xDC, 0xFF, + 0x71, 0x22, 0xAE, 0x53, 0x84, 0x3C, 0x25, 0x20, 0x60, 0x35, 0x3E, 0xEA, + 0x6C, 0x59, 0x69, 0xE9, 0xA6, 0x93, 0xC4, 0xD9, 0x1A, 0x3F, 0xC9, 0x6C, + 0x79, 0xD1, 0xC0, 0x62, 0xC1, 0xF7, 0xBC, 0x8C, 0x6C, 0x31, 0x60, 0x7F, + 0xCB, 0x15, 0xE9, 0x31, 0xB4, 0x69, 0x64, 0x12, 0xF5, 0x00, 0x8B, 0x19, + 0x96, 0xEE, 0x1D, 0xB1, 0x7D, 0x2D, 0x9F, 0x50, 0xA6, 0xC8, 0x33, 0x59, + 0xA9, 0x38, 0x0C, 0xB1, 0x65, 0x25, 0xA2, 0x67, 0x72, 0x9E, 0xC2, 0xDC, + 0xAC, 0x8F, 0xEF, 0x29, 0x47, 0xF6, 0xF0, 0x91, 0x5D, 0x0C, 0x65, 0x9A, + 0x01, 0x19, 0x57, 0xB1, 0xE6, 0xCE, 0x7A, 0xB0, 0xA6, 0x86, 0x39, 0x3F, + 0x91, 0x37, 0x31, 0xB9, 0xDE, 0x82, 0x81, 0xA5, 0x2F, 0xEB, 0xBE, 0xC6, + 0x9E, 0xDD, 0x27, 0x77, 0x64, 0x7E, 0x94, 0x82, 0x11, 0xE2, 0xBB, 0xD8, + 0xD3, 0x78, 0xC8, 0x3A, 0x48, 0x76, 0x82, 0x8B, 0x9E, 0x71, 0xDC, 0xA1, + 0x95, 0x60, 0x6F, 0x6A, 0xAE, 0xF9, 0xB7, 0xEB, 0xA2, 0x4B, 0x2C, 0xAB, + 0x3C, 0xC2, 0x10, 0x28, 0xE2, 0x7D, 0x22, 0xC3, 0xA1, 0x53, 0x0E, 0xD9, + 0x0C, 0xBA, 0x25, 0xB8, 0x21, 0x6C, 0x7C, 0x0F, 0xC3, 0x85, 0x6F, 0x1F, + 0x9D, 0x85, 0x49, 0x37, 0xA8, 0x5C, 0xE5, 0xDE, 0x88, 0x20, 0x60, 0xB7, + 0x7F, 0xF2, 0x33, 0xEA, 0xDA, 0xDD, 0x62, 0x7B, 0x02, 0x6B, 0x09, 0x08, + 0xA3, 0x7C, 0x30, 0xA2, 0x0D, 0x31, 0x82, 0x01, 0xE1, 0x30, 0x82, 0x01, + 0xDD, 0x02, 0x01, 0x01, 0x30, 0x2B, 0x30, 0x13, 0x31, 0x11, 0x30, 0x0F, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x08, 0x54, 0x65, 0x73, 0x74, 0x20, + 0x4B, 0x65, 0x79, 0x02, 0x14, 0x74, 0xE2, 0xFB, 0x91, 0xA1, 0x48, 0xDA, + 0xB7, 0x96, 0x6B, 0x09, 0xD6, 0x09, 0x5A, 0xD5, 0x51, 0xC9, 0x10, 0xD0, + 0xBF, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, + 0x02, 0x01, 0x05, 0x00, 0xA0, 0x81, 0x88, 0x30, 0x19, 0x06, 0x09, 0x2A, + 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x03, 0x31, 0x0C, 0x06, 0x0A, + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04, 0x30, 0x1C, + 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x05, 0x31, + 0x0F, 0x17, 0x0D, 0x32, 0x36, 0x30, 0x32, 0x32, 0x32, 0x31, 0x36, 0x33, + 0x31, 0x34, 0x31, 0x5A, 0x30, 0x1C, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, + 0x01, 0x82, 0x37, 0x02, 0x01, 0x0B, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x0A, + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x15, 0x30, 0x2F, + 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x04, 0x31, + 0x22, 0x04, 0x20, 0x50, 0x2E, 0x24, 0xC3, 0x82, 0x92, 0x4F, 0xCB, 0x0E, + 0x2C, 0x92, 0xED, 0xCA, 0x95, 0x54, 0x95, 0xDB, 0x05, 0xFE, 0x51, 0x03, + 0x65, 0x5A, 0x3D, 0xEE, 0xAD, 0x1C, 0xC0, 0xAF, 0x9D, 0xF4, 0xFB, 0x30, + 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, + 0x05, 0x00, 0x04, 0x82, 0x01, 0x00, 0x3E, 0x33, 0xA4, 0x75, 0x91, 0x7E, + 0x2B, 0xD6, 0x73, 0x46, 0xBB, 0xF0, 0x36, 0xF0, 0x80, 0x20, 0x3E, 0x75, + 0x0B, 0x75, 0x49, 0x27, 0x72, 0x2E, 0x13, 0x9D, 0xC6, 0xAA, 0xEC, 0xDC, + 0xAC, 0x3A, 0x9A, 0x7A, 0x04, 0x7A, 0xA9, 0x0F, 0x98, 0x21, 0xD0, 0x7E, + 0x8B, 0x6B, 0x63, 0xF7, 0xF3, 0x5E, 0xFB, 0x5A, 0xE0, 0x0B, 0xB8, 0xE2, + 0x2A, 0x5F, 0x3C, 0xCD, 0x7E, 0xDC, 0x3A, 0xFA, 0x57, 0x55, 0x95, 0xE8, + 0x1D, 0x75, 0x14, 0x7A, 0x6B, 0x66, 0x6B, 0xBF, 0xAD, 0xC9, 0x7C, 0xC5, + 0xF6, 0x32, 0x21, 0x3A, 0xAD, 0x7E, 0x70, 0x88, 0xED, 0x23, 0xC5, 0x5E, + 0xC1, 0x60, 0xDA, 0x5B, 0xFB, 0x8F, 0x9E, 0xD8, 0xD8, 0xBE, 0x72, 0x74, + 0x10, 0x32, 0xA2, 0xE8, 0xBB, 0x19, 0xD7, 0xC2, 0xCC, 0x55, 0x45, 0x58, + 0xC3, 0x27, 0x47, 0x05, 0x82, 0x5B, 0x4E, 0x3B, 0x54, 0x5E, 0xE2, 0xB8, + 0x1B, 0xAB, 0xB5, 0xE6, 0xA3, 0x68, 0x41, 0x68, 0x32, 0xDD, 0x7F, 0x4D, + 0x3E, 0x80, 0xBA, 0x63, 0xCD, 0x70, 0xAA, 0x0A, 0x1B, 0xAD, 0xD6, 0x46, + 0xAF, 0xED, 0xB7, 0xA1, 0xFB, 0xC5, 0x6E, 0x85, 0x42, 0xE0, 0x4E, 0x46, + 0xB9, 0x12, 0xEF, 0xD1, 0xBA, 0x54, 0xDD, 0xE4, 0x5B, 0xE0, 0xD0, 0x45, + 0x81, 0xC0, 0x01, 0xFA, 0x31, 0x21, 0x06, 0xCD, 0x7D, 0xBB, 0xD6, 0x7F, + 0x87, 0x2B, 0x79, 0xD7, 0x2A, 0x62, 0xEC, 0x85, 0xAF, 0x97, 0xAC, 0xED, + 0xF9, 0x73, 0x26, 0xDC, 0x49, 0x88, 0xB7, 0x2A, 0xFD, 0x47, 0x7B, 0xC9, + 0xEB, 0xAC, 0x59, 0x7B, 0x8C, 0xCA, 0x53, 0x04, 0x93, 0xE7, 0xEC, 0x52, + 0xE8, 0xB7, 0xFD, 0x96, 0xAB, 0x4F, 0xA5, 0x6A, 0x84, 0x59, 0xAD, 0x62, + 0x86, 0x06, 0xBE, 0xA6, 0x68, 0x39, 0x07, 0x9B, 0x8B, 0x49, 0xC1, 0x4E, + 0xCD, 0xF1, 0x7B, 0x1E, 0x61, 0x63, 0x15, 0xFE, 0x4E, 0xFE, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; + +const UINT8 PkcsCOFFSha1[20] = { + 0x81, 0x11, 0xc6, 0x9e, 0xb7, 0x34, 0x07, 0x22, 0x1a, 0x28, 0x84, 0xdc, + 0x18, 0x59, 0x05, 0xd0, 0xe3, 0x6c, 0x39, 0x1b +}; + +const UINT8 PkcsCOFFSha256[32] = { + 0x88, 0x99, 0x8e, 0xb1, 0x3c, 0xa8, 0x1d, 0x26, 0x28, 0xd3, 0x0c, 0xab, + 0x66, 0xf6, 0x70, 0x09, 0x81, 0x87, 0x66, 0xaa, 0xa4, 0x70, 0x2b, 0xd4, + 0xee, 0xad, 0x8f, 0xdc, 0xa3, 0x8a, 0xb1, 0x89 +}; + +const UINT8 PkcsCOFFSha384[48] = { + 0x77, 0x33, 0x4a, 0x0b, 0x0c, 0x61, 0xa5, 0x12, 0xde, 0xe4, 0x30, 0x2d, + 0x77, 0x1f, 0x59, 0x24, 0xbd, 0xd5, 0xc6, 0xb2, 0x0e, 0x31, 0x8e, 0xe5, + 0x51, 0xb9, 0x91, 0x01, 0xfd, 0xbd, 0x51, 0xd5, 0x16, 0xf2, 0x4d, 0x9c, + 0xd2, 0x48, 0x58, 0xc0, 0xc5, 0xd1, 0x95, 0xfb, 0x61, 0xca, 0x4d, 0xc0 +}; + +const UINT8 PkcsCOFFSha512[64] = { + 0x41, 0x55, 0xee, 0x56, 0x1d, 0xbe, 0x29, 0x3a, 0x69, 0xda, 0xf8, 0xd3, + 0x68, 0xe5, 0x5c, 0xd7, 0xf7, 0xb6, 0x87, 0x2a, 0x26, 0xbd, 0xb0, 0x11, + 0x6f, 0x43, 0x3e, 0x0d, 0xd9, 0xa4, 0x2b, 0x9b, 0x02, 0x59, 0x28, 0x8e, + 0x08, 0x71, 0xc4, 0xde, 0x6a, 0xb4, 0xba, 0xf2, 0xb9, 0xe4, 0xf7, 0x83, + 0xc3, 0x8b, 0xa3, 0x68, 0x83, 0x26, 0x67, 0x7c, 0xf8, 0xf3, 0x91, 0xdf, + 0xfe, 0xd1, 0x2a, 0x59 +}; +} diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/README.md b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/README.md index 9dd89ee286..840ada1ab0 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/README.md +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/README.md @@ -1,3 +1,12 @@ +### Certificate expiration date + +The `X509_V_FLAG_NO_CHECK_TIME` flag was deliberately added in the +Pkcs7Verify implementation so that UEFI Secure Boot validation is +time-agnostic — firmware doesn't have a reliable wall-clock during +early boot, so certificate expiry is intentionally not enforced here. +The tests will continue to pass indefinitely regardless of the +`TestCert.pem` expiry date. + ### How to reproduce the binary file 1. Apply the following patch. diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestCert.pem b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestCert.pem new file mode 100644 index 0000000000..fdea600652 --- /dev/null +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestCert.pem @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDBzCCAe+gAwIBAgIUdOL7kaFI2reWawnWCVrVUckQ0L8wDQYJKoZIhvcNAQEL +BQAwEzERMA8GA1UEAwwIVGVzdCBLZXkwHhcNMjYwMjIyMTYyNzE1WhcNMjcwMjIy +MTYyNzE1WjATMREwDwYDVQQDDAhUZXN0IEtleTCCASIwDQYJKoZIhvcNAQEBBQAD +ggEPADCCAQoCggEBANHi8a/hdnEGDfEDxd56UeXs8db02yhaB5luXcf9a3FccVrV ++xehlME19ZW7NzA+K5EcBL7BP5DsMHfYZiTPYQLEA/kXe8x/daF6IGuLKDnm+VR6 +cI3mSLRsVw3qlVrw2q1yX8bxx6g84crV9WjP5CqxKeUE7P83EIOOrQPnCpLu50pa +X+ISlJF6FriAk15Izs9kiTb9vA6hz/SBP3EMJiBj0ipncDmBORFLPZ2demZ5Q3LN +OfSRMUdXLokt4jfpUDw4f31TKGqqZZq022Eaj4xCO6Met8cRgTPm+16DyU99m6wg +aSv3FLt69XY77N1V/Ziv6/8qNu2xY20we9xXxMMCAwEAAaNTMFEwHQYDVR0OBBYE +FG/c5OFNAQxuYbwUXziCcNo9ngPvMB8GA1UdIwQYMBaAFG/c5OFNAQxuYbwUXziC +cNo9ngPvMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAI05eQVe +ZQul9x8DeIJz23HkxSpjFPcEBAgp28tY+K25XgjZu9auyEbk4HTRl/7XY27SJrbA +17VmgNz/cSKuU4Q8JSBgNT7qbFlp6aaTxNkaP8lsedHAYsH3vIxsMWB/yxXpMbRp +ZBL1AIsZlu4dsX0tn1CmyDNZqTgMsWUlomdynsLcrI/vKUf28JFdDGWaARlXsebO +erCmhjk/kTcxud6CgaUv677Gnt0nd2R+lIIR4rvY03jIOkh2gouecdyhlWBvaq75 +t+uiSyyrPMIQKOJ9IsOhUw7ZDLoluCFsfA/DhW8fnYVJN6hc5d6IIGC3f/Iz6trd +YnsCawkIo3wwog0= +-----END CERTIFICATE----- diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestCertCOFF.h b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestCertCOFF.h new file mode 100644 index 0000000000..74f0056edc --- /dev/null +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestCertCOFF.h @@ -0,0 +1,79 @@ +/** @file + Unit tests for the implementation of DxeImageVerificationLib. + + Copyright (c) 2026, Yandex. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#pragma once + +namespace certs +{ +const UINT8 TestCertDer[779] = { + 0x30, 0x82, 0x03, 0x07, 0x30, 0x82, 0x01, 0xef, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x14, 0x74, 0xe2, 0xfb, 0x91, 0xa1, 0x48, 0xda, 0xb7, 0x96, + 0x6b, 0x09, 0xd6, 0x09, 0x5a, 0xd5, 0x51, 0xc9, 0x10, 0xd0, 0xbf, 0x30, + 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, + 0x05, 0x00, 0x30, 0x13, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, + 0x03, 0x0c, 0x08, 0x54, 0x65, 0x73, 0x74, 0x20, 0x4b, 0x65, 0x79, 0x30, + 0x1e, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x32, 0x32, 0x32, 0x31, 0x36, 0x32, + 0x37, 0x31, 0x35, 0x5a, 0x17, 0x0d, 0x32, 0x37, 0x30, 0x32, 0x32, 0x32, + 0x31, 0x36, 0x32, 0x37, 0x31, 0x35, 0x5a, 0x30, 0x13, 0x31, 0x11, 0x30, + 0x0f, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x08, 0x54, 0x65, 0x73, 0x74, + 0x20, 0x4b, 0x65, 0x79, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, + 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, + 0x00, 0xd1, 0xe2, 0xf1, 0xaf, 0xe1, 0x76, 0x71, 0x06, 0x0d, 0xf1, 0x03, + 0xc5, 0xde, 0x7a, 0x51, 0xe5, 0xec, 0xf1, 0xd6, 0xf4, 0xdb, 0x28, 0x5a, + 0x07, 0x99, 0x6e, 0x5d, 0xc7, 0xfd, 0x6b, 0x71, 0x5c, 0x71, 0x5a, 0xd5, + 0xfb, 0x17, 0xa1, 0x94, 0xc1, 0x35, 0xf5, 0x95, 0xbb, 0x37, 0x30, 0x3e, + 0x2b, 0x91, 0x1c, 0x04, 0xbe, 0xc1, 0x3f, 0x90, 0xec, 0x30, 0x77, 0xd8, + 0x66, 0x24, 0xcf, 0x61, 0x02, 0xc4, 0x03, 0xf9, 0x17, 0x7b, 0xcc, 0x7f, + 0x75, 0xa1, 0x7a, 0x20, 0x6b, 0x8b, 0x28, 0x39, 0xe6, 0xf9, 0x54, 0x7a, + 0x70, 0x8d, 0xe6, 0x48, 0xb4, 0x6c, 0x57, 0x0d, 0xea, 0x95, 0x5a, 0xf0, + 0xda, 0xad, 0x72, 0x5f, 0xc6, 0xf1, 0xc7, 0xa8, 0x3c, 0xe1, 0xca, 0xd5, + 0xf5, 0x68, 0xcf, 0xe4, 0x2a, 0xb1, 0x29, 0xe5, 0x04, 0xec, 0xff, 0x37, + 0x10, 0x83, 0x8e, 0xad, 0x03, 0xe7, 0x0a, 0x92, 0xee, 0xe7, 0x4a, 0x5a, + 0x5f, 0xe2, 0x12, 0x94, 0x91, 0x7a, 0x16, 0xb8, 0x80, 0x93, 0x5e, 0x48, + 0xce, 0xcf, 0x64, 0x89, 0x36, 0xfd, 0xbc, 0x0e, 0xa1, 0xcf, 0xf4, 0x81, + 0x3f, 0x71, 0x0c, 0x26, 0x20, 0x63, 0xd2, 0x2a, 0x67, 0x70, 0x39, 0x81, + 0x39, 0x11, 0x4b, 0x3d, 0x9d, 0x9d, 0x7a, 0x66, 0x79, 0x43, 0x72, 0xcd, + 0x39, 0xf4, 0x91, 0x31, 0x47, 0x57, 0x2e, 0x89, 0x2d, 0xe2, 0x37, 0xe9, + 0x50, 0x3c, 0x38, 0x7f, 0x7d, 0x53, 0x28, 0x6a, 0xaa, 0x65, 0x9a, 0xb4, + 0xdb, 0x61, 0x1a, 0x8f, 0x8c, 0x42, 0x3b, 0xa3, 0x1e, 0xb7, 0xc7, 0x11, + 0x81, 0x33, 0xe6, 0xfb, 0x5e, 0x83, 0xc9, 0x4f, 0x7d, 0x9b, 0xac, 0x20, + 0x69, 0x2b, 0xf7, 0x14, 0xbb, 0x7a, 0xf5, 0x76, 0x3b, 0xec, 0xdd, 0x55, + 0xfd, 0x98, 0xaf, 0xeb, 0xff, 0x2a, 0x36, 0xed, 0xb1, 0x63, 0x6d, 0x30, + 0x7b, 0xdc, 0x57, 0xc4, 0xc3, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x53, + 0x30, 0x51, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, + 0x14, 0x6f, 0xdc, 0xe4, 0xe1, 0x4d, 0x01, 0x0c, 0x6e, 0x61, 0xbc, 0x14, + 0x5f, 0x38, 0x82, 0x70, 0xda, 0x3d, 0x9e, 0x03, 0xef, 0x30, 0x1f, 0x06, + 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x6f, 0xdc, + 0xe4, 0xe1, 0x4d, 0x01, 0x0c, 0x6e, 0x61, 0xbc, 0x14, 0x5f, 0x38, 0x82, + 0x70, 0xda, 0x3d, 0x9e, 0x03, 0xef, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, + 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, + 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, + 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x8d, 0x39, 0x79, 0x05, 0x5e, + 0x65, 0x0b, 0xa5, 0xf7, 0x1f, 0x03, 0x78, 0x82, 0x73, 0xdb, 0x71, 0xe4, + 0xc5, 0x2a, 0x63, 0x14, 0xf7, 0x04, 0x04, 0x08, 0x29, 0xdb, 0xcb, 0x58, + 0xf8, 0xad, 0xb9, 0x5e, 0x08, 0xd9, 0xbb, 0xd6, 0xae, 0xc8, 0x46, 0xe4, + 0xe0, 0x74, 0xd1, 0x97, 0xfe, 0xd7, 0x63, 0x6e, 0xd2, 0x26, 0xb6, 0xc0, + 0xd7, 0xb5, 0x66, 0x80, 0xdc, 0xff, 0x71, 0x22, 0xae, 0x53, 0x84, 0x3c, + 0x25, 0x20, 0x60, 0x35, 0x3e, 0xea, 0x6c, 0x59, 0x69, 0xe9, 0xa6, 0x93, + 0xc4, 0xd9, 0x1a, 0x3f, 0xc9, 0x6c, 0x79, 0xd1, 0xc0, 0x62, 0xc1, 0xf7, + 0xbc, 0x8c, 0x6c, 0x31, 0x60, 0x7f, 0xcb, 0x15, 0xe9, 0x31, 0xb4, 0x69, + 0x64, 0x12, 0xf5, 0x00, 0x8b, 0x19, 0x96, 0xee, 0x1d, 0xb1, 0x7d, 0x2d, + 0x9f, 0x50, 0xa6, 0xc8, 0x33, 0x59, 0xa9, 0x38, 0x0c, 0xb1, 0x65, 0x25, + 0xa2, 0x67, 0x72, 0x9e, 0xc2, 0xdc, 0xac, 0x8f, 0xef, 0x29, 0x47, 0xf6, + 0xf0, 0x91, 0x5d, 0x0c, 0x65, 0x9a, 0x01, 0x19, 0x57, 0xb1, 0xe6, 0xce, + 0x7a, 0xb0, 0xa6, 0x86, 0x39, 0x3f, 0x91, 0x37, 0x31, 0xb9, 0xde, 0x82, + 0x81, 0xa5, 0x2f, 0xeb, 0xbe, 0xc6, 0x9e, 0xdd, 0x27, 0x77, 0x64, 0x7e, + 0x94, 0x82, 0x11, 0xe2, 0xbb, 0xd8, 0xd3, 0x78, 0xc8, 0x3a, 0x48, 0x76, + 0x82, 0x8b, 0x9e, 0x71, 0xdc, 0xa1, 0x95, 0x60, 0x6f, 0x6a, 0xae, 0xf9, + 0xb7, 0xeb, 0xa2, 0x4b, 0x2c, 0xab, 0x3c, 0xc2, 0x10, 0x28, 0xe2, 0x7d, + 0x22, 0xc3, 0xa1, 0x53, 0x0e, 0xd9, 0x0c, 0xba, 0x25, 0xb8, 0x21, 0x6c, + 0x7c, 0x0f, 0xc3, 0x85, 0x6f, 0x1f, 0x9d, 0x85, 0x49, 0x37, 0xa8, 0x5c, + 0xe5, 0xde, 0x88, 0x20, 0x60, 0xb7, 0x7f, 0xf2, 0x33, 0xea, 0xda, 0xdd, + 0x62, 0x7b, 0x02, 0x6b, 0x09, 0x08, 0xa3, 0x7c, 0x30, 0xa2, 0x0d +}; +} diff --git a/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestKey.pem b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestKey.pem new file mode 100644 index 0000000000..ced8984c77 --- /dev/null +++ b/SecurityPkg/Library/DxeImageVerificationLib/GoogleTest/binfiles/TestKey.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDR4vGv4XZxBg3x +A8XeelHl7PHW9NsoWgeZbl3H/WtxXHFa1fsXoZTBNfWVuzcwPiuRHAS+wT+Q7DB3 +2GYkz2ECxAP5F3vMf3WheiBriyg55vlUenCN5ki0bFcN6pVa8Nqtcl/G8ceoPOHK +1fVoz+QqsSnlBOz/NxCDjq0D5wqS7udKWl/iEpSReha4gJNeSM7PZIk2/bwOoc/0 +gT9xDCYgY9IqZ3A5gTkRSz2dnXpmeUNyzTn0kTFHVy6JLeI36VA8OH99UyhqqmWa +tNthGo+MQjujHrfHEYEz5vteg8lPfZusIGkr9xS7evV2O+zdVf2Yr+v/KjbtsWNt +MHvcV8TDAgMBAAECggEABC3ptB/gNOXy9x6lHQYAhXyPYEFl78rDJfn9ohLYxdwa +Yb2rD1BnXuWNK1scATjrsysEqSu98UvSt0A24HrEqsJuddJS48KR/BIrfRi7R1Pj +GRyLCzhPsFAL97n5GWN8Z0HEyHheCmqT8G8MQPcKyxLWC7pqYbad/JClv1MlccGI +3B/mZM7OmKbIxfEZNtg8a1Ig6GObCam4EKxTeQWwJAikVF8E0s+G/1ZENXSVMzYG +HN7v0323nkeruKYYBD5O07t5btN1Iy7N7uXeWu82YjjC8dCukH9nqDcK/3WcwxOC +d2K33jqZGLf4d+MAChP0m97pXCQkyiXPFn299JkIGQKBgQDqE9IXrWAl4wEtphW3 +td0wNl+OHjEWRue1uc7df2Sp9nYpISxR/AifsbCmKp9hLm1QD4z4726VRJMvbPF0 +bw/w9S8R7ZwGOb4xX1IQb615ykZmPfIB9TePEVP/Bf+BVA4Xvwxx+6sgTZCu7lJc +2gqHcZpp2MHpsVbIXRWZwPBExwKBgQDliyDMrU0hTRkYy233VCz9byDKvORM3PX8 +uiEwcO+koQuaUiMlulyVrEEIGsHxPbEPqBiv97Bq+B2lM9ADZSG+m4a/TgU3QG5v +7PUVuNF1/cliuDor4MQkCVPHFeVXWCuI2dE370YBgrIidsD4W/bHNFJGgSJ6sJCB +gIsBCPeMJQKBgQCbXVqGIqp9myWOEf26OPi95mkYIEv+eEOVZ+W5OLQs54xYEk+j +fwCOVldkg0fULgeaKygrlmg0pRZ4VPwShyDykxqR8L8tlqf5h0Yl6Kog+zQs6pK1 +3/fnet3gmC+VvJ+5/TGaeiuEPld49HAwdvykF7Ag7yEOJonuZXJP4jLXwwKBgHA1 +q+oCSbMewkb5ox8FuhyFx4zz+9KLLYDG6FSK0Ms0orxkrKPTz1CnbP7uPaKVWsnh +jXfv6ADSm4NXqbcPKAjKdHtuQ2R4DcSPHFvrBhHc5yZoEp/Cd396Q8cNsBgblOSI +PhtOz3ULk9L/JGQEaMWGkTXACL/bMjjsQodV/9U1AoGAYP0OIhwb06vPfse/St75 +b4Glj8Vbdu4e7Eyrifv9i+oZAzsARcTrHs6ULr9qhiHLx8RGqhoDCkkrZ6/3pute +i1SlnrHI5CmbhUncCtsF/sFC/0YJ2BPXHoH682oCfanCqBTHGRJ6H6dxizGHm651 +OGcGR1lqcxYqs6d6x63+TIg= +-----END PRIVATE KEY----- From 9e83101fdfdbe97c9d5b9586b69a8444bb49584b Mon Sep 17 00:00:00 2001 From: Dongyan Qian <qiandongyan@loongson.cn> Date: Mon, 13 Jul 2026 16:47:38 +0800 Subject: [PATCH 192/406] DynamicTablesPkg/Smbios: Use EFIAPI for extended callbacks The SMBIOS_TABLE_GENERATOR_BUILD_TABLEEX and SMBIOS_TABLE_GENERATOR_FREE_TABLEEX callback types do not specify EFIAPI. The Type 37 implementations specify it, while the other extended callback implementations follow the omission in the shared types. For X64 GCC builds, BaseTools/Conf/tools_def.template adds -DEFIAPI=__attribute__((ms_abi)). Therefore, callbacks marked with EFIAPI use the Microsoft x64 ABI, while unannotated callback types use the compiler default ABI. If the two sides differ, the caller and callee use different argument registers, and GCC rejects the function pointer assignment. This mismatch remained hidden while the standalone Type 37 generator was built only for AARCH64. Moving the SMBIOS generators to the common component section adds X64 build coverage and exposes it. Add EFIAPI to the extended callback types and all matching implementations. This follows the ACPI generator callback convention and provides the ABI prerequisite for expanding the SMBIOS standalone build coverage. Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn> --- DynamicTablesPkg/Include/SmbiosTableGenerator.h | 4 ++-- .../Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c | 2 ++ .../Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c | 2 ++ .../Library/Smbios/SmbiosType19Lib/SmbiosType19Generator.c | 2 ++ .../Library/Smbios/SmbiosType20Lib/SmbiosType20Generator.c | 2 ++ .../Library/Smbios/SmbiosType26Lib/SmbiosType26Generator.c | 2 ++ .../Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c | 2 ++ .../Library/Smbios/SmbiosType28Lib/SmbiosType28Generator.c | 2 ++ .../Library/Smbios/SmbiosType29Lib/SmbiosType29Generator.c | 2 ++ .../Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c | 2 ++ .../Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c | 2 ++ .../Library/Smbios/SmbiosType7Lib/SmbiosType7Generator.c | 2 ++ 12 files changed, 24 insertions(+), 2 deletions(-) diff --git a/DynamicTablesPkg/Include/SmbiosTableGenerator.h b/DynamicTablesPkg/Include/SmbiosTableGenerator.h index 70133554da..62ab4e593f 100644 --- a/DynamicTablesPkg/Include/SmbiosTableGenerator.h +++ b/DynamicTablesPkg/Include/SmbiosTableGenerator.h @@ -211,7 +211,7 @@ typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_FREE_TABLE) ( @return EFI_SUCCESS If the table is generated successfully or other failure codes as returned by the generator. **/ -typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_BUILD_TABLEEX) ( +typedef EFI_STATUS (EFIAPI *SMBIOS_TABLE_GENERATOR_BUILD_TABLEEX)( IN CONST SMBIOS_TABLE_GENERATOR *Generator, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, @@ -239,7 +239,7 @@ typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_BUILD_TABLEEX) ( @return EFI_SUCCESS If freed successfully or other failure codes as returned by the generator. **/ -typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_FREE_TABLEEX) ( +typedef EFI_STATUS (EFIAPI *SMBIOS_TABLE_GENERATOR_FREE_TABLEEX)( IN CONST SMBIOS_TABLE_GENERATOR *Generator, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c index e8af2a5df8..ad6a62f124 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c @@ -58,6 +58,7 @@ GET_OBJECT_LIST ( **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType16TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -161,6 +162,7 @@ AddMemErrDeviceHandle ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType16TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c index 34a6ca8723..e40d8c9201 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c @@ -57,6 +57,7 @@ GET_OBJECT_LIST ( **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType17TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -250,6 +251,7 @@ UpdateSmbiosType17Rank ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType17TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Generator.c index 855c6bb6c9..8c4f4742d6 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Generator.c @@ -58,6 +58,7 @@ GET_OBJECT_LIST ( **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType19TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -177,6 +178,7 @@ UpdateSmbiosType19Address ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType19TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Generator.c index 3b7d0e8919..56221e397a 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Generator.c @@ -59,6 +59,7 @@ GET_OBJECT_LIST ( **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType20TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -112,6 +113,7 @@ FreeSmbiosType20TableEx ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType20TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Generator.c index af617ab4a9..be3f4516b5 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Generator.c @@ -111,6 +111,7 @@ IsValidVoltageProbeLocation ( **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType26TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -168,6 +169,7 @@ FreeSmbiosType26TableEx ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType26TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c index 48acc82278..6a4ccb44c8 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Generator.c @@ -159,6 +159,7 @@ AddTemperatureProbeHandle ( **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType27TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -216,6 +217,7 @@ FreeSmbiosType27TableEx ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType27TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Generator.c index db664c5afc..fc56f88f98 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Generator.c @@ -111,6 +111,7 @@ IsValidTemperatureProbeLocation ( **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType28TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -168,6 +169,7 @@ FreeSmbiosType28TableEx ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType28TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Generator.c index 6790162fcf..2d29a8cb41 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Generator.c @@ -111,6 +111,7 @@ IsValidElectricalCurrentProbeLocation ( **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType29TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -168,6 +169,7 @@ FreeSmbiosType29TableEx ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType29TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c index f130ef5f0f..20436eed0d 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c @@ -757,6 +757,7 @@ STATIC PROCESSOR_SPECIFIC_BLOCK_OPS mProcSpecificBlockOps[] = { **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType44TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -810,6 +811,7 @@ FreeSmbiosType44TableEx ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType44TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c index 462ebeb8f2..676357498c 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c @@ -69,6 +69,7 @@ GET_OBJECT_LIST ( **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType4TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -157,6 +158,7 @@ FindProcHierarchyInfoFromToken ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType4TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Generator.c index 3bb3fee11d..2592a2fdca 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Generator.c @@ -79,6 +79,7 @@ GET_OBJECT_LIST ( **/ STATIC EFI_STATUS +EFIAPI FreeSmbiosType7TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *CONST This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, @@ -411,6 +412,7 @@ FindExistingCacheRecord ( **/ STATIC EFI_STATUS +EFIAPI BuildSmbiosType7TableEx ( IN CONST SMBIOS_TABLE_GENERATOR *This, IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, From f5254b5c23fbe9e91941138c915132f2a0217d36 Mon Sep 17 00:00:00 2001 From: Dongyan Qian <qiandongyan@loongson.cn> Date: Mon, 13 Jul 2026 17:48:16 +0800 Subject: [PATCH 193/406] DynamicTablesPkg/Smbios: Fix X64 build warnings Moving the standalone SMBIOS generators to the common component section adds them to the X64 build. VS2022 reports narrowing warnings for native- width, wide, or enum values converted to fixed-width SMBIOS fields. These warnings are treated as errors under /WX. Use UINTN for the Type 7 table-list count and index. Add bounds checks for the Type 4 processor counts and Type 7 cache level where CM-derived values could exceed the corresponding SMBIOS fields, and make the remaining intended conversions explicit in the Type 4, Type 7, Type 16, Type 17, Type 19, and Type 44 generators. This rejects out-of-range processor counts and cache levels instead of silently truncating them, while preserving the existing behavior for valid configuration data. Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn> --- .../SmbiosType16Lib/SmbiosType16Generator.c | 2 +- .../SmbiosType17Lib/SmbiosType17Generator.c | 16 +++++------ .../SmbiosType19Lib/SmbiosType19Generator.c | 4 +-- .../SmbiosType44Lib/SmbiosType44Generator.c | 10 +++---- .../SmbiosType4Lib/SmbiosType4Generator.c | 28 ++++++++++++++----- .../SmbiosType7Lib/SmbiosType7Generator.c | 26 ++++++++++++----- 6 files changed, 56 insertions(+), 30 deletions(-) diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c index ad6a62f124..43644c7f50 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c @@ -108,7 +108,7 @@ UpdateSmbiosType16Size ( SizeKb = SizeBytes / SIZE_1KB; if (SizeBytes < EXTENDED_SIZE_THRESHOLD) { - SmbiosRecord->MaximumCapacity = SizeKb; + SmbiosRecord->MaximumCapacity = (UINT32)SizeKb; } else { SmbiosRecord->MaximumCapacity = 0x80000000; SmbiosRecord->ExtendedMaximumCapacity = SizeBytes; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c index e40d8c9201..f482139c99 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c @@ -165,13 +165,13 @@ UpdateSmbiosType17Size ( ) { if (Size < SIZE_GRANULARITY_THRESHOLD) { - SmbiosRecord->Size = Size / SIZE_1KB; + SmbiosRecord->Size = (UINT16)(Size / SIZE_1KB); SmbiosRecord->Size |= SIZE_GRANULARITY_BITMASK; } else if (Size >= EXTENDED_SIZE_THRESHOLD) { SmbiosRecord->Size = 0x7FFF; - SmbiosRecord->ExtendedSize = (Size / SIZE_1MB); + SmbiosRecord->ExtendedSize = (UINT32)(Size / SIZE_1MB); } else { - SmbiosRecord->Size = (Size / SIZE_1MB); + SmbiosRecord->Size = (UINT16)(Size / SIZE_1MB); } } @@ -194,14 +194,14 @@ UpdateSmbiosType17Speed ( SmbiosRecord->Speed = EXTENDED_SPEED_THRESHOLD; SmbiosRecord->ExtendedSpeed = Speed; } else { - SmbiosRecord->Speed = Speed; + SmbiosRecord->Speed = (UINT16)Speed; } if (ConfiguredMemoryClockSpeed > EXTENDED_SPEED_THRESHOLD) { SmbiosRecord->ConfiguredMemoryClockSpeed = EXTENDED_SPEED_THRESHOLD; SmbiosRecord->ExtendedConfiguredMemorySpeed = ConfiguredMemoryClockSpeed; } else { - SmbiosRecord->ConfiguredMemoryClockSpeed = ConfiguredMemoryClockSpeed; + SmbiosRecord->ConfiguredMemoryClockSpeed = (UINT16)ConfiguredMemoryClockSpeed; } } @@ -456,12 +456,12 @@ BuildSmbiosType17TableEx ( MemoryDevicesInfo[Index].ModuleProductId; SmbiosRecord->DataWidth = MemoryDevicesInfo[Index].DataWidth; SmbiosRecord->TotalWidth = MemoryDevicesInfo[Index].TotalWidth; - SmbiosRecord->MemoryType = MemoryDevicesInfo[Index].MemoryType; - SmbiosRecord->FormFactor = MemoryDevicesInfo[Index].FormFactor; + SmbiosRecord->MemoryType = (UINT8)MemoryDevicesInfo[Index].MemoryType; + SmbiosRecord->FormFactor = (UINT8)MemoryDevicesInfo[Index].FormFactor; SmbiosRecord->MinimumVoltage = MemoryDevicesInfo[Index].MinVolt; SmbiosRecord->MaximumVoltage = MemoryDevicesInfo[Index].MaxVolt; SmbiosRecord->ConfiguredVoltage = MemoryDevicesInfo[Index].ConfVolt; - SmbiosRecord->MemoryTechnology = MemoryDevicesInfo[Index].MemoryTechnology; + SmbiosRecord->MemoryTechnology = (UINT8)MemoryDevicesInfo[Index].MemoryTechnology; SmbiosRecord->TypeDetail = MemoryDevicesInfo[Index].TypeDetail; SmbiosRecord->MemoryOperatingModeCapability = MemoryDevicesInfo[Index].MemoryOperatingModeCapability; AddMemErrHandle ( diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Generator.c index 8c4f4742d6..402257bdb7 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Generator.c @@ -147,8 +147,8 @@ UpdateSmbiosType19Address ( SmbiosRecord->ExtendedStartingAddress = StartAddress; SmbiosRecord->ExtendedEndingAddress = EndAddress; } else { - SmbiosRecord->StartingAddress = StartingAddressKb; - SmbiosRecord->EndingAddress = EndingAddressKb; + SmbiosRecord->StartingAddress = (UINT32)StartingAddressKb; + SmbiosRecord->EndingAddress = (UINT32)EndingAddressKb; } } diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c index 20436eed0d..75b58b42a0 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Generator.c @@ -587,9 +587,9 @@ AddArmProcBlock ( } ProcBlock->Revision = Block->Revision; - ProcBlock->Length = sizeof (ARM_PROCESSOR_SPECIFIC_BLOCK) + SubDataSize; + ProcBlock->Length = (UINT8)(sizeof (ARM_PROCESSOR_SPECIFIC_BLOCK) + SubDataSize); ProcBlock->VendorId = Block->VendorId; - ProcBlock->SubType = Block->SubType; + ProcBlock->SubType = (UINT8)Block->SubType; return SubDataOps->AddProcSubData ( CfgMgrProtocol, @@ -965,10 +965,10 @@ BuildSmbiosType44TableEx ( // Set up the header SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_ADDITIONAL_INFORMATION; - SmbiosRecord->Hdr.Length = SmbiosRecordSize - 2; + SmbiosRecord->Hdr.Length = (UINT8)(SmbiosRecordSize - 2); SmbiosRecord->RefHandle = Type4Handle; - SmbiosRecord->ProcessorSpecificBlock.ProcessorArchType = ProcSpecificBlockList[Index].ProcArchType; - SmbiosRecord->ProcessorSpecificBlock.Length = ProcBlockSize; + SmbiosRecord->ProcessorSpecificBlock.ProcessorArchType = (UINT8)ProcSpecificBlockList[Index].ProcArchType; + SmbiosRecord->ProcessorSpecificBlock.Length = (UINT8)ProcBlockSize; Status = ProcBlockOps->AddProcBlock ( CfgMgrProtocol, diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c index 676357498c..30cd587b83 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Generator.c @@ -468,6 +468,20 @@ BuildSmbiosType4TableEx ( ThreadCount++; } + if ((CpuCount > MAX_UINT16) || (ThreadCount > MAX_UINT16)) { + DEBUG (( + DEBUG_ERROR, + "%a: CPU count %u or thread count %u exceeds the SMBIOS limit.\n", + __func__, + CpuCount, + ThreadCount + )); + Status = EFI_INVALID_PARAMETER; + FreePool (SmbiosRecord); + StringTableFree (&StrTable); + goto exitErrorBuildSmbiosType4Table; + } + SmbiosRecord->ProcessorType = CentralProcessor; SmbiosRecord->ProcessorUpgrade = ProcessorUpgradeUnknown; #if defined (MDE_CPU_AARCH64) @@ -494,13 +508,13 @@ BuildSmbiosType4TableEx ( CharacteristicFlags->Processor64BitCapable = 1; } - SmbiosRecord->CoreCount = (CpuCount < 256) ? CpuCount : 0xff; - SmbiosRecord->CoreCount2 = CpuCount; - SmbiosRecord->EnabledCoreCount = (CpuCount < 256) ? CpuCount : 0xff; - SmbiosRecord->EnabledCoreCount2 = CpuCount; - SmbiosRecord->ThreadCount = (ThreadCount < 256) ? ThreadCount : 0xff; - SmbiosRecord->ThreadCount2 = ThreadCount; - SmbiosRecord->ThreadEnabled = ThreadCount; + SmbiosRecord->CoreCount = (UINT8)((CpuCount < 256) ? CpuCount : MAX_UINT8); + SmbiosRecord->CoreCount2 = (UINT16)CpuCount; + SmbiosRecord->EnabledCoreCount = (UINT8)((CpuCount < 256) ? CpuCount : MAX_UINT8); + SmbiosRecord->EnabledCoreCount2 = (UINT16)CpuCount; + SmbiosRecord->ThreadCount = (UINT8)((ThreadCount < 256) ? ThreadCount : MAX_UINT8); + SmbiosRecord->ThreadCount2 = (UINT16)ThreadCount; + SmbiosRecord->ThreadEnabled = (UINT16)ThreadCount; SmbiosRecord->Socket = SocketDesignationRef; SmbiosRecord->ProcessorManufacturer = ProcessorManufacturerRef; diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Generator.c index 2592a2fdca..b6d4183a2b 100644 --- a/DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Generator.c +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Generator.c @@ -53,6 +53,7 @@ GET_OBJECT_LIST ( ); #define SMBIOS_TYPE7_MAX_STRINGS (1) +#define SMBIOS_CACHE_LEVEL_MAX ((1U << 3) - 1) /** * Free any resources allocated when installing SMBIOS Type7 table. @@ -363,12 +364,12 @@ FindExistingCacheRecord ( IN CM_ARCH_COMMON_PROC_HIERARCHY_INFO *SocketNode, IN SMBIOS_STRUCTURE **TableList, IN CM_OBJECT_TOKEN *SocketCmObjectList, - IN UINT32 CmObjectCount + IN UINTN CmObjectCount ) { SMBIOS_TABLE_TYPE7 *SmbiosRecord; SMBIOS_CACHE_CONFIGURATION_DATA *ConfigurationData; - UINT32 Index; + UINTN Index; for (Index = 0; Index < CmObjectCount; Index++) { if (SocketCmObjectList[Index] != SocketNode->Token) { @@ -578,6 +579,17 @@ BuildSmbiosType7TableEx ( for (Index = 0; Index < CacheStructCount; Index++) { CacheNode = &CacheStructList[Index]; + if (CacheNode->Level > SMBIOS_CACHE_LEVEL_MAX) { + DEBUG (( + DEBUG_ERROR, + "%a: Cache level %u exceeds the SMBIOS limit.\n", + __func__, + CacheNode->Level + )); + Status = EFI_INVALID_PARAMETER; + goto exitErrorBuildSmbiosType7Table; + } + for (SocketListIndex = 0; SocketListIndex < SocketCount; SocketListIndex++) { SocketNode = SocketNodeList[SocketListIndex]; @@ -614,7 +626,7 @@ BuildSmbiosType7TableEx ( goto exitErrorBuildSmbiosType7Table; } - CacheSize = CacheNode->Size * CacheUsers; + CacheSize = CacheNode->Size * (UINT32)CacheUsers; SmbiosRecord->MaximumCacheSize2.Size += CacheSize / 1024; @@ -670,7 +682,7 @@ BuildSmbiosType7TableEx ( SmbiosRecord->SocketDesignation = SocketDesignationRef; ConfigurationData = (SMBIOS_CACHE_CONFIGURATION_DATA *)&SmbiosRecord->CacheConfiguration; - ConfigurationData->CacheLevel = CacheNode->Level; + ConfigurationData->CacheLevel = (UINT16)CacheNode->Level; ConfigurationData->CacheSocketed = 0; ConfigurationData->Location = 0; ConfigurationData->Enabled = 1; @@ -689,7 +701,7 @@ BuildSmbiosType7TableEx ( goto exitErrorBuildSmbiosType7Table; } - CacheSize = CacheNode->Size * CacheUsers; + CacheSize = CacheNode->Size * (UINT32)CacheUsers; // Store cache size in MaximumCacheSize2.Size in 1K granularity. This will be // processed once all caches have been accumulated. @@ -733,13 +745,13 @@ BuildSmbiosType7TableEx ( SmbiosRecord->MaximumCacheSize2.Size = (CacheSize / 64); SmbiosRecord->MaximumCacheSize.Granularity64K = 1; - SmbiosRecord->MaximumCacheSize.Size = (CacheSize / 64); + SmbiosRecord->MaximumCacheSize.Size = (UINT16)(CacheSize / 64); } else { SmbiosRecord->MaximumCacheSize2.Granularity64K = 0; SmbiosRecord->MaximumCacheSize2.Size = CacheSize; SmbiosRecord->MaximumCacheSize.Granularity64K = 0; - SmbiosRecord->MaximumCacheSize.Size = CacheSize; + SmbiosRecord->MaximumCacheSize.Size = (UINT16)CacheSize; } SmbiosRecord->InstalledSize = SmbiosRecord->MaximumCacheSize; From 80462803041b11e6eabf20e08e1dbc169d3774f2 Mon Sep 17 00:00:00 2001 From: Dongyan Qian <qiandongyan@loongson.cn> Date: Mon, 13 Jul 2026 16:52:08 +0800 Subject: [PATCH 194/406] DynamicTablesPkg: Move SMBIOS generators to common components The SMBIOS generators are architecture-neutral standalone components. They are currently listed only for AARCH64. Move them to the existing common component section so every supported architecture receives the same package build coverage. Keep the DynamicTableFactoryDxe registration architecture-specific. Its NULL library list determines the generators registered at runtime. Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn> --- DynamicTablesPkg/DynamicTables.dsc.inc | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index b483ba95f6..a542bb6888 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -51,6 +51,22 @@ DynamicTablesPkg/Library/Acpi/Common/AcpiHestLib/AcpiHestLib.inf DynamicTablesPkg/Library/Acpi/Common/AcpiEinjLib/AcpiEinjLib.inf + # SMBIOS Generators (Common) + DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Lib.inf + # AML Fixup (Common) DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtSerialPortLib/SsdtSerialPortLib.inf @@ -110,21 +126,6 @@ DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/AcpiIortLibArm.inf DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/AcpiMadtLibArm.inf - DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType20Lib/SmbiosType20Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType23Lib/SmbiosType23Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType26Lib/SmbiosType26Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType27Lib/SmbiosType27Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf - DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Lib.inf - # AML Fixup (Arm specific) DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtCmn600LibArm/SsdtCmn600LibArm.inf From 3a4556803d3a02dc0b298c489013e04082a9617e Mon Sep 17 00:00:00 2001 From: Dongyan Qian <qiandongyan@loongson.cn> Date: Mon, 13 Jul 2026 16:53:13 +0800 Subject: [PATCH 195/406] DynamicTablesPkg: Enable LoongArch64 table generation Add LOONGARCH64 support to DynamicTablesPkg by adding it to the existing common component build list, adding the LoongArch64 DynamicTableManagerDxe source, and enabling the SMBIOS generators used by current LoongArch platforms. Keep DynamicTableFactoryDxe generator registration architecture-specific. The LoongArch64 factory instance links selected NULL generator libraries so their constructors register the generators at runtime. LoongArch64-specific tables can use AcpiRawLib initially and move to dedicated LoongArch64 generators in follow-up patches. Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn> --- .../DynamicTableManagerDxe.inf | 5 +- .../LoongArch64DynamicTableManagerDxe.c | 60 +++++++++++++++++++ DynamicTablesPkg/DynamicTables.dsc.inc | 24 +++++++- DynamicTablesPkg/DynamicTablesPkg.dsc | 2 +- 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 DynamicTablesPkg/Drivers/DynamicTableManagerDxe/LoongArch64/LoongArch64DynamicTableManagerDxe.c diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf index a933d83998..2c55778808 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf @@ -18,7 +18,7 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = X64 AARCH64 +# VALID_ARCHITECTURES = X64 AARCH64 LOONGARCH64 # [Sources] @@ -38,6 +38,9 @@ [Sources.RISCV64] RiscV/RiscVDynamicTableManagerDxe.c +[Sources.LOONGARCH64] + LoongArch64/LoongArch64DynamicTableManagerDxe.c + [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/LoongArch64/LoongArch64DynamicTableManagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/LoongArch64/LoongArch64DynamicTableManagerDxe.c new file mode 100644 index 0000000000..1397973259 --- /dev/null +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/LoongArch64/LoongArch64DynamicTableManagerDxe.c @@ -0,0 +1,60 @@ +/** @file + LoongArch64 Dynamic Table Manager Dxe + + Copyright (c) 2026, Loongson Technology Corporation Limited. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <IndustryStandard/Acpi.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Protocol/AcpiSystemDescriptionTable.h> +#include <Protocol/AcpiTable.h> + +// Module specific include files. +#include <AcpiTableGenerator.h> +#include <ConfigurationManagerObject.h> +#include <ConfigurationManagerHelper.h> +#include <DeviceTreeTableGenerator.h> +#include <Library/TableHelperLib.h> +#include <Protocol/ConfigurationManagerProtocol.h> +#include <Protocol/DynamicTableFactoryProtocol.h> +#include "DynamicTableManagerDxe.h" + +/// +/// Array containing the ACPI tables to check. +/// We require the FADT, MADT and DSDT tables to boot. +/// The FADT table must be placed at index 0. +/// +STATIC ACPI_TABLE_PRESENCE_INFO mAcpiVerifyTables[] = { + { EStdAcpiTableIdFadt, EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, "FADT", TRUE, 0 }, + { EStdAcpiTableIdMadt, EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE, "MADT", TRUE, 0 }, + { EStdAcpiTableIdDsdt, EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, "DSDT", TRUE, 0 }, +}; + +/** Get the arch specific ACPI table presence information. + + @param [out] PresenceArray Array containing the ACPI tables to check. + @param [out] PresenceArrayCount Count of elements in the PresenceArray. + @param [out] FadtIndex Index of the FADT table in the PresenceArray. + -1 if absent. + + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +GetAcpiTablePresenceInfo ( + OUT ACPI_TABLE_PRESENCE_INFO **PresenceArray, + OUT UINT32 *PresenceArrayCount, + OUT INT32 *FadtIndex + ) +{ + *PresenceArray = mAcpiVerifyTables; + *PresenceArrayCount = ARRAY_SIZE (mAcpiVerifyTables); + *FadtIndex = ACPI_TABLE_VERIFY_FADT; + + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index a542bb6888..6acdcd1a52 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -31,7 +31,7 @@ [LibraryClasses.AARCH64] DynamicTablesScmiInfoLib|DynamicTablesPkg/Library/DynamicTablesScmiInfoLib/DynamicTablesScmiInfoLib.inf -[Components.ARM, Components.AARCH64, Components.X64, Components.RISCV64] +[Components.ARM, Components.AARCH64, Components.X64, Components.RISCV64, Components.LOONGARCH64] # # Generators (Common) # @@ -219,3 +219,25 @@ NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtPcieLib/SsdtPcieLib.inf NULL|DynamicTablesPkg/Library/Acpi/RiscV/AcpiSsdtPlicAplicLib/AcpiSsdtPlicAplicLib.inf } + +[Components.LOONGARCH64] + # + # Dynamic Table Factory Dxe + # + DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf { + <LibraryClasses> + # Generators + # Common + NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiMcfgLib/AcpiMcfgLib.inf + NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiPcctLib/AcpiPcctLib.inf + NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiPpttLib/AcpiPpttLib.inf + NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiRawLib/AcpiRawLib.inf + NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiSlitLib/AcpiSlitLib.inf + + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType19Lib/SmbiosType19Lib.inf + } diff --git a/DynamicTablesPkg/DynamicTablesPkg.dsc b/DynamicTablesPkg/DynamicTablesPkg.dsc index ac9bad2a4d..91f46c2696 100644 --- a/DynamicTablesPkg/DynamicTablesPkg.dsc +++ b/DynamicTablesPkg/DynamicTablesPkg.dsc @@ -15,7 +15,7 @@ PLATFORM_VERSION = 0.1 DSC_SPECIFICATION = 0x0001001a OUTPUT_DIRECTORY = Build/DynamicTables - SUPPORTED_ARCHITECTURES = AARCH64|X64 + SUPPORTED_ARCHITECTURES = AARCH64|X64|LOONGARCH64 BUILD_TARGETS = DEBUG|RELEASE|NOOPT SKUID_IDENTIFIER = DEFAULT From 3fec6254088b8585e35f660b4fe289b179a15349 Mon Sep 17 00:00:00 2001 From: Joey Vagedes <joey.vagedes@gmail.com> Date: Thu, 9 Jul 2026 15:00:33 +0000 Subject: [PATCH 196/406] SecurityPkg: Add Google Test MockSecureBootVariableLib Add Google Test Mock library header and implementation for SecureBootVariableLib to allow simple mocking for host based unit tests that utilize the Google Test framework. Signed-off-by: Joey Vagedes <joey.vagedes@gmail.com> --- .../Library/MockSecureBootVariableLib.h | 27 +++++++++++++++ .../MockSecureBootVariableLib.cpp | 11 ++++++ .../MockSecureBootVariableLib.inf | 34 +++++++++++++++++++ SecurityPkg/Test/SecurityPkgHostTest.dsc | 1 + 4 files changed, 73 insertions(+) create mode 100644 SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockSecureBootVariableLib.h create mode 100644 SecurityPkg/Test/Mock/Library/GoogleTest/MockSecureBootVariableLib/MockSecureBootVariableLib.cpp create mode 100644 SecurityPkg/Test/Mock/Library/GoogleTest/MockSecureBootVariableLib/MockSecureBootVariableLib.inf diff --git a/SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockSecureBootVariableLib.h b/SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockSecureBootVariableLib.h new file mode 100644 index 0000000000..a0d53185c6 --- /dev/null +++ b/SecurityPkg/Test/Mock/Include/GoogleTest/Library/MockSecureBootVariableLib.h @@ -0,0 +1,27 @@ +/** @file + Google Test mocks for SecureBootVariableLib + + Copyright (C) Microsoft Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#pragma once + +#include <Library/GoogleTestLib.h> +#include <Library/FunctionMockLib.h> +extern "C" { + #include <Uefi.h> + #include <UefiSecureBoot.h> + #include <Guid/ImageAuthentication.h> + #include <Library/SecureBootVariableLib.h> +} + +struct MockSecureBootVariableLib { + MOCK_INTERFACE_DECLARATION (MockSecureBootVariableLib); + + MOCK_FUNCTION_DECLARATION ( + BOOLEAN, + IsSecureBootEnabled, + () + ); +}; diff --git a/SecurityPkg/Test/Mock/Library/GoogleTest/MockSecureBootVariableLib/MockSecureBootVariableLib.cpp b/SecurityPkg/Test/Mock/Library/GoogleTest/MockSecureBootVariableLib/MockSecureBootVariableLib.cpp new file mode 100644 index 0000000000..7cecd3eea8 --- /dev/null +++ b/SecurityPkg/Test/Mock/Library/GoogleTest/MockSecureBootVariableLib/MockSecureBootVariableLib.cpp @@ -0,0 +1,11 @@ +/** @file + Google Test mocks for SecureBootVariableLib + + Copyright (C) Microsoft Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +#include <GoogleTest/Library/MockSecureBootVariableLib.h> + +MOCK_INTERFACE_DEFINITION (MockSecureBootVariableLib); + +MOCK_FUNCTION_DEFINITION (MockSecureBootVariableLib, IsSecureBootEnabled, 0, EFIAPI); diff --git a/SecurityPkg/Test/Mock/Library/GoogleTest/MockSecureBootVariableLib/MockSecureBootVariableLib.inf b/SecurityPkg/Test/Mock/Library/GoogleTest/MockSecureBootVariableLib/MockSecureBootVariableLib.inf new file mode 100644 index 0000000000..dfe91985f0 --- /dev/null +++ b/SecurityPkg/Test/Mock/Library/GoogleTest/MockSecureBootVariableLib/MockSecureBootVariableLib.inf @@ -0,0 +1,34 @@ +## @file +# Google Test mocks for SecureBootVariableLib +# +# Copyright (C) Microsoft Corporation. All rights reserved.<BR> +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = MockSecureBootVariableLib + FILE_GUID = 4F5C2D34-2E9F-4F1E-9D6E-1F1F8C9D7C3A + MODULE_TYPE = HOST_APPLICATION + VERSION_STRING = 1.0 + LIBRARY_CLASS = SecureBootVariableLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + MockSecureBootVariableLib.cpp + +[Packages] + MdePkg/MdePkg.dec + SecurityPkg/SecurityPkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + GoogleTestLib + +[BuildOptions] + MSFT:*_*_*_CC_FLAGS = /EHsc diff --git a/SecurityPkg/Test/SecurityPkgHostTest.dsc b/SecurityPkg/Test/SecurityPkgHostTest.dsc index 7159b20b6b..64973c26e9 100644 --- a/SecurityPkg/Test/SecurityPkgHostTest.dsc +++ b/SecurityPkg/Test/SecurityPkgHostTest.dsc @@ -28,6 +28,7 @@ SecurityPkg/Test/Mock/Library/GoogleTest/MockPlatformPKProtectionLib/MockPlatformPKProtectionLib.inf SecurityPkg/Library/DxeTpm2MeasureBootLib/InternalUnitTest/DxeTpm2MeasureBootLibSanitizationTestHost.inf SecurityPkg/Library/DxeTpmMeasureBootLib/InternalUnitTest/DxeTpmMeasureBootLibSanitizationTestHost.inf + SecurityPkg/Test/Mock/Library/GoogleTest/MockSecureBootVariableLib/MockSecureBootVariableLib.inf # # Build SecurityPkg HOST_APPLICATION Tests From fb42b39a7d88d1966491cc1a1a533cdd5154c661 Mon Sep 17 00:00:00 2001 From: Tuan Phan <tuan.phan@oss.qualcomm.com> Date: Thu, 9 Jul 2026 11:06:38 -0700 Subject: [PATCH 197/406] SecurityPkg/RngDxe: Replace Intel-specific with arch-neutral comments The RngDxe driver and its non-AArch64 support files still contained comments and descriptions referring to Intel Secure Key technology, RDRAND/RDSEED instructions, and the Intel DRNG implementation guide. These references are no longer accurate because the driver obtains random data through the platform-provided RngLib abstraction rather than relying on Intel-specific CPU features. Update the comments and descriptions to use architecture-neutral language that better reflects the current implementation. Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com> --- .../RngDxe/Rand/AesCore.c | 5 ++-- .../RngDxe/Rand/AesCore.h | 5 ++-- .../RngDxe/Rand/RdRand.c | 24 ++++++++----------- .../RngDxe/Rand/RngDxe.c | 9 +++---- .../RandomNumberGenerator/RngDxe/RngDxe.c | 13 +++++----- .../RandomNumberGenerator/RngDxe/RngDxe.inf | 14 +++++------ .../RandomNumberGenerator/RngDxe/RngDxe.uni | 11 ++++----- .../RngDxe/RngDxeExtra.uni | 2 -- .../RngDxe/RngDxeInternals.h | 4 ++-- 9 files changed, 40 insertions(+), 47 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c index 3ac20e889c..582709d074 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c @@ -3,8 +3,9 @@ Refer to FIPS PUB 197 ("Advanced Encryption Standard (AES)") for detailed algorithm description of AES. -Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> -SPDX-License-Identifier: BSD-2-Clause-Patent + Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent **/ diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.h b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.h index 0afbe4cb14..6cc9873026 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.h +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.h @@ -1,8 +1,9 @@ /** @file Function prototype for AES Block Cipher support. -Copyright (c) 2013, Intel Corporation. All rights reserved.<BR> -SPDX-License-Identifier: BSD-2-Clause-Patent + Copyright (c) 2013, Intel Corporation. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent **/ diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c index 4b011c7e8e..c61357ee3f 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c @@ -1,15 +1,13 @@ /** @file - Support routines for RDRAND instruction access, which will leverage - Intel Secure Key technology to provide high-quality random numbers for use + Support routines for random number generation, which will leverage + the platform RngLib to provide high-quality random numbers for use in applications, or entropy for seeding other random number generators. - Refer to http://software.intel.com/en-us/articles/intel-digital-random-number - -generator-drng-software-implementation-guide/ for more information about Intel - Secure Key technology. -Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.<BR> -Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> -(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> -SPDX-License-Identifier: BSD-2-Clause-Patent + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.<BR> + Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> + (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include <Library/BaseLib.h> @@ -22,10 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent /** Creates a 128bit random value that is fully forward and backward prediction resistant, - suitable for seeding a NIST SP800-90 Compliant, FIPS 1402-2 certifiable SW DRBG. - This function takes multiple random numbers through RDRAND without intervening - delays to ensure reseeding and performs AES-CBC-MAC over the data to compute the - seed value. + suitable for seeding a NIST SP800-90 Compliant, FIPS 1402-2 certifiable SW DRBG using + the platform RngLib. @param[out] SeedBuffer Pointer to a 128bit buffer to store the random seed. @@ -84,7 +80,7 @@ RdRandGetSeed128 ( } /** - Generate high-quality entropy source through RDRAND. + Generate high-quality entropy source. @param[in] Length Size of the buffer, in bytes, to fill with. @param[out] Entropy Pointer to the buffer to store the entropy data. diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 8b0742bab6..416f733ff4 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -1,14 +1,12 @@ /** @file RNG Driver to produce the UEFI Random Number Generator protocol. - The driver will use the new RDRAND instruction to produce high-quality, high-performance - entropy and random number. + The driver uses the platform RngLib to produce high-quality, high-performance + entropy and random numbers. RNG Algorithms defined in UEFI 2.4: - EFI_RNG_ALGORITHM_SP800_90_CTR_256_GUID - Supported - (RDRAND implements a hardware NIST SP800-90 AES-CTR-256 based DRBG) - EFI_RNG_ALGORITHM_RAW - Supported - (Structuring RDRAND invocation can be guaranteed as high-quality entropy source) - EFI_RNG_ALGORITHM_SP800_90_HMAC_256_GUID - Unsupported - EFI_RNG_ALGORITHM_SP800_90_HASH_256_GUID - Unsupported - EFI_RNG_ALGORITHM_X9_31_3DES_GUID - Unsupported @@ -17,6 +15,7 @@ Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.<BR> Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -181,8 +180,6 @@ RngGetInfo ( } CopyMem (&RNGAlgorithmList[0], &gEfiRngAlgorithmSp80090Ctr256Guid, sizeof (EFI_RNG_ALGORITHM)); - - // x86 platforms also support EFI_RNG_ALGORITHM_RAW via RDSEED CopyMem (&RNGAlgorithmList[1], &gEfiRngAlgorithmRaw, sizeof (EFI_RNG_ALGORITHM)); *RNGAlgorithmListSize = RequiredSize; diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c index 292338b7d0..3c430894b3 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c @@ -1,8 +1,9 @@ /** @file RNG Driver to produce the UEFI Random Number Generator protocol. - The driver uses CPU RNG instructions to produce high-quality, - high-performance entropy and random number. + The driver uses the platform RngLib and/or architecture specific + instructions or firmware interface implementation to produce + high-quality, high-performance entropy and random numbers. RNG Algorithms defined in UEFI 2.4: - EFI_RNG_ALGORITHM_SP800_90_CTR_256_GUID @@ -12,10 +13,10 @@ - EFI_RNG_ALGORITHM_X9_31_3DES_GUID - EFI_RNG_ALGORITHM_X9_31_AES_GUID -Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> -(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> + Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> + (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> -SPDX-License-Identifier: BSD-2-Clause-Patent + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -118,7 +119,7 @@ RngDriverUnLoad ( } /** - Runs CPU RNG instruction to fill a buffer of arbitrary size with random bytes. + Fills a buffer of arbitrary size with random bytes. @param[in] Length Size of the buffer, in bytes, to fill with. @param[out] RandBuffer Pointer to the buffer to store the random result. diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf index fd5c1c9f99..9a126bae34 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -1,16 +1,16 @@ -## @file +## @file # Produces the UEFI Random Number Generator protocol # -# This module will leverage Intel Secure Key technology to produce the Random -# Number Generator protocol, which is used to provide high-quality random numbers -# for use in applications, or entropy for seeding other random number generators. -# Refer to http://software.intel.com/en-us/articles/intel-digital-random-number -# -generator-drng-software-implementation-guide/ for more information about Intel -# Secure Key technology. +# This module produces the Random Number Generator protocol, which is used to +# provide high-quality random numbers for use in applications, or entropy for +# seeding other random number generators. It relies on the platform RngLib and/or +# architecture specific instructions or firmware interface implementation to +# access the hardware random number source. # # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> # (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> # Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.<BR> +# # SPDX-License-Identifier: BSD-2-Clause-Patent # ## diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.uni b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.uni index 975c466330..dc5540500c 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.uni +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.uni @@ -1,12 +1,11 @@ // /** @file // Produces the UEFI Random Number Generator protocol // -// This module will leverage Intel Secure Key technology to produce the Random -// Number Generator protocol, which is used to provide high-quality random numbers -// for use in applications, or entropy for seeding other random number generators. -// Refer to http://software.intel.com/en-us/articles/intel-digital-random-number -// -generator-drng-software-implementation-guide/ for more information about Intel -// Secure Key technology. +// This module produces the Random Number Generator protocol, which is used to +// provide high-quality random numbers for use in applications, or entropy for +// seeding other random number generators. It relies on the platform RngLib and/or +// architecture specific instructions or firmware interface implementation to +// access the hardware random number source. // // Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> // diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeExtra.uni b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeExtra.uni index 0c7731e4f9..7f725e36db 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeExtra.uni +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeExtra.uni @@ -10,5 +10,3 @@ #string STR_PROPERTIES_MODULE_NAME #language en-US "UEFI Random Number Generator DXE" - - diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h index fc8c7db07b..9155d26383 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h @@ -101,7 +101,7 @@ RngGetRNG ( ); /** - Runs CPU RNG instruction to fill a buffer of arbitrary size with random bytes. + Fills a buffer of arbitrary size with random bytes. @param[in] Length Size of the buffer, in bytes, to fill with. @param[out] RandBuffer Pointer to the buffer to store the random result. @@ -118,7 +118,7 @@ RngGetBytes ( ); /** - Generate high-quality entropy source using a TRNG or through RDRAND. + Generate high-quality entropy source. @param[in] Length Size of the buffer, in bytes, to fill with. @param[out] Entropy Pointer to the buffer to store the entropy data. From 3613891d774d8a66c6fde2ae45a1f06a576d9684 Mon Sep 17 00:00:00 2001 From: Tuan Phan <tuan.phan@oss.qualcomm.com> Date: Thu, 9 Jul 2026 11:14:23 -0700 Subject: [PATCH 198/406] SecurityPkg/RngDxe: Support RISCV64 Add RISCV64 to the list of valid architectures. Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com> --- SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf index 9a126bae34..538db75e19 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -28,14 +28,14 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 RISCV64 # [Sources.common] RngDxe.c RngDxeInternals.h -[Sources.IA32, Sources.X64] +[Sources.IA32, Sources.X64, Sources.RISCV64] Rand/RngDxe.c Rand/RdRand.c Rand/AesCore.c From c70637de12e0d5cee78ebf5a0b5d09cdb1db53c9 Mon Sep 17 00:00:00 2001 From: Phil Noh <Phil.Noh@amd.com> Date: Thu, 25 Jun 2026 15:41:25 -0500 Subject: [PATCH 199/406] MdeModulePkg/PciBusDxe: Honor SpecificFlag for PMem64 in UpdatePciInfo When UpdatePciInfo() downgrades a PciBarTypePMem64 BAR to a 32-bit type via EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL, it unconditionally assigns PciBarTypePMem32 regardless of SpecificFlag, placing the BAR in the prefetchable bridge window even when the platform intended the non-prefetchable window. The ACPI resource descriptor's SpecificFlag field encodes the intended prefetchability of the constrained resource, using the bit: EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE. Fix this by checking the bit in SpecificFlag to select PciBarTypePMem32 or PciBarTypeMem32, consistent with DumpPpbPaddingResource() in PciEnumeratorSupport.c that uses the bit as the sole discriminator between the two 32-bit BAR types. Signed-off-by: Phil Noh <Phil.Noh@amd.com> --- MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c index a0f86f2806..ae94462f60 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c @@ -4,7 +4,7 @@ Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR> Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR> (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> -Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR> +Copyright (C) 2023 - 2026 Advanced Micro Devices, Inc. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -1595,7 +1595,14 @@ UpdatePciInfo ( if (PciIoDevice->PciBar[BarIndex].BarType == PciBarTypePMem64) { switch (Ptr->AddrSpaceGranularity) { case 32: - PciIoDevice->PciBar[BarIndex].BarType = PciBarTypePMem32; + if ((Ptr->SpecificFlag & EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE) == + EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE) + { + PciIoDevice->PciBar[BarIndex].BarType = PciBarTypePMem32; + } else { + PciIoDevice->PciBar[BarIndex].BarType = PciBarTypeMem32; + } + case 64: PciIoDevice->PciBar[BarIndex].BarTypeFixed = TRUE; break; From fa461abf8a51b09c965d15c0d65be704b8b00a19 Mon Sep 17 00:00:00 2001 From: Qihang Gao <gaoqihang@loongson.cn> Date: Thu, 25 Jun 2026 17:07:51 +0800 Subject: [PATCH 200/406] MdePkg/UefiDevicePathLib: Fix the potential memory leak issue The function DevPathToTextUsbWWID() allocates NewStr when the input SerialNumber lacks a null terminator. However, this allocated memory is never freed after use, resulting in a memory leak. This patch adds the missing FreePool() for NewStr before the function returns, ensuring that the allocated buffer is properly freed and eliminating the potential leak. Signed-off-by: Qihang Gao <gaoqihang@loongson.cn> --- MdePkg/Library/UefiDevicePathLib/DevicePathToText.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c index b0d5829e05..4b7ca27d01 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c @@ -996,6 +996,7 @@ DevPathToTextUsbWWID ( UINT16 Length; UsbWWId = DevPath; + NewStr = NULL; SerialNumberStr = (CHAR16 *)((UINT8 *)UsbWWId + sizeof (USB_WWID_DEVICE_PATH)); Length = (UINT16)((DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *)UsbWWId) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16)); @@ -1018,6 +1019,10 @@ DevPathToTextUsbWWID ( UsbWWId->InterfaceNumber, SerialNumberStr ); + + if (NewStr != NULL) { + FreePool (NewStr); + } } /** From 9fcb50d56cbec9e715024b5700cbbb318dcda742 Mon Sep 17 00:00:00 2001 From: Qihang Gao <gaoqihang@loongson.cn> Date: Fri, 26 Jun 2026 11:41:01 +0800 Subject: [PATCH 201/406] MdePkg/UefiDevicePathLib: Check allocated buffer before use The allocated buffer NewStr should be checked if it's NULL to avoid null pointer dereference. Signed-off-by: Qihang Gao <gaoqihang@loongson.cn> --- MdePkg/Library/UefiDevicePathLib/DevicePathToText.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c index 4b7ca27d01..db9b7eea5d 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c @@ -1006,6 +1006,10 @@ DevPathToTextUsbWWID ( // NewStr = AllocatePool ((Length + 1) * sizeof (CHAR16)); ASSERT (NewStr != NULL); + if (NewStr == NULL) { + return; + } + CopyMem (NewStr, SerialNumberStr, Length * sizeof (CHAR16)); NewStr[Length] = 0; SerialNumberStr = NewStr; From 2fc0e060efc25a2b9dd24bfc5844bf18e33b999e Mon Sep 17 00:00:00 2001 From: kowsiks <kowsiks@ami.com> Date: Tue, 31 Mar 2026 17:11:36 +0530 Subject: [PATCH 202/406] BaseTools/build.py: Use full source file path for dependency generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During Silent build,NMAKE suppresses the command echo entirely. As a result, the only output in ProcOut is the MSVC compiler’s output lines. Without the command echo, there is no full path in the output to identify which source file is currently being compiled. For unique basenames this is not an issue, but for namesake files (for example, AmdSev.c located in different directories), it is impossible to determine which file’s includes are being listed. This change improves dependency generation for MSVC builds by introducing explicit handling for source files with duplicate basenames (namesake sources). A new variable current_source_abs is added to consistently track the resolved absolute path of the active source file instead of repeatedly recomputing it from SourceFileAbsPathMap. To correctly resolve namesake files in silent builds (where compiler commands are not echoed), a namesake_queue is introduced, which preserves source ordering and sequentially maps basename occurrences to their corresponding full paths. Additionally, a cc_cmd_in_output flag is implemented to detect the presence of compiler command lines in the output stream; when present, source paths are derived directly from command-line arguments, otherwise the queue-based resolution is used. This ensures correct mapping of basenames to absolute paths across the silent builds, fixing incorrect dependency generation when multiple source files share the same name. Signed-off-by: Kowsik S <kowsiks@ami.com> --- .../Source/Python/AutoGen/IncludesAutoGen.py | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py b/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py index 5ec26eb98b..18ac5b8463 100644 --- a/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py +++ b/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py @@ -3,6 +3,7 @@ # # Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2020, ARM Limited. All rights reserved.<BR> +# Copyright (c) 2026, American Megatrends International LLC. All rights reserved.<BR> # SPDX-License-Identifier: BSD-2-Clause-Patent # from Common.caching import cached_property @@ -11,6 +12,7 @@ import Common.LongFilePathOs as os from Common.BuildToolError import * from Common.Misc import SaveFileOnChange, PathClass from Common.Misc import TemplateString +from collections import deque import sys gIsFileMap = {} @@ -191,12 +193,28 @@ ${END} return ModuleDepDict = {} current_source = "" + current_source_abs = "" SourceFileAbsPathMap = self.SourceFileList + namesake_queue = {} + cc_cmd_in_output = False + if self.HasNamesakeSourceFile: + basename_to_paths = {} + for _, (_, input_file) in sorted(self.TargetFileList.items()): + basename = os.path.basename(input_file.File) + if not basename: + continue + if basename not in basename_to_paths: + basename_to_paths[basename] = [] + basename_to_paths[basename].append(input_file.Path) + namesake_queue = { + k: deque(v) for k, v in basename_to_paths.items() if len(v) > 1 + } for line in DepList: line = line.strip() if self.HasNamesakeSourceFile: for cc_cmd in self.CcPPCommandPathSet: if cc_cmd in line: + cc_cmd_in_output = True if '''"'''+cc_cmd+'''"''' in line: cc_options = line[len(cc_cmd)+2:].split() else: @@ -214,13 +232,18 @@ ${END} # SourceFileAbsPathMap = {os.path.basename(item):item for item in cc_options if not item.startswith("/") and os.path.exists(item)} if line in SourceFileAbsPathMap: current_source = line - if current_source not in ModuleDepDict: - ModuleDepDict[SourceFileAbsPathMap[current_source]] = [] + if (self.HasNamesakeSourceFile and not cc_cmd_in_output + and line in namesake_queue and namesake_queue[line]): + current_source_abs = namesake_queue[line].popleft() + else: + current_source_abs = SourceFileAbsPathMap[current_source] + if current_source_abs not in ModuleDepDict: + ModuleDepDict[current_source_abs] = [] elif "Note: including file:" == line.lstrip()[:21]: if not current_source: EdkLogger.error("build",BUILD_ERROR, "Parse /showIncludes output failed. line: %s. \n" % line, RaiseError=False) else: - ModuleDepDict[SourceFileAbsPathMap[current_source]].append(line.lstrip()[22:].strip()) + ModuleDepDict[current_source_abs].append(line.lstrip()[22:].strip()) for source_abs in ModuleDepDict: if ModuleDepDict[source_abs]: From 7ac27b187e6063bef2023498da80396ff31467f6 Mon Sep 17 00:00:00 2001 From: Girish Mahadevan <gmahadevan@nvidia.com> Date: Mon, 20 Apr 2026 21:50:31 +0000 Subject: [PATCH 203/406] DynamicTablesPkg: Add System Information CM object and parser Add EArchCommonObjSystemInfo to ArchCommonNameSpaceObjects.h and a corresponding parser entry in ConfigurationManagerObjectParser.c. Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com> --- .../Include/ArchCommonNameSpaceObjects.h | 28 +++ .../ConfigurationManagerObjectParser.c | 180 +++++++++++------- 2 files changed, 142 insertions(+), 66 deletions(-) diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index 759dedc03b..da543b8495 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -93,6 +93,7 @@ typedef enum ArchCommonObjectID { EArchCommonObjMemoryChannelInfo, ///< 64 - Memory Channel Info EArchCommonObjMemoryChannelDevice, ///< 65 - Memory Channel Device Info EArchCommonObjProcessorSpecificBlockInfo, ///< 66 - Processor specific data Info + EArchCommonObjSystemInfo, ///< 67 - System Info EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1727,4 +1728,31 @@ typedef struct CmArchCommonProcessorSpecificBlockInfo { CM_OBJECT_TOKEN ArchProcessorSpecificDataToken; } CM_ARCH_COMMON_PROCESSOR_SPECIFIC_BLOCK_INFO; +/** A structure that describes System Information. + + SMBIOS Specification v3.9.0 Type 1 + + ID: EArchCommonObjSystemInfo +**/ +typedef struct CmArchCommonSystemInfo { + /// CM Object Token uniquely identifying this System Information entry. + CM_OBJECT_TOKEN SystemInfoToken; + /// Manufacturer of the system. + CHAR8 Manufacturer[SMBIOS_MAX_STRING_SIZE]; + /// Product name of the system. + CHAR8 ProductName[SMBIOS_MAX_STRING_SIZE]; + /// Version of the system. + CHAR8 Version[SMBIOS_MAX_STRING_SIZE]; + /// Serial number of the system. + CHAR8 SerialNum[SMBIOS_MAX_STRING_SIZE]; + /// Universal unique ID of the system. + GUID Uuid; + /// Identifies the event that caused the system to power up. + UINT8 WakeUpType; + /// SKU number of the system. + CHAR8 SkuNum[SMBIOS_MAX_STRING_SIZE]; + /// Family that the system belongs to. + CHAR8 Family[SMBIOS_MAX_STRING_SIZE]; +} CM_ARCH_COMMON_SYSTEM_INFO; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index 7b3f612866..77b94121f3 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -41,6 +41,15 @@ PrintChars ( UINT32 Length ); +STATIC +VOID +EFIAPI +PrintGuid ( + CONST CHAR8 *Format, + UINT8 *Ptr, + UINT32 Length + ); + STATIC VOID EFIAPI @@ -1320,76 +1329,92 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonSystemResetInfoParser[] = { { "Timeout", sizeof (UINT16), "0x%x", NULL }, }; +/** A parser for EArchCommonObjSystemInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonSystemInfoParser[] = { + { "SystemInfoToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "Manufacturer", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "ProductName", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "Version", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "SerialNum", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "Uuid", sizeof (GUID), NULL, PrintGuid }, + { "WakeUpType", sizeof (UINT8), "0x%x", NULL }, + { "SkuNum", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "Family", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, +}; + /** A parser for Arch Common namespace objects. */ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjReserved), - CM_PARSER_ADD_OBJECT (EArchCommonObjPowerManagementProfileInfo, CmArchCommonPowerManagementProfileInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjSerialPortInfo, CmArchCommonSerialPortInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjConsolePortInfo, CmArchCommonSerialPortInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjSerialDebugPortInfo, CmArchCommonSerialPortInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjHypervisorVendorIdentity, CmArchCommonHypervisorVendorIdentityParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjFixedFeatureFlags, CmArchCommonFixedFeatureFlagsParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjCmRef, CmArchCommonObjRefParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPciConfigSpaceInfo, CmArchCommonPciConfigSpaceInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPciAddressMapInfo, CmArchCommonPciAddressMapInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPciInterruptMapInfo, CmArchCommonPciInterruptMapInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryAffinityInfo, CmArchCommonMemoryAffinityInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjDeviceHandleAcpi, CmArchCommonDeviceHandleAcpiParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjDeviceHandlePci, CmArchCommonDeviceHandlePciParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjGenericInitiatorAffinityInfo, CmArchCommonGenericInitiatorAffinityInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjLpiInfo, CmArchCommonLpiInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjProcHierarchyInfo, CmArchCommonProcHierarchyInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjCacheInfo, CmArchCommonCacheInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjCpcInfo, CmArchCommonCpcInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType0Info, CmArchCommonPccSubspaceType0InfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType1Info, CmArchCommonPccSubspaceType1InfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType2Info, CmArchCommonPccSubspaceType2InfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType3Info, CmArchCommonPccSubspaceType34InfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType4Info, CmArchCommonPccSubspaceType34InfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType5Info, CmArchCommonPccSubspaceType5InfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPsdInfo, CmArchCommonPsdInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjTpm2InterfaceInfo, CmArchCommonTpm2InterfaceInfo), - CM_PARSER_ADD_OBJECT (EArchCommonObjSpmiInterfaceInfo, CmArchCommonSpmiInterfaceInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjSpmiInterruptDeviceInfo, CmArchCommonSpmiInterruptDeviceInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjCstInfo, CmArchCommonCstInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjCsdInfo, CmArchCommonCsdInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPctInfo, CmArchCommonPctInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPssInfo, CmArchCommonPssInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPpcInfo, CmArchCommonPpcInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjStaInfo, CmArchCommonStaInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryRangeDescriptor, CmArchCommonObjMemoryRangeDescriptor), - CM_PARSER_ADD_OBJECT (EArchCommonObjGenericDbg2DeviceInfo, CmArchCommonObjDbg2DeviceInfo), - CM_PARSER_ADD_OBJECT (EArchCommonObjCxlHostBridgeInfo, CmArchCommonObjCxlHostBridgeInfo), - CM_PARSER_ADD_OBJECT (EArchCommonObjCxlFixedMemoryWindowInfo, CmArchCommonObjCxlFixedMemoryWindowInfo), - CM_PARSER_ADD_OBJECT (EArchCommonObjProximityDomainInfo, CmArchCommonProximityDomainInfo), - CM_PARSER_ADD_OBJECT (EArchCommonObjProximityDomainRelationInfo, CmArchCommonProximityDomainRelationInfo), - CM_PARSER_ADD_OBJECT (EArchCommonObjSystemLocalityInfo, CmArchCommonSystemLocalityInfo), - CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryProximityDomainAttrInfo,CmArchCommonMemoryProximityDomainAttrInfo), - CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryLatBwInfo, CmArchCommonMemoryLatBwInfo), - CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryCacheInfo, CmArchCommonMemoryCacheInfo), - CM_PARSER_ADD_OBJECT (EArchCommonObjSpcrInfo, CmArchCommonObjSpcrInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjTpm2DeviceInfo, CmArchCommonObjTpm2DeviceInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjMcfgPciConfigSpaceInfo, CmArchCommonPciConfigSpaceInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPciRootPortInfo, CmArchCommonObjPciRootPortInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjErrSourcePciRootPortInfo, CmArchCommonObjErrSourcePciRootPortInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjErrSourcePciDeviceInfo, CmArchCommonObjErrSourcePciDeviceInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjErrSourcePciBridgeInfo, CmArchCommonObjErrSourcePciBridgeInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjErrSourceGenericHwInfo, CmArchCommonObjErrSourceGenericHwInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjErrSourceGenericHwVer2Info, CmArchCommonObjErrSourceGenericHwVer2InfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjEinjInstructionsInfo, CmArchCommonObjEinjInstructionsInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPlatformFwInfo, CmArchCommonPlatformFwInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjPhysicalMemoryArray, CmArchCommonPhysicalMemoryArrayParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryDeviceInfo, CmArchCommonMemoryDeviceInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryArrayMappedAddress, CmArchCommonMemoryArrayMappedAddressParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjCoolingDeviceInfo, CmArchCommonCoolingDeviceInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjTemperatureProbeInfo, CmArchCommonTemperatureProbeInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjVoltageProbeInfo, CmArchCommonVoltageProbeInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjElectricalCurrentProbeInfo, CmArchCommonElectricalCurrentProbeInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjSystemResetInfo, CmArchCommonSystemResetInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryDeviceMappedAddress, CmArchCommonMemoryDeviceMappedAddressParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryChannelInfo, CmArchCommonMemoryChannelInfoParser), - CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryChannelDevice, CmArchCommonMemoryChannelDeviceParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPowerManagementProfileInfo, CmArchCommonPowerManagementProfileInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjSerialPortInfo, CmArchCommonSerialPortInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjConsolePortInfo, CmArchCommonSerialPortInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjSerialDebugPortInfo, CmArchCommonSerialPortInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjHypervisorVendorIdentity, CmArchCommonHypervisorVendorIdentityParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjFixedFeatureFlags, CmArchCommonFixedFeatureFlagsParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjCmRef, CmArchCommonObjRefParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPciConfigSpaceInfo, CmArchCommonPciConfigSpaceInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPciAddressMapInfo, CmArchCommonPciAddressMapInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPciInterruptMapInfo, CmArchCommonPciInterruptMapInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryAffinityInfo, CmArchCommonMemoryAffinityInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjDeviceHandleAcpi, CmArchCommonDeviceHandleAcpiParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjDeviceHandlePci, CmArchCommonDeviceHandlePciParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjGenericInitiatorAffinityInfo, CmArchCommonGenericInitiatorAffinityInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjLpiInfo, CmArchCommonLpiInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjProcHierarchyInfo, CmArchCommonProcHierarchyInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjCacheInfo, CmArchCommonCacheInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjCpcInfo, CmArchCommonCpcInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType0Info, CmArchCommonPccSubspaceType0InfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType1Info, CmArchCommonPccSubspaceType1InfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType2Info, CmArchCommonPccSubspaceType2InfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType3Info, CmArchCommonPccSubspaceType34InfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType4Info, CmArchCommonPccSubspaceType34InfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPccSubspaceType5Info, CmArchCommonPccSubspaceType5InfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPsdInfo, CmArchCommonPsdInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjTpm2InterfaceInfo, CmArchCommonTpm2InterfaceInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjSpmiInterfaceInfo, CmArchCommonSpmiInterfaceInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjSpmiInterruptDeviceInfo, CmArchCommonSpmiInterruptDeviceInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjCstInfo, CmArchCommonCstInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjCsdInfo, CmArchCommonCsdInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPctInfo, CmArchCommonPctInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPssInfo, CmArchCommonPssInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPpcInfo, CmArchCommonPpcInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjStaInfo, CmArchCommonStaInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryRangeDescriptor, CmArchCommonObjMemoryRangeDescriptor), + CM_PARSER_ADD_OBJECT (EArchCommonObjGenericDbg2DeviceInfo, CmArchCommonObjDbg2DeviceInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjCxlHostBridgeInfo, CmArchCommonObjCxlHostBridgeInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjCxlFixedMemoryWindowInfo, CmArchCommonObjCxlFixedMemoryWindowInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjProximityDomainInfo, CmArchCommonProximityDomainInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjProximityDomainRelationInfo, CmArchCommonProximityDomainRelationInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjSystemLocalityInfo, CmArchCommonSystemLocalityInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryProximityDomainAttrInfo, CmArchCommonMemoryProximityDomainAttrInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryLatBwInfo, CmArchCommonMemoryLatBwInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryCacheInfo, CmArchCommonMemoryCacheInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjSpcrInfo, CmArchCommonObjSpcrInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjTpm2DeviceInfo, CmArchCommonObjTpm2DeviceInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMcfgPciConfigSpaceInfo, CmArchCommonPciConfigSpaceInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPciRootPortInfo, CmArchCommonObjPciRootPortInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjErrSourcePciRootPortInfo, CmArchCommonObjErrSourcePciRootPortInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjErrSourcePciDeviceInfo, CmArchCommonObjErrSourcePciDeviceInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjErrSourcePciBridgeInfo, CmArchCommonObjErrSourcePciBridgeInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjErrSourceGenericHwInfo, CmArchCommonObjErrSourceGenericHwInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjErrSourceGenericHwVer2Info, CmArchCommonObjErrSourceGenericHwVer2InfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjEinjInstructionsInfo, CmArchCommonObjEinjInstructionsInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPlatformFwInfo, CmArchCommonPlatformFwInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjPhysicalMemoryArray, CmArchCommonPhysicalMemoryArrayParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryDeviceInfo, CmArchCommonMemoryDeviceInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryArrayMappedAddress, CmArchCommonMemoryArrayMappedAddressParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjCoolingDeviceInfo, CmArchCommonCoolingDeviceInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjTemperatureProbeInfo, CmArchCommonTemperatureProbeInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjVoltageProbeInfo, CmArchCommonVoltageProbeInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjElectricalCurrentProbeInfo, CmArchCommonElectricalCurrentProbeInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjSystemResetInfo, CmArchCommonSystemResetInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryDeviceMappedAddress, CmArchCommonMemoryDeviceMappedAddressParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryChannelInfo, CmArchCommonMemoryChannelInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryChannelDevice, CmArchCommonMemoryChannelDeviceParser), + CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjProcessorSpecificBlockInfo), + CM_PARSER_ADD_OBJECT (EArchCommonObjSystemInfo, CmArchCommonSystemInfoParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; @@ -1786,6 +1811,29 @@ PrintString ( DEBUG ((DEBUG_INFO, "%a", Ptr)); } +/** Print GUID data. + + @param [in] Format Format to print the Ptr. + @param [in] Ptr Pointer to the GUID. + @param [in] Length Length of the field. +**/ +STATIC +VOID +EFIAPI +PrintGuid ( + IN CONST CHAR8 *Format, + IN UINT8 *Ptr, + IN UINT32 Length + ) +{ + if ((Ptr == NULL) || (Length != sizeof (GUID))) { + ASSERT (0); + return; + } + + DEBUG ((DEBUG_INFO, "%g", (GUID *)Ptr)); +} + /** Print string from pointer. The string must be NULL terminated. From 9b583dfc4b7359f6a6ee1e1e327e1bfd12948467 Mon Sep 17 00:00:00 2001 From: Girish Mahadevan <gmahadevan@nvidia.com> Date: Mon, 20 Apr 2026 21:50:31 +0000 Subject: [PATCH 204/406] DynamicTablesPkg: Smbios System Information (Type 1) Generator for Smbios System Information table (Type 1). Co-authored-by: Dat Mach <dmach@nvidia.com> Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com> --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../SmbiosType1Lib/SmbiosType1Generator.c | 428 ++++++++++++++++++ .../Smbios/SmbiosType1Lib/SmbiosType1Lib.inf | 37 ++ 3 files changed, 467 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index 6acdcd1a52..ada6562661 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -53,6 +53,7 @@ # SMBIOS Generators (Common) DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf @@ -171,6 +172,7 @@ NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtPcieLib/SsdtPcieLib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Generator.c new file mode 100644 index 0000000000..139bccb3bc --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Generator.c @@ -0,0 +1,428 @@ +/** @file + SMBIOS Type 1 Table Generator. + + Copyright (c) 2024 - 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/SmbiosStringTableLib.h> + +// Module specific include files. +#include <ConfigurationManagerObject.h> +#include <ConfigurationManagerHelper.h> +#include <Protocol/ConfigurationManagerProtocol.h> +#include <Protocol/DynamicTableFactoryProtocol.h> +#include <Protocol/Smbios.h> +#include <IndustryStandard/SmBios.h> + +#define SMBIOS_TYPE1_MAX_STRINGS (6) + +#define ALL_ONES_GUID \ + { 0xFFFFFFFF, 0xFFFF, 0xFFFF, { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } } + +/** This macro expands to a function that retrieves the System + information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjSystemInfo, + CM_ARCH_COMMON_SYSTEM_INFO + ) + +/** + Validate an SMBIOS Type 1 Wake-up Type field value. + + @param [in] WakeUpType Wake-up Type value provided by the Configuration + Manager. + + @retval EFI_SUCCESS The Wake-up Type is valid. + @retval EFI_INVALID_PARAMETER The Wake-up Type is invalid. +**/ +STATIC +EFI_STATUS +CheckWakeUpType ( + IN UINT8 WakeUpType + ) +{ + if ((WakeUpType == SystemWakeupTypeReserved) || + (WakeUpType == SystemWakeupTypeUnknown) || + (WakeUpType > SystemWakeupTypeAcPowerRestored)) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid WakeUpType 0x%x\n", + __func__, + WakeUpType + )); + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** Validate SMBIOS Type 1 System Information. + + Validation follows SMBIOS Specification v3.9.0, Annex A, + Section 4.2 (informative). + + @param [in] SystemInfo System Information provided by the Configuration + Manager. + + @retval EFI_SUCCESS The System Information is valid. + @retval EFI_INVALID_PARAMETER The System Information is invalid. +**/ +STATIC +EFI_STATUS +ValidateSystemInfo ( + IN CONST CM_ARCH_COMMON_SYSTEM_INFO *SystemInfo + ) +{ + CONST GUID AllOnesGuid = ALL_ONES_GUID; + + if ((SystemInfo->Manufacturer[0] == '\0') || + (SystemInfo->ProductName[0] == '\0')) + { + DEBUG (( + DEBUG_ERROR, + "%a: Manufacturer and ProductName must be non-empty\n", + __func__ + )); + return EFI_INVALID_PARAMETER; + } + + if (IsZeroGuid (&SystemInfo->Uuid) || CompareGuid (&SystemInfo->Uuid, &AllOnesGuid)) { + DEBUG ((DEBUG_ERROR, "%a: UUID must not be all-zero or all-ones\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + return CheckWakeUpType (SystemInfo->WakeUpType); +} + +/** + Free any resources allocated when installing SMBIOS Type 1 table. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the SMBIOS table. + + @retval EFI_SUCCESS Table freed successfully. +**/ +STATIC +EFI_STATUS +FreeSmbiosType1Table ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE **Table + ) +{ + if (*Table != NULL) { + FreePool (*Table); + } + + return EFI_SUCCESS; +} + +/** Construct SMBIOS Type 1 Table describing system information. + + If this function allocates any resources then they must be freed + in the FreeSmbiosType1Table function. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the SMBIOS table. + @param [out] CmObjToken Pointer to the CM Object Token. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +BuildSmbiosType1Table ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE **Table, + OUT CM_OBJECT_TOKEN *CmObjToken + ) +{ + EFI_STATUS Status; + CM_ARCH_COMMON_SYSTEM_INFO *SystemInfo; + UINT32 SystemInfoCount; + UINT8 ManufacturerRef; + UINT8 ProductNameRef; + UINT8 VersionRef; + UINT8 SerialNumRef; + UINT8 SkuNumRef; + UINT8 FamilyRef; + CHAR8 *OptionalStrings; + SMBIOS_TABLE_TYPE1 *SmbiosRecord; + UINTN SmbiosRecordSize; + STRING_TABLE StrTable; + + SmbiosRecord = NULL; + + ASSERT (This != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Table != NULL); + ASSERT (CmObjToken != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || + (SmbiosTableInfo == NULL) || + (CfgMgrProtocol == NULL) || + (Table == NULL) || + (CmObjToken == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + // + // Retrieve system info from CM object + // + *Table = NULL; + Status = GetEArchCommonObjSystemInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &SystemInfo, + &SystemInfoCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get System CM Object %r\n", + __func__, + Status + )); + return Status; + } + + if (SystemInfoCount != 1) { + DEBUG (( + DEBUG_ERROR, + "%a: Expected one System Information object, got %u\n", + __func__, + SystemInfoCount + )); + return EFI_INVALID_PARAMETER; + } + + Status = ValidateSystemInfo (SystemInfo); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Copy strings to SMBIOS table + // + Status = StringTableInitialize (&StrTable, SMBIOS_TYPE1_MAX_STRINGS); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to initialize string table %r\n", __func__, Status)); + return Status; + } + + ManufacturerRef = 0; + ProductNameRef = 0; + VersionRef = 0; + SerialNumRef = 0; + SkuNumRef = 0; + FamilyRef = 0; + + if (SystemInfo->Manufacturer[0] != '\0') { + Status = StringTableAddString (&StrTable, SystemInfo->Manufacturer, &ManufacturerRef); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to add Manufacturer string %r\n", __func__, Status)); + goto ErrorExit; + } + } + + if (SystemInfo->ProductName[0] != '\0') { + Status = StringTableAddString (&StrTable, SystemInfo->ProductName, &ProductNameRef); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to add ProductName string %r\n", __func__, Status)); + goto ErrorExit; + } + } + + if (SystemInfo->Version[0] != '\0') { + Status = StringTableAddString (&StrTable, SystemInfo->Version, &VersionRef); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to add Version string %r\n", __func__, Status)); + goto ErrorExit; + } + } + + if (SystemInfo->SerialNum[0] != '\0') { + Status = StringTableAddString (&StrTable, SystemInfo->SerialNum, &SerialNumRef); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to add SerialNum string %r\n", __func__, Status)); + goto ErrorExit; + } + } + + if (SystemInfo->SkuNum[0] != '\0') { + Status = StringTableAddString (&StrTable, SystemInfo->SkuNum, &SkuNumRef); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to add SkuNum string %r\n", __func__, Status)); + goto ErrorExit; + } + } + + if (SystemInfo->Family[0] != '\0') { + Status = StringTableAddString (&StrTable, SystemInfo->Family, &FamilyRef); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to add Family string %r\n", __func__, Status)); + goto ErrorExit; + } + } + + SmbiosRecordSize = sizeof (SMBIOS_TABLE_TYPE1) + + StringTableGetStringSetSize (&StrTable); + SmbiosRecord = (SMBIOS_TABLE_TYPE1 *)AllocateZeroPool (SmbiosRecordSize); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ErrorExit; + } + + SmbiosRecord->Manufacturer = ManufacturerRef; + SmbiosRecord->ProductName = ProductNameRef; + SmbiosRecord->Version = VersionRef; + SmbiosRecord->SerialNumber = SerialNumRef; + SmbiosRecord->SKUNumber = SkuNumRef; + SmbiosRecord->Family = FamilyRef; + + OptionalStrings = (CHAR8 *)(SmbiosRecord + 1); + // publish the string set + Status = StringTablePublishStringSet ( + &StrTable, + OptionalStrings, + (SmbiosRecordSize - sizeof (SMBIOS_TABLE_TYPE1)) + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to publish string set %r\n", __func__, Status)); + goto ErrorExit; + } + + // + // Fill in other fields of SMBIOS table + // + CopyGuid (&SmbiosRecord->Uuid, &SystemInfo->Uuid); + SmbiosRecord->WakeUpType = SystemInfo->WakeUpType; + + // + // Setup SMBIOS header + // + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_INFORMATION; + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE1); + + *Table = (SMBIOS_STRUCTURE *)SmbiosRecord; + *CmObjToken = SystemInfo->SystemInfoToken; + Status = EFI_SUCCESS; + +ErrorExit: + if (EFI_ERROR (Status) && (SmbiosRecord != NULL)) { + FreePool (SmbiosRecord); + } + + // free string table + StringTableFree (&StrTable); + return Status; +} + +/** The interface for the SMBIOS Type 1 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType1Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType01), + // Generator Description + L"SMBIOS.TYPE1.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_SYSTEM_INFORMATION, + // Build table function + BuildSmbiosType1Table, + // Free function + FreeSmbiosType1Table, + NULL, + NULL +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType1LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType1Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 1: Register Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType1LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType1Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type1: Deregister Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Lib.inf new file mode 100644 index 0000000000..674bf6594c --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Lib.inf @@ -0,0 +1,37 @@ +## @file +# SMBIOS Type 1 Table Generator +# +# Copyright (c) 2024 - 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType1LibArm + FILE_GUID = c4b1cb30-5652-11ed-9d3f-7fb5379f6d11 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType1LibConstructor + DESTRUCTOR = SmbiosType1LibDestructor + +[Sources] + SmbiosType1Generator.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[Protocols] + gEfiSmbiosProtocolGuid # PROTOCOL ALWAYS_CONSUMED + +[LibraryClasses] + BaseLib + DebugLib + SmbiosStringTableLib + MemoryAllocationLib From 74b8bfd953a7458a5452bef81a390e964271bc27 Mon Sep 17 00:00:00 2001 From: VarshitPandya <varshit.pandya@arm.com> Date: Wed, 15 Jul 2026 10:17:43 +0100 Subject: [PATCH 205/406] MdeModulePkg: Add definition for 64 bit ACPI GAS Add a macro definition for defining ACPI Generic Address Space for QWORD memory. Signed-off-by: Varshit Pandya <varshit.pandya@arm.com> --- MdeModulePkg/Include/AcpiHelperMacros.h | 1 + 1 file changed, 1 insertion(+) diff --git a/MdeModulePkg/Include/AcpiHelperMacros.h b/MdeModulePkg/Include/AcpiHelperMacros.h index 5a34720bc9..93d1fd1617 100644 --- a/MdeModulePkg/Include/AcpiHelperMacros.h +++ b/MdeModulePkg/Include/AcpiHelperMacros.h @@ -17,6 +17,7 @@ #define ACPI_GAS8(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 8, 0, EFI_ACPI_5_0_BYTE, Address } #define ACPI_GAS16(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 16, 0, EFI_ACPI_5_0_WORD, Address } #define ACPI_GAS32(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 32, 0, EFI_ACPI_5_0_DWORD, Address } +#define ACPI_GAS64(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 64, 0, EFI_ACPI_5_0_QWORD, Address } #define ACPI_GASN(Address) { EFI_ACPI_5_0_SYSTEM_MEMORY, 0, 0, EFI_ACPI_5_0_DWORD, Address } // From a59064933f698e7c192063d04157c302d3efc257 Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Thu, 11 Jun 2026 15:27:01 -0400 Subject: [PATCH 206/406] BaseTools/Trim.py: Strip "#pragma once" from inlined ASL content When Trim processes an ASL file (`--asl-file`), it textually inlines the body of every `Include()`'d file directly into the constructed preprocessor input, once per include site. Its has duplicate protection in the form of a circular-include stack (`gIncludedAslFile`), that prevents A->B->A cycles. But, as far as the script is concerned, each `Include()` is a unique include site. Various combinations of includes and file types are possible and handled slightly differently. Starting with file types as defined in BaseTools\Conf\build_rule.template: - `.aslc`, `.act` files fall under `Acpi-Table-Code-File` and are compiled, linked, and processed by genfw. - `.asl`, `.Asl`, and `.ASL` files fall in `Acpi-Source-Language-File` and are processed by Trim: 1. `Trim --asl-file` to produce a single combined .i file with includes inlined. 2. `ASLPP` (ASL preprocessor, a C preprocessor) on the output of Trim to produce a .iii file with all macros expanded and conditional branches resolved. AutoGen.h is also included and processed here to resolve fixed PCD values if needed. 3. `Trim --source-code` which takes the pre-processed .iii file and produces a .iiii file with content like linemarkers cleaned up. 4. The ACPI compiler compiles the .iiii file to produce AML bytecode in a .aml file. Because the `.aslc`/`.act` files are directly passed to normal C processing tools, they are not part of the Trim change made in this commit and the remainder of this message focuses on the ACPI Source Language File case. ASL files can use either an ASL `Include()` directive or a C-style `#include` directive. In addition, different file types may be included such as a `.asl` file or a `.h` file. `Trim` handles these cases differently: - For ASL `Include()` directives, `Trim` inlines the content of the included file directly into the output at the include site. This is done for all included ASL files regardless of their extension. The inlining is purely textual and does not attempt to resolve or preserve any preprocessor directives such as `#pragma once` or include guards. - For C-style `#include` directives, `Trim` checks the file extension of the included file. If the file is an ASL file (`.asl` or `.asi`), `Trim` treats the file the same as the `Include()` case. Otherwise, `Trim` passes the directive through verbatim to the output, allowing the downstream C preprocessor (`ASLPP`) to handle it according to normal C preprocessor rules. This creates a situtation in which the resulting `.i` might include: - Inlined file content (from a `.asl` or `.h` file) depending on the include type and file extension. - Verbatim `#include` directives for non-ASL files which will be processed by the C preprocessor. Focusing on the "inlined" case, historically `.h` files would have traditional C include guards (`#ifndef`/`#define`, `#endif`). However, files might also include `#pragma once` as a guard. In that case, the inlined content of the `.i` file could contain multiple `#pragma once` directives, one per include site. When the C preprocessor (`ASLPP`) processes the `.i` file, it sees multiple `#pragma once` directives in what it considers the main file, and could emit a warning like the following from gcc: warning: '#pragma once' in main file [-Wpragma-once-outside-header] The remainder of this commit message describes the change made to address this warning. This change strips "#pragma once" lines on the ASL content path in `DoInclude()` in `Trim.py` so the directive is removed before it reaches the C preprocessor. - "#include" directives for non-ASL files are still passed through verbatim for the C preprocessor to resolve where the contents of those .h files might contain "#pragma once" or traditional guards. - Traditional include guards are untouched and continue to behave as before where multiple include sites might inline the same content in the .i file before reaching the C preprocessor. The change: In the case that a file is inlined with a `#pragma once` directive, the directive is stripped from the inlined content which prevents the warning. This is considered acceptable because it only removes the `#pragma once` directive from the inlined content for these specific cases. So, the `.i` file might contain multiple inlined copies of the same header content (like always in this inline case) but without the `#pragma once` directives. Because actual C content was already not processed or trimmed out (e.g. `typedef struct`) duplicate content is not considered to be a problem (`#define` multiple times is not a problem for the C preprocessor). Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- BaseTools/Source/Python/Trim/Trim.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BaseTools/Source/Python/Trim/Trim.py b/BaseTools/Source/Python/Trim/Trim.py index c753cde5a5..844519431d 100644 --- a/BaseTools/Source/Python/Trim/Trim.py +++ b/BaseTools/Source/Python/Trim/Trim.py @@ -54,6 +54,8 @@ gLongNumberPattern = re.compile(r"(?<=[^a-zA-Z0-9_])(0[xX][0-9a-fA-F]+|[0-9]+)U? gAslIncludePattern = re.compile(r"^(\s*)[iI]nclude\s*\(\"?([^\"\(\)]+)\"\)", re.MULTILINE) ## Regular expression for matching C style #include "XXX.asl" in asl file gAslCIncludePattern = re.compile(r'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\s*([>"])', re.MULTILINE) +## Regular expression for matching "#pragma once" +gPragmaOncePattern = re.compile(r"^\s*#\s*pragma\s+once\b", re.IGNORECASE) ## Patterns used to convert EDK conventions to EDK2 ECP conventions ## Regular expression for finding header file inclusions @@ -328,6 +330,8 @@ def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None, Inclu if len(Result) == 0: Result = gAslCIncludePattern.findall(Line) if len(Result) == 0 or os.path.splitext(Result[0][1])[1].lower() not in [".asl", ".asi"]: + if gPragmaOncePattern.match(Line): + continue NewFileContent.append("%s%s" % (Indent, Line)) continue # From 21b358b81d8fd9d9b9a09a344bace41c13017d37 Mon Sep 17 00:00:00 2001 From: Vincent Gatine <vincent.gatine@sipearl.com> Date: Wed, 8 Jul 2026 11:33:26 +0200 Subject: [PATCH 207/406] ShellPkg/Pci: Restore BAR informations Restore informations lost in the pci shell command. sbsa-ref Host Bridge: ``` Cache Line Size(C): 00 Latency Timer(D): 00 Header Type(0E): 00, Single function, PCI device Class: Bridge Device - Host/PCI bridge - +Base Address Registers(10): + (None) +Expansion ROM Disabled(30) + +Cardbus CIS ptr(28): 00000000 +Sub VendorID(2C): 1AF4 Subsystem ID(2E): 1100 +Capabilities Ptr(34): 00 +Interrupt Line(3C): FF Interrupt Pin(3D): 00 +Min_Gnt(3E): 00 Max_Lat(3F): 00 ``` sbsa-ref Ethernet Controller: ``` Cache Line Size(C): 00 Latency Timer(D): 00 Header Type(0E): 00, Single function, PCI device Class: Network Controller - Ethernet controller - +Base Address Registers(10): + Start_Address Type Space Prefetchable? Size Limit + -------------------------------------------------------------------------- + 81060000 Mem 32 bits No 00020000 8107FFFF + 81040000 Mem 32 bits No 00020000 8105FFFF + 0000 I/O 0020 001F + 81080000 Mem 32 bits No 00004000 81083FFF + -------------------------------------------------------------------------- +Expansion ROM Disabled(30) + +Cardbus CIS ptr(28): 00000000 +Sub VendorID(2C): 8086 Subsystem ID(2E): 0000 +Capabilities Ptr(34): C8 +Interrupt Line(3C): FF Interrupt Pin(3D): 01 +Min_Gnt(3E): 00 Max_Lat(3F): 00 Pci Express device capability structure: CapID( 0): 10 NextCap Ptr( 1): A0 ``` Signed-off-by: Vincent Gatine <vincent.gatine@sipearl.com> --- .../Library/UefiShellDebug1CommandsLib/Pci.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c index 5169646826..6410dda30b 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -3286,6 +3286,22 @@ PciExplainPci ( ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI2_CLASS), gShellDebug1HiiHandle); PciPrintClassCode ((UINT8 *)Common->ClassCode, TRUE); ShellPrintDefaultEx (L"\r\n"); + + switch (HeaderType) { + case PciDevice: + PciExplainDeviceData (&ConfigSpace->NonCommon.Device, Address, IoDev); + break; + + case PciP2pBridge: + PciExplainBridgeData (&ConfigSpace->NonCommon.Bridge, Address, IoDev); + break; + + case PciCardBusBridge: + PciExplainCardBusData (&ConfigSpace->NonCommon.CardBus, Address, IoDev); + break; + + default:; + } } /** From 8f5a348a9d0502b041f76ab6cbb0d2b9d8599c24 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Mon, 13 Jul 2026 17:44:44 -0700 Subject: [PATCH 208/406] MdePkg: BaseMemoryLib: Add memory barrier to SetMem The implementation adds a toolchain-specific compiler barriers to discourage reordering under aggressive optimization around memory setting operations. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- MdePkg/Library/BaseMemoryLib/MemLibGeneric.c | 44 +++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c b/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c index b02fc0c4d8..646403accd 100644 --- a/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c +++ b/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c @@ -13,6 +13,41 @@ #include "MemLibInternals.h" +#if defined (_MSC_VER) && !defined (__GNUC__) && !defined (__clang__) +VOID +_ReadWriteBarrier ( + VOID + ); + + #pragma intrinsic(_ReadWriteBarrier) +#endif + +/** + Emit a compiler barrier that keeps the compiler from scheduling any later + memory access ahead of the preceding buffer clear. + + It emits no instructions; it only constrains compile-time ordering, and the + constraint holds even when the caller is inlined under LTO. + +**/ +STATIC +VOID +InternalMemBarrier ( + VOID + ) +{ + #if defined (__GNUC__) || defined (__clang__) + __asm__ __volatile__ ("" : : : "memory"); + #elif defined (_MSC_VER) + _ReadWriteBarrier (); + #else + // + // No portable compiler barrier is available for this toolchain. + // + #error "InternalMemBarrier: no compiler barrier is defined for this toolchain." + #endif +} + /** Fills a target buffer with a 16-bit value, and returns the target buffer. @@ -104,7 +139,14 @@ InternalMemZeroMem ( IN UINTN Length ) { - return InternalMemSetMem (Buffer, Length, 0); + // + // Zero the buffer through the worker, then emit a compiler barrier so a + // caller's subsequent store cannot be scheduled ahead of the clear. + // + Buffer = InternalMemSetMem (Buffer, Length, 0); + InternalMemBarrier (); + + return Buffer; } /** From 5309cdb92c5552e64fce7648ec15d0ab497b1161 Mon Sep 17 00:00:00 2001 From: "Michael G.A. Holland" <michael.holland@intel.com> Date: Fri, 17 Jul 2026 10:39:18 -0700 Subject: [PATCH 209/406] CryptoPkg/BaseCryptLib: EdDsa updates Include validation checks for Context and ContextSize in sign and verify functions. Returned FALSE for EdDsaGeneratePubKey. Updated ReadMe to show EdDsa support Signed-off-by: Michael G.A. Holland <michael.holland@intel.com> --- CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsa.c | 10 +++++++++- CryptoPkg/Readme.md | 1 + .../Test/UnitTest/Library/BaseCryptLib/EdDsaTests.c | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsa.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsa.c index 106274d603..0b75f9542a 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsa.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptEdDsa.c @@ -255,7 +255,7 @@ EdDsaGeneratePubKey ( IN UINTN PublicKeySize ) { - return TRUE; + return FALSE; } /** @@ -454,6 +454,10 @@ EdDsaSign ( return FALSE; } + if ((ContextSize > 0) && (Context == NULL)) { + return FALSE; + } + Ctx = (KEY_CONTEXT *)EdDsaContext; if (Ctx == NULL) { return FALSE; @@ -569,6 +573,10 @@ EdDsaVerify ( return FALSE; } + if ((ContextSize > 0) && (Context == NULL)) { + return FALSE; + } + Ctx = (KEY_CONTEXT *)EdDsaContext; if (Ctx == NULL) { return FALSE; diff --git a/CryptoPkg/Readme.md b/CryptoPkg/Readme.md index c29a9117d9..9518e96821 100644 --- a/CryptoPkg/Readme.md +++ b/CryptoPkg/Readme.md @@ -234,6 +234,7 @@ also configured. | Bn | N | N | | | C | C | | | Ec | N | N | | | C-Full | C-Full | | | Camellia | N | N | | | C-Full | C-Full | | +| EdDsa | N | N | | | C-Full | C-Full | | ## Platform Configuration of Cryptographic Services diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/EdDsaTests.c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/EdDsaTests.c index 77178ba119..1ba8431261 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/EdDsaTests.c +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/EdDsaTests.c @@ -809,16 +809,16 @@ TestVerifyEdDsaGeneratePubKey ( UT_ASSERT_NOT_NULL (EdDsaContext1); // - // EdDsaGeneratePubKey is a placeholder that always returns TRUE + // EdDsaGeneratePubKey is a placeholder that always returns FALSE // Status = EdDsaGeneratePubKey (EdDsaContext1, PublicKey, ED448_KEY_SIZE); - UT_ASSERT_TRUE (Status); + UT_ASSERT_FALSE (Status); // - // It should return TRUE even with NULL parameters + // It should return FALSE even with NULL parameters // Status = EdDsaGeneratePubKey (NULL, NULL, 0); - UT_ASSERT_TRUE (Status); + UT_ASSERT_FALSE (Status); return UNIT_TEST_PASSED; } From dc52b0c75bd299ea3bc4c6273d3dfeb26253c001 Mon Sep 17 00:00:00 2001 From: Shubham Kumar <kumarshubha@microsoft.com> Date: Wed, 1 Jul 2026 16:28:59 +0530 Subject: [PATCH 210/406] FmpDevicePkg/FmpDxe: Reduce NV variable reads for FMP state In PopulateDescriptor(), each FMP device previously called GetFmpControllerState() multiple times through individual getter functions (GetVersionFromVariable, GetLowestSupportedVersionFromVariable, etc.), each performing a separate GetVariable() call to read the same FmpControllerState NV variable. Rename the getter functions to *FromFmpControllerState and simplify them to pure field extractors that take a required FMP_CONTROLLER_STATE pointer. Each getter extracts the field value if the state is non-NULL and the field is valid, returning a default otherwise. No getter calls GetFmpControllerState() internally. PopulateDescriptor() now calls GetFmpControllerState() once and passes the result to all getters, then frees it after the last use. This eliminates redundant NV reads when the variable exists and avoids repeated failed reads and error messages when the variable does not exist. Signed-off-by: Shubham Kumar <kumarshubha@microsoft.com> --- FmpDevicePkg/FmpDxe/FmpDxe.c | 27 ++-- FmpDevicePkg/FmpDxe/VariableSupport.c | 178 +++++++++++--------------- FmpDevicePkg/FmpDxe/VariableSupport.h | 81 +++++++----- 3 files changed, 137 insertions(+), 149 deletions(-) diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c index 57ab2cda04..3d83affeac 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.c +++ b/FmpDevicePkg/FmpDxe/FmpDxe.c @@ -214,15 +214,15 @@ GetImageTypeNameString ( 2. Check if we have a variable for lowest supported version (this will be updated with each capsule applied) 3. Check Fixed at build PCD - @param[in] Private Pointer to the private context structure for the - Firmware Management Protocol instance. + @param[in] FmpControllerState The cached FMP Controller State, or NULL if the + state could not be retrieved. @retval The largest value **/ UINT32 GetLowestSupportedVersion ( - FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private + FMP_CONTROLLER_STATE *FmpControllerState ) { EFI_STATUS Status; @@ -259,7 +259,7 @@ GetLowestSupportedVersion ( // // Check the lowest supported version UEFI variable for this device // - VariableLowestSupportedVersion = GetLowestSupportedVersionFromVariable (Private); + VariableLowestSupportedVersion = GetLowestSupportedVersionFromFmpControllerState (FmpControllerState); if (VariableLowestSupportedVersion > ReturnLsv) { ReturnLsv = VariableLowestSupportedVersion; } @@ -283,8 +283,9 @@ PopulateDescriptor ( FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private ) { - EFI_STATUS Status; - UINT32 DependenciesSize; + EFI_STATUS Status; + UINT32 DependenciesSize; + FMP_CONTROLLER_STATE *FmpControllerState; if (Private == NULL) { DEBUG ((DEBUG_ERROR, "FmpDxe(%s): PopulateDescriptor() - Private is NULL.\n", mImageIdName)); @@ -314,6 +315,8 @@ PopulateDescriptor ( // GenerateFmpVariableNames (Private); + FmpControllerState = GetFmpControllerState (Private); + // // Get the version. Some devices don't support getting the firmware version // at runtime. If FmpDeviceLib does not support returning a version, then @@ -322,7 +325,7 @@ PopulateDescriptor ( Status = FmpDeviceGetVersion (&Private->Descriptor.Version); if (Status == EFI_UNSUPPORTED) { Private->RuntimeVersionSupported = FALSE; - Private->Descriptor.Version = GetVersionFromVariable (Private); + Private->Descriptor.Version = GetVersionFromFmpControllerState (FmpControllerState); } else if (EFI_ERROR (Status)) { // // Unexpected error. Use default version. @@ -358,7 +361,7 @@ PopulateDescriptor ( ); } - Private->Descriptor.LowestSupportedImageVersion = GetLowestSupportedVersion (Private); + Private->Descriptor.LowestSupportedImageVersion = GetLowestSupportedVersion (FmpControllerState); // // Get attributes from the FmpDeviceLib @@ -390,8 +393,12 @@ PopulateDescriptor ( Private->Descriptor.Size = 0; } - Private->Descriptor.LastAttemptVersion = GetLastAttemptVersionFromVariable (Private); - Private->Descriptor.LastAttemptStatus = GetLastAttemptStatusFromVariable (Private); + Private->Descriptor.LastAttemptVersion = GetLastAttemptVersionFromFmpControllerState (FmpControllerState); + Private->Descriptor.LastAttemptStatus = GetLastAttemptStatusFromFmpControllerState (FmpControllerState); + + if (FmpControllerState != NULL) { + FreePool (FmpControllerState); + } // // Get the dependency from the FmpDependencyDeviceLib. diff --git a/FmpDevicePkg/FmpDxe/VariableSupport.c b/FmpDevicePkg/FmpDxe/VariableSupport.c index 5126c5e2d5..71914f054f 100644 --- a/FmpDevicePkg/FmpDxe/VariableSupport.c +++ b/FmpDevicePkg/FmpDxe/VariableSupport.c @@ -87,14 +87,14 @@ DeleteFmpVariable ( Retrieve the FMP Controller State UEFI Variable value. Return NULL if the variable does not exist or if the size of the UEFI Variable is not the size of FMP_CONTROLLER_STATE. The buffer for the UEFI Variable value - if allocated using the UEFI Boot Service AllocatePool(). + is allocated using the UEFI Boot Service AllocatePool(). Caller must free + the returned buffer with FreePool(). @param[in] Private Private context structure for the managed controller. @return Pointer to the allocated FMP Controller State. Returns NULL if the variable does not exist or is a different size than expected. **/ -static FMP_CONTROLLER_STATE * GetFmpControllerState ( IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private @@ -323,40 +323,31 @@ GenerateFmpVariableNames ( /** Returns the value used to fill in the Version field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo() - service of the Firmware Management Protocol. The value is read from a UEFI - variable. If the UEFI variables does not exist, then a default version value - is returned. + service of the Firmware Management Protocol. The value is extracted from the + provided FmpControllerState. If FmpControllerState is NULL or the Version + field is not valid, then a default version value is returned. - UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpState" - - @param[in] Private Private context structure for the managed controller. + @param[in] FmpControllerState The cached FMP Controller State, or NULL if the + state could not be retrieved. @return The version of the firmware image in the firmware device. **/ UINT32 -GetVersionFromVariable ( - IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private +GetVersionFromFmpControllerState ( + IN FMP_CONTROLLER_STATE *FmpControllerState ) { - FMP_CONTROLLER_STATE *FmpControllerState; - UINT32 Value; + UINT32 Value; - Value = DEFAULT_VERSION; - FmpControllerState = GetFmpControllerState (Private); - if (FmpControllerState != NULL) { - if (FmpControllerState->VersionValid) { - Value = FmpControllerState->Version; - DEBUG (( - DEBUG_INFO, - "FmpDxe(%s): Get variable %g %s Version %08x\n", - mImageIdName, - &gEfiCallerIdGuid, - Private->FmpStateVariableName, - Value - )); - } - - FreePool (FmpControllerState); + Value = DEFAULT_VERSION; + if ((FmpControllerState != NULL) && FmpControllerState->VersionValid) { + Value = FmpControllerState->Version; + DEBUG (( + DEBUG_INFO, + "FmpDxe(%s): FMP Controller State Version %08x\n", + mImageIdName, + Value + )); } return Value; @@ -365,41 +356,32 @@ GetVersionFromVariable ( /** Returns the value used to fill in the LowestSupportedVersion field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo() - service of the Firmware Management Protocol. The value is read from a UEFI - variable. If the UEFI variables does not exist, then a default lowest - supported version value is returned. + service of the Firmware Management Protocol. The value is extracted from the + provided FmpControllerState. If FmpControllerState is NULL or the Lsv field + is not valid, then a default lowest supported version value is returned. - UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpState" - - @param[in] Private Private context structure for the managed controller. + @param[in] FmpControllerState The cached FMP Controller State, or NULL if the + state could not be retrieved. @return The lowest supported version of the firmware image in the firmware device. **/ UINT32 -GetLowestSupportedVersionFromVariable ( - IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private +GetLowestSupportedVersionFromFmpControllerState ( + IN FMP_CONTROLLER_STATE *FmpControllerState ) { - FMP_CONTROLLER_STATE *FmpControllerState; - UINT32 Value; + UINT32 Value; - Value = DEFAULT_LOWESTSUPPORTEDVERSION; - FmpControllerState = GetFmpControllerState (Private); - if (FmpControllerState != NULL) { - if (FmpControllerState->LsvValid) { - Value = FmpControllerState->Lsv; - DEBUG (( - DEBUG_INFO, - "FmpDxe(%s): Get variable %g %s LowestSupportedVersion %08x\n", - mImageIdName, - &gEfiCallerIdGuid, - Private->FmpStateVariableName, - Value - )); - } - - FreePool (FmpControllerState); + Value = DEFAULT_LOWESTSUPPORTEDVERSION; + if ((FmpControllerState != NULL) && FmpControllerState->LsvValid) { + Value = FmpControllerState->Lsv; + DEBUG (( + DEBUG_INFO, + "FmpDxe(%s): FMP Controller State LowestSupportedVersion %08x\n", + mImageIdName, + Value + )); } return Value; @@ -408,40 +390,32 @@ GetLowestSupportedVersionFromVariable ( /** Returns the value used to fill in the LastAttemptStatus field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo() - service of the Firmware Management Protocol. The value is read from a UEFI - variable. If the UEFI variables does not exist, then a default last attempt - status value is returned. + service of the Firmware Management Protocol. The value is extracted from the + provided FmpControllerState. If FmpControllerState is NULL or the + LastAttemptStatus field is not valid, then a default last attempt status value + is returned. - UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpState" - - @param[in] Private Private context structure for the managed controller. + @param[in] FmpControllerState The cached FMP Controller State, or NULL if the + state could not be retrieved. @return The last attempt status value for the most recent capsule update. **/ UINT32 -GetLastAttemptStatusFromVariable ( - IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private +GetLastAttemptStatusFromFmpControllerState ( + IN FMP_CONTROLLER_STATE *FmpControllerState ) { - FMP_CONTROLLER_STATE *FmpControllerState; - UINT32 Value; + UINT32 Value; - Value = DEFAULT_LASTATTEMPTSTATUS; - FmpControllerState = GetFmpControllerState (Private); - if (FmpControllerState != NULL) { - if (FmpControllerState->LastAttemptStatusValid) { - Value = FmpControllerState->LastAttemptStatus; - DEBUG (( - DEBUG_INFO, - "FmpDxe(%s): Get variable %g %s LastAttemptStatus %08x\n", - mImageIdName, - &gEfiCallerIdGuid, - Private->FmpStateVariableName, - Value - )); - } - - FreePool (FmpControllerState); + Value = DEFAULT_LASTATTEMPTSTATUS; + if ((FmpControllerState != NULL) && FmpControllerState->LastAttemptStatusValid) { + Value = FmpControllerState->LastAttemptStatus; + DEBUG (( + DEBUG_INFO, + "FmpDxe(%s): FMP Controller State LastAttemptStatus %08x\n", + mImageIdName, + Value + )); } return Value; @@ -450,40 +424,32 @@ GetLastAttemptStatusFromVariable ( /** Returns the value used to fill in the LastAttemptVersion field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo() - service of the Firmware Management Protocol. The value is read from a UEFI - variable. If the UEFI variables does not exist, then a default last attempt - version value is returned. + service of the Firmware Management Protocol. The value is extracted from the + provided FmpControllerState. If FmpControllerState is NULL or the + LastAttemptVersion field is not valid, then a default last attempt version + value is returned. - UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpState" - - @param[in] Private Private context structure for the managed controller. + @param[in] FmpControllerState The cached FMP Controller State, or NULL if the + state could not be retrieved. @return The last attempt version value for the most recent capsule update. **/ UINT32 -GetLastAttemptVersionFromVariable ( - IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private +GetLastAttemptVersionFromFmpControllerState ( + IN FMP_CONTROLLER_STATE *FmpControllerState ) { - FMP_CONTROLLER_STATE *FmpControllerState; - UINT32 Value; + UINT32 Value; - Value = DEFAULT_LASTATTEMPTVERSION; - FmpControllerState = GetFmpControllerState (Private); - if (FmpControllerState != NULL) { - if (FmpControllerState->LastAttemptVersionValid) { - Value = FmpControllerState->LastAttemptVersion; - DEBUG (( - DEBUG_INFO, - "FmpDxe(%s): Get variable %g %s LastAttemptVersion %08x\n", - mImageIdName, - &gEfiCallerIdGuid, - Private->FmpStateVariableName, - Value - )); - } - - FreePool (FmpControllerState); + Value = DEFAULT_LASTATTEMPTVERSION; + if ((FmpControllerState != NULL) && FmpControllerState->LastAttemptVersionValid) { + Value = FmpControllerState->LastAttemptVersion; + DEBUG (( + DEBUG_INFO, + "FmpDxe(%s): FMP Controller State LastAttemptVersion %08x\n", + mImageIdName, + Value + )); } return Value; diff --git a/FmpDevicePkg/FmpDxe/VariableSupport.h b/FmpDevicePkg/FmpDxe/VariableSupport.h index 516e799fca..d11044dd7f 100644 --- a/FmpDevicePkg/FmpDxe/VariableSupport.h +++ b/FmpDevicePkg/FmpDxe/VariableSupport.h @@ -81,76 +81,91 @@ GenerateFmpVariableNames ( ); /** - Returns the value used to fill in the Version field of the - EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo() - service of the Firmware Management Protocol. The value is read from a UEFI - variable. If the UEFI variables does not exist, then a default version value - is returned. - - UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe" + Retrieve the FMP Controller State UEFI Variable value. Return NULL if + the variable does not exist or if the size of the UEFI Variable is not the + size of FMP_CONTROLLER_STATE. The buffer for the UEFI Variable value + is allocated using the UEFI Boot Service AllocatePool(). Caller must free + the returned buffer with FreePool(). @param[in] Private Private context structure for the managed controller. + @return Pointer to the allocated FMP Controller State. Returns NULL + if the variable does not exist or is a different size than expected. +**/ +FMP_CONTROLLER_STATE * +GetFmpControllerState ( + IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private + ); + +/** + Returns the value used to fill in the Version field of the + EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo() + service of the Firmware Management Protocol. The value is extracted from the + provided FmpControllerState. If FmpControllerState is NULL or the Version + field is not valid, then a default version value is returned. + + @param[in] FmpControllerState The cached FMP Controller State, or NULL if the + state could not be retrieved. + @return The version of the firmware image in the firmware device. **/ UINT32 -GetVersionFromVariable ( - IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private +GetVersionFromFmpControllerState ( + IN FMP_CONTROLLER_STATE *FmpControllerState ); /** Returns the value used to fill in the LowestSupportedVersion field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo() - service of the Firmware Management Protocol. The value is read from a UEFI - variable. If the UEFI variables does not exist, then a default lowest - supported version value is returned. + service of the Firmware Management Protocol. The value is extracted from the + provided FmpControllerState. If FmpControllerState is NULL or the Lsv field + is not valid, then a default lowest supported version value is returned. - UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe" - - @param[in] Private Private context structure for the managed controller. + @param[in] FmpControllerState The cached FMP Controller State, or NULL if the + state could not be retrieved. @return The lowest supported version of the firmware image in the firmware device. **/ UINT32 -GetLowestSupportedVersionFromVariable ( - IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private +GetLowestSupportedVersionFromFmpControllerState ( + IN FMP_CONTROLLER_STATE *FmpControllerState ); /** Returns the value used to fill in the LastAttemptStatus field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo() - service of the Firmware Management Protocol. The value is read from a UEFI - variable. If the UEFI variables does not exist, then a default last attempt - status value is returned. + service of the Firmware Management Protocol. The value is extracted from the + provided FmpControllerState. If FmpControllerState is NULL or the + LastAttemptStatus field is not valid, then a default last attempt status value + is returned. - UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe" - - @param[in] Private Private context structure for the managed controller. + @param[in] FmpControllerState The cached FMP Controller State, or NULL if the + state could not be retrieved. @return The last attempt status value for the most recent capsule update. **/ UINT32 -GetLastAttemptStatusFromVariable ( - IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private +GetLastAttemptStatusFromFmpControllerState ( + IN FMP_CONTROLLER_STATE *FmpControllerState ); /** Returns the value used to fill in the LastAttemptVersion field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo() - service of the Firmware Management Protocol. The value is read from a UEFI - variable. If the UEFI variables does not exist, then a default last attempt - version value is returned. + service of the Firmware Management Protocol. The value is extracted from the + provided FmpControllerState. If FmpControllerState is NULL or the + LastAttemptVersion field is not valid, then a default last attempt version + value is returned. - UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe" - - @param[in] Private Private context structure for the managed controller. + @param[in] FmpControllerState The cached FMP Controller State, or NULL if the + state could not be retrieved. @return The last attempt version value for the most recent capsule update. **/ UINT32 -GetLastAttemptVersionFromVariable ( - IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private +GetLastAttemptVersionFromFmpControllerState ( + IN FMP_CONTROLLER_STATE *FmpControllerState ); /** From 264f812b70c8941e449740dbc1ae528620089f78 Mon Sep 17 00:00:00 2001 From: "Michael G.A. Holland" <michael.holland@intel.com> Date: Fri, 17 Jul 2026 11:00:08 -0700 Subject: [PATCH 211/406] CryptoPkg/BaseCryptLib: ML-DSA updates Include validation check for Context and ContextSize in signature function. Updated ReadMe to show ML-DSA support Signed-off-by: Michael G.A. Holland <michael.holland@intel.com> --- CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsa.c | 4 ++++ CryptoPkg/Readme.md | 1 + 2 files changed, 5 insertions(+) diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsa.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsa.c index 45ea241148..d17459daf9 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsa.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptMlDsa.c @@ -647,6 +647,10 @@ MlDsaVerify ( return FALSE; } + if ((ContextSize > 0) && (Context == NULL)) { + return FALSE; + } + Ctx = (KEY_CONTEXT *)MlDsaContext; if (Ctx->EvpPkey == NULL) { return FALSE; diff --git a/CryptoPkg/Readme.md b/CryptoPkg/Readme.md index 9518e96821..1e1c911599 100644 --- a/CryptoPkg/Readme.md +++ b/CryptoPkg/Readme.md @@ -235,6 +235,7 @@ also configured. | Ec | N | N | | | C-Full | C-Full | | | Camellia | N | N | | | C-Full | C-Full | | | EdDsa | N | N | | | C-Full | C-Full | | +| MlDsa | N | N | | | C-Full | C-Full | | ## Platform Configuration of Cryptographic Services From 048e36d5af8c536087f4f821a8db1f5340441181 Mon Sep 17 00:00:00 2001 From: Luigi Leonardi <leonardi@redhat.com> Date: Tue, 30 Jun 2026 11:33:58 +0200 Subject: [PATCH 212/406] OvmfPkg/VirtMmCommunicationDxe: Remove unused QemuX64.c QemuX64.c implemented PIO-based MM communication for the uefi-vars-isa device. It was already commented out in VirtMmCommunication.inf and is not referenced by any build file. Remove the dead code. Signed-off-by: Luigi Leonardi <leonardi@redhat.com> --- OvmfPkg/VirtMmCommunicationDxe/QemuX64.c | 149 ------------------ .../VirtMmCommunication.inf | 1 - 2 files changed, 150 deletions(-) delete mode 100644 OvmfPkg/VirtMmCommunicationDxe/QemuX64.c diff --git a/OvmfPkg/VirtMmCommunicationDxe/QemuX64.c b/OvmfPkg/VirtMmCommunicationDxe/QemuX64.c deleted file mode 100644 index 4610553957..0000000000 --- a/OvmfPkg/VirtMmCommunicationDxe/QemuX64.c +++ /dev/null @@ -1,149 +0,0 @@ -/** @file - - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include <IndustryStandard/QemuUefiVars.h> - -#include <Library/BaseLib.h> -#include <Library/DebugLib.h> -#include <Library/IoLib.h> - -#include "VirtMmCommunication.h" - -STATIC -EFI_STATUS -EFIAPI -VirtMmHwCommand ( - UINT32 Cmd - ) -{ - UINT32 Count; - UINT32 Sts; - - IoWrite16 (UEFI_VARS_IO_BASE + UEFI_VARS_REG_CMD_STS, Cmd); - for (Count = 0; Count < 100; Count++) { - Sts = IoRead16 (UEFI_VARS_IO_BASE + UEFI_VARS_REG_CMD_STS); - DEBUG ((DEBUG_VERBOSE, "%a: Sts: 0x%x\n", __func__, Sts)); - switch (Sts) { - case UEFI_VARS_STS_SUCCESS: - return RETURN_SUCCESS; - case UEFI_VARS_STS_BUSY: - CpuPause (); - break; - case UEFI_VARS_STS_ERR_NOT_SUPPORTED: - return RETURN_UNSUPPORTED; - case UEFI_VARS_STS_ERR_BAD_BUFFER_SIZE: - return RETURN_BAD_BUFFER_SIZE; - default: - return RETURN_DEVICE_ERROR; - } - } - - return RETURN_TIMEOUT; -} - -EFI_STATUS -EFIAPI -VirtMmHwInit ( - VOID - ) -{ - UINT32 Magic, AddrLo, AddrHi; - EFI_STATUS Status; - - Magic = IoRead16 (UEFI_VARS_IO_BASE + UEFI_VARS_REG_MAGIC); - if (Magic != UEFI_VARS_MAGIC_VALUE) { - DEBUG (( - DEBUG_ERROR, - "%a: Magic value mismatch (0x%x != 0x%x)\n", - __func__, - Magic, - UEFI_VARS_MAGIC_VALUE - )); - return RETURN_DEVICE_ERROR; - } - - DEBUG ((DEBUG_INFO, "%a: Magic 0x%x, good\n", __func__, Magic)); - - Status = VirtMmHwCommand (UEFI_VARS_CMD_RESET); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Reset failed: %d\n", __func__, Status)); - return Status; - } - - AddrLo = (UINT32)mCommunicateBufferPhys; - AddrHi = (UINT32)RShiftU64 (mCommunicateBufferPhys, 32); - IoWrite32 (UEFI_VARS_IO_BASE + UEFI_VARS_REG_DMA_BUFFER_ADDR_LO, AddrLo); - IoWrite32 (UEFI_VARS_IO_BASE + UEFI_VARS_REG_DMA_BUFFER_ADDR_HI, AddrHi); - IoWrite32 (UEFI_VARS_IO_BASE + UEFI_VARS_REG_BUFFER_SIZE, MAX_BUFFER_SIZE); - - return RETURN_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtMmHwPioTransfer ( - VOID *Buffer, - UINT32 BufferSize, - BOOLEAN ToDevice - ) -{ - UINT32 *Ptr = Buffer; - UINT32 Bytes = 0; - UINT32 Crc1; - UINT32 Crc2; - EFI_STATUS Status; - - Status = VirtMmHwCommand (UEFI_VARS_CMD_PIO_ZERO_OFFSET); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: zero offset failed: %d\n", __func__, Status)); - return Status; - } - - while (Bytes < BufferSize) { - if (ToDevice) { - IoWrite32 (UEFI_VARS_IO_BASE + UEFI_VARS_REG_PIO_BUFFER_TRANSFER, *Ptr); - } else { - *Ptr = IoRead32 (UEFI_VARS_IO_BASE + UEFI_VARS_REG_PIO_BUFFER_TRANSFER); - } - - Bytes += sizeof (*Ptr); - Ptr++; - } - - Crc1 = CalculateCrc32c (Buffer, Bytes, 0); - Crc2 = IoRead32 (UEFI_VARS_IO_BASE + UEFI_VARS_REG_PIO_BUFFER_CRC32C); - if (Crc1 != Crc2) { - DEBUG ((DEBUG_ERROR, "%a: crc32c mismatch (0x%08x,0x%08x)\n", __func__, Crc1, Crc2)); - return RETURN_DEVICE_ERROR; - } - - return RETURN_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtMmHwVirtMap ( - VOID - ) -{ - return RETURN_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtMmHwComm ( - VOID - ) -{ - EFI_STATUS Status; - UINT32 Cmd; - - Cmd = mUsePioTransfer ? UEFI_VARS_CMD_PIO_MM : UEFI_VARS_CMD_DMA_MM; - Status = VirtMmHwCommand (Cmd); - DEBUG ((DEBUG_VERBOSE, "%a: Status: %r\n", __func__, Status)); - - return Status; -} diff --git a/OvmfPkg/VirtMmCommunicationDxe/VirtMmCommunication.inf b/OvmfPkg/VirtMmCommunicationDxe/VirtMmCommunication.inf index 5de34467e5..c3988b6451 100644 --- a/OvmfPkg/VirtMmCommunicationDxe/VirtMmCommunication.inf +++ b/OvmfPkg/VirtMmCommunicationDxe/VirtMmCommunication.inf @@ -19,7 +19,6 @@ VirtMmCommunication.c [Sources.X64] -# QemuX64.c QemuHwInfo.c QemuMmio.c Svsm.c From 5dc785e7f664af82f06e9d450df398618edd0396 Mon Sep 17 00:00:00 2001 From: Luigi Leonardi <leonardi@redhat.com> Date: Tue, 30 Jun 2026 12:58:12 +0200 Subject: [PATCH 213/406] OvmfPkg/VirtMmCommunicationDxe: Fix unchecked VirtMmGetProp return values VirtMmHwFind() calls VirtMmGetProp() twice but does not assign the return value to Status. The subsequent EFI_ERROR(Status) checks test the stale Status from LocateProtocol(), which always succeeds at that point, so FDT lookup failures are silently ignored and the function proceeds with uninitialised Ranges/Reg pointers. Assign both VirtMmGetProp() return values to Status so the error checks work as intended. Fixes: 9dd47eeea1 ("OvmfPkg: add new VirtMmCommunicationDxe driver") Signed-off-by: Luigi Leonardi <leonardi@redhat.com> --- OvmfPkg/VirtMmCommunicationDxe/QemuFdt.c | 28 ++++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/VirtMmCommunicationDxe/QemuFdt.c b/OvmfPkg/VirtMmCommunicationDxe/QemuFdt.c index bb86290655..41cc25b63e 100644 --- a/OvmfPkg/VirtMmCommunicationDxe/QemuFdt.c +++ b/OvmfPkg/VirtMmCommunicationDxe/QemuFdt.c @@ -136,24 +136,24 @@ VirtMmHwFind ( ); ASSERT_EFI_ERROR (Status); - VirtMmGetProp ( - FdtClient, - "qemu,platform", - "ranges", - &Ranges, - &RangesSize - ); + Status = VirtMmGetProp ( + FdtClient, + "qemu,platform", + "ranges", + &Ranges, + &RangesSize + ); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } - VirtMmGetProp ( - FdtClient, - UEFI_VARS_FDT_COMPAT, - "reg", - &Reg, - &RegSize - ); + Status = VirtMmGetProp ( + FdtClient, + UEFI_VARS_FDT_COMPAT, + "reg", + &Reg, + &RegSize + ); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } From 99942e353274d6a4641c71e21399cd4ab0feca11 Mon Sep 17 00:00:00 2001 From: Luigi Leonardi <leonardi@redhat.com> Date: Tue, 30 Jun 2026 13:28:35 +0200 Subject: [PATCH 214/406] OvmfPkg/VirtMmCommunicationDxe: Fix NULL dereference of optional CommSize VirtMmCommunication2Communicate() dereferences *CommSize in a DEBUG statement before checking whether CommSize is NULL. CommSize is an optional parameter, so callers may legitimately pass NULL, causing a NULL pointer dereference in debug builds. Guard the dereference with a ternary so the DEBUG prints 0 when CommSize is NULL. Fixes: 9dd47eeea1 ("OvmfPkg: add new VirtMmCommunicationDxe driver") Signed-off-by: Luigi Leonardi <leonardi@redhat.com> --- OvmfPkg/VirtMmCommunicationDxe/VirtMmCommunication.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OvmfPkg/VirtMmCommunicationDxe/VirtMmCommunication.c b/OvmfPkg/VirtMmCommunicationDxe/VirtMmCommunication.c index bf5c48c0ba..648f804c04 100644 --- a/OvmfPkg/VirtMmCommunicationDxe/VirtMmCommunication.c +++ b/OvmfPkg/VirtMmCommunicationDxe/VirtMmCommunication.c @@ -102,7 +102,7 @@ VirtMmCommunication2Communicate ( &CommunicateHeader->HeaderGuid, CommunicateHeader->MessageLength, BufferSize, - *CommSize + CommSize ? *CommSize : 0 )); // If CommSize is not omitted, perform size inspection before proceeding. From 1506c6da7bb6820beb1a1170909f181b69d63c8a Mon Sep 17 00:00:00 2001 From: Jakov Zauzolkov <jakov.zauzolkov@aisec.fraunhofer.de> Date: Tue, 30 Jun 2026 09:47:21 +0200 Subject: [PATCH 215/406] OvmfPkg: Replace BaseAcpiTimerLib with BaseRomAcpiTimerLib in PEI The BaseAcpiTimerLib instance contains a static global variable, 'mAcpiTimerIoAddr', that caches the ACPI timer IO base address. As this library executes during PEI phase prior to the PEIFV measurement into PCR0, the value of the variable is included into the measurement. This causes the PEIFV binary footprint to change, preventing a precomputation of the expected value needed for remote attestation. Fix this by using the BaseRomAcpiTimerLib in the PEI phase instead of the BaseAcpiTimerLib. This library dynamically computes the required address and does not introduce global variables, keeping the PEIFV binary unchanged. Co-authored-by: Simon Ott <simon.ott@aisec.fraunhofer.de> Signed-off-by: Jakov Zauzolkov <jakov.zauzolkov@aisec.fraunhofer.de> --- OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf | 2 +- OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++ OvmfPkg/OvmfPkgX64.dsc | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf b/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf index 8f9bedbfe2..99ea20e829 100644 --- a/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf +++ b/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf @@ -13,7 +13,7 @@ FILE_GUID = CDD9D74F-213E-4c28-98F7-8B4A167DB936 MODULE_TYPE = BASE VERSION_STRING = 1.0 - LIBRARY_CLASS = TimerLib|SEC + LIBRARY_CLASS = TimerLib|SEC PEI_CORE PEIM CONSTRUCTOR = AcpiTimerLibConstructor [Sources] diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index aacf6b6f9b..2119527c1c 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -297,6 +297,7 @@ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiCoreLib.inf !endif PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf + TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf [LibraryClasses.common.PEIM] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -325,6 +326,7 @@ MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf PlatformInitLib|OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index d4b3cff7fd..098c8cd464 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -329,6 +329,7 @@ !endif PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf + TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf [LibraryClasses.common.PEIM] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -357,6 +358,7 @@ MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf PlatformInitLib|OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf From be0513a59a96411db919ca5e69bcc1363e72aaa7 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Thu, 25 Jun 2026 17:34:40 +0800 Subject: [PATCH 216/406] OvmfPkg/VirtioKeyboardDxe: Fix protocol uninstall in BindingStop UninstallMultipleProtocolInterfaces() takes the handle by value rather than pointer. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c index fa2bf4a124..e2fae72701 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c +++ b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c @@ -1379,7 +1379,7 @@ VirtioKeyboardBindingStop ( // Handle Stop() requests for in-use driver instances gracefully. // Status = gBS->UninstallMultipleProtocolInterfaces ( - &DeviceHandle, + DeviceHandle, &gEfiSimpleTextInProtocolGuid, &Dev->Txt, &gEfiSimpleTextInputExProtocolGuid, From a507ccdc6a3d33d2a32360cd44e07d2451797b3f Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Tue, 23 Jun 2026 20:36:55 +0800 Subject: [PATCH 217/406] OvmfPkg/VirtioKeyboardDxe: Fix RingMap check in UninitRing UnmapSharedBuffer() should be called on a valid mapping. Fix the inverted condition. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c index e2fae72701..b8fadd5730 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c +++ b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c @@ -321,7 +321,7 @@ VirtioKeyboardUninitRing ( Ring->Buffers = NULL; } - if (!Ring->RingMap) { + if (Ring->RingMap) { Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Ring->RingMap); Ring->RingMap = NULL; } From 2c6e9e13d692f2581509ecf587b992687afcf533 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Wed, 24 Jun 2026 15:38:58 +0800 Subject: [PATCH 218/406] OvmfPkg/VirtioKeyboardDxe: Close WaitForKey(Ex) events in Uninit() VirtioKeyboardInit() creates Txt.WaitForKey, TxtEx.WaitForKeyEx and KeyReadTimer events, but VirtioKeyboardUninit() currently only closes KeyReadTimer. Close the other two events to fix the leak. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c index b8fadd5730..e517e26d64 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c +++ b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c @@ -1167,6 +1167,9 @@ VirtioKeyboardUninit ( ) { gBS->CloseEvent (Dev->KeyReadTimer); + gBS->CloseEvent (Dev->Txt.WaitForKey); + gBS->CloseEvent (Dev->TxtEx.WaitForKeyEx); + // // Reset the virtual device -- see virtio-0.9.5, 2.2.2.1 Device Status. When // VIRTIO_CFG_WRITE() returns, the host will have learned to stay away from From 0a74b3a4de0ee98e6a5ad73d328c86bea04bada8 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Tue, 23 Jun 2026 23:06:09 +0800 Subject: [PATCH 219/406] OvmfPkg/VirtioKeyboardDxe: Drop unused functions and variables VirtioKeyboardRingHasBuffer() and VIRTIO_KBD_DEV.KeyNotifyTimer are defined but never called, drop them. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c | 23 ---------------------- OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h | 1 - 2 files changed, 24 deletions(-) diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c index e517e26d64..28cffe7f19 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c +++ b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c @@ -104,29 +104,6 @@ VirtioKeyboardRingSendBuffer ( return EFI_SUCCESS; } -// ----------------------------------------------------------------------------- -// Look for buffer ready to be processed -BOOLEAN -EFIAPI -VirtioKeyboardRingHasBuffer ( - IN OUT VIRTIO_KBD_DEV *Dev, - IN UINT16 Index - ) -{ - VIRTIO_KBD_RING *Ring = Dev->Rings + Index; - UINT16 UsedIdx = *Ring->Ring.Used.Idx; - - if (!Ring->Ready) { - return FALSE; - } - - if (Ring->LastUsedIdx == UsedIdx) { - return FALSE; - } - - return TRUE; -} - // ----------------------------------------------------------------------------- // Get data from buffer which is marked as ready from device BOOLEAN diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h index b244dec12e..4e08493d33 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h +++ b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h @@ -97,7 +97,6 @@ typedef struct { // List for notifications LIST_ENTRY NotifyList; - EFI_EVENT KeyNotifyTimer; // Last pressed key // typedef struct { From ff355e4bddf2a85b428dfbef8939330cc685a9fc Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Tue, 23 Jun 2026 23:11:51 +0800 Subject: [PATCH 220/406] OvmfPkg/VirtioKeyboardDxe: Fix typo in IsKeyRegistered() Regsiter -> Register No functional change. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c index 28cffe7f19..6181dfd257 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c +++ b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c @@ -794,15 +794,15 @@ VirtioKeyboardSetState ( BOOLEAN IsKeyRegistered ( - IN EFI_KEY_DATA *RegsiteredData, + IN EFI_KEY_DATA *RegisteredData, IN EFI_KEY_DATA *InputData ) { - ASSERT (RegsiteredData != NULL && InputData != NULL); + ASSERT (RegisteredData != NULL && InputData != NULL); - if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) || - (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) + if ((RegisteredData->Key.ScanCode != InputData->Key.ScanCode) || + (RegisteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) { return FALSE; } @@ -811,14 +811,14 @@ IsKeyRegistered ( // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means // these state could be ignored. // - if ((RegsiteredData->KeyState.KeyShiftState != 0) && - (RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState)) + if ((RegisteredData->KeyState.KeyShiftState != 0) && + (RegisteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState)) { return FALSE; } - if ((RegsiteredData->KeyState.KeyToggleState != 0) && - (RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState)) + if ((RegisteredData->KeyState.KeyToggleState != 0) && + (RegisteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState)) { return FALSE; } From a1b3a6bd1fec6d37e3d9866e818510b5687e6659 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Thu, 25 Jun 2026 15:28:52 +0800 Subject: [PATCH 221/406] OvmfPkg/VirtioKeyboardDxe: Simplify WaitForKey event handling Both WaitForKey and WaitForKeyEx event handler runs the same logic in VirtioKeyboardWaitForKey(). Pass the VIRTIO_KBD_DEV pointer directly as the event notify context so one function serves both events. Also drop the erroneous assignment of VirtioKeyboardWaitForKey() to Dev->Txt.WaitForKey, which stored a function pointer into the event handle field and was immediately overwritten by CreateEvent(). No functional change. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c | 28 +++++----------------- OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h | 9 ------- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c index 6181dfd257..4b14679995 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c +++ b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c @@ -643,7 +643,7 @@ VirtioKeyboardWaitForKey ( IN VOID *Context ) { - VIRTIO_KBD_DEV *Dev = VIRTIO_KEYBOARD_FROM_THIS (Context); + VIRTIO_KBD_DEV *Dev = (VIRTIO_KBD_DEV *)Context; // // Stall 1ms to give a chance to let other driver interrupt this routine @@ -761,21 +761,6 @@ VirtioKeyboardReadKeyStrokeEx ( return EFI_SUCCESS; } -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -VOID -EFIAPI -VirtioKeyboardWaitForKeyEx ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - VIRTIO_KBD_DEV *Dev; - - Dev = VIRTIO_KEYBOARD_EX_FROM_THIS (Context); - VirtioKeyboardWaitForKey (Event, &Dev->Txt); -} - // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API EFI_STATUS @@ -1048,7 +1033,6 @@ VirtioKeyboardInit ( // }; Dev->Txt.Reset = (EFI_INPUT_RESET)VirtioKeyboardSimpleTextInputReset; Dev->Txt.ReadKeyStroke = VirtioKeyboardSimpleTextInputReadKeyStroke; - Dev->Txt.WaitForKey = (EFI_EVENT)VirtioKeyboardWaitForKey; // struct _EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL { // EFI_INPUT_RESET_EX Reset; @@ -1072,8 +1056,8 @@ VirtioKeyboardInit ( EVT_NOTIFY_WAIT, TPL_NOTIFY, VirtioKeyboardWaitForKey, - &(Dev->Txt), - &((Dev->Txt).WaitForKey) + Dev, + &(Dev->Txt.WaitForKey) ); if (EFI_ERROR (Status)) { goto Failed; @@ -1085,9 +1069,9 @@ VirtioKeyboardInit ( Status = gBS->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY, - VirtioKeyboardWaitForKeyEx, - &(Dev->TxtEx), - &((Dev->TxtEx).WaitForKeyEx) + VirtioKeyboardWaitForKey, + Dev, + &(Dev->TxtEx.WaitForKeyEx) ); if (EFI_ERROR (Status)) { goto Failed; diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h index 4e08493d33..a8d8d0e18b 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h +++ b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h @@ -166,15 +166,6 @@ VirtioKeyboardReadKeyStrokeEx ( OUT EFI_KEY_DATA *KeyData ); -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -VOID -EFIAPI -VirtioKeyboardWaitForKeyEx ( - IN EFI_EVENT Event, - IN VOID *Context - ); - // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API EFI_STATUS From 7cc22c4b5baff57ef9f9b1ff3768cac193c8d6f7 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Tue, 23 Jun 2026 23:26:30 +0800 Subject: [PATCH 222/406] OvmfPkg/VirtioKeyboardDxe: Declare internal functions as STATIC The SimpleTextIn(Ex) protocol callbacks and IsKeyRegistered() are only used within VirtioKeyboard.c. Declare them STATIC and remove the declarations in VirtioKeyboard.h. No functional change. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c | 13 ++++ OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h | 74 ---------------------- 2 files changed, 13 insertions(+), 74 deletions(-) diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c index 4b14679995..205869f239 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c +++ b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c @@ -54,6 +54,7 @@ BufferNext ( // ----------------------------------------------------------------------------- // Push the buffer to the device +STATIC EFI_STATUS EFIAPI VirtioKeyboardRingSendBuffer ( @@ -106,6 +107,7 @@ VirtioKeyboardRingSendBuffer ( // ----------------------------------------------------------------------------- // Get data from buffer which is marked as ready from device +STATIC BOOLEAN EFIAPI VirtioKeyboardRingGetBuffer ( @@ -150,6 +152,7 @@ VirtioKeyboardRingGetBuffer ( // ----------------------------------------------------------------------------- // Initialize ring buffer +STATIC EFI_STATUS EFIAPI VirtioKeyboardInitRing ( @@ -275,6 +278,7 @@ Failed: // ----------------------------------------------------------------------------- // Deinitialize ring buffer +STATIC VOID EFIAPI VirtioKeyboardUninitRing ( @@ -363,6 +367,7 @@ VirtioKeyboardInit ( // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_PROTOCOL API +STATIC EFI_STATUS EFIAPI VirtioKeyboardSimpleTextInputReset ( @@ -381,6 +386,7 @@ VirtioKeyboardSimpleTextInputReset ( // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_PROTOCOL API +STATIC EFI_STATUS EFIAPI VirtioKeyboardSimpleTextInputReadKeyStroke ( @@ -636,6 +642,7 @@ VirtioKeyboardTimer ( // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_PROTOCOL API +STATIC VOID EFIAPI VirtioKeyboardWaitForKey ( @@ -668,6 +675,7 @@ VirtioKeyboardWaitForKey ( /// ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API +STATIC EFI_STATUS EFIAPI VirtioKeyboardResetEx ( @@ -699,6 +707,7 @@ VirtioKeyboardResetEx ( // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API +STATIC EFI_STATUS EFIAPI VirtioKeyboardReadKeyStrokeEx ( @@ -763,6 +772,7 @@ VirtioKeyboardReadKeyStrokeEx ( // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API +STATIC EFI_STATUS EFIAPI VirtioKeyboardSetState ( @@ -777,6 +787,7 @@ VirtioKeyboardSetState ( return EFI_SUCCESS; } +STATIC BOOLEAN IsKeyRegistered ( IN EFI_KEY_DATA *RegisteredData, @@ -813,6 +824,7 @@ IsKeyRegistered ( // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API +STATIC EFI_STATUS EFIAPI VirtioKeyboardRegisterKeyNotify ( @@ -882,6 +894,7 @@ Exit: // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API +STATIC EFI_STATUS EFIAPI VirtioKeyboardUnregisterKeyNotify ( diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h index a8d8d0e18b..242f005f74 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h +++ b/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h @@ -120,77 +120,3 @@ typedef struct { // Bellow candidates to be included as Linux header #define KEY_PRESSED 1 - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_PROTOCOL API -EFI_STATUS -EFIAPI -VirtioKeyboardSimpleTextInputReset ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN BOOLEAN ExtendedVerification - ); - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_PROTOCOL API -EFI_STATUS -EFIAPI -VirtioKeyboardSimpleTextInputReadKeyStroke ( - IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, - OUT EFI_INPUT_KEY *Key - ); - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_PROTOCOL API -VOID -EFIAPI -VirtioKeyboardWaitForKey ( - IN EFI_EVENT Event, - IN VOID *Context - ); - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -EFI_STATUS -EFIAPI -VirtioKeyboardResetEx ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN BOOLEAN ExtendedVerification - ); - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -EFI_STATUS -EFIAPI -VirtioKeyboardReadKeyStrokeEx ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - OUT EFI_KEY_DATA *KeyData - ); - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -EFI_STATUS -EFIAPI -VirtioKeyboardSetState ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN EFI_KEY_TOGGLE_STATE *KeyToggleState - ); - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -EFI_STATUS -EFIAPI -VirtioKeyboardRegisterKeyNotify ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN EFI_KEY_DATA *KeyData, - IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction, - OUT VOID **NotifyHandle - ); - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -EFI_STATUS -EFIAPI -VirtioKeyboardUnregisterKeyNotify ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN VOID *NotificationHandle - ); From afe4360dd27a9dd27db561e6df5f3d328cfc094e Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Tue, 23 Jun 2026 13:02:57 +0800 Subject: [PATCH 223/406] OvmfPkg, ArmVirtPkg: Rename VirtioKeyboardDxe to VirtioInputDxe The virtio input device can be used to create virtual human interface devices such as mice and tablets, not just keyboards. Rename VirtioKeyboardDxe to VirtioInputDxe for adding virtio-mouse and virtio-tablet support in following commits. No functional change. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- ArmVirtPkg/ArmVirtQemu.dsc | 2 +- OvmfPkg/Bhyve/BhyveX64.dsc | 2 +- OvmfPkg/Bhyve/BhyveX64.fdf | 2 +- .../PlatformBootManagerLib/BdsPlatform.c | 6 +- OvmfPkg/OvmfPkgIa32X64.dsc | 2 +- OvmfPkg/OvmfPkgIa32X64.fdf | 2 +- OvmfPkg/OvmfPkgX64.dsc | 2 +- OvmfPkg/OvmfPkgX64.fdf | 2 +- .../VirtioInput.c} | 351 +++++++++--------- .../VirtioInput.h} | 38 +- .../VirtioInput.inf} | 10 +- .../VirtioKeyCodes.h | 2 +- 12 files changed, 210 insertions(+), 211 deletions(-) rename OvmfPkg/{VirtioKeyboardDxe/VirtioKeyboard.c => VirtioInputDxe/VirtioInput.c} (79%) rename OvmfPkg/{VirtioKeyboardDxe/VirtioKeyboard.h => VirtioInputDxe/VirtioInput.h} (73%) rename OvmfPkg/{VirtioKeyboardDxe/VirtioKeyboard.inf => VirtioInputDxe/VirtioInput.inf} (72%) rename OvmfPkg/{VirtioKeyboardDxe => VirtioInputDxe}/VirtioKeyCodes.h (96%) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index e9eeeafce6..0212be4a33 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -438,7 +438,7 @@ <PcdsFixedAtBuild> gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0 } - OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.inf + OvmfPkg/VirtioInputDxe/VirtioInput.inf MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf { diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index 1f346d96ca..1bbf65ed71 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -722,7 +722,7 @@ OvmfPkg/VirtioBlkDxe/VirtioBlk.inf OvmfPkg/VirtioScsiDxe/VirtioScsi.inf OvmfPkg/VirtioSerialDxe/VirtioSerial.inf - OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.inf + OvmfPkg/VirtioInputDxe/VirtioInput.inf MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf diff --git a/OvmfPkg/Bhyve/BhyveX64.fdf b/OvmfPkg/Bhyve/BhyveX64.fdf index 0e894dca9b..41d0374acb 100644 --- a/OvmfPkg/Bhyve/BhyveX64.fdf +++ b/OvmfPkg/Bhyve/BhyveX64.fdf @@ -227,7 +227,7 @@ INF OvmfPkg/Virtio10Dxe/Virtio10.inf INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf INF OvmfPkg/VirtioSerialDxe/VirtioSerial.inf -INF OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.inf +INF OvmfPkg/VirtioInputDxe/VirtioInput.inf !if $(SECURE_BOOT_ENABLE) == TRUE INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c index b696f1b338..3edb92fabc 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c @@ -872,7 +872,7 @@ PrepareVirtioSerialDevicePath ( } EFI_STATUS -PrepareVirtioKeyboardDevicePath ( +PrepareVirtioInputDevicePath ( IN EFI_HANDLE DeviceHandle ) { @@ -1070,8 +1070,8 @@ DetectAndPreparePlatformPciDevicePath ( } if ((Pci->Hdr.VendorId == 0x1af4) && (Pci->Hdr.DeviceId == 0x1052)) { - DEBUG ((DEBUG_INFO, "Found virtio keyboard device\n")); - PrepareVirtioKeyboardDevicePath (Handle); + DEBUG ((DEBUG_INFO, "Found virtio input device\n")); + PrepareVirtioInputDevicePath (Handle); return EFI_SUCCESS; } diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 2119527c1c..d546c3c9ac 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -821,7 +821,7 @@ OvmfPkg/VirtioBlkDxe/VirtioBlk.inf OvmfPkg/VirtioScsiDxe/VirtioScsi.inf OvmfPkg/VirtioSerialDxe/VirtioSerial.inf - OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.inf + OvmfPkg/VirtioInputDxe/VirtioInput.inf MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf index adf98373e9..23731145a7 100644 --- a/OvmfPkg/OvmfPkgIa32X64.fdf +++ b/OvmfPkg/OvmfPkgIa32X64.fdf @@ -201,7 +201,7 @@ INF OvmfPkg/Virtio10Dxe/Virtio10.inf INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf INF OvmfPkg/VirtioSerialDxe/VirtioSerial.inf -INF OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.inf +INF OvmfPkg/VirtioInputDxe/VirtioInput.inf !if $(SECURE_BOOT_ENABLE) == TRUE INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 098c8cd464..d4a452c7e4 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -954,7 +954,7 @@ OvmfPkg/VirtioBlkDxe/VirtioBlk.inf OvmfPkg/VirtioScsiDxe/VirtioScsi.inf OvmfPkg/VirtioSerialDxe/VirtioSerial.inf - OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.inf + OvmfPkg/VirtioInputDxe/VirtioInput.inf MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index bf056fd139..3d1d33ed1d 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -214,7 +214,7 @@ INF OvmfPkg/Virtio10Dxe/Virtio10.inf INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf INF OvmfPkg/VirtioSerialDxe/VirtioSerial.inf -INF OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.inf +INF OvmfPkg/VirtioInputDxe/VirtioInput.inf !if $(SECURE_BOOT_ENABLE) == TRUE INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c b/OvmfPkg/VirtioInputDxe/VirtioInput.c similarity index 79% rename from OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c rename to OvmfPkg/VirtioInputDxe/VirtioInput.c index 205869f239..2422b46269 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.c +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.c @@ -1,6 +1,6 @@ /** @file - This driver produces EFI_SIMPLE_TEXT_INPUT_PROTOCOL for virtarm devices. + Driver for virtio input devices. Copyright (C) 2024, Red Hat, Inc. @@ -15,7 +15,7 @@ #include <Library/UefiLib.h> #include <Library/VirtioLib.h> -#include <VirtioKeyboard.h> +#include <VirtioInput.h> #include <VirtioKeyCodes.h> // ----------------------------------------------------------------------------- @@ -23,8 +23,8 @@ STATIC VOID * BufferPtr ( - IN VIRTIO_KBD_RING *Ring, - IN UINT32 BufferNr + IN VIRTIO_INPUT_RING *Ring, + IN UINT32 BufferNr ) { return Ring->Buffers + Ring->BufferSize * BufferNr; @@ -35,8 +35,8 @@ BufferPtr ( STATIC EFI_PHYSICAL_ADDRESS BufferAddr ( - IN VIRTIO_KBD_RING *Ring, - IN UINT32 BufferNr + IN VIRTIO_INPUT_RING *Ring, + IN UINT32 BufferNr ) { return Ring->DeviceAddress + Ring->BufferSize * BufferNr; @@ -46,7 +46,7 @@ BufferAddr ( STATIC UINT32 BufferNext ( - IN VIRTIO_KBD_RING *Ring + IN VIRTIO_INPUT_RING *Ring ) { return Ring->Indices.NextDescIdx % Ring->Ring.QueueSize; @@ -57,18 +57,18 @@ BufferNext ( STATIC EFI_STATUS EFIAPI -VirtioKeyboardRingSendBuffer ( - IN OUT VIRTIO_KBD_DEV *Dev, - IN UINT16 Index, - IN VOID *Data, - IN UINT32 DataSize, - IN BOOLEAN Notify +VirtioInputRingSendBuffer ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN UINT16 Index, + IN VOID *Data, + IN UINT32 DataSize, + IN BOOLEAN Notify ) { - VIRTIO_KBD_RING *Ring = Dev->Rings + Index; - UINT32 BufferNr = BufferNext (Ring); - UINT16 Idx = *Ring->Ring.Avail.Idx; - UINT16 Flags = 0; + VIRTIO_INPUT_RING *Ring = Dev->Rings + Index; + UINT32 BufferNr = BufferNext (Ring); + UINT16 Idx = *Ring->Ring.Avail.Idx; + UINT16 Flags = 0; ASSERT (DataSize <= Ring->BufferSize); @@ -110,14 +110,14 @@ VirtioKeyboardRingSendBuffer ( STATIC BOOLEAN EFIAPI -VirtioKeyboardRingGetBuffer ( - IN OUT VIRTIO_KBD_DEV *Dev, - IN UINT16 Index, - OUT VOID *Data, - OUT UINT32 *DataSize +VirtioInputRingGetBuffer ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN UINT16 Index, + OUT VOID *Data, + OUT UINT32 *DataSize ) { - VIRTIO_KBD_RING *Ring = Dev->Rings + Index; + VIRTIO_INPUT_RING *Ring = Dev->Rings + Index; UINT16 UsedIdx = *Ring->Ring.Used.Idx; volatile VRING_USED_ELEM *UsedElem; @@ -143,7 +143,7 @@ VirtioKeyboardRingGetBuffer ( if (Index % 2 == 0) { /* RX - re-queue buffer */ - VirtioKeyboardRingSendBuffer (Dev, Index, NULL, Ring->BufferSize, FALSE); + VirtioInputRingSendBuffer (Dev, Index, NULL, Ring->BufferSize, FALSE); } Ring->LastUsedIdx++; @@ -155,16 +155,16 @@ VirtioKeyboardRingGetBuffer ( STATIC EFI_STATUS EFIAPI -VirtioKeyboardInitRing ( - IN OUT VIRTIO_KBD_DEV *Dev, - IN UINT16 Index, - IN UINT32 BufferSize +VirtioInputInitRing ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN UINT16 Index, + IN UINT32 BufferSize ) { - VIRTIO_KBD_RING *Ring = Dev->Rings + Index; - EFI_STATUS Status; - UINT16 QueueSize; - UINT64 RingBaseShift; + VIRTIO_INPUT_RING *Ring = Dev->Rings + Index; + EFI_STATUS Status; + UINT16 QueueSize; + UINT64 RingBaseShift; // // step 4b -- allocate request virtqueue @@ -180,7 +180,7 @@ VirtioKeyboardInitRing ( } // - // VirtioKeyboard uses one descriptor + // VirtioInput uses one descriptor // if (QueueSize < 1) { Status = EFI_UNSUPPORTED; @@ -281,12 +281,12 @@ Failed: STATIC VOID EFIAPI -VirtioKeyboardUninitRing ( - IN OUT VIRTIO_KBD_DEV *Dev, - IN UINT16 Index +VirtioInputUninitRing ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN UINT16 Index ) { - VIRTIO_KBD_RING *Ring = Dev->Rings + Index; + VIRTIO_INPUT_RING *Ring = Dev->Rings + Index; if (Ring->BufferMap) { Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Ring->BufferMap); @@ -319,14 +319,14 @@ VirtioKeyboardUninitRing ( STATIC VOID EFIAPI -VirtioKeyboardUninitAllRings ( - IN OUT VIRTIO_KBD_DEV *Dev +VirtioInputUninitAllRings ( + IN OUT VIRTIO_INPUT_DEV *Dev ) { UINT16 Index; - for (Index = 0; Index < KEYBOARD_MAX_RINGS; Index++) { - VirtioKeyboardUninitRing (Dev, Index); + for (Index = 0; Index < MAX_RINGS; Index++) { + VirtioInputUninitRing (Dev, Index); } } @@ -334,16 +334,16 @@ VirtioKeyboardUninitAllRings ( // Mark all buffers as ready to write and push to device VOID EFIAPI -VirtioKeyboardRingFillRx ( - IN OUT VIRTIO_KBD_DEV *Dev, - IN UINT16 Index +VirtioInputRingFillRx ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN UINT16 Index ) { - VIRTIO_KBD_RING *Ring = Dev->Rings + Index; - UINT32 BufferNr; + VIRTIO_INPUT_RING *Ring = Dev->Rings + Index; + UINT32 BufferNr; for (BufferNr = 0; BufferNr < Ring->BufferCount; BufferNr++) { - VirtioKeyboardRingSendBuffer (Dev, Index, NULL, Ring->BufferSize, FALSE); + VirtioInputRingSendBuffer (Dev, Index, NULL, Ring->BufferSize, FALSE); } Dev->VirtIo->SetQueueNotify (Dev->VirtIo, Index); @@ -353,16 +353,16 @@ VirtioKeyboardRingFillRx ( STATIC VOID EFIAPI -VirtioKeyboardUninit ( - IN OUT VIRTIO_KBD_DEV *Dev +VirtioInputUninit ( + IN OUT VIRTIO_INPUT_DEV *Dev ); // Forward declaration of module Init function STATIC EFI_STATUS EFIAPI -VirtioKeyboardInit ( - IN OUT VIRTIO_KBD_DEV *Dev +VirtioInputInit ( + IN OUT VIRTIO_INPUT_DEV *Dev ); // ----------------------------------------------------------------------------- @@ -370,16 +370,16 @@ VirtioKeyboardInit ( STATIC EFI_STATUS EFIAPI -VirtioKeyboardSimpleTextInputReset ( +VirtioInputSimpleTextInputReset ( IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN BOOLEAN ExtendedVerification ) { - VIRTIO_KBD_DEV *Dev; + VIRTIO_INPUT_DEV *Dev; - Dev = VIRTIO_KEYBOARD_FROM_THIS (This); - VirtioKeyboardUninit (Dev); - VirtioKeyboardInit (Dev); + Dev = VIRTIO_INPUT_FROM_THIS (This); + VirtioInputUninit (Dev); + VirtioInputInit (Dev); return EFI_SUCCESS; } @@ -389,19 +389,19 @@ VirtioKeyboardSimpleTextInputReset ( STATIC EFI_STATUS EFIAPI -VirtioKeyboardSimpleTextInputReadKeyStroke ( +VirtioInputSimpleTextInputReadKeyStroke ( IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, OUT EFI_INPUT_KEY *Key ) { - VIRTIO_KBD_DEV *Dev; - EFI_TPL OldTpl; + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; if (Key == NULL) { return EFI_INVALID_PARAMETER; } - Dev = VIRTIO_KEYBOARD_FROM_THIS (This); + Dev = VIRTIO_INPUT_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_NOTIFY); if (Dev->KeyReady) { @@ -425,10 +425,10 @@ VirtioKeyboardSimpleTextInputReadKeyStroke ( STATIC VOID EFIAPI -VirtioKeyboardConvertKeyCode ( - IN OUT VIRTIO_KBD_DEV *Dev, - IN UINT16 Code, - OUT EFI_INPUT_KEY *Key +VirtioInputConvertKeyCode ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN UINT16 Code, + OUT EFI_INPUT_KEY *Key ) { // Key mapping in between Linux and UEFI @@ -557,22 +557,22 @@ VirtioKeyboardConvertKeyCode ( } // ----------------------------------------------------------------------------- -// Main function processing virtio keyboard events +// Main function processing virtio input events STATIC VOID EFIAPI -VirtioKeyboardGetDeviceData ( - IN OUT VIRTIO_KBD_DEV *Dev +VirtioInputGetDeviceData ( + IN OUT VIRTIO_INPUT_DEV *Dev ) { - BOOLEAN HasData; - UINT8 Data[KEYBOARD_RX_BUFSIZE + 1]; - UINT32 DataSize; - VIRTIO_KBD_EVENT Event; - EFI_TPL OldTpl; + BOOLEAN HasData; + UINT8 Data[RX_BUFSIZE + 1]; + UINT32 DataSize; + VIRTIO_INPUT_EVENT Event; + EFI_TPL OldTpl; for ( ; ; ) { - HasData = VirtioKeyboardRingGetBuffer (Dev, 0, Data, &DataSize); + HasData = VirtioInputRingGetBuffer (Dev, 0, Data, &DataSize); // Exit if no new data if (!HasData) { @@ -605,7 +605,7 @@ VirtioKeyboardGetDeviceData ( Dev->KeyActive[(UINT8)Event.Code] = TRUE; // Evaluate key - VirtioKeyboardConvertKeyCode (Dev, Event.Code, &Dev->LastKey); + VirtioInputConvertKeyCode (Dev, Event.Code, &Dev->LastKey); // Flag that printable character is ready to be send Dev->KeyReady = TRUE; @@ -630,14 +630,14 @@ VirtioKeyboardGetDeviceData ( STATIC VOID EFIAPI -VirtioKeyboardTimer ( +VirtioInputTimer ( IN EFI_EVENT Event, IN VOID *Context ) { - VIRTIO_KBD_DEV *Dev = Context; + VIRTIO_INPUT_DEV *Dev = Context; - VirtioKeyboardGetDeviceData (Dev); + VirtioInputGetDeviceData (Dev); } // ----------------------------------------------------------------------------- @@ -645,12 +645,12 @@ VirtioKeyboardTimer ( STATIC VOID EFIAPI -VirtioKeyboardWaitForKey ( +VirtioInputWaitForKey ( IN EFI_EVENT Event, IN VOID *Context ) { - VIRTIO_KBD_DEV *Dev = (VIRTIO_KBD_DEV *)Context; + VIRTIO_INPUT_DEV *Dev = (VIRTIO_INPUT_DEV *)Context; // // Stall 1ms to give a chance to let other driver interrupt this routine @@ -665,7 +665,7 @@ VirtioKeyboardWaitForKey ( gBS->Stall (1000); // Use TimerEvent callback function to check whether there's any key pressed - VirtioKeyboardTimer (NULL, Dev); + VirtioInputTimer (NULL, Dev); // If there is a new key ready - send signal if (Dev->KeyReady) { @@ -678,16 +678,16 @@ VirtioKeyboardWaitForKey ( STATIC EFI_STATUS EFIAPI -VirtioKeyboardResetEx ( +VirtioInputResetEx ( IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN BOOLEAN ExtendedVerification ) { - VIRTIO_KBD_DEV *Dev; - EFI_STATUS Status; - EFI_TPL OldTpl; + VIRTIO_INPUT_DEV *Dev; + EFI_STATUS Status; + EFI_TPL OldTpl; - Dev = VIRTIO_KEYBOARD_EX_FROM_THIS (This); + Dev = VIRTIO_INPUT_EX_FROM_THIS (This); // Call the reset function from SIMPLE_TEXT_INPUT protocol Status = Dev->Txt.Reset ( @@ -710,21 +710,21 @@ VirtioKeyboardResetEx ( STATIC EFI_STATUS EFIAPI -VirtioKeyboardReadKeyStrokeEx ( +VirtioInputReadKeyStrokeEx ( IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, OUT EFI_KEY_DATA *KeyData ) { - VIRTIO_KBD_DEV *Dev; - EFI_STATUS Status; - EFI_INPUT_KEY Key; - EFI_KEY_STATE KeyState; + VIRTIO_INPUT_DEV *Dev; + EFI_STATUS Status; + EFI_INPUT_KEY Key; + EFI_KEY_STATE KeyState; if (KeyData == NULL) { return EFI_INVALID_PARAMETER; } - Dev = VIRTIO_KEYBOARD_EX_FROM_THIS (This); + Dev = VIRTIO_INPUT_EX_FROM_THIS (This); // Get the last pressed key Status = Dev->Txt.ReadKeyStroke (&Dev->Txt, &Key); @@ -775,7 +775,7 @@ VirtioKeyboardReadKeyStrokeEx ( STATIC EFI_STATUS EFIAPI -VirtioKeyboardSetState ( +VirtioInputSetState ( IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_TOGGLE_STATE *KeyToggleState ) @@ -827,19 +827,19 @@ IsKeyRegistered ( STATIC EFI_STATUS EFIAPI -VirtioKeyboardRegisterKeyNotify ( +VirtioInputRegisterKeyNotify ( IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_DATA *KeyData, IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction, OUT VOID **NotifyHandle ) { - EFI_STATUS Status; - VIRTIO_KBD_DEV *Dev; - EFI_TPL OldTpl; - LIST_ENTRY *Link; - VIRTIO_KBD_IN_EX_NOTIFY *NewNotify; - VIRTIO_KBD_IN_EX_NOTIFY *CurrentNotify; + EFI_STATUS Status; + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; + LIST_ENTRY *Link; + VIRTIO_INPUT_IN_EX_NOTIFY *NewNotify; + VIRTIO_INPUT_IN_EX_NOTIFY *CurrentNotify; if ((KeyData == NULL) || (NotifyHandle == NULL) || @@ -848,20 +848,20 @@ VirtioKeyboardRegisterKeyNotify ( return EFI_INVALID_PARAMETER; } - Dev = VIRTIO_KEYBOARD_EX_FROM_THIS (This); + Dev = VIRTIO_INPUT_EX_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_NOTIFY); // Check if the (KeyData, NotificationFunction) pair is already registered. - for (Link = Dev->NotifyList.ForwardLink; - Link != &Dev->NotifyList; + for (Link = Dev->KeyNotifyList.ForwardLink; + Link != &Dev->KeyNotifyList; Link = Link->ForwardLink) { CurrentNotify = CR ( Link, - VIRTIO_KBD_IN_EX_NOTIFY, + VIRTIO_INPUT_IN_EX_NOTIFY, NotifyEntry, - VIRTIO_KBD_SIG + VIRTIO_INPUT_SIG ); if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) { @@ -872,16 +872,16 @@ VirtioKeyboardRegisterKeyNotify ( } } - NewNotify = (VIRTIO_KBD_IN_EX_NOTIFY *)AllocateZeroPool (sizeof (VIRTIO_KBD_IN_EX_NOTIFY)); + NewNotify = (VIRTIO_INPUT_IN_EX_NOTIFY *)AllocateZeroPool (sizeof (VIRTIO_INPUT_IN_EX_NOTIFY)); if (NewNotify == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Exit; } - NewNotify->Signature = VIRTIO_KBD_SIG; + NewNotify->Signature = VIRTIO_INPUT_SIG; NewNotify->KeyNotificationFn = KeyNotificationFunction; CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA)); - InsertTailList (&Dev->NotifyList, &NewNotify->NotifyEntry); + InsertTailList (&Dev->KeyNotifyList, &NewNotify->NotifyEntry); *NotifyHandle = NewNotify; Status = EFI_SUCCESS; @@ -897,38 +897,38 @@ Exit: STATIC EFI_STATUS EFIAPI -VirtioKeyboardUnregisterKeyNotify ( +VirtioInputUnregisterKeyNotify ( IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN VOID *NotificationHandle ) { - EFI_STATUS Status; - VIRTIO_KBD_DEV *Dev; - EFI_TPL OldTpl; - LIST_ENTRY *Link; - VIRTIO_KBD_IN_EX_NOTIFY *CurrentNotify; + EFI_STATUS Status; + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; + LIST_ENTRY *Link; + VIRTIO_INPUT_IN_EX_NOTIFY *CurrentNotify; if (NotificationHandle == NULL) { return EFI_INVALID_PARAMETER; } - if (((VIRTIO_KBD_IN_EX_NOTIFY *)NotificationHandle)->Signature != VIRTIO_KBD_SIG) { + if (((VIRTIO_INPUT_IN_EX_NOTIFY *)NotificationHandle)->Signature != VIRTIO_INPUT_SIG) { return EFI_INVALID_PARAMETER; } - Dev = VIRTIO_KEYBOARD_EX_FROM_THIS (This); + Dev = VIRTIO_INPUT_EX_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_NOTIFY); - for (Link = Dev->NotifyList.ForwardLink; - Link != &Dev->NotifyList; + for (Link = Dev->KeyNotifyList.ForwardLink; + Link != &Dev->KeyNotifyList; Link = Link->ForwardLink) { CurrentNotify = CR ( Link, - VIRTIO_KBD_IN_EX_NOTIFY, + VIRTIO_INPUT_IN_EX_NOTIFY, NotifyEntry, - VIRTIO_KBD_SIG + VIRTIO_INPUT_SIG ); if (CurrentNotify == NotificationHandle) { RemoveEntryList (&CurrentNotify->NotifyEntry); @@ -952,8 +952,8 @@ Exit: STATIC EFI_STATUS EFIAPI -VirtioKeyboardInit ( - IN OUT VIRTIO_KBD_DEV *Dev +VirtioInputInit ( + IN OUT VIRTIO_INPUT_DEV *Dev ) { UINT8 NextDevStat; @@ -1010,7 +1010,7 @@ VirtioKeyboardInit ( } } - Status = VirtioKeyboardInitRing (Dev, 0, KEYBOARD_RX_BUFSIZE); + Status = VirtioInputInitRing (Dev, 0, RX_BUFSIZE); if (EFI_ERROR (Status)) { goto Failed; } @@ -1044,8 +1044,8 @@ VirtioKeyboardInit ( // EFI_INPUT_READ_KEY ReadKeyStroke; // EFI_EVENT WaitForKey; // }; - Dev->Txt.Reset = (EFI_INPUT_RESET)VirtioKeyboardSimpleTextInputReset; - Dev->Txt.ReadKeyStroke = VirtioKeyboardSimpleTextInputReadKeyStroke; + Dev->Txt.Reset = (EFI_INPUT_RESET)VirtioInputSimpleTextInputReset; + Dev->Txt.ReadKeyStroke = VirtioInputSimpleTextInputReadKeyStroke; // struct _EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL { // EFI_INPUT_RESET_EX Reset; @@ -1055,12 +1055,12 @@ VirtioKeyboardInit ( // EFI_REGISTER_KEYSTROKE_NOTIFY RegisterKeyNotify; // EFI_UNREGISTER_KEYSTROKE_NOTIFY UnregisterKeyNotify; // } - Dev->TxtEx.Reset = (EFI_INPUT_RESET_EX)VirtioKeyboardResetEx; - Dev->TxtEx.ReadKeyStrokeEx = VirtioKeyboardReadKeyStrokeEx; - Dev->TxtEx.SetState = VirtioKeyboardSetState; - Dev->TxtEx.RegisterKeyNotify = VirtioKeyboardRegisterKeyNotify; - Dev->TxtEx.UnregisterKeyNotify = VirtioKeyboardUnregisterKeyNotify; - InitializeListHead (&Dev->NotifyList); + Dev->TxtEx.Reset = (EFI_INPUT_RESET_EX)VirtioInputResetEx; + Dev->TxtEx.ReadKeyStrokeEx = VirtioInputReadKeyStrokeEx; + Dev->TxtEx.SetState = VirtioInputSetState; + Dev->TxtEx.RegisterKeyNotify = VirtioInputRegisterKeyNotify; + Dev->TxtEx.UnregisterKeyNotify = VirtioInputUnregisterKeyNotify; + InitializeListHead (&Dev->KeyNotifyList); // // Setup the WaitForKey event @@ -1068,7 +1068,7 @@ VirtioKeyboardInit ( Status = gBS->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY, - VirtioKeyboardWaitForKey, + VirtioInputWaitForKey, Dev, &(Dev->Txt.WaitForKey) ); @@ -1082,7 +1082,7 @@ VirtioKeyboardInit ( Status = gBS->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY, - VirtioKeyboardWaitForKey, + VirtioInputWaitForKey, Dev, &(Dev->TxtEx.WaitForKeyEx) ); @@ -1090,7 +1090,7 @@ VirtioKeyboardInit ( goto Failed; } - VirtioKeyboardRingFillRx (Dev, 0); + VirtioInputRingFillRx (Dev, 0); // // Event for reading key in time intervals @@ -1098,18 +1098,18 @@ VirtioKeyboardInit ( Status = gBS->CreateEvent ( EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_NOTIFY, - VirtioKeyboardTimer, + VirtioInputTimer, Dev, - &Dev->KeyReadTimer + &Dev->PollTimer ); if (EFI_ERROR (Status)) { goto Failed; } Status = gBS->SetTimer ( - Dev->KeyReadTimer, + Dev->PollTimer, TimerPeriodic, - EFI_TIMER_PERIOD_MILLISECONDS (KEYBOARD_PROBE_TIME_MS) + EFI_TIMER_PERIOD_MILLISECONDS (PROBE_TIME_MS) ); if (EFI_ERROR (Status)) { goto Failed; @@ -1118,8 +1118,7 @@ VirtioKeyboardInit ( return EFI_SUCCESS; Failed: - VirtioKeyboardUninitAllRings (Dev); - // VirtualKeyboardFreeNotifyList (&VirtualKeyboardPrivate->NotifyList); + VirtioInputUninitAllRings (Dev); // // Notify the host about our failure to setup: virtio-0.9.5, 2.2.2.1 Device @@ -1136,11 +1135,11 @@ Failed: STATIC VOID EFIAPI -VirtioKeyboardUninit ( - IN OUT VIRTIO_KBD_DEV *Dev +VirtioInputUninit ( + IN OUT VIRTIO_INPUT_DEV *Dev ) { - gBS->CloseEvent (Dev->KeyReadTimer); + gBS->CloseEvent (Dev->PollTimer); gBS->CloseEvent (Dev->Txt.WaitForKey); gBS->CloseEvent (Dev->TxtEx.WaitForKeyEx); @@ -1151,7 +1150,7 @@ VirtioKeyboardUninit ( // Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); - VirtioKeyboardUninitAllRings (Dev); + VirtioInputUninitAllRings (Dev); } // ----------------------------------------------------------------------------- @@ -1159,12 +1158,12 @@ VirtioKeyboardUninit ( STATIC VOID EFIAPI -VirtioKeyboardExitBoot ( +VirtioInputExitBoot ( IN EFI_EVENT Event, IN VOID *Context ) { - VIRTIO_KBD_DEV *Dev; + VIRTIO_INPUT_DEV *Dev; DEBUG ((DEBUG_INFO, "%a: Context=0x%p\n", __func__, Context)); // @@ -1183,7 +1182,7 @@ VirtioKeyboardExitBoot ( STATIC EFI_STATUS EFIAPI -VirtioKeyboardBindingSupported ( +VirtioInputBindingSupported ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE DeviceHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath @@ -1238,16 +1237,16 @@ VirtioKeyboardBindingSupported ( STATIC EFI_STATUS EFIAPI -VirtioKeyboardBindingStart ( +VirtioInputBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE DeviceHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) { - VIRTIO_KBD_DEV *Dev; - EFI_STATUS Status; + VIRTIO_INPUT_DEV *Dev; + EFI_STATUS Status; - Dev = (VIRTIO_KBD_DEV *)AllocateZeroPool (sizeof *Dev); + Dev = (VIRTIO_INPUT_DEV *)AllocateZeroPool (sizeof *Dev); if (Dev == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -1261,13 +1260,13 @@ VirtioKeyboardBindingStart ( EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { - goto FreeVirtioKbd; + goto FreeVirtioInput; } // // VirtIo access granted, configure virtio keyboard device. // - Status = VirtioKeyboardInit (Dev); + Status = VirtioInputInit (Dev); if (EFI_ERROR (Status)) { goto CloseVirtIo; } @@ -1275,7 +1274,7 @@ VirtioKeyboardBindingStart ( Status = gBS->CreateEvent ( EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK, - &VirtioKeyboardExitBoot, + &VirtioInputExitBoot, Dev, &Dev->ExitBoot ); @@ -1287,7 +1286,7 @@ VirtioKeyboardBindingStart ( // Setup complete, attempt to export the driver instance's EFI_SIMPLE_TEXT_INPUT_PROTOCOL // interface. // - Dev->Signature = VIRTIO_KBD_SIG; + Dev->Signature = VIRTIO_INPUT_SIG; Status = gBS->InstallMultipleProtocolInterfaces ( &DeviceHandle, &gEfiSimpleTextInProtocolGuid, @@ -1306,7 +1305,7 @@ CloseExitBoot: gBS->CloseEvent (Dev->ExitBoot); UninitDev: - VirtioKeyboardUninit (Dev); + VirtioInputUninit (Dev); CloseVirtIo: gBS->CloseProtocol ( @@ -1316,7 +1315,7 @@ CloseVirtIo: DeviceHandle ); -FreeVirtioKbd: +FreeVirtioInput: FreePool (Dev); return Status; @@ -1327,7 +1326,7 @@ FreeVirtioKbd: STATIC EFI_STATUS EFIAPI -VirtioKeyboardBindingStop ( +VirtioInputBindingStop ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE DeviceHandle, IN UINTN NumberOfChildren, @@ -1336,7 +1335,7 @@ VirtioKeyboardBindingStop ( { EFI_STATUS Status; EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Txt; - VIRTIO_KBD_DEV *Dev; + VIRTIO_INPUT_DEV *Dev; Status = gBS->OpenProtocol ( DeviceHandle, // candidate device @@ -1350,7 +1349,7 @@ VirtioKeyboardBindingStop ( return Status; } - Dev = VIRTIO_KEYBOARD_FROM_THIS (Txt); + Dev = VIRTIO_INPUT_FROM_THIS (Txt); // // Handle Stop() requests for in-use driver instances gracefully. @@ -1369,7 +1368,7 @@ VirtioKeyboardBindingStop ( gBS->CloseEvent (Dev->ExitBoot); - VirtioKeyboardUninit (Dev); + VirtioInputUninit (Dev); gBS->CloseProtocol ( DeviceHandle, @@ -1392,8 +1391,8 @@ EFI_COMPONENT_NAME_PROTOCOL gComponentName; // Driver name to be displayed STATIC EFI_UNICODE_STRING_TABLE mDriverNameTable[] = { - { "eng;en", L"Virtio Keyboard Driver" }, - { NULL, NULL } + { "eng;en", L"Virtio Input Driver" }, + { NULL, NULL } }; // ----------------------------------------------------------------------------- @@ -1401,7 +1400,7 @@ EFI_UNICODE_STRING_TABLE mDriverNameTable[] = { STATIC EFI_STATUS EFIAPI -VirtioKeyboardGetDriverName ( +VirtioInputGetDriverName ( IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName @@ -1420,8 +1419,8 @@ VirtioKeyboardGetDriverName ( // Device name to be displayed STATIC EFI_UNICODE_STRING_TABLE mDeviceNameTable[] = { - { "eng;en", L"RHEL virtio virtual keyboard BOB (Basic Operation Board)" }, - { NULL, NULL } + { "eng;en", L"Red Hat Virtio Input device" }, + { NULL, NULL } }; // ----------------------------------------------------------------------------- @@ -1432,7 +1431,7 @@ EFI_COMPONENT_NAME_PROTOCOL gDeviceName; STATIC EFI_STATUS EFIAPI -VirtioKeyboardGetDeviceName ( +VirtioInputGetDeviceName ( IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE DeviceHandle, IN EFI_HANDLE ChildHandle, @@ -1453,8 +1452,8 @@ VirtioKeyboardGetDeviceName ( // General driver UEFI interface for showing driver name STATIC EFI_COMPONENT_NAME_PROTOCOL gComponentName = { - &VirtioKeyboardGetDriverName, - &VirtioKeyboardGetDeviceName, + &VirtioInputGetDriverName, + &VirtioInputGetDeviceName, "eng" // SupportedLanguages, ISO 639-2 language codes }; @@ -1462,20 +1461,20 @@ EFI_COMPONENT_NAME_PROTOCOL gComponentName = { // General driver UEFI interface for showing driver name STATIC EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = { - (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)&VirtioKeyboardGetDriverName, - (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)&VirtioKeyboardGetDeviceName, + (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)&VirtioInputGetDriverName, + (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)&VirtioInputGetDeviceName, "en" // SupportedLanguages, RFC 4646 language codes }; // ----------------------------------------------------------------------------- // General driver UEFI interface for loading / unloading driver STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = { - &VirtioKeyboardBindingSupported, - &VirtioKeyboardBindingStart, - &VirtioKeyboardBindingStop, + &VirtioInputBindingSupported, + &VirtioInputBindingStart, + &VirtioInputBindingStop, 0x10, // Version, must be in [0x10 .. 0xFFFFFFEF] for IHV-developed drivers NULL, // ImageHandle, to be overwritten by - // EfiLibInstallDriverBindingComponentName2() in VirtioKeyboardEntryPoint() + // EfiLibInstallDriverBindingComponentName2() in VirtioInputEntryPoint() NULL // DriverBindingHandle, ditto }; @@ -1483,12 +1482,12 @@ STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = { // Driver entry point set in INF file, registers all driver functions into UEFI EFI_STATUS EFIAPI -VirtioKeyboardEntryPoint ( +VirtioInputEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { - DEBUG ((DEBUG_INFO, "Virtio keyboard has been loaded.......................\n")); + DEBUG ((DEBUG_INFO, "Virtio input driver has been loaded.......................\n")); return EfiLibInstallDriverBindingComponentName2 ( ImageHandle, SystemTable, diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h b/OvmfPkg/VirtioInputDxe/VirtioInput.h similarity index 73% rename from OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h rename to OvmfPkg/VirtioInputDxe/VirtioInput.h index 242f005f74..11bb332692 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.h +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.h @@ -1,6 +1,6 @@ /** @file - Private definitions of the VirtioKeyboard driver + Private definitions of the VirtioInput driver Copyright (C) 2024, Red Hat @@ -17,13 +17,13 @@ #include <IndustryStandard/Virtio.h> -#define VIRTIO_KBD_SIG SIGNATURE_32 ('V', 'K', 'B', 'D') +#define VIRTIO_INPUT_SIG SIGNATURE_32 ('V', 'I', 'N', 'P') -#define KEYBOARD_MAX_RINGS 2 -#define KEYBOARD_RX_BUFSIZE 64 +#define MAX_RINGS 2 +#define RX_BUFSIZE 64 -// Fetch new key from VirtIO every 50ms -#define KEYBOARD_PROBE_TIME_MS 50 +// Fetch new input from VirtIO every 50ms +#define PROBE_TIME_MS 50 // Max range of recognized keyboard codes #define MAX_KEYBOARD_CODE 255 @@ -33,14 +33,14 @@ typedef struct { EFI_KEY_DATA KeyData; EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn; LIST_ENTRY NotifyEntry; -} VIRTIO_KBD_IN_EX_NOTIFY; +} VIRTIO_INPUT_IN_EX_NOTIFY; // Data structure representing payload delivered from VirtIo typedef struct { UINT16 Type; UINT16 Code; UINT32 Value; -} VIRTIO_KBD_EVENT; +} VIRTIO_INPUT_EVENT; // Data structure representing ring buffer typedef struct { @@ -57,7 +57,7 @@ typedef struct { EFI_PHYSICAL_ADDRESS DeviceAddress; BOOLEAN Ready; -} VIRTIO_KBD_RING; +} VIRTIO_INPUT_RING; // Declaration of data structure representing driver context typedef struct { @@ -90,13 +90,13 @@ typedef struct { VIRTIO_DEVICE_PROTOCOL *VirtIo; // Hook for ring buffer - VIRTIO_KBD_RING Rings[KEYBOARD_MAX_RINGS]; + VIRTIO_INPUT_RING Rings[MAX_RINGS]; - // Timer event for checking key presses from VirtIo - EFI_EVENT KeyReadTimer; + // Timer event for checking input from VirtIo + EFI_EVENT PollTimer; // List for notifications - LIST_ENTRY NotifyList; + LIST_ENTRY KeyNotifyList; // Last pressed key // typedef struct { @@ -110,13 +110,13 @@ typedef struct { // If key is ready BOOLEAN KeyReady; -} VIRTIO_KBD_DEV; +} VIRTIO_INPUT_DEV; -// Helper functions to extract VIRTIO_KBD_DEV structure pointers -#define VIRTIO_KEYBOARD_FROM_THIS(KbrPointer) \ - CR (KbrPointer, VIRTIO_KBD_DEV, Txt, VIRTIO_KBD_SIG) -#define VIRTIO_KEYBOARD_EX_FROM_THIS(KbrPointer) \ - CR (KbrPointer, VIRTIO_KBD_DEV, TxtEx, VIRTIO_KBD_SIG) +// Helper functions to extract VIRTIO_INPUT_DEV structure pointers +#define VIRTIO_INPUT_FROM_THIS(KbrPointer) \ + CR (KbrPointer, VIRTIO_INPUT_DEV, Txt, VIRTIO_INPUT_SIG) +#define VIRTIO_INPUT_EX_FROM_THIS(KbrPointer) \ + CR (KbrPointer, VIRTIO_INPUT_DEV, TxtEx, VIRTIO_INPUT_SIG) // Bellow candidates to be included as Linux header #define KEY_PRESSED 1 diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.inf b/OvmfPkg/VirtioInputDxe/VirtioInput.inf similarity index 72% rename from OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.inf rename to OvmfPkg/VirtioInputDxe/VirtioInput.inf index 6c35f2a4ce..d5575ac733 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyboard.inf +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.inf @@ -1,5 +1,5 @@ ## @file -# This driver produces EFI_SIMPLE_TEXT_INPUT_PROTOCOL for virt ARM devices. +# VirtIO Input DXE driver # # Copyright (C) 2024, Red Hat # @@ -9,15 +9,15 @@ [Defines] INF_VERSION = 1.29 - BASE_NAME = VirtioKeyboardDxe + BASE_NAME = VirtioInputDxe FILE_GUID = F141B1E5-9C7C-44CC-AFAA-E87D7689B113 MODULE_TYPE = UEFI_DRIVER VERSION_STRING = 1.0 - ENTRY_POINT = VirtioKeyboardEntryPoint + ENTRY_POINT = VirtioInputEntryPoint [Sources] - VirtioKeyboard.c - VirtioKeyboard.h + VirtioInput.c + VirtioInput.h VirtioKeyCodes.h [Packages] diff --git a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyCodes.h b/OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h similarity index 96% rename from OvmfPkg/VirtioKeyboardDxe/VirtioKeyCodes.h rename to OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h index fe5ddc5a51..70d8c454ac 100644 --- a/OvmfPkg/VirtioKeyboardDxe/VirtioKeyCodes.h +++ b/OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h @@ -1,6 +1,6 @@ /** @file - Key codes definitions for the VirtioKeyboard driver + Key codes definitions for the virtio input driver This is a fork of common Linux key codes: https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h From ae92eb78f6a45294a1c3dc637f69745e2f969bab Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Tue, 23 Jun 2026 20:53:51 +0800 Subject: [PATCH 224/406] OvmfPkg/IndustryStandard: Add type definitions for virtio input device Add IndustryStandard/VirtioInput.h for virtio input device type definitions defined in virtio 1.1 specification. https://docs.oasis-open.org/virtio/virtio/v1.1/cs01/virtio-v1.1-cs01.html#x1-3390008 Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- .../Include/IndustryStandard/VirtioInput.h | 72 +++++++++++++++++++ OvmfPkg/VirtioInputDxe/VirtioInput.c | 2 + OvmfPkg/VirtioInputDxe/VirtioInput.h | 7 -- 3 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 OvmfPkg/Include/IndustryStandard/VirtioInput.h diff --git a/OvmfPkg/Include/IndustryStandard/VirtioInput.h b/OvmfPkg/Include/IndustryStandard/VirtioInput.h new file mode 100644 index 0000000000..d8002e702f --- /dev/null +++ b/OvmfPkg/Include/IndustryStandard/VirtioInput.h @@ -0,0 +1,72 @@ +/** @file + + Virtio Input Device specific type and macro definitions corresponding to + the virtio 1.1 specification. + https://docs.oasis-open.org/virtio/virtio/v1.1/cs01/virtio-v1.1-cs01.html#x1-3390008 + + Copyright (C) 2026, Advanced Micro Devices, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#pragma once + +#include <IndustryStandard/Virtio.h> + +#pragma pack(1) + +// +// Device configuration +// +typedef enum { + VirtioInputCfg = 0x00, + VirtioInputCfgIdName = 0x01, + VirtioInputCfgIdSerial = 0x02, + VirtioInputCfgIdDevids = 0x03, + VirtioInputCfgPropBits = 0x10, + VirtioInputCfgEvBits = 0x11, + VirtioInputCfgAbsInfo = 0x12, +} VIRTIO_INPUT_CONFIG_SELECT; + +typedef struct { + UINT32 Min; + UINT32 Max; + UINT32 Fuzz; + UINT32 Flat; + UINT32 Res; +} VIRTIO_INPUT_ABS_INFO; + +typedef struct { + UINT16 Bustype; + UINT16 Vendor; + UINT16 Product; + UINT16 Version; +} VIRTIO_INPUT_DEVIDS; + +typedef struct { + UINT8 Select; + UINT8 Subsel; + UINT8 Size; + UINT8 Reserved[5]; + union { + CHAR8 String[128]; + UINT8 Bitmap[128]; + VIRTIO_INPUT_ABS_INFO Abs; + VIRTIO_INPUT_DEVIDS Ids; + } Data; +} VIRTIO_INPUT_CONFIG; + +#define OFFSET_OF_VINPUT(Field) OFFSET_OF (VIRTIO_INPUT_CONFIG, Field) +#define SIZE_OF_VINPUT(Field) (sizeof ((VIRTIO_INPUT_CONFIG *) 0)->Field) + +// +// Device Operation +// +typedef struct { + UINT16 Type; + UINT16 Code; + UINT32 Value; +} VIRTIO_INPUT_EVENT; + +#pragma pack () diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.c b/OvmfPkg/VirtioInputDxe/VirtioInput.c index 2422b46269..2ede3fd3f7 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.c +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.c @@ -15,6 +15,8 @@ #include <Library/UefiLib.h> #include <Library/VirtioLib.h> +#include <IndustryStandard/VirtioInput.h> + #include <VirtioInput.h> #include <VirtioKeyCodes.h> diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.h b/OvmfPkg/VirtioInputDxe/VirtioInput.h index 11bb332692..9122f3f0bc 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.h +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.h @@ -35,13 +35,6 @@ typedef struct { LIST_ENTRY NotifyEntry; } VIRTIO_INPUT_IN_EX_NOTIFY; -// Data structure representing payload delivered from VirtIo -typedef struct { - UINT16 Type; - UINT16 Code; - UINT32 Value; -} VIRTIO_INPUT_EVENT; - // Data structure representing ring buffer typedef struct { VRING Ring; From 0fc04cff3b211b979cb3b5f1602d1c6c5aad3bfe Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Tue, 23 Jun 2026 21:56:28 +0800 Subject: [PATCH 225/406] OvmfPkg/VirtioInputDxe: Fix Reset() function to only flush input state According to UEFI specification, "the implementation of Reset is required to clear the contents of any input queues resident in memory used for buffering keystroke data and put the input stream in a known empty state". So it should only reset the internal status of keyboard driver, not the driver itself. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioInputDxe/VirtioInput.c | 40 +++++++++------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.c b/OvmfPkg/VirtioInputDxe/VirtioInput.c index 2ede3fd3f7..f3be59d446 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.c +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.c @@ -351,38 +351,29 @@ VirtioInputRingFillRx ( Dev->VirtIo->SetQueueNotify (Dev->VirtIo, Index); } -// Forward declaration of module Uninit function -STATIC -VOID -EFIAPI -VirtioInputUninit ( - IN OUT VIRTIO_INPUT_DEV *Dev - ); - -// Forward declaration of module Init function -STATIC -EFI_STATUS -EFIAPI -VirtioInputInit ( - IN OUT VIRTIO_INPUT_DEV *Dev - ); - // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_PROTOCOL API STATIC EFI_STATUS EFIAPI VirtioInputSimpleTextInputReset ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN BOOLEAN ExtendedVerification + IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, + IN BOOLEAN ExtendedVerification ) { VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; Dev = VIRTIO_INPUT_FROM_THIS (This); - VirtioInputUninit (Dev); - VirtioInputInit (Dev); + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + + Dev->KeyReady = FALSE; + Dev->LastKey.ScanCode = SCAN_NULL; + Dev->LastKey.UnicodeChar = CHAR_NULL; + ZeroMem (Dev->KeyActive, sizeof (Dev->KeyActive)); + + gBS->RestoreTPL (OldTpl); return EFI_SUCCESS; } @@ -687,7 +678,6 @@ VirtioInputResetEx ( { VIRTIO_INPUT_DEV *Dev; EFI_STATUS Status; - EFI_TPL OldTpl; Dev = VIRTIO_INPUT_EX_FROM_THIS (This); @@ -696,14 +686,10 @@ VirtioInputResetEx ( &Dev->Txt, ExtendedVerification ); - if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } - OldTpl = gBS->RaiseTPL (TPL_NOTIFY); - gBS->RestoreTPL (OldTpl); - return EFI_SUCCESS; } @@ -1046,7 +1032,7 @@ VirtioInputInit ( // EFI_INPUT_READ_KEY ReadKeyStroke; // EFI_EVENT WaitForKey; // }; - Dev->Txt.Reset = (EFI_INPUT_RESET)VirtioInputSimpleTextInputReset; + Dev->Txt.Reset = VirtioInputSimpleTextInputReset; Dev->Txt.ReadKeyStroke = VirtioInputSimpleTextInputReadKeyStroke; // struct _EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL { @@ -1057,7 +1043,7 @@ VirtioInputInit ( // EFI_REGISTER_KEYSTROKE_NOTIFY RegisterKeyNotify; // EFI_UNREGISTER_KEYSTROKE_NOTIFY UnregisterKeyNotify; // } - Dev->TxtEx.Reset = (EFI_INPUT_RESET_EX)VirtioInputResetEx; + Dev->TxtEx.Reset = VirtioInputResetEx; Dev->TxtEx.ReadKeyStrokeEx = VirtioInputReadKeyStrokeEx; Dev->TxtEx.SetState = VirtioInputSetState; Dev->TxtEx.RegisterKeyNotify = VirtioInputRegisterKeyNotify; From d0c42935e22c8678aa15a79e0fe80294a115fcd4 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Wed, 24 Jun 2026 15:13:29 +0800 Subject: [PATCH 226/406] OvmfPkg/VirtioInputDxe: Add keyboard capability detection Current driver produces the EFI_SIMPLE_TEXT_INPUT[_EX]_PROTOCOL interfaces on every virtio-input device it binds. A virtio-input device may however be a pointer device (mouse or tablet) that reports no keyboard keys, in which case the keyboard protocols should not be installed. Add VirtioInputHasKeyboard() to check whether the virtio-input device implements a keyboard by scanning the EV_KEY capability bitmap to see if any keycodes between [0, MAX_KEYBOARD_CODE] is supported. A helper function VirtioInputConfigQuerySize() is also added for fetching the size of a virtio-input configuration sub-selection. VirtioInputInit() now stores the result in Dev->HasKeyboard and fails with EFI_UNSUPPORTED when no keyboard is present. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioInputDxe/VirtioInput.c | 199 ++++++++++++++++++--------- OvmfPkg/VirtioInputDxe/VirtioInput.h | 2 + 2 files changed, 133 insertions(+), 68 deletions(-) diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.c b/OvmfPkg/VirtioInputDxe/VirtioInput.c index f3be59d446..b2f70e77e5 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.c +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.c @@ -351,6 +351,63 @@ VirtioInputRingFillRx ( Dev->VirtIo->SetQueueNotify (Dev->VirtIo, Index); } +STATIC +EFI_STATUS +VirtioInputConfigQuerySize ( + IN VIRTIO_INPUT_DEV *Dev, + IN VIRTIO_INPUT_CONFIG_SELECT Select, + IN UINT8 Subsel, + OUT UINT8 *Size + ) +{ + EFI_STATUS Status; + + Status = Dev->VirtIo->WriteDevice (Dev->VirtIo, OFFSET_OF_VINPUT (Select), SIZE_OF_VINPUT (Select), Select); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = Dev->VirtIo->WriteDevice (Dev->VirtIo, OFFSET_OF_VINPUT (Subsel), SIZE_OF_VINPUT (Subsel), Subsel); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = Dev->VirtIo->ReadDevice (Dev->VirtIo, OFFSET_OF_VINPUT (Size), SIZE_OF_VINPUT (Size), sizeof (*Size), Size); + return Status; +} + +STATIC +BOOLEAN +VirtioInputHasKeyboard ( + IN VIRTIO_INPUT_DEV *Dev + ) +{ + EFI_STATUS Status; + UINT8 Size; + UINT8 Bitmap; + UINTN Index; + + Status = VirtioInputConfigQuerySize (Dev, VirtioInputCfgEvBits, EV_KEY, &Size); + if (EFI_ERROR (Status)) { + return FALSE; + } + + // Keyboard keys are 0 ~ 255, so if any of them is supported, we have a keyboard + Size = MIN (Size, (MAX_KEYBOARD_CODE / 8) + 1); + for (Index = 0; Index < Size; Index++) { + Status = Dev->VirtIo->ReadDevice (Dev->VirtIo, OFFSET_OF_VINPUT (Data) + Index, 1, 1, &Bitmap); + if (EFI_ERROR (Status)) { + return FALSE; + } + + if (Bitmap) { + return TRUE; + } + } + + return FALSE; +} + // ----------------------------------------------------------------------------- // EFI_SIMPLE_TEXT_INPUT_PROTOCOL API STATIC @@ -1024,58 +1081,56 @@ VirtioInputInit ( } // - // populate the exported interface's attributes + // Check input device capabilities // - - // struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL { - // EFI_INPUT_RESET Reset; - // EFI_INPUT_READ_KEY ReadKeyStroke; - // EFI_EVENT WaitForKey; - // }; - Dev->Txt.Reset = VirtioInputSimpleTextInputReset; - Dev->Txt.ReadKeyStroke = VirtioInputSimpleTextInputReadKeyStroke; - - // struct _EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL { - // EFI_INPUT_RESET_EX Reset; - // EFI_INPUT_READ_KEY_EX ReadKeyStrokeEx; - // EFI_EVENT WaitForKeyEx; - // EFI_SET_STATE SetState; - // EFI_REGISTER_KEYSTROKE_NOTIFY RegisterKeyNotify; - // EFI_UNREGISTER_KEYSTROKE_NOTIFY UnregisterKeyNotify; - // } - Dev->TxtEx.Reset = VirtioInputResetEx; - Dev->TxtEx.ReadKeyStrokeEx = VirtioInputReadKeyStrokeEx; - Dev->TxtEx.SetState = VirtioInputSetState; - Dev->TxtEx.RegisterKeyNotify = VirtioInputRegisterKeyNotify; - Dev->TxtEx.UnregisterKeyNotify = VirtioInputUnregisterKeyNotify; - InitializeListHead (&Dev->KeyNotifyList); - - // - // Setup the WaitForKey event - // - Status = gBS->CreateEvent ( - EVT_NOTIFY_WAIT, - TPL_NOTIFY, - VirtioInputWaitForKey, - Dev, - &(Dev->Txt.WaitForKey) - ); - if (EFI_ERROR (Status)) { + Dev->HasKeyboard = VirtioInputHasKeyboard (Dev); + if (!Dev->HasKeyboard) { + Status = EFI_UNSUPPORTED; goto Failed; } // - // Setup the WaitForKeyEx event + // populate the exported interface's attributes // - Status = gBS->CreateEvent ( - EVT_NOTIFY_WAIT, - TPL_NOTIFY, - VirtioInputWaitForKey, - Dev, - &(Dev->TxtEx.WaitForKeyEx) - ); - if (EFI_ERROR (Status)) { - goto Failed; + if (Dev->HasKeyboard) { + Dev->Txt.Reset = VirtioInputSimpleTextInputReset; + Dev->Txt.ReadKeyStroke = VirtioInputSimpleTextInputReadKeyStroke; + Dev->Txt.WaitForKey = (EFI_EVENT)VirtioInputWaitForKey; + + Dev->TxtEx.Reset = VirtioInputResetEx; + Dev->TxtEx.ReadKeyStrokeEx = VirtioInputReadKeyStrokeEx; + Dev->TxtEx.SetState = VirtioInputSetState; + Dev->TxtEx.RegisterKeyNotify = VirtioInputRegisterKeyNotify; + Dev->TxtEx.UnregisterKeyNotify = VirtioInputUnregisterKeyNotify; + InitializeListHead (&Dev->KeyNotifyList); + + // + // Setup the WaitForKey event + // + Status = gBS->CreateEvent ( + EVT_NOTIFY_WAIT, + TPL_NOTIFY, + VirtioInputWaitForKey, + Dev, + &(Dev->Txt.WaitForKey) + ); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // Setup the WaitForKeyEx event + // + Status = gBS->CreateEvent ( + EVT_NOTIFY_WAIT, + TPL_NOTIFY, + VirtioInputWaitForKey, + Dev, + &(Dev->TxtEx.WaitForKeyEx) + ); + if (EFI_ERROR (Status)) { + goto Failed; + } } VirtioInputRingFillRx (Dev, 0); @@ -1128,8 +1183,11 @@ VirtioInputUninit ( ) { gBS->CloseEvent (Dev->PollTimer); - gBS->CloseEvent (Dev->Txt.WaitForKey); - gBS->CloseEvent (Dev->TxtEx.WaitForKeyEx); + + if (Dev->HasKeyboard) { + gBS->CloseEvent (Dev->Txt.WaitForKey); + gBS->CloseEvent (Dev->TxtEx.WaitForKeyEx); + } // // Reset the virtual device -- see virtio-0.9.5, 2.2.2.1 Device Status. When @@ -1275,16 +1333,19 @@ VirtioInputBindingStart ( // interface. // Dev->Signature = VIRTIO_INPUT_SIG; - Status = gBS->InstallMultipleProtocolInterfaces ( - &DeviceHandle, - &gEfiSimpleTextInProtocolGuid, - &Dev->Txt, - &gEfiSimpleTextInputExProtocolGuid, - &Dev->TxtEx, - NULL - ); - if (EFI_ERROR (Status)) { - goto CloseExitBoot; + + if (Dev->HasKeyboard) { + Status = gBS->InstallMultipleProtocolInterfaces ( + &DeviceHandle, + &gEfiSimpleTextInProtocolGuid, + &Dev->Txt, + &gEfiSimpleTextInputExProtocolGuid, + &Dev->TxtEx, + NULL + ); + if (EFI_ERROR (Status)) { + goto CloseExitBoot; + } } return EFI_SUCCESS; @@ -1342,16 +1403,18 @@ VirtioInputBindingStop ( // // Handle Stop() requests for in-use driver instances gracefully. // - Status = gBS->UninstallMultipleProtocolInterfaces ( - DeviceHandle, - &gEfiSimpleTextInProtocolGuid, - &Dev->Txt, - &gEfiSimpleTextInputExProtocolGuid, - &Dev->TxtEx, - NULL - ); - if (EFI_ERROR (Status)) { - return Status; + if (Dev->HasKeyboard) { + Status = gBS->UninstallMultipleProtocolInterfaces ( + DeviceHandle, + &gEfiSimpleTextInProtocolGuid, + &Dev->Txt, + &gEfiSimpleTextInputExProtocolGuid, + &Dev->TxtEx, + NULL + ); + if (EFI_ERROR (Status)) { + return Status; + } } gBS->CloseEvent (Dev->ExitBoot); diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.h b/OvmfPkg/VirtioInputDxe/VirtioInput.h index 9122f3f0bc..ccf9f410b1 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.h +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.h @@ -91,6 +91,8 @@ typedef struct { // List for notifications LIST_ENTRY KeyNotifyList; + BOOLEAN HasKeyboard; + // Last pressed key // typedef struct { // UINT16 ScanCode; From fd63e805088df7655f038a03a28f861379f02376 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Wed, 24 Jun 2026 17:08:09 +0800 Subject: [PATCH 227/406] OvmfPkg/VirtioInputDxe: Split keyboard logic into VirtioKeyboard.c Move all keyboard-specific code including probing, initialization, keycode translation and Simple Text Input (Ex) protocol implementation into new VirtioKeyboard.c. VirtioInput.c retains only the shared virtio transport, the input poll timer and the event dispatcher. This is also the groundwork for the mouse and tablet support added in later commits. No functional change. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioInputDxe/VirtioInput.c | 595 +--------------------- OvmfPkg/VirtioInputDxe/VirtioInput.h | 83 ++-- OvmfPkg/VirtioInputDxe/VirtioInput.inf | 1 + OvmfPkg/VirtioInputDxe/VirtioKeyboard.c | 632 ++++++++++++++++++++++++ 4 files changed, 687 insertions(+), 624 deletions(-) create mode 100644 OvmfPkg/VirtioInputDxe/VirtioKeyboard.c diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.c b/OvmfPkg/VirtioInputDxe/VirtioInput.c index b2f70e77e5..9ca8fc8720 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.c +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.c @@ -351,7 +351,6 @@ VirtioInputRingFillRx ( Dev->VirtIo->SetQueueNotify (Dev->VirtIo, Index); } -STATIC EFI_STATUS VirtioInputConfigQuerySize ( IN VIRTIO_INPUT_DEV *Dev, @@ -376,236 +375,6 @@ VirtioInputConfigQuerySize ( return Status; } -STATIC -BOOLEAN -VirtioInputHasKeyboard ( - IN VIRTIO_INPUT_DEV *Dev - ) -{ - EFI_STATUS Status; - UINT8 Size; - UINT8 Bitmap; - UINTN Index; - - Status = VirtioInputConfigQuerySize (Dev, VirtioInputCfgEvBits, EV_KEY, &Size); - if (EFI_ERROR (Status)) { - return FALSE; - } - - // Keyboard keys are 0 ~ 255, so if any of them is supported, we have a keyboard - Size = MIN (Size, (MAX_KEYBOARD_CODE / 8) + 1); - for (Index = 0; Index < Size; Index++) { - Status = Dev->VirtIo->ReadDevice (Dev->VirtIo, OFFSET_OF_VINPUT (Data) + Index, 1, 1, &Bitmap); - if (EFI_ERROR (Status)) { - return FALSE; - } - - if (Bitmap) { - return TRUE; - } - } - - return FALSE; -} - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_PROTOCOL API -STATIC -EFI_STATUS -EFIAPI -VirtioInputSimpleTextInputReset ( - IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, - IN BOOLEAN ExtendedVerification - ) -{ - VIRTIO_INPUT_DEV *Dev; - EFI_TPL OldTpl; - - Dev = VIRTIO_INPUT_FROM_THIS (This); - - OldTpl = gBS->RaiseTPL (TPL_NOTIFY); - - Dev->KeyReady = FALSE; - Dev->LastKey.ScanCode = SCAN_NULL; - Dev->LastKey.UnicodeChar = CHAR_NULL; - ZeroMem (Dev->KeyActive, sizeof (Dev->KeyActive)); - - gBS->RestoreTPL (OldTpl); - return EFI_SUCCESS; -} - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_PROTOCOL API -STATIC -EFI_STATUS -EFIAPI -VirtioInputSimpleTextInputReadKeyStroke ( - IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, - OUT EFI_INPUT_KEY *Key - ) -{ - VIRTIO_INPUT_DEV *Dev; - EFI_TPL OldTpl; - - if (Key == NULL) { - return EFI_INVALID_PARAMETER; - } - - Dev = VIRTIO_INPUT_FROM_THIS (This); - - OldTpl = gBS->RaiseTPL (TPL_NOTIFY); - if (Dev->KeyReady) { - // Get last key from the buffer - *Key = Dev->LastKey; - - // Mark key as consumed - Dev->KeyReady = FALSE; - - gBS->RestoreTPL (OldTpl); - return EFI_SUCCESS; - } - - gBS->RestoreTPL (OldTpl); - - return EFI_NOT_READY; -} - -// ----------------------------------------------------------------------------- -// Function converting VirtIO key codes to UEFI key codes -STATIC -VOID -EFIAPI -VirtioInputConvertKeyCode ( - IN OUT VIRTIO_INPUT_DEV *Dev, - IN UINT16 Code, - OUT EFI_INPUT_KEY *Key - ) -{ - // Key mapping in between Linux and UEFI - // https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h - // https://dox.ipxe.org/SimpleTextIn_8h_source.html#l00048 - // https://uefi.org/specs/UEFI/2.10/Apx_B_Console.html - - static const UINT16 Map[] = { - [KEY_1] = '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', - [KEY_MINUS] = '-', '=', - [KEY_Q] = 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', - [KEY_LEFTBRACE] = '[', ']', - [KEY_A] = 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', - [KEY_SEMICOLON] = ';', '\'', '`', - [KEY_BACKSLASH] = '\\', - [KEY_Z] = 'z', 'x', 'c', 'v', 'b', 'n', 'm', - [KEY_COMMA] = ',', '.', '/', - [KEY_SPACE] = ' ', - [MAX_KEYBOARD_CODE] = 0x00 - }; - - static const UINT16 MapShift[] = { - [KEY_1] = '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', - [KEY_MINUS] = '_', '+', - [KEY_Q] = 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', - [KEY_LEFTBRACE] = '{', '}', - [KEY_A] = 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', - [KEY_SEMICOLON] = ':', '\"', '~', - [KEY_BACKSLASH] = '|', - [KEY_Z] = 'Z', 'X', 'C', 'V', 'B', 'N', 'M', - [KEY_COMMA] = '<', '>', '?', - [KEY_SPACE] = ' ', - [MAX_KEYBOARD_CODE] = 0x00 - }; - - // Set default readings - Key->ScanCode = SCAN_NULL; - Key->UnicodeChar = CHAR_NULL; - - // Check if key code is not out of the keyboard mapping boundaries - if (Code >= MAX_KEYBOARD_CODE) { - DEBUG ((DEBUG_INFO, "%a: Key code out of range \n", __func__)); - return; - } - - // Handle F1 - F10 keys - if ((Code >= KEY_F1) && (Code <= KEY_F10)) { - Key->ScanCode = SCAN_F1 + (Code - KEY_F1); - return; - } - - switch (Code) { - case KEY_PAGEUP: - Key->ScanCode = SCAN_PAGE_UP; - break; - - case KEY_PAGEDOWN: - Key->ScanCode = SCAN_PAGE_DOWN; - break; - - case KEY_HOME: - Key->ScanCode = SCAN_HOME; - break; - - case KEY_END: - Key->ScanCode = SCAN_END; - break; - - case KEY_DELETE: - Key->ScanCode = SCAN_DELETE; - break; - - case KEY_INSERT: - Key->ScanCode = SCAN_INSERT; - break; - - case KEY_UP: - Key->ScanCode = SCAN_UP; - break; - - case KEY_LEFT: - Key->ScanCode = SCAN_LEFT; - break; - - case KEY_RIGHT: - Key->ScanCode = SCAN_RIGHT; - break; - - case KEY_DOWN: - Key->ScanCode = SCAN_DOWN; - break; - - case KEY_BACKSPACE: - Key->UnicodeChar = CHAR_BACKSPACE; - break; - - case KEY_TAB: - Key->UnicodeChar = CHAR_TAB; - break; - - case KEY_ENTER: - // Key->UnicodeChar = CHAR_LINEFEED; - Key->UnicodeChar = CHAR_CARRIAGE_RETURN; - break; - - case KEY_ESC: - Key->ScanCode = SCAN_ESC; - break; - - default: - if (Dev->KeyActive[KEY_LEFTSHIFT] || Dev->KeyActive[KEY_RIGHTSHIFT]) { - Key->ScanCode = MapShift[Code]; - Key->UnicodeChar = MapShift[Code]; - } else { - Key->ScanCode = Map[Code]; - Key->UnicodeChar = Map[Code]; - } - - if (Dev->KeyActive[KEY_LEFTCTRL] || Dev->KeyActive[KEY_RIGHTCTRL]) { - // Convert Ctrl+[a-z] and Ctrl+[A-Z] into [1-26] ASCII table entries - Key->UnicodeChar &= 0x1F; - } - - break; - } -} - // ----------------------------------------------------------------------------- // Main function processing virtio input events STATIC @@ -633,13 +402,10 @@ VirtioInputGetDeviceData ( continue; } - // Clearing last character is not needed as it will be overwritten anyway - // Dev->LastKey.ScanCode = SCAN_NULL; - // Dev->LastKey.UnicodeChar = CHAR_NULL; + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); CopyMem (&Event, Data, sizeof (Event)); - OldTpl = gBS->RaiseTPL (TPL_NOTIFY); switch (Event.Type) { case EV_SYN: // Sync event received @@ -650,20 +416,7 @@ VirtioInputGetDeviceData ( // DEBUG ((DEBUG_INFO, "%a: ---------------------- \nType: %x Code: %x Value: %x\n", // __func__, Event.Type, Event.Code, Event.Value)); - if (Event.Value == KEY_PRESSED) { - // Key pressed event received - Dev->KeyActive[(UINT8)Event.Code] = TRUE; - - // Evaluate key - VirtioInputConvertKeyCode (Dev, Event.Code, &Dev->LastKey); - - // Flag that printable character is ready to be send - Dev->KeyReady = TRUE; - } else { - // Key released event received - Dev->KeyActive[(UINT8)Event.Code] = FALSE; - } - + VirtioKeyboardHandleEvent (Dev, &Event); break; default: @@ -677,7 +430,6 @@ VirtioInputGetDeviceData ( // ----------------------------------------------------------------------------- // Callback hook for timer interrupt -STATIC VOID EFIAPI VirtioInputTimer ( @@ -690,308 +442,6 @@ VirtioInputTimer ( VirtioInputGetDeviceData (Dev); } -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_PROTOCOL API -STATIC -VOID -EFIAPI -VirtioInputWaitForKey ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - VIRTIO_INPUT_DEV *Dev = (VIRTIO_INPUT_DEV *)Context; - - // - // Stall 1ms to give a chance to let other driver interrupt this routine - // for their timer event. - // e.g. UI setup or Shell, other drivers which are driven by timer event - // will have a bad performance during this period, - // e.g. usb keyboard driver. - // Add a stall period can greatly increate other driver performance during - // the WaitForKey is recursivly invoked. 1ms delay will make little impact - // to the thunk keyboard driver, and user can not feel the delay at all when - // input. - gBS->Stall (1000); - - // Use TimerEvent callback function to check whether there's any key pressed - VirtioInputTimer (NULL, Dev); - - // If there is a new key ready - send signal - if (Dev->KeyReady) { - gBS->SignalEvent (Event); - } -} - -/// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -STATIC -EFI_STATUS -EFIAPI -VirtioInputResetEx ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN BOOLEAN ExtendedVerification - ) -{ - VIRTIO_INPUT_DEV *Dev; - EFI_STATUS Status; - - Dev = VIRTIO_INPUT_EX_FROM_THIS (This); - - // Call the reset function from SIMPLE_TEXT_INPUT protocol - Status = Dev->Txt.Reset ( - &Dev->Txt, - ExtendedVerification - ); - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - - return EFI_SUCCESS; -} - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -STATIC -EFI_STATUS -EFIAPI -VirtioInputReadKeyStrokeEx ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - OUT EFI_KEY_DATA *KeyData - ) -{ - VIRTIO_INPUT_DEV *Dev; - EFI_STATUS Status; - EFI_INPUT_KEY Key; - EFI_KEY_STATE KeyState; - - if (KeyData == NULL) { - return EFI_INVALID_PARAMETER; - } - - Dev = VIRTIO_INPUT_EX_FROM_THIS (This); - - // Get the last pressed key - Status = Dev->Txt.ReadKeyStroke (&Dev->Txt, &Key); - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - - // Add key state informations - KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID; - KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID; - - // Shift key modifier - if (Dev->KeyActive[KEY_LEFTSHIFT]) { - KeyState.KeyShiftState |= EFI_LEFT_SHIFT_PRESSED; - } - - if (Dev->KeyActive[KEY_RIGHTSHIFT]) { - KeyState.KeyShiftState |= EFI_RIGHT_SHIFT_PRESSED; - } - - // Ctrl key modifier - if (Dev->KeyActive[KEY_LEFTCTRL]) { - KeyState.KeyShiftState |= EFI_LEFT_CONTROL_PRESSED; - } - - if (Dev->KeyActive[KEY_RIGHTCTRL]) { - KeyState.KeyShiftState |= EFI_RIGHT_CONTROL_PRESSED; - } - - // ALt key modifier - if (Dev->KeyActive[KEY_LEFTALT]) { - KeyState.KeyShiftState |= EFI_LEFT_ALT_PRESSED; - } - - if (Dev->KeyActive[KEY_RIGHTALT]) { - KeyState.KeyShiftState |= EFI_RIGHT_ALT_PRESSED; - } - - // Return value only when there is no failure - KeyData->Key = Key; - KeyData->KeyState = KeyState; - - return EFI_SUCCESS; -} - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -STATIC -EFI_STATUS -EFIAPI -VirtioInputSetState ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN EFI_KEY_TOGGLE_STATE *KeyToggleState - ) -{ - if (KeyToggleState == NULL) { - return EFI_INVALID_PARAMETER; - } - - return EFI_SUCCESS; -} - -STATIC -BOOLEAN -IsKeyRegistered ( - IN EFI_KEY_DATA *RegisteredData, - IN EFI_KEY_DATA *InputData - ) - -{ - ASSERT (RegisteredData != NULL && InputData != NULL); - - if ((RegisteredData->Key.ScanCode != InputData->Key.ScanCode) || - (RegisteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) - { - return FALSE; - } - - // - // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means - // these state could be ignored. - // - if ((RegisteredData->KeyState.KeyShiftState != 0) && - (RegisteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState)) - { - return FALSE; - } - - if ((RegisteredData->KeyState.KeyToggleState != 0) && - (RegisteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState)) - { - return FALSE; - } - - return TRUE; -} - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -STATIC -EFI_STATUS -EFIAPI -VirtioInputRegisterKeyNotify ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN EFI_KEY_DATA *KeyData, - IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction, - OUT VOID **NotifyHandle - ) -{ - EFI_STATUS Status; - VIRTIO_INPUT_DEV *Dev; - EFI_TPL OldTpl; - LIST_ENTRY *Link; - VIRTIO_INPUT_IN_EX_NOTIFY *NewNotify; - VIRTIO_INPUT_IN_EX_NOTIFY *CurrentNotify; - - if ((KeyData == NULL) || - (NotifyHandle == NULL) || - (KeyNotificationFunction == NULL)) - { - return EFI_INVALID_PARAMETER; - } - - Dev = VIRTIO_INPUT_EX_FROM_THIS (This); - - OldTpl = gBS->RaiseTPL (TPL_NOTIFY); - - // Check if the (KeyData, NotificationFunction) pair is already registered. - for (Link = Dev->KeyNotifyList.ForwardLink; - Link != &Dev->KeyNotifyList; - Link = Link->ForwardLink) - { - CurrentNotify = CR ( - Link, - VIRTIO_INPUT_IN_EX_NOTIFY, - NotifyEntry, - VIRTIO_INPUT_SIG - ); - if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { - if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) { - *NotifyHandle = CurrentNotify; - Status = EFI_SUCCESS; - goto Exit; - } - } - } - - NewNotify = (VIRTIO_INPUT_IN_EX_NOTIFY *)AllocateZeroPool (sizeof (VIRTIO_INPUT_IN_EX_NOTIFY)); - if (NewNotify == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Exit; - } - - NewNotify->Signature = VIRTIO_INPUT_SIG; - NewNotify->KeyNotificationFn = KeyNotificationFunction; - CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA)); - InsertTailList (&Dev->KeyNotifyList, &NewNotify->NotifyEntry); - - *NotifyHandle = NewNotify; - Status = EFI_SUCCESS; - -Exit: - gBS->RestoreTPL (OldTpl); - - return Status; -} - -// ----------------------------------------------------------------------------- -// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API -STATIC -EFI_STATUS -EFIAPI -VirtioInputUnregisterKeyNotify ( - IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN VOID *NotificationHandle - ) -{ - EFI_STATUS Status; - VIRTIO_INPUT_DEV *Dev; - EFI_TPL OldTpl; - LIST_ENTRY *Link; - VIRTIO_INPUT_IN_EX_NOTIFY *CurrentNotify; - - if (NotificationHandle == NULL) { - return EFI_INVALID_PARAMETER; - } - - if (((VIRTIO_INPUT_IN_EX_NOTIFY *)NotificationHandle)->Signature != VIRTIO_INPUT_SIG) { - return EFI_INVALID_PARAMETER; - } - - Dev = VIRTIO_INPUT_EX_FROM_THIS (This); - - OldTpl = gBS->RaiseTPL (TPL_NOTIFY); - - for (Link = Dev->KeyNotifyList.ForwardLink; - Link != &Dev->KeyNotifyList; - Link = Link->ForwardLink) - { - CurrentNotify = CR ( - Link, - VIRTIO_INPUT_IN_EX_NOTIFY, - NotifyEntry, - VIRTIO_INPUT_SIG - ); - if (CurrentNotify == NotificationHandle) { - RemoveEntryList (&CurrentNotify->NotifyEntry); - - Status = EFI_SUCCESS; - goto Exit; - } - } - - // Notification has not been found - Status = EFI_INVALID_PARAMETER; - -Exit: - gBS->RestoreTPL (OldTpl); - - return Status; -} - // ----------------------------------------------------------------------------- // Driver init STATIC @@ -1083,7 +533,7 @@ VirtioInputInit ( // // Check input device capabilities // - Dev->HasKeyboard = VirtioInputHasKeyboard (Dev); + Dev->HasKeyboard = VirtioKeyboardProbe (Dev); if (!Dev->HasKeyboard) { Status = EFI_UNSUPPORTED; goto Failed; @@ -1093,41 +543,7 @@ VirtioInputInit ( // populate the exported interface's attributes // if (Dev->HasKeyboard) { - Dev->Txt.Reset = VirtioInputSimpleTextInputReset; - Dev->Txt.ReadKeyStroke = VirtioInputSimpleTextInputReadKeyStroke; - Dev->Txt.WaitForKey = (EFI_EVENT)VirtioInputWaitForKey; - - Dev->TxtEx.Reset = VirtioInputResetEx; - Dev->TxtEx.ReadKeyStrokeEx = VirtioInputReadKeyStrokeEx; - Dev->TxtEx.SetState = VirtioInputSetState; - Dev->TxtEx.RegisterKeyNotify = VirtioInputRegisterKeyNotify; - Dev->TxtEx.UnregisterKeyNotify = VirtioInputUnregisterKeyNotify; - InitializeListHead (&Dev->KeyNotifyList); - - // - // Setup the WaitForKey event - // - Status = gBS->CreateEvent ( - EVT_NOTIFY_WAIT, - TPL_NOTIFY, - VirtioInputWaitForKey, - Dev, - &(Dev->Txt.WaitForKey) - ); - if (EFI_ERROR (Status)) { - goto Failed; - } - - // - // Setup the WaitForKeyEx event - // - Status = gBS->CreateEvent ( - EVT_NOTIFY_WAIT, - TPL_NOTIFY, - VirtioInputWaitForKey, - Dev, - &(Dev->TxtEx.WaitForKeyEx) - ); + Status = VirtioKeyboardInit (Dev); if (EFI_ERROR (Status)) { goto Failed; } @@ -1185,8 +601,7 @@ VirtioInputUninit ( gBS->CloseEvent (Dev->PollTimer); if (Dev->HasKeyboard) { - gBS->CloseEvent (Dev->Txt.WaitForKey); - gBS->CloseEvent (Dev->TxtEx.WaitForKeyEx); + VirtioKeyboardUninit (Dev); } // diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.h b/OvmfPkg/VirtioInputDxe/VirtioInput.h index ccf9f410b1..fd7362824f 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.h +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.h @@ -55,29 +55,11 @@ typedef struct { // Declaration of data structure representing driver context typedef struct { // Device signature - UINT32 Signature; + UINT32 Signature; // Hook for the function which shall be caled when driver is closed // before system state changes to boot - EFI_EVENT ExitBoot; - - // Hooks for functions required by UEFI keyboard API - // struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL { - // EFI_INPUT_RESET Reset; - // EFI_INPUT_READ_KEY ReadKeyStroke; - // EFI_EVENT WaitForKey; - // }; - EFI_SIMPLE_TEXT_INPUT_PROTOCOL Txt; - - // struct _EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL { - // EFI_INPUT_RESET_EX Reset; - // EFI_INPUT_READ_KEY_EX ReadKeyStrokeEx; - // EFI_EVENT WaitForKeyEx; - // EFI_SET_STATE SetState; - // EFI_REGISTER_KEYSTROKE_NOTIFY RegisterKeyNotify; - // EFI_UNREGISTER_KEYSTROKE_NOTIFY UnregisterKeyNotify; - // } - EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL TxtEx; + EFI_EVENT ExitBoot; // Virtio device hook VIRTIO_DEVICE_PROTOCOL *VirtIo; @@ -88,22 +70,13 @@ typedef struct { // Timer event for checking input from VirtIo EFI_EVENT PollTimer; - // List for notifications - LIST_ENTRY KeyNotifyList; - + // Keyboard implementation BOOLEAN HasKeyboard; - - // Last pressed key - // typedef struct { - // UINT16 ScanCode; - // CHAR16 UnicodeChar; - // } EFI_INPUT_KEY; + EFI_SIMPLE_TEXT_INPUT_PROTOCOL Txt; + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL TxtEx; EFI_INPUT_KEY LastKey; - - // Key modifiers - BOOLEAN KeyActive[MAX_KEYBOARD_CODE]; - - // If key is ready + LIST_ENTRY KeyNotifyList; + BOOLEAN KeyActive[MAX_KEYBOARD_CODE + 1]; // Key modifiers BOOLEAN KeyReady; } VIRTIO_INPUT_DEV; @@ -115,3 +88,45 @@ typedef struct { // Bellow candidates to be included as Linux header #define KEY_PRESSED 1 + +// +// VirtioInput.c +// +EFI_STATUS +VirtioInputConfigQuerySize ( + IN VIRTIO_INPUT_DEV *Dev, + IN VIRTIO_INPUT_CONFIG_SELECT Select, + IN UINT8 Subsel, + OUT UINT8 *Size + ); + +VOID +EFIAPI +VirtioInputTimer ( + IN EFI_EVENT Event, + IN VOID *Context + ); + +// +// VirtioKeyboard.c +// +BOOLEAN +VirtioKeyboardProbe ( + IN VIRTIO_INPUT_DEV *Dev + ); + +VOID +VirtioKeyboardHandleEvent ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN VIRTIO_INPUT_EVENT *Event + ); + +EFI_STATUS +VirtioKeyboardInit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ); + +VOID +VirtioKeyboardUninit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ); diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.inf b/OvmfPkg/VirtioInputDxe/VirtioInput.inf index d5575ac733..4fc2730ac9 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.inf +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.inf @@ -19,6 +19,7 @@ VirtioInput.c VirtioInput.h VirtioKeyCodes.h + VirtioKeyboard.c [Packages] MdePkg/MdePkg.dec diff --git a/OvmfPkg/VirtioInputDxe/VirtioKeyboard.c b/OvmfPkg/VirtioInputDxe/VirtioKeyboard.c new file mode 100644 index 0000000000..0813415902 --- /dev/null +++ b/OvmfPkg/VirtioInputDxe/VirtioKeyboard.c @@ -0,0 +1,632 @@ +/** @file + + EFI_SIMPLE_TEXT_INPUT_PROTOCOL and EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL + implementation for virtio keyboard. + + Copyright (C) 2026, Advanced Micro Devices, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> +#include <Library/VirtioLib.h> + +#include <IndustryStandard/VirtioInput.h> + +#include "VirtioInput.h" +#include "VirtioKeyCodes.h" + +BOOLEAN +VirtioKeyboardProbe ( + IN VIRTIO_INPUT_DEV *Dev + ) +{ + EFI_STATUS Status; + UINT8 Size; + UINT8 Bitmap; + UINTN Index; + + Status = VirtioInputConfigQuerySize (Dev, VirtioInputCfgEvBits, EV_KEY, &Size); + if (EFI_ERROR (Status)) { + return FALSE; + } + + // Keyboard keys are 0 ~ 255, so if any of them is supported, we have a keyboard + Size = MIN (Size, (MAX_KEYBOARD_CODE / 8) + 1); + for (Index = 0; Index < Size; Index++) { + Status = Dev->VirtIo->ReadDevice (Dev->VirtIo, OFFSET_OF_VINPUT (Data) + Index, 1, 1, &Bitmap); + if (EFI_ERROR (Status)) { + return FALSE; + } + + if (Bitmap) { + return TRUE; + } + } + + return FALSE; +} + +// ----------------------------------------------------------------------------- +// Function converting VirtIO key codes to UEFI key codes +STATIC +VOID +VirtioKeyboardConvertKeyCode ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN UINT16 Code, + OUT EFI_INPUT_KEY *Key + ) +{ + // Key mapping in between Linux and UEFI + // https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h + // https://dox.ipxe.org/SimpleTextIn_8h_source.html#l00048 + // https://uefi.org/specs/UEFI/2.10/Apx_B_Console.html + + static const UINT16 Map[] = { + [KEY_1] = '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', + [KEY_MINUS] = '-', '=', + [KEY_Q] = 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', + [KEY_LEFTBRACE] = '[', ']', + [KEY_A] = 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', + [KEY_SEMICOLON] = ';', '\'', '`', + [KEY_BACKSLASH] = '\\', + [KEY_Z] = 'z', 'x', 'c', 'v', 'b', 'n', 'm', + [KEY_COMMA] = ',', '.', '/', + [KEY_SPACE] = ' ', + [MAX_KEYBOARD_CODE] = 0x00 + }; + + static const UINT16 MapShift[] = { + [KEY_1] = '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', + [KEY_MINUS] = '_', '+', + [KEY_Q] = 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', + [KEY_LEFTBRACE] = '{', '}', + [KEY_A] = 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', + [KEY_SEMICOLON] = ':', '\"', '~', + [KEY_BACKSLASH] = '|', + [KEY_Z] = 'Z', 'X', 'C', 'V', 'B', 'N', 'M', + [KEY_COMMA] = '<', '>', '?', + [KEY_SPACE] = ' ', + [MAX_KEYBOARD_CODE] = 0x00 + }; + + // Set default readings + Key->ScanCode = SCAN_NULL; + Key->UnicodeChar = CHAR_NULL; + + // Check if key code is not out of the keyboard mapping boundaries + if (Code >= MAX_KEYBOARD_CODE) { + DEBUG ((DEBUG_INFO, "%a: Key code out of range \n", __func__)); + return; + } + + // Handle F1 - F10 keys + if ((Code >= KEY_F1) && (Code <= KEY_F10)) { + Key->ScanCode = SCAN_F1 + (Code - KEY_F1); + return; + } + + switch (Code) { + case KEY_PAGEUP: + Key->ScanCode = SCAN_PAGE_UP; + break; + + case KEY_PAGEDOWN: + Key->ScanCode = SCAN_PAGE_DOWN; + break; + + case KEY_HOME: + Key->ScanCode = SCAN_HOME; + break; + + case KEY_END: + Key->ScanCode = SCAN_END; + break; + + case KEY_DELETE: + Key->ScanCode = SCAN_DELETE; + break; + + case KEY_INSERT: + Key->ScanCode = SCAN_INSERT; + break; + + case KEY_UP: + Key->ScanCode = SCAN_UP; + break; + + case KEY_LEFT: + Key->ScanCode = SCAN_LEFT; + break; + + case KEY_RIGHT: + Key->ScanCode = SCAN_RIGHT; + break; + + case KEY_DOWN: + Key->ScanCode = SCAN_DOWN; + break; + + case KEY_BACKSPACE: + Key->UnicodeChar = CHAR_BACKSPACE; + break; + + case KEY_TAB: + Key->UnicodeChar = CHAR_TAB; + break; + + case KEY_ENTER: + Key->UnicodeChar = CHAR_CARRIAGE_RETURN; + break; + + case KEY_ESC: + Key->ScanCode = SCAN_ESC; + break; + + default: + if (Dev->KeyActive[KEY_LEFTSHIFT] || Dev->KeyActive[KEY_RIGHTSHIFT]) { + Key->ScanCode = MapShift[Code]; + Key->UnicodeChar = MapShift[Code]; + } else { + Key->ScanCode = Map[Code]; + Key->UnicodeChar = Map[Code]; + } + + if (Dev->KeyActive[KEY_LEFTCTRL] || Dev->KeyActive[KEY_RIGHTCTRL]) { + // Convert Ctrl+[a-z] and Ctrl+[A-Z] into [1-26] ASCII table entries + Key->UnicodeChar &= 0x1F; + } + + break; + } +} + +// ----------------------------------------------------------------------------- +// Function handling VirtIO keyboard events +VOID +VirtioKeyboardHandleEvent ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN VIRTIO_INPUT_EVENT *Event + ) +{ + if (Event->Value == KEY_PRESSED) { + // Key pressed event received + Dev->KeyActive[(UINT8)Event->Code] = TRUE; + + // Evaluate key + VirtioKeyboardConvertKeyCode (Dev, Event->Code, &Dev->LastKey); + + // Flag that printable character is ready to be send + Dev->KeyReady = TRUE; + } else { + // Key released event received + Dev->KeyActive[(UINT8)Event->Code] = FALSE; + } +} + +// ----------------------------------------------------------------------------- +// EFI_SIMPLE_TEXT_INPUT_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioKeyboardReset ( + IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, + IN BOOLEAN ExtendedVerification + ) +{ + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; + + Dev = VIRTIO_INPUT_FROM_THIS (This); + + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + + Dev->KeyReady = FALSE; + Dev->LastKey.ScanCode = SCAN_NULL; + Dev->LastKey.UnicodeChar = CHAR_NULL; + ZeroMem (Dev->KeyActive, sizeof (Dev->KeyActive)); + + gBS->RestoreTPL (OldTpl); + return EFI_SUCCESS; +} + +// ----------------------------------------------------------------------------- +// EFI_SIMPLE_TEXT_INPUT_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioKeyboardReadKeyStroke ( + IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, + OUT EFI_INPUT_KEY *Key + ) +{ + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; + + if (Key == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = VIRTIO_INPUT_FROM_THIS (This); + + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + if (Dev->KeyReady) { + // Get last key from the buffer + *Key = Dev->LastKey; + + // Mark key as consumed + Dev->KeyReady = FALSE; + + gBS->RestoreTPL (OldTpl); + return EFI_SUCCESS; + } + + gBS->RestoreTPL (OldTpl); + + return EFI_NOT_READY; +} + +// ----------------------------------------------------------------------------- +// EFI_SIMPLE_TEXT_INPUT_PROTOCOL API +STATIC +VOID +EFIAPI +VirtioKeyboardWaitForKey ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + VIRTIO_INPUT_DEV *Dev = (VIRTIO_INPUT_DEV *)Context; + + // + // Stall 1ms to give a chance to let other driver interrupt this routine + // for their timer event. + // e.g. UI setup or Shell, other drivers which are driven by timer event + // will have a bad performance during this period, + // e.g. usb keyboard driver. + // Add a stall period can greatly increate other driver performance during + // the WaitForKey is recursivly invoked. 1ms delay will make little impact + // to the thunk keyboard driver, and user can not feel the delay at all when + // input. + gBS->Stall (1000); + + // Use TimerEvent callback function to check whether there's any key pressed + VirtioInputTimer (NULL, Dev); + + // If there is a new key ready - send signal + if (Dev->KeyReady) { + gBS->SignalEvent (Event); + } +} + +/// ----------------------------------------------------------------------------- +// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioKeyboardResetEx ( + IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, + IN BOOLEAN ExtendedVerification + ) +{ + VIRTIO_INPUT_DEV *Dev; + EFI_STATUS Status; + + Dev = VIRTIO_INPUT_EX_FROM_THIS (This); + + // Call the reset function from SIMPLE_TEXT_INPUT protocol + Status = Dev->Txt.Reset ( + &Dev->Txt, + ExtendedVerification + ); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + return EFI_SUCCESS; +} + +// ----------------------------------------------------------------------------- +// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioKeyboardReadKeyStrokeEx ( + IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, + OUT EFI_KEY_DATA *KeyData + ) +{ + VIRTIO_INPUT_DEV *Dev; + EFI_STATUS Status; + EFI_INPUT_KEY Key; + EFI_KEY_STATE KeyState; + + if (KeyData == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = VIRTIO_INPUT_EX_FROM_THIS (This); + + // Get the last pressed key + Status = Dev->Txt.ReadKeyStroke (&Dev->Txt, &Key); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + // Add key state informations + KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID; + KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID; + + // Shift key modifier + if (Dev->KeyActive[KEY_LEFTSHIFT]) { + KeyState.KeyShiftState |= EFI_LEFT_SHIFT_PRESSED; + } + + if (Dev->KeyActive[KEY_RIGHTSHIFT]) { + KeyState.KeyShiftState |= EFI_RIGHT_SHIFT_PRESSED; + } + + // Ctrl key modifier + if (Dev->KeyActive[KEY_LEFTCTRL]) { + KeyState.KeyShiftState |= EFI_LEFT_CONTROL_PRESSED; + } + + if (Dev->KeyActive[KEY_RIGHTCTRL]) { + KeyState.KeyShiftState |= EFI_RIGHT_CONTROL_PRESSED; + } + + // ALt key modifier + if (Dev->KeyActive[KEY_LEFTALT]) { + KeyState.KeyShiftState |= EFI_LEFT_ALT_PRESSED; + } + + if (Dev->KeyActive[KEY_RIGHTALT]) { + KeyState.KeyShiftState |= EFI_RIGHT_ALT_PRESSED; + } + + // Return value only when there is no failure + KeyData->Key = Key; + KeyData->KeyState = KeyState; + + return EFI_SUCCESS; +} + +// ----------------------------------------------------------------------------- +// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioKeyboardSetStateEx ( + IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, + IN EFI_KEY_TOGGLE_STATE *KeyToggleState + ) +{ + if (KeyToggleState == NULL) { + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +STATIC +BOOLEAN +IsKeyRegistered ( + IN EFI_KEY_DATA *RegisteredData, + IN EFI_KEY_DATA *InputData + ) + +{ + ASSERT (RegisteredData != NULL && InputData != NULL); + + if ((RegisteredData->Key.ScanCode != InputData->Key.ScanCode) || + (RegisteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) + { + return FALSE; + } + + // + // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means + // these state could be ignored. + // + if ((RegisteredData->KeyState.KeyShiftState != 0) && + (RegisteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState)) + { + return FALSE; + } + + if ((RegisteredData->KeyState.KeyToggleState != 0) && + (RegisteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState)) + { + return FALSE; + } + + return TRUE; +} + +// ----------------------------------------------------------------------------- +// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioKeyboardRegisterKeyNotifyEx ( + IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, + IN EFI_KEY_DATA *KeyData, + IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction, + OUT VOID **NotifyHandle + ) +{ + EFI_STATUS Status; + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; + LIST_ENTRY *Link; + VIRTIO_INPUT_IN_EX_NOTIFY *NewNotify; + VIRTIO_INPUT_IN_EX_NOTIFY *CurrentNotify; + + if ((KeyData == NULL) || + (NotifyHandle == NULL) || + (KeyNotificationFunction == NULL)) + { + return EFI_INVALID_PARAMETER; + } + + Dev = VIRTIO_INPUT_EX_FROM_THIS (This); + + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + + // Check if the (KeyData, NotificationFunction) pair is already registered. + for (Link = Dev->KeyNotifyList.ForwardLink; + Link != &Dev->KeyNotifyList; + Link = Link->ForwardLink) + { + CurrentNotify = CR ( + Link, + VIRTIO_INPUT_IN_EX_NOTIFY, + NotifyEntry, + VIRTIO_INPUT_SIG + ); + if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { + if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) { + *NotifyHandle = CurrentNotify; + Status = EFI_SUCCESS; + goto Exit; + } + } + } + + NewNotify = (VIRTIO_INPUT_IN_EX_NOTIFY *)AllocateZeroPool (sizeof (VIRTIO_INPUT_IN_EX_NOTIFY)); + if (NewNotify == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + + NewNotify->Signature = VIRTIO_INPUT_SIG; + NewNotify->KeyNotificationFn = KeyNotificationFunction; + CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA)); + InsertTailList (&Dev->KeyNotifyList, &NewNotify->NotifyEntry); + + *NotifyHandle = NewNotify; + Status = EFI_SUCCESS; + +Exit: + gBS->RestoreTPL (OldTpl); + + return Status; +} + +// ----------------------------------------------------------------------------- +// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioKeyboardUnregisterKeyNotifyEx ( + IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, + IN VOID *NotificationHandle + ) +{ + EFI_STATUS Status; + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; + LIST_ENTRY *Link; + VIRTIO_INPUT_IN_EX_NOTIFY *CurrentNotify; + + if (NotificationHandle == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (((VIRTIO_INPUT_IN_EX_NOTIFY *)NotificationHandle)->Signature != VIRTIO_INPUT_SIG) { + return EFI_INVALID_PARAMETER; + } + + Dev = VIRTIO_INPUT_EX_FROM_THIS (This); + + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + + for (Link = Dev->KeyNotifyList.ForwardLink; + Link != &Dev->KeyNotifyList; + Link = Link->ForwardLink) + { + CurrentNotify = CR ( + Link, + VIRTIO_INPUT_IN_EX_NOTIFY, + NotifyEntry, + VIRTIO_INPUT_SIG + ); + if (CurrentNotify == NotificationHandle) { + RemoveEntryList (&CurrentNotify->NotifyEntry); + + Status = EFI_SUCCESS; + goto Exit; + } + } + + // Notification has not been found + Status = EFI_INVALID_PARAMETER; + +Exit: + gBS->RestoreTPL (OldTpl); + + return Status; +} + +EFI_STATUS +VirtioKeyboardInit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ) +{ + EFI_STATUS Status; + + InitializeListHead (&Dev->KeyNotifyList); + + Dev->Txt.Reset = VirtioKeyboardReset; + Dev->Txt.ReadKeyStroke = VirtioKeyboardReadKeyStroke; + + Dev->TxtEx.Reset = VirtioKeyboardResetEx; + Dev->TxtEx.ReadKeyStrokeEx = VirtioKeyboardReadKeyStrokeEx; + Dev->TxtEx.SetState = VirtioKeyboardSetStateEx; + Dev->TxtEx.RegisterKeyNotify = VirtioKeyboardRegisterKeyNotifyEx; + Dev->TxtEx.UnregisterKeyNotify = VirtioKeyboardUnregisterKeyNotifyEx; + + // + // Setup the WaitForKey event + // + Status = gBS->CreateEvent ( + EVT_NOTIFY_WAIT, + TPL_NOTIFY, + VirtioKeyboardWaitForKey, + Dev, + &(Dev->Txt.WaitForKey) + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Setup the WaitForKeyEx event + // + Status = gBS->CreateEvent ( + EVT_NOTIFY_WAIT, + TPL_NOTIFY, + VirtioKeyboardWaitForKey, + Dev, + &(Dev->TxtEx.WaitForKeyEx) + ); + if (EFI_ERROR (Status)) { + return Status; + } + + return EFI_SUCCESS; +} + +VOID +VirtioKeyboardUninit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ) +{ + gBS->CloseEvent (Dev->Txt.WaitForKey); + gBS->CloseEvent (Dev->TxtEx.WaitForKeyEx); +} From efdbf3c355c9e329bf57fec75744b68f12c1ee81 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Thu, 25 Jun 2026 16:16:39 +0800 Subject: [PATCH 228/406] OvmfPkg/VirtioInputDxe: Add virtio mouse support Virtio mouse devices report relative movements (EV_REL) and button inputs. Add VirtioMouse.c implementing mouse capability probing, EFI_SIMPLE_POINTER_PROTOCOL implementation and event handler that converts VIRTIO_INPUT_EVENT into EFI_SIMPLE_POINTER_STATE. The shared event dispatcher in VirtioInput.c now routes EV_REL events and EV_KEY codes above MAX_KEYBOARD_CODE to the mouse handler, while keycodes in [0, MAX_KEYBOARD_CODE] still go to the keyboard. A device is now accepted when it provides a keyboard or a mouse, and the EFI_SIMPLE_POINTER_PROTOCOL is installed on mouse-capable devices. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioInputDxe/VirtioInput.c | 89 +++++++++- OvmfPkg/VirtioInputDxe/VirtioInput.h | 41 ++++- OvmfPkg/VirtioInputDxe/VirtioInput.inf | 2 + OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h | 14 ++ OvmfPkg/VirtioInputDxe/VirtioMouse.c | 223 ++++++++++++++++++++++++ 5 files changed, 361 insertions(+), 8 deletions(-) create mode 100644 OvmfPkg/VirtioInputDxe/VirtioMouse.c diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.c b/OvmfPkg/VirtioInputDxe/VirtioInput.c index 9ca8fc8720..dfa8e78091 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.c +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.c @@ -415,8 +415,22 @@ VirtioInputGetDeviceData ( // Key press event received // DEBUG ((DEBUG_INFO, "%a: ---------------------- \nType: %x Code: %x Value: %x\n", // __func__, Event.Type, Event.Code, Event.Value)); + if (IS_BUTTON_CODE (Event.Code)) { + if (Dev->HasMouse) { + VirtioMouseHandleEvent (Dev, &Event); + } + } else if (Dev->HasKeyboard) { + VirtioKeyboardHandleEvent (Dev, &Event); + } + + break; + + case EV_REL: + // Relative pointer movement received + if (Dev->HasMouse) { + VirtioMouseHandleEvent (Dev, &Event); + } - VirtioKeyboardHandleEvent (Dev, &Event); break; default: @@ -534,7 +548,8 @@ VirtioInputInit ( // Check input device capabilities // Dev->HasKeyboard = VirtioKeyboardProbe (Dev); - if (!Dev->HasKeyboard) { + Dev->HasMouse = VirtioMouseProbe (Dev); + if (!Dev->HasKeyboard && !Dev->HasMouse) { Status = EFI_UNSUPPORTED; goto Failed; } @@ -549,6 +564,13 @@ VirtioInputInit ( } } + if (Dev->HasMouse) { + Status = VirtioMouseInit (Dev); + if (EFI_ERROR (Status)) { + goto Failed; + } + } + VirtioInputRingFillRx (Dev, 0); // @@ -604,6 +626,10 @@ VirtioInputUninit ( VirtioKeyboardUninit (Dev); } + if (Dev->HasMouse) { + VirtioMouseUninit (Dev); + } + // // Reset the virtual device -- see virtio-0.9.5, 2.2.2.1 Device Status. When // VIRTIO_CFG_WRITE() returns, the host will have learned to stay away from @@ -763,8 +789,32 @@ VirtioInputBindingStart ( } } + if (Dev->HasMouse) { + Status = gBS->InstallMultipleProtocolInterfaces ( + &DeviceHandle, + &gEfiSimplePointerProtocolGuid, + &Dev->SimplePointer, + NULL + ); + if (EFI_ERROR (Status)) { + goto UninstallKeyboard; + } + } + return EFI_SUCCESS; +UninstallKeyboard: + if (Dev->HasKeyboard) { + gBS->UninstallMultipleProtocolInterfaces ( + DeviceHandle, + &gEfiSimpleTextInProtocolGuid, + &Dev->Txt, + &gEfiSimpleTextInputExProtocolGuid, + &Dev->TxtEx, + NULL + ); + } + CloseExitBoot: gBS->CloseEvent (Dev->ExitBoot); @@ -799,21 +849,34 @@ VirtioInputBindingStop ( { EFI_STATUS Status; EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Txt; + EFI_SIMPLE_POINTER_PROTOCOL *Pointer; VIRTIO_INPUT_DEV *Dev; Status = gBS->OpenProtocol ( DeviceHandle, // candidate device - &gEfiSimpleTextInProtocolGuid, // retrieve the RNG iface + &gEfiSimpleTextInProtocolGuid, // retrieve the keyboard iface (VOID **)&Txt, // target pointer This->DriverBindingHandle, // requestor driver ident. DeviceHandle, // lookup req. for dev. EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no new ref. ); - if (EFI_ERROR (Status)) { - return Status; - } + if (!EFI_ERROR (Status)) { + Dev = VIRTIO_INPUT_FROM_THIS (Txt); + } else { + Status = gBS->OpenProtocol ( + DeviceHandle, + &gEfiSimplePointerProtocolGuid, + (VOID **)&Pointer, + This->DriverBindingHandle, + DeviceHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return Status; + } - Dev = VIRTIO_INPUT_FROM_THIS (Txt); + Dev = VIRTIO_INPUT_FROM_POINTER_THIS (Pointer); + } // // Handle Stop() requests for in-use driver instances gracefully. @@ -832,6 +895,18 @@ VirtioInputBindingStop ( } } + if (Dev->HasMouse) { + Status = gBS->UninstallMultipleProtocolInterfaces ( + DeviceHandle, + &gEfiSimplePointerProtocolGuid, + &Dev->SimplePointer, + NULL + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + gBS->CloseEvent (Dev->ExitBoot); VirtioInputUninit (Dev); diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.h b/OvmfPkg/VirtioInputDxe/VirtioInput.h index fd7362824f..98d20dad93 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.h +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.h @@ -12,11 +12,14 @@ #include <Protocol/ComponentName.h> #include <Protocol/DriverBinding.h> +#include <Protocol/SimplePointer.h> #include <Protocol/SimpleTextIn.h> #include <Protocol/SimpleTextInEx.h> #include <IndustryStandard/Virtio.h> +#include "VirtioKeyCodes.h" + #define VIRTIO_INPUT_SIG SIGNATURE_32 ('V', 'I', 'N', 'P') #define MAX_RINGS 2 @@ -26,7 +29,10 @@ #define PROBE_TIME_MS 50 // Max range of recognized keyboard codes -#define MAX_KEYBOARD_CODE 255 +#define MAX_KEYBOARD_CODE (BTN_MISC - 1) + +// Key code 0x100 ~ 0x15f range is for all kinds of button events. +#define IS_BUTTON_CODE(Code) (((Code) >= BTN_MISC) && ((Code) < KEY_OK)) typedef struct { UINTN Signature; @@ -78,6 +84,13 @@ typedef struct { LIST_ENTRY KeyNotifyList; BOOLEAN KeyActive[MAX_KEYBOARD_CODE + 1]; // Key modifiers BOOLEAN KeyReady; + + // Mouse implementation + BOOLEAN HasMouse; + EFI_SIMPLE_POINTER_PROTOCOL SimplePointer; + EFI_SIMPLE_POINTER_MODE PointerMode; + EFI_SIMPLE_POINTER_STATE PointerState; + BOOLEAN PointerReady; } VIRTIO_INPUT_DEV; // Helper functions to extract VIRTIO_INPUT_DEV structure pointers @@ -85,6 +98,8 @@ typedef struct { CR (KbrPointer, VIRTIO_INPUT_DEV, Txt, VIRTIO_INPUT_SIG) #define VIRTIO_INPUT_EX_FROM_THIS(KbrPointer) \ CR (KbrPointer, VIRTIO_INPUT_DEV, TxtEx, VIRTIO_INPUT_SIG) +#define VIRTIO_INPUT_FROM_POINTER_THIS(a) \ + CR (a, VIRTIO_INPUT_DEV, SimplePointer, VIRTIO_INPUT_SIG) // Bellow candidates to be included as Linux header #define KEY_PRESSED 1 @@ -130,3 +145,27 @@ VOID VirtioKeyboardUninit ( IN OUT VIRTIO_INPUT_DEV *Dev ); + +// +// VirtioMouse.c +// +BOOLEAN +VirtioMouseProbe ( + IN VIRTIO_INPUT_DEV *Dev + ); + +VOID +VirtioMouseHandleEvent ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN VIRTIO_INPUT_EVENT *Event + ); + +EFI_STATUS +VirtioMouseInit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ); + +VOID +VirtioMouseUninit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ); diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.inf b/OvmfPkg/VirtioInputDxe/VirtioInput.inf index 4fc2730ac9..0c680b01fa 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.inf +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.inf @@ -20,6 +20,7 @@ VirtioInput.h VirtioKeyCodes.h VirtioKeyboard.c + VirtioMouse.c [Packages] MdePkg/MdePkg.dec @@ -40,3 +41,4 @@ gEfiSimpleTextInProtocolGuid gEfiSimpleTextInputExProtocolGuid gVirtioDeviceProtocolGuid + gEfiSimplePointerProtocolGuid diff --git a/OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h b/OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h index 70d8c454ac..0cb9f49f3d 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h +++ b/OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h @@ -18,6 +18,7 @@ */ #define EV_SYN 0x00 #define EV_KEY 0x01 +#define EV_REL 0x02 /* * Keys and buttons @@ -289,3 +290,16 @@ #define KEY_MICMUTE 248 /* Mute / unmute the microphone */ /* Code 255 is reserved for special needs of AT keyboard driver */ + +#define BTN_MISC 0x100 + +#define BTN_LEFT 0x110 +#define BTN_RIGHT 0x111 + +#define KEY_OK 0x160 + +/* + * Relative axes + */ +#define REL_X 0x00 +#define REL_Y 0x01 diff --git a/OvmfPkg/VirtioInputDxe/VirtioMouse.c b/OvmfPkg/VirtioInputDxe/VirtioMouse.c new file mode 100644 index 0000000000..fcfcee6b9f --- /dev/null +++ b/OvmfPkg/VirtioInputDxe/VirtioMouse.c @@ -0,0 +1,223 @@ +/** @file + + EFI_SIMPLE_POINTER_PROTOCOL implementation for virtio mouse. + + Copyright (C) 2026, Advanced Micro Devices, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/VirtioLib.h> + +#include <IndustryStandard/VirtioInput.h> + +#include "VirtioInput.h" +#include "VirtioKeyCodes.h" + +BOOLEAN +VirtioMouseProbe ( + IN VIRTIO_INPUT_DEV *Dev + ) +{ + EFI_STATUS Status; + UINT8 Size; + UINT8 Bitmap; + + // Check if REL_X and REL_Y are set in the EV_REL bitmap + Status = VirtioInputConfigQuerySize (Dev, VirtioInputCfgEvBits, EV_REL, &Size); + if (EFI_ERROR (Status) || (Size == 0)) { + return FALSE; + } + + Status = Dev->VirtIo->ReadDevice (Dev->VirtIo, OFFSET_OF_VINPUT (Data), 1, 1, &Bitmap); + if (EFI_ERROR (Status)) { + return FALSE; + } + + return (Bitmap & (1 << REL_X)) && (Bitmap & (1 << REL_Y)); +} + +// ----------------------------------------------------------------------------- +// Function handling VirtIO mouse events +VOID +VirtioMouseHandleEvent ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN VIRTIO_INPUT_EVENT *Event + ) +{ + switch (Event->Type) { + case EV_KEY: + switch (Event->Code) { + case BTN_LEFT: + Dev->PointerState.LeftButton = (BOOLEAN)(Event->Value == KEY_PRESSED); + break; + + case BTN_RIGHT: + Dev->PointerState.RightButton = (BOOLEAN)(Event->Value == KEY_PRESSED); + break; + + default: + break; + } + + Dev->PointerReady = TRUE; + break; + + case EV_REL: + switch (Event->Code) { + case REL_X: + Dev->PointerState.RelativeMovementX += (INT32)Event->Value; + break; + + case REL_Y: + Dev->PointerState.RelativeMovementY += (INT32)Event->Value; + break; + + default: + break; + } + + Dev->PointerReady = TRUE; + break; + + default: + break; + } +} + +// ----------------------------------------------------------------------------- +// EFI_SIMPLE_POINTER_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioMouseReset ( + IN EFI_SIMPLE_POINTER_PROTOCOL *This, + IN BOOLEAN ExtendedVerification + ) +{ + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; + + Dev = VIRTIO_INPUT_FROM_POINTER_THIS (This); + + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + ZeroMem (&Dev->PointerState, sizeof (Dev->PointerState)); + Dev->PointerReady = FALSE; + gBS->RestoreTPL (OldTpl); + + return EFI_SUCCESS; +} + +// ----------------------------------------------------------------------------- +// EFI_SIMPLE_POINTER_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioMouseGetState ( + IN EFI_SIMPLE_POINTER_PROTOCOL *This, + OUT EFI_SIMPLE_POINTER_STATE *State + ) +{ + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; + + if (State == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = VIRTIO_INPUT_FROM_POINTER_THIS (This); + + if (!Dev->PointerReady) { + return EFI_NOT_READY; + } + + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + + CopyMem (State, &Dev->PointerState, sizeof (*State)); + + // + // Clear mouse state + // + Dev->PointerState.RelativeMovementX = 0; + Dev->PointerState.RelativeMovementY = 0; + Dev->PointerReady = FALSE; + + gBS->RestoreTPL (OldTpl); + + return EFI_SUCCESS; +} + +// ----------------------------------------------------------------------------- +// EFI_SIMPLE_POINTER_PROTOCOL WaitForInput event handler +STATIC +VOID +EFIAPI +VirtioMouseWaitForPointer ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + VIRTIO_INPUT_DEV *Dev = Context; + + // + // Stall 1ms to give other timer-driven drivers a chance to run while this + // routine is recursively invoked from WaitForEvent (). + // + gBS->Stall (1000); + + // Drain pending events from the device. + VirtioInputTimer (NULL, Dev); + + // If there is new pointer activity - send signal + if (Dev->PointerReady) { + gBS->SignalEvent (Event); + } +} + +EFI_STATUS +VirtioMouseInit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ) +{ + EFI_STATUS Status; + + Dev->SimplePointer.Reset = VirtioMouseReset; + Dev->SimplePointer.GetState = VirtioMouseGetState; + Dev->SimplePointer.Mode = &Dev->PointerMode; + + Dev->PointerMode.ResolutionX = 8; + Dev->PointerMode.ResolutionY = 8; + Dev->PointerMode.LeftButton = TRUE; + Dev->PointerMode.RightButton = TRUE; + + ZeroMem (&Dev->PointerState, sizeof (Dev->PointerState)); + Dev->PointerReady = FALSE; + + // + // Setup the WaitForInput event + // + Status = gBS->CreateEvent ( + EVT_NOTIFY_WAIT, + TPL_NOTIFY, + VirtioMouseWaitForPointer, + Dev, + &Dev->SimplePointer.WaitForInput + ); + if (EFI_ERROR (Status)) { + return Status; + } + + return EFI_SUCCESS; +} + +VOID +VirtioMouseUninit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ) +{ + gBS->CloseEvent (Dev->SimplePointer.WaitForInput); +} From 9e3e68218cf60b3689a6481f27e6511ff06aaf6f Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao <Zhao.Jiaqing@amd.com> Date: Thu, 25 Jun 2026 17:02:31 +0800 Subject: [PATCH 229/406] OvmfPkg/VirtioInputDxe: Add virtio tablet support Virtio tablet devices report absolute coordinates (EV_ABS) and button inputs. Add VirtioTablet.c implementing tablet capability probing, EFI_ABSOLUTE_POINTER_PROTOCOL implementation and event handler that converts VIRTIO_INPUT_EVENT into EFI_ABSOLUTE_POINTER_STATE. The axis ranges advertised by EFI_ABSOLUTE_POINTER_MODE are read from the device's abs_info for ABS_X and ABS_Y. The shared event dispatcher in VirtioInput.c now routes EV_ABS events and EV_KEY codes above MAX_KEYBOARD_CODE to the tablet handler. Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com> --- OvmfPkg/VirtioInputDxe/VirtioInput.c | 81 ++++++- OvmfPkg/VirtioInputDxe/VirtioInput.h | 34 +++ OvmfPkg/VirtioInputDxe/VirtioInput.inf | 2 + OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h | 8 + OvmfPkg/VirtioInputDxe/VirtioTablet.c | 293 ++++++++++++++++++++++++ 5 files changed, 413 insertions(+), 5 deletions(-) create mode 100644 OvmfPkg/VirtioInputDxe/VirtioTablet.c diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.c b/OvmfPkg/VirtioInputDxe/VirtioInput.c index dfa8e78091..1283a7f411 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.c +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.c @@ -419,6 +419,10 @@ VirtioInputGetDeviceData ( if (Dev->HasMouse) { VirtioMouseHandleEvent (Dev, &Event); } + + if (Dev->HasTablet) { + VirtioTabletHandleEvent (Dev, &Event); + } } else if (Dev->HasKeyboard) { VirtioKeyboardHandleEvent (Dev, &Event); } @@ -433,6 +437,14 @@ VirtioInputGetDeviceData ( break; + case EV_ABS: + // Absolute pointer movement received + if (Dev->HasTablet) { + VirtioTabletHandleEvent (Dev, &Event); + } + + break; + default: DEBUG ((DEBUG_INFO, "%a: Unhandled VirtIo event\n", __func__)); break; @@ -549,7 +561,8 @@ VirtioInputInit ( // Dev->HasKeyboard = VirtioKeyboardProbe (Dev); Dev->HasMouse = VirtioMouseProbe (Dev); - if (!Dev->HasKeyboard && !Dev->HasMouse) { + Dev->HasTablet = VirtioTabletProbe (Dev); + if (!Dev->HasKeyboard && !Dev->HasMouse && !Dev->HasTablet) { Status = EFI_UNSUPPORTED; goto Failed; } @@ -571,6 +584,13 @@ VirtioInputInit ( } } + if (Dev->HasTablet) { + Status = VirtioTabletInit (Dev); + if (EFI_ERROR (Status)) { + goto Failed; + } + } + VirtioInputRingFillRx (Dev, 0); // @@ -630,6 +650,10 @@ VirtioInputUninit ( VirtioMouseUninit (Dev); } + if (Dev->HasTablet) { + VirtioTabletUninit (Dev); + } + // // Reset the virtual device -- see virtio-0.9.5, 2.2.2.1 Device Status. When // VIRTIO_CFG_WRITE() returns, the host will have learned to stay away from @@ -801,8 +825,30 @@ VirtioInputBindingStart ( } } + if (Dev->HasTablet) { + Status = gBS->InstallMultipleProtocolInterfaces ( + &DeviceHandle, + &gEfiAbsolutePointerProtocolGuid, + &Dev->AbsolutePointer, + NULL + ); + if (EFI_ERROR (Status)) { + goto UninstallMouse; + } + } + return EFI_SUCCESS; +UninstallMouse: + if (Dev->HasMouse) { + gBS->UninstallMultipleProtocolInterfaces ( + DeviceHandle, + &gEfiSimplePointerProtocolGuid, + &Dev->SimplePointer, + NULL + ); + } + UninstallKeyboard: if (Dev->HasKeyboard) { gBS->UninstallMultipleProtocolInterfaces ( @@ -850,6 +896,7 @@ VirtioInputBindingStop ( EFI_STATUS Status; EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Txt; EFI_SIMPLE_POINTER_PROTOCOL *Pointer; + EFI_ABSOLUTE_POINTER_PROTOCOL *AbsPointer; VIRTIO_INPUT_DEV *Dev; Status = gBS->OpenProtocol ( @@ -871,11 +918,23 @@ VirtioInputBindingStop ( DeviceHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); - if (EFI_ERROR (Status)) { - return Status; - } + if (!EFI_ERROR (Status)) { + Dev = VIRTIO_INPUT_FROM_POINTER_THIS (Pointer); + } else { + Status = gBS->OpenProtocol ( + DeviceHandle, + &gEfiAbsolutePointerProtocolGuid, + (VOID **)&AbsPointer, + This->DriverBindingHandle, + DeviceHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return Status; + } - Dev = VIRTIO_INPUT_FROM_POINTER_THIS (Pointer); + Dev = VIRTIO_INPUT_FROM_ABS_POINTER_THIS (AbsPointer); + } } // @@ -907,6 +966,18 @@ VirtioInputBindingStop ( } } + if (Dev->HasTablet) { + Status = gBS->UninstallMultipleProtocolInterfaces ( + DeviceHandle, + &gEfiAbsolutePointerProtocolGuid, + &Dev->AbsolutePointer, + NULL + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + gBS->CloseEvent (Dev->ExitBoot); VirtioInputUninit (Dev); diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.h b/OvmfPkg/VirtioInputDxe/VirtioInput.h index 98d20dad93..1b00cb3655 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.h +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.h @@ -10,6 +10,7 @@ #pragma once +#include <Protocol/AbsolutePointer.h> #include <Protocol/ComponentName.h> #include <Protocol/DriverBinding.h> #include <Protocol/SimplePointer.h> @@ -91,6 +92,13 @@ typedef struct { EFI_SIMPLE_POINTER_MODE PointerMode; EFI_SIMPLE_POINTER_STATE PointerState; BOOLEAN PointerReady; + + // Tablet implementation + BOOLEAN HasTablet; + EFI_ABSOLUTE_POINTER_PROTOCOL AbsolutePointer; + EFI_ABSOLUTE_POINTER_MODE AbsPointerMode; + EFI_ABSOLUTE_POINTER_STATE AbsPointerState; + BOOLEAN AbsPointerReady; } VIRTIO_INPUT_DEV; // Helper functions to extract VIRTIO_INPUT_DEV structure pointers @@ -100,6 +108,8 @@ typedef struct { CR (KbrPointer, VIRTIO_INPUT_DEV, TxtEx, VIRTIO_INPUT_SIG) #define VIRTIO_INPUT_FROM_POINTER_THIS(a) \ CR (a, VIRTIO_INPUT_DEV, SimplePointer, VIRTIO_INPUT_SIG) +#define VIRTIO_INPUT_FROM_ABS_POINTER_THIS(a) \ + CR (a, VIRTIO_INPUT_DEV, AbsolutePointer, VIRTIO_INPUT_SIG) // Bellow candidates to be included as Linux header #define KEY_PRESSED 1 @@ -169,3 +179,27 @@ VOID VirtioMouseUninit ( IN OUT VIRTIO_INPUT_DEV *Dev ); + +// +// VirtioTablet.c +// +BOOLEAN +VirtioTabletProbe ( + IN VIRTIO_INPUT_DEV *Dev + ); + +VOID +VirtioTabletHandleEvent ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN VIRTIO_INPUT_EVENT *Event + ); + +EFI_STATUS +VirtioTabletInit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ); + +VOID +VirtioTabletUninit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ); diff --git a/OvmfPkg/VirtioInputDxe/VirtioInput.inf b/OvmfPkg/VirtioInputDxe/VirtioInput.inf index 0c680b01fa..4a20f606fc 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioInput.inf +++ b/OvmfPkg/VirtioInputDxe/VirtioInput.inf @@ -21,6 +21,7 @@ VirtioKeyCodes.h VirtioKeyboard.c VirtioMouse.c + VirtioTablet.c [Packages] MdePkg/MdePkg.dec @@ -42,3 +43,4 @@ gEfiSimpleTextInputExProtocolGuid gVirtioDeviceProtocolGuid gEfiSimplePointerProtocolGuid + gEfiAbsolutePointerProtocolGuid diff --git a/OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h b/OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h index 0cb9f49f3d..82f0db9b96 100644 --- a/OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h +++ b/OvmfPkg/VirtioInputDxe/VirtioKeyCodes.h @@ -19,6 +19,7 @@ #define EV_SYN 0x00 #define EV_KEY 0x01 #define EV_REL 0x02 +#define EV_ABS 0x03 /* * Keys and buttons @@ -295,6 +296,7 @@ #define BTN_LEFT 0x110 #define BTN_RIGHT 0x111 +#define BTN_TOUCH 0x14a #define KEY_OK 0x160 @@ -303,3 +305,9 @@ */ #define REL_X 0x00 #define REL_Y 0x01 + +/* + * Absolute axes + */ +#define ABS_X 0x00 +#define ABS_Y 0x01 diff --git a/OvmfPkg/VirtioInputDxe/VirtioTablet.c b/OvmfPkg/VirtioInputDxe/VirtioTablet.c new file mode 100644 index 0000000000..71b7a13a17 --- /dev/null +++ b/OvmfPkg/VirtioInputDxe/VirtioTablet.c @@ -0,0 +1,293 @@ +/** @file + + EFI_ABSOLUTE_POINTER_PROTOCOL implementation for virtio tablet. + + Copyright (C) 2026, Advanced Micro Devices, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/VirtioLib.h> + +#include <IndustryStandard/VirtioInput.h> + +#include "VirtioInput.h" +#include "VirtioKeyCodes.h" + +BOOLEAN +VirtioTabletProbe ( + IN VIRTIO_INPUT_DEV *Dev + ) +{ + EFI_STATUS Status; + UINT8 Size; + UINT8 Bitmap; + + // A tablet (absolute pointer) reports ABS_X and ABS_Y in the EV_ABS bitmap + Status = VirtioInputConfigQuerySize (Dev, VirtioInputCfgEvBits, EV_ABS, &Size); + if (EFI_ERROR (Status) || (Size == 0)) { + return FALSE; + } + + Status = Dev->VirtIo->ReadDevice (Dev->VirtIo, OFFSET_OF_VINPUT (Data), 1, 1, &Bitmap); + if (EFI_ERROR (Status)) { + return FALSE; + } + + return (Bitmap & (1 << ABS_X)) && (Bitmap & (1 << ABS_Y)); +} + +// ----------------------------------------------------------------------------- +// Function handling VirtIO tablet events +VOID +VirtioTabletHandleEvent ( + IN OUT VIRTIO_INPUT_DEV *Dev, + IN VIRTIO_INPUT_EVENT *Event + ) +{ + switch (Event->Type) { + case EV_KEY: + switch (Event->Code) { + case BTN_TOUCH: + case BTN_LEFT: + if (Event->Value == KEY_PRESSED) { + Dev->AbsPointerState.ActiveButtons |= (UINT32)EFI_ABSP_TouchActive; + } else { + Dev->AbsPointerState.ActiveButtons &= ~(UINT32)EFI_ABSP_TouchActive; + } + + break; + + case BTN_RIGHT: + if (Event->Value == KEY_PRESSED) { + Dev->AbsPointerState.ActiveButtons |= (UINT32)EFI_ABS_AltActive; + } else { + Dev->AbsPointerState.ActiveButtons &= ~(UINT32)EFI_ABS_AltActive; + } + + break; + + default: + break; + } + + Dev->AbsPointerReady = TRUE; + break; + + case EV_ABS: + switch (Event->Code) { + case ABS_X: + Dev->AbsPointerState.CurrentX = Event->Value; + break; + + case ABS_Y: + Dev->AbsPointerState.CurrentY = Event->Value; + break; + + default: + break; + } + + Dev->AbsPointerReady = TRUE; + break; + + default: + break; + } +} + +// ----------------------------------------------------------------------------- +// EFI_ABSOLUTE_POINTER_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioTabletReset ( + IN EFI_ABSOLUTE_POINTER_PROTOCOL *This, + IN BOOLEAN ExtendedVerification + ) +{ + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; + + Dev = VIRTIO_INPUT_FROM_ABS_POINTER_THIS (This); + + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + ZeroMem (&Dev->AbsPointerState, sizeof (Dev->AbsPointerState)); + Dev->AbsPointerReady = FALSE; + gBS->RestoreTPL (OldTpl); + + return EFI_SUCCESS; +} + +// ----------------------------------------------------------------------------- +// EFI_ABSOLUTE_POINTER_PROTOCOL API +STATIC +EFI_STATUS +EFIAPI +VirtioTabletGetState ( + IN EFI_ABSOLUTE_POINTER_PROTOCOL *This, + OUT EFI_ABSOLUTE_POINTER_STATE *State + ) +{ + VIRTIO_INPUT_DEV *Dev; + EFI_TPL OldTpl; + + if (State == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = VIRTIO_INPUT_FROM_ABS_POINTER_THIS (This); + + if (!Dev->AbsPointerReady) { + return EFI_NOT_READY; + } + + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + + CopyMem (State, &Dev->AbsPointerState, sizeof (*State)); + + // + // The reported position is absolute, so it persists; only clear the "new + // data" flag so the next GetState () returns EFI_NOT_READY until a fresh + // event arrives. + // + Dev->AbsPointerReady = FALSE; + + gBS->RestoreTPL (OldTpl); + + return EFI_SUCCESS; +} + +// ----------------------------------------------------------------------------- +// EFI_ABSOLUTE_POINTER_PROTOCOL WaitForInput event handler +STATIC +VOID +EFIAPI +VirtioTabletWaitForInput ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + VIRTIO_INPUT_DEV *Dev = Context; + + // + // Stall 1ms to give other timer-driven drivers a chance to run while this + // routine is recursively invoked from WaitForEvent (). + // + gBS->Stall (1000); + + // Drain pending events from the device. + VirtioInputTimer (NULL, Dev); + + // If there is new pointer activity - send signal + if (Dev->AbsPointerReady) { + gBS->SignalEvent (Event); + } +} + +STATIC +EFI_STATUS +VirtioTabletGetAbsMinMax ( + IN VIRTIO_INPUT_DEV *Dev, + IN UINT8 Axis, + OUT UINT32 *Min, + OUT UINT32 *Max + ) +{ + EFI_STATUS Status; + UINT8 Size; + + Status = VirtioInputConfigQuerySize (Dev, VirtioInputCfgAbsInfo, Axis, &Size); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Size < sizeof (VIRTIO_INPUT_ABS_INFO)) { + return EFI_UNSUPPORTED; + } + + Status = Dev->VirtIo->ReadDevice ( + Dev->VirtIo, + OFFSET_OF_VINPUT (Data.Abs.Min), + SIZE_OF_VINPUT (Data.Abs.Min), + sizeof (*Min), + Min + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = Dev->VirtIo->ReadDevice ( + Dev->VirtIo, + OFFSET_OF_VINPUT (Data.Abs.Max), + SIZE_OF_VINPUT (Data.Abs.Max), + sizeof (*Max), + Max + ); + return Status; +} + +EFI_STATUS +VirtioTabletInit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ) +{ + EFI_STATUS Status; + UINT32 AbsMinX; + UINT32 AbsMaxX; + UINT32 AbsMinY; + UINT32 AbsMaxY; + + Dev->AbsolutePointer.Reset = VirtioTabletReset; + Dev->AbsolutePointer.GetState = VirtioTabletGetState; + Dev->AbsolutePointer.Mode = &Dev->AbsPointerMode; + + ZeroMem (&Dev->AbsPointerMode, sizeof (Dev->AbsPointerMode)); + + Status = VirtioTabletGetAbsMinMax (Dev, ABS_X, &AbsMinX, &AbsMaxX); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = VirtioTabletGetAbsMinMax (Dev, ABS_Y, &AbsMinY, &AbsMaxY); + if (EFI_ERROR (Status)) { + return Status; + } + + Dev->AbsPointerMode.AbsoluteMinX = AbsMinX; + Dev->AbsPointerMode.AbsoluteMaxX = AbsMaxX; + Dev->AbsPointerMode.AbsoluteMinY = AbsMinY; + Dev->AbsPointerMode.AbsoluteMaxY = AbsMaxY; + Dev->AbsPointerMode.Attributes = EFI_ABSP_SupportsAltActive; + + ZeroMem (&Dev->AbsPointerState, sizeof (Dev->AbsPointerState)); + Dev->AbsPointerReady = FALSE; + + // + // Setup the WaitForInput event + // + Status = gBS->CreateEvent ( + EVT_NOTIFY_WAIT, + TPL_NOTIFY, + VirtioTabletWaitForInput, + Dev, + &Dev->AbsolutePointer.WaitForInput + ); + if (EFI_ERROR (Status)) { + return Status; + } + + return EFI_SUCCESS; +} + +VOID +VirtioTabletUninit ( + IN OUT VIRTIO_INPUT_DEV *Dev + ) +{ + gBS->CloseEvent (Dev->AbsolutePointer.WaitForInput); +} From 6c6d0a72c25ee4a43179d9d25b938eaa1381f8c8 Mon Sep 17 00:00:00 2001 From: FangSheng Huang <FangSheng.Huang@amd.com> Date: Tue, 30 Jun 2026 16:22:25 +0800 Subject: [PATCH 230/406] OvmfPkg/PlatformPei: retain SoftReserved memory under SEV-SNP Soft Reserved (Specific Purpose Memory) regions carry the EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE attribute, which the OS sees as EFI_MEMORY_SP (E820 Soft Reserved). Under SEV-SNP this does not reach the guest: AmdSevSnpInitialize() changes every EFI_RESOURCE_SYSTEM_MEMORY HOB above 4GB to EFI_RESOURCE_MEMORY_UNACCEPTED, and AcceptAllMemory() later re-adds the region as plain system memory without EFI_MEMORY_SP, so the guest sees ordinary RAM instead of Soft Reserved. Exclude SPECIAL_PURPOSE regions from the unaccepted conversion so they keep the EFI_RESOURCE_SYSTEM_MEMORY type and are pre-validated in place, like sub-4GB memory. Signed-off-by: FangSheng Huang <FangSheng.Huang@amd.com> --- OvmfPkg/PlatformPei/AmdSev.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 8562787035..9a77a34ecf 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -148,7 +148,17 @@ AmdSevSnpInitialize ( ResourceHob = Hob.ResourceDescriptor; if (ResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) { - if (ResourceHob->PhysicalStart >= SIZE_4GB) { + // + // Defer acceptance of memory above 4GB, which the OS accepts lazily. + // Specific Purpose Memory (E820 Soft Reserved) is excepted: it must + // keep the EFI_RESOURCE_SYSTEM_MEMORY type so its SPECIAL_PURPOSE + // attribute reaches the EFI memory map, and it is never handed to the + // OS allocator, so it would never be accepted lazily. Pre-validate + // it in place, like sub-4GB memory. + // + if ((ResourceHob->PhysicalStart >= SIZE_4GB) && + ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE) == 0)) + { ResourceHob->ResourceType = EFI_RESOURCE_MEMORY_UNACCEPTED; continue; } From 84690e91a4b3d7e0d17d8ba9c32dc2289cce381a Mon Sep 17 00:00:00 2001 From: Luigi Leonardi <leonardi@redhat.com> Date: Wed, 17 Jun 2026 12:56:42 +0200 Subject: [PATCH 231/406] OvmfPkg/QemuFwCfgSimpleParserLib: export QemuFwCfgGetAsString() Make QemuFwCfgGetAsString() a public EFIAPI entry point instead of a STATIC helper, so it can be used by consumers that need the raw fw_cfg string value rather than a parsed boolean or integer. Signed-off-by: Luigi Leonardi <leonardi@redhat.com> --- .../Library/QemuFwCfgSimpleParserLib.h | 44 +++++++++++++++++++ .../QemuFwCfgSimpleParser.c | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h b/OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h index 6275dd0ed6..e45ac058d7 100644 --- a/OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h +++ b/OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h @@ -10,6 +10,50 @@ #include <Base.h> +/** + Look up FileName with QemuFwCfgFindFile() from QemuFwCfgLib. Read the fw_cfg + file into the caller-provided CHAR8 array. NUL-terminate the array. + + @param[in] FileName The name of the fw_cfg file to look up and read. + + @param[in,out] BufferSize On input, number of bytes available in Buffer. + + On output, the number of bytes that have been + stored to Buffer. + + On error, BufferSize is indeterminate. + + @param[out] Buffer The buffer to read the fw_cfg file into. If the + fw_cfg file contents are not NUL-terminated, then + a NUL character is placed into Buffer after the + fw_cfg file contents. + + On error, Buffer is indeterminate. + + @retval RETURN_SUCCESS Buffer has been populated with the fw_cfg file + contents. Buffer is NUL-terminated regardless + of whether the fw_cfg file itself was + NUL-terminated. + + @retval RETURN_UNSUPPORTED Firmware configuration is unavailable. + + @retval RETURN_PROTOCOL_ERROR The fw_cfg file does not fit into Buffer. + + @retval RETURN_PROTOCOL_ERROR The fw_cfg file contents are not themselves + NUL-terminated, and an extra NUL byte does not + fit into Buffer. + + @return Error codes propagated from + QemuFwCfgFindFile(). +**/ +RETURN_STATUS +EFIAPI +QemuFwCfgGetAsString ( + IN CONST CHAR8 *FileName, + IN OUT UINTN *BufferSize, + OUT CHAR8 *Buffer + ); + /** Look up FileName with QemuFwCfgFindFile() from QemuFwCfgLib. Read the fw_cfg file into a small array with automatic storage duration. Parse the array as diff --git a/OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParser.c b/OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParser.c index c9e0091b82..18861735b9 100644 --- a/OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParser.c +++ b/OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParser.c @@ -82,8 +82,8 @@ STATIC CONST CHAR8 *CONST mFalseString[] = { @return Error codes propagated from QemuFwCfgFindFile(). **/ -STATIC RETURN_STATUS +EFIAPI QemuFwCfgGetAsString ( IN CONST CHAR8 *FileName, IN OUT UINTN *BufferSize, From f4bbef1dd7c15bec5ac164802842d55d740c36fe Mon Sep 17 00:00:00 2001 From: Luigi Leonardi <leonardi@redhat.com> Date: Wed, 17 Jun 2026 13:48:39 +0200 Subject: [PATCH 232/406] ArmVirtPkg: introduce compile and runtime control of serial debug log level MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new PCD `PcdSerialDebugPrintErrorLevel` that overrides the verbosity set in `DebugPrintErrorLevel` for the serial port debug output and does not affect memory debug logging. Accepted values are: - "silent": DEBUG_ERROR only - "verbose": use the `DebugPrintErrorLevel` value. - a hex bitmask (e.g. "0x80000040"). This PCD value can be overridden at runtime using the fw_cfg entry "opt/org.tianocore/DebugLevel" without rebuilding the firmware. The runtime override takes priority over the compile-time one. When neither is set, the serial output uses the compiled-in PcdDebugPrintErrorLevel. SEC and PEI_CORE phases do not support this override because they run from flash, where global variables are not available. Supporting it would require parsing the device tree on every debug write to locate the fw_cfg device and read the DebugLevel value — unnecessary overhead given the low volume of logs in those phases. ParseSerialDebugLevel() is duplicated as a STATIC function in Flash.c and PlatformPeiLib.c rather than shared via a header, because EDK2 coding style forbids function definitions in headers. A dedicated library class would be excessive for a small helper with only two consumers. Example QEMU command line: -fw_cfg name=opt/org.tianocore/DebugLevel,string=silent -fw_cfg name=opt/org.tianocore/DebugLevel,string=verbose -fw_cfg name=opt/org.tianocore/DebugLevel,string=0x80000000 Suggested-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Luigi Leonardi <leonardi@redhat.com> --- ArmVirtPkg/ArmVirtCloudHv.dsc | 2 + ArmVirtPkg/ArmVirtPkg.dec | 5 ++ ArmVirtPkg/ArmVirtQemuKernel.dsc | 3 + .../Include/Guid/EarlyPL011BaseAddress.h | 11 ++- .../Library/DebugLibFdtPL011Uart/DebugLib.c | 28 +++++-- .../DebugLibFdtPL011UartFlash.inf | 1 + .../Library/DebugLibFdtPL011Uart/Flash.c | 84 +++++++++++++++++++ ArmVirtPkg/Library/DebugLibFdtPL011Uart/Ram.c | 40 +++++++++ .../Library/DebugLibFdtPL011Uart/Write.h | 14 ++++ .../Library/PlatformPeiLib/PlatformPeiLib.c | 72 ++++++++++++++++ .../Library/PlatformPeiLib/PlatformPeiLib.inf | 3 + 11 files changed, 256 insertions(+), 7 deletions(-) diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index d76b17c602..122e0e8f6d 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -46,6 +46,8 @@ TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLibNull/PeiDxeTpmPlatformHierarchyLib.inf ArmTransferListLib|ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf + QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf + QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParserLib.inf !include MdePkg/MdeLibs.dsc.inc diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec index a05958ec64..8386ec0ad8 100644 --- a/ArmVirtPkg/ArmVirtPkg.dec +++ b/ArmVirtPkg/ArmVirtPkg.dec @@ -51,3 +51,8 @@ # Cloud Hypervisor has no other way to pass Rsdp address to the guest except use a PCD. # gArmVirtTokenSpaceGuid.PcdCloudHvAcpiRsdpBaseAddress|0x0|UINT64|0x00000005 + + ## Serial debug log level override. Accepts "silent", "verbose", or a + # hex bitmask (e.g. "0x80000040"). "verbose" falls back to the + # compiled-in PcdDebugPrintErrorLevel. + gArmVirtTokenSpaceGuid.PcdSerialDebugPrintErrorLevel|"verbose"|VOID*|0x00000006 diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc index 703eae9c07..7fdb3b55b9 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -75,6 +75,9 @@ ArmMonitorLib|ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.inf +[LibraryClasses.common.SEC] + QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf + [LibraryClasses.common.DXE_DRIVER] AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf diff --git a/ArmVirtPkg/Include/Guid/EarlyPL011BaseAddress.h b/ArmVirtPkg/Include/Guid/EarlyPL011BaseAddress.h index 2857a3b3c2..e56e7e3370 100644 --- a/ArmVirtPkg/Include/Guid/EarlyPL011BaseAddress.h +++ b/ArmVirtPkg/Include/Guid/EarlyPL011BaseAddress.h @@ -21,9 +21,16 @@ typedef struct { // // for SerialPortLib and console IO // - UINT64 ConsoleAddress; + UINT64 ConsoleAddress; // // for DebugLib; may equal ConsoleAddress if there's only one PL011 UART // - UINT64 DebugAddress; + UINT64 DebugAddress; + // + // Serial debug log level override from fw_cfg "opt/org.tianocore/DebugLevel" + // or PcdSerialDebugPrintErrorLevel. DebugLevelSet is TRUE when an override + // is active; DebugLevel contains the parsed bitmask. + // + BOOLEAN DebugLevelSet; + UINT32 DebugLevel; } EARLY_PL011_BASE_ADDRESS; diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLib.c b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLib.c index 18222aaebc..128db7c754 100644 --- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLib.c +++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLib.c @@ -94,17 +94,28 @@ DebugPrintMarker ( IN BASE_LIST BaseListMarker ) { - CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; + CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; + UINT32 SerialDebugLevel; + UINT32 DebugLevel; + EFI_STATUS Status; // // If Format is NULL, then ASSERT(). // ASSERT (Format != NULL); + DebugLevel = GetDebugPrintErrorLevel (); + + Status = GetSerialDebugPrintErrorLevel (&SerialDebugLevel); + if (EFI_ERROR (Status)) { + SerialDebugLevel = DebugLevel; + } + // - // Check driver debug mask value and global mask + // SerialDebugLevel can be more verbose than DebugLevel. + // Check if we have something to print // - if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) { + if (((ErrorLevel & DebugLevel) == 0) && ((ErrorLevel & SerialDebugLevel) == 0)) { return; } @@ -118,12 +129,19 @@ DebugPrintMarker ( } // - // Send string to Memory Debug Log if enabled + // Send string to Memory Debug Log if enabled and error level matches // - if (MemDebugLogEnabled ()) { + if (((ErrorLevel & DebugLevel) != 0) && MemDebugLogEnabled ()) { MemDebugLogWrite ((CHAR8 *)Buffer, AsciiStrLen (Buffer)); } + // + // Check runtime debug mask value and global mask + // + if ((ErrorLevel & SerialDebugLevel) == 0) { + return; + } + // // Send the print string to a Serial Port // diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf index 6b3b3316a2..9951edcd20 100644 --- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf +++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf @@ -50,6 +50,7 @@ [FixedPcd] gArmPlatformTokenSpaceGuid.PL011UartClkInHz + gArmVirtTokenSpaceGuid.PcdSerialDebugPrintErrorLevel gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Flash.c b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Flash.c index a624e0860d..7419fa0dc4 100644 --- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Flash.c +++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Flash.c @@ -6,12 +6,64 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> #include <Library/FdtSerialPortAddressLib.h> #include <Library/PL011UartLib.h> #include <Library/PcdLib.h> #include "Write.h" +// +// Duplicated in ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c — +// keep both copies in sync. +// + +/** + Parse a serial debug level string. + + Accepted values are "silent" (DEBUG_ERROR only), "verbose" (no + override), or a hex bitmask (e.g. "0x80000040"). + + @param[in] String NUL-terminated ASCII string to parse. + @param[out] DebugLevel On success, the parsed debug level bitmask. + + @retval TRUE String was recognised; *DebugLevel is valid. + @retval FALSE String is NULL, "verbose", or unrecognised; no override. +**/ +STATIC +BOOLEAN +ParseSerialDebugLevel ( + IN CONST CHAR8 *String, + OUT UINT32 *DebugLevel + ) +{ + UINT64 Value; + CHAR8 *End; + + if ((String == NULL) || (DebugLevel == NULL)) { + return FALSE; + } + + if (AsciiStrCmp (String, "silent") == 0) { + *DebugLevel = DEBUG_ERROR; + return TRUE; + } + + if (AsciiStrCmp (String, "verbose") == 0) { + return FALSE; + } + + if (!EFI_ERROR (AsciiStrHexToUint64S (String, &End, &Value)) && + (*End == '\0')) + { + *DebugLevel = (UINT32)Value; + return TRUE; + } + + return FALSE; +} + /** (Copied from SerialPortWrite() in "MdePkg/Include/Library/SerialPortLib.h" at commit c4547aefb3d0, with the Buffer non-nullity assertion removed:) @@ -105,3 +157,35 @@ DebugLibFdtPL011UartWrite ( return PL011UartWrite ((UINTN)DebugAddress, Buffer, NumberOfBytes); } + +/** + Retrieve the serial debug print error level override. + + The flash variant parses the compile-time PCD only. The fw_cfg + override is not available in SEC/PEI_CORE phases. + + @param[out] Value On success, the debug log level bitmask. + + @retval EFI_SUCCESS The debug level was retrieved successfully. + @retval EFI_INVALID_PARAMETER Value is NULL. + @retval EFI_NOT_FOUND No override is configured (e.g. "verbose"). +**/ +EFI_STATUS +GetSerialDebugPrintErrorLevel ( + OUT UINT32 *Value + ) +{ + CONST CHAR8 *String; + + if (Value == NULL) { + return EFI_INVALID_PARAMETER; + } + + String = (CONST CHAR8 *)PcdGetPtr (PcdSerialDebugPrintErrorLevel); + + if (ParseSerialDebugLevel (String, Value)) { + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; +} diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Ram.c b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Ram.c index bc5be015bd..1d923a0f87 100644 --- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Ram.c +++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Ram.c @@ -20,6 +20,8 @@ UINTN mDebugLibFdtPL011UartAddress; RETURN_STATUS mDebugLibFdtPL011UartPermanentStatus = RETURN_SUCCESS; +BOOLEAN mSerialDebugLevelSet; +UINT32 mSerialDebugLevel; /** Statefully initialize both the library instance and the debug PL011 UART. @@ -62,6 +64,11 @@ Initialize ( goto Failed; } + if (UartBase->DebugLevelSet) { + mSerialDebugLevelSet = TRUE; + mSerialDebugLevel = UartBase->DebugLevel; + } + BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate); ReceiveFifoDepth = 0; // Use the default value for Fifo depth Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity); @@ -122,3 +129,36 @@ DebugLibFdtPL011UartWrite ( return PL011UartWrite (mDebugLibFdtPL011UartAddress, Buffer, NumberOfBytes); } + +/** + Retrieve the serial debug print error level override. + + @param[out] Value On success, the debug log level bitmask. + + @retval EFI_SUCCESS The debug level was retrieved successfully. + @retval EFI_INVALID_PARAMETER Value is NULL. + @retval EFI_NOT_FOUND The debug level is not available. +**/ +EFI_STATUS +GetSerialDebugPrintErrorLevel ( + OUT UINT32 *Value + ) +{ + RETURN_STATUS Status; + + if (Value == NULL) { + return EFI_INVALID_PARAMETER; + } + + Status = Initialize (); + if (RETURN_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + if (mSerialDebugLevelSet) { + *Value = mSerialDebugLevel; + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; +} diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Write.h b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Write.h index b57861f67c..074d1ac448 100644 --- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Write.h +++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Write.h @@ -34,3 +34,17 @@ DebugLibFdtPL011UartWrite ( IN UINT8 *Buffer, IN UINTN NumberOfBytes ); + +/** + Retrieve the serial debug print error level override. + + @param[out] Value On success, the debug log level bitmask. + + @retval EFI_SUCCESS The debug level was retrieved successfully. + @retval EFI_INVALID_PARAMETER Value is NULL. + @retval EFI_NOT_FOUND The debug level is not available. +**/ +EFI_STATUS +GetSerialDebugPrintErrorLevel ( + OUT UINT32 *Value + ); diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c index 7d3f8c4c86..e039810dc1 100644 --- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c +++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c @@ -9,6 +9,7 @@ #include <PiPei.h> +#include <Library/BaseLib.h> #include <Library/BaseMemoryLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/DebugLib.h> @@ -17,10 +18,61 @@ #include <Library/PcdLib.h> #include <Library/PeiServicesLib.h> #include <Library/FdtSerialPortAddressLib.h> +#include <Library/QemuFwCfgSimpleParserLib.h> #include <Guid/EarlyPL011BaseAddress.h> #include <Guid/FdtHob.h> +// +// Duplicated in ArmVirtPkg/Library/DebugLibFdtPL011Uart/Flash.c — +// keep both copies in sync. +// + +/** + Parse a serial debug level string. + + Accepted values are "silent" (DEBUG_ERROR only), "verbose" (no + override), or a hex bitmask (e.g. "0x80000040"). + + @param[in] String NUL-terminated ASCII string to parse. + @param[out] DebugLevel On success, the parsed debug level bitmask. + + @retval TRUE String was recognised; *DebugLevel is valid. + @retval FALSE String is NULL, "verbose", or unrecognised; no override. +**/ +STATIC +BOOLEAN +ParseSerialDebugLevel ( + IN CONST CHAR8 *String, + OUT UINT32 *DebugLevel + ) +{ + UINT64 Value; + CHAR8 *End; + + if ((String == NULL) || (DebugLevel == NULL)) { + return FALSE; + } + + if (AsciiStrCmp (String, "silent") == 0) { + *DebugLevel = DEBUG_ERROR; + return TRUE; + } + + if (AsciiStrCmp (String, "verbose") == 0) { + return FALSE; + } + + if (!EFI_ERROR (AsciiStrHexToUint64S (String, &End, &Value)) && + (*End == '\0')) + { + *DebugLevel = (UINT32)Value; + return TRUE; + } + + return FALSE; +} + STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpm2DiscoveredPpi = { EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, &gOvmfTpmDiscoveredPpiGuid, @@ -56,6 +108,9 @@ PlatformPeim ( CONST UINT32 *RangesProp; UINT64 TpmBase; EFI_STATUS Status; + CHAR8 DebugLevelBuf[32]; + UINTN DebugLevelBufSize; + CONST CHAR8 *DebugLevelStr; Base = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress); ASSERT (Base != NULL); @@ -124,6 +179,23 @@ PlatformPeim ( )); } + DebugLevelBufSize = sizeof (DebugLevelBuf); + Status = QemuFwCfgGetAsString ( + "opt/org.tianocore/DebugLevel", + &DebugLevelBufSize, + DebugLevelBuf + ); + if (!RETURN_ERROR (Status)) { + DebugLevelStr = DebugLevelBuf; + } else { + DebugLevelStr = (CONST CHAR8 *)PcdGetPtr (PcdSerialDebugPrintErrorLevel); + } + + UartHobData->DebugLevelSet = ParseSerialDebugLevel ( + DebugLevelStr, + &UartHobData->DebugLevel + ); + TpmBase = 0; // diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf index d6c1b135c2..731d940333 100644 --- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf +++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf @@ -30,6 +30,7 @@ gArmVirtTokenSpaceGuid.PcdTpm2SupportEnabled [LibraryClasses] + BaseLib BaseMemoryLib DebugLib HobLib @@ -37,9 +38,11 @@ FdtSerialPortAddressLib PcdLib PeiServicesLib + QemuFwCfgSimpleParserLib [FixedPcd] gArmTokenSpaceGuid.PcdFvSize + gArmVirtTokenSpaceGuid.PcdSerialDebugPrintErrorLevel gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeAllocationPadding [Pcd] From af41063d814bb93dc8e72f7c94c09b513b28870d Mon Sep 17 00:00:00 2001 From: Luigi Leonardi <leonardi@redhat.com> Date: Wed, 17 Jun 2026 11:18:36 +0200 Subject: [PATCH 233/406] OvmfPkg: document DebugLevel runtime config Add documentation for the DebugLevel runtime config that sets the verbosity of the serial debug log level on ArmVirt. Signed-off-by: Luigi Leonardi <leonardi@redhat.com> --- OvmfPkg/RUNTIME_CONFIG.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/OvmfPkg/RUNTIME_CONFIG.md b/OvmfPkg/RUNTIME_CONFIG.md index 57d0dd9611..aad3f96d6e 100644 --- a/OvmfPkg/RUNTIME_CONFIG.md +++ b/OvmfPkg/RUNTIME_CONFIG.md @@ -240,6 +240,31 @@ qemu-system-x86_64 -fw_cfg name=opt/org.tianocore/PagingLevel,string=5 ``` +## Debug: opt/org.tianocore/DebugLevel + +Override the serial debug log level at boot time without rebuilding +the firmware. When set, serial port output uses this level; the +memory debug log continues to use the compiled-in level. Currently +only supported on ArmVirtQemu. + +Accepted values: + +- ``silent`` — only error messages (DEBUG_ERROR) +- ``verbose`` — use the compiled-in PcdDebugPrintErrorLevel +- A hex bitmask (e.g. ``0x80000040``) + +When the fw_cfg entry is absent, the value of +``PcdSerialDebugPrintErrorLevel`` is used (default: ``verbose``). + +Usage: + +``` +qemu-system-aarch64 -fw_cfg name=opt/org.tianocore/DebugLevel,string=silent +qemu-system-aarch64 -fw_cfg name=opt/org.tianocore/DebugLevel,string=verbose +qemu-system-aarch64 -fw_cfg name=opt/org.tianocore/DebugLevel,string=0x80000000 +``` + + ## Other: opt/org.tianocore/UsbStorageSupport This enables/disables the edk2 driver for USB storage devices. From 6f2b09986b911d811e6df61420ecc0ca34e1e442 Mon Sep 17 00:00:00 2001 From: Chris Fernald <chfernal@microsoft.com> Date: Wed, 17 Jun 2026 12:10:13 -0700 Subject: [PATCH 234/406] ArmPkg: Handle FFA_BUSY response for MM communication MM communicate is used at runtime, and the secure partition it is communicating with may provide services access through other means then the UEFI runtime services. As such, the MM communication library must not assume that the partition will be in the waiting state. Instead it must handle the case where the partition is busy and retry the communication to some limit. Signed-off-by: Chris Fernald <chfernal@microsoft.com> --- .../MmCommunicationDxe/MmCommunication.c | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c index a4ff4848cb..50d0a35526 100644 --- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c @@ -29,6 +29,11 @@ #define COMM_BUFFER_ATTRS (EFI_MEMORY_WB | EFI_MEMORY_XP | EFI_MEMORY_RUNTIME) +// This an absurdly high number. The timer cannot be used reliably at runtime so having some upper bound is necessary. +// This number is chosen with back-of-the-envelope calculations where the rough time to get a BUSY response it around +// 10 microseconds, so 500,000 retries is roughly 5 seconds. +#define MAX_BUSY_RETRIES 500000 + // // Partition ID if FF-A support is enabled // @@ -64,16 +69,31 @@ SendFfaMmCommunicate ( { EFI_STATUS Status; DIRECT_MSG_ARGS CommunicateArgs; + UINT64 Retries; - ZeroMem (&CommunicateArgs, sizeof (DIRECT_MSG_ARGS)); + Retries = 0; + while (TRUE) { + ZeroMem (&CommunicateArgs, sizeof (DIRECT_MSG_ARGS)); + CommunicateArgs.Arg0 = (UINTN)mNsCommBuffMemRegion.PhysicalBase; - CommunicateArgs.Arg0 = (UINTN)mNsCommBuffMemRegion.PhysicalBase; + Status = ArmFfaLibMsgSendDirectReq ( + mStMmPartId, + 0, + &CommunicateArgs + ); - Status = ArmFfaLibMsgSendDirectReq ( - mStMmPartId, - 0, - &CommunicateArgs - ); + if (Status == EFI_NO_RESPONSE) { + // Only try for so long before just failing. + if (Retries >= MAX_BUSY_RETRIES) { + return EFI_TIMEOUT; + } + + Retries++; + continue; + } + + break; + } while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the StMM SP since it is UP. From 89c6073683e18cd3271d7263b0e2712c88c7ec12 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Fri, 19 Jun 2026 10:05:17 -0700 Subject: [PATCH 235/406] MdePkg,MdeModulePkg: ArmFfaLib: Expand to include first 4 registers The direct message arguments stripped off the header, making the underlying FF-A function interface to lose information when it comes to certain return code, i.e. FFA_YIELD and FFA_INTERRUPT. This change adds back the header field for this purpose so that the callers can decide how to act on the corresponding return codes. It then populates the header field for this purpose in FFA direct message functions so that the callers can decide how to act on the corresponding return codes. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c | 12 +++++++++--- MdePkg/Include/Library/ArmFfaLib.h | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c index 9c90bcada0..c8b068ebfa 100644 --- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c @@ -749,13 +749,13 @@ ArmFfaLibRun ( ArmCallFfa (&FfaArgs); Status = FfaArgsToEfiStatus (&FfaArgs); - if (EFI_ERROR (Status)) { - return Status; - } if (DirectMsgArg != NULL) { ZeroMem (DirectMsgArg, sizeof (DIRECT_MSG_ARGS)); + // Copy the FFA header to the direct message arguments + CopyMem (&(DirectMsgArg->Header), &FfaArgs, sizeof (DirectMsgArg->Header)); + if (FfaArgs.Arg0 == ARM_FID_FFA_MSG_SEND_DIRECT_RESP) { DirectMsgArg->Arg0 = FfaArgs.Arg3; DirectMsgArg->Arg1 = FfaArgs.Arg4; @@ -790,6 +790,8 @@ ArmFfaLibRun ( @param [in] Flags Message flags @param [in, out] ImpDefArgs Implemented defined arguments and Implemented defined return values + The header registers (x0-x2) will be initialized + with the values from DestPartId and Flags. @retval EFI_SUCCESS Success @retval Others Error @@ -831,6 +833,7 @@ ArmFfaLibMsgSendDirectReq ( Status = FfaArgsToEfiStatus (&FfaArgs); if (EFI_ERROR (Status)) { + CopyMem (ImpDefArgs, &FfaArgs, sizeof (DIRECT_MSG_ARGS)); return Status; } @@ -850,6 +853,8 @@ ArmFfaLibMsgSendDirectReq ( @param [in] ServiceGuid Service guid @param [in, out] ImpDefArgs Implemented defined arguments and Implemented defined return values + The header registers (x0-x3) will be + initialized with the values from DestPartId and ServiceGuid. @retval EFI_SUCCESS Success @retval Others Error @@ -915,6 +920,7 @@ ArmFfaLibMsgSendDirectReq2 ( Status = FfaArgsToEfiStatus (&FfaArgs); if (EFI_ERROR (Status)) { + CopyMem (ImpDefArgs, &FfaArgs, sizeof (DIRECT_MSG_ARGS)); return Status; } diff --git a/MdePkg/Include/Library/ArmFfaLib.h b/MdePkg/Include/Library/ArmFfaLib.h index 9adfffb0e0..021b3056a8 100644 --- a/MdePkg/Include/Library/ArmFfaLib.h +++ b/MdePkg/Include/Library/ArmFfaLib.h @@ -53,6 +53,14 @@ typedef struct ArmFfaArgs { * FFA_SEND_MSG_DIRECT_REQ2/FFA_SEND_MSG_DIRECT_RESP2 (i.e. v2) */ typedef struct DirectMsgArgs { + /// Header containing the arguments for the header registers (x0-x2 (v1) or x0-x3 (v2)) + struct { + UINTN x0; + UINTN x1; + UINTN x2; + UINTN x3; + } Header; + /// Implementation define argument 0, this will be set to/from x3(v1) or x4(v2) UINTN Arg0; @@ -96,6 +104,8 @@ typedef struct DirectMsgArgs { UINTN Arg13; } DIRECT_MSG_ARGS; +STATIC_ASSERT (sizeof (DIRECT_MSG_ARGS) == sizeof (ARM_FFA_ARGS), "DIRECT_MSG_ARGS and ARM_FFA_ARGS must be the same size"); + /** Trigger FF-A ABI call according to PcdFfaLibConduitSmc. From ed21313ac782d7a4591e0883b07baaf7f5f25986 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Fri, 19 Jun 2026 10:06:24 -0700 Subject: [PATCH 236/406] ArmPkg: MmCommunication: FFA run should use the returned ID As the FFA function now returns the target ID properly, instead of hardcoding the FFA_RUN target ID being the STMM, we use the parsed ID to issue the FFA_RUN. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c | 2 +- ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c index 50d0a35526..2acfc180ab 100644 --- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c @@ -97,7 +97,7 @@ SendFfaMmCommunicate ( while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the StMM SP since it is UP. - Status = ArmFfaLibRun (mStMmPartId, 0x00, NULL); + Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (CommunicateArgs.Header.x1), 0x00, &CommunicateArgs); } return Status; diff --git a/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c b/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c index 4fc0a45728..cb53dd5131 100644 --- a/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c +++ b/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c @@ -217,7 +217,7 @@ SendFfaMmCommunicate ( while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the StMM SP since it is UP. - Status = ArmFfaLibRun (mStMmPartId, 0x00, NULL); + Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (CommunicateArgs.Header.x1), 0x00, &CommunicateArgs); } return Status; From 2938b830f61de6263f0e2dbf0f98fba63951a97b Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Fri, 19 Jun 2026 10:07:20 -0700 Subject: [PATCH 237/406] SecurityPkg: Tpm over FFA: FFA_RUN command should use the returned ID As the FFA function now returns the target ID properly, instead of hardcoding the FFA_RUN target ID being the TPM SP, we use the parsed ID to issue the FFA_RUN. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- .../Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c | 12 ++++++------ SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c index 7dd1fb594f..2314d1f22a 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c @@ -158,7 +158,7 @@ Tpm2GetInterfaceVersion ( Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. - Status = ArmFfaLibRun (mFfaTpm2PartitionId, 0x00, &FfaDirectReq2Args); + Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { @@ -210,7 +210,7 @@ Tpm2GetFeatureInfo ( Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. - Status = ArmFfaLibRun (mFfaTpm2PartitionId, 0x00, &FfaDirectReq2Args); + Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { @@ -254,7 +254,7 @@ Tpm2ServiceStart ( Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. - Status = ArmFfaLibRun (mFfaTpm2PartitionId, 0x00, &FfaDirectReq2Args); + Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { @@ -299,7 +299,7 @@ Tpm2RegisterNotification ( Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. - Status = ArmFfaLibRun (mFfaTpm2PartitionId, 0x00, &FfaDirectReq2Args); + Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { @@ -336,7 +336,7 @@ Tpm2UnregisterNotification ( Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. - Status = ArmFfaLibRun (mFfaTpm2PartitionId, 0x00, &FfaDirectReq2Args); + Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { @@ -373,7 +373,7 @@ Tpm2FinishNotified ( Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. - Status = ArmFfaLibRun (mFfaTpm2PartitionId, 0x00, &FfaDirectReq2Args); + Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c index 80df9db700..4c9e7fa536 100644 --- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c +++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c @@ -69,7 +69,7 @@ Tpm2FfaCheckInterfaceVersion ( Status = ArmFfaLibMsgSendDirectReq2 (TpmPartId, &gTpm2ServiceFfaGuid, &TpmArgs); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. - Status = ArmFfaLibRun (TpmPartId, 0x00, &TpmArgs); + Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (TpmArgs.Header.x1), 0x00, &TpmArgs); } if (EFI_ERROR (Status) || (TpmArgs.Arg0 != TPM2_FFA_SUCCESS_OK_RESULTS_RETURNED)) { From 00a865d595591fef44dc9f23353f5c3d50152e04 Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Thu, 25 Jun 2026 14:17:28 +0800 Subject: [PATCH 238/406] MdeModulePkg/GptLib: Extract shareable GPT parser into a library As reported in CVE-2024-13745 via oss-sec, DxeTpm2MeasureBootLib can measure a partition table that differs from the one parsed by the PartitionDxe driver. To address this, the more complete GPT parsing logic from PartitionDxe is extracted into a standalone GptLib library so it can be shared between PartitionDxe and DxeTpm2MeasureBootLib. This ensures that the exact same partition table measured into PCR[5] is the one parsed and used by the system. PartitionDxe behavior is unchanged. Ref: https://seclists.org/oss-sec/2026/q2/727 Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- MdeModulePkg/Include/Library/GptLib.h | 97 +++ MdeModulePkg/Library/GptLib/Gpt.c | 548 ++++++++++++++++ MdeModulePkg/Library/GptLib/GptLib.inf | 49 ++ MdeModulePkg/MdeModulePkg.dec | 3 + MdeModulePkg/MdeModulePkg.dsc | 2 + .../Universal/Disk/PartitionDxe/Gpt.c | 585 +----------------- .../Universal/Disk/PartitionDxe/Partition.h | 11 +- .../Disk/PartitionDxe/PartitionDxe.inf | 2 + 8 files changed, 707 insertions(+), 590 deletions(-) create mode 100644 MdeModulePkg/Include/Library/GptLib.h create mode 100644 MdeModulePkg/Library/GptLib/Gpt.c create mode 100644 MdeModulePkg/Library/GptLib/GptLib.inf diff --git a/MdeModulePkg/Include/Library/GptLib.h b/MdeModulePkg/Include/Library/GptLib.h new file mode 100644 index 0000000000..404d8630b7 --- /dev/null +++ b/MdeModulePkg/Include/Library/GptLib.h @@ -0,0 +1,97 @@ +/** @file + Shared GUID Partition Table (GPT) parsing and validation routines. + + These routines decode and validate a disk partitioned with the GPT scheme + as described in the UEFI specification. They are shared between the + Partition driver (which installs child handles) and other consumers that + need to parse the same on-disk GPT layout. + + Caution: These routines may receive untrusted input. The GPT partition + table is external input and must be validated carefully to avoid security + issues like buffer overflow and integer overflow. + +Copyright (c) 2026, SUSE LLC. All rights reserved.<BR> +Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. +Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#pragma once + +#include <Uefi.h> +#include <Guid/Gpt.h> +#include <Protocol/BlockIo.h> +#include <Protocol/DiskIo.h> + +// +// GPT Partition Entry Status +// +typedef struct { + BOOLEAN OutOfRange; + BOOLEAN Overlap; + BOOLEAN OsSpecific; +} EFI_PARTITION_ENTRY_STATUS; + +/** + Read GPT partition table header from the given LBA and validate it. + + Caution: This function may receive untrusted input. + The GPT partition table header is external input, so this routine + will do basic validation for GPT partition table header before return. + + @param[in] BlockIo Parent BlockIo interface. + @param[in] DiskIo Disk Io protocol. + @param[in] Lba The starting Lba of the Partition Table. + @param[out] PartHeader Stores the partition table that is read. + + @retval TRUE The partition table is valid. + @retval FALSE The partition table is not valid. + +**/ +BOOLEAN +PartitionValidGptTable ( + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_DISK_IO_PROTOCOL *DiskIo, + IN EFI_LBA Lba, + OUT EFI_PARTITION_TABLE_HEADER *PartHeader + ); + +/** + Restore Partition Table to its alternate place + (Primary -> Backup or Backup -> Primary). + + @param[in] BlockIo Parent BlockIo interface. + @param[in] DiskIo Disk Io Protocol. + @param[in] PartHeader Partition table header structure. + + @retval TRUE Restoring succeeds. + @retval FALSE Restoring failed. + +**/ +BOOLEAN +PartitionRestoreGptTable ( + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_DISK_IO_PROTOCOL *DiskIo, + IN EFI_PARTITION_TABLE_HEADER *PartHeader + ); + +/** + Check GPT partition entries and report the status of each entry. + + Caution: This function may receive untrusted input. + The GPT partition entry is external input, so this routine + will do basic validation for GPT partition entry and report status. + + @param[in] PartHeader Partition table header structure. + @param[in] PartEntry The partition entry array. + @param[out] PEntryStatus The partition entry status array + recording the status of each partition. + +**/ +VOID +PartitionCheckGptEntry ( + IN EFI_PARTITION_TABLE_HEADER *PartHeader, + IN EFI_PARTITION_ENTRY *PartEntry, + OUT EFI_PARTITION_ENTRY_STATUS *PEntryStatus + ); diff --git a/MdeModulePkg/Library/GptLib/Gpt.c b/MdeModulePkg/Library/GptLib/Gpt.c new file mode 100644 index 0000000000..e62a2299f5 --- /dev/null +++ b/MdeModulePkg/Library/GptLib/Gpt.c @@ -0,0 +1,548 @@ +/** @file + Decode a hard disk partitioned with the GPT scheme in the UEFI 2.0 + specification. + + Caution: This file requires additional review when modified. + This driver will have external input - disk partition. + This external input must be validated carefully to avoid security issue like + buffer overflow, integer overflow. + + PartitionValidGptTable(), PartitionCheckGptEntry() routine will accept disk + partition content and validate the GPT table and GPT entry. + +Copyright (c) 2026, SUSE LLC. All rights reserved.<BR> +Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. +Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/GptLib.h> + +/** + Check if the CRC field in the Partition table header is valid + for Partition entry array. + + @param[in] BlockIo Parent BlockIo interface + @param[in] DiskIo Disk Io Protocol. + @param[in] PartHeader Partition table header structure + + @retval TRUE the CRC is valid + @retval FALSE the CRC is invalid + +**/ +STATIC +BOOLEAN +PartitionCheckGptEntryArrayCRC ( + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_DISK_IO_PROTOCOL *DiskIo, + IN EFI_PARTITION_TABLE_HEADER *PartHeader + ); + +/** + Checks the CRC32 value in the table header. + + @param MaxSize Max Size limit + @param Size The size of the table + @param Hdr Table to check + + @return TRUE CRC Valid + @return FALSE CRC Invalid + +**/ +STATIC +BOOLEAN +PartitionCheckCrcAltSize ( + IN UINTN MaxSize, + IN UINTN Size, + IN OUT EFI_TABLE_HEADER *Hdr + ); + +/** + Checks the CRC32 value in the table header. + + @param MaxSize Max Size limit + @param Hdr Table to check + + @return TRUE CRC Valid + @return FALSE CRC Invalid + +**/ +STATIC +BOOLEAN +PartitionCheckCrc ( + IN UINTN MaxSize, + IN OUT EFI_TABLE_HEADER *Hdr + ); + +/** + Updates the CRC32 value in the table header. + + @param Size The size of the table + @param Hdr Table to update + +**/ +STATIC +VOID +PartitionSetCrcAltSize ( + IN UINTN Size, + IN OUT EFI_TABLE_HEADER *Hdr + ); + +/** + Updates the CRC32 value in the table header. + + @param Hdr Table to update + +**/ +STATIC +VOID +PartitionSetCrc ( + IN OUT EFI_TABLE_HEADER *Hdr + ); + +/** + This routine will read GPT partition table header and return it. + + Caution: This function may receive untrusted input. + The GPT partition table header is external input, so this routine + will do basic validation for GPT partition table header before return. + + @param[in] BlockIo Parent BlockIo interface. + @param[in] DiskIo Disk Io protocol. + @param[in] Lba The starting Lba of the Partition Table + @param[out] PartHeader Stores the partition table that is read + + @retval TRUE The partition table is valid + @retval FALSE The partition table is not valid + +**/ +BOOLEAN +PartitionValidGptTable ( + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_DISK_IO_PROTOCOL *DiskIo, + IN EFI_LBA Lba, + OUT EFI_PARTITION_TABLE_HEADER *PartHeader + ) +{ + EFI_STATUS Status; + UINT32 BlockSize; + EFI_PARTITION_TABLE_HEADER *PartHdr; + UINT32 MediaId; + + BlockSize = BlockIo->Media->BlockSize; + MediaId = BlockIo->Media->MediaId; + PartHdr = AllocateZeroPool (BlockSize); + + if (PartHdr == NULL) { + DEBUG ((DEBUG_ERROR, "Allocate pool error\n")); + return FALSE; + } + + // + // Read the EFI Partition Table Header + // + Status = DiskIo->ReadDisk ( + DiskIo, + MediaId, + MultU64x32 (Lba, BlockSize), + BlockSize, + PartHdr + ); + if (EFI_ERROR (Status)) { + FreePool (PartHdr); + return FALSE; + } + + if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) || + !PartitionCheckCrc (BlockSize, &PartHdr->Header) || + (PartHdr->MyLBA != Lba) || + (PartHdr->SizeOfPartitionEntry < sizeof (EFI_PARTITION_ENTRY)) + ) + { + DEBUG ((DEBUG_INFO, "Invalid efi partition table header\n")); + FreePool (PartHdr); + return FALSE; + } + + // + // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow. + // + if (PartHdr->NumberOfPartitionEntries > DivU64x32 (MAX_UINTN, PartHdr->SizeOfPartitionEntry)) { + FreePool (PartHdr); + return FALSE; + } + + CopyMem (PartHeader, PartHdr, sizeof (EFI_PARTITION_TABLE_HEADER)); + if (!PartitionCheckGptEntryArrayCRC (BlockIo, DiskIo, PartHeader)) { + FreePool (PartHdr); + return FALSE; + } + + DEBUG ((DEBUG_INFO, " Valid efi partition table header\n")); + FreePool (PartHdr); + return TRUE; +} + +/** + Check if the CRC field in the Partition table header is valid + for Partition entry array. + + @param[in] BlockIo Parent BlockIo interface + @param[in] DiskIo Disk Io Protocol. + @param[in] PartHeader Partition table header structure + + @retval TRUE the CRC is valid + @retval FALSE the CRC is invalid + +**/ +STATIC +BOOLEAN +PartitionCheckGptEntryArrayCRC ( + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_DISK_IO_PROTOCOL *DiskIo, + IN EFI_PARTITION_TABLE_HEADER *PartHeader + ) +{ + EFI_STATUS Status; + UINT8 *Ptr; + UINT32 Crc; + UINTN Size; + + // + // Read the EFI Partition Entries + // + Ptr = AllocatePool (PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry); + if (Ptr == NULL) { + DEBUG ((DEBUG_ERROR, " Allocate pool error\n")); + return FALSE; + } + + Status = DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + MultU64x32 (PartHeader->PartitionEntryLBA, BlockIo->Media->BlockSize), + PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry, + Ptr + ); + if (EFI_ERROR (Status)) { + FreePool (Ptr); + return FALSE; + } + + Size = PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry; + + Status = gBS->CalculateCrc32 (Ptr, Size, &Crc); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "CheckPEntryArrayCRC: Crc calculation failed\n")); + FreePool (Ptr); + return FALSE; + } + + FreePool (Ptr); + + return (BOOLEAN)(PartHeader->PartitionEntryArrayCRC32 == Crc); +} + +/** + Restore Partition Table to its alternate place + (Primary -> Backup or Backup -> Primary). + + @param[in] BlockIo Parent BlockIo interface. + @param[in] DiskIo Disk Io Protocol. + @param[in] PartHeader Partition table header structure. + + @retval TRUE Restoring succeeds + @retval FALSE Restoring failed + +**/ +BOOLEAN +PartitionRestoreGptTable ( + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_DISK_IO_PROTOCOL *DiskIo, + IN EFI_PARTITION_TABLE_HEADER *PartHeader + ) +{ + EFI_STATUS Status; + UINTN BlockSize; + EFI_PARTITION_TABLE_HEADER *PartHdr; + EFI_LBA PEntryLBA; + UINT8 *Ptr; + UINT32 MediaId; + + PartHdr = NULL; + Ptr = NULL; + + BlockSize = BlockIo->Media->BlockSize; + MediaId = BlockIo->Media->MediaId; + + PartHdr = AllocateZeroPool (BlockSize); + + if (PartHdr == NULL) { + DEBUG ((DEBUG_ERROR, "Allocate pool error\n")); + return FALSE; + } + + PEntryLBA = (PartHeader->MyLBA == PRIMARY_PART_HEADER_LBA) ? \ + (PartHeader->LastUsableLBA + 1) : \ + (PRIMARY_PART_HEADER_LBA + 1); + + CopyMem (PartHdr, PartHeader, sizeof (EFI_PARTITION_TABLE_HEADER)); + + PartHdr->MyLBA = PartHeader->AlternateLBA; + PartHdr->AlternateLBA = PartHeader->MyLBA; + PartHdr->PartitionEntryLBA = PEntryLBA; + PartitionSetCrc ((EFI_TABLE_HEADER *)PartHdr); + + Status = DiskIo->WriteDisk ( + DiskIo, + MediaId, + MultU64x32 (PartHdr->MyLBA, (UINT32)BlockSize), + BlockSize, + PartHdr + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + Ptr = AllocatePool (PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry); + if (Ptr == NULL) { + DEBUG ((DEBUG_ERROR, " Allocate pool error\n")); + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + + Status = DiskIo->ReadDisk ( + DiskIo, + MediaId, + MultU64x32 (PartHeader->PartitionEntryLBA, (UINT32)BlockSize), + PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry, + Ptr + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + Status = DiskIo->WriteDisk ( + DiskIo, + MediaId, + MultU64x32 (PEntryLBA, (UINT32)BlockSize), + PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry, + Ptr + ); + +Done: + FreePool (PartHdr); + + if (Ptr != NULL) { + FreePool (Ptr); + } + + if (EFI_ERROR (Status)) { + return FALSE; + } + + return TRUE; +} + +/** + This routine will check GPT partition entry and return entry status. + + Caution: This function may receive untrusted input. + The GPT partition entry is external input, so this routine + will do basic validation for GPT partition entry and report status. + + @param[in] PartHeader Partition table header structure + @param[in] PartEntry The partition entry array + @param[out] PEntryStatus the partition entry status array + recording the status of each partition + +**/ +VOID +PartitionCheckGptEntry ( + IN EFI_PARTITION_TABLE_HEADER *PartHeader, + IN EFI_PARTITION_ENTRY *PartEntry, + OUT EFI_PARTITION_ENTRY_STATUS *PEntryStatus + ) +{ + EFI_LBA StartingLBA; + EFI_LBA EndingLBA; + EFI_PARTITION_ENTRY *Entry; + UINTN Index1; + UINTN Index2; + + DEBUG ((DEBUG_INFO, " start check partition entries\n")); + for (Index1 = 0; Index1 < PartHeader->NumberOfPartitionEntries; Index1++) { + Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartEntry + Index1 * PartHeader->SizeOfPartitionEntry); + if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) { + continue; + } + + StartingLBA = Entry->StartingLBA; + EndingLBA = Entry->EndingLBA; + if ((StartingLBA > EndingLBA) || + (StartingLBA < PartHeader->FirstUsableLBA) || + (StartingLBA > PartHeader->LastUsableLBA) || + (EndingLBA < PartHeader->FirstUsableLBA) || + (EndingLBA > PartHeader->LastUsableLBA) + ) + { + PEntryStatus[Index1].OutOfRange = TRUE; + continue; + } + + if ((Entry->Attributes & BIT1) != 0) { + // + // If Bit 1 is set, this indicate that this is an OS specific GUID partition. + // + PEntryStatus[Index1].OsSpecific = TRUE; + } + + for (Index2 = Index1 + 1; Index2 < PartHeader->NumberOfPartitionEntries; Index2++) { + Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartEntry + Index2 * PartHeader->SizeOfPartitionEntry); + if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) { + continue; + } + + if ((Entry->EndingLBA >= StartingLBA) && (Entry->StartingLBA <= EndingLBA)) { + // + // This region overlaps with the Index1'th region + // + PEntryStatus[Index1].Overlap = TRUE; + PEntryStatus[Index2].Overlap = TRUE; + continue; + } + } + } + + DEBUG ((DEBUG_INFO, " End check partition entries\n")); +} + +/** + Updates the CRC32 value in the table header. + + @param Hdr Table to update + +**/ +STATIC +VOID +PartitionSetCrc ( + IN OUT EFI_TABLE_HEADER *Hdr + ) +{ + PartitionSetCrcAltSize (Hdr->HeaderSize, Hdr); +} + +/** + Updates the CRC32 value in the table header. + + @param Size The size of the table + @param Hdr Table to update + +**/ +STATIC +VOID +PartitionSetCrcAltSize ( + IN UINTN Size, + IN OUT EFI_TABLE_HEADER *Hdr + ) +{ + UINT32 Crc; + + Hdr->CRC32 = 0; + gBS->CalculateCrc32 ((UINT8 *)Hdr, Size, &Crc); + Hdr->CRC32 = Crc; +} + +/** + Checks the CRC32 value in the table header. + + @param MaxSize Max Size limit + @param Hdr Table to check + + @return TRUE CRC Valid + @return FALSE CRC Invalid + +**/ +STATIC +BOOLEAN +PartitionCheckCrc ( + IN UINTN MaxSize, + IN OUT EFI_TABLE_HEADER *Hdr + ) +{ + return PartitionCheckCrcAltSize (MaxSize, Hdr->HeaderSize, Hdr); +} + +/** + Checks the CRC32 value in the table header. + + @param MaxSize Max Size limit + @param Size The size of the table + @param Hdr Table to check + + @return TRUE CRC Valid + @return FALSE CRC Invalid + +**/ +STATIC +BOOLEAN +PartitionCheckCrcAltSize ( + IN UINTN MaxSize, + IN UINTN Size, + IN OUT EFI_TABLE_HEADER *Hdr + ) +{ + UINT32 Crc; + UINT32 OrgCrc; + EFI_STATUS Status; + + Crc = 0; + + if (Size == 0) { + // + // If header size is 0 CRC will pass so return FALSE here + // + return FALSE; + } + + if ((MaxSize != 0) && (Size > MaxSize)) { + DEBUG ((DEBUG_ERROR, "CheckCrc32: Size > MaxSize\n")); + return FALSE; + } + + // + // clear old crc from header + // + OrgCrc = Hdr->CRC32; + Hdr->CRC32 = 0; + + Status = gBS->CalculateCrc32 ((UINT8 *)Hdr, Size, &Crc); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "CheckCrc32: Crc calculation failed\n")); + return FALSE; + } + + // + // set results + // + Hdr->CRC32 = Crc; + + // + // return status + // + DEBUG_CODE_BEGIN (); + if (OrgCrc != Crc) { + DEBUG ((DEBUG_ERROR, "CheckCrc32: Crc check failed\n")); + } + + DEBUG_CODE_END (); + + return (BOOLEAN)(OrgCrc == Crc); +} diff --git a/MdeModulePkg/Library/GptLib/GptLib.inf b/MdeModulePkg/Library/GptLib/GptLib.inf new file mode 100644 index 0000000000..f110ee875a --- /dev/null +++ b/MdeModulePkg/Library/GptLib/GptLib.inf @@ -0,0 +1,49 @@ +## @file +# Shared GUID Partition Table (GPT) parsing and validation library. +# +# Provides the GPT table parsing, validation and restore routines that are +# shared between the Partition driver and other consumers that must parse the +# same on-disk GPT layout. +# +# Caution: This library requires additional review when modified. +# This library will have external input - disk partition. +# This external input must be validated carefully to avoid security issue like +# buffer overflow, integer overflow. +# +# Copyright (c) 2026, SUSE LLC. All rights reserved.<BR> +# Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. +# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR> +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = GptLib + FILE_GUID = E228F30C-C7D5-4A93-BBA7-B4E22327E289 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = GptLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 EBC AARCH64 RISCV64 LOONGARCH64 +# + +[Sources] + Gpt.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + UefiBootServicesTableLib + +[Guids] + gEfiPartTypeUnusedGuid ## SOMETIMES_CONSUMES ## GUID diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index fac0f8ebed..c817a32b81 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -32,6 +32,9 @@ Core/PrivateInclude [LibraryClasses] + ## @libraryclass Provides GPT partition table parsing and validation routines. + GptLib|Include/Library/GptLib.h + ## @libraryclass Defines a set of methods to reset whole system. ResetSystemLib|Include/Library/ResetSystemLib.h diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index b758fa940b..177703211d 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -46,6 +46,7 @@ PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf # # UEFI & PI # @@ -215,6 +216,7 @@ MdeModulePkg/Logo/Logo.inf MdeModulePkg/Logo/LogoDxe.inf MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf + MdeModulePkg/Library/GptLib/GptLib.inf MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.inf MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c index 5bcf94d587..d74880038d 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c @@ -1,6 +1,5 @@ /** @file - Decode a hard disk partitioned with the GPT scheme in the UEFI 2.0 - specification. + Install GPT partition child handles for the Partition driver. Caution: This file requires additional review when modified. This driver will have external input - disk partition. @@ -8,10 +7,9 @@ buffer overflow, integer overflow. PartitionInstallGptChildHandles() routine will read disk partition content and - do basic validation before PartitionInstallChildHandle(). - - PartitionValidGptTable(), PartitionCheckGptEntry() routine will accept disk - partition content and validate the GPT table and GPT entry. + do basic validation before PartitionInstallChildHandle(). The GPT table + parsing and validation helpers it relies on live in the shared GPT parser + (GptLib/Gpt.c). Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR> @@ -21,146 +19,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "Partition.h" -/** - Install child handles if the Handle supports GPT partition structure. - - Caution: This function may receive untrusted input. - The GPT partition table header is external input, so this routine - will do basic validation for GPT partition table header before return. - - @param[in] BlockIo Parent BlockIo interface. - @param[in] DiskIo Disk Io protocol. - @param[in] Lba The starting Lba of the Partition Table - @param[out] PartHeader Stores the partition table that is read - - @retval TRUE The partition table is valid - @retval FALSE The partition table is not valid - -**/ -BOOLEAN -PartitionValidGptTable ( - IN EFI_BLOCK_IO_PROTOCOL *BlockIo, - IN EFI_DISK_IO_PROTOCOL *DiskIo, - IN EFI_LBA Lba, - OUT EFI_PARTITION_TABLE_HEADER *PartHeader - ); - -/** - Check if the CRC field in the Partition table header is valid - for Partition entry array. - - @param[in] BlockIo Parent BlockIo interface - @param[in] DiskIo Disk Io Protocol. - @param[in] PartHeader Partition table header structure - - @retval TRUE the CRC is valid - @retval FALSE the CRC is invalid - -**/ -BOOLEAN -PartitionCheckGptEntryArrayCRC ( - IN EFI_BLOCK_IO_PROTOCOL *BlockIo, - IN EFI_DISK_IO_PROTOCOL *DiskIo, - IN EFI_PARTITION_TABLE_HEADER *PartHeader - ); - -/** - Restore Partition Table to its alternate place - (Primary -> Backup or Backup -> Primary). - - @param[in] BlockIo Parent BlockIo interface. - @param[in] DiskIo Disk Io Protocol. - @param[in] PartHeader Partition table header structure. - - @retval TRUE Restoring succeeds - @retval FALSE Restoring failed - -**/ -BOOLEAN -PartitionRestoreGptTable ( - IN EFI_BLOCK_IO_PROTOCOL *BlockIo, - IN EFI_DISK_IO_PROTOCOL *DiskIo, - IN EFI_PARTITION_TABLE_HEADER *PartHeader - ); - -/** - This routine will check GPT partition entry and return entry status. - - Caution: This function may receive untrusted input. - The GPT partition entry is external input, so this routine - will do basic validation for GPT partition entry and report status. - - @param[in] PartHeader Partition table header structure - @param[in] PartEntry The partition entry array - @param[out] PEntryStatus the partition entry status array - recording the status of each partition - -**/ -VOID -PartitionCheckGptEntry ( - IN EFI_PARTITION_TABLE_HEADER *PartHeader, - IN EFI_PARTITION_ENTRY *PartEntry, - OUT EFI_PARTITION_ENTRY_STATUS *PEntryStatus - ); - -/** - Checks the CRC32 value in the table header. - - @param MaxSize Max Size limit - @param Size The size of the table - @param Hdr Table to check - - @return TRUE CRC Valid - @return FALSE CRC Invalid - -**/ -BOOLEAN -PartitionCheckCrcAltSize ( - IN UINTN MaxSize, - IN UINTN Size, - IN OUT EFI_TABLE_HEADER *Hdr - ); - -/** - Checks the CRC32 value in the table header. - - @param MaxSize Max Size limit - @param Hdr Table to check - - @return TRUE CRC Valid - @return FALSE CRC Invalid - -**/ -BOOLEAN -PartitionCheckCrc ( - IN UINTN MaxSize, - IN OUT EFI_TABLE_HEADER *Hdr - ); - -/** - Updates the CRC32 value in the table header. - - @param Size The size of the table - @param Hdr Table to update - -**/ -VOID -PartitionSetCrcAltSize ( - IN UINTN Size, - IN OUT EFI_TABLE_HEADER *Hdr - ); - -/** - Updates the CRC32 value in the table header. - - @param Hdr Table to update - -**/ -VOID -PartitionSetCrc ( - IN OUT EFI_TABLE_HEADER *Hdr - ); - /** Install child handles if the Handle supports GPT partition structure. @@ -446,438 +304,3 @@ Done: return GptValidStatus; } - -/** - This routine will read GPT partition table header and return it. - - Caution: This function may receive untrusted input. - The GPT partition table header is external input, so this routine - will do basic validation for GPT partition table header before return. - - @param[in] BlockIo Parent BlockIo interface. - @param[in] DiskIo Disk Io protocol. - @param[in] Lba The starting Lba of the Partition Table - @param[out] PartHeader Stores the partition table that is read - - @retval TRUE The partition table is valid - @retval FALSE The partition table is not valid - -**/ -BOOLEAN -PartitionValidGptTable ( - IN EFI_BLOCK_IO_PROTOCOL *BlockIo, - IN EFI_DISK_IO_PROTOCOL *DiskIo, - IN EFI_LBA Lba, - OUT EFI_PARTITION_TABLE_HEADER *PartHeader - ) -{ - EFI_STATUS Status; - UINT32 BlockSize; - EFI_PARTITION_TABLE_HEADER *PartHdr; - UINT32 MediaId; - - BlockSize = BlockIo->Media->BlockSize; - MediaId = BlockIo->Media->MediaId; - PartHdr = AllocateZeroPool (BlockSize); - - if (PartHdr == NULL) { - DEBUG ((DEBUG_ERROR, "Allocate pool error\n")); - return FALSE; - } - - // - // Read the EFI Partition Table Header - // - Status = DiskIo->ReadDisk ( - DiskIo, - MediaId, - MultU64x32 (Lba, BlockSize), - BlockSize, - PartHdr - ); - if (EFI_ERROR (Status)) { - FreePool (PartHdr); - return FALSE; - } - - if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) || - !PartitionCheckCrc (BlockSize, &PartHdr->Header) || - (PartHdr->MyLBA != Lba) || - (PartHdr->SizeOfPartitionEntry < sizeof (EFI_PARTITION_ENTRY)) - ) - { - DEBUG ((DEBUG_INFO, "Invalid efi partition table header\n")); - FreePool (PartHdr); - return FALSE; - } - - // - // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow. - // - if (PartHdr->NumberOfPartitionEntries > DivU64x32 (MAX_UINTN, PartHdr->SizeOfPartitionEntry)) { - FreePool (PartHdr); - return FALSE; - } - - CopyMem (PartHeader, PartHdr, sizeof (EFI_PARTITION_TABLE_HEADER)); - if (!PartitionCheckGptEntryArrayCRC (BlockIo, DiskIo, PartHeader)) { - FreePool (PartHdr); - return FALSE; - } - - DEBUG ((DEBUG_INFO, " Valid efi partition table header\n")); - FreePool (PartHdr); - return TRUE; -} - -/** - Check if the CRC field in the Partition table header is valid - for Partition entry array. - - @param[in] BlockIo Parent BlockIo interface - @param[in] DiskIo Disk Io Protocol. - @param[in] PartHeader Partition table header structure - - @retval TRUE the CRC is valid - @retval FALSE the CRC is invalid - -**/ -BOOLEAN -PartitionCheckGptEntryArrayCRC ( - IN EFI_BLOCK_IO_PROTOCOL *BlockIo, - IN EFI_DISK_IO_PROTOCOL *DiskIo, - IN EFI_PARTITION_TABLE_HEADER *PartHeader - ) -{ - EFI_STATUS Status; - UINT8 *Ptr; - UINT32 Crc; - UINTN Size; - - // - // Read the EFI Partition Entries - // - Ptr = AllocatePool (PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry); - if (Ptr == NULL) { - DEBUG ((DEBUG_ERROR, " Allocate pool error\n")); - return FALSE; - } - - Status = DiskIo->ReadDisk ( - DiskIo, - BlockIo->Media->MediaId, - MultU64x32 (PartHeader->PartitionEntryLBA, BlockIo->Media->BlockSize), - PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry, - Ptr - ); - if (EFI_ERROR (Status)) { - FreePool (Ptr); - return FALSE; - } - - Size = PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry; - - Status = gBS->CalculateCrc32 (Ptr, Size, &Crc); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "CheckPEntryArrayCRC: Crc calculation failed\n")); - FreePool (Ptr); - return FALSE; - } - - FreePool (Ptr); - - return (BOOLEAN)(PartHeader->PartitionEntryArrayCRC32 == Crc); -} - -/** - Restore Partition Table to its alternate place - (Primary -> Backup or Backup -> Primary). - - @param[in] BlockIo Parent BlockIo interface. - @param[in] DiskIo Disk Io Protocol. - @param[in] PartHeader Partition table header structure. - - @retval TRUE Restoring succeeds - @retval FALSE Restoring failed - -**/ -BOOLEAN -PartitionRestoreGptTable ( - IN EFI_BLOCK_IO_PROTOCOL *BlockIo, - IN EFI_DISK_IO_PROTOCOL *DiskIo, - IN EFI_PARTITION_TABLE_HEADER *PartHeader - ) -{ - EFI_STATUS Status; - UINTN BlockSize; - EFI_PARTITION_TABLE_HEADER *PartHdr; - EFI_LBA PEntryLBA; - UINT8 *Ptr; - UINT32 MediaId; - - PartHdr = NULL; - Ptr = NULL; - - BlockSize = BlockIo->Media->BlockSize; - MediaId = BlockIo->Media->MediaId; - - PartHdr = AllocateZeroPool (BlockSize); - - if (PartHdr == NULL) { - DEBUG ((DEBUG_ERROR, "Allocate pool error\n")); - return FALSE; - } - - PEntryLBA = (PartHeader->MyLBA == PRIMARY_PART_HEADER_LBA) ? \ - (PartHeader->LastUsableLBA + 1) : \ - (PRIMARY_PART_HEADER_LBA + 1); - - CopyMem (PartHdr, PartHeader, sizeof (EFI_PARTITION_TABLE_HEADER)); - - PartHdr->MyLBA = PartHeader->AlternateLBA; - PartHdr->AlternateLBA = PartHeader->MyLBA; - PartHdr->PartitionEntryLBA = PEntryLBA; - PartitionSetCrc ((EFI_TABLE_HEADER *)PartHdr); - - Status = DiskIo->WriteDisk ( - DiskIo, - MediaId, - MultU64x32 (PartHdr->MyLBA, (UINT32)BlockSize), - BlockSize, - PartHdr - ); - if (EFI_ERROR (Status)) { - goto Done; - } - - Ptr = AllocatePool (PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry); - if (Ptr == NULL) { - DEBUG ((DEBUG_ERROR, " Allocate pool error\n")); - Status = EFI_OUT_OF_RESOURCES; - goto Done; - } - - Status = DiskIo->ReadDisk ( - DiskIo, - MediaId, - MultU64x32 (PartHeader->PartitionEntryLBA, (UINT32)BlockSize), - PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry, - Ptr - ); - if (EFI_ERROR (Status)) { - goto Done; - } - - Status = DiskIo->WriteDisk ( - DiskIo, - MediaId, - MultU64x32 (PEntryLBA, (UINT32)BlockSize), - PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry, - Ptr - ); - -Done: - FreePool (PartHdr); - - if (Ptr != NULL) { - FreePool (Ptr); - } - - if (EFI_ERROR (Status)) { - return FALSE; - } - - return TRUE; -} - -/** - This routine will check GPT partition entry and return entry status. - - Caution: This function may receive untrusted input. - The GPT partition entry is external input, so this routine - will do basic validation for GPT partition entry and report status. - - @param[in] PartHeader Partition table header structure - @param[in] PartEntry The partition entry array - @param[out] PEntryStatus the partition entry status array - recording the status of each partition - -**/ -VOID -PartitionCheckGptEntry ( - IN EFI_PARTITION_TABLE_HEADER *PartHeader, - IN EFI_PARTITION_ENTRY *PartEntry, - OUT EFI_PARTITION_ENTRY_STATUS *PEntryStatus - ) -{ - EFI_LBA StartingLBA; - EFI_LBA EndingLBA; - EFI_PARTITION_ENTRY *Entry; - UINTN Index1; - UINTN Index2; - - DEBUG ((DEBUG_INFO, " start check partition entries\n")); - for (Index1 = 0; Index1 < PartHeader->NumberOfPartitionEntries; Index1++) { - Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartEntry + Index1 * PartHeader->SizeOfPartitionEntry); - if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) { - continue; - } - - StartingLBA = Entry->StartingLBA; - EndingLBA = Entry->EndingLBA; - if ((StartingLBA > EndingLBA) || - (StartingLBA < PartHeader->FirstUsableLBA) || - (StartingLBA > PartHeader->LastUsableLBA) || - (EndingLBA < PartHeader->FirstUsableLBA) || - (EndingLBA > PartHeader->LastUsableLBA) - ) - { - PEntryStatus[Index1].OutOfRange = TRUE; - continue; - } - - if ((Entry->Attributes & BIT1) != 0) { - // - // If Bit 1 is set, this indicate that this is an OS specific GUID partition. - // - PEntryStatus[Index1].OsSpecific = TRUE; - } - - for (Index2 = Index1 + 1; Index2 < PartHeader->NumberOfPartitionEntries; Index2++) { - Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartEntry + Index2 * PartHeader->SizeOfPartitionEntry); - if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) { - continue; - } - - if ((Entry->EndingLBA >= StartingLBA) && (Entry->StartingLBA <= EndingLBA)) { - // - // This region overlaps with the Index1'th region - // - PEntryStatus[Index1].Overlap = TRUE; - PEntryStatus[Index2].Overlap = TRUE; - continue; - } - } - } - - DEBUG ((DEBUG_INFO, " End check partition entries\n")); -} - -/** - Updates the CRC32 value in the table header. - - @param Hdr Table to update - -**/ -VOID -PartitionSetCrc ( - IN OUT EFI_TABLE_HEADER *Hdr - ) -{ - PartitionSetCrcAltSize (Hdr->HeaderSize, Hdr); -} - -/** - Updates the CRC32 value in the table header. - - @param Size The size of the table - @param Hdr Table to update - -**/ -VOID -PartitionSetCrcAltSize ( - IN UINTN Size, - IN OUT EFI_TABLE_HEADER *Hdr - ) -{ - UINT32 Crc; - - Hdr->CRC32 = 0; - gBS->CalculateCrc32 ((UINT8 *)Hdr, Size, &Crc); - Hdr->CRC32 = Crc; -} - -/** - Checks the CRC32 value in the table header. - - @param MaxSize Max Size limit - @param Hdr Table to check - - @return TRUE CRC Valid - @return FALSE CRC Invalid - -**/ -BOOLEAN -PartitionCheckCrc ( - IN UINTN MaxSize, - IN OUT EFI_TABLE_HEADER *Hdr - ) -{ - return PartitionCheckCrcAltSize (MaxSize, Hdr->HeaderSize, Hdr); -} - -/** - Checks the CRC32 value in the table header. - - @param MaxSize Max Size limit - @param Size The size of the table - @param Hdr Table to check - - @return TRUE CRC Valid - @return FALSE CRC Invalid - -**/ -BOOLEAN -PartitionCheckCrcAltSize ( - IN UINTN MaxSize, - IN UINTN Size, - IN OUT EFI_TABLE_HEADER *Hdr - ) -{ - UINT32 Crc; - UINT32 OrgCrc; - EFI_STATUS Status; - - Crc = 0; - - if (Size == 0) { - // - // If header size is 0 CRC will pass so return FALSE here - // - return FALSE; - } - - if ((MaxSize != 0) && (Size > MaxSize)) { - DEBUG ((DEBUG_ERROR, "CheckCrc32: Size > MaxSize\n")); - return FALSE; - } - - // - // clear old crc from header - // - OrgCrc = Hdr->CRC32; - Hdr->CRC32 = 0; - - Status = gBS->CalculateCrc32 ((UINT8 *)Hdr, Size, &Crc); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "CheckCrc32: Crc calculation failed\n")); - return FALSE; - } - - // - // set results - // - Hdr->CRC32 = Crc; - - // - // return status - // - DEBUG_CODE_BEGIN (); - if (OrgCrc != Crc) { - DEBUG ((DEBUG_ERROR, "CheckCrc32: Crc check failed\n")); - } - - DEBUG_CODE_END (); - - return (BOOLEAN)(OrgCrc == Crc); -} diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h index 8deafbe313..8c598d0bc1 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h @@ -31,6 +31,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/UefiBootServicesTableLib.h> #include <Library/DevicePathLib.h> +#include <Library/GptLib.h> + #include <IndustryStandard/Mbr.h> #include <IndustryStandard/ElTorito.h> #include <IndustryStandard/Udf.h> @@ -93,15 +95,6 @@ extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2; (((UINT8 *) a)[2] << 16) | \ (((UINT8 *) a)[3] << 24) ) -// -// GPT Partition Entry Status -// -typedef struct { - BOOLEAN OutOfRange; - BOOLEAN Overlap; - BOOLEAN OsSpecific; -} EFI_PARTITION_ENTRY_STATUS; - // // Function Prototypes // diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf b/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf index 14ab6ae198..6450941af8 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf @@ -47,10 +47,12 @@ [Packages] MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec [LibraryClasses] DevicePathLib + GptLib UefiBootServicesTableLib MemoryAllocationLib BaseMemoryLib From 7c12d4359abd47901f3aa9e1e8bb11c2aed8155e Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Thu, 25 Jun 2026 14:54:20 +0800 Subject: [PATCH 239/406] SecurityPkg/DxeTpm2MeasureBootLib: Use GptLib parser The previous commit introduced GptLib by extracting PartitionDxe's GPT parsing and validation code. It provides a shared implementation for edk2 components that need to parse and validate GPT data consistently. Update DxeTpm2MeasureBootLib to use GptLib when selecting on-disk GPT data for measurement. Validate the current primary GPT or, when it is invalid, validate the backup and the header at its AlternateLBA. Do not extend PCR[5] if no valid header can be selected. The measurement therefore uses GPT data read from disk at measurement time and applies the shared parser and validation logic. Ref: https://seclists.org/oss-sec/2026/q2/727 Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- .../DxeTpm2MeasureBootLib.c | 58 ++++++++++++++----- .../DxeTpm2MeasureBootLib.inf | 1 + SecurityPkg/SecurityPkg.dsc | 1 + 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c index 9f2eb57e75..dd5c59d107 100644 --- a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c +++ b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c @@ -44,6 +44,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/PeCoffLib.h> #include <Library/SecurityManagementLib.h> #include <Library/HobLib.h> +#include <Library/GptLib.h> #include <Protocol/CcMeasurement.h> #include "DxeTpm2MeasureBootLibSanitization.h" @@ -140,6 +141,7 @@ Tcg2MeasureGptTable ( EFI_BLOCK_IO_PROTOCOL *BlockIo; EFI_DISK_IO_PROTOCOL *DiskIo; EFI_PARTITION_TABLE_HEADER *PrimaryHeader; + EFI_PARTITION_TABLE_HEADER *BackupHeader; EFI_PARTITION_ENTRY *PartitionEntry; UINT8 *EntryPtr; UINTN NumberOfPartition; @@ -159,6 +161,7 @@ Tcg2MeasureGptTable ( } PrimaryHeader = NULL; + BackupHeader = NULL; EntryPtr = NULL; EventPtr = NULL; @@ -186,24 +189,45 @@ Tcg2MeasureGptTable ( } // - // Read the EFI Partition Table Header + // Obtain the GPT partition table header that the platform actually parses + // and uses, applying the same strict validation (including the header CRC32 + // and the partition-entry-array CRC32) as the PartitionDxe driver, via the + // shared GptLib parser. Previously this code read LBA 1 directly and + // validated it with a relaxed, CRC-less check, which allowed the table + // measured into PCR[5] to differ from the table the driver actually used + // (CVE-2024-13745). // - PrimaryHeader = (EFI_PARTITION_TABLE_HEADER *)AllocatePool (BlockIo->Media->BlockSize); + PrimaryHeader = (EFI_PARTITION_TABLE_HEADER *)AllocatePool (sizeof (EFI_PARTITION_TABLE_HEADER)); if (PrimaryHeader == NULL) { return EFI_OUT_OF_RESOURCES; } - Status = DiskIo->ReadDisk ( - DiskIo, - BlockIo->Media->MediaId, - 1 * BlockIo->Media->BlockSize, - BlockIo->Media->BlockSize, - (UINT8 *)PrimaryHeader - ); - if (EFI_ERROR (Status) || EFI_ERROR (Tpm2SanitizeEfiPartitionTableHeader (PrimaryHeader, BlockIo))) { - DEBUG ((DEBUG_ERROR, "Failed to read Partition Table Header or invalid Partition Table Header!\n")); - FreePool (PrimaryHeader); - return EFI_DEVICE_ERROR; + if (!PartitionValidGptTable (BlockIo, DiskIo, PRIMARY_PART_HEADER_LBA, PrimaryHeader)) { + // + // The primary GPT header is not valid. Mirror the driver's recovery + // selection: when a valid backup header exists, the driver restores and + // then uses the header located at the backup's AlternateLBA. Validate and + // use that same header (read-only) so the measured table matches the used + // one. If neither the primary nor the backup table is valid, fail closed + // and measure nothing. + // + BackupHeader = (EFI_PARTITION_TABLE_HEADER *)AllocatePool (sizeof (EFI_PARTITION_TABLE_HEADER)); + if (BackupHeader == NULL) { + FreePool (PrimaryHeader); + return EFI_OUT_OF_RESOURCES; + } + + if (!PartitionValidGptTable (BlockIo, DiskIo, BlockIo->Media->LastBlock, BackupHeader) || + !PartitionValidGptTable (BlockIo, DiskIo, BackupHeader->AlternateLBA, PrimaryHeader)) + { + DEBUG ((DEBUG_ERROR, "Failed to obtain a valid GPT partition table header to measure!\n")); + FreePool (BackupHeader); + FreePool (PrimaryHeader); + return EFI_DEVICE_ERROR; + } + + FreePool (BackupHeader); + BackupHeader = NULL; } // @@ -237,6 +261,14 @@ Tcg2MeasureGptTable ( // // Count the valid partition // + // Empty entries (zero PartitionTypeGUID) are intentionally not measured + // individually. Their content is already fully covered by the + // partition-entry-array CRC32, which PartitionValidGptTable() verified above + // before any data was measured. Any tampering with an empty entry therefore + // changes that CRC32 and makes the primary GPT validation fail (causing a + // fall back to the backup, or a fail-closed with no PCR[5] extend), so + // re-measuring the all-zero entries would add no additional protection. + // PartitionEntry = (EFI_PARTITION_ENTRY *)EntryPtr; NumberOfPartition = 0; for (Index = 0; Index < PrimaryHeader->NumberOfPartitionEntries; Index++) { diff --git a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf index 78c8c32c29..4d7b44c3be 100644 --- a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf +++ b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf @@ -58,6 +58,7 @@ BaseLib SecurityManagementLib HobLib + GptLib [Guids] gMeasuredFvHobGuid ## SOMETIMES_CONSUMES ## HOB diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 34b20b4cf6..9d4fab48eb 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -47,6 +47,7 @@ OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf TpmCommLib|SecurityPkg/Library/TpmCommLib/TpmCommLib.inf From 2b27f795ec11e8de70fc284732656f19e50d0a32 Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Wed, 1 Jul 2026 11:15:17 +0800 Subject: [PATCH 240/406] ArmVirtPkg: Resolve GptLib library class GptLib is a new library class consumed both by PartitionDxe (built by essentially every platform) and by DxeTpm2MeasureBootLib. Any platform DSC that builds either module must resolve the GptLib library class, otherwise the build fails with "Instance of library class [GptLib] is not found". Resolve GptLib once in ArmVirtPkg/ArmVirt.dsc.inc for the whole ArmVirt family, whose platforms build PartitionDxe and, for ArmVirtQemu, link DxeTpm2MeasureBootLib. Out-of-tree platforms consuming either module need the same one-line resolution. Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- ArmVirtPkg/ArmVirt.dsc.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index f63181beab..b8c0cb5891 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -51,6 +51,7 @@ DEFINE FD_SIZE_IN_MB = 3 CLANGPDB:*_*_*_DLINK_FLAGS = /ALIGN:0x10000 [LibraryClasses.common] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf !if $(TARGET) == RELEASE DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf !else From 78c5050bb2480c87d810119205e6440a66a9189f Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Wed, 1 Jul 2026 11:15:17 +0800 Subject: [PATCH 241/406] EmulatorPkg: Resolve GptLib library class GptLib is a new library class consumed both by PartitionDxe (built by essentially every platform) and by DxeTpm2MeasureBootLib. Any platform DSC that builds either module must resolve the GptLib library class, otherwise the build fails with "Instance of library class [GptLib] is not found". Resolve GptLib in EmulatorPkg/EmulatorPkg.dsc, which builds PartitionDxe. Out-of-tree platforms consuming either module need the same one-line resolution. Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- EmulatorPkg/EmulatorPkg.dsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc index d6e71b310b..e554f54245 100644 --- a/EmulatorPkg/EmulatorPkg.dsc +++ b/EmulatorPkg/EmulatorPkg.dsc @@ -71,6 +71,8 @@ !endif [LibraryClasses] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf + # # Entry point # From cb6dcca33737a736382279fda931c5cc4a3dc03d Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Wed, 1 Jul 2026 11:15:17 +0800 Subject: [PATCH 242/406] OvmfPkg: Resolve GptLib library class GptLib is a new library class consumed both by PartitionDxe (built by essentially every platform) and by DxeTpm2MeasureBootLib. Any platform DSC that builds either module must resolve the GptLib library class, otherwise the build fails with "Instance of library class [GptLib] is not found". Resolve GptLib in each OVMF DSC. Every OVMF DSC builds PartitionDxe. IntelTdx, LoongArchVirt and RiscVVirt additionally link DxeTpm2MeasureBootLib directly; AmdSev, Bhyve, CloudHv, Microvm, OvmfPkgX64 and OvmfPkgIa32X64 pull it in through OvmfTpmSecurityStub.dsc.inc. Out-of-tree platforms consuming either module need the same one-line resolution. Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/Bhyve/BhyveX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 + OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc | 1 + OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 1 + 10 files changed, 10 insertions(+) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 4f9dc1ee06..2fbcd01ce4 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -109,6 +109,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index 1bbf65ed71..2b00d0db79 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -125,6 +125,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLibBhyve.inf diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index d4e2ad5e28..e64548d9e1 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -130,6 +130,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc index 3062fac11d..4717d0c79d 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -111,6 +111,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc index 7b49e53d65..15bb9a856a 100644 --- a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc +++ b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc @@ -98,6 +98,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses.common] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf PcdLib | MdePkg/Library/DxePcdLib/DxePcdLib.inf TimerLib | UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf PrintLib | MdePkg/Library/BasePrintLib/BasePrintLib.inf diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index ebe0a0f04c..0211e960f6 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -131,6 +131,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index d546c3c9ac..d981cc8c47 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -136,6 +136,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index d4a452c7e4..a12ea98bb7 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -150,6 +150,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf SmmRelocationLib|OvmfPkg/Library/SmmRelocationLib/SmmRelocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index e3fc52f8c4..ad1c0594ea 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -123,6 +123,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc index 828793f588..09dd86f1a7 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc @@ -102,6 +102,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses.common] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf PlatformSecLib|OvmfPkg/RiscVVirt/Library/PlatformSecLib/PlatformSecLib.inf # Virtio Support From 18407299295f14ea57b8aaa042a750757dfc2151 Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Wed, 1 Jul 2026 11:15:17 +0800 Subject: [PATCH 243/406] UefiPayloadPkg: Resolve GptLib library class GptLib is a new library class consumed both by PartitionDxe (built by essentially every platform) and by DxeTpm2MeasureBootLib. Any platform DSC that builds either module must resolve the GptLib library class, otherwise the build fails with "Instance of library class [GptLib] is not found". Resolve GptLib in UefiPayloadPkg/UefiPayloadPkg.dsc, which builds PartitionDxe. Out-of-tree platforms consuming either module need the same one-line resolution. Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- UefiPayloadPkg/UefiPayloadPkg.dsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index 5e228ba04a..34fb690d17 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -225,6 +225,8 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses] + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf + # # Entry point # From 45732edfffcabd8a96d396029e7269875da05407 Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Tue, 30 Jun 2026 16:11:36 +0800 Subject: [PATCH 244/406] MdeModulePkg/GptLib: Validate GPT header fields before use PartitionValidGptTable() checked the signature, header CRC32, MyLBA, the entry-array CRC32 and the entry-array size overflow, but not several other UEFI-mandated GPT header constraints. DxeTpm2MeasureBootLib used to enforce these via Tpm2SanitizeEfiPartitionTableHeader(); once it switched to this shared parser, the checks were lost on the path. Also reject a header unless Header.Revision is GPT_HEADER_REVISION_V1, HeaderSize is at least the 92-byte minimum, NumberOfPartitionEntries is non-zero, SizeOfPartitionEntry is 128 * 2^n, and PartitionEntryLBA * BlockSize cannot overflow. The "entries lie before FirstUsableLBA" rule is intentionally omitted, as this routine also validates the backup header whose entry array follows the usable region. This restores the validation the measurement path lost and, because GptLib is shared, tightens PartitionDxe the same way: malformed headers are now rejected and the parse and measure paths stay identical. Ref: https://seclists.org/oss-sec/2026/q2/727 Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- MdeModulePkg/Library/GptLib/Gpt.c | 34 ++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Library/GptLib/Gpt.c b/MdeModulePkg/Library/GptLib/Gpt.c index e62a2299f5..e83e9806ef 100644 --- a/MdeModulePkg/Library/GptLib/Gpt.c +++ b/MdeModulePkg/Library/GptLib/Gpt.c @@ -25,6 +25,19 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/UefiBootServicesTableLib.h> #include <Library/GptLib.h> +// +// The only GPT header revision defined by the UEFI specification. +// +#define GPT_HEADER_REVISION_V1 0x00010000 + +// +// Minimum on-disk GPT header size: large enough to cover every defined field +// through PartitionEntryArrayCRC32 (92 bytes). sizeof (EFI_PARTITION_TABLE_HEADER) +// cannot be used because the C structure is padded to an 8-byte boundary. +// +#define GPT_HEADER_MIN_SIZE (OFFSET_OF (EFI_PARTITION_TABLE_HEADER, PartitionEntryArrayCRC32) + \ + sizeof (((EFI_PARTITION_TABLE_HEADER *)0)->PartitionEntryArrayCRC32)) + /** Check if the CRC field in the Partition table header is valid for Partition entry array. @@ -160,10 +173,21 @@ PartitionValidGptTable ( return FALSE; } + // + // Validate the header fields against the constraints the UEFI specification + // places on a GPT header. SizeOfPartitionEntry must be 128 * 2^n. Note this + // routine validates both the primary and the backup header, so it must not + // assume the entry array sits before FirstUsableLBA: that holds for the + // primary but not for the backup, whose array follows the usable region. + // if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) || + (PartHdr->Header.Revision != GPT_HEADER_REVISION_V1) || + (PartHdr->Header.HeaderSize < GPT_HEADER_MIN_SIZE) || !PartitionCheckCrc (BlockSize, &PartHdr->Header) || (PartHdr->MyLBA != Lba) || - (PartHdr->SizeOfPartitionEntry < sizeof (EFI_PARTITION_ENTRY)) + (PartHdr->NumberOfPartitionEntries == 0) || + (PartHdr->SizeOfPartitionEntry < sizeof (EFI_PARTITION_ENTRY)) || + ((PartHdr->SizeOfPartitionEntry & (PartHdr->SizeOfPartitionEntry - 1)) != 0) ) { DEBUG ((DEBUG_INFO, "Invalid efi partition table header\n")); @@ -172,9 +196,13 @@ PartitionValidGptTable ( } // - // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow. + // Ensure PartitionEntryLBA * BlockSize and + // NumberOfPartitionEntries * SizeOfPartitionEntry don't overflow when they + // are later used to read and size the partition entry array. // - if (PartHdr->NumberOfPartitionEntries > DivU64x32 (MAX_UINTN, PartHdr->SizeOfPartitionEntry)) { + if ((PartHdr->PartitionEntryLBA > DivU64x32 (MAX_UINT64, BlockSize)) || + (PartHdr->NumberOfPartitionEntries > DivU64x32 (MAX_UINTN, PartHdr->SizeOfPartitionEntry))) + { FreePool (PartHdr); return FALSE; } From 070c9026f754b2c0b88445c8638eed0609673ccc Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Thu, 25 Jun 2026 15:07:29 +0800 Subject: [PATCH 245/406] MdeModulePkg/PartitionDxe: Abort on primary GPT recovery failure When the primary GPT is invalid, PartitionInstallGptChildHandles() restores it from the backup and re-validates it. Both the restore write and the re-validation can fail (e.g. write-protected media, or a backup AlternateLBA pointing beyond the device), yet the existing code only logs the failure and parses partitions from a known-invalid PrimaryHeader. Abort GPT processing when either the restore or the validation fails, so partitions are only ever parsed from a validated primary GPT. The backup recovery branch is left unchanged, as the primary is already validated. A device with an unrecoverable primary GPT now installs no child handles instead of using an invalid header. This keeps the table PartitionDxe uses in sync with the one DxeTpm2MeasureBootLib measures into PCR[5]. Ref: https://seclists.org/oss-sec/2026/q2/727 Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- .../Universal/Disk/PartitionDxe/Gpt.c | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c index d74880038d..df033c892a 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c @@ -149,17 +149,28 @@ PartitionInstallGptChildHandles ( if (!PartitionValidGptTable (BlockIo, DiskIo, LastBlock, BackupHeader)) { DEBUG ((DEBUG_INFO, " Not Valid backup partition table\n")); goto Done; - } else { - DEBUG ((DEBUG_INFO, " Valid backup partition table\n")); - DEBUG ((DEBUG_INFO, " Restore primary partition table by the backup\n")); - if (!PartitionRestoreGptTable (BlockIo, DiskIo, BackupHeader)) { - DEBUG ((DEBUG_INFO, " Restore primary partition table error\n")); - } - - if (PartitionValidGptTable (BlockIo, DiskIo, BackupHeader->AlternateLBA, PrimaryHeader)) { - DEBUG ((DEBUG_INFO, " Restore backup partition table success\n")); - } } + + DEBUG ((DEBUG_INFO, " Valid backup partition table\n")); + DEBUG ((DEBUG_INFO, " Restore primary partition table by the backup\n")); + // + // Both the restore write and the subsequent validation can fail (for + // example on write-protected media, or when the backup header's + // AlternateLBA points beyond the end of the device). Never fall through + // with PrimaryHeader left in an unrestored/invalid state; bail out so the + // partition table that gets used is always one that passed validation. + // + if (!PartitionRestoreGptTable (BlockIo, DiskIo, BackupHeader)) { + DEBUG ((DEBUG_INFO, " Restore primary partition table error\n")); + goto Done; + } + + if (!PartitionValidGptTable (BlockIo, DiskIo, BackupHeader->AlternateLBA, PrimaryHeader)) { + DEBUG ((DEBUG_INFO, " Not Valid restored primary partition table\n")); + goto Done; + } + + DEBUG ((DEBUG_INFO, " Restore primary partition table success\n")); } else if (!PartitionValidGptTable (BlockIo, DiskIo, PrimaryHeader->AlternateLBA, BackupHeader)) { DEBUG ((DEBUG_INFO, " Valid primary and !Valid backup partition table\n")); DEBUG ((DEBUG_INFO, " Restore backup partition table by the primary\n")); From b65fd21591230233f53d2cfb22c42d4605054902 Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Wed, 8 Jul 2026 10:17:41 +0800 Subject: [PATCH 246/406] SecurityPkg/DxeTpmMeasureBootLib: Use GptLib parser TcgMeasureGptTable() reads the primary GPT header directly from LBA 1 and validates it with field checks only: no header CRC32, no partition-entry-array CRC32 and no backup fallback. This is the same divergence between the measured and the parsed partition table that CVE-2024-13745 reports against DxeTpm2MeasureBootLib, and the tracking issue lists both libraries as affected. Mirror the DxeTpm2MeasureBootLib fix: select the GPT header to measure via the shared GptLib parser. Validate the current primary GPT or, when it is invalid, validate the backup and the header at its AlternateLBA. Do not extend PCR[5] if no valid header can be selected. Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- .../DxeTpmMeasureBootLib.c | 48 ++++++++++++++----- .../DxeTpmMeasureBootLib.inf | 1 + 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c index 6cb5ff25f5..39e56e4b27 100644 --- a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c +++ b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c @@ -42,6 +42,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/PeCoffLib.h> #include <Library/SecurityManagementLib.h> #include <Library/HobLib.h> +#include <Library/GptLib.h> #include "DxeTpmMeasureBootLibSanitization.h" @@ -132,6 +133,7 @@ TcgMeasureGptTable ( EFI_BLOCK_IO_PROTOCOL *BlockIo; EFI_DISK_IO_PROTOCOL *DiskIo; EFI_PARTITION_TABLE_HEADER *PrimaryHeader; + EFI_PARTITION_TABLE_HEADER *BackupHeader; EFI_PARTITION_ENTRY *PartitionEntry; UINT8 *EntryPtr; UINTN NumberOfPartition; @@ -160,24 +162,44 @@ TcgMeasureGptTable ( } // - // Read the EFI Partition Table Header + // Obtain the GPT partition table header that the platform actually parses + // and uses, applying the same strict validation (including the header CRC32 + // and the partition-entry-array CRC32) as the PartitionDxe driver, via the + // shared GptLib parser. Previously this code read LBA 1 directly and + // validated it with a relaxed, CRC-less check, which allowed the table + // measured into PCR[5] to differ from the table the driver actually used + // (CVE-2024-13745). // - PrimaryHeader = (EFI_PARTITION_TABLE_HEADER *)AllocatePool (BlockIo->Media->BlockSize); + PrimaryHeader = (EFI_PARTITION_TABLE_HEADER *)AllocatePool (sizeof (EFI_PARTITION_TABLE_HEADER)); if (PrimaryHeader == NULL) { return EFI_OUT_OF_RESOURCES; } - Status = DiskIo->ReadDisk ( - DiskIo, - BlockIo->Media->MediaId, - 1 * BlockIo->Media->BlockSize, - BlockIo->Media->BlockSize, - (UINT8 *)PrimaryHeader - ); - if (EFI_ERROR (Status) || EFI_ERROR (TpmSanitizeEfiPartitionTableHeader (PrimaryHeader, BlockIo))) { - DEBUG ((DEBUG_ERROR, "Failed to read Partition Table Header or invalid Partition Table Header!\n")); - FreePool (PrimaryHeader); - return EFI_DEVICE_ERROR; + if (!PartitionValidGptTable (BlockIo, DiskIo, PRIMARY_PART_HEADER_LBA, PrimaryHeader)) { + // + // The primary GPT header is not valid. Mirror the driver's recovery + // selection: when a valid backup header exists, the driver restores and + // then uses the header located at the backup's AlternateLBA. Validate and + // use that same header (read-only) so the measured table matches the used + // one. If neither the primary nor the backup table is valid, fail closed + // and measure nothing. + // + BackupHeader = (EFI_PARTITION_TABLE_HEADER *)AllocatePool (sizeof (EFI_PARTITION_TABLE_HEADER)); + if (BackupHeader == NULL) { + FreePool (PrimaryHeader); + return EFI_OUT_OF_RESOURCES; + } + + if (!PartitionValidGptTable (BlockIo, DiskIo, BlockIo->Media->LastBlock, BackupHeader) || + !PartitionValidGptTable (BlockIo, DiskIo, BackupHeader->AlternateLBA, PrimaryHeader)) + { + DEBUG ((DEBUG_ERROR, "Failed to obtain a valid GPT partition table header to measure!\n")); + FreePool (BackupHeader); + FreePool (PrimaryHeader); + return EFI_DEVICE_ERROR; + } + + FreePool (BackupHeader); } // diff --git a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.inf b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.inf index 414c654d15..c13bd5ea5a 100644 --- a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.inf +++ b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.inf @@ -53,6 +53,7 @@ BaseLib SecurityManagementLib HobLib + GptLib [Guids] gMeasuredFvHobGuid ## SOMETIMES_CONSUMES ## HOB From 77585e50049839856baed37d120d4f705a2cf1d0 Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Tue, 7 Jul 2026 20:42:40 +0800 Subject: [PATCH 247/406] MdeModulePkg/GptLib: Add host-based unit tests for valid GPT behavior Add the positive-path host-based tests for the shared GptLib parser (extracted as part of the parser security hardening), ensuring the tightened checks in PartitionValidGptTable(), PartitionCheckGptEntry() and PartitionRestoreGptTable() do not falsely reject well-formed GPTs. The tests run against an in-memory mock disk and cover accepted primary/backup headers, boundary but legal header/entry sizes, correct entry-status flagging on valid entries, and primary/backup restore round-trips. Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- .../Library/GptLib/UnitTest/GptLibUnitTest.c | 477 ++++++++++++++++++ .../GptLib/UnitTest/GptLibUnitTestCommon.c | 298 +++++++++++ .../GptLib/UnitTest/GptLibUnitTestCommon.h | 110 ++++ .../GptLib/UnitTest/GptLibUnitTestHost.inf | 40 ++ MdeModulePkg/MdeModulePkg.ci.yaml | 1 + MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 5 + 6 files changed, 931 insertions(+) create mode 100644 MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTest.c create mode 100644 MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestCommon.c create mode 100644 MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestCommon.h create mode 100644 MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestHost.inf diff --git a/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTest.c b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTest.c new file mode 100644 index 0000000000..fbc6e3ba46 --- /dev/null +++ b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTest.c @@ -0,0 +1,477 @@ +/** @file + Host-based unit tests for GptLib. + + These tests exercise PartitionValidGptTable(), PartitionCheckGptEntry() + and PartitionRestoreGptTable() against an in-memory mock disk, covering + their behavior on well-formed GPT structures. + + Copyright (c) 2026, SUSE LLC. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/UnitTestLib.h> +#include <Library/GptLib.h> +#include "GptLibUnitTestCommon.h" + +#define UNIT_TEST_NAME "GptLibUnitTest" +#define UNIT_TEST_VERSION "1.0" + +// --------------------------------------------------------------------------- +// PartitionValidGptTable() tests +// --------------------------------------------------------------------------- + +/** + Verify that a well-formed primary GPT header is accepted. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestValidPrimaryHeaderIsAccepted ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + UT_ASSERT_TRUE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + UT_ASSERT_EQUAL (Header.MyLBA, PRIMARY_PART_HEADER_LBA); + UT_ASSERT_EQUAL (Header.AlternateLBA, LAST_LBA); + UT_ASSERT_EQUAL (Header.NumberOfPartitionEntries, NUM_PARTITION_ENTRIES); + UT_ASSERT_EQUAL (Header.SizeOfPartitionEntry, PARTITION_ENTRY_SIZE); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a well-formed backup GPT header is accepted. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestValidBackupHeaderIsAccepted ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + // + // Backup header at the last LBA with its entry array after the usable + // region, as laid out by real partitioning tools. The validator must not + // reject an entry array located past FirstUsableLBA. + // + WriteGptTableAt ( + LAST_LBA, + PRIMARY_PART_HEADER_LBA, + LAST_USABLE_LBA + 1, + NUM_PARTITION_ENTRIES, + PARTITION_ENTRY_SIZE, + 2 + ); + + UT_ASSERT_TRUE (ValidateAt (LAST_LBA, &Header)); + UT_ASSERT_EQUAL (Header.MyLBA, LAST_LBA); + UT_ASSERT_EQUAL (Header.AlternateLBA, PRIMARY_PART_HEADER_LBA); + + return UNIT_TEST_PASSED; +} + +/** + Verify that the minimum (92-byte) header size is accepted. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestMinimumHeaderSizeIsAccepted ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + GetPrimaryHeader ()->Header.HeaderSize = TEST_GPT_HEADER_MIN_SIZE; + UpdateGptHeaderCrc (GetPrimaryHeader ()); + + UT_ASSERT_TRUE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a larger power-of-two (256-byte) partition entry size is accepted. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestLargerPowerOfTwoEntrySizeIsAccepted ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + // + // SizeOfPartitionEntry of 256 (128 * 2^1) is legal per the UEFI spec. + // + WriteGptTableAt (PRIMARY_PART_HEADER_LBA, LAST_LBA, PRIMARY_PART_HEADER_LBA + 1, 8, 256, 2); + + UT_ASSERT_TRUE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + UT_ASSERT_EQUAL (Header.SizeOfPartitionEntry, 256U); + + return UNIT_TEST_PASSED; +} + +// --------------------------------------------------------------------------- +// PartitionCheckGptEntry() tests +// --------------------------------------------------------------------------- + +/** + Verify that valid partition entries report no flags. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestValidEntriesReportNoFlags ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + EFI_PARTITION_ENTRY Entries[4]; + EFI_PARTITION_ENTRY_STATUS Status[4]; + UINTN Index; + + InitCheckEntryHeader (&Header, 4, sizeof (EFI_PARTITION_ENTRY)); + ZeroMem (Entries, sizeof (Entries)); + ZeroMem (Status, sizeof (Status)); + + FillPartitionEntry (&Entries[0], &mPartitionGuid1, 34, 100); + FillPartitionEntry (&Entries[1], &mPartitionGuid2, 101, 200); + + PartitionCheckGptEntry (&Header, Entries, Status); + + for (Index = 0; Index < 4; Index++) { + UT_ASSERT_FALSE (Status[Index].OutOfRange); + UT_ASSERT_FALSE (Status[Index].Overlap); + UT_ASSERT_FALSE (Status[Index].OsSpecific); + } + + return UNIT_TEST_PASSED; +} + +/** + Verify that an OS-specific partition attribute is reported. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestOsSpecificAttributeIsReported ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + EFI_PARTITION_ENTRY Entries[1]; + EFI_PARTITION_ENTRY_STATUS Status[1]; + + InitCheckEntryHeader (&Header, 1, sizeof (EFI_PARTITION_ENTRY)); + ZeroMem (Entries, sizeof (Entries)); + ZeroMem (Status, sizeof (Status)); + + FillPartitionEntry (&Entries[0], &mPartitionGuid1, 40, 100); + Entries[0].Attributes = BIT1; + + PartitionCheckGptEntry (&Header, Entries, Status); + + UT_ASSERT_TRUE (Status[0].OsSpecific); + UT_ASSERT_FALSE (Status[0].OutOfRange); + + return UNIT_TEST_PASSED; +} + +/** + Verify that unused partition entries are ignored. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestUnusedEntriesAreIgnored ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + EFI_PARTITION_ENTRY Entries[2]; + EFI_PARTITION_ENTRY_STATUS Status[2]; + + InitCheckEntryHeader (&Header, 2, sizeof (EFI_PARTITION_ENTRY)); + ZeroMem (Entries, sizeof (Entries)); + ZeroMem (Status, sizeof (Status)); + + // + // Unused (zero PartitionTypeGUID) entry with nonsense LBAs must be skipped + // and must not participate in the overlap scan. + // + Entries[0].StartingLBA = MAX_UINT64; + Entries[0].EndingLBA = 0; + FillPartitionEntry (&Entries[1], &mPartitionGuid1, 40, 100); + + PartitionCheckGptEntry (&Header, Entries, Status); + + UT_ASSERT_FALSE (Status[0].OutOfRange); + UT_ASSERT_FALSE (Status[0].Overlap); + UT_ASSERT_FALSE (Status[1].OutOfRange); + UT_ASSERT_FALSE (Status[1].Overlap); + + return UNIT_TEST_PASSED; +} + +/** + Verify that the entry stride follows SizeOfPartitionEntry. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestEntryStrideFollowsSizeOfPartitionEntry ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + UINT8 Buffer[2 * 256]; + EFI_PARTITION_ENTRY_STATUS Status[2]; + EFI_PARTITION_ENTRY *DecoyEntry; + + InitCheckEntryHeader (&Header, 2, 256); + ZeroMem (Buffer, sizeof (Buffer)); + ZeroMem (Status, sizeof (Status)); + + // + // Real entries at 256-byte stride: entry 0 at offset 0, entry 1 at offset + // 256, deliberately overlapping. A decoy non-overlapping but out-of-range + // entry is placed at offset 128: a checker that wrongly walked with a + // 128-byte stride would flag OutOfRange instead of Overlap on index 1. + // + FillPartitionEntry ((EFI_PARTITION_ENTRY *)(VOID *)&Buffer[0], &mPartitionGuid1, 40, 100); + FillPartitionEntry ((EFI_PARTITION_ENTRY *)(VOID *)&Buffer[256], &mPartitionGuid2, 90, 150); + DecoyEntry = (EFI_PARTITION_ENTRY *)(VOID *)&Buffer[128]; + FillPartitionEntry (DecoyEntry, &mPartitionGuid1, 1000, 2000); + + PartitionCheckGptEntry (&Header, (EFI_PARTITION_ENTRY *)(VOID *)Buffer, Status); + + UT_ASSERT_TRUE (Status[0].Overlap); + UT_ASSERT_TRUE (Status[1].Overlap); + UT_ASSERT_FALSE (Status[1].OutOfRange); + + return UNIT_TEST_PASSED; +} + +// --------------------------------------------------------------------------- +// PartitionRestoreGptTable() tests +// --------------------------------------------------------------------------- + +/** + Verify that a corrupted primary GPT is restored from the backup. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestRestorePrimaryFromBackup ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER BackupHeader; + EFI_PARTITION_TABLE_HEADER RestoredHeader; + + SetupDiskWithValidPrimary (); + + // + // Wipe the primary and keep only a valid backup whose entry array follows + // the usable region. + // + WriteGptTableAt ( + LAST_LBA, + PRIMARY_PART_HEADER_LBA, + LAST_USABLE_LBA + 1, + NUM_PARTITION_ENTRIES, + PARTITION_ENTRY_SIZE, + 2 + ); + ZeroMem (GetDiskLba (PRIMARY_PART_HEADER_LBA), SECTOR_SIZE); + ZeroMem (GetDiskLba (PRIMARY_PART_HEADER_LBA + 1), PART_ARRAY_SIZE); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &RestoredHeader)); + UT_ASSERT_TRUE (ValidateAt (LAST_LBA, &BackupHeader)); + + UT_ASSERT_TRUE (PartitionRestoreGptTable (&mBlockIo, &mDiskIo, &BackupHeader)); + + UT_ASSERT_TRUE (ValidateAt (PRIMARY_PART_HEADER_LBA, &RestoredHeader)); + UT_ASSERT_EQUAL (RestoredHeader.MyLBA, PRIMARY_PART_HEADER_LBA); + UT_ASSERT_EQUAL (RestoredHeader.AlternateLBA, LAST_LBA); + UT_ASSERT_EQUAL (RestoredHeader.PartitionEntryLBA, PRIMARY_PART_HEADER_LBA + 1); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a corrupted backup GPT is restored from the primary. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestRestoreBackupFromPrimary ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER PrimaryHeader; + EFI_PARTITION_TABLE_HEADER RestoredHeader; + + SetupDiskWithValidPrimary (); + + UT_ASSERT_TRUE (ValidateAt (PRIMARY_PART_HEADER_LBA, &PrimaryHeader)); + UT_ASSERT_FALSE (ValidateAt (LAST_LBA, &RestoredHeader)); + + UT_ASSERT_TRUE (PartitionRestoreGptTable (&mBlockIo, &mDiskIo, &PrimaryHeader)); + + UT_ASSERT_TRUE (ValidateAt (LAST_LBA, &RestoredHeader)); + UT_ASSERT_EQUAL (RestoredHeader.MyLBA, LAST_LBA); + UT_ASSERT_EQUAL (RestoredHeader.AlternateLBA, PRIMARY_PART_HEADER_LBA); + UT_ASSERT_EQUAL (RestoredHeader.PartitionEntryLBA, LAST_USABLE_LBA + 1); + + return UNIT_TEST_PASSED; +} + +// --------------------------------------------------------------------------- +// Test runner +// --------------------------------------------------------------------------- + +/** + Configure and run the GptLib unit test suites. + + @retval EFI_SUCCESS The unit tests ran to completion. + @retval other An error occurred setting up or running the tests. +**/ +EFI_STATUS +EFIAPI +UefiTestMain ( + VOID + ) +{ + EFI_STATUS Status; + UNIT_TEST_FRAMEWORK_HANDLE Framework; + UNIT_TEST_SUITE_HANDLE ValidSuite; + UNIT_TEST_SUITE_HANDLE EntrySuite; + UNIT_TEST_SUITE_HANDLE RestoreSuite; + + Framework = NULL; + + Status = InitUnitTestFramework (&Framework, UNIT_TEST_NAME, gEfiCallerBaseName, UNIT_TEST_VERSION); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = CreateUnitTestSuite (&ValidSuite, Framework, "PartitionValidGptTable tests", "GptLib.ValidGptTable", NULL, NULL); + if (EFI_ERROR (Status)) { + goto Exit; + } + + Status = CreateUnitTestSuite (&EntrySuite, Framework, "PartitionCheckGptEntry tests", "GptLib.CheckGptEntry", NULL, NULL); + if (EFI_ERROR (Status)) { + goto Exit; + } + + Status = CreateUnitTestSuite (&RestoreSuite, Framework, "PartitionRestoreGptTable tests", "GptLib.RestoreGptTable", NULL, NULL); + if (EFI_ERROR (Status)) { + goto Exit; + } + + AddTestCase (ValidSuite, "Valid primary header is accepted", "ValidPrimary", TestValidPrimaryHeaderIsAccepted, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Valid backup header is accepted", "ValidBackup", TestValidBackupHeaderIsAccepted, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Minimum (92-byte) header size is accepted", "MinHeaderSize", TestMinimumHeaderSizeIsAccepted, NULL, NULL, NULL); + AddTestCase (ValidSuite, "256-byte partition entry size is accepted", "EntrySize256", TestLargerPowerOfTwoEntrySizeIsAccepted, NULL, NULL, NULL); + + AddTestCase (EntrySuite, "Valid entries report no flags", "ValidEntries", TestValidEntriesReportNoFlags, NULL, NULL, NULL); + AddTestCase (EntrySuite, "OS-specific attribute is reported", "OsSpecificAttribute", TestOsSpecificAttributeIsReported, NULL, NULL, NULL); + AddTestCase (EntrySuite, "Unused entries are ignored", "UnusedEntriesIgnored", TestUnusedEntriesAreIgnored, NULL, NULL, NULL); + AddTestCase (EntrySuite, "Entry stride follows SizeOfPartitionEntry", "EntryStride", TestEntryStrideFollowsSizeOfPartitionEntry, NULL, NULL, NULL); + + AddTestCase (RestoreSuite, "Restore primary from backup", "RestorePrimary", TestRestorePrimaryFromBackup, NULL, NULL, NULL); + AddTestCase (RestoreSuite, "Restore backup from primary", "RestoreBackup", TestRestoreBackupFromPrimary, NULL, NULL, NULL); + + Status = RunAllTestSuites (Framework); + +Exit: + if (Framework != NULL) { + FreeUnitTestFramework (Framework); + } + + return Status; +} + +/// +/// Avoid ECC error for function name that starts with lower case letter +/// +#define GptLibUnitTestMain main + +/** + Standard POSIX C entry point for host based unit test execution. + + @param[in] Argc Number of arguments + @param[in] Argv Array of pointers to arguments + + @retval 0 Success + @retval other Error +**/ +INT32 +GptLibUnitTestMain ( + IN INT32 Argc, + IN CHAR8 *Argv[] + ) +{ + UefiTestMain (); + return 0; +} diff --git a/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestCommon.c b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestCommon.c new file mode 100644 index 0000000000..e7061a7e8f --- /dev/null +++ b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestCommon.c @@ -0,0 +1,298 @@ +/** @file + Shared mock disk and GPT construction helpers used by the GptLib + host-based unit tests. + + Copyright (c) 2026, SUSE LLC. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include "GptLibUnitTestCommon.h" + +UINT8 mDiskImage[DISK_IMAGE_SIZE]; + +EFI_BLOCK_IO_MEDIA mBlockIoMedia; +EFI_BLOCK_IO_PROTOCOL mBlockIo; +EFI_DISK_IO_PROTOCOL mDiskIo; +BOOLEAN mWriteProtected; + +CONST EFI_GUID mEspTypeGuid = { + 0xC12A7328, 0xF81F, 0x11D2, { 0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B } +}; + +CONST EFI_GUID mPartitionGuid1 = { + 0x11111111, 0x2222, 0x3333, { 0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77 } +}; + +CONST EFI_GUID mPartitionGuid2 = { + 0x88888888, 0x9999, 0xAAAA, { 0xBB, 0xBB, 0xCC, 0xCC, 0xDD, 0xDD, 0xEE, 0xEE } +}; + +/** + Mock implementation of EFI_DISK_IO_PROTOCOL.ReadDisk backed by the in-memory + disk image. + + @param[in] This Pointer to the EFI_DISK_IO_PROTOCOL instance. + @param[in] MediaId ID of the medium to read from. + @param[in] Offset Starting byte offset on the logical disk. + @param[in] BufferSize Number of bytes to read. + @param[out] Buffer Buffer into which the data is read. + + @retval EFI_SUCCESS The data was read successfully. + @retval EFI_DEVICE_ERROR The request was invalid or out of range. +**/ +STATIC +EFI_STATUS +EFIAPI +MockReadDisk ( + IN EFI_DISK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN UINT64 Offset, + IN UINTN BufferSize, + OUT VOID *Buffer + ) +{ + if ((Buffer == NULL) || + (MediaId != mBlockIoMedia.MediaId) || + (Offset > DISK_IMAGE_SIZE) || + (BufferSize > (DISK_IMAGE_SIZE - Offset))) + { + return EFI_DEVICE_ERROR; + } + + CopyMem (Buffer, mDiskImage + Offset, BufferSize); + return EFI_SUCCESS; +} + +/** + Mock implementation of EFI_DISK_IO_PROTOCOL.WriteDisk backed by the in-memory + disk image, honoring the write-protected flag. + + @param[in] This Pointer to the EFI_DISK_IO_PROTOCOL instance. + @param[in] MediaId ID of the medium to write to. + @param[in] Offset Starting byte offset on the logical disk. + @param[in] BufferSize Number of bytes to write. + @param[in] Buffer Buffer holding the data to write. + + @retval EFI_SUCCESS The data was written successfully. + @retval EFI_WRITE_PROTECTED The mock medium is write-protected. + @retval EFI_DEVICE_ERROR The request was invalid or out of range. +**/ +STATIC +EFI_STATUS +EFIAPI +MockWriteDisk ( + IN EFI_DISK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN UINT64 Offset, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ + if (mWriteProtected) { + return EFI_WRITE_PROTECTED; + } + + if ((Buffer == NULL) || + (MediaId != mBlockIoMedia.MediaId) || + (Offset > DISK_IMAGE_SIZE) || + (BufferSize > (DISK_IMAGE_SIZE - Offset))) + { + return EFI_DEVICE_ERROR; + } + + CopyMem (mDiskImage + Offset, Buffer, BufferSize); + return EFI_SUCCESS; +} + +/** + Return a pointer into the in-memory disk image at the given LBA. + + @param[in] Lba Logical block address to locate. + + @return Pointer to the start of the requested block within the disk image. +**/ +UINT8 * +GetDiskLba ( + IN EFI_LBA Lba + ) +{ + return mDiskImage + (UINTN)(Lba * SECTOR_SIZE); +} + +/** + Return a pointer to the primary GPT header within the in-memory disk image. + + @return Pointer to the primary EFI_PARTITION_TABLE_HEADER. +**/ +EFI_PARTITION_TABLE_HEADER * +GetPrimaryHeader ( + VOID + ) +{ + return (EFI_PARTITION_TABLE_HEADER *)(VOID *)GetDiskLba (PRIMARY_PART_HEADER_LBA); +} + +/** + Recompute and store the header CRC32 for the given GPT header. + + @param[in,out] Header The GPT header whose CRC32 field is updated. +**/ +VOID +UpdateGptHeaderCrc ( + IN OUT EFI_PARTITION_TABLE_HEADER *Header + ) +{ + Header->Header.CRC32 = 0; + Header->Header.CRC32 = CalculateCrc32 (Header, Header->Header.HeaderSize); +} + +/** + Populate a partition entry with the ESP type GUID and the given attributes. + + @param[in,out] Entry The partition entry to fill. + @param[in] UniquePartitionGuid Unique partition GUID to assign. + @param[in] StartingLba Starting LBA of the partition. + @param[in] EndingLba Ending LBA of the partition. +**/ +VOID +FillPartitionEntry ( + IN OUT EFI_PARTITION_ENTRY *Entry, + IN CONST EFI_GUID *UniquePartitionGuid, + IN EFI_LBA StartingLba, + IN EFI_LBA EndingLba + ) +{ + CopyGuid (&Entry->PartitionTypeGUID, &mEspTypeGuid); + CopyGuid (&Entry->UniquePartitionGUID, UniquePartitionGuid); + Entry->StartingLBA = StartingLba; + Entry->EndingLBA = EndingLba; +} + +/** + Construct a complete GPT header and partition entry array at the given LBA in + the in-memory disk image, recalculating all CRCs. + + @param[in] HeaderLba LBA at which to write the GPT header. + @param[in] AlternateLba Value stored in the header AlternateLBA field. + @param[in] EntryArrayLba LBA at which to write the partition entry array. + @param[in] NumEntries Number of partition entries in the array. + @param[in] EntrySize Size in bytes of each partition entry. + @param[in] NumPartitions Number of populated partition entries. +**/ +VOID +WriteGptTableAt ( + IN EFI_LBA HeaderLba, + IN EFI_LBA AlternateLba, + IN EFI_LBA EntryArrayLba, + IN UINT32 NumEntries, + IN UINT32 EntrySize, + IN UINT32 NumPartitions + ) +{ + EFI_PARTITION_TABLE_HEADER *Header; + UINT8 *Array; + UINT32 ArraySize; + + ArraySize = NumEntries * EntrySize; + Array = GetDiskLba (EntryArrayLba); + ZeroMem (Array, ArraySize); + if (NumPartitions >= 1) { + FillPartitionEntry ((EFI_PARTITION_ENTRY *)(VOID *)Array, &mPartitionGuid1, 34, 133); + } + + if (NumPartitions >= 2) { + FillPartitionEntry ((EFI_PARTITION_ENTRY *)(VOID *)(Array + EntrySize), &mPartitionGuid2, 134, 233); + } + + Header = (EFI_PARTITION_TABLE_HEADER *)(VOID *)GetDiskLba (HeaderLba); + ZeroMem (Header, SECTOR_SIZE); + Header->Header.Signature = EFI_PTAB_HEADER_ID; + Header->Header.Revision = TEST_GPT_REVISION_V1; + Header->Header.HeaderSize = sizeof (EFI_PARTITION_TABLE_HEADER); + Header->MyLBA = HeaderLba; + Header->AlternateLBA = AlternateLba; + Header->FirstUsableLBA = FIRST_USABLE_LBA; + Header->LastUsableLBA = LAST_USABLE_LBA; + Header->PartitionEntryLBA = EntryArrayLba; + Header->NumberOfPartitionEntries = NumEntries; + Header->SizeOfPartitionEntry = EntrySize; + Header->PartitionEntryArrayCRC32 = CalculateCrc32 (Array, ArraySize); + UpdateGptHeaderCrc (Header); +} + +/** + Reset the mock disk and protocol state and lay down a valid primary GPT. +**/ +VOID +SetupDiskWithValidPrimary ( + VOID + ) +{ + ZeroMem (mDiskImage, sizeof (mDiskImage)); + + ZeroMem (&mBlockIoMedia, sizeof (mBlockIoMedia)); + mBlockIoMedia.MediaId = 1; + mBlockIoMedia.BlockSize = SECTOR_SIZE; + mBlockIoMedia.LastBlock = LAST_LBA; + + ZeroMem (&mBlockIo, sizeof (mBlockIo)); + mBlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION; + mBlockIo.Media = &mBlockIoMedia; + + ZeroMem (&mDiskIo, sizeof (mDiskIo)); + mDiskIo.Revision = EFI_DISK_IO_PROTOCOL_REVISION; + mDiskIo.ReadDisk = MockReadDisk; + mDiskIo.WriteDisk = MockWriteDisk; + + mWriteProtected = FALSE; + + WriteGptTableAt ( + PRIMARY_PART_HEADER_LBA, + LAST_LBA, + PRIMARY_PART_HEADER_LBA + 1, + NUM_PARTITION_ENTRIES, + PARTITION_ENTRY_SIZE, + 2 + ); +} + +/** + Invoke PartitionValidGptTable against the mock disk at the given LBA. + + @param[in] Lba LBA of the GPT header to validate. + @param[out] Header Buffer to receive the validated GPT header. + + @retval TRUE The GPT table at Lba is valid. + @retval FALSE The GPT table at Lba is invalid. +**/ +BOOLEAN +ValidateAt ( + IN EFI_LBA Lba, + OUT EFI_PARTITION_TABLE_HEADER *Header + ) +{ + return PartitionValidGptTable (&mBlockIo, &mDiskIo, Lba, Header); +} + +/** + Initialize a GPT header in memory for PartitionCheckGptEntry tests. + + @param[out] Header The GPT header to initialize. + @param[in] NumEntries Number of partition entries to record. + @param[in] EntrySize Size in bytes of each partition entry. +**/ +VOID +InitCheckEntryHeader ( + OUT EFI_PARTITION_TABLE_HEADER *Header, + IN UINT32 NumEntries, + IN UINT32 EntrySize + ) +{ + ZeroMem (Header, sizeof (*Header)); + Header->FirstUsableLBA = FIRST_USABLE_LBA; + Header->LastUsableLBA = 200; + Header->NumberOfPartitionEntries = NumEntries; + Header->SizeOfPartitionEntry = EntrySize; +} diff --git a/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestCommon.h b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestCommon.h new file mode 100644 index 0000000000..677dbc4c4f --- /dev/null +++ b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestCommon.h @@ -0,0 +1,110 @@ +/** @file + Shared mock disk and GPT construction helpers used by the GptLib + host-based unit tests. + + Copyright (c) 2026, SUSE LLC. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#pragma once + +#include <Uefi.h> +#include <Protocol/BlockIo.h> +#include <Protocol/DiskIo.h> +#include <Library/GptLib.h> + +#define SECTOR_SIZE 512U +#define DISK_SECTORS 4096U +#define DISK_IMAGE_SIZE (DISK_SECTORS * SECTOR_SIZE) +#define LAST_LBA (DISK_SECTORS - 1U) +#define NUM_PARTITION_ENTRIES 128U +#define PARTITION_ENTRY_SIZE 128U +#define PART_ARRAY_SIZE (NUM_PARTITION_ENTRIES * PARTITION_ENTRY_SIZE) +#define FIRST_USABLE_LBA 34U +#define LAST_USABLE_LBA (DISK_SECTORS - 34U) + +// +// The only GPT header revision defined by the UEFI specification, and the +// minimum on-disk header size (through PartitionEntryArrayCRC32). +// +#define TEST_GPT_REVISION_V1 0x00010000U +#define TEST_GPT_HEADER_MIN_SIZE 92U + +extern UINT8 mDiskImage[DISK_IMAGE_SIZE]; + +extern EFI_BLOCK_IO_MEDIA mBlockIoMedia; +extern EFI_BLOCK_IO_PROTOCOL mBlockIo; +extern EFI_DISK_IO_PROTOCOL mDiskIo; +extern BOOLEAN mWriteProtected; + +extern CONST EFI_GUID mEspTypeGuid; +extern CONST EFI_GUID mPartitionGuid1; +extern CONST EFI_GUID mPartitionGuid2; + +UINT8 * +GetDiskLba ( + IN EFI_LBA Lba + ); + +EFI_PARTITION_TABLE_HEADER * +GetPrimaryHeader ( + VOID + ); + +VOID +UpdateGptHeaderCrc ( + IN OUT EFI_PARTITION_TABLE_HEADER *Header + ); + +VOID +FillPartitionEntry ( + IN OUT EFI_PARTITION_ENTRY *Entry, + IN CONST EFI_GUID *UniquePartitionGuid, + IN EFI_LBA StartingLba, + IN EFI_LBA EndingLba + ); + +/** + Write a self-consistent GPT table (header plus partition entry array) to the + mock disk at the requested locations, computing correct header and + entry-array CRC32 values. + + @param[in] HeaderLba LBA where the GPT header is written. Also stored + in the header's MyLBA field. + @param[in] AlternateLba Value stored in the header's AlternateLBA field. + @param[in] EntryArrayLba LBA where the partition entry array is written. + @param[in] NumEntries NumberOfPartitionEntries value. + @param[in] EntrySize SizeOfPartitionEntry value. + @param[in] NumPartitions Number of non-empty partition entries to populate. +**/ +VOID +WriteGptTableAt ( + IN EFI_LBA HeaderLba, + IN EFI_LBA AlternateLba, + IN EFI_LBA EntryArrayLba, + IN UINT32 NumEntries, + IN UINT32 EntrySize, + IN UINT32 NumPartitions + ); + +/** + Reset the mock disk to a single valid primary GPT: header at LBA 1, a + 128 x 128-byte entry array at LBA 2 holding two partitions. +**/ +VOID +SetupDiskWithValidPrimary ( + VOID + ); + +BOOLEAN +ValidateAt ( + IN EFI_LBA Lba, + OUT EFI_PARTITION_TABLE_HEADER *Header + ); + +VOID +InitCheckEntryHeader ( + OUT EFI_PARTITION_TABLE_HEADER *Header, + IN UINT32 NumEntries, + IN UINT32 EntrySize + ); diff --git a/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestHost.inf b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestHost.inf new file mode 100644 index 0000000000..a387e6afda --- /dev/null +++ b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestHost.inf @@ -0,0 +1,40 @@ +## @file +# Host-based unit tests for GptLib. +# +# Exercises PartitionValidGptTable(), PartitionCheckGptEntry() and +# PartitionRestoreGptTable() against an in-memory mock disk, covering their +# behavior on well-formed GPT structures. +# +# Copyright (c) 2026, SUSE LLC. All rights reserved.<BR> +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010006 + BASE_NAME = GptLibUnitTestHost + FILE_GUID = 2F5B4C8E-6D3A-4B1F-9E07-8A2C5D14E6B3 + MODULE_TYPE = HOST_APPLICATION + VERSION_STRING = 1.0 + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + GptLibUnitTestCommon.h + GptLibUnitTestCommon.c + GptLibUnitTest.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + GptLib + UnitTestLib diff --git a/MdeModulePkg/MdeModulePkg.ci.yaml b/MdeModulePkg/MdeModulePkg.ci.yaml index 37dc5caaf6..6056e263a6 100644 --- a/MdeModulePkg/MdeModulePkg.ci.yaml +++ b/MdeModulePkg/MdeModulePkg.ci.yaml @@ -24,6 +24,7 @@ "8005", "UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGE.HID", "8001", "UefiSortLibUnitTestMain", "8001", "MediaSanitizeUnitTestMain", + "8001", "GptLibUnitTestMain", ], ## Both file path and directory path are accepted. "IgnoreFiles": [ diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc index 4f04a6dd79..05fd4652ff 100644 --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc @@ -77,6 +77,11 @@ HobLib|MdePkg/Test/Mock/Library/GoogleTest/MockHobLib/MockHobLib.inf } + MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestHost.inf { + <LibraryClasses> + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf + } + # # Build HOST_APPLICATION Libraries # From b1029265b1459a4021df8e7495daf281df3344ef Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Tue, 7 Jul 2026 22:56:54 +0800 Subject: [PATCH 248/406] MdeModulePkg/GptLib: Add host-based unit tests for malformed GPT input Extend the GptLib host-based tests with negative cases that guard the security hardening in PartitionValidGptTable(), PartitionCheckGptEntry() and PartitionRestoreGptTable() against future regressions. These tests exercise the shared parser, not the specific fix itself. The new cases drive the parser with malformed GPT structures that an attacker may present: bad signature/revision, header-size boundaries, CRC corruption, MyLBA replay, zero/non-power-of-two entry sizes, LBA multiplication overflow, out-of-range and overlapping entries, and restore failure on write-protected media. The INF file header is updated to note the added malformed coverage. Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- .../Library/GptLib/UnitTest/GptLibUnitTest.c | 570 +++++++++++++++++- .../GptLib/UnitTest/GptLibUnitTestHost.inf | 4 +- 2 files changed, 571 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTest.c b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTest.c index fbc6e3ba46..ee99668315 100644 --- a/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTest.c +++ b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTest.c @@ -3,7 +3,11 @@ These tests exercise PartitionValidGptTable(), PartitionCheckGptEntry() and PartitionRestoreGptTable() against an in-memory mock disk, covering - their behavior on well-formed GPT structures. + both well-formed GPT structures and malformed ones an attacker may + present: bad signature/revision, header size + boundaries, CRC corruption, MyLBA replay, zero/non-power-of-two entry + sizes, LBA multiplication overflow, out-of-range and overlapping + entries, and backup/primary restore behavior. Copyright (c) 2026, SUSE LLC. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -145,6 +149,421 @@ TestLargerPowerOfTwoEntrySizeIsAccepted ( return UNIT_TEST_PASSED; } +/** + Verify that a GPT header read failure is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestHeaderReadFailureIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + UT_ASSERT_FALSE (ValidateAt (DISK_SECTORS + 10, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that an invalid GPT signature is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestInvalidSignatureIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + GetPrimaryHeader ()->Header.Signature = SIGNATURE_64 ('X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'); + UpdateGptHeaderCrc (GetPrimaryHeader ()); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that an invalid GPT revision is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestInvalidRevisionIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + STATIC CONST UINT32 BadRevisions[] = { 0x00000000, 0x00010001, 0x00020000, 0xFFFFFFFF }; + UINTN Index; + + for (Index = 0; Index < ARRAY_SIZE (BadRevisions); Index++) { + SetupDiskWithValidPrimary (); + + GetPrimaryHeader ()->Header.Revision = BadRevisions[Index]; + UpdateGptHeaderCrc (GetPrimaryHeader ()); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + } + + return UNIT_TEST_PASSED; +} + +/** + Verify that a header size below the minimum is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestHeaderSizeBelowMinimumIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + GetPrimaryHeader ()->Header.HeaderSize = TEST_GPT_HEADER_MIN_SIZE - 1; + GetPrimaryHeader ()->Header.CRC32 = 0; + GetPrimaryHeader ()->Header.CRC32 = CalculateCrc32 (GetPrimaryHeader (), TEST_GPT_HEADER_MIN_SIZE - 1); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a zero header size is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestZeroHeaderSizeIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + GetPrimaryHeader ()->Header.HeaderSize = 0; + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a header size beyond the block size is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestHeaderSizeBeyondBlockSizeIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + // + // HeaderSize larger than the block that was read: the CRC check must + // refuse to scan past the buffer instead of reading out of bounds. + // + GetPrimaryHeader ()->Header.HeaderSize = SECTOR_SIZE + 1; + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a corrupt header CRC is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestCorruptHeaderCrcIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + GetPrimaryHeader ()->Header.CRC32 ^= 0xFFFFFFFF; + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a MyLBA mismatch is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestMyLbaMismatchIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + // + // A header claiming to live at a different LBA than the one it was read + // from (e.g. a copied/replayed header) must be rejected. + // + GetPrimaryHeader ()->MyLBA = 5; + UpdateGptHeaderCrc (GetPrimaryHeader ()); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a header reporting zero partition entries is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestZeroPartitionEntriesIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + GetPrimaryHeader ()->NumberOfPartitionEntries = 0; + UpdateGptHeaderCrc (GetPrimaryHeader ()); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a partition entry size below 128 bytes is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestEntrySizeTooSmallIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + GetPrimaryHeader ()->SizeOfPartitionEntry = (UINT32)(sizeof (EFI_PARTITION_ENTRY) / 2); + UpdateGptHeaderCrc (GetPrimaryHeader ()); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a zero partition entry size is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestZeroEntrySizeIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + // + // Must be rejected by the size check before the later division by + // SizeOfPartitionEntry (division by zero) can be reached. + // + GetPrimaryHeader ()->SizeOfPartitionEntry = 0; + UpdateGptHeaderCrc (GetPrimaryHeader ()); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a non power-of-two partition entry size is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestNonPowerOfTwoEntrySizeIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + // + // 192 is >= 128 but not 128 * 2^n. + // + GetPrimaryHeader ()->SizeOfPartitionEntry = 192; + UpdateGptHeaderCrc (GetPrimaryHeader ()); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that a PartitionEntryLBA causing multiplication overflow is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestEntryLbaMultiplicationOverflowIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + // + // PartitionEntryLBA * BlockSize would wrap around UINT64. Must be rejected + // before any read is attempted with the truncated offset. + // + GetPrimaryHeader ()->PartitionEntryLBA = MAX_UINT64; + UpdateGptHeaderCrc (GetPrimaryHeader ()); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that an entry array CRC mismatch is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestEntryArrayCrcMismatchIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + // + // Flip one byte inside an unused entry slot without refreshing the + // entry-array CRC32 recorded in the header. + // + GetDiskLba (PRIMARY_PART_HEADER_LBA + 1)[(2U * PARTITION_ENTRY_SIZE) + 7] ^= 0xA5; + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + +/** + Verify that an entry array read failure is rejected. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestEntryArrayReadFailureIsRejected ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + + SetupDiskWithValidPrimary (); + + // + // Entry array placed so close to the end of the device that reading + // NumberOfPartitionEntries * SizeOfPartitionEntry bytes runs off the disk. + // + GetPrimaryHeader ()->PartitionEntryLBA = LAST_LBA; + UpdateGptHeaderCrc (GetPrimaryHeader ()); + + UT_ASSERT_FALSE (ValidateAt (PRIMARY_PART_HEADER_LBA, &Header)); + + return UNIT_TEST_PASSED; +} + // --------------------------------------------------------------------------- // PartitionCheckGptEntry() tests // --------------------------------------------------------------------------- @@ -302,6 +721,108 @@ TestEntryStrideFollowsSizeOfPartitionEntry ( return UNIT_TEST_PASSED; } +/** + Verify that an inverted LBA range reports OutOfRange. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestInvertedLbaRangeReportsOutOfRange ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + EFI_PARTITION_ENTRY Entries[1]; + EFI_PARTITION_ENTRY_STATUS Status[1]; + + InitCheckEntryHeader (&Header, 1, sizeof (EFI_PARTITION_ENTRY)); + ZeroMem (Entries, sizeof (Entries)); + ZeroMem (Status, sizeof (Status)); + + FillPartitionEntry (&Entries[0], &mPartitionGuid1, 100, 50); + + PartitionCheckGptEntry (&Header, Entries, Status); + + UT_ASSERT_TRUE (Status[0].OutOfRange); + + return UNIT_TEST_PASSED; +} + +/** + Verify that an entry outside the usable region reports OutOfRange. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestEntryOutsideUsableRegionReportsOutOfRange ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + EFI_PARTITION_ENTRY Entries[2]; + EFI_PARTITION_ENTRY_STATUS Status[2]; + + InitCheckEntryHeader (&Header, 2, sizeof (EFI_PARTITION_ENTRY)); + ZeroMem (Entries, sizeof (Entries)); + ZeroMem (Status, sizeof (Status)); + + // + // Entry 0 starts before FirstUsableLBA; entry 1 ends after LastUsableLBA. + // + FillPartitionEntry (&Entries[0], &mPartitionGuid1, FIRST_USABLE_LBA - 1, 100); + FillPartitionEntry (&Entries[1], &mPartitionGuid2, 150, 201); + + PartitionCheckGptEntry (&Header, Entries, Status); + + UT_ASSERT_TRUE (Status[0].OutOfRange); + UT_ASSERT_TRUE (Status[1].OutOfRange); + + return UNIT_TEST_PASSED; +} + +/** + Verify that overlapping partition entries report Overlap. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestOverlappingEntriesReportOverlap ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER Header; + EFI_PARTITION_ENTRY Entries[3]; + EFI_PARTITION_ENTRY_STATUS Status[3]; + + InitCheckEntryHeader (&Header, 3, sizeof (EFI_PARTITION_ENTRY)); + ZeroMem (Entries, sizeof (Entries)); + ZeroMem (Status, sizeof (Status)); + + FillPartitionEntry (&Entries[0], &mPartitionGuid1, 40, 100); + FillPartitionEntry (&Entries[1], &mPartitionGuid2, 90, 150); + FillPartitionEntry (&Entries[2], &mPartitionGuid1, 160, 200); + + PartitionCheckGptEntry (&Header, Entries, Status); + + UT_ASSERT_TRUE (Status[0].Overlap); + UT_ASSERT_TRUE (Status[1].Overlap); + UT_ASSERT_FALSE (Status[2].Overlap); + + return UNIT_TEST_PASSED; +} + // --------------------------------------------------------------------------- // PartitionRestoreGptTable() tests // --------------------------------------------------------------------------- @@ -385,6 +906,34 @@ TestRestoreBackupFromPrimary ( return UNIT_TEST_PASSED; } +/** + Verify that a restore attempt fails on write-protected media. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The test passed. +**/ +STATIC +UNIT_TEST_STATUS +EFIAPI +TestRestoreFailsOnWriteProtectedMedia ( + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_PARTITION_TABLE_HEADER PrimaryHeader; + + SetupDiskWithValidPrimary (); + + UT_ASSERT_TRUE (ValidateAt (PRIMARY_PART_HEADER_LBA, &PrimaryHeader)); + + mWriteProtected = TRUE; + + UT_ASSERT_FALSE (PartitionRestoreGptTable (&mBlockIo, &mDiskIo, &PrimaryHeader)); + UT_ASSERT_FALSE (ValidateAt (LAST_LBA, &PrimaryHeader)); + + return UNIT_TEST_PASSED; +} + // --------------------------------------------------------------------------- // Test runner // --------------------------------------------------------------------------- @@ -433,14 +982,33 @@ UefiTestMain ( AddTestCase (ValidSuite, "Valid backup header is accepted", "ValidBackup", TestValidBackupHeaderIsAccepted, NULL, NULL, NULL); AddTestCase (ValidSuite, "Minimum (92-byte) header size is accepted", "MinHeaderSize", TestMinimumHeaderSizeIsAccepted, NULL, NULL, NULL); AddTestCase (ValidSuite, "256-byte partition entry size is accepted", "EntrySize256", TestLargerPowerOfTwoEntrySizeIsAccepted, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Header read failure is rejected", "HeaderReadFailure", TestHeaderReadFailureIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Invalid signature is rejected", "InvalidSignature", TestInvalidSignatureIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Invalid revision is rejected", "InvalidRevision", TestInvalidRevisionIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Header size below minimum is rejected", "HeaderSizeTooSmall", TestHeaderSizeBelowMinimumIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Zero header size is rejected", "ZeroHeaderSize", TestZeroHeaderSizeIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Header size beyond block size is rejected", "HeaderSizeBeyondBlock", TestHeaderSizeBeyondBlockSizeIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Corrupt header CRC is rejected", "CorruptHeaderCrc", TestCorruptHeaderCrcIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "MyLBA mismatch is rejected", "MyLbaMismatch", TestMyLbaMismatchIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Zero partition entries is rejected", "ZeroEntries", TestZeroPartitionEntriesIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Entry size below 128 is rejected", "EntrySizeTooSmall", TestEntrySizeTooSmallIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Zero entry size is rejected", "ZeroEntrySize", TestZeroEntrySizeIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Non power-of-two entry size is rejected", "NonPowerOfTwoEntrySize", TestNonPowerOfTwoEntrySizeIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "PartitionEntryLBA overflow is rejected", "EntryLbaOverflow", TestEntryLbaMultiplicationOverflowIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Entry array CRC mismatch is rejected", "EntryArrayCrcMismatch", TestEntryArrayCrcMismatchIsRejected, NULL, NULL, NULL); + AddTestCase (ValidSuite, "Entry array read failure is rejected", "EntryArrayReadFailure", TestEntryArrayReadFailureIsRejected, NULL, NULL, NULL); AddTestCase (EntrySuite, "Valid entries report no flags", "ValidEntries", TestValidEntriesReportNoFlags, NULL, NULL, NULL); AddTestCase (EntrySuite, "OS-specific attribute is reported", "OsSpecificAttribute", TestOsSpecificAttributeIsReported, NULL, NULL, NULL); AddTestCase (EntrySuite, "Unused entries are ignored", "UnusedEntriesIgnored", TestUnusedEntriesAreIgnored, NULL, NULL, NULL); AddTestCase (EntrySuite, "Entry stride follows SizeOfPartitionEntry", "EntryStride", TestEntryStrideFollowsSizeOfPartitionEntry, NULL, NULL, NULL); + AddTestCase (EntrySuite, "Inverted LBA range reports OutOfRange", "InvertedRange", TestInvertedLbaRangeReportsOutOfRange, NULL, NULL, NULL); + AddTestCase (EntrySuite, "Entry outside usable region reports OutOfRange", "OutsideUsableRegion", TestEntryOutsideUsableRegionReportsOutOfRange, NULL, NULL, NULL); + AddTestCase (EntrySuite, "Overlapping entries report Overlap", "OverlappingEntries", TestOverlappingEntriesReportOverlap, NULL, NULL, NULL); AddTestCase (RestoreSuite, "Restore primary from backup", "RestorePrimary", TestRestorePrimaryFromBackup, NULL, NULL, NULL); AddTestCase (RestoreSuite, "Restore backup from primary", "RestoreBackup", TestRestoreBackupFromPrimary, NULL, NULL, NULL); + AddTestCase (RestoreSuite, "Restore fails on write-protected media", "RestoreWriteProtected", TestRestoreFailsOnWriteProtectedMedia, NULL, NULL, NULL); Status = RunAllTestSuites (Framework); diff --git a/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestHost.inf b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestHost.inf index a387e6afda..f552a3fdcc 100644 --- a/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestHost.inf +++ b/MdeModulePkg/Library/GptLib/UnitTest/GptLibUnitTestHost.inf @@ -2,8 +2,8 @@ # Host-based unit tests for GptLib. # # Exercises PartitionValidGptTable(), PartitionCheckGptEntry() and -# PartitionRestoreGptTable() against an in-memory mock disk, covering their -# behavior on well-formed GPT structures. +# PartitionRestoreGptTable() against an in-memory mock disk, covering both +# well-formed GPT structures and malformed ones an attacker may present. # # Copyright (c) 2026, SUSE LLC. All rights reserved.<BR> # SPDX-License-Identifier: BSD-2-Clause-Patent From 0e13e105c625810b816dbed199f0f9520d6611a0 Mon Sep 17 00:00:00 2001 From: Richard Lyu <richard.lyu@suse.com> Date: Wed, 15 Jul 2026 23:44:05 +0800 Subject: [PATCH 249/406] BREAKING-CHANGES.md: Document GptLib library class addition Per the Breaking Change and Release Process RFC, a non-removal breaking change must add an entry to BREAKING-CHANGES.md in the PR that introduces the change. Add the entry for the new GptLib library class dependency under edk2-stable202608, Source-Level Breaking Changes, Changes without Removal. Signed-off-by: Richard Lyu <richard.lyu@suse.com> --- BREAKING-CHANGES.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 4191162a37..6b55e27f40 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -68,7 +68,35 @@ None #### edk2-stable202608: Changes without Removal -None +##### Breaking Change: New GptLib library class dependency + +**Status**: Announced + +**Tracking Issue**: tianocore/edk2#12808 + +**Type**: Source-Level (Non-removal) - Library class dependency addition +(single expected instance) + +**What changed**: PartitionDxe, DxeTpm2MeasureBootLib and +DxeTpmMeasureBootLib gained a required dependency on the new GptLib library +class declared in MdeModulePkg. Platforms that build any of these modules +must resolve GptLib in their DSC or the build fails with an unresolved +library class. + +**Why it changed**: As reported in CVE-2024-13745, DxeTpm2MeasureBootLib +could measure a GPT partition table that differs from the one parsed and +used by PartitionDxe, because the two components carried independent GPT +parsing logic. GptLib consolidates GPT parsing and validation so the +partition table measured into PCR[5] is validated by the same logic the +firmware uses. + +**What replaces it**: Nothing is removed. A single canonical GptLib +instance is provided in-tree (MdeModulePkg/Library/GptLib/GptLib.inf). + +**How to migrate**: Add the following mapping to the platform DSC +[LibraryClasses] section: + + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf ### edk2-stable202608: Behavioral Breaking Changes From 3fa842faf9cd3b7e323693102d68714ed95a3a40 Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Mon, 30 Sep 2024 12:45:45 +0100 Subject: [PATCH 250/406] ArmVirtPkg: Add Crypto helper library for Boot Sync Introduce a helper library that implements wrappers for the cryptographic functionality required by the Arm Boot Sync Blocks protocol implementation. This library implements the following: - Key Exchange: ECDH key using the ECC Curve-P384 - Key Derivation: SHA512 HMAC-based Extract-and-Expand HKDF - Encryption/Decryption: AEAD AES-GCM authenticated encryption and decryption Also register the library class in ArmVirtPkg.dec, wire the instance into the KvmTool guest firmware and update the CI YAML file to add CryptoPkg/CryptoPkg.dec as an acceptable dependency. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- ArmVirtPkg/ArmVirtKvmTool.dsc | 4 + ArmVirtPkg/ArmVirtPkg.ci.yaml | 3 +- ArmVirtPkg/ArmVirtPkg.dec | 1 + .../Include/Library/ArmCcaBootSyncCryptoLib.h | 239 +++++++ .../ArmCcaBootSyncCrypto.h | 37 ++ .../ArmCcaBootSyncCryptoLib.c | 614 ++++++++++++++++++ .../ArmCcaBootSyncCryptoLib.inf | 33 + 7 files changed, 930 insertions(+), 1 deletion(-) create mode 100644 ArmVirtPkg/Include/Library/ArmCcaBootSyncCryptoLib.h create mode 100644 ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCrypto.h create mode 100644 ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCryptoLib.c create mode 100644 ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCryptoLib.inf diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index f63838c795..91411b5264 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -68,6 +68,10 @@ DynamicPlatRepoLib|DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoLib.inf ArmMonitorLib|ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.inf + # OpensslLibFull/FullAccel is required for ECDH, see CryptoPkg/Readme.md + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf + + ArmCcaBootSyncCryptoLib|ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCryptoLib.inf [LibraryClasses.common.SEC, LibraryClasses.common.PEI_CORE, LibraryClasses.common.PEIM] PciExpressLib|MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf diff --git a/ArmVirtPkg/ArmVirtPkg.ci.yaml b/ArmVirtPkg/ArmVirtPkg.ci.yaml index b8b8f190bd..21cb190014 100644 --- a/ArmVirtPkg/ArmVirtPkg.ci.yaml +++ b/ArmVirtPkg/ArmVirtPkg.ci.yaml @@ -56,7 +56,8 @@ "PcAtChipsetPkg/PcAtChipsetPkg.dec", "SecurityPkg/SecurityPkg.dec", "UefiCpuPkg/UefiCpuPkg.dec", - "ShellPkg/ShellPkg.dec" #Is this ok? + "ShellPkg/ShellPkg.dec", #Is this ok? + "CryptoPkg/CryptoPkg.dec" ], # For host based unit tests "AcceptableDependencies-HOST_APPLICATION":[ diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec index 8386ec0ad8..fd9a31a916 100644 --- a/ArmVirtPkg/ArmVirtPkg.dec +++ b/ArmVirtPkg/ArmVirtPkg.dec @@ -26,6 +26,7 @@ Include # Root include for the package [LibraryClasses] + ArmCcaBootSyncCryptoLib|Include/Library/ArmCcaBootSyncCryptoLib.h ArmCcaInitPeiLib|Include/Library/ArmCcaInitPeiLib.h ArmCcaLib|Include/Library/ArmCcaLib.h ArmCcaRsiLib|Include/Library/ArmCcaRsiLib.h diff --git a/ArmVirtPkg/Include/Library/ArmCcaBootSyncCryptoLib.h b/ArmVirtPkg/Include/Library/ArmCcaBootSyncCryptoLib.h new file mode 100644 index 0000000000..6733f07c9b --- /dev/null +++ b/ArmVirtPkg/Include/Library/ArmCcaBootSyncCryptoLib.h @@ -0,0 +1,239 @@ +/** @file + Boot Sync Crypto Lib. + + Copyright (c) 2024, Arm Limited. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - BS - Boot Sync + + @par Reference(s): + - Realm Host Interface (RHI) Specification, version 1.0-alp0 + (https://developer.arm.com/documentation/den0148/) +**/ + +#pragma once + +#include <Uefi/UefiBaseType.h> + +/** + Generate an ECDH key using the ECC Curve-P384 and retrive the public key. + + @param[out] Context Pointer to the key handle. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval EFI_ABORTED An operation failed. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoGenerateKey ( + OUT VOID **Context + ); + +/** + Delete the key and associated data. + + @param[in] Context Pointer to the key handle. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoDeleteKey ( + VOID *Context + ); + +/** + Get the public key in PEM format. + + Note: The caller is responsible to free the PubKeyPem buffer + by calling FreePool(). + + @param[in] Context Pointer to the key handle. + @param[out] PubKeyPem Pointer to store the PEM data. + @param[out] PubKeyPemSize PEM data size. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval EFI_ABORTED An operation failed. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoGetPublicKey ( + IN VOID *Context, + OUT UINT8 **PubKeyPem, + OUT UINTN *PubKeyPemSize + ); + +/** + Get the peer key using the peer public PEM data. + + Note: The caller is responsible for freeing the peer key by calling + ArmCcaBootSyncCryptoDeleteKey() for the PeerContext. + + @param[out] Context Pointer to the peer key handle. + @param[in] PeerPubKeyPem Pointer to the peer PEM data. + @param[in] PeerPubKeyPemSize PEM data size. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval EFI_ABORTED An operation failed. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoGeneratePeerKey ( + OUT VOID **PeerContext, + IN UINT8 *PeerPubKeyPem, + IN UINTN PeerPubKeyPemSize + ); + +/** + Generate the common key. + + Note: The common key is freed when the caller frees the Context + by calling ArmCcaBootSyncCryptoDeleteKey(). + + @param[in] Context Pointer to the key handle. + @param[in] PeerContext Pointer to the peer key handle. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval EFI_ABORTED An operation failed. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoGenerateCommonKey ( + IN VOID *Context, + IN VOID *PeerContext + ); + +/** + Derive keys using SHA512 HMAC-based Extract-and-Expand Key + Derivation Function (HKDF). + + @param[in] Context Pointer to the key handle. + @param[in] Salt Pointer to the salt(non-secret) value. + @param[in] SaltSize Salt size in bytes. + @param[in] Info Pointer to the application specific info. + @param[in] InfoSize Info size in bytes. + @param[out] Out Pointer to buffer to receive hkdf value. + @param[in] OutSize Size of hkdf bytes to generate. + + @retval TRUE Key derevation successful. + @retval FALSE Key derevation failed. +**/ +BOOLEAN +EFIAPI +ArmCcaBootSyncCryptoDeriveKey ( + IN VOID *Context, + IN CONST UINT8 *Salt, + IN UINTN SaltSize, + IN CONST UINT8 *Info, + IN UINTN InfoSize, + OUT UINT8 *Out, + IN UINTN OutSize + ); + +/** + Performs AEAD AES-GCM authenticated encryption on a data buffer and + additional authenticated data (AAD). + + IvSize must be 12, otherwise FALSE is returned. + KeySize must be 16, 24 or 32, otherwise FALSE is returned. + TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned. + + @param[in] Key Pointer to the encryption key. + @param[in] KeySize Size of the encryption key in bytes. + @param[in] Iv Pointer to the IV value. + @param[in] IvSize Size of the IV value in bytes. + @param[in] AData Pointer to the additional authenticated data (AAD). + @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes. + @param[in] DataIn Pointer to the input data buffer to be encrypted. + @param[in] DataInSize Size of the input data buffer in bytes. + @param[out] TagOut Pointer to a buffer that receives the authentication tag output. + @param[in] TagSize Size of the authentication tag in bytes. + @param[out] DataOut Pointer to a buffer that receives the encryption output. + @param[out] DataOutSize Size of the output data buffer in bytes. + + @retval TRUE AEAD AES-GCM authenticated encryption succeeded. + @retval FALSE AEAD AES-GCM authenticated encryption failed. +**/ +BOOLEAN +EFIAPI +ArmCcaBootSyncCryptoEncrypt ( + IN CONST UINT8 *Key, + IN UINTN KeySize, + IN CONST UINT8 *Iv, + IN UINTN IvSize, + IN CONST UINT8 *AData, + IN UINTN ADataSize, + IN CONST UINT8 *DataIn, + IN UINTN DataInSize, + OUT UINT8 *TagOut, + IN UINTN TagSize, + OUT UINT8 *DataOut, + OUT UINTN *DataOutSize + ); + +/** + Performs AEAD AES-GCM authenticated decryption on a data buffer and + additional authenticated data (AAD). + + IvSize must be 12, otherwise FALSE is returned. + KeySize must be 16, 24 or 32, otherwise FALSE is returned. + TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned. + If additional authenticated data verification fails, FALSE is returned. + + @param[in] Key Pointer to the encryption key. + @param[in] KeySize Size of the encryption key in bytes. + @param[in] Iv Pointer to the IV value. + @param[in] IvSize Size of the IV value in bytes. + @param[in] AData Pointer to the additional authenticated data (AAD). + @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes. + @param[in] DataIn Pointer to the input data buffer to be decrypted. + @param[in] DataInSize Size of the input data buffer in bytes. + @param[in] Tag Pointer to a buffer that contains the authentication tag. + @param[in] TagSize Size of the authentication tag in bytes. + @param[out] DataOut Pointer to a buffer that receives the decryption output. + @param[out] DataOutSize Size of the output data buffer in bytes. + + @retval TRUE AEAD AES-GCM authenticated decryption succeeded. + @retval FALSE AEAD AES-GCM authenticated decryption failed. +**/ +BOOLEAN +EFIAPI +ArmCcaBootSyncCryptoDecrypt ( + IN CONST UINT8 *Key, + IN UINTN KeySize, + IN CONST UINT8 *Iv, + IN UINTN IvSize, + IN CONST UINT8 *AData, + IN UINTN ADataSize, + IN CONST UINT8 *DataIn, + IN UINTN DataInSize, + IN CONST UINT8 *Tag, + IN UINTN TagSize, + OUT UINT8 *DataOut, + OUT UINTN *DataOutSize + ); + +/** + Perform initialisation required for cryptographic operations. + + Note: This API must be called once before any other APIs in this library + are used. + + @retval EFI_ABORTED Failed to generate seed. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoInit ( + VOID + ); diff --git a/ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCrypto.h b/ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCrypto.h new file mode 100644 index 0000000000..f75eff291f --- /dev/null +++ b/ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCrypto.h @@ -0,0 +1,37 @@ +/** @file + Boot Sync Crypto definitions. + + Copyright (c) 2024, Arm Limited. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - BS - Boot Sync + + @par Reference(s): + - Realm Host Interface (RHI) Specification, version 1.0-alp0 + (https://developer.arm.com/documentation/den0148/) +**/ + +#pragma once + +/** + A structure for storing the cryptographic key context and associated + parameters and data. +*/ +typedef struct ArmCcaBootSyncKeyContext { + /// Pointer to the key context. + VOID *EcContext; + /// Cryptographic curve Nid. + UINTN EcCurveNid; + /// Pointer to the public key. + UINT8 *PublicKey; + /// Public key size + UINTN PublicKeySize; + /// Pointer to the Common key. + UINT8 *CommonKey; + /// Common key size. + UINTN CommonKeySize; +} ARM_CCA_BOOTSYNC_KEY_CONTEXT; + +// For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y. +#define ECC_CURVE_P384_PUB_KEY_SIZE 96 diff --git a/ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCryptoLib.c b/ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCryptoLib.c new file mode 100644 index 0000000000..cbc6ebe7fc --- /dev/null +++ b/ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCryptoLib.c @@ -0,0 +1,614 @@ +/** @file + Arm CCA Boot Sync Crypto library. + + Copyright (c) 2024, Arm Limited. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - BS - Boot Sync + + @par Reference(s): + - Realm Host Interface (RHI) Specification, version 1.0-alp0 + (https://developer.arm.com/documentation/den0148/) +**/ + +#include <Base.h> +#include <Library/BaseLib.h> +#include <Library/BaseCryptLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/PrintLib.h> +#include <Library/RngLib.h> + +#include "ArmCcaBootSyncCrypto.h" + +/** + Generate a 256-bit random number as initial seed and + prime the pseudo-random number generator. + + @retval EFI_ABORTED Failed to generate seed. + @retval EFI_SUCCESS Success. +**/ +STATIC +EFI_STATUS +EFIAPI +ArmCcaInitRandomNumberSeed ( + VOID + ) +{ + UINT64 RngSeed[4]; + + ZeroMem (RngSeed, sizeof (RngSeed)); + // Generate a 256 bit random number as an inital seed. + if (!GetRandomNumber128 (RngSeed)) { + return EFI_ABORTED; + } + + if (!GetRandomNumber128 (&RngSeed[2])) { + return EFI_ABORTED; + } + + // Prime the pseudo-random number generator with the initial seed. + if (!RandomSeed ((UINT8 *)RngSeed, 32)) { + return EFI_ABORTED; + } + + return EFI_SUCCESS; +} + +/** + Generate an ECDH key using the ECC Curve-P384 and retrive the public key. + + @param[out] Context Pointer to the key handle. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval EFI_ABORTED An operation failed. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoGenerateKey ( + OUT VOID **Context + ) +{ + BOOLEAN Result; + EFI_STATUS Status; + + ARM_CCA_BOOTSYNC_KEY_CONTEXT *BsKey; + VOID *EcContext; + UINT8 *PublicKey; + UINTN PublicKeySize; + UINTN EcCurveNid; + + if (Context == NULL) { + return EFI_INVALID_PARAMETER; + } + + BsKey = (ARM_CCA_BOOTSYNC_KEY_CONTEXT *)AllocateZeroPool ( + sizeof (ARM_CCA_BOOTSYNC_KEY_CONTEXT) + ); + if (BsKey == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // Arm CCA Security Model document section '12.3.1 Recommended parameter + // sizes' recommends using ECC Curve-P384 + EcCurveNid = CRYPTO_NID_SECP384R1; + + EcContext = EcNewByNid (EcCurveNid); + if (EcContext == NULL) { + Status = EFI_ABORTED; + goto exit_handler; + } + + PublicKeySize = ECC_CURVE_P384_PUB_KEY_SIZE; + PublicKey = (UINT8 *)AllocateZeroPool (PublicKeySize); + if (PublicKey == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto exit_handler1; + } + + Result = EcGenerateKey ( + EcContext, + PublicKey, + &PublicKeySize + ); + if (!Result) { + Status = EFI_ABORTED; + goto exit_handler2; + } + + BsKey->EcContext = EcContext; + BsKey->PublicKey = PublicKey; + BsKey->PublicKeySize = PublicKeySize; + BsKey->EcCurveNid = EcCurveNid; + + *Context = BsKey; + return EFI_SUCCESS; + +exit_handler2: + FreePool (PublicKey); +exit_handler1: + EcFree (EcContext); +exit_handler: + FreePool (BsKey); + return Status; +} + +/** + Delete the key and associated data. + + @param[in] Context Pointer to the key handle. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoDeleteKey ( + VOID *Context + ) +{ + ARM_CCA_BOOTSYNC_KEY_CONTEXT *BsKey; + + if (Context == NULL) { + return EFI_INVALID_PARAMETER; + } + + BsKey = (ARM_CCA_BOOTSYNC_KEY_CONTEXT *)Context; + + if (BsKey->PublicKey != NULL) { + ZeroMem (BsKey->PublicKey, BsKey->PublicKeySize); + FreePool (BsKey->PublicKey); + } + + if (BsKey->CommonKey != NULL) { + ZeroMem (BsKey->CommonKey, BsKey->CommonKeySize); + FreePool (BsKey->CommonKey); + } + + if (BsKey->EcContext != NULL) { + EcFree (BsKey->EcContext); + } + + FreePool (BsKey); + return EFI_SUCCESS; +} + +/** + Get the public key in PEM format. + + Note: The caller is responsible to free the PubKeyPem buffer + by calling FreePool(). + + @param[in] Context Pointer to the key handle. + @param[out] PubKeyPem Pointer to store the PEM data. + @param[out] PubKeyPemSize PEM data size. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval EFI_ABORTED An operation failed. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoGetPublicKey ( + IN VOID *Context, + OUT UINT8 **PubKeyPem, + OUT UINTN *PubKeyPemSize + ) +{ + BOOLEAN Result; + EFI_STATUS Status; + + ARM_CCA_BOOTSYNC_KEY_CONTEXT *BsKey; + UINT8 *PemData; + UINTN PemSize; + + if ((Context == NULL) || (PubKeyPem == NULL) || (PubKeyPemSize == NULL)) { + return EFI_INVALID_PARAMETER; + } + + BsKey = (ARM_CCA_BOOTSYNC_KEY_CONTEXT *)Context; + + // First get the PEM size. + PemData = NULL; + PemSize = 0; + Result = EcPublicKeyToPEM ( + BsKey->EcContext, + PemData, + &PemSize + ); + if ((!Result) && (PemSize == 0)) { + return EFI_ABORTED; + } + + PemData = AllocateZeroPool (PemSize); + if (PemData == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Result = EcPublicKeyToPEM ( + BsKey->EcContext, + PemData, + &PemSize + ); + if (!Result) { + Status = EFI_ABORTED; + goto exit_handler; + } + + *PubKeyPem = PemData; + *PubKeyPemSize = PemSize; + return EFI_SUCCESS; + +exit_handler: + FreePool (PemData); + return Status; +} + +/** + Get the peer key using the peer public PEM data. + + Note: The caller is responsible for freeing the peer key by calling + ArmCcaBootSyncCryptoDeleteKey() for the PeerContext. + + @param[out] PeerContext Pointer to the peer key handle. + @param[in] PeerPubKeyPem Pointer to the peer PEM data. + @param[in] PeerPubKeyPemSize PEM data size. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval EFI_ABORTED An operation failed. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoGeneratePeerKey ( + OUT VOID **PeerContext, + IN UINT8 *PeerPubKeyPem, + IN UINTN PeerPubKeyPemSize + ) +{ + BOOLEAN Result; + EFI_STATUS Status; + + ARM_CCA_BOOTSYNC_KEY_CONTEXT *BsKey; + VOID *EcContextRetrieved; + UINT8 *PublicKey; + UINTN PublicKeySize; + UINTN PeerKeyNid; + + if ((PeerContext == NULL) || + (PeerPubKeyPem == NULL) || + (PeerPubKeyPemSize == 0)) + { + return EFI_INVALID_PARAMETER; + } + + BsKey = (ARM_CCA_BOOTSYNC_KEY_CONTEXT *)AllocateZeroPool ( + sizeof (ARM_CCA_BOOTSYNC_KEY_CONTEXT) + ); + if (BsKey == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Result = EcGetPublicKeyFromPem ( + PeerPubKeyPem, + PeerPubKeyPemSize, + NULL, + &EcContextRetrieved + ); + if (!Result) { + Status = EFI_ABORTED; + goto exit_handler; + } + + Result = EcGetCurveNid (EcContextRetrieved, &PeerKeyNid); + if ((!Result) || (PeerKeyNid != CRYPTO_NID_SECP384R1)) { + Status = EFI_INVALID_PARAMETER; + goto exit_handler1; + } + + PublicKeySize = ECC_CURVE_P384_PUB_KEY_SIZE; + PublicKey = AllocateZeroPool (PublicKeySize); + if (PublicKey == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto exit_handler1; + } + + Result = EcGetPubKey ( + EcContextRetrieved, + PublicKey, + &PublicKeySize + ); + if (!Result) { + Status = EFI_ABORTED; + goto exit_handler2; + } + + BsKey->EcContext = EcContextRetrieved; + BsKey->PublicKey = PublicKey; + BsKey->PublicKeySize = PublicKeySize; + BsKey->EcCurveNid = CRYPTO_NID_SECP384R1; + + *PeerContext = BsKey; + return EFI_SUCCESS; + +exit_handler2: + FreePool (PublicKey); +exit_handler1: + EcFree (EcContextRetrieved); +exit_handler: + FreePool (BsKey); + return Status; +} + +/** + Generate the common key. + + Note: The common key is freed when the caller frees the Context + by calling ArmCcaBootSyncCryptoDeleteKey(). + + @param[in] Context Pointer to the key handle. + @param[in] PeerContext Pointer to the peer key handle. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval EFI_ABORTED An operation failed. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoGenerateCommonKey ( + IN VOID *Context, + IN VOID *PeerContext + ) +{ + BOOLEAN Result; + EFI_STATUS Status; + + ARM_CCA_BOOTSYNC_KEY_CONTEXT *BsKey; + ARM_CCA_BOOTSYNC_KEY_CONTEXT *BsKeyPeer; + UINT8 *CommKey; + UINTN CommKeySize; + + if ((Context == NULL) || + (PeerContext == NULL)) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + BsKey = (ARM_CCA_BOOTSYNC_KEY_CONTEXT *)Context; + BsKeyPeer = (ARM_CCA_BOOTSYNC_KEY_CONTEXT *)PeerContext; + + if ((BsKey->CommonKey != NULL) || + (BsKey->CommonKeySize != 0)) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + CommKeySize = ECC_CURVE_P384_PUB_KEY_SIZE; + CommKey = (UINT8 *)AllocateZeroPool (CommKeySize); + if (CommKey == NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + Result = EcDhComputeKey ( + BsKey->EcContext, + BsKeyPeer->PublicKey, + BsKeyPeer->PublicKeySize, + NULL, + CommKey, + &CommKeySize + ); + if (!Result) { + Status = EFI_ABORTED; + ASSERT (0); + goto exit_handler; + } + + BsKey->CommonKey = CommKey; + BsKey->CommonKeySize = CommKeySize; + return EFI_SUCCESS; + +exit_handler: + FreePool (CommKey); + return Status; +} + +/** + Derive keys using SHA512 HMAC-based Extract-and-Expand Key + Derivation Function (HKDF). + + @param[in] Context Pointer to the key handle. + @param[in] Salt Pointer to the salt(non-secret) value. + @param[in] SaltSize Salt size in bytes. + @param[in] Info Pointer to the application specific info. + @param[in] InfoSize Info size in bytes. + @param[out] Out Pointer to buffer to receive hkdf value. + @param[in] OutSize Size of hkdf bytes to generate. + + @retval TRUE Key derevation successful. + @retval FALSE Key derevation failed. +**/ +BOOLEAN +EFIAPI +ArmCcaBootSyncCryptoDeriveKey ( + IN VOID *Context, + IN CONST UINT8 *Salt, + IN UINTN SaltSize, + IN CONST UINT8 *Info, + IN UINTN InfoSize, + OUT UINT8 *Out, + IN UINTN OutSize + ) +{ + ARM_CCA_BOOTSYNC_KEY_CONTEXT *BsKey; + + if ((Context == NULL) || + (Salt == NULL) || + (Info == NULL) || + (Out == NULL)) + { + return FALSE; + } + + BsKey = (ARM_CCA_BOOTSYNC_KEY_CONTEXT *)Context; + + if ((BsKey->CommonKey == NULL) || + (BsKey->CommonKeySize == 0)) + { + return FALSE; + } + + // Derive SHA512 HMAC-based Extract-and-Expand Key Derivation Function (HKDF). + return HkdfSha512ExtractAndExpand ( + BsKey->CommonKey, + BsKey->CommonKeySize, + Salt, + SaltSize, + Info, + InfoSize, + Out, + OutSize + ); +} + +/** + Performs AEAD AES-GCM authenticated encryption on a data buffer and + additional authenticated data (AAD). + + IvSize must be 12, otherwise FALSE is returned. + KeySize must be 16, 24 or 32, otherwise FALSE is returned. + TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned. + + @param[in] Key Pointer to the encryption key. + @param[in] KeySize Size of the encryption key in bytes. + @param[in] Iv Pointer to the IV value. + @param[in] IvSize Size of the IV value in bytes. + @param[in] AData Pointer to the additional authenticated data (AAD). + @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes. + @param[in] DataIn Pointer to the input data buffer to be encrypted. + @param[in] DataInSize Size of the input data buffer in bytes. + @param[out] TagOut Pointer to a buffer that receives the authentication tag output. + @param[in] TagSize Size of the authentication tag in bytes. + @param[out] DataOut Pointer to a buffer that receives the encryption output. + @param[out] DataOutSize Size of the output data buffer in bytes. + + @retval TRUE AEAD AES-GCM authenticated encryption succeeded. + @retval FALSE AEAD AES-GCM authenticated encryption failed. +**/ +BOOLEAN +EFIAPI +ArmCcaBootSyncCryptoEncrypt ( + IN CONST UINT8 *Key, + IN UINTN KeySize, + IN CONST UINT8 *Iv, + IN UINTN IvSize, + IN CONST UINT8 *AData, + IN UINTN ADataSize, + IN CONST UINT8 *DataIn, + IN UINTN DataInSize, + OUT UINT8 *TagOut, + IN UINTN TagSize, + OUT UINT8 *DataOut, + OUT UINTN *DataOutSize + ) +{ + return AeadAesGcmEncrypt ( + Key, + KeySize, + Iv, + IvSize, + AData, + ADataSize, + DataIn, + DataInSize, + TagOut, + TagSize, + DataOut, + DataOutSize + ); +} + +/** + Performs AEAD AES-GCM authenticated decryption on a data buffer and + additional authenticated data (AAD). + + IvSize must be 12, otherwise FALSE is returned. + KeySize must be 16, 24 or 32, otherwise FALSE is returned. + TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned. + If additional authenticated data verification fails, FALSE is returned. + + @param[in] Key Pointer to the encryption key. + @param[in] KeySize Size of the encryption key in bytes. + @param[in] Iv Pointer to the IV value. + @param[in] IvSize Size of the IV value in bytes. + @param[in] AData Pointer to the additional authenticated data (AAD). + @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes. + @param[in] DataIn Pointer to the input data buffer to be decrypted. + @param[in] DataInSize Size of the input data buffer in bytes. + @param[in] Tag Pointer to a buffer that contains the authentication tag. + @param[in] TagSize Size of the authentication tag in bytes. + @param[out] DataOut Pointer to a buffer that receives the decryption output. + @param[out] DataOutSize Size of the output data buffer in bytes. + + @retval TRUE AEAD AES-GCM authenticated decryption succeeded. + @retval FALSE AEAD AES-GCM authenticated decryption failed. +**/ +BOOLEAN +EFIAPI +ArmCcaBootSyncCryptoDecrypt ( + IN CONST UINT8 *Key, + IN UINTN KeySize, + IN CONST UINT8 *Iv, + IN UINTN IvSize, + IN CONST UINT8 *AData, + IN UINTN ADataSize, + IN CONST UINT8 *DataIn, + IN UINTN DataInSize, + IN CONST UINT8 *Tag, + IN UINTN TagSize, + OUT UINT8 *DataOut, + OUT UINTN *DataOutSize + ) +{ + return AeadAesGcmDecrypt ( + Key, + KeySize, + Iv, + IvSize, + AData, + ADataSize, + DataIn, + DataInSize, + Tag, + TagSize, + DataOut, + DataOutSize + ); +} + +/** + Perform initialisation required for cryptographic operations. + + Note: This API must be called once before any other APIs in this library + are used. + + @retval EFI_ABORTED Failed to generate seed. + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +EFIAPI +ArmCcaBootSyncCryptoInit ( + VOID + ) +{ + return ArmCcaInitRandomNumberSeed (); +} diff --git a/ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCryptoLib.inf b/ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCryptoLib.inf new file mode 100644 index 0000000000..569aa948ff --- /dev/null +++ b/ArmVirtPkg/Library/ArmCcaBootSyncCryptoLib/ArmCcaBootSyncCryptoLib.inf @@ -0,0 +1,33 @@ +## @file +# Library that implements the Boot Sync Crypto interfaces. +# +# Copyright (c) 2024, Arm Limited. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = ArmCcaBootSyncCryptoLib + FILE_GUID = 234394BC-1D5D-4F6D-A890-259B166BCF0A + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmCcaBootSyncCryptoLib + +[Sources] + ArmCcaBootSyncCrypto.h + ArmCcaBootSyncCryptoLib.c + +[Packages] + ArmVirtPkg/ArmVirtPkg.dec + CryptoPkg/CryptoPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseCryptLib + BaseLib + BaseMemoryLib + DebugLib + RngLib + MemoryAllocationLib From 08dd5e921c26ad819bbf05a71b2f83bf5223f88c Mon Sep 17 00:00:00 2001 From: Rebecca Cran <rebecca@bsdio.com> Date: Wed, 24 Jun 2026 18:05:24 -0600 Subject: [PATCH 251/406] ArmPkg: Add SMBIOS Type 4 SocketType handling The SMBIOS Type 4 field SocketType was added in commit 7f505d377b44aeee59f34b3d898f6caf0a0df538 in 2024. This caused the table size to be invalid when platforms specify versions of SMBIOS before 3.8. Update ProcessorSubClassDxe to handle fetching the string for the socket type including calling into OemMiscLib to retrieve it. Signed-off-by: Rebecca Cran <rebecca@bsdio.com> --- ArmPkg/ArmPkg.dec | 1 + ArmPkg/Include/Library/OemMiscLib.h | 1 + .../ProcessorSubClassDxe/ProcessorSubClass.c | 29 +++++++++++++++++-- .../ProcessorSubClassDxe.inf | 1 + .../ProcessorSubClassStrings.uni | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index 7f869f03e7..67ce5ff1a6 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -166,6 +166,7 @@ gArmTokenSpaceGuid.PcdProcessorSerialNumber|L""|VOID*|0x30000073 gArmTokenSpaceGuid.PcdProcessorAssetTag|L""|VOID*|0x30000074 gArmTokenSpaceGuid.PcdProcessorPartNumber|L""|VOID*|0x30000075 + gArmTokenSpaceGuid.PcdProcessorSocketType|L""|VOID*|0x30000076 # # ARM L2x0 PCDs diff --git a/ArmPkg/Include/Library/OemMiscLib.h b/ArmPkg/Include/Library/OemMiscLib.h index 240e0307ec..054e82fa98 100644 --- a/ArmPkg/Include/Library/OemMiscLib.h +++ b/ArmPkg/Include/Library/OemMiscLib.h @@ -60,6 +60,7 @@ typedef enum { ProcessorPartNumType04, ProcessorSerialNumType04, ProcessorVersionType04, + ProcessorSocketTypeType04, SmbiosHiiStringFieldMax } OEM_MISC_SMBIOS_HII_STRING_FIELD; diff --git a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c index b49caaab45..416e6fb166 100644 --- a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c +++ b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c @@ -104,7 +104,9 @@ SMBIOS_TABLE_TYPE4 mSmbiosProcessorTableTemplate = { ProcessorFamilyARM, // ProcessorFamily2 0, // CoreCount2 0, // EnabledCoreCount2 - 0 // ThreadCount2 + 0, // ThreadCount2 + 0, // ThreadEnabled + 7 // SocketType }; /** Sets the HII variable `StringId` is `Pcd` isn't empty. @@ -495,12 +497,14 @@ AllocateType4AndSetProcessorInformationStrings ( EFI_STRING_ID SerialNumber; EFI_STRING_ID AssetTag; EFI_STRING_ID PartNumber; + EFI_STRING_ID SocketType; EFI_STRING ProcessorStr; EFI_STRING ProcessorManuStr; EFI_STRING ProcessorVersionStr; EFI_STRING SerialNumberStr; EFI_STRING AssetTagStr; EFI_STRING PartNumberStr; + EFI_STRING SocketTypeStr; CHAR8 *OptionalStrStart; CHAR8 *StrStart; UINTN ProcessorStrLen; @@ -509,6 +513,7 @@ AllocateType4AndSetProcessorInformationStrings ( UINTN SerialNumberStrLen; UINTN AssetTagStrLen; UINTN PartNumberStrLen; + UINTN SocketTypeStrLen; UINTN TotalSize; UINTN StringBufferSize; @@ -519,12 +524,14 @@ AllocateType4AndSetProcessorInformationStrings ( SerialNumberStr = NULL; AssetTagStr = NULL; PartNumberStr = NULL; + SocketTypeStr = NULL; ProcessorManu = STRING_TOKEN (STR_PROCESSOR_MANUFACTURE); ProcessorVersion = STRING_TOKEN (STR_PROCESSOR_VERSION); SerialNumber = STRING_TOKEN (STR_PROCESSOR_SERIAL_NUMBER); AssetTag = STRING_TOKEN (STR_PROCESSOR_ASSET_TAG); PartNumber = STRING_TOKEN (STR_PROCESSOR_PART_NUMBER); + SocketType = STRING_TOKEN (STR_PROCESSOR_SOCKET_TYPE); SET_HII_STRING_IF_PCD_NOT_EMPTY (PcdProcessorManufacturer, ProcessorManu); SET_HII_STRING_IF_PCD_NOT_EMPTY (PcdProcessorAssetTag, AssetTag); @@ -547,6 +554,12 @@ AllocateType4AndSetProcessorInformationStrings ( OemUpdateSmbiosInfo (mHiiHandle, ProcessorVersion, ProcessorVersionType04); } + if (StrLen ((CHAR16 *)FixedPcdGetPtr (PcdProcessorSocketType)) > 0) { + HiiSetString (mHiiHandle, SocketType, (CHAR16 *)FixedPcdGetPtr (PcdProcessorSocketType), NULL); + } else { + OemUpdateSmbiosInfo (mHiiHandle, SocketType, ProcessorSocketTypeType04); + } + // Processor Designation StringBufferSize = sizeof (CHAR16) * SMBIOS_STRING_MAX_LENGTH; ProcessorStr = AllocateZeroPool (StringBufferSize); @@ -581,13 +594,17 @@ AllocateType4AndSetProcessorInformationStrings ( PartNumberStr = HiiGetPackageString (&gEfiCallerIdGuid, PartNumber, NULL); PartNumberStrLen = StrLen (PartNumberStr); + SocketTypeStr = HiiGetPackageString (&gEfiCallerIdGuid, SocketType, NULL); + SocketTypeStrLen = StrLen (SocketTypeStr); + TotalSize = sizeof (SMBIOS_TABLE_TYPE4) + ProcessorStrLen + 1 + ProcessorManuStrLen + 1 + ProcessorVersionStrLen + 1 + SerialNumberStrLen + 1 + AssetTagStrLen + 1 + - PartNumberStrLen + 1 + 1; + PartNumberStrLen + 1 + + SocketTypeStrLen + 1 + 1; *Type4Record = AllocateZeroPool (TotalSize); if (*Type4Record == NULL) { @@ -639,6 +656,13 @@ AllocateType4AndSetProcessorInformationStrings ( PartNumberStrLen + 1 ); + StrStart += PartNumberStrLen + 1; + UnicodeStrToAsciiStrS ( + SocketTypeStr, + StrStart, + SocketTypeStrLen + 1 + ); + Exit: FreePool (ProcessorStr); FreePool (ProcessorManuStr); @@ -646,6 +670,7 @@ Exit: FreePool (SerialNumberStr); FreePool (AssetTagStr); FreePool (PartNumberStr); + FreePool (SocketTypeStr); return Status; } diff --git a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassDxe.inf b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassDxe.inf index 939efe6553..79d20399c6 100644 --- a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassDxe.inf +++ b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassDxe.inf @@ -55,6 +55,7 @@ gArmTokenSpaceGuid.PcdProcessorSerialNumber gArmTokenSpaceGuid.PcdProcessorAssetTag gArmTokenSpaceGuid.PcdProcessorPartNumber + gArmTokenSpaceGuid.PcdProcessorSocketType [Guids] diff --git a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassStrings.uni b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassStrings.uni index c67706ecd1..fd6d80cd1d 100644 --- a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassStrings.uni +++ b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassStrings.uni @@ -21,4 +21,5 @@ #string STR_PROCESSOR_SERIAL_NUMBER #language en-US "Not Specified" #string STR_PROCESSOR_ASSET_TAG #language en-US "Not Specified" #string STR_PROCESSOR_PART_NUMBER #language en-US "Not Specified" +#string STR_PROCESSOR_SOCKET_TYPE #language en-US "Not Specified" #string STR_PROCESSOR_UNKNOWN #language en-US "Unknown" From 97665a4ef0ee378bbf3db5375188a6e413c479c4 Mon Sep 17 00:00:00 2001 From: Rebecca Cran <rebecca@bsdio.com> Date: Wed, 24 Jun 2026 18:08:13 -0600 Subject: [PATCH 252/406] MdeModulePkg: Bump the default SMBIOS version to 3.8 Commit 7f505d377b44aeee59f34b3d898f6caf0a0df538 in 2024 added the Type 4 field SocketType. Bump the default SMBIOS version to 3.8 in order for the larger table size to be valid. Signed-off-by: Rebecca Cran <rebecca@bsdio.com> --- MdeModulePkg/MdeModulePkg.dec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index c817a32b81..f6b1a73d70 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -2105,7 +2105,7 @@ ## SMBIOS version. # @Prompt SMBIOS version. - gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion|0x0303|UINT16|0x00010055 + gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion|0x0308|UINT16|0x00010055 ## SMBIOS Docrev field in SMBIOS 3.0 (64-bit) Entry Point Structure. # @Prompt SMBIOS Docrev field in SMBIOS 3.0 (64-bit) Entry Point Structure. From c5e42e79428ef736a975909bba042d9504c6c47e Mon Sep 17 00:00:00 2001 From: Sunil V L <sunilvl@oss.qualcomm.com> Date: Fri, 24 Apr 2026 09:59:32 +0530 Subject: [PATCH 253/406] DynamicTablesPkg/RiscV: Fix ISA string copy in RiscVIntcParser The IsaStringInfoParser() routine currently sets the ISA string length to PropSize + 1 and used AsciiStrCpyS() with PropSize + 1 as the destination size. This could lead to incorrect length handling and potential buffer issues. Update the code to: - Set IsaStringInfo.Length to PropSize (actual property size). - Use MAX_ISA_STRING_LENGTH as the destination buffer size when copying the ISA string. - Check the return status of AsciiStrCpyS() and abort with an error message if the copy fails. This ensures safe string handling and prevents buffer overflow or truncation when parsing ISA strings. Reported-by: Zhenyu Liu <lzy00419@outlook.com> Signed-off-by: Sunil V L <sunilvl@oss.qualcomm.com> --- .../FdtHwInfoParserLib/RiscV/Intc/RiscVIntcParser.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/RiscV/Intc/RiscVIntcParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/RiscV/Intc/RiscVIntcParser.c index 6619e6ee79..caad27a645 100644 --- a/DynamicTablesPkg/Library/FdtHwInfoParserLib/RiscV/Intc/RiscVIntcParser.c +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/RiscV/Intc/RiscVIntcParser.c @@ -225,8 +225,13 @@ IsaStringInfoParser ( return EFI_ABORTED; } - IsaStringInfo.Length = PropSize + 1; - AsciiStrCpyS (IsaStringInfo.IsaString, PropSize + 1, (CHAR8 *)Prop); + IsaStringInfo.Length = PropSize; + Status = AsciiStrCpyS (IsaStringInfo.IsaString, MAX_ISA_STRING_LENGTH, (CHAR8 *)Prop); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to copy ISA string\n")); + ASSERT (0); + return EFI_ABORTED; + } // Add the CmObj to the Configuration Manager. Status = AddSingleCmObj ( From f539e44fe447e980aa608111716f64030bbb3934 Mon Sep 17 00:00:00 2001 From: Sunil V L <sunilvl@oss.qualcomm.com> Date: Mon, 20 Jul 2026 10:24:34 +0530 Subject: [PATCH 254/406] DynamicTablesPkg/RiscV: Fix unused variables warnings Either use the variables or get rid of them. Signed-off-by: Sunil V L <sunilvl@oss.qualcomm.com> --- .../Library/Acpi/RiscV/AcpiRhctLibRiscV/RhctGenerator.c | 5 +++++ .../FdtHwInfoParserLib/RiscV/Intc/RiscVIntcParser.c | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/DynamicTablesPkg/Library/Acpi/RiscV/AcpiRhctLibRiscV/RhctGenerator.c b/DynamicTablesPkg/Library/Acpi/RiscV/AcpiRhctLibRiscV/RhctGenerator.c index 5fbd04b814..e4b5b2d5ca 100644 --- a/DynamicTablesPkg/Library/Acpi/RiscV/AcpiRhctLibRiscV/RhctGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/RiscV/AcpiRhctLibRiscV/RhctGenerator.c @@ -503,6 +503,11 @@ AddIsaStringNodes ( IsaLength, NodeList->IsaString ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + IsaStringNode = (EFI_ACPI_6_6_RHCT_ISA_STRING_NODE *)((CHAR8 *)IsaStringNode + NodeLength); NodeList++; } diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/RiscV/Intc/RiscVIntcParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/RiscV/Intc/RiscVIntcParser.c index caad27a645..4376ce1270 100644 --- a/DynamicTablesPkg/Library/FdtHwInfoParserLib/RiscV/Intc/RiscVIntcParser.c +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/RiscV/Intc/RiscVIntcParser.c @@ -945,6 +945,11 @@ PlicAplicInfoParser ( ); } + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + Id++; } @@ -1095,7 +1100,6 @@ ImsicGetInfo ( CONST UINT64 *Prop; INT32 Len; INT32 NumPhandle; - UINTN NumImsicBase; if (ImsicInfo == NULL) { ASSERT (0); @@ -1172,7 +1176,6 @@ ImsicGetInfo ( return EFI_INVALID_PARAMETER; } - NumImsicBase = (Len / sizeof (UINT32)) / 4; if (ImsicInfo->HartIndexBits == 0) { Len = NumPhandle; while (Len > 0) { @@ -1286,14 +1289,12 @@ RiscVIntcInfoParser ( { CM_OBJ_DESCRIPTOR *NewCmObjDesc; EFI_STATUS Status; - VOID *Fdt; if (FdtParserHandle == NULL) { ASSERT (0); return EFI_INVALID_PARAMETER; } - Fdt = FdtParserHandle->Fdt; NewCmObjDesc = NULL; // Parse the "cpus" nodes and its children "cpu" nodes, From a933771361883455245d42e8c77fe7a0ed7eb083 Mon Sep 17 00:00:00 2001 From: Jared Pan <jared.pan@dell.com> Date: Tue, 23 Jun 2026 17:01:17 +0800 Subject: [PATCH 255/406] UefiPayloadPkg/DxeHobLib: Add lazy initialization for gHobList This change adds dynamic initialization of gHobList in GetHobList() to handle cases where library constructors are executed before DxeHobListLibConstructor. Issue: On ARM platforms using ArmMmuBaseLib, the ArmMmuBaseLibConstructor calls GetFirstGuidHob() before xeHobListLibConstructor has initialized gHobList, causing an ASSERT. Root Cause: ArmMmuBaseLib's constructor uses HobLib functions, but UefiPayloadPkg's DxeHobLib assumes gHobList is already initialized by DxeHobListLib's constructor. Solution: Add the same lazy initialization pattern already used in MdePkg/Library/DxeHobLib, which dynamically retrieves the HOB list from the System Configuration Table if gHobList is NULL. This change: - Aligns behavior with MdePkg/Library/DxeHobLib - Has no impact on existing functionality - Improves robustness for ARM platforms Signed-off-by: Jared Pan <jared.pan@dell.com> --- UefiPayloadPkg/Library/DxeHobLib/DxeHobLib.inf | 3 +++ UefiPayloadPkg/Library/DxeHobLib/HobLib.c | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/UefiPayloadPkg/Library/DxeHobLib/DxeHobLib.inf b/UefiPayloadPkg/Library/DxeHobLib/DxeHobLib.inf index ff334a0d41..ce6171a556 100644 --- a/UefiPayloadPkg/Library/DxeHobLib/DxeHobLib.inf +++ b/UefiPayloadPkg/Library/DxeHobLib/DxeHobLib.inf @@ -29,8 +29,11 @@ MdePkg/MdePkg.dec UefiPayloadPkg/UefiPayloadPkg.dec +[Guids] + gEfiHobListGuid [LibraryClasses] + UefiLib BaseMemoryLib DebugLib DxeHobListLib diff --git a/UefiPayloadPkg/Library/DxeHobLib/HobLib.c b/UefiPayloadPkg/Library/DxeHobLib/HobLib.c index 757be5b8dc..2cfcd3d81b 100644 --- a/UefiPayloadPkg/Library/DxeHobLib/HobLib.c +++ b/UefiPayloadPkg/Library/DxeHobLib/HobLib.c @@ -12,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/DebugLib.h> #include <Library/BaseMemoryLib.h> #include <Library/DxeHobListLib.h> +#include <Library/UefiLib.h> /** Returns the pointer to the HOB list. @@ -35,7 +36,13 @@ GetHobList ( VOID ) { - ASSERT (gHobList != NULL); + EFI_STATUS Status; + + if (gHobList == NULL) { + Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &gHobList); + ASSERT_EFI_ERROR (Status); + } + return gHobList; } From 0adb357ab7bfe7e5f4df94ea5076f4f5eeb725be Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Mon, 13 Jul 2026 11:19:50 -0400 Subject: [PATCH 256/406] BREAKING-CHANGES.md: Add changes prior to process during 202608 dev period This file was added as part of the new TianoCore EDK II breaking changes process defined in the following RFC: https://github.com/tianocore/tianocore-wiki.github.io/blob/main/rfc/text/0001-rfc-process.md In order to make the file accurate for the upcoming edk2-stable202605 stable tag, this commit adds all breaking changes that have been merged into the master branch since the last stable tag (edk2-stable202605). Because these changes did not follow the full process, they do not have some required information like tracking issues. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- BREAKING-CHANGES.md | 256 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 254 insertions(+), 2 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 6b55e27f40..da10d5a963 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -60,11 +60,111 @@ None - Milestone: [edk2-stable202608](https://github.com/tianocore/edk2/milestone/5) +> Note: The entries below with "N/A" issues were merged during the edk2-stable202608 development period +> (after the `edk2-stable202605 tag`) and before the breaking change process took effect. They therefore have no +> associated GitHub Tracking, Deprecation, or Removal issues. Each entry links to the pull request that introduced +> the change in place of those issues. This is expected to be a one-time occurrence during the transition to the new +> breaking changes process during the `edk2-stable202608` development period. + ### edk2-stable202608: Source-Level Breaking Changes #### edk2-stable202608: Changes with Removal -None +### Breaking Change: AArch64 exception handling relocated from ArmPkg to UefiCpuPkg + +- **Status**: Removed +- **Tracking Issue**: N/A (merged before the breaking change process took effect) +- **Deprecation Issue**: N/A +- **Removal Issue**: N/A +- **Pull Request**: [tianocore/edk2#12340](https://github.com/tianocore/edk2/pull/12340) +- **Type**: Source-Level (Removal) - Library class restructure, API removal, and header file removal + +**What changed**: AArch64 exception handling was moved from `ArmPkg` to `UefiCpuPkg`. `ArmExceptionLib` and +`DefaultExceptionHandlerLib` were merged into `CpuExceptionHandlerLib`, the `DefaultExceptionHandler()` API was renamed +to `DumpCpuContext()`, and the `ArmPkg/Include/Library/DefaultExceptionHandlerLib.h` public header was removed. + +**What is removed**: The `ArmPkg` `ArmExceptionLib` and `DefaultExceptionHandlerLib` library instances, the +`DefaultExceptionHandlerLib.h` public header, and the `DefaultExceptionHandler()` API. + +**Why it changed**: To provide consistent exception handling across all CPU architectures (IA32, X64, LoongArch64, +RISCV64, AARCH64) by unifying on the `UefiCpuPkg` `CpuExceptionHandlerLib`. + +**What replaces it**: The `UefiCpuPkg` `CpuExceptionHandlerLib` (for example, `DxeCpuExceptionHandlerLib.inf`) and the +`DumpCpuContext()` API declared in the `UefiCpuPkg` `CpuExceptionLib.h` interface. + +**How to migrate**: For out-of-tree modules that used `DefaultExceptionHandlerLib`, add `UefiCpuPkg.dec` as a package +dependency and update the platform DSC to map the exception handling library class to `CpuExceptionHandlerLib`. Replace +all `DefaultExceptionHandler()` calls with `DumpCpuContext()`. Remove all references of `ArmExceptionLib` from the DSC +file. + +**Breaking conditions**: Affects AArch64 (ARM) platforms and out-of-tree modules that consumed `ArmExceptionLib`, +`DefaultExceptionHandlerLib`, or the `DefaultExceptionHandler()` API. + +**Earliest removal**: Already removed in this change. The old code was removed in the same PR with no compatibility window. + +### Breaking Change: BaseRiscV64CpuTimerLib renamed and split into SEC and DXE TimerLib instances + +- **Status**: Removed +- **Tracking Issue**: N/A (merged before the breaking change process took effect) +- **Deprecation Issue**: N/A +- **Removal Issue**: N/A +- **Pull Request**: [tianocore/edk2#12210](https://github.com/tianocore/edk2/pull/12210) +- **Type**: Source-Level (Removal) - Library class restructure + +**What changed**: The `UefiCpuPkg` `BaseRiscV64CpuTimerLib` was renamed to `RiscV64CpuTimerLib` and split into two +instances: `RiscV64CpuTimerSecLib.inf` (`MODULE_TYPE` `SEC`, for SEC and PEI, no constructor) and +`RiscV64CpuTimerDxeLib.inf` (for `DXE_CORE`, `DXE_DRIVER`, and other DXE-phase modules, which retains the constructor). +The old `UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf` path was removed. + +**What is removed**: The `BaseRiscV64CpuTimerLib` library instance and its INF path. + +**Why it changed**: The library constructor calls `GetPerformanceCounterProperties()`, which requires the HOB list. In +the SEC and PEI phases the HOB list may not yet be available, causing a crash. Splitting the instances runs the +constructor only in the DXE instance. + +**What replaces it**: The phase-specific instances `RiscV64CpuTimerSecLib.inf` (SEC and PEI) and +`RiscV64CpuTimerDxeLib.inf` (DXE). + +**How to migrate**: Update platform DSC `TimerLib` mappings that referenced +`UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf`. Map `TimerLib` to `RiscV64CpuTimerSecLib.inf` +for SEC and PEI modules and to `RiscV64CpuTimerDxeLib.inf` for DXE modules. + +**Breaking conditions**: Affects RISC-V (RISCV64) platforms that consume the RISC-V CPU timer library. + +**Earliest removal**: Already removed in this change. The old INF path was removed in the same PR with no compatibility +window. + +### Breaking Change: PrePiLib FfsFindSectionDataWithHook and FfsProcessFvFile gain new parameters + +- **Status**: Removed +- **Tracking Issue**: N/A (merged before the breaking change process took effect) +- **Deprecation Issue**: N/A +- **Removal Issue**: N/A +- **Pull Request**: [tianocore/edk2#12672](https://github.com/tianocore/edk2/pull/12672) +- **Type**: Source-Level (Removal) - API signature change + +**What changed**: `EmbeddedPkg` `PrePiLib` API signatures changed to improve FV2/FV3 HOB handling. +`FfsFindSectionDataWithHook()` gained an `AuthenticationStatus` output parameter and `FfsProcessFvFile()` gained a +`ParentVolumeHandle` parameter. In addition, `PrePi.h` dropped duplicate HOB definitions in favor of `HobLib.h`. + +**What is removed**: The previous `FfsFindSectionDataWithHook()` and `FfsProcessFvFile()` function signatures. + +**Why it changed**: To correctly produce FV3 HOBs (which supersede FV2 HOBs) for extracted FVs and to set the FV2 HOB +`FvName` to the parent FV name so DXE does not re-extract already-extracted FVs (a performance hit of approximately one +second on some platforms). Producing the FV3 HOB requires the authentication status from the GUIDed extraction, and +correct FV2 HOB production requires the parent FV handle. + +**What replaces it**: The same functions with the new signatures. + +**How to migrate**: Update callers of `FfsFindSectionDataWithHook()` to pass the new `AuthenticationStatus` argument +(pass `NULL` to retain existing behavior, or a `UINT32 *` to receive the status). Update callers of +`FfsProcessFvFile()` to pass the `ParentVolumeHandle`. + +**Breaking conditions**: Affects modules that call `PrePiLib`'s `FfsFindSectionDataWithHook()` or `FfsProcessFvFile()` +(for example, `EmbeddedPkg` and `OvmfPkg` peiless startup consumers). + +**Earliest removal**: Already removed in this change. The old signatures were replaced in the same PR with no +compatibility window. #### edk2-stable202608: Changes without Removal @@ -98,10 +198,162 @@ instance is provided in-tree (MdeModulePkg/Library/GptLib/GptLib.inf). GptLib|MdeModulePkg/Library/GptLib/GptLib.inf +### Breaking Change: TPM2 helper functions moved to new Tpm2HelpLib library class + +- **Status**: Deprecation Active +- **Tracking Issue**: [tianocore/edk2#12797](https://github.com/tianocore/edk2/issues/12797) +- **Deprecation Issue**: [tianocore/edk2#12799](https://github.com/tianocore/edk2/issues/12799) +- **Pull Request**: [tianocore/edk2#11634](https://github.com/tianocore/edk2/pull/11634) +- **Type**: Source-Level (Non-removal) - Library class dependency addition (single expected instance) + +**What changed**: The TPM2 helper functions in `Tpm2Help.c` were decoupled from `Tpm2CommandLib` into a new standalone +`SecurityPkg` library class, `Tpm2HelpLib`. This allows using the helpers without pulling in `Tpm2CommandLib` and +`Tpm2DeviceLib`, which are tied to TPM communication. In-tree modules (for example, `HashLibBaseCryptoRouter`, +`PeilessSecMeasureLib`, and `TdTcg2Dxe`) were updated to consume `Tpm2HelpLib`. + +**Library class dependency case**: Single expected instance. `SecurityPkg` provides the single recommended instance at +`SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf`, so migration is a DSC library class mapping. + +**Why it changed**: Some callers need the helper functions without TPM communication dependencies. Examples include +generating a HOB for pre-DXE measurements and the SEC phase, where there is no `Tpm2DeviceLib`. + +**What replaces it**: The `Tpm2HelpLib` library class. The helper functions remaining in `Tpm2CommandLib`'s +`Tpm2Help.c` are now deprecated wrappers that delegate to `Tpm2HelpLib`. + +**How to migrate**: Platforms building modules that now depend on `Tpm2HelpLib` must add a mapping in their DSC +(`Tpm2HelpLib|SecurityPkg/Library/Tpm2HelpLib/Tpm2HelpLib.inf`) or the build fails with an unresolved library class. For +code, add `Tpm2HelpLib` to the module INF and include the header, then update calls to the deprecated `Tpm2Help.c` +wrappers in `Tpm2CommandLib` to use the `Tpm2HelpLib` versions. + +**Earliest removal**: The deprecated `Tpm2CommandLib` `Tpm2Help.c` wrappers may be removed in a future stable tag. A +removal stable tag has not been scheduled at this time. + +> Note: GitHub issues were created to track edk2-platforms following migration instructions. +> +> - [Platform/ARM: Switch to Tpm2HelpLib](https://github.com/tianocore/edk2-platforms/issues/994) +> - [Platform/MinPlatformPkg: Switch to Tpm2HelpLib](https://github.com/tianocore/edk2-platforms/issues/995) +> - [Silicon/Ampere/AmpereAltraPkg: Switch to Tpm2HelpLib](https://github.com/tianocore/edk2-platforms/issues/996) + ### edk2-stable202608: Behavioral Breaking Changes None ### edk2-stable202608: Build-System Breaking Changes -None +### Breaking Change: GenFv ForceRebase now honors a per-module Xip flag + +- **Status**: Removed +- **Tracking Issue**: N/A (merged before the breaking change process took effect) +- **Deprecation Issue**: N/A +- **Removal Issue**: N/A +- **Pull Request**: [tianocore/edk2#12551](https://github.com/tianocore/edk2/pull/12551) +- **Type**: Build-System - DSC/INF/DEC syntax change and BaseTools change + +**What changed**: Previously the `GenFv` rebase feature (`ForceRebase=1`, that is `FvForceRebase=TRUE`) was +all-or-nothing: it rebased every eligible FFS file in the firmware volume to the FV base address, with no way to +selectively rebase only XIP modules. A new `Xip=TRUE/FALSE` keyword was added to the FDF `[Rule]` section PE32/TE +section syntax so specific module types can be tagged for XIP rebase. + +```text +[Rule.Common.PEI_CORE] + FILE PEI_CORE = $(NAMED_GUID) { + PE32 PE32 Align=Auto Xip=TRUE $(INF_OUTPUT)/$(MODULE_NAME).efi + } +``` + +When `ForceRebase=1`, `GenFv` now rebases only modules whose type is tagged `Xip=TRUE`; a module type with no `Xip` +keyword defaults to not being rebased. The eligible file types considered for rebase are `SECURITY_CORE`, `PEI_CORE`, +`PEIM`, `COMBINED_PEIM_DRIVER`, `DRIVER`, and `DXE_CORE`. Per-module (rather than per-type) control is available by +defining named `XIP`/`NOXIP` rules and selecting them with `RuleOverride` in the `[FV]` section: + +```text +[Rule.Common.PEIM.XIP] + FILE PEIM = $(NAMED_GUID) { + PE32 PE32 Align=Auto Xip=TRUE $(INF_OUTPUT)/$(MODULE_NAME).efi + } + +[Rule.Common.PEIM.NOXIP] + FILE PEIM = $(NAMED_GUID) { + PE32 PE32 Align=Auto $(INF_OUTPUT)/$(MODULE_NAME).efi + } + +[FV.PEIFV] + INF RuleOverride=XIP MdeModulePkg/Core/Pei/PeiMain.inf + INF RuleOverride=NOXIP SomePkg/SomePeim/SomePeim.inf +``` + +**`FvForceRebase` rebase decision table** + +| FvForceRebase | FvBaseAddress | Xip in any Rule | Result | +| :---: | :---: | :---: | :--- | +| `TRUE` | any | No files have `Xip=TRUE` | Rebase ALL eligible files (legacy) | +| `TRUE` | any | At least one file has `Xip=TRUE` | Rebase ONLY files with `Xip=TRUE` | +| `FALSE` | any | any | No rebase | +| not specified | != 0 | any | Rebase ALL eligible files (legacy) | +| not specified | == 0 or not specified | any | No rebase | + +**Detailed changes**: The pull request description has a detailed explanation of the change and its motivation that +readers may find useful: [tianocore/edk2#12551](https://github.com/tianocore/edk2/pull/12551). + +**Why it changed**: Only XIP (execute-in-place) modules (for example, `PEI_CORE` and `PEIM`) need PE32 address fixups to +their flash location. Rebasing non-XIP modules (for example, `DXE_CORE` and `DRIVER`) is unnecessary and can cause +issues. This provides finer-grained control than the all-or-nothing `ForceRebase`. + +**What replaces it**: The `Xip` keyword in FDF `[Rule]` sections used together with `ForceRebase`. + +**How to migrate**: The selective rebase only activates for an FV once at least one of its `[Rule]` sections uses +`Xip=TRUE`. Platforms that relied on `ForceRebase=1` rebasing all eligible modules and do not use `Xip=TRUE` anywhere +in the FV are unaffected. Platforms adopting selective rebase must add `Xip=TRUE` to the relevant `[Rule]` sections +(for example, the `PEI_CORE` and `PEIM` rules) so those modules continue to be rebased. Module types without +`Xip=TRUE` will not be rebased once any rule in the FV uses `Xip=TRUE`. For per-module rather than per-type control, +define named `XIP`/`NOXIP` rules and select them with `RuleOverride`. + +**Breaking conditions**: The new `Xip` filter only applies when `ForceRebase=1` (`FvForceRebase=TRUE`) **and** at +least one FFS file in the FV is produced by a `[Rule]` section with `Xip=TRUE`. If no rule in the FV uses +`Xip=TRUE`, `ForceRebase=1` continues to rebase all eligible files, matching pre-#12551 behavior. The default +behavior is unchanged: when `ForceRebase` is unspecified with a non-zero FV base address, all eligible files are still +rebased unconditionally and the `Xip` keyword is not consulted. When `ForceRebase=0`, nothing is rebased regardless of +`Xip`. + +**Earliest removal**: Already in effect in this change. The previous "rebase all" behavior was replaced in the same PR +with no compatibility window. + +> Note: [tianocore/edk2#12807](https://github.com/tianocore/edk2/pull/12807) fixed a backward-compatibility +> regression introduced by this change, in which `FvForceRebase=TRUE` stopped rebasing any files in an FV when no +> `[Rule]` section in that FV specified `Xip=TRUE`. The fix tracks the count of `Xip=TRUE` files per FV and only +> enables the selective rebase logic when that count is greater than zero. Otherwise the legacy "rebase all" behavior +> is preserved. The **Breaking conditions** and **How to migrate** guidance above reflect the behavior after this +> fix. + +### Breaking Change: Visual Studio 2015 and 2017 toolchain support removed + +- **Status**: Removed +- **Tracking Issue**: N/A (merged before the breaking change process took effect) +- **Deprecation Issue**: N/A +- **Removal Issue**: N/A +- **Pull Request**: [tianocore/edk2#12683](https://github.com/tianocore/edk2/pull/12683) +- **Type**: Build-System - Tool version requirement + +**What changed**: Support for the `VS2015` and `VS2017` toolchains was removed from the repository. This removed the +`VS2015` and `VS2017` toolchain definitions from `BaseTools/Conf/tools_def.template`, the associated environment setup +logic in `toolsetup.bat`, `set_vsprefix_envs.bat`, `get_vsvars.bat`, and `edksetup.bat`, the `VS2017` configuration in +the `WindowsVsToolChain` build plugin, the `VS2015`-specific `CryptoPkg` compiler flags, the `EmulatorPkg` `VS2017` +Visual Studio solution, and the unused `ShowEnvironment.bat` and `SetVisualStudio.bat` helper scripts. The oldest +supported Visual Studio toolchain is now `VS2019`. + +**What is removed**: The `VS2015` and `VS2017` toolchain definitions and their supporting scripts and build options. + +**Why it changed**: To reduce maintenance burden and align on newer, supported toolchains. Visual Studio 2015 +mainstream support ended on October 13, 2020 and extended support ended on October 14, 2025. Visual Studio 2017 is past +its mainstream support end date. + +**What replaces it**: The `VS2019`, `VS2022`, and `VS2026` toolchains. + +**How to migrate**: Developers building locally with the `VS2015` or `VS2017` toolchain must move to a newer Visual +Studio version (`VS2019` is the next supported version). + +**Breaking conditions**: Only affects Windows developers and CI environments that build with the `VS2015` or `VS2017` +toolchain. + +**Earliest removal**: Already removed in this change. The toolchains were removed in the same PR with no compatibility +window. From 6a9c048ba54c7e27898b861410741f5b27bfb2d6 Mon Sep 17 00:00:00 2001 From: DC-Damien <damien.chen@dell.com> Date: Fri, 5 Jun 2026 16:29:15 +0800 Subject: [PATCH 257/406] MdeModulePkg/UsbBusPei: Use dynamic buffer for USB configuration data USB devices whose configuration descriptor TotalLength exceeds 1024 bytes (e.g. IR cameras with large descriptor tables) previously hit an EFI_DEVICE_ERROR hard-limit and failed to enumerate in PEI. Replace the fixed array with a UINT8 * pointer and dynamically allocate the exact amount of memory required via PeiServicesAllocatePool() after the TotalLength is learned from the initial 4-byte descriptor probe. Signed-off-by: Damien Chen <damien.chen@dell.com> --- MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c | 20 +++++++++----------- MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h | 3 ++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c index 93900531d2..93b7eacbf9 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c +++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c @@ -3,6 +3,7 @@ The module to produce Usb Bus PPI. Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.<BR> Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2026 Dell Inc. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -722,7 +723,7 @@ PeiUsbGetAllConfiguration ( ) { EFI_STATUS Status; - EFI_USB_CONFIG_DESCRIPTOR *ConfigDesc; + EFI_USB_CONFIG_DESCRIPTOR ConfigDescHeader; PEI_USB_IO_PPI *UsbIoPpi; UINT16 ConfigDescLength; UINT8 *Ptr; @@ -735,7 +736,7 @@ PeiUsbGetAllConfiguration ( UsbIoPpi = &PeiUsbDevice->UsbIoPpi; // - // First get its 4-byte configuration descriptor + // First get its 4-byte configuration descriptor to learn TotalLength. // Status = PeiUsbGetDescriptor ( PeiServices, @@ -743,7 +744,7 @@ PeiUsbGetAllConfiguration ( (USB_DT_CONFIG << 8), // Value 0, // Index 4, // Length - PeiUsbDevice->ConfigurationData + (UINT8 *)&ConfigDescHeader ); if (EFI_ERROR (Status)) { @@ -753,21 +754,18 @@ PeiUsbGetAllConfiguration ( MicroSecondDelay (USB_GET_CONFIG_DESCRIPTOR_STALL); - ConfigDesc = (EFI_USB_CONFIG_DESCRIPTOR *)PeiUsbDevice->ConfigurationData; - ConfigDescLength = ConfigDesc->TotalLength; + ConfigDescLength = ConfigDescHeader.TotalLength; // // Reject if TotalLength even cannot cover itself. // - if (ConfigDescLength < OFFSET_OF (EFI_USB_CONFIG_DESCRIPTOR, TotalLength) + sizeof (ConfigDesc->TotalLength)) { + if (ConfigDescLength < OFFSET_OF (EFI_USB_CONFIG_DESCRIPTOR, TotalLength) + sizeof (ConfigDescHeader.TotalLength)) { return EFI_DEVICE_ERROR; } - // - // Reject if TotalLength exceeds the PeiUsbDevice->ConfigurationData. - // - if (ConfigDescLength > sizeof (PeiUsbDevice->ConfigurationData)) { - return EFI_DEVICE_ERROR; + Status = PeiServicesAllocatePool (ConfigDescLength, (VOID **)&PeiUsbDevice->ConfigurationData); + if (EFI_ERROR (Status)) { + return Status; } // diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h index cfea3c44fc..7af81d614c 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h +++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h @@ -2,6 +2,7 @@ Usb Peim definition. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. <BR> +Copyright (c) 2026 Dell Inc. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -50,7 +51,6 @@ typedef struct { UINT8 DownStreamPortNo; UINTN AllocateAddress; PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi; - UINT8 ConfigurationData[1024]; EFI_USB_CONFIG_DESCRIPTOR *ConfigDesc; EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDesc; EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDescList[MAX_INTERFACE]; @@ -58,6 +58,7 @@ typedef struct { EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescList[MAX_INTERFACE][MAX_ENDPOINT]; EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator; UINT8 Tier; + UINT8 *ConfigurationData; } PEI_USB_DEVICE; #define PEI_USB_DEVICE_FROM_THIS(a) CR (a, PEI_USB_DEVICE, UsbIoPpi, PEI_USB_DEVICE_SIGNATURE) From 2b842a2081613684117fb1f924eb27a05a112e5d Mon Sep 17 00:00:00 2001 From: "Michael G.A. Holland" <michael.holland@intel.com> Date: Tue, 14 Jul 2026 07:34:04 -0700 Subject: [PATCH 258/406] CryptoPkg/BaseCryptLib: Add SLH-DSA Support Created SLH-DSA API functions to configure public and private keys for SLH-DSA algorithm. This will allow users to sign and verify with SLH-DSA. Unit tests were added to confirm operation of the API. Signed-off-by: Michael G.A. Holland <michael.holland@intel.com> --- CryptoPkg/Driver/Crypto.c | 258 ++ CryptoPkg/Include/Library/BaseCryptLib.h | 302 ++ .../Pcd/PcdCryptoServiceFamilyEnable.h | 15 + .../Library/BaseCryptLib/BaseCryptLib.inf | 1 + .../Library/BaseCryptLib/PeiCryptLib.inf | 1 + CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c | 112 + .../Library/BaseCryptLib/Pem/CryptPemNull.c | 29 + .../Library/BaseCryptLib/Pk/CryptSlhDsa.c | 696 +++++ .../Library/BaseCryptLib/Pk/CryptSlhDsaNull.c | 291 ++ CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c | 172 +- .../Library/BaseCryptLib/Pk/CryptX509Null.c | 28 + .../Library/BaseCryptLib/RuntimeCryptLib.inf | 1 + .../Library/BaseCryptLib/SecCryptLib.inf | 1 + .../Library/BaseCryptLib/SmmCryptLib.inf | 1 + .../BaseCryptLib/UnitTestHostBaseCryptLib.inf | 1 + .../BaseCryptLibOnProtocolPpi/CryptLib.c | 328 +++ .../include/openssl/configuration-ec.h | 3 - .../include/openssl/configuration-noec.h | 3 - .../providers/common/der/der_slh_dsa_gen.c | 2 + .../common/include/prov/der_slh_dsa.h | 2 + CryptoPkg/Library/OpensslLib/OpensslLib.inf | 14 + .../Library/OpensslLib/OpensslLibAccel.inf | 42 + .../Library/OpensslLib/OpensslLibCrypto.inf | 14 + .../Library/OpensslLib/OpensslLibFull.inf | 14 + .../OpensslLib/OpensslLibFullAccel.inf | 42 + .../Library/OpensslLib/OpensslStub/uefiprov.c | 7 + CryptoPkg/Library/OpensslLib/configure.py | 3 +- CryptoPkg/Private/Protocol/Crypto.h | 307 +- CryptoPkg/Readme.md | 1 + .../BaseCryptLib/BaseCryptLibUnitTests.c | 1 + .../Library/BaseCryptLib/SlhDsaTestVectors.h | 2581 +++++++++++++++++ .../Library/BaseCryptLib/SlhDsaTests.c | 1779 ++++++++++++ .../Library/BaseCryptLib/TestBaseCryptLib.h | 3 + .../BaseCryptLib/TestBaseCryptLibHost.inf | 1 + .../BaseCryptLib/TestBaseCryptLibShell.inf | 1 + 35 files changed, 7047 insertions(+), 10 deletions(-) create mode 100644 CryptoPkg/Library/BaseCryptLib/Pk/CryptSlhDsa.c create mode 100644 CryptoPkg/Library/BaseCryptLib/Pk/CryptSlhDsaNull.c create mode 100644 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/SlhDsaTestVectors.h create mode 100644 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/SlhDsaTests.c diff --git a/CryptoPkg/Driver/Crypto.c b/CryptoPkg/Driver/Crypto.c index f6c4d8ebc5..a2d23fce4d 100644 --- a/CryptoPkg/Driver/Crypto.c +++ b/CryptoPkg/Driver/Crypto.c @@ -7894,6 +7894,253 @@ CryptoServiceMlDsaVerify ( return CALL_BASECRYPTLIB (MlDsa.Services.Verify, MlDsaVerify, (MlDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); } +/** + Creates a new SLH-DSA context by Crypto NID. + + This function allocates and initializes a new SLH-DSA context for the specified + SLH-DSA variant. The context contains an EVP_PKEY structure initialized with the + SLH-DSA parameters. The caller must call SlhDsaFree() to release the context when done. + + Before keys can be used for signing or verification, they must be set using + SlhDsaSetPrivKey() or SlhDsaSetPubKey(). + + @param[in] Nid Crypto NID of the SLH-DSA variant (e.g., CRYPTO_NID_SLH_DSA_SHAKE_256S). + + @retval Pointer to new SLH-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +CryptoServiceSlhDsaNewByNid ( + IN UINTN Nid + ) +{ + return CALL_BASECRYPTLIB (SlhDsa.Services.NewByNid, SlhDsaNewByNid, (Nid), NULL); +} + +/** + Frees an SLH-DSA context and all associated resources. + + This function releases all memory associated with the SLH-DSA context, including + the EVP_PKEY structure. After calling this function, the SlhDsaContext pointer + should not be used. + + If SlhDsaContext is NULL, then this function returns immediately without action. + + @param[in] SlhDsaContext Pointer to the SLH-DSA context to be released. + +**/ +VOID +EFIAPI +CryptoServiceSlhDsaFree ( + IN VOID *SlhDsaContext + ) +{ + CALL_VOID_BASECRYPTLIB (SlhDsa.Services.Free, SlhDsaFree, (SlhDsaContext)); +} + +/** + Sets the SLH-DSA private key in the SLH-DSA context. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE SLH-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +CryptoServiceSlhDsaSetPrivKey ( + IN VOID *SlhDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + return CALL_BASECRYPTLIB (SlhDsa.Services.SetPrivKey, SlhDsaSetPrivKey, (SlhDsaContext, PrivateKey, PrivateKeySize), FALSE); +} + +/** + Generates and retrieves the public key from a private key context. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +CryptoServiceSlhDsaGeneratePubKey ( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + return CALL_BASECRYPTLIB (SlhDsa.Services.GeneratePubKey, SlhDsaGeneratePubKey, (SlhDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Sets the SLH-DSA public key in the SLH-DSA context. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE SLH-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +CryptoServiceSlhDsaSetPubKey ( + IN VOID *SlhDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + return CALL_BASECRYPTLIB (SlhDsa.Services.SetPubKey, SlhDsaSetPubKey, (SlhDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieves the SLH-DSA public key from the SLH-DSA context. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE SLH-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +CryptoServiceSlhDsaGetPubKey ( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + return CALL_BASECRYPTLIB (SlhDsa.Services.GetPubKey, SlhDsaGetPubKey, (SlhDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieve the SLH-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contain the retrieved + SLH-DSA public key component. Use SlhDsaFree() function to free the + resource. + + @retval TRUE SLH-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve SLH-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +CryptoServiceSlhDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **SlhDsaContext + ) +{ + return CALL_BASECRYPTLIB (SlhDsa.Services.GetPublicKeyFromX509, SlhDsaGetPublicKeyFromX509, (Cert, CertSize, SlhDsaContext), FALSE); +} + +/** + Retrieve the SLH-DSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contains + the retrieved SLH-DSA private key. Use SlhDsaFree() to free. + + @retval TRUE SLH-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +CryptoServiceSlhDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **SlhDsaContext + ) +{ + return CALL_BASECRYPTLIB (SlhDsa.Services.GetPrivateKeyFromPem, SlhDsaGetPrivateKeyFromPem, (PemData, PemSize, Password, SlhDsaContext), FALSE); +} + +/** + Generates an SLH-DSA signature for a given message. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature. + + @retval TRUE SLH-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +CryptoServiceSlhDsaSign ( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + return CALL_BASECRYPTLIB (SlhDsa.Services.Sign, SlhDsaSign, (SlhDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} + +/** + Verifies the SLH-DSA signature for a given message. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the SLH-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE SLH-DSA signature verification succeeded. + @retval FALSE SLH-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +CryptoServiceSlhDsaVerify ( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + return CALL_BASECRYPTLIB (SlhDsa.Services.Verify, SlhDsaVerify, (SlhDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} + const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = { /// Version CryptoServiceGetCryptoVersion, @@ -8245,4 +8492,15 @@ const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = { CryptoServiceMlDsaGetPrivateKeyFromPem, CryptoServiceMlDsaSign, CryptoServiceMlDsaVerify, + /// SLH-DSA + CryptoServiceSlhDsaNewByNid, + CryptoServiceSlhDsaFree, + CryptoServiceSlhDsaSetPrivKey, + CryptoServiceSlhDsaGeneratePubKey, + CryptoServiceSlhDsaSetPubKey, + CryptoServiceSlhDsaGetPubKey, + CryptoServiceSlhDsaGetPublicKeyFromX509, + CryptoServiceSlhDsaGetPrivateKeyFromPem, + CryptoServiceSlhDsaSign, + CryptoServiceSlhDsaVerify, }; diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h b/CryptoPkg/Include/Library/BaseCryptLib.h index 801001c6c1..bca3680d15 100644 --- a/CryptoPkg/Include/Library/BaseCryptLib.h +++ b/CryptoPkg/Include/Library/BaseCryptLib.h @@ -34,6 +34,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // ML-DSA #define CRYPTO_NID_ML_DSA_87 0x05B3 +// SLH-DSA +#define CRYPTO_NID_SLH_DSA_SHAKE_256S 0x05CD + /// /// MD5 digest size in bytes /// @@ -5332,3 +5335,302 @@ MlDsaGetPublicKeyFromX509 ( IN UINTN CertSize, OUT VOID **MlDsaContext ); + +/** + Creates a new SLH-DSA context by Crypto NID. + + This function allocates and initializes a new SLH-DSA context for the specified + SLH-DSA variant. The context is created with no key material; the EVP_PKEY + structure is set to NULL. The caller must call SlhDsaFree() to release the + context when done. + + Before keys can be used for signing or verification, they must be set using + SlhDsaSetPrivKey() or SlhDsaSetPubKey(). + + If Nid is not a supported SLH-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the SLH-DSA variant (e.g., CRYPTO_NID_SLH_DSA_SHAKE_256S). + + @retval Pointer to new SLH-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +SlhDsaNewByNid ( + IN UINTN Nid + ); + +/** + Frees an SLH-DSA context and all associated resources. + + This function releases all memory associated with the SLH-DSA context, including + the EVP_PKEY structure. After calling this function, the SlhDsaContext pointer + should not be used. + + If SlhDsaContext is NULL, then this function returns immediately without action. + + @param[in] SlhDsaContext Pointer to the SLH-DSA context to be released. + +**/ +VOID +EFIAPI +SlhDsaFree ( + IN VOID *SlhDsaContext + ); + +/** + Retrieves the SLH-DSA public key from the SLH-DSA context. + + This function extracts the public key from the SLH-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via SlhDsaSetPrivKey() or SlhDsaSetPubKey()) + before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE SLH-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPubKey ( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ); + +/** + Sets the SLH-DSA public key in the SLH-DSA context. + + This function imports a raw public key into the SLH-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the SLH-DSA variant (64 bytes for SLH-DSA-SHAKE-256s). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If SlhDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE SLH-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +SlhDsaSetPubKey ( + IN VOID *SlhDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Sets the SLH-DSA private key in the SLH-DSA context. + + This function imports a raw private key into the SLH-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the SLH-DSA variant (128 bytes for SLH-DSA-SHAKE-256s). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If SlhDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE SLH-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +SlhDsaSetPrivKey ( + IN VOID *SlhDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ); + +/** + Generates and retrieves the public key from a private key context. + + This function extracts the public key from an SLH-DSA context that contains + a private key. It is equivalent to calling SlhDsaGetPubKey() but is provided + for API consistency with other cryptographic implementations. + + The context must contain a private key (set via SlhDsaSetPrivKey()) before + calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +SlhDsaGeneratePubKey ( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Generates an SLH-DSA signature for a given message. + + This function creates an SLH-DSA signature using the private key stored in the + SLH-DSA context. SLH-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via SlhDsaSetPrivKey()) before + calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + If SigSize buffer is too small, SigSize is updated with required size and return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (29792 bytes for SLH-DSA-SHAKE-256s). + + @retval TRUE SLH-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +SlhDsaSign ( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ); + +/** + Verifies the SLH-DSA signature for a given message. + + This function verifies an SLH-DSA signature against a message using the public key + contained in the SLH-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via SlhDsaSetPrivKey() + or SlhDsaSetPubKey() before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the SLH-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE SLH-DSA signature verification succeeded. + @retval FALSE SLH-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +SlhDsaVerify ( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ); + +/** + Retrieve the SLH-DSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If SlhDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contains + the retrieved SLH-DSA private key. Use SlhDsaFree() to free. + + @retval TRUE SLH-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **SlhDsaContext + ); + +/** + Retrieve the SLH-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contain the retrieved + SLH-DSA public key component. Use SlhDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If SlhDsaContext is NULL, then return FALSE. + + @retval TRUE SLH-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve SLH-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **SlhDsaContext + ); diff --git a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h index 56701f2202..b5f0de5d27 100644 --- a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h +++ b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h @@ -483,4 +483,19 @@ typedef struct { } Services; UINT32 Family; } MlDsa; + union { + struct { + UINT8 NewByNid : 1; + UINT8 Free : 1; + UINT8 SetPrivKey : 1; + UINT8 GeneratePubKey : 1; + UINT8 SetPubKey : 1; + UINT8 GetPubKey : 1; + UINT8 GetPublicKeyFromX509 : 1; + UINT8 GetPrivateKeyFromPem : 1; + UINT8 Sign : 1; + UINT8 Verify : 1; + } Services; + UINT32 Family; + } SlhDsa; } PCD_CRYPTO_SERVICE_FAMILY_ENABLE; diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf index f3d22f7173..bf8f1f86af 100644 --- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf @@ -63,6 +63,7 @@ Pk/CryptEc.c Pk/CryptEdDsa.c Pk/CryptMlDsa.c + Pk/CryptSlhDsa.c Pem/CryptPem.c Bn/CryptBn.c diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf index 2cf4cab6f9..693aa88511 100644 --- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf @@ -62,6 +62,7 @@ Pk/CryptEcNull.c Pk/CryptEdDsaNull.c Pk/CryptMlDsaNull.c + Pk/CryptSlhDsaNull.c Pem/CryptPemNull.c Rand/CryptRandNull.c Bn/CryptBnNull.c diff --git a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c index eb333abce0..fe54f291fd 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c +++ b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c @@ -185,6 +185,63 @@ IsMlDsaNidSupported ( } } +/** + Convert an SLH-DSA type name string to an OpenSSL NID. + + This helper function translates SLH-DSA type name strings (e.g., "SLH-DSA-SHAKE-256s") + to their corresponding OpenSSL EVP_PKEY NIDs (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S). + + If the type name is not recognized, EVP_PKEY_NONE is returned. + + @param[in] TypeName SLH-DSA type name string (e.g., "SLH-DSA-SHAKE-256s"). + + @retval OpenSSL NID (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S) if recognized. + @retval EVP_PKEY_NONE if the type name is not recognized. + +**/ +STATIC +INT32 +SlhDsaTypeNameToNid ( + IN CONST CHAR8 *TypeName + ) +{ + INT32 Nid; + + if (AsciiStrCmp (TypeName, "SLH-DSA-SHAKE-256s") == 0) { + Nid = EVP_PKEY_SLH_DSA_SHAKE_256S; + } else { + Nid = EVP_PKEY_NONE; + } + + return Nid; +} + +/** + Check if the given NID is supported for SLH-DSA. + + This helper function checks if the provided NID corresponds to a supported + SLH-DSA type. Currently, only EVP_PKEY_SLH_DSA_SHAKE_256S is supported. + + @param[in] Nid The NID to check. + + @retval TRUE The NID is supported for SLH-DSA. + @retval FALSE The NID is not supported for SLH-DSA. + +**/ +STATIC +BOOLEAN +IsSlhDsaNidSupported ( + IN INT32 Nid + ) +{ + switch (Nid) { + case EVP_PKEY_SLH_DSA_SHAKE_256S: + return TRUE; + default: + return FALSE; + } +} + /** Retrieve the RSA Private Key from the password-protected PEM key data. @@ -459,3 +516,58 @@ MlDsaGetPrivateKeyFromPem ( return TRUE; } + +/** + Retrieve the SLH-DSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If SlhDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contains + the retrieved SLH-DSA private key. Use SlhDsaFree() to free. + + @retval TRUE SLH-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **SlhDsaContext + ) +{ + EVP_PKEY *Pkey; + INT32 Nid; + + // + // Check input parameters. + // + if ((PemData == NULL) || (SlhDsaContext == NULL) || (PemSize > INT_MAX)) { + return FALSE; + } + + // Read PEM data + if (!GetPrivateKeyFromPem (PemData, PemSize, Password, &Pkey)) { + return FALSE; + } + + Nid = SlhDsaTypeNameToNid (EVP_PKEY_get0_type_name (Pkey)); + if (!IsSlhDsaNidSupported (Nid)) { + EVP_PKEY_free (Pkey); + return FALSE; + } + + // Allocate wrapper structure (now consistent with other key types) + if (!AllocateKeyContext (Pkey, Nid, SlhDsaContext)) { + EVP_PKEY_free (Pkey); + return FALSE; + } + + return TRUE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c index 134e511f7f..832c6034ff 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c +++ b/CryptoPkg/Library/BaseCryptLib/Pem/CryptPemNull.c @@ -125,3 +125,32 @@ MlDsaGetPrivateKeyFromPem ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the SLH-DSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If SlhDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contains + the retrieved SLH-DSA private key. Use SlhDsaFree() to free. + + @retval TRUE SLH-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **SlhDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptSlhDsa.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptSlhDsa.c new file mode 100644 index 0000000000..dc974fde12 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptSlhDsa.c @@ -0,0 +1,696 @@ +/** @file + SLH-DSA API implementation based on OpenSSL + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "InternalCryptLib.h" +#include "KeyContext.h" +#include <openssl/core_names.h> +#include <openssl/crypto.h> +#include <openssl/evp.h> +#include <openssl/param_build.h> + +/** + Get the public key size in bytes for an SLH-DSA variant from its OpenSSL NID. + + This helper function maps OpenSSL SLH-DSA NIDs to their corresponding public key sizes. + For SLH-DSA-SHAKE-256s, the public key size is 64 bytes. + + If the NID is not supported, PubKeySize is set to 0 and FALSE is returned. + + @param[in] Nid OpenSSL NID of the SLH-DSA variant (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S). + @param[out] PubKeySize Pointer to receive the public key size in bytes. + + @retval TRUE Public key size retrieved successfully. + @retval FALSE Unsupported SLH-DSA NID. + +**/ +STATIC +BOOLEAN +OpensslNidToPubKeySize ( + IN UINTN Nid, + OUT UINTN *PubKeySize + ) +{ + switch (Nid) { + case EVP_PKEY_SLH_DSA_SHAKE_256S: + *PubKeySize = 64; + break; + default: + *PubKeySize = 0; + return FALSE; + } + + return TRUE; +} + +/** + Get the private key size in bytes for an SLH-DSA variant from its OpenSSL NID. + + This helper function maps OpenSSL SLH-DSA NIDs to their corresponding private key sizes. + For SLH-DSA-SHAKE-256s, the private key size is 128 bytes. + + If the NID is not supported, PrivKeySize is set to 0 and FALSE is returned. + + @param[in] Nid OpenSSL NID of the SLH-DSA variant (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S). + @param[out] PrivKeySize Pointer to receive the private key size in bytes. + + @retval TRUE Private key size retrieved successfully. + @retval FALSE Unsupported SLH-DSA NID. + +**/ +STATIC +BOOLEAN +OpensslNidToPrivKeySize ( + IN UINTN Nid, + OUT UINTN *PrivKeySize + ) +{ + switch (Nid) { + case EVP_PKEY_SLH_DSA_SHAKE_256S: + *PrivKeySize = 128; + break; + default: + *PrivKeySize = 0; + return FALSE; + } + + return TRUE; +} + +/** + Get the signature size in bytes for an SLH-DSA variant from its OpenSSL NID. + + This helper function maps OpenSSL SLH-DSA NIDs to their corresponding signature sizes. + For SLH-DSA-SHAKE-256s, the signature size is 29792 bytes. + + If the NID is not supported, SignatureSize is set to 0 and FALSE is returned. + + @param[in] Nid OpenSSL NID of the SLH-DSA variant (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S). + @param[out] SignatureSize Pointer to receive the signature size in bytes. + + @retval TRUE Signature size retrieved successfully. + @retval FALSE Unsupported SLH-DSA NID. + +**/ +STATIC +BOOLEAN +OpensslNidToSignatureSize ( + IN UINTN Nid, + OUT UINTN *SignatureSize + ) +{ + switch (Nid) { + case EVP_PKEY_SLH_DSA_SHAKE_256S: + *SignatureSize = 29792; + break; + default: + *SignatureSize = 0; + return FALSE; + } + + return TRUE; +} + +/** + Convert a Crypto NID to an OpenSSL NID. + + This helper function translates EDK II Crypto library NIDs (e.g., CRYPTO_NID_SLH_DSA_SHAKE_256S) + to their corresponding OpenSSL EVP_PKEY NIDs (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S). + + If the Crypto NID is not supported, EVP_PKEY_NONE is returned. + + @param[in] CryptoNid EDK II Crypto library NID (e.g., CRYPTO_NID_SLH_DSA_SHAKE_256S). + + @retval OpenSSL NID (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S) if supported. + @retval EVP_PKEY_NONE if the Crypto NID is unsupported. + +**/ +STATIC +INT32 +CryptoNidToOpensslNid ( + IN UINTN CryptoNid + ) +{ + INT32 Nid; + + switch (CryptoNid) { + case CRYPTO_NID_SLH_DSA_SHAKE_256S: + Nid = EVP_PKEY_SLH_DSA_SHAKE_256S; + break; + default: + Nid = EVP_PKEY_NONE; + break; + } + + return Nid; +} + +/** + Convert an SLH-DSA type name string to an OpenSSL NID. + + This helper function translates SLH-DSA type name strings (e.g., "SLH-DSA-SHAKE-256s") + to their corresponding OpenSSL EVP_PKEY NIDs (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S). + + If the type name is not recognized, EVP_PKEY_NONE is returned. + + @param[in] TypeName SLH-DSA type name string (e.g., "SLH-DSA-SHAKE-256s"). + + @retval OpenSSL NID (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S) if recognized. + @retval EVP_PKEY_NONE if the type name is not recognized. + +**/ +STATIC +INT32 +SlhDsaTypeNameToNid ( + IN CONST CHAR8 *TypeName + ) +{ + INT32 Nid; + + if (AsciiStrCmp (TypeName, "SLH-DSA-SHAKE-256s") == 0) { + Nid = EVP_PKEY_SLH_DSA_SHAKE_256S; + } else { + Nid = EVP_PKEY_NONE; + } + + return Nid; +} + +/** + Creates a new SLH-DSA context by Crypto NID. + + This function allocates and initializes a new SLH-DSA context for the specified + SLH-DSA variant. The context is created with no key material; the EVP_PKEY + structure is set to NULL. The caller must call SlhDsaFree() to release the + context when done. + + Before keys can be used for signing or verification, they must be set using + SlhDsaSetPrivKey() or SlhDsaSetPubKey(). + + If Nid is not a supported SLH-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the SLH-DSA variant (e.g., CRYPTO_NID_SLH_DSA_SHAKE_256S). + + @retval Pointer to new SLH-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +SlhDsaNewByNid ( + IN UINTN Nid + ) +{ + KEY_CONTEXT *Ctx; + INT32 OpensslNid; + + OpensslNid = CryptoNidToOpensslNid (Nid); + if (OpensslNid <= EVP_PKEY_NONE) { + return NULL; + } + + Ctx = (KEY_CONTEXT *)AllocateZeroPool (sizeof (KEY_CONTEXT)); + if (Ctx == NULL) { + return NULL; + } + + Ctx->Nid = OpensslNid; + Ctx->EvpPkey = NULL; + + return (VOID *)Ctx; +} + +/** + Frees an SLH-DSA context and all associated resources. + + This function releases all memory associated with the SLH-DSA context, including + the EVP_PKEY structure. After calling this function, the SlhDsaContext pointer + should not be used. + + If SlhDsaContext is NULL, then this function returns immediately without action. + + @param[in] SlhDsaContext Pointer to the SLH-DSA context to be released. + +**/ +VOID +EFIAPI +SlhDsaFree ( + IN VOID *SlhDsaContext + ) +{ + KEY_CONTEXT *Ctx; + + if (SlhDsaContext == NULL) { + return; + } + + Ctx = (KEY_CONTEXT *)SlhDsaContext; + + if (Ctx->EvpPkey != NULL) { + EVP_PKEY_free (Ctx->EvpPkey); + } + + FreePool (Ctx); +} + +/** + Sets the SLH-DSA private key in the SLH-DSA context. + + This function imports a raw private key into the SLH-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the SLH-DSA variant (128 bytes for SLH-DSA-SHAKE-256s). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If SlhDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE SLH-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +SlhDsaSetPrivKey ( + IN VOID *SlhDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + KEY_CONTEXT *Ctx; + UINTN FinalPrivateKeySize; + + if ((SlhDsaContext == NULL) || (PrivateKey == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)SlhDsaContext; + + if (!OpensslNidToPrivKeySize (Ctx->Nid, &FinalPrivateKeySize)) { + return FALSE; + } + + if (FinalPrivateKeySize != PrivateKeySize) { + return FALSE; + } + + if (Ctx->EvpPkey != NULL) { + EVP_PKEY_free (Ctx->EvpPkey); + Ctx->EvpPkey = NULL; + } + + Ctx->EvpPkey = EVP_PKEY_new_raw_private_key (Ctx->Nid, NULL, PrivateKey, PrivateKeySize); + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + return TRUE; +} + +/** + Generates and retrieves the public key from a private key context. + + This function extracts the public key from an SLH-DSA context that contains + a private key. It is equivalent to calling SlhDsaGetPubKey() but is provided + for API consistency with other cryptographic implementations. + + The context must contain a private key (set via SlhDsaSetPrivKey()) before + calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +SlhDsaGeneratePubKey ( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + return FALSE; +} + +/** + Sets the SLH-DSA public key in the SLH-DSA context. + + This function imports a raw public key into the SLH-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the SLH-DSA variant (64 bytes for SLH-DSA-SHAKE-256s). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If SlhDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE SLH-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +SlhDsaSetPubKey ( + IN VOID *SlhDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + KEY_CONTEXT *Ctx; + UINTN FinalPublicKeySize; + + if ((SlhDsaContext == NULL) || (PublicKey == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)SlhDsaContext; + + if (!OpensslNidToPubKeySize (Ctx->Nid, &FinalPublicKeySize)) { + return FALSE; + } + + if (FinalPublicKeySize != PublicKeySize) { + return FALSE; + } + + if (Ctx->EvpPkey != NULL) { + EVP_PKEY_free (Ctx->EvpPkey); + Ctx->EvpPkey = NULL; + } + + Ctx->EvpPkey = EVP_PKEY_new_raw_public_key (Ctx->Nid, NULL, PublicKey, PublicKeySize); + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + return TRUE; +} + +/** + Retrieves the SLH-DSA public key from the SLH-DSA context. + + This function extracts the public key from the SLH-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via SlhDsaSetPrivKey() or SlhDsaSetPubKey()) + before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE SLH-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPubKey ( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + KEY_CONTEXT *Ctx; + INT32 Result; + UINTN FinalPublicKeySize; + + if ((SlhDsaContext == NULL) || (PublicKeySize == NULL)) { + return FALSE; + } + + if (PublicKey == NULL) { + *PublicKeySize = 0; + return FALSE; + } + + Ctx = (KEY_CONTEXT *)SlhDsaContext; + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + if (!OpensslNidToPubKeySize (Ctx->Nid, &FinalPublicKeySize)) { + return FALSE; + } + + if (*PublicKeySize < FinalPublicKeySize) { + *PublicKeySize = FinalPublicKeySize; + return FALSE; + } + + *PublicKeySize = FinalPublicKeySize; + + Result = EVP_PKEY_get_raw_public_key (Ctx->EvpPkey, PublicKey, PublicKeySize); + if (Result != 1) { + return FALSE; + } + + return TRUE; +} + +/** + Generates an SLH-DSA signature for a given message. + + This function creates an SLH-DSA signature using the private key stored in the + SLH-DSA context. SLH-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via SlhDsaSetPrivKey()) before + calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + If SigSize buffer is too small, SigSize is updated with required size and return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (29792 bytes for SLH-DSA-SHAKE-256s). + + @retval TRUE SLH-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +SlhDsaSign ( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + KEY_CONTEXT *Ctx; + EVP_MD_CTX *SignCtx; + INT32 Result; + UINTN FinalSigSize; + OSSL_PARAM Params[2]; + OSSL_PARAM ParamsDefault[1]; + + if ((SlhDsaContext == NULL) || (Message == NULL)) { + return FALSE; + } + + if ((Signature == NULL) || (SigSize == NULL)) { + return FALSE; + } + + if ((ContextSize > 0) && (Context == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)SlhDsaContext; + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + if (!OpensslNidToSignatureSize (Ctx->Nid, &FinalSigSize)) { + return FALSE; + } + + if (*SigSize < FinalSigSize) { + *SigSize = FinalSigSize; + return FALSE; + } + + *SigSize = FinalSigSize; + ZeroMem (Signature, *SigSize); + + Params[0] = OSSL_PARAM_construct_octet_string (OSSL_SIGNATURE_PARAM_CONTEXT_STRING, (VOID *)Context, ContextSize); + Params[1] = OSSL_PARAM_construct_end (); + + Result = FALSE; + SignCtx = EVP_MD_CTX_new (); + if (SignCtx == NULL) { + return FALSE; + } + + if (ContextSize == 0) { + ParamsDefault[0] = OSSL_PARAM_construct_end (); + Result = EVP_DigestSignInit_ex (SignCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, ParamsDefault); + } else { + Result = EVP_DigestSignInit_ex (SignCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, Params); + } + + if (Result != 1) { + EVP_MD_CTX_free (SignCtx); + return FALSE; + } + + Result = EVP_DigestSign (SignCtx, Signature, SigSize, Message, MessageSize); + if (Result != 1) { + EVP_MD_CTX_free (SignCtx); + return FALSE; + } + + EVP_MD_CTX_free (SignCtx); + return TRUE; +} + +/** + Verifies the SLH-DSA signature for a given message. + + This function verifies an SLH-DSA signature against a message using the public key + contained in the SLH-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via SlhDsaSetPrivKey() + or SlhDsaSetPubKey() before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the SLH-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE SLH-DSA signature verification succeeded. + @retval FALSE SLH-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +SlhDsaVerify ( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + KEY_CONTEXT *Ctx; + EVP_MD_CTX *VerifyCtx; + INT32 OpensslNid; + UINTN FinalSigSize; + INT32 Result; + OSSL_PARAM Params[2]; + OSSL_PARAM ParamsDefault[1]; + + if ((SlhDsaContext == NULL) || (Message == NULL) || (Signature == NULL)) { + return FALSE; + } + + if ((SigSize > INT_MAX) || (SigSize == 0)) { + return FALSE; + } + + if ((ContextSize > 0) && (Context == NULL)) { + return FALSE; + } + + Ctx = (KEY_CONTEXT *)SlhDsaContext; + if (Ctx->EvpPkey == NULL) { + return FALSE; + } + + OpensslNid = SlhDsaTypeNameToNid (EVP_PKEY_get0_type_name (Ctx->EvpPkey)); + if (!OpensslNidToSignatureSize (OpensslNid, &FinalSigSize)) { + return FALSE; + } + + if (SigSize != FinalSigSize) { + return FALSE; + } + + Params[0] = OSSL_PARAM_construct_octet_string (OSSL_SIGNATURE_PARAM_CONTEXT_STRING, (VOID *)Context, ContextSize); + Params[1] = OSSL_PARAM_construct_end (); + + VerifyCtx = EVP_MD_CTX_new (); + if (VerifyCtx == NULL) { + return FALSE; + } + + if (ContextSize == 0) { + ParamsDefault[0] = OSSL_PARAM_construct_end (); + Result = EVP_DigestVerifyInit_ex (VerifyCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, ParamsDefault); + } else { + Result = EVP_DigestVerifyInit_ex (VerifyCtx, NULL, NULL, NULL, NULL, Ctx->EvpPkey, Params); + } + + if (Result != 1) { + EVP_MD_CTX_free (VerifyCtx); + return FALSE; + } + + Result = EVP_DigestVerify (VerifyCtx, Signature, SigSize, Message, MessageSize); + if (Result != 1) { + EVP_MD_CTX_free (VerifyCtx); + return FALSE; + } + + EVP_MD_CTX_free (VerifyCtx); + return TRUE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptSlhDsaNull.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptSlhDsaNull.c new file mode 100644 index 0000000000..a1a98e5e7c --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptSlhDsaNull.c @@ -0,0 +1,291 @@ +/** @file + SLH-DSA API implementation based on OpenSSL + + Copyright (c) 2026, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/BaseCryptLib.h> +#include <Library/DebugLib.h> + +/** + Creates a new SLH-DSA context by Crypto NID. + + This function allocates and initializes a new SLH-DSA context for the specified + SLH-DSA variant. The context is created with no key material; the EVP_PKEY + structure is set to NULL. The caller must call SlhDsaFree() to release the + context when done. + + Before keys can be used for signing or verification, they must be set using + SlhDsaSetPrivKey() or SlhDsaSetPubKey(). + + If Nid is not a supported SLH-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the SLH-DSA variant (e.g., CRYPTO_NID_SLH_DSA_SHAKE_256S). + + @retval Pointer to new SLH-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +SlhDsaNewByNid ( + IN UINTN Nid + ) +{ + ASSERT (FALSE); + return NULL; +} + +/** + Frees an SLH-DSA context and all associated resources. + + This function releases all memory associated with the SLH-DSA context, including + the EVP_PKEY structure. After calling this function, the SlhDsaContext pointer + should not be used. + + If SlhDsaContext is NULL, then this function returns immediately without action. + + @param[in] SlhDsaContext Pointer to the SLH-DSA context to be released. + +**/ +VOID +EFIAPI +SlhDsaFree ( + IN VOID *SlhDsaContext + ) +{ + ASSERT (FALSE); +} + +/** + Retrieves the SLH-DSA public key from the SLH-DSA context. + + This function extracts the public key from the SLH-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via SlhDsaSetPrivKey() or SlhDsaSetPubKey()) + before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE SLH-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPubKey ( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the SLH-DSA public key in the SLH-DSA context. + + This function imports a raw public key into the SLH-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the SLH-DSA variant (64 bytes for SLH-DSA-SHAKE-256s). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If SlhDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE SLH-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +SlhDsaSetPubKey ( + IN VOID *SlhDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Sets the SLH-DSA private key in the SLH-DSA context. + + This function imports a raw private key into the SLH-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the SLH-DSA variant (128 bytes for SLH-DSA-SHAKE-256s). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If SlhDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE SLH-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +SlhDsaSetPrivKey ( + IN VOID *SlhDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates and retrieves the public key from a private key context. + + This function extracts the public key from an SLH-DSA context that contains + a private key. It is equivalent to calling SlhDsaGetPubKey() but is provided + for API consistency with other cryptographic implementations. + + The context must contain a private key (set via SlhDsaSetPrivKey()) before + calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +SlhDsaGeneratePubKey ( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Generates an SLH-DSA signature for a given message. + + This function creates an SLH-DSA signature using the private key stored in the + SLH-DSA context. SLH-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via SlhDsaSetPrivKey()) before + calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + If SigSize buffer is too small, SigSize is updated with required size and return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (29792 bytes for SLH-DSA-SHAKE-256s). + + @retval TRUE SLH-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +SlhDsaSign ( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Verifies the SLH-DSA signature for a given message. + + This function verifies an SLH-DSA signature against a message using the public key + contained in the SLH-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via SlhDsaSetPrivKey() + or SlhDsaSetPubKey() before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the SLH-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE SLH-DSA signature verification succeeded. + @retval FALSE SLH-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +SlhDsaVerify ( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c index 7ae6df3d13..937ebd5790 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c @@ -82,6 +82,63 @@ IsMlDsaNidSupported ( } } +/** + Convert an SLH-DSA type name string to an OpenSSL NID. + + This helper function translates SLH-DSA type name strings (e.g., "SLH-DSA-SHAKE-256s") + to their corresponding OpenSSL EVP_PKEY NIDs (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S). + + If the type name is not recognized, EVP_PKEY_NONE is returned. + + @param[in] TypeName SLH-DSA type name string (e.g., "SLH-DSA-SHAKE-256s"). + + @retval OpenSSL NID (e.g., EVP_PKEY_SLH_DSA_SHAKE_256S) if recognized. + @retval EVP_PKEY_NONE if the type name is not recognized. + +**/ +STATIC +INT32 +SlhDsaTypeNameToNid ( + IN CONST CHAR8 *TypeName + ) +{ + INT32 Nid; + + if (AsciiStrCmp (TypeName, "SLH-DSA-SHAKE-256s") == 0) { + Nid = EVP_PKEY_SLH_DSA_SHAKE_256S; + } else { + Nid = EVP_PKEY_NONE; + } + + return Nid; +} + +/** + Check if the given NID is supported for SLH-DSA. + + This helper function checks if the provided NID corresponds to a supported + SLH-DSA type. Currently, only EVP_PKEY_SLH_DSA_SHAKE_256S is supported. + + @param[in] Nid The NID to check. + + @retval TRUE The NID is supported for SLH-DSA. + @retval FALSE The NID is not supported for SLH-DSA. + +**/ +STATIC +BOOLEAN +IsSlhDsaNidSupported ( + IN INT32 Nid + ) +{ + switch (Nid) { + case EVP_PKEY_SLH_DSA_SHAKE_256S: + return TRUE; + default: + return FALSE; + } +} + /** Construct a X509 object from DER-encoded certificate data. @@ -1208,7 +1265,7 @@ MlDsaGetPublicKeyFromX509 ( } // - // Duplicate EdDSA Context from the retrieved EVP_PKEY. + // Duplicate ML-DSA Context from the retrieved EVP_PKEY. // DupPkey = EVP_PKEY_dup (Pkey); if (DupPkey == NULL) { @@ -1246,6 +1303,119 @@ _Exit: return Status; } +/** + Retrieve the SLH-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contain the retrieved + SLH-DSA public key component. Use SlhDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If SlhDsaContext is NULL, then return FALSE. + + @retval TRUE SLH-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve SLH-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **SlhDsaContext + ) +{ + BOOLEAN Status; + EVP_PKEY *Pkey; + EVP_PKEY *DupPkey; + INT32 Nid; + X509 *X509Cert; + KEY_CONTEXT *Ctx; + + if ((Cert == NULL) || (SlhDsaContext == NULL)) { + return FALSE; + } + + // + // If CertSize is 0, return FALSE to be safe. + // + if (CertSize == 0) { + *SlhDsaContext = NULL; + return FALSE; + } + + Pkey = NULL; + X509Cert = NULL; + Status = FALSE; + + // + // Read DER-encoded X509 Certificate and Construct X509 object. + // + Status = X509ConstructCertificate (Cert, CertSize, (UINT8 **)&X509Cert); + if (!Status || (X509Cert == NULL)) { + Status = FALSE; + goto _Exit; + } + + // + // Retrieve and check EVP_PKEY data from X509 Certificate. + // + Pkey = X509_get_pubkey (X509Cert); + if (Pkey == NULL) { + Status = FALSE; + goto _Exit; + } + + // + // Check if the retrieved EVP_PKEY is one supported SLH-DSA key type. + // + Nid = SlhDsaTypeNameToNid (EVP_PKEY_get0_type_name (Pkey)); + if (!IsSlhDsaNidSupported (Nid)) { + Status = FALSE; + goto _Exit; + } + + // + // Duplicate SLH-DSA Context from the retrieved EVP_PKEY. + // + DupPkey = EVP_PKEY_dup (Pkey); + if (DupPkey == NULL) { + Status = FALSE; + goto _Exit; + } + + // + // Allocate KEY_CONTEXT wrapper structure + // + Ctx = (KEY_CONTEXT *)AllocateZeroPool (sizeof (KEY_CONTEXT)); + if (Ctx == NULL) { + EVP_PKEY_free (DupPkey); + Status = FALSE; + goto _Exit; + } + + Ctx->Nid = Nid; + Ctx->EvpPkey = DupPkey; + *SlhDsaContext = (VOID *)Ctx; + Status = TRUE; + +_Exit: + // + // Release Resources. + // + if (X509Cert != NULL) { + X509_free (X509Cert); + } + + if (Pkey != NULL) { + EVP_PKEY_free (Pkey); + } + + return Status; +} + /** Retrieve the version from one X.509 certificate. diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c index 4d247383a5..bb5c6bd1e0 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509Null.c @@ -805,3 +805,31 @@ MlDsaGetPublicKeyFromX509 ( ASSERT (FALSE); return FALSE; } + +/** + Retrieve the SLH-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contain the retrieved + SLH-DSA public key component. Use SlhDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If SlhDsaContext is NULL, then return FALSE. + + @retval TRUE SLH-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve SLH-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **SlhDsaContext + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf index e104036245..d342449e05 100644 --- a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf @@ -65,6 +65,7 @@ Pk/CryptEcNull.c Pk/CryptEdDsaNull.c Pk/CryptMlDsaNull.c + Pk/CryptSlhDsaNull.c Pem/CryptPem.c Bn/CryptBnNull.c diff --git a/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf index fd3a102f54..82fe7e076d 100644 --- a/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf @@ -59,6 +59,7 @@ Pk/CryptEcNull.c Pk/CryptEdDsaNull.c Pk/CryptMlDsaNull.c + Pk/CryptSlhDsaNull.c Bn/CryptBnNull.c SysCall/CrtWrapper.c diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf index ee5a5647ec..d7d34cb20b 100644 --- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf @@ -66,6 +66,7 @@ Pk/CryptEc.c Pk/CryptEdDsa.c Pk/CryptMlDsa.c + Pk/CryptSlhDsa.c Pem/CryptPem.c Bn/CryptBn.c diff --git a/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf index 216ffd8435..9c60aa5f5a 100644 --- a/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf @@ -53,6 +53,7 @@ Pk/CryptEc.c Pk/CryptEdDsa.c Pk/CryptMlDsa.c + Pk/CryptSlhDsa.c SysCall/UnitTestHostCrtWrapper.c diff --git a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c index 5a1d1cb81e..b0afd91351 100644 --- a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c +++ b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c @@ -6998,3 +6998,331 @@ MlDsaVerify ( { CALL_CRYPTO_SERVICE (MlDsaVerify, (MlDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); } + +/** + Creates a new SLH-DSA context by Crypto NID. + + This function allocates and initializes a new SLH-DSA context for the specified + SLH-DSA variant. The context is created with no key material; the EVP_PKEY + structure is set to NULL. The caller must call SlhDsaFree() to release the + context when done. + + Before keys can be used for signing or verification, they must be set using + SlhDsaSetPrivKey() or SlhDsaSetPubKey(). + + If Nid is not a supported SLH-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the SLH-DSA variant (e.g., CRYPTO_NID_SLH_DSA_SHAKE_256S). + + @retval Pointer to new SLH-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +VOID * +EFIAPI +SlhDsaNewByNid ( + IN UINTN Nid + ) +{ + CALL_CRYPTO_SERVICE (SlhDsaNewByNid, (Nid), NULL); +} + +/** + Frees an SLH-DSA context and all associated resources. + + This function releases all memory associated with the SLH-DSA context, including + the EVP_PKEY structure. After calling this function, the SlhDsaContext pointer + should not be used. + + If SlhDsaContext is NULL, then this function returns immediately without action. + + @param[in] SlhDsaContext Pointer to the SLH-DSA context to be released. + +**/ +VOID +EFIAPI +SlhDsaFree ( + IN VOID *SlhDsaContext + ) +{ + CALL_VOID_CRYPTO_SERVICE (SlhDsaFree, (SlhDsaContext)); +} + +/** + Sets the SLH-DSA private key in the SLH-DSA context. + + This function imports a raw private key into the SLH-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the SLH-DSA variant (128 bytes for SLH-DSA-SHAKE-256s). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If SlhDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE SLH-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +SlhDsaSetPrivKey ( + IN VOID *SlhDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ) +{ + CALL_CRYPTO_SERVICE (SlhDsaSetPrivKey, (SlhDsaContext, PrivateKey, PrivateKeySize), FALSE); +} + +/** + Generates and retrieves the public key from a private key context. + + This function extracts the public key from an SLH-DSA context that contains + a private key. It is equivalent to calling SlhDsaGetPubKey() but is provided + for API consistency with other cryptographic implementations. + + The context must contain a private key (set via SlhDsaSetPrivKey()) before + calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +BOOLEAN +EFIAPI +SlhDsaGeneratePubKey ( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + CALL_CRYPTO_SERVICE (SlhDsaGeneratePubKey, (SlhDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Sets the SLH-DSA public key in the SLH-DSA context. + + This function imports a raw public key into the SLH-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the SLH-DSA variant (64 bytes for SLH-DSA-SHAKE-256s). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If SlhDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE SLH-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +BOOLEAN +EFIAPI +SlhDsaSetPubKey ( + IN VOID *SlhDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ) +{ + CALL_CRYPTO_SERVICE (SlhDsaSetPubKey, (SlhDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieves the SLH-DSA public key from the SLH-DSA context. + + This function extracts the public key from the SLH-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via SlhDsaSetPrivKey() or SlhDsaSetPubKey()) + before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE SLH-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPubKey ( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ) +{ + CALL_CRYPTO_SERVICE (SlhDsaGetPubKey, (SlhDsaContext, PublicKey, PublicKeySize), FALSE); +} + +/** + Retrieve the SLH-DSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If SlhDsaContext is NULL, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contains + the retrieved SLH-DSA private key. Use SlhDsaFree() to free. + + @retval TRUE SLH-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **SlhDsaContext + ) +{ + CALL_CRYPTO_SERVICE (SlhDsaGetPrivateKeyFromPem, (PemData, PemSize, Password, SlhDsaContext), FALSE); +} + +/** + Retrieve the SLH-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contains the retrieved + SLH-DSA public key component. Use SlhDsaFree() to free the resource. + + If Cert is NULL, then return FALSE. + If SlhDsaContext is NULL, then return FALSE. + + @retval TRUE SLH-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve SLH-DSA public key from X509 certificate. + +**/ +BOOLEAN +EFIAPI +SlhDsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **SlhDsaContext + ) +{ + CALL_CRYPTO_SERVICE (SlhDsaGetPublicKeyFromX509, (Cert, CertSize, SlhDsaContext), FALSE); +} + +/** + Generates an SLH-DSA signature for a given message. + + This function creates an SLH-DSA signature using the private key stored in the + SLH-DSA context. SLH-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via SlhDsaSetPrivKey()) before + calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + If SigSize buffer is too small, SigSize is updated with required size and return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (29792 bytes for SLH-DSA-SHAKE-256s). + + @retval TRUE SLH-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +BOOLEAN +EFIAPI +SlhDsaSign ( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ) +{ + CALL_CRYPTO_SERVICE (SlhDsaSign, (SlhDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} + +/** + Verifies the SLH-DSA signature for a given message. + + This function verifies an SLH-DSA signature against a message using the public key + contained in the SLH-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via SlhDsaSetPrivKey() + or SlhDsaSetPubKey() before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the SLH-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + + @retval TRUE SLH-DSA signature verification succeeded. + @retval FALSE SLH-DSA signature verification failed or invalid parameters. + +**/ +BOOLEAN +EFIAPI +SlhDsaVerify ( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ) +{ + CALL_CRYPTO_SERVICE (SlhDsaVerify, (SlhDsaContext, Context, ContextSize, Message, MessageSize, Signature, SigSize), FALSE); +} diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h index a93829e440..3261e9e109 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-ec.h @@ -275,9 +275,6 @@ extern "C" { # ifndef OPENSSL_NO_SIV # define OPENSSL_NO_SIV # endif -# ifndef OPENSSL_NO_SLH_DSA -# define OPENSSL_NO_SLH_DSA -# endif # ifndef OPENSSL_NO_SM2 # define OPENSSL_NO_SM2 # endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h index a42bd1b4c9..b0abb2ece5 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/include/openssl/configuration-noec.h @@ -293,9 +293,6 @@ extern "C" { # ifndef OPENSSL_NO_SIV # define OPENSSL_NO_SIV # endif -# ifndef OPENSSL_NO_SLH_DSA -# define OPENSSL_NO_SLH_DSA -# endif # ifndef OPENSSL_NO_SM2 # define OPENSSL_NO_SM2 # endif diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_slh_dsa_gen.c b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_slh_dsa_gen.c index f9fb0bdc51..6366f5394f 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_slh_dsa_gen.c +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/der/der_slh_dsa_gen.c @@ -13,6 +13,7 @@ #include "prov/der_slh_dsa.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * id-slh-dsa-sha2-128s OBJECT IDENTIFIER ::= { sigAlgs 20 } @@ -98,3 +99,4 @@ const unsigned char ossl_der_oid_id_slh_dsa_shake_256f[DER_OID_SZ_id_slh_dsa_sha DER_OID_V_id_slh_dsa_shake_256f }; +/* clang-format on */ diff --git a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_slh_dsa.h b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_slh_dsa.h index 0da6cdd7b1..4574d331e0 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_slh_dsa.h +++ b/CryptoPkg/Library/OpensslLib/OpensslGen/providers/common/include/prov/der_slh_dsa.h @@ -14,6 +14,7 @@ #include "crypto/slh_dsa.h" /* Well known OIDs precompiled */ +/* clang-format off */ /* * id-slh-dsa-sha2-128s OBJECT IDENTIFIER ::= { sigAlgs 20 } @@ -99,5 +100,6 @@ extern const unsigned char ossl_der_oid_id_slh_dsa_shake_256s[DER_OID_SZ_id_slh_ #define DER_OID_SZ_id_slh_dsa_shake_256f 11 extern const unsigned char ossl_der_oid_id_slh_dsa_shake_256f[DER_OID_SZ_id_slh_dsa_shake_256f]; +/* clang-format on */ int ossl_DER_w_algorithmIdentifier_SLH_DSA(WPACKET *pkt, int tag, SLH_DSA_KEY *key); diff --git a/CryptoPkg/Library/OpensslLib/OpensslLib.inf b/CryptoPkg/Library/OpensslLib/OpensslLib.inf index 66df768cf5..1456be7320 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLib.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLib.inf @@ -467,6 +467,16 @@ $(OPENSSL_PATH)/crypto/sha/sha256.c $(OPENSSL_PATH)/crypto/sha/sha3.c $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_adrs.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_hash_ctx.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_key.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_fors.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hash.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hypertree.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_params.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_wots.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_xmss.c $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c $(OPENSSL_PATH)/crypto/sm3/sm3.c $(OPENSSL_PATH)/crypto/stack/stack.c @@ -638,6 +648,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/slh_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/kmac_prov.c @@ -655,12 +666,14 @@ $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/slh_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c $(OPENSSL_GEN_PATH)/crypto/params_idx.c $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/der/der_slh_dsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c @@ -675,6 +688,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_slh_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c $(OPENSSL_PATH)/ssl/d1_lib.c diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf index 4ba73af89c..95e87ac7aa 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf @@ -487,6 +487,16 @@ $(OPENSSL_PATH)/crypto/sha/sha256.c $(OPENSSL_PATH)/crypto/sha/sha3.c $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_adrs.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_hash_ctx.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_key.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_fors.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hash.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hypertree.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_params.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_wots.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_xmss.c $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c $(OPENSSL_PATH)/crypto/sm3/sm3.c $(OPENSSL_PATH)/crypto/stack/stack.c @@ -658,6 +668,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/slh_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/kmac_prov.c @@ -675,12 +686,14 @@ $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/slh_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c $(OPENSSL_GEN_PATH)/crypto/params_idx.c $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/der/der_slh_dsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c @@ -695,6 +708,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_slh_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c $(OPENSSL_PATH)/ssl/d1_lib.c @@ -1205,6 +1219,16 @@ $(OPENSSL_PATH)/crypto/sha/sha256.c $(OPENSSL_PATH)/crypto/sha/sha3.c $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_adrs.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_hash_ctx.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_key.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_fors.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hash.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hypertree.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_params.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_wots.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_xmss.c $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c $(OPENSSL_PATH)/crypto/sm3/sm3.c $(OPENSSL_PATH)/crypto/stack/stack.c @@ -1376,6 +1400,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/slh_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/kmac_prov.c @@ -1393,12 +1418,14 @@ $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/slh_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c $(OPENSSL_GEN_PATH)/crypto/params_idx.c $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/der/der_slh_dsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c @@ -1413,6 +1440,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_slh_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c $(OPENSSL_PATH)/ssl/d1_lib.c @@ -1944,6 +1972,16 @@ $(OPENSSL_PATH)/crypto/sha/sha256.c $(OPENSSL_PATH)/crypto/sha/sha3.c $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_adrs.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_hash_ctx.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_key.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_fors.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hash.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hypertree.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_params.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_wots.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_xmss.c $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c $(OPENSSL_PATH)/crypto/sm3/sm3.c $(OPENSSL_PATH)/crypto/stack/stack.c @@ -2115,6 +2153,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/slh_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/kmac_prov.c @@ -2132,12 +2171,14 @@ $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/slh_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c $(OPENSSL_GEN_PATH)/crypto/params_idx.c $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/der/der_slh_dsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c @@ -2152,6 +2193,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_slh_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c $(OPENSSL_PATH)/ssl/d1_lib.c diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf b/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf index d09d2b6ad8..b89b0313bf 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf @@ -468,6 +468,16 @@ $(OPENSSL_PATH)/crypto/sha/sha256.c $(OPENSSL_PATH)/crypto/sha/sha3.c $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_adrs.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_hash_ctx.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_key.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_fors.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hash.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hypertree.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_params.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_wots.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_xmss.c $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c $(OPENSSL_PATH)/crypto/sm3/sm3.c $(OPENSSL_PATH)/crypto/stack/stack.c @@ -639,6 +649,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/slh_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/kmac_prov.c @@ -656,12 +667,14 @@ $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/slh_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c $(OPENSSL_GEN_PATH)/crypto/params_idx.c $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/der/der_slh_dsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c @@ -676,6 +689,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_digests_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_slh_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c # Autogenerated files list ends here buildinf.h diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf b/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf index 07e8e729d5..170b8695af 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFull.inf @@ -519,6 +519,16 @@ $(OPENSSL_PATH)/crypto/sha/sha256.c $(OPENSSL_PATH)/crypto/sha/sha3.c $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_adrs.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_hash_ctx.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_key.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_fors.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hash.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hypertree.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_params.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_wots.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_xmss.c $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c $(OPENSSL_PATH)/crypto/sm3/sm3.c $(OPENSSL_PATH)/crypto/stack/stack.c @@ -699,6 +709,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/slh_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c @@ -719,6 +730,7 @@ $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/slh_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c @@ -728,6 +740,7 @@ $(OPENSSL_PATH)/providers/common/der/der_ecx_key.c $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/der/der_slh_dsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c @@ -744,6 +757,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_ecx_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_slh_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c $(OPENSSL_PATH)/ssl/d1_lib.c diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf index 3812eb6b68..22b50203e3 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf @@ -535,6 +535,16 @@ $(OPENSSL_PATH)/crypto/sha/sha256.c $(OPENSSL_PATH)/crypto/sha/sha3.c $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_adrs.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_hash_ctx.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_key.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_fors.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hash.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hypertree.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_params.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_wots.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_xmss.c $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c $(OPENSSL_PATH)/crypto/sm3/sm3.c $(OPENSSL_PATH)/crypto/stack/stack.c @@ -715,6 +725,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/slh_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c @@ -735,6 +746,7 @@ $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/slh_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c @@ -744,6 +756,7 @@ $(OPENSSL_PATH)/providers/common/der/der_ecx_key.c $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/der/der_slh_dsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c @@ -760,6 +773,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_ecx_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_slh_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c $(OPENSSL_PATH)/ssl/d1_lib.c @@ -1317,6 +1331,16 @@ $(OPENSSL_PATH)/crypto/sha/sha256.c $(OPENSSL_PATH)/crypto/sha/sha3.c $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_adrs.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_hash_ctx.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_key.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_fors.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hash.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hypertree.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_params.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_wots.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_xmss.c $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c $(OPENSSL_PATH)/crypto/sm3/sm3.c $(OPENSSL_PATH)/crypto/stack/stack.c @@ -1497,6 +1521,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/slh_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c @@ -1517,6 +1542,7 @@ $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/slh_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c @@ -1526,6 +1552,7 @@ $(OPENSSL_PATH)/providers/common/der/der_ecx_key.c $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/der/der_slh_dsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c @@ -1542,6 +1569,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_ecx_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_slh_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c $(OPENSSL_PATH)/ssl/d1_lib.c @@ -2122,6 +2150,16 @@ $(OPENSSL_PATH)/crypto/sha/sha256.c $(OPENSSL_PATH)/crypto/sha/sha3.c $(OPENSSL_PATH)/crypto/sha/sha512.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_adrs.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_hash_ctx.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_dsa_key.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_fors.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hash.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_hypertree.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_params.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_wots.c + $(OPENSSL_PATH)/crypto/slh_dsa/slh_xmss.c $(OPENSSL_PATH)/crypto/sm3/legacy_sm3.c $(OPENSSL_PATH)/crypto/sm3/sm3.c $(OPENSSL_PATH)/crypto/stack/stack.c @@ -2302,6 +2340,7 @@ $(OPENSSL_PATH)/providers/implementations/keymgmt/mac_legacy_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/ml_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/keymgmt/rsa_kmgmt.c + $(OPENSSL_PATH)/providers/implementations/keymgmt/slh_dsa_kmgmt.c $(OPENSSL_PATH)/providers/implementations/macs/cmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/gmac_prov.c $(OPENSSL_PATH)/providers/implementations/macs/hmac_prov.c @@ -2322,6 +2361,7 @@ $(OPENSSL_PATH)/providers/implementations/signature/mac_legacy_sig.c $(OPENSSL_PATH)/providers/implementations/signature/ml_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/signature/rsa_sig.c + $(OPENSSL_PATH)/providers/implementations/signature/slh_dsa_sig.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/aes_skmgmt.c $(OPENSSL_PATH)/providers/implementations/skeymgmt/generic.c $(OPENSSL_PATH)/ssl/record/methods/ssl3_cbc.c @@ -2331,6 +2371,7 @@ $(OPENSSL_PATH)/providers/common/der/der_ecx_key.c $(OPENSSL_PATH)/providers/common/der/der_ml_dsa_key.c $(OPENSSL_PATH)/providers/common/der/der_rsa_key.c + $(OPENSSL_PATH)/providers/common/der/der_slh_dsa_key.c $(OPENSSL_PATH)/providers/common/provider_ctx.c $(OPENSSL_PATH)/providers/common/provider_err.c $(OPENSSL_PATH)/providers/implementations/ciphers/ciphercommon.c @@ -2347,6 +2388,7 @@ $(OPENSSL_GEN_PATH)/providers/common/der/der_ecx_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_ml_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_rsa_gen.c + $(OPENSSL_GEN_PATH)/providers/common/der/der_slh_dsa_gen.c $(OPENSSL_GEN_PATH)/providers/common/der/der_wrap_gen.c $(OPENSSL_PATH)/ssl/bio_ssl.c $(OPENSSL_PATH)/ssl/d1_lib.c diff --git a/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c b/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c index ef4d4375ab..9ed9f180d4 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c +++ b/CryptoPkg/Library/OpensslLib/OpensslStub/uefiprov.c @@ -203,6 +203,9 @@ static const OSSL_ALGORITHM deflt_signature[] = { #ifndef OPENSSL_NO_ML_DSA { PROV_NAMES_ML_DSA_87, "provider=default", ossl_ml_dsa_87_signature_functions }, #endif +#ifndef OPENSSL_NO_SLH_DSA + { PROV_NAMES_SLH_DSA_SHAKE_256S, "provider=default", ossl_slh_dsa_shake_256s_signature_functions }, +#endif { NULL, NULL, NULL } }; @@ -242,6 +245,10 @@ static const OSSL_ALGORITHM deflt_keymgmt[] = { { PROV_NAMES_ML_DSA_87, "provider=default", ossl_ml_dsa_87_keymgmt_functions, PROV_DESCS_ML_DSA_87 }, #endif +#ifndef OPENSSL_NO_SLH_DSA + { PROV_NAMES_SLH_DSA_SHAKE_256S, "provider=default", ossl_slh_dsa_shake_256s_keymgmt_functions, + PROV_DESCS_SLH_DSA_SHAKE_256S }, +#endif { NULL, NULL, NULL } }; diff --git a/CryptoPkg/Library/OpensslLib/configure.py b/CryptoPkg/Library/OpensslLib/configure.py index e92fc721b1..ef0cbec131 100755 --- a/CryptoPkg/Library/OpensslLib/configure.py +++ b/CryptoPkg/Library/OpensslLib/configure.py @@ -72,7 +72,6 @@ def openssl_configure(openssldir, target, ec = True, lite = True): 'no-shared', 'no-siphash', 'no-siv', - 'no-slh-dsa', 'no-sm2', 'no-sm4', 'no-sock', @@ -93,7 +92,7 @@ def openssl_configure(openssldir, target, ec = True, lite = True): if not ec: cmdline += [ 'no-ec', 'no-camellia', 'no-cmac' ] if lite: - cmdline += [ 'no-camellia', 'no-dh', 'no-ecx', 'no-ml-dsa' ] + cmdline += [ 'no-camellia', 'no-dh', 'no-ecx', 'no-ml-dsa', 'no-slh-dsa' ] print('') print(f'# -*- configure openssl for {target} (ec={ec}, lite={lite}) -*-') rc = subprocess.run(cmdline, cwd = openssldir, diff --git a/CryptoPkg/Private/Protocol/Crypto.h b/CryptoPkg/Private/Protocol/Crypto.h index 3b6190362c..cbe97579e5 100644 --- a/CryptoPkg/Private/Protocol/Crypto.h +++ b/CryptoPkg/Private/Protocol/Crypto.h @@ -21,7 +21,7 @@ /// the EDK II Crypto Protocol is extended, this version define must be /// increased. /// -#define EDKII_CRYPTO_VERSION 26 +#define EDKII_CRYPTO_VERSION 27 /// /// EDK II Crypto Protocol forward declaration @@ -6459,6 +6459,300 @@ BOOLEAN IN UINTN SigSize ); +/** + Creates a new SLH-DSA context by Crypto NID. + + This function allocates and initializes a new SLH-DSA context for the specified + SLH-DSA variant. The context contains an EVP_PKEY structure initialized with the + SLH-DSA parameters. The caller must call SlhDsaFree() to release the context when done. + + Before keys can be used for signing or verification, they must be set using + SlhDsaSetPrivKey() or SlhDsaSetPubKey(). + + If Nid is not a supported SLH-DSA variant, then return NULL. + If memory allocation fails, then return NULL. + + @param[in] Nid Crypto NID of the SLH-DSA variant (e.g., CRYPTO_NID_SLH_DSA_SHAKE_256S). + + @retval Pointer to new SLH-DSA context if successful. + @retval NULL if Nid is unsupported or allocation failed. + +**/ +typedef +VOID * +(EFIAPI *EDKII_CRYPTO_SLH_DSA_NEW_BY_NID)( + IN UINTN Nid + ); + +/** + Frees an SLH-DSA context and all associated resources. + + This function releases all memory associated with the SLH-DSA context, including + the EVP_PKEY structure. After calling this function, the SlhDsaContext pointer + should not be used. + + If SlhDsaContext is NULL, then this function returns immediately without action. + + @param[in] SlhDsaContext Pointer to the SLH-DSA context to be released. + +**/ +typedef +VOID +(EFIAPI *EDKII_CRYPTO_SLH_DSA_FREE)( + IN VOID *SlhDsaContext + ); + +/** + Sets the SLH-DSA private key in the SLH-DSA context. + + This function imports a raw private key into the SLH-DSA context. The private key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the SLH-DSA variant (128 bytes for SLH-DSA-SHAKE-256s). + + OpenSSL automatically derives the public key from the private key, so after + calling this function, both signing and verification operations are possible. + + If SlhDsaContext is NULL, then return FALSE. + If PrivateKey is NULL, then return FALSE. + If PrivateKeySize is 0, then return FALSE. + If PrivateKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PrivateKey Pointer to raw private key bytes. + @param[in] PrivateKeySize Size of the private key in bytes. + + @retval TRUE SLH-DSA private key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_SLH_DSA_SET_PRIV_KEY)( + IN VOID *SlhDsaContext, + IN UINT8 *PrivateKey, + IN UINTN PrivateKeySize + ); + +/** + Generates and retrieves the public key from a private key context. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in] PublicKeySize Size of the PublicKey buffer in bytes. + + @retval TRUE Public key generated and retrieved successfully. + @retval FALSE Invalid parameters or public key extraction failed. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_SLH_DSA_GENERATE_PUB_KEY)( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Sets the SLH-DSA public key in the SLH-DSA context. + + This function imports a raw public key into the SLH-DSA context. The public key + must be in raw binary format (not PEM or DER encoded). The key size must match + the expected size for the SLH-DSA variant (64 bytes for SLH-DSA-SHAKE-256s). + + After setting the public key, the context can be used for signature verification + but not for signing (which requires the private key). + + If SlhDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is 0, then return FALSE. + If PublicKeySize does not match the expected size for the variant, then return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context created by SlhDsaNewByNid(). + @param[in] PublicKey Pointer to raw public key bytes. + @param[in] PublicKeySize Size of the public key in bytes. + + @retval TRUE SLH-DSA public key was set successfully. + @retval FALSE Invalid parameters or key size mismatch. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_SLH_DSA_SET_PUB_KEY)( + IN VOID *SlhDsaContext, + IN UINT8 *PublicKey, + IN UINTN PublicKeySize + ); + +/** + Retrieves the SLH-DSA public key from the SLH-DSA context. + + This function extracts the public key from the SLH-DSA context and copies it to + the provided buffer. The public key is returned in raw binary format. + + The context must have a key set (either via SlhDsaSetPrivKey() or SlhDsaSetPubKey()) + before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If PublicKey is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If the context does not contain a valid key, then return FALSE. + If PublicKey buffer is too small, PublicKeySize is updated with required size and return FALSE. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the key. + @param[out] PublicKey Pointer to buffer to receive the public key. + @param[in,out] PublicKeySize On input, size of PublicKey buffer in bytes. + On output, actual size of public key written. + + @retval TRUE SLH-DSA public key retrieved successfully. + @retval FALSE Invalid parameters or buffer too small. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_SLH_DSA_GET_PUB_KEY)( + IN VOID *SlhDsaContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ); + +/** + Retrieve the SLH-DSA Public Key from one DER-encoded X509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contain the retrieved + SLH-DSA public key component. Use SlhDsaFree() function to free the + resource. + + If Cert is NULL, then return FALSE. + If SlhDsaContext is NULL, then return FALSE. + + @retval TRUE SLH-DSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve SLH-DSA public key from X509 certificate. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_SLH_DSA_GET_PUBLIC_KEY_FROM_X509)( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **SlhDsaContext + ); + +/** + Retrieve the SLH-DSA Private Key from the password-protected PEM key data. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] SlhDsaContext Pointer to new-generated SLH-DSA context which contains the retrieved + SLH-DSA private key component. Use SlhDsaFree() function to free the + resource. + + If PemData is NULL, then return FALSE. + If SlhDsaContext is NULL, then return FALSE. + + @retval TRUE SLH-DSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_SLH_DSA_GET_PRIVATE_KEY_FROM_PEM)( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **SlhDsaContext + ); + +/** + Generates an SLH-DSA signature for a given message. + + This function creates an SLH-DSA signature using the private key stored in the + SLH-DSA context. SLH-DSA signatures can include an optional context string for + domain separation, allowing the same key to be used in different contexts + without creating security vulnerabilities. + + The context must contain a private key (set via SlhDsaSetPrivKey() or loaded + from PEM) before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0 or exceeds INT_MAX, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is NULL, then return FALSE. + Context may be NULL if no context string is used (ContextSize must be 0). + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the private key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to message data to be signed. + @param[in] MessageSize Size of message in bytes. + @param[out] Signature Pointer to buffer to receive the signature. + @param[in,out] SigSize On input, size of Signature buffer. + On output, actual size of signature (29792 bytes for SLH-DSA-SHAKE-256s). + + @retval TRUE SLH-DSA signature generated successfully. + @retval FALSE Invalid parameters or signature generation failed. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_SLH_DSA_SIGN)( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ); + +/** + Verifies the SLH-DSA signature for a given message. + + This function verifies an SLH-DSA signature against a message using the public key + contained in the SLH-DSA context. An optional context string can be provided which + must match the context used during signing. + + The context must contain a key (either public or private) set via SlhDsaSetPrivKey() + or SlhDsaSetPubKey() before calling this function. + + If SlhDsaContext is NULL, then return FALSE. + If Message is NULL, then return FALSE. + If MessageSize is 0, then return FALSE. + If Signature is NULL, then return FALSE. + If SigSize is 0 or exceeds INT_MAX, then return FALSE. + If SigSize does not match expected signature size for the variant, then return FALSE. + Context may be NULL if no context string is used. + + @param[in] SlhDsaContext Pointer to SLH-DSA context containing the public key. + @param[in] Context Optional context string for domain separation. + May be NULL for default context. + @param[in] ContextSize Size of context string in bytes. Set to 0 if Context is NULL. + @param[in] Message Pointer to the message data to verify. + @param[in] MessageSize Size of the message in bytes. + @param[in] Signature Pointer to the SLH-DSA signature to verify. + @param[in] SigSize Size of the signature in bytes. + Must match variant size (29792 bytes for SLH-DSA-SHAKE-256s). + + @retval TRUE SLH-DSA signature verification succeeded. + @retval FALSE SLH-DSA signature verification failed or invalid parameters. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_SLH_DSA_VERIFY)( + IN VOID *SlhDsaContext, + IN UINT8 *Context, + IN UINTN ContextSize, + IN CONST UINT8 *Message, + IN UINTN MessageSize, + IN UINT8 *Signature, + IN UINTN SigSize + ); + /// /// EDK II Crypto Protocol /// @@ -6793,6 +7087,17 @@ struct _EDKII_CRYPTO_PROTOCOL { EDKII_CRYPTO_ML_DSA_GET_PRIVATE_KEY_FROM_PEM MlDsaGetPrivateKeyFromPem; EDKII_CRYPTO_ML_DSA_SIGN MlDsaSign; EDKII_CRYPTO_ML_DSA_VERIFY MlDsaVerify; + /// SLH-DSA + EDKII_CRYPTO_SLH_DSA_NEW_BY_NID SlhDsaNewByNid; + EDKII_CRYPTO_SLH_DSA_FREE SlhDsaFree; + EDKII_CRYPTO_SLH_DSA_SET_PRIV_KEY SlhDsaSetPrivKey; + EDKII_CRYPTO_SLH_DSA_GENERATE_PUB_KEY SlhDsaGeneratePubKey; + EDKII_CRYPTO_SLH_DSA_SET_PUB_KEY SlhDsaSetPubKey; + EDKII_CRYPTO_SLH_DSA_GET_PUB_KEY SlhDsaGetPubKey; + EDKII_CRYPTO_SLH_DSA_GET_PUBLIC_KEY_FROM_X509 SlhDsaGetPublicKeyFromX509; + EDKII_CRYPTO_SLH_DSA_GET_PRIVATE_KEY_FROM_PEM SlhDsaGetPrivateKeyFromPem; + EDKII_CRYPTO_SLH_DSA_SIGN SlhDsaSign; + EDKII_CRYPTO_SLH_DSA_VERIFY SlhDsaVerify; }; extern GUID gEdkiiCryptoProtocolGuid; diff --git a/CryptoPkg/Readme.md b/CryptoPkg/Readme.md index 1e1c911599..033dd5dac8 100644 --- a/CryptoPkg/Readme.md +++ b/CryptoPkg/Readme.md @@ -236,6 +236,7 @@ also configured. | Camellia | N | N | | | C-Full | C-Full | | | EdDsa | N | N | | | C-Full | C-Full | | | MlDsa | N | N | | | C-Full | C-Full | | +| SlhDsa | N | N | | | C-Full | C-Full | | ## Platform Configuration of Cryptographic Services diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c index 8ce8acdb4f..b376ad5438 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c @@ -31,6 +31,7 @@ SUITE_DESC mSuiteDesc[] = { { "EC verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mEcTestNum, mEcTest }, { "ED-DSA verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mEdDsaTestNum, mEdDsaTest }, { "ML-DSA verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mMlDsaTestNum, mMlDsaTest }, + { "SLH-DSA verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mSlhDsaTestNum, mSlhDsaTest }, { "X509 Verify tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mX509TestNum, mX509Test }, { "PKCS7 Attach Content tests", "CryptoPkg.BaseCryptLib", NULL, NULL, &mPkcs7ContentTestNum, mPkcs7ContentTest }, }; diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/SlhDsaTestVectors.h b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/SlhDsaTestVectors.h new file mode 100644 index 0000000000..38f4a4188c --- /dev/null +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/SlhDsaTestVectors.h @@ -0,0 +1,2581 @@ +/** @file + SLH-DSA Test Vectors + + This file contains test vectors for SLH-DSA-SHAKE-256s cryptographic operations. + The vectors include: + - mSlhDsaShake256sTestCert: X.509 DER certificate containing SLH-DSA-SHAKE-256s public key + - mSlhDsaShake256sTestPemKey: PEM-encoded SLH-DSA-SHAKE-256s private key + + IMPORTANT: These test vectors form a MATCHING KEY PAIR. The certificate + was generated from the private key in the PEM file, ensuring that: + - Signatures created with the private key can be verified with the public key + - Test operations using both keys will succeed + + Generated: 2026-07-13 + OpenSSL Version: 3.5.7 + +Copyright (c) 2026, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +// PEM key size: 258 bytes +// DER cert size: 30285 bytes + +// +// slhdsa_shake256s_cert.der as C array +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mSlhDsaShake256sTestCert[] = { + 0x30, 0x82, 0x76, 0x49, 0x30, 0x82, 0x01, 0xd3, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x14, 0x70, 0x38, 0xd6, 0x20, 0x0a, 0xe8, 0x83, 0xce, 0xc8, + 0x87, 0x3d, 0x08, 0x75, 0x8b, 0x56, 0xee, 0xd8, 0x60, 0x69, 0x80, 0x30, + 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x1e, + 0x30, 0x70, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, + 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, + 0x0c, 0x09, 0x54, 0x65, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, + 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x08, 0x54, 0x65, + 0x73, 0x74, 0x43, 0x69, 0x74, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, + 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4f, 0x72, 0x67, + 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x08, 0x54, + 0x65, 0x73, 0x74, 0x55, 0x6e, 0x69, 0x74, 0x31, 0x15, 0x30, 0x13, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c, 0x53, 0x4c, 0x48, 0x2d, 0x44, 0x53, + 0x41, 0x20, 0x54, 0x65, 0x73, 0x74, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x36, + 0x30, 0x37, 0x31, 0x34, 0x30, 0x36, 0x33, 0x32, 0x31, 0x36, 0x5a, 0x17, + 0x0d, 0x33, 0x36, 0x30, 0x37, 0x31, 0x31, 0x30, 0x36, 0x33, 0x32, 0x31, + 0x36, 0x5a, 0x30, 0x70, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, + 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, + 0x04, 0x08, 0x0c, 0x09, 0x54, 0x65, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, + 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x08, + 0x54, 0x65, 0x73, 0x74, 0x43, 0x69, 0x74, 0x79, 0x31, 0x10, 0x30, 0x0e, + 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4f, + 0x72, 0x67, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, + 0x08, 0x54, 0x65, 0x73, 0x74, 0x55, 0x6e, 0x69, 0x74, 0x31, 0x15, 0x30, + 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c, 0x53, 0x4c, 0x48, 0x2d, + 0x44, 0x53, 0x41, 0x20, 0x54, 0x65, 0x73, 0x74, 0x30, 0x50, 0x30, 0x0b, + 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x1e, 0x03, + 0x41, 0x00, 0xf7, 0xc6, 0x1c, 0x16, 0x76, 0xae, 0x47, 0x28, 0xbe, 0xb0, + 0xcb, 0xac, 0xe6, 0xe6, 0xe8, 0xad, 0x34, 0x60, 0xa1, 0x40, 0xf5, 0x1d, + 0x4e, 0x7f, 0x32, 0xa1, 0x1c, 0x69, 0xe0, 0xd1, 0x3d, 0x8e, 0x9e, 0x23, + 0xdf, 0xf3, 0x2a, 0x45, 0xa7, 0x5d, 0x12, 0x9b, 0xac, 0xe5, 0xdb, 0x87, + 0x81, 0xdc, 0x88, 0x9f, 0xcf, 0xa4, 0x36, 0xaa, 0xb0, 0xe6, 0x4e, 0x7c, + 0x29, 0xda, 0x31, 0xd4, 0xe4, 0xcf, 0xa3, 0x53, 0x30, 0x51, 0x30, 0x1d, + 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x98, 0xc9, 0xe2, + 0x2e, 0x10, 0xdf, 0xaa, 0xa4, 0x33, 0xb8, 0x04, 0xd6, 0x59, 0xd3, 0xb9, + 0x71, 0x1f, 0x08, 0xa0, 0x08, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, + 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x98, 0xc9, 0xe2, 0x2e, 0x10, 0xdf, + 0xaa, 0xa4, 0x33, 0xb8, 0x04, 0xd6, 0x59, 0xd3, 0xb9, 0x71, 0x1f, 0x08, + 0xa0, 0x08, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, + 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0b, 0x06, 0x09, 0x60, + 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x1e, 0x03, 0x82, 0x74, 0x61, + 0x00, 0xab, 0x2d, 0x81, 0x77, 0xfc, 0x24, 0x07, 0x95, 0xab, 0x0d, 0xeb, + 0xad, 0x6e, 0x65, 0x82, 0xaa, 0x7d, 0x04, 0xc1, 0xc1, 0x75, 0xba, 0xf4, + 0xa5, 0x6e, 0x45, 0x9c, 0x50, 0x49, 0xb5, 0xed, 0x9d, 0x28, 0x00, 0xd4, + 0x7a, 0xe9, 0xec, 0x98, 0x6d, 0x59, 0xd0, 0x37, 0x36, 0x44, 0x3f, 0x81, + 0xdd, 0x3c, 0x6e, 0x5f, 0x7f, 0xf4, 0x85, 0xf8, 0xeb, 0x2f, 0xe4, 0x53, + 0x35, 0xac, 0x4c, 0x42, 0x8c, 0x60, 0x12, 0xfe, 0xe8, 0x72, 0xaa, 0xa3, + 0xbb, 0x89, 0xda, 0x63, 0x51, 0x39, 0x30, 0xfc, 0x48, 0xd8, 0xe0, 0x61, + 0xc2, 0xc7, 0xba, 0x51, 0x69, 0x82, 0xd0, 0xab, 0xfb, 0x1b, 0x55, 0xfe, + 0xac, 0x43, 0x0a, 0x61, 0xa5, 0xfd, 0x38, 0xa0, 0x73, 0xbf, 0x0d, 0x3b, + 0x89, 0x83, 0x2e, 0xc5, 0x4b, 0x6a, 0x53, 0x3a, 0x99, 0xc3, 0xf8, 0x5a, + 0x3a, 0xde, 0x98, 0x07, 0x87, 0x80, 0xbc, 0x6a, 0x47, 0x17, 0x96, 0x27, + 0xa1, 0x9d, 0x0b, 0xdd, 0xff, 0xf7, 0xfa, 0xca, 0x33, 0xac, 0x0f, 0xed, + 0x24, 0x81, 0x14, 0x1c, 0x53, 0x26, 0xe8, 0x8d, 0x22, 0x9a, 0x73, 0xe0, + 0xe4, 0x91, 0x3c, 0x90, 0xc5, 0xd9, 0x68, 0xc9, 0xf0, 0x7e, 0x8d, 0x40, + 0x2a, 0xe4, 0xdc, 0x82, 0xf9, 0xce, 0xbd, 0xbb, 0xc2, 0x9c, 0xf4, 0x49, + 0x50, 0x30, 0x19, 0xc0, 0x10, 0x2f, 0x0f, 0xbb, 0xa7, 0xca, 0x52, 0x06, + 0x8e, 0xa1, 0x1c, 0xbd, 0x47, 0x4e, 0xa0, 0x3f, 0xb7, 0x2f, 0x59, 0x92, + 0xb8, 0x38, 0xde, 0x6c, 0xfb, 0x6a, 0x0b, 0xf4, 0x08, 0xe2, 0x4f, 0xc1, + 0x19, 0x62, 0xad, 0x02, 0x19, 0x70, 0xa5, 0xf2, 0xa9, 0xdb, 0x84, 0xa0, + 0xd3, 0x01, 0x72, 0x8b, 0x40, 0x1a, 0x80, 0x43, 0x97, 0x39, 0x0b, 0xa8, + 0xad, 0x9a, 0xe9, 0x36, 0xb1, 0xab, 0x91, 0x60, 0xf1, 0x44, 0xa1, 0x7f, + 0xa3, 0x70, 0xca, 0x6a, 0x33, 0xcf, 0x12, 0xe4, 0xb5, 0x26, 0x48, 0x0f, + 0xc8, 0xef, 0x6e, 0xc7, 0xce, 0xfe, 0xc6, 0x24, 0x89, 0x0d, 0x02, 0x9f, + 0x8b, 0x55, 0x6a, 0xdb, 0xf6, 0xe7, 0xed, 0xc8, 0xdc, 0xbc, 0xf8, 0xca, + 0x15, 0x79, 0x25, 0xf3, 0x57, 0xc4, 0x07, 0x31, 0x0a, 0x97, 0x55, 0xec, + 0x5d, 0x30, 0xbe, 0x44, 0x64, 0xec, 0x73, 0x1f, 0xaf, 0x92, 0x56, 0xdd, + 0x98, 0x96, 0x52, 0x0a, 0x8c, 0xc0, 0x3f, 0x8a, 0xe6, 0xa2, 0xec, 0x44, + 0x0f, 0xfc, 0x3b, 0xa6, 0xaa, 0xc8, 0x21, 0x6b, 0x45, 0x7f, 0xea, 0x48, + 0x36, 0x75, 0xb5, 0xbf, 0x89, 0x42, 0xab, 0x22, 0x48, 0xbe, 0xa3, 0xbd, + 0x40, 0x2b, 0x89, 0xb5, 0x8c, 0x17, 0x5b, 0x28, 0xf4, 0x67, 0x8a, 0x84, + 0x1f, 0x94, 0x24, 0x39, 0x7c, 0xf8, 0x53, 0x21, 0xb3, 0xa7, 0x91, 0x55, + 0x4e, 0x59, 0x06, 0x84, 0xe9, 0x29, 0x06, 0xc7, 0x94, 0x55, 0x87, 0x9d, + 0x0e, 0x11, 0xf3, 0x2a, 0xb7, 0x4e, 0xb4, 0x25, 0xab, 0xc2, 0xd2, 0xd2, + 0x41, 0x4b, 0x8d, 0xb6, 0x2c, 0xf9, 0x72, 0xfc, 0x95, 0xc1, 0x98, 0xf0, + 0xd0, 0xe3, 0xde, 0x99, 0xd9, 0x5b, 0x13, 0x2b, 0x4c, 0x18, 0x34, 0xfe, + 0x20, 0x80, 0xf2, 0x77, 0xc4, 0x51, 0x40, 0x54, 0x7a, 0x15, 0x34, 0xdf, + 0xd3, 0x00, 0x5a, 0xb2, 0x86, 0x15, 0x68, 0x5a, 0xf9, 0xff, 0xc7, 0x6e, + 0xc2, 0xe9, 0xe0, 0x54, 0x59, 0xca, 0xd6, 0xff, 0x5c, 0x32, 0xa0, 0x6a, + 0xdb, 0xf1, 0xb2, 0xad, 0xec, 0xfa, 0x50, 0x50, 0x86, 0x4a, 0xff, 0x21, + 0xa7, 0x29, 0x42, 0x4d, 0xff, 0x86, 0xa8, 0x4a, 0x07, 0x42, 0xb7, 0x32, + 0x80, 0x96, 0x7b, 0xc8, 0x62, 0x1d, 0x96, 0x24, 0x2b, 0x08, 0xee, 0x42, + 0x40, 0x6d, 0xd1, 0x13, 0x61, 0xa7, 0xc6, 0x45, 0x8b, 0x94, 0x4c, 0x25, + 0xb6, 0x45, 0x1f, 0x50, 0x0b, 0xd3, 0xdb, 0x82, 0x67, 0x35, 0x74, 0x3e, + 0x86, 0xb0, 0xaa, 0xcd, 0xf3, 0xe9, 0xa2, 0x10, 0xd3, 0xdb, 0x68, 0x45, + 0x8f, 0x85, 0xa1, 0xae, 0x11, 0xaa, 0x09, 0x72, 0x8a, 0xdb, 0x26, 0x2a, + 0x2d, 0x28, 0x78, 0xdb, 0x22, 0x59, 0xf2, 0x70, 0x9e, 0x3e, 0x96, 0x73, + 0x62, 0x8f, 0x28, 0xe0, 0xaa, 0xd2, 0x28, 0x77, 0x32, 0xfc, 0xc5, 0x3c, + 0xbb, 0xcd, 0xe1, 0xed, 0xa4, 0x55, 0x27, 0x1c, 0xa4, 0x82, 0x36, 0xb4, + 0x74, 0xfa, 0xf8, 0xc9, 0xe0, 0xae, 0x4f, 0xb4, 0xa7, 0xc9, 0xea, 0xa1, + 0xb4, 0x93, 0x38, 0x56, 0x12, 0xb4, 0xac, 0xd1, 0x25, 0x13, 0x8c, 0x12, + 0xce, 0xbb, 0xea, 0x07, 0xdd, 0xba, 0x36, 0xd3, 0x10, 0xc1, 0xad, 0xab, + 0xea, 0xb9, 0x68, 0x35, 0xf9, 0x07, 0x6c, 0xa9, 0xdd, 0xd8, 0xe5, 0xc7, + 0x83, 0x29, 0xd6, 0xf5, 0xa6, 0x36, 0xc2, 0xca, 0x87, 0xf6, 0x7f, 0x0e, + 0x10, 0x07, 0xa1, 0x33, 0xd3, 0x9c, 0xd6, 0x27, 0x24, 0x35, 0xe6, 0x52, + 0xdc, 0x57, 0xed, 0x6f, 0x08, 0x06, 0x90, 0xfb, 0x2c, 0xe0, 0xa5, 0x6b, + 0x48, 0x01, 0x81, 0xa5, 0x4f, 0x15, 0x8b, 0xce, 0xd2, 0x33, 0x4b, 0xf9, + 0xaf, 0xb5, 0xe6, 0xab, 0x70, 0xd2, 0x0e, 0x1b, 0x12, 0xa5, 0xe8, 0x69, + 0x49, 0xb4, 0x14, 0xa2, 0xaa, 0x79, 0xb8, 0x4d, 0x60, 0xb1, 0xb5, 0x6e, + 0xd2, 0x86, 0xa4, 0x90, 0x37, 0x7a, 0x80, 0xa8, 0xc2, 0x1c, 0xad, 0x30, + 0xf0, 0x3f, 0xa4, 0x3f, 0xd0, 0x0e, 0x03, 0x1a, 0xce, 0x2b, 0x30, 0x60, + 0x8a, 0x6e, 0x40, 0xf9, 0x87, 0x23, 0x47, 0x0a, 0xf0, 0x60, 0x5c, 0x33, + 0xe8, 0x75, 0x92, 0x53, 0x02, 0xb4, 0x3b, 0x79, 0xba, 0xb0, 0x22, 0xa8, + 0x34, 0xd7, 0x1e, 0x0e, 0x87, 0x9b, 0x47, 0xf9, 0x2a, 0xee, 0x30, 0x63, + 0x38, 0xc5, 0xda, 0x76, 0x00, 0x7e, 0x40, 0x03, 0x8e, 0x35, 0xd8, 0xd5, + 0x25, 0xad, 0x6f, 0x45, 0xc2, 0x3d, 0x1b, 0xb6, 0xb5, 0x81, 0x8d, 0xcb, + 0x1a, 0xb0, 0xd8, 0x8c, 0xbb, 0xdf, 0x3c, 0xc3, 0xe7, 0x29, 0xde, 0x7a, + 0xe3, 0xf6, 0x14, 0xfb, 0xea, 0xa5, 0x28, 0x4f, 0x2c, 0x08, 0x03, 0xc6, + 0x26, 0x88, 0x96, 0xda, 0x28, 0x95, 0x3f, 0xd0, 0xc2, 0x36, 0xd4, 0x46, + 0x81, 0xfc, 0x34, 0xba, 0x85, 0x37, 0xbc, 0xcc, 0xd3, 0xd1, 0xbf, 0x5f, + 0xba, 0x55, 0xfa, 0x65, 0x83, 0x44, 0x29, 0xa3, 0x6c, 0xd8, 0x38, 0xe6, + 0x3d, 0xab, 0x38, 0xeb, 0xf4, 0xfb, 0xa2, 0xa1, 0x97, 0x30, 0xfc, 0x04, + 0x8c, 0x04, 0xec, 0x24, 0xc1, 0xed, 0x4a, 0x96, 0x7e, 0x7b, 0x87, 0x62, + 0xad, 0x2e, 0x6e, 0x29, 0xe8, 0x81, 0x6f, 0x62, 0x14, 0x2f, 0xbd, 0x56, + 0x89, 0xb6, 0xa6, 0xa1, 0x63, 0xc1, 0x82, 0x6c, 0x69, 0x68, 0xc1, 0x33, + 0xca, 0x06, 0x32, 0x95, 0x5e, 0x79, 0x9e, 0x69, 0x88, 0xc2, 0x63, 0x58, + 0x7b, 0xc6, 0x37, 0x1e, 0x59, 0xd3, 0x66, 0x40, 0x78, 0x49, 0x40, 0xeb, + 0xe9, 0xc8, 0xbe, 0xff, 0x71, 0xd4, 0x1b, 0xac, 0x26, 0x7f, 0xda, 0x4a, + 0x4a, 0xcc, 0x64, 0x10, 0xbc, 0x00, 0xbb, 0x3d, 0x49, 0x51, 0x38, 0x0e, + 0x99, 0x0e, 0x29, 0x57, 0x3a, 0x8e, 0x70, 0xc1, 0x75, 0x1e, 0xf8, 0xad, + 0xa9, 0x8d, 0xcc, 0xca, 0xd9, 0x07, 0x5e, 0x9c, 0x3b, 0x99, 0xe6, 0xd0, + 0x00, 0xa9, 0xb6, 0xc7, 0x37, 0xa5, 0x4b, 0x48, 0xb7, 0xb0, 0xc7, 0xa0, + 0xe3, 0xed, 0xdd, 0x90, 0xaa, 0x5f, 0x7e, 0x6a, 0xa9, 0x11, 0x6d, 0x0c, + 0x04, 0xfc, 0x78, 0x7a, 0xbe, 0xff, 0xa0, 0x4d, 0xe2, 0xc6, 0xcd, 0x05, + 0x61, 0x0e, 0x3f, 0x2b, 0xb1, 0x9a, 0xc5, 0xca, 0x33, 0x2a, 0x54, 0x04, + 0x5f, 0x7a, 0x3d, 0x42, 0xe8, 0xbe, 0xd8, 0x63, 0x71, 0xde, 0xec, 0x5f, + 0xed, 0x5f, 0x4e, 0x1b, 0xee, 0xdc, 0x85, 0xc7, 0x2d, 0x0f, 0x5b, 0x7a, + 0x62, 0xbd, 0xf8, 0x82, 0x82, 0xd7, 0x1d, 0xa9, 0xcd, 0x00, 0x0e, 0x7c, + 0x02, 0x3d, 0x6d, 0x7b, 0x06, 0xfd, 0x0b, 0xa3, 0xde, 0xd3, 0x11, 0x68, + 0x8c, 0x60, 0xeb, 0xe7, 0x59, 0xd6, 0xcb, 0x75, 0x68, 0xd0, 0xa5, 0xca, + 0x45, 0x38, 0x61, 0x83, 0xcd, 0x30, 0x9e, 0x11, 0xd2, 0xdc, 0x72, 0xa2, + 0xc9, 0x46, 0x80, 0xdf, 0x3a, 0x3f, 0x49, 0x6f, 0x82, 0x28, 0x66, 0x02, + 0xc0, 0x3c, 0xec, 0xcc, 0xd7, 0x52, 0xfc, 0x91, 0x35, 0x6b, 0x86, 0x4f, + 0x84, 0xa1, 0x15, 0x7a, 0x9c, 0x5b, 0xc8, 0xc7, 0xf9, 0xb1, 0xc0, 0xf6, + 0xa2, 0x19, 0x5f, 0xe3, 0x2c, 0x36, 0xb9, 0xd9, 0x36, 0xe2, 0x3c, 0xb4, + 0x76, 0x1a, 0x2b, 0xcb, 0xb7, 0xf4, 0xfa, 0xbf, 0x57, 0x4a, 0x05, 0x80, + 0x38, 0xd6, 0x9f, 0x6b, 0xdf, 0x00, 0x2c, 0x02, 0xa4, 0xb2, 0xbe, 0x6e, + 0xdd, 0xa3, 0x6a, 0x48, 0xe4, 0x15, 0xd3, 0x1d, 0x60, 0x8d, 0xd6, 0x6f, + 0xb4, 0xf0, 0x44, 0xe8, 0x42, 0x07, 0x3e, 0xbc, 0x92, 0xaa, 0x11, 0xa7, + 0x42, 0xe3, 0xfb, 0x0d, 0x1c, 0x3c, 0x28, 0xab, 0x97, 0xba, 0x23, 0x7e, + 0xa4, 0x25, 0x83, 0x2a, 0xee, 0xc1, 0x25, 0x69, 0xc0, 0x76, 0x68, 0x35, + 0xe1, 0x1b, 0x9b, 0x96, 0x48, 0xfe, 0x86, 0xe2, 0xeb, 0x0e, 0x36, 0xc9, + 0x93, 0x41, 0x54, 0x74, 0xf7, 0xde, 0x3c, 0x8a, 0x65, 0x02, 0x0d, 0xe8, + 0x8b, 0x23, 0xb5, 0x0d, 0xf9, 0x2f, 0x64, 0x36, 0x79, 0x82, 0xf0, 0xe4, + 0xa8, 0x34, 0x23, 0xe8, 0xfd, 0x69, 0x05, 0x30, 0xf6, 0xc5, 0x18, 0x75, + 0xea, 0xa9, 0xcb, 0xbe, 0xcf, 0x4f, 0xc1, 0x96, 0x85, 0x47, 0x51, 0xb5, + 0xf0, 0xf2, 0xbc, 0xf5, 0x84, 0xe4, 0x31, 0xba, 0x4a, 0x7d, 0x02, 0x4e, + 0x6f, 0xcc, 0x8e, 0xa8, 0xc9, 0x43, 0x6e, 0xdd, 0x27, 0xd0, 0x81, 0x08, + 0xf5, 0xbe, 0xdf, 0xa6, 0x9a, 0x47, 0x4e, 0x05, 0x5f, 0xca, 0xd3, 0x8e, + 0x1a, 0x3d, 0x11, 0x92, 0xd7, 0x00, 0x2e, 0xcd, 0xf3, 0x86, 0xe7, 0x98, + 0x2b, 0xdc, 0x84, 0x3d, 0xe2, 0xf2, 0x70, 0x66, 0x16, 0xf2, 0xb2, 0x17, + 0xca, 0xf8, 0xa2, 0x70, 0x67, 0x8c, 0x25, 0xda, 0xcd, 0x87, 0x38, 0x96, + 0x3e, 0x67, 0x32, 0x5c, 0x0c, 0xae, 0x53, 0x41, 0xb2, 0x44, 0x20, 0x7f, + 0x8b, 0xd5, 0x95, 0x4e, 0x7b, 0x44, 0x40, 0xd8, 0x73, 0x22, 0x6a, 0x5b, + 0xe0, 0x36, 0x22, 0xb0, 0x56, 0x3c, 0x4c, 0x81, 0xe7, 0x3f, 0x79, 0x34, + 0x8e, 0x88, 0xf0, 0x9a, 0x1a, 0x94, 0x7a, 0x68, 0xd6, 0x3a, 0xea, 0x85, + 0x87, 0x36, 0x6f, 0x58, 0xea, 0x90, 0xce, 0xb5, 0x6c, 0x03, 0x6a, 0xf0, + 0xe4, 0xf6, 0xc7, 0xe8, 0xec, 0xcc, 0x1e, 0x1c, 0x42, 0xba, 0xa8, 0x45, + 0x3e, 0x61, 0xb5, 0x0b, 0xb8, 0x6a, 0x34, 0x49, 0x98, 0x9f, 0x85, 0xcc, + 0xc0, 0xb9, 0x37, 0x36, 0x3b, 0x25, 0x31, 0xb8, 0x43, 0xd2, 0x64, 0x42, + 0x89, 0xec, 0x13, 0x2b, 0x9e, 0x03, 0xd1, 0x4f, 0x5f, 0xa8, 0x3c, 0xab, + 0xa4, 0xc3, 0xd5, 0xc0, 0x2b, 0xf1, 0x81, 0xa6, 0xc7, 0x3e, 0xfe, 0x07, + 0x13, 0x2f, 0xa6, 0xab, 0x9a, 0x8a, 0xdd, 0x8e, 0x45, 0xbb, 0xaa, 0x66, + 0xee, 0x6a, 0xdd, 0x4e, 0x6f, 0x22, 0x97, 0x80, 0xcb, 0x7e, 0xb0, 0x39, + 0xb8, 0xc9, 0xf8, 0x1e, 0x19, 0xad, 0x6c, 0x2a, 0x62, 0x5c, 0x0b, 0x2a, + 0xf3, 0x8c, 0x77, 0xf1, 0x38, 0xde, 0x10, 0x9b, 0x37, 0xad, 0xaa, 0xae, + 0xa1, 0x4a, 0x1d, 0x7d, 0x38, 0xf6, 0xce, 0x39, 0x0f, 0x43, 0xb8, 0x6e, + 0x8c, 0x80, 0xcc, 0x8f, 0x3e, 0x78, 0xd5, 0xea, 0x8b, 0x10, 0x86, 0x69, + 0xcd, 0x07, 0x5b, 0xaa, 0xc8, 0x37, 0x76, 0xe9, 0x88, 0x65, 0x68, 0x00, + 0x4a, 0xc3, 0x04, 0x7a, 0x9d, 0x9c, 0x4d, 0xdd, 0x5d, 0x3e, 0xe2, 0xc9, + 0xad, 0x76, 0xcc, 0x76, 0xfc, 0xee, 0xd6, 0xbf, 0x1e, 0xfd, 0x6e, 0x41, + 0xc3, 0x6a, 0xb9, 0x07, 0x2f, 0x93, 0x7c, 0x71, 0x0b, 0xd2, 0x1e, 0xc1, + 0xa6, 0xd3, 0x2a, 0x4e, 0x10, 0x28, 0xdd, 0x69, 0xab, 0xc4, 0xca, 0xc0, + 0x3f, 0x20, 0x22, 0xe9, 0xb1, 0x4b, 0xe9, 0xeb, 0xbc, 0x05, 0xc2, 0x27, + 0x11, 0xbb, 0x0f, 0x6d, 0xfc, 0x4d, 0xc5, 0x02, 0x0f, 0xca, 0x1c, 0x5e, + 0x5e, 0x16, 0x25, 0x82, 0xc2, 0xb6, 0x89, 0x61, 0x7b, 0x02, 0x24, 0x16, + 0xe9, 0x22, 0xd0, 0x50, 0x76, 0x00, 0x6d, 0xfe, 0xda, 0xac, 0xcf, 0x8b, + 0xc3, 0xcf, 0xd4, 0x8c, 0xec, 0xf7, 0x5f, 0x51, 0xf7, 0x99, 0x0a, 0x8a, + 0x58, 0xed, 0xb1, 0x96, 0x42, 0x26, 0x00, 0x22, 0xa9, 0x74, 0x52, 0xbc, + 0x28, 0xd5, 0x71, 0x12, 0x91, 0xb6, 0x7c, 0xed, 0xea, 0x1c, 0xfe, 0xfb, + 0xf7, 0x54, 0xf3, 0x68, 0x7d, 0x92, 0xb3, 0xfb, 0x0b, 0x4d, 0x73, 0x75, + 0xc8, 0xc5, 0xae, 0xd8, 0xda, 0x43, 0x95, 0x9d, 0x63, 0x2e, 0x35, 0x08, + 0x6e, 0xff, 0x49, 0xc4, 0xa1, 0x1b, 0xf4, 0x9f, 0x85, 0x21, 0x5e, 0x57, + 0x3c, 0x02, 0x02, 0xe4, 0xfb, 0x98, 0xe1, 0x06, 0x5c, 0xf7, 0xe7, 0x7a, + 0x31, 0x31, 0x1e, 0x6d, 0x5d, 0xbb, 0x38, 0x34, 0x54, 0x05, 0xc3, 0x6d, + 0x88, 0xca, 0x81, 0xb7, 0x69, 0x92, 0xe5, 0x4c, 0x97, 0xf7, 0x13, 0x72, + 0x62, 0x9c, 0x11, 0x9b, 0xe3, 0x5c, 0x2a, 0x7d, 0xe5, 0x6e, 0x63, 0x27, + 0x68, 0x7d, 0xa8, 0xc7, 0x75, 0x18, 0x85, 0x46, 0xcd, 0x9a, 0x0f, 0x62, + 0xb1, 0x6c, 0x1e, 0x2f, 0x19, 0xb4, 0x5e, 0x76, 0xa0, 0x42, 0x1d, 0xe4, + 0x7c, 0xdc, 0x1d, 0x9d, 0x16, 0xcf, 0x4c, 0xf5, 0x74, 0xbb, 0x05, 0x9b, + 0xc4, 0x17, 0x06, 0xe3, 0x49, 0xb4, 0x27, 0x0b, 0x74, 0x5a, 0x57, 0xae, + 0x78, 0x08, 0xaa, 0x9c, 0xf2, 0x5f, 0xbc, 0x03, 0xc0, 0x30, 0xec, 0x5f, + 0x05, 0x2b, 0xd9, 0xbb, 0x5a, 0x1d, 0x6d, 0x90, 0x48, 0x11, 0x9d, 0x4e, + 0x3a, 0x1a, 0x2b, 0xb9, 0x98, 0x96, 0xc0, 0x10, 0x2b, 0x36, 0xcd, 0xef, + 0x06, 0xac, 0x02, 0x87, 0x24, 0x95, 0x6e, 0x62, 0x63, 0xd1, 0x19, 0x0b, + 0x73, 0x14, 0xfa, 0x30, 0xd7, 0xa3, 0x61, 0xca, 0xf0, 0x9f, 0x17, 0x5d, + 0xb9, 0x16, 0xa5, 0xe3, 0xfe, 0x5f, 0x63, 0x19, 0x86, 0x47, 0xd9, 0x9f, + 0xdb, 0x10, 0x6c, 0x25, 0xa5, 0xdc, 0xb1, 0xfb, 0xc7, 0xdf, 0x49, 0x77, + 0x8e, 0xd7, 0x0f, 0x7d, 0xd2, 0x90, 0x01, 0x38, 0xf5, 0x45, 0x21, 0x9a, + 0x0b, 0x9d, 0xf0, 0xd8, 0xc8, 0x69, 0x9c, 0x68, 0x69, 0x97, 0x15, 0xee, + 0x0f, 0xbe, 0xd0, 0x2f, 0xdc, 0x62, 0x49, 0x4f, 0x86, 0x4e, 0x31, 0x0b, + 0x8d, 0xe6, 0x27, 0xc4, 0x41, 0x94, 0x5d, 0x5f, 0x8d, 0x70, 0xd0, 0x41, + 0x1d, 0x74, 0x4e, 0x91, 0xd0, 0xff, 0xbb, 0x70, 0xe6, 0xd7, 0x14, 0x26, + 0x91, 0xc3, 0x35, 0xec, 0x8d, 0x92, 0x04, 0xcb, 0xb5, 0xa2, 0x13, 0x28, + 0x85, 0x44, 0x67, 0x04, 0x9a, 0x24, 0xe7, 0xa3, 0x91, 0x06, 0xad, 0xab, + 0xed, 0x9e, 0xdf, 0x0f, 0x42, 0xb4, 0xf8, 0x4a, 0xee, 0x40, 0xa7, 0xe2, + 0xc3, 0xbe, 0xd3, 0x27, 0x52, 0xe3, 0xd3, 0x12, 0xa4, 0xa8, 0x8a, 0xf5, + 0xd4, 0xdb, 0x78, 0xb9, 0xaa, 0x3d, 0x46, 0xf1, 0xb7, 0xc4, 0x66, 0xe2, + 0xcd, 0x2e, 0x3e, 0x0f, 0xad, 0x44, 0x56, 0xb1, 0xf9, 0x7a, 0x11, 0x3f, + 0x6b, 0x5f, 0x55, 0xe3, 0xb1, 0x18, 0xf9, 0xb3, 0xc2, 0xfd, 0xc4, 0xb5, + 0x93, 0x50, 0xcb, 0x4f, 0x5b, 0x22, 0x1d, 0x81, 0xd5, 0xc5, 0x1a, 0x52, + 0xa8, 0x35, 0xeb, 0xe0, 0xb7, 0x8c, 0xf0, 0x13, 0xd1, 0xf9, 0x07, 0xbe, + 0xda, 0x61, 0xbc, 0x3b, 0x4c, 0x5e, 0x06, 0x7b, 0x7d, 0xeb, 0x55, 0x9d, + 0x2e, 0xaa, 0xaf, 0x8e, 0x5b, 0x2b, 0x7a, 0x7c, 0xbd, 0xe2, 0x60, 0x0a, + 0xff, 0xf1, 0x6e, 0x55, 0xb8, 0x95, 0xbf, 0x45, 0xc8, 0x45, 0x25, 0xce, + 0x06, 0x15, 0x67, 0xff, 0xfe, 0x46, 0x43, 0xe4, 0xc9, 0xee, 0x78, 0x74, + 0x93, 0x77, 0x3f, 0xdb, 0x39, 0x7a, 0x2e, 0x40, 0x9a, 0xc1, 0x0b, 0x8d, + 0x09, 0x83, 0xd1, 0x1e, 0x74, 0x65, 0xa6, 0xc2, 0x74, 0x52, 0x71, 0xaf, + 0xe0, 0x9e, 0x95, 0xe4, 0x3c, 0x00, 0x37, 0xfb, 0xda, 0x52, 0x9a, 0x56, + 0xca, 0x2f, 0x2d, 0xc2, 0xbc, 0xf2, 0x95, 0x0d, 0x60, 0x77, 0xdb, 0x7a, + 0x67, 0x0f, 0xee, 0xac, 0x91, 0x09, 0x2e, 0xc8, 0xcd, 0x19, 0xdb, 0x2a, + 0x70, 0xf9, 0xc2, 0x89, 0x58, 0x29, 0xf6, 0xdb, 0xdd, 0x87, 0x1b, 0x2a, + 0x3f, 0x16, 0xd5, 0x91, 0x8a, 0xd7, 0x01, 0x52, 0x68, 0x12, 0x6c, 0x15, + 0x5b, 0x10, 0xda, 0x91, 0x8f, 0x5c, 0x13, 0x84, 0x08, 0x35, 0xa5, 0xf2, + 0x4f, 0x7e, 0x73, 0x64, 0xca, 0x4e, 0x08, 0x49, 0xd6, 0xd1, 0xa2, 0x4f, + 0x2a, 0x23, 0x68, 0x98, 0x34, 0x4e, 0x03, 0x0b, 0x41, 0xea, 0x9e, 0xf6, + 0x83, 0x61, 0x11, 0x1d, 0x49, 0x9b, 0xd1, 0x0e, 0x3c, 0x69, 0xad, 0x1a, + 0xd2, 0x2a, 0x4b, 0xa5, 0x98, 0xbf, 0x3f, 0x1f, 0x49, 0x8b, 0x2a, 0x1c, + 0x43, 0xfa, 0x13, 0x63, 0xc2, 0x1f, 0x00, 0x5f, 0xfe, 0x60, 0x88, 0x5e, + 0x95, 0xd9, 0x6c, 0xcf, 0x40, 0x1b, 0x98, 0x12, 0xd4, 0xb1, 0xff, 0xdf, + 0xb4, 0x43, 0xe4, 0xc3, 0x46, 0x12, 0x7c, 0x39, 0x67, 0x1d, 0x64, 0x27, + 0x83, 0x2c, 0xc4, 0x91, 0xd0, 0x65, 0x4e, 0x71, 0x34, 0xa3, 0x83, 0x6c, + 0x4f, 0xda, 0x3f, 0xb8, 0x3b, 0xbf, 0xaa, 0x67, 0x95, 0x69, 0xa0, 0xc4, + 0x2e, 0x06, 0x10, 0xa0, 0x45, 0x21, 0x24, 0x96, 0xe9, 0xf8, 0xce, 0xf4, + 0xc8, 0xe6, 0xc8, 0x21, 0x3c, 0xc1, 0xa4, 0x78, 0x24, 0xba, 0x33, 0xef, + 0x44, 0x74, 0x9c, 0x8a, 0xe5, 0x88, 0xe2, 0xe4, 0xc5, 0x5f, 0x2f, 0xd7, + 0x83, 0xfa, 0x5f, 0x9c, 0x47, 0x86, 0x9e, 0xba, 0x6d, 0x92, 0xd7, 0xfd, + 0x58, 0x26, 0xcf, 0xd8, 0xb5, 0x44, 0x91, 0x33, 0x7d, 0x0b, 0x1f, 0x39, + 0xef, 0xf6, 0xb5, 0xb6, 0x01, 0x9e, 0x9a, 0x8c, 0xc5, 0x8b, 0x7d, 0x91, + 0x85, 0x29, 0xa9, 0x70, 0x44, 0x13, 0x0a, 0xd3, 0xa0, 0xd8, 0x45, 0x41, + 0x69, 0x65, 0xac, 0x5f, 0x18, 0x6d, 0xe3, 0x3b, 0x8b, 0x4c, 0xab, 0x3e, + 0xa6, 0xd2, 0xa1, 0x05, 0x18, 0xb1, 0xb1, 0xde, 0x0f, 0x4d, 0x05, 0x86, + 0xb9, 0x6f, 0x32, 0x6d, 0x3d, 0xca, 0x7e, 0xeb, 0x65, 0x52, 0xba, 0x8c, + 0x33, 0x2a, 0x5c, 0xa1, 0xbc, 0x21, 0x66, 0xcd, 0x77, 0x09, 0xcd, 0x72, + 0x29, 0x0f, 0xdd, 0x9f, 0x00, 0xb5, 0xc4, 0x75, 0xb1, 0xdb, 0x6c, 0x59, + 0x3c, 0x30, 0x30, 0x33, 0xba, 0x11, 0xd9, 0x44, 0x05, 0xb7, 0xc2, 0x11, + 0x43, 0x54, 0xa8, 0x13, 0x80, 0x5e, 0x35, 0xf3, 0x33, 0x74, 0xf8, 0x2d, + 0x56, 0x77, 0xad, 0xda, 0x15, 0xda, 0xda, 0xd0, 0x3d, 0x8a, 0xd1, 0x8d, + 0x42, 0xf0, 0xc4, 0x8d, 0x90, 0x55, 0x02, 0x7d, 0x87, 0x1d, 0x58, 0xdf, + 0x50, 0x74, 0x86, 0xb2, 0x50, 0xb3, 0x34, 0x9d, 0xe0, 0x77, 0x50, 0x17, + 0xf7, 0x8f, 0xc9, 0xf5, 0x06, 0x03, 0x85, 0x88, 0xb3, 0x6f, 0xf9, 0xa5, + 0xd0, 0xfa, 0xf2, 0x43, 0x6b, 0x50, 0x6c, 0x9b, 0xfe, 0xbd, 0xff, 0x2c, + 0x06, 0xce, 0x43, 0xf8, 0x44, 0x67, 0x88, 0x21, 0x53, 0x88, 0x04, 0x23, + 0x73, 0xd6, 0x89, 0xd8, 0xe4, 0x71, 0x77, 0x5f, 0x33, 0x3e, 0xc0, 0xf2, + 0x7f, 0xda, 0x99, 0x17, 0xea, 0x13, 0x5b, 0x64, 0xf2, 0x73, 0xc4, 0x11, + 0x52, 0x4f, 0x67, 0x1e, 0xdd, 0xe0, 0x66, 0x4d, 0x02, 0x11, 0x86, 0xe8, + 0x91, 0xb7, 0x8b, 0xcd, 0x4f, 0xbb, 0xb2, 0x18, 0xea, 0x30, 0x7b, 0x63, + 0x13, 0x37, 0x81, 0x76, 0x84, 0x48, 0x17, 0x2c, 0x06, 0x82, 0x56, 0x58, + 0x8b, 0xd9, 0xa2, 0xcb, 0x01, 0x44, 0xcd, 0x47, 0x16, 0x99, 0x03, 0x55, + 0xf7, 0xdc, 0x36, 0xd8, 0xce, 0xdf, 0xde, 0x92, 0x44, 0xf7, 0x95, 0x89, + 0x27, 0x9b, 0x37, 0xbf, 0xe1, 0xec, 0x4e, 0x48, 0x25, 0x86, 0x74, 0xa5, + 0xb7, 0xe7, 0xb0, 0x25, 0x01, 0xb8, 0x04, 0x3a, 0xd2, 0x64, 0xe2, 0xc6, + 0x99, 0xbf, 0xb9, 0x00, 0xae, 0x3a, 0xe9, 0x5f, 0xad, 0xca, 0xae, 0x02, + 0x82, 0x93, 0xaf, 0x54, 0xc5, 0x01, 0x1c, 0xad, 0x0a, 0x51, 0x4c, 0x3b, + 0xeb, 0xc8, 0x76, 0xb0, 0xf5, 0xbc, 0x70, 0x3d, 0x33, 0xb1, 0x53, 0xeb, + 0x8d, 0xb5, 0xad, 0x17, 0x08, 0x8b, 0x55, 0xe2, 0x9c, 0xb4, 0xee, 0xae, + 0x5a, 0x21, 0x92, 0x7f, 0x77, 0x06, 0x1e, 0xe2, 0x9a, 0x0e, 0x8f, 0xeb, + 0x5c, 0x9c, 0x8d, 0x0a, 0xc5, 0x6b, 0xc3, 0xc3, 0xb6, 0x10, 0xc4, 0x8d, + 0x6e, 0xb5, 0x88, 0xbb, 0x1f, 0x57, 0x5b, 0x68, 0xdf, 0xd7, 0xfc, 0xfe, + 0x17, 0x18, 0x40, 0x30, 0x5f, 0x1d, 0x08, 0x55, 0x48, 0x12, 0x67, 0x36, + 0x8d, 0x06, 0x55, 0xc3, 0xab, 0x77, 0xd0, 0x34, 0x79, 0xf1, 0x5d, 0x69, + 0x6f, 0x9a, 0xec, 0x7e, 0x43, 0xad, 0xe9, 0xd6, 0xa7, 0x63, 0xbe, 0xc3, + 0x48, 0xe9, 0x60, 0xad, 0xf8, 0xf3, 0x48, 0x76, 0x0a, 0x22, 0x95, 0x22, + 0x2d, 0x2d, 0xc1, 0x15, 0xd9, 0xd5, 0x30, 0x07, 0x57, 0x30, 0x7f, 0x2d, + 0xae, 0xfc, 0x5d, 0x3e, 0x1c, 0xaf, 0xa0, 0xb6, 0xdc, 0xda, 0xf9, 0x31, + 0x57, 0x2d, 0x41, 0xe5, 0x60, 0x87, 0xd6, 0x74, 0xcd, 0x09, 0xc0, 0x71, + 0x60, 0x00, 0x08, 0x75, 0x52, 0xc2, 0xc6, 0xcb, 0x6a, 0x27, 0x8e, 0x1c, + 0x6b, 0x95, 0xb3, 0xba, 0x47, 0x01, 0xc9, 0xf1, 0xe8, 0x11, 0x4a, 0x85, + 0x60, 0xaa, 0x36, 0xa3, 0xce, 0x8a, 0x90, 0xf8, 0x9e, 0x77, 0x01, 0xf2, + 0x4c, 0x99, 0xc4, 0xdd, 0xda, 0xaa, 0x0d, 0xc3, 0x26, 0xf6, 0x76, 0xb4, + 0xa5, 0x34, 0x19, 0x99, 0xcd, 0x23, 0x20, 0x89, 0xe0, 0x00, 0x61, 0xe5, + 0x80, 0xd3, 0xc3, 0xd7, 0x39, 0x7c, 0xb0, 0x50, 0xb1, 0x3b, 0x55, 0x78, + 0xbf, 0x89, 0x50, 0xb8, 0x0e, 0x0c, 0xef, 0xf1, 0x03, 0xf4, 0x2c, 0xd9, + 0xa9, 0x99, 0x58, 0x01, 0xc5, 0x91, 0x06, 0xd2, 0xd5, 0x5d, 0x24, 0x9b, + 0x25, 0x06, 0x74, 0x3b, 0x72, 0xce, 0x24, 0x85, 0x06, 0xf6, 0xdc, 0x44, + 0x04, 0x09, 0x30, 0x95, 0xc3, 0x7e, 0x32, 0x69, 0x23, 0xb3, 0x32, 0x86, + 0xdc, 0xe3, 0xe8, 0x5c, 0xb2, 0x2c, 0xad, 0xcf, 0x41, 0x92, 0x70, 0x89, + 0xb1, 0xb2, 0x6a, 0xee, 0xfb, 0xe6, 0x21, 0xa1, 0xb6, 0x19, 0x0b, 0x36, + 0x41, 0x8a, 0xa5, 0xf8, 0x39, 0x97, 0x01, 0x27, 0xd9, 0x48, 0xbe, 0x2b, + 0x88, 0x40, 0x65, 0x59, 0x30, 0x53, 0x2f, 0x6c, 0x6c, 0xf0, 0x8c, 0x8f, + 0x9b, 0xd7, 0x4d, 0x42, 0x72, 0xd6, 0x50, 0x90, 0x59, 0xca, 0x21, 0x26, + 0x4d, 0x27, 0x3f, 0x18, 0x7e, 0x8e, 0x0d, 0xb4, 0x25, 0xb9, 0x6c, 0x29, + 0x40, 0xe7, 0xf8, 0x19, 0xa7, 0xd0, 0x07, 0xd1, 0x31, 0x83, 0x82, 0xab, + 0x95, 0x5a, 0xf9, 0x66, 0x48, 0x9a, 0x3b, 0x53, 0x16, 0x2c, 0x99, 0x37, + 0x36, 0xc7, 0x90, 0x01, 0xa0, 0xbc, 0x89, 0x69, 0xe0, 0x2c, 0x4b, 0x2a, + 0xd2, 0xf3, 0x8b, 0xa4, 0xa6, 0x99, 0x19, 0x3c, 0x23, 0xf1, 0x9b, 0xe1, + 0x0d, 0xfb, 0x42, 0x97, 0x79, 0x11, 0xdc, 0x80, 0xb3, 0x0b, 0xd3, 0x3e, + 0x6b, 0x36, 0xb5, 0x13, 0xc6, 0xcc, 0xd5, 0xb5, 0x3b, 0xdf, 0xb1, 0x09, + 0x21, 0xd6, 0xf0, 0x4e, 0x55, 0x2a, 0x31, 0xbc, 0x9a, 0x8e, 0x7c, 0x0d, + 0xbf, 0x71, 0x25, 0xfd, 0xd6, 0x03, 0x2f, 0x44, 0x01, 0xff, 0xbd, 0xce, + 0x36, 0x38, 0xbd, 0x44, 0x1c, 0x82, 0xd4, 0x23, 0xfa, 0x9a, 0x91, 0xb8, + 0x5e, 0x55, 0x24, 0x7e, 0x1b, 0x28, 0xb8, 0x1f, 0x0b, 0x64, 0xdf, 0x69, + 0x87, 0xcf, 0xea, 0x31, 0x51, 0xa3, 0x61, 0xdb, 0xd0, 0xa8, 0x4e, 0x1f, + 0x7a, 0xc3, 0x6e, 0xf7, 0x5c, 0x8c, 0x31, 0xa6, 0x89, 0xf0, 0xb2, 0x51, + 0xfd, 0x9c, 0xbf, 0x76, 0xe4, 0x5a, 0x7f, 0xad, 0x08, 0xc0, 0xe0, 0xac, + 0x7d, 0x3b, 0x9d, 0x07, 0x48, 0xbe, 0xba, 0x95, 0xed, 0x66, 0xe0, 0xed, + 0xde, 0x4a, 0xb6, 0xa4, 0x67, 0x36, 0x69, 0xe8, 0xf6, 0xd9, 0x78, 0x10, + 0x75, 0x8a, 0x36, 0xe2, 0x72, 0x31, 0x7b, 0x68, 0x68, 0x04, 0x24, 0xe5, + 0xdb, 0x79, 0xc2, 0x92, 0x90, 0x35, 0x3d, 0xd8, 0xdf, 0x84, 0x24, 0x6c, + 0x9c, 0x30, 0xab, 0x40, 0x18, 0xb5, 0x5a, 0xdd, 0xac, 0x6a, 0x12, 0x99, + 0x77, 0x52, 0x2e, 0x53, 0x37, 0xa0, 0x4e, 0xe8, 0x01, 0x6e, 0x37, 0x59, + 0xad, 0x56, 0x70, 0x9c, 0x50, 0x93, 0xf1, 0x69, 0xd0, 0xe1, 0x6e, 0xa1, + 0x93, 0x6b, 0xe1, 0x3b, 0xbd, 0xfd, 0xdf, 0xaa, 0x0a, 0x55, 0x8b, 0x3e, + 0x3c, 0xb6, 0xc5, 0x8b, 0x60, 0x6c, 0xdb, 0xf2, 0x9e, 0x53, 0x1b, 0x11, + 0x06, 0x9d, 0x18, 0x6b, 0x70, 0x16, 0x7e, 0xf8, 0x20, 0xff, 0x12, 0x39, + 0xd3, 0x2a, 0xc5, 0x09, 0xbd, 0xa3, 0xd7, 0x12, 0x13, 0x2f, 0xb5, 0x79, + 0xce, 0x26, 0x95, 0xd8, 0x55, 0x5b, 0x63, 0x5b, 0x3f, 0xe6, 0x3e, 0x6b, + 0x2d, 0xf8, 0x70, 0xb1, 0x43, 0xa3, 0x7d, 0xb3, 0x65, 0x49, 0xe8, 0x47, + 0x2f, 0x46, 0xc3, 0x38, 0xbc, 0xd2, 0x8f, 0x7f, 0xbc, 0xae, 0xea, 0x7a, + 0x6c, 0x28, 0xd2, 0x30, 0x37, 0x74, 0xa6, 0x5f, 0x9b, 0x0b, 0x48, 0x60, + 0xb6, 0x61, 0x9f, 0xe7, 0x9a, 0xd1, 0xea, 0x58, 0xbb, 0x16, 0xb7, 0x06, + 0x9e, 0xaf, 0x16, 0xc0, 0xc4, 0x60, 0xd2, 0x4c, 0x15, 0xe7, 0x4b, 0x5c, + 0x37, 0xb4, 0xf2, 0xb0, 0xba, 0x52, 0x6c, 0xc1, 0x0e, 0x57, 0x26, 0x84, + 0x72, 0x7f, 0x08, 0xdf, 0x7b, 0xd0, 0x92, 0xcf, 0x18, 0x88, 0xac, 0xea, + 0xdd, 0x95, 0x93, 0xa7, 0xb8, 0x4d, 0xab, 0x1f, 0xfd, 0xf0, 0x4e, 0x52, + 0x7c, 0x44, 0xbf, 0x73, 0x96, 0x94, 0xa2, 0xa4, 0xce, 0x30, 0x10, 0xa1, + 0xf1, 0xa8, 0x5f, 0x3b, 0x8d, 0x45, 0x92, 0x60, 0x61, 0xf7, 0x95, 0x40, + 0x57, 0xdf, 0x79, 0x6d, 0xf9, 0xfe, 0x42, 0x14, 0xe2, 0xc2, 0xaa, 0xd1, + 0x91, 0x42, 0x8c, 0x4d, 0xe7, 0x89, 0xb1, 0xa4, 0xf9, 0xb4, 0xd6, 0xdb, + 0x12, 0xda, 0x96, 0xbe, 0xb9, 0x85, 0x3b, 0x9a, 0x6c, 0x55, 0xd7, 0x6e, + 0x87, 0x29, 0x3d, 0x32, 0x5a, 0x0e, 0x3b, 0x45, 0xe7, 0x24, 0xd2, 0x93, + 0x95, 0x30, 0x0e, 0x54, 0x60, 0x01, 0x09, 0x3e, 0x13, 0x46, 0x3e, 0x0d, + 0x0a, 0x55, 0xb6, 0xfb, 0x8f, 0xc9, 0x6c, 0xd8, 0xef, 0xbf, 0x40, 0xd6, + 0x16, 0xf3, 0xbb, 0x72, 0xc3, 0x74, 0x5b, 0x07, 0x45, 0x9c, 0x7c, 0x17, + 0xc2, 0xd8, 0x02, 0xdb, 0x05, 0xe1, 0xca, 0x67, 0xb9, 0x9a, 0xf0, 0xed, + 0x1c, 0x4a, 0x79, 0xce, 0xf1, 0x09, 0x34, 0x79, 0x8d, 0x22, 0xcd, 0x4e, + 0x55, 0x70, 0xbf, 0xdf, 0x40, 0x2e, 0x65, 0x2f, 0xb5, 0x1f, 0xb9, 0xdc, + 0x75, 0x93, 0x93, 0xd3, 0x94, 0x1b, 0x0f, 0x3e, 0xef, 0xe2, 0xbc, 0x27, + 0x2e, 0x34, 0x2b, 0xde, 0xe1, 0xe0, 0x94, 0xca, 0xca, 0x7f, 0x0a, 0xd8, + 0xad, 0x4e, 0xc9, 0xb5, 0xaa, 0x7a, 0xf3, 0xe3, 0x8d, 0x4e, 0x67, 0x5e, + 0x9a, 0x50, 0x2c, 0x9f, 0xb6, 0xf6, 0xd8, 0x01, 0x83, 0xd9, 0x9a, 0x20, + 0xda, 0x7c, 0xcc, 0x4d, 0xb7, 0x93, 0xb6, 0x16, 0x4f, 0x63, 0xfd, 0x4e, + 0x11, 0x22, 0xb4, 0x10, 0x8c, 0xf6, 0xad, 0xea, 0x60, 0x8e, 0xc6, 0xcf, + 0xf7, 0x6f, 0xcd, 0x4e, 0x7b, 0x1a, 0x08, 0xab, 0xaa, 0x70, 0xea, 0x64, + 0x1c, 0xdd, 0x69, 0x45, 0x3d, 0xbf, 0xbc, 0x86, 0xfc, 0xf1, 0x7f, 0x15, + 0x8d, 0x29, 0x3a, 0x82, 0x49, 0x1a, 0xc6, 0xe7, 0x25, 0x00, 0x19, 0xb2, + 0x6d, 0x0a, 0x51, 0x52, 0x12, 0x80, 0x1c, 0x7e, 0x6a, 0xd5, 0x14, 0x31, + 0xa7, 0xdb, 0xbd, 0xa4, 0xb2, 0x70, 0xb6, 0xf6, 0x6d, 0xd8, 0xc9, 0x89, + 0x0e, 0xcf, 0x73, 0x0e, 0x06, 0xbd, 0x2c, 0xc7, 0xbf, 0x80, 0x9f, 0xa7, + 0x58, 0xda, 0x0c, 0x66, 0xdf, 0xcd, 0xbb, 0x8d, 0xef, 0x07, 0x55, 0x69, + 0x10, 0x56, 0x4e, 0x0e, 0x44, 0x44, 0x33, 0x06, 0x28, 0xdf, 0xb7, 0x29, + 0x5e, 0xf4, 0x5e, 0x24, 0x4f, 0x3a, 0xd1, 0x87, 0x58, 0xbe, 0xf2, 0xd4, + 0x91, 0xdf, 0x42, 0xd5, 0x10, 0xf3, 0x91, 0x53, 0x42, 0x32, 0x56, 0xe4, + 0x5c, 0x20, 0x36, 0x39, 0xa1, 0x49, 0xa2, 0x71, 0x54, 0x62, 0x4a, 0x13, + 0x38, 0xf0, 0x68, 0x4e, 0xe8, 0x66, 0xd2, 0x1b, 0x99, 0x45, 0xb3, 0x12, + 0x7f, 0x9e, 0x3f, 0x7e, 0xce, 0x31, 0xce, 0x57, 0xa4, 0xa6, 0xe1, 0x24, + 0xd9, 0x30, 0xf4, 0xe4, 0x49, 0x07, 0x92, 0x22, 0xfe, 0xb3, 0x86, 0x0a, + 0x98, 0x3f, 0x89, 0xcf, 0xaa, 0x2f, 0xbd, 0x55, 0x6a, 0x58, 0x58, 0x11, + 0x91, 0xa1, 0x17, 0xcf, 0xdc, 0x83, 0xb1, 0x13, 0x9a, 0xd9, 0xb4, 0xb5, + 0xe2, 0x12, 0x32, 0xa7, 0x42, 0x6b, 0x22, 0x15, 0xd6, 0x30, 0x66, 0x52, + 0x6c, 0xdd, 0x1a, 0x64, 0x8b, 0xcf, 0xfb, 0x61, 0x5f, 0x7f, 0xd9, 0xff, + 0xa1, 0x9a, 0x6f, 0xc1, 0xe0, 0x21, 0x76, 0x8e, 0x0e, 0x37, 0x13, 0x14, + 0xb7, 0x2a, 0xfc, 0x20, 0xca, 0x2a, 0x33, 0x8c, 0xa5, 0x2b, 0x75, 0xdf, + 0x5c, 0xd5, 0xdf, 0xae, 0xed, 0xcb, 0x0e, 0x44, 0xb5, 0x43, 0xec, 0xc8, + 0xb7, 0x80, 0x8c, 0xdc, 0x46, 0xdf, 0x8b, 0x7b, 0xf3, 0x26, 0xb2, 0xfc, + 0x1e, 0xe5, 0x8b, 0x0c, 0x8c, 0x2f, 0xf8, 0x94, 0x73, 0x46, 0xc2, 0x30, + 0x9c, 0x3a, 0xb8, 0x7c, 0x47, 0x21, 0xf4, 0xd6, 0x02, 0xa8, 0xda, 0x8e, + 0xf4, 0x62, 0x85, 0x21, 0x87, 0x68, 0x1c, 0x8d, 0x6d, 0x0c, 0x88, 0xa9, + 0x7c, 0x05, 0x27, 0xfe, 0x9a, 0x24, 0x53, 0xb0, 0xc6, 0x40, 0x44, 0xbf, + 0xa5, 0xb8, 0xbb, 0xb8, 0xe2, 0x40, 0x23, 0x2c, 0x4d, 0x19, 0xd1, 0x01, + 0xed, 0x1a, 0x65, 0x7f, 0xdd, 0x5a, 0x30, 0x86, 0xd8, 0xe0, 0xb1, 0x85, + 0xa2, 0xe5, 0x20, 0x5d, 0x28, 0xc7, 0xe6, 0x92, 0xcf, 0x39, 0x8b, 0x7e, + 0x6e, 0xf1, 0x8e, 0x3f, 0xd4, 0x0b, 0xc3, 0xe5, 0x4b, 0xa9, 0x6e, 0x50, + 0x5a, 0xf7, 0x09, 0xe4, 0x4b, 0x75, 0x06, 0x73, 0x06, 0xfa, 0x94, 0xf0, + 0x99, 0xc3, 0xf9, 0xc3, 0x40, 0x8e, 0x7c, 0x3d, 0xc7, 0x54, 0x3b, 0x76, + 0x58, 0x26, 0xdf, 0x89, 0xa1, 0x66, 0xee, 0x3c, 0xe2, 0x04, 0xd9, 0x94, + 0x15, 0x8b, 0xe6, 0x99, 0xfe, 0x30, 0x33, 0x62, 0xf1, 0xb7, 0x7f, 0x18, + 0x8b, 0xdc, 0x08, 0xd5, 0xa6, 0x07, 0xf9, 0x83, 0xf4, 0x2e, 0x91, 0x0c, + 0x2c, 0xc5, 0xd5, 0x3e, 0x4d, 0x9e, 0xd4, 0xec, 0x6b, 0x5e, 0x9b, 0xb3, + 0x42, 0xf8, 0x4f, 0x27, 0xfb, 0x57, 0x61, 0x64, 0x27, 0xd7, 0x17, 0xbf, + 0xe1, 0xb9, 0x26, 0xe9, 0xf3, 0xd2, 0x3d, 0x75, 0x44, 0x9e, 0x3d, 0x07, + 0x1a, 0x6e, 0x3f, 0xcf, 0xde, 0x7f, 0xbb, 0x34, 0x1f, 0xb3, 0xf1, 0xaf, + 0xab, 0xc9, 0x8d, 0xc2, 0x20, 0x22, 0xa0, 0xbb, 0x96, 0xda, 0x9a, 0xab, + 0x2e, 0x33, 0xfc, 0x5f, 0x04, 0x8c, 0xac, 0x2b, 0x43, 0x6d, 0xf1, 0x60, + 0xe2, 0x7d, 0x36, 0x49, 0xbf, 0x91, 0xcd, 0x16, 0x92, 0x47, 0xdf, 0x90, + 0xcc, 0xc3, 0xd5, 0x6d, 0x6d, 0x57, 0xf8, 0xf8, 0x15, 0x4c, 0x83, 0xab, + 0xaa, 0xe8, 0xca, 0xb3, 0xeb, 0x23, 0x88, 0x33, 0x96, 0xaa, 0x7b, 0xd0, + 0x15, 0xd3, 0xe3, 0xd4, 0xfe, 0xa0, 0x77, 0x26, 0x7b, 0x0d, 0xf4, 0x3b, + 0x58, 0x33, 0xb3, 0x9e, 0x79, 0x87, 0xda, 0x06, 0x7b, 0x2e, 0x77, 0xf5, + 0xf2, 0x3e, 0x71, 0x33, 0x18, 0x10, 0x93, 0xe2, 0x49, 0xb7, 0x3c, 0xbe, + 0x3c, 0xd9, 0xd8, 0x44, 0xe0, 0xc6, 0xba, 0x42, 0x57, 0xa7, 0x4b, 0x44, + 0x18, 0xb6, 0x3c, 0xbd, 0xb9, 0x0c, 0x28, 0x87, 0x6f, 0x12, 0x0a, 0xf4, + 0xe4, 0xf7, 0xb0, 0xb5, 0xb2, 0x4e, 0xff, 0x8f, 0x10, 0x3a, 0xf4, 0x17, + 0xfd, 0xae, 0x03, 0xdb, 0x5b, 0x4d, 0x46, 0xfe, 0x80, 0x98, 0x9b, 0xc1, + 0xfc, 0x47, 0x1e, 0x29, 0xd8, 0xcd, 0x8b, 0x46, 0x40, 0x99, 0x37, 0x39, + 0x16, 0x81, 0x95, 0xb2, 0x68, 0xfe, 0xd7, 0xdc, 0x12, 0x4d, 0xc9, 0x64, + 0x03, 0x1d, 0xb7, 0x51, 0x64, 0xf4, 0x96, 0xa4, 0xc4, 0x60, 0x2c, 0x14, + 0x2a, 0xae, 0xdf, 0xd8, 0x31, 0x83, 0xcc, 0x34, 0x29, 0x1c, 0x95, 0x82, + 0xe1, 0x47, 0xa3, 0xd6, 0xf5, 0x67, 0xb0, 0x25, 0x66, 0x10, 0x35, 0xa6, + 0x65, 0x3f, 0x11, 0x2f, 0x14, 0x4a, 0x80, 0x86, 0x39, 0x64, 0xaa, 0x88, + 0xa9, 0x81, 0xe1, 0xcd, 0x3d, 0xf7, 0xa9, 0x7a, 0x83, 0xb2, 0xa3, 0xef, + 0x31, 0xb9, 0x1c, 0x6c, 0x11, 0x8f, 0xf2, 0xad, 0x36, 0xa7, 0x9e, 0xa9, + 0x58, 0xef, 0x04, 0xb5, 0xdc, 0xeb, 0xdd, 0xda, 0xca, 0x52, 0x08, 0x49, + 0x78, 0xf7, 0x0e, 0x31, 0xd3, 0x34, 0x7a, 0x37, 0x93, 0xb3, 0xba, 0x43, + 0x93, 0x71, 0xc0, 0xf6, 0xad, 0xe6, 0x37, 0x22, 0xd5, 0xf0, 0x9f, 0xf8, + 0x29, 0x90, 0x29, 0xaf, 0x17, 0x2b, 0x5c, 0x3a, 0x95, 0x42, 0x07, 0x25, + 0x46, 0x88, 0xd0, 0xa0, 0x90, 0xdc, 0x18, 0x2d, 0x93, 0xcd, 0x76, 0x2c, + 0x3e, 0xd5, 0x23, 0x4e, 0xae, 0xa4, 0x40, 0x14, 0xb9, 0xd5, 0x35, 0x92, + 0x55, 0x08, 0xcb, 0x6f, 0xde, 0x45, 0x6f, 0x20, 0x3a, 0x3a, 0x42, 0xde, + 0x97, 0xed, 0xab, 0xc1, 0xa7, 0xe5, 0x62, 0x7e, 0x04, 0x20, 0x31, 0x5f, + 0x1b, 0x7e, 0xe9, 0xc3, 0xe9, 0xb6, 0x6a, 0x83, 0x6a, 0xd9, 0xd8, 0xda, + 0x34, 0xd1, 0xed, 0x2f, 0x57, 0x07, 0x33, 0x35, 0x68, 0x9a, 0x53, 0x6d, + 0x7b, 0x10, 0x03, 0xcd, 0x68, 0x45, 0xb6, 0xbf, 0x3c, 0x89, 0x09, 0x43, + 0xf3, 0x85, 0x5c, 0xf6, 0x85, 0x98, 0x24, 0xb5, 0x0a, 0x36, 0xba, 0x9b, + 0x25, 0x85, 0x93, 0xfb, 0x0b, 0xe7, 0x05, 0x95, 0x01, 0x42, 0x65, 0x6a, + 0xa9, 0x8f, 0x13, 0x6e, 0x4e, 0x5b, 0x48, 0xda, 0x45, 0x35, 0xf9, 0x35, + 0x69, 0x08, 0xe8, 0x5f, 0xd3, 0xfd, 0x17, 0x3e, 0x34, 0x26, 0x9b, 0x3a, + 0xf7, 0x04, 0x87, 0xf0, 0x72, 0x89, 0x2c, 0x4e, 0x38, 0x0f, 0x8b, 0xde, + 0x82, 0xe6, 0xae, 0x96, 0xeb, 0x70, 0xe8, 0xed, 0x64, 0xfa, 0xa6, 0xf2, + 0xce, 0x6e, 0x09, 0xbe, 0xf1, 0xb6, 0xd8, 0xe1, 0xb4, 0xd6, 0x46, 0x1c, + 0x3e, 0x98, 0x9b, 0x7f, 0x88, 0xab, 0x02, 0xcf, 0x00, 0xb3, 0xa3, 0x57, + 0xd1, 0x94, 0x16, 0x6a, 0x79, 0x9d, 0x0d, 0xbb, 0x40, 0x13, 0x83, 0x21, + 0xbe, 0x16, 0xc4, 0x58, 0x95, 0x9c, 0x69, 0x89, 0x90, 0x48, 0xc0, 0x84, + 0x62, 0xa6, 0x11, 0x40, 0x4e, 0xad, 0x94, 0xb3, 0xf9, 0x3a, 0x68, 0x83, + 0xfb, 0xfc, 0x7f, 0xe9, 0xde, 0xd4, 0xd8, 0xac, 0x7c, 0xdc, 0x7e, 0xb0, + 0x99, 0x7c, 0xba, 0x4d, 0xeb, 0xec, 0xdc, 0xca, 0x23, 0x7a, 0xeb, 0xa4, + 0xc8, 0xaa, 0x55, 0x16, 0x58, 0xe7, 0xb0, 0xcc, 0xd8, 0x82, 0x00, 0xc5, + 0xff, 0xa4, 0xad, 0x1d, 0x4d, 0xf3, 0x00, 0xb8, 0x4c, 0xce, 0xfd, 0xf4, + 0x22, 0xd4, 0x38, 0x6f, 0x5a, 0x28, 0x7a, 0x82, 0x48, 0x11, 0x3b, 0x3a, + 0xe5, 0x59, 0x0f, 0x58, 0x18, 0xbf, 0x32, 0x1e, 0xd8, 0xaa, 0xd0, 0x1a, + 0x6a, 0x14, 0xe7, 0x55, 0x63, 0x16, 0x1f, 0x92, 0xad, 0x80, 0x84, 0x66, + 0xf8, 0x8f, 0x50, 0x9f, 0xa4, 0xf9, 0x37, 0x7a, 0xfa, 0xb6, 0x06, 0x93, + 0x9f, 0xfd, 0x74, 0x31, 0xf5, 0x41, 0xa5, 0x0d, 0xb7, 0xb9, 0xab, 0xef, + 0xa4, 0x48, 0x72, 0x61, 0xad, 0xe4, 0x88, 0x0c, 0x86, 0xe1, 0x98, 0xee, + 0x81, 0xf8, 0xde, 0x5d, 0x0f, 0x39, 0x6c, 0x9a, 0x29, 0x37, 0x19, 0x5d, + 0xb5, 0x03, 0x3d, 0x41, 0x89, 0x21, 0xd2, 0x19, 0xb3, 0xa7, 0xc3, 0x7e, + 0x63, 0xa3, 0x6c, 0xcd, 0x8a, 0xe9, 0x7a, 0xa1, 0x85, 0xc1, 0xaa, 0x24, + 0xae, 0x03, 0x0a, 0x41, 0xbf, 0xcc, 0x00, 0xdd, 0xfc, 0xed, 0xe9, 0x23, + 0xb4, 0x57, 0xda, 0x46, 0x52, 0x27, 0x10, 0xe5, 0xfa, 0x54, 0x98, 0x2b, + 0x91, 0xf4, 0x8b, 0x87, 0x70, 0x84, 0x16, 0xf8, 0xcc, 0xb1, 0x2a, 0xcd, + 0x68, 0x19, 0xea, 0x72, 0xb1, 0x74, 0xe9, 0x88, 0x30, 0xd3, 0xcb, 0x6c, + 0x5a, 0xd9, 0x82, 0x93, 0xda, 0x6d, 0xaa, 0x1a, 0x21, 0x41, 0xfe, 0xdf, + 0x0d, 0x45, 0x49, 0x4a, 0xdb, 0xa2, 0x8b, 0x1e, 0x7a, 0xcc, 0xc7, 0x4b, + 0xe2, 0xb6, 0x64, 0x90, 0x14, 0x24, 0xef, 0xfb, 0x3f, 0xda, 0x2d, 0x81, + 0xd1, 0xb5, 0x07, 0x81, 0xb0, 0xb1, 0x03, 0x31, 0x82, 0x0b, 0x2d, 0xe0, + 0x02, 0xc3, 0x20, 0x80, 0x34, 0x7b, 0xac, 0xc8, 0x45, 0x48, 0x3d, 0x06, + 0x0a, 0xa9, 0x94, 0x34, 0x80, 0x70, 0x62, 0x9c, 0xa6, 0xed, 0xc5, 0x64, + 0xce, 0x81, 0xea, 0xaa, 0x74, 0x98, 0x9a, 0x1b, 0x25, 0x7f, 0x4b, 0x75, + 0x22, 0xf3, 0x6c, 0x55, 0x77, 0xba, 0xee, 0x05, 0xf6, 0xfe, 0x42, 0xa0, + 0x77, 0x64, 0x7a, 0x2f, 0x84, 0x31, 0xb3, 0x19, 0x2d, 0x8e, 0xc9, 0x2b, + 0x20, 0x71, 0x31, 0x0b, 0x66, 0x74, 0xab, 0x88, 0x10, 0xbf, 0x83, 0x7c, + 0xbc, 0x61, 0x4b, 0x72, 0x77, 0x81, 0x6e, 0x6a, 0x80, 0xcd, 0xf9, 0x7f, + 0x94, 0xe6, 0xf1, 0xb1, 0x65, 0xa2, 0xc3, 0xea, 0xb6, 0x69, 0xa8, 0xae, + 0x10, 0xbb, 0xeb, 0xe2, 0x25, 0xfd, 0x67, 0x71, 0x33, 0xb9, 0xcd, 0x97, + 0xb1, 0xc9, 0x2b, 0xdd, 0xbb, 0x03, 0xfe, 0x72, 0x16, 0x8d, 0xb2, 0xbb, + 0xd7, 0x10, 0x83, 0x72, 0xbe, 0x02, 0x1e, 0x29, 0x29, 0xa0, 0x95, 0xb9, + 0x70, 0x44, 0xb9, 0x74, 0xa3, 0x3f, 0x2a, 0x44, 0x3a, 0xac, 0xd2, 0x21, + 0x8d, 0x53, 0x95, 0x7d, 0xc1, 0x09, 0x05, 0xeb, 0xe9, 0x60, 0xc2, 0x6f, + 0x40, 0x09, 0xc8, 0x98, 0x61, 0x3f, 0x1f, 0xa5, 0x2d, 0x09, 0x18, 0x2f, + 0x0f, 0x62, 0x97, 0xec, 0x39, 0x46, 0x3d, 0x33, 0xa2, 0xc0, 0xaf, 0x29, + 0xa6, 0xfb, 0x11, 0x83, 0x2c, 0xb8, 0x51, 0xcb, 0xf8, 0x3b, 0x2b, 0xb5, + 0x09, 0xa5, 0xdd, 0x49, 0x43, 0xdb, 0x13, 0xd7, 0xd6, 0x21, 0x4b, 0xe8, + 0x33, 0x54, 0x50, 0x27, 0x75, 0xab, 0x03, 0x3c, 0xa3, 0xc0, 0x98, 0x1f, + 0x2b, 0xbe, 0x11, 0xc9, 0x6b, 0xf7, 0x1f, 0x8a, 0xf8, 0x85, 0x48, 0xe3, + 0x24, 0x67, 0x3b, 0xbe, 0xe8, 0x12, 0xf0, 0x4d, 0x2a, 0x67, 0x0a, 0x98, + 0xbb, 0x9f, 0x3c, 0xfc, 0xb2, 0xb2, 0x4a, 0xd2, 0xf4, 0xb2, 0x73, 0xe4, + 0xc8, 0xdd, 0x05, 0xe5, 0x48, 0x1a, 0x4c, 0xfb, 0x06, 0x29, 0x58, 0x4d, + 0x6a, 0x03, 0x34, 0x63, 0xae, 0x8b, 0xdc, 0x00, 0x5a, 0xd9, 0x04, 0x61, + 0xb8, 0xf6, 0x42, 0x65, 0xd1, 0x97, 0xe0, 0xe0, 0x4b, 0x46, 0x2a, 0x97, + 0x2c, 0x93, 0x31, 0x67, 0xe4, 0x0e, 0x21, 0x0c, 0x1d, 0x11, 0x41, 0xa6, + 0x4b, 0x03, 0x0e, 0xc9, 0x42, 0x9e, 0x6d, 0x4b, 0x77, 0xb5, 0x57, 0xd1, + 0x16, 0x16, 0xe5, 0x4d, 0x35, 0xb9, 0xcf, 0x74, 0x06, 0x59, 0x92, 0x66, + 0xdd, 0xe3, 0x44, 0x1c, 0x52, 0xf5, 0x08, 0xff, 0x2b, 0xd3, 0x9c, 0x8c, + 0xed, 0xbc, 0x47, 0x51, 0x01, 0xf7, 0xb3, 0x7d, 0x6c, 0x60, 0x31, 0x45, + 0x8e, 0x07, 0xe0, 0x58, 0x12, 0xff, 0x4b, 0x93, 0x8f, 0xf1, 0x24, 0xf6, + 0xfd, 0x18, 0xc7, 0x3b, 0xca, 0x91, 0x6e, 0x66, 0x77, 0x85, 0xab, 0xd8, + 0x11, 0xa7, 0x81, 0xdd, 0xa0, 0x8a, 0x90, 0x53, 0x6c, 0x08, 0x27, 0x71, + 0xfb, 0x62, 0x33, 0xb4, 0x04, 0xf0, 0x81, 0x58, 0x9b, 0xad, 0x92, 0xb0, + 0x17, 0x93, 0x86, 0x59, 0x3c, 0xa1, 0xe1, 0x7f, 0xce, 0x30, 0x0d, 0x83, + 0x6b, 0x61, 0x06, 0x27, 0x3d, 0xe1, 0x4f, 0x3b, 0xb4, 0x5f, 0xc7, 0xf8, + 0x83, 0x43, 0xdf, 0xba, 0xeb, 0x54, 0x37, 0xa0, 0x3d, 0x20, 0xe1, 0x25, + 0xd6, 0x59, 0xdd, 0x74, 0x9e, 0xaf, 0xc0, 0xae, 0x9b, 0xd0, 0x2d, 0xf5, + 0xf6, 0x3d, 0x5c, 0x1d, 0xea, 0x1a, 0xdd, 0xf5, 0xa9, 0xc3, 0xfe, 0x8f, + 0x0a, 0x3c, 0xcd, 0x4c, 0xda, 0xf8, 0x8a, 0x6d, 0x56, 0x98, 0x19, 0x50, + 0xc6, 0xa0, 0x6d, 0x70, 0x07, 0x04, 0x10, 0xa6, 0x4b, 0x4e, 0xc7, 0x0b, + 0xf4, 0x7c, 0xb0, 0x26, 0x4c, 0x0f, 0xd2, 0x15, 0xde, 0xb4, 0xd8, 0xe3, + 0xac, 0xc1, 0xff, 0xa3, 0x17, 0x2a, 0xd5, 0x0d, 0x6c, 0x79, 0xad, 0xde, + 0x4c, 0x70, 0xb9, 0xf9, 0x07, 0xcf, 0xf3, 0x36, 0x3d, 0x5a, 0x7f, 0xc4, + 0xd3, 0x52, 0x3f, 0x15, 0xc3, 0x6b, 0x25, 0x8e, 0x00, 0x67, 0x85, 0x66, + 0x24, 0x8f, 0x6a, 0x23, 0x3a, 0x2f, 0x0b, 0xa2, 0x19, 0xd1, 0x6a, 0x8b, + 0x54, 0x4e, 0x52, 0x69, 0xe6, 0xc6, 0xa6, 0x02, 0x5b, 0x06, 0x7d, 0xf9, + 0xe6, 0x1f, 0x5b, 0x25, 0xf1, 0x95, 0x13, 0x80, 0xf2, 0x73, 0x17, 0xdf, + 0xd3, 0x35, 0x82, 0xe4, 0x07, 0x65, 0x7a, 0x77, 0xf5, 0x51, 0xd4, 0xf9, + 0xb0, 0xa0, 0x62, 0x03, 0xc2, 0x23, 0x5d, 0xc4, 0x95, 0x00, 0xaa, 0xba, + 0xb3, 0x64, 0x2e, 0x46, 0xf8, 0x1c, 0xce, 0x9d, 0x2f, 0x7e, 0x86, 0xab, + 0x17, 0x41, 0x5c, 0x0d, 0x27, 0xe6, 0x50, 0xd5, 0x14, 0xe8, 0x69, 0x97, + 0x22, 0xb1, 0x97, 0x13, 0x29, 0xc9, 0x6d, 0xcd, 0xed, 0x9f, 0xf6, 0xb5, + 0xc5, 0xd1, 0xc1, 0x25, 0x12, 0x18, 0xcc, 0x75, 0x8b, 0x25, 0x39, 0x67, + 0x91, 0xb4, 0x20, 0x91, 0x57, 0x04, 0xdb, 0xc4, 0x4e, 0x17, 0x9d, 0x06, + 0x8a, 0x89, 0x69, 0xc3, 0x25, 0x01, 0x02, 0x7f, 0xef, 0x83, 0x79, 0xd7, + 0x08, 0xcc, 0x21, 0xe3, 0x07, 0xe8, 0x9d, 0x7d, 0xc8, 0x48, 0x6a, 0x26, + 0x46, 0xe7, 0xf9, 0xbe, 0x2a, 0x3d, 0x5f, 0x68, 0xfd, 0xf0, 0xf4, 0x64, + 0xac, 0x52, 0x83, 0x95, 0x2c, 0xee, 0xc5, 0x3a, 0x3e, 0x2e, 0x64, 0xc6, + 0x26, 0x19, 0xf7, 0xc5, 0x3d, 0xf5, 0x92, 0x63, 0x71, 0x7c, 0x81, 0x06, + 0x19, 0x72, 0xb3, 0x46, 0xe9, 0xdd, 0xde, 0xf0, 0x89, 0x4b, 0xde, 0xc1, + 0xa7, 0x86, 0xd6, 0x01, 0xc4, 0xcf, 0xa8, 0x67, 0xc2, 0x8f, 0x32, 0xa8, + 0xc5, 0x33, 0x29, 0xc8, 0xbd, 0x01, 0x2a, 0x37, 0xe3, 0x36, 0x49, 0x45, + 0xd0, 0x96, 0x74, 0x3c, 0x0e, 0xeb, 0x5b, 0x91, 0x4d, 0x1b, 0x68, 0x3b, + 0xf3, 0x03, 0xcf, 0x8f, 0xb7, 0x74, 0xc6, 0xcc, 0xc4, 0xe6, 0xe0, 0x7d, + 0x18, 0x9b, 0x62, 0x91, 0x4c, 0x5e, 0x27, 0x78, 0x3c, 0x28, 0xc3, 0xb3, + 0x95, 0x79, 0x1d, 0x1c, 0xe8, 0x96, 0x68, 0x5a, 0x57, 0xeb, 0x8c, 0x59, + 0xfb, 0x07, 0x38, 0xe0, 0xa9, 0xc3, 0xc5, 0x35, 0xba, 0x36, 0xf4, 0x08, + 0x6a, 0xe8, 0x7c, 0x28, 0xbb, 0xe4, 0x8b, 0xbe, 0x4d, 0x09, 0xfc, 0x4b, + 0x4a, 0x3d, 0x42, 0x20, 0x00, 0x85, 0xe8, 0x37, 0x89, 0x66, 0xdc, 0x6e, + 0xf6, 0xd3, 0x32, 0x5c, 0x5f, 0x2a, 0xd0, 0x41, 0xeb, 0x25, 0xcb, 0xea, + 0xdf, 0xe1, 0xe6, 0xac, 0x2d, 0x53, 0x1f, 0x14, 0x52, 0x13, 0xe8, 0xd9, + 0xd2, 0x05, 0x4f, 0x17, 0x7b, 0xd3, 0x91, 0x0a, 0x56, 0x8c, 0x75, 0x2a, + 0xfd, 0x2b, 0xae, 0x27, 0x1b, 0xb6, 0xac, 0xb9, 0xe6, 0x60, 0xaa, 0xba, + 0x58, 0xbd, 0x27, 0x9f, 0x64, 0xc2, 0x76, 0xe6, 0x13, 0xcd, 0xa9, 0xa2, + 0x01, 0x4e, 0x6e, 0x80, 0xe6, 0x8f, 0x94, 0xaa, 0x2c, 0x76, 0xca, 0x99, + 0xc0, 0xc7, 0x4a, 0x4b, 0x94, 0xec, 0x8e, 0x99, 0xc5, 0x2b, 0x26, 0x2f, + 0x69, 0x1e, 0x1e, 0x72, 0x58, 0xfc, 0x07, 0x9a, 0x54, 0x52, 0xfc, 0xb3, + 0x87, 0x8c, 0xc6, 0x48, 0x87, 0xcf, 0xe1, 0x58, 0x4f, 0xed, 0x14, 0xb5, + 0xf3, 0x0f, 0x48, 0xde, 0xe6, 0x2c, 0x00, 0x1b, 0x21, 0x6c, 0xc7, 0xab, + 0xdf, 0x48, 0x77, 0xb9, 0x3f, 0xec, 0xb1, 0xa2, 0x9d, 0xba, 0x2c, 0xd0, + 0x85, 0x04, 0x6b, 0x84, 0x9c, 0x0f, 0x35, 0xb4, 0x1f, 0x89, 0x32, 0xa5, + 0x04, 0x60, 0xeb, 0xd9, 0x26, 0xc4, 0xea, 0xe0, 0x81, 0xce, 0xa8, 0x3c, + 0x55, 0x41, 0x3d, 0x6b, 0xe7, 0x1f, 0x05, 0x6e, 0x0b, 0xf1, 0x01, 0xd0, + 0x34, 0x8b, 0xfc, 0x7c, 0x74, 0xa0, 0xb0, 0xb7, 0x42, 0x0f, 0x1b, 0x82, + 0x80, 0x92, 0x3f, 0x39, 0x9f, 0xc9, 0x50, 0xeb, 0xfb, 0x02, 0x3f, 0x21, + 0xa2, 0x4a, 0xe7, 0xf8, 0x28, 0xf3, 0x51, 0x35, 0x6b, 0xa9, 0xb0, 0x3f, + 0x0d, 0xda, 0x03, 0x01, 0x31, 0xf2, 0x8e, 0x9a, 0xc0, 0xe2, 0x9a, 0x02, + 0x13, 0xed, 0xc9, 0x80, 0x95, 0x6c, 0x6c, 0x38, 0x21, 0x5c, 0xfe, 0x58, + 0x95, 0x2c, 0xa9, 0x02, 0xa1, 0xb5, 0x45, 0x16, 0xd0, 0x2d, 0xcb, 0x1b, + 0xd7, 0x6b, 0x8c, 0x83, 0xaa, 0xb3, 0x08, 0x47, 0x24, 0xac, 0xd0, 0x82, + 0x9f, 0x35, 0x7b, 0xf5, 0x56, 0x5d, 0x13, 0xf4, 0xf9, 0xf7, 0xb6, 0x0d, + 0x24, 0x6e, 0xf4, 0x81, 0xe4, 0x7b, 0x83, 0x59, 0x5c, 0xd5, 0xf2, 0xe8, + 0x1d, 0x5a, 0x52, 0xa2, 0x29, 0x6b, 0x10, 0x1f, 0xde, 0x70, 0xb0, 0x48, + 0x9b, 0x7d, 0x98, 0xc8, 0x09, 0x26, 0x92, 0x63, 0xc3, 0x3c, 0xfd, 0x28, + 0x44, 0x90, 0x1e, 0x5d, 0x1d, 0x2a, 0x95, 0xef, 0xba, 0xd7, 0x46, 0x86, + 0x29, 0x82, 0x4d, 0xfc, 0x6d, 0xf1, 0xc5, 0x7e, 0x89, 0xdf, 0xdb, 0x25, + 0x5c, 0x9f, 0x55, 0xee, 0xcf, 0x65, 0x4c, 0x97, 0x87, 0x37, 0x39, 0x45, + 0x97, 0xc7, 0x3e, 0x2f, 0xd4, 0x66, 0x35, 0x7e, 0x32, 0x77, 0x1c, 0xcf, + 0xa0, 0x78, 0x93, 0x71, 0x56, 0xc4, 0xcc, 0x35, 0xed, 0xba, 0x6d, 0x02, + 0x38, 0x80, 0xe6, 0xc6, 0x32, 0x2f, 0xad, 0xc8, 0x43, 0x19, 0x4b, 0x05, + 0xd1, 0x5c, 0x7f, 0xb1, 0x0e, 0x63, 0x74, 0x27, 0x5d, 0x7f, 0x39, 0xbc, + 0x15, 0xfd, 0x71, 0x68, 0x79, 0x9e, 0xd4, 0x0d, 0x3f, 0x58, 0x1d, 0x86, + 0x7e, 0xac, 0x7b, 0x72, 0x0e, 0x81, 0x45, 0x06, 0x56, 0x84, 0x11, 0xc1, + 0xb8, 0x1e, 0xf4, 0x90, 0x0f, 0xe4, 0xce, 0x99, 0x39, 0xc8, 0x0f, 0x7e, + 0x4a, 0xd5, 0x63, 0x2f, 0x39, 0xc6, 0x65, 0x59, 0xf3, 0xd9, 0xe8, 0x7c, + 0x0d, 0x0c, 0xca, 0xdb, 0xd3, 0xcc, 0x42, 0xc3, 0xbb, 0x0b, 0x19, 0xba, + 0xe4, 0x13, 0x94, 0x51, 0x2e, 0xe8, 0x66, 0x05, 0xe4, 0xe3, 0xdf, 0xba, + 0x5f, 0x00, 0xac, 0x82, 0x21, 0xa2, 0xa1, 0xa2, 0x9e, 0x12, 0xba, 0xe5, + 0x33, 0x14, 0x70, 0xfe, 0x6d, 0xe4, 0xe3, 0xff, 0x89, 0x31, 0x8a, 0x01, + 0x55, 0x68, 0xa7, 0x8d, 0x60, 0x7e, 0xb2, 0x97, 0x30, 0x08, 0xa0, 0x20, + 0x05, 0x32, 0x50, 0x1b, 0x9d, 0x98, 0x46, 0xe5, 0x47, 0xee, 0xb2, 0x02, + 0x87, 0x9c, 0x86, 0x36, 0x62, 0x15, 0x85, 0x91, 0xdc, 0xc0, 0xb6, 0xf9, + 0x5b, 0xf4, 0x53, 0xe1, 0x53, 0xb9, 0x07, 0x27, 0x87, 0xf0, 0xb8, 0xdf, + 0x92, 0x69, 0xbb, 0xe0, 0xf9, 0x92, 0xa6, 0x50, 0xc5, 0xe9, 0x6b, 0x7c, + 0x3b, 0x9e, 0x90, 0xe7, 0xa3, 0x86, 0xaa, 0xb2, 0x3c, 0xd3, 0x20, 0x57, + 0xd9, 0xe3, 0x5f, 0xb4, 0x94, 0x49, 0x96, 0xc7, 0x61, 0x0d, 0x29, 0x88, + 0x98, 0x10, 0x81, 0x5e, 0x64, 0x8d, 0xda, 0x46, 0x7a, 0x27, 0x3c, 0xac, + 0x73, 0xae, 0x02, 0x16, 0x4e, 0x98, 0x57, 0x39, 0xa3, 0x29, 0x5b, 0xfc, + 0x1e, 0xb8, 0x3a, 0x28, 0xf3, 0x00, 0x03, 0xa2, 0x91, 0xac, 0xa0, 0xf3, + 0x71, 0xae, 0x32, 0x8a, 0x96, 0xba, 0x8d, 0xe2, 0x86, 0x44, 0x10, 0x2c, + 0x00, 0x4a, 0x71, 0xdf, 0x39, 0x44, 0x50, 0xf6, 0x9a, 0xd4, 0x6e, 0x13, + 0x17, 0x1d, 0x8a, 0xd4, 0xd7, 0x8d, 0x3e, 0x1b, 0x4b, 0x1d, 0x47, 0x34, + 0x55, 0x49, 0x39, 0xc4, 0x45, 0x69, 0x50, 0xe2, 0xab, 0x48, 0x44, 0x04, + 0x74, 0x25, 0xa2, 0x03, 0x17, 0xf9, 0x7a, 0x4a, 0x75, 0x3a, 0x40, 0xa8, + 0x27, 0x4f, 0x97, 0xac, 0xee, 0x3f, 0x7e, 0xa0, 0xee, 0x90, 0xc6, 0x57, + 0xf9, 0x2d, 0xd4, 0xfc, 0xb4, 0xe1, 0x5c, 0xb6, 0xbc, 0x34, 0x7c, 0x58, + 0x9c, 0x0a, 0xd5, 0x78, 0xca, 0x7e, 0x44, 0xf1, 0x4a, 0x1c, 0x9a, 0x58, + 0xef, 0xab, 0x91, 0xfe, 0xa8, 0xea, 0x34, 0x4f, 0x06, 0xbf, 0xae, 0x77, + 0xcd, 0x50, 0xe0, 0xeb, 0x31, 0x41, 0x9a, 0x6d, 0x03, 0x3d, 0xaa, 0x51, + 0x03, 0x53, 0x25, 0xaf, 0xaa, 0xf4, 0x5c, 0xe3, 0x01, 0x08, 0xb6, 0x16, + 0xd7, 0xef, 0xae, 0xed, 0xf7, 0x9f, 0x2f, 0x40, 0xf5, 0x01, 0xd4, 0x05, + 0x6f, 0x2e, 0x46, 0x8d, 0xaf, 0x06, 0x9e, 0xee, 0x32, 0x2c, 0x12, 0x99, + 0xf0, 0x88, 0xb3, 0x86, 0xb9, 0x92, 0x83, 0x38, 0x32, 0xd7, 0xfd, 0xea, + 0x4a, 0xf1, 0x7d, 0x30, 0x5c, 0x6f, 0xd4, 0x55, 0xb8, 0xc5, 0x91, 0xfe, + 0x52, 0xc4, 0x4f, 0xe1, 0x23, 0x56, 0x60, 0xd0, 0x95, 0x2a, 0xd0, 0x68, + 0x4f, 0xaa, 0x3e, 0xb9, 0xfd, 0xa3, 0x9a, 0x70, 0x62, 0xfd, 0xae, 0x71, + 0x68, 0x8e, 0xbd, 0xb4, 0x19, 0xeb, 0xdc, 0x36, 0x15, 0xc2, 0xd8, 0xfb, + 0x2c, 0xa3, 0x0a, 0xc8, 0xfa, 0xb6, 0xbe, 0x9e, 0xbb, 0xc6, 0x2d, 0x67, + 0x86, 0x6b, 0x25, 0xb3, 0x68, 0xdd, 0x05, 0xfe, 0x9e, 0x36, 0x63, 0x32, + 0x4c, 0x3f, 0x81, 0x21, 0x0d, 0x12, 0x7c, 0x90, 0xc1, 0xf5, 0xc6, 0x82, + 0x2a, 0xdb, 0xf8, 0x04, 0xbb, 0x62, 0x4f, 0x35, 0xa5, 0x9c, 0xcc, 0xd9, + 0xc9, 0x95, 0xa7, 0x2b, 0xc0, 0xd8, 0x49, 0xaa, 0xc4, 0x33, 0x9a, 0x3d, + 0xd2, 0x5f, 0x98, 0x29, 0x28, 0x49, 0x9e, 0xd0, 0xb9, 0x7a, 0x70, 0x05, + 0xb9, 0x8c, 0xf6, 0xe3, 0x1d, 0x46, 0x73, 0x24, 0x14, 0x7f, 0x5f, 0x3a, + 0xdb, 0x7d, 0x73, 0x11, 0xab, 0x8e, 0xe7, 0xac, 0x11, 0x3b, 0x6e, 0x9b, + 0x48, 0x05, 0x4b, 0xc3, 0x50, 0x9b, 0x23, 0x42, 0x45, 0xc3, 0xb7, 0xaf, + 0x0d, 0x62, 0x1d, 0xe8, 0xa9, 0xe0, 0x09, 0x7a, 0x81, 0xb2, 0xd2, 0x96, + 0xa1, 0xcb, 0x51, 0x54, 0x5d, 0x8c, 0x2f, 0x22, 0x9e, 0x7a, 0x00, 0xb8, + 0x8a, 0xec, 0xd4, 0x87, 0x84, 0xec, 0x1e, 0x1b, 0xe3, 0xf8, 0xec, 0xef, + 0xc3, 0xaa, 0x7d, 0xbf, 0x1b, 0xce, 0xd4, 0xa9, 0x2b, 0x15, 0xab, 0x2b, + 0x19, 0xa7, 0xdc, 0x14, 0x33, 0x33, 0x6d, 0x14, 0xc2, 0xff, 0x1f, 0x5f, + 0xda, 0x63, 0x23, 0xc4, 0x67, 0x8c, 0xce, 0xc9, 0x9e, 0xd2, 0x7a, 0x81, + 0xbc, 0x4d, 0xa0, 0x91, 0x56, 0xbe, 0x19, 0x2d, 0xe3, 0x60, 0x82, 0xcd, + 0x4c, 0x97, 0x2f, 0x67, 0x6e, 0x24, 0xca, 0xc5, 0xe7, 0x5c, 0x80, 0x36, + 0x09, 0xeb, 0xef, 0x6f, 0xb0, 0x73, 0x30, 0x98, 0x6a, 0xc9, 0x7d, 0x0c, + 0x87, 0x4d, 0xec, 0x1b, 0x58, 0xa3, 0x9f, 0xdf, 0x62, 0x3d, 0xb8, 0x92, + 0x61, 0xd6, 0x54, 0x31, 0x5a, 0x0a, 0x37, 0xff, 0x4f, 0xad, 0xf5, 0x9a, + 0x6c, 0xd9, 0x41, 0x29, 0xf3, 0xdc, 0x4e, 0xd6, 0xba, 0x9d, 0x75, 0x97, + 0x15, 0x6b, 0x82, 0x67, 0x12, 0x02, 0x6b, 0x07, 0x15, 0x8e, 0x5c, 0xce, + 0x99, 0x62, 0x8a, 0x31, 0xf5, 0x1c, 0x1c, 0xe9, 0x7d, 0xe3, 0xe0, 0x69, + 0x2e, 0x36, 0x1c, 0x4d, 0x3a, 0x41, 0xfb, 0x71, 0x5f, 0x15, 0x67, 0x73, + 0x90, 0x61, 0x16, 0xc1, 0xe5, 0x52, 0x01, 0x01, 0x32, 0x7e, 0x6b, 0x2b, + 0x56, 0x2b, 0x3b, 0xa6, 0x2e, 0xb8, 0x61, 0x26, 0xd7, 0x14, 0x1d, 0xd1, + 0xc6, 0x93, 0x6a, 0x42, 0xb9, 0x14, 0x97, 0xdb, 0xf8, 0xed, 0x5f, 0x9e, + 0x01, 0x08, 0x71, 0x73, 0xdf, 0xd8, 0xd7, 0x9d, 0x70, 0x3b, 0x12, 0x0e, + 0x46, 0x92, 0x31, 0xd5, 0xce, 0xb5, 0xb7, 0x79, 0x80, 0x22, 0x4b, 0x25, + 0xa0, 0xed, 0x2f, 0xee, 0xd1, 0x92, 0x97, 0x7d, 0x86, 0xf4, 0xb1, 0x4a, + 0xca, 0xd4, 0x90, 0xcc, 0x4d, 0x0f, 0x3a, 0x50, 0xf4, 0x83, 0x12, 0x10, + 0x59, 0x12, 0xc4, 0x77, 0xdc, 0xea, 0x4e, 0x19, 0x29, 0xfa, 0xef, 0xcd, + 0xa2, 0x7c, 0x02, 0xd9, 0xf5, 0x1e, 0x23, 0x15, 0xe2, 0x18, 0x05, 0x44, + 0xcb, 0xb4, 0x84, 0x5f, 0x6b, 0xb4, 0xd7, 0x0f, 0x8f, 0xf5, 0xae, 0x41, + 0xba, 0x77, 0xc1, 0x8a, 0xc7, 0x8a, 0xc8, 0x7b, 0xac, 0x11, 0x5b, 0xc5, + 0x63, 0xa7, 0x3d, 0xcb, 0xcc, 0x99, 0x9c, 0xbf, 0x72, 0x2f, 0xa2, 0xeb, + 0x42, 0x94, 0x21, 0x6f, 0x60, 0x03, 0xe0, 0x2a, 0x47, 0xff, 0xa1, 0xf1, + 0xdd, 0xca, 0xd0, 0x3b, 0x17, 0x25, 0xac, 0xf4, 0xcc, 0x12, 0x6c, 0x7d, + 0x1e, 0xb8, 0x11, 0xbc, 0x20, 0xfd, 0x11, 0x09, 0x67, 0x53, 0x13, 0xb7, + 0x3a, 0xfe, 0x19, 0x02, 0xff, 0xe0, 0x6d, 0x8a, 0x44, 0x6e, 0xa2, 0x84, + 0x43, 0x29, 0x01, 0xe8, 0xb2, 0x42, 0x2e, 0xd2, 0xb5, 0x93, 0x1a, 0xd3, + 0xb2, 0xa1, 0xa1, 0x72, 0xa1, 0xb5, 0xbc, 0x51, 0x4e, 0x04, 0x82, 0x41, + 0x8e, 0x19, 0x32, 0xe4, 0xe7, 0xc6, 0xbd, 0x1c, 0xf3, 0xf0, 0x76, 0xc5, + 0x05, 0xbe, 0xe0, 0x5d, 0xc7, 0x8f, 0x4f, 0x12, 0x1a, 0xe2, 0x04, 0x31, + 0x0d, 0x3f, 0xb2, 0x85, 0x69, 0x1e, 0xde, 0xd4, 0x82, 0xdf, 0x44, 0x4e, + 0x6c, 0x26, 0xe9, 0x85, 0x37, 0x0e, 0x90, 0x94, 0x33, 0xfe, 0xae, 0x22, + 0x3e, 0xb1, 0x9c, 0xee, 0xc7, 0xd7, 0xc2, 0xfb, 0xe4, 0x09, 0x61, 0x9c, + 0xa9, 0xef, 0xc2, 0xbc, 0xab, 0x56, 0xec, 0xfa, 0x40, 0x3c, 0xfd, 0x3d, + 0xe3, 0x5a, 0x5b, 0x53, 0x5c, 0xb1, 0x2f, 0x33, 0x66, 0xdb, 0x32, 0x25, + 0x19, 0xfc, 0x08, 0xcc, 0x6c, 0x37, 0x30, 0xdc, 0x9a, 0x8c, 0x2c, 0xb3, + 0x6f, 0xe3, 0x53, 0x2e, 0x6e, 0x94, 0x07, 0xd5, 0xc3, 0x82, 0x53, 0x1c, + 0x78, 0x78, 0x8b, 0x30, 0x2d, 0xaa, 0x10, 0x6c, 0xf2, 0x93, 0x52, 0xa3, + 0x74, 0x30, 0x61, 0x42, 0x47, 0x7e, 0x1f, 0x7e, 0xdb, 0xa8, 0xa8, 0x16, + 0xe0, 0x58, 0x17, 0xcb, 0xb5, 0x2f, 0xf0, 0x88, 0xd2, 0xc5, 0x6d, 0xdc, + 0x1c, 0x28, 0xd9, 0x6a, 0xb5, 0xb3, 0x14, 0x22, 0xe6, 0xa1, 0x47, 0x20, + 0xee, 0xd8, 0x8d, 0xba, 0x2b, 0xe8, 0x3c, 0x1c, 0x21, 0x1b, 0xa9, 0x5d, + 0xfd, 0xb4, 0x38, 0xae, 0x07, 0xa1, 0xd5, 0x8e, 0x59, 0x7b, 0xf6, 0xe2, + 0x1f, 0xb4, 0xa6, 0x48, 0xba, 0x9c, 0x22, 0xc2, 0xb5, 0x00, 0x8e, 0xdb, + 0x19, 0x90, 0x9b, 0x63, 0x06, 0x2c, 0x9e, 0xf7, 0x5b, 0xcb, 0x20, 0x31, + 0x43, 0x29, 0x08, 0xd0, 0x89, 0x1c, 0x11, 0xa2, 0x68, 0x96, 0xf8, 0x0e, + 0x11, 0xaa, 0x5e, 0xc1, 0x5e, 0x28, 0x91, 0xcb, 0x12, 0xa1, 0x74, 0x54, + 0xb4, 0xfb, 0x10, 0x85, 0x20, 0xb5, 0x75, 0x6a, 0xbd, 0x5b, 0xe3, 0xfa, + 0x22, 0x0e, 0xb0, 0xf4, 0x0f, 0x6f, 0xdd, 0x78, 0x92, 0xc9, 0x5d, 0x70, + 0x34, 0xb1, 0x56, 0x14, 0x03, 0x56, 0x9e, 0x7c, 0x38, 0x3e, 0x69, 0x7d, + 0xe7, 0xa0, 0x1e, 0xe5, 0xbc, 0x7c, 0x3e, 0xd9, 0xc0, 0x5f, 0x53, 0x94, + 0xde, 0x3d, 0xde, 0xdf, 0x8a, 0x76, 0x6d, 0x8b, 0xeb, 0x61, 0x1d, 0x6c, + 0xc5, 0xef, 0x6c, 0xdb, 0xbd, 0xc7, 0x44, 0x91, 0x53, 0x4d, 0x42, 0xa4, + 0xfb, 0x41, 0xa3, 0x91, 0x31, 0xb0, 0x1d, 0xd6, 0x39, 0xe9, 0x3c, 0x91, + 0x4d, 0x9d, 0x54, 0x6b, 0x8e, 0xd0, 0xc8, 0x6e, 0x02, 0x4b, 0x7c, 0x4a, + 0x70, 0xc6, 0x53, 0xd2, 0xd5, 0xad, 0xd1, 0x08, 0xc7, 0xde, 0xa4, 0x6f, + 0x30, 0x77, 0x31, 0x83, 0x0d, 0xa5, 0xa4, 0xf6, 0x2b, 0x5c, 0xc5, 0x1f, + 0xe6, 0x2d, 0x6e, 0xbc, 0x22, 0xdd, 0xa0, 0x52, 0x42, 0x85, 0x82, 0x05, + 0x53, 0x1e, 0x19, 0x45, 0xee, 0x2b, 0x03, 0x22, 0x14, 0x90, 0x8c, 0x83, + 0x28, 0x45, 0x02, 0xa7, 0xe0, 0x10, 0x66, 0xb8, 0x8d, 0xc6, 0x3f, 0x9f, + 0x15, 0xfa, 0x83, 0xdf, 0x7f, 0x30, 0xf4, 0x19, 0x12, 0x99, 0x57, 0x4e, + 0xc9, 0x56, 0x03, 0xd7, 0x08, 0xfe, 0xb6, 0x99, 0xc2, 0x31, 0x49, 0x40, + 0xa0, 0xea, 0x81, 0x25, 0x1d, 0x1b, 0x60, 0xcb, 0x40, 0x6b, 0x8e, 0x37, + 0xd4, 0xe8, 0x44, 0xe1, 0xcd, 0x63, 0x5d, 0x87, 0x80, 0x47, 0x03, 0xc9, + 0x82, 0xf0, 0x53, 0x2c, 0x29, 0xd0, 0x0f, 0x52, 0x36, 0x51, 0x0c, 0x60, + 0xe1, 0xf1, 0x6e, 0x88, 0x44, 0x14, 0x74, 0x5d, 0x2f, 0x6f, 0xb5, 0x6e, + 0x41, 0x9e, 0xe6, 0x51, 0xa9, 0x69, 0x43, 0x8d, 0xbb, 0x10, 0x56, 0x36, + 0x0b, 0x20, 0x54, 0x01, 0x5e, 0xb7, 0x97, 0x1e, 0x57, 0x40, 0x5e, 0x63, + 0xba, 0xfc, 0x6f, 0xfc, 0x6f, 0xf6, 0xb0, 0x47, 0x36, 0xce, 0x8c, 0x83, + 0x68, 0xba, 0xdc, 0x7d, 0x79, 0x4b, 0x14, 0x33, 0xee, 0x7b, 0x3d, 0x3d, + 0x21, 0x62, 0x28, 0xe3, 0x09, 0x3a, 0x74, 0xa1, 0x0c, 0x5c, 0x92, 0xbf, + 0xd5, 0x35, 0x41, 0xda, 0xbb, 0x95, 0xaa, 0xbb, 0x5e, 0xbe, 0xb0, 0x57, + 0xc8, 0x5a, 0x18, 0x2b, 0x07, 0x6c, 0x92, 0x73, 0x75, 0x84, 0x83, 0x60, + 0x10, 0x76, 0x87, 0x8a, 0xa7, 0xe9, 0x03, 0xd4, 0x1e, 0xc9, 0x30, 0xad, + 0xb8, 0xef, 0x6d, 0x70, 0x8a, 0x28, 0xb9, 0xe3, 0xbf, 0xbb, 0xdf, 0x66, + 0xbc, 0x70, 0xa3, 0x22, 0xdc, 0x6d, 0x0d, 0xf1, 0x93, 0x4b, 0x93, 0xae, + 0xbd, 0xc2, 0xc8, 0x86, 0x54, 0x73, 0x26, 0xea, 0x15, 0xb7, 0xce, 0x89, + 0x6c, 0xd3, 0x90, 0x28, 0x6d, 0x86, 0x92, 0x31, 0x19, 0x58, 0x12, 0xf4, + 0x08, 0xa1, 0x1d, 0xa7, 0x78, 0xe9, 0xce, 0x41, 0x7e, 0x8e, 0xf9, 0xe1, + 0x55, 0x0b, 0xe3, 0x23, 0x91, 0x81, 0x04, 0x5b, 0xe9, 0x08, 0x71, 0x71, + 0x35, 0xd3, 0x5a, 0x8e, 0x15, 0x54, 0x2c, 0xb6, 0x93, 0x4f, 0xab, 0x65, + 0xa9, 0x25, 0x5e, 0xaf, 0x54, 0x0c, 0x03, 0x71, 0xba, 0x27, 0xdb, 0xd5, + 0xc4, 0x31, 0xf4, 0x63, 0x60, 0xd4, 0x2f, 0x7d, 0x7a, 0xe3, 0x7a, 0xbb, + 0xac, 0x42, 0xac, 0x76, 0x84, 0xc1, 0x1c, 0x9f, 0xa0, 0x62, 0x15, 0x56, + 0x43, 0xd5, 0x13, 0xaa, 0xe1, 0xca, 0x3a, 0xc2, 0x1d, 0xd9, 0xb3, 0x00, + 0xf0, 0x69, 0x4a, 0xfd, 0x28, 0xa2, 0x6e, 0xe9, 0x7d, 0x0d, 0x51, 0xf3, + 0x92, 0xa2, 0xd9, 0x65, 0xe3, 0x42, 0xe4, 0x68, 0x63, 0xae, 0xf5, 0x56, + 0x46, 0xc9, 0xbe, 0xe1, 0xc2, 0x07, 0x48, 0x5a, 0x8e, 0xf8, 0x54, 0xf9, + 0x35, 0x90, 0x35, 0xd9, 0x75, 0xb3, 0xc2, 0x92, 0xdc, 0x69, 0x4a, 0x6b, + 0x9a, 0x68, 0x0e, 0xd1, 0x7c, 0xaa, 0x0a, 0x9a, 0x94, 0x24, 0x4a, 0x05, + 0xd3, 0x41, 0x51, 0x51, 0xf0, 0xc7, 0x59, 0xfa, 0x15, 0x84, 0xa6, 0x50, + 0x1b, 0x35, 0xa3, 0x0f, 0x88, 0xde, 0x7e, 0x58, 0xaf, 0x93, 0x9a, 0xbb, + 0x72, 0xcb, 0x94, 0x3a, 0x7e, 0xec, 0x81, 0xf1, 0xd8, 0xa4, 0xa1, 0x96, + 0xc5, 0x08, 0x2f, 0x84, 0x25, 0x89, 0xf3, 0xe3, 0xce, 0x2d, 0x86, 0x51, + 0x6c, 0x48, 0x94, 0x08, 0xea, 0x97, 0x50, 0x6c, 0x3c, 0xbf, 0xec, 0xeb, + 0x3a, 0x9e, 0xd2, 0xe2, 0x6c, 0x0e, 0x8d, 0x0f, 0xe9, 0x2f, 0xb1, 0xe7, + 0x93, 0xb8, 0xa8, 0x6b, 0x81, 0xa0, 0x87, 0xf3, 0x0b, 0x0c, 0x3f, 0x46, + 0xb2, 0x72, 0x22, 0x85, 0x76, 0x00, 0x98, 0xcb, 0x93, 0x58, 0xd9, 0x75, + 0x16, 0x29, 0xf6, 0x8a, 0x6e, 0xa5, 0x13, 0x78, 0x51, 0xe8, 0x60, 0x20, + 0xbc, 0x74, 0x07, 0xd7, 0x8c, 0xe8, 0x32, 0x69, 0xd1, 0x21, 0x71, 0x1f, + 0xca, 0xf9, 0xf6, 0x30, 0x1b, 0x9f, 0x9a, 0x24, 0x68, 0xa9, 0x8f, 0x2d, + 0x1e, 0x5f, 0x4c, 0x0d, 0x6b, 0x97, 0x2d, 0xf8, 0x1d, 0xd4, 0x80, 0x71, + 0x07, 0xbb, 0x15, 0x6d, 0xe5, 0x11, 0x43, 0xcd, 0xd3, 0x5c, 0xff, 0x5f, + 0x43, 0x9a, 0x91, 0x2c, 0xdd, 0x50, 0xb1, 0x52, 0x2b, 0xb3, 0xb7, 0x5d, + 0x04, 0x15, 0xba, 0xdf, 0xa0, 0x31, 0x52, 0x0c, 0xd1, 0x1d, 0x4b, 0x47, + 0x3d, 0xab, 0x03, 0x86, 0xaf, 0x3d, 0x9b, 0xb2, 0x56, 0x5b, 0x50, 0xef, + 0xba, 0x7f, 0x6e, 0x95, 0x6f, 0x8d, 0x0b, 0xaf, 0x7d, 0x75, 0x8a, 0xb1, + 0x1f, 0xbd, 0xe4, 0xe4, 0x72, 0xb3, 0x6b, 0xf9, 0xe4, 0x5f, 0x1a, 0xf2, + 0x0c, 0x44, 0x21, 0xfc, 0x56, 0x06, 0x2f, 0xb1, 0xac, 0xcb, 0x2f, 0x4d, + 0x38, 0x86, 0xa2, 0x00, 0x44, 0xc8, 0x5a, 0x1e, 0xca, 0xf6, 0x90, 0x45, + 0xcd, 0xc7, 0x9d, 0x87, 0x5d, 0x79, 0x78, 0xb0, 0x7c, 0xa4, 0x03, 0x52, + 0x0e, 0x1a, 0x3b, 0x1d, 0x66, 0x1b, 0x4f, 0x48, 0x34, 0xa1, 0xa1, 0xe7, + 0x9c, 0x4a, 0x5f, 0x42, 0xec, 0x62, 0x83, 0xe0, 0x10, 0xfc, 0xb8, 0x65, + 0x4f, 0xe6, 0x8b, 0x3a, 0x43, 0x9e, 0xd6, 0x9a, 0x60, 0x77, 0x3f, 0xbe, + 0x3b, 0x18, 0x32, 0x92, 0x86, 0x78, 0x48, 0x21, 0x6e, 0x03, 0x40, 0xfe, + 0x8f, 0x7b, 0x3c, 0xe1, 0x15, 0x9d, 0x42, 0xef, 0x3e, 0x29, 0x89, 0x54, + 0x58, 0x8a, 0x03, 0x16, 0xb7, 0xf6, 0x7d, 0x6f, 0x14, 0x90, 0xd3, 0xff, + 0xe6, 0x18, 0x1f, 0x78, 0xa9, 0xe6, 0x77, 0xa4, 0x9b, 0xf0, 0x4f, 0x62, + 0x5d, 0xd9, 0x20, 0x69, 0x35, 0x4c, 0xa2, 0xc2, 0x8a, 0xed, 0x9a, 0xfa, + 0x5e, 0x13, 0xec, 0xd3, 0x11, 0xa6, 0xc9, 0x64, 0x20, 0x30, 0x30, 0xc6, + 0x34, 0x27, 0x63, 0x56, 0xb5, 0x2a, 0x97, 0x3d, 0x9e, 0xbc, 0xb3, 0x1a, + 0x7c, 0x97, 0xff, 0x39, 0x64, 0xec, 0x7f, 0xf6, 0x04, 0x98, 0xbb, 0x03, + 0xeb, 0xc2, 0x2b, 0xb8, 0xdb, 0x45, 0xf3, 0x01, 0xde, 0x83, 0xd4, 0xdf, + 0x05, 0x48, 0x42, 0x14, 0x3a, 0x23, 0x27, 0x0b, 0xdc, 0x0f, 0xe8, 0x56, + 0xb5, 0xe2, 0xe9, 0x23, 0xab, 0xc2, 0xed, 0x5d, 0xc7, 0x6f, 0xaf, 0x0c, + 0xb2, 0x0e, 0x75, 0x47, 0xc5, 0x02, 0x97, 0x82, 0x6e, 0xb6, 0xc7, 0xc4, + 0xb3, 0x4d, 0xe5, 0x89, 0x01, 0x80, 0x21, 0x08, 0x21, 0x2b, 0xfc, 0xe0, + 0x9e, 0x68, 0x41, 0x5e, 0x93, 0xf7, 0x8d, 0x32, 0x65, 0x39, 0x36, 0x46, + 0x98, 0xc1, 0x04, 0xf2, 0xc3, 0x0c, 0xd6, 0x29, 0xe1, 0xf1, 0x3b, 0x19, + 0x7b, 0x7e, 0x1e, 0x15, 0x02, 0xb5, 0x61, 0xc8, 0x18, 0xbc, 0xd3, 0x5c, + 0x5e, 0x00, 0x90, 0xc2, 0xc2, 0xc7, 0xab, 0x51, 0xfa, 0xd4, 0xc1, 0xfd, + 0x2d, 0xc3, 0x98, 0x4b, 0xd6, 0x02, 0x0c, 0x0e, 0xa7, 0xe8, 0xa6, 0xd3, + 0xa3, 0xda, 0x28, 0x70, 0x63, 0x4b, 0x6b, 0x45, 0x0d, 0x76, 0xa5, 0x46, + 0xcd, 0x98, 0x52, 0x1b, 0x03, 0xf1, 0x2d, 0x5c, 0xc2, 0xe4, 0xc7, 0x07, + 0x7b, 0x5e, 0xe3, 0x73, 0x98, 0xaa, 0xe1, 0xb0, 0x08, 0xaa, 0x5a, 0x40, + 0xf5, 0x8f, 0xd8, 0xb8, 0x44, 0xd3, 0xe6, 0xcd, 0x35, 0xa5, 0xa5, 0x66, + 0x7c, 0xc9, 0x5f, 0x92, 0xb5, 0x59, 0x66, 0xf7, 0xf6, 0xbe, 0x98, 0x38, + 0x7e, 0xcf, 0xa8, 0xd2, 0x57, 0xe0, 0x70, 0x3e, 0x35, 0x54, 0x5f, 0xe0, + 0x0c, 0xfd, 0x9f, 0x6b, 0x59, 0x39, 0x9b, 0x26, 0xd0, 0x21, 0x17, 0x5b, + 0x16, 0x6d, 0x83, 0x7c, 0xd5, 0xaa, 0xe0, 0xee, 0x8e, 0x9a, 0x50, 0x0f, + 0x10, 0x6b, 0x3e, 0x02, 0x46, 0x5d, 0xcf, 0xc3, 0x17, 0x20, 0xa0, 0x5d, + 0x2f, 0x63, 0x5d, 0xbf, 0x85, 0x8f, 0x3e, 0xc6, 0xc3, 0xad, 0x6e, 0xfb, + 0x92, 0xa6, 0xd0, 0x66, 0xc5, 0x09, 0x1c, 0x8c, 0x16, 0xb7, 0x54, 0xf8, + 0x62, 0x18, 0xe5, 0xa1, 0xc3, 0x3d, 0xcd, 0x04, 0xb6, 0x12, 0x19, 0xb8, + 0x6c, 0x1f, 0x8c, 0x8b, 0x4d, 0x29, 0x09, 0xa4, 0x80, 0x8a, 0x87, 0xbb, + 0xc7, 0xd3, 0x59, 0x26, 0xdb, 0x29, 0x9f, 0x56, 0x35, 0x97, 0xec, 0x26, + 0xb0, 0xe0, 0x04, 0x55, 0xd4, 0x8e, 0xb1, 0xc4, 0xba, 0x72, 0x29, 0x64, + 0x78, 0x1b, 0x58, 0xa1, 0xaa, 0x9a, 0x36, 0x77, 0xd7, 0x86, 0x84, 0xa6, + 0x2a, 0x80, 0x84, 0xa2, 0x6c, 0x85, 0x71, 0x96, 0x23, 0x56, 0xac, 0xdb, + 0xd5, 0x4d, 0x93, 0x68, 0xb3, 0xd6, 0xc0, 0xd8, 0x74, 0x73, 0x2d, 0x21, + 0x27, 0xc5, 0xb0, 0x0f, 0x62, 0xc9, 0x4c, 0x0d, 0x8e, 0x12, 0xd6, 0xe4, + 0xfc, 0x74, 0x39, 0xb3, 0xb8, 0x09, 0x31, 0x18, 0x41, 0xa2, 0x0e, 0x00, + 0x4e, 0x50, 0xf3, 0xbe, 0xa4, 0x04, 0x11, 0x04, 0x1d, 0xcc, 0x20, 0xe2, + 0xa2, 0x82, 0xe0, 0xb6, 0x92, 0x04, 0xfb, 0xbb, 0xd7, 0x24, 0xb5, 0xe8, + 0x87, 0x77, 0xa2, 0x6e, 0x66, 0x12, 0x10, 0x8d, 0x58, 0x65, 0x36, 0xa2, + 0x7f, 0x00, 0x9e, 0xe8, 0xe1, 0xa6, 0xf9, 0xc1, 0xee, 0xd0, 0x5f, 0x36, + 0x67, 0xe6, 0x21, 0xc2, 0xa9, 0x1b, 0xad, 0x88, 0x9e, 0x06, 0xeb, 0xc6, + 0xfd, 0xa4, 0x55, 0x85, 0xe7, 0xfb, 0xcf, 0xa2, 0x14, 0x06, 0x56, 0x67, + 0x9e, 0xd5, 0xac, 0xd1, 0x00, 0x4d, 0x81, 0x5c, 0xc7, 0x69, 0xfd, 0x73, + 0x01, 0x19, 0x84, 0x80, 0x3c, 0x34, 0x33, 0xdb, 0xc2, 0x37, 0xf3, 0x4b, + 0xe1, 0x78, 0x90, 0x6c, 0x8c, 0x2f, 0x82, 0x93, 0x04, 0x05, 0x47, 0xcc, + 0x57, 0xcc, 0x4f, 0x82, 0xfc, 0x99, 0xb4, 0x80, 0xbf, 0x18, 0xd8, 0xdc, + 0xf8, 0x51, 0x56, 0x5c, 0x86, 0x5c, 0x8b, 0xff, 0x34, 0xfd, 0xb8, 0x59, + 0x3d, 0xdb, 0xb4, 0xaa, 0x2e, 0xef, 0xc5, 0x1a, 0xda, 0x99, 0x6d, 0x09, + 0x34, 0x85, 0xc1, 0x38, 0xa5, 0xeb, 0x1b, 0x6b, 0xf6, 0xe6, 0xf7, 0x04, + 0x0d, 0x86, 0xc5, 0xd5, 0x75, 0xde, 0x67, 0x22, 0x74, 0xe7, 0x3c, 0x05, + 0xc6, 0x53, 0xbd, 0x10, 0xc9, 0x21, 0x95, 0x9e, 0x05, 0xb9, 0xbc, 0xc8, + 0xe1, 0x18, 0x3a, 0x8f, 0xe5, 0x72, 0xe8, 0x8f, 0xf5, 0x01, 0x5e, 0xde, + 0xe1, 0x4f, 0xbb, 0x0b, 0x79, 0x91, 0xca, 0xe2, 0x36, 0x3a, 0xa4, 0xe3, + 0x45, 0x50, 0x09, 0x26, 0xff, 0x31, 0xb6, 0xfa, 0x85, 0xdb, 0xd6, 0xa5, + 0x1e, 0xa8, 0x10, 0x92, 0x74, 0xc9, 0xa1, 0x59, 0x8b, 0xea, 0xda, 0x80, + 0x93, 0x3b, 0xdc, 0x52, 0xfa, 0xae, 0x9a, 0xe8, 0x2c, 0x22, 0x3f, 0xf3, + 0xe4, 0x7c, 0xe7, 0x49, 0x74, 0x47, 0xb9, 0xf7, 0x96, 0x1e, 0x09, 0x53, + 0x2a, 0x6b, 0xd5, 0x33, 0x03, 0xee, 0x70, 0xe4, 0xe1, 0xc1, 0x1a, 0x6b, + 0x44, 0xc9, 0x8f, 0x54, 0xef, 0x54, 0x3f, 0x98, 0xe2, 0xee, 0x58, 0x99, + 0x93, 0x98, 0x3d, 0xa1, 0x3a, 0xbf, 0x30, 0x1d, 0x70, 0xaf, 0x62, 0xb4, + 0xfb, 0x36, 0xb8, 0xb5, 0x7d, 0x1b, 0xc0, 0x2d, 0x0c, 0x5e, 0x2d, 0xb0, + 0xb8, 0x02, 0x24, 0x47, 0x41, 0x28, 0x14, 0xb3, 0x94, 0xfd, 0x23, 0xe7, + 0xb8, 0xac, 0x04, 0x87, 0xa1, 0xa8, 0x59, 0xc0, 0x4d, 0xe5, 0x19, 0xac, + 0x1d, 0xb9, 0xf2, 0x83, 0xaa, 0x63, 0x52, 0x80, 0x9c, 0x45, 0x91, 0x88, + 0x94, 0xe8, 0xb2, 0xd2, 0x3b, 0x82, 0x28, 0xc4, 0x08, 0x95, 0x4b, 0x57, + 0x24, 0xf6, 0xf2, 0x23, 0x68, 0xaf, 0x76, 0x78, 0x69, 0x92, 0x00, 0x20, + 0x6a, 0xfe, 0x43, 0x39, 0x5c, 0x21, 0x83, 0xbb, 0x6d, 0x24, 0xc6, 0xae, + 0xce, 0x6d, 0xf7, 0x3a, 0x1d, 0xf8, 0x16, 0x9a, 0x11, 0xa1, 0xd3, 0x6d, + 0xca, 0xe0, 0x11, 0x90, 0x44, 0x41, 0xde, 0x8b, 0x79, 0x51, 0xf6, 0x4b, + 0xe3, 0xb3, 0x05, 0x15, 0x74, 0x0d, 0x89, 0xea, 0x30, 0xa7, 0x40, 0xd4, + 0xc9, 0xed, 0x16, 0xcd, 0xbe, 0xb8, 0x06, 0xb6, 0xa9, 0x68, 0x6f, 0xba, + 0x40, 0xb0, 0xc8, 0xc4, 0x98, 0x28, 0x66, 0xdc, 0x4e, 0x86, 0xa2, 0x75, + 0x20, 0xaa, 0xc7, 0xb9, 0x36, 0x7e, 0x4c, 0x41, 0x7d, 0x4b, 0x00, 0x5d, + 0x76, 0xa9, 0xec, 0xec, 0x95, 0xb9, 0xac, 0xd2, 0x55, 0x33, 0xf3, 0xde, + 0x5f, 0xe7, 0x0d, 0x55, 0x22, 0xfa, 0x5c, 0x82, 0x56, 0x89, 0x9c, 0x2a, + 0x31, 0xc5, 0x14, 0x39, 0x1c, 0xc4, 0xb5, 0xc5, 0xe9, 0x3c, 0x1d, 0x6d, + 0xc7, 0x17, 0xc9, 0xeb, 0x49, 0xaf, 0xef, 0x7d, 0x47, 0x95, 0xbe, 0xcd, + 0x87, 0x00, 0xd3, 0xc8, 0xae, 0x0c, 0xf1, 0xe7, 0xa4, 0xf3, 0x2f, 0x22, + 0xea, 0x4c, 0x22, 0x15, 0x61, 0xdb, 0xa4, 0x5d, 0xc0, 0xd5, 0x26, 0x07, + 0xb6, 0x27, 0x70, 0xe2, 0xcd, 0x72, 0xc4, 0xda, 0x2c, 0xfe, 0x73, 0x6e, + 0x02, 0xa5, 0x64, 0x83, 0x9b, 0x3e, 0x1a, 0x27, 0x75, 0xee, 0x94, 0x7b, + 0x2a, 0xc1, 0x4a, 0xf3, 0x3d, 0xb4, 0xc9, 0x36, 0x72, 0xd9, 0x5d, 0x98, + 0x26, 0x95, 0xb9, 0xae, 0xbe, 0x45, 0x72, 0x8d, 0x9c, 0xcf, 0x5e, 0xd9, + 0x1a, 0x44, 0x39, 0x47, 0x55, 0x5a, 0x64, 0x2c, 0x4a, 0xd1, 0x5f, 0x5e, + 0x2c, 0x7e, 0x41, 0xb1, 0x43, 0xe3, 0x11, 0xc3, 0x72, 0x9f, 0xd7, 0x25, + 0xda, 0x0a, 0xd4, 0xeb, 0x23, 0xb7, 0x03, 0x4b, 0x63, 0xde, 0xa7, 0x12, + 0x51, 0x9b, 0x4f, 0x67, 0x22, 0x25, 0x72, 0xfe, 0x93, 0xbd, 0x14, 0xbb, + 0x70, 0xa6, 0xb9, 0xf4, 0x13, 0xbd, 0x09, 0x8e, 0xcd, 0x61, 0x30, 0xed, + 0x79, 0xf2, 0x82, 0x25, 0xaf, 0x8e, 0x2e, 0x53, 0x3b, 0xef, 0xcb, 0x79, + 0x90, 0x9c, 0xea, 0x6a, 0xb9, 0x2a, 0xfe, 0x2e, 0x1b, 0x53, 0x1f, 0xe7, + 0x66, 0x27, 0x73, 0x52, 0x53, 0x1b, 0x38, 0x91, 0xeb, 0x81, 0xf9, 0x6d, + 0x54, 0xc3, 0x6e, 0x0d, 0x7b, 0xcb, 0x0f, 0x4c, 0x15, 0x5d, 0xf4, 0x41, + 0xdf, 0x53, 0x71, 0x5b, 0x65, 0x1d, 0x8b, 0x1f, 0x0c, 0xff, 0x64, 0x6f, + 0x2d, 0x76, 0xd0, 0x89, 0x46, 0xf3, 0x91, 0x0d, 0x85, 0xde, 0xf4, 0x30, + 0x4d, 0xc1, 0x4b, 0xb3, 0xa6, 0xb2, 0x1b, 0x5f, 0x3c, 0xaa, 0x90, 0xdd, + 0x43, 0x4b, 0x3d, 0x04, 0x21, 0x4e, 0x42, 0x99, 0xeb, 0x93, 0x52, 0xa6, + 0x41, 0x1b, 0xdd, 0xc1, 0x70, 0x8c, 0xb3, 0xe9, 0x06, 0x3d, 0xe4, 0x5a, + 0x50, 0x87, 0x7a, 0x49, 0x56, 0x52, 0xa0, 0x4d, 0x24, 0x56, 0x99, 0x37, + 0xa4, 0xd2, 0x3f, 0x34, 0x4b, 0x93, 0xd1, 0xd0, 0x62, 0x0a, 0x81, 0x2a, + 0x6e, 0x23, 0x89, 0x9d, 0x46, 0x00, 0x14, 0xe6, 0x63, 0x02, 0x22, 0x26, + 0xc6, 0x09, 0x46, 0xa9, 0xac, 0x55, 0x41, 0x90, 0xd6, 0x57, 0x3a, 0xc7, + 0x8e, 0xd4, 0x5a, 0x1f, 0xd7, 0xd5, 0xdc, 0xac, 0x55, 0x07, 0x7e, 0x05, + 0x31, 0x03, 0x33, 0xea, 0x72, 0xfe, 0x5f, 0x79, 0x81, 0x77, 0x10, 0x3f, + 0x43, 0xf7, 0x73, 0x8f, 0x21, 0x07, 0xe1, 0x01, 0x01, 0xb4, 0x91, 0xe0, + 0x07, 0x8f, 0x0e, 0x6e, 0x15, 0x7a, 0x01, 0xdc, 0xe4, 0x72, 0x89, 0x8e, + 0x30, 0x36, 0x42, 0x45, 0xa0, 0x62, 0x37, 0x7e, 0x68, 0xb8, 0xa5, 0x9a, + 0x79, 0x43, 0x99, 0x7d, 0x0a, 0x7b, 0x60, 0x94, 0x49, 0xb2, 0xf0, 0x3c, + 0x5b, 0x67, 0xbf, 0xb4, 0x7b, 0x77, 0xc2, 0xe8, 0x02, 0xcc, 0x87, 0x21, + 0x86, 0x4b, 0x48, 0x76, 0xd9, 0x29, 0x59, 0x97, 0x3a, 0xfc, 0x7f, 0x71, + 0xf8, 0x03, 0xee, 0xad, 0x8f, 0x12, 0x76, 0x16, 0x00, 0xdf, 0xd8, 0x40, + 0x85, 0x62, 0x2f, 0x67, 0x34, 0x12, 0xa2, 0x17, 0x71, 0xf5, 0x58, 0x05, + 0x0c, 0x76, 0x4b, 0xa7, 0x4c, 0x57, 0x9f, 0x80, 0xf6, 0xe6, 0xb8, 0x46, + 0xe1, 0x84, 0x7e, 0xb5, 0x67, 0x48, 0xbc, 0x30, 0x78, 0xfb, 0x17, 0x50, + 0x56, 0xf0, 0xe1, 0xa2, 0x06, 0xac, 0x6c, 0xc6, 0xef, 0xf7, 0x42, 0x4b, + 0xaa, 0x26, 0x9f, 0xb8, 0xa7, 0xca, 0x80, 0x56, 0xf0, 0x09, 0x5b, 0x46, + 0x16, 0x16, 0x63, 0x0c, 0xf0, 0x41, 0x5c, 0x0a, 0x74, 0xf5, 0x76, 0x20, + 0x3d, 0xd5, 0x40, 0x46, 0x0e, 0xf8, 0x1b, 0x89, 0xd6, 0x7e, 0x93, 0xb4, + 0x98, 0x4b, 0x12, 0xee, 0xb7, 0xbd, 0xce, 0xe8, 0xbd, 0x18, 0xc6, 0x10, + 0x43, 0xf9, 0xce, 0x1a, 0xd4, 0x1a, 0xa2, 0xd8, 0x7d, 0xb3, 0x00, 0x3b, + 0x1c, 0x97, 0x5c, 0x1e, 0xd8, 0x6c, 0x36, 0x6b, 0xa6, 0xef, 0x5e, 0x78, + 0xd9, 0x02, 0x12, 0x61, 0x28, 0x87, 0xb7, 0x19, 0x08, 0xee, 0xdf, 0x16, + 0x15, 0x46, 0xa2, 0xa1, 0x0b, 0x07, 0x6b, 0x08, 0x39, 0x50, 0x43, 0x66, + 0x3f, 0xce, 0x25, 0xc1, 0x37, 0x57, 0x29, 0x95, 0xb9, 0x25, 0x9b, 0xfe, + 0x49, 0x76, 0xcd, 0x88, 0x8e, 0x5e, 0x64, 0x1e, 0xba, 0x66, 0x1f, 0x03, + 0xc6, 0x72, 0xb1, 0x8d, 0x66, 0x0f, 0x3a, 0x2f, 0x67, 0xf4, 0xf5, 0x05, + 0x84, 0xc0, 0x91, 0x15, 0x1a, 0xde, 0x6b, 0xef, 0x5e, 0xcc, 0x97, 0x54, + 0x0b, 0x5b, 0xa2, 0x2b, 0x40, 0x41, 0xa7, 0xd5, 0x90, 0xfc, 0x9b, 0x87, + 0xcc, 0x2d, 0xe6, 0xab, 0x2b, 0xbd, 0x40, 0x2d, 0x2a, 0x00, 0xe7, 0xb8, + 0x96, 0xa2, 0x97, 0xfa, 0x41, 0xf9, 0x70, 0xf3, 0x4e, 0xcb, 0xc0, 0x96, + 0x15, 0x4a, 0x56, 0x72, 0x59, 0x82, 0xa3, 0xf8, 0x4c, 0xca, 0x92, 0xa2, + 0x19, 0x94, 0x5d, 0x4b, 0x3f, 0x8a, 0xaa, 0x14, 0x62, 0x82, 0xf9, 0x8b, + 0xf1, 0x94, 0x9c, 0xe0, 0xd3, 0x8b, 0x7e, 0x78, 0x0b, 0x19, 0xb4, 0x6e, + 0xc6, 0x87, 0xc4, 0xce, 0xe1, 0x53, 0x04, 0xea, 0xdf, 0x9d, 0x00, 0x92, + 0x44, 0x2f, 0x05, 0xdd, 0xe5, 0xbb, 0x67, 0xe6, 0xad, 0x17, 0x6d, 0x64, + 0x60, 0x1e, 0x91, 0x63, 0x9e, 0x8c, 0xe1, 0x78, 0x64, 0xd1, 0x69, 0x54, + 0xc9, 0xcf, 0xdb, 0xb7, 0xbd, 0xa8, 0x90, 0x90, 0x4c, 0x86, 0xf3, 0x90, + 0x2d, 0x68, 0x26, 0x29, 0x3e, 0x5b, 0x16, 0xe9, 0xbc, 0xa2, 0xaf, 0x18, + 0xf7, 0x55, 0xc1, 0xbb, 0xc6, 0x8c, 0xc8, 0x15, 0xdf, 0x80, 0x99, 0xaf, + 0x2d, 0x27, 0xa8, 0xf4, 0x10, 0x72, 0x7a, 0x95, 0x33, 0x5a, 0x4e, 0x06, + 0x31, 0x9e, 0x7e, 0xd8, 0x30, 0x3f, 0xcc, 0x2e, 0x46, 0x00, 0x4e, 0xac, + 0x02, 0xb8, 0xaf, 0x48, 0x6f, 0x87, 0xd1, 0x7c, 0x35, 0x88, 0x7f, 0xbb, + 0xf6, 0x15, 0x23, 0xcd, 0x04, 0xfa, 0x87, 0x21, 0x5a, 0x8c, 0x9a, 0x73, + 0x41, 0x4b, 0xdf, 0xd8, 0x49, 0xa9, 0xac, 0x0d, 0x34, 0xb5, 0xd9, 0x37, + 0x01, 0x9b, 0x90, 0xea, 0xb7, 0x4f, 0x7a, 0x7f, 0x73, 0x95, 0x4d, 0x2f, + 0x08, 0xca, 0x65, 0x2a, 0x06, 0x8a, 0x7b, 0x29, 0x65, 0x35, 0xb9, 0xb7, + 0x33, 0x78, 0x1b, 0xdb, 0x7d, 0xb4, 0xb9, 0xac, 0x8d, 0x72, 0x98, 0xa9, + 0x37, 0x1b, 0x10, 0x1a, 0x4c, 0xc4, 0xb5, 0x81, 0x0a, 0xdf, 0x5a, 0x79, + 0xde, 0x45, 0x89, 0xd5, 0x60, 0x04, 0xa9, 0xdc, 0x6a, 0x2c, 0xea, 0x51, + 0x5b, 0x06, 0xe8, 0xa9, 0xc7, 0x36, 0x5c, 0x2d, 0x5f, 0x2d, 0x06, 0xf3, + 0x42, 0xbd, 0x6b, 0xe0, 0x1c, 0xcb, 0x26, 0x7f, 0xce, 0x8f, 0x87, 0x71, + 0xe6, 0xb4, 0x7b, 0xc6, 0x37, 0xc7, 0xbe, 0xc5, 0x71, 0x40, 0xe4, 0xa0, + 0x66, 0x19, 0xab, 0x6f, 0x14, 0xd7, 0x47, 0x52, 0xbb, 0x25, 0x98, 0x39, + 0xe4, 0x32, 0xdd, 0x9f, 0xd1, 0x4e, 0x43, 0x6a, 0x02, 0xb7, 0xb0, 0x40, + 0xf4, 0x18, 0x55, 0x7d, 0x04, 0xf5, 0xe5, 0xe1, 0x57, 0x6c, 0x07, 0x11, + 0x36, 0x7b, 0x81, 0x6f, 0xd4, 0x3a, 0xd3, 0x5b, 0x7e, 0x3d, 0x4b, 0x4b, + 0x29, 0x43, 0x6e, 0x88, 0xf6, 0xf7, 0xd6, 0x83, 0x85, 0x92, 0x4c, 0x27, + 0x7f, 0x5b, 0x7c, 0x7d, 0xe8, 0x22, 0x48, 0x5c, 0x8f, 0xab, 0xf8, 0xe8, + 0x90, 0xf5, 0x41, 0x0d, 0xda, 0xa4, 0x84, 0xf0, 0x76, 0x92, 0xc1, 0x5a, + 0xe0, 0x13, 0xca, 0x92, 0x89, 0xee, 0x14, 0x1e, 0x2e, 0x1d, 0x44, 0x8c, + 0x79, 0xf8, 0x4d, 0xa9, 0x3a, 0xa6, 0x24, 0x5f, 0x46, 0xc5, 0x79, 0x8d, + 0xf1, 0x09, 0xc4, 0xb2, 0xfc, 0x1e, 0x9d, 0xb4, 0x95, 0xdc, 0x02, 0x90, + 0xd5, 0x26, 0x63, 0x31, 0xf6, 0xcc, 0xbd, 0x9d, 0xf1, 0xa5, 0x53, 0x92, + 0xd7, 0x0e, 0x68, 0xa5, 0xa8, 0x00, 0x2c, 0x70, 0xf1, 0xe8, 0xf4, 0x9c, + 0xae, 0xe6, 0x4b, 0x05, 0xd4, 0xcf, 0xbc, 0xba, 0x78, 0x77, 0xba, 0xe9, + 0x67, 0x73, 0x5f, 0x12, 0x6a, 0xcc, 0x53, 0xe0, 0x30, 0x33, 0xc4, 0x5a, + 0x04, 0x4c, 0xb8, 0x85, 0x72, 0x86, 0x08, 0x09, 0x92, 0x09, 0xf1, 0xe3, + 0x15, 0x18, 0x3a, 0x9e, 0x4b, 0x84, 0x7b, 0x59, 0xce, 0xad, 0x3a, 0x1c, + 0xf5, 0x7c, 0x79, 0x1d, 0xe7, 0x4f, 0xf8, 0x58, 0xfc, 0x3a, 0xab, 0x04, + 0xd2, 0xa9, 0xcd, 0xd5, 0x95, 0x4c, 0x81, 0x4d, 0xe9, 0x65, 0x2c, 0x81, + 0x01, 0xd5, 0x99, 0xb1, 0x90, 0x02, 0x61, 0x80, 0x5d, 0xab, 0x9f, 0x4b, + 0x93, 0x32, 0x38, 0xb4, 0x6f, 0x16, 0x77, 0x26, 0xa9, 0x23, 0x2b, 0x1e, + 0x1f, 0x96, 0x6c, 0x36, 0x74, 0xf9, 0x9a, 0xcb, 0xe9, 0x31, 0x3e, 0xe2, + 0xbd, 0x1f, 0x62, 0xe6, 0xb2, 0xda, 0xee, 0x49, 0xfa, 0x25, 0x31, 0x21, + 0x90, 0x37, 0x56, 0x4e, 0x45, 0x28, 0x63, 0x1d, 0xa4, 0xee, 0x2f, 0xfa, + 0xab, 0x24, 0xdd, 0xb4, 0xb7, 0x7e, 0x53, 0xd4, 0xec, 0xfa, 0xd3, 0xa9, + 0x22, 0x7a, 0x91, 0x31, 0x32, 0xde, 0xcc, 0xf4, 0x29, 0x75, 0xa8, 0xa5, + 0x3e, 0x8a, 0x32, 0xb9, 0xb7, 0xeb, 0x03, 0x34, 0x87, 0xbc, 0x5b, 0xb4, + 0x48, 0xc3, 0x54, 0x2d, 0xad, 0x86, 0x05, 0x08, 0x4d, 0x31, 0xfc, 0x56, + 0x7a, 0x86, 0x37, 0xe0, 0x73, 0xce, 0x7a, 0xac, 0x4f, 0x3b, 0x46, 0x78, + 0x8d, 0xee, 0x97, 0x64, 0xd5, 0x4b, 0x73, 0x35, 0x49, 0xee, 0xc0, 0xc7, + 0x5c, 0x46, 0xcf, 0x19, 0xdd, 0xc9, 0x12, 0x98, 0x13, 0x68, 0xf2, 0x20, + 0x26, 0xbc, 0x52, 0x5f, 0x64, 0x1d, 0xfe, 0xad, 0x03, 0x5f, 0x39, 0x6d, + 0xe4, 0x43, 0x93, 0xaa, 0x70, 0xf1, 0x40, 0xb9, 0x59, 0x1b, 0x94, 0xba, + 0x15, 0x0e, 0x39, 0xf8, 0xb5, 0xc5, 0x21, 0x94, 0xb6, 0x9c, 0x09, 0x42, + 0x1c, 0x6a, 0x78, 0x76, 0x10, 0xee, 0x39, 0x5e, 0x0a, 0x16, 0x22, 0x41, + 0x6d, 0x37, 0x57, 0xa4, 0x72, 0x83, 0x8f, 0xff, 0xd2, 0x51, 0x2c, 0xc9, + 0x6e, 0xad, 0x80, 0xd7, 0xe9, 0x29, 0xa7, 0x96, 0x95, 0xfb, 0x52, 0xd5, + 0x41, 0xb9, 0x1a, 0x29, 0xb9, 0xc0, 0x00, 0x66, 0xae, 0x8a, 0x14, 0xb4, + 0x66, 0x16, 0x0c, 0x06, 0xb9, 0x19, 0x73, 0xc0, 0x85, 0x1d, 0x99, 0x26, + 0x06, 0x07, 0x63, 0x82, 0x40, 0x54, 0xbf, 0x76, 0x9f, 0xce, 0xa0, 0x87, + 0x7b, 0x86, 0x89, 0x57, 0x14, 0x47, 0xf9, 0xdd, 0xcb, 0x7d, 0x4c, 0x23, + 0x35, 0x94, 0x8c, 0xbc, 0xd3, 0x1f, 0xc3, 0xc9, 0xef, 0x9b, 0x62, 0x4e, + 0xb9, 0xc5, 0xfb, 0xe5, 0x77, 0x48, 0xdb, 0x78, 0xc4, 0xe4, 0xd7, 0x91, + 0x9d, 0x20, 0x1e, 0xea, 0xd1, 0x68, 0xa3, 0x74, 0xb8, 0xcd, 0x99, 0x47, + 0x9d, 0xd0, 0x3d, 0x46, 0x14, 0xa7, 0x29, 0xa2, 0xf8, 0x34, 0xf2, 0x8c, + 0xad, 0xda, 0xa8, 0x52, 0x89, 0xb6, 0xa1, 0x5b, 0x64, 0x55, 0xec, 0x5b, + 0xb5, 0x1e, 0x7b, 0x34, 0xe8, 0x24, 0xe0, 0x38, 0x56, 0x1a, 0x22, 0x71, + 0x8d, 0x60, 0x6d, 0x67, 0xbb, 0x6d, 0x11, 0xa2, 0x9d, 0x28, 0x82, 0x3d, + 0x24, 0x21, 0xf9, 0x02, 0x78, 0x00, 0x53, 0x11, 0xf5, 0x65, 0xcb, 0x0e, + 0x78, 0x64, 0x23, 0x50, 0xe8, 0x6b, 0xbc, 0x8f, 0xc7, 0xff, 0xd0, 0xad, + 0x0c, 0x7e, 0x84, 0x21, 0xce, 0x69, 0x8c, 0xf1, 0x29, 0x1f, 0x01, 0x52, + 0x2b, 0x45, 0x5c, 0x3a, 0xa3, 0x00, 0xba, 0x3f, 0xae, 0xec, 0x2d, 0xb3, + 0x25, 0x81, 0x04, 0x44, 0x77, 0xcc, 0xf6, 0x4f, 0x93, 0x88, 0x5f, 0xef, + 0xbc, 0x31, 0x85, 0xb3, 0xdb, 0xe6, 0x89, 0x63, 0x7c, 0xd1, 0xc2, 0xe3, + 0x8e, 0x14, 0x8a, 0xa3, 0x2f, 0x8e, 0x7b, 0xd8, 0xcb, 0xf3, 0x28, 0x0c, + 0x86, 0x1b, 0x94, 0xdb, 0xc6, 0x2b, 0xa0, 0xce, 0x79, 0xae, 0x2e, 0x94, + 0xb4, 0xc5, 0xda, 0x22, 0x02, 0x52, 0x00, 0x9f, 0xad, 0xad, 0xb6, 0x2d, + 0x50, 0x98, 0xa8, 0x85, 0xea, 0xa3, 0xba, 0x5f, 0xa8, 0xde, 0x20, 0xe8, + 0x81, 0x4d, 0x79, 0x5d, 0x87, 0x93, 0x0c, 0x9f, 0x39, 0xb5, 0x11, 0xf4, + 0x47, 0xc5, 0x5b, 0xd8, 0x79, 0x55, 0x7b, 0x49, 0x88, 0x47, 0x86, 0x92, + 0x0d, 0x37, 0xbb, 0x05, 0xe7, 0xc1, 0xbb, 0x3e, 0x84, 0x76, 0xef, 0x64, + 0xea, 0xa2, 0xed, 0xa3, 0x9f, 0x10, 0xa8, 0x94, 0x56, 0x83, 0x1a, 0x77, + 0xa9, 0xb7, 0xa9, 0xa4, 0x09, 0x31, 0x7b, 0xae, 0x03, 0x13, 0xb5, 0xbc, + 0x6e, 0xe4, 0x0a, 0x5b, 0xeb, 0xbb, 0x4f, 0x96, 0x6e, 0xed, 0x75, 0xbc, + 0xc3, 0xa5, 0x33, 0x9c, 0x23, 0xa8, 0x19, 0xa9, 0x35, 0x6d, 0x44, 0xbd, + 0x45, 0x59, 0xcc, 0x3e, 0xa1, 0xb1, 0x08, 0x8d, 0x94, 0x19, 0x11, 0x89, + 0x37, 0xc4, 0xea, 0x2f, 0x53, 0xa0, 0x8f, 0x0c, 0x3c, 0x07, 0x01, 0xc6, + 0x1c, 0x0e, 0x61, 0x0d, 0x61, 0x18, 0xba, 0x03, 0x26, 0xa8, 0x89, 0x7a, + 0xfb, 0x19, 0x6c, 0xb4, 0xdb, 0xd1, 0xc8, 0xa0, 0xf2, 0x07, 0xe1, 0xfd, + 0xb9, 0x9b, 0x3a, 0x58, 0x4c, 0xbc, 0xca, 0xc5, 0x0b, 0x02, 0x56, 0x61, + 0x6e, 0x34, 0x24, 0x46, 0x35, 0xac, 0x2d, 0xcf, 0x71, 0xfd, 0x07, 0xfe, + 0xf7, 0x56, 0xe8, 0x45, 0x7a, 0xe8, 0x90, 0x66, 0xbc, 0x1d, 0x18, 0xa1, + 0xff, 0x45, 0xb9, 0xde, 0x05, 0x7d, 0x70, 0xb4, 0xb7, 0x87, 0x63, 0x02, + 0xd8, 0x9f, 0x4b, 0xf9, 0xe7, 0x41, 0xab, 0xb5, 0xe0, 0x2d, 0x9b, 0x39, + 0x2f, 0x1a, 0xab, 0x50, 0x9b, 0x8c, 0x9b, 0x8c, 0xad, 0xeb, 0xa2, 0x69, + 0x1b, 0xd5, 0x00, 0xe8, 0x93, 0x84, 0x5a, 0xc2, 0xab, 0xde, 0xa1, 0xf5, + 0x61, 0x4e, 0x40, 0xc2, 0x3c, 0xc7, 0xcf, 0xc0, 0x60, 0x63, 0x6d, 0x56, + 0xf6, 0x41, 0x0e, 0x39, 0x40, 0x6a, 0x1a, 0x7b, 0x7c, 0x8f, 0xaf, 0x54, + 0x1c, 0x6b, 0x56, 0xa3, 0xf9, 0x9f, 0xbc, 0xcd, 0xfe, 0x25, 0x68, 0xd6, + 0x84, 0x3c, 0x85, 0xd4, 0x54, 0xa0, 0x23, 0x9f, 0x58, 0x23, 0x9c, 0xca, + 0x5b, 0x67, 0x55, 0x2c, 0x66, 0xce, 0x64, 0xaf, 0x27, 0x93, 0xe3, 0xfc, + 0x79, 0x04, 0x2c, 0x98, 0x3d, 0x7d, 0xba, 0xf2, 0xb4, 0xea, 0x3e, 0x65, + 0xe1, 0x57, 0x35, 0x89, 0xfb, 0xf1, 0x8a, 0xaa, 0x80, 0x80, 0xaa, 0x4f, + 0x7e, 0xb8, 0xb0, 0x01, 0x39, 0x63, 0x48, 0x17, 0xb4, 0x56, 0xb7, 0xe0, + 0xd2, 0x5e, 0x73, 0x56, 0x27, 0x46, 0xc0, 0xde, 0xc3, 0x18, 0x40, 0x90, + 0xd0, 0xa1, 0x4b, 0x8c, 0xc3, 0xa5, 0x1b, 0xdf, 0x43, 0xde, 0x2d, 0x45, + 0x91, 0x1f, 0xc9, 0x1d, 0xf6, 0xef, 0xab, 0xeb, 0x74, 0x9c, 0xb3, 0x4e, + 0x2a, 0x50, 0xf6, 0xae, 0x9a, 0x80, 0xa0, 0x1d, 0x6d, 0x5c, 0xd8, 0xcc, + 0x31, 0x16, 0x76, 0x16, 0xc6, 0xf2, 0x48, 0xf1, 0xcc, 0x43, 0xea, 0x55, + 0xec, 0x0d, 0x00, 0xd9, 0xda, 0xa6, 0xb7, 0x50, 0xb7, 0x12, 0xf6, 0x8a, + 0x7a, 0x6e, 0xe9, 0x5b, 0x3b, 0x96, 0x3b, 0x28, 0xf9, 0x85, 0x01, 0x2e, + 0x10, 0x19, 0xa9, 0x87, 0x50, 0x04, 0x04, 0x16, 0xcf, 0x53, 0x2d, 0x74, + 0x33, 0x9f, 0x6c, 0x34, 0x3f, 0x42, 0xf3, 0xa1, 0xe3, 0x59, 0x9d, 0xaf, + 0x63, 0x5e, 0x86, 0xc8, 0xbc, 0x35, 0x3f, 0xc2, 0x8f, 0x25, 0x25, 0x87, + 0x8e, 0x19, 0x7e, 0x8f, 0xef, 0xe8, 0xc9, 0xb7, 0x1d, 0x19, 0x6a, 0x5b, + 0x3f, 0xb5, 0x0f, 0x41, 0x9b, 0x0f, 0x89, 0x5e, 0xcf, 0x89, 0xf1, 0x24, + 0x79, 0xa6, 0x97, 0xa0, 0x60, 0xa0, 0xd6, 0xaf, 0xc2, 0x02, 0x34, 0xa1, + 0xa2, 0x3b, 0xbd, 0xe5, 0xee, 0x3f, 0x28, 0x3e, 0x10, 0x8a, 0x73, 0xe5, + 0xb8, 0x31, 0x2e, 0xdf, 0xfe, 0x78, 0x70, 0x62, 0x79, 0x38, 0x7f, 0xf7, + 0x0e, 0xd1, 0x69, 0xe6, 0x7d, 0x2a, 0x2f, 0xfe, 0xc4, 0xaa, 0xc4, 0xcd, + 0x67, 0x52, 0xc9, 0x34, 0xf7, 0xf8, 0x07, 0xf4, 0x72, 0x5d, 0x47, 0x97, + 0x41, 0x44, 0x99, 0xb3, 0xa3, 0xda, 0x3c, 0x3a, 0x2b, 0xfb, 0x1a, 0xbb, + 0xdf, 0x3c, 0x86, 0x36, 0x68, 0x1c, 0xe5, 0x21, 0x1d, 0xd7, 0x7b, 0x2c, + 0x7e, 0xa5, 0xb2, 0xc8, 0x91, 0x04, 0xa5, 0xd8, 0x4d, 0xd7, 0x5b, 0xa9, + 0x1b, 0xae, 0x20, 0xa9, 0x0f, 0xde, 0x62, 0x6f, 0x7b, 0xfd, 0xc0, 0xb6, + 0xb9, 0x94, 0x1e, 0x62, 0xd0, 0x11, 0x1b, 0x7e, 0xfe, 0xd2, 0x82, 0xcd, + 0xf3, 0x47, 0xde, 0x8c, 0x50, 0x74, 0x9c, 0xda, 0x09, 0xb0, 0x4e, 0x3f, + 0x8f, 0xf5, 0x5f, 0x26, 0x0b, 0x71, 0x0b, 0xe3, 0xe6, 0x5b, 0x2d, 0xaf, + 0x82, 0xed, 0x2c, 0x28, 0xc5, 0x4e, 0xdd, 0xa0, 0xbb, 0xab, 0x8f, 0x0e, + 0xfd, 0x3b, 0xa2, 0xc5, 0xe5, 0x1f, 0x2d, 0x5f, 0x55, 0x8e, 0x0e, 0x99, + 0xaf, 0x08, 0x78, 0xa5, 0x2c, 0x11, 0x17, 0x5e, 0x54, 0x3a, 0x9e, 0xa3, + 0x37, 0x50, 0xb8, 0xa3, 0xec, 0x27, 0x68, 0x03, 0xab, 0x3e, 0x6a, 0x23, + 0x35, 0x3b, 0x24, 0xe3, 0xa2, 0x0a, 0xc4, 0x2d, 0x05, 0xa1, 0x8f, 0xee, + 0xc1, 0x41, 0xe0, 0x3d, 0x54, 0xd2, 0xe8, 0x63, 0xf8, 0xa2, 0xa8, 0x85, + 0xfc, 0xbc, 0x3d, 0x1d, 0x7d, 0xc5, 0xe1, 0x65, 0x78, 0xd8, 0x5f, 0xb0, + 0x49, 0xf3, 0x37, 0x78, 0x37, 0xe9, 0x3b, 0x70, 0x6b, 0xd3, 0xfc, 0x0b, + 0x6c, 0x68, 0x9a, 0xa2, 0x86, 0xcf, 0xae, 0xaa, 0xec, 0x92, 0xf5, 0xec, + 0x2f, 0xe2, 0x0f, 0x66, 0x43, 0xce, 0xbc, 0xc9, 0x08, 0x86, 0x8b, 0xc5, + 0x2d, 0x9d, 0x1f, 0x7b, 0xe1, 0x51, 0xb9, 0xca, 0x45, 0x92, 0xb0, 0x39, + 0x49, 0x75, 0x79, 0x0a, 0x03, 0xf8, 0xa1, 0x1f, 0x1e, 0x2d, 0x1b, 0xee, + 0x69, 0x06, 0xe1, 0x4d, 0x84, 0x0b, 0x23, 0x61, 0x98, 0xcb, 0x63, 0x09, + 0x2f, 0x1d, 0xe9, 0x53, 0x36, 0xf1, 0x92, 0x5d, 0xe5, 0x96, 0x49, 0x1f, + 0xfb, 0xb4, 0x31, 0xb4, 0x26, 0x46, 0x1f, 0x1f, 0xf9, 0x91, 0x0b, 0xf3, + 0x1d, 0x7c, 0x03, 0x2d, 0x9a, 0xaf, 0x5a, 0xc0, 0xd8, 0xc5, 0x43, 0x17, + 0x8d, 0xd0, 0x63, 0xa7, 0x0c, 0xcb, 0x40, 0x39, 0xf6, 0xae, 0x25, 0xf1, + 0xe2, 0xfa, 0x19, 0xff, 0x79, 0x78, 0xd6, 0xe2, 0x16, 0x49, 0xcf, 0x44, + 0xb9, 0x4a, 0xbb, 0x3e, 0xd0, 0x33, 0x3a, 0xc7, 0xdb, 0x82, 0x2c, 0xe3, + 0xcf, 0x03, 0x92, 0x13, 0x1d, 0x23, 0x3d, 0xe2, 0xe3, 0x52, 0x7a, 0x2e, + 0xd2, 0x94, 0xe2, 0x48, 0xa0, 0xf3, 0xef, 0x5a, 0x1f, 0xd1, 0xa8, 0xee, + 0xa2, 0x32, 0x78, 0xd2, 0x04, 0x59, 0xaf, 0xf2, 0x58, 0xab, 0x90, 0xbd, + 0x1f, 0x3f, 0xa2, 0x3f, 0xc8, 0x96, 0xb8, 0x00, 0x5a, 0xb7, 0xcb, 0xd5, + 0x39, 0xc4, 0xcd, 0x3e, 0x8c, 0x49, 0x73, 0x72, 0x19, 0x7c, 0xc2, 0xd4, + 0x17, 0xb9, 0x79, 0xa0, 0xf5, 0x77, 0x90, 0x14, 0xa6, 0xcf, 0x59, 0x3c, + 0xbf, 0xf8, 0x38, 0xe7, 0xf2, 0x8a, 0x8d, 0x7c, 0xd8, 0x21, 0x95, 0x9f, + 0xa6, 0x10, 0xd7, 0x54, 0x26, 0xa4, 0xdf, 0xde, 0xa4, 0x04, 0xb5, 0xf0, + 0x3c, 0x3c, 0x2a, 0x63, 0xfd, 0x15, 0xff, 0x06, 0x8a, 0x59, 0x5c, 0x12, + 0xba, 0x07, 0x3d, 0xb2, 0x4e, 0xcb, 0xdd, 0xee, 0xa9, 0xd8, 0x92, 0x1c, + 0x75, 0x5e, 0x85, 0xf1, 0x31, 0xcc, 0xea, 0x7d, 0x63, 0x6a, 0xb4, 0x2d, + 0x41, 0x12, 0x63, 0x19, 0x06, 0xa2, 0x0e, 0xab, 0xb2, 0xd9, 0x2c, 0x84, + 0x54, 0xdd, 0xb6, 0xe0, 0xdc, 0x0c, 0x8f, 0xab, 0x33, 0x81, 0xda, 0x39, + 0x36, 0x38, 0x0b, 0x6a, 0x7b, 0x77, 0x38, 0x03, 0xe9, 0x05, 0x89, 0x03, + 0x9e, 0xbf, 0x5f, 0xe1, 0xe2, 0x2c, 0x57, 0x08, 0xdd, 0xef, 0x6f, 0x52, + 0x42, 0xa7, 0x2a, 0x3a, 0xea, 0xe1, 0x78, 0x36, 0xb7, 0x48, 0xab, 0xd3, + 0xfd, 0xf7, 0x93, 0x53, 0xac, 0x31, 0x3c, 0x1e, 0xb2, 0xc3, 0xa9, 0x97, + 0xa2, 0x86, 0x0e, 0x2b, 0x73, 0x44, 0x09, 0xd2, 0xd0, 0x6e, 0x77, 0x38, + 0x1f, 0x5f, 0xa4, 0x0e, 0x3e, 0x34, 0x67, 0x70, 0x4c, 0x2c, 0xb6, 0x46, + 0xe7, 0x1c, 0x2f, 0x8b, 0x4e, 0x33, 0xb5, 0xf1, 0x15, 0x16, 0x7d, 0x8c, + 0xfd, 0xdb, 0x27, 0x04, 0xd8, 0xf3, 0xb9, 0x27, 0x36, 0xa8, 0x74, 0x2f, + 0x66, 0xc6, 0x7e, 0xa5, 0xa2, 0xde, 0xb2, 0x0d, 0x2b, 0xb7, 0xbc, 0xf3, + 0x50, 0xb8, 0xf6, 0x9b, 0x66, 0xed, 0xe1, 0x1b, 0x4c, 0x8a, 0xb9, 0xe1, + 0xb2, 0xc1, 0xec, 0x4b, 0x5a, 0x3a, 0x93, 0x75, 0xf5, 0xee, 0xf7, 0x1b, + 0xf1, 0xd2, 0x6f, 0x39, 0xf1, 0xb5, 0x04, 0xc3, 0x4d, 0x26, 0x68, 0x47, + 0xc2, 0x29, 0xda, 0x98, 0x8f, 0x0a, 0xc6, 0xaf, 0x26, 0x9f, 0x03, 0x44, + 0x66, 0x80, 0x3d, 0x59, 0x09, 0x2b, 0x27, 0xd7, 0x12, 0x59, 0xf6, 0xa3, + 0x2d, 0xc4, 0xb7, 0xed, 0x52, 0xef, 0x38, 0xd3, 0x93, 0x42, 0x08, 0x0f, + 0x69, 0x08, 0xbd, 0xa2, 0xf8, 0x3e, 0x72, 0x9d, 0xf8, 0x89, 0xba, 0xca, + 0x03, 0x74, 0xf5, 0x75, 0xd3, 0x6b, 0xe7, 0x25, 0x44, 0x5e, 0xed, 0xcc, + 0x51, 0xb0, 0x81, 0x59, 0xe1, 0xd5, 0x04, 0x3e, 0xcc, 0x96, 0x70, 0x7c, + 0x86, 0xf8, 0x05, 0x7d, 0x21, 0x08, 0xa3, 0x76, 0xc0, 0x1a, 0xdc, 0x48, + 0x85, 0x89, 0xcb, 0xe0, 0x2a, 0xfe, 0x7f, 0x12, 0xba, 0xe2, 0x9e, 0x5c, + 0x86, 0x62, 0x87, 0xbf, 0x33, 0xd0, 0x1a, 0xa2, 0x1a, 0x38, 0xd5, 0x5f, + 0xe3, 0xd4, 0x5a, 0x62, 0x01, 0x52, 0x08, 0x5a, 0x3c, 0xe0, 0x5a, 0xfe, + 0xc3, 0x03, 0x91, 0xc2, 0x2c, 0xc5, 0xf9, 0x47, 0xe6, 0x8d, 0x92, 0x08, + 0x22, 0x2f, 0xc8, 0x32, 0x1d, 0x26, 0x5d, 0x75, 0x9b, 0x50, 0xc0, 0x7c, + 0xf8, 0x61, 0xde, 0xa7, 0x1c, 0xc0, 0x3c, 0x77, 0xd0, 0xf1, 0xd0, 0xf7, + 0x42, 0xef, 0x09, 0xf4, 0x5d, 0x0f, 0x9a, 0x1e, 0x21, 0xa2, 0xd6, 0xb0, + 0x0c, 0xea, 0x50, 0x35, 0x28, 0x69, 0xe0, 0xb0, 0x03, 0x12, 0x7a, 0x34, + 0x00, 0x73, 0x07, 0x06, 0x18, 0x6f, 0x65, 0xaa, 0xbe, 0x0d, 0xc3, 0x9d, + 0x7f, 0x30, 0xcc, 0x9a, 0x71, 0x1f, 0x38, 0x65, 0x1d, 0xc8, 0xd0, 0x26, + 0xa0, 0xce, 0x40, 0x73, 0x36, 0x63, 0xe5, 0x3b, 0x94, 0x8e, 0xaf, 0xe0, + 0xfb, 0xbe, 0x31, 0x1d, 0x40, 0x02, 0xe3, 0xd2, 0xdd, 0x3b, 0xe2, 0x06, + 0x13, 0xb1, 0x42, 0x85, 0x56, 0x1a, 0x16, 0x30, 0x4c, 0xe7, 0x7a, 0xcc, + 0xa7, 0xe1, 0x93, 0x7a, 0x09, 0x96, 0xf5, 0xbf, 0xf0, 0x54, 0x3f, 0xe3, + 0xa4, 0x44, 0xdb, 0xe6, 0xdb, 0x0f, 0xbb, 0x3a, 0xe3, 0x69, 0x6e, 0xee, + 0x22, 0x7c, 0x73, 0xd0, 0xc1, 0x54, 0xba, 0x3e, 0xa6, 0x69, 0x56, 0xaa, + 0x1b, 0xaa, 0x14, 0xa7, 0x27, 0x1f, 0x0f, 0xf2, 0xe8, 0x98, 0xac, 0x66, + 0x7d, 0x07, 0x8c, 0x8a, 0xde, 0x0d, 0x32, 0x09, 0xbf, 0xd5, 0x5a, 0x4f, + 0x3f, 0xbb, 0xce, 0x60, 0x95, 0xf4, 0x1f, 0x9d, 0xac, 0xd5, 0x5a, 0xb6, + 0x8e, 0x76, 0x49, 0xac, 0xc5, 0x16, 0x82, 0x5a, 0xc1, 0xae, 0xa8, 0xa8, + 0x32, 0xc3, 0xf6, 0x86, 0x74, 0x48, 0xcd, 0x3b, 0x48, 0x32, 0x62, 0x41, + 0x1a, 0xe0, 0xf0, 0x8d, 0x51, 0x53, 0x45, 0xa8, 0xcf, 0x6a, 0xb2, 0xad, + 0xd3, 0x23, 0xb4, 0x53, 0x42, 0xfe, 0xae, 0x95, 0x64, 0x2f, 0x5b, 0x25, + 0x2d, 0x91, 0x65, 0x48, 0xa9, 0xca, 0x71, 0x5f, 0x4d, 0xdd, 0xb2, 0x33, + 0xac, 0xbf, 0xd9, 0x53, 0x2e, 0xcd, 0x5c, 0xf8, 0xd8, 0xb4, 0x96, 0xd2, + 0x37, 0x68, 0x38, 0xdc, 0x53, 0x22, 0x1e, 0x33, 0xf8, 0x17, 0xc7, 0xfc, + 0x36, 0x65, 0xf5, 0x3f, 0x89, 0xb5, 0x1d, 0xcf, 0x97, 0x79, 0xea, 0x9e, + 0x03, 0x8c, 0x13, 0x94, 0x9b, 0xdc, 0x39, 0xa9, 0xbd, 0x37, 0xb3, 0x9e, + 0xd2, 0x09, 0x12, 0x1c, 0x0b, 0x30, 0xd2, 0xe0, 0xe2, 0x50, 0xa8, 0x1c, + 0x9f, 0x8c, 0x36, 0xee, 0xed, 0x85, 0x80, 0xb5, 0x98, 0x7f, 0x00, 0x88, + 0xe2, 0xf8, 0xa9, 0xe5, 0xbe, 0xac, 0x44, 0xf1, 0x63, 0xb8, 0x24, 0x25, + 0x53, 0x6e, 0x85, 0x05, 0x9f, 0x03, 0xa1, 0x24, 0x70, 0x56, 0x40, 0xd8, + 0xfe, 0xce, 0xcb, 0xc2, 0x4d, 0x6e, 0x5c, 0x29, 0xe8, 0xae, 0x40, 0x48, + 0x56, 0xe1, 0xdd, 0xad, 0xae, 0x7a, 0x68, 0xe4, 0x4e, 0x17, 0x6f, 0xcb, + 0x24, 0x7f, 0x67, 0x3f, 0x11, 0xcf, 0x75, 0x71, 0x29, 0x38, 0xa4, 0x35, + 0x4f, 0xd1, 0x39, 0x21, 0x9a, 0xe1, 0x54, 0x2a, 0xa5, 0x1d, 0xf6, 0x58, + 0x85, 0xec, 0xa2, 0x43, 0x14, 0xc9, 0x00, 0x78, 0x16, 0x13, 0x65, 0x3e, + 0x3a, 0x13, 0x2e, 0xb5, 0x61, 0xa1, 0x1b, 0xd6, 0x60, 0x2b, 0x38, 0x64, + 0x7b, 0x1c, 0x19, 0xb1, 0x79, 0x8c, 0x12, 0x02, 0xb3, 0x13, 0xb8, 0x2f, + 0x2e, 0xeb, 0xd3, 0x59, 0xdf, 0xf2, 0x15, 0xa4, 0xb9, 0x34, 0x06, 0xde, + 0xad, 0xc1, 0xfc, 0xc1, 0xf4, 0x95, 0xba, 0xef, 0xe8, 0x07, 0x1a, 0xe4, + 0x59, 0xa2, 0xec, 0x16, 0xab, 0x2c, 0x63, 0x91, 0xb6, 0xee, 0x06, 0xa4, + 0x06, 0xca, 0x27, 0xe5, 0x27, 0x0a, 0x0d, 0x95, 0x2a, 0xb3, 0x30, 0x87, + 0x60, 0xa6, 0x50, 0x01, 0x57, 0xb8, 0x55, 0x42, 0x27, 0xe4, 0x47, 0xac, + 0x63, 0x61, 0xb2, 0xdd, 0x77, 0x8c, 0x5a, 0x6d, 0x42, 0x02, 0xd1, 0xfd, + 0x5d, 0xc5, 0x47, 0xd1, 0x4d, 0x08, 0x10, 0xe3, 0x27, 0xe1, 0xee, 0x54, + 0x14, 0x0c, 0x5e, 0xbf, 0x64, 0x68, 0xcf, 0xcb, 0x67, 0x85, 0x4c, 0x42, + 0x9b, 0xc6, 0x80, 0x66, 0xca, 0x78, 0x7c, 0x5a, 0x50, 0x3d, 0xc5, 0x32, + 0x10, 0x96, 0x6d, 0x77, 0x06, 0x78, 0xef, 0xad, 0x5c, 0xfd, 0x06, 0xa7, + 0x07, 0x1f, 0xac, 0x64, 0xe9, 0xdc, 0x24, 0x85, 0x35, 0x54, 0xc2, 0x7d, + 0x4e, 0xa5, 0xbe, 0xf2, 0x4f, 0xde, 0x52, 0xaa, 0x25, 0xad, 0x7a, 0x8f, + 0xea, 0xd1, 0x32, 0xa9, 0x09, 0xc8, 0xb9, 0x9c, 0x9b, 0xf1, 0x3b, 0x72, + 0x7a, 0x74, 0xbd, 0x2c, 0x8e, 0xf1, 0xa0, 0xee, 0xa7, 0xee, 0xe3, 0xc9, + 0x53, 0x86, 0x07, 0x22, 0x27, 0xeb, 0xfc, 0x2f, 0xa9, 0xcc, 0x1f, 0x05, + 0x6a, 0xad, 0xbe, 0x3e, 0xe3, 0x3b, 0xef, 0x00, 0x36, 0xec, 0xa0, 0x46, + 0xaa, 0xf5, 0xd5, 0xe1, 0x85, 0x4a, 0xca, 0xeb, 0xf9, 0x8f, 0x84, 0x78, + 0xcd, 0xcc, 0x25, 0x26, 0x2c, 0x04, 0x84, 0xa3, 0xd4, 0xc3, 0x49, 0xfc, + 0x55, 0xe8, 0xae, 0x2a, 0x09, 0xd1, 0x86, 0xed, 0xc9, 0xfb, 0x6c, 0x32, + 0x2f, 0x48, 0x37, 0x12, 0xc2, 0x83, 0xf5, 0x3f, 0x40, 0xf8, 0x33, 0xf0, + 0x67, 0x7f, 0x10, 0xbc, 0x0d, 0x2b, 0xe1, 0x4f, 0x47, 0xe4, 0xf8, 0x22, + 0x97, 0xbb, 0x33, 0xde, 0x23, 0xb2, 0xe2, 0xeb, 0xd8, 0x90, 0xff, 0xb5, + 0xc9, 0xc8, 0x59, 0x50, 0xce, 0x1d, 0x7a, 0x43, 0x1b, 0x3b, 0x5a, 0x0c, + 0x03, 0xa9, 0xa7, 0xed, 0x44, 0x11, 0xfd, 0x21, 0xba, 0x8b, 0x32, 0x2b, + 0x0a, 0xfc, 0xfa, 0xec, 0x5a, 0xff, 0xa2, 0x7b, 0x91, 0x23, 0x1b, 0xe6, + 0x76, 0x22, 0x9c, 0x26, 0x4c, 0x43, 0xbc, 0x1b, 0xd0, 0xc4, 0xc5, 0x2a, + 0xd0, 0x01, 0x0b, 0xd9, 0x75, 0xd6, 0x41, 0x12, 0xc8, 0x59, 0xdc, 0x6f, + 0x73, 0x15, 0x5b, 0x57, 0xc5, 0x56, 0x03, 0x7c, 0x8a, 0x21, 0x40, 0x1e, + 0xc8, 0x63, 0x4e, 0x39, 0x08, 0x39, 0x03, 0x45, 0xae, 0x14, 0xaf, 0xd1, + 0xd9, 0x2c, 0xb1, 0x35, 0x08, 0xd5, 0x45, 0xec, 0xad, 0x7c, 0x2c, 0x4f, + 0x65, 0x25, 0x60, 0x4c, 0x75, 0x64, 0x4f, 0x4c, 0xf2, 0x24, 0x2f, 0xfb, + 0xdf, 0xee, 0xef, 0x2b, 0x72, 0x3c, 0x87, 0xf6, 0x91, 0x4d, 0xe4, 0xe6, + 0xed, 0x31, 0x3f, 0xbd, 0xb3, 0x9d, 0x49, 0x3e, 0x3e, 0x5c, 0x24, 0x16, + 0x35, 0x7c, 0x2d, 0xf0, 0xbb, 0x5a, 0xfa, 0xc0, 0xeb, 0x38, 0x91, 0x0f, + 0x46, 0x3c, 0xc0, 0x86, 0xd6, 0x80, 0x14, 0xc3, 0xe8, 0x5b, 0x89, 0x8a, + 0xc8, 0x7f, 0xed, 0xce, 0x57, 0xef, 0x05, 0x6a, 0x87, 0x40, 0x0e, 0x95, + 0xab, 0x86, 0x71, 0x30, 0xcd, 0x17, 0x21, 0xb5, 0xf7, 0xdc, 0x5d, 0xe5, + 0x57, 0x01, 0x68, 0x43, 0xa5, 0x57, 0xd5, 0x1a, 0xac, 0xf1, 0x9e, 0xf3, + 0x0a, 0x7a, 0x03, 0xcf, 0x74, 0x21, 0xea, 0x6f, 0xc9, 0x04, 0x08, 0xa1, + 0x7c, 0x30, 0x27, 0x28, 0xca, 0x4e, 0x5a, 0xb8, 0x51, 0x80, 0xee, 0xf9, + 0x8e, 0x04, 0x2f, 0x10, 0xdb, 0xb3, 0xf2, 0x4d, 0xf3, 0x1b, 0x00, 0x51, + 0x8d, 0xef, 0x20, 0x16, 0x56, 0xe7, 0xfc, 0xf3, 0x00, 0xf4, 0x4f, 0xab, + 0xed, 0x58, 0x25, 0x42, 0x5a, 0xb3, 0x8b, 0x3c, 0x64, 0xa1, 0x69, 0x0f, + 0x0c, 0x90, 0xfb, 0x7d, 0xf9, 0xc5, 0x88, 0x6c, 0xfb, 0x6c, 0x41, 0x3d, + 0x82, 0xd3, 0x35, 0x74, 0xcf, 0x5d, 0xb9, 0x98, 0x06, 0x52, 0xe2, 0xd2, + 0xfc, 0x8e, 0xf1, 0x78, 0x39, 0x3a, 0xf7, 0xd2, 0x20, 0xda, 0xd5, 0x9a, + 0x47, 0xcd, 0xed, 0xc7, 0x99, 0x03, 0xeb, 0xa3, 0x19, 0xd5, 0xa7, 0x68, + 0x26, 0x6e, 0x55, 0xb9, 0x99, 0x15, 0xc7, 0xc1, 0x8a, 0x13, 0xca, 0xb9, + 0x87, 0x4d, 0x02, 0x31, 0xee, 0x32, 0xa2, 0x7c, 0x5c, 0x6b, 0x38, 0x4b, + 0xe1, 0x64, 0xe8, 0x53, 0x9c, 0x39, 0xee, 0xd5, 0x18, 0xda, 0x22, 0xa3, + 0xf2, 0xb7, 0x50, 0xf1, 0x47, 0x6c, 0x93, 0xdd, 0xed, 0xb2, 0x6b, 0x10, + 0x6e, 0xec, 0xb9, 0x41, 0x19, 0x71, 0x41, 0x11, 0xad, 0xb3, 0x28, 0x0d, + 0xe7, 0x45, 0xa7, 0xa2, 0x0c, 0xc6, 0x85, 0x51, 0xe8, 0x1a, 0xe2, 0x54, + 0xc2, 0xeb, 0x83, 0xfa, 0x65, 0x5d, 0x3d, 0x42, 0x73, 0xdf, 0xcf, 0x2d, + 0xf8, 0xb0, 0x6f, 0x95, 0x0d, 0x8b, 0xca, 0x71, 0xa8, 0x58, 0xf0, 0x15, + 0x1d, 0x41, 0xe5, 0xcc, 0x9a, 0x7b, 0xf6, 0x38, 0x36, 0x39, 0x92, 0x1e, + 0x4d, 0xd4, 0xdd, 0xdb, 0x60, 0xbe, 0xa7, 0x77, 0x83, 0x2d, 0xa7, 0x23, + 0x03, 0xa3, 0x57, 0xec, 0xb6, 0xeb, 0x5f, 0x6c, 0x06, 0x41, 0x21, 0x05, + 0x91, 0x49, 0x01, 0xdd, 0x5d, 0x3d, 0x31, 0x19, 0x73, 0xaf, 0x47, 0x53, + 0xfb, 0xe0, 0xc7, 0xd0, 0xb9, 0xb4, 0xfd, 0x4c, 0xd6, 0x0b, 0x0f, 0xd7, + 0xc2, 0x2d, 0x9d, 0xe6, 0xbc, 0x9b, 0xc9, 0xd1, 0xe1, 0xd8, 0x39, 0xb4, + 0x43, 0x03, 0x53, 0x24, 0x6d, 0x01, 0xbb, 0xeb, 0x7b, 0x24, 0xeb, 0x73, + 0xd6, 0x9a, 0x79, 0xdb, 0xd8, 0x2a, 0x1c, 0x1a, 0x6f, 0x1d, 0x09, 0x8d, + 0xe2, 0xd0, 0x69, 0xa8, 0xa6, 0x9a, 0xcf, 0x9b, 0xdd, 0x11, 0xc8, 0x7e, + 0x1d, 0xaf, 0xd1, 0x42, 0x13, 0x26, 0xe1, 0x18, 0x14, 0x4f, 0x8c, 0x0a, + 0xad, 0x2e, 0x95, 0x1e, 0x1d, 0xa5, 0xa3, 0x62, 0xbe, 0x04, 0xff, 0x4e, + 0xc2, 0x6a, 0x7b, 0x41, 0x26, 0x85, 0x92, 0x38, 0xcf, 0x95, 0x80, 0xe7, + 0x47, 0xc6, 0xf1, 0xbb, 0xa3, 0xe6, 0x77, 0x62, 0x4e, 0x33, 0x42, 0xa9, + 0xe0, 0x21, 0xd0, 0x25, 0x47, 0x77, 0xfb, 0xcb, 0xf7, 0x46, 0x76, 0xff, + 0x18, 0x56, 0xce, 0x00, 0x94, 0x6d, 0x2d, 0x4f, 0x9f, 0x0a, 0x43, 0x8b, + 0x52, 0xad, 0x5e, 0x7f, 0x59, 0x46, 0x34, 0xf7, 0x79, 0x4b, 0x55, 0x48, + 0x76, 0xad, 0x60, 0x83, 0x4e, 0xd6, 0x45, 0xc6, 0xe9, 0x77, 0x71, 0x23, + 0xdc, 0xad, 0x87, 0x62, 0x94, 0x8a, 0xf3, 0xb4, 0xb8, 0xb4, 0x05, 0x90, + 0x3a, 0x83, 0xb8, 0xf1, 0x48, 0xcd, 0x75, 0x10, 0x87, 0xdb, 0xe1, 0x71, + 0xac, 0x4c, 0x1a, 0x1d, 0x4f, 0x66, 0x6f, 0xd1, 0xd1, 0x4c, 0x1e, 0xde, + 0x7d, 0x93, 0xbd, 0xfc, 0x80, 0xff, 0xe2, 0x72, 0xa3, 0xa8, 0x8d, 0xd9, + 0x74, 0x4d, 0xe7, 0xea, 0x72, 0x28, 0xab, 0xef, 0x96, 0xe4, 0x4b, 0xc5, + 0xe6, 0x5d, 0x31, 0xeb, 0x5d, 0xca, 0x79, 0xb6, 0xd5, 0xf8, 0x82, 0x7a, + 0xb1, 0xff, 0x1f, 0xcd, 0x16, 0x4b, 0x38, 0x6a, 0x39, 0x66, 0xf7, 0xcd, + 0xcf, 0x88, 0x6d, 0x00, 0x56, 0xa5, 0xff, 0x45, 0x24, 0x21, 0x1a, 0xa5, + 0xa6, 0xa4, 0xd7, 0xda, 0x7f, 0x95, 0xf5, 0x71, 0x48, 0x12, 0x45, 0x8d, + 0xb7, 0x98, 0x61, 0xed, 0x30, 0x7e, 0xbc, 0xe4, 0xd9, 0x44, 0x18, 0xd9, + 0xb2, 0x96, 0x8c, 0x44, 0x84, 0x41, 0x8b, 0xde, 0x83, 0xd8, 0x9b, 0x03, + 0xad, 0x63, 0xd6, 0xfa, 0x98, 0x98, 0x4e, 0x7c, 0x84, 0xf1, 0x90, 0xbe, + 0xd1, 0xb0, 0x6a, 0x3b, 0xbc, 0x04, 0x11, 0x4e, 0xbd, 0x24, 0x09, 0x12, + 0x5c, 0xbb, 0x54, 0xc6, 0xf5, 0x6f, 0xb5, 0xf3, 0x6c, 0x31, 0x2c, 0x74, + 0x50, 0x78, 0xcb, 0x7a, 0x64, 0xf6, 0xd3, 0x0d, 0xe3, 0x8a, 0x5d, 0x11, + 0xc7, 0xfa, 0x8f, 0x26, 0xf2, 0xad, 0x89, 0xf1, 0x77, 0xca, 0x7f, 0x2c, + 0xd8, 0xbb, 0xe2, 0x0e, 0xb9, 0xe2, 0xaf, 0x5d, 0x68, 0xbd, 0x01, 0x9f, + 0x54, 0x27, 0x68, 0xbf, 0xc6, 0x8d, 0xef, 0xf0, 0xfe, 0x5e, 0x5c, 0x6f, + 0xb6, 0x85, 0x06, 0x40, 0x25, 0x6f, 0x97, 0xf8, 0x3d, 0x65, 0xd4, 0x33, + 0x28, 0x25, 0xa3, 0x9f, 0xf3, 0xa0, 0xaf, 0x0e, 0x6c, 0xd3, 0xdb, 0x70, + 0x7e, 0xfe, 0x5f, 0x1c, 0xa0, 0xb0, 0x03, 0xa1, 0xb9, 0xb7, 0xfc, 0x7c, + 0x6a, 0x11, 0xde, 0xb8, 0xd6, 0x3e, 0x08, 0x41, 0x47, 0x34, 0x16, 0x21, + 0x17, 0xb7, 0x4b, 0xf0, 0x54, 0x31, 0xd0, 0xfc, 0x42, 0xe5, 0xde, 0x55, + 0xa2, 0x77, 0x47, 0xdb, 0x55, 0xab, 0xa0, 0xe4, 0x53, 0x50, 0x7a, 0xa8, + 0xe8, 0x66, 0xb1, 0x75, 0xd1, 0x09, 0x41, 0xbd, 0x7a, 0xb1, 0xe7, 0x6f, + 0x04, 0x0c, 0xe2, 0xd1, 0xcd, 0x8c, 0x1e, 0xd8, 0x7f, 0xff, 0xb9, 0x2c, + 0x3e, 0x3e, 0xaa, 0xb4, 0x96, 0x0f, 0xe9, 0xd7, 0x6e, 0x97, 0x26, 0x07, + 0x99, 0xea, 0xa7, 0x69, 0x91, 0xf9, 0xf4, 0x8f, 0x8a, 0x32, 0xee, 0x47, + 0x84, 0x3f, 0x1f, 0x5e, 0x07, 0x7e, 0xaf, 0x90, 0x7a, 0x2a, 0x22, 0x11, + 0xf1, 0xdf, 0x40, 0x0d, 0xef, 0xe8, 0x78, 0xeb, 0xb2, 0x4f, 0x9b, 0x3e, + 0x27, 0x42, 0x59, 0x3d, 0x78, 0x21, 0xda, 0x87, 0x60, 0x18, 0x76, 0x63, + 0x6d, 0x2d, 0x3d, 0x66, 0xf5, 0xb3, 0x57, 0xcc, 0x1e, 0xcb, 0x55, 0x1f, + 0xff, 0x64, 0xd4, 0x84, 0xb2, 0xc4, 0x30, 0xdb, 0x7c, 0x20, 0x9c, 0x9d, + 0x51, 0xdd, 0x7c, 0x5e, 0x24, 0x71, 0x17, 0x02, 0x6d, 0x89, 0x43, 0x93, + 0xbb, 0x60, 0x70, 0xee, 0xf7, 0x5f, 0x9b, 0x1e, 0xf6, 0x81, 0xa2, 0x2d, + 0xbc, 0xec, 0xe2, 0xe8, 0xfc, 0x6f, 0x11, 0x40, 0x30, 0x7a, 0xb7, 0x9f, + 0x74, 0x1d, 0x53, 0x0a, 0xe7, 0xbf, 0x6a, 0x9c, 0xf6, 0x26, 0xdb, 0x9e, + 0xc5, 0x57, 0x06, 0x15, 0x7d, 0xfe, 0xb6, 0x7f, 0xde, 0x06, 0xbe, 0x44, + 0x37, 0x96, 0x92, 0x48, 0xdb, 0x1f, 0xbd, 0x2c, 0x9b, 0xde, 0xd1, 0x99, + 0x74, 0xad, 0x08, 0x47, 0xd7, 0x22, 0x3b, 0x63, 0x07, 0x66, 0xc4, 0x39, + 0xdc, 0xe6, 0xd9, 0x0a, 0x46, 0x8c, 0x62, 0x14, 0xde, 0x88, 0xf3, 0x05, + 0x0a, 0x12, 0x14, 0xbe, 0x29, 0xb0, 0x46, 0x5c, 0x53, 0x1b, 0x08, 0x08, + 0x4c, 0x33, 0xde, 0xef, 0xb8, 0x31, 0xa7, 0x25, 0xda, 0xce, 0x53, 0x47, + 0xf6, 0x11, 0x3d, 0x9d, 0x67, 0x5f, 0x8c, 0x4c, 0xac, 0x43, 0x91, 0xa4, + 0xea, 0xfe, 0xa5, 0xd8, 0xea, 0x9d, 0xb5, 0xe5, 0xe7, 0xfb, 0xf5, 0x11, + 0x3e, 0x7d, 0xc5, 0x59, 0x73, 0xcc, 0xd1, 0xf8, 0x28, 0x48, 0x5f, 0x14, + 0x6b, 0x90, 0x76, 0xf2, 0xe5, 0xdf, 0xf0, 0xe4, 0xd7, 0x1c, 0x44, 0x3d, + 0xfd, 0x68, 0xa5, 0x1e, 0xe2, 0xd8, 0x7d, 0x2f, 0xde, 0xdb, 0x7c, 0xe5, + 0x29, 0xa8, 0xf3, 0x4c, 0xe3, 0x09, 0xec, 0x43, 0x36, 0x6d, 0x1a, 0xc8, + 0xdd, 0x8a, 0xd1, 0x49, 0xc3, 0x9b, 0xf7, 0x5a, 0x1e, 0x5f, 0xdf, 0x52, + 0x33, 0x60, 0x22, 0xac, 0x48, 0xec, 0xbb, 0x6f, 0xce, 0x15, 0xf6, 0x7e, + 0x3f, 0x22, 0x0e, 0xd6, 0x93, 0x4d, 0xa0, 0x99, 0x3c, 0x63, 0xda, 0x93, + 0x9f, 0xe0, 0x26, 0x79, 0xd2, 0x1b, 0xa8, 0x36, 0xe1, 0x13, 0x16, 0xfe, + 0x70, 0xd3, 0x86, 0x0b, 0xf5, 0xb5, 0x95, 0x7d, 0x34, 0xef, 0x34, 0x11, + 0x7d, 0x29, 0x65, 0x31, 0xbd, 0x5a, 0xe1, 0x36, 0x33, 0x30, 0xdc, 0xfd, + 0x6e, 0xa1, 0xc0, 0xcc, 0x9e, 0xbb, 0xc2, 0x32, 0x4b, 0x43, 0xe1, 0x7a, + 0x6f, 0x33, 0xb4, 0x15, 0x77, 0x07, 0x0a, 0x06, 0x82, 0x91, 0xf9, 0xb1, + 0x1c, 0x16, 0x8c, 0xae, 0x67, 0x68, 0x37, 0x2e, 0x80, 0x24, 0x05, 0xd9, + 0x9a, 0xf1, 0x09, 0x25, 0xaf, 0x57, 0x69, 0x96, 0x64, 0xdc, 0x2e, 0x76, + 0xae, 0xb9, 0x75, 0x9e, 0xc4, 0x97, 0x6d, 0x75, 0x9b, 0x53, 0x72, 0xb5, + 0x94, 0x8f, 0x85, 0x9a, 0xcb, 0xbc, 0x59, 0xbc, 0xd3, 0x54, 0x61, 0xe1, + 0xc2, 0xe2, 0x88, 0x0f, 0x0a, 0x9a, 0x53, 0x3d, 0xeb, 0xf7, 0x27, 0x36, + 0x5f, 0xa3, 0x81, 0x7e, 0x7a, 0x7c, 0x79, 0x85, 0xc6, 0xf3, 0x60, 0x92, + 0xcb, 0xa9, 0xe0, 0x4a, 0x76, 0xca, 0x21, 0xf2, 0xe9, 0x37, 0xe0, 0x10, + 0x4b, 0x40, 0x0a, 0x20, 0x06, 0x82, 0xb6, 0xed, 0x93, 0x86, 0x75, 0x13, + 0xbf, 0xb7, 0x54, 0xb1, 0x2c, 0x5d, 0x9e, 0xeb, 0x68, 0x28, 0x96, 0xa1, + 0xa3, 0x2e, 0x5c, 0xe4, 0x6d, 0xf8, 0x11, 0x6e, 0xc9, 0x4c, 0xae, 0x84, + 0x47, 0x0d, 0x6d, 0x3e, 0x34, 0x30, 0x81, 0xe8, 0x7c, 0x25, 0x38, 0xcd, + 0xd7, 0xd3, 0x3d, 0x85, 0xe7, 0xe2, 0xe7, 0x78, 0x3d, 0x16, 0x01, 0xb4, + 0x2a, 0x79, 0xc5, 0x59, 0x66, 0x5c, 0xf9, 0x94, 0x1a, 0x67, 0x1d, 0x55, + 0x8b, 0x4e, 0x07, 0x3b, 0x6f, 0xd4, 0x16, 0xe6, 0xbd, 0xd7, 0x6e, 0xa8, + 0x8f, 0x04, 0xa6, 0xe3, 0x27, 0xa0, 0x57, 0xce, 0x9f, 0xa2, 0xd3, 0xd0, + 0x49, 0x08, 0x9f, 0x47, 0xdb, 0x49, 0xeb, 0x0f, 0x59, 0x55, 0xd9, 0x31, + 0x99, 0x01, 0x7c, 0xf2, 0x5b, 0x67, 0x53, 0xf2, 0xc0, 0xda, 0x38, 0xc4, + 0x03, 0x65, 0xae, 0x80, 0xd9, 0xa5, 0xdb, 0x97, 0xfb, 0x46, 0x44, 0xd8, + 0x94, 0x12, 0x75, 0x05, 0xae, 0x49, 0x8a, 0xcc, 0xb2, 0xb5, 0x8a, 0xe6, + 0xf5, 0x57, 0x0e, 0xf8, 0x7b, 0x66, 0xa5, 0xec, 0x71, 0x3c, 0xa4, 0x7b, + 0xaf, 0xb4, 0x7f, 0x76, 0x62, 0xfe, 0x68, 0x29, 0x33, 0x2a, 0x59, 0xba, + 0xc2, 0xa1, 0xb6, 0x8b, 0xc7, 0x50, 0x7c, 0x6e, 0x7e, 0x5a, 0xcc, 0x06, + 0x7f, 0x66, 0x26, 0x4c, 0x4c, 0xd1, 0xe7, 0x69, 0x53, 0x9c, 0xf2, 0x6f, + 0x38, 0x60, 0xa9, 0x58, 0x62, 0x2f, 0x26, 0xe3, 0x7a, 0x2e, 0x00, 0xad, + 0xdc, 0x43, 0xd6, 0x08, 0xf4, 0xc8, 0x73, 0xec, 0x2a, 0x09, 0xd6, 0xcf, + 0xbf, 0x24, 0x19, 0x1c, 0xf0, 0xd9, 0x60, 0xca, 0x3c, 0xc1, 0x98, 0xae, + 0xad, 0x26, 0xaa, 0xd7, 0xdc, 0xae, 0x9c, 0x58, 0x65, 0x9f, 0x41, 0x74, + 0x68, 0xa2, 0xda, 0x4e, 0x8b, 0xd3, 0x7f, 0x47, 0x81, 0x2e, 0xa3, 0x84, + 0xf3, 0xdf, 0xdb, 0x92, 0xa6, 0x7c, 0xd4, 0xc9, 0x5f, 0x98, 0x96, 0x7e, + 0x71, 0x35, 0x76, 0x79, 0x73, 0xf2, 0x27, 0x85, 0x1d, 0xa5, 0x11, 0xa4, + 0x79, 0x07, 0x68, 0xb7, 0x8e, 0xcd, 0xd0, 0xc0, 0xbb, 0xbb, 0xaa, 0x0b, + 0xe5, 0xf4, 0x10, 0xa7, 0xc8, 0xa5, 0xb8, 0x6b, 0xd1, 0xf5, 0x77, 0x98, + 0xcd, 0x52, 0xcb, 0xc9, 0xdc, 0xb8, 0x7d, 0xf6, 0x7e, 0x3c, 0x43, 0x46, + 0x06, 0xa4, 0xb3, 0x11, 0xbc, 0xe9, 0x79, 0x86, 0x33, 0x17, 0xf7, 0x8f, + 0x25, 0x33, 0x97, 0xa6, 0x6d, 0x48, 0x5a, 0x82, 0x90, 0x26, 0x33, 0xce, + 0xf8, 0xf5, 0xb2, 0x01, 0x4e, 0x0d, 0x82, 0x4b, 0x7e, 0xe2, 0x37, 0x83, + 0x57, 0x47, 0x0d, 0x38, 0x31, 0xca, 0xbf, 0x83, 0xfc, 0xdd, 0x3e, 0x53, + 0xf1, 0x10, 0xc0, 0x46, 0x29, 0x72, 0xc9, 0x43, 0x79, 0x9c, 0x3b, 0xc0, + 0xe9, 0x09, 0xe8, 0xe3, 0x54, 0x00, 0x50, 0x63, 0xc7, 0xbf, 0x6e, 0x5a, + 0xbe, 0x18, 0x20, 0x08, 0xed, 0x69, 0xba, 0x6b, 0x26, 0x20, 0x74, 0x22, + 0x48, 0x16, 0x6b, 0x87, 0x1d, 0x14, 0x4a, 0xa7, 0x30, 0x49, 0x1d, 0x71, + 0xe4, 0x6f, 0x15, 0x4b, 0xa8, 0xcb, 0xa2, 0xb4, 0xd7, 0x68, 0x0e, 0xd2, + 0x5f, 0xa3, 0x92, 0x30, 0x13, 0xb9, 0x8f, 0x57, 0xc7, 0xf7, 0x84, 0x8e, + 0x71, 0x62, 0x07, 0xa8, 0xa6, 0x9b, 0x68, 0xbe, 0xe9, 0x15, 0x3a, 0x85, + 0x62, 0x22, 0xfa, 0xbe, 0x28, 0x4b, 0x48, 0x8b, 0xe9, 0x59, 0x4e, 0x5b, + 0x3f, 0xd9, 0x07, 0x8b, 0x86, 0x75, 0x4a, 0x15, 0x99, 0x24, 0x00, 0xff, + 0xec, 0xeb, 0xce, 0x5c, 0x66, 0xde, 0x86, 0x13, 0xf2, 0x89, 0x6c, 0x28, + 0xa4, 0x85, 0x4b, 0x43, 0x52, 0xf5, 0xe5, 0xa4, 0x69, 0x2f, 0x53, 0xc9, + 0x64, 0x4e, 0xfe, 0x21, 0x2d, 0xb9, 0x4d, 0x16, 0x29, 0x58, 0x18, 0x77, + 0xbe, 0xfe, 0x3f, 0xd2, 0x46, 0x87, 0xb7, 0xb6, 0x66, 0x2f, 0x6b, 0x10, + 0x6c, 0x36, 0xa6, 0x02, 0x34, 0x2d, 0xcb, 0xcc, 0xd7, 0x02, 0x66, 0x1f, + 0x84, 0xc0, 0x58, 0xed, 0x5a, 0x77, 0x50, 0x9b, 0xf9, 0xbd, 0x82, 0x49, + 0xd8, 0x76, 0x5e, 0x10, 0x6e, 0x52, 0x51, 0x70, 0x67, 0x3e, 0xa3, 0x5e, + 0x10, 0x0e, 0x1c, 0xe1, 0xb2, 0xf1, 0x29, 0x34, 0x28, 0xc4, 0x65, 0xf0, + 0x58, 0x5c, 0xbb, 0x41, 0xfa, 0x19, 0x3c, 0x50, 0x64, 0x9a, 0x95, 0x60, + 0x40, 0xe1, 0x61, 0x76, 0x70, 0xcd, 0xb6, 0xc6, 0xca, 0x48, 0x0b, 0x75, + 0xa9, 0xb8, 0x4f, 0xd4, 0x32, 0x31, 0x0c, 0xf3, 0xdc, 0xf7, 0x46, 0x51, + 0x80, 0xe2, 0x03, 0xcf, 0xa6, 0x31, 0x97, 0x17, 0x9a, 0xd6, 0xbe, 0xb5, + 0x10, 0xbe, 0xb4, 0xf2, 0xb5, 0x32, 0x28, 0xb5, 0xd6, 0x8b, 0x20, 0x10, + 0x5d, 0x57, 0x4d, 0x59, 0x0d, 0xf7, 0x7c, 0xfb, 0xe4, 0xb8, 0x7e, 0x0d, + 0x9d, 0xc0, 0x1a, 0xef, 0x35, 0x83, 0x0f, 0x7d, 0x33, 0x9c, 0x74, 0x11, + 0xc3, 0xe2, 0x55, 0x45, 0x1a, 0xbb, 0x6d, 0xb6, 0x69, 0xd5, 0xf7, 0xc1, + 0xf8, 0x87, 0x90, 0x72, 0x23, 0xb4, 0xd1, 0x88, 0x72, 0xd1, 0xbf, 0x92, + 0x88, 0x6e, 0xf3, 0x67, 0x3e, 0xbc, 0xcd, 0x1b, 0xe9, 0x73, 0x9d, 0xc5, + 0x1f, 0x4d, 0x25, 0xce, 0x8e, 0xa4, 0x32, 0x8e, 0x58, 0x62, 0x51, 0x66, + 0x65, 0xe0, 0x0d, 0xf8, 0x62, 0x37, 0xf3, 0x6e, 0x1b, 0xf5, 0xe3, 0xcd, + 0x97, 0x62, 0x8f, 0x33, 0x5e, 0x1a, 0x5d, 0xe5, 0x63, 0xb8, 0xba, 0xe8, + 0x91, 0xcf, 0xe0, 0xdb, 0xfc, 0x7d, 0x61, 0x09, 0xb1, 0x54, 0xd6, 0xe2, + 0xd5, 0x6b, 0x9e, 0x49, 0x08, 0xaa, 0xd3, 0x2b, 0x52, 0x0b, 0x7b, 0x8c, + 0x3f, 0xce, 0x59, 0xf9, 0x03, 0xa3, 0x6a, 0xe3, 0xa2, 0x23, 0x7f, 0x56, + 0x2b, 0x8a, 0xb4, 0xb0, 0x97, 0xf4, 0xc9, 0xcb, 0x14, 0x69, 0x54, 0xd5, + 0x52, 0x3c, 0x1e, 0x51, 0xae, 0x4e, 0xbb, 0x3d, 0x34, 0x96, 0xbe, 0x9b, + 0xc7, 0x12, 0x7c, 0x15, 0x2e, 0x55, 0x4d, 0xd7, 0xf1, 0xa0, 0xda, 0x3f, + 0x19, 0x50, 0x5c, 0xae, 0x1c, 0x80, 0xc2, 0xae, 0x68, 0x1a, 0xe1, 0x10, + 0x1c, 0x51, 0x76, 0x9a, 0x70, 0xda, 0x0b, 0x95, 0x92, 0x76, 0x9e, 0x45, + 0x2d, 0x76, 0xcc, 0xbe, 0xb6, 0x79, 0xf9, 0xff, 0x17, 0x2c, 0xae, 0x04, + 0x67, 0xce, 0x7e, 0x10, 0xc1, 0xd7, 0xba, 0xc5, 0x31, 0x42, 0xda, 0xa0, + 0x51, 0x45, 0x61, 0xdc, 0x59, 0x91, 0x44, 0x09, 0x9a, 0x04, 0xaf, 0xaa, + 0x5c, 0xb7, 0x0e, 0x5c, 0x24, 0xb0, 0x15, 0x3c, 0xe9, 0xb9, 0x7d, 0xf0, + 0x80, 0x97, 0xd4, 0x45, 0xe9, 0x2a, 0xff, 0x3b, 0x8c, 0x8f, 0xcb, 0x3a, + 0x0c, 0xc8, 0xa4, 0xfc, 0x9b, 0x4d, 0xd5, 0xbb, 0x64, 0x77, 0xa3, 0xc9, + 0xc9, 0x6a, 0xff, 0x3c, 0xb8, 0xe3, 0x43, 0x00, 0x40, 0xa4, 0xc8, 0x9e, + 0xab, 0x8e, 0x1b, 0x8e, 0x52, 0x9b, 0x3a, 0x36, 0x09, 0x43, 0x4c, 0xc6, + 0xd8, 0x0f, 0x73, 0x4a, 0x54, 0x04, 0xfc, 0xdd, 0x3d, 0x6f, 0xbe, 0xfc, + 0x0e, 0xb5, 0xeb, 0x83, 0x28, 0x40, 0x2e, 0xb8, 0xbe, 0x3f, 0xfa, 0x77, + 0xe0, 0x83, 0xec, 0xb0, 0x2f, 0x79, 0x16, 0x92, 0x3e, 0xf6, 0xb7, 0xc1, + 0xd0, 0xe4, 0xf4, 0x3e, 0x34, 0xdd, 0x2b, 0x10, 0x72, 0x1b, 0x7e, 0xcf, + 0x07, 0xfa, 0x99, 0xbe, 0xb1, 0x4a, 0xe5, 0xee, 0x2f, 0x1b, 0x30, 0xcc, + 0x61, 0x4c, 0x13, 0xb2, 0xea, 0x7c, 0xdc, 0xd9, 0xd7, 0xeb, 0xc5, 0x2e, + 0x87, 0xae, 0x31, 0x7b, 0x2b, 0x9f, 0xe1, 0x7f, 0x2d, 0x8b, 0x07, 0xf5, + 0x3e, 0x53, 0xec, 0x72, 0x04, 0x51, 0xf5, 0xac, 0x8d, 0xbc, 0x53, 0x08, + 0xae, 0x92, 0x49, 0xfd, 0x06, 0xd7, 0x5d, 0xdc, 0xaa, 0x05, 0x92, 0xf7, + 0x4e, 0x8d, 0x3c, 0xc1, 0xd0, 0x7f, 0x3f, 0x27, 0x54, 0x23, 0x94, 0xf6, + 0x90, 0xbc, 0xf7, 0x72, 0xbd, 0xd5, 0xfd, 0x9e, 0xe4, 0x55, 0xd4, 0x6c, + 0xa5, 0x45, 0x5c, 0x6d, 0xc4, 0xe3, 0xde, 0x6b, 0xb6, 0xb7, 0xb1, 0xd8, + 0x3c, 0x42, 0x4e, 0xaa, 0x9d, 0x0c, 0x5a, 0x55, 0x88, 0xcb, 0x53, 0x0a, + 0xf9, 0x24, 0x15, 0x28, 0xfc, 0x64, 0x61, 0x0d, 0xe3, 0x44, 0x8c, 0x23, + 0x9b, 0x9a, 0x00, 0x09, 0x2e, 0x51, 0x20, 0x79, 0xe4, 0xaf, 0xc3, 0xa6, + 0xa6, 0xc3, 0x56, 0x9a, 0x14, 0xbe, 0xdc, 0xb1, 0xaf, 0xfa, 0xb1, 0x56, + 0x03, 0x14, 0x24, 0x92, 0x86, 0x89, 0x36, 0x35, 0x7d, 0xf2, 0xf4, 0xce, + 0x29, 0xfc, 0xf7, 0x99, 0x0e, 0xc1, 0x46, 0x66, 0xbe, 0x92, 0x06, 0x69, + 0xc3, 0x2b, 0x6c, 0x40, 0x5d, 0xb6, 0x19, 0x41, 0xec, 0x82, 0x7f, 0x79, + 0x9a, 0x09, 0xd3, 0x42, 0x70, 0x0b, 0xbf, 0xf1, 0x94, 0x4c, 0x62, 0x7b, + 0xf7, 0x7f, 0x51, 0xb9, 0x2b, 0x2a, 0x94, 0x75, 0xec, 0x1d, 0xa9, 0xaf, + 0x4b, 0xb9, 0x1f, 0x52, 0x0d, 0xc1, 0x38, 0x2e, 0xb0, 0x6b, 0x5b, 0x97, + 0x7e, 0xfa, 0x92, 0x75, 0x8c, 0x97, 0xd0, 0x3d, 0x5b, 0xd1, 0x9c, 0xd7, + 0x0c, 0xc1, 0x39, 0x77, 0x29, 0x0f, 0x92, 0xd1, 0xac, 0x2d, 0xdc, 0xc0, + 0x39, 0xe9, 0xc9, 0x4f, 0xbe, 0x09, 0xc2, 0x2e, 0xf2, 0x7f, 0xe1, 0xc3, + 0xd8, 0x22, 0xb5, 0x5f, 0xc0, 0x4b, 0x2b, 0xb9, 0xa4, 0x5b, 0x3b, 0x44, + 0x42, 0x71, 0x7c, 0xe2, 0xe0, 0x36, 0x69, 0xb4, 0xa7, 0x5e, 0xe8, 0x1f, + 0x17, 0xb1, 0x18, 0x7c, 0x0b, 0xa2, 0x57, 0x45, 0xb7, 0x05, 0x47, 0x4a, + 0x39, 0x33, 0x99, 0xf3, 0x69, 0xfe, 0xa8, 0x3b, 0x47, 0x9e, 0x43, 0x0b, + 0xd0, 0xef, 0xc0, 0xbc, 0x7f, 0x2d, 0x8b, 0x1c, 0xf0, 0x58, 0xdf, 0x53, + 0x60, 0x1c, 0x0c, 0xe2, 0xe8, 0x7b, 0x1c, 0x7c, 0xc9, 0xfa, 0x0d, 0x04, + 0xfd, 0xc2, 0x97, 0x25, 0xfc, 0x29, 0xd3, 0xea, 0x7d, 0x66, 0x52, 0xa9, + 0x37, 0xd6, 0x6e, 0x0b, 0x1d, 0x75, 0x73, 0x10, 0xd7, 0x75, 0xe7, 0xa5, + 0x0f, 0xb8, 0xed, 0x27, 0x0f, 0x02, 0x7c, 0x09, 0xcb, 0xfa, 0x33, 0x38, + 0x17, 0xc6, 0xcf, 0xc7, 0x66, 0x7e, 0x56, 0x17, 0x42, 0x2c, 0xad, 0xf6, + 0x9b, 0x8b, 0x05, 0xd2, 0xd9, 0x02, 0xde, 0x5a, 0x97, 0xc6, 0x25, 0x4d, + 0x28, 0x5d, 0xbe, 0x80, 0xf3, 0xec, 0xbd, 0x33, 0xaf, 0x73, 0xcc, 0xa0, + 0x77, 0x6a, 0x32, 0x8d, 0x82, 0x7f, 0xf6, 0x74, 0x32, 0x5e, 0xcc, 0x49, + 0x99, 0x75, 0x69, 0x91, 0x7f, 0x9b, 0x36, 0x54, 0xe0, 0xc3, 0xe6, 0x30, + 0xdc, 0x68, 0x59, 0xd2, 0x1a, 0x54, 0x1e, 0x04, 0xfa, 0xb8, 0x1b, 0x4d, + 0x6f, 0xb8, 0x5d, 0x6f, 0x84, 0x38, 0xb2, 0x33, 0xd5, 0x9a, 0xfc, 0x80, + 0x42, 0x39, 0x27, 0x78, 0xb2, 0x58, 0x72, 0xcc, 0x89, 0x95, 0x30, 0x19, + 0x46, 0x9e, 0x63, 0x49, 0x7a, 0xa6, 0xb9, 0x7e, 0x02, 0x50, 0xe9, 0x3f, + 0x7c, 0xd3, 0x0a, 0xb4, 0xaa, 0x1c, 0x5e, 0x68, 0xac, 0x34, 0x66, 0x45, + 0xca, 0x2f, 0x56, 0xd2, 0xca, 0x40, 0xb0, 0x22, 0x04, 0x30, 0x86, 0x00, + 0x2c, 0x99, 0xb6, 0x0b, 0x16, 0x26, 0x27, 0x53, 0xa8, 0x4a, 0x5c, 0x9a, + 0xab, 0x84, 0xbe, 0x25, 0x32, 0xdb, 0x30, 0xa6, 0xde, 0x10, 0x4b, 0x31, + 0x23, 0xfa, 0xc3, 0x48, 0x5a, 0x00, 0x02, 0x53, 0xde, 0x65, 0x97, 0x51, + 0xaf, 0xdd, 0x80, 0xe5, 0x9c, 0x65, 0x74, 0x89, 0xfc, 0xd8, 0x6a, 0x27, + 0xcd, 0x3e, 0xf6, 0xf5, 0xf7, 0xec, 0xed, 0x8e, 0x75, 0x43, 0x4f, 0x86, + 0x08, 0xc8, 0xc1, 0x71, 0x4d, 0x24, 0x88, 0xa0, 0x7f, 0x72, 0x01, 0x17, + 0x07, 0x58, 0x57, 0x6f, 0x07, 0xe5, 0x52, 0xa4, 0xa3, 0x86, 0x68, 0x00, + 0x75, 0x9d, 0x95, 0xcd, 0x54, 0x29, 0xd1, 0xd4, 0x05, 0xd7, 0x84, 0x49, + 0x2c, 0x94, 0x1b, 0xe5, 0xd2, 0xe1, 0x14, 0xf0, 0xfe, 0x18, 0x6c, 0xe4, + 0xee, 0x6e, 0xff, 0xf9, 0x82, 0xf0, 0x2c, 0xa1, 0xab, 0x26, 0x90, 0x91, + 0x9b, 0x38, 0x27, 0x84, 0x04, 0x07, 0x32, 0x80, 0x4b, 0x3d, 0x72, 0x88, + 0x4c, 0x54, 0xd5, 0x9c, 0xaa, 0x27, 0xa8, 0xf9, 0x6c, 0x34, 0xf0, 0x0f, + 0x3d, 0xab, 0x5d, 0x2a, 0x7c, 0xa1, 0xef, 0x37, 0x8b, 0xd9, 0xd5, 0x69, + 0xbe, 0xe9, 0x46, 0xa6, 0x79, 0x1c, 0x6c, 0x49, 0x1c, 0xb8, 0x2f, 0x24, + 0xe3, 0x82, 0xe2, 0x5a, 0x2e, 0xca, 0xd9, 0xe9, 0x0a, 0x90, 0x93, 0xd7, + 0xd9, 0x0d, 0x3d, 0x73, 0x39, 0x9d, 0xb3, 0x8d, 0x1b, 0x3c, 0x4c, 0x76, + 0xff, 0x28, 0x8d, 0x08, 0xcc, 0x60, 0x44, 0xd8, 0x7a, 0x04, 0x93, 0xda, + 0xe7, 0xdb, 0x90, 0x4f, 0x93, 0xe9, 0xbc, 0xfe, 0x88, 0x31, 0xb4, 0x0a, + 0xe1, 0x23, 0xf5, 0xf8, 0xb9, 0xdd, 0x8b, 0x85, 0x44, 0x55, 0x06, 0xb1, + 0x7b, 0x40, 0x4e, 0xb8, 0x0b, 0xd7, 0xe0, 0x38, 0x28, 0x16, 0x4a, 0x14, + 0xa5, 0xc7, 0x98, 0xff, 0xdd, 0xeb, 0xcf, 0xdc, 0xb1, 0xf2, 0x34, 0xc0, + 0x41, 0xa4, 0x54, 0x4d, 0x3a, 0xc4, 0x86, 0x41, 0x82, 0xc7, 0x16, 0xac, + 0x24, 0x43, 0x9e, 0xf1, 0xf4, 0xed, 0x3f, 0xac, 0xf7, 0xdb, 0xbf, 0x17, + 0xaa, 0x03, 0x31, 0xd0, 0x84, 0x03, 0x44, 0x40, 0x0c, 0xe0, 0x25, 0x53, + 0x2c, 0x4d, 0x03, 0x9b, 0x3e, 0x26, 0x9b, 0x40, 0xd2, 0x53, 0xdf, 0x3d, + 0x45, 0x99, 0xb3, 0xdb, 0x97, 0xfe, 0x95, 0x16, 0xad, 0x44, 0xce, 0x46, + 0x6e, 0x80, 0x70, 0x81, 0x1a, 0x02, 0xce, 0xb4, 0x19, 0x10, 0xce, 0xfa, + 0xb9, 0xd0, 0x0a, 0x46, 0x70, 0xfd, 0xc8, 0x1b, 0xfd, 0x3a, 0x44, 0x94, + 0x63, 0x4f, 0x44, 0x09, 0x77, 0x84, 0xa1, 0xf7, 0xd6, 0x2a, 0x19, 0x27, + 0xdd, 0xe8, 0xf8, 0xa1, 0xe5, 0x8b, 0x9e, 0xa5, 0x57, 0x16, 0x1d, 0xcf, + 0xbe, 0xc9, 0xc4, 0x5c, 0xa9, 0x2b, 0x9d, 0xb1, 0x24, 0x1c, 0xb3, 0xa0, + 0xaa, 0xf3, 0x04, 0x41, 0x07, 0x3b, 0x2b, 0x47, 0x6c, 0x81, 0xd7, 0xa5, + 0x1d, 0xcd, 0x1c, 0x29, 0x21, 0x0c, 0xce, 0x3b, 0xae, 0xa2, 0x3e, 0x3d, + 0xa5, 0x21, 0x68, 0xd6, 0x64, 0xb1, 0xe5, 0xee, 0xf4, 0xa4, 0x8f, 0x1e, + 0x46, 0x7e, 0x65, 0x39, 0xb6, 0x6b, 0x17, 0x8f, 0x39, 0xe0, 0xb2, 0xff, + 0x43, 0x51, 0x3b, 0x06, 0x00, 0x03, 0x4b, 0xc4, 0x03, 0x08, 0x2d, 0x07, + 0x6e, 0x9a, 0x77, 0xb3, 0x16, 0xb8, 0xa7, 0x2c, 0xdc, 0x7d, 0xdc, 0x86, + 0x7e, 0x2b, 0x22, 0x00, 0x17, 0x6d, 0x71, 0x03, 0x10, 0x90, 0xe7, 0x41, + 0x5e, 0xf0, 0xa4, 0x97, 0xce, 0x10, 0x75, 0xbe, 0x11, 0xc0, 0x10, 0x0a, + 0x54, 0xfe, 0xe0, 0xa2, 0x3e, 0xa8, 0x12, 0xc6, 0x84, 0xd7, 0x5c, 0xfd, + 0xe8, 0x9b, 0xdf, 0x0c, 0x93, 0xc1, 0x0a, 0x77, 0x0a, 0x8c, 0xab, 0x75, + 0xab, 0x32, 0x88, 0x26, 0x8f, 0xa2, 0xbc, 0xb2, 0x4b, 0x86, 0x3d, 0xef, + 0x8d, 0x3f, 0x63, 0xcd, 0x63, 0xcc, 0x77, 0xe1, 0x57, 0xb6, 0xff, 0x6d, + 0x34, 0x8c, 0xf8, 0x70, 0x5d, 0x84, 0xb5, 0x73, 0x7b, 0x9f, 0x93, 0xbb, + 0xa5, 0xe3, 0x09, 0xc9, 0x34, 0x1f, 0x99, 0xf8, 0x8e, 0x63, 0xd9, 0x75, + 0xd2, 0x36, 0xf1, 0x34, 0x71, 0x00, 0xf6, 0x3b, 0x60, 0xdf, 0x3c, 0x91, + 0x0b, 0xf3, 0xd6, 0xd7, 0x83, 0x86, 0x28, 0x5f, 0xfc, 0xd2, 0x19, 0xe6, + 0x34, 0xc9, 0x5c, 0xff, 0xbf, 0x84, 0xd3, 0x2b, 0xae, 0x30, 0x86, 0x0e, + 0x99, 0x71, 0xb1, 0xaa, 0x6b, 0xab, 0x9a, 0x6b, 0xe4, 0x88, 0xb1, 0xc7, + 0xc7, 0xc7, 0xc6, 0x3b, 0xc9, 0x45, 0x68, 0x96, 0x2f, 0x88, 0x54, 0x73, + 0x68, 0xae, 0x0b, 0x48, 0x20, 0x1e, 0xb8, 0x62, 0x99, 0xca, 0x9f, 0xde, + 0xd8, 0x0d, 0x8f, 0x62, 0xe2, 0x4f, 0xeb, 0xe9, 0x9c, 0x47, 0xee, 0x49, + 0xe6, 0xdb, 0x78, 0xa0, 0x6c, 0x20, 0x08, 0x26, 0xaf, 0xa7, 0x22, 0x2c, + 0x0b, 0x30, 0xc8, 0x97, 0x90, 0xb7, 0x60, 0xff, 0x7d, 0x4b, 0x65, 0xf6, + 0xd5, 0xf9, 0x2d, 0x0b, 0x41, 0x40, 0x13, 0x14, 0x0d, 0x5d, 0xb1, 0x4f, + 0xfa, 0xd5, 0x14, 0x3f, 0xdb, 0x3f, 0x4a, 0x2d, 0x32, 0x0f, 0x70, 0xa6, + 0x5f, 0x12, 0xbb, 0x49, 0x0e, 0x70, 0xdd, 0x4e, 0x5c, 0x1b, 0x89, 0x2b, + 0xeb, 0xf7, 0x51, 0xae, 0x42, 0xd4, 0x59, 0x53, 0x8f, 0xa5, 0x13, 0xce, + 0x1b, 0xdc, 0x9d, 0x82, 0x27, 0x7b, 0x7a, 0x7c, 0x62, 0xaa, 0x4d, 0x48, + 0xfd, 0xdc, 0xba, 0xa4, 0x59, 0x1b, 0xb5, 0x74, 0x1c, 0xbc, 0x84, 0xc9, + 0x67, 0x37, 0x36, 0x9b, 0x4e, 0x2f, 0x89, 0x3f, 0xb8, 0x29, 0xe4, 0xb0, + 0xba, 0x23, 0x1c, 0x7f, 0x5d, 0x60, 0x24, 0x62, 0xdb, 0xd3, 0x96, 0xb2, + 0x9d, 0x7c, 0x6e, 0x5e, 0x78, 0xda, 0x78, 0x45, 0x3c, 0xeb, 0xb6, 0xb3, + 0x0a, 0x38, 0x66, 0xb4, 0xe4, 0x6e, 0x73, 0x47, 0x4d, 0xb4, 0x6f, 0xf8, + 0xcb, 0x55, 0xac, 0x67, 0x03, 0x20, 0x85, 0x97, 0x4a, 0x6c, 0x97, 0xdc, + 0xf4, 0x43, 0xb5, 0x8a, 0x9a, 0xe0, 0xbd, 0x03, 0x04, 0x48, 0xca, 0xc5, + 0x99, 0x82, 0xd2, 0xdf, 0x6d, 0x25, 0xb5, 0x75, 0x92, 0xd6, 0x6d, 0xaa, + 0x73, 0x19, 0x37, 0xbe, 0xf6, 0x0a, 0x51, 0x55, 0x95, 0x28, 0x94, 0x5f, + 0x1e, 0xd8, 0xb2, 0xd8, 0x37, 0xa5, 0x13, 0x49, 0xbb, 0x20, 0xc1, 0xb1, + 0x2e, 0x95, 0x8d, 0xa1, 0x14, 0x1d, 0xd3, 0x89, 0x92, 0x81, 0x29, 0x5c, + 0x1d, 0x47, 0x8b, 0xee, 0x29, 0xd1, 0x3c, 0x84, 0x3f, 0xf5, 0x08, 0x4d, + 0xc1, 0xf5, 0xce, 0xe4, 0xf9, 0xf1, 0x44, 0x37, 0x21, 0x8b, 0x66, 0xe6, + 0x34, 0x6a, 0xdd, 0x60, 0xd2, 0xa3, 0x05, 0x94, 0x62, 0x35, 0x2a, 0x6e, + 0x07, 0x7e, 0xb3, 0xea, 0xae, 0x7e, 0xba, 0x31, 0x95, 0xf0, 0x0c, 0xa8, + 0x52, 0x63, 0xeb, 0xb9, 0xa4, 0x73, 0xaf, 0xb3, 0xf6, 0x56, 0x44, 0x45, + 0x29, 0xc7, 0xba, 0x8b, 0xa8, 0x92, 0xb0, 0xff, 0xfb, 0x6e, 0x3b, 0xf7, + 0x73, 0xfa, 0x83, 0xdb, 0xd9, 0x41, 0x5c, 0x64, 0x4f, 0x2d, 0xad, 0x2f, + 0x8e, 0x33, 0x7c, 0xd5, 0x71, 0x7b, 0x32, 0x57, 0x21, 0xbc, 0x53, 0x66, + 0xa0, 0x62, 0x28, 0x31, 0x70, 0xcb, 0xdb, 0x1b, 0xd3, 0xfd, 0xb2, 0xd8, + 0xcb, 0x8f, 0x21, 0x31, 0x4d, 0xe0, 0xa1, 0xf0, 0x72, 0xe4, 0xa5, 0xfb, + 0x7f, 0x9b, 0xec, 0x5b, 0x74, 0xbe, 0x90, 0x9b, 0x88, 0x61, 0x90, 0xb9, + 0x71, 0xcc, 0xc5, 0x6b, 0x53, 0x32, 0x3b, 0xe4, 0xbc, 0xd6, 0xb6, 0x6c, + 0x21, 0xcb, 0x44, 0x71, 0xf5, 0xca, 0x56, 0xfb, 0xde, 0xcc, 0xe1, 0x2f, + 0x4c, 0xd1, 0xcf, 0x52, 0x53, 0x35, 0x7a, 0xf5, 0x18, 0x81, 0xc5, 0x2f, + 0x22, 0x85, 0xb9, 0x2c, 0xfb, 0x27, 0x66, 0xcd, 0xb2, 0x95, 0x74, 0xb7, + 0x48, 0x62, 0x76, 0x7e, 0xd6, 0x77, 0x67, 0x8c, 0x40, 0x35, 0x2b, 0x9d, + 0x3f, 0x3f, 0x28, 0xcd, 0xd5, 0x93, 0x31, 0x29, 0xc4, 0xb5, 0x94, 0x9d, + 0xa1, 0xee, 0x18, 0xf3, 0x59, 0xab, 0x2a, 0x83, 0x10, 0xbd, 0x3a, 0xa4, + 0x84, 0xe9, 0xc2, 0xa0, 0x86, 0xc7, 0x23, 0x7d, 0x5e, 0x05, 0xc8, 0x58, + 0xf3, 0xef, 0x49, 0x26, 0x01, 0x2f, 0xc2, 0x42, 0x43, 0xa5, 0xbd, 0xec, + 0x53, 0xeb, 0x13, 0x7e, 0xcc, 0xdc, 0x6a, 0x72, 0x31, 0xfa, 0x96, 0x52, + 0x21, 0x89, 0x97, 0x2a, 0xb1, 0x40, 0x09, 0x78, 0xb4, 0xb2, 0x5f, 0xd5, + 0x90, 0x8f, 0x3d, 0x35, 0xa0, 0x5c, 0x41, 0xc7, 0x61, 0x65, 0x1a, 0xa3, + 0x8d, 0x08, 0xbd, 0xa3, 0x20, 0x1f, 0xa9, 0xca, 0xe6, 0x9f, 0x42, 0x02, + 0x78, 0x19, 0x1d, 0x9d, 0xd3, 0x10, 0x58, 0x69, 0x3e, 0x7e, 0x90, 0x42, + 0x7c, 0x66, 0xaa, 0xce, 0x5c, 0x20, 0x77, 0x59, 0x89, 0xa2, 0xca, 0x9c, + 0xef, 0x5d, 0xf9, 0x55, 0x4e, 0x25, 0x7e, 0x60, 0xb0, 0xd0, 0x93, 0x01, + 0xa2, 0x36, 0xc7, 0xab, 0xe5, 0x15, 0x1f, 0xf8, 0x46, 0x7e, 0x2c, 0x51, + 0xbc, 0x1f, 0x5e, 0x93, 0x16, 0x07, 0x12, 0xd9, 0xc3, 0x3e, 0x51, 0xef, + 0x8a, 0xae, 0xb2, 0xd5, 0x6c, 0xe7, 0x33, 0xe3, 0xcd, 0x4d, 0x97, 0x08, + 0x69, 0x59, 0x63, 0x87, 0x3b, 0x9d, 0x0c, 0x94, 0xaa, 0xa3, 0xed, 0xc4, + 0xcc, 0x18, 0x7d, 0x3f, 0x0d, 0xa5, 0x46, 0x58, 0xb0, 0xf7, 0xa4, 0x2c, + 0xfe, 0x7c, 0xb4, 0xe2, 0x12, 0xf1, 0xe8, 0xd1, 0x42, 0x4a, 0x10, 0xbd, + 0xbb, 0xa2, 0x01, 0xeb, 0x40, 0xc0, 0x1d, 0xec, 0xdf, 0x3f, 0x98, 0xec, + 0x76, 0x89, 0xd1, 0xc5, 0x07, 0x85, 0xea, 0x1e, 0x0b, 0x47, 0xc4, 0x1f, + 0x9e, 0xe1, 0xd3, 0xf4, 0x9e, 0x45, 0x48, 0x6e, 0xf4, 0x3f, 0xe7, 0xd3, + 0xac, 0x29, 0xa7, 0xc6, 0xbb, 0xd7, 0x69, 0xaf, 0x1d, 0x3f, 0x62, 0x30, + 0xf8, 0x9e, 0x14, 0x14, 0x5c, 0xff, 0xaa, 0x65, 0x4c, 0x5b, 0x49, 0x0a, + 0x7b, 0x24, 0x61, 0x9d, 0xc8, 0xa7, 0x81, 0x3c, 0xce, 0xc9, 0xad, 0xb8, + 0x8b, 0x49, 0x22, 0x49, 0xa1, 0x08, 0x6f, 0x55, 0xea, 0x51, 0x20, 0x5f, + 0x18, 0x98, 0x34, 0x39, 0x24, 0x1b, 0x8d, 0x23, 0x51, 0xce, 0xb9, 0xf3, + 0x06, 0x5d, 0xf5, 0x53, 0xa6, 0x77, 0x1d, 0x04, 0x44, 0x9c, 0x77, 0xcf, + 0x46, 0x5d, 0x5b, 0x18, 0x3f, 0xb7, 0xe4, 0xcb, 0x49, 0xe2, 0xc3, 0xdf, + 0x99, 0x9f, 0x8f, 0xd8, 0x92, 0x1a, 0xd4, 0x7c, 0xf3, 0x4a, 0x9c, 0xbf, + 0x7d, 0xf1, 0x03, 0xc3, 0xba, 0x9d, 0xfe, 0x79, 0xeb, 0xa8, 0x51, 0x09, + 0x96, 0xfd, 0x41, 0x69, 0xc5, 0x38, 0xfb, 0x60, 0xb7, 0x7a, 0x7a, 0x7a, + 0xd1, 0xa7, 0xe2, 0xc3, 0x77, 0x5c, 0xaa, 0x55, 0x15, 0xf5, 0x82, 0xe0, + 0x7e, 0x12, 0x57, 0x97, 0x63, 0x28, 0x78, 0x49, 0x93, 0x63, 0x6c, 0xe2, + 0x01, 0xf6, 0x17, 0x03, 0xb6, 0x7a, 0x9e, 0x74, 0x6b, 0xf3, 0xc4, 0xf2, + 0x23, 0xba, 0xbf, 0x97, 0x98, 0xcc, 0x40, 0xc3, 0x81, 0xf5, 0x0a, 0xc6, + 0x7d, 0x3d, 0x8f, 0xfb, 0x98, 0xb1, 0x0c, 0x42, 0x74, 0x56, 0x65, 0x8e, + 0xf3, 0xe7, 0x5c, 0x82, 0xa2, 0xf8, 0x59, 0xe1, 0x5e, 0x16, 0xa8, 0x35, + 0xfd, 0x7e, 0x82, 0xab, 0x35, 0x72, 0x57, 0xb5, 0xc3, 0x5b, 0xfd, 0x6b, + 0xaa, 0x78, 0xd0, 0x4e, 0x13, 0xd1, 0x1c, 0x28, 0x12, 0x44, 0x50, 0xa5, + 0xb1, 0xcf, 0xf1, 0x0b, 0x4c, 0xfa, 0x56, 0x03, 0x7c, 0xd0, 0x9a, 0xff, + 0x7f, 0x99, 0x60, 0xec, 0x6c, 0x52, 0x57, 0xe5, 0xb6, 0x00, 0x12, 0xb4, + 0x74, 0x25, 0xfb, 0xe0, 0xec, 0xcf, 0xde, 0xc4, 0x19, 0x3b, 0x44, 0x08, + 0x48, 0x75, 0x1c, 0x84, 0xeb, 0x90, 0xe0, 0xae, 0x36, 0x3a, 0xb4, 0xee, + 0xf5, 0x4d, 0x40, 0x7c, 0xe8, 0x93, 0xb9, 0xcf, 0xe5, 0xa5, 0x63, 0xbf, + 0x81, 0x0f, 0xf0, 0xcb, 0x88, 0x5d, 0x57, 0x99, 0x99, 0x42, 0x45, 0x99, + 0x4d, 0x5e, 0xad, 0xe7, 0x8e, 0x7c, 0x74, 0x75, 0x43, 0xa4, 0x4f, 0x12, + 0x97, 0x54, 0x96, 0xd6, 0xef, 0x7c, 0x6f, 0xd3, 0xc7, 0xac, 0x2d, 0x05, + 0x92, 0x35, 0xc1, 0xe7, 0xfc, 0xfc, 0x20, 0x2e, 0xfd, 0x18, 0x90, 0xa6, + 0x0a, 0x06, 0x12, 0x0e, 0x05, 0x0a, 0x00, 0x2a, 0xe6, 0x8a, 0x8d, 0x07, + 0x3b, 0x2b, 0x8a, 0xc1, 0x1c, 0xcf, 0x86, 0x59, 0x75, 0x05, 0x07, 0x5c, + 0xaa, 0x5b, 0x9b, 0x3d, 0x82, 0xdc, 0xda, 0x71, 0x6a, 0x01, 0x0f, 0xc1, + 0x08, 0xdc, 0xc1, 0xe7, 0xe4, 0xac, 0xed, 0xa6, 0xc8, 0x5a, 0x5d, 0x60, + 0xba, 0x48, 0x41, 0x1a, 0x3a, 0x84, 0x8c, 0x37, 0x37, 0x13, 0x63, 0xb2, + 0x38, 0x83, 0xf3, 0x22, 0xa2, 0x0e, 0x0f, 0x23, 0xb8, 0x7f, 0x13, 0x38, + 0x39, 0xbb, 0x56, 0x3e, 0x3d, 0x68, 0x28, 0x95, 0xa4, 0x80, 0x2d, 0xd4, + 0xcd, 0x55, 0x72, 0x41, 0xdc, 0xc2, 0xe9, 0xb5, 0xc9, 0x26, 0xa7, 0x6f, + 0x21, 0x66, 0xca, 0x97, 0x99, 0x8c, 0xa2, 0xdb, 0xc4, 0x68, 0x89, 0x13, + 0xde, 0x8f, 0xf6, 0x7b, 0x5a, 0x57, 0x68, 0x5f, 0xf1, 0x9d, 0x78, 0x37, + 0x76, 0x35, 0x48, 0xbb, 0xb3, 0xaa, 0x29, 0x41, 0x8f, 0xc4, 0x10, 0xb9, + 0xf7, 0x92, 0x95, 0xe6, 0xa9, 0xb7, 0xcc, 0xf9, 0x85, 0x98, 0xc6, 0x8d, + 0x0f, 0xdb, 0xb1, 0x01, 0x7b, 0xce, 0x9c, 0x66, 0x8d, 0x59, 0xed, 0xcb, + 0xf4, 0xd4, 0xd8, 0x27, 0x4c, 0xaa, 0x7d, 0x0f, 0x63, 0x9e, 0xad, 0x24, + 0x7a, 0x98, 0x1f, 0x73, 0x73, 0x43, 0x3a, 0x6e, 0xe9, 0x48, 0xe5, 0xf9, + 0xae, 0x09, 0xd0, 0x5b, 0x15, 0xf3, 0xb2, 0xba, 0x71, 0x37, 0xc7, 0x35, + 0xed, 0x28, 0x65, 0x72, 0xfb, 0xf8, 0x90, 0xf0, 0xc1, 0x37, 0xa3, 0x26, + 0xcd, 0x44, 0xd2, 0xc6, 0xc0, 0x6d, 0xe9, 0x09, 0x22, 0x28, 0x71, 0x7c, + 0x56, 0xc5, 0x59, 0x5e, 0x27, 0x88, 0xf2, 0x0c, 0xdd, 0x04, 0xd8, 0xa4, + 0x1b, 0x67, 0x7b, 0x8f, 0xb0, 0x54, 0x8c, 0x09, 0xf9, 0x43, 0xcd, 0x81, + 0xfe, 0x9a, 0xa9, 0xc8, 0x85, 0x7f, 0x1d, 0xf1, 0x21, 0x29, 0x54, 0xa9, + 0x2c, 0x97, 0xd3, 0xe8, 0xdc, 0xc5, 0x9f, 0x0a, 0x1a, 0x9d, 0xb1, 0x01, + 0x6e, 0xb3, 0x10, 0x63, 0x1c, 0x52, 0x72, 0x9f, 0x65, 0xbe, 0x33, 0x80, + 0xd8, 0x84, 0x8e, 0xd7, 0x9b, 0x1a, 0xff, 0x1c, 0x01, 0xdc, 0x7e, 0xe0, + 0x87, 0xc8, 0xef, 0x18, 0xba, 0x3a, 0x7a, 0x23, 0x02, 0x0b, 0xeb, 0x3b, + 0xda, 0xec, 0xfb, 0x1a, 0x5f, 0x18, 0x4a, 0xe3, 0x7b, 0x74, 0x4c, 0x84, + 0xf6, 0x09, 0x30, 0xbd, 0xba, 0xb4, 0xb9, 0xdf, 0x0b, 0xd8, 0x18, 0xf4, + 0x78, 0x04, 0x5b, 0x2c, 0xd9, 0x68, 0xde, 0xac, 0xf4, 0xc1, 0xf4, 0x8c, + 0x9d, 0x0a, 0x54, 0x18, 0x68, 0xa3, 0xf0, 0xdf, 0x1a, 0x76, 0x02, 0x39, + 0xdd, 0xd8, 0x73, 0xd0, 0x97, 0xe7, 0x04, 0x5d, 0x10, 0x5c, 0xa5, 0x92, + 0xb6, 0x51, 0x05, 0x65, 0x52, 0xa0, 0x3a, 0xc3, 0x4f, 0xea, 0x00, 0xc4, + 0x97, 0xeb, 0x42, 0x49, 0xd3, 0x0a, 0x52, 0xdb, 0xec, 0x6d, 0xfd, 0xfe, + 0x63, 0x84, 0x84, 0x5e, 0xae, 0xe8, 0x00, 0xb2, 0x84, 0x4a, 0xbb, 0x1a, + 0x17, 0x13, 0xe4, 0xf4, 0x54, 0x48, 0x55, 0xf4, 0x92, 0x7f, 0x80, 0x72, + 0x15, 0x22, 0xee, 0xd2, 0x69, 0x1a, 0xf2, 0xc3, 0xd4, 0x62, 0x91, 0x53, + 0x8d, 0xb2, 0xdc, 0x4b, 0x1c, 0xbc, 0x25, 0x9a, 0x5a, 0x37, 0x9e, 0x9f, + 0x46, 0x10, 0x71, 0xd2, 0x35, 0xdd, 0x02, 0xb1, 0x3f, 0xdf, 0xc1, 0x5c, + 0x54, 0x71, 0xbb, 0xd0, 0xf6, 0xc2, 0x9c, 0xa6, 0xd5, 0x4e, 0x4f, 0x30, + 0xfb, 0xce, 0x78, 0x89, 0x51, 0xe1, 0x73, 0xdc, 0x2b, 0x0e, 0xc0, 0x1b, + 0x18, 0xef, 0xe5, 0x06, 0x74, 0xd2, 0x5c, 0x56, 0x1b, 0x21, 0x98, 0x14, + 0x5c, 0xed, 0x73, 0xe7, 0xf6, 0xbd, 0x38, 0xe4, 0xb3, 0xbc, 0x8f, 0x35, + 0xff, 0x5b, 0x88, 0xf8, 0x81, 0xff, 0xd8, 0xa0, 0x73, 0x79, 0x44, 0xd6, + 0x9f, 0xc9, 0x5c, 0x0d, 0x1e, 0x00, 0x22, 0x70, 0xbe, 0xff, 0xd9, 0x81, + 0x60, 0x45, 0x22, 0x82, 0xe8, 0x13, 0x28, 0xdf, 0x24, 0x96, 0x73, 0x4f, + 0xd1, 0xd3, 0x71, 0x82, 0xb9, 0xbb, 0xc5, 0xb1, 0xf8, 0x49, 0x79, 0xd8, + 0x43, 0x44, 0x17, 0x47, 0xf6, 0xe5, 0xe6, 0x95, 0xd1, 0x0b, 0x90, 0xa2, + 0x40, 0xc3, 0x5e, 0x54, 0xe7, 0x1c, 0x17, 0xe7, 0x24, 0x70, 0xec, 0x00, + 0xee, 0x98, 0x4b, 0xb6, 0x99, 0x01, 0xfd, 0x38, 0x7b, 0x40, 0xa3, 0x38, + 0x5b, 0x98, 0x55, 0x8e, 0xaa, 0x00, 0xaa, 0x45, 0xf9, 0x97, 0xa0, 0xdc, + 0xd6, 0x9b, 0xc1, 0xd3, 0xde, 0x56, 0x3c, 0x1e, 0x07, 0x53, 0x15, 0x28, + 0x55, 0x19, 0x32, 0x35, 0x2d, 0x66, 0x73, 0x69, 0x79, 0xc4, 0x12, 0x68, + 0x4d, 0x59, 0x5a, 0x96, 0x8a, 0x7c, 0x81, 0x0f, 0xd0, 0x97, 0x94, 0x44, + 0x48, 0xf4, 0xc5, 0x18, 0x02, 0xb6, 0x93, 0x7f, 0x3c, 0x79, 0x5f, 0xd4, + 0x16, 0x61, 0x11, 0x9f, 0x1f, 0x99, 0x85, 0xbd, 0x8c, 0x9b, 0xb6, 0x06, + 0x25, 0xb9, 0x8f, 0x0f, 0x73, 0xc6, 0x5c, 0x57, 0xd9, 0xcb, 0x10, 0x50, + 0x93, 0xf2, 0xc1, 0x2b, 0x07, 0x3b, 0xae, 0x16, 0x5d, 0x93, 0x58, 0xba, + 0x4f, 0x74, 0x1e, 0x3e, 0xd3, 0xbe, 0xbd, 0x38, 0xe5, 0xec, 0x17, 0xfa, + 0x0a, 0x6e, 0x4e, 0xea, 0xa0, 0x4e, 0xca, 0x7f, 0x56, 0x98, 0x27, 0xb5, + 0x46, 0x2d, 0xc6, 0x8e, 0xb1, 0xfc, 0x39, 0x01, 0xc6, 0xc0, 0x4c, 0xf7, + 0x37, 0x1c, 0xe4, 0xed, 0x7d, 0xf6, 0x6a, 0xdf, 0x07, 0x16, 0x50, 0xa4, + 0xf1, 0xdb, 0x5b, 0xa9, 0x08, 0x33, 0xe3, 0xa8, 0xdb, 0x49, 0x51, 0x03, + 0x77, 0x89, 0xea, 0x42, 0x45, 0x1d, 0x10, 0x69, 0xa3, 0xd2, 0x7b, 0xec, + 0x01, 0x56, 0x72, 0x89, 0x44, 0xfd, 0x3a, 0x5b, 0x24, 0x1f, 0x32, 0x22, + 0x37, 0x72, 0x41, 0x99, 0x7d, 0x94, 0x7c, 0xa9, 0x23, 0x14, 0xd5, 0xd1, + 0x28, 0xd9, 0x49, 0x2a, 0xed, 0x7b, 0xfc, 0x2b, 0xc3, 0xcd, 0x74, 0xe4, + 0x9b, 0xa2, 0xe0, 0x6e, 0x42, 0x6c, 0xc6, 0x10, 0x2c, 0x24, 0xe1, 0xa5, + 0x6b, 0xd0, 0xcf, 0x56, 0x2a, 0x3b, 0x90, 0x01, 0x06, 0x80, 0x27, 0xe9, + 0x81, 0x9a, 0xdd, 0xe3, 0x84, 0xd8, 0x10, 0x87, 0x1d, 0x9f, 0xe0, 0xdc, + 0x2c, 0x24, 0x03, 0x95, 0xeb, 0xac, 0x22, 0x51, 0x01, 0x6a, 0xc4, 0xb0, + 0x4b, 0x68, 0x6a, 0x47, 0x2f, 0xbc, 0xe9, 0xb7, 0x09, 0x7b, 0xf1, 0x2b, + 0xd5, 0x2c, 0x2c, 0x13, 0x74, 0x14, 0x46, 0xe7, 0xe9, 0x22, 0x2b, 0xbe, + 0x79, 0x4e, 0xd9, 0x11, 0x04, 0x4a, 0x81, 0x50, 0x6a, 0x0a, 0x17, 0x3f, + 0x37, 0x68, 0x07, 0x0a, 0x0c, 0xa6, 0xfb, 0xec, 0xcc, 0x71, 0xb7, 0x3a, + 0x65, 0x33, 0x36, 0x41, 0x21, 0xb0, 0x50, 0x8a, 0xc1, 0x98, 0x4f, 0x65, + 0x10, 0x88, 0xdb, 0x56, 0x90, 0x50, 0x1b, 0x99, 0x6d, 0x2b, 0x20, 0x2a, + 0xd2, 0xae, 0x06, 0x7e, 0x9c, 0xc9, 0x93, 0xbc, 0x00, 0xd2, 0xef, 0x60, + 0x8b, 0xf6, 0xe0, 0x93, 0xca, 0x27, 0xb3, 0x3d, 0x6c, 0x73, 0x5d, 0x53, + 0x91, 0xc6, 0xf0, 0x4f, 0xc1, 0xd2, 0x5e, 0x91, 0x6a, 0xb2, 0x90, 0x67, + 0x82, 0x06, 0xc2, 0x1f, 0xc7, 0xff, 0x59, 0x36, 0x10, 0x4c, 0x12, 0x58, + 0x49, 0xc2, 0x01, 0x1c, 0xa3, 0xc0, 0xb5, 0xd2, 0x2b, 0x12, 0xe5, 0x4e, + 0xa2, 0x50, 0x21, 0x1c, 0x16, 0xb2, 0x4a, 0xaa, 0xa1, 0x1b, 0xb8, 0x2b, + 0x07, 0xad, 0xfd, 0x34, 0xde, 0xf8, 0xe1, 0x9c, 0x83, 0xb6, 0xb3, 0xb5, + 0xbb, 0xa8, 0x04, 0x65, 0xaa, 0x03, 0x02, 0xae, 0x6f, 0xb6, 0x4b, 0x9a, + 0xb5, 0x81, 0xfe, 0xd8, 0x18, 0x3a, 0x4b, 0x96, 0x9c, 0x9f, 0x2f, 0xf2, + 0xfb, 0xe2, 0x84, 0xdd, 0x5a, 0xf9, 0x4b, 0x0f, 0x28, 0x61, 0x93, 0xb6, + 0xbe, 0x37, 0xda, 0xb1, 0x2f, 0x58, 0x03, 0x8d, 0x49, 0xeb, 0x45, 0xf4, + 0xb5, 0x31, 0x26, 0xfa, 0x60, 0x62, 0x77, 0x65, 0x6d, 0x0b, 0x1d, 0x47, + 0x6a, 0xdf, 0xc2, 0x87, 0xa6, 0x43, 0x99, 0xe3, 0x2a, 0x6f, 0xa2, 0xb4, + 0xe0, 0xa4, 0x10, 0x04, 0x04, 0xba, 0xee, 0x49, 0xf7, 0xa6, 0x7b, 0x59, + 0xf1, 0xe1, 0xef, 0xad, 0x36, 0xf1, 0x35, 0x40, 0x8d, 0x24, 0x68, 0xe9, + 0xd7, 0x9e, 0x76, 0x14, 0x00, 0x1a, 0x6a, 0x47, 0xa2, 0x4c, 0xc0, 0xb0, + 0xae, 0xf4, 0xdb, 0xf6, 0x9b, 0xa5, 0xcf, 0xfd, 0x66, 0xe2, 0xd0, 0xf2, + 0x6c, 0x1f, 0x68, 0x3f, 0x49, 0x83, 0x7c, 0x6c, 0x29, 0x5d, 0x4d, 0x85, + 0x10, 0x65, 0xeb, 0x2c, 0xa9, 0xae, 0xcb, 0x48, 0x53, 0x06, 0xe1, 0x1f, + 0xe0, 0x84, 0xfa, 0xf9, 0xc4, 0x4f, 0x89, 0x13, 0xf6, 0x04, 0x1c, 0x21, + 0x6e, 0xef, 0xe5, 0xd6, 0x18, 0x56, 0x8e, 0x2a, 0x6f, 0x95, 0x08, 0xfb, + 0x88, 0xeb, 0x1f, 0xb8, 0x5f, 0x09, 0xeb, 0x0e, 0xd3, 0xe0, 0x90, 0x43, + 0x61, 0x62, 0xf2, 0x99, 0x40, 0xa6, 0xc1, 0x3b, 0xc0, 0x09, 0xa1, 0xe7, + 0x58, 0x9c, 0x33, 0x02, 0xca, 0xd2, 0x22, 0x11, 0x3b, 0xe2, 0x02, 0x51, + 0xe2, 0x38, 0xfc, 0x31, 0x42, 0x36, 0x49, 0x15, 0xb0, 0x10, 0x26, 0xeb, + 0xd7, 0x00, 0xb1, 0x11, 0x86, 0x98, 0x8f, 0xfd, 0x57, 0x66, 0x05, 0xaf, + 0x95, 0xd6, 0x2c, 0xb7, 0x4a, 0x59, 0x07, 0x7b, 0xe9, 0x82, 0x5f, 0x3b, + 0x92, 0xf7, 0x02, 0x22, 0xe0, 0x5c, 0xe3, 0xac, 0xfe, 0x3e, 0xf4, 0x79, + 0x93, 0x5e, 0x8c, 0x69, 0x00, 0x36, 0xdb, 0x9d, 0x32, 0x9a, 0xdb, 0xcc, + 0x5f, 0x75, 0xc3, 0xc6, 0x3c, 0x39, 0x05, 0x06, 0x47, 0xc7, 0x03, 0x01, + 0x14, 0xf2, 0xeb, 0x3d, 0x7f, 0x98, 0x63, 0xdd, 0xcd, 0x2d, 0x9f, 0x91, + 0x8e, 0xc7, 0xfe, 0x29, 0x69, 0xe2, 0x71, 0xd9, 0x44, 0x84, 0x72, 0xdf, + 0xc0, 0x38, 0x57, 0x95, 0x98, 0x89, 0x11, 0x00, 0x55, 0xdb, 0xb6, 0x7c, + 0xeb, 0x4c, 0x08, 0x97, 0xff, 0x7a, 0x99, 0x41, 0x66, 0xb4, 0xe1, 0x62, + 0x47, 0xf5, 0x54, 0xd6, 0x76, 0x20, 0x23, 0xab, 0xae, 0xdb, 0x5d, 0x6c, + 0xc1, 0x1c, 0x2d, 0x13, 0x25, 0x47, 0xae, 0x37, 0x3c, 0xe8, 0x19, 0xd3, + 0xf6, 0xbb, 0x32, 0x62, 0x68, 0xaf, 0x6e, 0x6a, 0x8c, 0xef, 0xd0, 0x66, + 0x46, 0x2f, 0xa9, 0x7d, 0x9a, 0xd6, 0xb4, 0x5d, 0xf3, 0x88, 0x52, 0xe2, + 0x5e, 0x30, 0x99, 0xbb, 0xbf, 0x1d, 0x24, 0x0f, 0xcf, 0x4c, 0x28, 0x86, + 0x74, 0xfd, 0xbd, 0x70, 0xb1, 0x18, 0xf6, 0xe0, 0x43, 0x7d, 0x5a, 0x2f, + 0xd8, 0xca, 0x38, 0x21, 0xba, 0x8d, 0x95, 0x18, 0x04, 0xfb, 0xfd, 0xcd, + 0xaf, 0xfc, 0x21, 0xf7, 0x25, 0x3f, 0xb0, 0x61, 0x0a, 0x6a, 0xd6, 0x68, + 0x85, 0x88, 0xda, 0x2d, 0xd0, 0x04, 0xbb, 0x29, 0x17, 0x49, 0x10, 0xca, + 0xe4, 0xbd, 0x3c, 0xcf, 0x8e, 0xab, 0x33, 0xdc, 0x26, 0x77, 0x90, 0x7c, + 0x7c, 0xb0, 0xca, 0xc0, 0x2d, 0xba, 0x14, 0x45, 0x5a, 0x0f, 0x80, 0xb1, + 0xf6, 0xbe, 0x69, 0xcc, 0x8e, 0xe8, 0x43, 0xe1, 0x7d, 0x98, 0xb2, 0xcc, + 0x8e, 0x64, 0x25, 0xbe, 0x97, 0x68, 0x2c, 0x36, 0xc6, 0x99, 0x2a, 0x9a, + 0x58, 0x16, 0xbb, 0x93, 0x43, 0xff, 0x85, 0x17, 0x2e, 0xc8, 0x6d, 0x63, + 0xbc, 0x51, 0x41, 0x00, 0xd4, 0x78, 0x12, 0x43, 0x6b, 0xc9, 0x0d, 0xbd, + 0xcc, 0x6d, 0xf7, 0x69, 0x40, 0x50, 0xd1, 0x40, 0xf6, 0xfd, 0x14, 0xff, + 0xed, 0x94, 0x79, 0x61, 0x1c, 0xea, 0xba, 0x39, 0x8b, 0xd0, 0x69, 0x33, + 0x5d, 0xfe, 0xf1, 0xaa, 0x80, 0xa4, 0x15, 0x5c, 0x0e, 0xb7, 0x26, 0xac, + 0x8e, 0x09, 0x7c, 0xc5, 0x92, 0xf2, 0xbf, 0x98, 0x71, 0x1f, 0x0e, 0xf1, + 0x63, 0x9b, 0x9f, 0x2b, 0x9f, 0x34, 0xf4, 0x2e, 0xd5, 0x1d, 0xe8, 0x6f, + 0x8e, 0x99, 0xeb, 0xbf, 0x4d, 0xd7, 0x02, 0x54, 0x01, 0xcc, 0xbb, 0xbc, + 0x40, 0x4b, 0x85, 0x88, 0x40, 0x4a, 0xbd, 0x8b, 0x4b, 0xc3, 0xa7, 0xfe, + 0x07, 0xd3, 0xf7, 0xda, 0x2a, 0x20, 0x6f, 0x39, 0x3f, 0x6a, 0xf6, 0x37, + 0xb7, 0xcb, 0x23, 0xb6, 0xc6, 0x6f, 0x1f, 0xb5, 0xfa, 0x05, 0xf5, 0x3b, + 0x86, 0xff, 0x58, 0xa0, 0xcc, 0x29, 0x57, 0xdf, 0x8a, 0xa8, 0x41, 0x2c, + 0xe9, 0x94, 0x31, 0xd9, 0xdf, 0xa6, 0x08, 0xeb, 0x38, 0xab, 0x2c, 0x3c, + 0xe4, 0xac, 0x9e, 0xb2, 0x94, 0x83, 0x46, 0x8d, 0x81, 0x23, 0xa4, 0x09, + 0xff, 0xb9, 0x88, 0x63, 0x90, 0x1c, 0x10, 0x1e, 0x10, 0xa0, 0x7f, 0xbf, + 0x67, 0xa9, 0x0b, 0x9c, 0xa3, 0x4b, 0x19, 0xb9, 0x2e, 0x20, 0x8d, 0x26, + 0x25, 0xab, 0x1a, 0x94, 0xe2, 0x85, 0xfa, 0xcf, 0x6d, 0x37, 0xae, 0xc8, + 0xd0, 0xbb, 0x8e, 0xb7, 0xd7, 0x71, 0x9a, 0x01, 0x6f, 0x1e, 0xcb, 0x01, + 0xea, 0xd3, 0x3d, 0x43, 0x8c, 0x69, 0xf3, 0xc0, 0x81, 0x43, 0xe7, 0xbf, + 0xc5, 0xdf, 0x84, 0x6b, 0x1d, 0xb0, 0x7f, 0xa6, 0xfd, 0x2c, 0xd8, 0xc4, + 0x38, 0x68, 0xb6, 0x36, 0xd9, 0x67, 0x94, 0xb8, 0x68, 0x40, 0x52, 0xf6, + 0xe5, 0xe0, 0x6f, 0x7b, 0x02, 0xf9, 0x02, 0xd1, 0x85, 0xf4, 0xcb, 0x1c, + 0xd7, 0x51, 0x8e, 0xe7, 0x58, 0x3c, 0xf6, 0x8b, 0xef, 0x85, 0x38, 0xcd, + 0xdd, 0x2f, 0xe3, 0xe9, 0x8a, 0xd6, 0x9e, 0x7d, 0x2f, 0x60, 0xa6, 0x84, + 0x70, 0xfe, 0x11, 0x60, 0x79, 0x17, 0x84, 0x9a, 0x4c, 0x31, 0x19, 0x51, + 0x46, 0x9d, 0x08, 0x80, 0xba, 0xf8, 0x55, 0x10, 0xa4, 0x63, 0x53, 0xfb, + 0xd4, 0x50, 0xa1, 0x05, 0x25, 0x34, 0x72, 0x9b, 0x64, 0x3b, 0x3f, 0x65, + 0xb3, 0xe2, 0x56, 0x8d, 0x9d, 0x74, 0x3c, 0x3a, 0x40, 0xc1, 0xcf, 0x0d, + 0x29, 0x49, 0x25, 0x8c, 0x31, 0xed, 0xc4, 0x80, 0x75, 0xe7, 0xed, 0x90, + 0x9a, 0xd2, 0x5d, 0x47, 0x74, 0xef, 0xec, 0xbf, 0xe3, 0x43, 0x44, 0x1e, + 0x36, 0xcf, 0x1b, 0x55, 0x02, 0x90, 0xfe, 0x93, 0x00, 0x3a, 0xf4, 0x7c, + 0x64, 0xdc, 0x9a, 0x84, 0xda, 0x9b, 0x1e, 0x14, 0x67, 0x93, 0xb4, 0xc6, + 0xfb, 0x80, 0x6a, 0x32, 0x4c, 0x75, 0x69, 0x31, 0x20, 0xc1, 0xc7, 0x0a, + 0x22, 0xe5, 0xc4, 0x82, 0x50, 0xc8, 0xeb, 0x91, 0x4f, 0x6c, 0x3b, 0xdb, + 0xaa, 0xa8, 0x9f, 0x8f, 0xc6, 0x71, 0x4a, 0xef, 0xef, 0xdc, 0x7b, 0xb6, + 0xe4, 0x45, 0x08, 0x53, 0x3e, 0x5c, 0x03, 0x90, 0x06, 0x0c, 0x3a, 0x8d, + 0x95, 0xda, 0x36, 0x4d, 0xc9, 0xd1, 0x41, 0x82, 0x2e, 0xd9, 0x8e, 0xda, + 0xb2, 0xd0, 0x41, 0x86, 0x5c, 0x9b, 0x3e, 0x76, 0xab, 0x91, 0x66, 0x01, + 0x0b, 0x6c, 0x2f, 0x15, 0x62, 0xad, 0xbd, 0x49, 0xd8, 0x3f, 0x59, 0x89, + 0xa4, 0x31, 0xc3, 0x99, 0xed, 0x17, 0x82, 0x4a, 0xab, 0x40, 0xb6, 0x6c, + 0xa8, 0xcf, 0x22, 0xed, 0xd2, 0x8b, 0x9a, 0x84, 0x62, 0xf9, 0xc3, 0x57, + 0x43, 0x58, 0x1c, 0x54, 0xee, 0x5b, 0x1c, 0xad, 0xe4, 0xe0, 0xe1, 0x47, + 0x1a, 0x68, 0x8e, 0xd7, 0xb7, 0x61, 0x50, 0x63, 0x63, 0x0d, 0x5e, 0x12, + 0x07, 0xa2, 0xc7, 0xc8, 0x24, 0x6a, 0xf1, 0xd9, 0x3e, 0x76, 0x6f, 0x72, + 0x2f, 0x2b, 0x9c, 0x11, 0xaa, 0x28, 0x66, 0x2c, 0xab, 0x00, 0xea, 0xe5, + 0x7d, 0x13, 0x86, 0x2f, 0x10, 0x3f, 0x0f, 0x45, 0xa5, 0xee, 0x1c, 0xf6, + 0xb9, 0x2e, 0xfb, 0x61, 0x14, 0xc5, 0xec, 0xee, 0xc3, 0x39, 0x81, 0xde, + 0x67, 0x3e, 0xc8, 0xc4, 0xf4, 0xe1, 0x87, 0x8c, 0xaa, 0xca, 0x85, 0x84, + 0x52, 0xdb, 0xc2, 0xc3, 0x66, 0x90, 0x85, 0x20, 0x66, 0x93, 0x9a, 0x17, + 0x72, 0xe2, 0x70, 0x57, 0xe0, 0xca, 0xb2, 0xac, 0x38, 0xfa, 0x0c, 0xee, + 0xb7, 0x27, 0x29, 0xd2, 0x75, 0x80, 0xd6, 0xe4, 0x49, 0x82, 0xcb, 0xdc, + 0x0a, 0xbc, 0x34, 0x18, 0x96, 0x96, 0xe1, 0x5d, 0x53, 0x4c, 0x20, 0x5d, + 0xd9, 0xf6, 0x29, 0x89, 0xbc, 0x8c, 0x25, 0xe9, 0x59, 0xd4, 0x3b, 0x66, + 0xc2, 0x74, 0x3a, 0x5f, 0x88, 0xc9, 0x42, 0x6a, 0x10, 0x7e, 0x4b, 0x5f, + 0x66, 0x0a, 0x54, 0x0a, 0x3b, 0x96, 0x28, 0x4d, 0x8b, 0xe0, 0x1e, 0x8d, + 0xaa, 0xa5, 0xa1, 0x87, 0xa6, 0x4a, 0xd6, 0xfe, 0xc5, 0x94, 0xd5, 0x7a, + 0xf3, 0x46, 0xe2, 0x65, 0x87, 0x75, 0x09, 0x22, 0x5f, 0x0b, 0x28, 0xaa, + 0x0d, 0x70, 0xbb, 0xa3, 0xb9, 0xb2, 0xaa, 0x98, 0x02, 0x7c, 0x90, 0xdc, + 0xbd, 0x76, 0xab, 0x3c, 0xa4, 0x41, 0x71, 0x0f, 0x13, 0xf6, 0xaf, 0x7e, + 0x51, 0x6f, 0xd8, 0xcc, 0xcc, 0x20, 0x1f, 0xd2, 0x49, 0x58, 0x09, 0x38, + 0x5e, 0xa7, 0xd2, 0x36, 0xfa, 0xa3, 0xd2, 0x13, 0x35, 0x88, 0x12, 0xf0, + 0x61, 0x44, 0xe9, 0xdc, 0x83, 0x9e, 0xd6, 0x61, 0x90, 0xe5, 0x78, 0xce, + 0xc8, 0x3b, 0x85, 0x13, 0x64, 0x7a, 0x9d, 0xc9, 0xe3, 0xbb, 0x96, 0xd4, + 0x4c, 0x31, 0x67, 0x87, 0xd8, 0x23, 0x41, 0xb8, 0xb6, 0xb2, 0x1b, 0xe1, + 0xbc, 0xbb, 0xc1, 0x9a, 0x9a, 0xb0, 0x41, 0xa7, 0x64, 0x2e, 0x3e, 0x6e, + 0xc3, 0x6d, 0x32, 0xd3, 0xba, 0xcd, 0xc4, 0x6c, 0x29, 0x16, 0x2e, 0x5b, + 0xfe, 0x04, 0x03, 0x67, 0x1a, 0x5b, 0x25, 0x06, 0x9f, 0x12, 0x28, 0x0e, + 0xae, 0x6b, 0x37, 0xb7, 0xd8, 0xb6, 0x22, 0xe9, 0xbf, 0x39, 0x85, 0x43, + 0xdd, 0xb0, 0x6b, 0xd1, 0x62, 0x1a, 0x57, 0x3c, 0x03, 0xfd, 0xa2, 0xb8, + 0x45, 0x7f, 0x21, 0x23, 0xe6, 0x4b, 0xf5, 0x17, 0xe8, 0x09, 0xf0, 0x96, + 0xbc, 0x7b, 0x60, 0xfe, 0x4b, 0xf1, 0x43, 0x0d, 0x58, 0x37, 0x30, 0xcb, + 0xbe, 0x53, 0xa8, 0x66, 0x0b, 0x20, 0xbd, 0x5b, 0x93, 0x5a, 0xe9, 0x10, + 0xf2, 0xc9, 0x04, 0x36, 0xa3, 0xf1, 0xc9, 0x3b, 0x0d, 0x4c, 0xd4, 0x8d, + 0xd7, 0xa2, 0x7c, 0xd7, 0xcd, 0xf4, 0x90, 0xb1, 0x11, 0x55, 0x57, 0xc7, + 0x40, 0x53, 0xa6, 0xcd, 0xd6, 0xe2, 0xa9, 0x16, 0x18, 0xbb, 0x42, 0xab, + 0xee, 0xf4, 0xd8, 0x38, 0x4f, 0xf2, 0xdd, 0xb7, 0xc6, 0x20, 0x81, 0x51, + 0xfb, 0x46, 0xc3, 0x53, 0x99, 0xcd, 0x66, 0xd6, 0x11, 0xbe, 0xc9, 0xda, + 0x8b, 0x6b, 0x23, 0x4f, 0xe6, 0xa5, 0xa0, 0x3d, 0xd5, 0x4d, 0x5c, 0xd9, + 0xd9, 0xc8, 0xd1, 0x9e, 0xeb, 0xee, 0x17, 0x8b, 0x22, 0x22, 0xd8, 0x8a, + 0x2a, 0x15, 0x12, 0x4e, 0xc8, 0x31, 0x92, 0x72, 0x83, 0xd4, 0x1b, 0x08, + 0xfc, 0x48, 0xf8, 0xe1, 0x7b, 0xb1, 0xe1, 0x07, 0x78, 0xec, 0x50, 0xe7, + 0x8a, 0x5d, 0x9e, 0xef, 0x14, 0x5b, 0x2a, 0x65, 0x31, 0x19, 0xd9, 0xd9, + 0x05, 0x92, 0x90, 0x27, 0x7a, 0xa3, 0x8f, 0x83, 0xa6, 0xd8, 0xd1, 0xd8, + 0x66, 0xf4, 0x60, 0x87, 0x64, 0xae, 0xd6, 0x09, 0xcd, 0xad, 0x24, 0xf3, + 0xa3, 0x44, 0xf7, 0xbe, 0x35, 0x5c, 0x48, 0xd5, 0x99, 0xd3, 0x9e, 0x75, + 0x38, 0xd2, 0x1d, 0x85, 0x4b, 0x83, 0xce, 0xf6, 0x0d, 0x7f, 0xe8, 0x7b, + 0xc7, 0x34, 0x44, 0x62, 0xf7, 0x2f, 0x71, 0xa6, 0x46, 0x09, 0x0a, 0xb2, + 0x3e, 0x8f, 0x5f, 0xe7, 0xd8, 0x58, 0x1f, 0xc6, 0x8e, 0x65, 0xc4, 0x2d, + 0xbb, 0x11, 0xd3, 0xe9, 0x63, 0x80, 0x6b, 0xca, 0x88, 0xd3, 0x8e, 0x7d, + 0x50, 0x88, 0x86, 0xb1, 0x99, 0x53, 0x2a, 0x3a, 0x3d, 0x14, 0x47, 0x42, + 0x51, 0x1c, 0x56, 0xc4, 0xeb, 0xa8, 0x72, 0xc0, 0x06, 0xa4, 0x87, 0x36, + 0x08, 0x73, 0x71, 0x80, 0x65, 0x47, 0xf9, 0xf3, 0xa3, 0x59, 0xa8, 0x88, + 0x30, 0x44, 0x43, 0x92, 0x80, 0x12, 0xd9, 0x45, 0xb3, 0x27, 0x91, 0xb3, + 0xbd, 0xb6, 0x3f, 0x96, 0x67, 0x73, 0x97, 0xfd, 0x16, 0xc0, 0xd5, 0x45, + 0xa6, 0xfa, 0x36, 0x82, 0x3a, 0x4f, 0x40, 0x82, 0x2e, 0xef, 0xf1, 0x57, + 0x27, 0x74, 0x99, 0x12, 0x75, 0x73, 0x41, 0x1d, 0xcd, 0xfd, 0xdc, 0x28, + 0xe1, 0xa6, 0x21, 0xaf, 0x86, 0x6f, 0xff, 0x7a, 0x0f, 0xb3, 0x6f, 0xf4, + 0xc0, 0x00, 0xad, 0xa0, 0x65, 0xcd, 0xf1, 0x4e, 0xd3, 0x5e, 0xdf, 0x72, + 0x72, 0x56, 0xe5, 0xdc, 0x57, 0xde, 0x52, 0x38, 0x0a, 0xe8, 0xa8, 0x29, + 0x37, 0x0b, 0xfa, 0xf7, 0x74, 0x12, 0x7e, 0xd8, 0x77, 0x12, 0x15, 0xad, + 0x5f, 0x00, 0x49, 0x7f, 0x75, 0x0b, 0x75, 0x2f, 0xd8, 0xa2, 0x46, 0xcd, + 0x11, 0x84, 0x73, 0x99, 0xaa, 0xa8, 0xc5, 0x8b, 0x41, 0xdf, 0x7f, 0x3d, + 0x51, 0x42, 0x70, 0xc7, 0x71, 0xbc, 0xae, 0xf9, 0x62, 0x1b, 0xdb, 0x4c, + 0x42, 0x07, 0x13, 0xc5, 0xf0, 0xd6, 0x6a, 0xb2, 0xde, 0x5e, 0xe9, 0xe3, + 0xe6, 0xfa, 0xe4, 0x53, 0x24, 0xf5, 0x2c, 0x63, 0x66, 0x40, 0xb6, 0x05, + 0x63, 0xa5, 0xf5, 0x30, 0xcb, 0x29, 0x92, 0x74, 0xd7, 0x18, 0x29, 0x5d, + 0xba, 0x23, 0x3e, 0x21, 0xbf, 0x3b, 0xee, 0xbe, 0x31, 0x5d, 0x9a, 0xe9, + 0xa5, 0x93, 0x61, 0x21, 0xb9, 0xdb, 0xb9, 0x95, 0xc0, 0x3f, 0xdf, 0xe9, + 0x3d, 0xf9, 0x9f, 0x41, 0xb5, 0xd2, 0xc0, 0x97, 0x29, 0x28, 0x2b, 0xc4, + 0x80, 0xe6, 0x67, 0x0c, 0x67, 0xfe, 0x7e, 0xc3, 0x3e, 0x5f, 0xae, 0xee, + 0xa0, 0x6f, 0xc3, 0xa2, 0x21, 0x4f, 0xfb, 0x43, 0x3d, 0x24, 0x10, 0x66, + 0xfd, 0x9c, 0x6a, 0x36, 0xa5, 0x58, 0xe3, 0x8c, 0x3c, 0xce, 0x24, 0xd0, + 0xeb, 0x94, 0x8b, 0x12, 0x43, 0x9b, 0xe1, 0x3e, 0xf3, 0x1b, 0x9a, 0xf9, + 0x78, 0xd7, 0x4a, 0x8f, 0xa4, 0x23, 0xdc, 0xbc, 0x38, 0x9a, 0x0e, 0xb4, + 0x11, 0x16, 0x44, 0x6b, 0x56, 0x94, 0x07, 0xe6, 0xc8, 0x61, 0x7c, 0xd6, + 0xfc, 0x98, 0x7c, 0x67, 0xcd, 0xf7, 0x1b, 0x5a, 0xc6, 0x11, 0x1f, 0x85, + 0xaf, 0xe6, 0xfe, 0xa5, 0xea, 0xd8, 0xdc, 0xb4, 0x8a, 0x97, 0x7e, 0xc8, + 0x3c, 0x63, 0xa1, 0xdb, 0xc0, 0xc1, 0xae, 0xb2, 0xa3, 0x36, 0xa7, 0xa5, + 0x73, 0xb2, 0xdf, 0x10, 0x4f, 0x86, 0xc5, 0x4d, 0x47, 0x56, 0x16, 0xcf, + 0xc6, 0x9c, 0x24, 0x9a, 0x72, 0x69, 0x44, 0x85, 0x29, 0x34, 0xe5, 0xb5, + 0x73, 0xea, 0x86, 0xde, 0xde, 0xd9, 0x8f, 0x88, 0x3f, 0xe5, 0x39, 0x55, + 0xf7, 0xe6, 0x91, 0xf6, 0xa6, 0xe4, 0x45, 0x06, 0x55, 0xc4, 0x6d, 0x56, + 0xc5, 0xf2, 0x4a, 0x05, 0x69, 0xa6, 0x8d, 0xb5, 0x97, 0xe6, 0xe8, 0x50, + 0x42, 0x0e, 0x8f, 0x1e, 0x5f, 0x22, 0x3d, 0x5f, 0xfe, 0x03, 0xa0, 0xd3, + 0x59, 0x67, 0xc4, 0x25, 0xdf, 0x98, 0xbe, 0xd5, 0xf3, 0x9e, 0xfa, 0x5c, + 0xe5, 0x74, 0x85, 0xc1, 0x35, 0xa7, 0x92, 0xa8, 0x26, 0xb4, 0xc5, 0xa4, + 0xfb, 0xf8, 0x88, 0x2d, 0x3a, 0x71, 0xd8, 0xee, 0xe2, 0x84, 0xa0, 0x70, + 0xbe, 0xf2, 0x9c, 0xc5, 0x4f, 0xa6, 0x60, 0xf4, 0xc0, 0xfc, 0x1e, 0x3a, + 0xa9, 0x11, 0x99, 0xd8, 0x37, 0x09, 0xa6, 0x6e, 0x19, 0x4e, 0x80, 0x1d, + 0x42, 0xb1, 0x9d, 0x75, 0x9d, 0xf2, 0xf5, 0x00, 0x6b, 0x24, 0x8a, 0x59, + 0xfc, 0x10, 0x4e, 0x89, 0x26, 0x18, 0xfc, 0x5a, 0x87, 0x91, 0xe0, 0x28, + 0x5b, 0x50, 0x22, 0xec, 0x67, 0xd5, 0x6b, 0xf5, 0x41, 0xf8, 0x69, 0xf5, + 0xee, 0x9b, 0x92, 0x4e, 0x94, 0xe8, 0x8d, 0x4a, 0x9f, 0xbd, 0x41, 0x26, + 0xac, 0xa0, 0x84, 0x23, 0xef, 0xd6, 0xb7, 0xb6, 0x7e, 0xb0, 0xac, 0x2b, + 0xdc, 0x7b, 0x75, 0xfc, 0xf8, 0xbf, 0x5a, 0x50, 0xf1, 0xd8, 0xb4, 0x1e, + 0x0c, 0x51, 0x24, 0x8b, 0x0d, 0xb6, 0xec, 0x31, 0x1f, 0x79, 0xa0, 0xda, + 0x93, 0x90, 0xc8, 0x1c, 0xc0, 0x0f, 0xb3, 0x4a, 0x1c, 0xaa, 0x5b, 0xa3, + 0x0d, 0xd3, 0x4a, 0x91, 0xed, 0xd6, 0x61, 0x44, 0xf8, 0x60, 0xfd, 0x32, + 0x89, 0x48, 0xd1, 0x75, 0x5d, 0xdf, 0xca, 0x12, 0xa3, 0x86, 0x9e, 0xe5, + 0xf1, 0xd4, 0xf8, 0x34, 0xb0, 0x4b, 0x60, 0x51, 0x39, 0x2b, 0xbb, 0x8a, + 0xa8, 0xf5, 0x6c, 0xf0, 0x21, 0x71, 0x6d, 0x17, 0xae, 0x4a, 0xb3, 0xad, + 0x69, 0x05, 0x37, 0x70, 0xa7, 0x6c, 0x4c, 0x0c, 0x97, 0x33, 0x5e, 0x6f, + 0x16, 0x72, 0x28, 0x2e, 0x52, 0xb2, 0x22, 0x63, 0x06, 0xfc, 0x5e, 0x83, + 0x6e, 0xe4, 0x14, 0xfb, 0xf4, 0x90, 0x5e, 0xce, 0x5b, 0x97, 0x9f, 0x74, + 0xee, 0xaf, 0x38, 0x93, 0xc3, 0x2f, 0x55, 0x70, 0x29, 0x2d, 0x50, 0xb7, + 0xcb, 0x2d, 0x73, 0xed, 0xcb, 0x53, 0x01, 0xce, 0x75, 0xd5, 0x05, 0x51, + 0x09, 0x7a, 0x48, 0x9a, 0x17, 0xd2, 0xc6, 0x4b, 0x54, 0xcc, 0x41, 0x38, + 0xda, 0x45, 0x04, 0x9d, 0x0c, 0x83, 0xc5, 0x9d, 0xa2, 0xe3, 0xdd, 0x24, + 0x34, 0xa6, 0xd5, 0x55, 0x6c, 0x61, 0xc4, 0xe0, 0xfe, 0x57, 0x7a, 0x71, + 0x87, 0xfc, 0x65, 0xd2, 0x9f, 0xde, 0xbb, 0xd2, 0x3a, 0xad, 0xc4, 0xe6, + 0x77, 0x45, 0x68, 0x60, 0x91, 0x6a, 0xa1, 0xfd, 0x84, 0x87, 0xa7, 0x33, + 0xfe, 0xac, 0x5d, 0xfc, 0xcf, 0x52, 0x58, 0xb9, 0xbc, 0x88, 0x7c, 0x6b, + 0x22, 0xb7, 0x7f, 0xc9, 0x3d, 0x4b, 0x72, 0x83, 0x15, 0x9b, 0x43, 0x08, + 0xbe, 0xe6, 0xaf, 0xf0, 0x3c, 0x26, 0x6a, 0xea, 0x44, 0xba, 0x19, 0x4d, + 0xf0, 0x6e, 0x9b, 0xf9, 0x9e, 0x04, 0x3b, 0x84, 0x82, 0xa5, 0x8a, 0xd9, + 0x9b, 0x87, 0x9a, 0x49, 0x24, 0xd0, 0xde, 0x5d, 0x24, 0x53, 0xa1, 0xf0, + 0xec, 0x83, 0xbc, 0x0c, 0xc8, 0xf6, 0x5b, 0x03, 0x9f, 0xf2, 0x54, 0x1e, + 0x02, 0x6e, 0x8e, 0x16, 0xe1, 0x6d, 0xaa, 0x5d, 0x60, 0x33, 0x57, 0x41, + 0x82, 0xa8, 0x0f, 0xe9, 0x51, 0x81, 0xf4, 0xf0, 0x80, 0x07, 0xbd, 0xff, + 0x39, 0xd4, 0x27, 0x3e, 0xd6, 0xef, 0x7c, 0x9f, 0x55, 0x19, 0x7f, 0x08, + 0x21, 0x9e, 0x64, 0xbb, 0x9e, 0x70, 0x20, 0x28, 0x29, 0x5f, 0x52, 0x8f, + 0x29, 0x76, 0x18, 0x93, 0x9c, 0x6a, 0x57, 0x6b, 0x07, 0x8a, 0x6c, 0xfb, + 0x02, 0x9d, 0x71, 0xa2, 0xfa, 0xac, 0xcb, 0xe5, 0xc6, 0x1e, 0x70, 0xca, + 0x92, 0x35, 0x9b, 0xb8, 0xf6, 0xdd, 0x55, 0x93, 0xd1, 0xa4, 0x78, 0x42, + 0x34, 0xe0, 0xec, 0x6e, 0xa1, 0xbd, 0xb7, 0x26, 0x54, 0x95, 0x49, 0xba, + 0x45, 0x44, 0x50, 0xd2, 0x51, 0xcb, 0xc1, 0x22, 0xf8, 0x01, 0x32, 0x15, + 0x36, 0xb2, 0xcd, 0xf3, 0x55, 0x23, 0x91, 0x9e, 0xa6, 0x4e, 0x07, 0x26, + 0x2d, 0x78, 0x50, 0xd6, 0xdc, 0xb5, 0x8f, 0x67, 0x60, 0x4b, 0x45, 0x4b, + 0x29, 0xfc, 0xdf, 0x9a, 0x33, 0x4c, 0xf7, 0x1e, 0x75, 0x1d, 0xab, 0x91, + 0xda, 0xb5, 0xcd, 0xfc, 0xd9, 0xa3, 0xdf, 0xc6, 0x1e, 0x2e, 0x11, 0x3f, + 0x79, 0x80, 0xd8, 0xd4, 0x60, 0x25, 0x66, 0x1a, 0x6b, 0x11, 0x89, 0xa0, + 0x6e, 0x1f, 0xb8, 0x54, 0x4c, 0x86, 0x36, 0x0b, 0x72, 0xda, 0x20, 0xec, + 0x0a, 0x52, 0xdd, 0x67, 0x64, 0xbc, 0x9e, 0x61, 0x9c, 0x6b, 0x27, 0x1f, + 0x62, 0xd8, 0xf2, 0x95, 0x35, 0xb6, 0x73, 0x52, 0x47, 0x57, 0xfe, 0xd7, + 0xdd, 0xf4, 0x6c, 0x91, 0xec, 0x9f, 0xaa, 0x9a, 0xa9, 0xc8, 0x83, 0x65, + 0x51, 0x15, 0x94, 0xcd, 0xf2, 0x16, 0x0c, 0xdf, 0x79, 0xc3, 0xa7, 0x1f, + 0xda, 0x45, 0xba, 0x6a, 0xe3, 0x4b, 0xce, 0xb7, 0x58, 0x21, 0xf8, 0xb1, + 0x6a, 0xf0, 0xa3, 0xa4, 0x72, 0x28, 0x6b, 0x94, 0xeb, 0xd3, 0x78, 0xa2, + 0x6a, 0x73, 0xa8, 0xe5, 0x86, 0x30, 0xb5, 0xca, 0x00, 0xc5, 0xcd, 0x72, + 0x08, 0xf0, 0x87, 0xc4, 0xe8, 0xac, 0x46, 0xcd, 0x20, 0xd2, 0x16, 0xcc, + 0x2b, 0xc8, 0x63, 0x04, 0x51, 0x5f, 0x08, 0x4d, 0xa7, 0x47, 0xf6, 0xcb, + 0x68, 0x28, 0x54, 0xdd, 0x1f, 0xa2, 0x6c, 0xc4, 0x41, 0x31, 0x81, 0x4e, + 0x6d, 0x11, 0x20, 0xba, 0xfa, 0xa2, 0x78, 0xa0, 0x28, 0x4b, 0x60, 0x4a, + 0xe3, 0x51, 0x1d, 0x89, 0xd6, 0x8a, 0xc4, 0xda, 0xf6, 0x1f, 0x0d, 0xb1, + 0x86, 0xe9, 0xf2, 0x10, 0x67, 0xeb, 0xec, 0xdb, 0x5d, 0x58, 0x7d, 0xd7, + 0xb7, 0x3e, 0x4b, 0x40, 0xd6, 0xb2, 0x67, 0x22, 0xf6, 0x39, 0xed, 0x60, + 0x73, 0x54, 0x5e, 0xc2, 0x90, 0x7e, 0x75, 0xb7, 0x34, 0x80, 0xb6, 0x46, + 0x2f, 0x29, 0x7b, 0xe7, 0x93, 0x46, 0x24, 0xfe, 0xe4, 0x1d, 0x77, 0xbc, + 0x3e, 0x3d, 0x3e, 0x5e, 0x95, 0xd3, 0x18, 0x83, 0xa2, 0x9e, 0x95, 0xb1, + 0x86, 0x01, 0x2b, 0x68, 0x69, 0xf5, 0xba, 0x80, 0x2b, 0x41, 0x99, 0xc1, + 0x5e, 0x56, 0x7d, 0x5c, 0xa9, 0xf6, 0x60, 0xad, 0x13, 0x41, 0x5f, 0xd1, + 0xa0, 0x5e, 0x32, 0x71, 0x15, 0x02, 0xbe, 0x21, 0x9c, 0x8e, 0xdb, 0x66, + 0xa9, 0x57, 0x22, 0x5b, 0x0e, 0x0b, 0x7d, 0xe4, 0x9c, 0x5c, 0x82, 0x1d, + 0x3e, 0x51, 0x37, 0xd8, 0xde, 0xae, 0xbf, 0xe5, 0x72, 0xf9, 0xb5, 0xe4, + 0x0a, 0xe2, 0x50, 0x91, 0xb8, 0xcb, 0x29, 0xb6, 0x75, 0x4a, 0xe5, 0x93, + 0x4d, 0x6a, 0xd5, 0x71, 0x23, 0xa5, 0x60, 0x98, 0x35, 0x13, 0x17, 0x9c, + 0x3d, 0xf5, 0x08, 0x18, 0xd4, 0xbc, 0xf8, 0x7e, 0x26, 0x18, 0x73, 0x7e, + 0x90, 0x8b, 0x1a, 0x8f, 0x3b, 0xae, 0xe9, 0x7a, 0x1f, 0xfd, 0xa8, 0xa2, + 0x82, 0x95, 0x17, 0xca, 0x0e, 0x48, 0x47, 0x9d, 0xf0, 0xab, 0xe0, 0xf7, + 0x4a, 0xbf, 0x73, 0x46, 0x09, 0x03, 0x09, 0xa6, 0x46, 0xa5, 0xb4, 0x15, + 0x3e, 0x7d, 0xfe, 0x1e, 0xfa, 0x47, 0x0a, 0x89, 0xb1, 0x1b, 0x96, 0x51, + 0x8b, 0x25, 0x44, 0xca, 0xf0, 0xda, 0x09, 0x55, 0x20, 0x87, 0xbb, 0x60, + 0x5f, 0x27, 0xfc, 0x5e, 0x0a, 0xd9, 0xa4, 0xfc, 0x35, 0x8d, 0x84, 0x1e, + 0xe1, 0xda, 0x63, 0xba, 0xe7, 0x82, 0x16, 0x3b, 0xdd, 0x9f, 0x11, 0x31, + 0xb5, 0x8f, 0x29, 0x0d, 0x9f, 0xce, 0x8d, 0xbd, 0x48, 0x07, 0xc5, 0x1b, + 0xf7, 0xa2, 0x22, 0xed, 0x5a, 0x9d, 0x70, 0xf3, 0xc1, 0x97, 0xe8, 0xcc, + 0x91, 0x4b, 0x36, 0x2b, 0x09, 0x09, 0xea, 0x86, 0x40, 0x41, 0xe6, 0x04, + 0xb0, 0x04, 0x2e, 0x85, 0xa2, 0xc3, 0xd2, 0xdf, 0x20, 0xaa, 0x45, 0x4b, + 0x28, 0xf6, 0xa0, 0xb7, 0x68, 0xe3, 0x91, 0x7a, 0x78, 0x32, 0x43, 0x2f, + 0xd6, 0x9c, 0x57, 0x4d, 0x06, 0x81, 0xa0, 0xde, 0x04, 0x08, 0xff, 0xf8, + 0x25, 0xfa, 0xa6, 0xc6, 0xdf, 0x00, 0xd4, 0x99, 0x63, 0x39, 0xd2, 0xb9, + 0x51, 0xf5, 0x3d, 0x54, 0x48, 0x9a, 0x24, 0x3b, 0x65, 0x31, 0xb1, 0x8b, + 0x35, 0x80, 0xba, 0xee, 0xc5, 0x19, 0x49, 0xc8, 0xbd, 0xe7, 0x53, 0x68, + 0x20, 0x7d, 0x87, 0x23, 0xb1, 0x79, 0xd8, 0x12, 0x82, 0xb0, 0x11, 0xb6, + 0x78, 0x3f, 0x15, 0xad, 0xd8, 0xbc, 0xab, 0x36, 0xa0, 0x8f, 0x53, 0xf6, + 0x29, 0x87, 0x64, 0x56, 0xe9, 0x38, 0x2c, 0x7c, 0xc7, 0x66, 0x05, 0xb1, + 0x28, 0x7f, 0x06, 0xcc, 0x7c, 0x83, 0x84, 0x31, 0xc5, 0x7c, 0x14, 0x74, + 0xa9, 0xe5, 0xc9, 0x23, 0xcf, 0x14, 0xb7, 0x79, 0x46, 0x38, 0x70, 0x14, + 0x59, 0x38, 0x6d, 0xc0, 0xb0, 0xef, 0x30, 0x0a, 0x2e, 0xae, 0xf9, 0x4c, + 0x90, 0xcf, 0x32, 0x24, 0x29, 0xfe, 0x29, 0x75, 0x75, 0x6a, 0x14, 0xb7, + 0x21, 0xc2, 0x82, 0xa1, 0xb9, 0xfc, 0xf3, 0x9e, 0xe2, 0xa2, 0xb6, 0xcf, + 0x4e, 0x4f, 0xc8, 0xe9, 0x8a, 0x50, 0x6d, 0xd6, 0x9b, 0x35, 0x34, 0x46, + 0xfa, 0xb8, 0x4a, 0x7c, 0x7d, 0x8d, 0x16, 0x5d, 0x01, 0x7c, 0x2c, 0xce, + 0x4e, 0x9b, 0xf4, 0x34, 0x3b, 0xde, 0x96, 0xc6, 0x51, 0xe1, 0x6b, 0x23, + 0x9f, 0xee, 0xc1, 0x27, 0xe3, 0xb1, 0xa6, 0x2a, 0xc6, 0xb2, 0x08, 0xbf, + 0x39, 0x45, 0x64, 0x8b, 0xa3, 0xa5, 0x02, 0xb6, 0x11, 0x51, 0x68, 0x39, + 0x1c, 0xcd, 0x5c, 0xa9, 0x2a, 0x61, 0xa8, 0x8c, 0x04, 0xce, 0x40, 0x66, + 0x0f, 0x1e, 0x26, 0x04, 0x0f, 0x11, 0x06, 0xee, 0x41, 0x1c, 0x81, 0xb0, + 0x35, 0x86, 0x68, 0x27, 0x38, 0xe9, 0x7b, 0xcd, 0xd7, 0x82, 0x96, 0xa2, + 0x26, 0x56, 0x5a, 0x32, 0x5a, 0xe7, 0xfe, 0x16, 0x6a, 0xf8, 0xe5, 0xf1, + 0x3f, 0xd6, 0xec, 0x75, 0x0f, 0x3b, 0x83, 0xf9, 0xdf, 0x75, 0x4c, 0x6f, + 0x5d, 0xa0, 0xba, 0xfb, 0xbb, 0x67, 0x25, 0xe5, 0x14, 0x6c, 0x60, 0x25, + 0x6c, 0x43, 0x92, 0xde, 0xdd, 0xc2, 0x33, 0x31, 0x6f, 0xcc, 0x4f, 0x06, + 0xc1, 0x63, 0x1d, 0xec, 0xdd, 0x87, 0x4d, 0x25, 0xf7, 0x50, 0xd5, 0xe9, + 0xc7, 0x71, 0xc9, 0xa0, 0x50, 0xa4, 0xa4, 0x84, 0x6d, 0x43, 0xfe, 0xc6, + 0x93, 0x50, 0x12, 0x0c, 0x37, 0xbb, 0xc6, 0x13, 0xe4, 0x57, 0x49, 0x36, + 0xe7, 0x8c, 0x2b, 0xcb, 0x83, 0x8d, 0x08, 0x12, 0x2e, 0xf1, 0xf3, 0xe5, + 0x0d, 0xb3, 0x1a, 0x66, 0xbe, 0x91, 0x1e, 0xd2, 0x70, 0xcc, 0x72, 0x13, + 0x91, 0xaf, 0xbd, 0xf2, 0xe8, 0x8b, 0xd5, 0x7d, 0x3c, 0x03, 0x40, 0x41, + 0x3b, 0xbd, 0x7a, 0xd5, 0xa3, 0xd2, 0x0f, 0xa1, 0xdf, 0xb3, 0xf7, 0xc0, + 0xf1, 0xf0, 0x09, 0xd7, 0x8f, 0x6c, 0x7d, 0x39, 0x26, 0xda, 0xda, 0x06, + 0xb6, 0x80, 0x9e, 0xec, 0xa5, 0xea, 0x9c, 0xce, 0xef, 0x1c, 0xbc, 0x77, + 0x3d, 0xb4, 0x0d, 0x64, 0x3b, 0x94, 0xee, 0x15, 0x3c, 0x52, 0x3b, 0x21, + 0xbc, 0xa5, 0x8d, 0x0a, 0x06, 0x39, 0x72, 0x73, 0x51, 0x34, 0x87, 0x38, + 0xfd, 0x42, 0x52, 0x35, 0x75, 0x48, 0xb3, 0xb7, 0xec, 0x76, 0x81, 0x89, + 0x74, 0x91, 0x5b, 0xa9, 0x17, 0x69, 0x1b, 0xe7, 0x34, 0xa6, 0xf8, 0x1f, + 0x32, 0x87, 0x66, 0xe3, 0xd9, 0xef, 0xcb, 0xfe, 0x00, 0xca, 0x76, 0x22, + 0x88, 0x04, 0xda, 0x14, 0xf9, 0xea, 0x36, 0xc8, 0x0f, 0x8f, 0xf0, 0xe8, + 0xf8, 0xbb, 0x77, 0x5c, 0xf7, 0x68, 0x95, 0x8a, 0x58, 0x2b, 0xfa, 0x12, + 0x9f, 0x2a, 0xd9, 0x7d, 0x0b, 0x12, 0x3d, 0x49, 0xe8, 0x43, 0x40, 0x0b, + 0xbf, 0xed, 0x9d, 0x19, 0x74, 0xf0, 0xcc, 0xf4, 0x79, 0xb3, 0x82, 0x0d, + 0x97, 0xa0, 0x19, 0x5b, 0x52, 0xe8, 0x46, 0x5b, 0x89, 0xdc, 0xcf, 0xb6, + 0xe9, 0x14, 0x0c, 0xe1, 0xc5, 0x81, 0x15, 0x5f, 0x4d, 0x0f, 0x16, 0x05, + 0x12, 0x55, 0xa1, 0x4f, 0x4f, 0x13, 0xc9, 0x45, 0x89, 0x14, 0x2b, 0x47, + 0x9e, 0x33, 0x51, 0x71, 0x69, 0x60, 0x89, 0x36, 0x20, 0xce, 0xe7, 0xf5, + 0x4a, 0xba, 0xbe, 0xa3, 0x3d, 0x58, 0x0e, 0x12, 0xab, 0x38, 0x9e, 0xe1, + 0xe0, 0x9f, 0x5c, 0x56, 0x10, 0x2e, 0xc8, 0x88, 0xbf, 0x0a, 0x4e, 0xce, + 0xa3, 0x32, 0xca, 0x66, 0x8b, 0x22, 0xb0, 0x3e, 0xc4, 0x0b, 0x2a, 0x6d, + 0xf7, 0x3c, 0x6e, 0x33, 0x7b, 0x3c, 0xc5, 0x2a, 0xf0, 0xb8, 0xb3, 0xb6, + 0x3e, 0x57, 0x94, 0x25, 0x63, 0x7c, 0xb0, 0xef, 0x69, 0xc4, 0x02, 0x69, + 0xf4, 0x81, 0x1b, 0x6d, 0xcf, 0xca, 0x35, 0x8e, 0x67, 0xdf, 0xcd, 0x4c, + 0x82, 0x2f, 0x8e, 0x5b, 0xd1, 0x05, 0xf7, 0x3a, 0x53, 0x68, 0x3e, 0x4d, + 0x7a, 0xf7, 0x50, 0x53, 0xda, 0x3d, 0xeb, 0x4a, 0x17, 0xa5, 0x26, 0x82, + 0x5e, 0x16, 0x81, 0x8f, 0xa1, 0xb6, 0x4a, 0x76, 0xe8, 0xea, 0xba, 0xf4, + 0x7c, 0x9c, 0x79, 0xb3, 0x20, 0x56, 0xab, 0xa3, 0xe0, 0xf2, 0x9b, 0xde, + 0xec, 0x3e, 0x4c, 0xc6, 0xc1, 0xff, 0x9a, 0x8f, 0x09, 0xa2, 0xe6, 0xec, + 0xb2, 0xc0, 0x16, 0xf7, 0xbc, 0x73, 0x9a, 0x02, 0x34, 0x60, 0xc4, 0xdc, + 0xf4, 0x2f, 0x67, 0xd9, 0x78, 0x46, 0x18, 0x99, 0x00, 0xfc, 0x88, 0xa6, + 0x4d, 0x3f, 0x8f, 0x2a, 0x32, 0xb1, 0xba, 0xfd, 0x68, 0x24, 0x0b, 0x2f, + 0xb2, 0xbe, 0xc6, 0x2b, 0xb8, 0x63, 0x61, 0xe0, 0x3c, 0x36, 0x57, 0xfc, + 0x8b, 0xcb, 0x10, 0x21, 0x37, 0xbb, 0x0b, 0xc4, 0x8b, 0x23, 0x0d, 0x63, + 0x1b, 0x21, 0x99, 0x2f, 0x1d, 0xf8, 0x5a, 0x98, 0xed, 0x4e, 0x8e, 0x31, + 0xf4, 0x6d, 0x6f, 0xb2, 0xaa, 0x84, 0x2e, 0xa2, 0x70, 0x29, 0x57, 0xb0, + 0x65, 0xce, 0xa2, 0x56, 0xf4, 0x50, 0x6c, 0xc1, 0xd0, 0x7a, 0xfd, 0x89, + 0xd1, 0x65, 0x68, 0xb2, 0xb4, 0x48, 0xac, 0x93, 0x28, 0x07, 0xb1, 0xa3, + 0x10, 0x6b, 0x67, 0xf3, 0x3a, 0xaa, 0x42, 0x51, 0x6e, 0xb0, 0x4e, 0x19, + 0x1c, 0x55, 0x24, 0x7f, 0xb5, 0x59, 0x85, 0x6d, 0x45, 0x1b, 0xfe, 0x20, + 0x1c, 0xa3, 0xde, 0x3c, 0x15, 0xd7, 0x30, 0x3e, 0x89, 0x79, 0xe0, 0xab, + 0xa9, 0xaf, 0x69, 0xa6, 0x87, 0x48, 0xf2, 0x7b, 0x97, 0xbd, 0x3c, 0x21, + 0x35, 0x91, 0x9e, 0x60, 0x3e, 0x60, 0x03, 0x87, 0xf2, 0x7a, 0x8c, 0x2a, + 0x9e, 0x5b, 0x3c, 0x74, 0x20, 0x1a, 0xae, 0x71, 0x30, 0x64, 0x6c, 0x6f, + 0x29, 0xb8, 0xa1, 0x08, 0xa2, 0x0a, 0x56, 0xa8, 0x62, 0x6a, 0xad, 0x8a, + 0x48, 0xb0, 0xf3, 0x3d, 0x66, 0xd6, 0xd0, 0xbe, 0x83, 0x49, 0x3e, 0x91, + 0x84, 0xa9, 0xa7, 0xbd, 0x81, 0x70, 0x30, 0xe2, 0x2f, 0x43, 0x59, 0x2d, + 0x7a, 0x34, 0x40, 0x25, 0x63, 0x21, 0x1c, 0x4b, 0x6e, 0x3b, 0x7d, 0xa2, + 0xfe, 0x06, 0x26, 0xf3, 0xe7, 0xeb, 0xb6, 0xf4, 0xe3, 0x71, 0xad, 0xf7, + 0x85, 0xbc, 0x7b, 0xc2, 0xbd, 0x00, 0x1c, 0x02, 0xba, 0xb5, 0x7b, 0x2c, + 0x57, 0x93, 0xc8, 0xfd, 0xd5, 0x6a, 0xca, 0xf8, 0x13, 0xde, 0x59, 0xae, + 0x85, 0x91, 0xb0, 0x9b, 0x86, 0xff, 0xec, 0x07, 0x86, 0xf0, 0x3d, 0x36, + 0xad, 0x3c, 0x91, 0x67, 0x8b, 0x45, 0x81, 0x46, 0xfe, 0xdc, 0x72, 0x78, + 0xbf, 0x0d, 0x9d, 0x7d, 0xc6, 0x43, 0x67, 0xd4, 0xf6, 0x38, 0xf6, 0xc2, + 0x27, 0xc8, 0x2b, 0x57, 0x47, 0x32, 0xa6, 0x09, 0x25, 0x1f, 0xda, 0x85, + 0x32, 0xbe, 0x34, 0xce, 0xda, 0x32, 0x6c, 0x84, 0xdd, 0x59, 0x57, 0x78, + 0xb9, 0x02, 0x4d, 0x65, 0x74, 0xce, 0x9e, 0x77, 0xbb, 0x9f, 0xa3, 0x7d, + 0x59, 0xcc, 0xb6, 0x93, 0xae, 0xf6, 0x7d, 0x16, 0x5b, 0xc5, 0x40, 0x3d, + 0xee, 0x18, 0x16, 0xa1, 0x17, 0x02, 0x07, 0x8d, 0xdf, 0xe5, 0x50, 0x8b, + 0xd5, 0x03, 0x2b, 0x9b, 0x5f, 0x21, 0x34, 0x2d, 0x48, 0x6a, 0x8b, 0xa9, + 0x5e, 0x71, 0x33, 0x6b, 0xa5, 0xc6, 0x48, 0xa8, 0x53, 0x6b, 0xcf, 0xf9, + 0x40, 0xc5, 0xff, 0x72, 0x87, 0xc2, 0x32, 0x17, 0x6b, 0x10, 0x64, 0x5f, + 0x96, 0xf7, 0x50, 0x38, 0x69, 0x49, 0x1c, 0x35, 0x9a, 0x90, 0xf9, 0xc1, + 0xa6, 0x40, 0x5d, 0xe5, 0x9b, 0xcc, 0x83, 0xe7, 0xed, 0x0a, 0xea, 0x53, + 0x3f, 0x41, 0xc6, 0x5b, 0xd9, 0x97, 0x9b, 0xd6, 0x03, 0x8d, 0xc3, 0xff, + 0x18, 0xd7, 0xd2, 0x57, 0x81, 0xe5, 0x5a, 0x11, 0xaa, 0x74, 0x30, 0x2c, + 0x90, 0x7b, 0x2c, 0xb9, 0x19, 0x2e, 0x4b, 0xef, 0xfd, 0x4b, 0xc1, 0x02, + 0x45, 0x8c, 0x5b, 0x25, 0x81, 0xcd, 0xf7, 0x30, 0xfc, 0xb7, 0xd2, 0xd6, + 0x97, 0x1f, 0x95, 0x28, 0x7b, 0x8e, 0x6b, 0x40, 0xfc, 0x2b, 0xe9, 0x09, + 0x34, 0xc3, 0x38, 0x3b, 0x96, 0x0b, 0x51, 0x5f, 0x46, 0x1b, 0x5f, 0x07, + 0x44, 0x85, 0xb7, 0xe6, 0xfc, 0x0a, 0x3b, 0xf3, 0x34, 0x58, 0xce, 0xbc, + 0x59, 0xea, 0x49, 0x0f, 0x71, 0x0d, 0x7f, 0x28, 0xf3, 0x1c, 0x1f, 0x76, + 0x35, 0xa8, 0x28, 0xc0, 0x61, 0xdb, 0x6c, 0xc1, 0xe6, 0x6c, 0x76, 0xae, + 0xf6, 0x51, 0x53, 0xa4, 0x2d, 0xd4, 0x23, 0x04, 0x8d, 0x19, 0xd3, 0x4d, + 0x49, 0xd4, 0x27, 0x8f, 0x38, 0x39, 0xc2, 0xcd, 0xd7, 0x14, 0xec, 0xc1, + 0x25, 0x58, 0x51, 0xf2, 0xa0, 0x0b, 0x98, 0xe3, 0x65, 0xd6, 0x4f, 0x2a, + 0x6a, 0x4b, 0xdb, 0x0a, 0x02, 0x9a, 0xa7, 0x3f, 0x87, 0xc6, 0xc8, 0x31, + 0xa3, 0x6f, 0xcb, 0xa2, 0x38, 0xf1, 0x0a, 0xba, 0x12, 0xe2, 0x1b, 0xc0, + 0xf1, 0xc4, 0xf3, 0x80, 0x41, 0xf5, 0x0b, 0x17, 0x74, 0xdb, 0xba, 0x24, + 0xec, 0xdc, 0xe5, 0x5f, 0xcc, 0x96, 0xc9, 0x06, 0x19, 0x73, 0x5f, 0x0f, + 0x27, 0xf1, 0x93, 0x14, 0x80, 0x8e, 0x48, 0x7e, 0x43, 0x98, 0x5e, 0x6d, + 0x11, 0x34, 0xf4, 0x36, 0xc5, 0x19, 0x70, 0x82, 0x5b, 0x32, 0xec, 0xa7, + 0x6e, 0xaa, 0x86, 0xff, 0xfb, 0x52, 0x0c, 0xba, 0x2b, 0x60, 0x7f, 0x15, + 0xa9, 0xd6, 0xc0, 0x06, 0xad, 0xac, 0x21, 0xb9, 0x85, 0xa6, 0x19, 0x82, + 0xc9, 0xe0, 0xc7, 0xa2, 0xbe, 0x6c, 0x99, 0xe7, 0x7a, 0x74, 0x11, 0xaa, + 0xb9, 0xae, 0x63, 0xfa, 0xad, 0xad, 0x1f, 0x7e, 0x1e, 0x83, 0xb8, 0xd7, + 0x4d, 0xcd, 0xd6, 0x28, 0xae, 0xfd, 0x12, 0x84, 0xf4, 0x25, 0x9c, 0x13, + 0x4d, 0x2b, 0x70, 0x3b, 0x85, 0x5c, 0x48, 0xf4, 0x9a, 0x50, 0x09, 0xd8, + 0xb8, 0x96, 0x36, 0x9f, 0x2a, 0x9a, 0x25, 0x79, 0xe4, 0x56, 0x21, 0xcc, + 0x0e, 0xd3, 0x53, 0x6d, 0xd1, 0x1f, 0x02, 0xca, 0x87, 0x0b, 0xae, 0x7f, + 0x53, 0x81, 0x50, 0xa3, 0x04, 0x92, 0x9c, 0xfa, 0xa4, 0x8c, 0x71, 0x30, + 0x09, 0xe3, 0x64, 0x4b, 0xa6, 0x1f, 0x6f, 0x8b, 0x52, 0x95, 0xef, 0x9a, + 0x38, 0x8c, 0xdc, 0xa8, 0xbb, 0x7b, 0x72, 0xc1, 0xba, 0xa7, 0x4d, 0x29, + 0xf3, 0x4a, 0x59, 0x91, 0x44, 0xa0, 0x30, 0xda, 0x1c, 0x1f, 0xd0, 0xe6, + 0x15, 0xa9, 0xfb, 0xe1, 0x25, 0xe8, 0xa2, 0x62, 0x62, 0xb6, 0x5b, 0xdb, + 0xb8, 0x60, 0x9c, 0x70, 0xf5, 0x61, 0x1a, 0xc6, 0x55, 0x0a, 0x7f, 0x35, + 0xa0, 0x2b, 0xbb, 0x7b, 0x2e, 0x19, 0xd7, 0x81, 0xe5, 0x04, 0xd9, 0x13, + 0xb3, 0x02, 0x6b, 0x5a, 0xbd, 0x62, 0xe5, 0x44, 0x05, 0x67, 0x60, 0x40, + 0xbd, 0xe0, 0x2d, 0xef, 0x71, 0x1c, 0xce, 0x0a, 0x0e, 0x40, 0x9c, 0xfa, + 0xac, 0x5b, 0x5f, 0xef, 0x1f, 0xa1, 0x30, 0xee, 0xe0, 0x7e, 0xad, 0x49, + 0x43, 0xf3, 0x05, 0x44, 0xad, 0x98, 0x46, 0xd2, 0x50, 0x1f, 0x6e, 0x61, + 0x12, 0x19, 0x43, 0x4f, 0x67, 0x33, 0x1d, 0x2c, 0x1f, 0x9d, 0x2b, 0x81, + 0x88, 0x7b, 0x3a, 0x63, 0x50, 0x42, 0x47, 0x82, 0x38, 0xa4, 0x5e, 0xa7, + 0x35, 0xee, 0x1b, 0xac, 0x9c, 0xad, 0x3f, 0x47, 0x6e, 0xd4, 0xdd, 0xcc, + 0x63, 0x61, 0x44, 0x20, 0xb6, 0x88, 0x49, 0x84, 0x14, 0x24, 0x70, 0xd6, + 0x98, 0x43, 0xb5, 0xa5, 0xb7, 0x80, 0x05, 0x60, 0x00, 0x5a, 0xb8, 0xd7, + 0x2d, 0xbc, 0x03, 0xed, 0xad, 0xd8, 0xaa, 0xdc, 0xcc, 0xff, 0x79, 0xec, + 0x8b, 0x66, 0x95, 0x4e, 0x44, 0x1f, 0xa7, 0x63, 0xe6, 0x1f, 0xdc, 0x1f, + 0x7e, 0x1d, 0x6f, 0xe5, 0x13, 0x5a, 0x77, 0xfc, 0x3c, 0x59, 0xdb, 0xaa, + 0x6a, 0xbd, 0xaf, 0xd0, 0xca, 0x62, 0x70, 0x60, 0x83, 0x5a, 0xbc, 0x44, + 0xbf, 0x56, 0x9d, 0x99, 0x2a, 0x86, 0x55, 0x47, 0xaf, 0x3f, 0x20, 0x18, + 0xe4, 0x51, 0xd1, 0x11, 0x4b, 0xc4, 0x9c, 0xbf, 0x7c, 0x34, 0x16, 0x10, + 0xe2, 0x99, 0x6a, 0x3e, 0x9c, 0xb5, 0x6c, 0x96, 0xea, 0xe7, 0x12, 0xac, + 0xfb, 0xae, 0x77, 0xe8, 0x67, 0x86, 0xe6, 0x7c, 0xce, 0x31, 0x20, 0x02, + 0xfe, 0x16, 0x72, 0x00, 0x7e, 0x83, 0xcc, 0xcb, 0x8b, 0xc5, 0xf6, 0x5b, + 0x43, 0x37, 0xc2, 0x55, 0x9a, 0xdd, 0x5f, 0x32, 0x6c, 0x82, 0xbf, 0x75, + 0x96, 0x08, 0x59, 0x17, 0xe3, 0x45, 0xa0, 0xc0, 0x39, 0xd4, 0x95, 0xca, + 0x77, 0x34, 0x7d, 0x50, 0x7a, 0x50, 0xc0, 0xd9, 0xb7, 0x34, 0x0f, 0xf3, + 0x8b, 0xde, 0xff, 0x60, 0x98, 0x17, 0xe6, 0x5a, 0x01, 0xf7, 0x9a, 0xda, + 0x7f, 0x47, 0x4e, 0x4d, 0x11, 0xe7, 0x38, 0x0b, 0x49, 0x20, 0x92, 0x84, + 0xeb, 0xfd, 0x93, 0x02, 0x94, 0xd5, 0xeb, 0xbf, 0x76, 0x2f, 0x97, 0xe7, + 0xdc, 0x41, 0xe4, 0x7a, 0xdc, 0xe5, 0x6b, 0xf3, 0x79, 0x14, 0x95, 0xb2, + 0x20, 0x9a, 0x37, 0x14, 0xe3, 0xda, 0x06, 0x32, 0xca, 0xe6, 0x47, 0x31, + 0x93, 0x65, 0x1b, 0x8a, 0x30, 0x14, 0x04, 0x18, 0xc4, 0x17, 0x80, 0x34, + 0xf9, 0x29, 0x32, 0x0a, 0x45, 0x8c, 0x8f, 0xba, 0xa8, 0xd3, 0xa6, 0x39, + 0xcb, 0x38, 0x02, 0x75, 0xa3, 0x95, 0x6b, 0xf5, 0xca, 0xbc, 0x17, 0x4f, + 0x93, 0x77, 0x2b, 0x1a, 0x68, 0xde, 0x97, 0xb4, 0x6a, 0xf1, 0xea, 0x44, + 0x09, 0x60, 0x60, 0x8f, 0x3e, 0x37, 0x29, 0xbf, 0xaa, 0xd4, 0xf9, 0x32, + 0x11, 0x6d, 0xb3, 0xfb, 0x8b, 0x2a, 0x39, 0xc3, 0x2f, 0xf8, 0x4c, 0xb0, + 0xdf, 0x90, 0x41, 0x1b, 0xd7, 0x7d, 0x28, 0x57, 0xb5, 0x4c, 0xc9, 0x28, + 0x47, 0x72, 0x25, 0x4a, 0x4c, 0xe3, 0x77, 0x0e, 0xb8, 0x4c, 0xa4, 0xc8, + 0x77, 0x77, 0xbb, 0xd0, 0x5a, 0xe5, 0xf6, 0xe0, 0xc9, 0xa9, 0xc2, 0xb1, + 0xfb, 0x35, 0x95, 0xe2, 0x10, 0xf9, 0xfd, 0x9e, 0x16, 0x0e, 0x35, 0xec, + 0x88, 0xad, 0xe4, 0xcc, 0xcb, 0x90, 0xf6, 0x60, 0xf4, 0xf6, 0x52, 0xa9, + 0xbc, 0x4d, 0xbf, 0x23, 0xdc, 0xa7, 0x27, 0x3f, 0xa5, 0x0d, 0x6e, 0xd7, + 0x43, 0x83, 0x2a, 0xb7, 0x06, 0x08, 0xec, 0x14, 0x9c, 0xee, 0x85, 0xad, + 0xff, 0x30, 0x5e, 0x15, 0x6e, 0x91, 0x1d, 0x04, 0x23, 0x83, 0x9d, 0x75, + 0x72, 0xf4, 0x0e, 0x8f, 0x02, 0xd3, 0x5f, 0xf0, 0x82, 0xa5, 0xc7, 0x95, + 0x4e, 0xaa, 0x65, 0x4c, 0xe9, 0x53, 0xb1, 0x87, 0x6e, 0xab, 0xfa, 0x8a, + 0x99, 0x9e, 0x1b, 0x25, 0xe8, 0x54, 0xcc, 0x3a, 0xed, 0xd1, 0x4d, 0xda, + 0x31, 0x9a, 0xb8, 0x13, 0xfe, 0xb5, 0x3c, 0x46, 0xed, 0xff, 0xaf, 0xcc, + 0xf3, 0xc5, 0xa1, 0xcd, 0x87, 0xa9, 0xad, 0x5c, 0xbf, 0x21, 0x90, 0x23, + 0x15, 0x36, 0x26, 0x50, 0xe2, 0x47, 0x50, 0x24, 0x5f, 0x0a, 0x06, 0xf0, + 0x28, 0xc3, 0x50, 0x34, 0xa8, 0xea, 0x69, 0xd0, 0x2f, 0xf6, 0x46, 0xb3, + 0xab, 0x5a, 0xea, 0x73, 0xa2, 0xe8, 0xf8, 0xff, 0x33, 0x12, 0x15, 0xfe, + 0x82, 0xaf, 0xca, 0xdf, 0xe7, 0x06, 0xad, 0x95, 0x36, 0xe4, 0xd9, 0x32, + 0x7a, 0x7f, 0x18, 0xcc, 0x6e, 0x30, 0x09, 0x2f, 0x88, 0xa5, 0x9f, 0x43, + 0x05, 0x77, 0x70, 0x4b, 0xe7, 0x9f, 0x16, 0x0c, 0x0d, 0x4d, 0x1c, 0xb4, + 0xfe, 0x8d, 0x22, 0x6a, 0x38, 0xa9, 0xe2, 0xe6, 0x8f, 0x01, 0xbc, 0xa2, + 0x53, 0x4b, 0x2b, 0xa2, 0xb0, 0x39, 0x39, 0x31, 0x8e, 0xcc, 0x67, 0x7a, + 0x72, 0x8b, 0x5e, 0x45, 0x0d, 0x5e, 0x81, 0x10, 0xaf, 0x03, 0x79, 0xd7, + 0xbc, 0x61, 0xe5, 0x51, 0xa8, 0x2e, 0xb2, 0xad, 0x5c, 0xa5, 0x29, 0xe1, + 0xa9, 0x5f, 0x2d, 0xe8, 0x41, 0xea, 0x27, 0xd4, 0x36, 0xa0, 0x7e, 0xb0, + 0xad, 0x91, 0xc7, 0x40, 0x2b, 0x35, 0xb8, 0xce, 0x1b, 0x61, 0xa2, 0x14, + 0x1c, 0x09, 0x23, 0x69, 0xf8, 0xfd, 0x11, 0x9e, 0x00, 0x70, 0x17, 0xf0, + 0x0c, 0xa6, 0xff, 0xed, 0x39, 0x89, 0xe3, 0xcc, 0x15, 0x6e, 0x91, 0xd6, + 0x4c, 0xe6, 0x20, 0x7f, 0x03, 0x5e, 0x90, 0x2e, 0x1a, 0xd9, 0x31, 0x2d, + 0xc8, 0xf5, 0x34, 0x15, 0x33, 0xa1, 0x88, 0x57, 0xb2, 0xe9, 0xe2, 0xee, + 0x53, 0xb8, 0x10, 0x92, 0xb2, 0xf1, 0x1e, 0x3e, 0x4e, 0xbf, 0x2d, 0xa8, + 0x92, 0xee, 0xc5, 0xe4, 0x3f, 0x05, 0x93, 0x80, 0xf1, 0xc7, 0xc0, 0x64, + 0x0b, 0xe3, 0x88, 0x0f, 0x47, 0xcc, 0x48, 0x1e, 0x85, 0x63, 0x58, 0x7f, + 0xf6, 0xe0, 0x16, 0x34, 0xed, 0x30, 0xd6, 0xb2, 0xb2, 0x7f, 0xc6, 0xcf, + 0x24, 0x47, 0x54, 0xe9, 0x6f, 0x35, 0x75, 0x8e, 0x53, 0x91, 0x58, 0x63, + 0x3f, 0x31, 0x18, 0x4f, 0x26, 0xab, 0x4b, 0xc6, 0x8e, 0xcc, 0x63, 0x22, + 0x19, 0x09, 0x8f, 0x21, 0x76, 0x8f, 0x3d, 0x46, 0xd0, 0x57, 0x6a, 0x43, + 0x7f, 0x98, 0x8d, 0x6a, 0xe5, 0x18, 0x28, 0x9b, 0xb5, 0xe0, 0x3c, 0x8d, + 0xf8, 0x02, 0xbf, 0x52, 0xd7, 0xa8, 0xa0, 0x29, 0xf3, 0xd8, 0x9d, 0x43, + 0x4b, 0x2e, 0x28, 0x18, 0x6d, 0xda, 0x0e, 0xe2, 0xc5, 0xab, 0x85, 0x0d, + 0x34, 0x7a, 0x54, 0xda, 0x76, 0x65, 0x14, 0x15, 0xad, 0xa4, 0x3c, 0xff, + 0xa5, 0xaf, 0xaf, 0x24, 0x92, 0x4d, 0x79, 0x60, 0x1e, 0x4d, 0xbf, 0xa9, + 0x8a, 0x46, 0x7e, 0x27, 0x53, 0x0e, 0x2c, 0x52, 0xbc, 0x72, 0xf1, 0xb4, + 0x31, 0x5e, 0xb5, 0x0a, 0x48, 0x02, 0xc7, 0x71, 0x6e, 0x8e, 0xe5, 0xd9, + 0xe4, 0xe9, 0xf2, 0x69, 0xfa, 0x7b, 0x9a, 0xa7, 0x0d, 0x16, 0x57, 0x86, + 0xc2, 0xaf, 0x78, 0x5f, 0xc2, 0x3f, 0x1b, 0x7e, 0x16, 0x25, 0x59, 0x99, + 0x7a, 0xd0, 0x9f, 0x78, 0x18, 0x4b, 0x26, 0x63, 0x30, 0x91, 0x45, 0x2e, + 0x1a, 0xb2, 0x2b, 0x8c, 0x66, 0x13, 0xd1, 0xbb, 0xbb, 0x96, 0xd9, 0x52, + 0xf1, 0x69, 0xcb, 0x09, 0x0b, 0xda, 0xc2, 0xb4, 0xd3, 0x47, 0xe8, 0x7e, + 0xa2, 0xfc, 0x02, 0x3a, 0xfb, 0x46, 0x62, 0x14, 0x30, 0x80, 0x0a, 0x65, + 0x81, 0x1d, 0x89, 0x2f, 0xd6, 0xae, 0xae, 0xd4, 0xad, 0x61, 0xf5, 0x60, + 0xd2, 0xc5, 0xf8, 0xca, 0x46, 0x1b, 0x3b, 0x13, 0x51, 0x84, 0xfb, 0x2c, + 0x3d, 0x61, 0xb5, 0xdb, 0x0a, 0xe7, 0xe9, 0xaf, 0x6e, 0x11, 0x1f, 0x8f, + 0x04, 0xe6, 0xbb, 0x89, 0x3a, 0xb1, 0x81, 0xf8, 0x23, 0x85, 0xd0, 0xea, + 0x3e, 0x08, 0xad, 0x8a, 0xb0, 0x04, 0xd9, 0x05, 0x45, 0x48, 0xaf, 0xad, + 0x29, 0xa2, 0x58, 0xe9, 0xbf, 0xd9, 0x5e, 0x96, 0x16, 0xbf, 0x0e, 0x1c, + 0x03, 0x33, 0x4e, 0x9e, 0xbd, 0x33, 0x68, 0x50, 0xc6, 0xa6, 0x89, 0x0c, + 0x42, 0xb9, 0x9e, 0x98, 0xd6, 0x9d, 0xa2, 0x6c, 0x61, 0x8e, 0xc6, 0xda, + 0x9d, 0xf1, 0x6a, 0x84, 0xc8, 0xeb, 0x15, 0x98, 0xd2, 0x16, 0xa0, 0xa1, + 0xe7, 0x43, 0x72, 0x8f, 0xa1, 0x75, 0x24, 0x44, 0x3c, 0x9b, 0x0a, 0xed, + 0x80, 0x59, 0x4a, 0x6e, 0xed, 0xe7, 0xb7, 0x65, 0xc0, 0x87, 0xca, 0xad, + 0x0d, 0xc0, 0x2e, 0x66, 0x84, 0x7d, 0x7d, 0xfe, 0xe0, 0x2d, 0x42, 0x73, + 0xdd, 0xb4, 0x95, 0x93, 0x16, 0x46, 0x4d, 0x2c, 0xdc, 0xb6, 0x75, 0x85, + 0x54, 0x0d, 0xec, 0x6b, 0x19, 0xb1, 0x69, 0x00, 0x24, 0x6c, 0x73, 0xe8, + 0xcd, 0x7d, 0x1e, 0xf6, 0xbb, 0x09, 0x77, 0x51, 0xe1, 0x18, 0x45, 0xe6, + 0xa5, 0xe3, 0x90, 0x5a, 0xfd, 0x66, 0xf2, 0x57, 0x4c, 0xcd, 0x82, 0x78, + 0x5f, 0xea, 0xbb, 0xc6, 0x45, 0xf7, 0x6e, 0x0c, 0xa3, 0x62, 0x84, 0xdc, + 0x61, 0xa1, 0x41, 0x15, 0xc0, 0x4c, 0x2f, 0xdd, 0xb9, 0x70, 0xc5, 0xb9, + 0x77, 0x07, 0xab, 0xbe, 0x29, 0x31, 0x34, 0xf4, 0x71, 0xf1, 0x2d, 0xfa, + 0x2e, 0x53, 0x06, 0x24, 0xc3, 0x3c, 0xf8, 0x1e, 0xe1, 0x1e, 0xc0, 0x41, + 0xce, 0xb7, 0x3e, 0xe3, 0x5c, 0x98, 0x4b, 0x36, 0x0b, 0x24, 0xd4, 0xb2, + 0x2a, 0xdc, 0x2b, 0xd2, 0x9b, 0xb6, 0xa3, 0x9c, 0x45, 0x67, 0x53, 0x64, + 0xfe, 0x81, 0xf7, 0x76, 0x29, 0x89, 0x76, 0x5b, 0x91, 0x6d, 0x1e, 0xd8, + 0xe7, 0x39, 0x23, 0x26, 0x50, 0xc3, 0xdb, 0xbf, 0xe9, 0x55, 0x45, 0x39, + 0xb3, 0x60, 0x8a, 0xe4, 0x52, 0x89, 0x2b, 0x13, 0x6f, 0xbd, 0x97, 0x15, + 0xf8, 0xa5, 0x14, 0x12, 0x2f, 0xac, 0x76, 0x64, 0x14, 0x5f, 0xdb, 0x58, + 0x27, 0x5d, 0xca, 0x40, 0xf0, 0x46, 0xd7, 0x39, 0xa5, 0xea, 0x9c, 0x97, + 0xf9, 0xee, 0x9e, 0x10, 0xbe, 0x6a, 0xe7, 0x98, 0xa5, 0xd5, 0x2e, 0xb6, + 0x17, 0xfd, 0x3c, 0x9f, 0x45, 0x06, 0x1b, 0xb2, 0x18, 0x8a, 0xcd, 0x74, + 0x56, 0x5f, 0xb3, 0xf2, 0x58, 0x5a, 0xa3, 0xd4, 0x00, 0x45, 0xc4, 0x15, + 0x9f, 0x05, 0xf2, 0x34, 0x26, 0x37, 0x1b, 0x33, 0xbd, 0xfa, 0x70, 0xf3, + 0x79, 0x27, 0xc8, 0x37, 0xa9, 0x23, 0x55, 0x34, 0x76, 0x1a, 0x04, 0x40, + 0x6e, 0xac, 0x67, 0xc7, 0x6d, 0xeb, 0x35, 0xfc, 0x6e, 0xab, 0xd1, 0x90, + 0xd2, 0xf8, 0xdb, 0xf1, 0x93, 0xf2, 0xd6, 0x15, 0x89, 0x7e, 0xca, 0x2b, + 0x13, 0x4e, 0xcd, 0xe9, 0x73, 0x09, 0x12, 0xac, 0xc0, 0xdd, 0xba, 0x63, + 0x31, 0xfc, 0xea, 0xc7, 0x34, 0xd2, 0xea, 0xbb, 0x74, 0xd6, 0x7e, 0xa1, + 0x90, 0x22, 0xfa, 0x27, 0xee, 0xd6, 0x8c, 0x66, 0x24, 0x59, 0xa2, 0xb9, + 0x94, 0x07, 0xc9, 0x11, 0x45, 0x9a, 0x89, 0x03, 0xca, 0xe2, 0xd9, 0x3e, + 0xa2, 0x84, 0x77, 0x38, 0xdd, 0x78, 0xd0, 0x3d, 0xd4, 0x8a, 0xbe, 0x05, + 0xdb, 0x66, 0x77, 0xeb, 0xd1, 0x35, 0xcb, 0xbc, 0xb5, 0x53, 0x50, 0x59, + 0x6f, 0x7c, 0xf4, 0x91, 0xec, 0xe5, 0x5c, 0x19, 0xcb, 0x0f, 0x05, 0x99, + 0x55, 0x0f, 0xbf, 0x38, 0x4a, 0x87, 0xa8, 0x41, 0xcc, 0x7a, 0x75, 0x66, + 0xa3, 0xf0, 0x24, 0xc6, 0x2c, 0x18, 0x9c, 0x56, 0x26, 0x56, 0xc4, 0x76, + 0x8d, 0xa6, 0xdc, 0xe4, 0x2e, 0x34, 0x66, 0xd9, 0xbb, 0x79, 0x2a, 0x21, + 0x21, 0x36, 0x2f, 0xe4, 0x7b, 0x76, 0xa6, 0x4d, 0xe5, 0x06, 0xf9, 0x55, + 0xba, 0x30, 0x3b, 0x40, 0x90, 0x56, 0xeb, 0x99, 0x3a, 0x15, 0x54, 0xa7, + 0x0c, 0x12, 0x84, 0xcc, 0x8d, 0x69, 0xf2, 0x4c, 0xa6, 0x9b, 0x48, 0x49, + 0x9a, 0xb8, 0x60, 0x09, 0x94, 0x88, 0x41, 0x64, 0xcc, 0x0c, 0x5c, 0x3a, + 0x33, 0x03, 0x95, 0x16, 0xdf, 0x7a, 0x6b, 0x12, 0xd2, 0xdc, 0x40, 0xd7, + 0x6b, 0xb4, 0xab, 0x64, 0xa6, 0xd5, 0xe4, 0xb9, 0x0a, 0xcd, 0x9b, 0x14, + 0x2d, 0xd8, 0x71, 0x01, 0xbd, 0x93, 0x43, 0x3c, 0xb5, 0x6d, 0x76, 0x66, + 0xac, 0xc3, 0xf7, 0xd8, 0xe8, 0xc8, 0xa7, 0x43, 0x1b, 0x1d, 0x46, 0xe0, + 0x9e, 0x9e, 0x9e, 0xce, 0x38, 0x31, 0xf7, 0x5d, 0xa9, 0xed, 0x62, 0x4d, + 0x7d, 0xe3, 0x8b, 0xfb, 0x94, 0x9b, 0x5d, 0x9f, 0xd6, 0x04, 0x9f, 0xb3, + 0xb8, 0x13, 0xc9, 0x2b, 0x0f, 0xd3, 0x9c, 0x24, 0x14, 0xc3, 0x07, 0xe6, + 0xa0, 0xc0, 0x0d, 0x17, 0x2b, 0x94, 0x57, 0x99, 0xc4, 0x17, 0xf7, 0x7d, + 0xd6, 0xf8, 0xee, 0x11, 0xba, 0x7c, 0x44, 0xe3, 0xfb, 0xf2, 0xf0, 0xec, + 0x36, 0x5e, 0xde, 0x56, 0xc8, 0x10, 0xd4, 0x0f, 0x2a, 0xf1, 0xe7, 0x58, + 0x13, 0x6d, 0xc3, 0x5f, 0xd8, 0xe1, 0x27, 0x41, 0xb6, 0x64, 0xc1, 0x0f, + 0x64, 0x85, 0xc5, 0x5a, 0xa5, 0x7f, 0xa3, 0x1f, 0xc9, 0x87, 0x16, 0xac, + 0xc6, 0xed, 0x59, 0x5f, 0x9c, 0xbf, 0xb8, 0x90, 0x42, 0x5e, 0x72, 0x34, + 0x41, 0xa8, 0x53, 0xcf, 0x84, 0xb6, 0x57, 0x47, 0xda, 0x7b, 0xbe, 0x48, + 0xbd, 0x2f, 0xa2, 0xa6, 0xa4, 0x8f, 0x6d, 0xdf, 0x90, 0x17, 0xaa, 0x0b, + 0x98, 0xaf, 0x13, 0xf8, 0x5a, 0x16, 0xa1, 0xa9, 0xd4, 0x52, 0x9f, 0x7c, + 0x0b, 0x05, 0xc8, 0x6b, 0x23, 0xbc, 0xb6, 0xb6, 0xcf, 0x0f, 0xaf, 0x30, + 0x53, 0x27, 0xa3, 0xcb, 0xd6, 0xbe, 0x5b, 0x0c, 0x43, 0xd6, 0x59, 0x54, + 0x5d, 0x9c, 0x14, 0x59, 0xe0, 0x34, 0x1a, 0xff, 0xa3, 0xf9, 0x19, 0x3f, + 0x1b, 0x99, 0x85, 0xd1, 0xcf, 0xbc, 0x91, 0xb2, 0x6f, 0x9c, 0x64, 0x78, + 0xeb, 0xc8, 0x0e, 0x92, 0x53, 0xbe, 0xd3, 0xb5, 0xa9, 0x8c, 0xcc, 0xed, + 0xb1, 0xb4, 0x92, 0x4a, 0x7e, 0x00, 0xf3, 0xac, 0xba, 0x07, 0xd0, 0x06, + 0xea, 0xef, 0x60, 0x9b, 0x95, 0x95, 0x16, 0x2a, 0x0c, 0x93, 0xce, 0x8e, + 0x62, 0x60, 0x78, 0x1a, 0x44, 0x64, 0xaf, 0x58, 0x6b, 0x88, 0x00, 0xbd, + 0x55, 0x6c, 0xed, 0xf3, 0xd4, 0x62, 0x6f, 0x11, 0xa8, 0x8f, 0x2a, 0x02, + 0x14, 0xae, 0x4c, 0x4b, 0x68, 0x39, 0xa5, 0x6f, 0x03, 0x11, 0xc8, 0x0d, + 0x4b, 0xef, 0xc9, 0x5d, 0x1d, 0xba, 0x76, 0x31, 0xcb, 0xe0, 0x0b, 0x74, + 0xf6, 0x91, 0xa0, 0x0a, 0x3a, 0xd4, 0x8b, 0x06, 0x36, 0xfc, 0xae, 0xab, + 0x18, 0x24, 0xb5, 0x73, 0xaa, 0xe5, 0xcf, 0x6a, 0x03, 0x13, 0xba, 0xdc, + 0x95, 0x06, 0x27, 0xf5, 0x5f, 0x51, 0x39, 0x2b, 0x77, 0xe9, 0x4e, 0x66, + 0xdc, 0xa1, 0x96, 0x47, 0xc4, 0xae, 0x61, 0xfb, 0xc3, 0x3b, 0xfa, 0x7b, + 0x51, 0xca, 0x77, 0xad, 0x8e, 0xdc, 0xee, 0x31, 0xbe, 0x79, 0x70, 0xf9, + 0x0f, 0x66, 0xc4, 0xd7, 0x6b, 0xdf, 0x9c, 0x14, 0x28, 0x5b, 0xc2, 0x0d, + 0xcc, 0xf0, 0x2f, 0xbc, 0x07, 0x12, 0x09, 0x54, 0x07, 0xbd, 0x4a, 0xb9, + 0xa1, 0xa2, 0xb6, 0x81, 0xc0, 0x36, 0x9c, 0xec, 0x72, 0xdb, 0x1a, 0x41, + 0x42, 0x0f, 0x62, 0xd2, 0x1b, 0x04, 0xf6, 0x02, 0x80, 0xa5, 0xac, 0xb5, + 0x2a, 0x38, 0x5f, 0xc6, 0xde, 0xe9, 0x78, 0xb1, 0x98, 0xc0, 0xd5, 0x6e, + 0xaa, 0xe2, 0xff, 0xe1, 0x50, 0xe2, 0xaa, 0x77, 0x3e, 0x7b, 0x3f, 0xc6, + 0x0a, 0x31, 0x02, 0x70, 0x43, 0x01, 0xa9, 0x9c, 0x80, 0xc2, 0x4f, 0x61, + 0x3c, 0xa9, 0x53, 0x6c, 0x54, 0xda, 0x3d, 0xa6, 0x68, 0xaf, 0x33, 0xa2, + 0xfd, 0x5a, 0x19, 0x0e, 0xa5, 0xd1, 0x2f, 0x5b, 0x14, 0xa8, 0x73, 0x77, + 0xf4, 0x50, 0x2a, 0x6b, 0x2c, 0x55, 0x33, 0x47, 0xa0, 0xa8, 0xf0, 0xf8, + 0xd2, 0xe4, 0xe8, 0x4d, 0xff, 0x81, 0x28, 0x3d, 0xef, 0xe1, 0xbe, 0x57, + 0x77, 0x88, 0xbb, 0x4c, 0x4e, 0xec, 0x79, 0x1d, 0xd7, 0x6d, 0xcf, 0x18, + 0x88, 0x86, 0x8a, 0xd9, 0x68, 0x14, 0x39, 0xee, 0x03, 0x1c, 0xc7, 0xcb, + 0xf6, 0x1e, 0x8a, 0xc1, 0xf9, 0x56, 0xf9, 0x7c, 0xc9, 0x3e, 0xab, 0x3d, + 0x7e, 0x2b, 0xb9, 0x11, 0xee, 0xd5, 0x2c, 0x52, 0x22, 0x5c, 0x82, 0xd1, + 0x0c, 0xa2, 0x5b, 0x64, 0x17, 0x51, 0xf4, 0xf1, 0x71, 0xf6, 0x83, 0x60, + 0x8e, 0xa0, 0xcf, 0x95, 0x95, 0x17, 0x03, 0xd7, 0x90, 0xb1, 0xb3, 0x6d, + 0x8a, 0xca, 0xdd, 0x98, 0x67, 0xe3, 0x13, 0x15, 0x6e, 0xc7, 0xff, 0x98, + 0x00, 0xe7, 0xa8, 0xa5, 0xa1, 0x95, 0x05, 0x6c, 0x12, 0x5a, 0x88, 0x26, + 0xce, 0x5a, 0x36, 0xe2, 0x45, 0x45, 0x53, 0xe5, 0x2b, 0xf6, 0xd1, 0xe4, + 0x0d, 0xef, 0x04, 0xab, 0x51, 0x98, 0x42, 0x22, 0xb9, 0x55, 0x6f, 0xa8, + 0x85, 0xb6, 0x0e, 0x15, 0x44, 0x02, 0xdc, 0xf3, 0x81, 0x9a, 0xa9, 0xf4, + 0x11, 0x6c, 0xc0, 0x61, 0x56, 0x91, 0x36, 0xf3, 0xb0, 0xbf, 0x2f, 0xf0, + 0x49, 0x39, 0x20, 0x94, 0xc7, 0x7d, 0x30, 0x37, 0xee, 0x11, 0x06, 0x9f, + 0x3f, 0xc5, 0x7a, 0x3f, 0x9e, 0xd6, 0x55, 0x38, 0x21, 0x69, 0xf5, 0xc5, + 0xdb, 0x31, 0x99, 0x2d, 0xc9, 0x38, 0xed, 0xef, 0xb2, 0xe8, 0x49, 0x38, + 0x15, 0x04, 0xed, 0x23, 0x93, 0x7a, 0x4b, 0x0b, 0x21, 0x6d, 0x1f, 0xe1, + 0x48, 0x7d, 0x6b, 0x5e, 0x2a, 0xb0, 0x59, 0x17, 0x71, 0x27, 0x3e, 0x60, + 0x8a, 0xe4, 0xb2, 0x68, 0x87, 0xe9, 0x11, 0x09, 0x22, 0xc7, 0xc9, 0x05, + 0xb7, 0xa9, 0xe8, 0x5c, 0x86, 0x1b, 0x34, 0xd1, 0xc8, 0x7e, 0x99, 0xf4, + 0x60, 0xfa, 0x2e, 0xaa, 0x33, 0x7c, 0xf5, 0x15, 0x8f, 0x50, 0x6a, 0xe0, + 0x62, 0xbf, 0xd6, 0x48, 0x8e, 0x62, 0xf8, 0x3c, 0xd9, 0xb5, 0xba, 0x88, + 0xd4, 0x83, 0x4f, 0x11, 0xce, 0xf6, 0x1e, 0xc7, 0xa6, 0xb8, 0x78, 0x69, + 0xd2, 0x6b, 0xc9, 0x30, 0x20, 0x24, 0xf6, 0x4d, 0x67, 0x62, 0x69, 0x1f, + 0xe6, 0xd6, 0xaa, 0xf6, 0x1e, 0xae, 0xff, 0xf1, 0xc8, 0x8b, 0x5b, 0xaf, + 0x1a, 0x2d, 0xf0, 0x1b, 0x79, 0xad, 0x7d, 0xc5, 0xb7, 0xd5, 0x50, 0x15, + 0x45, 0x2f, 0xb1, 0x9b, 0xff, 0xc3, 0xd3, 0xe4, 0xe2, 0x7b, 0x64, 0x36, + 0x91, 0xe2, 0x76, 0xde, 0xe7, 0x6e, 0x6a, 0xb0, 0xcb, 0x23, 0xf2, 0x51, + 0x78, 0xf1, 0x11, 0x63, 0xb6, 0xaa, 0x95, 0x36, 0xb4, 0x3b, 0x0d, 0xf1, + 0x5a, 0x36, 0x12, 0x58, 0xcc, 0x8c, 0xbb, 0x99, 0x15, 0x44, 0xfd, 0xf0, + 0xf4, 0x77, 0x48, 0xfc, 0x5b, 0xed, 0x91, 0x27, 0xbb, 0x18, 0xd5, 0x06, + 0x53, 0x28, 0x2f, 0x2f, 0x96, 0x03, 0x91, 0x8e, 0x6e, 0x46, 0xdf, 0xff, + 0x60, 0xfc, 0xe3, 0x0c, 0x75, 0x62, 0x59, 0x24, 0x33, 0x33, 0xd5, 0x52, + 0xda, 0xe9, 0xb0, 0x94, 0x9e, 0x6f, 0x82, 0x92, 0x83, 0x41, 0x7c, 0xf3, + 0x7d, 0x8f, 0x07, 0x77, 0x05, 0x74, 0xea, 0x27, 0x7b, 0x4b, 0x5a, 0xd5, + 0x48, 0xd7, 0x0b, 0x0b, 0xcf, 0x5a, 0xce, 0xba, 0x10, 0xb3, 0x14, 0xe5, + 0x59, 0x37, 0x12, 0xef, 0xab, 0x7f, 0x72, 0x95, 0x6d, 0x0c, 0xce, 0x9b, + 0xa7, 0x59, 0x23, 0xc2, 0xf0, 0x1d, 0x8e, 0xdc, 0xf3, 0x73, 0x73, 0xa8, + 0xab, 0xa8, 0x8a, 0x97, 0xcd, 0x39, 0x5f, 0xbc, 0x64, 0xac, 0xe6, 0x6d, + 0xe4, 0xe1, 0xef, 0x89, 0x1c, 0x7b, 0xac, 0x7f, 0x4d, 0x13, 0x90, 0x67, + 0x4d, 0x6b, 0x96, 0x91, 0x96, 0x63, 0x6b, 0x2d, 0xa6, 0x10, 0x50, 0x0d, + 0x7d, 0x9c, 0x5e, 0x8b, 0x9c, 0x0f, 0x03, 0xbf, 0x26, 0xa7, 0x68, 0xe4, + 0x3d, 0xa8, 0x13, 0x34, 0xd9, 0x28, 0x3e, 0x0d, 0x7c, 0xd9, 0xab, 0x88, + 0x25, 0xb1, 0x85, 0x08, 0x53, 0x8f, 0x87, 0xd6, 0x68, 0xc6, 0x4c, 0x51, + 0x63, 0x08, 0xa2, 0xd5, 0xfc, 0xff, 0x91, 0x87, 0xa5, 0xad, 0xf9, 0x95, + 0xc2, 0xbf, 0x9f, 0x16, 0x5a, 0x81, 0x5e, 0xfc, 0x75, 0x66, 0x47, 0xf5, + 0x5c, 0x00, 0xe2, 0x35, 0x60, 0xb0, 0x5e, 0x7d, 0xb0, 0x67, 0x6d, 0x44, + 0x1c, 0x8c, 0xdf, 0x36, 0x92, 0x80, 0xdf, 0xbb, 0xf8, 0xfa, 0x85, 0x57, + 0x07, 0x81, 0x5e, 0x52, 0xdd, 0x49, 0x89, 0x7e, 0x0a, 0x99, 0x73, 0xdd, + 0x03, 0x24, 0x0f, 0xda, 0xf6, 0xf1, 0x75, 0x9f, 0x15, 0xc0, 0x63, 0x37, + 0x2d, 0x01, 0x52, 0x21, 0x2d, 0xe9, 0xa6, 0xd8, 0xae, 0x41, 0x54, 0xb7, + 0x87, 0x86, 0x69, 0x96, 0x4c, 0xb9, 0xb9, 0x33, 0x18, 0x9b, 0x7f, 0x5d, + 0x86, 0x75, 0x71, 0x83, 0x7d, 0xd3, 0x81, 0xd1, 0x02, 0x75, 0x11, 0xab, + 0xc9, 0x3a, 0xaf, 0xdb, 0x1a, 0x5f, 0xbb, 0x53, 0xe0, 0x74, 0x3f, 0xfa, + 0x9d, 0x57, 0x0f, 0xd3, 0x0a, 0x01, 0x12, 0x5f, 0xcc, 0xaa, 0x76, 0x24, + 0xb3, 0x91, 0x52, 0x9d, 0x1b, 0x74, 0xa4, 0xa6, 0x5b, 0x11, 0xcd, 0xd9, + 0xac, 0x4f, 0xe3, 0xe7, 0x89, 0x7e, 0x60, 0x40, 0x6d, 0xfc, 0x47, 0x37, + 0x0c, 0xef, 0x8d, 0xa9, 0x3d, 0x88, 0x01, 0x6d, 0x0f, 0xc0, 0x88, 0x00, + 0x17, 0xd6, 0xd2, 0x1c, 0xf9, 0x16, 0x9d, 0xec, 0xae, 0xa9, 0x2a, 0x62, + 0x32, 0x51, 0x4b, 0x70, 0x84, 0x68, 0x1f, 0xc0, 0x2c, 0x72, 0x3d, 0xb9, + 0x25, 0x90, 0x68, 0x17, 0xa2, 0x6f, 0x55, 0x35, 0x86, 0x6e, 0xdd, 0xad, + 0xe3, 0xfc, 0xcf, 0x24, 0xa2, 0x1b, 0xe8, 0xd5, 0xd4, 0xf7, 0x2a, 0x68, + 0x61, 0xc1, 0xe3, 0x5a, 0x6e, 0x4b, 0x0c, 0x8c, 0xa6, 0x53, 0xc2, 0xbf, + 0xc0, 0xb2, 0x57, 0x96, 0x95, 0x5d, 0x40, 0x76, 0xea, 0x84, 0x4d, 0xab, + 0x87, 0xbc, 0xa1, 0x4c, 0x67, 0x7f, 0x1e, 0xa8, 0x82, 0xf9, 0x63, 0x96, + 0xbf, 0x8f, 0xc9, 0x56, 0x94, 0xf1, 0x09, 0x48, 0x7e, 0xbc, 0x65, 0x99, + 0x03, 0xce, 0xa5, 0x33, 0xfc, 0x63, 0xdf, 0x7c, 0xa1, 0x01, 0xe0, 0x00, + 0x04, 0xd7, 0x53, 0x23, 0x52, 0x0c, 0xb0, 0x42, 0xde, 0x4a, 0xc3, 0xd5, + 0xf9, 0x25, 0xd4, 0x7b, 0x05, 0x96, 0x5a, 0xae, 0xab, 0xb6, 0xdd, 0xb1, + 0x13, 0x3b, 0x46, 0xd8, 0xf7, 0x79, 0x25, 0x69, 0xd9, 0x48, 0x18, 0x13, + 0x18, 0x25, 0xd8, 0x35, 0xf4, 0x4c, 0x2e, 0xcc, 0xb5, 0x08, 0xb6, 0xc4, + 0x79, 0x5d, 0xb8, 0xb4, 0xc1, 0x52, 0x20, 0x0b, 0x6f, 0xb8, 0x13, 0xa0, + 0x22, 0x5b, 0x8c, 0xf4, 0xbf, 0xed, 0x98, 0x1a, 0x00, 0x0e, 0x6b, 0x61, + 0x53, 0x6d, 0xaa, 0xe4, 0xbc, 0x9e, 0x25, 0x05, 0xb6, 0x01, 0x42, 0x71, + 0x13, 0xf3, 0xae, 0x46, 0x8f, 0xce, 0x75, 0x62, 0xf8, 0x35, 0x6f, 0x08, + 0xa9, 0xdf, 0xfa, 0xdf, 0x4c, 0xd2, 0x75, 0x1a, 0x42, 0xb9, 0x74, 0x4c, + 0xbc, 0xe3, 0xb3, 0x22, 0x1e, 0x21, 0x8f, 0xde, 0xca, 0xa2, 0xb8, 0xbc, + 0xa2, 0x85, 0x42, 0x00, 0xd6, 0xd7, 0x0f, 0x64, 0x66, 0x61, 0x91, 0xc4, + 0x34, 0x4b, 0x2c, 0x02, 0xb3, 0xac, 0x03, 0x08, 0x15, 0x16, 0xc7, 0xab, + 0xb3, 0x4b, 0x23, 0x9b, 0xd5, 0xf9, 0xa6, 0x9f, 0x38, 0x19, 0x62, 0xc9, + 0xb5, 0x19, 0xda, 0xed, 0x79, 0x80, 0x7e, 0xb1, 0x7e, 0xd3, 0x7b, 0xe8, + 0xbe, 0xa6, 0x0b, 0xd7, 0x43, 0x5b, 0x38, 0x23, 0xbe, 0xca, 0x71, 0x23, + 0xd1, 0x76, 0x7a, 0x2a, 0xbc, 0xa1, 0x28, 0xef, 0xfd, 0x7d, 0xdb, 0xfa, + 0x4b, 0x52, 0x3e, 0x99, 0x54, 0x0a, 0xfe, 0x92, 0x2e, 0xb8, 0xd2, 0x90, + 0x7f, 0x98, 0xb9, 0x40, 0x8e, 0x4d, 0xc2, 0x35, 0xce, 0x40, 0xbf, 0x76, + 0x11, 0x23, 0x31, 0x63, 0xa8, 0xae, 0xd0, 0x62, 0x42, 0xd5, 0x73, 0xc1, + 0x09, 0x92, 0x8a, 0x59, 0x0b, 0x22, 0xcb, 0xc3, 0x16, 0x6f, 0x62, 0xa3, + 0xa4, 0x7e, 0x18, 0x81, 0x19, 0xd7, 0x21, 0xfe, 0xf4, 0xff, 0xa1, 0xa9, + 0x03, 0xa2, 0x0a, 0xcf, 0x1a, 0x69, 0x49, 0x68, 0xf7, 0x5c, 0xc0, 0x37, + 0x6c, 0x8e, 0x97, 0x23, 0xf5, 0x4e, 0x7e, 0x15, 0x56, 0xf0, 0x7c, 0x8b, + 0x56, 0x2a, 0x05, 0x07, 0x3d, 0xf3, 0xc1, 0xcc, 0xae, 0x96, 0x90, 0xf1, + 0x6a, 0xaf, 0x5c, 0xbe, 0x4d, 0xda, 0xca, 0x8a, 0xa3, 0x4f, 0x78, 0xea, + 0x1f, 0x4e, 0xa9, 0x2e, 0xfc, 0x66, 0xe6, 0x6c, 0x5a, 0xa5, 0x83, 0xc9, + 0x53, 0x0b, 0x65, 0x22, 0x5d, 0x89, 0x91, 0xf0, 0x85, 0xb3, 0x12, 0x20, + 0x61, 0x28, 0x09, 0x37, 0xd5, 0xf7, 0x09, 0x12, 0x35, 0x23, 0x49, 0xc3, + 0xf3, 0xda, 0x64, 0x3d, 0x7d, 0x00, 0x7d, 0x0b, 0xfc, 0x4c, 0xec, 0xed, + 0xcd, 0x77, 0x3f, 0xd8, 0xe6, 0xfb, 0x8f, 0xb8, 0x6f, 0xd0, 0xf0, 0x58, + 0x81, 0x7a, 0x99, 0x3c, 0x8d, 0x5d, 0x6c, 0x56, 0xac, 0x1e, 0x1a, 0xdb, + 0x8d, 0xc9, 0xc3, 0xc9, 0xbd, 0x96, 0x52, 0xe9, 0xc3, 0x1e, 0x62, 0x74, + 0x4b, 0xe8, 0x48, 0x19, 0x9f, 0x60, 0x78, 0xa6, 0xd3, 0xb7, 0x33, 0xcb, + 0xd9, 0xa6, 0x1e, 0xe7, 0xed, 0x97, 0xab, 0xd0, 0xbf, 0x37, 0x2d, 0x87, + 0xb5, 0xca, 0x7f, 0x21, 0xa2, 0x84, 0x1a, 0xee, 0xe4, 0xef, 0x05, 0x86, + 0x6b, 0xbc, 0x61, 0xf7, 0x3e, 0x92, 0x1a, 0x1c, 0x6e, 0x48, 0x39, 0x7b, + 0x3e, 0xb4, 0xb8, 0x0f, 0xa5, 0xf3, 0x59, 0x48, 0xb3, 0x22, 0xcf, 0x2d, + 0x2e, 0xd8, 0xab, 0xc1, 0xbe, 0x7e, 0xd3, 0x43, 0x2f, 0x32, 0x2c, 0xdd, + 0x4c, 0xf3, 0x14, 0x6a, 0xb2, 0x4d, 0x0d, 0xa2, 0x5f, 0x8b, 0x02, 0x12, + 0x94, 0x75, 0xdf, 0x88, 0x89, 0x3d, 0xdd, 0x27, 0xc5, 0xe5, 0x63, 0x27, + 0xc8, 0x6a, 0xb6, 0xe8, 0x8a, 0x06, 0x3f, 0x65, 0x8b, 0x57, 0x11, 0xc1, + 0x03, 0x8b, 0x35, 0xff, 0x9c, 0xda, 0xf1, 0xbf, 0x60, 0x6f, 0xc9, 0x56, + 0x08, 0x10, 0x37, 0x8d, 0x01, 0x2f, 0x5e, 0x2d, 0xd2, 0x10, 0x83, 0x9e, + 0x12, 0xfd, 0x28, 0xa5, 0x78, 0xb3, 0xe9, 0xdc, 0xaa, 0x1f, 0x4a, 0x02, + 0x17, 0x4c, 0x82, 0xb1, 0x49, 0x80, 0x62, 0x17, 0x8a, 0x4c, 0x3d, 0x50, + 0x29, 0x70, 0xe3, 0x09, 0x15, 0x15, 0x7d, 0xdc, 0x92, 0xa9, 0xc5, 0x51, + 0x2b, 0x34, 0xc1, 0xff, 0xbd, 0xb4, 0xec, 0x4a, 0x15, 0xff, 0xcc, 0x7c, + 0x6f, 0xed, 0xcf, 0x6c, 0xd4, 0x88, 0xb0, 0x17, 0x7b, 0xec, 0x8b, 0x0b, + 0x15, 0x56, 0xf1, 0x90, 0xc4, 0x2f, 0x03, 0x71, 0x23, 0xf0, 0x61, 0xd4, + 0x25, 0x3c, 0x36, 0x0a, 0xb2, 0x61, 0x65, 0x0f, 0xbd, 0xb6, 0x56, 0xd7, + 0x5e, 0xc1, 0x2d, 0x7a, 0xfe, 0xc2, 0xb8, 0x61, 0x81, 0x3e, 0x17, 0x43, + 0x9b, 0xdb, 0x60, 0x74, 0xcc, 0xc9, 0x9d, 0x39, 0x20, 0x40, 0x4f, 0x32, + 0x33, 0xc7, 0x0c, 0x87, 0x51, 0x19, 0x1c, 0x81, 0x5f, 0x45, 0xe3, 0xf2, + 0x38, 0x7b, 0x43, 0xb3, 0x9e, 0x9e, 0x15, 0x15, 0xcb, 0xe2, 0x1a, 0xd9, + 0x70, 0x05, 0xab, 0x92, 0x56, 0x0a, 0xa9, 0x30, 0x43, 0x11, 0xe2, 0xd3, + 0xb0, 0xf9, 0x70, 0xf0, 0xb2, 0x8f, 0x55, 0x01, 0x03, 0xa6, 0x5e, 0xb0, + 0x75, 0xcb, 0x73, 0x67, 0x4f, 0xeb, 0x57, 0x1f, 0xb0, 0x30, 0x16, 0xe7, + 0xd1, 0x9f, 0x4b, 0xa6, 0x4c, 0x46, 0x08, 0x54, 0x74, 0x0d, 0xe7, 0xae, + 0x62, 0x01, 0x33, 0x99, 0x08, 0x7a, 0xed, 0x71, 0x75, 0x4e, 0x9b, 0x3e, + 0x05, 0xc5, 0xac, 0x84, 0xc3, 0xfa, 0x70, 0xf7, 0xb1, 0x50, 0x1e, 0x89, + 0x73, 0x99, 0x1e, 0x1c, 0x14, 0xc3, 0x82, 0xe1, 0xb1, 0xac, 0x38, 0xea, + 0xfb, 0x3b, 0x45, 0xa6, 0xc4, 0xa1, 0x88, 0xaa, 0xed, 0x5a, 0xa1, 0x8a, + 0xbe, 0x09, 0xbc, 0xea, 0xd2, 0xa2, 0x49, 0xad, 0x54, 0xc4, 0xa8, 0x12, + 0x03, 0xc1, 0x8d, 0xc2, 0xde, 0xd5, 0x2e, 0x73, 0x32, 0xab, 0xd3, 0x02, + 0xf5, 0x5c, 0xae, 0x35, 0x2a, 0x96, 0x7b, 0xe0, 0x7f, 0x32, 0x2e, 0x64, + 0x68, 0x51, 0xd1, 0x87, 0x5c, 0xa0, 0x6b, 0x55, 0xb5, 0x0d, 0x3f, 0x3b, + 0xd9, 0xea, 0x23, 0xe7, 0xa7, 0x0a, 0xa1, 0x8f, 0x8c, 0x07, 0x1e, 0x73, + 0xcc, 0xe6, 0xd2, 0x4f, 0xaf, 0x86, 0xc0, 0xb4, 0x53, 0xa9, 0x2c, 0xff, + 0xcd, 0xd5, 0xf7, 0x46, 0xa7, 0xa9, 0xa9, 0x40, 0xfe, 0x97, 0xe1, 0xc0, + 0xfc, 0x0b, 0x4d, 0xa5, 0x8f, 0xd9, 0xbc, 0x5f, 0x0f, 0xe9, 0xa9, 0x4f, + 0xc4, 0x74, 0x63, 0xf7, 0xca, 0xd0, 0x7b, 0xb9, 0x2c, 0x3e, 0x26, 0x11, + 0xd6, 0x15, 0xab, 0x6c, 0x42, 0x36, 0xf8, 0xf6, 0x74, 0x68, 0xce, 0x4d, + 0x58, 0xea, 0x4f, 0xac, 0xf8, 0xe4, 0x2a, 0xbe, 0xd7, 0x73, 0x17, 0xba, + 0x3a, 0xc5, 0xe4, 0x60, 0x82, 0xdd, 0x03, 0x67, 0x67, 0xd0, 0x75, 0xc4, + 0xec, 0xbd, 0xf2, 0x3b, 0x9b, 0x45, 0xc8, 0xfd, 0x2e, 0xb9, 0xb8, 0x50, + 0x48, 0xf7, 0x7c, 0xe0, 0xc2, 0xe9, 0xc9, 0x76, 0xbd, 0x79, 0xba, 0x59, + 0x4c, 0xbd, 0x6f, 0x45, 0xa8, 0x04, 0xc1, 0x95, 0x06, 0x21, 0x00, 0xaa, + 0x78, 0x58, 0x4e, 0xd8, 0xfe, 0x71, 0x6e, 0x03, 0x30, 0xe0, 0xa7, 0xe6, + 0x87, 0x9b, 0xbc, 0x10, 0x77, 0x9d, 0xee, 0x21, 0x95, 0x2c, 0xff, 0x3a, + 0x92, 0xe3, 0xd0, 0x2f, 0x36, 0x5b, 0x61, 0xe0, 0x23, 0xc4, 0x26, 0x9e, + 0x6b, 0x1d, 0xa8, 0x32, 0x1a, 0x1e, 0x70, 0xa6, 0x75, 0xda, 0x5e, 0xcf, + 0x65, 0x53, 0x1a, 0x18, 0x13, 0x3a, 0xb8, 0x85, 0x2d, 0x83, 0xc2, 0x28, + 0x5b, 0x26, 0x88, 0x19, 0x3b, 0xd1, 0x08, 0x1c, 0xb6, 0x28, 0x20, 0x56, + 0x5a, 0x07, 0xb0, 0x4f, 0x65, 0xd1, 0xa8, 0x93, 0x35, 0x3e, 0x8a, 0x09, + 0xf8, 0xb0, 0xd1, 0x01, 0x93, 0xa7, 0x6e, 0xdb, 0xc0, 0xc0, 0x67, 0x17, + 0x27, 0xd0, 0x1e, 0xb4, 0x61, 0x39, 0x76, 0x65, 0x5d, 0xad, 0x7d, 0x0b, + 0xcf, 0xc6, 0xdb, 0x4a, 0xed, 0x5c, 0x3d, 0xe0, 0x7c, 0x07, 0xd9, 0xb1, + 0xa8, 0x30, 0x9c, 0xfe, 0xe1, 0x79, 0x86, 0x22, 0x99, 0x83, 0xae, 0x7b, + 0xbe, 0xc0, 0x0b, 0xa7, 0x00, 0x67, 0xd6, 0xfa, 0xca, 0x36, 0x57, 0x90, + 0x10, 0xe5, 0x2e, 0x11, 0x0a, 0x2d, 0x92, 0x47, 0xcc, 0xce, 0x3a, 0x7a, + 0xf6, 0x69, 0x5f, 0x87, 0x4f, 0x7a, 0xab, 0xe5, 0x2e, 0x95, 0x57, 0xe8, + 0x54, 0x67, 0xf6, 0xc5, 0x03, 0x92, 0x0a, 0x98, 0xc5, 0x54, 0x3e, 0x9b, + 0x68, 0x3d, 0xcc, 0xbc, 0x44, 0xc4, 0xe4, 0x60, 0x76, 0x6e, 0xfa, 0x2f, + 0x5c, 0xcc, 0xb5, 0xb4, 0x62, 0xbf, 0x74, 0x1c, 0x32, 0x1f, 0xf7, 0xb0, + 0xae, 0x50, 0xa3, 0x53, 0x41, 0x4f, 0x89, 0x29, 0x42, 0x66, 0x37, 0x8a, + 0xbb, 0xdf, 0x0b, 0xdf, 0x63, 0x10, 0x8f, 0x0f, 0xc3, 0x4c, 0x50, 0xe8, + 0xcb, 0xa5, 0xae, 0x6b, 0x1b, 0x70, 0x71, 0xeb, 0xd8, 0xf3, 0xf4, 0xc0, + 0xee, 0x23, 0xe2, 0x7c, 0x98, 0x85, 0x17, 0xe8, 0xb7, 0x76, 0x1f, 0x33, + 0xaa, 0x1a, 0x14, 0x8b, 0x1d, 0x4c, 0xf1, 0x41, 0x60, 0x7d, 0x31, 0xe9, + 0x2a, 0x60, 0x5b, 0x41, 0x3d, 0x3f, 0xf5, 0x7f, 0xd9, 0xe4, 0x8f, 0x28, + 0xff, 0x12, 0x93, 0x8c, 0x08, 0xb1, 0xa1, 0xe3, 0x81, 0xb1, 0xe3, 0x6c, + 0xe4, 0x0a, 0x1b, 0x62, 0x2b, 0x30, 0x36, 0xcc, 0x6d, 0x35, 0x75, 0x59, + 0x4a, 0x70, 0x09, 0x7d, 0x1d, 0xc3, 0x75, 0x07, 0x79, 0x2a, 0x30, 0x5b, + 0xb2, 0x96, 0xf8, 0xde, 0xf1, 0xae, 0x32, 0x23, 0x90, 0xbc, 0xcb, 0xab, + 0xb8, 0xd9, 0xf6, 0x23, 0x58, 0x8c, 0xfe, 0x76, 0x7a, 0x0e, 0x21, 0xee, + 0x71, 0x0a, 0xc1, 0xf3, 0x49, 0xae, 0x19, 0x4c, 0x1f, 0x53, 0x10, 0x7c, + 0x75, 0x3e, 0x31, 0x37, 0xc2, 0xee, 0xae, 0x20, 0x2d, 0x30, 0x4e, 0xcd, + 0x63, 0x81, 0x5f, 0xc4, 0x72, 0x1c, 0x60, 0x0e, 0xa0, 0xf5, 0xe8, 0xc9, + 0xfe, 0x10, 0x9a, 0x88, 0xd9, 0x35, 0x5f, 0xce, 0x23, 0x57, 0xb9, 0xbf, + 0x1a, 0x42, 0x2b, 0xf2, 0x2a, 0x36, 0xd3, 0xc3, 0xaa, 0xe3, 0xc2, 0x14, + 0x54, 0x94, 0x1b, 0x8e, 0x9d, 0x41, 0xa8, 0xeb, 0x19, 0xf0, 0x94, 0xd0, + 0x0e, 0x94, 0x07, 0x99, 0x67, 0x37, 0x2b, 0x36, 0x82, 0xae, 0x3f, 0x08, + 0xac, 0x3c, 0x8b, 0x16, 0x0e, 0xc0, 0xea, 0x60, 0x00, 0x57, 0x3e, 0x88, + 0x0b, 0x26, 0x38, 0x36, 0xee, 0xdf, 0xa4, 0xbc, 0xf6, 0xbc, 0x6e, 0x74, + 0x39, 0xa8, 0x1e, 0xd1, 0x18, 0x77, 0x11, 0xb7, 0xcd, 0x1e, 0xf1, 0x30, + 0x5a, 0x04, 0x9f, 0x69, 0x2c, 0xe6, 0x20, 0x47, 0x8f, 0xe3, 0xf6, 0xcf, + 0xf7, 0xa4, 0x93, 0x22, 0xba, 0x9b, 0x95, 0x56, 0x41, 0xd1, 0x88, 0xf1, + 0x78, 0x33, 0xdf, 0x5e, 0xe7, 0xa5, 0xf8, 0x71, 0xda, 0xaa, 0xe3, 0xe0, + 0x4c, 0x9a, 0xcd, 0xc4, 0x89, 0xb8, 0x9a, 0xea, 0xa5, 0x71, 0xd6, 0xdf, + 0x81, 0x73, 0xfe, 0x0e, 0x5e, 0x18, 0xe5, 0x03, 0x97, 0x71, 0xce, 0xd4, + 0x59, 0xab, 0x26, 0x0e, 0xb8, 0xbb, 0xfe, 0x14, 0x1e, 0x76, 0x71, 0x12, + 0x60, 0x75, 0x7c, 0x8d, 0x04, 0x6a, 0x54, 0x9b, 0x4a, 0x4b, 0x79, 0xf8, + 0xf4, 0xad, 0x81, 0x53, 0x15, 0x5e, 0x19, 0xf1, 0xf3, 0x6d, 0x9e, 0x7f, + 0x14, 0x29, 0x22, 0x5e, 0xd1, 0x76, 0xf6, 0x0e, 0x2b, 0x12, 0x04, 0xe4, + 0x14, 0xd2, 0xfe, 0xdd, 0x7b, 0x6c, 0x38, 0xe2, 0xe5, 0x20, 0xf6, 0xf9, + 0xc9, 0xcd, 0x36, 0x24, 0xb2, 0xba, 0x18, 0x4d, 0x62, 0x8d, 0x62, 0xb2, + 0x83, 0x3c, 0x6a, 0x1d, 0x6c, 0x61, 0xb9, 0x4e, 0x32, 0x79, 0x70, 0x47, + 0x2e, 0xff, 0x3a, 0x82, 0x8e, 0xdd, 0x90, 0x0f, 0x1d, 0xc4, 0xc9, 0x0c, + 0x41, 0x78, 0xa5, 0x29, 0xa5, 0xa5, 0xc9, 0x93, 0x6c, 0x26, 0xc7, 0x2e, + 0x1c, 0x3b, 0x9c, 0x7b, 0x47, 0xe6, 0xe6, 0x11, 0xd0, 0xfc, 0x34, 0x48, + 0x8c, 0x39, 0xf5, 0xfd, 0xb4, 0xbb, 0x2d, 0xbb, 0x8c, 0x9f, 0xae, 0xb2, + 0x3e, 0x32, 0xfa, 0x4e, 0xd7, 0xf2, 0x6e, 0xbf, 0x15, 0xba, 0x2d, 0x2c, + 0xe2, 0xa0, 0x06, 0xf0, 0x36, 0xf0, 0xaa, 0x40, 0xc4, 0xec, 0x65, 0xe0, + 0x5a, 0x48, 0xf0, 0x5f, 0x3b, 0x15, 0x9e, 0x79, 0x30, 0xdc, 0xf4, 0x5d, + 0x08, 0xbf, 0xe2, 0xee, 0xa6, 0xae, 0x69, 0x3e, 0x6f, 0x2c, 0x2c, 0xd5, + 0x36, 0x87, 0xe7, 0x01, 0xb6, 0x63, 0x7f, 0xff, 0xcb, 0x87, 0x86, 0xca, + 0xeb, 0xd3, 0xde, 0x2d, 0xeb, 0xa7, 0x44, 0x27, 0x81, 0x12, 0x89, 0x36, + 0x5f, 0x3b, 0x56, 0x6e, 0xb1, 0x96, 0x04, 0xfb, 0x5e, 0xd7, 0xf7, 0xff, + 0x74, 0xd4, 0x49, 0x2f, 0xdf, 0x05, 0x25, 0xfc, 0x56, 0xcf, 0x54, 0xfe, + 0x1f, 0x03, 0xb6, 0x53, 0x80, 0x00, 0xb9, 0x2e, 0xd1, 0x56, 0x4f, 0x95, + 0xce, 0x78, 0x63, 0x8f, 0x21, 0xc3, 0x8d, 0x47, 0xa0, 0x64, 0x74, 0x18, + 0x15, 0xbc, 0x6c, 0x29, 0xd0, 0x22, 0xa1, 0xa3, 0x3b, 0xea, 0xe8, 0x44, + 0x48, 0xab, 0xa7, 0x4e, 0x93, 0xb1, 0x0f, 0x80, 0x94, 0xbf, 0x8f, 0x63, + 0x72, 0x5b, 0x81, 0x3f, 0xe8, 0x7f, 0x7c, 0xe5, 0x0f, 0x24, 0x49, 0x35, + 0x37, 0xd1, 0x6d, 0xea, 0xef, 0x70, 0x78, 0xe0, 0x67, 0x87, 0x2b, 0xee, + 0xcd, 0x6f, 0x2d, 0x4b, 0x4c, 0x77, 0x57, 0x1f, 0x5b, 0xc8, 0x07, 0x78, + 0x63, 0xc6, 0xb1, 0x65, 0x27, 0x58, 0xfa, 0xf3, 0x0a, 0x41, 0xba, 0x9a, + 0x3b, 0x53, 0xcb, 0xa9, 0x23, 0x52, 0xec, 0xac, 0x67, 0x69, 0x94, 0x6b, + 0x5c, 0xec, 0xb0, 0x54, 0xe5, 0xa4, 0xa4, 0x7d, 0xf9, 0xb9, 0xe2, 0x93, + 0xe2, 0x9c, 0xd7, 0x07, 0xb9, 0xf6, 0x5f, 0x37, 0x82, 0xf5, 0x83, 0xa3, + 0x5e, 0xd1, 0x75, 0x14, 0xdb, 0x25, 0x43, 0xae, 0x82, 0xfa, 0x1f, 0x76, + 0x24, 0x4e, 0x0e, 0xf7, 0x50, 0xee, 0x2b, 0x50, 0xcd, 0xaa, 0x56, 0x91, + 0x42, 0x7b, 0xd3, 0xa8, 0xe2, 0x33, 0x3b, 0x7b, 0xe1, 0xaa, 0x22, 0x14, + 0xb6, 0x76, 0x62, 0x3a, 0x98, 0xcc, 0x45, 0xdc, 0xbb, 0x0c, 0x34, 0x96, + 0xe6, 0x64, 0x80, 0x1d, 0x14, 0x5b, 0xa3, 0x25, 0xf5, 0x94, 0x7e, 0xc9, + 0x2c, 0x6c, 0xc0, 0xc7, 0x62, 0x05, 0x02, 0xc7, 0x42, 0x2f, 0x0b, 0xd0, + 0x66, 0xa7, 0x21, 0xcb, 0x1a, 0xea, 0x0f, 0xf5, 0x34, 0x7f, 0x06, 0xc0, + 0xbf, 0x8a, 0x3b, 0xdf, 0x58, 0xed, 0x18, 0x47, 0x22, 0x03, 0xe0, 0xb1, + 0x49, 0x3d, 0x02, 0xde, 0x37, 0x89, 0xa1, 0xd7, 0x69, 0xf0, 0x2e, 0x39, + 0xaf, 0xde, 0x92, 0xbf, 0xde, 0x24, 0xa7, 0x2b, 0x23, 0xf7, 0x37, 0x1b, + 0x86, 0xf6, 0x67, 0x7a, 0x3d, 0xef, 0xf9, 0x62, 0xae, 0xc2, 0x39, 0x91, + 0x21, 0xa8, 0x12, 0x39, 0x87, 0x44, 0xc3, 0x2f, 0xc7, 0x78, 0x72, 0x94, + 0xd1, 0x2e, 0x41, 0xd1, 0x75, 0x41, 0x78, 0x48, 0x9c, 0x55, 0xcc, 0x97, + 0x52, 0x2e, 0x40, 0x8f, 0xe9, 0xef, 0xfb, 0x1b, 0x02, 0xcd, 0x9f, 0x1d, + 0x38, 0xc6, 0x00, 0x4a, 0x4a, 0xc1, 0x7b, 0x4d, 0xc7, 0xcb, 0x80, 0x60, + 0x4c, 0x40, 0xcc, 0xae, 0xaf, 0x41, 0x87, 0x99, 0x56, 0xb6, 0xf5, 0x7a, + 0xa2, 0x2a, 0x23, 0x70, 0x97, 0x40, 0x78, 0x10, 0xcc, 0x06, 0x5f, 0xdd, + 0xcc, 0x4b, 0x95, 0x50, 0x0f, 0x38, 0x4c, 0x14, 0x58, 0x45, 0xa6, 0xa4, + 0x12, 0x71, 0x53, 0xfb, 0x06, 0x85, 0x67, 0xfe, 0x4c, 0x75, 0x24, 0x84, + 0x5c, 0x86, 0x5c, 0x3e, 0xb4, 0x83, 0x49, 0xfc, 0xd0, 0xd2, 0x21, 0x51, + 0xdc, 0xb9, 0xcb, 0x04, 0x37, 0x68, 0x71, 0x2d, 0x34, 0xea, 0x58, 0x73, + 0xf2, 0x3c, 0x1c, 0x97, 0x18, 0xc8, 0xb5, 0x70, 0xd7, 0xd5, 0x78, 0xf4, + 0xc6, 0x89, 0xd4, 0xb5, 0xc0, 0xfc, 0x7c, 0xe1, 0x1b, 0xd9, 0xac, 0x05, + 0x84, 0x00, 0x9d, 0xb0, 0x58, 0x9a, 0xe7, 0x89, 0xe4, 0x9a, 0x3b, 0xe5, + 0xa1, 0xf5, 0x11, 0x9d, 0xa1, 0x16, 0xf5, 0x1a, 0xa2, 0xfd, 0x66, 0xd9, + 0xf9, 0xb9, 0x26, 0xcc, 0x50, 0x9e, 0x9a, 0xfb, 0xfd, 0xda, 0x7e, 0x07, + 0x38, 0xbe, 0xa2, 0x36, 0xc3, 0xc1, 0x21, 0x19, 0xaa, 0xa9, 0x8a, 0x4e, + 0x97, 0x26, 0x17, 0x27, 0xbc, 0x42, 0xd9, 0x49, 0x61, 0x38, 0x9c, 0x93, + 0x1e, 0x85, 0x0c, 0x67, 0xc6, 0x14, 0x63, 0xaf, 0x03, 0x21, 0xac, 0xcc, + 0x97, 0x42, 0x1a, 0xfc, 0xee, 0x2e, 0xcc, 0xb3, 0x4d, 0xaf, 0x80, 0xe8, + 0x34, 0x12, 0x77, 0xaa, 0xf2, 0x98, 0x63, 0x32, 0xe1, 0x5e, 0x3a, 0x07, + 0xa9, 0x4e, 0x26, 0xbf, 0x5e, 0x43, 0x4b, 0x20, 0xff, 0xa4, 0x0f, 0xd7, + 0x38, 0x20, 0x6f, 0xa2, 0x83, 0x41, 0xac, 0x3b, 0xc6, 0xed, 0xb1, 0x89, + 0xb5, 0x6c, 0x71, 0xfc, 0xd9, 0xad, 0x30, 0x91, 0x60, 0x0d, 0xf2, 0x5d, + 0x0f, 0x8e, 0xee, 0x4f, 0x45, 0x13, 0x45, 0x4d, 0xe3, 0xd0, 0x36, 0xb1, + 0x9a, 0x92, 0x16, 0x99, 0x31, 0x99, 0x6a, 0x95, 0x66, 0x48, 0x8e, 0x7a, + 0xab, 0xac, 0xea, 0xd9, 0x6f, 0x69, 0x66, 0x15, 0x90, 0xe4, 0xdf, 0x0f, + 0xe8, 0x36, 0x86, 0x5f, 0xe2, 0x0a, 0x44, 0x36, 0xfe, 0x7d, 0x1d, 0x50, + 0x45, 0x5d, 0x69, 0x4a, 0xf7, 0x4e, 0xd5, 0xc6, 0xb8, 0xc4, 0xee, 0x98, + 0x2f, 0x19, 0xc2, 0x77, 0xcc, 0x7c, 0xbe, 0xfd, 0x4a, 0xd1, 0x27, 0xb8, + 0x79, 0x88, 0x89, 0x9c, 0x61, 0x77, 0xcf, 0x19, 0xb7, 0x4b, 0x76, 0x4d, + 0xe6, 0x85, 0x4c, 0x8b, 0x8d, 0xb8, 0x8e, 0x2d, 0xf0, 0x34, 0x67, 0xcb, + 0x8e, 0x66, 0xca, 0xfb, 0x32, 0x13, 0x6e, 0x0c, 0xaa, 0x07, 0x83, 0xdc, + 0x56, 0xb0, 0x11, 0x0f, 0x30, 0xda, 0x9d, 0x15, 0xe2, 0x71, 0x2f, 0x3f, + 0x1f, 0x07, 0x83, 0x8f, 0xe5, 0xdf, 0xc2, 0xa2, 0x52, 0x4c, 0xf8, 0xb3, + 0xbd, 0x94, 0x7b, 0x4f, 0x9f, 0x42, 0x07, 0xb7, 0x68, 0xcb, 0x43, 0x82, + 0xd1, 0x34, 0x85, 0x99, 0xce, 0x9c, 0x68, 0xfe, 0x83, 0xc4, 0x30, 0x01, + 0x51, 0xbb, 0x1a, 0x6b, 0xc0, 0x51, 0x8e, 0x27, 0xcd, 0xbb, 0x0c, 0x2f, + 0x06, 0x30, 0x13, 0x4c, 0x8d, 0x6a, 0xe2, 0x0a, 0x41, 0x5e, 0xab, 0x63, + 0x5a, 0x33, 0x23, 0x5a, 0xce, 0x04, 0x0b, 0x6f, 0xba, 0xc0, 0x82, 0x77, + 0xef, 0x5c, 0x3a, 0x27, 0xf7, 0x63, 0xe0, 0xae, 0x1d, 0x29, 0xb4, 0x3c, + 0xd1, 0xbb, 0x22, 0x4d, 0xa3, 0x85, 0x40, 0x8f, 0x69, 0x76, 0x13, 0x41, + 0xf1, 0x71, 0x76, 0x44, 0x56, 0x8a, 0x0d, 0x7e, 0x16, 0x06, 0x7e, 0x22, + 0x4f, 0x79, 0x59, 0x19, 0xda, 0x09, 0x6b, 0x2f, 0x56, 0x4c, 0x5b, 0x64, + 0x37, 0x87, 0x75, 0x91, 0xca, 0xc3, 0xc4, 0x21, 0x25, 0x89, 0x98, 0xf5, + 0xc7, 0x05, 0x23, 0x4a, 0xd9, 0x50, 0xb7, 0xc2, 0x87, 0x98, 0x1f, 0xaf, + 0x86, 0xf9, 0x56, 0xf7, 0xdd, 0x18, 0x4e, 0x8e, 0xd8, 0xe5, 0xe3, 0x3b, + 0x0b, 0x63, 0xa2, 0x69, 0xb7, 0x0b, 0x77, 0x14, 0xb5, 0x9b, 0x89, 0x79, + 0x90, 0xe0, 0xe6, 0x12, 0x9c, 0x4d, 0x84, 0xbc, 0x26, 0x54, 0xde, 0x6f, + 0xbf, 0xac, 0x18, 0x6c, 0xa0, 0x74, 0x66, 0xcc, 0xe4, 0xdf, 0x94, 0xe7, + 0xd9, 0xce, 0xe9, 0xb1, 0x3b, 0xcf, 0xdc, 0x38, 0xab, 0x43, 0x37, 0x16, + 0x3a, 0xa0, 0x0c, 0xe9, 0x47, 0xe1, 0x8f, 0x51, 0x74, 0x8d, 0x0b, 0x76, + 0xf7, 0x8e, 0x02, 0x30, 0x74, 0x5d, 0x0b, 0x7a, 0x7a, 0x2d, 0x57, 0x71, + 0xe7, 0x82, 0x80, 0xb6, 0x08, 0x3e, 0xa3, 0x65, 0xa7, 0xcf, 0x03, 0x67, + 0x65, 0xbd, 0x65, 0x52, 0x3a, 0xcc, 0x44, 0x22, 0x50, 0x56, 0x28, 0x20, + 0x95, 0x23, 0x7b, 0xa3, 0xf9, 0x4f, 0xec, 0x9a, 0x34, 0xa3, 0xe3, 0x09, + 0x98, 0x19, 0x50, 0x2a, 0x21, 0x81, 0x49, 0xa0, 0xd7, 0x5c, 0x44, 0xb7, + 0x2f, 0x7e, 0x01, 0x7d, 0xd9, 0xab, 0xe6, 0xdb, 0x88, 0x74, 0x60, 0x4d, + 0xb7, 0x51, 0x86, 0x00, 0x1f, 0x29, 0x6c, 0x6f, 0x57, 0x9b, 0xeb, 0xae, + 0x13, 0x91, 0x09, 0xe1, 0x53, 0x8b, 0x25, 0x17, 0xfe, 0xf3, 0x93, 0x7a, + 0x12, 0x92, 0x11, 0x4b, 0x52, 0x26, 0x9e, 0x37, 0x3f, 0x64, 0x50, 0x6c, + 0x4c, 0xbf, 0x94, 0x9d, 0x3d, 0xf4, 0x16, 0xce, 0x3f, 0xdc, 0xbf, 0x2e, + 0x07, 0xbe, 0xc6, 0x38, 0x1d, 0xc0, 0xc0, 0x18, 0x4a, 0x65, 0xe9, 0x51, + 0x55, 0xbc, 0x44, 0xd2, 0x90, 0x8a, 0x06, 0x3e, 0x36, 0x0c, 0x80, 0x98, + 0x1c, 0x8f, 0xfc, 0x88, 0x84, 0x6e, 0xc5, 0xf6, 0xf4, 0x35, 0xb2, 0x03, + 0xf2, 0xef, 0xb2, 0x19, 0x40, 0x2b, 0xf1, 0xec, 0x9d, 0x51, 0x8b, 0xcf, + 0xe7, 0xa9, 0x57, 0x71, 0x8a, 0x0f, 0xc6, 0xb7, 0xf4, 0xdb, 0xa9, 0x91, + 0xb8, 0xd2, 0x75, 0x94, 0x4e, 0x73, 0xea, 0x13, 0xd7, 0x44, 0xd8, 0xb6, + 0xe0, 0xcb, 0x9e, 0xbf, 0x01, 0xfa, 0x1e, 0xfd, 0xf6, 0xb8, 0x0f, 0x26, + 0x72, 0x2b, 0xe2, 0x17, 0x75, 0x35, 0x78, 0x10, 0x81, 0x19, 0xb4, 0xee, + 0xbb, 0xbd, 0xb2, 0x17, 0x78, 0x16, 0xa6, 0x7d, 0x05, 0x4b, 0x6a, 0x97, + 0x85, 0x79, 0xd7, 0xbf, 0x41, 0x96, 0x2f, 0xcf, 0xfa, 0xe0, 0xcd, 0x0e, + 0xbf, 0x96, 0x00, 0xe8, 0xc0, 0xbc, 0x7f, 0x19, 0x52, 0x27, 0x4d, 0x5f, + 0xcd, 0xff, 0x81, 0xe7, 0x8b, 0x16, 0xce, 0xfe, 0x97, 0x25, 0x77, 0x73, + 0x72, 0x32, 0x52, 0x57, 0x6d, 0x58, 0x3e, 0x72, 0x47, 0xf4, 0x92, 0x79, + 0x8e, 0xcc, 0x10, 0x54, 0x95, 0x8f, 0x4c, 0x54, 0x71, 0x06, 0x23, 0xd6, + 0xa5, 0x55, 0xbc, 0x0f, 0x92, 0x15, 0x11, 0xf5, 0xdf, 0x28, 0x7a, 0x17, + 0x48, 0x94, 0x17, 0x3a, 0xc2, 0xbc, 0x44, 0x11, 0x28, 0x41, 0x4a, 0x72, + 0x68, 0xfb, 0x9e, 0xbc, 0x00, 0xea, 0x95, 0xd2, 0x6d, 0x32, 0xba, 0x6f, + 0xad, 0xab, 0xa1, 0x09, 0xaa, 0x19, 0x4f, 0x19, 0x30, 0xad, 0x7c, 0x1f, + 0xcf, 0xae, 0x0c, 0x69, 0x5c, 0x6c, 0x98, 0x78, 0x64, 0xa9, 0x68, 0x0f, + 0x92, 0x7a, 0x06, 0xa1, 0xf3, 0x01, 0x3f, 0x8e, 0x66, 0xf1, 0x3f, 0x52, + 0xec, 0x94, 0x8c, 0x7f, 0x96, 0x42, 0xf5, 0x70, 0x84, 0xf2, 0x0c, 0x6b, + 0xcf, 0x40, 0xa5, 0x28, 0x2f, 0x36, 0xa3, 0x48, 0xa7, 0x06, 0x4d, 0x19, + 0x6d, 0xa9, 0x7c, 0xe9, 0xde, 0xba, 0x18, 0x7b, 0x64, 0x03, 0xfe, 0x99, + 0xd2, 0x06, 0x02, 0xb3, 0x29, 0xa2, 0xd8, 0x87, 0x7e, 0x4a, 0xab, 0x41, + 0xff, 0x29, 0x81, 0x54, 0xab, 0x3f, 0xd6, 0xd3, 0xa1, 0x00, 0xbc, 0x98, + 0x96, 0x77, 0x28, 0x09, 0x08, 0xa9, 0xd3, 0x0e, 0xd6, 0xd7, 0x1f, 0x04, + 0xa2, 0xf7, 0x5d, 0xeb, 0x10, 0x48, 0x03, 0xb2, 0x4e, 0xb1, 0xc7, 0x8e, + 0xeb, 0x7d, 0x92, 0x9a, 0xcb, 0x5d, 0x99, 0xe4, 0xdd, 0x25, 0x37, 0x6b, + 0x9c, 0x26, 0xac, 0x96, 0x72, 0xf0, 0xe6, 0xc8, 0x31, 0xe0, 0x6f, 0xa4, + 0x5f, 0xfa, 0xaf, 0x13, 0xd8, 0xde, 0x2f, 0x00, 0xa7, 0x98, 0x79, 0x00, + 0xad, 0x11, 0xc8, 0x51, 0x77, 0xbf, 0xc6, 0x95, 0xb9, 0x79, 0x16, 0xe8, + 0xa2, 0x5b, 0xf5, 0x83, 0xdc, 0xc4, 0x24, 0xa8, 0x20, 0x43, 0x21, 0x87, + 0x57, 0x67, 0x9d, 0x50, 0x12, 0x54, 0x4e, 0x1a, 0x44, 0xf6, 0x70, 0x4a, + 0xca, 0x01, 0x0c, 0xa1, 0x89, 0xd3, 0xef, 0x97, 0x91, 0x20, 0x2b, 0x2d, + 0xd1, 0xfe, 0xa9, 0x27, 0x52, 0xa1, 0xa4, 0xfe, 0x34, 0x00, 0xef, 0x40, + 0x28, 0xc9, 0x21, 0x5e, 0x97, 0xf8, 0xf6, 0xc3, 0x61, 0x01, 0x6b, 0x93, + 0xcc, 0xb1, 0x24, 0x93, 0x8c, 0x4e, 0x09, 0xaf, 0x0b, 0x96, 0x8b, 0xfa, + 0x19, 0xff, 0x1f, 0xf9, 0x3b, 0x79, 0x80, 0xa9, 0xfe, 0x43, 0x54, 0x32, + 0x2b, 0xa2, 0xeb, 0x66, 0xc9, 0x2c, 0x60, 0xc2, 0x0c, 0x27, 0xf3, 0xca, + 0xc6, 0x64, 0x50, 0xe7, 0x97, 0xc1, 0xa6, 0x6c, 0x7e, 0x76, 0xf6, 0x5c, + 0x05, 0x39, 0x13, 0x13, 0xa8, 0x34, 0xaf, 0xaa, 0xf1, 0xed, 0xbe, 0x57, + 0xf7, 0xde, 0x44, 0x46, 0xf4, 0xb2, 0x9b, 0xd5, 0x38, 0xd8, 0xc5, 0x28, + 0xe9, 0xb8, 0x2a, 0x8f, 0x83, 0x91, 0xb8, 0x8c, 0x15, 0x4c, 0x8f, 0x0c, + 0xfe, 0x78, 0x63, 0x8b, 0x9b, 0x79, 0x6a, 0xd2, 0x2b, 0x1d, 0x55, 0x73, + 0x32, 0x6c, 0x23, 0xdb, 0x2e, 0x23, 0x1c, 0x5c, 0x56, 0x14, 0x1f, 0xf7, + 0x88, 0x98, 0x47, 0x5c, 0xeb, 0x54, 0x17, 0xb1, 0x62, 0x69, 0xa3, 0x0d, + 0x73, 0xc5, 0x4c, 0x44, 0x80, 0xb6, 0x8c, 0x7f, 0x7e, 0xb3, 0x1e, 0xbc, + 0x2e, 0x86, 0x79, 0xb4, 0x51, 0xc5, 0x94, 0xb0, 0x28, 0x69, 0x04, 0x5f, + 0xab, 0xdf, 0xed, 0xf4, 0xe1, 0x80, 0x13, 0x93, 0x72, 0x21, 0xf6, 0x7c, + 0x6a, 0x88, 0xb8, 0x7e, 0x3e, 0x64, 0xf6, 0x34, 0xd9, 0x7f, 0x66, 0x07, + 0xed, 0x0d, 0x30, 0xe9, 0x7b, 0x18, 0x59, 0xdf, 0x87, 0xa6, 0x17, 0x4d, + 0x02, 0x17, 0x39, 0x4f, 0x75, 0xd5, 0x3f, 0xfe, 0x18, 0x06, 0x62, 0x4f, + 0xb7, 0x1a, 0x54, 0xb2, 0x10, 0x19, 0xdc, 0x48, 0xb1, 0x15, 0xd5, 0x03, + 0xdb, 0xbd, 0xd0, 0xdf, 0x1d, 0xab, 0x00, 0xd4, 0x0a, 0x35, 0xaf, 0xc1, + 0xac, 0x82, 0x2a, 0x70, 0xfa, 0x5c, 0xb9, 0x98, 0x38, 0x1d, 0xfb, 0x67, + 0x56, 0x4e, 0x4d, 0x5b, 0x70, 0xca, 0x32, 0x20, 0x9a, 0x08, 0xeb, 0x5f, + 0xaa, 0x5b, 0x50, 0x9e, 0x26, 0x62, 0x0a, 0xf7, 0x62, 0xbd, 0x06, 0x68, + 0x4e, 0xeb, 0x67, 0x8c, 0xfa, 0x27, 0x1f, 0x3a, 0x0a, 0xe3, 0x8d, 0x50, + 0x5a, 0x4d, 0x1c, 0x79, 0xeb, 0xfd, 0x05, 0x6d, 0x2e, 0x4b, 0x8b, 0xba, + 0xa9, 0x2a, 0x22, 0x50, 0xbf, 0xef, 0xca, 0x54, 0x50, 0xdf, 0x27, 0x7d, + 0xef, 0x57, 0x99, 0x90, 0x0e, 0xb3, 0xda, 0x67, 0x25, 0x58, 0xf7, 0x0c, + 0xc5, 0x30, 0x55, 0x71, 0xe3, 0xd2, 0x16, 0x8c, 0x4e, 0xaf, 0x4b, 0x65, + 0x45, 0xf4, 0x95, 0x0f, 0x83, 0xaa, 0x21, 0xf9, 0x0a, 0xf3, 0x3b, 0xbe, + 0xa6, 0xc9, 0x28, 0x8d, 0x07, 0x45, 0x59, 0x62, 0x27, 0x67, 0xc9, 0x41, + 0x05, 0x27, 0xce, 0x0b, 0x0f, 0x7a, 0x95, 0xc7, 0x25, 0x5e, 0x8a, 0x10, + 0x9b, 0x01, 0xc6, 0x55, 0xe7, 0x5c, 0xd6, 0x2f, 0x4f, 0x21, 0xb3, 0x79, + 0x68, 0xfe, 0x5c, 0xcb, 0xc8, 0x57, 0x8c, 0x09, 0x22, 0xe1, 0x8e, 0xe4, + 0xe1, 0x6c, 0x96, 0x27, 0xfe, 0x58, 0x8a, 0xe5, 0x2b, 0xb6, 0x2a, 0x68, + 0xa7, 0x2b, 0xc5, 0xfd, 0x4e, 0xce, 0xec, 0x1e, 0xdf, 0xb0, 0xb3, 0xb8, + 0x5e, 0x9c, 0x9e, 0x75, 0xf3, 0x15, 0xd8, 0x0e, 0x37, 0x7c, 0x2e, 0x28, + 0xfc, 0x1a, 0x1f, 0xc2, 0xaa, 0xf8, 0x33, 0xbc, 0xdf, 0xe7, 0x2c, 0xf1, + 0x1f, 0xf5, 0xbb, 0x3c, 0x12, 0x9f, 0xd6, 0xdd, 0x60, 0xfa, 0x78, 0x6c, + 0xfe, 0x63, 0x2a, 0xc7, 0xe6, 0x0a, 0x6e, 0x2b, 0x46, 0x5a, 0xda, 0x38, + 0x4b, 0xc5, 0xeb, 0xb9, 0x06, 0x70, 0xea, 0xc6, 0x6c, 0x70, 0x10, 0x71, + 0xb5, 0xe1, 0x1e, 0x00, 0x3f, 0xec, 0xab, 0x2d, 0x07, 0xb1, 0xd8, 0x63, + 0x41, 0x63, 0x69, 0x67, 0xf5, 0xd1, 0x15, 0x00, 0x3e, 0x24, 0xbe, 0x03, + 0x4d, 0x5d, 0x20, 0x00, 0xbb, 0x55, 0xc3, 0xae, 0x2d, 0x83, 0xe7, 0x15, + 0x32, 0xe7, 0x06, 0x1c, 0x07, 0x41, 0xef, 0x18, 0x92, 0x6f, 0xe5, 0xef, + 0x81, 0xf6, 0x80, 0xb5, 0x69, 0x2b, 0x27, 0x2c, 0x1e, 0x51, 0x2d, 0xea, + 0x56, 0x73, 0x1e, 0x64, 0x53, 0x1f, 0x90, 0xca, 0xf3, 0x4c, 0x33, 0x44, + 0x75, 0xed, 0xb2, 0xff, 0x5d, 0x09, 0xe8, 0xa8, 0x2c, 0xc9, 0x7c, 0x97, + 0xc5, 0xec, 0x13, 0x3e, 0xf1, 0x37, 0x3c, 0x98, 0x08, 0x68, 0xf7, 0x7d, + 0x7a, 0xfd, 0x87, 0x52, 0xd7, 0xd8, 0x16, 0x06, 0x87, 0xaa, 0xb4, 0xa1, + 0xe7, 0x1f, 0x20, 0x5e, 0xbb, 0x77, 0x0b, 0xc8, 0xab, 0xb2, 0xcd, 0x97, + 0x22, 0x52, 0xe7, 0x60, 0x8b, 0x9a, 0x38, 0x60, 0xc8, 0x35, 0x9a, 0xcf, + 0x7f, 0xcd, 0xb5, 0xd7, 0xea, 0xc1, 0x9b, 0xc4, 0x2f, 0xe2, 0x0a, 0x0a, + 0xd1, 0x5a, 0x52, 0x2c, 0xa4, 0x07, 0xf7, 0x82, 0x8d, 0xc8, 0xdf, 0x4f, + 0xa4, 0x7c, 0x02, 0x21, 0xea, 0x41, 0x46, 0x02, 0xc1, 0xed, 0x8f, 0x7d, + 0x11, 0x57, 0x29, 0x04, 0x22, 0x96, 0x56, 0xd6, 0xf6, 0x02, 0xa7, 0x61, + 0xa7, 0x9b, 0xd7, 0x68, 0xb7, 0xc3, 0x1f, 0x13, 0xa3, 0xb5, 0xfb, 0xbf, + 0x6a, 0xba, 0xdb, 0x0c, 0x9a, 0x26, 0x97, 0x0f, 0x6d, 0x2a, 0xb3, 0x5b, + 0x8b, 0x74, 0x7e, 0x28, 0x9a, 0x33, 0xd3, 0x85, 0xd8, 0x22, 0xaa, 0xe1, + 0xa2, 0x60, 0xbb, 0x7c, 0x07, 0x27, 0x3c, 0x40, 0x5b, 0x01, 0x18, 0x46, + 0xb4, 0x02, 0x84, 0xd8, 0x31, 0x69, 0x5f, 0x81, 0x22, 0x88, 0x05, 0x3b, + 0x45, 0x33, 0xab, 0x5e, 0xd6, 0xaf, 0x50, 0x38, 0x01, 0x85, 0x77, 0x3d, + 0x6d, 0xc0, 0xec, 0xc8, 0xf0, 0xb0, 0x80, 0xec, 0x7e, 0x90, 0x58, 0x2c, + 0xcf, 0x6a, 0x97, 0x85, 0x5e, 0x0e, 0x8b, 0x31, 0x7e, 0x3a, 0xf3, 0x7c, + 0x4c, 0xf9, 0x80, 0x30, 0xcc, 0xf6, 0x9f, 0x7e, 0x65, 0xe1, 0xdb, 0x5e, + 0x37, 0xc3, 0xda, 0xa2, 0x37, 0xab, 0x21, 0xb1, 0xc6, 0x05, 0xd9, 0xf8, + 0x26, 0x98, 0xf1, 0x78, 0x4e, 0x0e, 0xc3, 0x30, 0x51, 0x76, 0xaf, 0xf9, + 0x04, 0x50, 0xc6, 0x39, 0xd3, 0x37, 0xff, 0xe0, 0x41, 0xc0, 0x2d, 0xcb, + 0xba, 0x9c, 0xc9, 0x21, 0xa2, 0x02, 0xef, 0x03, 0x5e, 0x57, 0xc4, 0x53, + 0x11, 0x8c, 0xb0, 0xee, 0x4e, 0xc6, 0xc4, 0xca, 0x73, 0x03, 0x56, 0x9f, + 0x9c, 0xf3, 0xf1, 0x4e, 0xb9, 0x20, 0xaa, 0x5b, 0xba, 0x7a, 0x55, 0xf1, + 0x86, 0xc5, 0x63, 0xd7, 0x4e, 0x6c, 0x8d, 0x0c, 0x5a, 0x4d, 0x34, 0x56, + 0x31, 0x61, 0x3f, 0xbe, 0x0a, 0x5e, 0xbd, 0x05, 0xaf, 0xc8, 0x80, 0x11, + 0x4c, 0x8a, 0x53, 0x67, 0xed, 0x75, 0xe5, 0x4e, 0xa2, 0xed, 0x41, 0xe0, + 0x70, 0xc4, 0x8f, 0x83, 0xee, 0xe1, 0xf9, 0xf1, 0xe8, 0x2f, 0xd2, 0x87, + 0xcf, 0x9d, 0x06, 0xf7, 0xca, 0x3d, 0x51, 0x59, 0x57, 0xf6, 0x94, 0xe2, + 0xf4, 0xa0, 0xa8, 0x3c, 0x48, 0x5d, 0x81, 0xae, 0x4f, 0x15, 0x84, 0xeb, + 0xf8, 0x09, 0x69, 0x1b, 0x51, 0x77, 0xd2, 0xba, 0x11, 0x76, 0x1e, 0x1c, + 0xcc, 0xf5, 0x85, 0x90, 0xc8, 0x73, 0x67, 0x43, 0x64, 0xf2, 0x9e, 0x1e, + 0xa2, 0xd5, 0x65, 0x9a, 0xb9, 0xd9, 0x45, 0x2b, 0x09, 0x4c, 0xa5, 0xa3, + 0x36, 0x25, 0xa8, 0x37, 0xd9, 0xd7, 0x14, 0xca, 0x33, 0xa4, 0xee, 0x50, + 0x6e, 0x53, 0x8f, 0x14, 0xfc, 0x6b, 0x09, 0x54, 0x01, 0x53, 0xef, 0xce, + 0xd2, 0x74, 0x51, 0xcf, 0x06, 0x62, 0xb2, 0xd2, 0x6c, 0xf7, 0x21, 0xce, + 0x5e, 0x0d, 0x98, 0x98, 0xc3, 0x3a, 0x9e, 0xbe, 0x41, 0x3d, 0x45, 0xdb, + 0xea, 0xa4, 0x10, 0xaf, 0x60, 0x08, 0xd3, 0x95, 0x42, 0x28, 0x6e, 0xb5, + 0xf4, 0xb0, 0x02, 0x0c, 0x7e, 0x73, 0xb4, 0xa3, 0x55, 0x83, 0x37, 0x0f, + 0x72, 0x2d, 0x80, 0x4a, 0xea, 0x39, 0x7f, 0xd7, 0x6a, 0xb1, 0x7b, 0x2a, + 0xd5, 0x8a, 0x42, 0x7d, 0xaa, 0x60, 0x03, 0x98, 0x79, 0x58, 0xcb, 0x72, + 0xc9, 0xc3, 0x6d, 0xbc, 0x62, 0x06, 0x82, 0x50, 0xe4, 0x5d, 0xad, 0x76, + 0xcd, 0x3c, 0xe1, 0xa2, 0x24, 0x84, 0xc5, 0xc5, 0xf6, 0x92, 0xef, 0x9a, + 0xb8, 0xd3, 0x89, 0x8a, 0x75, 0xa8, 0xd5, 0xac, 0x4f, 0x32, 0x9f, 0x37, + 0x78, 0x41, 0x52, 0x93, 0x55, 0x46, 0xaa, 0xa9, 0x31, 0x96, 0xca, 0x84, + 0x39, 0x15, 0x85, 0x61, 0xb3, 0xb9, 0x29, 0x99, 0x39, 0x52, 0xb2, 0x54, + 0xb0, 0xdf, 0xc3, 0x70, 0xb7, 0x08, 0x07, 0x3f, 0xf9, 0x91, 0x39, 0x80, + 0x6b, 0xda, 0xb8, 0x74, 0x2b, 0xd9, 0x4b, 0x85, 0x9e, 0xaf, 0x9c, 0x76, + 0x13, 0x4d, 0xd9, 0x11, 0x7a, 0x42, 0xeb, 0x90, 0xb0, 0xbc, 0x62, 0x3c, + 0x03, 0x5d, 0x6a, 0x43, 0x42, 0x13, 0xc3, 0x54, 0x65, 0xf2, 0x4a, 0x53, + 0x66, 0x69, 0x5a, 0x7a, 0x1a, 0x94, 0x87, 0x67, 0xb6, 0x4e, 0xd2, 0x25, + 0xf2, 0x0c, 0x80, 0x0f, 0x69, 0x8f, 0xdd, 0xcb, 0x6f, 0xca, 0x49, 0xe1, + 0x76, 0xf7, 0x54, 0xb9, 0x5d, 0xdd, 0xb1, 0x14, 0xe6, 0x0e, 0x3b, 0x97, + 0xc6, 0x70, 0x7e, 0x7e, 0xf7, 0xa9, 0xb0, 0x7c, 0xbc, 0xb2, 0xf0, 0x73, + 0x8f, 0x88, 0xbe, 0xdb, 0xdc, 0x11, 0x38, 0xa9, 0x91, 0xa6, 0x72, 0x63, + 0x8a, 0x55, 0x0d, 0x98, 0xeb, 0xdb, 0xbf, 0x1e, 0xfb, 0x75, 0x09, 0xaf, + 0x2f, 0x52, 0xef, 0xb6, 0x8f, 0x02, 0x37, 0xd2, 0xe0, 0xdb, 0xb7, 0xfc, + 0x34, 0xb7, 0xef, 0x4c, 0xbf, 0x82, 0x4b, 0xa9, 0x1c, 0x73, 0xce, 0xf5, + 0xc4, 0x30, 0x5b, 0x80, 0xdd, 0xaf, 0xa9, 0x2a, 0xbe, 0xd0, 0x68, 0x21, + 0xe2, 0x2d, 0xcb, 0x81, 0x1b, 0xba, 0xc3, 0x37, 0xf0, 0x57, 0x73, 0xf9, + 0xe0, 0x6f, 0x7e, 0xfd, 0x70, 0xb6, 0x62, 0x97, 0xe4, 0x22, 0xa2, 0x63, + 0x81, 0x85, 0x31, 0x3b, 0xb6, 0x97, 0xe8, 0x84, 0x89, 0x7e, 0xe3, 0x06, + 0x71, 0x78, 0x4a, 0x87, 0x37, 0x46, 0xc9, 0x86, 0x10, 0x66, 0xed, 0xfe, + 0xb1, 0xe7, 0x90, 0x19, 0x5f, 0x88, 0xbb, 0x0b, 0x14, 0x3f, 0xc4, 0x68, + 0x11, 0x45, 0xa1, 0xed, 0xb3, 0x4a, 0x2d, 0x8f, 0x3d, 0x9d, 0x90, 0x8c, + 0x49, 0xb4, 0xf1, 0xbf, 0xad, 0x55, 0x95, 0xe4, 0x1e, 0x11, 0x67, 0x3d, + 0xcf, 0x75, 0x04, 0x51, 0x3a, 0xe5, 0xab, 0x7f, 0xf8, 0x94, 0x9c, 0x7d, + 0x48, 0xa4, 0xa7, 0x53, 0x03, 0x7b, 0xd7, 0xbf, 0xf1, 0x25, 0xae, 0x90, + 0x29, 0x0a, 0xde, 0x4a, 0xed, 0x89, 0x68, 0x73, 0xe4, 0x07, 0x64, 0xe2, + 0x82, 0xc4, 0x15, 0xd7, 0xb9, 0xe1, 0x49, 0x14, 0x40, 0xa3, 0xf8, 0x7e, + 0xbb, 0x8c, 0x45, 0xca, 0x2e, 0xf9, 0x78, 0x39, 0x89, 0x75, 0xa6, 0x94, + 0xf8, 0x67, 0xc4, 0xcd, 0x20, 0x0a, 0x45, 0xdc, 0xf4, 0x43, 0x4c, 0xe3, + 0x47, 0x3e, 0xfa, 0x1e, 0x60, 0xba, 0x06, 0x79, 0x4f, 0x53, 0x5c, 0x27, + 0xbc, 0xb3, 0x89, 0x55, 0x16, 0x55, 0xa8, 0xf9, 0x31, 0x2a, 0x5d, 0x9b, + 0x19, 0xa4, 0x05, 0xbd, 0x6d, 0x45, 0x1b, 0xd5, 0x7d, 0xd4, 0x04, 0x0b, + 0xc4, 0x4c, 0x9f, 0xb1, 0xcc, 0xa1, 0xf6, 0x9b, 0xce, 0x1f, 0x94, 0x54, + 0x4a, 0x98, 0xb1, 0x66, 0x95, 0xf0, 0x65, 0x84, 0x2b, 0x9c, 0xeb, 0x35, + 0x44, 0xf7, 0x95, 0xbb, 0x4e, 0x9f, 0xca, 0xbc, 0xae, +}; + +// +// slhdsa_shake256s_key.pem as C array +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mSlhDsaShake256sTestPemKey[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x50, + 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, + 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x47, 0x54, 0x41, 0x67, 0x45, 0x41, + 0x4d, 0x41, 0x73, 0x47, 0x43, 0x57, 0x43, 0x47, 0x53, 0x41, 0x46, 0x6c, + 0x41, 0x77, 0x51, 0x44, 0x48, 0x67, 0x53, 0x42, 0x67, 0x42, 0x62, 0x6b, + 0x6e, 0x63, 0x67, 0x70, 0x50, 0x73, 0x38, 0x65, 0x66, 0x42, 0x4b, 0x48, + 0x76, 0x77, 0x6e, 0x2b, 0x35, 0x6b, 0x4c, 0x31, 0x47, 0x70, 0x75, 0x6e, + 0x7a, 0x73, 0x2f, 0x35, 0x66, 0x71, 0x72, 0x2f, 0x0a, 0x50, 0x56, 0x39, + 0x4c, 0x46, 0x32, 0x49, 0x41, 0x69, 0x70, 0x6b, 0x32, 0x58, 0x6e, 0x44, + 0x7a, 0x66, 0x59, 0x4a, 0x5a, 0x2f, 0x68, 0x73, 0x56, 0x49, 0x64, 0x48, + 0x6c, 0x53, 0x57, 0x49, 0x2f, 0x42, 0x6b, 0x4a, 0x50, 0x76, 0x33, 0x5a, + 0x6c, 0x6a, 0x4e, 0x32, 0x41, 0x71, 0x43, 0x66, 0x59, 0x4e, 0x66, 0x72, + 0x33, 0x78, 0x68, 0x77, 0x57, 0x64, 0x71, 0x35, 0x48, 0x4b, 0x4c, 0x36, + 0x77, 0x0a, 0x79, 0x36, 0x7a, 0x6d, 0x35, 0x75, 0x69, 0x74, 0x4e, 0x47, + 0x43, 0x68, 0x51, 0x50, 0x55, 0x64, 0x54, 0x6e, 0x38, 0x79, 0x6f, 0x52, + 0x78, 0x70, 0x34, 0x4e, 0x45, 0x39, 0x6a, 0x70, 0x34, 0x6a, 0x33, 0x2f, + 0x4d, 0x71, 0x52, 0x61, 0x64, 0x64, 0x45, 0x70, 0x75, 0x73, 0x35, 0x64, + 0x75, 0x48, 0x67, 0x64, 0x79, 0x49, 0x6e, 0x38, 0x2b, 0x6b, 0x4e, 0x71, + 0x71, 0x77, 0x35, 0x6b, 0x35, 0x38, 0x0a, 0x4b, 0x64, 0x6f, 0x78, 0x31, + 0x4f, 0x54, 0x50, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, + 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b, 0x45, 0x59, + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, +}; diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/SlhDsaTests.c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/SlhDsaTests.c new file mode 100644 index 0000000000..83d1aec6f3 --- /dev/null +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/SlhDsaTests.c @@ -0,0 +1,1779 @@ +/** @file + Application for SLH-DSA Primitives Validation. + + This file contains unit tests for the SLH-DSA (Stateless Hash-Based Digital Signature Algorithm) + cryptographic functions defined in CryptSlhDsa.c. SLH-DSA is a post-quantum digital signature + scheme based on the SPHINCS+ algorithm and standardized in FIPS 205. + + The test vectors are provided in SlhDsaTestVectors.h which contains: + - mSlhDsaShake256sTestCert[] - X.509 DER certificate with SLH-DSA-SHAKE-256s public key + - mSlhDsaShake256sTestPemKey[] - PEM-encoded SLH-DSA-SHAKE-256s private key + + The test structure mirrors SlhDsaTests.c and validates: + - Context creation and destruction (SlhDsaNewByNid, SlhDsaFree) + - Key setting and retrieval error cases (SlhDsaSetPrivKey, SlhDsaSetPubKey, SlhDsaGetPubKey) + - Signature generation and verification via PEM/X509 (TestVerifySlhDsaPemX509) + - Error handling for invalid inputs + +Copyright (c) 2026, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "TestBaseCryptLib.h" + +#define SLH_DSA_SHAKE_256S_PRIVATE_KEY_SIZE 128 +#define SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE 64 +#define SLH_DSA_SHAKE_256S_SIGNATURE_SIZE 29792 +#define SLH_DSA_MAX_CONTEXT_SIZE 255 + +// +// SLH-DSA-SHAKE-256s test vectors - include generated certificate and PEM key +// +#include "SlhDsaTestVectors.h" + +// +// Test message for signing and verification +// +CONST CHAR8 *mSlhDsaTestMessage = "Test message for SLH-DSA signing and verification"; + +// +// Optional context string for domain separation +// +CONST CHAR8 *mSlhDsaTestContext = "SLH-DSA test context"; + +VOID *SlhDsaContext1; +VOID *SlhDsaContext2; + +/** + Prerequisite function for SLH-DSA tests. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaPreReq ( + UNIT_TEST_CONTEXT Context + ) +{ + SlhDsaContext1 = NULL; + SlhDsaContext2 = NULL; + + return UNIT_TEST_PASSED; +} + +/** + Cleanup function for SLH-DSA tests. + + @param[in] Context Unit test context. +**/ +VOID +EFIAPI +TestVerifySlhDsaCleanUp ( + UNIT_TEST_CONTEXT Context + ) +{ + if (SlhDsaContext1 != NULL) { + SlhDsaFree (SlhDsaContext1); + SlhDsaContext1 = NULL; + } + + if (SlhDsaContext2 != NULL) { + SlhDsaFree (SlhDsaContext2); + SlhDsaContext2 = NULL; + } +} + +/** + Validate UEFI-OpenSSL SLH-DSA Context Creation. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaNew ( + UNIT_TEST_CONTEXT Context + ) +{ + // + // Test SlhDsaNewByNid with SLH-DSA-87 + // + SlhDsaContext1 = SlhDsaNewByNid (CRYPTO_NID_SLH_DSA_SHAKE_256S); + UT_ASSERT_NOT_NULL (SlhDsaContext1); + + // + // Test SlhDsaNewByNid with invalid NID + // + SlhDsaContext2 = SlhDsaNewByNid (CRYPTO_NID_NULL); + UT_ASSERT_EQUAL ((UINTN)SlhDsaContext2, (UINTN)NULL); + + // + // Test SlhDsaFree + // + SlhDsaFree (SlhDsaContext1); + SlhDsaContext1 = NULL; + + // + // Test SlhDsaFree with NULL (should not crash) + // + SlhDsaFree (NULL); + + return UNIT_TEST_PASSED; +} + +/** + Validate UEFI-OpenSSL SLH-DSA Key Setting and Getting. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaKeySetGet ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 PublicKey[SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE]; + UINTN PublicKeySize; + UINT8 TooSmallBuffer[10]; + UINTN TooSmallSize; + + // + // Create SLH-DSA context + // + SlhDsaContext1 = SlhDsaNewByNid (CRYPTO_NID_SLH_DSA_SHAKE_256S); + UT_ASSERT_NOT_NULL (SlhDsaContext1); + + // + // Test SlhDsaGetPubKey with too small buffer (before key is set) + // + TooSmallSize = sizeof (TooSmallBuffer); + Status = SlhDsaGetPubKey (SlhDsaContext1, TooSmallBuffer, &TooSmallSize); + UT_ASSERT_FALSE (Status); + UT_ASSERT_NOT_EQUAL (TooSmallSize, SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE); + + // + // Test SlhDsaSetPrivKey with NULL context + // + Status = SlhDsaSetPrivKey (NULL, (UINT8 *)mSlhDsaShake256sTestPemKey, 100); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaSetPrivKey with NULL key + // + Status = SlhDsaSetPrivKey (SlhDsaContext1, NULL, SLH_DSA_SHAKE_256S_PRIVATE_KEY_SIZE); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaSetPrivKey with wrong size + // + Status = SlhDsaSetPrivKey (SlhDsaContext1, (UINT8 *)mSlhDsaShake256sTestPemKey, 32); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaSetPubKey with NULL context + // + Status = SlhDsaSetPubKey (NULL, (UINT8 *)mSlhDsaShake256sTestCert, 100); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaSetPubKey with NULL key + // + Status = SlhDsaSetPubKey (SlhDsaContext1, NULL, SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaSetPubKey with wrong size + // + Status = SlhDsaSetPubKey (SlhDsaContext1, (UINT8 *)mSlhDsaShake256sTestCert, 32); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaGetPubKey with NULL context + // + PublicKeySize = sizeof (PublicKey); + Status = SlhDsaGetPubKey (NULL, PublicKey, &PublicKeySize); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaGetPubKey with NULL size + // + Status = SlhDsaGetPubKey (SlhDsaContext1, PublicKey, NULL); + UT_ASSERT_FALSE (Status); + + // + // Clean up context + // + SlhDsaFree (SlhDsaContext1); + SlhDsaContext1 = NULL; + + return UNIT_TEST_PASSED; +} + +/** + Validate SLH-DSA error cases. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaErrorCases ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 *Signature; + UINTN SigSize; + UINT8 TooSmallBuffer[10]; + UINTN TooSmallSize; + + // + // Allocate signature buffer on the heap to avoid large stack frames. + // + Signature = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_NOT_NULL (Signature); + if (Signature == NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + // + // Create SLH-DSA context + // + SlhDsaContext1 = SlhDsaNewByNid (CRYPTO_NID_SLH_DSA_SHAKE_256S); + UT_ASSERT_NOT_NULL (SlhDsaContext1); + + // + // Test SlhDsaSign with NULL context + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + NULL, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + AsciiStrLen (mSlhDsaTestMessage), + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaSign with NULL message + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + SlhDsaContext1, + NULL, + 0, + NULL, + 0, + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaSign with too small buffer + // + TooSmallSize = sizeof (TooSmallBuffer); + Status = SlhDsaSign ( + SlhDsaContext1, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + AsciiStrLen (mSlhDsaTestMessage), + TooSmallBuffer, + &TooSmallSize + ); + UT_ASSERT_FALSE (Status); + UT_ASSERT_NOT_EQUAL (TooSmallSize, SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + + // + // Test SlhDsaVerify with NULL context + // + Status = SlhDsaVerify ( + NULL, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + AsciiStrLen (mSlhDsaTestMessage), + Signature, + SLH_DSA_SHAKE_256S_SIGNATURE_SIZE + ); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaVerify with NULL message + // + Status = SlhDsaVerify ( + SlhDsaContext1, + NULL, + 0, + NULL, + 0, + Signature, + SLH_DSA_SHAKE_256S_SIGNATURE_SIZE + ); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaVerify with NULL signature + // + Status = SlhDsaVerify ( + SlhDsaContext1, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + AsciiStrLen (mSlhDsaTestMessage), + NULL, + SLH_DSA_SHAKE_256S_SIGNATURE_SIZE + ); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaVerify with zero signature size + // + Status = SlhDsaVerify ( + SlhDsaContext1, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + AsciiStrLen (mSlhDsaTestMessage), + Signature, + 0 + ); + UT_ASSERT_FALSE (Status); + + FreePool (Signature); + + return UNIT_TEST_PASSED; +} + +/** + Validate SLH-DSA key retrieval from PEM and X509. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaPemX509 ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *SlhDsaPrivKey; + VOID *SlhDsaPubKey; + UINT8 *Signature; + UINTN SigSize; + UINTN MessageSize; + + SlhDsaPrivKey = NULL; + SlhDsaPubKey = NULL; + MessageSize = AsciiStrLen (mSlhDsaTestMessage); + + // + // Allocate signature buffer on the heap to avoid large stack frames. + // + Signature = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_NOT_NULL (Signature); + if (Signature == NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + // + // Retrieve SLH-DSA private key from PEM data. + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &SlhDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (SlhDsaPrivKey); + + // + // Retrieve SLH-DSA public key from X509 certificate. + // + Status = SlhDsaGetPublicKeyFromX509 ( + mSlhDsaShake256sTestCert, + sizeof (mSlhDsaShake256sTestCert), + &SlhDsaPubKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (SlhDsaPubKey); + + // + // SLH-DSA signing with key from PEM (no context string) + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + SlhDsaPrivKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (SigSize, SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + + // + // SLH-DSA verification with key from X509 + // + Status = SlhDsaVerify ( + SlhDsaPubKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + SlhDsaFree (SlhDsaPrivKey); + SlhDsaFree (SlhDsaPubKey); + FreePool (Signature); + + return UNIT_TEST_PASSED; +} + +/** + Validate SLH-DSA signing and verification with context string. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaSignVerifyWithContext ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *SlhDsaPrivKey; + VOID *SlhDsaPubKey; + UINT8 *Signature; + UINTN SigSize; + UINTN MessageSize; + UINTN ContextSize; + + SlhDsaPrivKey = NULL; + SlhDsaPubKey = NULL; + MessageSize = AsciiStrLen (mSlhDsaTestMessage); + ContextSize = AsciiStrLen (mSlhDsaTestContext); + + // + // Allocate signature buffer on the heap to avoid large stack frames. + // + Signature = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_NOT_NULL (Signature); + if (Signature == NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + // + // Retrieve SLH-DSA private key from PEM data. + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &SlhDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (SlhDsaPrivKey); + + // + // Retrieve SLH-DSA public key from X509 certificate. + // + Status = SlhDsaGetPublicKeyFromX509 ( + mSlhDsaShake256sTestCert, + sizeof (mSlhDsaShake256sTestCert), + &SlhDsaPubKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (SlhDsaPubKey); + + // + // SLH-DSA signing with context string + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + SlhDsaPrivKey, + (UINT8 *)mSlhDsaTestContext, + ContextSize, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (SigSize, SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + + // + // SLH-DSA verification with matching context string + // + Status = SlhDsaVerify ( + SlhDsaPubKey, + (UINT8 *)mSlhDsaTestContext, + ContextSize, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // SLH-DSA verification should fail with mismatched context string + // + Status = SlhDsaVerify ( + SlhDsaPubKey, + (UINT8 *)"Different context", + AsciiStrLen ("Different context"), + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // SLH-DSA verification should fail with no context when signature used context + // + Status = SlhDsaVerify ( + SlhDsaPubKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + SlhDsaFree (SlhDsaPrivKey); + SlhDsaFree (SlhDsaPubKey); + FreePool (Signature); + + return UNIT_TEST_PASSED; +} + +/** + Validate SLH-DSA public key extraction and generation. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaGetPubKey ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *SlhDsaPrivKey; + UINT8 PublicKey[SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE]; + UINTN PublicKeySize; + + SlhDsaPrivKey = NULL; + + // + // Retrieve SLH-DSA private key from PEM data. + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &SlhDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (SlhDsaPrivKey); + + // + // Get public key from private key context + // + PublicKeySize = sizeof (PublicKey); + Status = SlhDsaGetPubKey ( + SlhDsaPrivKey, + PublicKey, + &PublicKeySize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (PublicKeySize, SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE); + + // + // Verify the public key buffer is not all zeros + // + BOOLEAN AllZeros; + UINTN Index; + + AllZeros = TRUE; + for (Index = 0; Index < PublicKeySize; Index++) { + if (PublicKey[Index] != 0) { + AllZeros = FALSE; + break; + } + } + + UT_ASSERT_FALSE (AllZeros); + + SlhDsaFree (SlhDsaPrivKey); + + return UNIT_TEST_PASSED; +} + +/** + Validate SLH-DSA signature verification fails with tampered data. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaTamperedData ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *SlhDsaPrivKey; + VOID *SlhDsaPubKey; + UINT8 *Signature; + UINT8 *TamperedSignature; + CHAR8 TamperedMessage[100]; + UINTN SigSize; + UINTN MessageSize; + + SlhDsaPrivKey = NULL; + SlhDsaPubKey = NULL; + MessageSize = AsciiStrLen (mSlhDsaTestMessage); + + // + // Allocate signature buffers on the heap to avoid large stack frames. + // + Signature = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + TamperedSignature = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + if ((Signature == NULL) || (TamperedSignature == NULL)) { + if (Signature != NULL) { + FreePool (Signature); + } + + if (TamperedSignature != NULL) { + FreePool (TamperedSignature); + } + + UT_ASSERT_TRUE ((Signature != NULL) && (TamperedSignature != NULL)); + return UNIT_TEST_ERROR_TEST_FAILED; + } + + // + // Retrieve SLH-DSA private key from PEM data. + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &SlhDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (SlhDsaPrivKey); + + // + // Retrieve SLH-DSA public key from X509 certificate. + // + Status = SlhDsaGetPublicKeyFromX509 ( + mSlhDsaShake256sTestCert, + sizeof (mSlhDsaShake256sTestCert), + &SlhDsaPubKey + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_NOT_NULL (SlhDsaPubKey); + + // + // Generate valid signature + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + SlhDsaPrivKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Verify original signature works + // + Status = SlhDsaVerify ( + SlhDsaPubKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Test with tampered message (should fail) + // + AsciiStrCpyS (TamperedMessage, sizeof (TamperedMessage), mSlhDsaTestMessage); + TamperedMessage[0] = 'X'; + Status = SlhDsaVerify ( + SlhDsaPubKey, + NULL, + 0, + (UINT8 *)TamperedMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test with tampered signature (should fail) + // + CopyMem (TamperedSignature, Signature, SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + + TamperedSignature[0] ^= 0x01; + Status = SlhDsaVerify ( + SlhDsaPubKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + TamperedSignature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Test with wrong signature size (should fail) + // + Status = SlhDsaVerify ( + SlhDsaPubKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + SigSize - 1 + ); + UT_ASSERT_FALSE (Status); + + SlhDsaFree (SlhDsaPrivKey); + SlhDsaFree (SlhDsaPubKey); + FreePool (Signature); + FreePool (TamperedSignature); + + return UNIT_TEST_PASSED; +} + +/** + Validate SLH-DSA PEM loading error cases. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaPemErrors ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *SlhDsaKey; + + SlhDsaKey = NULL; + + // + // Test SlhDsaGetPrivateKeyFromPem with NULL PEM data + // + Status = SlhDsaGetPrivateKeyFromPem ( + NULL, + 100, + NULL, + &SlhDsaKey + ); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaGetPrivateKeyFromPem with NULL context pointer + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + NULL + ); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaGetPrivateKeyFromPem with invalid PEM data + // + Status = SlhDsaGetPrivateKeyFromPem ( + (UINT8 *)"Invalid PEM data", + 16, + NULL, + &SlhDsaKey + ); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaGetPublicKeyFromX509 with NULL certificate + // + Status = SlhDsaGetPublicKeyFromX509 ( + NULL, + 100, + &SlhDsaKey + ); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaGetPublicKeyFromX509 with NULL context pointer + // + Status = SlhDsaGetPublicKeyFromX509 ( + mSlhDsaShake256sTestCert, + sizeof (mSlhDsaShake256sTestCert), + NULL + ); + UT_ASSERT_FALSE (Status); + + // + // Test SlhDsaGetPublicKeyFromX509 with invalid certificate data + // + Status = SlhDsaGetPublicKeyFromX509 ( + (UINT8 *)"Invalid cert data", + 17, + &SlhDsaKey + ); + UT_ASSERT_FALSE (Status); + + return UNIT_TEST_PASSED; +} + +/** + Validate SLH-DSA operations on context without keys. + + This test validates that operations fail properly when no key is set. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaNoKeyOperations ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT8 *Signature; + UINT8 PublicKey[SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE]; + UINTN SigSize; + UINTN PublicKeySize; + + // + // Allocate signature buffer on the heap to avoid large stack frames. + // + Signature = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_NOT_NULL (Signature); + if (Signature == NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + // + // Create context without setting any key + // + SlhDsaContext1 = SlhDsaNewByNid (CRYPTO_NID_SLH_DSA_SHAKE_256S); + UT_ASSERT_NOT_NULL (SlhDsaContext1); + + // + // SlhDsaSign should fail when EvpPkey is NULL + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + SlhDsaContext1, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + AsciiStrLen (mSlhDsaTestMessage), + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // SlhDsaVerify should fail when EvpPkey is NULL + // + Status = SlhDsaVerify ( + SlhDsaContext1, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + AsciiStrLen (mSlhDsaTestMessage), + Signature, + SLH_DSA_SHAKE_256S_SIGNATURE_SIZE + ); + UT_ASSERT_FALSE (Status); + + // + // SlhDsaGetPubKey should fail when EvpPkey is NULL + // + PublicKeySize = sizeof (PublicKey); + Status = SlhDsaGetPubKey ( + SlhDsaContext1, + PublicKey, + &PublicKeySize + ); + UT_ASSERT_FALSE (Status); + + SlhDsaFree (SlhDsaContext1); + SlhDsaContext1 = NULL; + FreePool (Signature); + + return UNIT_TEST_PASSED; +} + +/** + Validate SLH-DSA context string parameter validation. + + This test validates the check: (ContextSize > 0) && (Context == NULL). + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaInvalidContextParams ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *SlhDsaPrivKey; + VOID *SlhDsaPubKey; + UINT8 *Signature; + UINTN SigSize; + UINTN MessageSize; + + SlhDsaPrivKey = NULL; + SlhDsaPubKey = NULL; + MessageSize = AsciiStrLen (mSlhDsaTestMessage); + + // + // Allocate signature buffer on the heap to avoid large stack frames. + // + Signature = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_NOT_NULL (Signature); + if (Signature == NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + // + // Get valid keys + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &SlhDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + + Status = SlhDsaGetPublicKeyFromX509 ( + mSlhDsaShake256sTestCert, + sizeof (mSlhDsaShake256sTestCert), + &SlhDsaPubKey + ); + UT_ASSERT_TRUE (Status); + + // + // Test SlhDsaSign with NULL Context but ContextSize > 0 (invalid combination) + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + SlhDsaPrivKey, + NULL, + 10, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Generate valid signature for verify test + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + SlhDsaPrivKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Test SlhDsaVerify with NULL Context but ContextSize > 0 (invalid combination) + // + Status = SlhDsaVerify ( + SlhDsaPubKey, + NULL, + 5, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + SlhDsaFree (SlhDsaPrivKey); + SlhDsaFree (SlhDsaPubKey); + FreePool (Signature); + + return UNIT_TEST_PASSED; +} + +/** + Validate SlhDsaGetPubKey with NULL buffer parameter. + + This test validates that NULL PublicKey buffer returns FALSE and sets size to 0. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaGetPubKeyNullBuffer ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *SlhDsaPrivKey; + UINTN PublicKeySize; + + SlhDsaPrivKey = NULL; + + // + // Get valid private key + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &SlhDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + + // + // Test SlhDsaGetPubKey with NULL buffer + // Should return FALSE and set PublicKeySize to 0 + // + PublicKeySize = 9999; + Status = SlhDsaGetPubKey ( + SlhDsaPrivKey, + NULL, + &PublicKeySize + ); + UT_ASSERT_FALSE (Status); + UT_ASSERT_EQUAL (PublicKeySize, 0); + + SlhDsaFree (SlhDsaPrivKey); + + return UNIT_TEST_PASSED; +} + +/** + Validate SLH-DSA signature size exact match validation. + + This test validates that SlhDsaVerify properly validates signature size. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaSignatureSizeExact ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *SlhDsaPrivKey; + VOID *SlhDsaPubKey; + UINT8 *Signature; + UINTN SigSize; + UINTN MessageSize; + + SlhDsaPrivKey = NULL; + SlhDsaPubKey = NULL; + MessageSize = AsciiStrLen (mSlhDsaTestMessage); + + // + // Allocate signature buffer on the heap to avoid large stack frames. + // + Signature = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_NOT_NULL (Signature); + if (Signature == NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + // + // Get valid keys + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &SlhDsaPrivKey + ); + UT_ASSERT_TRUE (Status); + + Status = SlhDsaGetPublicKeyFromX509 ( + mSlhDsaShake256sTestCert, + sizeof (mSlhDsaShake256sTestCert), + &SlhDsaPubKey + ); + UT_ASSERT_TRUE (Status); + + // + // Generate valid signature + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + SlhDsaPrivKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (SigSize, SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + + // + // Verify with exact size - should succeed + // + Status = SlhDsaVerify ( + SlhDsaPubKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + SLH_DSA_SHAKE_256S_SIGNATURE_SIZE + ); + UT_ASSERT_TRUE (Status); + + // + // Verify with size + 1 - should fail + // + Status = SlhDsaVerify ( + SlhDsaPubKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + SLH_DSA_SHAKE_256S_SIGNATURE_SIZE + 1 + ); + UT_ASSERT_FALSE (Status); + + // + // Verify with size - 1 - should fail + // + Status = SlhDsaVerify ( + SlhDsaPubKey, + NULL, + 0, + (UINT8 *)mSlhDsaTestMessage, + MessageSize, + Signature, + SLH_DSA_SHAKE_256S_SIGNATURE_SIZE - 1 + ); + UT_ASSERT_FALSE (Status); + + SlhDsaFree (SlhDsaPrivKey); + SlhDsaFree (SlhDsaPubKey); + FreePool (Signature); + + return UNIT_TEST_PASSED; +} + +/** + Test SLH-DSA context lifecycle with multiple allocations. + + Tests proper resource management including multiple successive allocations, + cleanup verification, and null pointer safety. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaContextLifecycle ( + UNIT_TEST_CONTEXT Context + ) +{ + VOID *TempCtx1; + VOID *TempCtx2; + VOID *TempCtx3; + + // + // Test creating multiple contexts + // + TempCtx1 = SlhDsaNewByNid (CRYPTO_NID_SLH_DSA_SHAKE_256S); + UT_ASSERT_NOT_NULL (TempCtx1); + + TempCtx2 = SlhDsaNewByNid (CRYPTO_NID_SLH_DSA_SHAKE_256S); + UT_ASSERT_NOT_NULL (TempCtx2); + + TempCtx3 = SlhDsaNewByNid (CRYPTO_NID_SLH_DSA_SHAKE_256S); + UT_ASSERT_NOT_NULL (TempCtx3); + + // + // Free in different order + // + SlhDsaFree (TempCtx2); + SlhDsaFree (TempCtx1); + SlhDsaFree (TempCtx3); + + // + // Double-free safety (should not crash) + // + SlhDsaFree (NULL); + SlhDsaFree (NULL); + + return UNIT_TEST_PASSED; +} + +/** + Test SLH-DSA empty message signing and verification. + + Tests edge case of zero-length messages. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaEmptyMessage ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *PrivKey; + VOID *PubKey; + UINT8 *Signature; + UINTN SigSize; + UINT8 EmptyMsg[1]; + + PrivKey = NULL; + PubKey = NULL; + + // + // Allocate signature buffer on the heap to avoid large stack frames. + // + Signature = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_NOT_NULL (Signature); + if (Signature == NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + // + // Load keys + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &PrivKey + ); + UT_ASSERT_TRUE (Status); + + Status = SlhDsaGetPublicKeyFromX509 ( + mSlhDsaShake256sTestCert, + sizeof (mSlhDsaShake256sTestCert), + &PubKey + ); + UT_ASSERT_TRUE (Status); + + // + // Sign empty message - should fail with NULL message + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + PrivKey, + NULL, + 0, + NULL, + 0, + Signature, + &SigSize + ); + UT_ASSERT_FALSE (Status); + + // + // Sign with valid pointer but zero size - should succeed + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + PrivKey, + NULL, + 0, + EmptyMsg, + 0, + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Verify the zero-length message signature + // + Status = SlhDsaVerify ( + PubKey, + NULL, + 0, + EmptyMsg, + 0, + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + SlhDsaFree (PrivKey); + SlhDsaFree (PubKey); + FreePool (Signature); + + return UNIT_TEST_PASSED; +} + +/** + Test SLH-DSA maximum length context string. + + Tests the maximum allowed context string size per FIPS 204. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaMaxContextString ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *PrivKey; + VOID *PubKey; + UINT8 *Signature; + UINTN SigSize; + UINT8 MaxContext[SLH_DSA_MAX_CONTEXT_SIZE]; + UINTN Index; + + PrivKey = NULL; + PubKey = NULL; + + // + // Allocate signature buffer on the heap to avoid large stack frames. + // + Signature = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_NOT_NULL (Signature); + if (Signature == NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + // + // Fill context with pattern + // + for (Index = 0; Index < SLH_DSA_MAX_CONTEXT_SIZE; Index++) { + MaxContext[Index] = (UINT8)(Index & 0xFF); + } + + // + // Load keys + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &PrivKey + ); + UT_ASSERT_TRUE (Status); + + Status = SlhDsaGetPublicKeyFromX509 ( + mSlhDsaShake256sTestCert, + sizeof (mSlhDsaShake256sTestCert), + &PubKey + ); + UT_ASSERT_TRUE (Status); + + // + // Sign with maximum context + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign ( + PrivKey, + MaxContext, + SLH_DSA_MAX_CONTEXT_SIZE, + (UINT8 *)mSlhDsaTestMessage, + AsciiStrLen (mSlhDsaTestMessage), + Signature, + &SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Verify with matching context + // + Status = SlhDsaVerify ( + PubKey, + MaxContext, + SLH_DSA_MAX_CONTEXT_SIZE, + (UINT8 *)mSlhDsaTestMessage, + AsciiStrLen (mSlhDsaTestMessage), + Signature, + SigSize + ); + UT_ASSERT_TRUE (Status); + + // + // Verify should fail with one byte different + // + MaxContext[0] ^= 1; + Status = SlhDsaVerify ( + PubKey, + MaxContext, + SLH_DSA_MAX_CONTEXT_SIZE, + (UINT8 *)mSlhDsaTestMessage, + AsciiStrLen (mSlhDsaTestMessage), + Signature, + SigSize + ); + UT_ASSERT_FALSE (Status); + + SlhDsaFree (PrivKey); + SlhDsaFree (PubKey); + FreePool (Signature); + + return UNIT_TEST_PASSED; +} + +/** + Test SLH-DSA key replacement in context. + + Tests that replacing keys properly frees old key and sets new key. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaKeyReplacement ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *PrivKey; + UINT8 PublicKey1[SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE]; + UINT8 PublicKey2[SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE]; + UINTN PubKeySize; + + PrivKey = NULL; + + // + // Load first key + // + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &PrivKey + ); + UT_ASSERT_TRUE (Status); + + // + // Get public key + // + PubKeySize = sizeof (PublicKey1); + Status = SlhDsaGetPubKey (PrivKey, PublicKey1, &PubKeySize); + UT_ASSERT_TRUE (Status); + + // + // Now replace with a public-only key + // + SlhDsaContext1 = SlhDsaNewByNid (CRYPTO_NID_SLH_DSA_SHAKE_256S); + UT_ASSERT_NOT_NULL (SlhDsaContext1); + + Status = SlhDsaSetPubKey (SlhDsaContext1, PublicKey1, SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE); + UT_ASSERT_TRUE (Status); + + // + // Replace with same public key again (tests EVP_PKEY_free path) + // + Status = SlhDsaSetPubKey (SlhDsaContext1, PublicKey1, SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE); + UT_ASSERT_TRUE (Status); + + // + // Verify we can still get the key + // + PubKeySize = sizeof (PublicKey2); + Status = SlhDsaGetPubKey (SlhDsaContext1, PublicKey2, &PubKeySize); + UT_ASSERT_TRUE (Status); + UT_ASSERT_EQUAL (PubKeySize, SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE); + + SlhDsaFree (PrivKey); + SlhDsaFree (SlhDsaContext1); + SlhDsaContext1 = NULL; + + return UNIT_TEST_PASSED; +} + +/** + Test SLH-DSA multiple signatures with same key. + + Tests that the same key can generate multiple signatures. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaMultipleSignatures ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *PrivKey; + VOID *PubKey; + UINT8 *Sig1; + UINT8 *Sig2; + UINT8 *Sig3; + UINTN SigSize; + CHAR8 *Msg1 = "First message"; + CHAR8 *Msg2 = "Second message"; + CHAR8 *Msg3 = "Third message"; + + PrivKey = NULL; + PubKey = NULL; + + // + // Allocate signature buffers on the heap to avoid large stack frames. + // + Sig1 = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + Sig2 = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + Sig3 = AllocatePool (SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + if ((Sig1 == NULL) || (Sig2 == NULL) || (Sig3 == NULL)) { + if (Sig1 != NULL) { + FreePool (Sig1); + } + + if (Sig2 != NULL) { + FreePool (Sig2); + } + + if (Sig3 != NULL) { + FreePool (Sig3); + } + + UT_ASSERT_TRUE ((Sig1 != NULL) && (Sig2 != NULL) && (Sig3 != NULL)); + return UNIT_TEST_ERROR_TEST_FAILED; + } + + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &PrivKey + ); + UT_ASSERT_TRUE (Status); + + Status = SlhDsaGetPublicKeyFromX509 ( + mSlhDsaShake256sTestCert, + sizeof (mSlhDsaShake256sTestCert), + &PubKey + ); + UT_ASSERT_TRUE (Status); + + // + // Generate three different signatures + // + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign (PrivKey, NULL, 0, (UINT8 *)Msg1, AsciiStrLen (Msg1), Sig1, &SigSize); + UT_ASSERT_TRUE (Status); + + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign (PrivKey, NULL, 0, (UINT8 *)Msg2, AsciiStrLen (Msg2), Sig2, &SigSize); + UT_ASSERT_TRUE (Status); + + SigSize = SLH_DSA_SHAKE_256S_SIGNATURE_SIZE; + Status = SlhDsaSign (PrivKey, NULL, 0, (UINT8 *)Msg3, AsciiStrLen (Msg3), Sig3, &SigSize); + UT_ASSERT_TRUE (Status); + + // + // Verify all three with correct messages + // + Status = SlhDsaVerify (PubKey, NULL, 0, (UINT8 *)Msg1, AsciiStrLen (Msg1), Sig1, SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_TRUE (Status); + + Status = SlhDsaVerify (PubKey, NULL, 0, (UINT8 *)Msg2, AsciiStrLen (Msg2), Sig2, SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_TRUE (Status); + + Status = SlhDsaVerify (PubKey, NULL, 0, (UINT8 *)Msg3, AsciiStrLen (Msg3), Sig3, SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_TRUE (Status); + + // + // Cross-verify should fail (wrong message/signature pairs) + // + Status = SlhDsaVerify (PubKey, NULL, 0, (UINT8 *)Msg1, AsciiStrLen (Msg1), Sig2, SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_FALSE (Status); + + Status = SlhDsaVerify (PubKey, NULL, 0, (UINT8 *)Msg2, AsciiStrLen (Msg2), Sig3, SLH_DSA_SHAKE_256S_SIGNATURE_SIZE); + UT_ASSERT_FALSE (Status); + + SlhDsaFree (PrivKey); + SlhDsaFree (PubKey); + FreePool (Sig1); + FreePool (Sig2); + FreePool (Sig3); + + return UNIT_TEST_PASSED; +} + +/** + Test SLH-DSA GetPubKey called multiple times. + + Tests that repeated calls to GetPubKey return consistent results. + + @param[in] Context Unit test context. + + @retval UNIT_TEST_PASSED The unit test has completed successfully. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TestVerifySlhDsaGetPubKeyRepeated ( + UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + VOID *PrivKey; + UINT8 PubKey1[SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE]; + UINT8 PubKey2[SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE]; + UINT8 PubKey3[SLH_DSA_SHAKE_256S_PUBLIC_KEY_SIZE]; + UINTN Size1, Size2, Size3; + + PrivKey = NULL; + + Status = SlhDsaGetPrivateKeyFromPem ( + mSlhDsaShake256sTestPemKey, + sizeof (mSlhDsaShake256sTestPemKey), + NULL, + &PrivKey + ); + UT_ASSERT_TRUE (Status); + + // + // Get public key three times + // + Size1 = sizeof (PubKey1); + Status = SlhDsaGetPubKey (PrivKey, PubKey1, &Size1); + UT_ASSERT_TRUE (Status); + + Size2 = sizeof (PubKey2); + Status = SlhDsaGetPubKey (PrivKey, PubKey2, &Size2); + UT_ASSERT_TRUE (Status); + + Size3 = sizeof (PubKey3); + Status = SlhDsaGetPubKey (PrivKey, PubKey3, &Size3); + UT_ASSERT_TRUE (Status); + + // + // All should be identical + // + UT_ASSERT_EQUAL (Size1, Size2); + UT_ASSERT_EQUAL (Size2, Size3); + UT_ASSERT_MEM_EQUAL (PubKey1, PubKey2, Size1); + UT_ASSERT_MEM_EQUAL (PubKey2, PubKey3, Size2); + + SlhDsaFree (PrivKey); + + return UNIT_TEST_PASSED; +} + +TEST_DESC mSlhDsaTest[] = { + // + // -----Description------------------------------------Class-------------------------Function----------------------------Pre-------------------Post--------------------Context + // + { "TestVerifySlhDsaNew()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaNew, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaKeySetGet()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaKeySetGet, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaErrorCases()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaErrorCases, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaPemX509()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaPemX509, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaSignVerifyWithContext()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaSignVerifyWithContext, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaGetPubKey()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaGetPubKey, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaTamperedData()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaTamperedData, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaPemErrors()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaPemErrors, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaNoKeyOperations()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaNoKeyOperations, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaInvalidContextParams()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaInvalidContextParams, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaGetPubKeyNullBuffer()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaGetPubKeyNullBuffer, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaSignatureSizeExact()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaSignatureSizeExact, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaContextLifecycle()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaContextLifecycle, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaEmptyMessage()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaEmptyMessage, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaMaxContextString()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaMaxContextString, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaKeyReplacement()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaKeyReplacement, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaMultipleSignatures()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaMultipleSignatures, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, + { "TestVerifySlhDsaGetPubKeyRepeated()", "CryptoPkg.BaseCryptLib.SlhDsa", TestVerifySlhDsaGetPubKeyRepeated, TestVerifySlhDsaPreReq, TestVerifySlhDsaCleanUp, NULL }, +}; + +UINTN mSlhDsaTestNum = ARRAY_SIZE (mSlhDsaTest); diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h index 393d1e4760..d23763d9a2 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h @@ -103,6 +103,9 @@ extern TEST_DESC mEdDsaTest[]; extern UINTN mMlDsaTestNum; extern TEST_DESC mMlDsaTest[]; +extern UINTN mSlhDsaTestNum; +extern TEST_DESC mSlhDsaTest[]; + extern UINTN mX509TestNum; extern TEST_DESC mX509Test[]; diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf index d8d6d6248e..670ab3b621 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf @@ -46,6 +46,7 @@ X509Tests.c EdDsaTests.c MlDsaTests.c + SlhDsaTests.c [Packages] MdePkg/MdePkg.dec diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf index 6dc37f1a61..23a4c9138a 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf @@ -42,6 +42,7 @@ EcTests.c EdDsaTests.c MlDsaTests.c + SlhDsaTests.c X509Tests.c Pkcs7AttachedContentTest.c From 084ce2b04bdd9b3ed8f2a1eb51d09355c04c692c Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Thu, 21 May 2026 08:06:17 +0100 Subject: [PATCH 259/406] ArmVirtPkg: Clear TPIDR_EL0 before early HOB lookups TPIDR_EL0 is used to hold the PrePi HOB list pointer, but its reset value is unknown. Some early boot paths can call GetHobList() before PrePiMain() creates and installs the HOB list. Clear TPIDR_EL0 at the SEC entry point so those early lookups see NULL rather than an invalid pointer. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- ArmVirtPkg/PrePi/ModuleEntryPoint.S | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ArmVirtPkg/PrePi/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/ModuleEntryPoint.S index 92272eaf52..71601e3275 100644 --- a/ArmVirtPkg/PrePi/ModuleEntryPoint.S +++ b/ArmVirtPkg/PrePi/ModuleEntryPoint.S @@ -1,5 +1,5 @@ // -// Copyright (c) 2011-2013, ARM Limited. All rights reserved. +// Copyright (c) 2011-2026, ARM Limited. All rights reserved. // Copyright (c) 2015-2016, Linaro Limited. All rights reserved. // // SPDX-License-Identifier: BSD-2-Clause-Patent @@ -20,6 +20,12 @@ ASM_FUNC(_ModuleEntryPoint) 0:mov x28, x0 // preserve DTB pointer mov x27, x1 // preserve base of image pointer + // The TPIDR_EL0 register is used to store the HobList pointer. + // The register value is unknown at reset, so clear the register + // to prevent early callers of GetHobList(), i.e. before the HOB list + // has been setup in PrePiMain() from getting an invalid value. + msr tpidr_el0, xzr + // Enable Floating Point. This needs to be done before entering C code, which // may use FP/SIMD registers. bl ArmEnableVFP From 760bb2d2fd7f648dea6ae8d2bf04c69e260d9181 Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Fri, 26 Jun 2026 16:44:03 +0100 Subject: [PATCH 260/406] OvmfPkg/MapMmioLib: Introduce a library for mapping MMIO regions Introduce MapMmioLib to add MMIO regions to the GCD memory map. MapMmioMemory() normalizes the requested range to page boundaries, adds missing MMIO descriptors, and updates attributes for new and existing MMIO descriptors. Existing descriptors of any other type are reported as conflicts. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- OvmfPkg/Include/Library/MapMmioLib.h | 49 ++++++ OvmfPkg/Library/MapMmioLib/MapMmioLib.c | 200 ++++++++++++++++++++++ OvmfPkg/Library/MapMmioLib/MapMmioLib.inf | 33 ++++ OvmfPkg/OvmfPkg.dec | 4 + 4 files changed, 286 insertions(+) create mode 100644 OvmfPkg/Include/Library/MapMmioLib.h create mode 100644 OvmfPkg/Library/MapMmioLib/MapMmioLib.c create mode 100644 OvmfPkg/Library/MapMmioLib/MapMmioLib.inf diff --git a/OvmfPkg/Include/Library/MapMmioLib.h b/OvmfPkg/Include/Library/MapMmioLib.h new file mode 100644 index 0000000000..afb8bec347 --- /dev/null +++ b/OvmfPkg/Include/Library/MapMmioLib.h @@ -0,0 +1,49 @@ +/** @file + Helper library to map memory regions. + + Copyright (c) 2026, Arm Ltd. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#pragma once + +#include <Base.h> + +/** + Map a range as MMIO in the GCD memory map. + + The requested range is expanded to page boundaries before it is processed. + Missing GCD memory space descriptors are added as + EfiGcdMemoryTypeMemoryMappedIo. Existing MMIO descriptors are accepted only + when their capabilities contain the requested attributes. Existing descriptors + of any other type are treated as conflicts. + + After the range is backed by compatible MMIO descriptors, the requested GCD + memory space attributes are applied to the normalized full range. + + If this function fails after adding new GCD MMIO descriptors, the descriptors + are not rolled back. Callers are expected to treat failures from this function + as fatal to the current boot path. + + @param[in] Base The base address of the requested MMIO range. + @param[in] Length The size of the requested MMIO range, in bytes. + @param[in] Attributes The GCD memory space attributes to apply to the MMIO + range. + + @retval EFI_SUCCESS The full range was mapped as MMIO and + configured with the requested attributes. + @retval EFI_INVALID_PARAMETER Length is zero, or the normalized range + overflows the physical address space. + @retval EFI_UNSUPPORTED The range overlaps an existing non-MMIO + descriptor, or an MMIO descriptor without the + requested attributes. + @retval EFI_ABORTED An existing GCD descriptor is malformed. + @retval Others The GCD memory services returned an error. +**/ +EFI_STATUS +EFIAPI +MapMmioMemory ( + IN EFI_PHYSICAL_ADDRESS Base, + IN UINT64 Length, + IN UINT64 Attributes + ); diff --git a/OvmfPkg/Library/MapMmioLib/MapMmioLib.c b/OvmfPkg/Library/MapMmioLib/MapMmioLib.c new file mode 100644 index 0000000000..582b97bca7 --- /dev/null +++ b/OvmfPkg/Library/MapMmioLib/MapMmioLib.c @@ -0,0 +1,200 @@ +/** @file + Helper library to map mmio memory regions. + + Copyright (c) 2026, Arm Ltd. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Base.h> +#include <Uefi.h> + +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/DxeServicesTableLib.h> +#include <Library/UefiBootServicesTableLib.h> + +/** + Ensure a range is present in the GCD memory space map as MMIO. + + The input range must already be page-aligned. The function walks the current + GCD memory space map and adds every overlapping EfiGcdMemoryTypeNonExistent + descriptor as EfiGcdMemoryTypeMemoryMappedIo with the requested attributes. + Existing EfiGcdMemoryTypeMemoryMappedIo descriptors are accepted only when + their capabilities contain all requested attributes. Existing descriptors of + any other type, or MMIO descriptors without the requested attributes, are + treated as conflicts. + + This function only ensures that MMIO GCD descriptors exist. It does not set + memory space attributes. + + @param[in] Base The page-aligned base address of the MMIO range. + @param[in] Length The page-aligned size of the MMIO range, in bytes. + @param[in] Attributes The GCD memory space attributes required for the MMIO + range. + + @retval EFI_SUCCESS The range is backed by compatible MMIO descriptors. + @retval EFI_UNSUPPORTED The range overlaps an existing non-MMIO descriptor, + or an MMIO descriptor without the requested + attributes. + @retval EFI_ABORTED An existing GCD descriptor is malformed. + @retval Others The GCD memory services returned an error. +**/ +STATIC +EFI_STATUS +AddMmioMemorySpace ( + IN UINT64 Base, + IN UINT64 Length, + IN UINT64 Attributes + ) +{ + EFI_STATUS Status; + UINTN Index; + UINTN NumberOfDescriptors; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor; + UINT64 IntersectionBase; + UINT64 IntersectionEnd; + + Status = gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index = 0; Index < NumberOfDescriptors; Index++) { + Descriptor = &MemorySpaceMap[Index]; + + if (Descriptor->BaseAddress > (MAX_UINT64 - Descriptor->Length)) { + Status = EFI_ABORTED; + break; + } + + IntersectionBase = MAX (Base, Descriptor->BaseAddress); + IntersectionEnd = MIN ( + Base + Length, + Descriptor->BaseAddress + Descriptor->Length + ); + if (IntersectionBase >= IntersectionEnd) { + // + // The descriptor and the aperture don't overlap. + // + continue; + } + + if (Descriptor->GcdMemoryType == EfiGcdMemoryTypeNonExistent) { + Status = gDS->AddMemorySpace ( + EfiGcdMemoryTypeMemoryMappedIo, + IntersectionBase, + IntersectionEnd - IntersectionBase, + Attributes + ); + + DEBUG (( + EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE, + "%a: %a: add [%Lx, %Lx): %r\n", + gEfiCallerBaseName, + __func__, + IntersectionBase, + IntersectionEnd, + Status + )); + if (EFI_ERROR (Status)) { + break; + } + + continue; + } + + if ((Descriptor->GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo) || + ((Descriptor->Capabilities & Attributes) != Attributes)) + { + Status = EFI_UNSUPPORTED; + break; + } + } // for + + FreePool (MemorySpaceMap); + return Status; +} + +/** + Map a range as MMIO in the GCD memory map. + + The requested range is expanded to page boundaries before it is processed. + Missing GCD memory space descriptors are added as + EfiGcdMemoryTypeMemoryMappedIo. Existing MMIO descriptors are accepted only + when their capabilities contain the requested attributes. Existing descriptors + of any other type are treated as conflicts. + + After the range is backed by compatible MMIO descriptors, the requested GCD + memory space attributes are applied to the normalized full range. + + If this function fails after adding new GCD MMIO descriptors, the descriptors + are not rolled back. Callers are expected to treat failures from this function + as fatal to the current boot path. + + @param[in] Base The base address of the requested MMIO range. + @param[in] Length The size of the requested MMIO range, in bytes. + @param[in] Attributes The GCD memory space attributes to apply to the MMIO + range. + + @retval EFI_SUCCESS The full range was mapped as MMIO and + configured with the requested attributes. + @retval EFI_INVALID_PARAMETER Length is zero, or the normalized range + overflows the physical address space. + @retval EFI_UNSUPPORTED The range overlaps an existing non-MMIO + descriptor, or an MMIO descriptor without the + requested attributes. + @retval EFI_ABORTED An existing GCD descriptor is malformed. + @retval Others The GCD memory services returned an error. +**/ +EFI_STATUS +EFIAPI +MapMmioMemory ( + IN EFI_PHYSICAL_ADDRESS Base, + IN UINT64 Length, + IN UINT64 Attributes + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS RegionEnd; + + DEBUG (( + DEBUG_INFO, + "Map MMIO Memory: 0x%08lx - 0x%08lx : 0x%08lx\n", + Base, + Length, + Attributes + )); + + if (Length == 0) { + return EFI_INVALID_PARAMETER; + } + + // Check if RegionsBase + Length would overflow + if ((Base > (MAX_UINT64 - Length))) { + return EFI_INVALID_PARAMETER; + } + + RegionEnd = Base + Length; + + // Check if aligning RegionEnd would overflow + if (RegionEnd > MAX_UINT64 - ALIGN_VALUE_ADDEND (RegionEnd, EFI_PAGE_SIZE)) { + return EFI_INVALID_PARAMETER; + } + + RegionEnd = ALIGN_VALUE (RegionEnd, EFI_PAGE_SIZE); + + // Align down Base to page boundary + Base = Base & ~(EFI_PAGE_SIZE - 1); + + // Calculate the total region size. + Length = RegionEnd - Base; + + Status = AddMmioMemorySpace (Base, Length, Attributes); + if (EFI_ERROR (Status)) { + return Status; + } + + return gDS->SetMemorySpaceAttributes (Base, Length, Attributes); +} diff --git a/OvmfPkg/Library/MapMmioLib/MapMmioLib.inf b/OvmfPkg/Library/MapMmioLib/MapMmioLib.inf new file mode 100644 index 0000000000..5a10641eed --- /dev/null +++ b/OvmfPkg/Library/MapMmioLib/MapMmioLib.inf @@ -0,0 +1,33 @@ +## @file +# Helper Library for mapping mmio memory regions. +# +# Copyright (c) 2026, Arm Ltd. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001C + BASE_NAME = MapMmioLib + FILE_GUID = 65d2e4bd-7e64-4c5a-888e-eb0e5337033a + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = MapMmioLib|DXE_DRIVER + +[Sources] + MapMmioLib.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + DxeServicesTableLib + MemoryAllocationLib + UefiBootServicesTableLib + +[Depex] + gEfiCpuArchProtocolGuid diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 9cf13d3fb2..ce5d5dda4f 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -164,6 +164,10 @@ # MemDebugLogLib|Include/Library/MemDebugLogLib.h + ## @libraryclass Provides helper interface for mapping mmio memory regions. + # + MapMmioLib|Include/Library/MapMmioLib.h + [Guids] gUefiOvmfPkgTokenSpaceGuid = {0x93bb96af, 0xb9f2, 0x4eb8, {0x94, 0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}} gEfiXenInfoGuid = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}} From 838240263a476ae54ffb6f694cc4bc0a0ce42727 Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Thu, 2 Jul 2026 11:12:50 +0100 Subject: [PATCH 261/406] OvmfPkg/MapMmioLib: Support runtime drivers Allow MapMmioLib to be consumed by DXE_RUNTIME_DRIVER modules. MapMmioMemory() depends on DXE services, so it cannot map new ranges after ExitBootServices(). Return EFI_ACCESS_DENIED when called at runtime. This allows runtime drivers such as ArmVirtPkg/Library/KvmtoolRtcFdtClientLib to use MapMmioLib for boot-time MMIO setup. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- OvmfPkg/Include/Library/MapMmioLib.h | 1 + OvmfPkg/Library/MapMmioLib/MapMmioLib.c | 81 +++++++++++++++++++++++ OvmfPkg/Library/MapMmioLib/MapMmioLib.inf | 7 +- 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/Library/MapMmioLib.h b/OvmfPkg/Include/Library/MapMmioLib.h index afb8bec347..aed056bf22 100644 --- a/OvmfPkg/Include/Library/MapMmioLib.h +++ b/OvmfPkg/Include/Library/MapMmioLib.h @@ -38,6 +38,7 @@ descriptor, or an MMIO descriptor without the requested attributes. @retval EFI_ABORTED An existing GCD descriptor is malformed. + @retval EFI_ACCESS_DENIED DXE Services are no longer available. @retval Others The GCD memory services returned an error. **/ EFI_STATUS diff --git a/OvmfPkg/Library/MapMmioLib/MapMmioLib.c b/OvmfPkg/Library/MapMmioLib/MapMmioLib.c index 582b97bca7..56042ca855 100644 --- a/OvmfPkg/Library/MapMmioLib/MapMmioLib.c +++ b/OvmfPkg/Library/MapMmioLib/MapMmioLib.c @@ -14,6 +14,9 @@ #include <Library/DxeServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h> +STATIC EFI_EVENT mExitBootServicesEvent; +STATIC BOOLEAN mAtRuntime = FALSE; + /** Ensure a range is present in the GCD memory space map as MMIO. @@ -146,6 +149,7 @@ AddMmioMemorySpace ( descriptor, or an MMIO descriptor without the requested attributes. @retval EFI_ABORTED An existing GCD descriptor is malformed. + @retval EFI_ACCESS_DENIED DXE Services are no longer available. @retval Others The GCD memory services returned an error. **/ EFI_STATUS @@ -159,6 +163,13 @@ MapMmioMemory ( EFI_STATUS Status; EFI_PHYSICAL_ADDRESS RegionEnd; + if (mAtRuntime) { + // + // DXE Services are no longer available. + // + return EFI_ACCESS_DENIED; + } + DEBUG (( DEBUG_INFO, "Map MMIO Memory: 0x%08lx - 0x%08lx : 0x%08lx\n", @@ -198,3 +209,73 @@ MapMmioMemory ( return gDS->SetMemorySpaceAttributes (Base, Length, Attributes); } + +/** + Notification function signaled when ExitBootServices() is called. + + Record that DXE services are no longer available. MapMmioMemory() uses this + state to reject calls after ExitBootServices(). + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +STATIC +VOID +EFIAPI +MapMmioLibExitBootServicesNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + mAtRuntime = TRUE; +} + +/** + Library instance destructor. + + Close the ExitBootServices event created by the constructor. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The ExitBootServices event was closed. + @retval Others Failed to close the ExitBootServices event. +**/ +EFI_STATUS +EFIAPI +MapMmioLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return gBS->CloseEvent (mExitBootServicesEvent); +} + +/** + Library instance constructor. + + Register for ExitBootServices() notification so MapMmioLib can detect when + DXE services are no longer available. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The ExitBootServices event was registered. + @retval Others Failed to register the ExitBootServices event. +**/ +EFI_STATUS +EFIAPI +MapMmioLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + MapMmioLibExitBootServicesNotify, + NULL, + &gEfiEventExitBootServicesGuid, + &mExitBootServicesEvent + ); +} diff --git a/OvmfPkg/Library/MapMmioLib/MapMmioLib.inf b/OvmfPkg/Library/MapMmioLib/MapMmioLib.inf index 5a10641eed..24bf72984a 100644 --- a/OvmfPkg/Library/MapMmioLib/MapMmioLib.inf +++ b/OvmfPkg/Library/MapMmioLib/MapMmioLib.inf @@ -13,7 +13,9 @@ FILE_GUID = 65d2e4bd-7e64-4c5a-888e-eb0e5337033a MODULE_TYPE = DXE_DRIVER VERSION_STRING = 1.0 - LIBRARY_CLASS = MapMmioLib|DXE_DRIVER + LIBRARY_CLASS = MapMmioLib|DXE_DRIVER DXE_RUNTIME_DRIVER + CONSTRUCTOR = MapMmioLibConstructor + DESTRUCTOR = MapMmioLibDestructor [Sources] MapMmioLib.c @@ -29,5 +31,8 @@ MemoryAllocationLib UefiBootServicesTableLib +[Guids] + gEfiEventExitBootServicesGuid + [Depex] gEfiCpuArchProtocolGuid From b2b548c05750105d51fe86770974fffc1bafd50a Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Fri, 26 Jun 2026 17:23:59 +0100 Subject: [PATCH 262/406] ArmVirtPkg: Include MapMmioLib in ArmVirt.dsc.inc Add the MapMmioLib instance to the ArmVirt DXE_DRIVER library class list so DXE drivers can map MMIO regions through the common helper. Also add the runtime-driver library class mapping in ArmVirt.dsc.inc so that runtime modules like KvmtoolRtcFdtClientLib can use MapMmioLib. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- ArmVirtPkg/ArmVirt.dsc.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index b8c0cb5891..195e6595db 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -280,6 +280,7 @@ DEFINE FD_SIZE_IN_MB = 3 SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + MapMmioLib|OvmfPkg/Library/MapMmioLib/MapMmioLib.inf [LibraryClasses.common.UEFI_APPLICATION] PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf @@ -287,6 +288,7 @@ DEFINE FD_SIZE_IN_MB = 3 [LibraryClasses.common.DXE_RUNTIME_DRIVER] MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + MapMmioLib|OvmfPkg/Library/MapMmioLib/MapMmioLib.inf !if $(TARGET) != RELEASE DebugLib|ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf !endif From 28526dbba322e043c8089706f8e8e4c78012ee10 Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Sat, 23 May 2026 14:11:38 +0100 Subject: [PATCH 263/406] ArmVirtPkg: Map GIC MMIO ranges before configuring GIC Discover the GIC register ranges from the device tree and map them into the GCD memory map before ArmGicDxe configures the interrupt controller. Map the distributor and redistributor ranges for GICv3, and the distributor and CPU interface ranges for GICv2, using MapMmioLib. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- .../ArmVirtGicArchLib/ArmVirtGicArchLib.c | 62 ++++++++++++++++++- .../ArmVirtGicArchLib/ArmVirtGicArchLib.inf | 3 + 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c b/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c index b41f2660ff..2db53186ec 100644 --- a/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c +++ b/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c @@ -2,6 +2,7 @@ NULL library class implementation to discover the GIC for DT based virt platforms Copyright (c) 2015 - 2016, Linaro Ltd. All rights reserved.<BR> + Copyright (c) 2026, Arm Ltd. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -13,6 +14,7 @@ #include <Library/ArmGicLib.h> #include <Library/BaseLib.h> #include <Library/DebugLib.h> +#include <Library/MapMmioLib.h> #include <Library/PcdLib.h> #include <Library/UefiBootServicesTableLib.h> @@ -31,6 +33,7 @@ ArmVirtGicArchLibConstructor ( UINTN GicRevision; EFI_STATUS Status; UINT64 DistBase, CpuBase, RedistBase; + UINT64 DistSize, CpuSize, RedistSize; RETURN_STATUS PcdStatus; Status = gBS->LocateProtocol ( @@ -84,10 +87,14 @@ ArmVirtGicArchLibConstructor ( // RegProp[0..1] == { GICD base, GICD size } DistBase = SwapBytes64 (Reg[0]); ASSERT (DistBase < MAX_UINTN); + DistSize = SwapBytes64 (Reg[1]); + ASSERT (DistSize < MAX_UINTN); // RegProp[2..3] == { GICR base, GICR size } RedistBase = SwapBytes64 (Reg[2]); ASSERT (RedistBase < MAX_UINTN); + RedistSize = SwapBytes64 (Reg[3]); + ASSERT (RedistSize < MAX_UINTN); PcdStatus = PcdSet64S (PcdGicDistributorBase, DistBase); ASSERT_RETURN_ERROR (PcdStatus); @@ -96,11 +103,38 @@ ArmVirtGicArchLibConstructor ( DEBUG (( DEBUG_INFO, - "Found GIC v3 (re)distributor @ 0x%Lx (0x%Lx)\n", + "Found GIC v3 Distributor @ 0x%Lx, Len 0x%Lx\n", DistBase, - RedistBase + DistSize )); + DEBUG (( + DEBUG_INFO, + "Found GIC v3 Redistributor @ 0x%Lx, Len 0x%Lx\n", + RedistBase, + RedistSize + )); + + Status = MapMmioMemory ( + DistBase, + DistSize, + (EFI_MEMORY_UC | EFI_MEMORY_XP) + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return (RETURN_STATUS)Status; + } + + Status = MapMmioMemory ( + RedistBase, + RedistSize, + (EFI_MEMORY_UC | EFI_MEMORY_XP) + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return (RETURN_STATUS)Status; + } + break; case 2: @@ -112,9 +146,13 @@ ArmVirtGicArchLibConstructor ( ASSERT ((RegSize == 32) || (RegSize == 64)); DistBase = SwapBytes64 (Reg[0]); + DistSize = SwapBytes64 (Reg[1]); CpuBase = SwapBytes64 (Reg[2]); + CpuSize = SwapBytes64 (Reg[3]); ASSERT (DistBase < MAX_UINTN); ASSERT (CpuBase < MAX_UINTN); + ASSERT (DistSize < MAX_UINTN); + ASSERT (CpuSize < MAX_UINTN); PcdStatus = PcdSet64S (PcdGicDistributorBase, DistBase); ASSERT_RETURN_ERROR (PcdStatus); @@ -123,6 +161,26 @@ ArmVirtGicArchLibConstructor ( DEBUG ((DEBUG_INFO, "Found GIC @ 0x%Lx/0x%Lx\n", DistBase, CpuBase)); + Status = MapMmioMemory ( + DistBase, + DistSize, + (EFI_MEMORY_UC | EFI_MEMORY_XP) + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return (RETURN_STATUS)Status; + } + + Status = MapMmioMemory ( + CpuBase, + CpuSize, + (EFI_MEMORY_UC | EFI_MEMORY_XP) + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return (RETURN_STATUS)Status; + } + break; default: diff --git a/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf b/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf index a653ba68c9..ff65a6876d 100644 --- a/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf +++ b/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf @@ -3,6 +3,7 @@ # Component description file for ArmVirtGicArchLib module # # Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR> +# Copyright (c) 2026, Arm Ltd. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -24,6 +25,7 @@ BaseLib DebugLib PcdLib + MapMmioLib UefiBootServicesTableLib [Packages] @@ -31,6 +33,7 @@ ArmVirtPkg/ArmVirtPkg.dec EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec [Protocols] gFdtClientProtocolGuid ## CONSUMES From 9dcf9d317a0273482ca38a5b161a761e35cca18a Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Sat, 23 May 2026 14:13:16 +0100 Subject: [PATCH 264/406] ArmVirtPkg/KvmtoolRtcFdtClientLib: Use MapMmioLib for MMIO mapping Replace the local RTC MMIO mapping sequence with MapMmioMemory(), while keeping the explicit GCD allocation so the RTC page remains owned by the driver image handle. This reuses the common MMIO mapping path for GCD attributes. Also update the incorrect error code documentation to reflect that EFI_NOT_FOUND can be returned if the GCD space is not found and drop the depex on gEfiCpuArchProtocolGuid as this is now done by MapMmioLib which is where the Cpu Arch protocol is utilised. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- .../KvmtoolRtcFdtClientLib.c | 48 +++++-------------- .../KvmtoolRtcFdtClientLib.inf | 6 ++- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/ArmVirtPkg/Library/KvmtoolRtcFdtClientLib/KvmtoolRtcFdtClientLib.c b/ArmVirtPkg/Library/KvmtoolRtcFdtClientLib/KvmtoolRtcFdtClientLib.c index 2afb56ccf8..1f711a43b7 100644 --- a/ArmVirtPkg/Library/KvmtoolRtcFdtClientLib/KvmtoolRtcFdtClientLib.c +++ b/ArmVirtPkg/Library/KvmtoolRtcFdtClientLib/KvmtoolRtcFdtClientLib.c @@ -1,7 +1,7 @@ /** @file FDT client library for motorola,mc146818 RTC driver - Copyright (c) 2020, ARM Limited. All rights reserved.<BR> + Copyright (c) 2020 - 2026, ARM Limited. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -10,6 +10,7 @@ #include <Library/BaseLib.h> #include <Library/DebugLib.h> #include <Library/DxeServicesTableLib.h> +#include <Library/MapMmioLib.h> #include <Library/PcdLib.h> #include <Library/UefiBootServicesTableLib.h> #include <Protocol/FdtClient.h> @@ -29,7 +30,8 @@ @retval EFI_SUCCESS Success. @retval EFI_INVALID_PARAMETER A parameter is invalid. - @retval EFI_NOT_FOUND Flash device not found. + @retval EFI_NOT_FOUND The requested GCD memory space could + not be found. **/ STATIC EFI_STATUS @@ -40,16 +42,15 @@ KvmtoolRtcMapMemory ( { EFI_STATUS Status; - Status = gDS->AddMemorySpace ( - EfiGcdMemoryTypeMemoryMappedIo, - RtcPageBase, - EFI_PAGE_SIZE, - EFI_MEMORY_UC | EFI_MEMORY_RUNTIME | EFI_MEMORY_XP - ); + Status = MapMmioMemory ( + RtcPageBase, + EFI_PAGE_SIZE, + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME | EFI_MEMORY_XP + ); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, - "Failed to add memory space. Status = %r\n", + "Failed to map memory. Status = %r\n", Status )); return Status; @@ -70,32 +71,6 @@ KvmtoolRtcMapMemory ( "Failed to allocate memory space. Status = %r\n", Status )); - gDS->RemoveMemorySpace ( - RtcPageBase, - EFI_PAGE_SIZE - ); - return Status; - } - - Status = gDS->SetMemorySpaceAttributes ( - RtcPageBase, - EFI_PAGE_SIZE, - EFI_MEMORY_UC | EFI_MEMORY_RUNTIME | EFI_MEMORY_XP - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "Failed to set memory attributes. Status = %r\n", - Status - )); - gDS->FreeMemorySpace ( - RtcPageBase, - EFI_PAGE_SIZE - ); - gDS->RemoveMemorySpace ( - RtcPageBase, - EFI_PAGE_SIZE - ); } return Status; @@ -113,7 +88,8 @@ KvmtoolRtcMapMemory ( @retval EFI_SUCCESS Success. @retval EFI_INVALID_PARAMETER A parameter is invalid. - @retval EFI_NOT_FOUND Flash device not found. + @retval EFI_NOT_FOUND The requested GCD memory space could + not be found. **/ EFI_STATUS EFIAPI diff --git a/ArmVirtPkg/Library/KvmtoolRtcFdtClientLib/KvmtoolRtcFdtClientLib.inf b/ArmVirtPkg/Library/KvmtoolRtcFdtClientLib/KvmtoolRtcFdtClientLib.inf index c10a6737a0..aa26088073 100644 --- a/ArmVirtPkg/Library/KvmtoolRtcFdtClientLib/KvmtoolRtcFdtClientLib.inf +++ b/ArmVirtPkg/Library/KvmtoolRtcFdtClientLib/KvmtoolRtcFdtClientLib.inf @@ -1,7 +1,7 @@ ## @file # FDT client library for motorola,mc146818 RTC driver # -# Copyright (c) 2020 - 2023, ARM Limited. All rights reserved.<BR> +# Copyright (c) 2020 - 2026, ARM Limited. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -23,11 +23,13 @@ ArmVirtPkg/ArmVirtPkg.dec EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec PcAtChipsetPkg/PcAtChipsetPkg.dec [LibraryClasses] BaseLib DebugLib + MapMmioLib PcdLib UefiBootServicesTableLib DxeServicesTableLib @@ -40,4 +42,4 @@ gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister64 [Depex] - gFdtClientProtocolGuid AND gEfiCpuArchProtocolGuid + gFdtClientProtocolGuid From d46e38c5ea4cefa6ccb7a291196ab255c9d528ef Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Wed, 1 Jul 2026 18:56:25 +0100 Subject: [PATCH 265/406] OvmfPkg/FdtPciHostBridgeLib: Use MapMmioLib for MMIO mapping Replace the local GCD MMIO mapping helper with MapMmioMemory() when mapping the PCI ECAM region and the translated I/O MMIO window. This keeps the FDT PCI host bridge code aligned with the common MMIO mapping helper and avoids duplicating AddMemorySpace() and SetMemorySpaceAttributes() handling. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- .../FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 47 ++----------------- .../FdtPciHostBridgeLib.inf | 2 +- OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc | 1 + OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc | 1 + 5 files changed, 8 insertions(+), 44 deletions(-) diff --git a/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c index 9af8c21a21..4912355999 100644 --- a/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c +++ b/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c @@ -2,6 +2,7 @@ PCI Host Bridge Library instance for pci-ecam-generic DT nodes Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR> + Copyright (c) 2026, Arm Ltd. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -10,7 +11,7 @@ #include <Library/BaseMemoryLib.h> #include <Library/DebugLib.h> #include <Library/DevicePathLib.h> -#include <Library/DxeServicesTableLib.h> +#include <Library/MapMmioLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/PcdLib.h> #include <Library/PciHostBridgeLib.h> @@ -42,46 +43,6 @@ typedef struct { #define DTB_PCI_HOST_RANGE_IO BIT24 #define DTB_PCI_HOST_RANGE_TYPEMASK (BIT31 | BIT30 | BIT29 | BIT25 | BIT24) -STATIC -EFI_STATUS -MapGcdMmioSpace ( - IN UINT64 Base, - IN UINT64 Size - ) -{ - EFI_STATUS Status; - - Status = gDS->AddMemorySpace ( - EfiGcdMemoryTypeMemoryMappedIo, - Base, - Size, - EFI_MEMORY_UC - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "%a: failed to add GCD memory space for region [0x%Lx+0x%Lx)\n", - __func__, - Base, - Size - )); - return Status; - } - - Status = gDS->SetMemorySpaceAttributes (Base, Size, EFI_MEMORY_UC); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "%a: failed to set memory space attributes for region [0x%Lx+0x%Lx)\n", - __func__, - Base, - Size - )); - } - - return Status; -} - STATIC EFI_STATUS ProcessPciHost ( @@ -322,7 +283,7 @@ ProcessPciHost ( )); // Map the ECAM space in the GCD memory map - Status = MapGcdMmioSpace (ConfigBase, ConfigSize); + Status = MapMmioMemory (ConfigBase, ConfigSize, EFI_MEMORY_UC); ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { return Status; @@ -334,7 +295,7 @@ ProcessPciHost ( // is not aware of this translation and so it will only map the I/O view // in the GCD I/O map. // - Status = MapGcdMmioSpace (*IoBase + IoTranslation, *IoSize); + Status = MapMmioMemory (*IoBase + IoTranslation, *IoSize, EFI_MEMORY_UC); ASSERT_EFI_ERROR (Status); } diff --git a/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf b/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf index 26b38b5966..5c6bbba912 100644 --- a/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf +++ b/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf @@ -29,7 +29,7 @@ BaseMemoryLib DebugLib DevicePathLib - DxeServicesTableLib + MapMmioLib MemoryAllocationLib PciHostBridgeUtilityLib PciPcdProducerLib diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc index 15bb9a856a..aa8c10493b 100644 --- a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc +++ b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc @@ -332,6 +332,7 @@ QemuFwCfgLib | OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgMmioDxeLib.inf PciPcdProducerLib | OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf AcpiPlatformLib | OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf + MapMmioLib | OvmfPkg/Library/MapMmioLib/MapMmioLib.inf MpInitLib | UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf !if $(TPM2_ENABLE) == TRUE Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index 0211e960f6..ee8cf56ca6 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -397,6 +397,7 @@ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + MapMmioLib|OvmfPkg/Library/MapMmioLib/MapMmioLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf diff --git a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc index 47248f2312..83e0cdaefa 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc +++ b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc @@ -186,6 +186,7 @@ [LibraryClasses.common.DXE_DRIVER] SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf + MapMmioLib|OvmfPkg/Library/MapMmioLib/MapMmioLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf From da1ccea67ce0fa58dd934abc5535443d7197004b Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Sat, 23 May 2026 14:14:05 +0100 Subject: [PATCH 266/406] OvmfPkg/FdtPciHostBridgeLib: Map PCI MMIO windows in GCD Map the PCI MMIO32 and MMIO64 windows into the GCD memory map after parsing the DT ranges property. This makes the PCI memory apertures available as MMIO regions. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- .../FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c index 4912355999..783ce27f30 100644 --- a/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c +++ b/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c @@ -297,6 +297,22 @@ ProcessPciHost ( // Status = MapMmioMemory (*IoBase + IoTranslation, *IoSize, EFI_MEMORY_UC); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + } + + if (*Mmio32Size != 0) { + Status = MapMmioMemory (*Mmio32Base, *Mmio32Size, EFI_MEMORY_UC); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + } + + if (*Mmio64Size != 0) { + Status = MapMmioMemory (*Mmio64Base, *Mmio64Size, EFI_MEMORY_UC); + ASSERT_EFI_ERROR (Status); } return Status; From 2adf8dc56d1036eb9f8c00a11620f68d71bf277b Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Mon, 15 Jun 2026 16:24:28 +0100 Subject: [PATCH 267/406] ArmVirtPkg: Add early FDT 16550 serial port probe library Fdt16550SerialPortHookLib does not provide a constructor and expects SerialPortLib to call PlatformHookSerialPortInitialize(). Add an early FDT 16550 serial port probe library that invokes the platform serial hook from its constructor. This allows the FDT to be parsed early, the 16550 serial port base address to be extracted, and the serial port PCD to be populated. It is needed during early boot so the serial port memory map can be set up using the populated serial port PCD. The probe library wraps the hook call in its constructor instead of reusing PlatformHookSerialPortInitialize() directly. This avoids duplicate global definitions in modules that already link against the PlatformHookLib instance. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- .../EarlyFdt16550SerialPortProbeLib.c | 31 +++++++++++++++++++ .../EarlyFdt16550SerialPortProbeLib.inf | 29 +++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.c create mode 100644 ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.inf diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.c b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.c new file mode 100644 index 0000000000..17d919eb79 --- /dev/null +++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.c @@ -0,0 +1,31 @@ +/** @file + Early FDT 16550 serial port probe constructor. + + Copyright (c) 2026, ARM Ltd. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Base.h> +#include <Library/PlatformHookLib.h> + +/** + Early constructor to probe the FDT for the 16550 UART base address. + + This constructor invokes the platform serial hook so early boot code can + populate PcdSerialRegisterBase before it is used. + + @retval RETURN_SUCCESS The serial port base address was already + configured or was found and stored. + @retval RETURN_INVALID_PARAMETER A parameter was invalid. + @retval RETURN_NOT_FOUND Serial port information was not found. + @retval RETURN_PROTOCOL_ERROR Invalid serial port information was found + in the device tree. +**/ +RETURN_STATUS +EFIAPI +EarlyFdt16550SerialPortProbeLibConstructor ( + VOID + ) +{ + return PlatformHookSerialPortInitialize (); +} diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.inf b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.inf new file mode 100644 index 0000000000..bc57ecf921 --- /dev/null +++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.inf @@ -0,0 +1,29 @@ +## @file +# Early Platform Probe Library instance for 16550 Uart. +# +# Copyright (c) 2026, ARM Ltd. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = EarlyFdt16550SerialPortProbeLib + MODULE_UNI_FILE = Fdt16550SerialPortHookLib.uni + FILE_GUID = 07a000d5-7de7-485f-ab59-a2ce4da5e488 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL|SEC PEI_CORE PEIM + CONSTRUCTOR = EarlyFdt16550SerialPortProbeLibConstructor + +[Sources] + EarlyFdt16550SerialPortProbeLib.c + +[LibraryClasses] + PlatformHookLib + +[Packages] + ArmVirtPkg/ArmVirtPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec From 2f91cf9045bf43a24c99c8df799a92841eb9ad28 Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Mon, 15 Jun 2026 18:03:33 +0100 Subject: [PATCH 268/406] ArmVirtPkg: Refactor memory map configuration for Kvmtool Guest VM Refactor the memory mapping configuration for Kvmtool Guest VM to only setup the memory map for the System Memory, FV and the Serial Port. The memory mappings for he remaining devices are expected to be configured by the respective drivers, this could be done as part of the DXE drivers itself or using a Probe Library that adds the device memory regions to the memory map. The only special cases that remain are the System Memory, FV and the Serial Port for which the memory mappings are created by the KvmtoolVirtMemInfoLib. The memory mapping for the Serial port is added as it is utilised for logging before the DXE driver is loaded. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- ArmVirtPkg/ArmVirtKvmTool.dsc | 1 + .../KvmtoolVirtMemInfoLib.c | 24 +++++-------------- .../KvmtoolVirtMemInfoLib.inf | 3 +-- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index 91411b5264..b91a64a0e0 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -227,6 +227,7 @@ HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf + NULL|ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.inf } # diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c index 79412897f2..e5612bb75d 100644 --- a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c +++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c @@ -1,7 +1,7 @@ /** @file Kvmtool virtual memory map library. - Copyright (c) 2018 - 2020, ARM Limited. All rights reserved. + Copyright (c) 2018 - 2026, ARM Limited. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent @@ -9,8 +9,6 @@ #include <Base.h> #include <Library/ArmLib.h> -#include <Library/BaseLib.h> -#include <Library/BaseMemoryLib.h> #include <Library/DebugLib.h> #include <Library/MemoryAllocationLib.h> @@ -37,12 +35,9 @@ ArmVirtGetMemoryMap ( { ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable; UINTN Idx; - EFI_PHYSICAL_ADDRESS TopOfAddressSpace; ASSERT (VirtualMemoryMap != NULL); - TopOfAddressSpace = LShiftU64 (1ULL, ArmGetPhysicalAddressBits ()); - VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR *) AllocatePages ( EFI_SIZE_TO_PAGES ( @@ -66,20 +61,13 @@ ArmVirtGetMemoryMap ( VirtualMemoryTable[Idx].Length = PcdGet64 (PcdSystemMemorySize); VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK; - // Peripheral space before DRAM - VirtualMemoryTable[++Idx].PhysicalBase = 0x0; - VirtualMemoryTable[Idx].VirtualBase = 0x0; - VirtualMemoryTable[Idx].Length = PcdGet64 (PcdSystemMemoryBase); + // Map the UART + ASSERT (IS_ALIGNED (PcdGet64 (PcdSerialRegisterBase), EFI_PAGE_SIZE)); + VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdSerialRegisterBase); + VirtualMemoryTable[Idx].VirtualBase = PcdGet64 (PcdSerialRegisterBase); + VirtualMemoryTable[Idx].Length = EFI_PAGE_SIZE; VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE; - // Peripheral space after DRAM - VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdSystemMemoryBase) + - PcdGet64 (PcdSystemMemorySize); - VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase; - VirtualMemoryTable[Idx].Length = TopOfAddressSpace - - VirtualMemoryTable[Idx].PhysicalBase; - VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE; - // Map the FV region as normal executable memory VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdFvBaseAddress); VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase; diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf index a354e734ab..16b3564e48 100644 --- a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf +++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf @@ -27,8 +27,6 @@ [LibraryClasses] ArmLib - BaseLib - BaseMemoryLib DebugLib MemoryAllocationLib PcdLib @@ -37,6 +35,7 @@ gArmTokenSpaceGuid.PcdFvBaseAddress gArmTokenSpaceGuid.PcdSystemMemoryBase gArmTokenSpaceGuid.PcdSystemMemorySize + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase [FixedPcd] gArmTokenSpaceGuid.PcdFvSize From 422cc775a910e0f42f70162d3ed6a228a8a1437d Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Wed, 24 Jun 2026 13:17:43 +0100 Subject: [PATCH 269/406] OvmfPkg: Introduce a Virtio MMIO probe lib Introduce a Virtio MMIO probe library that discovers virtio-mmio nodes from the FDT and maps their MMIO ranges before the virtio transport driver creates virtio devices and accesses the device MMIO regions. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- .../VirtioMmioProbeLib/VirtioMmioProbeLib.c | 117 ++++++++++++++++++ .../VirtioMmioProbeLib/VirtioMmioProbeLib.inf | 40 ++++++ 2 files changed, 157 insertions(+) create mode 100644 OvmfPkg/Library/VirtioMmioProbeLib/VirtioMmioProbeLib.c create mode 100644 OvmfPkg/Library/VirtioMmioProbeLib/VirtioMmioProbeLib.inf diff --git a/OvmfPkg/Library/VirtioMmioProbeLib/VirtioMmioProbeLib.c b/OvmfPkg/Library/VirtioMmioProbeLib/VirtioMmioProbeLib.c new file mode 100644 index 0000000000..26b254db6a --- /dev/null +++ b/OvmfPkg/Library/VirtioMmioProbeLib/VirtioMmioProbeLib.c @@ -0,0 +1,117 @@ +/** @file + NULL library class implementation to discover the virtio-mmio regions and map them. + + Copyright (c) 2026, Arm Ltd. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Base.h> +#include <Uefi.h> + +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/MapMmioLib.h> +#include <Library/DxeServicesTableLib.h> +#include <Library/UefiBootServicesTableLib.h> + +#include <Protocol/FdtClient.h> + +/** Entrypoint for VirtioMmioProbeLib. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Flash device not found. +**/ +EFI_STATUS +EFIAPI +VirtioMmioProbe ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_STATUS FindNodeStatus; + FDT_CLIENT_PROTOCOL *FdtClient; + INT32 Node; + CONST UINT64 *Reg; + UINT32 RegSize; + UINT64 RegBase; + UINT64 Range; + + Status = gBS->LocateProtocol ( + &gFdtClientProtocolGuid, + NULL, + (VOID **)&FdtClient + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + for (FindNodeStatus = FdtClient->FindCompatibleNode ( + FdtClient, + "virtio,mmio", + &Node + ); + !EFI_ERROR (FindNodeStatus); + FindNodeStatus = FdtClient->FindNextCompatibleNode ( + FdtClient, + "virtio,mmio", + Node, + &Node + )) + { + Status = FdtClient->GetNodeProperty ( + FdtClient, + Node, + "reg", + (CONST VOID **)&Reg, + &RegSize + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: GetNodeProperty () failed (Status == %r)\n", + __func__, + Status + )); + continue; + } + + if (RegSize != 16) { + ASSERT (RegSize == 16); + continue; + } + + RegBase = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0])); + Range = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[1])); + DEBUG (( + DEBUG_INFO, + "virtio-mmio : RegBase = 0x%lx - 0x%lx\n", + RegBase, + Range + )); + + Status = MapMmioMemory ( + RegBase, + Range, + (EFI_MEMORY_UC | EFI_MEMORY_XP) + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "virtio-mmio : Failed to map memory region - RegBase = 0x%lx - 0x%lx\n", + RegBase, + Range + )); + return Status; + } + } // for + + return Status; +} diff --git a/OvmfPkg/Library/VirtioMmioProbeLib/VirtioMmioProbeLib.inf b/OvmfPkg/Library/VirtioMmioProbeLib/VirtioMmioProbeLib.inf new file mode 100644 index 0000000000..013f0e59b1 --- /dev/null +++ b/OvmfPkg/Library/VirtioMmioProbeLib/VirtioMmioProbeLib.inf @@ -0,0 +1,40 @@ +## @file +# Probe Library for mapping the virtio-mmio memory regions. +# +# Copyright (c) 2026, Arm Ltd. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001C + BASE_NAME = VirtioMmioProbeLib + FILE_GUID = 4e2e15be-b53e-4a8f-acf9-98b2204a38b7 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = VirtioMmioProbe + +[Sources] + VirtioMmioProbeLib.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + DxeServicesTableLib + MapMmioLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Depex] + gFdtClientProtocolGuid From 74caea295623fc7ec3f27a71f3488662864cbb4e Mon Sep 17 00:00:00 2001 From: Sami Mujawar <sami.mujawar@arm.com> Date: Fri, 26 Jun 2026 17:22:37 +0100 Subject: [PATCH 270/406] ArmVirtPkg: Link VirtioMmioProbeLib to VirtioFdtDxe Link VirtioMmioProbeLib to VirtioFdtDxe so that the Virtio MMIO probe constructor maps the virtio-mmio ranges before the transport driver accesses the device MMIO regions. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> --- ArmVirtPkg/ArmVirt.dsc.inc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 195e6595db..fc60d87ce3 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -483,7 +483,11 @@ DEFINE FD_SIZE_IN_MB = 3 # EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf !if $(ENABLE_VIRTIO) - OvmfPkg/Fdt/VirtioFdtDxe/VirtioFdtDxe.inf + OvmfPkg/Fdt/VirtioFdtDxe/VirtioFdtDxe.inf { + <LibraryClasses> + NULL|OvmfPkg/Library/VirtioMmioProbeLib/VirtioMmioProbeLib.inf + } + OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf OvmfPkg/VirtioBlkDxe/VirtioBlk.inf OvmfPkg/VirtioScsiDxe/VirtioScsi.inf From bcd168735f46b30525a59b782cad032b8de55e60 Mon Sep 17 00:00:00 2001 From: VarshitPandya <varshit.pandya@arm.com> Date: Fri, 17 Jul 2026 16:28:53 +0100 Subject: [PATCH 271/406] DynamicTablesPkg: Move common size definitions Move SMBIOS_MAX_STRING_SIZE and CFMWS_MAX_INTERLEAVE_WAYS to the common definitions near the top of ArchCommonNameSpaceObjects.h. Document that SMBIOS_MAX_STRING_SIZE is an implementation-defined Configuration Manager storage limit, including the terminating NULL, rather than an SMBIOS specification limit. Also distinguish it from the legacy SMBIOS_STRING_MAX_LENGTH definition used for SMBIOS 2.6 MIF compatibility. Signed-off-by: Varshit Pandya <varshit.pandya@arm.com> --- .../Include/ArchCommonNameSpaceObjects.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index da543b8495..b6642bcad6 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -21,6 +21,19 @@ #include <IndustryStandard/Tpm2Acpi.h> #include <IndustryStandard/SmBios.h> +/// +/// Maximum storage size, including the terminating NULL, for SMBIOS strings +/// represented inline in Configuration Manager objects. This is a +/// DynamicTablesPkg implementation limit. +/// +/// The legacy 64-character constraint from SMBIOS 2.6 was required for MIF +/// compatibility and does not apply to SMBIOS 2.7 or later tables. +/// +#define SMBIOS_MAX_STRING_SIZE (1024) + +// Maximum interleave ways is defined in the CXL spec section 8.2.4.19.7. +#define CFMWS_MAX_INTERLEAVE_WAYS (16) + /** The EARCH_COMMON_OBJECT_ID enum describes the Object IDs in the Arch Common Namespace */ @@ -459,8 +472,6 @@ typedef struct CmArchCommonLpiInfo { CHAR8 StateName[16]; } CM_ARCH_COMMON_LPI_INFO; -#define SMBIOS_MAX_STRING_SIZE (1024) - /** A structure that describes the Processor Hierarchy Node (Type 0) in PPTT ID: EArchCommonObjProcHierarchyInfo @@ -980,9 +991,6 @@ typedef struct CmArchCommonCxlHostBridgeInfo { UINT64 ComponentRegisterBase; } CM_ARCH_COMMON_CXL_HOST_BRIDGE_INFO; -// Maximum interleave ways is defined in the CXL spec section 8.2.4.19.7. -#define CFMWS_MAX_INTERLEAVE_WAYS (16) - /** A structure that describes the CXL Fixed Memory Window Structure (Type 1). ID: EArchCommonObjCxlFixedMemoryWindowInfo From ea275a48fa983d9d2266d697b1248d63ea5a9ba2 Mon Sep 17 00:00:00 2001 From: Jared Pan <jared.pan@dell.com> Date: Mon, 13 Jul 2026 16:10:14 +0800 Subject: [PATCH 272/406] MdePkg/Usb: Add BOS Descriptor to support SuperSpeed Devices [Suggested Solution] Add the BOS descriptor structure and definition. Signed-off-by: Marlboro Chuang <marlboro.chuang@dell.com> Signed-off-by: Jared Pan <jared.pan@dell.com> --- MdePkg/Include/IndustryStandard/Usb.h | 27 +++++++++++++++++++++++++++ MdePkg/Include/Protocol/UsbIo.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/MdePkg/Include/IndustryStandard/Usb.h b/MdePkg/Include/IndustryStandard/Usb.h index e7caf65a33..abb78b1c2c 100644 --- a/MdePkg/Include/IndustryStandard/Usb.h +++ b/MdePkg/Include/IndustryStandard/Usb.h @@ -117,6 +117,24 @@ typedef struct { UINT8 NumConfigurations; } USB_DEVICE_DESCRIPTOR; +/// +/// Binary Device Object Store (BOS) +/// USB 3.0 spec, Section 9.6.2 +/// +typedef struct { + UINT8 Length; + UINT8 DescriptorType; + UINT16 TotalLength; + UINT8 NumDeviceCaps; +} USB_BOS_DESCRIPTOR; + +typedef struct { + UINT8 Length; + UINT8 DescriptorType; + UINT8 DevCapabilityType; + UINT8 CapData[1]; +} USB_DEV_CAP_DESCRIPTOR; + /// /// Standard Configuration Descriptor /// USB 2.0 spec, Section 9.6.3 @@ -229,11 +247,20 @@ typedef enum { USB_DESC_TYPE_INTERFACE = 0x04, USB_DESC_TYPE_ENDPOINT = 0x05, USB_DESC_TYPE_INTERFACE_ASSOCIATION = 0x0b, + USB_DESC_TYPE_BOS = 0x0f, + USB_DESC_TYPE_DEV_CAP = 0x10, USB_DESC_TYPE_HID = 0x21, USB_DESC_TYPE_REPORT = 0x22, USB_DESC_TYPE_CS_INTERFACE = 0x24, USB_DESC_TYPE_CS_ENDPOINT = 0x25, + // + // Device Capability Type Codes + // + USB_DEV_CAP_WIRELESS_USB = 0x01, + USB_DEV_CAP_USB20_EXTENSION = 0x02, + USB_DEV_CAP_SUPPERSPEED_USB = 0x03, + // // Features to be cleared by CLEAR_FEATURE requests // diff --git a/MdePkg/Include/Protocol/UsbIo.h b/MdePkg/Include/Protocol/UsbIo.h index 2f9fae2a37..23f041fd51 100644 --- a/MdePkg/Include/Protocol/UsbIo.h +++ b/MdePkg/Include/Protocol/UsbIo.h @@ -34,6 +34,8 @@ typedef struct _EFI_USB_IO_PROTOCOL EFI_USB_IO_PROTOCOL; typedef USB_DEVICE_REQUEST EFI_USB_DEVICE_REQUEST; typedef USB_DEVICE_DESCRIPTOR EFI_USB_DEVICE_DESCRIPTOR; typedef USB_CONFIG_DESCRIPTOR EFI_USB_CONFIG_DESCRIPTOR; +typedef USB_BOS_DESCRIPTOR EFI_USB_BOS_DESCRIPTOR; +typedef USB_DEV_CAP_DESCRIPTOR EFI_USB_DEV_CAP_DESCRIPTOR; typedef USB_INTERFACE_DESCRIPTOR EFI_USB_INTERFACE_DESCRIPTOR; typedef USB_ENDPOINT_DESCRIPTOR EFI_USB_ENDPOINT_DESCRIPTOR; From 4d5f8e68a1e9baec74c8bd73c0dd09a596c1c3f9 Mon Sep 17 00:00:00 2001 From: Jared Pan <jared.pan@dell.com> Date: Mon, 13 Jul 2026 16:10:37 +0800 Subject: [PATCH 273/406] MdeModulePkg/UsbBusDxe: BOS Descriptor Check for SS Devices Some SuperSpeed-capable devices may fall back to High-Speed mode and cause subsequent commands to fail. [Suggested Solution] Check the BOS descriptor to verify SuperSpeed support and trigger a port reset if needed to re-enumerate the device properly. Signed-off-by: Marlboro Chuang <marlboro.chuang@dell.com> Signed-off-by: Jared Pan <jared.pan@dell.com> --- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h | 1 + MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c | 112 +++++++++++++++++++++ MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h | 1 + MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 13 +++ MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c | 18 ++++ 5 files changed, 145 insertions(+) diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h index bc4f7ceb02..50b5187ece 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h @@ -198,6 +198,7 @@ struct _USB_DEVICE { UINT8 Tier; BOOLEAN DisconnectFail; UINT8 EnumScript; + BOOLEAN IsSSDev; }; // diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c index 3f55c3a381..106757ecb8 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c @@ -114,6 +114,10 @@ UsbFreeDevDesc ( FreePool (DevDesc->Configs); } + if (DevDesc->BosDesc != NULL) { + FreePool (DevDesc->BosDesc); + } + if (DevDesc->StrDescManufacturerUS != NULL) { FreePool (DevDesc->StrDescManufacturerUS); } @@ -331,6 +335,44 @@ ON_ERROR: return NULL; } +/** + Parse the BOS descriptor and check if it is a SS device. + + @param BosDesc The buffer pointer of BOS descriptor. + @param Len The length of the raw descriptor buffer. + + @return TRUE The device is a SS device + FALSE The device is not a SS device + +**/ +BOOLEAN +UsbIsSSDevice ( + IN EFI_USB_BOS_DESCRIPTOR *BosDesc, + IN UINTN Len + ) +{ + UINT8 *NextCap; + UINT8 Index; + UINT8 NumCapDesc; + EFI_USB_DEV_CAP_DESCRIPTOR *DevCapDesc; + + if ((BosDesc->DescriptorType != USB_DESC_TYPE_BOS) || (Len == 0)) { + return FALSE; + } + + NumCapDesc = BosDesc->NumDeviceCaps; + NextCap = (UINT8 *)BosDesc + BosDesc->Length; + + for (Index = 0; Index < NumCapDesc; Index++, NextCap += DevCapDesc->Length) { + DevCapDesc = (EFI_USB_DEV_CAP_DESCRIPTOR *)NextCap; + if ((DevCapDesc->DescriptorType == USB_DESC_TYPE_DEV_CAP) && (DevCapDesc->DevCapabilityType == USB_DEV_CAP_SUPPERSPEED_USB)) { + return TRUE; + } + } + + return FALSE; +} + /** Parse the configuration descriptor and its interfaces. @@ -644,6 +686,66 @@ UsbGetDevDesc ( return Status; } +/** + Get the device BOS descriptor for the device. + + @param UsbDev The Usb device to retrieve descriptor from. + + @retval EFI_SUCCESS The device descriptor is returned. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + +**/ +EFI_STATUS +UsbGetDevBosDesc ( + IN USB_DEVICE *UsbDev + ) +{ + UINT8 *Buf; + UINTN TotalLength; + EFI_STATUS Status; + + Buf = AllocateZeroPool (sizeof (EFI_USB_BOS_DESCRIPTOR)); + if (Buf == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = UsbCtrlGetDesc ( + UsbDev, + USB_DESC_TYPE_BOS, + 0, + 0, + Buf, + sizeof (EFI_USB_BOS_DESCRIPTOR) + ); + if (!EFI_ERROR (Status)) { + TotalLength = ((EFI_USB_BOS_DESCRIPTOR *)Buf)->TotalLength; + gBS->FreePool (Buf); + Buf = NULL; + Buf = AllocateZeroPool (TotalLength); + if (Buf == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = UsbCtrlGetDesc ( + UsbDev, + USB_DESC_TYPE_BOS, + 0, + 0, + Buf, + TotalLength + ); + + if (EFI_ERROR (Status)) { + gBS->FreePool (Buf); + Buf = NULL; + } + + UsbDev->DevDesc->BosDesc = (EFI_USB_BOS_DESCRIPTOR *)Buf; + } + + return Status; +} + /** Retrieve the indexed string for the language. It requires two steps to get a string, first to get the string's length. Then @@ -1036,6 +1138,16 @@ UsbBuildDescTable ( DevDesc->Configs[Index] = ConfigDesc; } + if (DevDesc->Desc.BcdUSB >= 0x210) { + Status = UsbGetDevBosDesc (UsbDev); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "UsbBuildDescTable: get BOS descriptor %r\n", Status)); + } else { + UsbDev->IsSSDev = UsbIsSSDevice (UsbDev->DevDesc->BosDesc, (UINTN)((EFI_USB_BOS_DESCRIPTOR *)(UsbDev->DevDesc->BosDesc))->TotalLength); + DEBUG ((DEBUG_INFO, "UsbBuildDescTable: get BOS descriptor %r, UsbDev->IsSSDev = %d\n", Status, UsbDev->IsSSDev)); + } + } + // // Don't return error even this function failed because // it is possible for the device to not support strings. diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h index 9d4540bff9..1def04fb57 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h @@ -71,6 +71,7 @@ typedef struct { UINT8 *StrDescManufacturerUS; UINT8 *StrDescProductUS; UINT8 *StrDescSerialNumberUS; + EFI_USB_BOS_DESCRIPTOR *BosDesc; } USB_DEVICE_DESC; /** diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c index 82c9a4f9ef..64da8d7bfc 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c @@ -234,6 +234,7 @@ UsbCreateDevice ( Device->ParentPort = ParentPort; Device->Tier = (UINT8)(ParentIf->Device->Tier + 1); Device->EnumScript = 0; + Device->IsSSDev = FALSE; return Device; } @@ -854,6 +855,18 @@ DeviceRetry: goto ON_ERROR; } + // Below code is ensuring the device can be executed with SS. + // Some device FW might execute with SS later but it would produce failure if the device is already enumerated with HS. + if ( (RetryCount > 0) + && (Bus->Usb2Hc != NULL) + && (Bus->Usb2Hc->MajorRevision >= 0x3) + && (Child->IsSSDev) + && (Child->Speed < EFI_USB_SPEED_SUPER) + && (Child->DevDesc->Desc.DeviceClass != USB_HUB_CLASS_CODE)) + { + goto ON_ERROR; + } + // // Select a default configuration: UEFI must set the configuration // before the driver can connect to the device. diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c index c4abf12c2d..550323059b 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c @@ -1166,6 +1166,24 @@ UsbRootHubResetPort ( // gBS->Stall (USB_SET_ROOT_PORT_RESET_STALL); + for (Index = 0; Index < Bus->MaxDevices; Index++) { + if ( (Bus->Devices[Index] != NULL) + && (Bus->Devices[Index]->ParentPort == Port) + && (Bus->Devices[Index]->ParentIf == RootIf)) + { + if ( (Bus->Usb2Hc != NULL) + && (Bus->Usb2Hc->MajorRevision >= 0x3) + && (Bus->Devices[Index]->IsSSDev) + && (Bus->Devices[Index]->Speed < EFI_USB_SPEED_SUPER) + && (Bus->Devices[Index]->DevDesc->Desc.DeviceClass != USB_HUB_CLASS_CODE)) + { + DEBUG ((DEBUG_INFO, "Found the device matched, Index = %d, Port = %X, ParentIf = %X\n", Index, Port, RootIf)); + DEBUG ((DEBUG_INFO, "This is a USB 3 device and it need a longer waiting time for super speed.\n")); + gBS->Stall (USB_WAIT_PORT_STABLE_STALL); + } + } + } + Status = UsbHcClearRootHubPortFeature (Bus, Port, EfiUsbPortReset); if (EFI_ERROR (Status)) { From e59458b6582afd365c6b170ff442d87327fb6cfa Mon Sep 17 00:00:00 2001 From: Luigi Leonardi <leonardi@redhat.com> Date: Tue, 23 Jun 2026 15:34:41 +0200 Subject: [PATCH 274/406] OvmfPkg/MemDebugLogLib: Add MemDebugLogInit/Copy stubs to Null instance The Null instance of MemDebugLogLib only provides MemDebugLogWrite(), MemDebugLogPages(), and MemDebugLogEnabled(). Any module that references MemDebugLogInit() or MemDebugLogCopy() cannot link against the Null instance, forcing the feature to be gated at the build-system level rather than at runtime. Add no-op stubs for MemDebugLogInit() and MemDebugLogCopy(). This will be used by the following commit to add memory debug log support in TDX. Signed-off-by: Luigi Leonardi <leonardi@redhat.com> --- .../Library/MemDebugLogLib/MemDebugLogNull.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/OvmfPkg/Library/MemDebugLogLib/MemDebugLogNull.c b/OvmfPkg/Library/MemDebugLogLib/MemDebugLogNull.c index 59bb7c87a0..1fbcdce1fe 100644 --- a/OvmfPkg/Library/MemDebugLogLib/MemDebugLogNull.c +++ b/OvmfPkg/Library/MemDebugLogLib/MemDebugLogNull.c @@ -38,3 +38,23 @@ MemDebugLogEnabled ( { return FALSE; } + +EFI_STATUS +EFIAPI +MemDebugLogInit ( + IN EFI_PHYSICAL_ADDRESS MemDebugLogBufAddr, + IN UINT32 MemDebugLogBufSize + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +MemDebugLogCopy ( + IN EFI_PHYSICAL_ADDRESS MemDebugLogBufDestAddr, + IN EFI_PHYSICAL_ADDRESS MemDebugLogBufSrcAddr + ) +{ + return EFI_SUCCESS; +} From 35345c76a978f724f022a756aa47c847e61ffacc Mon Sep 17 00:00:00 2001 From: Luigi Leonardi <leonardi@redhat.com> Date: Mon, 22 Jun 2026 10:04:34 +0200 Subject: [PATCH 275/406] OvmfPkg/IntelTdx: Add memory debug logging support for TDX guests OVMF already supports MemDebugLogLib for capturing firmware debug output in a runtime memory buffer. Align the TDX peiless boot path with OVMF by integrating the same library, so that TDX guests can use memory-based debug logging. In PeilessStartupLib, allocate a runtime buffer for the debug log during PeilessStartup() and copy any early SEC-phase logs from the pre-allocated FDF region into it. Register the early debug log memory region in the TDX metadata as TEMP_MEM so the TDX module accepts it during guest initialization. Move PlatformDxe/Platform.inf from NCCFV to DXEFV because it exposes the memory debug log HOB to the guest. Signed-off-by: Luigi Leonardi <leonardi@redhat.com> --- OvmfPkg/IntelTdx/IntelTdxX64.dsc | 15 ++++ OvmfPkg/IntelTdx/IntelTdxX64.fdf | 8 +- .../PeilessStartupLib/PeilessStartup.c | 79 +++++++++++++++++++ .../PeilessStartupLib/PeilessStartupLib.inf | 8 ++ OvmfPkg/ResetVector/ResetVector.inf | 2 + OvmfPkg/ResetVector/ResetVector.nasmb | 3 + .../ResetVector/X64/IntelTdxMetadata.nasm.inc | 10 +++ 7 files changed, 124 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc index 4717d0c79d..be2ddacaac 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -30,6 +30,7 @@ # -D FLAG=VALUE # DEFINE SECURE_BOOT_ENABLE = FALSE + DEFINE DEBUG_TO_MEM = FALSE # # Shell can be useful for debugging but should not be enabled for production @@ -218,11 +219,18 @@ TdxLib|MdePkg/Library/TdxLib/TdxLib.inf TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLib.inf PlatformInitLib|OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +!if $(DEBUG_TO_MEM) + MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogDxeLib.inf +!else MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogLibNull.inf +!endif [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf +!if $(DEBUG_TO_MEM) + MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogSecLib.inf +!endif !ifdef $(DEBUG_ON_SERIAL_PORT) DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf !else @@ -271,6 +279,9 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf !endif UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf +!if $(DEBUG_TO_MEM) + MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogRtLib.inf +!endif BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf @@ -565,6 +576,7 @@ MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { <LibraryClasses> PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogLibNull.inf } MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf @@ -654,6 +666,9 @@ <LibraryClasses> DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf +!if $(DEBUG_TO_MEM) + MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogLibNull.inf +!endif } MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.fdf b/OvmfPkg/IntelTdx/IntelTdxX64.fdf index dfc2401631..53f2b51f62 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.fdf +++ b/OvmfPkg/IntelTdx/IntelTdxX64.fdf @@ -94,6 +94,11 @@ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase|gUefiOvmfPkgTokenSpaceGuid.PcdO 0x00E000|0x001000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize +!if $(DEBUG_TO_MEM) +0x00F000|0x001000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfEarlyMemDebugLogBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfEarlyMemDebugLogSize +!endif + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize @@ -263,6 +268,8 @@ INF MdeModulePkg/Universal/SmbiosMeasurementDxe/SmbiosMeasurementDxe.inf INF MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf +INF OvmfPkg/PlatformDxe/Platform.inf + ################################################################################ [FV.NCCFV] @@ -321,7 +328,6 @@ INF OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf INF OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf -INF OvmfPkg/PlatformDxe/Platform.inf !include OvmfPkg/Include/Fdf/ShellDxe.fdf.inc !include OvmfPkg/Include/Fdf/OvmfRngDxe.fdf.inc diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c index 170860f4f5..f3f164c119 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c @@ -21,8 +21,10 @@ #include <Library/PeilessStartupLib.h> #include <Library/PlatformInitLib.h> #include <Library/TdxHelperLib.h> +#include <Library/QemuFwCfgSimpleParserLib.h> #include <ConfidentialComputingGuestAttr.h> #include <Guid/MemoryTypeInformation.h> +#include <Library/MemDebugLogLib.h> #include <OvmfPlatforms.h> #include "PeilessStartupInternal.h" @@ -123,6 +125,79 @@ InitializePlatform ( return EFI_SUCCESS; } +STATIC +VOID +MemDebugLogSetup ( + VOID + ) +{ + UINT32 MemDebugLogBufPages; + VOID *Buffer; + MEM_DEBUG_LOG_HOB_DATA HobData; + EFI_STATUS Status; + + Status = QemuFwCfgParseUint32 ("opt/ovmf/MemDebugLogPages", TRUE, &MemDebugLogBufPages); + if (EFI_ERROR (Status)) { + MemDebugLogBufPages = FixedPcdGet32 (PcdMemDebugLogPages); + } + + if (MemDebugLogBufPages == 0) { + HobData.MemDebugLogBufAddr = 0; + BuildGuidDataHob (&gMemDebugLogHobGuid, &HobData, sizeof (HobData)); + return; + } + + if (MemDebugLogBufPages > MAX_MEM_DEBUG_LOG_PAGES) { + MemDebugLogBufPages = MAX_MEM_DEBUG_LOG_PAGES; + } + + Buffer = AllocateRuntimePages (MemDebugLogBufPages); + if (Buffer == NULL) { + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate Memory Debug Log buffer. Logging disabled\n", __func__)); + HobData.MemDebugLogBufAddr = 0; + BuildGuidDataHob (&gMemDebugLogHobGuid, &HobData, sizeof (HobData)); + return; + } + + Status = MemDebugLogInit ( + (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, + (UINT32)EFI_PAGES_TO_SIZE (MemDebugLogBufPages) + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: MemDebugLogInit failed: %r\n", __func__, Status)); + FreePages (Buffer, MemDebugLogBufPages); + HobData.MemDebugLogBufAddr = 0; + BuildGuidDataHob (&gMemDebugLogHobGuid, &HobData, sizeof (HobData)); + return; + } + + if (FixedPcdGet32 (PcdOvmfEarlyMemDebugLogBase) != 0) { + Status = MemDebugLogCopy ( + (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, + (EFI_PHYSICAL_ADDRESS)(UINTN)FixedPcdGet32 (PcdOvmfEarlyMemDebugLogBase) + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "%a: MemDebugLogCopy failed: %r\n", __func__, Status)); + } + + ZeroMem ( + (VOID *)(UINTN)FixedPcdGet32 (PcdOvmfEarlyMemDebugLogBase), + FixedPcdGet32 (PcdOvmfEarlyMemDebugLogSize) + ); + } + + HobData.MemDebugLogBufAddr = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer; + BuildGuidDataHob (&gMemDebugLogHobGuid, &HobData, sizeof (HobData)); + + DEBUG (( + DEBUG_INFO, + "%a: MemDebugLog buffer at 0x%lx, %d pages\n", + __func__, + (UINT64)(UINTN)Buffer, + MemDebugLogBufPages + )); +} + STATIC EFI_HOB_PLATFORM_INFO * BuildPlatformInfoHob ( @@ -215,6 +290,10 @@ PeilessStartup ( CpuDeadLoop (); } + if (MemDebugLogEnabled ()) { + MemDebugLogSetup (); + } + // // SecFV // diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf index 585d504637..7aa1bed3b3 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf @@ -55,7 +55,9 @@ MemoryAllocationLib PrePiLib QemuFwCfgLib + QemuFwCfgSimpleParserLib PlatformInitLib + MemDebugLogLib [Guids] gEfiHobMemoryAllocModuleGuid @@ -65,6 +67,7 @@ gPcdDataBaseHobGuid gCcEventEntryHobGuid gEfiNonCcFvGuid + gMemDebugLogHobGuid [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdBfvBase @@ -84,3 +87,8 @@ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdSecureBootSupported + +[FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdMemDebugLogPages + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfEarlyMemDebugLogBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfEarlyMemDebugLogSize diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/ResetVector.inf index e15dace7e3..a564872118 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -70,4 +70,6 @@ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfIgvmParamSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfIgvmHobBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfIgvmHobSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfEarlyMemDebugLogBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfEarlyMemDebugLogSize gEfiMdeModulePkgTokenSpaceGuid.PcdUse5LevelPageTable diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/ResetVector.nasmb index 1e19209f71..c54cbb470d 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -138,6 +138,9 @@ %define OVMF_PAGE_TABLE_BASE FixedPcdGet32 (PcdOvmfSecPageTablesBase) %define OVMF_PAGE_TABLE_SIZE FixedPcdGet32 (PcdOvmfSecPageTablesSize) + %define TDX_EARLY_DEBUG_LOG_BASE FixedPcdGet32 (PcdOvmfEarlyMemDebugLogBase) + %define TDX_EARLY_DEBUG_LOG_SIZE FixedPcdGet32 (PcdOvmfEarlyMemDebugLogSize) + %define TDX_WORK_AREA_PGTBL_READY (FixedPcdGet32 (PcdOvmfWorkAreaBase) + 4) %define TDX_WORK_AREA_GPAW (FixedPcdGet32 (PcdOvmfWorkAreaBase) + 8) diff --git a/OvmfPkg/ResetVector/X64/IntelTdxMetadata.nasm.inc b/OvmfPkg/ResetVector/X64/IntelTdxMetadata.nasm.inc index 07f89ef493..2fa1a9209b 100644 --- a/OvmfPkg/ResetVector/X64/IntelTdxMetadata.nasm.inc +++ b/OvmfPkg/ResetVector/X64/IntelTdxMetadata.nasm.inc @@ -111,5 +111,15 @@ _OvmfPageTable: DD TDX_METADATA_SECTION_TYPE_TEMP_MEM DD 0 +%if TDX_EARLY_DEBUG_LOG_SIZE != 0 +_EarlyDebugLog: + DD 0 + DD 0 + DQ TDX_EARLY_DEBUG_LOG_BASE + DQ TDX_EARLY_DEBUG_LOG_SIZE + DD TDX_METADATA_SECTION_TYPE_TEMP_MEM + DD 0 +%endif + TdxGuidedStructureEnd: ALIGN 16 From 2bdb08ab006a178305ee9da3883a30dda41290ae Mon Sep 17 00:00:00 2001 From: VarshitPandya <varshit.pandya@arm.com> Date: Tue, 21 Jul 2026 17:41:36 +0100 Subject: [PATCH 276/406] DynamicTablesPkg: Add Additional Information CM objects Add the Configuration Manager objects required to describe SMBIOS Additional Information (Type 40) structures. The top-level object references a list of Additional Information entries. Each entry identifies a field in an existing SMBIOS structure and references a typed value object containing the additional data. Define the maximum value buffer size from the SMBIOS Type 40 formatted length limit and add parsers for the new CM objects. Signed-off-by: Varshit Pandya <varshit.pandya@arm.com> --- .../Include/ArchCommonNameSpaceObjects.h | 73 +++++++++++++++++++ .../ConfigurationManagerObjectParser.c | 27 +++++++ 2 files changed, 100 insertions(+) diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index b6642bcad6..70837b15ba 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -34,6 +34,23 @@ // Maximum interleave ways is defined in the CXL spec section 8.2.4.19.7. #define CFMWS_MAX_INTERLEAVE_WAYS (16) +/** + Maximum number of Value bytes that can fit in a single-entry SMBIOS Type 40 + formatted structure. + + The SMBIOS formatted length is limited to MAX_UINT8. Five bytes are required + for the SMBIOS Type 40 header and NumberOfAdditionalInformationEntries, and + five bytes are required for the fixed portion of an Additional Information + Entry: + + MAX_UINT8 - 5 - 5 = 245 bytes. + + A Type 40 structure containing multiple entries may have a smaller effective + maximum per entry. The generator must therefore also validate the aggregate + formatted length. +**/ +#define SMBIOS_MAX_ADDITIONAL_INFORMATION_VALUE_SIZE 245 + /** The EARCH_COMMON_OBJECT_ID enum describes the Object IDs in the Arch Common Namespace */ @@ -107,6 +124,9 @@ typedef enum ArchCommonObjectID { EArchCommonObjMemoryChannelDevice, ///< 65 - Memory Channel Device Info EArchCommonObjProcessorSpecificBlockInfo, ///< 66 - Processor specific data Info EArchCommonObjSystemInfo, ///< 67 - System Info + EArchCommonObjAdditionalInformation, ///< 68 - Additional Information + EArchCommonObjAdditionalInformationEntry, ///< 69 - Additional Information Entry + EArchCommonObjAdditionalInformationValue, ///< 70 - Additional Information Value EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1763,4 +1783,57 @@ typedef struct CmArchCommonSystemInfo { CHAR8 Family[SMBIOS_MAX_STRING_SIZE]; } CM_ARCH_COMMON_SYSTEM_INFO; +/** A structure that describes SMBIOS Additional Information. + + SMBIOS Specification v3.9.0 Type 40 + + ID: EArchCommonObjAdditionalInformation +**/ +typedef struct CmArchCommonAdditionalInformation { + /// CM Object Token uniquely identifying this Additional Information structure. + CM_OBJECT_TOKEN AdditionalInformationToken; + + /// Token referencing an array of Additional Information Entry structures. + CM_OBJECT_TOKEN AdditionalInformationEntryListToken; +} CM_ARCH_COMMON_ADDITIONAL_INFORMATION; + +/** A structure that describes an Additional Information Entry. + + SMBIOS Specification v3.9.0 Type 40 + + ID: EArchCommonObjAdditionalInformationEntry +**/ +typedef struct CmArchCommonAdditionalInformationEntry { + /// CM Object Token of the SMBIOS structure referenced by this entry. + CM_OBJECT_TOKEN ReferencedObjectToken; + + /// SMBIOS table generator ID for the referenced structure. + /// Allows to find the handle of the Smbios table to update. + UINT32 ReferencedTableGeneratorId; + + /// Offset of the referenced field in the referenced SMBIOS structure. + UINT8 ReferencedOffset; + + /// String describing the additional information entry. + /// Optional for SMBIOS spec. update already proposed. + CHAR8 EntryString[SMBIOS_MAX_STRING_SIZE]; + + /// Token referencing an Additional Information Value structure. + CM_OBJECT_TOKEN ValueToken; +} CM_ARCH_COMMON_ADDITIONAL_INFORMATION_ENTRY; + +/** A structure that describes an Additional Information Value. + + SMBIOS Specification v3.9.0 Type 40 + + ID: EArchCommonObjAdditionalInformationValue +**/ +typedef struct CmArchCommonAdditionalInformationValue { + /// Number of valid bytes in the Value array. + UINT8 Len; + + /// Additional Information Value bytes. + UINT8 Value[SMBIOS_MAX_ADDITIONAL_INFORMATION_VALUE_SIZE]; +} CM_ARCH_COMMON_ADDITIONAL_INFORMATION_VALUE; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index 77b94121f3..45e2d9e46d 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -1248,6 +1248,30 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonMemoryChannelInfoParser[] = { { "MemoryDeviceListToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, }; +/** A parser for EArchCommonObjAdditionalInformation. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonAdditionalInformationParser[] = { + { "AdditionalInformationToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "AdditionalInformationEntryListToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, +}; + +/** A parser for EArchCommonObjAdditionalInformationEntry. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonAdditionalInformationEntryParser[] = { + { "ReferencedObjectToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "ReferencedTableGeneratorId", sizeof (UINT32), "0x%x", NULL }, + { "ReferencedOffset", sizeof (UINT8), "0x%x", NULL }, + { "EntryString", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "ValueToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, +}; + +/** A parser for EArchCommonObjAdditionalInformationValue. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonAdditionalInformationValueParser[] = { + { "Len", sizeof (UINT8), "0x%x", NULL }, + { "Value", SMBIOS_MAX_ADDITIONAL_INFORMATION_VALUE_SIZE, NULL, HexDump }, +}; + /** A parser for EArchCommonObjMemoryDeviceMappedAddress. */ STATIC CONST CM_OBJ_PARSER CmArchCommonMemoryDeviceMappedAddressParser[] = { @@ -1415,6 +1439,9 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArchCommonObjMemoryChannelDevice, CmArchCommonMemoryChannelDeviceParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjProcessorSpecificBlockInfo), CM_PARSER_ADD_OBJECT (EArchCommonObjSystemInfo, CmArchCommonSystemInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjAdditionalInformation, CmArchCommonAdditionalInformationParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjAdditionalInformationEntry, CmArchCommonAdditionalInformationEntryParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjAdditionalInformationValue, CmArchCommonAdditionalInformationValueParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; From b551e8bb32fa096cb985a0fa599995160474c8e9 Mon Sep 17 00:00:00 2001 From: VarshitPandya <varshit.pandya@arm.com> Date: Thu, 9 Jul 2026 14:20:10 +0100 Subject: [PATCH 277/406] DynamicTablesPkg: Smbios Additional Information (Type 40) Add a DynamicTables SMBIOS generator for the Additional Information (Type 40) structure. SMBIOS Type 40 provides additional information for fields in other SMBIOS structures. Each Type 40 entry references an existing SMBIOS record by handle and offset, provides an optional entry string, and carries a supplemental field value. The generator consumes one or more top-level CM objects, each referencing a list of Additional Information entries. Each entry provides: - the CM object token of the referenced SMBIOS structure, - the referenced table generator ID, - the offset of the referenced field, - an optional entry string, - a token to a typed Additional Information Value object. Example platform CM object layout: CM_ARCH_COMMON_ADDITIONAL_INFORMATION AdditionalInformation[] = { { REFERENCE_TOKEN (AdditionalInformation[0]), REFERENCE_TOKEN (AdditionalInformationEntry[0]) } }; CM_ARCH_COMMON_ADDITIONAL_INFORMATION_ENTRY AdditionalInformationEntry[] = { { REFERENCE_TOKEN (MemoryDeviceInfo[0]), CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType17), OFFSET_OF (SMBIOS_TABLE_TYPE17, MemoryType), "DIMM0 memory type", REFERENCE_TOKEN (AdditionalInformationValue[0]) } }; CM_ARCH_COMMON_ADDITIONAL_INFORMATION_VALUE AdditionalInformationValue[] = { { sizeof (UINT8), { MemoryTypeDram } } }; The generator resolves referenced SMBIOS handles using CM object tokens and table generator IDs. It validates the typed value objects, individual entry lengths, and aggregate formatted record size. The maximum accepted value length is controlled by PcdMaxAdditionalInformationValue. Build the variable-length Type 40 formatted area and append the entry strings to the SMBIOS string area. Signed-off-by: Varshit Pandya <varshit.pandya@arm.com> --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + DynamicTablesPkg/DynamicTablesPkg.dec | 3 + .../SmbiosType40Lib/SmbiosType40Generator.c | 758 ++++++++++++++++++ .../SmbiosType40Lib/SmbiosType40Lib.inf | 38 + 4 files changed, 801 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType40Lib/SmbiosType40Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType40Lib/SmbiosType40Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index ada6562661..2ea65fdabe 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -66,6 +66,7 @@ DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType40Lib/SmbiosType40Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Lib.inf # AML Fixup (Common) @@ -185,6 +186,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType28Lib/SmbiosType28Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType29Lib/SmbiosType29Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType37Lib/SmbiosType37Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType40Lib/SmbiosType40Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType44Lib/SmbiosType44Lib.inf } diff --git a/DynamicTablesPkg/DynamicTablesPkg.dec b/DynamicTablesPkg/DynamicTablesPkg.dec index 3aae6e92a2..322f922866 100644 --- a/DynamicTablesPkg/DynamicTablesPkg.dec +++ b/DynamicTablesPkg/DynamicTablesPkg.dec @@ -97,5 +97,8 @@ # Generate Tpm2 device table when generate TPM2 acpi table together. gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdGenTpm2DeviceTable|FALSE|BOOLEAN|0x4000000B + # Maximum number of Additional Information Value bytes used by SMBIOS Type 40. + gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdMaxAdditionalInformationValue|128|UINT8|0xC0000005 + [Guids] gEdkiiDynamicTablesPkgTokenSpaceGuid = { 0xab226e66, 0x31d8, 0x4613, { 0x87, 0x9d, 0xd2, 0xfa, 0xb6, 0x10, 0x26, 0x3c } } diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType40Lib/SmbiosType40Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType40Lib/SmbiosType40Generator.c new file mode 100644 index 0000000000..28124036b2 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType40Lib/SmbiosType40Generator.c @@ -0,0 +1,758 @@ +/** @file + SMBIOS Type40 Table Generator. + + Copyright (c) 2026, Arm Limited. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/SmbiosStringTableLib.h> + +// Module specific include files. +#include <ConfigurationManagerObject.h> +#include <ConfigurationManagerHelper.h> +#include <Protocol/ConfigurationManagerProtocol.h> +#include <Protocol/DynamicTableFactoryProtocol.h> +#include <IndustryStandard/SmBios.h> + +/** SMBIOS Type 40 Additional Information Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArchCommonObjAdditionalInformation + - EArchCommonObjAdditionalInformationEntry + - EArchCommonObjAdditionalInformationValue + + The Additional Information object provides the list of Type 40 entries. + Each Additional Information Entry references the SMBIOS structure field + being described and a value object containing the raw entry Value bytes. +*/ + +/** + This macro expands to a function that retrieves the Additional Information + object from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjAdditionalInformation, + CM_ARCH_COMMON_ADDITIONAL_INFORMATION + ); + +/** + This macro expands to a function that retrieves the Additional Information + Entry array from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjAdditionalInformationEntry, + CM_ARCH_COMMON_ADDITIONAL_INFORMATION_ENTRY + ); + +/** + This macro expands to a function that retrieves the Additional Information + Value bytes from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjAdditionalInformationValue, + CM_ARCH_COMMON_ADDITIONAL_INFORMATION_VALUE + ); + +/** + Ensure the platform-configured maximum value size is non-zero and does not + exceed the capacity of the Additional Information Value CM object. +*/ +STATIC_ASSERT ( + (FixedPcdGet8 (PcdMaxAdditionalInformationValue) > 0) && + (FixedPcdGet8 (PcdMaxAdditionalInformationValue) <= + SMBIOS_MAX_ADDITIONAL_INFORMATION_VALUE_SIZE), + "PcdMaxAdditionalInformationValue is invalid" + ); + +/** Validate an SMBIOS Type 40 CM object and calculate its record size. + + @param [in] TableFactoryProtocol Pointer to the SMBIOS table + factory protocol. + @param [in] CfgMgrProtocol Pointer to the Configuration + Manager Protocol interface. + @param [in] AdditionalInformation Pointer to the Additional + Information CM object. + @param [in] AdditionalInformationIndex Index of the Additional + Information CM object. + @param [out] AdditionalInformationEntry Pointer to the Additional + Information Entry CM objects. + @param [out] AdditionalInformationEntryCount Number of Additional + Information Entry CM objects. + @param [out] RecordSize Size of the formatted SMBIOS + Type 40 record. + + @retval EFI_SUCCESS The CM object is valid. + @retval EFI_INVALID_PARAMETER The CM object is invalid. + @retval EFI_NOT_FOUND A referenced SMBIOS handle is not found. + @retval Others Error returned by the Configuration Manager. +**/ +STATIC +EFI_STATUS +ValidateSmbiosType40Table ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *TableFactoryProtocol, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CfgMgrProtocol, + IN CONST CM_ARCH_COMMON_ADDITIONAL_INFORMATION *AdditionalInformation, + IN UINTN AdditionalInformationIndex, + OUT CM_ARCH_COMMON_ADDITIONAL_INFORMATION_ENTRY **AdditionalInformationEntry, + OUT UINT32 *AdditionalInformationEntryCount, + OUT UINTN *RecordSize + ) +{ + EFI_STATUS Status; + CM_ARCH_COMMON_ADDITIONAL_INFORMATION_VALUE *AdditionalInformationValue; + SMBIOS_HANDLE ReferencedHandle; + UINT32 AdditionalInformationValueCount; + UINTN EntryIndex; + UINTN EntryLength; + + if ((AdditionalInformation->AdditionalInformationToken == CM_NULL_TOKEN) || + (AdditionalInformation->AdditionalInformationEntryListToken == CM_NULL_TOKEN)) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid token for object %u\n", + __func__, + AdditionalInformationIndex + )); + return EFI_INVALID_PARAMETER; + } + + Status = GetEArchCommonObjAdditionalInformationEntry ( + CfgMgrProtocol, + AdditionalInformation->AdditionalInformationEntryListToken, + AdditionalInformationEntry, + AdditionalInformationEntryCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Additional Information Entry CM Object " + "for object %u. Status = %r\n", + __func__, + AdditionalInformationIndex, + Status + )); + return Status; + } + + if ((*AdditionalInformationEntryCount == 0) || + (*AdditionalInformationEntryCount > MAX_UINT8)) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Additional Information Entry count %u for object %u\n", + __func__, + *AdditionalInformationEntryCount, + AdditionalInformationIndex + )); + return EFI_INVALID_PARAMETER; + } + + *RecordSize = OFFSET_OF ( + SMBIOS_TABLE_TYPE40, + AdditionalInfoEntries + ); + + for (EntryIndex = 0; + EntryIndex < *AdditionalInformationEntryCount; + EntryIndex++) + { + if (((*AdditionalInformationEntry)[EntryIndex].ReferencedObjectToken == + CM_NULL_TOKEN) || + ((*AdditionalInformationEntry)[EntryIndex].ValueToken == CM_NULL_TOKEN)) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid token for Additional Information Entry %u\n", + __func__, + EntryIndex + )); + return EFI_INVALID_PARAMETER; + } + + ReferencedHandle = TableFactoryProtocol->GetSmbiosHandleEx ( + (*AdditionalInformationEntry)[EntryIndex].ReferencedTableGeneratorId, + (*AdditionalInformationEntry)[EntryIndex].ReferencedObjectToken + ); + if (ReferencedHandle == SMBIOS_HANDLE_INVALID) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to resolve referenced SMBIOS handle for Additional Information Entry %u\n", + __func__, + EntryIndex + )); + return EFI_NOT_FOUND; + } + + Status = GetEArchCommonObjAdditionalInformationValue ( + CfgMgrProtocol, + (*AdditionalInformationEntry)[EntryIndex].ValueToken, + &AdditionalInformationValue, + &AdditionalInformationValueCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Additional Information Value CM Object for Entry %u. Status = %r\n", + __func__, + EntryIndex, + Status + )); + return Status; + } + + if ((AdditionalInformationValue == NULL) || + (AdditionalInformationValueCount != 1) || + (AdditionalInformationValue->Len == 0) || + (AdditionalInformationValue->Len > + FixedPcdGet8 (PcdMaxAdditionalInformationValue))) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Additional Information Value for Entry %u\n", + __func__, + EntryIndex + )); + return EFI_INVALID_PARAMETER; + } + + EntryLength = OFFSET_OF (ADDITIONAL_INFORMATION_ENTRY, Value) + + AdditionalInformationValue->Len; + + if (EntryLength > MAX_UINT8) { + DEBUG (( + DEBUG_ERROR, + "%a: Additional Information Entry %u length %u exceeds SMBIOS Type 40 limit\n", + __func__, + EntryIndex, + EntryLength + )); + return EFI_INVALID_PARAMETER; + } + + *RecordSize += EntryLength; + } + + if (*RecordSize > MAX_UINT8) { + DEBUG (( + DEBUG_ERROR, + "%a: Type 40 record size %u exceeds SMBIOS header length limit\n", + __func__, + *RecordSize + )); + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** Construct SMBIOS Type 40 table describing Additional Information. + + If this function allocates any resources then they must be freed in + FreeSmbiosType40TableEx(). + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS table factory protocol. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to the generated SMBIOS table. + @param [out] CmObjectToken Pointer to the CM object token for the + generated SMBIOS table. + @param [out] TableCount Number of generated SMBIOS tables. + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Required CM object is not found. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +BuildSmbiosType40TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + CM_ARCH_COMMON_ADDITIONAL_INFORMATION *AdditionalInformation; + CM_ARCH_COMMON_ADDITIONAL_INFORMATION_ENTRY *AdditionalInformationEntry; + CM_ARCH_COMMON_ADDITIONAL_INFORMATION_VALUE *AdditionalInformationValue; + UINT32 AdditionalInformationCount; + UINT32 AdditionalInformationEntryCount; + UINT32 AdditionalInformationValueCount; + STRING_TABLE StrTable; + SMBIOS_STRUCTURE **TableList; + CM_OBJECT_TOKEN *CmObjectList; + SMBIOS_TABLE_TYPE40 *SmbiosRecord; + ADDITIONAL_INFORMATION_ENTRY *SmbiosEntry; + SMBIOS_TABLE_STRING *EntryStringRef; + SMBIOS_HANDLE ReferencedHandle; + UINTN EntryLength; + UINTN RecordSize; + UINTN StringAreaSize; + UINTN TableIndex; + UINTN EntryIndex; + BOOLEAN StrTableInitialized; + + AdditionalInformation = NULL; + AdditionalInformationEntry = NULL; + AdditionalInformationValue = NULL; + AdditionalInformationCount = 0; + AdditionalInformationEntryCount = 0; + AdditionalInformationValueCount = 0; + TableList = NULL; + CmObjectList = NULL; + SmbiosRecord = NULL; + SmbiosEntry = NULL; + EntryStringRef = NULL; + RecordSize = 0; + StringAreaSize = 0; + StrTableInitialized = FALSE; + + ASSERT (This != NULL); + ASSERT (TableFactoryProtocol != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Table != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (TableFactoryProtocol == NULL) || + (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL) || + (TableCount == NULL)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + if (SmbiosTableInfo->TableGeneratorId != This->GeneratorID) { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Generator ID. Expected 0x%x, got 0x%x\n", + __func__, + This->GeneratorID, + SmbiosTableInfo->TableGeneratorId + )); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + *CmObjectToken = NULL; + *TableCount = 0; + + Status = GetEArchCommonObjAdditionalInformation ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &AdditionalInformation, + &AdditionalInformationCount + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Additional Information CM Object. Status = %r\n", + __func__, + Status + )); + return Status; + } + + if (AdditionalInformationCount == 0) { + DEBUG (( + DEBUG_ERROR, + "%a: No Additional Information CM Objects found\n", + __func__ + )); + return EFI_NOT_FOUND; + } + + TableList = AllocateZeroPool ( + sizeof (SMBIOS_STRUCTURE *) * + AdditionalInformationCount + ); + if (TableList == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType40TableEx; + } + + CmObjectList = AllocateZeroPool ( + sizeof (CM_OBJECT_TOKEN) * + AdditionalInformationCount + ); + if (CmObjectList == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType40TableEx; + } + + for (TableIndex = 0; + TableIndex < AdditionalInformationCount; + TableIndex++) + { + AdditionalInformationEntry = NULL; + AdditionalInformationValue = NULL; + AdditionalInformationEntryCount = 0; + AdditionalInformationValueCount = 0; + SmbiosRecord = NULL; + SmbiosEntry = NULL; + EntryStringRef = NULL; + RecordSize = 0; + StringAreaSize = 0; + StrTableInitialized = FALSE; + + Status = ValidateSmbiosType40Table ( + TableFactoryProtocol, + CfgMgrProtocol, + &AdditionalInformation[TableIndex], + TableIndex, + &AdditionalInformationEntry, + &AdditionalInformationEntryCount, + &RecordSize + ); + if (EFI_ERROR (Status)) { + goto exitBuildSmbiosType40TableEx; + } + + Status = StringTableInitialize ( + &StrTable, + AdditionalInformationEntryCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to initialise Type 40 string table for object %u. " + "Status = %r\n", + __func__, + TableIndex, + Status + )); + goto exitBuildSmbiosType40TableEx; + } + + StrTableInitialized = TRUE; + + EntryStringRef = AllocateZeroPool ( + sizeof (SMBIOS_TABLE_STRING) * + AdditionalInformationEntryCount + ); + if (EntryStringRef == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType40TableEx; + } + + for (EntryIndex = 0; + EntryIndex < AdditionalInformationEntryCount; + EntryIndex++) + { + if (AdditionalInformationEntry[EntryIndex].EntryString[0] != '\0') { + Status = StringTableAddString ( + &StrTable, + AdditionalInformationEntry[EntryIndex].EntryString, + &EntryStringRef[EntryIndex] + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to add EntryString for Additional Information Entry %u. Status = %r\n", + __func__, + EntryIndex, + Status + )); + goto exitBuildSmbiosType40TableEx; + } + } + } + + SmbiosRecord = (SMBIOS_TABLE_TYPE40 *)AllocateSmbiosRecord ( + RecordSize, + &StrTable + ); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType40TableEx; + } + + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_ADDITIONAL_INFORMATION; + SmbiosRecord->Hdr.Length = (UINT8)RecordSize; + SmbiosRecord->Hdr.Handle = SMBIOS_HANDLE_PI_RESERVED; + SmbiosRecord->NumberOfAdditionalInformationEntries = + (UINT8)AdditionalInformationEntryCount; + + SmbiosEntry = SmbiosRecord->AdditionalInfoEntries; + + for (EntryIndex = 0; + EntryIndex < AdditionalInformationEntryCount; + EntryIndex++) + { + AdditionalInformationValue = NULL; + AdditionalInformationValueCount = 0; + + Status = GetEArchCommonObjAdditionalInformationValue ( + CfgMgrProtocol, + AdditionalInformationEntry[EntryIndex].ValueToken, + &AdditionalInformationValue, + &AdditionalInformationValueCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Additional Information Value CM Object for Entry %u. Status = %r\n", + __func__, + EntryIndex, + Status + )); + goto exitBuildSmbiosType40TableEx; + } + + if ((AdditionalInformationValue == NULL) || + (AdditionalInformationValueCount != 1)) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Additional Information Value CM Object for Entry %u\n", + __func__, + EntryIndex + )); + Status = EFI_INVALID_PARAMETER; + goto exitBuildSmbiosType40TableEx; + } + + ReferencedHandle = TableFactoryProtocol->GetSmbiosHandleEx ( + AdditionalInformationEntry[EntryIndex].ReferencedTableGeneratorId, + AdditionalInformationEntry[EntryIndex].ReferencedObjectToken + ); + + EntryLength = OFFSET_OF (ADDITIONAL_INFORMATION_ENTRY, Value) + + AdditionalInformationValue->Len; + + SmbiosEntry->EntryLength = (UINT8)EntryLength; + SmbiosEntry->ReferencedHandle = ReferencedHandle; + SmbiosEntry->ReferencedOffset = + AdditionalInformationEntry[EntryIndex].ReferencedOffset; + SmbiosEntry->EntryString = EntryStringRef[EntryIndex]; + + CopyMem ( + SmbiosEntry->Value, + AdditionalInformationValue->Value, + AdditionalInformationValue->Len + ); + + SmbiosEntry = (ADDITIONAL_INFORMATION_ENTRY *)( + (UINT8 *)SmbiosEntry + EntryLength + ); + } + + StringAreaSize = StringTableGetStringSetSize (&StrTable); + + Status = StringTablePublishStringSet ( + &StrTable, + (CHAR8 *)SmbiosRecord + RecordSize, + StringAreaSize + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to publish Type 40 string set. Status = %r\n", + __func__, + Status + )); + goto exitBuildSmbiosType40TableEx; + } + + TableList[TableIndex] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[TableIndex] = + AdditionalInformation[TableIndex].AdditionalInformationToken; + + SmbiosRecord = NULL; + + if (StrTableInitialized) { + StringTableFree (&StrTable); + StrTableInitialized = FALSE; + } + + if (EntryStringRef != NULL) { + FreePool (EntryStringRef); + EntryStringRef = NULL; + } + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = AdditionalInformationCount; + Status = EFI_SUCCESS; + +exitBuildSmbiosType40TableEx: + if (StrTableInitialized) { + StringTableFree (&StrTable); + } + + if (EntryStringRef != NULL) { + FreePool (EntryStringRef); + } + + if (EFI_ERROR (Status)) { + if (TableList != NULL) { + for (TableIndex = 0; + TableIndex < AdditionalInformationCount; + TableIndex++) + { + if (TableList[TableIndex] != NULL) { + FreePool (TableList[TableIndex]); + } + } + + FreePool (TableList); + } + + if (CmObjectList != NULL) { + FreePool (CmObjectList); + } + + if (SmbiosRecord != NULL) { + FreePool (SmbiosRecord); + } + } + + return Status; +} + +/** Free any resources allocated for constructing SMBIOS Type 40 table. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS table factory + protocol. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the SMBIOS table. + @param [in] CmObjectToken Pointer to the CM object token. + @param [in] TableCount Number of generated SMBIOS tables. + + @retval EFI_SUCCESS Resources freed successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +FreeSmbiosType40TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + + if ((This == NULL) || (TableFactoryProtocol == NULL) || + (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + if (*Table != NULL) { + for (Index = 0; Index < TableCount; Index++) { + if ((*Table)[Index] != NULL) { + FreePool ((*Table)[Index]); + } + } + + FreePool (*Table); + *Table = NULL; + } + + if (*CmObjectToken != NULL) { + FreePool (*CmObjectToken); + *CmObjectToken = NULL; + } + + return EFI_SUCCESS; +} + +/** The SMBIOS Type 40 Table Generator. +*/ +STATIC CONST SMBIOS_TABLE_GENERATOR SmbiosType40Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType40), + // Generator Description + L"SMBIOS.TYPE40.GENERATOR", + // SMBIOS structure type + SMBIOS_TYPE_ADDITIONAL_INFORMATION, + NULL, + NULL, + // Build table function. + BuildSmbiosType40TableEx, + // Free function. + FreeSmbiosType40TableEx +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType40LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType40Generator); + DEBUG ((DEBUG_INFO, "SMBIOS Type 40: Register Generator. Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType40LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType40Generator); + DEBUG ((DEBUG_INFO, "SMBIOS Type 40: Deregister Generator. Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType40Lib/SmbiosType40Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType40Lib/SmbiosType40Lib.inf new file mode 100644 index 0000000000..63f727c424 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType40Lib/SmbiosType40Lib.inf @@ -0,0 +1,38 @@ +## @file +# SMBIOS Type40 Table Generator. +# +# Copyright (c) 2026, Arm Limited. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType40LibArm + FILE_GUID = aae7f4ca-f8f5-460a-b0fa-91a478f273d4 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType40LibConstructor + DESTRUCTOR = SmbiosType40LibDestructor + +[Sources] + SmbiosType40Generator.c + +[Packages] + DynamicTablesPkg/DynamicTablesPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + SmbiosStringTableLib + +[Protocols] + gEdkiiConfigurationManagerProtocolGuid + gEdkiiDynamicTableFactoryProtocolGuid + +[FixedPcd] + gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdMaxAdditionalInformationValue From 27ac8fac0b61e6b464369cc1cadc66a7b83336c4 Mon Sep 17 00:00:00 2001 From: Chris Fernald <chfernal@microsoft.com> Date: Fri, 16 Jan 2026 09:30:45 -0800 Subject: [PATCH 278/406] BaseTools: Add support for preserving build ID Adds an optional flag that copies the GNU build-id note from the input ELF file into the output PE/COFF firmware image as a dedicated ".bldid" section. The build ID is emitted by the linker as a unique fingerprint of the binary and allows custom post-build and debugging tools to reliably match a firmware image against its corresponding unstripped ELF and debug symbols, without relying on file names, timestamps, or build paths. This notable opts to use a non-standard section name ".bldid" to store the build ID. This approach was chosen to keep genfw and the parsers simple since the full "build-id" name would require redirecting the section name. While this breaks from standard conventions, this is not impactful since GenFW is already creating a non-standard artifact for the PE image with the associated ELF symbol file. Signed-off-by: Chris Fernald <chfernal@microsoft.com> --- BaseTools/Source/C/GenFw/Elf64Convert.c | 88 ++++++++++++++++++++++++- BaseTools/Source/C/GenFw/ElfConvert.c | 5 ++ BaseTools/Source/C/GenFw/ElfConvert.h | 13 ++-- BaseTools/Source/C/GenFw/GenFw.c | 12 ++++ 4 files changed, 110 insertions(+), 8 deletions(-) diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c index f6398cb2b2..1208137bca 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -130,6 +130,8 @@ STATIC UINT32 mHiiRsrcOffset; STATIC UINT32 mRelocOffset; STATIC UINT32 mDebugOffset; STATIC UINT32 mExportOffset; +STATIC UINT32 mBuildIdOffset; +STATIC BOOLEAN mBuildIdFound; // // Used for RISC-V relocations. // @@ -227,6 +229,10 @@ InitializeElf64 ( ElfFunctions->WriteExport = WriteExport64; } + if (mBuildIdFlag) { + mCoffNbrSections++; + } + return TRUE; } @@ -290,6 +296,22 @@ IsHiiRsrcShdr ( return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namedr->sh_offset + Shdr->sh_name, ELF_HII_SECTION_NAME) == 0); } +STATIC +BOOLEAN +IsBuildIdShdr ( + Elf_Shdr *Shdr + ) +{ + Elf_Shdr *Namedr = GetShdrByIndex(mEhdr->e_shstrndx); + + if (Namedr->sh_offset + Shdr->sh_name >= mFileBufferSize) { + Error (NULL, 0, 3000, "Invalid", "IsBuildIdShdr: Name offset %lu is larger then file size %lu", mEhdr->e_shstrndx, mFileBufferSize); + exit(EXIT_FAILURE); + } + + return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namedr->sh_offset + Shdr->sh_name, ELF_BUILD_ID_SECTION_NAME) == 0); +} + STATIC BOOLEAN IsSymbolShdr ( @@ -1123,6 +1145,40 @@ ScanSections64 ( } } + // + // The build-ID section. + // + mBuildIdOffset = mCoffOffset; + mBuildIdFound = FALSE; + if (mBuildIdFlag) { + for (i = 0; i < mEhdr->e_shnum; i++) { + Elf_Shdr *shdr = GetShdrByIndex(i); + if (IsBuildIdShdr(shdr)) { + if ((shdr->sh_addralign != 0) && (shdr->sh_addralign != 1)) { + // the alignment field is valid + if ((shdr->sh_addr & (shdr->sh_addralign - 1)) == 0) { + // if the section address is aligned we must align PE/COFF + mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1)); + } else { + Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment."); + } + } + if (shdr->sh_size != 0) { + mBuildIdOffset = mCoffOffset; + mCoffSectionsOffset[i] = mCoffOffset; + mCoffOffset += (UINT32) shdr->sh_size; + mCoffOffset = CoffAlign(mCoffOffset); + mBuildIdFound = TRUE; + } + break; + } + } + + if (!mBuildIdFound) { + Warning (NULL, 0, 0, NULL, "Build ID section is not found in %s.", mInImageName); + } + } + mRelocOffset = mCoffOffset; // @@ -1242,18 +1298,41 @@ ScanSections64 ( } } - if ((mRelocOffset - mHiiRsrcOffset) > 0) { - CreateSectionHeader (".rsrc", mHiiRsrcOffset, mRelocOffset - mHiiRsrcOffset, + // + // Determine the end offset for .rsrc section based on whether build-ID is present + // + if (mBuildIdFound) { + Offset = mBuildIdOffset; + } else { + Offset = mRelocOffset; + } + + if ((Offset - mHiiRsrcOffset) > 0) { + CreateSectionHeader (".rsrc", mHiiRsrcOffset, Offset - mHiiRsrcOffset, EFI_IMAGE_SCN_CNT_INITIALIZED_DATA | EFI_IMAGE_SCN_MEM_READ); - NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = mRelocOffset - mHiiRsrcOffset; + NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = Offset - mHiiRsrcOffset; NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = mHiiRsrcOffset; } else { // Don't make a section of size 0. NtHdr->Pe32Plus.FileHeader.NumberOfSections--; } + // + // Add build-ID section if requested and found + // + if (mBuildIdFlag) { + if (mBuildIdFound) { + CreateSectionHeader (".bldid", mBuildIdOffset, mRelocOffset - mBuildIdOffset, + EFI_IMAGE_SCN_CNT_INITIALIZED_DATA + | EFI_IMAGE_SCN_MEM_READ); + } else { + // Don't make a section of size 0, decrement the section count + NtHdr->Pe32Plus.FileHeader.NumberOfSections--; + } + } + } STATIC @@ -1281,6 +1360,9 @@ WriteSections64 ( case SECTION_DATA: Filter = IsDataShdr; break; + case SECTION_BUILD_ID: + Filter = IsBuildIdShdr; + break; default: return FALSE; } diff --git a/BaseTools/Source/C/GenFw/ElfConvert.c b/BaseTools/Source/C/GenFw/ElfConvert.c index d6d9feb7d8..9a42f5d530 100644 --- a/BaseTools/Source/C/GenFw/ElfConvert.c +++ b/BaseTools/Source/C/GenFw/ElfConvert.c @@ -210,6 +210,11 @@ ConvertElf ( if (!ElfFunctions.WriteSections (SECTION_HII)) { return FALSE; } + if (mBuildIdFlag) { + if (!ElfFunctions.WriteSections (SECTION_BUILD_ID)) { + return FALSE; + } + } // // Translate and write relocations. diff --git a/BaseTools/Source/C/GenFw/ElfConvert.h b/BaseTools/Source/C/GenFw/ElfConvert.h index a4dadc6624..d570461f7c 100644 --- a/BaseTools/Source/C/GenFw/ElfConvert.h +++ b/BaseTools/Source/C/GenFw/ElfConvert.h @@ -24,14 +24,16 @@ extern UINT32 mTableOffset; extern UINT32 mOutImageType; extern UINT32 mFileBufferSize; extern BOOLEAN mExportFlag; +extern BOOLEAN mBuildIdFlag; // // Common EFI specific data. // -#define ELF_HII_SECTION_NAME ".hii" -#define ELF_STRTAB_SECTION_NAME ".strtab" -#define MAX_COFF_ALIGNMENT 0x10000 -#define ELF_SYMBOL_SECTION_NAME ".symtab" +#define ELF_HII_SECTION_NAME ".hii" +#define ELF_STRTAB_SECTION_NAME ".strtab" +#define MAX_COFF_ALIGNMENT 0x10000 +#define ELF_SYMBOL_SECTION_NAME ".symtab" +#define ELF_BUILD_ID_SECTION_NAME ".build-id" // // Platform Runtime Mechanism (PRM) specific data. @@ -77,7 +79,8 @@ typedef enum { SECTION_TEXT, SECTION_HII, SECTION_DATA, - SECTION_SYMBOL + SECTION_SYMBOL, + SECTION_BUILD_ID } SECTION_FILTER_TYPES; // diff --git a/BaseTools/Source/C/GenFw/GenFw.c b/BaseTools/Source/C/GenFw/GenFw.c index 51c8c80e8b..a8f4076b35 100644 --- a/BaseTools/Source/C/GenFw/GenFw.c +++ b/BaseTools/Source/C/GenFw/GenFw.c @@ -89,6 +89,7 @@ UINT32 mOutImageType = FW_DUMMY_IMAGE; BOOLEAN mIsConvertXip = FALSE; BOOLEAN mExportFlag = FALSE; BOOLEAN mNoNxCompat = FALSE; +BOOLEAN mBuildIdFlag = FALSE; STATIC EFI_STATUS @@ -290,6 +291,10 @@ Returns: fprintf (stdout, " --nonxcompat Do not set the IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit \n\ of the optional header in the PE header even if the \n\ requirements are met.\n"); + fprintf (stdout, " --build-id Preserve the .build-id section from the ELF image\n\ + and copy it to a .bldid section in the PE image.\n\ + This option can be used together with -e or -t.\n\ + It doesn't work for other options.\n"); fprintf (stdout, " -v, --verbose Turn on verbose output with informational messages.\n"); fprintf (stdout, " -q, --quiet Disable all messages except key message and fatal error\n"); fprintf (stdout, " -d, --debug level Enable debug messages, at input debug level.\n"); @@ -1576,6 +1581,13 @@ Returns: continue; } + if (stricmp (argv[0], "--build-id") == 0) { + mBuildIdFlag = TRUE; + argc--; + argv++; + continue; + } + if (argv[0][0] == '-') { Error (NULL, 0, 1000, "Unknown option", argv[0]); goto Finish; From 1d8239c4fc8434babb91ae1355ef07aa6a0d073a Mon Sep 17 00:00:00 2001 From: Girish Mahadevan <gmahadevan@nvidia.com> Date: Sat, 11 Jul 2026 16:20:13 +0000 Subject: [PATCH 279/406] DynamicTablesPkg: Add System Enclosure CM object and parser Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com> --- .../Include/ArchCommonNameSpaceObjects.h | 65 ++++++++++++++++++- .../ConfigurationManagerObjectParser.c | 34 +++++++++- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index 70837b15ba..165fe73d1a 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -1,7 +1,7 @@ /** @file Copyright (c) 2024 - 2026, Arm Limited. All rights reserved.<BR> - Copyright (c) 2024 - 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR> + Copyright (c) 2024 - 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR> Copyright (C) 2024 - 2025, Advanced Micro Devices, Inc. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent @@ -127,6 +127,8 @@ typedef enum ArchCommonObjectID { EArchCommonObjAdditionalInformation, ///< 68 - Additional Information EArchCommonObjAdditionalInformationEntry, ///< 69 - Additional Information Entry EArchCommonObjAdditionalInformationValue, ///< 70 - Additional Information Value + EArchCommonObjSystemEnclosureInfo, ///< 71 - System Enclosure Info + EArchCommonObjEnclosureElement, ///< 72 - System Enclosure Contained Element EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1836,4 +1838,65 @@ typedef struct CmArchCommonAdditionalInformationValue { UINT8 Value[SMBIOS_MAX_ADDITIONAL_INFORMATION_VALUE_SIZE]; } CM_ARCH_COMMON_ADDITIONAL_INFORMATION_VALUE; +/** A structure that describes a System Enclosure Contained Element. + + SMBIOS Specification v3.9.0 Type 3 + + ID: EArchCommonObjEnclosureElement +**/ +typedef struct CmArchCommonEnclosureElement { + /// The contained element type. + UINT8 ContainedElementType; + + /// Minimum number of the element type required for proper operation. + UINT8 ContainedElementMinimum; + + /// Maximum number of the element type that can be installed. + UINT8 ContainedElementMaximum; +} CM_ARCH_COMMON_ENCLOSURE_ELEMENT; + +/** A structure that describes System Enclosure Information. + + SMBIOS Specification v3.9.0 Type 3 + + ID: EArchCommonObjSystemEnclosureInfo +**/ +typedef struct CmArchCommonSystemEnclosureInfo { + /// CM Object Token uniquely identifying this System Enclosure entry. + CM_OBJECT_TOKEN SystemEnclosureToken; + /// Manufacturer of the enclosure. + CHAR8 Manufacturer[SMBIOS_MAX_STRING_SIZE]; + /// Chassis type with the lock-present bit in bit 7. + UINT8 Type; + /// Version of the enclosure. + CHAR8 Version[SMBIOS_MAX_STRING_SIZE]; + /// Serial number of the enclosure. + CHAR8 SerialNum[SMBIOS_MAX_STRING_SIZE]; + /// Asset tag of the enclosure. + CHAR8 AssetTag[SMBIOS_MAX_STRING_SIZE]; + /// Boot-up state as defined by SMBIOS Type 3. + UINT8 BootUpState; + /// Power supply state as defined by SMBIOS Type 3. + UINT8 PowerSupplyState; + /// Thermal state as defined by SMBIOS Type 3. + UINT8 ThermalState; + /// Security status as defined by SMBIOS Type 3. + UINT8 SecurityStatus; + /// OEM-defined value. + UINT32 OemDefined; + /// Height of the enclosure in rack units. + UINT8 Height; + /// Number of power cords associated with the enclosure. + UINT8 NumberOfPowerCords; + /// Token referencing an array of System Enclosure Contained Elements. + /// CM_NULL_TOKEN indicates that no contained elements are supplied. + CM_OBJECT_TOKEN ContainedElementListToken; + /// SKU number of the enclosure. + CHAR8 SkuNum[SMBIOS_MAX_STRING_SIZE]; + /// Rack type as defined by SMBIOS Type 3. + UINT8 RackType; + /// Rack height in rack units when Height is 0xFF. + UINT8 RackHeight; +} CM_ARCH_COMMON_SYSTEM_ENCLOSURE_INFO; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index 45e2d9e46d..d1f08ea26a 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -3,7 +3,7 @@ Copyright (c) 2021 - 2026, ARM Limited. All rights reserved.<BR> Copyright (C) 2024 - 2025 Advanced Micro Devices, Inc. All rights reserved. - Copyright (c) 2024 - 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR> + Copyright (c) 2024 - 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -1367,6 +1367,36 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonSystemInfoParser[] = { { "Family", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, }; +/** A parser for EArchCommonObjSystemEnclosureInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonSystemEnclosureInfoParser[] = { + { "SystemEnclosureToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "Manufacturer", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "Type", sizeof (UINT8), "0x%x", NULL }, + { "Version", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "SerialNum", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "AssetTag", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "BootUpState", sizeof (UINT8), "0x%x", NULL }, + { "PowerSupplyState", sizeof (UINT8), "0x%x", NULL }, + { "ThermalState", sizeof (UINT8), "0x%x", NULL }, + { "SecurityStatus", sizeof (UINT8), "0x%x", NULL }, + { "OemDefined", sizeof (UINT32), "0x%x", NULL }, + { "Height", sizeof (UINT8), "0x%x", NULL }, + { "NumberOfPowerCords", sizeof (UINT8), "0x%x", NULL }, + { "ContainedElementListToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "SkuNum", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "RackType", sizeof (UINT8), "0x%x", NULL }, + { "RackHeight", sizeof (UINT8), "0x%x", NULL }, +}; + +/** A parser for EArchCommonObjEnclosureElement. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonEnclosureElementParser[] = { + { "ContainedElementType", sizeof (UINT8), "0x%x", NULL }, + { "ContainedElementMinimum", sizeof (UINT8), "%u", NULL }, + { "ContainedElementMaximum", sizeof (UINT8), "%u", NULL }, +}; + /** A parser for Arch Common namespace objects. */ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { @@ -1442,6 +1472,8 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArchCommonObjAdditionalInformation, CmArchCommonAdditionalInformationParser), CM_PARSER_ADD_OBJECT (EArchCommonObjAdditionalInformationEntry, CmArchCommonAdditionalInformationEntryParser), CM_PARSER_ADD_OBJECT (EArchCommonObjAdditionalInformationValue, CmArchCommonAdditionalInformationValueParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjSystemEnclosureInfo, CmArchCommonSystemEnclosureInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjEnclosureElement, CmArchCommonEnclosureElementParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; From f246d215eada6bb9fa7abc81c6aed2b49732f51a Mon Sep 17 00:00:00 2001 From: Girish Mahadevan <gmahadevan@nvidia.com> Date: Sat, 11 Jul 2026 17:39:02 +0000 Subject: [PATCH 280/406] DynamicTablesPkg: Smbios System Enclosure (Type 3) Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com> --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../SmbiosType3Lib/SmbiosType3Generator.c | 601 ++++++++++++++++++ .../Smbios/SmbiosType3Lib/SmbiosType3Lib.inf | 30 + 3 files changed, 633 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index 2ea65fdabe..c71abe57a6 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -54,6 +54,7 @@ # SMBIOS Generators (Common) DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf @@ -174,6 +175,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Generator.c new file mode 100644 index 0000000000..47b1910c11 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Generator.c @@ -0,0 +1,601 @@ +/** @file + SMBIOS Type 3 System Enclosure Table Generator. + + Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/SmbiosStringTableLib.h> + +#include <ConfigurationManagerObject.h> +#include <ConfigurationManagerHelper.h> +#include <Protocol/ConfigurationManagerProtocol.h> +#include <Protocol/DynamicTableFactoryProtocol.h> +#include <IndustryStandard/SmBios.h> + +#define SMBIOS_TYPE3_MAX_STRINGS 5 +#define SMBIOS_TYPE3_CHASSIS_TYPE_MASK 0x7F +#define SMBIOS_TYPE3_CONTAINED_ELEMENT_TYPE_SELECT BIT7 +#define SMBIOS_TYPE3_CONTAINED_ELEMENT_TYPE_MASK 0x7F +#define SMBIOS_TYPE3_CONTAINED_ELEMENT_RECORD_LENGTH 3 +#define SMBIOS_TYPE3_TRAILING_FIELD_LENGTH 3 +#define SMBIOS_TYPE3_BASE_LENGTH \ + (OFFSET_OF (SMBIOS_TABLE_TYPE3, ContainedElements) + SMBIOS_TYPE3_TRAILING_FIELD_LENGTH) + +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjSystemEnclosureInfo, + CM_ARCH_COMMON_SYSTEM_ENCLOSURE_INFO + ); + +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjEnclosureElement, + CM_ARCH_COMMON_ENCLOSURE_ELEMENT + ); + +/** Validate System Enclosure Contained Element CM objects. + + @param [in] ContainedElement Contained Element objects to validate. + @param [in] ContainedElementCount Number of Contained Element objects. + + @retval EFI_SUCCESS The Contained Element objects are valid. + @retval EFI_INVALID_PARAMETER A Contained Element object is invalid. +**/ +STATIC +EFI_STATUS +ValidateSystemEnclosureContainedElements ( + IN CONST CM_ARCH_COMMON_ENCLOSURE_ELEMENT *ContainedElement, + IN UINT32 ContainedElementCount + ) +{ + UINT32 Index; + UINT8 ElementType; + + for (Index = 0; Index < ContainedElementCount; Index++) { + ElementType = ContainedElement[Index].ContainedElementType & + SMBIOS_TYPE3_CONTAINED_ELEMENT_TYPE_MASK; + + if (((ContainedElement[Index].ContainedElementType & + SMBIOS_TYPE3_CONTAINED_ELEMENT_TYPE_SELECT) == 0) && + ((ElementType < BaseBoardTypeUnknown) || + (ElementType > BaseBoardTypeInterconnectBoard))) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid Baseboard Type 0x%x for Contained Element %u\n", + __func__, + ElementType, + Index + )); + return EFI_INVALID_PARAMETER; + } + + // When bit 7 is set, bits 6:0 identify an SMBIOS structure type. + // Type 127 is the end-of-table marker and cannot represent a device. + if (((ContainedElement[Index].ContainedElementType & + SMBIOS_TYPE3_CONTAINED_ELEMENT_TYPE_SELECT) != 0) && + (ElementType > EFI_SMBIOS_TYPE_INACTIVE)) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid SMBIOS Type 0x%x for Contained Element %u\n", + __func__, + ElementType, + Index + )); + return EFI_INVALID_PARAMETER; + } + + if ((ContainedElement[Index].ContainedElementMinimum == MAX_UINT8) || + (ContainedElement[Index].ContainedElementMaximum == 0) || + (ContainedElement[Index].ContainedElementMinimum > + ContainedElement[Index].ContainedElementMaximum)) + { + DEBUG (( + DEBUG_ERROR, + "%a: Invalid quantity range %u-%u for Contained Element %u\n", + __func__, + ContainedElement[Index].ContainedElementMinimum, + ContainedElement[Index].ContainedElementMaximum, + Index + )); + return EFI_INVALID_PARAMETER; + } + } + + return EFI_SUCCESS; +} + +/** Validate a System Enclosure CM object. + + @param [in] EnclosureInfo System Enclosure information to validate. + + @retval EFI_SUCCESS The System Enclosure information is valid. + @retval EFI_INVALID_PARAMETER The System Enclosure information is invalid. +**/ +STATIC +EFI_STATUS +ValidateSystemEnclosureInfo ( + IN CONST CM_ARCH_COMMON_SYSTEM_ENCLOSURE_INFO *EnclosureInfo + ) +{ + UINT8 ChassisType; + + if (EnclosureInfo->Manufacturer[0] == '\0') { + DEBUG ((DEBUG_ERROR, "%a: Manufacturer must be non-empty\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + ChassisType = EnclosureInfo->Type & SMBIOS_TYPE3_CHASSIS_TYPE_MASK; + if ((ChassisType < MiscChassisTypeOther) || + (ChassisType == MiscChassisTypeUnknown) || + (ChassisType > MiscChassisStickPc)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid chassis Type 0x%x\n", __func__, EnclosureInfo->Type)); + return EFI_INVALID_PARAMETER; + } + + if ((EnclosureInfo->BootUpState < ChassisStateOther) || + (EnclosureInfo->BootUpState > ChassisStateNonRecoverable) || + (EnclosureInfo->PowerSupplyState < ChassisStateOther) || + (EnclosureInfo->PowerSupplyState > ChassisStateNonRecoverable) || + (EnclosureInfo->ThermalState < ChassisStateOther) || + (EnclosureInfo->ThermalState > ChassisStateNonRecoverable)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid chassis state\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + if ((EnclosureInfo->SecurityStatus < ChassisSecurityStatusOther) || + (EnclosureInfo->SecurityStatus > ChassisSecurityStatusExternalInterfaceLockedEnabled)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid SecurityStatus 0x%x\n", __func__, EnclosureInfo->SecurityStatus)); + return EFI_INVALID_PARAMETER; + } + + if (EnclosureInfo->RackType > ChassisRackTypeOU) { + DEBUG ((DEBUG_ERROR, "%a: Invalid RackType 0x%x\n", __func__, EnclosureInfo->RackType)); + return EFI_INVALID_PARAMETER; + } + + if ((EnclosureInfo->Height == ChassisHeightUseRackHeight) && + (EnclosureInfo->RackHeight == 0)) + { + DEBUG ((DEBUG_ERROR, "%a: RackHeight must be non-zero when Height is 0xFF\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** Construct SMBIOS Type 3 tables describing system enclosures. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS table factory. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager. + @param [out] Table Pointer to the generated SMBIOS tables. + @param [out] CmObjectToken Pointer to the CM object tokens. + @param [out] TableCount Number of generated SMBIOS tables. + + @retval EFI_SUCCESS Tables generated successfully. + @retval EFI_INVALID_PARAMETER A parameter or CM object is invalid. + @retval EFI_NOT_FOUND No System Enclosure objects were found. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +BuildSmbiosType3TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + CM_ARCH_COMMON_SYSTEM_ENCLOSURE_INFO *EnclosureInfo; + CM_ARCH_COMMON_ENCLOSURE_ELEMENT *ContainedElement; + UINT32 EnclosureCount; + UINT32 ContainedElementCount; + SMBIOS_STRUCTURE **TableList; + CM_OBJECT_TOKEN *CmObjectList; + SMBIOS_TABLE_TYPE3 *SmbiosRecord; + CONTAINED_ELEMENT *ContainedElementField; + STRING_TABLE StrTable; + SMBIOS_TABLE_STRING ManufacturerRef; + SMBIOS_TABLE_STRING VersionRef; + SMBIOS_TABLE_STRING SerialNumRef; + SMBIOS_TABLE_STRING AssetTagRef; + SMBIOS_TABLE_STRING SkuNumRef; + SMBIOS_TABLE_STRING *SkuNumField; + UINT8 *RackTypeField; + UINT8 *RackHeightField; + UINTN FormattedLength; + UINTN RecordSize; + UINTN Index; + UINTN ContainedElementIndex; + + ASSERT (This != NULL); + ASSERT (TableFactoryProtocol != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Table != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (TableFactoryProtocol == NULL) || + (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL) || (TableCount == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + *CmObjectToken = NULL; + *TableCount = 0; + TableList = NULL; + CmObjectList = NULL; + SmbiosRecord = NULL; + + Status = GetEArchCommonObjSystemEnclosureInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &EnclosureInfo, + &EnclosureCount + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get System Enclosure objects: %r\n", __func__, Status)); + return Status; + } + + if (EnclosureCount == 0) { + return EFI_NOT_FOUND; + } + + TableList = AllocateZeroPool (sizeof (*TableList) * EnclosureCount); + if (TableList == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CmObjectList = AllocateZeroPool (sizeof (*CmObjectList) * EnclosureCount); + if (CmObjectList == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ErrorExit; + } + + for (Index = 0; Index < EnclosureCount; Index++) { + Status = ValidateSystemEnclosureInfo (&EnclosureInfo[Index]); + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + + ContainedElement = NULL; + ContainedElementCount = 0; + if (EnclosureInfo[Index].ContainedElementListToken != CM_NULL_TOKEN) { + Status = GetEArchCommonObjEnclosureElement ( + CfgMgrProtocol, + EnclosureInfo[Index].ContainedElementListToken, + &ContainedElement, + &ContainedElementCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Contained Elements for enclosure %u: %r\n", + __func__, + Index, + Status + )); + goto ErrorExit; + } + + if ((ContainedElementCount != 0) && (ContainedElement == NULL)) { + DEBUG (( + DEBUG_ERROR, + "%a: Contained Element list is NULL for enclosure %u\n", + __func__, + Index + )); + Status = EFI_INVALID_PARAMETER; + goto ErrorExit; + } + + if (ContainedElementCount > MAX_UINT8) { + DEBUG (( + DEBUG_ERROR, + "%a: Too many Contained Elements for enclosure %u: %u\n", + __func__, + Index, + ContainedElementCount + )); + Status = EFI_INVALID_PARAMETER; + goto ErrorExit; + } + + Status = ValidateSystemEnclosureContainedElements ( + ContainedElement, + ContainedElementCount + ); + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + } + + FormattedLength = SMBIOS_TYPE3_BASE_LENGTH + + (ContainedElementCount * SMBIOS_TYPE3_CONTAINED_ELEMENT_RECORD_LENGTH); + if (FormattedLength > MAX_UINT8) { + DEBUG (( + DEBUG_ERROR, + "%a: Formatted length %Lu exceeds Hdr.Length for enclosure %u\n", + __func__, + (UINT64)FormattedLength, + Index + )); + Status = EFI_INVALID_PARAMETER; + goto ErrorExit; + } + + Status = StringTableInitialize (&StrTable, SMBIOS_TYPE3_MAX_STRINGS); + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + + ManufacturerRef = 0; + VersionRef = 0; + SerialNumRef = 0; + AssetTagRef = 0; + SkuNumRef = 0; + + Status = StringTableAddString (&StrTable, EnclosureInfo[Index].Manufacturer, &ManufacturerRef); + if (EFI_ERROR (Status)) { + StringTableFree (&StrTable); + goto ErrorExit; + } + + if (EnclosureInfo[Index].Version[0] != '\0') { + Status = StringTableAddString (&StrTable, EnclosureInfo[Index].Version, &VersionRef); + } + + if (!EFI_ERROR (Status) && (EnclosureInfo[Index].SerialNum[0] != '\0')) { + Status = StringTableAddString (&StrTable, EnclosureInfo[Index].SerialNum, &SerialNumRef); + } + + if (!EFI_ERROR (Status) && (EnclosureInfo[Index].AssetTag[0] != '\0')) { + Status = StringTableAddString (&StrTable, EnclosureInfo[Index].AssetTag, &AssetTagRef); + } + + if (!EFI_ERROR (Status) && (EnclosureInfo[Index].SkuNum[0] != '\0')) { + Status = StringTableAddString (&StrTable, EnclosureInfo[Index].SkuNum, &SkuNumRef); + } + + if (EFI_ERROR (Status)) { + StringTableFree (&StrTable); + goto ErrorExit; + } + + RecordSize = FormattedLength + StringTableGetStringSetSize (&StrTable); + SmbiosRecord = AllocateZeroPool (RecordSize); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + StringTableFree (&StrTable); + goto ErrorExit; + } + + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE; + SmbiosRecord->Hdr.Length = (UINT8)FormattedLength; + SmbiosRecord->Manufacturer = ManufacturerRef; + SmbiosRecord->Type = EnclosureInfo[Index].Type; + SmbiosRecord->Version = VersionRef; + SmbiosRecord->SerialNumber = SerialNumRef; + SmbiosRecord->AssetTag = AssetTagRef; + SmbiosRecord->BootupState = EnclosureInfo[Index].BootUpState; + SmbiosRecord->PowerSupplyState = EnclosureInfo[Index].PowerSupplyState; + SmbiosRecord->ThermalState = EnclosureInfo[Index].ThermalState; + SmbiosRecord->SecurityStatus = EnclosureInfo[Index].SecurityStatus; + SmbiosRecord->Height = EnclosureInfo[Index].Height; + SmbiosRecord->NumberofPowerCords = EnclosureInfo[Index].NumberOfPowerCords; + SmbiosRecord->ContainedElementCount = (UINT8)ContainedElementCount; + SmbiosRecord->ContainedElementRecordLength = + (ContainedElementCount == 0) ? 0 : SMBIOS_TYPE3_CONTAINED_ELEMENT_RECORD_LENGTH; + WriteUnaligned32 ((UINT32 *)SmbiosRecord->OemDefined, EnclosureInfo[Index].OemDefined); + + ContainedElementField = (CONTAINED_ELEMENT *)((UINT8 *)SmbiosRecord + + OFFSET_OF (SMBIOS_TABLE_TYPE3, ContainedElements)); + if (ContainedElement != NULL) { + for (ContainedElementIndex = 0; + ContainedElementIndex < ContainedElementCount; + ContainedElementIndex++) + { + ContainedElementField[ContainedElementIndex].ContainedElementType = + ContainedElement[ContainedElementIndex].ContainedElementType; + ContainedElementField[ContainedElementIndex].ContainedElementMinimum = + ContainedElement[ContainedElementIndex].ContainedElementMinimum; + ContainedElementField[ContainedElementIndex].ContainedElementMaximum = + ContainedElement[ContainedElementIndex].ContainedElementMaximum; + } + } + + SkuNumField = (SMBIOS_TABLE_STRING *)((UINT8 *)ContainedElementField + + (ContainedElementCount * + SMBIOS_TYPE3_CONTAINED_ELEMENT_RECORD_LENGTH)); + RackTypeField = (UINT8 *)(SkuNumField + 1); + RackHeightField = RackTypeField + 1; + *SkuNumField = SkuNumRef; + *RackTypeField = EnclosureInfo[Index].RackType; + *RackHeightField = EnclosureInfo[Index].RackHeight; + + Status = StringTablePublishStringSet ( + &StrTable, + (CHAR8 *)SmbiosRecord + FormattedLength, + RecordSize - FormattedLength + ); + StringTableFree (&StrTable); + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] = EnclosureInfo[Index].SystemEnclosureToken; + SmbiosRecord = NULL; + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = EnclosureCount; + return EFI_SUCCESS; + +ErrorExit: + if (SmbiosRecord != NULL) { + FreePool (SmbiosRecord); + } + + if (TableList != NULL) { + for (Index = 0; Index < EnclosureCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + FreePool (TableList); + } + + if (CmObjectList != NULL) { + FreePool (CmObjectList); + } + + return Status; +} + +/** + Free any resources allocated when installing SMBIOS Type 3 tables. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] Table Pointer to the SMBIOS tables. + @param [in] CmObjectToken Pointer to the CM ObjectToken array. + @param [in] TableCount Number of SMBIOS tables. + + @retval EFI_SUCCESS Resources freed successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +FreeSmbiosType3TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + + if ((This == NULL) || (TableFactoryProtocol == NULL) || + (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + if (*Table != NULL) { + for (Index = 0; Index < TableCount; Index++) { + if ((*Table)[Index] != NULL) { + FreePool ((*Table)[Index]); + } + } + + FreePool (*Table); + *Table = NULL; + } + + if (*CmObjectToken != NULL) { + FreePool (*CmObjectToken); + *CmObjectToken = NULL; + } + + return EFI_SUCCESS; +} + +STATIC CONST SMBIOS_TABLE_GENERATOR SmbiosType3Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType03), + // Generator Description + L"SMBIOS.TYPE3.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE, + NULL, + NULL, + // Build table function Extended. + BuildSmbiosType3TableEx, + // Free function Extended. + FreeSmbiosType3TableEx +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType3LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType3Generator); + DEBUG ((DEBUG_INFO, "SMBIOS Type 3: Register Generator. Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType3LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType3Generator); + DEBUG ((DEBUG_INFO, "SMBIOS Type 3: Deregister Generator. Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Lib.inf new file mode 100644 index 0000000000..c1e24aa518 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Lib.inf @@ -0,0 +1,30 @@ +## @file +# SMBIOS Type 3 Table Generator +# +# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType3Lib + FILE_GUID = 82f255ee-f7c3-49b8-bd45-dc637a9817cf + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType3LibConstructor + DESTRUCTOR = SmbiosType3LibDestructor + +[Sources] + SmbiosType3Generator.c + +[Packages] + MdePkg/MdePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MemoryAllocationLib + SmbiosStringTableLib From 8d2bbdfb14384d77a5be491d90a8ac35cfa192a8 Mon Sep 17 00:00:00 2001 From: Qihang Gao <gaoqihang@loongson.cn> Date: Fri, 24 Jul 2026 10:55:15 +0800 Subject: [PATCH 281/406] StandaloneMmPkg/Core: Fix memory leak in MmiHandlerRegister In MmiHandlerRegister(), the MmiHandler structure is currently allocated before looking up the target MmiEntry. If the lookup fails, the function returns an error but the allocated MmiHandler is never freed, causing a memory leak. This patch moves the allocation of MmiHandler and its initialization to after the MmiEntry lookup and validation. This ensures that memory is only allocated when the operation can succeed, eliminating the need for a FreePool() on the error path and simplifying the error handling logic. Signed-off-by: Qihang Gao <gaoqihang@loongson.cn> Suggested-by: Ray Ni <ray.ni@intel.com> --- StandaloneMmPkg/Core/Mmi.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/StandaloneMmPkg/Core/Mmi.c b/StandaloneMmPkg/Core/Mmi.c index 47ef20df78..add397387c 100644 --- a/StandaloneMmPkg/Core/Mmi.c +++ b/StandaloneMmPkg/Core/Mmi.c @@ -367,15 +367,6 @@ MmiHandlerRegister ( return EFI_INVALID_PARAMETER; } - MmiHandler = AllocateZeroPool (sizeof (MMI_HANDLER)); - if (MmiHandler == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - MmiHandler->Signature = MMI_HANDLER_SIGNATURE; - MmiHandler->Handler = Handler; - MmiHandler->ToRemove = FALSE; - if (HandlerType == NULL) { // // This is root MMI handler @@ -394,7 +385,15 @@ MmiHandlerRegister ( List = &MmiEntry->MmiHandlers; } - MmiHandler->MmiEntry = MmiEntry; + MmiHandler = AllocateZeroPool (sizeof (MMI_HANDLER)); + if (MmiHandler == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + MmiHandler->Signature = MMI_HANDLER_SIGNATURE; + MmiHandler->Handler = Handler; + MmiHandler->ToRemove = FALSE; + MmiHandler->MmiEntry = MmiEntry; InsertTailList (List, &MmiHandler->Link); *DispatchHandle = (EFI_HANDLE)MmiHandler; From 58e8828bb37ba3b9ef9a5bebcc3369fd032188a6 Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Wed, 22 Jul 2026 22:25:18 -0400 Subject: [PATCH 282/406] .pytool: Include the British English dictionary Prevent British English words from being flagged as spelling errors. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- .pytool/Plugin/SpellCheck/cspell.base.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pytool/Plugin/SpellCheck/cspell.base.yaml b/.pytool/Plugin/SpellCheck/cspell.base.yaml index 2dbd18be25..0c79a0cd3e 100644 --- a/.pytool/Plugin/SpellCheck/cspell.base.yaml +++ b/.pytool/Plugin/SpellCheck/cspell.base.yaml @@ -6,9 +6,9 @@ ## { "version": "0.1", - "language": "en", + "language": "en,en-GB", "dictionaries": [ - "companies ", + "companies", "softwareTerms", "python", "cpp" From 71c401f2e98f2bf13e98a4258f6e92854a6a0711 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Tue, 21 Jul 2026 15:41:13 -0700 Subject: [PATCH 283/406] DynamicTablesPkg: Fix markdownlint errors Fixing all markdown lint errors found by running markdownlint-cli. Verified that rendering still shows valid information. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- DynamicTablesPkg/DynamicTablesPkg.ci.yaml | 6 + DynamicTablesPkg/Readme.md | 467 +++++++++++----------- 2 files changed, 242 insertions(+), 231 deletions(-) diff --git a/DynamicTablesPkg/DynamicTablesPkg.ci.yaml b/DynamicTablesPkg/DynamicTablesPkg.ci.yaml index 224051cb03..0631fe8149 100644 --- a/DynamicTablesPkg/DynamicTablesPkg.ci.yaml +++ b/DynamicTablesPkg/DynamicTablesPkg.ci.yaml @@ -169,5 +169,11 @@ # Reason: Debug format strings are dynamically set. "Parser[Index].Format": "%d" } + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": False, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/DynamicTablesPkg/Readme.md b/DynamicTablesPkg/Readme.md index b84cfd96fb..e7b0c6f3d9 100644 --- a/DynamicTablesPkg/Readme.md +++ b/DynamicTablesPkg/Readme.md @@ -9,7 +9,7 @@ be generated from the system construction. This initial release does not fully implement that - the configuration is held in local UEFI modules. -# Feature Summary +## Feature Summary The dynamic tables framework is designed to generate standardised firmware tables that describe the hardware information at @@ -92,11 +92,13 @@ framework that provides a solution for dynamic generation of ACPI Definition block tables. Dynamic AML introduces the following techniques: + * AML Fixup * AML Codegen * AML Fixup + Codegen ### AML Fixup + AML fixup is a technique that involves compiling an ASL template file to generate AML bytecode. This template AML bytecode can be parsed at run-time and a fixup code can update the required fields in the AML template. @@ -105,46 +107,51 @@ To simplify AML Fixup, the Dynamic Tables Framework provides an *AmlLib* library with a rich set of APIs that can be used to fixup the AML code. ### AML Codegen + AML Codegen employs generating small segments of AML code. The *AmlLib* library provides AML Codegen APIs that generate the AML code segments. - Example: The following table depicts the AML Codegen APIs and the - corresponding ASL code that would be generated. +```text +Example: The following table depicts the AML Codegen APIs and the + corresponding ASL code that would be generated. - | AML Codegen API | ASL Code | - |--------------------------------|--------------------------------| - | AmlCodeGenDefinitionBlock ( | DefinitionBlock ( | - | .., | ... | - | &RootNode); | ) { | - | AmlCodeGenScope ( | Scope (_SB) { | - | "\_SB", | | - | RootNode, | | - | &ScopeNode); | | - | AmlCodeGenDevice ( | Device (CPU0) { | - | "CPU0", | | - | ScopeNode, | | - | &CpuNode); | | - | AmlCodeGenNameString ( | Name (_HID, "ACPI0007") | - | "_HID", | | - | "ACPI0007", | | - | CpuNode, | | - | &HidNode); | | - | AmlCodeGenNameInteger ( | Name (_UID, Zero) | - | "_UID", | | - | 0, | | - | CpuNode, | | - | &UidNode); | | - | | } // Device | - | | } // Scope | - | | } // DefinitionBlock | +| AML Codegen API | ASL Code | +|--------------------------------|--------------------------------| +| AmlCodeGenDefinitionBlock ( | DefinitionBlock ( | +| .., | ... | +| &RootNode); | ) { | +| AmlCodeGenScope ( | Scope (_SB) { | +| "\_SB", | | +| RootNode, | | +| &ScopeNode); | | +| AmlCodeGenDevice ( | Device (CPU0) { | +| "CPU0", | | +| ScopeNode, | | +| &CpuNode); | | +| AmlCodeGenNameString ( | Name (_HID, "ACPI0007") | +| "_HID", | | +| "ACPI0007", | | +| CpuNode, | | +| &HidNode); | | +| AmlCodeGenNameInteger ( | Name (_UID, Zero) | +| "_UID", | | +| 0, | | +| CpuNode, | | +| &UidNode); | | +| | } // Device | +| | } // Scope | +| | } // DefinitionBlock | +``` ### AML Fixup + Codegen + A combination of AML Fixup and AML Codegen could be used for generating Definition Blocks. For example the AML Fixup could be used to fixup certain parts of the AML template while the AML Codegen APIs could be used to inserted small fragments of AML code in the AML template. ### AmlLib Library + Since, AML bytecode represents complex AML grammar, an **AmlLib** library is introduced to assist parsing and traversing of the AML bytecode at run-time. @@ -168,12 +175,14 @@ definition block, these checks may not cover all aspects due to the complexity of the ASL/AML language. It is therefore recommended to review any operation performed, and validate the generated output. - Example: The serialized AML code could be validated by - - Saving the generated AML to a file and comparing with - a reference output. - or - - Disassemble the generated AML using the iASL compiler - and verifying the output. +```text +Example: The serialized AML code could be validated by + - Saving the generated AML to a file and comparing with + a reference output. + or + - Disassemble the generated AML using the iASL compiler + and verifying the output. +``` ### Bespoke ACPI tables @@ -183,8 +192,8 @@ standard generators, see Feature Summary Section for a list of such tables. The supported platforms already contain several tables. If a table is not present for the platform, two alternative processes can be followed: -- define the table in using ASL, -- define the table in packed C structures (also known as RAW). +* define the table in using ASL, +* define the table in packed C structures (also known as RAW). The two approaches are detailed below. @@ -195,63 +204,61 @@ Perform the following steps: 1. Create the table source file, placing it within the ConfigurationManager source tree, e.g.: -Create a file Platform/ARM/VExpressPkg/ConfigurationManager/ConfigurationManagerDxe/AslTables/NewTableSource.asl -with the following contents: + Create a file Platform/ARM/VExpressPkg/ConfigurationManager/ConfigurationManagerDxe/AslTables/NewTableSource.asl + with the following contents: -``` -DefinitionBlock ("", "SSDT", 2, "XXXXXX", "XXXXXXXX", 1) { - Scope(_SB) { - Device(FLA0) { - Name(_HID, "XXXX0000") - Name(_UID, 0) + ```asl + DefinitionBlock ("", "SSDT", 2, "XXXXXX", "XXXXXXXX", 1) { + Scope(_SB) { + Device(FLA0) { + Name(_HID, "XXXX0000") + Name(_UID, 0) - // _DSM - Device Specific Method - Function(_DSM,{IntObj,BuffObj},{BuffObj, IntObj, IntObj, PkgObj}) - { - W0 = 0x1 - return (W0) - } + // _DSM - Device Specific Method + Function(_DSM,{IntObj,BuffObj},{BuffObj, IntObj, IntObj, PkgObj}) + { + W0 = 0x1 + return (W0) + } } - } -} -``` + ``` 2. Reference the table source file in ConfigurationMangerDxe.inf -``` - [Sources] - AslTables/NewTableSource.asl -``` + ```ini + [Sources] + AslTables/NewTableSource.asl + ``` -3. Update the ConfigurationManager.h file -Platform/ARM/VExpressPkg/ConfigurationManager/ConfigurationManagerDxe/ConfigurationManager.h +3. Update the ConfigurationManager.h file Platform/ARM/VExpressPkg/ConfigurationManager/ConfigurationManagerDxe/ConfigurationManager.h -Add an array to hold the AML code: -``` - extern CHAR8 newtablesource_aml_code[]; -``` + Add an array to hold the AML code: -Note: the array name is composed of the ASL source file name all in lower case, followed by the _aml_code postfix. + ```c + extern CHAR8 newtablesource_aml_code[]; + ``` + + Note: the array name is composed of the ASL source file name all in lower case, followed by the _aml_code postfix. 4. Increment the macro PLAT_ACPI_TABLE_COUNT 5. Add a new CM_STD_OBJ_ACPI_TABLE_INFO structure entry and initialise. - - the entry contains: - - the table signature, - - the table revision (unused in this case), - - the ID of the standard generator to be used (the SSDT generator in this case). - - a pointer to the AML code, + * the entry contains: + * the table signature, + * the table revision (unused in this case), + * the ID of the standard generator to be used (the SSDT generator in this case). + * a pointer to the AML code, -``` - // Table defined in the NewTableSource.asl file - { - EFI_ACPI_6_4_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, - 0, // Unused - CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdSsdt), - (EFI_ACPI_DESCRIPTION_HEADER*)newtablesource_aml_code - }, -``` + ```c + // Table defined in the NewTableSource.asl file + { + EFI_ACPI_6_4_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, + 0, // Unused + CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdSsdt), + (EFI_ACPI_DESCRIPTION_HEADER*)newtablesource_aml_code + }, + ``` #### Add a RAW table for which there is no standard generator @@ -262,40 +269,40 @@ The steps to create a table in raw format are detailed below: For example, create the file Platform/ARM/VExpressPkg/ConfigurationManager/ConfigurationManagerDxe/RawTable.c -``` - // Example creating the HMAT in raw format - EFI_ACPI_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE Hmat = { - ... - }; -``` + ```c + // Example creating the HMAT in raw format + EFI_ACPI_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE Hmat = { + ... + }; + ``` 2. Reference the table source file in ConfigurationMangerDxe.inf -``` - [Sources] - RawTable.c -``` + ```ini + [Sources] + RawTable.c + ``` -2. Increment the macro PLAT_ACPI_TABLE_COUNT +3. Increment the macro PLAT_ACPI_TABLE_COUNT -3. Add a new CM_STD_OBJ_ACPI_TABLE_INFO structure entry and initialise. +4. Add a new CM_STD_OBJ_ACPI_TABLE_INFO structure entry and initialise. - - the entry contains: - - the table signature, - - the table revision, - - the RAW generator ID. - - a pointer to the C packed struct that defines the table, + * the entry contains: + * the table signature, + * the table revision, + * the RAW generator ID. + * a pointer to the C packed struct that defines the table, -``` - { - EFI_ACPI_6_3_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_SIGNATURE, - EFI_ACPI_6_3_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_REVISION, - CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdRaw), - (EFI_ACPI_DESCRIPTION_HEADER*)&Hmat - }, -``` + ```c + { + EFI_ACPI_6_3_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_SIGNATURE, + EFI_ACPI_6_3_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_REVISION, + CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdRaw), + (EFI_ACPI_DESCRIPTION_HEADER*)&Hmat + }, + ``` -# Roadmap +## Roadmap The current implementation of the Configuration Manager populates the platform information statically as a C structure. Further enhancements @@ -305,56 +312,53 @@ information file is planned. Also support for generating SMBIOS tables is planned and will be added subsequently. -# Supported Platforms +## Supported Platforms 1. Juno 2. FVP Models -# Build Instructions +## Build Instructions 1. Set path for the iASL compiler with support for generating a C header file as output. 2. Set PACKAGES_PATH to point to the locations of the following repositories: -Example: + Example: -> set PACKAGES_PATH=%CD%\edk2;%CD%\edk2-platforms; + > set PACKAGES_PATH=%CD%\edk2;%CD%\edk2-platforms; - or + or -> export PACKAGES_PATH=$PWD/edk2:$PWD/edk2-platforms + > export PACKAGES_PATH=$PWD/edk2:$PWD/edk2-platforms -3. To enable Dynamic tables framework the *'DYNAMIC_TABLES_FRAMEWORK'* -option must be defined. This can be passed as a command line -parameter to the edk2 build system. +3. To enable Dynamic tables framework the *'DYNAMIC_TABLES_FRAMEWORK'* option must be defined. This can be passed as a +command line parameter to the edk2 build system. -Example: + Example: ->build -a AARCH64 -p Platform\ARM\JunoPkg\ArmJuno.dsc - -t GCC **-D DYNAMIC_TABLES_FRAMEWORK** + >build -a AARCH64 -p Platform\ARM\JunoPkg\ArmJuno.dsc + -t GCC **-D DYNAMIC_TABLES_FRAMEWORK** -or + or ->build -a AARCH64 -p Platform\ARM\VExpressPkg\ArmVExpress-FVP-AArch64.dsc - -t GCC **-D DYNAMIC_TABLES_FRAMEWORK** + >build -a AARCH64 -p Platform\ARM\VExpressPkg\ArmVExpress-FVP-AArch64.dsc + -t GCC **-D DYNAMIC_TABLES_FRAMEWORK** -# Prerequisites +## Prerequisites Ensure that the latest ACPICA iASL compiler is used for building *Dynamic Tables Framework*. *Dynamic Tables Framework* has been tested using the following iASL compiler version: [Version 20200717](https://www.intel.com/content/www/us/en/download/774849/774863/acpi-component-architecture-downloads-previous-releases-2020.html), dated 17 July, 2020. - -#Running CI builds locally +## Running CI builds locally The TianoCore EDKII project has introduced Core CI infrastructure using TianoCore EDKII Tools PIP modules: - - *[edk2-pytool-library](https://pypi.org/project/edk2-pytool-library)* - - - *[edk2-pytool-extensions](https://pypi.org/project/edk2-pytool-extensions)* +* *[edk2-pytool-library](https://pypi.org/project/edk2-pytool-library)* +* *[edk2-pytool-extensions](https://pypi.org/project/edk2-pytool-extensions)* The instructions to setup the CI environment are in *'edk2\\.pytool\\Readme.md'* @@ -362,7 +366,7 @@ The instructions to setup the CI environment are in *'edk2\\.pytool\\Readme.md'* 1. [Optional] Create a Python Virtual Environment - generally once per workspace - ``` + ```shell python -m venv <name of virtual environment> e.g. python -m venv edk2-ci @@ -370,21 +374,22 @@ The instructions to setup the CI environment are in *'edk2\\.pytool\\Readme.md'* 2. [Optional] Activate Virtual Environment - each time new shell/command window is opened - ``` + ```shell <name of virtual environment>/Scripts/activate e.g. On a windows host PC run: edk2-ci\Scripts\activate.bat ``` + 3. Install Pytools - generally once per virtual env or whenever pip-requirements.txt changes - ``` + ```shell pip install --upgrade -r pip-requirements.txt ``` 4. Initialize & Update Submodules - only when submodules updated - ``` + ```shell stuart_setup -c .pytool/CISettings.py TOOL_CHAIN_TAG=<TOOL_CHAIN_TAG> -a <TARGET_ARCH> e.g. stuart_setup -c .pytool/CISettings.py TOOL_CHAIN_TAG=GCC @@ -392,7 +397,7 @@ The instructions to setup the CI environment are in *'edk2\\.pytool\\Readme.md'* 5. Initialize & Update Dependencies - only as needed when ext_deps change - ``` + ```shell stuart_update -c .pytool/CISettings.py TOOL_CHAIN_TAG=<TOOL_CHAIN_TAG> -a <TARGET_ARCH> e.g. stuart_update -c .pytool/CISettings.py TOOL_CHAIN_TAG=GCC @@ -400,22 +405,21 @@ The instructions to setup the CI environment are in *'edk2\\.pytool\\Readme.md'* 6. Compile the basetools if necessary - only when basetools C source files change - ``` + ```shell python BaseTools/Edk2ToolsBuild.py -t <ToolChainTag> ``` 7. Compile DynamicTablesPkg - ``` + ```shell stuart_build-c .pytool/CISettings.py TOOL_CHAIN_TAG=<TOOL_CHAIN_TAG> -a <TARGET_ARCH> e.g. stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=GCC -p DynamicTablesPkg -a AARCH64 --verbose ``` - - use `stuart_build -c .pytool/CISettings.py -h` option to see help on additional options. + * use `stuart_build -c .pytool/CISettings.py -h` option to see help on additional options. - -# Documentation +## Documentation Refer to the following presentation from *UEFI Plugfest Seattle 2018*: @@ -431,123 +435,124 @@ The CM_OBJECT_ID type is used to identify the Configuration Manager | 31 - 28 | 27 - 8 | 7 - 0 | | :-------------: | :----: | :---------: | | `Name Space ID` | 0 | `Object ID` | + ------------------------------------------ ### Name Space ID: Bits [31:28] | ID | Description | Comments | | ---: | :-------------------------- | :--- | -| 0000b | Standard | | -| 0001b | Arch Common | | -| 0010b | ARM | | -| 0011b | X64 | | -| 1111b | Custom/OEM | | -| `*` | All other values are reserved. | | +| 0000b | Standard | | +| 0001b | Arch Common | | +| 0010b | ARM | | +| 0011b | X64 | | +| 1111b | Custom/OEM | | +| `*` | All other values are reserved. | | -### Bits: [27:8] - Reserved, must be zero. +### Bits: [27:8] - Reserved, must be zero ### Bits: [7:0] - Object ID -#### Object ID's in the Standard Namespace: +#### Object ID's in the Standard Namespace | ID | Description | Comments | | ---: | :-------------------------- | :--- | -| 0 | Configuration Manager Revision | | -| 1 | ACPI Table List | | -| 2 | SMBIOS Table List | | +| 0 | Configuration Manager Revision | | +| 1 | ACPI Table List | | +| 2 | SMBIOS Table List | | -#### Object ID's in the ARM Namespace: +#### Object ID's in the ARM Namespace | ID | Description | Comments | | ---: | :-------------------------- | :--- | -| 0 | Reserved | | -| 1 | Boot Architecture Info | | -| 2 | GICC Info | | -| 3 | GICD Info | | -| 4 | GIC MSI Frame Info | | -| 5 | GIC Redistributor Info | | -| 6 | GIC ITS Info | | -| 7 | Generic Timer Info | | -| 8 | Platform GT Block Info | | -| 9 | Generic Timer Block Frame Info | | -| 10 | Platform Generic Watchdog | | -| 11 | ITS Group | | -| 12 | Named Component | | -| 13 | Root Complex | | -| 14 | SMMUv1 or SMMUv2 | | -| 15 | SMMUv3 | | -| 16 | PMCG | | -| 17 | GIC ITS Identifier Array | | -| 18 | ID Mapping Array | | -| 19 | SMMU Interrupt Array | | -| 20 | CMN 600 Info | | -| 21 | Reserved Memory Range Node | | -| 22 | Memory Range Descriptor | | -| 23 | Embedded Trace Extension/Module Info | | -| `*` | All other values are reserved. | | +| 0 | Reserved | | +| 1 | Boot Architecture Info | | +| 2 | GICC Info | | +| 3 | GICD Info | | +| 4 | GIC MSI Frame Info | | +| 5 | GIC Redistributor Info | | +| 6 | GIC ITS Info | | +| 7 | Generic Timer Info | | +| 8 | Platform GT Block Info | | +| 9 | Generic Timer Block Frame Info | | +| 10 | Platform Generic Watchdog | | +| 11 | ITS Group | | +| 12 | Named Component | | +| 13 | Root Complex | | +| 14 | SMMUv1 or SMMUv2 | | +| 15 | SMMUv3 | | +| 16 | PMCG | | +| 17 | GIC ITS Identifier Array | | +| 18 | ID Mapping Array | | +| 19 | SMMU Interrupt Array | | +| 20 | CMN 600 Info | | +| 21 | Reserved Memory Range Node | | +| 22 | Memory Range Descriptor | | +| 23 | Embedded Trace Extension/Module Info | | +| `*` | All other values are reserved. | | -#### Object ID's in the Arch Common Namespace: +#### Object ID's in the Arch Common Namespace | ID | Description | Comments | | ---: | :-------------------------- | :--- | -| 0 | Reserved | | -| 1 | Power Management Profile Info | | -| 2 | Serial Port Info | | -| 3 | Serial Console Port Info | | -| 4 | Serial Debug Port Info | | -| 5 | Hypervisor Vendor Id | | -| 6 | Fixed feature flags for FADT | | -| 7 | CM Object Reference | | -| 8 | PCI Configuration Space Info | | -| 9 | PCI Address Map Info | | -| 10 | PCI Interrupt Map Info | | -| 11 | Memory Affinity Info | | -| 12 | Device Handle Acpi | | -| 13 | Device Handle PCI | | -| 14 | Generic Initiator Affinity Info | | -| 15 | Low Power Idle State Info | | -| 16 | Processor Hierarchy Info | | -| 17 | Cache Info | | -| 18 | Continuous Performance Control Info | | -| 19 | Pcc Subspace Type 0 Info | | -| 20 | Pcc Subspace Type 1 Info | | -| 21 | Pcc Subspace Type 2 Info | | -| 22 | Pcc Subspace Type 3 Info | | -| 23 | Pcc Subspace Type 4 Info | | -| 24 | Pcc Subspace Type 5 Info | | -| 25 | P-State Dependency (PSD) Info | | -| 26 | TPM Interface Info | | -| 27 | SPMI Interface Info | | -| 28 | SPMI Interrupt and Device/Uid Info | | -| 29 | Processor C-State Control Info | | -| 30 | Processor C-State Dependency Info | | -| 31 | Processor P-State Control Info | | -| 32 | Processor P-State Status Info | | -| 33 | Processor P-State Capability Info | | -| 34 | _STA Device Status Info | | -| `*` | All other values are reserved. | | +| 0 | Reserved | | +| 1 | Power Management Profile Info | | +| 2 | Serial Port Info | | +| 3 | Serial Console Port Info | | +| 4 | Serial Debug Port Info | | +| 5 | Hypervisor Vendor Id | | +| 6 | Fixed feature flags for FADT | | +| 7 | CM Object Reference | | +| 8 | PCI Configuration Space Info | | +| 9 | PCI Address Map Info | | +| 10 | PCI Interrupt Map Info | | +| 11 | Memory Affinity Info | | +| 12 | Device Handle Acpi | | +| 13 | Device Handle PCI | | +| 14 | Generic Initiator Affinity Info | | +| 15 | Low Power Idle State Info | | +| 16 | Processor Hierarchy Info | | +| 17 | Cache Info | | +| 18 | Continuous Performance Control Info | | +| 19 | Pcc Subspace Type 0 Info | | +| 20 | Pcc Subspace Type 1 Info | | +| 21 | Pcc Subspace Type 2 Info | | +| 22 | Pcc Subspace Type 3 Info | | +| 23 | Pcc Subspace Type 4 Info | | +| 24 | Pcc Subspace Type 5 Info | | +| 25 | P-State Dependency (PSD) Info | | +| 26 | TPM Interface Info | | +| 27 | SPMI Interface Info | | +| 28 | SPMI Interrupt and Device/Uid Info | | +| 29 | Processor C-State Control Info | | +| 30 | Processor C-State Dependency Info | | +| 31 | Processor P-State Control Info | | +| 32 | Processor P-State Status Info | | +| 33 | Processor P-State Capability Info | | +| 34 | _STA Device Status Info | | +| `*` | All other values are reserved. | | -#### Object ID's in the X64 Namespace: +#### Object ID's in the X64 Namespace | ID | Description | Comments | | ---: | :-------------------------- | :--- | -| 0 | Reserved | | -| 1 | SCI Interrupt Info | | -| 2 | SCI Command Info | | -| 3 | Legacy Power Management Block Info | | -| 4 | Legacy GPE Block Info | | -| 5 | Power Management Block Info | | -| 6 | GPE Block Info | | -| 7 | Sleep Block Info | | -| 8 | Reset Block Info | | -| 9 | Miscellaneous Block Info | | -| 10 | Windows protection flag Info | | -| 11 | HPET device Info | | -| 12 | MADT Table Info | | -| 13 | Local APIC and X2APIC info | | -| 14 | IO APIC info | | -| 15 | Interrupt Source Override info | | -| 16 | Local APIC and X2APIC NMI info | | -| 17 | FACS Information | | -| 18 | Local APIC and X2APIC Affinity info | | -| `*` | All other values are reserved. | | +| 0 | Reserved | | +| 1 | SCI Interrupt Info | | +| 2 | SCI Command Info | | +| 3 | Legacy Power Management Block Info | | +| 4 | Legacy GPE Block Info | | +| 5 | Power Management Block Info | | +| 6 | GPE Block Info | | +| 7 | Sleep Block Info | | +| 8 | Reset Block Info | | +| 9 | Miscellaneous Block Info | | +| 10 | Windows protection flag Info | | +| 11 | HPET device Info | | +| 12 | MADT Table Info | | +| 13 | Local APIC and X2APIC info | | +| 14 | IO APIC info | | +| 15 | Interrupt Source Override info | | +| 16 | Local APIC and X2APIC NMI info | | +| 17 | FACS Information | | +| 18 | Local APIC and X2APIC Affinity info | | +| `*` | All other values are reserved. | | From 5c6e9d475fe2943f2844ca879785c198588a30d0 Mon Sep 17 00:00:00 2001 From: VarshitPandya <varshit.pandya@arm.com> Date: Wed, 22 Jul 2026 15:51:46 +0100 Subject: [PATCH 284/406] ArmPkg: Add Arm SMCCC SoC ID library Add ArmSmcccSocIdLib to provide a shared interface for checking support for the SMCCC Architecture SoC ID service and retrieving the JEP106 identification code and SoC revision. Move the existing SMCCC SoC ID handling out of ProcessorSubClassDxe and update the driver to use the new library. Continue to use the MIDR value for the SMBIOS Processor ID when the SMCCC SoC ID service is unavailable. This allows other SMBIOS implementations to reuse the SMCCC handling without duplicating it or depending on the legacy ProcessorSubClassDxe driver. Signed-off-by: Varshit Pandya <Varshit.Pandya@arm.com> --- ArmPkg/ArmPkg.dec | 7 +- ArmPkg/ArmPkg.dsc | 4 +- ArmPkg/Include/Library/ArmSmcccSocIdLib.h | 39 +++++++ .../ArmSmcccSocIdLib/ArmSmcccSocIdLib.c | 110 ++++++++++++++++++ .../ArmSmcccSocIdLib/ArmSmcccSocIdLib.inf | 25 ++++ .../ProcessorSubClassDxe/ProcessorSubClass.c | 2 - .../ProcessorSubClassDxe.inf | 3 +- .../SmbiosProcessorArmCommon.c | 87 ++------------ 8 files changed, 195 insertions(+), 82 deletions(-) create mode 100644 ArmPkg/Include/Library/ArmSmcccSocIdLib.h create mode 100644 ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.c create mode 100644 ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.inf diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index 67ce5ff1a6..8166fdc658 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -2,7 +2,7 @@ # ARM processor package. # # Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR> -# Copyright (c) 2011 - 2023, ARM Limited. All rights reserved. +# Copyright (c) 2011 - 2026, ARM Limited. All rights reserved. # Copyright (c) 2021, Ampere Computing LLC. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -51,6 +51,11 @@ # ArmMonitorLib|Include/Library/ArmMonitorLib.h + ## @libraryclass Provides access to the Arm SMCCC Architecture SoC ID + # interface. + # + ArmSmcccSocIdLib|Include/Library/ArmSmcccSocIdLib.h + ## @libraryclass Provides an interface to query miscellaneous OEM # information. # diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index eb71431ff8..810efcd7c6 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -2,7 +2,7 @@ # ARM processor package. # # Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR> -# Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.<BR> +# Copyright (c) 2011 - 2026, Arm Limited. All rights reserved.<BR> # Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR> # Copyright (c) Microsoft Corporation.<BR> # Copyright (c) 2021, Ampere Computing LLC. All rights reserved. @@ -37,6 +37,7 @@ !include MdePkg/MdeLibs.dsc.inc [LibraryClasses.common] + ArmSmcccSocIdLib|ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf @@ -111,6 +112,7 @@ [Components.common] ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.inf + ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.inf ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf ArmPkg/Library/SemiHostingDebugLib/SemiHostingDebugLib.inf diff --git a/ArmPkg/Include/Library/ArmSmcccSocIdLib.h b/ArmPkg/Include/Library/ArmSmcccSocIdLib.h new file mode 100644 index 0000000000..d6ec35c110 --- /dev/null +++ b/ArmPkg/Include/Library/ArmSmcccSocIdLib.h @@ -0,0 +1,39 @@ +/** @file + Arm SMCCC SoC ID library. + + Copyright (c) 2026, Arm Limited. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#pragma once + +/** + Check whether the SMCCC Architecture SoC ID interface is supported. + + @retval TRUE The SMCCC Architecture SoC ID interface is supported. + @retval FALSE The SMCCC Architecture SoC ID interface is not supported. +**/ +BOOLEAN +ArmSmcccSocIdIsSupported ( + VOID + ); + +/** + Get the JEP106 identification code and SoC revision using the SMCCC + Architecture SoC ID interface. + + @param[out] Jep106Code Pointer to the JEP106 identification code. + @param[out] SocRevision Pointer to the SoC revision. + + @retval EFI_SUCCESS The SoC identification information was + returned successfully. + @retval EFI_INVALID_PARAMETER A required output parameter is NULL. + @retval EFI_UNSUPPORTED The SMCCC Architecture SoC ID interface is + unsupported or an SoC ID call failed. +**/ +EFI_STATUS +ArmSmcccGetSocId ( + OUT UINT32 *Jep106Code, + OUT UINT32 *SocRevision + ); diff --git a/ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.c b/ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.c new file mode 100644 index 0000000000..59e2e79b4e --- /dev/null +++ b/ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.c @@ -0,0 +1,110 @@ +/** @file + Arm SMCCC SoC ID library. + + Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR> + Copyright (c) 2021 - 2022, Ampere Computing LLC. All rights reserved.<BR> + Copyright (c) 2026, Arm Limited. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Uefi.h> + +#include <IndustryStandard/ArmStdSmc.h> + +#include <Library/ArmSmcLib.h> +#include <Library/ArmSmcccSocIdLib.h> + +/** + Check whether the SMCCC Architecture SoC ID interface is supported. + + @retval TRUE The SMCCC Architecture SoC ID interface is supported. + @retval FALSE The SMCCC Architecture SoC ID interface is not supported. +**/ +BOOLEAN +ArmSmcccSocIdIsSupported ( + VOID + ) +{ + INT32 SmcCallStatus; + UINTN SmcParameter; + + SmcCallStatus = ArmCallSmc0 (SMCCC_VERSION, NULL, NULL, NULL); + if ((SmcCallStatus >= 0) && ((SmcCallStatus >> 16) < 1)) { + return FALSE; + } + + SmcParameter = SMCCC_ARCH_SOC_ID; + SmcCallStatus = ArmCallSmc1 ( + SMCCC_ARCH_FEATURES, + &SmcParameter, + NULL, + NULL + ); + + return (SmcCallStatus >= 0); +} + +/** + Get the JEP106 identification code and SoC revision using the SMCCC + Architecture SoC ID interface. + + @param[out] Jep106Code Pointer to the JEP106 identification code. + @param[out] SocRevision Pointer to the SoC revision. + + @retval EFI_SUCCESS The SoC identification information was + returned successfully. + @retval EFI_INVALID_PARAMETER A required output parameter is NULL. + @retval EFI_UNSUPPORTED The SMCCC Architecture SoC ID interface is + unsupported or an SoC ID call failed. +**/ +EFI_STATUS +ArmSmcccGetSocId ( + OUT UINT32 *Jep106Code, + OUT UINT32 *SocRevision + ) +{ + INT32 SmcCallStatus; + UINTN SmcParameter; + UINT32 LocalJep106Code; + UINT32 LocalSocRevision; + + if ((Jep106Code == NULL) || (SocRevision == NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (!ArmSmcccSocIdIsSupported ()) { + return EFI_UNSUPPORTED; + } + + SmcParameter = 0; + SmcCallStatus = ArmCallSmc1 ( + SMCCC_ARCH_SOC_ID, + &SmcParameter, + NULL, + NULL + ); + if (SmcCallStatus < 0) { + return EFI_UNSUPPORTED; + } + + LocalJep106Code = (UINT32)SmcCallStatus; + + SmcParameter = 1; + SmcCallStatus = ArmCallSmc1 ( + SMCCC_ARCH_SOC_ID, + &SmcParameter, + NULL, + NULL + ); + if (SmcCallStatus < 0) { + return EFI_UNSUPPORTED; + } + + LocalSocRevision = (UINT32)SmcCallStatus; + + *Jep106Code = LocalJep106Code; + *SocRevision = LocalSocRevision; + + return EFI_SUCCESS; +} diff --git a/ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.inf b/ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.inf new file mode 100644 index 0000000000..b74ac0fc29 --- /dev/null +++ b/ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.inf @@ -0,0 +1,25 @@ +## @file +# Arm SMCCC SoC ID library. +# +# Copyright (c) 2026, Arm Limited. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 1.30 + BASE_NAME = ArmSmcccSocIdLib + FILE_GUID = 06525cc6-5a4d-4465-be65-186e2e587b1d + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmSmcccSocIdLib + +[Sources] + ArmSmcccSocIdLib.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmSmcLib diff --git a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c index 416e6fb166..b7aad987ca 100644 --- a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c +++ b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c @@ -12,10 +12,8 @@ #include <Uefi.h> #include <Protocol/Smbios.h> #include <IndustryStandard/ArmCache.h> -#include <IndustryStandard/ArmStdSmc.h> #include <IndustryStandard/SmBios.h> #include <Library/ArmLib.h> -#include <Library/ArmSmcLib.h> #include <Library/BaseLib.h> #include <Library/BaseMemoryLib.h> #include <Library/DebugLib.h> diff --git a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassDxe.inf b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassDxe.inf index 79d20399c6..2616077941 100644 --- a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassDxe.inf +++ b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassDxe.inf @@ -4,6 +4,7 @@ # Copyright (c) 2021, NUVIA Inc. All rights reserved. # Copyright (c) 2015, Hisilicon Limited. All rights reserved. # Copyright (c) 2015, Linaro Limited. All rights reserved. +# Copyright (c) 2026, Arm Limited. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -34,7 +35,7 @@ [LibraryClasses] ArmLib - ArmSmcLib + ArmSmcccSocIdLib BaseLib BaseMemoryLib DebugLib diff --git a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/SmbiosProcessorArmCommon.c b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/SmbiosProcessorArmCommon.c index bc9aa7d174..7226969d5c 100644 --- a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/SmbiosProcessorArmCommon.c +++ b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/SmbiosProcessorArmCommon.c @@ -3,6 +3,7 @@ Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR> Copyright (c) 2021 - 2022, Ampere Computing LLC. All rights reserved.<BR> + Copyright (c) 2026, Arm Limited. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -10,10 +11,9 @@ #include <Uefi.h> #include <IndustryStandard/ArmCache.h> -#include <IndustryStandard/ArmStdSmc.h> #include <IndustryStandard/SmBios.h> #include <Library/ArmLib.h> -#include <Library/ArmSmcLib.h> +#include <Library/ArmSmcccSocIdLib.h> #include <Library/BaseMemoryLib.h> #include "SmbiosProcessor.h" @@ -79,75 +79,6 @@ SmbiosProcessorHasSeparateCaches ( return SeparateCaches; } -/** Checks if ther ARM64 SoC ID SMC call is supported - - @return Whether the ARM64 SoC ID call is supported. -**/ -BOOLEAN -HasSmcArm64SocId ( - VOID - ) -{ - INT32 SmcCallStatus; - BOOLEAN Arm64SocIdSupported; - UINTN SmcParam; - - Arm64SocIdSupported = FALSE; - - SmcCallStatus = ArmCallSmc0 (SMCCC_VERSION, NULL, NULL, NULL); - - if ((SmcCallStatus < 0) || ((SmcCallStatus >> 16) >= 1)) { - SmcParam = SMCCC_ARCH_SOC_ID; - SmcCallStatus = ArmCallSmc1 (SMCCC_ARCH_FEATURES, &SmcParam, NULL, NULL); - if (SmcCallStatus >= 0) { - Arm64SocIdSupported = TRUE; - } - } - - return Arm64SocIdSupported; -} - -/** Fetches the JEP106 code and SoC Revision. - - @param Jep106Code JEP 106 code. - @param SocRevision SoC revision. - - @retval EFI_SUCCESS Succeeded. - @retval EFI_UNSUPPORTED Failed. -**/ -EFI_STATUS -SmbiosGetSmcArm64SocId ( - OUT INT32 *Jep106Code, - OUT INT32 *SocRevision - ) -{ - INT32 SmcCallStatus; - EFI_STATUS Status; - UINTN SmcParam; - - Status = EFI_SUCCESS; - - SmcParam = 0; - SmcCallStatus = ArmCallSmc1 (SMCCC_ARCH_SOC_ID, &SmcParam, NULL, NULL); - - if (SmcCallStatus >= 0) { - *Jep106Code = SmcCallStatus; - } else { - Status = EFI_UNSUPPORTED; - } - - SmcParam = 1; - SmcCallStatus = ArmCallSmc1 (SMCCC_ARCH_SOC_ID, &SmcParam, NULL, NULL); - - if (SmcCallStatus >= 0) { - *SocRevision = SmcCallStatus; - } else { - Status = EFI_UNSUPPORTED; - } - - return Status; -} - /** Returns a value for the Processor ID field that conforms to SMBIOS requirements. @@ -158,12 +89,13 @@ SmbiosGetProcessorId ( VOID ) { - INT32 Jep106Code; - INT32 SocRevision; - UINT64 ProcessorId; + EFI_STATUS Status; + UINT32 Jep106Code; + UINT32 SocRevision; + UINT64 ProcessorId; - if (HasSmcArm64SocId ()) { - SmbiosGetSmcArm64SocId (&Jep106Code, &SocRevision); + Status = ArmSmcccGetSocId (&Jep106Code, &SocRevision); + if (!EFI_ERROR (Status)) { ProcessorId = ((UINT64)SocRevision << 32) | Jep106Code; } else { ProcessorId = ArmReadMidr (); @@ -236,7 +168,8 @@ SmbiosGetProcessorCharacteristics ( ZeroMem (&Characteristics, sizeof (Characteristics)); - Characteristics.ProcessorArm64SocId = HasSmcArm64SocId (); + Characteristics.ProcessorArm64SocId = + ArmSmcccSocIdIsSupported (); return Characteristics; } From 984b2fb3bda61ddda065566c72e6e32ea35b67b4 Mon Sep 17 00:00:00 2001 From: VarshitPandya <varshit.pandya@arm.com> Date: Wed, 22 Jul 2026 16:07:24 +0100 Subject: [PATCH 285/406] DynamicTablesPkg: Use ArmSmcccSocIdLib for SoC ID Update SmbiosSmcLib to use ArmSmcccSocIdLib for retrieving the JEP106 identification code and SoC revision. Remove the duplicated SMCCC feature detection and SoC ID calls while retaining the SMBIOS-specific formatting of the Type 4 Processor ID. Signed-off-by: Varshit Pandya <Varshit.Pandya@arm.com> --- DynamicTablesPkg/DynamicTables.dsc.inc | 1 + .../Include/Library/SmbiosSmcLib.h | 17 +-- .../Smbios/Arm/SmbiosSmcLib/SmbiosSmcLib.c | 105 +++--------------- .../Smbios/Arm/SmbiosSmcLib/SmbiosSmcLib.inf | 5 +- 4 files changed, 32 insertions(+), 96 deletions(-) diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index c71abe57a6..a442a29d1e 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -29,6 +29,7 @@ Tpm2DeviceTableLib|DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.inf [LibraryClasses.AARCH64] + ArmSmcccSocIdLib|ArmPkg/Library/ArmSmcccSocIdLib/ArmSmcccSocIdLib.inf DynamicTablesScmiInfoLib|DynamicTablesPkg/Library/DynamicTablesScmiInfoLib/DynamicTablesScmiInfoLib.inf [Components.ARM, Components.AARCH64, Components.X64, Components.RISCV64, Components.LOONGARCH64] diff --git a/DynamicTablesPkg/Include/Library/SmbiosSmcLib.h b/DynamicTablesPkg/Include/Library/SmbiosSmcLib.h index 2f49055efa..bfd0bf7b91 100644 --- a/DynamicTablesPkg/Include/Library/SmbiosSmcLib.h +++ b/DynamicTablesPkg/Include/Library/SmbiosSmcLib.h @@ -1,6 +1,6 @@ /** @file * -* Copyright (c) 2025, ARM Limited. All rights reserved. +* Copyright (c) 2025 - 2026, ARM Limited. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent * @@ -8,14 +8,17 @@ #pragma once -/** Returns the SOC ID, formatted for the SMBIOS Type 4 Processor ID field. +/** + Return the SoC ID formatted for the SMBIOS Type 4 Processor ID field. - @param Processor ID. + @param[out] ProcessorId Pointer to the SMBIOS Processor ID. - @return 0 on success - @return EFI_UNSUPPORTED if SMCCC_ARCH_SOC_ID is not implemented + @retval EFI_SUCCESS The Processor ID was returned successfully. + @retval EFI_INVALID_PARAMETER ProcessorId is NULL. + @retval EFI_UNSUPPORTED The SMCCC Architecture SoC ID interface is + unsupported or an SoC ID call failed. **/ -UINT64 +EFI_STATUS SmbiosSmcGetSocId ( - UINT64 *ProcessorId + OUT UINT64 *ProcessorId ); diff --git a/DynamicTablesPkg/Library/Smbios/Arm/SmbiosSmcLib/SmbiosSmcLib.c b/DynamicTablesPkg/Library/Smbios/Arm/SmbiosSmcLib/SmbiosSmcLib.c index 1e163c86b2..b838f1c4a0 100644 --- a/DynamicTablesPkg/Library/Smbios/Arm/SmbiosSmcLib/SmbiosSmcLib.c +++ b/DynamicTablesPkg/Library/Smbios/Arm/SmbiosSmcLib/SmbiosSmcLib.c @@ -3,111 +3,42 @@ Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR> Copyright (c) 2021 - 2022, Ampere Computing LLC. All rights reserved.<BR> - Copyright (c) 2025, ARM Ltd. All rights reserved.<BR> + Copyright (c) 2025 - 2026, ARM Ltd. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include <Uefi.h> -#include <IndustryStandard/ArmStdSmc.h> -#include <Library/ArmSmcLib.h> +#include <Library/ArmSmcccSocIdLib.h> #include <Library/SmbiosSmcLib.h> -/** Checks if the ARM64 SoC ID SMC call is supported +/** + Return the SoC ID formatted for the SMBIOS Type 4 Processor ID field. - @return Whether the ARM64 SoC ID call is supported. + @param[out] ProcessorId Pointer to the SMBIOS Processor ID. + + @retval EFI_SUCCESS The Processor ID was returned successfully. + @retval EFI_INVALID_PARAMETER ProcessorId is NULL. + @retval EFI_UNSUPPORTED The SMCCC Architecture SoC ID interface is + unsupported or an SoC ID call failed. **/ -STATIC -BOOLEAN -HasSmcArm64SocId ( - VOID - ) -{ - INT32 SmcCallStatus; - BOOLEAN Arm64SocIdSupported; - UINTN SmcParam; - - Arm64SocIdSupported = FALSE; - - SmcCallStatus = ArmCallSmc0 (SMCCC_VERSION, NULL, NULL, NULL); - - if ((SmcCallStatus < 0) || ((SmcCallStatus >> 16) >= 1)) { - SmcParam = SMCCC_ARCH_SOC_ID; - SmcCallStatus = ArmCallSmc1 (SMCCC_ARCH_FEATURES, &SmcParam, NULL, NULL); - if (SmcCallStatus >= 0) { - Arm64SocIdSupported = TRUE; - } - } - - return Arm64SocIdSupported; -} - -/** Fetches the JEP106 code and SoC Revision. - - @param Jep106Code JEP 106 code. - @param SocRevision SoC revision. - - @retval EFI_SUCCESS Succeeded. - @retval EFI_UNSUPPORTED Failed. -**/ -STATIC EFI_STATUS -SmbiosGetSmcArm64SocId ( - OUT UINT32 *Jep106Code, - OUT UINT32 *SocRevision - ) -{ - INT32 SmcCallStatus; - EFI_STATUS Status; - UINTN SmcParam; - - Status = EFI_SUCCESS; - - SmcParam = 0; - SmcCallStatus = ArmCallSmc1 (SMCCC_ARCH_SOC_ID, &SmcParam, NULL, NULL); - - if (SmcCallStatus >= 0) { - *Jep106Code = (UINT32)SmcCallStatus; - } else { - Status = EFI_UNSUPPORTED; - } - - SmcParam = 1; - SmcCallStatus = ArmCallSmc1 (SMCCC_ARCH_SOC_ID, &SmcParam, NULL, NULL); - - if (SmcCallStatus >= 0) { - *SocRevision = (UINT32)SmcCallStatus; - } else { - Status = EFI_UNSUPPORTED; - } - - return Status; -} - -/** Returns the SOC ID, formatted for the SMBIOS Type 4 Processor ID field. - - @param Processor ID. - - @return 0 on success - @return EFI_UNSUPPORTED if SMCCC_ARCH_SOC_ID is not implemented -**/ -UINT64 SmbiosSmcGetSocId ( - UINT64 *ProcessorId + OUT UINT64 *ProcessorId ) { EFI_STATUS Status; UINT32 Jep106Code; UINT32 SocRevision; - if (HasSmcArm64SocId ()) { - Status = SmbiosGetSmcArm64SocId (&Jep106Code, &SocRevision); - if (!EFI_ERROR (Status)) { - *ProcessorId = ((UINT64)SocRevision << 32) | Jep106Code; - } - } else { - Status = EFI_UNSUPPORTED; + if (ProcessorId == NULL) { + return EFI_INVALID_PARAMETER; + } + + Status = ArmSmcccGetSocId (&Jep106Code, &SocRevision); + if (!EFI_ERROR (Status)) { + *ProcessorId = ((UINT64)SocRevision << 32) | Jep106Code; } return Status; diff --git a/DynamicTablesPkg/Library/Smbios/Arm/SmbiosSmcLib/SmbiosSmcLib.inf b/DynamicTablesPkg/Library/Smbios/Arm/SmbiosSmcLib/SmbiosSmcLib.inf index ea43c0784a..ab95d443a3 100644 --- a/DynamicTablesPkg/Library/Smbios/Arm/SmbiosSmcLib/SmbiosSmcLib.inf +++ b/DynamicTablesPkg/Library/Smbios/Arm/SmbiosSmcLib/SmbiosSmcLib.inf @@ -1,6 +1,6 @@ #/** @file # -# Copyright (c) 2025, ARM Ltd. All rights reserved.<BR> +# Copyright (c) 2025 - 2026, ARM Ltd. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -18,9 +18,10 @@ SmbiosSmcLib.c [Packages] + ArmPkg/ArmPkg.dec DynamicTablesPkg/DynamicTablesPkg.dec MdePkg/MdePkg.dec [LibraryClasses] - ArmSmcLib + ArmSmcccSocIdLib From 479a79c57f2a9de05caa516dc6befdcfe02f24ad Mon Sep 17 00:00:00 2001 From: rdiaz <raymonddiaz@microsoft.com> Date: Thu, 25 Jun 2026 21:47:40 +0000 Subject: [PATCH 286/406] MdePkg,SecurityPkg: Fix TPM2 ACPI Table Updated the ACPI code to fix an issue where the template was outdated and the revision was reporting V5 but the template was still using the V4 version of the Start Method specific parameters. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com> --- MdePkg/Include/IndustryStandard/Tpm2Acpi.h | 74 +++++++++- SecurityPkg/Tcg/Tcg2Acpi/Tcg2Acpi.c | 149 +++++++++++---------- SecurityPkg/Tcg/Tcg2AcpiFfa/Tcg2AcpiFfa.c | 140 ++++++++----------- 3 files changed, 203 insertions(+), 160 deletions(-) diff --git a/MdePkg/Include/IndustryStandard/Tpm2Acpi.h b/MdePkg/Include/IndustryStandard/Tpm2Acpi.h index 454581d1d3..77c6cd0a4a 100644 --- a/MdePkg/Include/IndustryStandard/Tpm2Acpi.h +++ b/MdePkg/Include/IndustryStandard/Tpm2Acpi.h @@ -23,17 +23,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_5 16 #define EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_5 +// Flags field is replaced in version 4 and above: +// BIT0~15: PlatformClass This field is only valid for version 4 and above +// BIT16~31: Reserved typedef struct { EFI_ACPI_DESCRIPTION_HEADER Header; - // Flags field is replaced in version 4 and above - // BIT0~15: PlatformClass This field is only valid for version 4 and above - // BIT16~31: Reserved UINT32 Flags; UINT64 AddressOfControlArea; UINT32 StartMethod; - // UINT8 PlatformSpecificParameters[]; // size up to 16 - // UINT32 Laml; // Optional - // UINT64 Lasa; // Optional } EFI_TPM2_ACPI_TABLE; #define EFI_TPM2_ACPI_TABLE_START_METHOD_ACPI 2 @@ -63,7 +60,8 @@ typedef struct { UINT32 Interrupt; UINT8 Flags; UINT8 OperationFlags; - UINT8 Reserved[2]; + UINT8 Attributes; + UINT8 Reserved; UINT32 SmcFunctionId; } EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_ARM_SMC; @@ -79,6 +77,68 @@ typedef struct { UINT8 Reserved[8]; } EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_ARM_FFA; +typedef union { + UINT8 PlatformSpecificParameters[EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4]; + EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_ARM_SMC SmcParameters; +} EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_V4; +STATIC_ASSERT ( + sizeof (EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_V4) == EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4, + "EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_V4 size mismatch" + ); + +typedef struct { + EFI_ACPI_DESCRIPTION_HEADER Header; + UINT32 Flags; + UINT64 AddressOfControlArea; + UINT32 StartMethod; + + // StartMethodSpecificParameters is variable in size and LAML/LASA are + // optional fields. It is the user's responsibility to access the + // Header.Length field to determine what is accessible in the table. + EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_V4 StartMethodSpecificParameters; + + UINT32 Laml; // Optional + UINT64 Lasa; // Optional +} EFI_TPM2_ACPI_TABLE_V4; + +typedef union { + UINT8 PlatformSpecificParameters[EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_5]; + EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_ARM_SMC SmcParameters; + EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_ARM_FFA FfaParameters; +} EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_V5; +STATIC_ASSERT ( + sizeof (EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_V5) == EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_5, + "EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_V5 size mismatch" + ); + +typedef struct { + EFI_ACPI_DESCRIPTION_HEADER Header; + UINT32 Flags; + UINT64 AddressOfControlArea; + UINT32 StartMethod; + + // StartMethodSpecificParameters is variable in size and LAML/LASA are + // optional fields. It is the user's responsibility to access the + // Header.Length field to determine what is accessible in the table. + EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_V5 StartMethodSpecificParameters; + + UINT32 Laml; // Optional + UINT64 Lasa; // Optional +} EFI_TPM2_ACPI_TABLE_V5; + +typedef struct { + EFI_ACPI_DESCRIPTION_HEADER Header; + UINT32 Flags; + UINT64 AddressOfControlArea; + UINT32 StartMethod; + UINT8 PlatformSpecificParameters[EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE]; + UINT32 Laml; // Optional + UINT64 Lasa; // Optional +} EFI_TPM2_ACPI_TABLE_TEMPLATE; + +// Mask for the PlatformClass field (BIT0~15) within the Flags field +#define EFI_TPM2_ACPI_TABLE_FLAGS_PLATFORM_CLASS_MASK 0x0000FFFF + #define EFI_TPM2_ACPI_TABLE_ARM_FFA_PARAMETER_FLAG_NOTIFICATION_SUPPORT BIT0 #define EFI_TPM2_ACPI_TABLE_ARM_FFA_PARAMETER_ATTR_MEM_TYPE_MASK 0x3 diff --git a/SecurityPkg/Tcg/Tcg2Acpi/Tcg2Acpi.c b/SecurityPkg/Tcg/Tcg2Acpi/Tcg2Acpi.c index d295f9aa28..5d26f1cd6a 100644 --- a/SecurityPkg/Tcg/Tcg2Acpi/Tcg2Acpi.c +++ b/SecurityPkg/Tcg/Tcg2Acpi/Tcg2Acpi.c @@ -74,39 +74,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // #define MAX_PRS_INT_BUF_SIZE (15*4) -#pragma pack(1) - -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - // Flags field is replaced in version 4 and above - // BIT0~15: PlatformClass This field is only valid for version 4 and above - // BIT16~31: Reserved - UINT32 Flags; - UINT64 AddressOfControlArea; - UINT32 StartMethod; - UINT8 PlatformSpecificParameters[12]; // size up to 12 - UINT32 Laml; // Optional - UINT64 Lasa; // Optional -} EFI_TPM2_ACPI_TABLE_V4; - -#pragma pack() - -EFI_TPM2_ACPI_TABLE_V4 mTpm2AcpiTemplate = { - { - EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE, - sizeof (mTpm2AcpiTemplate), - EFI_TPM2_ACPI_TABLE_REVISION, - // - // Compiler initializes the remaining bytes to 0 - // These fields should be filled in in production - // - }, - 0, // BIT0~15: PlatformClass - // BIT16~31: Reserved - 0, // Control Area - EFI_TPM2_ACPI_TABLE_START_METHOD_TIS, // StartMethod -}; - TCG_NVS *mTcgNvs; /** @@ -780,12 +747,18 @@ PublishTpm2 ( VOID ) { - EFI_STATUS Status; - EFI_ACPI_TABLE_PROTOCOL *AcpiTable; - UINTN TableKey; - UINT64 OemTableId; - EFI_TPM2_ACPI_CONTROL_AREA *ControlArea; - TPM2_PTP_INTERFACE_TYPE InterfaceType; + EFI_STATUS Status; + EFI_ACPI_TABLE_PROTOCOL *AcpiTable; + UINTN TableKey; + UINT64 OemTableId; + EFI_TPM2_ACPI_CONTROL_AREA *ControlArea; + TPM2_PTP_INTERFACE_TYPE InterfaceType; + EFI_TPM2_ACPI_TABLE_V4 *Tpm2AcpiTableV4; + EFI_TPM2_ACPI_TABLE_V5 *Tpm2AcpiTableV5; + EFI_TPM2_ACPI_TABLE_TEMPLATE Tpm2AcpiTemplate; + + // Zero the template so its measured contents are deterministic. + ZeroMem (&Tpm2AcpiTemplate, sizeof (Tpm2AcpiTemplate)); // // Measure to PCR[0] with event EV_POST_CODE ACPI DATA. @@ -798,70 +771,106 @@ PublishTpm2 ( EV_POST_CODE, EV_POSTCODE_INFO_ACPI_DATA, ACPI_DATA_LEN, - &mTpm2AcpiTemplate, - mTpm2AcpiTemplate.Header.Length + &Tpm2AcpiTemplate, + sizeof (EFI_TPM2_ACPI_TABLE_TEMPLATE) ); - mTpm2AcpiTemplate.Header.Revision = PcdGet8 (PcdTpm2AcpiTableRev); - DEBUG ((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", mTpm2AcpiTemplate.Header.Revision)); + Tpm2AcpiTemplate.Header.Signature = EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE; + Tpm2AcpiTemplate.Header.Revision = PcdGet8 (PcdTpm2AcpiTableRev); + DEBUG ((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", Tpm2AcpiTemplate.Header.Revision)); // // PlatformClass is only valid for version 4 and above // BIT0~15: PlatformClass // BIT16~31: Reserved // - if (mTpm2AcpiTemplate.Header.Revision >= EFI_TPM2_ACPI_TABLE_REVISION_4) { - mTpm2AcpiTemplate.Flags = (mTpm2AcpiTemplate.Flags & 0xFFFF0000) | PcdGet8 (PcdTpmPlatformClass); - DEBUG ((DEBUG_INFO, "Tpm2 ACPI table PlatformClass is %d\n", (mTpm2AcpiTemplate.Flags & 0x0000FFFF))); + if (Tpm2AcpiTemplate.Header.Revision >= EFI_TPM2_ACPI_TABLE_REVISION_4) { + Tpm2AcpiTemplate.Flags = (Tpm2AcpiTemplate.Flags & 0xFFFF0000) | PcdGet8 (PcdTpmPlatformClass); + DEBUG ((DEBUG_INFO, "Tpm2 ACPI table PlatformClass is %d\n", (Tpm2AcpiTemplate.Flags & 0x0000FFFF))); } - mTpm2AcpiTemplate.Laml = PcdGet32 (PcdTpm2AcpiTableLaml); - mTpm2AcpiTemplate.Lasa = PcdGet64 (PcdTpm2AcpiTableLasa); - if ((mTpm2AcpiTemplate.Header.Revision < EFI_TPM2_ACPI_TABLE_REVISION_4) || - (mTpm2AcpiTemplate.Laml == 0) || (mTpm2AcpiTemplate.Lasa == 0)) - { - // - // If version is smaller than 4 or Laml/Lasa is not valid, rollback to original Length. - // - mTpm2AcpiTemplate.Header.Length = sizeof (EFI_TPM2_ACPI_TABLE); + switch (Tpm2AcpiTemplate.Header.Revision) { + case EFI_TPM2_ACPI_TABLE_REVISION_3: + Tpm2AcpiTemplate.Header.Length = sizeof (EFI_TPM2_ACPI_TABLE); + break; + + case EFI_TPM2_ACPI_TABLE_REVISION_4: + Tpm2AcpiTemplate.Header.Length = sizeof (EFI_TPM2_ACPI_TABLE_V4); + Tpm2AcpiTableV4 = (EFI_TPM2_ACPI_TABLE_V4 *)&Tpm2AcpiTemplate; + Tpm2AcpiTableV4->Laml = PcdGet32 (PcdTpm2AcpiTableLaml); + Tpm2AcpiTableV4->Lasa = PcdGet64 (PcdTpm2AcpiTableLasa); + + if ((Tpm2AcpiTableV4->Laml == 0) || (Tpm2AcpiTableV4->Lasa == 0)) { + // Remove LAML/LASA from the length if either is 0. + Tpm2AcpiTemplate.Header.Length = OFFSET_OF (EFI_TPM2_ACPI_TABLE_V4, Laml); + } + + break; + + case EFI_TPM2_ACPI_TABLE_REVISION_5: + Tpm2AcpiTemplate.Header.Length = sizeof (EFI_TPM2_ACPI_TABLE_V5); + Tpm2AcpiTableV5 = (EFI_TPM2_ACPI_TABLE_V5 *)&Tpm2AcpiTemplate; + Tpm2AcpiTableV5->Laml = PcdGet32 (PcdTpm2AcpiTableLaml); + Tpm2AcpiTableV5->Lasa = PcdGet64 (PcdTpm2AcpiTableLasa); + + if ((Tpm2AcpiTableV5->Laml == 0) || (Tpm2AcpiTableV5->Lasa == 0)) { + // Remove LAML/LASA from the length if either is 0. + Tpm2AcpiTemplate.Header.Length = OFFSET_OF (EFI_TPM2_ACPI_TABLE_V5, Laml); + } + + break; + + default: + Tpm2AcpiTemplate.Header.Length = sizeof (EFI_TPM2_ACPI_TABLE_TEMPLATE); + DEBUG ((DEBUG_ERROR, "TPM2 revision get error! %d\n", Tpm2AcpiTemplate.Header.Revision)); + ASSERT (FALSE); + return EFI_INVALID_PARAMETER; } + DEBUG ((DEBUG_INFO, "Tpm2 ACPI table size %d\n", Tpm2AcpiTemplate.Header.Length)); + InterfaceType = PcdGet8 (PcdActiveTpmInterfaceType); switch (InterfaceType) { case Tpm2PtpInterfaceCrb: - mTpm2AcpiTemplate.StartMethod = EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE; - mTpm2AcpiTemplate.AddressOfControlArea = PcdGet64 (PcdTpmBaseAddress) + 0x40; - ControlArea = (EFI_TPM2_ACPI_CONTROL_AREA *)(UINTN)mTpm2AcpiTemplate.AddressOfControlArea; - ControlArea->CommandSize = 0xF80; - ControlArea->ResponseSize = 0xF80; - ControlArea->Command = PcdGet64 (PcdTpmBaseAddress) + 0x80; - ControlArea->Response = PcdGet64 (PcdTpmBaseAddress) + 0x80; + Tpm2AcpiTemplate.StartMethod = EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE; + Tpm2AcpiTemplate.AddressOfControlArea = PcdGet64 (PcdTpmBaseAddress) + 0x40; + ControlArea = (EFI_TPM2_ACPI_CONTROL_AREA *)(UINTN)Tpm2AcpiTemplate.AddressOfControlArea; + ControlArea->CommandSize = 0xF80; + ControlArea->ResponseSize = 0xF80; + ControlArea->Command = PcdGet64 (PcdTpmBaseAddress) + 0x80; + ControlArea->Response = PcdGet64 (PcdTpmBaseAddress) + 0x80; break; case Tpm2PtpInterfaceFifo: case Tpm2PtpInterfaceTis: + Tpm2AcpiTemplate.StartMethod = EFI_TPM2_ACPI_TABLE_START_METHOD_TIS; break; default: DEBUG ((DEBUG_ERROR, "TPM2 InterfaceType get error! %d\n", InterfaceType)); + ASSERT (FALSE); + return EFI_INVALID_PARAMETER; break; } - CopyMem (mTpm2AcpiTemplate.Header.OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (mTpm2AcpiTemplate.Header.OemId)); + CopyMem (Tpm2AcpiTemplate.Header.OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (Tpm2AcpiTemplate.Header.OemId)); OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId); - CopyMem (&mTpm2AcpiTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64)); - mTpm2AcpiTemplate.Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision); - mTpm2AcpiTemplate.Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId); - mTpm2AcpiTemplate.Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision); + CopyMem (&Tpm2AcpiTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64)); + Tpm2AcpiTemplate.Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision); + Tpm2AcpiTemplate.Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId); + Tpm2AcpiTemplate.Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision); // // Construct ACPI table // Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **)&AcpiTable); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + ASSERT (FALSE); + return Status; + } Status = AcpiTable->InstallAcpiTable ( AcpiTable, - &mTpm2AcpiTemplate, - mTpm2AcpiTemplate.Header.Length, + &Tpm2AcpiTemplate, + Tpm2AcpiTemplate.Header.Length, &TableKey ); ASSERT_EFI_ERROR (Status); diff --git a/SecurityPkg/Tcg/Tcg2AcpiFfa/Tcg2AcpiFfa.c b/SecurityPkg/Tcg/Tcg2AcpiFfa/Tcg2AcpiFfa.c index 8791d06c74..c51433ca5d 100644 --- a/SecurityPkg/Tcg/Tcg2AcpiFfa/Tcg2AcpiFfa.c +++ b/SecurityPkg/Tcg/Tcg2AcpiFfa/Tcg2AcpiFfa.c @@ -66,39 +66,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // #define MAX_PRS_INT_BUF_SIZE (15*4) -#pragma pack(1) - -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - // Flags field is replaced in version 4 and above - // BIT0~15: PlatformClass This field is only valid for version 4 and above - // BIT16~31: Reserved - UINT32 Flags; - UINT64 AddressOfControlArea; - UINT32 StartMethod; - EFI_TPM2_ACPI_START_METHOD_SPECIFIC_PARAMETERS_ARM_FFA FfaParameters; - UINT32 Laml; // Optional - UINT64 Lasa; // Optional -} EFI_TPM2_ACPI_TABLE_V5; - -#pragma pack() - -EFI_TPM2_ACPI_TABLE_V5 mTpm2AcpiTemplate = { - { - EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE, - sizeof (mTpm2AcpiTemplate), - EFI_TPM2_ACPI_TABLE_REVISION, - // - // Compiler initializes the remaining bytes to 0 - // These fields should be filled in in production - // - }, - 0, // BIT0~15: PlatformClass - // BIT16~31: Reserved - 0, // Control Area - EFI_TPM2_ACPI_TABLE_START_METHOD_TIS, // StartMethod -}; - /** Patch version string of Physical Presence interface supported by platform. The initial string tag in TPM ACPI table is "$PV". @@ -334,16 +301,20 @@ PublishTpm2 ( VOID ) { - EFI_STATUS Status; - EFI_ACPI_TABLE_PROTOCOL *AcpiTable; - UINTN TableKey; - UINT64 OemTableId; - EFI_TPM2_ACPI_CONTROL_AREA *ControlArea; - TPM2_PTP_INTERFACE_TYPE InterfaceType; - UINT64 PartitionId; + EFI_STATUS Status; + EFI_ACPI_TABLE_PROTOCOL *AcpiTable; + UINTN TableKey; + UINT64 OemTableId; + EFI_TPM2_ACPI_CONTROL_AREA *ControlArea; + TPM2_PTP_INTERFACE_TYPE InterfaceType; + EFI_TPM2_ACPI_TABLE_V5 *Tpm2AcpiTableV5; + EFI_TPM2_ACPI_TABLE_TEMPLATE Tpm2AcpiTemplate; STATIC_ASSERT ((FixedPcdGet64 (PcdTpmMaxAddress) - FixedPcdGet64 (PcdTpmBaseAddress)) == (FixedPcdGet32 (PcdTpmCrbRegionSize) - 1), "TPM CRB region size mismatch"); + // Zero the template so its measured contents are deterministic. + ZeroMem (&Tpm2AcpiTemplate, sizeof (Tpm2AcpiTemplate)); + // // Measure to PCR[0] with event EV_POST_CODE ACPI DATA. // The measurement has to be done before any update. @@ -355,61 +326,64 @@ PublishTpm2 ( EV_POST_CODE, EV_POSTCODE_INFO_ACPI_DATA, ACPI_DATA_LEN, - &mTpm2AcpiTemplate, - mTpm2AcpiTemplate.Header.Length + &Tpm2AcpiTemplate, + sizeof (EFI_TPM2_ACPI_TABLE_TEMPLATE) ); - mTpm2AcpiTemplate.Header.Revision = PcdGet8 (PcdTpm2AcpiTableRev); - DEBUG ((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", mTpm2AcpiTemplate.Header.Revision)); + Tpm2AcpiTemplate.Header.Signature = EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE; + Tpm2AcpiTemplate.Header.Length = sizeof (EFI_TPM2_ACPI_TABLE_V5); + Tpm2AcpiTemplate.Header.Revision = PcdGet8 (PcdTpm2AcpiTableRev); + DEBUG ((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", Tpm2AcpiTemplate.Header.Revision)); - if (mTpm2AcpiTemplate.Header.Revision < EFI_TPM2_ACPI_TABLE_REVISION_5) { - DEBUG ((DEBUG_ERROR, "%a The minimum revision supported for TPM over FFA table is 5, not %d.\n", __func__, mTpm2AcpiTemplate.Header.Revision)); + // FF-A is only supported in revisions 5 and up. + if (Tpm2AcpiTemplate.Header.Revision != EFI_TPM2_ACPI_TABLE_REVISION_5) { + DEBUG ((DEBUG_ERROR, "%a The minimum revision supported for TPM over FF-A table is 5 not %d\n", __func__, Tpm2AcpiTemplate.Header.Revision)); ASSERT (FALSE); return EFI_UNSUPPORTED; } - mTpm2AcpiTemplate.Flags = (mTpm2AcpiTemplate.Flags & 0xFFFF0000) | PcdGet8 (PcdTpmPlatformClass); - DEBUG ((DEBUG_INFO, "Tpm2 ACPI table PlatformClass is %d\n", (mTpm2AcpiTemplate.Flags & 0x0000FFFF))); - - mTpm2AcpiTemplate.Laml = PcdGet32 (PcdTpm2AcpiTableLaml); - mTpm2AcpiTemplate.Lasa = PcdGet64 (PcdTpm2AcpiTableLasa); - if ((mTpm2AcpiTemplate.Laml == 0) || (mTpm2AcpiTemplate.Lasa == 0)) { - // - // If version is smaller than 4 or Laml/Lasa is not valid, rollback to original Length. - // - mTpm2AcpiTemplate.Header.Length = sizeof (EFI_TPM2_ACPI_TABLE); - } - + // CRB over FF-A only supports the CRB interface type. InterfaceType = PcdGet8 (PcdActiveTpmInterfaceType); DEBUG ((DEBUG_INFO, "Tpm Active Interface Type %d\n", InterfaceType)); - - PartitionId = PcdGet16 (PcdTpmServiceFfaPartitionId); - ASSERT (PartitionId != 0); - if (InterfaceType == Tpm2PtpInterfaceCrb) { - mTpm2AcpiTemplate.StartMethod = EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_FFA; - mTpm2AcpiTemplate.AddressOfControlArea = PcdGet64 (PcdTpmBaseAddress) + 0x40; - mTpm2AcpiTemplate.FfaParameters.Flags = 0x00; // Notifications Not Supported - mTpm2AcpiTemplate.FfaParameters.Attributes = (EFI_TPM2_ACPI_TABLE_ARM_FFA_PARAMETER_ATTR_CRB_REGION_SIZE_4KB << EFI_TPM2_ACPI_TABLE_ARM_FFA_PARAMETER_ATTR_CRB_REGION_SIZE_SHIFT) | - (EFI_TPM2_ACPI_TABLE_ARM_FFA_PARAMETER_ATTR_MEM_TYPE_NOT_CACHEABLE << EFI_TPM2_ACPI_TABLE_ARM_FFA_PARAMETER_ATTR_MEM_TYPE_SHIFT); - mTpm2AcpiTemplate.FfaParameters.PartitionId = PartitionId; // Partition ID - ControlArea = (EFI_TPM2_ACPI_CONTROL_AREA *)(UINTN)mTpm2AcpiTemplate.AddressOfControlArea; - ControlArea->CommandSize = 0xF80; - ControlArea->ResponseSize = 0xF80; - ControlArea->Command = PcdGet64 (PcdTpmBaseAddress) + 0x80; - ControlArea->Response = PcdGet64 (PcdTpmBaseAddress) + 0x80; - } else { - DEBUG ((DEBUG_ERROR, "TPM2 InterfaceType get error! %d\n", InterfaceType)); + if (InterfaceType != Tpm2PtpInterfaceCrb) { + DEBUG ((DEBUG_ERROR, "TPM over FF-A only supports CRB interface\n")); return EFI_UNSUPPORTED; } - DEBUG ((DEBUG_INFO, "Tpm2 ACPI table size %d\n", mTpm2AcpiTemplate.Header.Length)); + Tpm2AcpiTemplate.Flags = (Tpm2AcpiTemplate.Flags & ~EFI_TPM2_ACPI_TABLE_FLAGS_PLATFORM_CLASS_MASK) | PcdGet8 (PcdTpmPlatformClass); + DEBUG ((DEBUG_INFO, "Tpm2 ACPI table PlatformClass is %d\n", (Tpm2AcpiTemplate.Flags & EFI_TPM2_ACPI_TABLE_FLAGS_PLATFORM_CLASS_MASK))); - CopyMem (mTpm2AcpiTemplate.Header.OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (mTpm2AcpiTemplate.Header.OemId)); + Tpm2AcpiTableV5 = (EFI_TPM2_ACPI_TABLE_V5 *)&Tpm2AcpiTemplate; + Tpm2AcpiTableV5->Laml = PcdGet32 (PcdTpm2AcpiTableLaml); + Tpm2AcpiTableV5->Lasa = PcdGet64 (PcdTpm2AcpiTableLasa); + if ((Tpm2AcpiTableV5->Laml == 0) || (Tpm2AcpiTableV5->Lasa == 0)) { + // Remove LAML/LASA from the length if either is 0. + Tpm2AcpiTemplate.Header.Length = OFFSET_OF (EFI_TPM2_ACPI_TABLE_V5, Laml); + } + + DEBUG ((DEBUG_INFO, "Tpm2 ACPI table size %d\n", Tpm2AcpiTemplate.Header.Length)); + + Tpm2AcpiTemplate.StartMethod = EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_FFA; + Tpm2AcpiTemplate.AddressOfControlArea = PcdGet64 (PcdTpmBaseAddress) + 0x40; + ControlArea = (EFI_TPM2_ACPI_CONTROL_AREA *)(UINTN)Tpm2AcpiTemplate.AddressOfControlArea; + ControlArea->CommandSize = 0xF80; + ControlArea->ResponseSize = 0xF80; + ControlArea->Command = PcdGet64 (PcdTpmBaseAddress) + 0x80; + ControlArea->Response = PcdGet64 (PcdTpmBaseAddress) + 0x80; + + // Set the FF-A specific parameters. + Tpm2AcpiTableV5->StartMethodSpecificParameters.FfaParameters.Flags = 0x00; // Notifications Not Supported + Tpm2AcpiTableV5->StartMethodSpecificParameters.FfaParameters.Attributes = (EFI_TPM2_ACPI_TABLE_ARM_FFA_PARAMETER_ATTR_CRB_REGION_SIZE_4KB << EFI_TPM2_ACPI_TABLE_ARM_FFA_PARAMETER_ATTR_CRB_REGION_SIZE_SHIFT) | + (EFI_TPM2_ACPI_TABLE_ARM_FFA_PARAMETER_ATTR_MEM_TYPE_NOT_CACHABLE << EFI_TPM2_ACPI_TABLE_ARM_FFA_PARAMETER_ATTR_MEM_TYPE_SHIFT); + Tpm2AcpiTableV5->StartMethodSpecificParameters.FfaParameters.PartitionId = PcdGet16 (PcdTpmServiceFfaPartitionId); + ASSERT (Tpm2AcpiTableV5->StartMethodSpecificParameters.FfaParameters.PartitionId != 0); + + CopyMem (Tpm2AcpiTemplate.Header.OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (Tpm2AcpiTemplate.Header.OemId)); OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId); - CopyMem (&mTpm2AcpiTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64)); - mTpm2AcpiTemplate.Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision); - mTpm2AcpiTemplate.Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId); - mTpm2AcpiTemplate.Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision); + CopyMem (&Tpm2AcpiTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64)); + Tpm2AcpiTemplate.Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision); + Tpm2AcpiTemplate.Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId); + Tpm2AcpiTemplate.Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision); // // Construct ACPI table @@ -419,8 +393,8 @@ PublishTpm2 ( Status = AcpiTable->InstallAcpiTable ( AcpiTable, - &mTpm2AcpiTemplate, - mTpm2AcpiTemplate.Header.Length, + &Tpm2AcpiTemplate, + Tpm2AcpiTemplate.Header.Length, &TableKey ); ASSERT_EFI_ERROR (Status); From a9670673255f1e0c3755d3eed442ee8e147c5c3d Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Fri, 19 Jun 2026 07:17:42 -0700 Subject: [PATCH 287/406] pip-requirements.txt: Upgrade Pytool Lib for VS2026 Support This pulls in the latest edk2-pytool-library which includes support for locating VS2026. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- pip-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pip-requirements.txt b/pip-requirements.txt index 6680c90d07..0773262171 100644 --- a/pip-requirements.txt +++ b/pip-requirements.txt @@ -12,7 +12,7 @@ # https://www.python.org/dev/peps/pep-0440/#version-specifiers ## -edk2-pytool-library~=0.23.13 +edk2-pytool-library~=0.23.14 edk2-pytool-extensions~=0.31.0 antlr4-python3-runtime==4.13.2 lcov-cobertura==2.1.1 From 69cf33dd9d5c7bf40411140a4e087ee8c4df229b Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Fri, 19 Jun 2026 07:18:37 -0700 Subject: [PATCH 288/406] BaseTools: Default Windows Build to VS2026 edk2 is moving to VS2026 for the MSVC toolchain, as such, upgrade the Windows BaseTools build default from VS2022 -> VS2026. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- BaseTools/Edk2ToolsBuild.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseTools/Edk2ToolsBuild.py b/BaseTools/Edk2ToolsBuild.py index 4d9dc08842..5d9f53d1d9 100644 --- a/BaseTools/Edk2ToolsBuild.py +++ b/BaseTools/Edk2ToolsBuild.py @@ -1,7 +1,7 @@ # @file Edk2ToolsBuild.py # Invocable class that builds the basetool c files. # -# Supports VS2019, VS2022, and GCC +# Supports VS2019, VS2022, VS2026, and GCC ## # Copyright (c) Microsoft Corporation # @@ -25,7 +25,7 @@ class Edk2ToolsBuild(BaseAbstractInvocable): def ParseCommandLineOptions(self): ''' parse arguments ''' ParserObj = argparse.ArgumentParser() - ParserObj.add_argument("-t", "--tool_chain_tag", dest="tct", default="VS2022", + ParserObj.add_argument("-t", "--tool_chain_tag", dest="tct", default="VS2026", help="Set the toolchain used to compile the build tools") ParserObj.add_argument("-a", "--target_arch", dest="arch", default=None, choices=[None, 'IA32', 'X64', 'AARCH64'], help="Specify the architecture of the built base tools. Not specifying this will fall back to the default " From 80c428c1fe74c32313d7f6b7de9da9a8fdb5ab6c Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Fri, 19 Jun 2026 07:19:46 -0700 Subject: [PATCH 289/406] PrmPkg: Update Readmes for VS2026 edk2 is moving to VS2026 for the MSVC toolchain. Update examples accordingly. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- PrmPkg/Readme.md | 4 ++-- PrmPkg/Samples/Readme.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PrmPkg/Readme.md b/PrmPkg/Readme.md index 03e892b609..923721e946 100644 --- a/PrmPkg/Readme.md +++ b/PrmPkg/Readme.md @@ -97,8 +97,8 @@ the package being built. Like a typical EDK II package, the PrmPkg binary build output can be found in the Build directory in the edk2 workspace. The organization in that directory follows the same layout as other EDK II packages. -For example, that path to PRM module sample binaries for a DEBUG VS2022 X64 build is: \ -``edk2/Build/Prm/DEBUG_VS2022/X64/PrmPkg/Samples`` +For example, that path to PRM module sample binaries for a DEBUG VS2026 X64 build is: \ +``edk2/Build/Prm/DEBUG_VS2026/X64/PrmPkg/Samples`` ## Overview diff --git a/PrmPkg/Samples/Readme.md b/PrmPkg/Samples/Readme.md index 1ba4e839f7..bdeb51affd 100644 --- a/PrmPkg/Samples/Readme.md +++ b/PrmPkg/Samples/Readme.md @@ -16,7 +16,7 @@ The sample modules are built as part of the normal `PrmPkg` build so you can fol workspace build output directory. For example, if your build workspace is called "edk2" and you build 64-bit binaries on the Visual Studio 2017 tool chain, your sample module binaries will be in the following location: \ -``edk2/Build/Prm/DEBUG_VS2022/X64/PrmPkg/Samples`` +``edk2/Build/Prm/DEBUG_VS2026/X64/PrmPkg/Samples`` ### Build an Individual PRM Sample Module @@ -26,7 +26,7 @@ the module INF file with the "-m" argument to `build`. For example, this command with Visual Studio 2022: \ ```shell -build -p PrmPkg/PrmPkg.dsc -m PrmPkg/Samples/PrmSampleContextBufferModule/PrmSampleContextBufferModule.inf -a X64 -t VS2022 +build -p PrmPkg/PrmPkg.dsc -m PrmPkg/Samples/PrmSampleContextBufferModule/PrmSampleContextBufferModule.inf -a X64 -t VS2026 ``` ## PRM Sample Module User's Guide From b5c33ab37f81c598f9f6c546b0732c21e179d627 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Fri, 19 Jun 2026 07:20:20 -0700 Subject: [PATCH 290/406] UnitTestFrameworkPkg: Update ReadMe for VS2026 edk2 is moving to VS2026 for the MSVC toolchain, update the ReadMe accordingly. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- UnitTestFrameworkPkg/ReadMe.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md index fef3f5fa30..dda0aeef4b 100644 --- a/UnitTestFrameworkPkg/ReadMe.md +++ b/UnitTestFrameworkPkg/ReadMe.md @@ -1332,7 +1332,7 @@ If you are trying to iterate on a single test, a convenient pattern is to build the following command will build only the SafeIntLib host-based test from the MdePkg... ```bash -stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=VS2022 -p MdePkg -t NOOPT BUILDMODULE=MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.inf +stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=VS2026 -p MdePkg -t NOOPT BUILDMODULE=MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.inf ``` ### Hooking BaseLib @@ -1357,7 +1357,7 @@ symbolic debugging to be enabled. You can run a build by adding the `BLD_*_UNIT_TESTING_DEBUG=TRUE` parameter to enable this build option. ```bash -stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=VS2022 -p MdePkg -t NOOPT BLD_*_UNIT_TESTING_DEBUG=TRUE +stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=VS2026 -p MdePkg -t NOOPT BLD_*_UNIT_TESTING_DEBUG=TRUE ``` ## Building and Running Host-Based Tests @@ -1381,16 +1381,16 @@ After that, the following commands will set up the build and run the host-based ```bash # Setup repo for building -# stuart_setup -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC, VS2022, etc.> -stuart_setup -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2022 +# stuart_setup -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC, VS2026, etc.> +stuart_setup -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2026 # Update all binary dependencies -# stuart_update -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC, VS2022, etc.> -stuart_update -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2022 +# stuart_update -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC, VS2026, etc.> +stuart_update -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2026 # Build and run the tests -# stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC, VS2022, etc.> -t NOOPT [-p <Package Name>] -stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2022 -t NOOPT -p MdePkg +# stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC, VS2026, etc.> -t NOOPT [-p <Package Name>] +stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2026 -t NOOPT -p MdePkg ``` #### Disabling Address Sanitizer @@ -1399,7 +1399,7 @@ By default, the address sanitizer feature is enabled for all host based unit tes development/debug purposes by setting the DSC define `UNIT_TESTING_ADDRESS_SANITIZER_ENABLE` to `FALSE`. ```bash -stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2022 -t NOOPT -p MdePkg BLD_*_UNIT_TESTING_ADDRESS_SANITIZER_ENABLE=FALSE +stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2026 -t NOOPT -p MdePkg BLD_*_UNIT_TESTING_ADDRESS_SANITIZER_ENABLE=FALSE ``` ### Evaluating the Results @@ -1407,7 +1407,7 @@ stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2022 -t NOOPT -p Mde In your immediate output, any build failures will be highlighted. You can see these below as "WARNING" and "ERROR" messages. ```text -(edk_env) PS C:\_uefi\edk2> stuart_ci_build -c .\.pytool\CISettings.py TOOL_CHAIN_TAG=VS2022 -t NOOPT -p MdePkg +(edk_env) PS C:\_uefi\edk2> stuart_ci_build -c .\.pytool\CISettings.py TOOL_CHAIN_TAG=VS2026 -t NOOPT -p MdePkg SECTION - Init SDE SECTION - Loading Plugins @@ -1442,7 +1442,7 @@ ERROR - Error If a test fails, you can run it manually to get more details... ```text -(edk_env) PS C:\_uefi\edk2> .\Build\MdePkg\HostTest\NOOPT_VS2022\X64\TestBaseSafeIntLibHost.exe +(edk_env) PS C:\_uefi\edk2> .\Build\MdePkg\HostTest\NOOPT_VS2026\X64\TestBaseSafeIntLibHost.exe Int Safe Lib Unit Test Application v0.1 --------------------------------------------------------- @@ -1475,7 +1475,7 @@ A sample of this output looks like: ```xml <!-- Excerpt taken from: - Build\MdePkg\HostTest\NOOPT_VS2022\X64\TestBaseSafeIntLibHost.exe.Int Safe Conversions Test Suite.X64.result.xml + Build\MdePkg\HostTest\NOOPT_VS2026\X64\TestBaseSafeIntLibHost.exe.Int Safe Conversions Test Suite.X64.result.xml --> <?xml version="1.0" encoding="UTF-8" ?> <testsuites> @@ -1544,14 +1544,14 @@ OpenCppCoverage windows tool to parse coverage data to cobertura xml format. ```bash Download and install https://github.com/OpenCppCoverage/OpenCppCoverage/releases python -m pip install --upgrade -r ./pip-requirements.txt - stuart_ci_build -c .pytool/CISettings.py -t NOOPT TOOL_CHAIN_TAG=VS2022 -p MdeModulePkg + stuart_ci_build -c .pytool/CISettings.py -t NOOPT TOOL_CHAIN_TAG=VS2026 -p MdeModulePkg Open Build/coverage.xml ``` * How to see code coverage data on IDE Visual Studio ```bash - Open Visual Studio VS2022 or above version + Open Visual Studio VS2026 or above version Click "Tools" -> "OpenCppCoverage Settings" Fill your execute file into "Program to run:" Click "Tools" -> "Run OpenCppCoverage" From df07555061ffae47adc5ac01e85be8141fa58b9a Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Fri, 19 Jun 2026 07:21:54 -0700 Subject: [PATCH 291/406] EmulatorPkg: Update DSC/Readme for VS2026 edk2 is moving to VS2026 for the MSVC toolchain. Update the building instructions and DSC conditionals. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- EmulatorPkg/EmulatorPkg.dsc | 5 +++-- EmulatorPkg/Readme.md | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc index e554f54245..7766d5d56d 100644 --- a/EmulatorPkg/EmulatorPkg.dsc +++ b/EmulatorPkg/EmulatorPkg.dsc @@ -557,6 +557,7 @@ # +--------------------+--------+----------+------------+-----+----+--------+ # | OS/Compiler | VS2019 | CLANGPDB | CLANGDWARF | GCC | XCODE5 | # | | VS2022 | | | GCCNOLTO | | +# | | VS2026 | | | | | # +--------------------+--------+----------+------------+----------+--------+ # | Windows/VS |IA32/X64| | | | | # | Windows/LLVM/VS | | IA32/X64 | | | | @@ -597,7 +598,7 @@ # macOS/XCODE: macOS environment with XCODE5 installed. # !if $(WIN_MINGW32_BUILD) - !if $(TOOL_CHAIN_TAG) in "VS2019 VS2022" + !if $(TOOL_CHAIN_TAG) in "VS2019 VS2022 VS2026" !error EmulatorPkg not supported for Mingw/VS20xx builds !endif !if $(TOOL_CHAIN_TAG) in "CLANGPDB" @@ -615,7 +616,7 @@ !error EmulatorPkg not supported for Windows/CLANGDWARF builds !endif !else - !if $(TOOL_CHAIN_TAG) in "VS2019 VS2022" + !if $(TOOL_CHAIN_TAG) in "VS2019 VS2022 VS2026" !error EmulatorPkg not supported for Linux/VS20xx builds !endif !if $(TOOL_CHAIN_TAG) in "CLANGPDB" diff --git a/EmulatorPkg/Readme.md b/EmulatorPkg/Readme.md index 1cf267c92f..4135bc46b1 100644 --- a/EmulatorPkg/Readme.md +++ b/EmulatorPkg/Readme.md @@ -21,11 +21,11 @@ https://github.com/tianocore/tianocore.github.io/wiki/EmulatorPkg **You can use the following command to build.** * 32bit emulator in Windows: - `build -p EmulatorPkg\EmulatorPkg.dsc -t VS2022 -a IA32` + `build -p EmulatorPkg\EmulatorPkg.dsc -t VS2026 -a IA32` * 64bit emulator in Windows: - `build -p EmulatorPkg\EmulatorPkg.dsc -t VS2022 -a X64` + `build -p EmulatorPkg\EmulatorPkg.dsc -t VS2026 -a X64` * 32bit emulator in Linux: @@ -38,11 +38,11 @@ https://github.com/tianocore/tianocore.github.io/wiki/EmulatorPkg **You can start/run the emulator using the following command:** * 32bit emulator in Windows: - `cd Build\EmulatorIA32\DEBUG_VS2022\IA32\ && WinHost.exe` + `cd Build\EmulatorIA32\DEBUG_VS2026\IA32\ && WinHost.exe` * 64bit emulator in Windows: - `cd Build\EmulatorX64\DEBUG_VS2022\X64\ && WinHost.exe` + `cd Build\EmulatorX64\DEBUG_VS2026\X64\ && WinHost.exe` * 32bit emulator in Linux: From 0f8d430e5282ff7f7ecdb59fd52b21136dbd80f5 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Fri, 19 Jun 2026 07:23:30 -0700 Subject: [PATCH 292/406] .pytool: Update Readme for VS2026 edk2 is moving to VS2026 for the MSVC toolchain. Updated the .pytool Readme. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- .pytool/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pytool/Readme.md b/.pytool/Readme.md index 6a31c75694..9e4887f28a 100644 --- a/.pytool/Readme.md +++ b/.pytool/Readme.md @@ -9,7 +9,7 @@ on the TianoCore wiki. ## Basic Status -| Package | Windows VS2022 (IA32/X64)| Ubuntu GCC (IA32/X64/AARCH64) | Known Issues | +| Package | Windows VS2026 (IA32/X64)| Ubuntu GCC (IA32/X64/AARCH64) | Known Issues | | :---- | :----- | :---- | :--- | | ArmPkg | | :heavy_check_mark: | | ArmPlatformPkg | | :heavy_check_mark: | From d1b6a9c968b612302bf6cf631a4c18958c1dca35 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Fri, 19 Jun 2026 07:24:15 -0700 Subject: [PATCH 293/406] .azurepipelines: Move to VS2026 This upgrades the Azure Pipelines CI to use VS2026 instead of VS2022. The Windows VM image is updated to windows-2025-vs2026 which has been updated to use VS2026. Note, 2025 references the Windows Server release, not the VS version. Azure pipelines has not migrated its windows-2025 VM image to use VS2026 yet, it will do so after that feature is GA'd, at which point edk2 will have time to update to that VM image. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- .azurepipelines/ReadMe.md | 2 +- .azurepipelines/Windows-VS.yml | 2 +- .azurepipelines/templates/defaults.yml | 2 +- .azurepipelines/templates/pr-gate-build-job.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.azurepipelines/ReadMe.md b/.azurepipelines/ReadMe.md index c0d751e916..41d16ddd94 100644 --- a/.azurepipelines/ReadMe.md +++ b/.azurepipelines/ReadMe.md @@ -22,7 +22,7 @@ Focused on building a single target platform and confirming functionality on tha * Top level CI files should be named `<host os>-<tool_chain>.yml` * The pipeline YAML file name is referenced in Azure Pipelines. To allow flexibility for toolchain updates in the YAML file without necessitating changes in Azure Pipelines, the toolchain version is not included in the filename. - For example, `Windows-VS.yml` is used instead of `Windows-VS2022.yml`. + For example, `Windows-VS.yml` is used instead of `Windows-VS2026.yml`. ## Links diff --git a/.azurepipelines/Windows-VS.yml b/.azurepipelines/Windows-VS.yml index 86d4bff5f9..9020249a2a 100644 --- a/.azurepipelines/Windows-VS.yml +++ b/.azurepipelines/Windows-VS.yml @@ -25,7 +25,7 @@ variables: jobs: - template: templates/pr-gate-build-job.yml parameters: - tool_chain_tag: 'VS2022' + tool_chain_tag: 'VS2026' vm_image: ${{ variables.default_windows_vm }} arch_list: "IA32,X64" usePythonVersion: ${{ variables.default_python_version }} diff --git a/.azurepipelines/templates/defaults.yml b/.azurepipelines/templates/defaults.yml index 6bb55c7e81..fa738ed20c 100644 --- a/.azurepipelines/templates/defaults.yml +++ b/.azurepipelines/templates/defaults.yml @@ -11,4 +11,4 @@ variables: default_python_version: "3.12" default_linux_container: "ghcr.io/tianocore/containers/fedora-43-test:b562821" default_linux_vm: "ubuntu-24.04" - default_windows_vm: "windows-2022" + default_windows_vm: "windows-2025-vs2026" diff --git a/.azurepipelines/templates/pr-gate-build-job.yml b/.azurepipelines/templates/pr-gate-build-job.yml index 2029ac52a5..f0e90dca96 100644 --- a/.azurepipelines/templates/pr-gate-build-job.yml +++ b/.azurepipelines/templates/pr-gate-build-job.yml @@ -117,7 +117,7 @@ jobs: container: ${{ parameters.container }} steps: - # Strip test targets for CI toolchains other than GCC and VS2022, as these + # Strip test targets for CI toolchains other than GCC and VS2026, as these # cannot run them and would be duplicating work during CI if they could. # Note: Within PR gate CI, NOOPT is only used for building tests. - bash: | @@ -147,7 +147,7 @@ jobs: clean: all pool: - vmImage: 'windows-2022' + vmImage: 'windows-2025-vs2026' steps: - checkout: self From db183242ac438ad2c44fcacd25e678cf60e9f54a Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Fri, 19 Jun 2026 07:24:41 -0700 Subject: [PATCH 294/406] .github: Move GitHub Actions to VS2026 This updates all GitHub Actions using VS2022 to VS2026. Note, windows-2025 is the VM image that contains VS2026. 2025 refers to the Windows Server version, not the VS version. GitHub runners have updated the windows-2025 VM version to include VS2026, so no additional migration is required. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- .github/workflows/codeql.yml | 14 +++++++------- .github/workflows/upl-build.yml | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 739d63145e..70ad226517 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -129,7 +129,7 @@ body: description: | Examples: - **OS**: Ubuntu 24.04 or Windows 11... - - **Tool Chain**: GCC or VS2022 or CLANGPDB... + - **Tool Chain**: GCC or VS2026 or CLANGPDB... value: | - OS(s): - Tool Chain(s): diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 07d5129388..fca1e77889 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -25,7 +25,7 @@ on: jobs: analyze: name: Analyze - runs-on: windows-2022 + runs-on: windows-2025 permissions: actions: read contents: read @@ -149,7 +149,7 @@ jobs: - name: Setup if: steps.get_ci_file_operations.outputs.setup_supported == 'true' - run: stuart_setup -c .pytool/CISettings.py -t DEBUG -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2022 + run: stuart_setup -c .pytool/CISettings.py -t DEBUG -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2026 - name: Upload Setup Log As An Artifact uses: actions/upload-artifact@v7 @@ -163,7 +163,7 @@ jobs: - name: CI Setup if: steps.get_ci_file_operations.outputs.ci_setup_supported == 'true' - run: stuart_ci_setup -c .pytool/CISettings.py -t DEBUG -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2022 + run: stuart_ci_setup -c .pytool/CISettings.py -t DEBUG -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2026 - name: Upload CI Setup Log As An Artifact uses: actions/upload-artifact@v7 @@ -176,7 +176,7 @@ jobs: if-no-files-found: ignore - name: Update - run: stuart_update -c .pytool/CISettings.py -t DEBUG -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2022 + run: stuart_update -c .pytool/CISettings.py -t DEBUG -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2026 - name: Upload Update Log As An Artifact uses: actions/upload-artifact@v7 @@ -189,7 +189,7 @@ jobs: if-no-files-found: ignore - name: Build Tools From Source - run: python BaseTools/Edk2ToolsBuild.py -t VS2022 + run: python BaseTools/Edk2ToolsBuild.py -t VS2026 - name: Find CodeQL Plugin Directory id: find_dir @@ -246,7 +246,7 @@ jobs: - name: Download CodeQL CLI if: steps.codeqlcli_cache.outputs.cache-hit != 'true' - run: stuart_update -c .pytool/CISettings.py -t DEBUG -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2022 --codeql + run: stuart_update -c .pytool/CISettings.py -t DEBUG -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2026 --codeql - name: Remove CI Plugins Irrelevant to CodeQL shell: python @@ -269,7 +269,7 @@ jobs: - name: CI Build env: STUART_CODEQL_PATH: ${{ steps.cache_key_gen.outputs.codeql_cli_ext_dep_dir }} - run: stuart_ci_build -c .pytool/CISettings.py -t DEBUG -p ${{ matrix.Package }} -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2022 --codeql + run: stuart_ci_build -c .pytool/CISettings.py -t DEBUG -p ${{ matrix.Package }} -a ${{ matrix.ArchList }} TOOL_CHAIN_TAG=VS2026 --codeql - name: Build Cleanup id: build_cleanup diff --git a/.github/workflows/upl-build.yml b/.github/workflows/upl-build.yml index 73480f08a5..f5e9f80ef4 100644 --- a/.github/workflows/upl-build.yml +++ b/.github/workflows/upl-build.yml @@ -14,15 +14,15 @@ on: branches: ['master'] jobs: - build_vs2022: + build_vs2026: strategy: matrix: - os: [windows-2022] + os: [windows-2025] python-version: ['3.12'] - tool-chain: ['VS2022'] + tool-chain: ['VS2026'] target: ['DEBUG'] extra-build-args: ['FIT_BUILD=TRUE', 'FIT_BUILD=FALSE'] - name: Build UPL VS2022 + name: Build UPL VS2026 uses: ./.github/workflows/BuildPlatform.yml with: runs-on: ${{ matrix.os }} From e17aaec44ba9e010926d989ee7b6a06696fe1826 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Fri, 19 Jun 2026 07:25:08 -0700 Subject: [PATCH 295/406] EmulatorPkg: Update CI to VS2026 This updates the VS2022 EmulatorPkg CI to VS2026. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- EmulatorPkg/PlatformCI/.azurepipelines/Windows-VS.yml | 2 +- EmulatorPkg/PlatformCI/PlatformBuild.py | 6 +++--- EmulatorPkg/PlatformCI/ReadMe.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/EmulatorPkg/PlatformCI/.azurepipelines/Windows-VS.yml b/EmulatorPkg/PlatformCI/.azurepipelines/Windows-VS.yml index 8c21327fc2..0b51cd0d20 100644 --- a/EmulatorPkg/PlatformCI/.azurepipelines/Windows-VS.yml +++ b/EmulatorPkg/PlatformCI/.azurepipelines/Windows-VS.yml @@ -90,7 +90,7 @@ jobs: steps: - template: ../../../.azurepipelines/templates/platform-build-run-steps.yml parameters: - tool_chain_tag: VS2022 + tool_chain_tag: VS2026 build_pkg: $(package) build_target: $(Build.Target) build_arch: $(Build.Arch) diff --git a/EmulatorPkg/PlatformCI/PlatformBuild.py b/EmulatorPkg/PlatformCI/PlatformBuild.py index 4afe956cfd..42e3290544 100644 --- a/EmulatorPkg/PlatformCI/PlatformBuild.py +++ b/EmulatorPkg/PlatformCI/PlatformBuild.py @@ -186,11 +186,11 @@ class PlatformBuilder(UefiBuilder, BuildSettingsManager): def SetPlatformEnv(self): logging.debug("PlatformBuilder SetPlatformEnv") self.env.SetValue("PRODUCT_NAME", "EmulatorPkg", "Platform Hardcoded") - self.env.SetValue("TOOL_CHAIN_TAG", "VS2022", "Default Toolchain") + self.env.SetValue("TOOL_CHAIN_TAG", "VS2026", "Default Toolchain") # Add support for using the correct Platform Headers, tools, and Libs based on emulator architecture - # requested to be built when building VS2022 or VS2019 - if self.env.GetValue("TOOL_CHAIN_TAG") == "VS2022" or self.env.GetValue("TOOL_CHAIN_TAG") == "VS2019": + # requested to be built when building VS2026, VS2022 or VS2019 + if self.env.GetValue("TOOL_CHAIN_TAG") in ("VS2019", "VS2022", "VS2026"): key = self.env.GetValue("TOOL_CHAIN_TAG") + "_HOST" if self.env.GetValue("TARGET_ARCH") == "IA32": shell_environment.ShellEnvironment().set_shell_var(key, "x86") diff --git a/EmulatorPkg/PlatformCI/ReadMe.md b/EmulatorPkg/PlatformCI/ReadMe.md index 54a7330734..71dddd9769 100644 --- a/EmulatorPkg/PlatformCI/ReadMe.md +++ b/EmulatorPkg/PlatformCI/ReadMe.md @@ -6,7 +6,7 @@ to use the same Pytools based build infrastructure locally. ## Supported Configuration Details This solution for building and running EmulatorPkg has only been validated with Windows 10 -with VS2022 and Ubuntu 18.04 with GCC toolchain. Four different firmware builds are +with VS2026 and Ubuntu 18.04 with GCC toolchain. Four different firmware builds are supported and are described below. | Configuration name | Architectures | DSC File |Additional Flags | From e11670b37916faa2b6e430551ec95b88e2c62e7e Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Fri, 19 Jun 2026 07:25:26 -0700 Subject: [PATCH 296/406] OvmfPkg: Update VS2022 CI to VS2026 This follows the rest of edk2 to update VS2022 CI to VS2026. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- OvmfPkg/PlatformCI/.azurepipelines/Windows-VS.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS.yml b/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS.yml index ae53dd814d..15415d3c17 100644 --- a/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS.yml +++ b/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS.yml @@ -83,7 +83,7 @@ jobs: steps: - template: ../../../.azurepipelines/templates/platform-build-run-steps.yml parameters: - tool_chain_tag: VS2022 + tool_chain_tag: VS2026 build_pkg: $(package) build_target: $(Build.Target) build_arch: $(Build.Arch) From 82cfea329cc2214df006edc067ed852f4d86a314 Mon Sep 17 00:00:00 2001 From: Luigi Leonardi <leonardi@redhat.com> Date: Thu, 23 Jul 2026 16:51:38 +0200 Subject: [PATCH 297/406] ArmVirtPkg: add QemuFwCfg null library instances to common DSC PlatformPeiLib consumes QemuFwCfgSimpleParserLib, but ArmVirtXen.dsc provided no resolution for it or its dependency QemuFwCfgLib, causing: error 4000: Instance of library class [QemuFwCfgSimpleParserLib] is not found for module [ArmVirtPrePiUniCoreRelocatable.inf], consumed by PlatformPeiLib.inf Wire up QemuFwCfgLibNull and QemuFwCfgSimpleParserLib in the common ArmVirt.dsc.inc so all platforms without fw_cfg fail gracefully. ArmVirtCloudHv.dsc already carried the same null pair; both per-DSC copies are removed now that the common default covers them. ArmVirtQemu and ArmVirtQemuKernel continue to override with their real MMIO implementations. Fixes: f4bbef1dd7 ("ArmVirtPkg: introduce compile and runtime control of serial debug log level") Reported-by: Pierre Gondois <pierre.gondois@arm.com> Signed-off-by: Luigi Leonardi <leonardi@redhat.com> --- ArmVirtPkg/ArmVirt.dsc.inc | 2 ++ ArmVirtPkg/ArmVirtCloudHv.dsc | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index fc60d87ce3..2bc99de0d7 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -121,6 +121,8 @@ DEFINE FD_SIZE_IN_MB = 3 # Virtio Support VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf + QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf + QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParserLib.inf # # Misc diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index 122e0e8f6d..d76b17c602 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -46,8 +46,6 @@ TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLibNull/PeiDxeTpmPlatformHierarchyLib.inf ArmTransferListLib|ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf - QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf - QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParserLib.inf !include MdePkg/MdeLibs.dsc.inc From eeaac552f81111014ab77f8f6e0dea00e03b3c46 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Jul 2026 14:32:51 -0700 Subject: [PATCH 298/406] OvmfPkg/FdtPciHostBridgeLib: mark PCI host MMIO mappings as non-executable Add EFI_MEMORY_XP to all MapMmioMemory() calls in ProcessPciHost() for: - ECAM space - Translated I/O window - 32-bit MMIO window - 64-bit MMIO window These regions are data/MMIO only and should not be executable. Marking them with EFI_MEMORY_XP improves memory protection hardening without changing intended runtime behavior. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c index 783ce27f30..53d2258fa4 100644 --- a/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c +++ b/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c @@ -283,7 +283,7 @@ ProcessPciHost ( )); // Map the ECAM space in the GCD memory map - Status = MapMmioMemory (ConfigBase, ConfigSize, EFI_MEMORY_UC); + Status = MapMmioMemory (ConfigBase, ConfigSize, EFI_MEMORY_UC | EFI_MEMORY_XP); ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { return Status; @@ -295,7 +295,7 @@ ProcessPciHost ( // is not aware of this translation and so it will only map the I/O view // in the GCD I/O map. // - Status = MapMmioMemory (*IoBase + IoTranslation, *IoSize, EFI_MEMORY_UC); + Status = MapMmioMemory (*IoBase + IoTranslation, *IoSize, EFI_MEMORY_UC | EFI_MEMORY_XP); ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { return Status; @@ -303,7 +303,7 @@ ProcessPciHost ( } if (*Mmio32Size != 0) { - Status = MapMmioMemory (*Mmio32Base, *Mmio32Size, EFI_MEMORY_UC); + Status = MapMmioMemory (*Mmio32Base, *Mmio32Size, EFI_MEMORY_UC | EFI_MEMORY_XP); ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { return Status; @@ -311,7 +311,7 @@ ProcessPciHost ( } if (*Mmio64Size != 0) { - Status = MapMmioMemory (*Mmio64Base, *Mmio64Size, EFI_MEMORY_UC); + Status = MapMmioMemory (*Mmio64Base, *Mmio64Size, EFI_MEMORY_UC | EFI_MEMORY_XP); ASSERT_EFI_ERROR (Status); } From ac0777f893bc96d456b153e1594adaefa7de9605 Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Wed, 22 Jul 2026 15:36:17 -0400 Subject: [PATCH 299/406] BREAKING-CHANGES.md: Sort entries and add order guidance 1. To provide greater clarity and consistency, the file instructions are updated to indicate that entries should be added after existing entries within a given section so that they are in chronological merge order within the section. 2. Existing entries are sorted accordingly. 3. Existing entries are updated to have consistent style and some section header levels are adjusted to properly reflect the level of the section. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- BREAKING-CHANGES.md | 123 +++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index da10d5a963..0ece3f20b5 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -4,6 +4,9 @@ This file is the in-tree record of breaking changes in EDK II. Each breaking cha in the pull request that introduces the change and updated in any later pull request that changes its state. The file is organized by stable tag milestone with most recent first. +Within a given section, each breaking change is added after existing entries so they are in chronological merge order +within the section. + For the full process, including the breaking change taxonomy, deprecation timeline, required entry content, and GitHub issue requirements, see the [Breaking Change and Release Process for EDK II](https://raw.githubusercontent.com/tianocore/tianocore-wiki.github.io/refs/heads/main/rfc/text/0003-edk2-breaking-change-and-release-process.md) RFC. @@ -70,7 +73,7 @@ None #### edk2-stable202608: Changes with Removal -### Breaking Change: AArch64 exception handling relocated from ArmPkg to UefiCpuPkg +##### Breaking Change: AArch64 exception handling relocated from ArmPkg to UefiCpuPkg - **Status**: Removed - **Tracking Issue**: N/A (merged before the breaking change process took effect) @@ -102,39 +105,7 @@ file. **Earliest removal**: Already removed in this change. The old code was removed in the same PR with no compatibility window. -### Breaking Change: BaseRiscV64CpuTimerLib renamed and split into SEC and DXE TimerLib instances - -- **Status**: Removed -- **Tracking Issue**: N/A (merged before the breaking change process took effect) -- **Deprecation Issue**: N/A -- **Removal Issue**: N/A -- **Pull Request**: [tianocore/edk2#12210](https://github.com/tianocore/edk2/pull/12210) -- **Type**: Source-Level (Removal) - Library class restructure - -**What changed**: The `UefiCpuPkg` `BaseRiscV64CpuTimerLib` was renamed to `RiscV64CpuTimerLib` and split into two -instances: `RiscV64CpuTimerSecLib.inf` (`MODULE_TYPE` `SEC`, for SEC and PEI, no constructor) and -`RiscV64CpuTimerDxeLib.inf` (for `DXE_CORE`, `DXE_DRIVER`, and other DXE-phase modules, which retains the constructor). -The old `UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf` path was removed. - -**What is removed**: The `BaseRiscV64CpuTimerLib` library instance and its INF path. - -**Why it changed**: The library constructor calls `GetPerformanceCounterProperties()`, which requires the HOB list. In -the SEC and PEI phases the HOB list may not yet be available, causing a crash. Splitting the instances runs the -constructor only in the DXE instance. - -**What replaces it**: The phase-specific instances `RiscV64CpuTimerSecLib.inf` (SEC and PEI) and -`RiscV64CpuTimerDxeLib.inf` (DXE). - -**How to migrate**: Update platform DSC `TimerLib` mappings that referenced -`UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf`. Map `TimerLib` to `RiscV64CpuTimerSecLib.inf` -for SEC and PEI modules and to `RiscV64CpuTimerDxeLib.inf` for DXE modules. - -**Breaking conditions**: Affects RISC-V (RISCV64) platforms that consume the RISC-V CPU timer library. - -**Earliest removal**: Already removed in this change. The old INF path was removed in the same PR with no compatibility -window. - -### Breaking Change: PrePiLib FfsFindSectionDataWithHook and FfsProcessFvFile gain new parameters +##### Breaking Change: PrePiLib FfsFindSectionDataWithHook and FfsProcessFvFile gain new parameters - **Status**: Removed - **Tracking Issue**: N/A (merged before the breaking change process took effect) @@ -166,39 +137,39 @@ correct FV2 HOB production requires the parent FV handle. **Earliest removal**: Already removed in this change. The old signatures were replaced in the same PR with no compatibility window. -#### edk2-stable202608: Changes without Removal +##### Breaking Change: BaseRiscV64CpuTimerLib renamed and split into SEC and DXE TimerLib instances -##### Breaking Change: New GptLib library class dependency +- **Status**: Removed +- **Tracking Issue**: N/A (merged before the breaking change process took effect) +- **Deprecation Issue**: N/A +- **Removal Issue**: N/A +- **Pull Request**: [tianocore/edk2#12210](https://github.com/tianocore/edk2/pull/12210) +- **Type**: Source-Level (Removal) - Library class restructure -**Status**: Announced +**What changed**: The `UefiCpuPkg` `BaseRiscV64CpuTimerLib` was renamed to `RiscV64CpuTimerLib` and split into two +instances: `RiscV64CpuTimerSecLib.inf` (`MODULE_TYPE` `SEC`, for SEC and PEI, no constructor) and +`RiscV64CpuTimerDxeLib.inf` (for `DXE_CORE`, `DXE_DRIVER`, and other DXE-phase modules, which retains the constructor). +The old `UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf` path was removed. -**Tracking Issue**: tianocore/edk2#12808 +**What is removed**: The `BaseRiscV64CpuTimerLib` library instance and its INF path. -**Type**: Source-Level (Non-removal) - Library class dependency addition -(single expected instance) +**Why it changed**: The library constructor calls `GetPerformanceCounterProperties()`, which requires the HOB list. In +the SEC and PEI phases the HOB list may not yet be available, causing a crash. Splitting the instances runs the +constructor only in the DXE instance. -**What changed**: PartitionDxe, DxeTpm2MeasureBootLib and -DxeTpmMeasureBootLib gained a required dependency on the new GptLib library -class declared in MdeModulePkg. Platforms that build any of these modules -must resolve GptLib in their DSC or the build fails with an unresolved -library class. +**What replaces it**: The phase-specific instances `RiscV64CpuTimerSecLib.inf` (SEC and PEI) and +`RiscV64CpuTimerDxeLib.inf` (DXE). -**Why it changed**: As reported in CVE-2024-13745, DxeTpm2MeasureBootLib -could measure a GPT partition table that differs from the one parsed and -used by PartitionDxe, because the two components carried independent GPT -parsing logic. GptLib consolidates GPT parsing and validation so the -partition table measured into PCR[5] is validated by the same logic the -firmware uses. +**How to migrate**: Update platform DSC `TimerLib` mappings that referenced +`UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf`. Map `TimerLib` to `RiscV64CpuTimerSecLib.inf` +for SEC and PEI modules and to `RiscV64CpuTimerDxeLib.inf` for DXE modules. -**What replaces it**: Nothing is removed. A single canonical GptLib -instance is provided in-tree (MdeModulePkg/Library/GptLib/GptLib.inf). +**Breaking conditions**: Affects RISC-V (RISCV64) platforms that consume the RISC-V CPU timer library. -**How to migrate**: Add the following mapping to the platform DSC -[LibraryClasses] section: +**Earliest removal**: Already removed in this change. The old INF path was removed in the same PR with no compatibility +window. - GptLib|MdeModulePkg/Library/GptLib/GptLib.inf - -### Breaking Change: TPM2 helper functions moved to new Tpm2HelpLib library class +##### Breaking Change: TPM2 helper functions moved to new Tpm2HelpLib library class - **Status**: Deprecation Active - **Tracking Issue**: [tianocore/edk2#12797](https://github.com/tianocore/edk2/issues/12797) @@ -234,13 +205,45 @@ removal stable tag has not been scheduled at this time. > - [Platform/MinPlatformPkg: Switch to Tpm2HelpLib](https://github.com/tianocore/edk2-platforms/issues/995) > - [Silicon/Ampere/AmpereAltraPkg: Switch to Tpm2HelpLib](https://github.com/tianocore/edk2-platforms/issues/996) +#### edk2-stable202608: Changes without Removal + +##### Breaking Change: New GptLib library class dependency + +- **Status**: Announced +- **Tracking Issue**: [tianocore/edk2#12808](https://github.com/tianocore/edk2/issues/12808) +- **Pull Request**: [tianocore/edk2#12745](https://github.com/tianocore/edk2/pull/12745) + +**Type**: Source-Level (Non-removal) - Library class dependency addition +(single expected instance) + +**What changed**: PartitionDxe, DxeTpm2MeasureBootLib and +DxeTpmMeasureBootLib gained a required dependency on the new GptLib library +class declared in MdeModulePkg. Platforms that build any of these modules +must resolve GptLib in their DSC or the build fails with an unresolved +library class. + +**Why it changed**: As reported in CVE-2024-13745, DxeTpm2MeasureBootLib +could measure a GPT partition table that differs from the one parsed and +used by PartitionDxe, because the two components carried independent GPT +parsing logic. GptLib consolidates GPT parsing and validation so the +partition table measured into PCR[5] is validated by the same logic the +firmware uses. + +**What replaces it**: Nothing is removed. A single canonical GptLib +instance is provided in-tree (MdeModulePkg/Library/GptLib/GptLib.inf). + +**How to migrate**: Add the following mapping to the platform DSC +[LibraryClasses] section: + + GptLib|MdeModulePkg/Library/GptLib/GptLib.inf + ### edk2-stable202608: Behavioral Breaking Changes None ### edk2-stable202608: Build-System Breaking Changes -### Breaking Change: GenFv ForceRebase now honors a per-module Xip flag +#### Breaking Change: GenFv ForceRebase now honors a per-module Xip flag - **Status**: Removed - **Tracking Issue**: N/A (merged before the breaking change process took effect) @@ -325,7 +328,7 @@ with no compatibility window. > is preserved. The **Breaking conditions** and **How to migrate** guidance above reflect the behavior after this > fix. -### Breaking Change: Visual Studio 2015 and 2017 toolchain support removed +#### Breaking Change: Visual Studio 2015 and 2017 toolchain support removed - **Status**: Removed - **Tracking Issue**: N/A (merged before the breaking change process took effect) From df9111c2d381546ff23cdf327546ad49f51ce779 Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Tue, 21 Jul 2026 20:42:07 -0400 Subject: [PATCH 300/406] Global: Set MarkdownLintCheck plugin to AuditOnly In preparation for the MarkdownLintCheck plugin being added to the repo, this change defaults the plugin to `AuditOnly` mode in each package. This allows package maintainers to enable the plugin as they see fit. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- ArmPkg/ArmPkg.ci.yaml | 6 ++++++ ArmPlatformPkg/ArmPlatformPkg.ci.yaml | 6 ++++++ ArmVirtPkg/ArmVirtPkg.ci.yaml | 6 ++++++ CryptoPkg/CryptoPkg.ci.yaml | 6 ++++++ EmbeddedPkg/EmbeddedPkg.ci.yaml | 6 ++++++ EmulatorPkg/EmulatorPkg.ci.yaml | 6 ++++++ FatPkg/FatPkg.ci.yaml | 6 ++++++ FmpDevicePkg/FmpDevicePkg.ci.yaml | 6 ++++++ IntelFsp2Pkg/IntelFsp2Pkg.ci.yaml | 6 ++++++ IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.ci.yaml | 6 ++++++ ManageabilityPkg/ManageabilityPkg.ci.yaml | 6 ++++++ MdeModulePkg/MdeModulePkg.ci.yaml | 8 ++++++++ MdePkg/MdePkg.ci.yaml | 1 + NetworkPkg/NetworkPkg.ci.yaml | 6 ++++++ OvmfPkg/OvmfPkg.ci.yaml | 6 ++++++ PcAtChipsetPkg/PcAtChipsetPkg.ci.yaml | 6 ++++++ PrmPkg/PrmPkg.ci.yaml | 6 ++++++ RedfishPkg/RedfishPkg.ci.yaml | 6 ++++++ SecurityPkg/SecurityPkg.ci.yaml | 6 ++++++ ShellPkg/ShellPkg.ci.yaml | 6 ++++++ SourceLevelDebugPkg/SourceLevelDebugPkg.ci.yaml | 6 ++++++ StandaloneMmPkg/StandaloneMmPkg.ci.yaml | 6 ++++++ TcgTpmPkg/TcgTpmPkg.ci.yaml | 6 ++++++ UefiCpuPkg/UefiCpuPkg.ci.yaml | 6 ++++++ UefiPayloadPkg/UefiPayloadPkg.ci.yaml | 6 ++++++ UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml | 9 +++++++++ 26 files changed, 156 insertions(+) diff --git a/ArmPkg/ArmPkg.ci.yaml b/ArmPkg/ArmPkg.ci.yaml index 14da56132e..9bd080a613 100644 --- a/ArmPkg/ArmPkg.ci.yaml +++ b/ArmPkg/ArmPkg.ci.yaml @@ -241,5 +241,11 @@ ], "AdditionalIncludePaths": [] # Additional paths to spell check # (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/ArmPlatformPkg/ArmPlatformPkg.ci.yaml b/ArmPlatformPkg/ArmPlatformPkg.ci.yaml index b42ffc7518..613a7ebe6b 100644 --- a/ArmPlatformPkg/ArmPlatformPkg.ci.yaml +++ b/ArmPlatformPkg/ArmPlatformPkg.ci.yaml @@ -135,5 +135,11 @@ ], "AdditionalIncludePaths": [] # Additional paths to spell check # (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/ArmVirtPkg/ArmVirtPkg.ci.yaml b/ArmVirtPkg/ArmVirtPkg.ci.yaml index 21cb190014..1927085467 100644 --- a/ArmVirtPkg/ArmVirtPkg.ci.yaml +++ b/ArmVirtPkg/ArmVirtPkg.ci.yaml @@ -134,5 +134,11 @@ # Reason: Expansion of macro that contains a print specifier. "FMT_CM_OBJECT_ID": "0x%lx" } + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/CryptoPkg/CryptoPkg.ci.yaml b/CryptoPkg/CryptoPkg.ci.yaml index 96d6df1e81..938c1f0cc7 100644 --- a/CryptoPkg/CryptoPkg.ci.yaml +++ b/CryptoPkg/CryptoPkg.ci.yaml @@ -157,5 +157,11 @@ "Library/OpensslLib/OpensslGen/providers/common/include/prov/der_wrap.h", "Library/OpensslLib/OpensslStub/uefiprov.c" ] + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/EmbeddedPkg/EmbeddedPkg.ci.yaml b/EmbeddedPkg/EmbeddedPkg.ci.yaml index f4956e679d..b9493d7279 100644 --- a/EmbeddedPkg/EmbeddedPkg.ci.yaml +++ b/EmbeddedPkg/EmbeddedPkg.ci.yaml @@ -91,5 +91,11 @@ "ExtendWords": [], # words to extend to the dictionary for this package "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/EmulatorPkg/EmulatorPkg.ci.yaml b/EmulatorPkg/EmulatorPkg.ci.yaml index 6090fe3363..4b49c6a03f 100644 --- a/EmulatorPkg/EmulatorPkg.ci.yaml +++ b/EmulatorPkg/EmulatorPkg.ci.yaml @@ -107,5 +107,11 @@ ], # words to extend to the dictionary for this package "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/FatPkg/FatPkg.ci.yaml b/FatPkg/FatPkg.ci.yaml index 804688c987..fb99efac16 100644 --- a/FatPkg/FatPkg.ci.yaml +++ b/FatPkg/FatPkg.ci.yaml @@ -65,5 +65,11 @@ "DMDEPKG", "lba's", ] + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/FmpDevicePkg/FmpDevicePkg.ci.yaml b/FmpDevicePkg/FmpDevicePkg.ci.yaml index 1e687a53fa..ec04aee83a 100644 --- a/FmpDevicePkg/FmpDevicePkg.ci.yaml +++ b/FmpDevicePkg/FmpDevicePkg.ci.yaml @@ -67,5 +67,11 @@ }, "Defines": { "BLD_*_CONTINUOUS_INTEGRATION": "TRUE", + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/IntelFsp2Pkg/IntelFsp2Pkg.ci.yaml b/IntelFsp2Pkg/IntelFsp2Pkg.ci.yaml index bd6f4cc961..cdc73d8a5c 100644 --- a/IntelFsp2Pkg/IntelFsp2Pkg.ci.yaml +++ b/IntelFsp2Pkg/IntelFsp2Pkg.ci.yaml @@ -89,5 +89,11 @@ "ExtendWords": [], # words to extend to the dictionary for this package "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.ci.yaml b/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.ci.yaml index 2d32bc65b4..a9a92f1c7e 100644 --- a/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.ci.yaml +++ b/IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.ci.yaml @@ -91,5 +91,11 @@ "ExtendWords": [], # words to extend to the dictionary for this package "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/ManageabilityPkg/ManageabilityPkg.ci.yaml b/ManageabilityPkg/ManageabilityPkg.ci.yaml index e1621d2613..c43661a6d1 100644 --- a/ManageabilityPkg/ManageabilityPkg.ci.yaml +++ b/ManageabilityPkg/ManageabilityPkg.ci.yaml @@ -70,5 +70,11 @@ "Defines": { "BLD_*_CONTINUOUS_INTEGRATION": "TRUE" + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/MdeModulePkg/MdeModulePkg.ci.yaml b/MdeModulePkg/MdeModulePkg.ci.yaml index 6056e263a6..724795ef56 100644 --- a/MdeModulePkg/MdeModulePkg.ci.yaml +++ b/MdeModulePkg/MdeModulePkg.ci.yaml @@ -120,5 +120,13 @@ "canthave" ], "AdditionalIncludePaths": [] # Additional paths to spell check relative to package root (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [ "Universal/RegularExpressionDxe/oniguruma", # submodule outside of control + "Library/BrotliCustomDecompressLib/brotli" # submodule outside of control + ] } } diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index c686dcbdd9..9823e6c6ba 100644 --- a/MdePkg/MdePkg.ci.yaml +++ b/MdePkg/MdePkg.ci.yaml @@ -242,6 +242,7 @@ ## options defined .pytool/Plugin/MarkdownLintCheck "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped "IgnoreFiles": [ "Library/MipiSysTLib/mipisyst" # submodule outside of control ] # package root relative file, folder, or glob pattern to ignore } diff --git a/NetworkPkg/NetworkPkg.ci.yaml b/NetworkPkg/NetworkPkg.ci.yaml index 24695f97d9..817fa80b80 100644 --- a/NetworkPkg/NetworkPkg.ci.yaml +++ b/NetworkPkg/NetworkPkg.ci.yaml @@ -84,5 +84,11 @@ "BLD_*_NETWORK_HTTP_BOOT_ENABLE": "TRUE", "BLD_*_NETWORK_ISCSI_ENABLE": "TRUE", "BLD_*_NETWORK_PXE_BOOT_ENABLE": "TRUE", + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/OvmfPkg/OvmfPkg.ci.yaml b/OvmfPkg/OvmfPkg.ci.yaml index f44c1b8f2d..454f3015fc 100644 --- a/OvmfPkg/OvmfPkg.ci.yaml +++ b/OvmfPkg/OvmfPkg.ci.yaml @@ -105,5 +105,11 @@ # options defined in .pytool/Plugin/UncrustifyCheck "UncrustifyCheck": { "IgnoreFiles": ["VbeShim.h"] + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.ci.yaml b/PcAtChipsetPkg/PcAtChipsetPkg.ci.yaml index 278bb43969..3d2d7cf5b0 100644 --- a/PcAtChipsetPkg/PcAtChipsetPkg.ci.yaml +++ b/PcAtChipsetPkg/PcAtChipsetPkg.ci.yaml @@ -61,5 +61,11 @@ "PCATCHIPSET", "TXRDY" ] + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/PrmPkg/PrmPkg.ci.yaml b/PrmPkg/PrmPkg.ci.yaml index 0c6e4c9e01..0dc5bd28fe 100644 --- a/PrmPkg/PrmPkg.ci.yaml +++ b/PrmPkg/PrmPkg.ci.yaml @@ -115,5 +115,11 @@ # should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check # (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/RedfishPkg/RedfishPkg.ci.yaml b/RedfishPkg/RedfishPkg.ci.yaml index b95e8bfdc7..d8ee40450d 100644 --- a/RedfishPkg/RedfishPkg.ci.yaml +++ b/RedfishPkg/RedfishPkg.ci.yaml @@ -106,5 +106,11 @@ "Defines": { "BLD_*_CONTINUOUS_INTEGRATION": "TRUE", "BLD_*_REDFISH_ENABLE": "TRUE" + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/SecurityPkg/SecurityPkg.ci.yaml b/SecurityPkg/SecurityPkg.ci.yaml index d54903293c..f144e38923 100644 --- a/SecurityPkg/SecurityPkg.ci.yaml +++ b/SecurityPkg/SecurityPkg.ci.yaml @@ -134,5 +134,11 @@ # Replace ternary operator in debug string with single specifier 'Index == COLUME_SIZE/2 ? " | %02x" : " %02x"': "%d" } + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/ShellPkg/ShellPkg.ci.yaml b/ShellPkg/ShellPkg.ci.yaml index 2c3a70d84b..c62ffe570f 100644 --- a/ShellPkg/ShellPkg.ci.yaml +++ b/ShellPkg/ShellPkg.ci.yaml @@ -72,5 +72,11 @@ "ExtendWords": [], # words to extend to the dictionary for this package "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/SourceLevelDebugPkg/SourceLevelDebugPkg.ci.yaml b/SourceLevelDebugPkg/SourceLevelDebugPkg.ci.yaml index 295a11640e..24e9ac1947 100644 --- a/SourceLevelDebugPkg/SourceLevelDebugPkg.ci.yaml +++ b/SourceLevelDebugPkg/SourceLevelDebugPkg.ci.yaml @@ -117,5 +117,11 @@ ], "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/StandaloneMmPkg/StandaloneMmPkg.ci.yaml b/StandaloneMmPkg/StandaloneMmPkg.ci.yaml index 7d9b0c9cac..232c60e20f 100644 --- a/StandaloneMmPkg/StandaloneMmPkg.ci.yaml +++ b/StandaloneMmPkg/StandaloneMmPkg.ci.yaml @@ -97,5 +97,11 @@ # should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check # (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/TcgTpmPkg/TcgTpmPkg.ci.yaml b/TcgTpmPkg/TcgTpmPkg.ci.yaml index 4f47b424a1..e930ce4dc4 100644 --- a/TcgTpmPkg/TcgTpmPkg.ci.yaml +++ b/TcgTpmPkg/TcgTpmPkg.ci.yaml @@ -135,5 +135,11 @@ "Private/Include/Standard/time.h", "Private/Include/Standard/unistd.h" ] + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/UefiCpuPkg/UefiCpuPkg.ci.yaml b/UefiCpuPkg/UefiCpuPkg.ci.yaml index 57867ddf98..00def953c5 100644 --- a/UefiCpuPkg/UefiCpuPkg.ci.yaml +++ b/UefiCpuPkg/UefiCpuPkg.ci.yaml @@ -86,5 +86,11 @@ "ExtendWords": [], # words to extend to the dictionary for this package "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported) + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/UefiPayloadPkg/UefiPayloadPkg.ci.yaml b/UefiPayloadPkg/UefiPayloadPkg.ci.yaml index 84e3f14b68..dbdda74961 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.ci.yaml +++ b/UefiPayloadPkg/UefiPayloadPkg.ci.yaml @@ -97,5 +97,11 @@ "BLD_*_SERIAL_DRIVER_ENABLE": "FALSE", "BLD_*_BUILD_ARCH": "", "BLD_*_SECURE_BOOT_ENABLE": "TRUE", + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml index 0e3fd4411a..0d78a6ae69 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml @@ -130,6 +130,15 @@ "Library/CmockaLib/cmocka/**", "Library/GoogleTestLib/googletest/**", "Library/SubhookLib/subhook/**" + ], + }, + + ## options defined .pytool/Plugin/MarkdownLintCheck + "MarkdownLintCheck": { + "AuditOnly": True, # If True, log all errors and then mark as skipped + "IgnoreFiles": [ + "Library/CmockaLib/cmocka", # cmocka is submodule outside of control + "Library/GoogleTestLib/googletest" # googletest is submodule outside of control ] } } From 3ff3b0e43f4b21eb5c1597ae602fa2a7c3d86e03 Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Tue, 21 Jul 2026 12:14:33 -0400 Subject: [PATCH 301/406] .pytool: Add MarkdownLintCheck plugin This plugin runs markdownlint against all markdown files in a given package to report linter errors. See the following readme for me details: .pytool/Plugin/MarkdownLintCheck/Readme.md Co-authored-by: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- .../MarkdownLintCheck/MarkdownLintCheck.py | 180 ++++++++++++++++++ .../MarkdownLintCheck_plug_in.yaml | 11 ++ .pytool/Plugin/MarkdownLintCheck/Readme.md | 61 ++++++ 3 files changed, 252 insertions(+) create mode 100644 .pytool/Plugin/MarkdownLintCheck/MarkdownLintCheck.py create mode 100644 .pytool/Plugin/MarkdownLintCheck/MarkdownLintCheck_plug_in.yaml create mode 100644 .pytool/Plugin/MarkdownLintCheck/Readme.md diff --git a/.pytool/Plugin/MarkdownLintCheck/MarkdownLintCheck.py b/.pytool/Plugin/MarkdownLintCheck/MarkdownLintCheck.py new file mode 100644 index 0000000000..eedf2dcf71 --- /dev/null +++ b/.pytool/Plugin/MarkdownLintCheck/MarkdownLintCheck.py @@ -0,0 +1,180 @@ +# @file MarkdownLintCheck.py +# +# An edk2-pytool based plugin wrapper for markdownlint +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## +import logging +from io import StringIO +import os +from typing import List +from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin +from edk2toollib.utility_functions import RunCmd +from edk2toolext.environment.var_dict import VarDict +from edk2toolext.environment import version_aggregator + + +class MarkdownLintCheck(ICiBuildPlugin): + """ + A CiBuildPlugin that uses the markdownlint-cli node module to scan the files + from the package being tested for linter errors. + + The linter config file (.markdownlint.yaml) must be present in one of the defined + locations otherwise the test will be skipped. These locations were picked to also + align with how editors and tools will find the config file. + + 1st priority location - At the package root + 2nd Priority location - At the workspace root of the build (suggested location unless override needed) + + Configuration options: + "MarkdownLintCheck": { + "AuditOnly": False, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore + } + """ + + CONFIG_FILE_NAME = ".markdownlint.yaml" + + def GetTestName(self, packagename: str, environment: VarDict) -> tuple: + """ Provide the testcase name and classname for use in reporting + + Args: + packagename: string containing name of package to build + environment: The VarDict for the test to run in + Returns: + a tuple containing the testcase name and the classname + (testcasename, classname) + testclassname: a descriptive string for the testcase can include whitespace + classname: should be patterned <packagename>.<plugin>.<optionally any unique condition> + """ + return ("Lint Markdown files in " + packagename, packagename + ".markdownlint") + + ## + # External function of plugin. This function is used to perform the task of the CiBuild Plugin + # + # - package is the edk2 path to package. This means workspace/packagepath relative. + # - edk2path object configured with workspace and packages path + # - PkgConfig Object (dict) for the pkg + # - EnvConfig Object + # - Plugin Manager Instance + # - Plugin Helper Obj Instance + # - Junit Logger + # - output_stream the StringIO output stream from this plugin via logging + + def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None): + abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSystemFromEdk2RelativePath( + packagename) + + if abs_pkg_path is None: + tc.SetSkipped() + tc.LogStdError("No package {0}".format(packagename)) + return -1 + + # check for node + return_buffer = StringIO() + ret = RunCmd("node", "--version", outstream=return_buffer) + if ret != 0: + tc.SetSkipped() + tc.LogStdError("NodeJs not installed. Test can't run") + logging.warning("NodeJs not installed. Test can't run") + return -1 + node_version = return_buffer.getvalue().strip() # format vXX.XX.XX + tc.LogStdOut(f"Node version: {node_version}") + + # Check for markdownlint-cli + return_buffer = StringIO() + ret = RunCmd("markdownlint", "--version", outstream=return_buffer) + if ret != 0: + tc.SetSkipped() + tc.LogStdError("markdownlint not installed. Test can't run") + logging.warning("markdownlint not installed. Test can't run") + return -1 + mdl_version = return_buffer.getvalue().strip() # format XX.XX.XX + tc.LogStdOut(f"MarkdownLint version: {mdl_version}") + version_aggregator.GetVersionAggregator().ReportVersion( + "MarkDownLint", mdl_version, version_aggregator.VersionTypes.INFO) + + # Get relative path for the root of package to use with ignore and path parameters + relpath = os.path.relpath(abs_pkg_path) + + # Newer versions of markdownlint don't understand backslashes + relpath = relpath.replace(os.path.sep, '/') + + # + # check for any package specific ignore patterns defined by package config + # + Ignores = [] + if "IgnoreFiles" in pkgconfig: + for i in pkgconfig["IgnoreFiles"]: + Ignores.append(f"{relpath}/{i}") + + # + # Make the path string to check + # + path_to_check = f'{relpath}/**/*.md' + + # get path to config file - + + # Currently there is support for two different config files + # If the config file is not found then the test case is skipped + # + # 1st - At the package root + # 2nd - At the workspace root of the build + config_file_path = None + + # 1st check to see if the config file is at package root + if os.path.isfile(os.path.join(abs_pkg_path, MarkdownLintCheck.CONFIG_FILE_NAME)): + config_file_path = os.path.join(abs_pkg_path, MarkdownLintCheck.CONFIG_FILE_NAME) + + # 2nd check to see if at workspace root + elif os.path.isfile(os.path.join(Edk2pathObj.WorkspacePath, MarkdownLintCheck.CONFIG_FILE_NAME)): + config_file_path = os.path.join(Edk2pathObj.WorkspacePath, MarkdownLintCheck.CONFIG_FILE_NAME) + + # If not found - skip test + else: + tc.SetSkipped() + tc.LogStdError(f"{MarkdownLintCheck.CONFIG_FILE_NAME} not found. Skipping test") + logging.warning(f"{MarkdownLintCheck.CONFIG_FILE_NAME} not found. Skipping test") + return -1 + + # Run the linter + results = self._check_markdown(path_to_check, config_file_path, Ignores) + for r in results: + tc.LogStdError(r.strip()) + + # add result to test case + overall_status = len(results) + if overall_status != 0: + if "AuditOnly" in pkgconfig and pkgconfig["AuditOnly"]: + # set as skipped if AuditOnly + tc.SetSkipped() + return -1 + else: + tc.SetFailed("Markdown Lint Check {0} Failed. Errors {1}".format( + packagename, overall_status), "CHECK_FAILED") + else: + tc.SetSuccess() + return overall_status + + def _check_markdown(self, rel_file_to_check: os.PathLike, abs_config_file_to_use: os.PathLike, Ignores: List[str]) -> List[str]: + """ Run markdownlint against the given path and return any errors found. + + Args: + rel_file_to_check: package root relative glob pattern of markdown files to check + abs_config_file_to_use: absolute path to the .markdownlint.yaml config file to use + Ignores: list of package root relative file, folder, or glob patterns to ignore + Returns: + a list of error strings reported by markdownlint. Empty if no errors found. + """ + output = StringIO() + param = f"--config {abs_config_file_to_use}" + for a in Ignores: + param += f' --ignore "{a}"' + param += f' "{rel_file_to_check}"' + + ret = RunCmd("markdownlint", param, outstream=output) + if ret == 0: + return [] + else: + return output.getvalue().strip().splitlines() diff --git a/.pytool/Plugin/MarkdownLintCheck/MarkdownLintCheck_plug_in.yaml b/.pytool/Plugin/MarkdownLintCheck/MarkdownLintCheck_plug_in.yaml new file mode 100644 index 0000000000..53d8172e18 --- /dev/null +++ b/.pytool/Plugin/MarkdownLintCheck/MarkdownLintCheck_plug_in.yaml @@ -0,0 +1,11 @@ +## @file +# CiBuildPlugin used to lint repository documentation in markdown files +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## +{ + "scope": "cibuild", + "name": "Markdown Lint Test", + "module": "MarkdownLintCheck" +} diff --git a/.pytool/Plugin/MarkdownLintCheck/Readme.md b/.pytool/Plugin/MarkdownLintCheck/Readme.md new file mode 100644 index 0000000000..93f2bb8ade --- /dev/null +++ b/.pytool/Plugin/MarkdownLintCheck/Readme.md @@ -0,0 +1,61 @@ +# Markdown Lint Plugin + +This CiBuildPlugin scans all the markdown files in a given package and checks for linter errors. + +## Requirements + +The test case in this plugin will be skipped if the requirements are not met. + +1. NodeJs installed and on your path +2. `markdownlint-cli` NodeJs package installed +3. A `.markdownlint.yaml` config file either at your repository root or package root. + +- NodeJS: <https://nodejs.org/en/> +- markdownlint-cli: <https://www.npmjs.com/package/markdownlint-cli> + - Source repository: <https://github.com/igorshubovych/markdownlint-cli> + +## Configuration + +It is desired to use standard configuration methods so that both local editors and CI process leverage the same +configuration. This mostly works but for ignoring files there is currently a small discrepancy. + +First there is/can be a `.markdownlintignore` file at root of the repository. This file much like a `.gitignore` is +great for broadly ignoring files with patterns. This works for both usage in a local editor and CI. + +For the CI plugin, you can use the `IgnoreFiles` configuration option described in the Plugin Configuration. + +## Plugin Configuration + +The plugin has only minimal configuration options to support the UEFI codebase. + +``` yaml + "MarkdownLintCheck": { + "AuditOnly": False, # If True, log all errors and then mark as skipped + "IgnoreFiles": [] # Package root relative file, folder, or glob pattern to ignore + } +``` + +### AuditOnly + +- `Boolean` - Default is `False`. + +If `True` run the test in an Audit only mode which will log all errors but instead of failing the build it will set the +test as skipped. This allows visibility into the failures without breaking the build. + +### IgnoreFiles + +This supports package relative files, folders, and glob patterns to ignore. These are passed to the markdownlint-cli +tool as quoted `-i` parameters. + +## Linter Configuration + +All configuration options available to the linter can be set in `.markdownlint.yaml`. This includes customizing +rule options and enforcement. + +- Markdownlint configuration options: <https://github.com/DavidAnson/markdownlint#configuration> +- Linter rules: <https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md> + +## Rule Overrides + +There are times when a certain rule should not apply to part of a markdown file. Markdownlint has numerous ways +to configure this. See the in-file configuration options described in the links above. From b3f19fb5ce9e9214a74c71c1993023977b26c919 Mon Sep 17 00:00:00 2001 From: Jean-Tiare Le Bigot <jt@yadutaf.fr> Date: Tue, 16 Jun 2026 11:10:45 +0200 Subject: [PATCH 302/406] CryptoPkg: Match OpenSSL's default security level `TlsNew()` explicitly sets the default security level to 3. The current default in OpenSSL is security level 2 which is inherited by Linux distributions like Ubuntu 26.04. This is also the security level that was announced in https://edk2.groups.io/g/devel/topic/115039926. Signed-off-by: Jean-Tiare Le Bigot <jt@yadutaf.fr> --- CryptoPkg/Library/TlsLib/TlsInit.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CryptoPkg/Library/TlsLib/TlsInit.c b/CryptoPkg/Library/TlsLib/TlsInit.c index 96634cffcc..d19f5cb233 100644 --- a/CryptoPkg/Library/TlsLib/TlsInit.c +++ b/CryptoPkg/Library/TlsLib/TlsInit.c @@ -185,11 +185,6 @@ TlsNew ( return NULL; } - // - // This retains compatibility with previous version of OpenSSL. - // - SSL_set_security_level (TlsConn->Ssl, 3); - // // Initialize the created SSL Object // From 93ee30067582f325c951505c835f5c5b85649148 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Fri, 24 Jul 2026 00:49:22 -0700 Subject: [PATCH 303/406] ArmPkg: StandaloneMmCoreEntryPoint: Use ARM_FFA_ARGS for misc buffer The MISC_MM_COMMUNICATE_BUFFER stored the FF-A direct message registers in a DIRECT_MSG_ARGS structure. Populating and reading it required manually re-indexing every register (EventSvcArgs->Arg4..Arg17 into DirectMsgArgs.Arg0..Arg13). This shifted the register positions and left the buffer layout inconsistent with the raw FF-A argument register file, making it error prone to correlate a slot with its architectural register. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- .../Library/ArmStandaloneMmCoreEntryPoint.h | 6 +-- .../ArmStandaloneMmCoreEntryPoint.c | 46 +++++++------------ 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/ArmPkg/Include/Library/ArmStandaloneMmCoreEntryPoint.h b/ArmPkg/Include/Library/ArmStandaloneMmCoreEntryPoint.h index 2f99fa1b6e..8cad12cafd 100644 --- a/ArmPkg/Include/Library/ArmStandaloneMmCoreEntryPoint.h +++ b/ArmPkg/Include/Library/ArmStandaloneMmCoreEntryPoint.h @@ -58,13 +58,13 @@ typedef struct ServiceTableEntry { */ typedef struct { /// Service guid - EFI_GUID HeaderGuid; + EFI_GUID HeaderGuid; /// Length of Message. In case of misc service, sizeof (EventSvcArgs) - UINTN MessageLength; + UINTN MessageLength; /// Delivered register values. - DIRECT_MSG_ARGS DirectMsgArgs; + ARM_FFA_ARGS FfaArgs; } MISC_MM_COMMUNICATE_BUFFER; typedef struct { diff --git a/ArmPkg/Library/ArmStandaloneMmCoreEntryPoint/ArmStandaloneMmCoreEntryPoint.c b/ArmPkg/Library/ArmStandaloneMmCoreEntryPoint/ArmStandaloneMmCoreEntryPoint.c index 344cfe3904..98c6d87d10 100644 --- a/ArmPkg/Library/ArmStandaloneMmCoreEntryPoint/ArmStandaloneMmCoreEntryPoint.c +++ b/ArmPkg/Library/ArmStandaloneMmCoreEntryPoint/ArmStandaloneMmCoreEntryPoint.c @@ -780,20 +780,20 @@ SetEventCompleteSvcArgs ( EventCompleteSvcArgs->Arg0 = ARM_FID_FFA_MSG_SEND_DIRECT_RESP2; if (FfaMsgInfo->ServiceType == ServiceTypeMisc) { - EventCompleteSvcArgs->Arg4 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg0; - EventCompleteSvcArgs->Arg5 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg1; - EventCompleteSvcArgs->Arg6 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg2; - EventCompleteSvcArgs->Arg7 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg3; - EventCompleteSvcArgs->Arg8 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg4; - EventCompleteSvcArgs->Arg9 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg5; - EventCompleteSvcArgs->Arg10 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg6; - EventCompleteSvcArgs->Arg11 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg7; - EventCompleteSvcArgs->Arg12 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg8; - EventCompleteSvcArgs->Arg13 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg9; - EventCompleteSvcArgs->Arg14 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg10; - EventCompleteSvcArgs->Arg15 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg11; - EventCompleteSvcArgs->Arg16 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg12; - EventCompleteSvcArgs->Arg17 = mMiscMmCommunicateBuffer->DirectMsgArgs.Arg13; + EventCompleteSvcArgs->Arg4 = mMiscMmCommunicateBuffer->FfaArgs.Arg4; + EventCompleteSvcArgs->Arg5 = mMiscMmCommunicateBuffer->FfaArgs.Arg5; + EventCompleteSvcArgs->Arg6 = mMiscMmCommunicateBuffer->FfaArgs.Arg6; + EventCompleteSvcArgs->Arg7 = mMiscMmCommunicateBuffer->FfaArgs.Arg7; + EventCompleteSvcArgs->Arg8 = mMiscMmCommunicateBuffer->FfaArgs.Arg8; + EventCompleteSvcArgs->Arg9 = mMiscMmCommunicateBuffer->FfaArgs.Arg9; + EventCompleteSvcArgs->Arg10 = mMiscMmCommunicateBuffer->FfaArgs.Arg10; + EventCompleteSvcArgs->Arg11 = mMiscMmCommunicateBuffer->FfaArgs.Arg11; + EventCompleteSvcArgs->Arg12 = mMiscMmCommunicateBuffer->FfaArgs.Arg12; + EventCompleteSvcArgs->Arg13 = mMiscMmCommunicateBuffer->FfaArgs.Arg13; + EventCompleteSvcArgs->Arg14 = mMiscMmCommunicateBuffer->FfaArgs.Arg14; + EventCompleteSvcArgs->Arg15 = mMiscMmCommunicateBuffer->FfaArgs.Arg15; + EventCompleteSvcArgs->Arg16 = mMiscMmCommunicateBuffer->FfaArgs.Arg16; + EventCompleteSvcArgs->Arg17 = mMiscMmCommunicateBuffer->FfaArgs.Arg17; } } @@ -831,21 +831,9 @@ InitializeMiscMmCommunicateBuffer ( { ZeroMem (Buffer, sizeof (MISC_MM_COMMUNICATE_BUFFER)); - Buffer->MessageLength = sizeof (DIRECT_MSG_ARGS); - Buffer->DirectMsgArgs.Arg0 = EventSvcArgs->Arg4; - Buffer->DirectMsgArgs.Arg1 = EventSvcArgs->Arg5; - Buffer->DirectMsgArgs.Arg2 = EventSvcArgs->Arg6; - Buffer->DirectMsgArgs.Arg3 = EventSvcArgs->Arg7; - Buffer->DirectMsgArgs.Arg4 = EventSvcArgs->Arg8; - Buffer->DirectMsgArgs.Arg5 = EventSvcArgs->Arg9; - Buffer->DirectMsgArgs.Arg6 = EventSvcArgs->Arg10; - Buffer->DirectMsgArgs.Arg7 = EventSvcArgs->Arg11; - Buffer->DirectMsgArgs.Arg8 = EventSvcArgs->Arg12; - Buffer->DirectMsgArgs.Arg9 = EventSvcArgs->Arg13; - Buffer->DirectMsgArgs.Arg10 = EventSvcArgs->Arg14; - Buffer->DirectMsgArgs.Arg11 = EventSvcArgs->Arg15; - Buffer->DirectMsgArgs.Arg12 = EventSvcArgs->Arg16; - Buffer->DirectMsgArgs.Arg13 = EventSvcArgs->Arg17; + Buffer->MessageLength = sizeof (DIRECT_MSG_ARGS); + + CopyMem (&Buffer->FfaArgs, EventSvcArgs, sizeof (ARM_FFA_ARGS)); CopyGuid (&Buffer->HeaderGuid, ServiceGuid); } From bdd36cdc1a1fb411bc8edc5f8ec81115be99ab48 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Thu, 23 Jul 2026 17:12:02 -0700 Subject: [PATCH 304/406] SecurityPkg: Tcg2StandaloneMmArm: Align PP buffer with ARM_FFA_ARGS The misc MM communicate buffer now stores the FF-A direct message registers in an ARM_FFA_ARGS layout that preserves the native register indices. The TCG physical presence callback must therefore locate the TCG_NVS payload at the correct register offset instead of the start of the communication buffer. Point LocalTcgNvs at CommBuffer + OFFSET_OF (ARM_FFA_ARGS, Arg4) and validate the buffer size against sizeof (ARM_FFA_ARGS). Add a STATIC_ASSERT to guarantee TCG_NVS fits within the register space available for the direct message payload, and include ArmFfaLib.h for the ARM_FFA_ARGS definition. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- SecurityPkg/Tcg/Tcg2StandaloneMmArm/Tcg2StandaloneMmArm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SecurityPkg/Tcg/Tcg2StandaloneMmArm/Tcg2StandaloneMmArm.c b/SecurityPkg/Tcg/Tcg2StandaloneMmArm/Tcg2StandaloneMmArm.c index aed3f6a7eb..7651edb70b 100644 --- a/SecurityPkg/Tcg/Tcg2StandaloneMmArm/Tcg2StandaloneMmArm.c +++ b/SecurityPkg/Tcg/Tcg2StandaloneMmArm/Tcg2StandaloneMmArm.c @@ -18,12 +18,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <PiMm.h> #include <IndustryStandard/TcgPhysicalPresence.h> #include <Guid/TpmNvsMm.h> +#include <Library/ArmFfaLib.h> #include <Library/DebugLib.h> #include <Library/BaseMemoryLib.h> #include <Library/MmServicesTableLib.h> #include <Library/StandaloneMmMemLib.h> #include <Library/Tcg2PhysicalPresenceLib.h> +STATIC_ASSERT (sizeof (TCG_NVS) <= (sizeof (ARM_FFA_ARGS) - OFFSET_OF (ARM_FFA_ARGS, Arg4)), "TCG_NVS size is larger than direct message buffer size"); + /** This function checks if the required instance is a supported TPM 2.0 instance. It currently supports two instances: dTPM and FFA. @@ -97,7 +100,7 @@ PhysicalPresenceCallback ( return EFI_INVALID_PARAMETER; } - if (*CommBufferSize < sizeof (TCG_NVS)) { + if (*CommBufferSize < sizeof (ARM_FFA_ARGS)) { return EFI_INVALID_PARAMETER; } @@ -107,7 +110,7 @@ PhysicalPresenceCallback ( } // Enough complaints, now get to work... - LocalTcgNvs = (TCG_NVS *)CommBuffer; + LocalTcgNvs = (TCG_NVS *)((UINT8 *)CommBuffer + OFFSET_OF (ARM_FFA_ARGS, Arg4)); if (LocalTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS) { LocalTcgNvs->PhysicalPresence.ReturnCode = Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction ( From 372318bb941f6dd222c30847889aeacf871d2cf2 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Tue, 7 Jul 2026 16:08:41 -0700 Subject: [PATCH 305/406] ArmVirtPkg: PlatformCI: Add PATH_TO_OS Flag This adds the ability to pass PATH_TO_OS to the PlatformBuild.py scripts in the PlatformCI folder. This allows easy booting to an OS (or generically adding a drive) while using the standard PlatformBuild.py for ArmVirtPkg. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- ArmVirtPkg/PlatformCI/PlatformBuildLib.py | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ArmVirtPkg/PlatformCI/PlatformBuildLib.py b/ArmVirtPkg/PlatformCI/PlatformBuildLib.py index 6895677d43..8987217e41 100644 --- a/ArmVirtPkg/PlatformCI/PlatformBuildLib.py +++ b/ArmVirtPkg/PlatformCI/PlatformBuildLib.py @@ -17,7 +17,7 @@ from edk2toolext.invocables.edk2_update import UpdateSettingsManager from edk2toolext.invocables.edk2_pr_eval import PrEvalSettingsManager from edk2toollib.utility_functions import RunCmd from edk2toollib.utility_functions import GetHostInfo - +from pathlib import Path # ####################################################################################### # # Configuration for Update & Setup # @@ -236,11 +236,33 @@ class PlatformBuilder(UefiBuilder, BuildSettingsManager): # Common Args args += CommonPlatform.FvQemuArg + Built_FV # path to fw - args += " -m 1024" # 1gb memory # turn off network args += " -net none" # Serial messages out args += " -serial stdio" + + path_to_os = self.env.GetValue("PATH_TO_OS") + if path_to_os is not None: + args += f" -m 8192" # 8gb memory for OS + file_extension = Path(path_to_os).suffix.lower().replace('"', '') + + storage_format = { + ".vhd": "raw", + ".qcow2": "qcow2", + ".iso": "iso", + }.get(file_extension, None) + + if storage_format is None: + raise Exception(f"Unknown OS storage type: {path_to_os}") + + if storage_format == "iso": + args += f" -cdrom \"{path_to_os}\"" + else: + args += f" -drive file=\"{path_to_os}\",format={storage_format},if=none,id=os_nvme" + args += " -device nvme,serial=nvme-1,drive=os_nvme,bootindex=0" + else: + args += " -m 1024" # 1gb memory + # Mount disk with startup.nsh args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk" # Provides Rng services to the Guest VM From 73f796bcf96ddd06e1aa0439c776154cccf06a5f Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny <osde@microsoft.com> Date: Tue, 7 Jul 2026 16:10:17 -0700 Subject: [PATCH 306/406] OvmfPkg: PlatformCI: Add PATH_TO_OS Flag This adds the ability to pass PATH_TO_OS to the PlatformBuild.py scripts in the PlatformCI folder. This allows easy booting to an OS (or generically adding a drive) while using the standard PlatformBuild.py for OvmfPkg. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com> --- OvmfPkg/PlatformCI/PlatformBuildLib.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/PlatformCI/PlatformBuildLib.py b/OvmfPkg/PlatformCI/PlatformBuildLib.py index 635da87761..6aec9af3fa 100644 --- a/OvmfPkg/PlatformCI/PlatformBuildLib.py +++ b/OvmfPkg/PlatformCI/PlatformBuildLib.py @@ -16,7 +16,7 @@ from edk2toolext.invocables.edk2_setup import SetupSettingsManager, RequiredSubm from edk2toolext.invocables.edk2_update import UpdateSettingsManager from edk2toolext.invocables.edk2_pr_eval import PrEvalSettingsManager from edk2toollib.utility_functions import RunCmd - +from pathlib import Path # ####################################################################################### # # Configuration for Update & Setup # @@ -209,6 +209,27 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager): args += " -cpu IvyBridge,+rdrand" # IvyBridge is the first CPU that supported # RDRAND, which is required for dynamic # stack cookies + + path_to_os = self.env.GetValue("PATH_TO_OS") + if path_to_os is not None: + args += f" -m 8192" # 8gb memory for OS + file_extension = Path(path_to_os).suffix.lower().replace('"', '') + + storage_format = { + ".vhd": "raw", + ".qcow2": "qcow2", + ".iso": "iso", + }.get(file_extension, None) + + if storage_format is None: + raise Exception(f"Unknown OS storage type: {path_to_os}") + + if storage_format == "iso": + args += f" -cdrom \"{path_to_os}\"" + else: + args += f" -drive file=\"{path_to_os}\",format={storage_format},if=none,id=os_nvme" + args += " -device nvme,serial=nvme-1,drive=os_nvme,bootindex=0" + args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk" # Mount disk with startup.nsh # Provides Rng services to the Guest VM args += " -device virtio-rng-pci" From 8f38acae6bd350622dd13dfbcd33777a2a4a0d9f Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Oct 2025 11:13:38 -0700 Subject: [PATCH 307/406] MdeModulePkg: Fix comparison with wider widths https://codeql.github.com/codeql-query-help/cpp/cpp-comparison-with-wider-type If the narrow type (smaller range) is compared against a wide type (larger range), the narrow value may overflow before reaching the wide value. This can cause unexpected behavior, such as: Infinite loops (loop condition never becomes false). Incorrect logic (comparison results are misleading). Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../CustomizedDisplayLibInternal.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c index bd5b8f5ea2..21e7e87c94 100644 --- a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c +++ b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c @@ -49,8 +49,8 @@ PrintBannerInfo ( IN FORM_DISPLAY_ENGINE_FORM *FormData ) { - UINT8 Line; - UINT8 Alignment; + UINTN Line; + UINTN Alignment; CHAR16 *StrFrontPageBanner; UINT8 RowIdx; UINT8 ColumnIdx; @@ -69,12 +69,12 @@ PrintBannerInfo ( // // for (Line = 0; Line < BANNER_HEIGHT; Line++) { // - for (Line = (UINT8)gScreenDimensions.TopRow; Line < BANNER_HEIGHT + (UINT8)gScreenDimensions.TopRow; Line++) { + for (Line = gScreenDimensions.TopRow; Line < BANNER_HEIGHT + gScreenDimensions.TopRow; Line++) { // // for (Alignment = 0; Alignment < BANNER_COLUMNS; Alignment++) { // - for (Alignment = (UINT8)gScreenDimensions.LeftColumn; - Alignment < BANNER_COLUMNS + (UINT8)gScreenDimensions.LeftColumn; + for (Alignment = gScreenDimensions.LeftColumn; + Alignment < BANNER_COLUMNS + gScreenDimensions.LeftColumn; Alignment++ ) { From a1aab535ce2a009e91b7b93490a856cc7bf25e27 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Oct 2025 12:57:49 -0700 Subject: [PATCH 308/406] MdeModulePkg: Fix missing NULL tests https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp For items which allocate memory, or get a pointer from another structure, it is important to validate that the pointers are not null before they are dereferenced. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../Library/BootManagerUiLib/BootManager.c | 20 +++++++++++++++-- .../DeviceManagerUiLib/DeviceManager.c | 5 ++++- .../Library/DxeCapsuleLibFmp/CapsuleOnDisk.c | 2 +- .../DxeSecurityManagementLib.c | 19 ++++++++++------ .../Library/FileExplorerLib/FileExplorer.c | 5 ++++- .../Library/SmmLockBoxLib/SmmLockBoxMmLib.c | 22 +++++++++++++++---- .../Library/UefiSortLib/UefiSortLib.c | 5 ++++- 7 files changed, 61 insertions(+), 17 deletions(-) diff --git a/MdeModulePkg/Library/BootManagerUiLib/BootManager.c b/MdeModulePkg/Library/BootManagerUiLib/BootManager.c index c2232e525b..a42f44e4a9 100644 --- a/MdeModulePkg/Library/BootManagerUiLib/BootManager.c +++ b/MdeModulePkg/Library/BootManagerUiLib/BootManager.c @@ -514,6 +514,12 @@ UpdateBootManager ( GroupMultipleLegacyBootOption4SameType (); BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); + if (BootOption == NULL) { + // + // No boot option available, return directly + // + return; + } HiiHandle = gBootManagerPrivate.HiiHandle; @@ -521,10 +527,17 @@ UpdateBootManager ( // Allocate space for creation of UpdateData Buffer // StartOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (StartOpCodeHandle != NULL); + if (StartOpCodeHandle == NULL) { + ASSERT (StartOpCodeHandle != NULL); + return; + } EndOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (EndOpCodeHandle != NULL); + if (EndOpCodeHandle == NULL) { + HiiFreeOpCodeHandle (StartOpCodeHandle); + ASSERT (EndOpCodeHandle != NULL); + return; + } // // Create Hii Extend Label OpCode as the start opcode @@ -853,6 +866,9 @@ BootManagerCallback ( } BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); + if (BootOption == NULL) { + return EFI_UNSUPPORTED; + } // // Clear the screen before. diff --git a/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c b/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c index 3950bbb169..c20ab86b2d 100644 --- a/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c +++ b/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c @@ -593,7 +593,10 @@ CreateDeviceManagerForm ( // Get all the Hii handles // HiiHandles = HiiGetHiiHandles (NULL); - ASSERT (HiiHandles != NULL); + if (HiiHandles == NULL) { + ASSERT (HiiHandles != NULL); + return; + } // // Search for formset of each class type diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c index 41b3282d29..a69c2365cc 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c @@ -301,7 +301,7 @@ GetBootOptionInOrder ( // Second get BootOption from "BootOrder" // BootOrderOptionBuf = EfiBootManagerGetLoadOptions (&BootOrderCount, LoadOptionTypeBoot); - if ((BootNextCount == 0) && (BootOrderCount == 0)) { + if (((BootNextCount == 0) && (BootOrderCount == 0)) || (BootOrderOptionBuf == NULL)) { return EFI_NOT_FOUND; } diff --git a/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c b/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c index 8b8cf3a7d3..c89cf9f985 100644 --- a/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c +++ b/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c @@ -220,7 +220,7 @@ ExecuteSecurityHandlers ( UINTN FileSize; EFI_HANDLE Handle; EFI_DEVICE_PATH_PROTOCOL *Node; - EFI_DEVICE_PATH_PROTOCOL *FilePathToVerfiy; + EFI_DEVICE_PATH_PROTOCOL *FilePathToVerify; if (FilePath == NULL) { return EFI_INVALID_PARAMETER; @@ -237,7 +237,7 @@ ExecuteSecurityHandlers ( FileBuffer = NULL; FileSize = 0; HandlerAuthenticationStatus = AuthenticationStatus; - FilePathToVerfiy = (EFI_DEVICE_PATH_PROTOCOL *)FilePath; + FilePathToVerify = (EFI_DEVICE_PATH_PROTOCOL *)FilePath; // // Run security handler in same order to their registered list // @@ -247,7 +247,7 @@ ExecuteSecurityHandlers ( // Try get file buffer when the handler requires image buffer. // if (FileBuffer == NULL) { - Node = FilePathToVerfiy; + Node = FilePathToVerify; Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &Node, &Handle); // // Try to get image by FALSE boot policy for the exact boot file path. @@ -264,14 +264,19 @@ ExecuteSecurityHandlers ( // // LoadFile () may cause the device path of the Handle be updated. // - FilePathToVerfiy = AppendDevicePath (DevicePathFromHandle (Handle), Node); + FilePathToVerify = AppendDevicePath (DevicePathFromHandle (Handle), Node); } } } + if (FilePathToVerify == NULL) { + ASSERT (FilePathToVerify != NULL); + continue; + } + Status = mSecurityTable[Index].SecurityHandler ( HandlerAuthenticationStatus, - FilePathToVerfiy, + FilePathToVerify, FileBuffer, FileSize ); @@ -284,8 +289,8 @@ ExecuteSecurityHandlers ( FreePool (FileBuffer); } - if (FilePathToVerfiy != FilePath) { - FreePool (FilePathToVerfiy); + if (FilePathToVerify != FilePath) { + FreePool (FilePathToVerify); } return Status; diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c index 42ad80c2d7..1555972ee0 100644 --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c @@ -560,7 +560,10 @@ LibFileInfo ( ); if (Status == EFI_BUFFER_TOO_SMALL) { Buffer = AllocatePool (BufferSize); - ASSERT (Buffer != NULL); + if (Buffer == NULL) { + ASSERT (Buffer != NULL); + return NULL; + } } Status = FHand->GetInfo ( diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c index ab2cb7a2b4..5209b5cb1b 100644 --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c @@ -366,7 +366,9 @@ InternalGetLockBoxQueue ( /** This function find LockBox by GUID. - @param Guid The guid to indentify the LockBox + NULL will be returned by this function if the lock box queue is not found. + + @param Guid The guid to identify the LockBox @return LockBoxData **/ @@ -380,7 +382,11 @@ InternalFindLockBoxByGuid ( LIST_ENTRY *LockBoxQueue; LockBoxQueue = InternalGetLockBoxQueue (); - ASSERT (LockBoxQueue != NULL); + + if (LockBoxQueue == NULL) { + ASSERT (LockBoxQueue != NULL); + return NULL; + } for (Link = LockBoxQueue->ForwardLink; Link != LockBoxQueue; @@ -500,7 +506,11 @@ SaveLockBox ( )); LockBoxQueue = InternalGetLockBoxQueue (); - ASSERT (LockBoxQueue != NULL); + if (LockBoxQueue == NULL) { + ASSERT (LockBoxQueue != NULL); + return EFI_OUT_OF_RESOURCES; + } + InsertTailList (LockBoxQueue, &LockBox->Link); // @@ -834,6 +844,7 @@ RestoreLockBox ( @retval RETURN_SUCCESS the information is restored successfully. @retval RETURN_NOT_STARTED it is too early to invoke this interface @retval RETURN_UNSUPPORTED the service is not supported by implementaion. + @retval RETURN_OUT_OF_RESOURCES Not enough resources to save the information. **/ RETURN_STATUS EFIAPI @@ -848,7 +859,10 @@ RestoreAllLockBoxInPlace ( DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib RestoreAllLockBoxInPlace - Enter\n")); LockBoxQueue = InternalGetLockBoxQueue (); - ASSERT (LockBoxQueue != NULL); + if (LockBoxQueue == NULL) { + ASSERT (LockBoxQueue != NULL); + return EFI_OUT_OF_RESOURCES; + } // // Restore all, Buffer and Length MUST be NULL diff --git a/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c b/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c index 0ba1244930..46a3e8de4f 100644 --- a/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c +++ b/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c @@ -62,7 +62,10 @@ PerformQuickSort ( ASSERT (CompareFunction != NULL); Buffer = AllocateZeroPool (ElementSize); - ASSERT (Buffer != NULL); + if (Buffer == NULL) { + ASSERT (Buffer != NULL); + return; + } QuickSort ( BufferToSort, From 4f03df803e0863d7517a21cc9cd98d8a4696ec45 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Mon, 27 Jul 2026 09:52:37 -0700 Subject: [PATCH 309/406] Maintainers: Add Aaron Pop to EDK II Contributed Files Add as reviewer to Breaking-Changs.md. Add as a maintainer to VSCode notebook. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- Maintainers.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Maintainers.txt b/Maintainers.txt index 2fcb84e8f1..61b1a08d3c 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -153,10 +153,12 @@ EDK II Contributed Files: Breaking Changes Documentation F: BREAKING-CHANGES.md R: Michael Kubacki <mikuback@linux.microsoft.com> [makubacki] +R: Aaron Pop <aaronpop@microsoft.com> [apop5] VS Code PR Dashboard Notebook F: contrib/PullRequests.github-issues M: Michael Kubacki <mikuback@linux.microsoft.com> [makubacki] +M: Aaron Pop <aaronpop@microsoft.com> [apop5] EDK II Packages: ---------------- From 99afb1ffb0c5e1c772853a6e5b4ecb75ff95f896 Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Thu, 12 May 2022 20:08:19 +0000 Subject: [PATCH 310/406] MdeModulePkg/HiiDatabaseDxe: Fix potential intrinsic error In some VS22 versions, these code patterns (assiging the scalar in a loop) have been found to be converted into calls to the `memcpy` intrinsic. This change updates them to use CopyMem to avoid the potential error. Previous: - MSVC version: 14.31.31103 New: - MSVC version: 14.32.31326 Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- MdeModulePkg/Universal/HiiDatabaseDxe/Image.c | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c index ae5eff7078..a30a3d3ab7 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c @@ -287,9 +287,9 @@ Output1bitPixel ( Byte = *(Data + OffsetY + Xpos); for (Index = 0; Index < 8; Index++) { if ((Byte & (1 << Index)) != 0) { - BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)].Raw = PaletteValue[1].Raw; + CopyMem (&BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)], &PaletteValue[1], sizeof (*BitMapPtr)); } else { - BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)].Raw = PaletteValue[0].Raw; + CopyMem (&BitMapPtr[Ypos * Image->Width + Xpos * 8 + (8 - Index - 1)], &PaletteValue[0], sizeof (*BitMapPtr)); } } } @@ -301,9 +301,9 @@ Output1bitPixel ( Byte = *(Data + OffsetY + Xpos); for (Index = 0; Index < Image->Width % 8; Index++) { if ((Byte & (1 << (8 - Index - 1))) != 0) { - BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index].Raw = PaletteValue[1].Raw; + CopyMem (&BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index], &PaletteValue[1], sizeof (*BitMapPtr)); } else { - BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index].Raw = PaletteValue[0].Raw; + CopyMem (&BitMapPtr[Ypos * Image->Width + Xpos * 8 + Index], &PaletteValue[0], sizeof (*BitMapPtr)); } } } @@ -373,17 +373,17 @@ Output4bitPixel ( // All bits in these bytes are meaningful // for (Xpos = 0; Xpos < Image->Width / 2; Xpos++) { - Byte = *(Data + OffsetY + Xpos); - BitMapPtr[Ypos * Image->Width + Xpos * 2].Raw = PaletteValue[Byte >> 4].Raw; - BitMapPtr[Ypos * Image->Width + Xpos * 2 + 1].Raw = PaletteValue[Byte & 0x0F].Raw; + Byte = *(Data + OffsetY + Xpos); + CopyMem (&BitMapPtr[Ypos * Image->Width + Xpos * 2], &PaletteValue[Byte >> 4], sizeof (*BitMapPtr)); + CopyMem (&BitMapPtr[Ypos * Image->Width + Xpos * 2 + 1], &PaletteValue[Byte & 0x0F], sizeof (*BitMapPtr)); } if (Image->Width % 2 != 0) { // // Padding bits in this byte should be ignored. // - Byte = *(Data + OffsetY + Xpos); - BitMapPtr[Ypos * Image->Width + Xpos * 2].Raw = PaletteValue[Byte >> 4].Raw; + Byte = *(Data + OffsetY + Xpos); + CopyMem (&BitMapPtr[Ypos * Image->Width + Xpos * 2], &PaletteValue[Byte >> 4], sizeof (*BitMapPtr)); } } } @@ -450,8 +450,8 @@ Output8bitPixel ( // All bits are meaningful since the bitmap is 8 bits per pixel. // for (Xpos = 0; Xpos < Image->Width; Xpos++) { - Byte = *(Data + OffsetY + Xpos); - BitMapPtr[OffsetY + Xpos].Raw = PaletteValue[Byte].Raw; + Byte = *(Data + OffsetY + Xpos); + CopyMem (&BitMapPtr[OffsetY + Xpos], &PaletteValue[Byte], sizeof (*BitMapPtr)); } } } @@ -528,8 +528,6 @@ ImageToBlt ( UINTN OffsetY2; // dest buffer EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION SrcPixel; EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION ZeroPixel; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *BltBufferPixel; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *ImageBitmap; if ((BltBuffer == NULL) || (Blt == NULL) || (*Blt == NULL)) { return EFI_INVALID_PARAMETER; @@ -547,20 +545,17 @@ ImageToBlt ( ZeroMem (&ZeroPixel, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); - BltBufferPixel = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *)BltBuffer; - ImageBitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *)ImageOut->Image.Bitmap; - for (Ypos = 0; Ypos < Height; Ypos++) { OffsetY1 = Width * Ypos; OffsetY2 = ImageOut->Width * (BltY + Ypos); for (Xpos = 0; Xpos < Width; Xpos++) { - SrcPixel.Raw = BltBufferPixel[OffsetY1 + Xpos].Raw; + CopyMem (&SrcPixel, &BltBuffer[OffsetY1 + Xpos], sizeof (SrcPixel)); if (Transparent) { if (CompareMem (&SrcPixel, &ZeroPixel, 3) != 0) { - ImageBitmap[OffsetY2 + BltX + Xpos].Raw = SrcPixel.Raw; + CopyMem (&ImageOut->Image.Bitmap[OffsetY2 + BltX + Xpos], &SrcPixel, sizeof (SrcPixel)); } } else { - ImageBitmap[OffsetY2 + BltX + Xpos].Raw = SrcPixel.Raw; + CopyMem (&ImageOut->Image.Bitmap[OffsetY2 + BltX + Xpos], &SrcPixel, sizeof (SrcPixel)); } } } From 2d43dcfc6ccfafe1e0db09e3b0371be3b42a0f3a Mon Sep 17 00:00:00 2001 From: Sean Brogan <sean.brogan@microsoft.com> Date: Tue, 2 Jul 2024 13:28:04 -0700 Subject: [PATCH 311/406] PcAtChipsetPkg/SerialIoLib: Allow configurable UART IO Port Base Address Today's implementation used a hardcoded value for the I/O Port Base Address. This creates a problem for platform configurability. If a platform needs to use a different I/O port address, then it requires modification of a source file. Create gPcAtChipsetPkgTokenSpaceGuid.PcdUartIoPortBaseAddress as a FixedAtBuild pcd scoped to PcAtChipsetPkg, with default value for 0x3f8 to match existing value, and update code to use PCD. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf | 3 +++ PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c | 2 +- PcAtChipsetPkg/PcAtChipsetPkg.dec | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf b/PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf index d02259a07c..1c5099cdb5 100644 --- a/PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf +++ b/PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf @@ -17,6 +17,7 @@ [Packages] MdePkg/MdePkg.dec + PcAtChipsetPkg/PcAtChipsetPkg.dec [LibraryClasses] BaseLib @@ -25,3 +26,5 @@ [Sources] SerialPortLib.c +[Pcd] + gPcAtChipsetPkgTokenSpaceGuid.PcdUartIoPortBaseAddress diff --git a/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c b/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c index 11537ec276..6e25b1ba5a 100644 --- a/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c +++ b/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c @@ -43,7 +43,7 @@ // --------------------------------------------- // UART Settings // --------------------------------------------- -UINT16 gUartBase = 0x3F8; +UINT16 gUartBase = FixedPcdGet16 (PcdUartIoPortBaseAddress); UINTN gBps = 115200; UINT8 gData = 8; UINT8 gStop = 1; diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dec b/PcAtChipsetPkg/PcAtChipsetPkg.dec index 0db385fb90..8026fcd8a8 100644 --- a/PcAtChipsetPkg/PcAtChipsetPkg.dec +++ b/PcAtChipsetPkg/PcAtChipsetPkg.dec @@ -164,5 +164,10 @@ # @Prompt RTC Update Timeout Value. gPcAtChipsetPkgTokenSpaceGuid.PcdRealTimeClockUpdateTimeout|100000|UINT32|0x00000020 +[PcdsFixedAtBuild] + ## Defines the UART base address. + # @Prompt UART IO Port Base Address + gPcAtChipsetPkgTokenSpaceGuid.PcdUartIoPortBaseAddress|0x3F8|UINT16|0x00000024 + [UserExtensions.TianoCore."ExtraFiles"] PcAtChipsetPkgExtra.uni From f7776de02e12fbae51937a4fbf74c637e0c76029 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Tue, 21 Jul 2026 15:41:13 -0700 Subject: [PATCH 312/406] IntelFsp2Pkg: Fix markdownlint errors Fixing all markdown lint errors found by running markdownlint-cli. Verified that rendering still shows valid information. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- IntelFsp2Pkg/IntelFsp2Pkg.ci.yaml | 2 +- IntelFsp2Pkg/Readme.md | 4 +- .../UserManuals/ConfigEditorUserManual.md | 45 ++++-- .../UserManuals/FspDscBsf2YamlUserManual.md | 11 +- .../Tools/UserManuals/GenCfgOptUserManual.md | 132 ++++++++++++------ .../Tools/UserManuals/PatchFvUserManual.md | 77 ++++++---- .../UserManuals/SplitFspBinUserManual.md | 18 ++- 7 files changed, 193 insertions(+), 96 deletions(-) diff --git a/IntelFsp2Pkg/IntelFsp2Pkg.ci.yaml b/IntelFsp2Pkg/IntelFsp2Pkg.ci.yaml index cdc73d8a5c..4db8c3be70 100644 --- a/IntelFsp2Pkg/IntelFsp2Pkg.ci.yaml +++ b/IntelFsp2Pkg/IntelFsp2Pkg.ci.yaml @@ -93,7 +93,7 @@ ## options defined .pytool/Plugin/MarkdownLintCheck "MarkdownLintCheck": { - "AuditOnly": True, # If True, log all errors and then mark as skipped + "AuditOnly": False, # If True, log all errors and then mark as skipped "IgnoreFiles": [] # package root relative file, folder, or glob pattern to ignore } } diff --git a/IntelFsp2Pkg/Readme.md b/IntelFsp2Pkg/Readme.md index 719ce099e4..313775761f 100644 --- a/IntelFsp2Pkg/Readme.md +++ b/IntelFsp2Pkg/Readme.md @@ -2,6 +2,6 @@ This package provides the component to create an FSP binary. -Source Repository: https://github.com/tianocore/edk2/tree/master/IntelFsp2Pkg +Source Repository: <https://github.com/tianocore/edk2/tree/master/IntelFsp2Pkg> -A whitepaper to describe the IntelFsp2Pkg: https://firmware.intel.com/sites/default/files/A_Tour_Beyond_BIOS_Creating_the_Intel_Firmware_Support_Package_with_the_EFI_Developer_Kit_II_%28FSP2.0%29.pdf +A whitepaper to describe the IntelFsp2Pkg: <https://firmware.intel.com/sites/default/files/A_Tour_Beyond_BIOS_Creating_the_Intel_Firmware_Support_Package_with_the_EFI_Developer_Kit_II_%28FSP2.0%29.pdf> diff --git a/IntelFsp2Pkg/Tools/UserManuals/ConfigEditorUserManual.md b/IntelFsp2Pkg/Tools/UserManuals/ConfigEditorUserManual.md index 721b2fdaf9..8f665f76d3 100644 --- a/IntelFsp2Pkg/Tools/UserManuals/ConfigEditorUserManual.md +++ b/IntelFsp2Pkg/Tools/UserManuals/ConfigEditorUserManual.md @@ -1,51 +1,70 @@ -#Name -**ConfigEditor.py** is a python script with a GUI interface that can support changing configuration settings directly from the interface without having to modify the source. +# Name -#Description -This is a GUI interface that can be used by users who would like to change configuration settings directly from the interface without having to modify the SBL source. +**ConfigEditor.py** is a python script with a GUI interface that can support changing configuration +settings directly from the interface without having to modify the source. + +## Description + +This is a GUI interface that can be used by users who would like to change configuration settings +directly from the interface without having to modify the SBL source. This tool depends on Python GUI tool kit Tkinter. It runs on both Windows and Linux. -The user needs to load the YAML file along with DLT file for a specific board into the ConfigEditor, change the desired configuration values. Finally, generate a new configuration delta file or a config binary blob for the newly changed values to take effect. These will be the inputs to the merge tool or the stitch tool so that new config changes can be merged and stitched into the final configuration blob. - +The user needs to load the YAML file along with DLT file for a specific board into the ConfigEditor, +change the desired configuration values. Finally, generate a new configuration delta file or a config +binary blob for the newly changed values to take effect. These will be the inputs to the merge tool or +the stitch tool so that new config changes can be merged and stitched into the final configuration blob. It supports the following options: ## 1. Open Config YAML file + This option loads the YAML file for a FSP UPD into the ConfigEditor to change the desired configuration values. This option loads the YAML file for a VFR config data into the ConfigEditor to view the desired form values. -#####Example: -``` +### Example + ![Example ConfigEditor 1](https://slimbootloader.github.io/_images/CfgEditOpen.png) ![Example ConfigEditor 2](https://slimbootloader.github.io/_images/CfgEditDefYaml.png) -``` ## 2. Open Config BSF file -This option loads the BSF file for a FSP UPD into the ConfigEditor to change the desired configuration values. It works as a similar fashion with Binary Configuration Tool (BCT) + +This option loads the BSF file for a FSP UPD into the ConfigEditor to change the desired configuration +values. It works as a similar fashion with Binary Configuration Tool (BCT) ## 3. Show Binary Information + This option loads configuration data from FD file and displays it in the ConfigEditor. ## 4. Save Config Data to Binary + This option generates a config binary blob for the newly changed values to take effect. ## 5. Load Config Data from Binary + This option reloads changed configuration from BIN file into the ConfigEditor. ## 6. Load Config Changes from Delta File + This option loads the changed configuration values from Delta file into the ConfigEditor. ## 7. Save Config Changes to Delta File + This option generates a new configuration delta file for the newly changed values to take effect. ## 8. Save Full Config Data to Delta File + This option saves all the changed configuration values into a Delta file. ## 9. Search feature + This feature helps the user to easily find any configuration item they are looking for in ConfigEditor. -A text search box is available on the Top Right Corner of ConfigEditor. To use this feature the user should type the name or a key word of the item they want to search in the text box and then click on the "Search" button. This will display all the items which contains that particular word searched by the user. +A text search box is available on the Top Right Corner of ConfigEditor. To use this feature the user +should type the name or a key word of the item they want to search in the text box and then click on +the "Search" button. This will display all the items which contains that particular word searched by the user. -## Running Configuration Editor: +## Running Configuration Editor - **python ConfigEditor.py** +```python +python ConfigEditor.py +``` diff --git a/IntelFsp2Pkg/Tools/UserManuals/FspDscBsf2YamlUserManual.md b/IntelFsp2Pkg/Tools/UserManuals/FspDscBsf2YamlUserManual.md index ba2311445c..27b228f24a 100644 --- a/IntelFsp2Pkg/Tools/UserManuals/FspDscBsf2YamlUserManual.md +++ b/IntelFsp2Pkg/Tools/UserManuals/FspDscBsf2YamlUserManual.md @@ -1,4 +1,5 @@ -#Name +# Name + **FspDscBsf2Yaml.py** The python script that generates YAML file for the Boot Settings from an EDK II Platform Description (**DSC**) file or from a Boot Settings File (**BSF**). It is created to help @@ -6,12 +7,14 @@ transitioning FSP Updateable Product Data (**UPD**) file format to new standardized YAML format so that it can be configured through open source tools. -#Synopsis -``` +## Synopsis + +```text FspDscBsf2Yaml DscFile|BsfFile YamlFile ``` -#Description +## Description + **FspDscBsf2Yaml.py** is a script that generates configuration options from an **EDK II Platform Description (DSC)** file or **a Boot Settings File (BSF)** file. diff --git a/IntelFsp2Pkg/Tools/UserManuals/GenCfgOptUserManual.md b/IntelFsp2Pkg/Tools/UserManuals/GenCfgOptUserManual.md index 0a0f592801..ae9bba861e 100644 --- a/IntelFsp2Pkg/Tools/UserManuals/GenCfgOptUserManual.md +++ b/IntelFsp2Pkg/Tools/UserManuals/GenCfgOptUserManual.md @@ -1,16 +1,21 @@ -#Name +# Name + +<!-- markdownlint-disable MD024 --> + **GenCfgOpt.py** The python script that generates UPD text (**.txt**) files for the compiler, header files for the UPD regions, and generates a Boot Settings File (**BSF**), all from an EDK II Platform Description (**DSC**) file. -#Synopsis -``` +## Synopsis + +```text GenCfgOpt UPDTXT PlatformDscFile BuildFvDir [TxtOutFile] [-D Macros] GenCfgOpt HEADER PlatformDscFile BuildFvDir [InputHFile] [-D Macros] GenCfgOpt GENBSF PlatformDscFile BuildFvDir BsfOutFile [-D Macros] ``` -#Description +## Description + **GenCfgOpt.py** is a script that generates configuration options from an **EDK II Platform Description (DSC)** file. It has three functions. @@ -28,6 +33,7 @@ the **'build'** command; the **GENBSF** use case may be done at any time. The following sections explain the three use cases. ## 1. GenCfgOpt.py UPDTXT + The **UPDTXT** option creates a text file with all the UPD entries, offsets, size in bytes, and values. **GenCfgOpt** reads this information from the **[PcdsDynamicVpd.Upd]** section of the project's DSC file. The DSC file allows @@ -36,7 +42,7 @@ introducing gaps between entries. **GenCfgOpt** fills in these gaps with UPD entries that have the generic names **UnusedUpdSpaceN** where N begins with 0 and increments. The command signature for **UPDTXT** is: -``` +```text GenCfgOpt UPDTXT PlatformDscFile BuildFvDir [TxtOutFile] [-D Macros] ``` @@ -52,13 +58,16 @@ must follow the form ```?D <MACRO_NAME>=<VALUE>```. will only re-create it if the DSC was modified after it was created. ## 2. GenCfgOpt.py HEADER + The **HEADER** option creates header files in the build folder. Both header files define the ```_UPD_DATA_REGION``` data structures in FspUpd.h, FsptUpd.h, FspmUpd.h and FspsUpd.h. In these header files any undefined elements of structures will be added as **ReservedUpdSpaceN** beginning with N=0. The command signature for **HEADER** is -```GenCfgOpt HEADER PlatformDscFile BuildFvDir [InputHFile] [-D Macros]``` +```text +GenCfgOpt HEADER PlatformDscFile BuildFvDir [InputHFile] [-D Macros] +``` **PlatformDscFile** and **BuildFvDir** are described in the previous section. The optional **InputHFile** is a header file that may contain data definitions @@ -72,29 +81,36 @@ the DSC file. The special commands begin with ```!HDR```, for header. The following table summarizes the two command options. ### HEADER + Use the **HEADER** command to hide specific variables in the public header file. In your project DSC file, use ```!HDR HEADER:{OFF}``` at the beginning of the section you wish to hide and ```!HDR HEADER:{ON}``` at the end. ### STRUCT + The **STRUCT** command allows you to specify a specific data type for a variable. You can specify a pointer to a data struct, for example. You define the data structure in the **InputHFile** between ```!EXPORT EXTERNAL_BOOTLOADER_STRUCT_BEGIN``` and ```!EXPORT EXTERNAL_BOOTLOADER_STRUCT_END```. -#####Example: -```!HDR STRUCT:{MY_DATA_STRUCT*}``` +#### Example + +```text +!HDR STRUCT:{MY_DATA_STRUCT*} +``` You then define ```MY_DATA_STRUCT``` in **InputHFile**. ### EMBED + The **EMBED** command allows you to put one or more UPD data into a specify data structure. You can utilize it as a group of UPD for example. You must specify a start and an end for the specify data structure. -#####Example: -``` +#### Example + +```text !HDR EMBED:{MY_DATA_STRUCT:MyDataStructure:START} gTokenSpaceGuid.Upd1 | 0x0020 | 0x01 | 0x00 gTokenSpaceGuid.Upd2 | 0x0021 | 0x01 | 0x00 @@ -102,8 +118,9 @@ start and an end for the specify data structure. gTokenSpaceGuid.UpdN | 0x0022 | 0x01 | 0x00 ``` -#####Result: -``` +##### Result + +```text typedef struct { /** Offset 0x0020 **/ @@ -126,6 +143,7 @@ start and an end for the specify data structure. ``` ## 3. GenCfgOpt .py GENBSF + The **GENBSF** option generates a BSF from the UPD entries in a package's DSC file. It does this by parsing special commands found in the comments of the DSC file. They roughly match the keywords that define the different sections of the @@ -141,20 +159,25 @@ relative path to where the BSF should be stored. Every BSF command in the DSC file begins with **!BSF** or **@Bsf**. The following table summarizes the options that come after **!BSF** or **@Bsf**: -# BSF Commands Description -###PAGES +## BSF Commands Description + +### PAGES + **PAGES** maps abbreviations to friendly-text descriptions of the pages in a BSF. -#####Example: +#### Example + ```!BSF PAGES:{PG1:?Page 1?, PG2:?Page 2?}``` or ```@Bsf PAGES:{PG1:?Page 1?, PG2:?Page 2?}``` -###PAGE +### PAGE + This marks the beginning of a page. Use the abbreviation specified in **PAGES** command. -#####Example: +#### Example + ```!BSF PAGE:{PG1}``` or ```@Bsf PAGE:{PG1}``` @@ -162,32 +185,38 @@ command. All the entries that come after this command are assumed to be on that page, until the next **PAGE** command -###FIND +### FIND + FIND maps to the BSF **Find** command. It will be placed in the **StructDef** region of the BSF and should come at the beginning of the UPD sections of the DSC, immediately before the signatures that mark the beginning of these sections. The content should be the plain-text equivalent of the signature. The signature is usually 8 characters. -#####Example: +#### Example + ```!BSF FIND:{PROJSIG1}``` or ```@Bsf FIND:{PROJSIG1}``` -###BLOCK +### BLOCK + The BLOCK command maps to the **BeginInfoBlock** section of the BSF. There are two elements: a version number and a plain-text description. -#####Example: +#### Example + ```!BSF BLOCK:{NAME:"My platform name", VER:"0.1"}``` or ```@Bsf BLOCK:{NAME:"My platform name", VER:"0.1"}``` -###NAME +### NAME + **NAME** gives a plain-text for a variable. This is the text label that will appear next to the control in **BCT**. -#####Example: +#### Example + ```!BSF NAME:{Variable 0}``` or ```@Bsf NAME:{Variable 0}``` @@ -195,20 +224,23 @@ appear next to the control in **BCT**. If the **!BSF NAME** or **@Bsf NAME** command does not appear before an entry in the UPD region of the DSC file, then that entry will not appear in the BSF. -###TYPE +### TYPE + The **TYPE** command is used either by itself or with the **NAME** command. It is usually used by itself when defining an **EditNum** field for the BSF. You specify the type of data in the second parameter and the range of valid values in the third. -#####Example: +#### Example + ```!BSF TYPE:{EditNum, HEX, (0x00,0xFF)}``` or ```@Bsf TYPE:{EditNum, HEX, (0x00,0xFF)}``` **TYPE** appears on the same line as the **NAME** command when using a combo-box. -#####Example: +#### Example + ```!BSF NAME:{Variable 1} TYPE:{Combo}``` or ```@Bsf NAME:{Variable 1} TYPE:{Combo}``` @@ -216,20 +248,24 @@ There is a special **None** type that puts the variable in the **StructDef** region of the BSF, but doesn't put it in any **Page** section. This makes the variable visible to BCT, but not to the end user. -###HELP +### HELP + The **HELP** command defines what will appear in the help text for each control in BCT. -#####Example: +#### Example + ```!BSF HELP:{Enable/disable LAN controller.}``` or ```@Bsf HELP:{Enable/disable LAN controller.}``` -###OPTION +### OPTION + The **OPTION** command allows you to custom-define combo boxes and map integer or hex values to friendly-text options. -#####Example: +#### Example + ```!BSF OPTION:{0:IDE, 1:AHCI, 2:RAID}``` ```!BSF OPTION:{0x00:0 MB, 0x01:32 MB, 0x02:64 MB}``` @@ -240,25 +276,29 @@ or ```@Bsf OPTION:{0x00:0 MB, 0x01:32 MB, 0x02:64 MB}``` -###FIELD +### FIELD + The **FIELD** command can be used to define a section of a consolidated PCD such that the PCD will be displayed in several fields via BCT interface instead of one long entry. -#####Example: +#### Example + ```!BSF FIELD:{PcdDRAMSpeed:1}``` or ```@Bsf FIELD:{PcdDRAMSpeed:1}``` -###ORDER +### ORDER + The **ORDER** command can be used to adjust the display order for the BSF items. By default the order value for a BSF item is assigned to be the UPD item -```(Offset * 256)```. It can be overridden by declaring **ORDER** command using +```(Offset *256)```. It can be overridden by declaring **ORDER** command using format ORDER: ```{HexMajor.HexMinor}```. In this case the order value will be ```(HexMajor*256+HexMinor)```. The item order value will be used as the sort key during the BSF item display. -#####Example: +#### Example + ```!BSF ORDER:{0x0040.01}``` or ```@Bsf ORDER:{0x0040.01}``` @@ -293,11 +333,14 @@ same line following the **!BSF** or **@Bsf** keyword or they may appear on separate lines to improve readability. There are four alternative ways to replace current BSF commands. + ### 1. ```# @Prompt``` + An alternative way replacing **NAME** gives a plain-text for a variable. This is the text label that will appear next to the control in BCT. -#####Example: +#### Example + ```# @Prompt Variable 0``` The above example can replace the two methods as below. @@ -310,10 +353,12 @@ If the ```# @Prompt``` command does not appear before an entry in the UPD region of the DSC file, then that entry will not appear in the BSF. ### 2. ```##``` + An alternative way replacing **HELP** command defines what will appear in the help text for each control in BCT. -#####Example: +#### Example + ```## Enable/disable LAN controller.``` The above example can replace the two methods as below. @@ -323,13 +368,15 @@ The above example can replace the two methods as below. ```@Bsf HELP:{Enable/disable LAN controller.}``` ### 3. ```# @ValidList``` + An alternative way replacing **OPTION** command allows you to custom-define combo boxes and map integer or hex values to friendly-text options. -#####Example: +#### Example + ``` # @ValidList 0x80000003 | 0, 1, 2 | IDE, AHCI, RAID Error Code | Options | Descriptions -``` +```text The above example can replace the two methods as below. @@ -338,16 +385,17 @@ The above example can replace the two methods as below. ```@Bsf OPTION:{0:IDE, 1:AHCI, 2:RAID}``` ### 4. ```# @ValidRange``` + An alternative way replace **EditNum** field for the BSF. -#####Example: +#### Example + ```# @ValidRange 0x80000001 | 0x0 ? 0xFF Error Code | Range -``` +```text The above example can replace the two methods as below. ```!BSF TYPE:{EditNum, HEX, (0x00,0xFF)}``` or ```@Bsf TYPE:{EditNum, HEX, (0x00,0xFF)}``` - diff --git a/IntelFsp2Pkg/Tools/UserManuals/PatchFvUserManual.md b/IntelFsp2Pkg/Tools/UserManuals/PatchFvUserManual.md index 205ad57773..9db87acf83 100644 --- a/IntelFsp2Pkg/Tools/UserManuals/PatchFvUserManual.md +++ b/IntelFsp2Pkg/Tools/UserManuals/PatchFvUserManual.md @@ -1,101 +1,113 @@ # Name + +<!-- markdownlint-disable MD024 --> + **_PatchFv.py_** - The python script that patches the firmware volumes (**FV**) with in the flash device (**FD**) file post FSP build. From version 0.60, script is capable of patching flash device (**FD**) directly. -# Synopsis +## Synopsis -``` +```text PatchFv FvBuildDir [FvFileBaseNames:]FdFileBaseNameToPatch ["Offset, Value"]+ | ["Offset, Value, @Comment"]+ | ["Offset, Value, $Command"]+ | ["Offset, Value, $Command, @Comment"]+ ``` -``` + +```text PatchFv FdFileDir FdFileName ["Offset, Value"]+ | ["Offset, Value, @Comment"]+ | ["Offset, Value, $Command"]+ | ["Offset, Value, $Command, @Comment"]+ ``` -# Description +## Description + The **_PatchFv.py_** tool allows the developer to fix up FD images to follow the Intel FSP Architecture specification. It also makes the FD image relocatable. The tool is written in Python and uses Python 2.7 or later to run. Consider using the tool in a build script. -# FvBuildDir (Argument 1) +## FvBuildDir (Argument 1) + This is the first argument that **_PatchFv.py_** requires. It is the build directory for all firmware volumes created during the FSP build. The path must be either an absolute path or a relevant path, relevant to the top level of the FSP tree. -#### Example usage: -``` +### Example usage + +```text Build\YouPlatformFspPkg\%BD_TARGET%_%VS_VERSION%%VS_X86%\FV ``` The example used contains Windows batch script %VARIABLES%. -# FvFileBaseNames (Argument 2: Optional Part 1) +## FvFileBaseNames (Argument 2: Optional Part 1) + The firmware volume file base names (**_FvFileBaseNames_**) are the independent FVs that are to be patched within the FD. (0 or more in the form **FvFileBaseNames:**) The colon **:** is used for delimiting the single argument and must be appended to the end of each (**_FvFileBaseNames_**). -#### Example usage: -``` +### Example usage + +```text STAGE1:STAGE2:MANIFEST:YOURPLATFORM ``` In the example **STAGE1** is **STAGE1.Fv** in **YOURPLATFORM.fd**. -# FdFileNameToPatch (Argument 2: Mandatory Part 2) +## FdFileNameToPatch (Argument 2: Mandatory Part 2) Firmware device file name to patch (**_FdFileNameToPatch_**) is the base name of the FD file that is to be patched. (1 only, in the form **YOURPLATFORM**) -#### Example usage: -``` +### Example usage + +```text STAGE1:STAGE2:MANIFEST:YOURPLATFORM ``` In the example **YOURPLATFORM** is from **_YOURPLATFORM.fd_** -# "Offset, Value[, Command][, Comment]" (Argument 3) +## "Offset, Value\[, Command\]\[, Comment\]" (Argument 3) + The **_Offset_** can be a positive or negative number and represents where the **_Value_** to be patched is located within the FD. The **_Value_** is what will be written at the given **_Offset_** in the FD. Constants may be used for both offsets and values. Also, this argument handles expressions for both offsets and values using these operators: -``` +```text = - * & | ~ ( ) [ ] { } < > ``` The entire argument includes the quote marks like in the example argument below: -``` +```text 0xFFFFFFC0, SomeCore:__EntryPoint - [0x000000F0],@SomeCore Entry ``` -### Constants: +### Constants + Hexadecimal (use **0x** as prefix) | Decimal -#### Examples: +#### Examples | **Positive Hex** | **Negative Hex** | **Positive Decimal** | **Negative Decimal** | | ---------------: | ---------------: | -------------------: | -------------------: | | 0x000000BC | 0xFFFFFFA2 | 188 | -94 | -``` +```text ModuleName:FunctionName | ModuleName:GlobalVariableName ModuleGuid:Offset ``` -### Operators: +### Operators -``` +```text + Addition - Subtraction @@ -109,35 +121,42 @@ ModuleGuid:Offset < > Convert absolute address <expr> into an image offset (expr & FSP_SIZE) ``` + From version 0.60 tool allows to pass flash device file path as Argument 1 and flash device name as Argument 2 and rules for passing offset & value are same as explained in the previous sections. -#### Example usage: +### Example usage + Argument 1 -``` + +```text YouPlatformFspBinPkg\ ``` + Argument 2 -``` + +```text Fsp_Rebased_T ``` -### Special Commands: +### Special Commands + Special commands must use the **$** symbol as a prefix to the command itself. There is only one command available at this time. -``` +```text $COPY Copy a binary block from source to destination. ``` -#### Example: +#### Example -``` +```text 0x94, [PlatformInit:__gPcd_BinPatch_FvRecOffset] + 0x94, [0x98], $COPY, @Sync up 2nd FSP Header ``` -### Comments: +### Comments + Comments are allowed in the **Offset, Value [, Comment]** argument. Comments must use the **@** symbol as a prefix. The comment will output to the build window upon successful completion of patching along with the offset and value data. diff --git a/IntelFsp2Pkg/Tools/UserManuals/SplitFspBinUserManual.md b/IntelFsp2Pkg/Tools/UserManuals/SplitFspBinUserManual.md index 06d87bbb2e..2b13d03183 100644 --- a/IntelFsp2Pkg/Tools/UserManuals/SplitFspBinUserManual.md +++ b/IntelFsp2Pkg/Tools/UserManuals/SplitFspBinUserManual.md @@ -1,4 +1,4 @@ -# SplitFspBin.py is a python script to support some operations on Intel FSP 1.x/2.x image. +# SplitFspBin.py is a python script to support some operations on Intel FSP 1.x/2.x image It supports: @@ -16,7 +16,9 @@ FSP 1.x image is not supported by split command. To split individual FSP component in Intel FSP 2.x image, the following command can be used: - **python SplitFspBin.py split [-h] -f FSPBINARY [-o OUTPUTDIR] [-n NAMETEMPLATE]** +```text + python SplitFspBin.py split [-h] -f FSPBINARY [-o OUTPUTDIR] [-n NAMETEMPLATE] +``` For example: @@ -29,7 +31,9 @@ For example: To rebase one or multiple FSP components in Intel FSP 1.x/2.x image, the following command can be used: - **python SplitFspBin.py rebase [-h] -f FSPBINARY -c {t,m,s,o} [{t,m,s,o} ...] -b FSPBASE [FSPBASE ...] [-o OUTPUTDIR] [-n OUTPUTFILE]** +```text + python SplitFspBin.py rebase [-h] -f FSPBINARY -c {t,m,s,o} [{t,m,s,o} ...] -b FSPBASE [FSPBASE ...] [-o OUTPUTDIR] [-n OUTPUTFILE] +``` For example: @@ -50,7 +54,9 @@ For example: To generate Intel FSP 1.x/2.x C header file, the following command can be used: - **Python SplitFspBin.py genhdr [-h] -f FSPBINARY [-o OUTPUTDIR] [-n HFILENAME]** +```text + Python SplitFspBin.py genhdr [-h] -f FSPBINARY [-o OUTPUTDIR] [-n HFILENAME] +``` For example: @@ -63,7 +69,9 @@ For example: To display Intel FSP 1.x/2.x information headers, the following command can be used: - **Python SplitFspBin.py info [-h] -f FSPBINARY** +```text + Python SplitFspBin.py info [-h] -f FSPBINARY +``` For example: From 7a3943da83d9dfc23288b25cec219fce7c28d069 Mon Sep 17 00:00:00 2001 From: Girish Mahadevan <gmahadevan@nvidia.com> Date: Mon, 20 Jul 2026 22:56:27 +0000 Subject: [PATCH 313/406] DynamicTablesPkg: Add Baseboard CM object and parser Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com> --- .../Include/ArchCommonNameSpaceObjects.h | 48 +++++++++++++++++++ .../ConfigurationManagerObjectParser.c | 25 ++++++++++ 2 files changed, 73 insertions(+) diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index 165fe73d1a..ade806dda9 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -129,6 +129,8 @@ typedef enum ArchCommonObjectID { EArchCommonObjAdditionalInformationValue, ///< 70 - Additional Information Value EArchCommonObjSystemEnclosureInfo, ///< 71 - System Enclosure Info EArchCommonObjEnclosureElement, ///< 72 - System Enclosure Contained Element + EArchCommonObjBaseboardInfo, ///< 73 - Baseboard Info + EArchCommonObjBaseboardContainedObject, ///< 74 - Baseboard Contained Object EArchCommonObjMax } EARCH_COMMON_OBJECT_ID; @@ -1899,4 +1901,50 @@ typedef struct CmArchCommonSystemEnclosureInfo { UINT8 RackHeight; } CM_ARCH_COMMON_SYSTEM_ENCLOSURE_INFO; +/** A structure that identifies an SMBIOS object contained by a Baseboard. + + SMBIOS Specification v3.9.0 Type 2 + + ID: EArchCommonObjBaseboardContainedObject +**/ +typedef struct CmArchCommonBaseboardContainedObject { + /// CM Object Token identifying the contained SMBIOS object. + CM_OBJECT_TOKEN ContainedObjectToken; + /// Generator ID for the contained SMBIOS object. + SMBIOS_TABLE_GENERATOR_ID GeneratorId; +} CM_ARCH_COMMON_BASEBOARD_CONTAINED_OBJECT; + +/** A structure that describes Baseboard (or Module) Information. + + SMBIOS Specification v3.9.0 Type 2 + + ID: EArchCommonObjBaseboardInfo +**/ +typedef struct CmArchCommonBaseboardInfo { + /// CM Object Token uniquely identifying this Baseboard entry. + CM_OBJECT_TOKEN BaseboardInfoToken; + /// CM Object Token identifying the containing System Enclosure. + /// CM_NULL_TOKEN indicates that no enclosure reference is supplied. + CM_OBJECT_TOKEN ChassisToken; + /// Token referencing an array of Baseboard Contained Objects. + /// CM_NULL_TOKEN indicates that no contained objects are supplied. + CM_OBJECT_TOKEN ContainedObjectListToken; + /// Manufacturer of the Baseboard. + CHAR8 Manufacturer[SMBIOS_MAX_STRING_SIZE]; + /// Product name of the Baseboard. + CHAR8 ProductName[SMBIOS_MAX_STRING_SIZE]; + /// Version of the Baseboard. + CHAR8 Version[SMBIOS_MAX_STRING_SIZE]; + /// Serial number of the Baseboard. + CHAR8 SerialNum[SMBIOS_MAX_STRING_SIZE]; + /// Asset tag of the Baseboard. + CHAR8 AssetTag[SMBIOS_MAX_STRING_SIZE]; + /// Baseboard feature flags as defined by SMBIOS Type 2. + UINT8 FeatureFlag; + /// Location of the Baseboard within the chassis. + CHAR8 LocationInChassis[SMBIOS_MAX_STRING_SIZE]; + /// Baseboard type as defined by SMBIOS Type 2. + UINT8 BoardType; +} CM_ARCH_COMMON_BASEBOARD_INFO; + #pragma pack() diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index d1f08ea26a..5a9cdf58ef 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -1397,6 +1397,29 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonEnclosureElementParser[] = { { "ContainedElementMaximum", sizeof (UINT8), "%u", NULL }, }; +/** A parser for EArchCommonObjBaseboardContainedObject. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonBaseboardContainedObjectParser[] = { + { "ContainedObjectToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "GeneratorId", sizeof (SMBIOS_TABLE_GENERATOR_ID), "0x%x", NULL }, +}; + +/** A parser for EArchCommonObjBaseboardInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmArchCommonBaseboardInfoParser[] = { + { "BaseboardInfoToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "ChassisToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "ContainedObjectListToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, + { "Manufacturer", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "ProductName", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "Version", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "SerialNum", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "AssetTag", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "FeatureFlag", sizeof (UINT8), "0x%x", NULL }, + { "LocationInChassis", SMBIOS_MAX_STRING_SIZE, NULL, PrintString }, + { "BoardType", sizeof (UINT8), "0x%x", NULL }, +}; + /** A parser for Arch Common namespace objects. */ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { @@ -1474,6 +1497,8 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArchCommonNamespaceObjectParser[] = { CM_PARSER_ADD_OBJECT (EArchCommonObjAdditionalInformationValue, CmArchCommonAdditionalInformationValueParser), CM_PARSER_ADD_OBJECT (EArchCommonObjSystemEnclosureInfo, CmArchCommonSystemEnclosureInfoParser), CM_PARSER_ADD_OBJECT (EArchCommonObjEnclosureElement, CmArchCommonEnclosureElementParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjBaseboardInfo, CmArchCommonBaseboardInfoParser), + CM_PARSER_ADD_OBJECT (EArchCommonObjBaseboardContainedObject, CmArchCommonBaseboardContainedObjectParser), CM_PARSER_ADD_OBJECT_RESERVED (EArchCommonObjMax) }; From 71dc4edb9217cb498813539ef703da4ab75261e2 Mon Sep 17 00:00:00 2001 From: Girish Mahadevan <gmahadevan@nvidia.com> Date: Mon, 20 Jul 2026 22:58:23 +0000 Subject: [PATCH 314/406] DynamicTablesPkg: Smbios Baseboard Information (Type 2) Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com> --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + .../SmbiosType2Lib/SmbiosType2Generator.c | 540 ++++++++++++++++++ .../Smbios/SmbiosType2Lib/SmbiosType2Lib.inf | 30 + 3 files changed, 572 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType2Lib/SmbiosType2Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType2Lib/SmbiosType2Lib.inf diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc index a442a29d1e..bbfdce916d 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -55,6 +55,7 @@ # SMBIOS Generators (Common) DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Lib.inf + DynamicTablesPkg/Library/Smbios/SmbiosType2Lib/SmbiosType2Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf @@ -176,6 +177,7 @@ NULL|DynamicTablesPkg/Library/Smbios/SmbiosType0Lib/SmbiosType0Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType1Lib/SmbiosType1Lib.inf + NULL|DynamicTablesPkg/Library/Smbios/SmbiosType2Lib/SmbiosType2Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType3Lib/SmbiosType3Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType4Lib/SmbiosType4Lib.inf NULL|DynamicTablesPkg/Library/Smbios/SmbiosType7Lib/SmbiosType7Lib.inf diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType2Lib/SmbiosType2Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType2Lib/SmbiosType2Generator.c new file mode 100644 index 0000000000..1250ef8059 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType2Lib/SmbiosType2Generator.c @@ -0,0 +1,540 @@ +/** @file + SMBIOS Type 2 Baseboard (or Module) Information Table Generator. + + Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/SmbiosStringTableLib.h> + +#include <ConfigurationManagerObject.h> +#include <ConfigurationManagerHelper.h> +#include <Protocol/ConfigurationManagerProtocol.h> +#include <Protocol/DynamicTableFactoryProtocol.h> +#include <IndustryStandard/SmBios.h> + +/** SMBIOS Type 2 Baseboard (or Module) Information Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArchCommonObjBaseboardInfo + - EArchCommonObjBaseboardContainedObject + Required only when a baseboard provides a non-null + ContainedObjectListToken. +*/ + +#define SMBIOS_TYPE2_MAX_STRINGS 6 +#define SMBIOS_TYPE2_FEATURE_FLAG_RESERVED_MASK 0xE0 +#define SMBIOS_TYPE2_BASE_LENGTH OFFSET_OF (SMBIOS_TABLE_TYPE2, ContainedObjectHandles) + +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjBaseboardInfo, + CM_ARCH_COMMON_BASEBOARD_INFO + ); + +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjBaseboardContainedObject, + CM_ARCH_COMMON_BASEBOARD_CONTAINED_OBJECT + ); + +/** Validate a Baseboard Information CM object. + + Validation follows SMBIOS Specification v3.9.0, Sections 7.3.1 and 7.3.2. + + @param [in] BaseboardInfo Baseboard Information to validate. + + @retval EFI_SUCCESS The Baseboard Information is valid. + @retval EFI_INVALID_PARAMETER The Baseboard Information is invalid. +**/ +STATIC +EFI_STATUS +ValidateBaseboardInfo ( + IN CONST CM_ARCH_COMMON_BASEBOARD_INFO *BaseboardInfo + ) +{ + if ((BaseboardInfo->FeatureFlag & SMBIOS_TYPE2_FEATURE_FLAG_RESERVED_MASK) != 0) { + DEBUG (( + DEBUG_ERROR, + "%a: FeatureFlag reserved bits must be zero: 0x%x\n", + __func__, + BaseboardInfo->FeatureFlag + )); + return EFI_INVALID_PARAMETER; + } + + if ((BaseboardInfo->BoardType < BaseBoardTypeUnknown) || + (BaseboardInfo->BoardType > BaseBoardTypeInterconnectBoard)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid BoardType 0x%x\n", __func__, BaseboardInfo->BoardType)); + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** Add an optional string to a string table. + + @param [in,out] StrTable String table receiving the string. + @param [in] String Null-terminated string to add. + @param [out] StringRef SMBIOS string reference. + + @retval EFI_SUCCESS The string was added or was empty. + @return Error status returned by StringTableAddString(). +**/ +STATIC +EFI_STATUS +AddOptionalString ( + IN OUT STRING_TABLE *StrTable, + IN CONST CHAR8 *String, + OUT SMBIOS_TABLE_STRING *StringRef + ) +{ + *StringRef = 0; + if (String[0] == '\0') { + return EFI_SUCCESS; + } + + return StringTableAddString (StrTable, String, StringRef); +} + +/** Construct SMBIOS Type 2 tables describing Baseboards. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS table factory. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager. + @param [out] Table Pointer to the generated SMBIOS tables. + @param [out] CmObjectToken Pointer to the CM object tokens. + @param [out] TableCount Number of generated SMBIOS tables. + + @retval EFI_SUCCESS Tables generated successfully. + @retval EFI_INVALID_PARAMETER A parameter or CM object is invalid. + @retval EFI_NOT_FOUND No Baseboard Information objects were found. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +BuildSmbiosType2TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + CM_ARCH_COMMON_BASEBOARD_INFO *BaseboardInfo; + CM_ARCH_COMMON_BASEBOARD_CONTAINED_OBJECT *ContainedObject; + UINT32 BaseboardCount; + UINT32 ContainedObjectCount; + SMBIOS_STRUCTURE **TableList; + CM_OBJECT_TOKEN *CmObjectList; + SMBIOS_TABLE_TYPE2 *SmbiosRecord; + STRING_TABLE StrTable; + BOOLEAN StringTableInitialized; + SMBIOS_TABLE_STRING ManufacturerRef; + SMBIOS_TABLE_STRING ProductNameRef; + SMBIOS_TABLE_STRING VersionRef; + SMBIOS_TABLE_STRING SerialNumRef; + SMBIOS_TABLE_STRING AssetTagRef; + SMBIOS_TABLE_STRING LocationInChassisRef; + SMBIOS_HANDLE ReferenceHandle; + UINTN FormattedLength; + UINTN Index; + UINTN ContainedObjectIndex; + + ASSERT (This != NULL); + ASSERT (TableFactoryProtocol != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Table != NULL); + ASSERT (CmObjectToken != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (TableFactoryProtocol == NULL) || + (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL) || (TableCount == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + *CmObjectToken = NULL; + *TableCount = 0; + TableList = NULL; + CmObjectList = NULL; + SmbiosRecord = NULL; + StringTableInitialized = FALSE; + + Status = GetEArchCommonObjBaseboardInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &BaseboardInfo, + &BaseboardCount + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get Baseboard objects: %r\n", __func__, Status)); + return Status; + } + + if (BaseboardCount == 0) { + return EFI_NOT_FOUND; + } + + if ((BaseboardInfo == NULL) || + (BaseboardCount > (MAX_UINTN / sizeof (*TableList))) || + (BaseboardCount > (MAX_UINTN / sizeof (*CmObjectList)))) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Baseboard object list\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + TableList = AllocateZeroPool (sizeof (*TableList) * BaseboardCount); + if (TableList == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CmObjectList = AllocateZeroPool (sizeof (*CmObjectList) * BaseboardCount); + if (CmObjectList == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ErrorExit; + } + + for (Index = 0; Index < BaseboardCount; Index++) { + Status = ValidateBaseboardInfo (&BaseboardInfo[Index]); + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + + ContainedObject = NULL; + ContainedObjectCount = 0; + if (BaseboardInfo[Index].ContainedObjectListToken != CM_NULL_TOKEN) { + Status = GetEArchCommonObjBaseboardContainedObject ( + CfgMgrProtocol, + BaseboardInfo[Index].ContainedObjectListToken, + &ContainedObject, + &ContainedObjectCount + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get contained objects for Baseboard %u: %r\n", + __func__, + Index, + Status + )); + goto ErrorExit; + } + + if ((ContainedObjectCount != 0) && (ContainedObject == NULL)) { + DEBUG ((DEBUG_ERROR, "%a: Contained object list is NULL for Baseboard %u\n", __func__, Index)); + Status = EFI_INVALID_PARAMETER; + goto ErrorExit; + } + } + + if (ContainedObjectCount > MAX_UINT8) { + DEBUG (( + DEBUG_ERROR, + "%a: Too many contained objects for Baseboard %u: %u\n", + __func__, + Index, + ContainedObjectCount + )); + Status = EFI_INVALID_PARAMETER; + goto ErrorExit; + } + + FormattedLength = SMBIOS_TYPE2_BASE_LENGTH + + (ContainedObjectCount * sizeof (SMBIOS_HANDLE)); + if (FormattedLength > MAX_UINT8) { + DEBUG (( + DEBUG_ERROR, + "%a: Formatted length %Lu exceeds Hdr.Length for Baseboard %u\n", + __func__, + (UINT64)FormattedLength, + Index + )); + Status = EFI_INVALID_PARAMETER; + goto ErrorExit; + } + + Status = StringTableInitialize (&StrTable, SMBIOS_TYPE2_MAX_STRINGS); + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + + StringTableInitialized = TRUE; + Status = AddOptionalString (&StrTable, BaseboardInfo[Index].Manufacturer, &ManufacturerRef); + if (!EFI_ERROR (Status)) { + Status = AddOptionalString (&StrTable, BaseboardInfo[Index].ProductName, &ProductNameRef); + } + + if (!EFI_ERROR (Status)) { + Status = AddOptionalString (&StrTable, BaseboardInfo[Index].Version, &VersionRef); + } + + if (!EFI_ERROR (Status)) { + Status = AddOptionalString (&StrTable, BaseboardInfo[Index].SerialNum, &SerialNumRef); + } + + if (!EFI_ERROR (Status)) { + Status = AddOptionalString (&StrTable, BaseboardInfo[Index].AssetTag, &AssetTagRef); + } + + if (!EFI_ERROR (Status)) { + Status = AddOptionalString ( + &StrTable, + BaseboardInfo[Index].LocationInChassis, + &LocationInChassisRef + ); + } + + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + + SmbiosRecord = AllocateSmbiosRecord (FormattedLength, &StrTable); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ErrorExit; + } + + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION; + SmbiosRecord->Hdr.Length = (UINT8)FormattedLength; + SmbiosRecord->Manufacturer = ManufacturerRef; + SmbiosRecord->ProductName = ProductNameRef; + SmbiosRecord->Version = VersionRef; + SmbiosRecord->SerialNumber = SerialNumRef; + SmbiosRecord->AssetTag = AssetTagRef; + *(UINT8 *) &SmbiosRecord->FeatureFlag = BaseboardInfo[Index].FeatureFlag; + SmbiosRecord->LocationInChassis = LocationInChassisRef; + SmbiosRecord->BoardType = BaseboardInfo[Index].BoardType; + SmbiosRecord->NumberOfContainedObjectHandles = (UINT8)ContainedObjectCount; + + ReferenceHandle = SMBIOS_HANDLE_INVALID; + if (BaseboardInfo[Index].ChassisToken != CM_NULL_TOKEN) { + ReferenceHandle = TableFactoryProtocol->GetSmbiosHandleEx ( + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType03), + BaseboardInfo[Index].ChassisToken + ); + if (ReferenceHandle == SMBIOS_HANDLE_INVALID) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to resolve ChassisToken 0x%p for Baseboard %u\n", + __func__, + BaseboardInfo[Index].ChassisToken, + Index + )); + Status = EFI_NOT_FOUND; + goto ErrorExit; + } + } + + WriteUnaligned16 (&SmbiosRecord->ChassisHandle, ReferenceHandle); + + if (ContainedObject != NULL) { + for (ContainedObjectIndex = 0; + ContainedObjectIndex < ContainedObjectCount; + ContainedObjectIndex++) + { + ReferenceHandle = TableFactoryProtocol->GetSmbiosHandleEx ( + ContainedObject[ContainedObjectIndex].GeneratorId, + ContainedObject[ContainedObjectIndex].ContainedObjectToken + ); + if (ReferenceHandle == SMBIOS_HANDLE_INVALID) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to resolve contained object %u for Baseboard %u\n", + __func__, + ContainedObjectIndex, + Index + )); + Status = EFI_NOT_FOUND; + goto ErrorExit; + } + + WriteUnaligned16 ( + &SmbiosRecord->ContainedObjectHandles[ContainedObjectIndex], + ReferenceHandle + ); + } + } + + Status = StringTablePublishStringSet ( + &StrTable, + (CHAR8 *)SmbiosRecord + FormattedLength, + StringTableGetStringSetSize (&StrTable) + ); + StringTableFree (&StrTable); + StringTableInitialized = FALSE; + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] = BaseboardInfo[Index].BaseboardInfoToken; + SmbiosRecord = NULL; + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = BaseboardCount; + return EFI_SUCCESS; + +ErrorExit: + if (StringTableInitialized) { + StringTableFree (&StrTable); + } + + if (SmbiosRecord != NULL) { + FreePool (SmbiosRecord); + } + + if (TableList != NULL) { + for (Index = 0; Index < BaseboardCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + FreePool (TableList); + } + + if (CmObjectList != NULL) { + FreePool (CmObjectList); + } + + return Status; +} + +/** Free resources allocated when installing SMBIOS Type 2 tables. + + @param [in] This Pointer to the SMBIOS table generator. + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory. + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager. + @param [in] Table Pointer to the SMBIOS tables. + @param [in] CmObjectToken Pointer to the CM ObjectToken array. + @param [in] TableCount Number of SMBIOS tables. + + @retval EFI_SUCCESS Resources freed successfully. + @retval EFI_INVALID_PARAMETER A parameter is invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +FreeSmbiosType2TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + + if ((This == NULL) || (TableFactoryProtocol == NULL) || + (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (CmObjectToken == NULL)) + { + DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter\n", __func__)); + return EFI_INVALID_PARAMETER; + } + + if (*Table != NULL) { + for (Index = 0; Index < TableCount; Index++) { + if ((*Table)[Index] != NULL) { + FreePool ((*Table)[Index]); + } + } + + FreePool (*Table); + *Table = NULL; + } + + if (*CmObjectToken != NULL) { + FreePool (*CmObjectToken); + *CmObjectToken = NULL; + } + + return EFI_SUCCESS; +} + +STATIC CONST SMBIOS_TABLE_GENERATOR SmbiosType2Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType02), + // Generator Description + L"SMBIOS.TYPE2.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION, + NULL, + NULL, + // Build table function Extended. + BuildSmbiosType2TableEx, + // Free function Extended. + FreeSmbiosType2TableEx +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType2LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType2Generator); + DEBUG ((DEBUG_INFO, "SMBIOS Type 2: Register Generator. Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType2LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType2Generator); + DEBUG ((DEBUG_INFO, "SMBIOS Type 2: Deregister Generator. Status = %r\n", Status)); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType2Lib/SmbiosType2Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType2Lib/SmbiosType2Lib.inf new file mode 100644 index 0000000000..f93ed08b85 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType2Lib/SmbiosType2Lib.inf @@ -0,0 +1,30 @@ +## @file +# SMBIOS Type 2 Table Generator +# +# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType2Lib + FILE_GUID = 46034810-da88-4cc7-83ef-d263b6575dc7 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType2LibConstructor + DESTRUCTOR = SmbiosType2LibDestructor + +[Sources] + SmbiosType2Generator.c + +[Packages] + MdePkg/MdePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MemoryAllocationLib + SmbiosStringTableLib From 40c898febeea93cc83e56608a3d1d2e9f85b019a Mon Sep 17 00:00:00 2001 From: Leif Lindholm <leif.lindholm@oss.qualcomm.com> Date: Thu, 18 Jun 2026 18:47:29 +0100 Subject: [PATCH 315/406] ManageabilityPkg: simplify HelperManageabilityPayLoadDebugPrint () While reviewing PR #12035, I found this function a bit overcomplicated, with a bunch of live-coded integers, so I reworked it for improved human and compiler readability. Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com> --- .../BaseManageabilityTransportHelper.c | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c b/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c index 933db4c1d5..af5e4ab234 100644 --- a/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c +++ b/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c @@ -397,47 +397,55 @@ HelperManageabilityPayLoadDebugPrint ( IN UINT32 PayloadSize ) { - UINT16 Page256; - UINT16 Row16; - UINT16 Column16; - UINT32 RemainingBytes; - UINT32 TotalBytePrinted; + UINTN Block; + UINTN BlockSize; + UINTN RowSize; + UINTN RemainingBytes; + UINTN BytesPrinted; - RemainingBytes = PayloadSize; - TotalBytePrinted = 0; - Page256 = 0; - while (TRUE) { - if (TotalBytePrinted % 256 == 0) { - Page256 = (UINT16)TotalBytePrinted / 256; - DEBUG ((DEBUG_MANAGEABILITY_INFO, "======== Manageability Payload %04xH - %04xH =========\n", Page256 * 256, Page256 * 256 + MIN (RemainingBytes, 256) - 1)); + RemainingBytes = PayloadSize; + BlockSize = 256; + RowSize = 16; + + for (Block = 0, BytesPrinted = 0; RemainingBytes > 0;) { + UINTN BlockBase; + UINTN Row; + UINTN RowsToPrint; + UINTN Column; + + Block = BytesPrinted / BlockSize; + BlockBase = Block * BlockSize; + + if (BytesPrinted % BlockSize == 0) { + DEBUG ((DEBUG_MANAGEABILITY_INFO, "======== Manageability Payload %04xH - %04xH =========\n", BlockBase, BlockBase + MIN (RemainingBytes, BlockSize) - 1)); DEBUG ((DEBUG_MANAGEABILITY_INFO, " ")); - for (Column16 = 0; Column16 < 16; Column16++) { - DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", Column16)); + for (Column = 0; Column < RowSize; Column++) { + DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", Column)); } DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n -----------------------------------------------\n")); } - for (Row16 = 0; Row16 < 16; Row16++) { - DEBUG ((DEBUG_MANAGEABILITY_INFO, "%04x | ", Page256 * 256 + Row16 * 16)); - for (Column16 = 0; Column16 < MIN (RemainingBytes, 16); Column16++) { - DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", *((UINT8 *)Payload + Page256 * 256 + Row16 * 16 + Column16))); + if (RemainingBytes >= BlockSize) { + RowsToPrint = BlockSize / RowSize; + } else { + RowsToPrint = RemainingBytes / RowSize + 1; + } + + for (Row = 0; Row < RowsToPrint; Row++) { + DEBUG ((DEBUG_MANAGEABILITY_INFO, "%04x | ", BlockBase + Row * RowSize)); + for (Column = 0; Column < MIN (RemainingBytes, RowSize); Column++) { + DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", *((UINT8 *)Payload + BlockBase + Row * RowSize + Column))); } - RemainingBytes -= Column16; - TotalBytePrinted += Column16; - if (RemainingBytes == 0) { - DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n\n")); - return; - } + RemainingBytes -= Column; + BytesPrinted += Column; DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n")); } DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n")); } - - DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n\n")); } /** From be62f3ded57452bafff4e627313637d4d39c34d9 Mon Sep 17 00:00:00 2001 From: Leif Lindholm <leif.lindholm@oss.qualcomm.com> Date: Mon, 22 Jun 2026 19:27:45 +0100 Subject: [PATCH 316/406] ManageabilityPkg: reorganise ManageabilityTransportSsifLib For some reason this module was created "backwards", with .inf files in subdirectories, as well as identical apart from failes to keep in sync source files for Dxe and Pei drivers. Flip the thing the right way around and delete the duplicated files. Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com> --- .../Dxe/ManageabilityTransportSsif.c | 387 ------------------ .../DxeManageabilityTransportSsif.inf | 4 +- .../{Pei => }/ManageabilityTransportSsif.c | 0 .../{Common => }/ManageabilityTransportSsif.h | 0 .../{Dxe => }/ManageabilityTransportSsif.uni | 0 .../Pei/ManageabilityTransportSsif.uni | 12 - .../PeiManageabilityTransportSsif.inf | 4 +- .../{Common => }/SsifCommon.c | 0 ManageabilityPkg/Manageability.dsc.inc | 4 +- ManageabilityPkg/ManageabilityPkg.dsc | 4 +- 10 files changed, 8 insertions(+), 407 deletions(-) delete mode 100644 ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/ManageabilityTransportSsif.c rename ManageabilityPkg/Library/ManageabilityTransportSsifLib/{Dxe => }/DxeManageabilityTransportSsif.inf (91%) rename ManageabilityPkg/Library/ManageabilityTransportSsifLib/{Pei => }/ManageabilityTransportSsif.c (100%) rename ManageabilityPkg/Library/ManageabilityTransportSsifLib/{Common => }/ManageabilityTransportSsif.h (100%) rename ManageabilityPkg/Library/ManageabilityTransportSsifLib/{Dxe => }/ManageabilityTransportSsif.uni (100%) delete mode 100644 ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/ManageabilityTransportSsif.uni rename ManageabilityPkg/Library/ManageabilityTransportSsifLib/{Pei => }/PeiManageabilityTransportSsif.inf (91%) rename ManageabilityPkg/Library/ManageabilityTransportSsifLib/{Common => }/SsifCommon.c (100%) diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/ManageabilityTransportSsif.c b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/ManageabilityTransportSsif.c deleted file mode 100644 index 8612115d3f..0000000000 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/ManageabilityTransportSsif.c +++ /dev/null @@ -1,387 +0,0 @@ -/** @file - - SSIF instance of Manageability Transport Library - - Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR> - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include <Uefi.h> -#include <IndustryStandard/IpmiSsif.h> -#include <Library/BaseMemoryLib.h> -#include <Library/DebugLib.h> -#include <Library/MemoryAllocationLib.h> -#include <Library/ManageabilityTransportLib.h> -#include <Library/ManageabilityTransportIpmiLib.h> -#include <Library/ManageabilityTransportHelperLib.h> -#include <Library/PlatformBmcReadyLib.h> - -#include "ManageabilityTransportSsif.h" - -MANAGEABILITY_TRANSPORT_SSIF *mSingleSessionToken = NULL; - -EFI_GUID *mSupportedManageabilityProtocol[] = { - &gManageabilityProtocolIpmiGuid -}; - -UINT8 mNumberOfSupportedProtocol = (sizeof (mSupportedManageabilityProtocol) / sizeof (EFI_GUID *)); - -MANAGEABILITY_TRANSPORT_SSIF_HARDWARE_INFO mSsifHardwareInfo; - -// -// Initialize SSIF Interface capabilities -// -BOOLEAN mPecSupport = FALSE; -UINT8 mMaxRequestSize = IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES; -UINT8 mMaxResponseSize = IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES; -UINT8 mTransactionSupport = IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_SSIF_TRANSACTION_SUPPORT_SINGLE_PARTITION_RW; - -/** - This function initializes the transport interface. - - @param [in] TransportToken The transport token acquired through - AcquireTransportSession function. - @param [in] HardwareInfo The hardware information - assigned to SSIF transport interface. - - @retval EFI_SUCCESS Transport interface is initialized - successfully. - @retval EFI_INVALID_PARAMETER The invalid transport token. - @retval EFI_NOT_READY The transport interface works fine but - @retval is not ready. - @retval EFI_DEVICE_ERROR The transport interface has problems. - @retval EFI_ALREADY_STARTED Teh protocol interface has already initialized. - @retval Otherwise Other errors. - -**/ -EFI_STATUS -EFIAPI -SsifTransportInit ( - IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, - IN MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION HardwareInfo OPTIONAL - ) -{ - EFI_STATUS Status; - CHAR16 *ManageabilityProtocolName; - - if (TransportToken == NULL) { - DEBUG ((DEBUG_ERROR, "%a: Invalid transport token.\n", __func__)); - return EFI_INVALID_PARAMETER; - } - - if (HardwareInfo.Ssif == NULL) { - DEBUG ((DEBUG_MANAGEABILITY_INFO, "%a: Hardware information is not provided, use default settings.\n", __func__)); - mSsifHardwareInfo.BmcSlaveAddress = FixedPcdGet8 (PcdIpmiSsifSmbusSlaveAddr); - } else { - mSsifHardwareInfo.BmcSlaveAddress = ((MANAGEABILITY_TRANSPORT_SSIF_HARDWARE_INFO *)HardwareInfo.Ssif)->BmcSlaveAddress; - } - - Status = SsifTransportGetCapabilities ( - &mPecSupport, - &mTransactionSupport, - &mMaxRequestSize, - &mMaxResponseSize - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_MANAGEABILITY_INFO, "%a: Could not retrieve IPMI SSIF capabilites, use default settings.\n", __func__)); - } - - // Get protocol specification name. - ManageabilityProtocolName = HelperManageabilitySpecName (TransportToken->ManageabilityProtocolSpecification); - - DEBUG ((DEBUG_MANAGEABILITY_INFO, "%a: transport hardware for %s is:\n", __func__, ManageabilityProtocolName)); - DEBUG ((DEBUG_MANAGEABILITY_INFO, "BMC Slave Address: 0x%x\n", mSsifHardwareInfo.BmcSlaveAddress)); - DEBUG ((DEBUG_MANAGEABILITY_INFO, "PEC Support: %d\n", mPecSupport)); - DEBUG ((DEBUG_MANAGEABILITY_INFO, "Transaction Support: %d\n", mTransactionSupport)); - DEBUG ((DEBUG_MANAGEABILITY_INFO, "Max Request Size: %d\n", mMaxRequestSize)); - DEBUG ((DEBUG_MANAGEABILITY_INFO, "Max Response Size: %d\n", mMaxResponseSize)); - - return EFI_SUCCESS; -} - -/** - This function returns the transport interface status. - The generic EFI_STATUS is returned to caller directly, The additional - information of transport interface could be optionally returned in - TransportAdditionalStatus to describes the status that can't be - described obviously through EFI_STATUS. - See the definition of MANAGEABILITY_TRANSPORT_STATUS. - - @param [in] TransportToken The transport token acquired through - AcquireTransportSession function. - @param [out] TransportAdditionalStatus The additional status of transport - interface. - NULL means no additional status of this - transport interface. - - @retval EFI_SUCCESS Transport interface status is returned. - @retval EFI_INVALID_PARAMETER The invalid transport token. - @retval EFI_DEVICE_ERROR The transport interface has problems to return - @retval EFI_UNSUPPORTED The transport interface doesn't have status report. - Otherwise Other errors. - -**/ -EFI_STATUS -EFIAPI -SsifTransportStatus ( - IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, - OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *TransportAdditionalStatus OPTIONAL - ) -{ - if (TransportToken == NULL) { - DEBUG ((DEBUG_ERROR, "%a: Invalid transport token.\n", __func__)); - return EFI_INVALID_PARAMETER; - } - - // - // SMBUS does not provide transport status checking capabilities. This only determines - // if the BMC is ready or not, without updating any additional status. - // - if (!PlatformBmcReady ()) { - return EFI_NOT_READY; - } - - return EFI_SUCCESS; -} - -/** - This function resets the transport interface. - The generic EFI_STATUS is returned to caller directly after reseting transport - interface. The additional information of transport interface could be optionally - returned in TransportAdditionalStatus to describes the status that can't be - described obviously through EFI_STATUS. - See the definition of MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS. - - @param [in] TransportToken The transport token acquired through - AcquireTransportSession function. - @param [out] TransportAdditionalStatus The additional status of specific transport - interface after the reset. - NULL means no additional status of this - transport interface. - - @retval EFI_SUCCESS Transport interface status is returned. - @retval EFI_INVALID_PARAMETER The invalid transport token. - @retval EFI_TIMEOUT The reset process is time out. - @retval EFI_DEVICE_ERROR The transport interface has problems to return - status. - Otherwise Other errors. - -**/ -EFI_STATUS -EFIAPI -SsifTransportReset ( - IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, - OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *TransportAdditionalStatus OPTIONAL - ) -{ - return EFI_UNSUPPORTED; -} - -/** - This function transmit the request over target transport interface. - The generic EFI_STATUS is returned to caller directly after reseting transport - interface. The additional information of transport interface could be optionally - returned in TransportAdditionalStatus to describes the status that can't be - described obviously through EFI_STATUS. - See the definition of MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS. - - @param [in] TransportToken The transport token acquired through - AcquireTransportSession function. - @param [in] TransferToken The transfer token, see the definition of - MANAGEABILITY_TRANSFER_TOKEN. - -**/ -VOID -EFIAPI -SsifTransportTransmitReceive ( - IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, - IN MANAGEABILITY_TRANSFER_TOKEN *TransferToken - ) -{ - EFI_STATUS Status; - MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS AdditionalStatus; - - if ((TransportToken == NULL) || (TransferToken == NULL)) { - DEBUG ((DEBUG_ERROR, "%a: Invalid transport token or transfer token.\n", __func__)); - return; - } - - Status = SsifTransportSendCommand ( - TransferToken->TransmitHeader, - TransferToken->TransmitHeaderSize, - TransferToken->TransmitTrailer, - TransferToken->TransmitTrailerSize, - TransferToken->TransmitPackage.TransmitPayload, - TransferToken->TransmitPackage.TransmitSizeInByte, - TransferToken->ReceivePackage.ReceiveBuffer, - &TransferToken->ReceivePackage.ReceiveSizeInByte, - &AdditionalStatus - ); - - TransferToken->TransferStatus = Status; - TransferToken->TransportAdditionalStatus = AdditionalStatus; -} - -/** - This function acquires to create a transport session to transmit manageability - packet. A transport token is returned to caller for the follow up operations. - - @param [in] ManageabilityProtocolSpec The protocol spec the transport interface is acquired. - @param [out] TransportToken The pointer to receive the transport token created by - the target transport interface library. - @retval EFI_SUCCESS Token is created successfully. - @retval EFI_OUT_OF_RESOURCES Out of resource to create a new transport session. - @retval EFI_UNSUPPORTED Protocol is not supported on this transport interface. - @retval Otherwise Other errors. - -**/ -EFI_STATUS -AcquireTransportSession ( - IN EFI_GUID *ManageabilityProtocolSpec, - OUT MANAGEABILITY_TRANSPORT_TOKEN **TransportToken - ) -{ - EFI_STATUS Status; - MANAGEABILITY_TRANSPORT_SSIF *SsifTransportToken; - - if (ManageabilityProtocolSpec == NULL) { - DEBUG ((DEBUG_ERROR, "%a: No Manageability protocol specification specified.\n", __func__)); - return EFI_INVALID_PARAMETER; - } - - if (TransportToken == NULL) { - DEBUG ((DEBUG_ERROR, "%a: TransportToken is NULL.\n", __func__)); - return EFI_INVALID_PARAMETER; - } - - Status = HelperManageabilityCheckSupportedSpec ( - &gManageabilityTransportSmbusI2cGuid, - mSupportedManageabilityProtocol, - mNumberOfSupportedProtocol, - ManageabilityProtocolSpec - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Protocol is not supported on this transport interface.\n", __func__)); - return EFI_UNSUPPORTED; - } - - if (mSingleSessionToken != NULL) { - DEBUG ((DEBUG_ERROR, "%a: This manageability transport library only supports one session transport token.\n", __func__)); - return EFI_OUT_OF_RESOURCES; - } - - SsifTransportToken = AllocateZeroPool (sizeof (MANAGEABILITY_TRANSPORT_SSIF)); - if (SsifTransportToken == NULL) { - DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TRANSPORT_SSIF\n", __func__)); - return EFI_OUT_OF_RESOURCES; - } - - SsifTransportToken->Token.Transport = AllocateZeroPool (sizeof (MANAGEABILITY_TRANSPORT)); - if (SsifTransportToken->Token.Transport == NULL) { - FreePool (SsifTransportToken); - DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TRANSPORT\n", __func__)); - return EFI_OUT_OF_RESOURCES; - } - - SsifTransportToken->Signature = MANAGEABILITY_TRANSPORT_SSIF_SIGNATURE; - SsifTransportToken->Token.ManageabilityProtocolSpecification = ManageabilityProtocolSpec; - SsifTransportToken->Token.Transport->TransportVersion = MANAGEABILITY_TRANSPORT_TOKEN_VERSION; - SsifTransportToken->Token.Transport->ManageabilityTransportSpecification = &gManageabilityTransportSmbusI2cGuid; - SsifTransportToken->Token.Transport->TransportName = L"SSIF"; - SsifTransportToken->Token.Transport->Function.Version1_0 = AllocateZeroPool (sizeof (MANAGEABILITY_TRANSPORT_FUNCTION_V1_0)); - if (SsifTransportToken->Token.Transport->Function.Version1_0 == NULL) { - DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TRANSPORT_FUNCTION_V1_0\n", __func__)); - FreePool (SsifTransportToken->Token.Transport); - FreePool (SsifTransportToken); - return EFI_OUT_OF_RESOURCES; - } - - SsifTransportToken->Token.Transport->Function.Version1_0->TransportInit = SsifTransportInit; - SsifTransportToken->Token.Transport->Function.Version1_0->TransportReset = SsifTransportReset; - SsifTransportToken->Token.Transport->Function.Version1_0->TransportStatus = SsifTransportStatus; - SsifTransportToken->Token.Transport->Function.Version1_0->TransportTransmitReceive = SsifTransportTransmitReceive; - - mSingleSessionToken = SsifTransportToken; - *TransportToken = &SsifTransportToken->Token; - return EFI_SUCCESS; -} - -/** - This function returns the transport capabilities according to - the manageability protocol. - - @param [in] TransportToken Transport token acquired from manageability - transport library. - @param [out] TransportCapability Pointer to receive transport capabilities. - See the definitions of - MANAGEABILITY_TRANSPORT_CAPABILITY. - @retval EFI_SUCCESS TransportCapability is returned successfully. - @retval EFI_INVALID_PARAMETER TransportToken is not a valid token. -**/ -EFI_STATUS -GetTransportCapability ( - IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, - OUT MANAGEABILITY_TRANSPORT_CAPABILITY *TransportCapability - ) -{ - if ((TransportToken == NULL) || (TransportCapability == NULL)) { - return EFI_INVALID_PARAMETER; - } - - *TransportCapability = 0; - if (CompareGuid ( - TransportToken->ManageabilityProtocolSpecification, - &gManageabilityProtocolIpmiGuid - )) - { - *TransportCapability |= - (MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POSITION); - } - - return EFI_SUCCESS; -} - -/** - This function releases the manageability session. - - @param [in] TransportToken The transport token acquired through - AcquireTransportSession. - @retval EFI_SUCCESS Token is released successfully. - @retval EFI_INVALID_PARAMETER Invalid TransportToken. - @retval Otherwise Other errors. - -**/ -EFI_STATUS -ReleaseTransportSession ( - IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken - ) -{ - EFI_STATUS Status; - MANAGEABILITY_TRANSPORT_SSIF *SsifTransportToken; - - Status = EFI_INVALID_PARAMETER; - - if (TransportToken != NULL) { - SsifTransportToken = MANAGEABILITY_TRANSPORT_SSIF_FROM_LINK (TransportToken); - - if (SsifTransportToken != NULL) { - if ((mSingleSessionToken != NULL) && - (mSingleSessionToken == SsifTransportToken)) - { - mSingleSessionToken = NULL; - Status = EFI_SUCCESS; - } - - FreePool (SsifTransportToken->Token.Transport->Function.Version1_0); - FreePool (SsifTransportToken->Token.Transport); - FreePool (SsifTransportToken); - } - } - - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Fail to release SSIF transport token (%r).\n", __func__, Status)); - } - - return Status; -} diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/DxeManageabilityTransportSsif.inf b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/DxeManageabilityTransportSsif.inf similarity index 91% rename from ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/DxeManageabilityTransportSsif.inf rename to ManageabilityPkg/Library/ManageabilityTransportSsifLib/DxeManageabilityTransportSsif.inf index c8142744c6..97eaee64a2 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/DxeManageabilityTransportSsif.inf +++ b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/DxeManageabilityTransportSsif.inf @@ -21,8 +21,8 @@ [Sources] ManageabilityTransportSsif.c - ../Common/SsifCommon.c - ../Common/ManageabilityTransportSsif.h + SsifCommon.c + ManageabilityTransportSsif.h [Packages] ManageabilityPkg/ManageabilityPkg.dec diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/ManageabilityTransportSsif.c b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/ManageabilityTransportSsif.c similarity index 100% rename from ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/ManageabilityTransportSsif.c rename to ManageabilityPkg/Library/ManageabilityTransportSsifLib/ManageabilityTransportSsif.c diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/ManageabilityTransportSsif.h b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/ManageabilityTransportSsif.h similarity index 100% rename from ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/ManageabilityTransportSsif.h rename to ManageabilityPkg/Library/ManageabilityTransportSsifLib/ManageabilityTransportSsif.h diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/ManageabilityTransportSsif.uni b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/ManageabilityTransportSsif.uni similarity index 100% rename from ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/ManageabilityTransportSsif.uni rename to ManageabilityPkg/Library/ManageabilityTransportSsifLib/ManageabilityTransportSsif.uni diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/ManageabilityTransportSsif.uni b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/ManageabilityTransportSsif.uni deleted file mode 100644 index 7d6fea780c..0000000000 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/ManageabilityTransportSsif.uni +++ /dev/null @@ -1,12 +0,0 @@ -// /** @file -// SSIF instance of Manageability Transport Library -// -// Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR> -// -// SPDX-License-Identifier: BSD-2-Clause-Patent -// -// **/ - -#string STR_MODULE_ABSTRACT #language en-US "SSIF instance of Manageability Transport Library" - -#string STR_MODULE_DESCRIPTION #language en-US "SSIF Manageability Transport library implementation." diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/PeiManageabilityTransportSsif.inf b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/PeiManageabilityTransportSsif.inf similarity index 91% rename from ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/PeiManageabilityTransportSsif.inf rename to ManageabilityPkg/Library/ManageabilityTransportSsifLib/PeiManageabilityTransportSsif.inf index ef74c2c624..f4fb1c0de8 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/PeiManageabilityTransportSsif.inf +++ b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/PeiManageabilityTransportSsif.inf @@ -21,8 +21,8 @@ [Sources] ManageabilityTransportSsif.c - ../Common/SsifCommon.c - ../Common/ManageabilityTransportSsif.h + SsifCommon.c + ManageabilityTransportSsif.h [Packages] ManageabilityPkg/ManageabilityPkg.dec diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/SsifCommon.c b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c similarity index 100% rename from ManageabilityPkg/Library/ManageabilityTransportSsifLib/Common/SsifCommon.c rename to ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c diff --git a/ManageabilityPkg/Manageability.dsc.inc b/ManageabilityPkg/Manageability.dsc.inc index 869efe2d46..0d820a124d 100644 --- a/ManageabilityPkg/Manageability.dsc.inc +++ b/ManageabilityPkg/Manageability.dsc.inc @@ -91,7 +91,7 @@ ManageabilityPkg/Library/ManageabilityTransportKcsLib/BaseManageabilityTransportKcs.inf ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/DxeManageabilityTransportMctp.inf ManageabilityPkg/Library/ManageabilityTransportSerialLib/Dxe/DxeManageabilityTransportSerial.inf - ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/DxeManageabilityTransportSsif.inf - ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/PeiManageabilityTransportSsif.inf + ManageabilityPkg/Library/ManageabilityTransportSsifLib/DxeManageabilityTransportSsif.inf + ManageabilityPkg/Library/ManageabilityTransportSsifLib/PeiManageabilityTransportSsif.inf ManageabilityPkg/Library/PlatformBmcReadyLibNull/PlatformBmcReadyLibNull.inf ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf diff --git a/ManageabilityPkg/ManageabilityPkg.dsc b/ManageabilityPkg/ManageabilityPkg.dsc index 202df4bd95..0fe2defecf 100644 --- a/ManageabilityPkg/ManageabilityPkg.dsc +++ b/ManageabilityPkg/ManageabilityPkg.dsc @@ -49,8 +49,8 @@ ManageabilityPkg/Library/ManageabilityTransportKcsLib/BaseManageabilityTransportKcs.inf ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/DxeManageabilityTransportMctp.inf ManageabilityPkg/Library/ManageabilityTransportSerialLib/Dxe/DxeManageabilityTransportSerial.inf - ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/DxeManageabilityTransportSsif.inf - ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/PeiManageabilityTransportSsif.inf + ManageabilityPkg/Library/ManageabilityTransportSsifLib/DxeManageabilityTransportSsif.inf + ManageabilityPkg/Library/ManageabilityTransportSsifLib/PeiManageabilityTransportSsif.inf ManageabilityPkg/Library/PlatformBmcReadyLibNull/PlatformBmcReadyLibNull.inf ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf From e8cbfab461e28ce22be3e0c6beadd82b2f925bc1 Mon Sep 17 00:00:00 2001 From: Leif Lindholm <leif.lindholm@oss.qualcomm.com> Date: Wed, 24 Jun 2026 13:22:43 +0100 Subject: [PATCH 317/406] ManageabilityPkg: refactor SsifWriteRequest #1 Separate input validation from argument marshalling. Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com> --- .../Library/ManageabilityTransportSsifLib/SsifCommon.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c index 597cd7912f..4d60777227 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c +++ b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c @@ -68,7 +68,6 @@ SsifWriteRequest ( } MiddleCount = 0; - IsMultiPartWrite = FALSE; Status = EFI_SUCCESS; if (RequestDataSize > IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES) { @@ -80,7 +79,11 @@ SsifWriteRequest ( DEBUG ((DEBUG_ERROR, "%a: The request data size exceeds the maximum transfer blocks: RequestDataSize = %d, maximum transfer blocks = %d.\n", __func__, RequestDataSize, (1 << 8) - 1 + 2)); return EFI_INVALID_PARAMETER; } + } else { + IsMultiPartWrite = FALSE; + } + if (IsMultiPartWrite) { MiddleCount = ((RequestDataSize - 1) / IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES) - 1; if ( ((MiddleCount == 0) && (mTransactionSupport == IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_SSIF_TRANSACTION_SUPPORT_SINGLE_PARTITION_RW)) From 598025e8660c07ee806aaf0efe2a2fff4e235a9c Mon Sep 17 00:00:00 2001 From: Leif Lindholm <leif.lindholm@oss.qualcomm.com> Date: Wed, 24 Jun 2026 13:28:38 +0100 Subject: [PATCH 318/406] ManageabilityPkg: fix/cleanup request size check in SsifWriteRequest From the IPMI v2.0 (April 21, 2015 E7 Markup) specification, Table 22-12, Get System Interface Capabilities Command: "Input message size in bytes. (1 based.)" ... "A BMC that supports multi-part Start and End would return a value from 33 to 64. A BMC that supports multi-part with Middle transactions would return a value from 65 to 255." Yet the comment in the existing code describes this as being a counter of the number of middle packets, with Start and End packets counting outside of that. This seems very incorrect to me. Address this, and simplify the code, by using the already existing global variable mMaxRequestSize. Update the debug error message text to reflect the functional change. Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com> --- .../Library/ManageabilityTransportSsifLib/SsifCommon.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c index 4d60777227..6a9f62ac93 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c +++ b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c @@ -73,10 +73,8 @@ SsifWriteRequest ( if (RequestDataSize > IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES) { IsMultiPartWrite = TRUE; - // Minus by one for the maximum integer the data type of MiddleCount presents. - // Plus by two for the WRITE start and end. - if (RequestDataSize > IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES * ((1 << 8) - 1 + 2)) { - DEBUG ((DEBUG_ERROR, "%a: The request data size exceeds the maximum transfer blocks: RequestDataSize = %d, maximum transfer blocks = %d.\n", __func__, RequestDataSize, (1 << 8) - 1 + 2)); + if (RequestDataSize > mMaxRequestSize) { + DEBUG ((DEBUG_ERROR, "%a: The request data size exceeds the maximum input message size: RequestDataSize = %d, maximum input message size = %d.\n", __func__, RequestDataSize, mMaxRequestSize)); return EFI_INVALID_PARAMETER; } } else { From 150339f262fc2c54a27dc2aae4a4bbe540379a86 Mon Sep 17 00:00:00 2001 From: Leif Lindholm <leif.lindholm@oss.qualcomm.com> Date: Wed, 24 Jun 2026 13:54:20 +0100 Subject: [PATCH 319/406] ManageabilityPkg: SsifWriteRequest loop refactoring A multi-part request can consist of a Start, zero-to-several Middle, and an End packet. For what I can only assume was an attempt to confuse the enemy, SsifWriteRequest () handled this by setting up three separate loops. Rewrite this as a single loop in order to reduce confusion for revewers and compilers. Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com> --- .../SsifCommon.c | 58 ++++++------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c index 6a9f62ac93..e82eb545ce 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c +++ b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c @@ -58,7 +58,7 @@ SsifWriteRequest ( { EFI_STATUS Status; BOOLEAN IsMultiPartWrite; - UINTN Index; + UINTN BytesLeft; UINTN MiddleCount; UINT8 SsifCmd; UINTN WriteLen; @@ -98,58 +98,34 @@ SsifWriteRequest ( SsifCmd = IPMI_SSIF_SMBUS_CMD_SINGLE_PART_WRITE; } - SmBusWriteBlock ( - SMBUS_LIB_ADDRESS ( - IPMI_SSIF_BMC_SLAVE_ADDR_7BIT, - SsifCmd, - WriteLen, - mPecSupport - ), - RequestData, - &Status - ); - - if ( EFI_ERROR (Status) - || !IsMultiPartWrite) + for (BytesLeft = RequestDataSize, Status = EFI_SUCCESS; + (BytesLeft > 0) && !EFI_ERROR (Status); + BytesLeft -= MIN (BytesLeft, IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES)) { - goto Exit; - } + // Check for SsifCmd transitions if not the first packet + if (BytesLeft < RequestDataSize) { + // Is this the End packet? + if (BytesLeft <= IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES) { + WriteLen = BytesLeft; + SsifCmd = IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_END; + } else if (SsifCmd == IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_START) { + // Did we just write the Start packet of an operation with Middles? + SsifCmd = IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_MIDDLE; + } + } - for (Index = 1; Index <= MiddleCount; Index++) { SmBusWriteBlock ( SMBUS_LIB_ADDRESS ( IPMI_SSIF_BMC_SLAVE_ADDR_7BIT, - IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_MIDDLE, + SsifCmd, WriteLen, mPecSupport ), - &RequestData[Index * IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES], + &RequestData[RequestDataSize - BytesLeft], &Status ); - - if (EFI_ERROR (Status)) { - goto Exit; - } } - // - // Remain RequestData for END - // - WriteLen = RequestDataSize - (MiddleCount + 1) * IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES; - ASSERT (WriteLen > 0); - SmBusWriteBlock ( - SMBUS_LIB_ADDRESS ( - IPMI_SSIF_BMC_SLAVE_ADDR_7BIT, - IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_END, - WriteLen, - mPecSupport - ), - &RequestData[(MiddleCount + 1) * IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES], - &Status - ); - -Exit: - return Status; } From a6a060f940f11e9fb4f204e4110c3cee9dbae9ca Mon Sep 17 00:00:00 2001 From: Leif Lindholm <leif.lindholm@oss.qualcomm.com> Date: Wed, 24 Jun 2026 14:06:12 +0100 Subject: [PATCH 320/406] ManageabilityPkg: SsifWriteRequest post-refactor cleanup Now the logic of the function is less convoluted, drop some redundant casts, variable initialisations and move the MiddleCount definition into the only block where it's used. Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com> --- .../Library/ManageabilityTransportSsifLib/SsifCommon.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c index e82eb545ce..67132c38a9 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c +++ b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c @@ -59,7 +59,6 @@ SsifWriteRequest ( EFI_STATUS Status; BOOLEAN IsMultiPartWrite; UINTN BytesLeft; - UINTN MiddleCount; UINT8 SsifCmd; UINTN WriteLen; @@ -67,9 +66,6 @@ SsifWriteRequest ( return EFI_INVALID_PARAMETER; } - MiddleCount = 0; - Status = EFI_SUCCESS; - if (RequestDataSize > IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES) { IsMultiPartWrite = TRUE; @@ -82,6 +78,7 @@ SsifWriteRequest ( } if (IsMultiPartWrite) { + UINTN MiddleCount; MiddleCount = ((RequestDataSize - 1) / IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES) - 1; if ( ((MiddleCount == 0) && (mTransactionSupport == IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_SSIF_TRANSACTION_SUPPORT_SINGLE_PARTITION_RW)) @@ -94,7 +91,7 @@ SsifWriteRequest ( WriteLen = IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES; SsifCmd = IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_START; } else { - WriteLen = (UINT8)RequestDataSize; + WriteLen = RequestDataSize; SsifCmd = IPMI_SSIF_SMBUS_CMD_SINGLE_PART_WRITE; } From 708e440ddff577da7d96aab0fd81305d8c49f8b9 Mon Sep 17 00:00:00 2001 From: Mike Turner <miketur@microsoft.com> Date: Wed, 17 Jul 2024 23:23:38 -0700 Subject: [PATCH 321/406] PcAtChipsetPkg: Add VarPolicy to PcAtRealTimeClock variables Register a variable policy for L"RTCALARM" and L"RTC". The policy will enforce strict requiremnts for the variable size and attributes, and will block updates to the variables unless those requirements are met. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- PcAtChipsetPkg/PcAtChipsetPkg.ci.yaml | 3 +- PcAtChipsetPkg/PcAtChipsetPkg.dsc | 1 + .../PcatRealTimeClockRuntimeDxe/PcRtc.h | 2 + .../PcatRealTimeClockRuntimeDxe/PcRtcEntry.c | 86 +++++++++++++++++++ .../PcatRealTimeClockRuntimeDxe.inf | 3 + 5 files changed, 94 insertions(+), 1 deletion(-) diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.ci.yaml b/PcAtChipsetPkg/PcAtChipsetPkg.ci.yaml index 3d2d7cf5b0..000aac55f8 100644 --- a/PcAtChipsetPkg/PcAtChipsetPkg.ci.yaml +++ b/PcAtChipsetPkg/PcAtChipsetPkg.ci.yaml @@ -34,7 +34,8 @@ "AcceptableDependencies": [ "MdePkg/MdePkg.dec", "PcAtChipsetPkg/PcAtChipsetPkg.dec", - "UefiCpuPkg/UefiCpuPkg.dec" + "UefiCpuPkg/UefiCpuPkg.dec", + "MdeModulePkg/MdeModulePkg.dec" ], # For host based unit tests "AcceptableDependencies-HOST_APPLICATION":[], diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc b/PcAtChipsetPkg/PcAtChipsetPkg.dsc index 2f02ecf6fd..5a3d23d682 100644 --- a/PcAtChipsetPkg/PcAtChipsetPkg.dsc +++ b/PcAtChipsetPkg/PcAtChipsetPkg.dsc @@ -44,6 +44,7 @@ LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf [Components] PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h index e44f954272..e3f9004e0f 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h @@ -15,6 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Guid/Acpi.h> #include <Protocol/RealTimeClock.h> +#include <Protocol/VariablePolicy.h> #include <Library/BaseLib.h> #include <Library/DebugLib.h> @@ -28,6 +29,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/UefiRuntimeServicesTableLib.h> #include <Library/PcdLib.h> #include <Library/ReportStatusCodeLib.h> +#include <Library/VariablePolicyHelperLib.h> typedef struct { EFI_LOCK RtcLock; diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c index ca0cad9b01..f8a8817821 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c @@ -139,6 +139,83 @@ VirtualNotifyEvent ( EfiConvertPointer (0x0, (VOID **)&mRtcTargetRegister); } +/** + Callback function invoked when the VariablePolicy protocol is installed. + + This function registers the RTCALARM and RTC variables with the VariablePolicy protocol + to set strict requirements for the variables. + + @param[in] Event The notification event (non-NULL when called as a notification callback). + NULL if called directly during initialization. + @param[in] Context The VariablePolicy protocol pointer. Non-NULL when called directly or + when the protocol is available. NULL on the initial notification if + the protocol is not yet installed, in which case this function returns + without error. +**/ +STATIC +VOID +EFIAPI +OnVariablePolicyProtocolNotification ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy; + EFI_STATUS Status; + + Status = gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL, (VOID **)&VariablePolicy); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: - Variable Policy not yet available - %r\n", __func__, Status)); + return; + } + + // + // Register policy for RTCALARM variable: + // - Size must be exactly sizeof(EFI_TIME) bytes (no variable-sized buffers) + // - Must have BS_ACCESS, RT_ACCESS, and NON_VOLATILE attributes (required for runtime use) + // - Cannot have any other attributes (prevents tampering) + // + Status = RegisterBasicVariablePolicy ( + VariablePolicy, + &gEfiCallerIdGuid, + L"RTCALARM", + sizeof (EFI_TIME), + sizeof (EFI_TIME), + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + (UINT32) ~(EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE), + VARIABLE_POLICY_TYPE_NO_LOCK + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: - Error setting policy for RTCALARM - %r\n", __func__, Status)); + ASSERT_EFI_ERROR (Status); + } + + // + // Register policy for RTC variable: + // - Size must be exactly sizeof(UINT32) bytes (no variable-sized buffers) + // - Must have BS_ACCESS, RT_ACCESS, and NON_VOLATILE attributes (required for runtime use) + // - Cannot have any other attributes (prevents tampering) + // + Status = RegisterBasicVariablePolicy ( + VariablePolicy, + &gEfiCallerIdGuid, + L"RTC", + sizeof (UINT32), + sizeof (UINT32), + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + (UINT32) ~(EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE), + VARIABLE_POLICY_TYPE_NO_LOCK + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: - Error setting policy for RTC - %r\n", __func__, Status)); + ASSERT_EFI_ERROR (Status); + } + + gBS->CloseEvent (Event); + + return; +} + /** The user Entry Point for PcRTC module. @@ -161,6 +238,7 @@ InitializePcRtc ( { EFI_STATUS Status; EFI_EVENT Event; + VOID *ProtocolRegistration; EfiInitializeLock (&mModuleGlobal.RtcLock, TPL_CALLBACK); mModuleGlobal.CenturyRtcAddress = GetCenturyRtcAddress (); @@ -229,5 +307,13 @@ InitializePcRtc ( ASSERT_EFI_ERROR (Status); } + EfiCreateProtocolNotifyEvent ( + &gEdkiiVariablePolicyProtocolGuid, + TPL_CALLBACK, + OnVariablePolicyProtocolNotification, + NULL, + &ProtocolRegistration + ); + return Status; } diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf index c344b05987..8bcfc75a51 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf @@ -34,6 +34,7 @@ [Packages] MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec PcAtChipsetPkg/PcAtChipsetPkg.dec [LibraryClasses] @@ -49,9 +50,11 @@ BaseLib PcdLib ReportStatusCodeLib + VariablePolicyHelperLib [Protocols] gEfiRealTimeClockArchProtocolGuid ## PRODUCES + gEdkiiVariablePolicyProtocolGuid ## CONSUMES [Guids] ## SOMETIMES_CONSUMES ## Event From 7c2ec06a93ef36396db6f46f983a94d2aa26acdb Mon Sep 17 00:00:00 2001 From: Jared Pan <jared.pan@dell.com> Date: Tue, 23 Jun 2026 11:09:25 +0800 Subject: [PATCH 322/406] MdeModulePkg/UsbBusDxe: Fix UsbPortReset might run into recursive loop UsbSelectConfig will introduce the UsbConnectDriver call. If this UsbPortReset is happened in the Usb device driver Start() routine and the device FW can not be recovered by PortReset, the UsbSelectConfig will introduce the recursive loop. [Suggested solution] Since UsbPortReset should not change the Bus Topology, the Reset flow should only SetAddress and reconfigure the device. Signed-off-by: Marlboro Chuang <marlboro.chuang@dell.com> Signed-off-by: Jared Pan <jared.pan@dell.com> --- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 43 ++++++++++++++----------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c index 0438638b49..b0dd19444e 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c @@ -816,13 +816,14 @@ UsbIoPortReset ( IN EFI_USB_IO_PROTOCOL *This ) { - USB_INTERFACE *UsbIf; - USB_INTERFACE *HubIf; - USB_DEVICE *Dev; - EFI_TPL OldTpl; - EFI_STATUS Status; - UINT8 DevAddress; - UINT8 Config; + USB_INTERFACE *UsbIf; + USB_INTERFACE *HubIf; + USB_DEVICE *Dev; + EFI_TPL OldTpl; + EFI_STATUS Status; + UINT8 DevAddress; + UINT8 Config; + USB_DEVICE_DESC *DevDesc; OldTpl = gBS->RaiseTPL (USB_BUS_TPL); @@ -884,21 +885,30 @@ UsbIoPortReset ( // is in CONFIGURED state. // if (Dev->ActiveConfig != NULL) { - UsbFreeDevDesc (Dev->DevDesc); - - Status = UsbRemoveConfig (Dev); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to remove configuration - %r\n", Status)); - } - Status = UsbGetMaxPacketSize0 (Dev); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to get max packet size - %r\n", Status)); } + // Expect the Device Descriptor should not be changed. + // UEFI spec 2.11 Ch. 17.2.18 EFI_USB_IO_PROTOCOL.UsbPortReset + // This Reset function does not change the bus topology. + + // Save the device descriptor before resetting and then restore it after build descriptor table + DevDesc = Dev->DevDesc; + Dev->DevDesc = NULL; + Status = UsbBuildDescTable (Dev); + + if (Dev->DevDesc != NULL) { + UsbFreeDevDesc (Dev->DevDesc); + } + + Dev->DevDesc = DevDesc; + if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to build descriptor table - %r\n", Status)); + goto ON_EXIT; } Config = Dev->DevDesc->Configs[0]->Desc.ConfigurationValue; @@ -912,11 +922,6 @@ UsbIoPortReset ( Status )); } - - Status = UsbSelectConfig (Dev, Config); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to set configuration - %r\n", Status)); - } } ON_EXIT: From 95a7323e86126560e0a37b3801bc6c12a8428cda Mon Sep 17 00:00:00 2001 From: Tuan Phan <tuan.phan@oss.qualcomm.com> Date: Thu, 23 Jul 2026 00:06:57 -0700 Subject: [PATCH 323/406] DynamicTablesPkg/AmiLib: Make AmlCodeGenMethod public There is currently no API available for generating AML methods without a return value. This change exports the AmlCodeGenMethod API so it can be used to create non-returning methods when required. Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com> --- .../Include/Library/AmlLib/AmlLib.h | 44 +++++++++++++++++++ .../Common/AmlLib/CodeGen/AmlCodeGen.c | 13 +++--- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h index 1e7642523d..f4edaecc41 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -1447,6 +1447,50 @@ AmlCodeGenScope ( OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL ); +/** AML code generation for a Method object node. + + AmlCodeGenMethod ("MET0", 1, TRUE, 3, ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Method(MET0, 1, Serialized, 3) {} + + ACPI 6.4, s20.2.5.2 "Named Objects Encoding": + DefMethod := MethodOp PkgLength NameString MethodFlags TermList + MethodOp := 0x14 + + The ASL parameters "ReturnType" and "ParameterTypes" are not asked + in this function. They are optional parameters in ASL. + + @param [in] NameString The new Method's name. + Must be a NULL-terminated ASL NameString + e.g.: "MET0", "_SB.MET0", etc. + The input string is copied. + @param [in] NumArgs Number of arguments. + Must be 0 <= NumArgs <= 6. + @param [in] IsSerialized TRUE is equivalent to Serialized. + FALSE is equivalent to NotSerialized. + Default is NotSerialized in ASL spec. + @param [in] SyncLevel Synchronization level for the method. + Must be 0 <= SyncLevel <= 15. + Default is 0 in ASL. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + @param [out] NewObjectNode If success, contains the created node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenMethod ( + IN CONST CHAR8 *NameString, + IN UINT8 NumArgs, + IN BOOLEAN IsSerialized, + IN UINT8 SyncLevel, + IN AML_NODE_HANDLE ParentNode OPTIONAL, + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL + ); + /** AML code generation for a method returning a NameString. AmlCodeGenMethodRetNameString ( diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c index 60818866c6..41a43e7388 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -1568,16 +1568,15 @@ error_handler1: @retval EFI_INVALID_PARAMETER Invalid parameter. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. **/ -STATIC EFI_STATUS EFIAPI AmlCodeGenMethod ( - IN CONST CHAR8 *NameString, - IN UINT8 NumArgs, - IN BOOLEAN IsSerialized, - IN UINT8 SyncLevel, - IN AML_NODE_HEADER *ParentNode OPTIONAL, - OUT AML_OBJECT_NODE **NewObjectNode OPTIONAL + IN CONST CHAR8 *NameString, + IN UINT8 NumArgs, + IN BOOLEAN IsSerialized, + IN UINT8 SyncLevel, + IN AML_NODE_HANDLE ParentNode OPTIONAL, + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL ) { EFI_STATUS Status; From 4d92f22a5c398028ebcc0f52db298053fd161a99 Mon Sep 17 00:00:00 2001 From: Tuan Phan <tuan.phan@oss.qualcomm.com> Date: Thu, 23 Jul 2026 01:07:23 -0700 Subject: [PATCH 324/406] DynamicTablesPkg/AmlLib: Add AmlCodeGenMethodRetBuffer API Add support for generating AML methods that return a buffer through the new AmlCodeGenMethodRetBuffer() API. Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com> --- .../Include/Library/AmlLib/AmlLib.h | 51 ++++++++ .../Common/AmlLib/CodeGen/AmlCodeGen.c | 114 ++++++++++++++++++ 2 files changed, 165 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h index f4edaecc41..cea78d4192 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -1591,6 +1591,57 @@ AmlCodeGenMethodRetInteger ( OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL ); +/** AML code generation for a method returning a Buffer. + + AmlCodeGenMethodRetBuffer ( + "_MAT", ReturnedBuffer, ReturnedBufferSize, 1, TRUE, 0, ParentNode, NewObjectNode + ); + is equivalent of the following ASL code: + Method(_MAT, 1, Serialized, 0) { + Return (Buffer (ReturnedBufferSize) {...}) + } + + To return an empty buffer, call the function with + (ReturnedBuffer=NULL, ReturnedBufferSize=0). + + @param [in] MethodNameString The new Method's name. + Must be a NULL-terminated ASL NameString + e.g.: "MET0", "_SB.MET0", etc. + The input string is copied. + @param [in] ReturnedBuffer The buffer returned by the method. + The input buffer is copied. + NULL if an empty buffer is returned. + @param [in] ReturnedBufferSize Size of ReturnedBuffer. + Must be 0 if ReturnedBuffer is NULL. + @param [in] NumArgs Number of arguments. + Must be 0 <= NumArgs <= 6. + @param [in] IsSerialized TRUE is equivalent to Serialized. + FALSE is equivalent to NotSerialized. + Default is NotSerialized in ASL spec. + @param [in] SyncLevel Synchronization level for the method. + Must be 0 <= SyncLevel <= 15. + Default is 0 in ASL. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + @param [out] NewObjectNode If success, contains the created node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenMethodRetBuffer ( + IN CONST CHAR8 *MethodNameString, + IN CONST UINT8 *ReturnedBuffer, + IN UINT32 ReturnedBufferSize, + IN UINT8 NumArgs, + IN BOOLEAN IsSerialized, + IN UINT8 SyncLevel, + IN AML_NODE_HANDLE ParentNode OPTIONAL, + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL + ); + /** AML code generation for a method returning a NameString that takes an integer argument. diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c index 41a43e7388..5ed4340b0c 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -2414,6 +2414,120 @@ error_handler: return Status; } +/** AML code generation for a method returning a Buffer. + + AmlCodeGenMethodRetBuffer ( + "_MAT", ReturnedBuffer, ReturnedBufferSize, 1, TRUE, 0, ParentNode, NewObjectNode + ); + is equivalent of the following ASL code: + Method(_MAT, 1, Serialized, 0) { + Return (Buffer (ReturnedBufferSize) {...}) + } + + To return an empty buffer, call the function with + (ReturnedBuffer=NULL, ReturnedBufferSize=0). + + @param [in] MethodNameString The new Method's name. + Must be a NULL-terminated ASL NameString + e.g.: "MET0", "_SB.MET0", etc. + The input string is copied. + @param [in] ReturnedBuffer The buffer returned by the method. + The input buffer is copied. + NULL if an empty buffer is returned. + @param [in] ReturnedBufferSize Size of ReturnedBuffer. + Must be 0 if ReturnedBuffer is NULL. + @param [in] NumArgs Number of arguments. + Must be 0 <= NumArgs <= 6. + @param [in] IsSerialized TRUE is equivalent to Serialized. + FALSE is equivalent to NotSerialized. + Default is NotSerialized in ASL spec. + @param [in] SyncLevel Synchronization level for the method. + Must be 0 <= SyncLevel <= 15. + Default is 0 in ASL. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + @param [out] NewObjectNode If success, contains the created node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenMethodRetBuffer ( + IN CONST CHAR8 *MethodNameString, + IN CONST UINT8 *ReturnedBuffer, + IN UINT32 ReturnedBufferSize, + IN UINT8 NumArgs, + IN BOOLEAN IsSerialized, + IN UINT8 SyncLevel, + IN AML_NODE_HANDLE ParentNode OPTIONAL, + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE_HANDLE MethodNode; + AML_OBJECT_NODE_HANDLE BufferNode; + + if ((MethodNameString == NULL) || + ((ParentNode == NULL) && (NewObjectNode == NULL)) || + ((ReturnedBuffer == NULL) != (ReturnedBufferSize == 0))) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Create a Method named MethodNameString. + Status = AmlCodeGenMethod ( + MethodNameString, + NumArgs, + IsSerialized, + SyncLevel, + NULL, + &MethodNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = AmlCodeGenBuffer (ReturnedBuffer, ReturnedBufferSize, &BufferNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + // AmlCodeGenReturn() deletes BufferNode if an error occurs. + Status = AmlCodeGenReturn ( + (AML_NODE_HEADER *)BufferNode, + (AML_NODE_HEADER *)MethodNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status = LinkNode ( + MethodNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + return Status; + +error_handler: + if (MethodNode != NULL) { + AmlDeleteTree ((AML_NODE_HANDLE)MethodNode); + } + + return Status; +} + /** Create a _LPI name. AmlCreateLpiNode ("_LPI", 0, 1, ParentNode, &LpiNode) is From 82dd8ab1b374a907bff6a009d5f0efc510d53a98 Mon Sep 17 00:00:00 2001 From: Tuan Phan <tuan.phan@oss.qualcomm.com> Date: Thu, 23 Jul 2026 21:49:37 -0700 Subject: [PATCH 325/406] DynamicTablesPkg/AmiLib: Fix stack corruption in AmlCodeGenRdInterrupt In AmlCodeGenRdInterrupt(), the IRQ list was copied directly into an EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR structure allocated on the stack. Since the structure only contains storage for the first interrupt entry, copying multiple IRQs would write beyond the allocated buffer and corrupt the stack. Fix this issue by allocating the descriptor dynamically with sufficient space to accommodate the entire IRQ list. This ensures all interrupt entries are copied safely without overwriting adjacent stack memory. Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com> --- .../AmlLib/CodeGen/AmlResourceDataCodeGen.c | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c index 4b5e100209..cc94521e86 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c @@ -1266,7 +1266,8 @@ AmlCodeGenRdInterrupt ( EFI_STATUS Status; AML_DATA_NODE *RdNode; - EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR RdInterrupt; + EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR *RdInterrupt; + UINT16 RdInterruptSize; UINT32 *FirstInterrupt; if ((IrqList == NULL) || @@ -1277,32 +1278,40 @@ AmlCodeGenRdInterrupt ( return EFI_INVALID_PARAMETER; } + // EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR already includes the first interrupt + RdInterruptSize = sizeof (EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR) + (IrqCount - 1) * sizeof (UINT32); + RdInterrupt = (EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR *)AllocateZeroPool (RdInterruptSize); + if (RdInterrupt == NULL) { + ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES); + return EFI_OUT_OF_RESOURCES; + } + // Header - RdInterrupt.Header.Header.Bits.Name = + RdInterrupt->Header.Header.Bits.Name = ACPI_LARGE_EXTENDED_IRQ_DESCRIPTOR_NAME; - RdInterrupt.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG; - RdInterrupt.Header.Length = sizeof (EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR) - - sizeof (ACPI_LARGE_RESOURCE_HEADER); + RdInterrupt->Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG; + RdInterrupt->Header.Length = RdInterruptSize - sizeof (ACPI_LARGE_RESOURCE_HEADER); // Body - RdInterrupt.InterruptVectorFlags = (ResourceConsumer ? BIT0 : 0) | - (EdgeTriggered ? BIT1 : 0) | - (ActiveLow ? BIT2 : 0) | - (Shared ? BIT3 : 0); - RdInterrupt.InterruptTableLength = IrqCount; + RdInterrupt->InterruptVectorFlags = (ResourceConsumer ? BIT0 : 0) | + (EdgeTriggered ? BIT1 : 0) | + (ActiveLow ? BIT2 : 0) | + (Shared ? BIT3 : 0); + RdInterrupt->InterruptTableLength = IrqCount; // Get the address of the first interrupt field. - FirstInterrupt = RdInterrupt.InterruptNumber; + FirstInterrupt = RdInterrupt->InterruptNumber; // Copy the list of interrupts. CopyMem (FirstInterrupt, IrqList, (sizeof (UINT32) * IrqCount)); Status = AmlCreateDataNode ( EAmlNodeDataTypeResourceData, - (UINT8 *)&RdInterrupt, - sizeof (EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR), + (UINT8 *)RdInterrupt, + RdInterruptSize, &RdNode ); + FreePool (RdInterrupt); if (EFI_ERROR (Status)) { ASSERT (0); return Status; From abff40cb50ed7ffd6d8549f44b68a2fd7552e067 Mon Sep 17 00:00:00 2001 From: Marc Zyngier <maz@kernel.org> Date: Sat, 27 Jun 2026 08:52:35 -0700 Subject: [PATCH 326/406] DynamicTablesPkg: Support EL2 virtual timer in ArmGenericTimerParser When edk2 runs as a kvmtool guest with nested virtualization enabled, the Arm architectural timer DT node contains five interrupt specifiers. The fifth interrupt describes the EL2 virtual timer. ArmGenericTimerParser currently expects exactly four timer interrupts. It therefore asserts when parsing the timer node generated for a nested virtualization guest. Determine the number of interrupt specifiers present in the DT and populate each architectural timer entry only when it is available. Add support for the EL2 virtual timer and use it to populate the VirtualPL2Timer fields in the generated GTDT information. Tested as a KVM guest at EL1 and EL2, with both E2H==0 and E2H==1. Signed-off-by: Marc Zyngier <maz@kernel.org> [Varshit Pandya: Rewrite commit message for clarity.] Ref: https://edk2.groups.io/g/devel/message/122008 Signed-off-by: Varshit Pandya <varshit.pandya@arm.com> --- .../Arm/GenericTimer/ArmGenericTimerParser.c | 88 ++++++++++++------- .../Arm/GenericTimer/ArmGenericTimerParser.h | 1 + 2 files changed, 58 insertions(+), 31 deletions(-) diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Arm/GenericTimer/ArmGenericTimerParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Arm/GenericTimer/ArmGenericTimerParser.c index a14ed3a98a..05f2b1c7c0 100644 --- a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Arm/GenericTimer/ArmGenericTimerParser.c +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Arm/GenericTimer/ArmGenericTimerParser.c @@ -56,7 +56,8 @@ TimerNodeParser ( UINT32 GicVersion; INT32 DataSize; INT32 IntCells; - BOOLEAN AlwaysOnTimer; + INT32 IntCount; + UINT32 AlwaysOnTimerFlag; if ((Fdt == NULL) || (GenericTimerInfo == NULL)) @@ -67,9 +68,9 @@ TimerNodeParser ( Data = FdtGetProp (Fdt, TimerNode, "always-on", &DataSize); if ((Data == NULL) || (DataSize < 0)) { - AlwaysOnTimer = FALSE; + AlwaysOnTimerFlag = 0; } else { - AlwaysOnTimer = TRUE; + AlwaysOnTimerFlag = BIT2; } // Get the associated interrupt-controller. @@ -88,8 +89,9 @@ TimerNodeParser ( // Get the number of cells used to encode an interrupt. Status = FdtGetInterruptCellsInfo (Fdt, IntcNode, &IntCells); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || (IntCells == 0)) { ASSERT (0); + ASSERT (IntCells != 0); if (Status == EFI_NOT_FOUND) { // Should have found the node. Status = EFI_ABORTED; @@ -98,37 +100,65 @@ TimerNodeParser ( return Status; } - Data = FdtGetProp (Fdt, TimerNode, "interrupts", &DataSize); + Data = FdtGetProp (Fdt, TimerNode, "interrupts", &DataSize); + IntCount = DataSize / IntCells / sizeof (UINT32); if ((Data == NULL) || - (DataSize != (FdtMaxTimerItem * IntCells * sizeof (UINT32)))) + (IntCount > FdtMaxTimerItem)) { // If error or not FdtMaxTimerItem interrupts. ASSERT (0); return EFI_ABORTED; } - GenericTimerInfo->SecurePL1TimerGSIV = - FdtGetInterruptId (&Data[FdtSecureTimerIrq * IntCells]); - GenericTimerInfo->SecurePL1TimerFlags = - FdtGetInterruptFlags (&Data[FdtSecureTimerIrq * IntCells]); - GenericTimerInfo->NonSecurePL1TimerGSIV = - FdtGetInterruptId (&Data[FdtNonSecureTimerIrq * IntCells]); - GenericTimerInfo->NonSecurePL1TimerFlags = - FdtGetInterruptFlags (&Data[FdtNonSecureTimerIrq * IntCells]); - GenericTimerInfo->VirtualTimerGSIV = - FdtGetInterruptId (&Data[FdtVirtualTimerIrq * IntCells]); - GenericTimerInfo->VirtualTimerFlags = - FdtGetInterruptFlags (&Data[FdtVirtualTimerIrq * IntCells]); - GenericTimerInfo->NonSecurePL2TimerGSIV = - FdtGetInterruptId (&Data[FdtHypervisorTimerIrq * IntCells]); - GenericTimerInfo->NonSecurePL2TimerFlags = - FdtGetInterruptFlags (&Data[FdtHypervisorTimerIrq * IntCells]); + if ((IntCount > FdtSecureTimerIrq)) { + GenericTimerInfo->SecurePL1TimerGSIV = + FdtGetInterruptId (&Data[FdtSecureTimerIrq * IntCells]); + GenericTimerInfo->SecurePL1TimerFlags = + FdtGetInterruptFlags (&Data[FdtSecureTimerIrq * IntCells]) | AlwaysOnTimerFlag; + } else { + // No timer, no luck + ASSERT (0); + return EFI_ABORTED; + } - if (AlwaysOnTimer) { - GenericTimerInfo->SecurePL1TimerFlags |= BIT2; - GenericTimerInfo->NonSecurePL1TimerFlags |= BIT2; - GenericTimerInfo->VirtualTimerFlags |= BIT2; - GenericTimerInfo->NonSecurePL2TimerFlags |= BIT2; + if ((IntCount > FdtNonSecureTimerIrq)) { + GenericTimerInfo->NonSecurePL1TimerGSIV = + FdtGetInterruptId (&Data[FdtNonSecureTimerIrq * IntCells]); + GenericTimerInfo->NonSecurePL1TimerFlags = + FdtGetInterruptFlags (&Data[FdtNonSecureTimerIrq * IntCells]) | AlwaysOnTimerFlag; + } else { + GenericTimerInfo->NonSecurePL1TimerGSIV = 0; + GenericTimerInfo->NonSecurePL1TimerFlags = 0; + } + + if ((IntCount > FdtVirtualTimerIrq)) { + GenericTimerInfo->VirtualTimerGSIV = + FdtGetInterruptId (&Data[FdtVirtualTimerIrq * IntCells]); + GenericTimerInfo->VirtualTimerFlags = + FdtGetInterruptFlags (&Data[FdtVirtualTimerIrq * IntCells]) | AlwaysOnTimerFlag; + } else { + GenericTimerInfo->VirtualTimerGSIV = 0; + GenericTimerInfo->VirtualTimerFlags = 0; + } + + if ((IntCount > FdtHypervisorTimerIrq)) { + GenericTimerInfo->NonSecurePL2TimerGSIV = + FdtGetInterruptId (&Data[FdtHypervisorTimerIrq * IntCells]); + GenericTimerInfo->NonSecurePL2TimerFlags = + FdtGetInterruptFlags (&Data[FdtHypervisorTimerIrq * IntCells]) | AlwaysOnTimerFlag; + } else { + GenericTimerInfo->NonSecurePL2TimerGSIV = 0; + GenericTimerInfo->NonSecurePL2TimerFlags = 0; + } + + if ((IntCount > FdtHypervisorVTimerIrq)) { + GenericTimerInfo->VirtualPL2TimerGSIV = + FdtGetInterruptId (&Data[FdtHypervisorVTimerIrq * IntCells]); + GenericTimerInfo->VirtualPL2TimerFlags = + FdtGetInterruptFlags (&Data[FdtHypervisorVTimerIrq * IntCells]) | AlwaysOnTimerFlag; + } else { + GenericTimerInfo->VirtualPL2TimerGSIV = 0; + GenericTimerInfo->VirtualPL2TimerFlags = 0; } // Setup default values @@ -138,10 +168,6 @@ TimerNodeParser ( GenericTimerInfo->CounterControlBaseAddress = 0xFFFFFFFFFFFFFFFF; GenericTimerInfo->CounterReadBaseAddress = 0xFFFFFFFFFFFFFFFF; - // For systems not implementing ARMv8.1 VHE, this field is 0. - GenericTimerInfo->VirtualPL2TimerGSIV = 0; - GenericTimerInfo->VirtualPL2TimerFlags = 0; - return EFI_SUCCESS; } diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Arm/GenericTimer/ArmGenericTimerParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Arm/GenericTimer/ArmGenericTimerParser.h index f4712048ef..8b685397b9 100644 --- a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Arm/GenericTimer/ArmGenericTimerParser.h +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Arm/GenericTimer/ArmGenericTimerParser.h @@ -17,6 +17,7 @@ typedef enum FdtTimerInterruptItems { FdtNonSecureTimerIrq, ///< Non-secure timer IRQ FdtVirtualTimerIrq, ///< Virtual timer IRQ FdtHypervisorTimerIrq, ///< Hypervisor timer IRQ + FdtHypervisorVTimerIrq, ///< Hypervisor virtual timer IRQ FdtMaxTimerItem ///< Max timer item } FDT_TIMER_INTERRUPT_ITEMS; From 70d2149e39e4765eae4ee4350b09f8484b8e43a7 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 27 Jan 2026 12:24:43 -0800 Subject: [PATCH 327/406] BaseTools: iasl: Update iasl binaries to 20230628 release This change updates the iasl binary to the 20230628 release. The updated release also adds support for execution on ARM host machines. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- BaseTools/Bin/iasl_ext_dep.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseTools/Bin/iasl_ext_dep.yaml b/BaseTools/Bin/iasl_ext_dep.yaml index ea2bc315d1..f9fcffc540 100644 --- a/BaseTools/Bin/iasl_ext_dep.yaml +++ b/BaseTools/Bin/iasl_ext_dep.yaml @@ -16,6 +16,6 @@ "type": "nuget", "name": "edk2-acpica-iasl", "source": "https://pkgs.dev.azure.com/projectmu/acpica/_packaging/mu_iasl/nuget/v3/index.json", - "version": "20200717.0.0", + "version": "20230628.0.1", "flags": ["set_path", "host_specific"] } From 94d9804c32d62d6d51885f5019aaa53ac5e85a8c Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 20 Jan 2026 12:50:49 -0800 Subject: [PATCH 328/406] MdePkg: UnitTestHostBaseLib: Added preprocessor for AArch64 instances This change adds a few preprocessors to build AArch64 host based unit tests properly. An AArch64 specific instance of `gUnitTestHostBaseLib` is created to abstract the reference of arch specific special instructions. Signed-off-by: Kun Qin <kuqin12@gmail.com> --- MdePkg/Library/BaseLib/AArch64UnitTestHost.c | 30 +++++++++++++++++++ .../Library/BaseLib/UnitTestHostBaseLib.inf | 5 ++-- .../Include/Library/UnitTestHostBaseLib.h | 10 +++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 MdePkg/Library/BaseLib/AArch64UnitTestHost.c diff --git a/MdePkg/Library/BaseLib/AArch64UnitTestHost.c b/MdePkg/Library/BaseLib/AArch64UnitTestHost.c new file mode 100644 index 0000000000..03d4f4e7b2 --- /dev/null +++ b/MdePkg/Library/BaseLib/AArch64UnitTestHost.c @@ -0,0 +1,30 @@ +/** @file + AARCH64 specific Unit Test Host functions. + + Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> + Copyright (c), Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UnitTestHost.h" + +/// +/// Common services +/// +STATIC UNIT_TEST_HOST_BASE_LIB_COMMON mUnitTestHostBaseLibCommon = { + UnitTestHostBaseLibEnableInterrupts, + UnitTestHostBaseLibDisableInterrupts, + UnitTestHostBaseLibEnableDisableInterrupts, + UnitTestHostBaseLibGetInterruptState, +}; + +/// +/// Structure of hook functions for BaseLib functions that can not be used from +/// a host application. A simple emulation of these function is provided by +/// default. A specific unit test can provide its own implementation for any +/// of these functions. +/// +UNIT_TEST_HOST_BASE_LIB gUnitTestHostBaseLib = { + &mUnitTestHostBaseLibCommon +}; diff --git a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf index 74eec73555..3452f4cd57 100644 --- a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf +++ b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf @@ -23,7 +23,7 @@ LIBRARY_CLASS = UnitTestHostBaseLib|HOST_APPLICATION # -# VALID_ARCHITECTURES = IA32 X64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 # [Sources] @@ -183,7 +183,7 @@ [Sources.AARCH64] AArch64/InternalSwitchStack.c - AArch64/Unaligned.c + Unaligned.c Math64.c AArch64/MemoryFence.S | GCC @@ -197,6 +197,7 @@ AArch64/SetJumpLongJump.asm | MSFT AArch64/CpuBreakpoint.asm | MSFT AArch64/SpeculationBarrier.asm | MSFT + AArch64UnitTestHost.c [Sources.RISCV64] Math64.c diff --git a/MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h b/MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h index 60a57aed67..babaa5f562 100644 --- a/MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h +++ b/MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h @@ -76,6 +76,8 @@ UINTN IN UINTN Value ); +#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) + /** Prototype of service that reads and returns an IA32_DESCRIPTOR. @@ -490,6 +492,8 @@ VOID IN UINTN ValueSize ); +#endif // MDE_CPU_IA32 || MDE_CPU_X64 + /// /// Common services /// @@ -500,6 +504,8 @@ typedef struct { UNIT_TEST_HOST_BASE_LIB_READ_BOOLEAN GetInterruptState; } UNIT_TEST_HOST_BASE_LIB_COMMON; +#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) + /// /// IA32/X64 services /// @@ -566,6 +572,8 @@ typedef struct { UNIT_TEST_HOST_BASE_LIB_ASM_PATCH_INSTRUCTION_X86 PatchInstructionX86; } UNIT_TEST_HOST_BASE_LIB_X86; +#endif // MDE_CPU_IA32 || MDE_CPU_X64 + /// /// Data structure that contains pointers structures of common services and CPU /// architecture specific services. Support for additional CPU architectures @@ -573,7 +581,9 @@ typedef struct { /// typedef struct { UNIT_TEST_HOST_BASE_LIB_COMMON *Common; + #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) UNIT_TEST_HOST_BASE_LIB_X86 *X86; + #endif } UNIT_TEST_HOST_BASE_LIB; extern UNIT_TEST_HOST_BASE_LIB gUnitTestHostBaseLib; From 668b5d7bb7f9bf90412110fae420dc15fd580b58 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Fri, 1 May 2026 13:58:11 -0700 Subject: [PATCH 329/406] MdePkg: UnitTestHostBaseLib: Clean up source entries The existing UnitTestHostBaseLib has some source entries that are either redundant or for unsupported architectures. This change consolidated the redundant entries and removed the entries for unsupported architectures. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf index 3452f4cd57..987e4e2821 100644 --- a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf +++ b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf @@ -63,6 +63,7 @@ SafeString.c String.c FilePaths.c + Unaligned.c BaseLibInternals.h UnitTestHost.c UnitTestHost.h @@ -121,7 +122,6 @@ Ia32/InternalSwitchStack.c | MSFT Ia32/InternalSwitchStack.nasm | GCC Ia32/Non-existing.c - Unaligned.c X86MemoryFence.c | MSFT X86FxSave.c X86FxRestore.c @@ -160,7 +160,6 @@ X64/ReadEflags.nasm| MSFT X64/Non-existing.c Math64.c - Unaligned.c X86MemoryFence.c | MSFT X86FxSave.c X86FxRestore.c @@ -173,17 +172,8 @@ IntelTdxNull.c AmdSevNull.c -[Sources.EBC] - Ebc/CpuBreakpoint.c - Ebc/SetJumpLongJump.c - Ebc/SwitchStack.c - Ebc/SpeculationBarrier.c - Unaligned.c - Math64.c - [Sources.AARCH64] AArch64/InternalSwitchStack.c - Unaligned.c Math64.c AArch64/MemoryFence.S | GCC From 1fa1a89382cc6978a22d1aed0420ae12bd4f60c3 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 20 Jan 2026 13:00:06 -0800 Subject: [PATCH 330/406] UnitTestFrameworkPkg: SampleGoogleTest: No divide-by-zero test for AArch64 AArch64 does not have divide-by-zero exception. This change modifies the corresponding test to work with AArch64. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- .../SampleGoogleTest/SampleGoogleTest.cpp | 22 ----------- .../SampleGoogleTest/SampleGoogleTestHost.inf | 5 ++- .../SampleGoogleTest/SampleGoogleTestX86.cpp | 39 +++++++++++++++++++ 3 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTestX86.cpp diff --git a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp index 278a14f4ee..81f463188b 100644 --- a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp +++ b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp @@ -544,28 +544,6 @@ TEST (SanitizerTests, InvalidPointerWriteDeathTest) { EXPECT_DEATH (*(volatile UINT8 *)(-1) = 0, "ERROR: AddressSanitizer: "); } -UINTN -DivideWithNoParameterChecking ( - UINTN Dividend, - UINTN Divisor - ) -{ - // - // Perform integer division with no check for divide by zero - // - return (Dividend / Divisor); -} - -/** - Sample unit test that performs a divide by 0 -**/ -TEST (SanitizerTests, DivideByZeroDeathTest) { - // - // Divide by 0 should be caught by address sanitizer, log details, and exit - // - EXPECT_DEATH (DivideWithNoParameterChecking (10, 0), "ERROR: AddressSanitizer: "); -} - /** Sample unit test that allocates and frees buffers below 4GB **/ diff --git a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTestHost.inf b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTestHost.inf index 37e7c86910..776b2bfbff 100644 --- a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTestHost.inf +++ b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTestHost.inf @@ -16,12 +16,15 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = IA32 X64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 # [Sources] SampleGoogleTest.cpp +[Sources.IA32, Sources.X64] + SampleGoogleTestX86.cpp + [Packages] MdePkg/MdePkg.dec UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec diff --git a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTestX86.cpp b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTestX86.cpp new file mode 100644 index 0000000000..2bea0c3af6 --- /dev/null +++ b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTestX86.cpp @@ -0,0 +1,39 @@ +/** @file + This is a sample to demonstrates the use of GoogleTest that supports host + execution environments. + + Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/GoogleTestLib.h> +extern "C" { + #include <Uefi.h> + #include <Library/BaseLib.h> + #include <Library/DebugLib.h> + #include <Library/MemoryAllocationLib.h> + #include <Library/HostMemoryAllocationBelowAddressLib.h> +} + +UINTN +DivideWithNoParameterChecking ( + UINTN Dividend, + UINTN Divisor + ) +{ + // + // Perform integer division with no check for divide by zero + // + return (Dividend / Divisor); +} + +/** + Sample unit test that performs a divide by 0 +**/ +TEST (SanitizerTests, DivideByZeroDeathTest) { + // + // Divide by 0 should be caught by address sanitizer, log details, and exit + // + EXPECT_DEATH (DivideWithNoParameterChecking (10, 0), "ERROR: AddressSanitizer: "); +} From d47954ceb47592b8f6dc24d21c4e422e1df3485b Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Mon, 11 May 2026 13:06:37 -0700 Subject: [PATCH 331/406] UnitTestFrameworkPkg: SampleGoogleTestGenerateException: Support AArch64 The SampleGoogleTestGenerateException GoogleTest sample previously generated a CPU exception by performing an integer divide by zero. That mechanism is X86-specific: the AArch64 architecture defines SDIV/UDIV by zero to return zero rather than raising a synchronous abort, so the sample produced no exception when built and run on AArch64 hosts and the test failed due to the test assert instead of triggering an exception through the framework. This change replaces the divide-by-zero with a NULL pointer write performed through a small volatile helper, which is expected to work on all host systems. The MSVC '/wd4723' build option is no longer needed because it was added to silence the divide-by-zero compile-time warning. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- .../SampleGoogleTestGenerateException.cpp | 32 +++++++++++++------ .../SampleGoogleTestHostGenerateException.inf | 2 +- ...UnitTestFrameworkPkgHostTestExpectFail.dsc | 10 +++--- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/SampleGoogleTestGenerateException.cpp b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/SampleGoogleTestGenerateException.cpp index 6e62bd79ff..69f9364baf 100644 --- a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/SampleGoogleTestGenerateException.cpp +++ b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/SampleGoogleTestGenerateException.cpp @@ -6,6 +6,10 @@ condition may be report a unit test failure and continue with additional unit tests. + A NULL pointer write is used to generate the exception because it produces + a fatal CPU exception (translation/page fault) on every architecture + supported by EDK II host-based testing. + Copyright (c) 2024, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -17,30 +21,38 @@ extern "C" { #include <Library/DebugLib.h> } -UINTN -DivideWithNoParameterChecking ( - UINTN Dividend, - UINTN Divisor +VOID +WriteByteWithNoParameterChecking ( + VOID *Address, + UINT8 Value ) { // - // Perform integer division with no check for divide by zero + // Perform a byte write to the supplied address with no validity check. // - return (Dividend / Divisor); + *(volatile UINT8 *)Address = Value; } /** - Sample unit test that generates an unexpected exception + Sample unit test that generates an unexpected exception by writing to a + NULL pointer. **/ TEST (ExceptionTest, GenerateExceptionExpectTestFail) { + UINT8 LocalByte; + + LocalByte = 0; + // // Assertion that passes without generating an exception // - EXPECT_EQ (DivideWithNoParameterChecking (20, 1), (UINTN)20); + WriteByteWithNoParameterChecking (&LocalByte, 0xA5); + EXPECT_EQ (LocalByte, (UINT8)0xA5); // - // Assertion that generates divide by zero exception before result evaluated + // Assertion that generates a NULL pointer access exception before the + // following EXPECT_EQ result is evaluated // - EXPECT_EQ (DivideWithNoParameterChecking (20, 0), MAX_UINTN); + WriteByteWithNoParameterChecking (NULL, 0xA5); + EXPECT_EQ (LocalByte, (UINT8)0xA5); } int diff --git a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/SampleGoogleTestHostGenerateException.inf b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/SampleGoogleTestHostGenerateException.inf index 3ce356c8ce..59acc6e984 100644 --- a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/SampleGoogleTestHostGenerateException.inf +++ b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/SampleGoogleTestHostGenerateException.inf @@ -20,7 +20,7 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = IA32 X64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 # [Sources] diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc index 73b4cb1b92..662d552225 100644 --- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc +++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc @@ -35,14 +35,16 @@ UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestExpectFail/SampleGoogleTestHostExpectFail.inf UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestExpectFail/SampleUnitTestHostExpectFail.inf + # + # Unit tests that deliberately trigger a NULL pointer access to demonstrate how + # the framework reports a test case that is terminated by the host operating system. + # + UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/SampleGoogleTestHostGenerateException.inf + # # Disable warning for divide by zero to pass build of unit tests # that generate a divide by zero exception. # - UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/SampleGoogleTestHostGenerateException.inf { - <BuildOptions> - MSFT:*_*_*_CC_FLAGS = /wd4723 - } UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestHostGenerateException.inf { <BuildOptions> MSFT:*_*_*_CC_FLAGS = /wd4723 From 4d024b0cde7527e6b0fbb363881c2c1aa751b23b Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Thu, 16 Jul 2026 13:55:57 -0700 Subject: [PATCH 332/406] UnitTestFrameworkPkg: SampleUnitTestGenerateException: Fix for AArch64 AArch64 does not generate divide-by-zero exceptions like x86. Yet the current generate exception test is using this operation to attempt triggering exceptions. This change abstracted the exception generation logic into per-arch files and use undefined instruction to trigger AArch64 exceptions. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- .../SampleUnitTestDxeGenerateException.inf | 8 ++- .../SampleUnitTestGenerateException.c | 66 ++++++------------ .../SampleUnitTestGenerateExceptionAArch64.c | 41 +++++++++++ .../SampleUnitTestGenerateExceptionIA32X64.c | 69 +++++++++++++++++++ .../SampleUnitTestHostGenerateException.inf | 8 ++- .../SampleUnitTestPeiGenerateException.inf | 8 ++- .../SampleUnitTestSmmGenerateException.inf | 3 + ...mpleUnitTestUefiShellGenerateException.inf | 8 ++- UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc | 11 +-- 9 files changed, 169 insertions(+), 53 deletions(-) create mode 100644 UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateExceptionAArch64.c create mode 100644 UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateExceptionIA32X64.c diff --git a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestDxeGenerateException.inf b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestDxeGenerateException.inf index b742befe4d..d3ef3ddffd 100644 --- a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestDxeGenerateException.inf +++ b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestDxeGenerateException.inf @@ -20,12 +20,18 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = IA32 X64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 # [Sources] SampleUnitTestGenerateException.c +[Sources.IA32, Sources.X64] + SampleUnitTestGenerateExceptionIA32X64.c + +[Sources.AARCH64] + SampleUnitTestGenerateExceptionAArch64.c + [Packages] MdePkg/MdePkg.dec diff --git a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateException.c b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateException.c index 4576e0c81e..26d3f8b020 100644 --- a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateException.c +++ b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateException.c @@ -20,6 +20,27 @@ #define UNIT_TEST_NAME "Sample Unit Test Generate Exception" #define UNIT_TEST_VERSION "0.1" +/** + Sample unit test the triggers an unexpected exception + + @param[in] Context [Optional] An optional parameter that enables: + 1) test-case reuse with varied parameters and + 2) test-case re-entry for Target tests that need a + reboot. This parameter is a VOID* and it is the + responsibility of the test author to ensure that the + contents are well understood by all test cases that may + consume it. + + @retval UNIT_TEST_PASSED The Unit test has completed and the test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +GenerateUnexpectedException ( + IN UNIT_TEST_CONTEXT Context + ); + /** Unit-Test Test Suite Setup (before) function that enables ASSERT() macros. **/ @@ -50,51 +71,6 @@ TestSuiteDisableAsserts ( PatchPcdSet8 (PcdDebugPropertyMask, PcdGet8 (PcdDebugPropertyMask) & (~BIT0)); } -UINTN -DivideWithNoParameterChecking ( - UINTN Dividend, - UINTN Divisor - ) -{ - // - // Perform integer division with no check for divide by zero - // - return (Dividend / Divisor); -} - -/** - Sample unit test the triggers an unexpected exception - - @param[in] Context [Optional] An optional parameter that enables: - 1) test-case reuse with varied parameters and - 2) test-case re-entry for Target tests that need a - reboot. This parameter is a VOID* and it is the - responsibility of the test author to ensure that the - contents are well understood by all test cases that may - consume it. - - @retval UNIT_TEST_PASSED The Unit test has completed and the test - case was successful. - @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. -**/ -UNIT_TEST_STATUS -EFIAPI -GenerateUnexpectedException ( - IN UNIT_TEST_CONTEXT Context - ) -{ - // - // Assertion that passes without generating an exception - // - UT_ASSERT_EQUAL (DivideWithNoParameterChecking (20, 1), (UINTN)20); - // - // Assertion that generates divide by zero exception before result evaluated - // - UT_ASSERT_EQUAL (DivideWithNoParameterChecking (20, 0), MAX_UINTN); - - return UNIT_TEST_PASSED; -} - /** Initialize the unit test framework, suite, and unit tests for the sample unit tests and run the unit tests. diff --git a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateExceptionAArch64.c b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateExceptionAArch64.c new file mode 100644 index 0000000000..b6ef5ea817 --- /dev/null +++ b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateExceptionAArch64.c @@ -0,0 +1,41 @@ +/** @file + This is a sample to demonstrate the usage of the Unit Test Library that + supports the PEI, DXE, SMM, UEFI Shell, and host execution environments. + This test case generates an exception. For some host-based environments, this + is a fatal condition that terminates the unit tests and no additional test + cases are executed. On other environments, this condition may be report a unit + test failure and continue with additional unit tests. + + Copyright (c) 2024, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include <PiPei.h> +#include <Uefi.h> +#include <Library/UnitTestLib.h> + +/** + Sample unit test the triggers an unexpected exception + + @param[in] Context [Optional] An optional parameter that enables: + 1) test-case reuse with varied parameters and + 2) test-case re-entry for Target tests that need a + reboot. This parameter is a VOID* and it is the + responsibility of the test author to ensure that the + contents are well understood by all test cases that may + consume it. + + @retval UNIT_TEST_PASSED The Unit test has completed and the test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +GenerateUnexpectedException ( + IN UNIT_TEST_CONTEXT Context + ) +{ + asm volatile ("udf #0"); + + return UNIT_TEST_PASSED; +} diff --git a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateExceptionIA32X64.c b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateExceptionIA32X64.c new file mode 100644 index 0000000000..5b5d4c81b5 --- /dev/null +++ b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestGenerateExceptionIA32X64.c @@ -0,0 +1,69 @@ +/** @file + This is a sample to demonstrate the usage of the Unit Test Library that + supports the PEI, DXE, SMM, UEFI Shell, and host execution environments. + This test case generates an exception. For some host-based environments, this + is a fatal condition that terminates the unit tests and no additional test + cases are executed. On other environments, this condition may be report a unit + test failure and continue with additional unit tests. + + Copyright (c) 2024, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include <PiPei.h> +#include <Uefi.h> +#include <Library/DebugLib.h> +#include <Library/UnitTestLib.h> + +/** + Helper function to perform a division operation. + + @param[in] Dividend Dividend of the operation. + @param[in] Divisor Divisor of the operation. + + @return Result of the division. +**/ +UINTN +DivideWithNoParameterChecking ( + UINTN Dividend, + UINTN Divisor + ) +{ + // + // Perform integer division with no check for divide by zero + // + return (Dividend / Divisor); +} + +/** + Sample unit test the triggers an unexpected exception + + @param[in] Context [Optional] An optional parameter that enables: + 1) test-case reuse with varied parameters and + 2) test-case re-entry for Target tests that need a + reboot. This parameter is a VOID* and it is the + responsibility of the test author to ensure that the + contents are well understood by all test cases that may + consume it. + + @retval UNIT_TEST_PASSED The Unit test has completed and the test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +GenerateUnexpectedException ( + IN UNIT_TEST_CONTEXT Context + ) +{ + // + // Assertion that passes without generating an exception + // + UT_ASSERT_EQUAL (DivideWithNoParameterChecking (20, 1), (UINTN)20); + // + // Assertion that generates divide by zero exception before result evaluated + // + UT_ASSERT_EQUAL (DivideWithNoParameterChecking (20, 0), MAX_UINTN); + + return UNIT_TEST_PASSED; +} diff --git a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestHostGenerateException.inf b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestHostGenerateException.inf index a9f10ff184..11328320b2 100644 --- a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestHostGenerateException.inf +++ b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestHostGenerateException.inf @@ -19,12 +19,18 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = IA32 X64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 # [Sources] SampleUnitTestGenerateException.c +[Sources.IA32, Sources.X64] + SampleUnitTestGenerateExceptionIA32X64.c + +[Sources.AARCH64] + SampleUnitTestGenerateExceptionAArch64.c + [Packages] MdePkg/MdePkg.dec diff --git a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestPeiGenerateException.inf b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestPeiGenerateException.inf index cb26961568..c20155ba09 100644 --- a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestPeiGenerateException.inf +++ b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestPeiGenerateException.inf @@ -20,12 +20,18 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = IA32 X64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 # [Sources] SampleUnitTestGenerateException.c +[Sources.IA32, Sources.X64] + SampleUnitTestGenerateExceptionIA32X64.c + +[Sources.AARCH64] + SampleUnitTestGenerateExceptionAArch64.c + [Packages] MdePkg/MdePkg.dec diff --git a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestSmmGenerateException.inf b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestSmmGenerateException.inf index 5aee6a52bd..3c3c56afed 100644 --- a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestSmmGenerateException.inf +++ b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestSmmGenerateException.inf @@ -27,6 +27,9 @@ [Sources] SampleUnitTestGenerateException.c +[Sources.IA32, Sources.X64] + SampleUnitTestGenerateExceptionIA32X64.c + [Packages] MdePkg/MdePkg.dec diff --git a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestUefiShellGenerateException.inf b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestUefiShellGenerateException.inf index 32d6f4270a..2a90537294 100644 --- a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestUefiShellGenerateException.inf +++ b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestUefiShellGenerateException.inf @@ -20,12 +20,18 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = IA32 X64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 # [Sources] SampleUnitTestGenerateException.c +[Sources.IA32, Sources.X64] + SampleUnitTestGenerateExceptionIA32X64.c + +[Sources.AARCH64] + SampleUnitTestGenerateExceptionAArch64.c + [Packages] MdePkg/MdePkg.dec diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc index 0fe700fc62..fed90a7cbe 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc @@ -47,6 +47,7 @@ UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestExpectFail/SampleUnitTestSmmExpectFail.inf UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestExpectFail/SampleUnitTestUefiShellExpectFail.inf +[Components.IA32, Components.X64, Components.AARCH64] # # Disable warning for divide by zero to pass build of unit tests # that generate a divide by zero exception. @@ -59,11 +60,13 @@ <BuildOptions> MSFT:*_*_*_CC_FLAGS = /wd4723 } - UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestSmmGenerateException.inf { - <BuildOptions> - MSFT:*_*_*_CC_FLAGS = /wd4723 - } UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestUefiShellGenerateException.inf { <BuildOptions> MSFT:*_*_*_CC_FLAGS = /wd4723 } + +[Components.IA32, Components.X64] + UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTestGenerateException/SampleUnitTestSmmGenerateException.inf { + <BuildOptions> + MSFT:*_*_*_CC_FLAGS = /wd4723 + } From 476c89e564c89ecd0da9b2a41c612e7377ce6660 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 27 Jan 2026 12:34:35 -0800 Subject: [PATCH 333/406] UnitTestFrameworkPkg: CmockaLib: Support float operations This change adds the support of float operations for AArch64 host based unit tests by overriding the compiler flags. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf | 4 +++- UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf b/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf index e0c55e024b..5b0e62ce72 100644 --- a/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf +++ b/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf @@ -16,7 +16,7 @@ LIBRARY_CLASS = CmockaLib|HOST_APPLICATION # -# VALID_ARCHITECTURES = IA32 X64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 # [Sources] @@ -34,3 +34,5 @@ GCC:*_*_IA32_CC_FLAGS = -m32 GCC:*_*_X64_CC_FLAGS = -m64 GCC:*_CLANGPDB_*_CC_FLAGS = -DHAVE_VSNPRINTF -DHAVE_SNPRINTF -Wno-deprecated-declarations + # Need to use floats in this library. Got rid of -mgeneral-regs-only to do so. + GCC:*_*_AARCH64_CC_XIPFLAGS == -mstrict-align diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml index 0d78a6ae69..8b238c6dc4 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml @@ -118,7 +118,9 @@ "corthon", # Contact GitHub account in Readme "mdkinney", # Contact GitHub account in Readme "spbrogan", # Contact GitHub account in Readme - "uintn" + "uintn", + "mgeneral", # build flag for AArch64 cmocka in the INF + "mstrict", # build flag for AArch64 cmocka in the INF ], "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported) From 26800658dfd24cedde5eacf33a3997087cd5928c Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 20 Jan 2026 13:43:56 -0800 Subject: [PATCH 334/406] UnitTestFrameworkPkg: UnitTestDebugAssertLib: GCC support for AArch64 This change adds the GCC compiler flag for AArch64 targets. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- .../UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf | 1 + 1 file changed, 1 insertion(+) diff --git a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf index 5fa90f521a..09c2e6c826 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf +++ b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf @@ -30,3 +30,4 @@ MSFT:*_*_*_CC_FLAGS == /c /Zi /Od GCC:*_*_IA32_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m32 -malign-double -fno-pie GCC:*_*_X64_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m64 -fno-pie "-DEFIAPI=__attribute__((ms_abi))" + GCC:*_*_AARCH64_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -fno-pie From 56e1e042025707c48715186e50efba4d6b7613b9 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 31 Mar 2026 10:50:57 -0700 Subject: [PATCH 335/406] UnitTestFrameworkPkg: FunctionMockLib: Do not support AArch64 Current FunctionMockLib is relying on the subhoob module to support the backend operation by bitbanging the binary post-disassembly. However subhook module is a x64 centric module and does not support AArch64 usage. This change removes the mock function support for AArch64. The functionality will need other solutions to be properly supported. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- .../Include/Library/FunctionMockLib.h | 12 ++++++- .../FunctionMockLib/FunctionMockLib.inf | 2 ++ .../Test/UnitTestFrameworkPkgHostTest.dsc | 6 ++-- .../UnitTestFrameworkPkgHost.dsc.inc | 32 ++++++++++--------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h b/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h index 9303542fcb..74c8a659ab 100644 --- a/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h +++ b/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h @@ -8,7 +8,9 @@ #pragma once #include <Library/GoogleTestLib.h> -#include <Library/SubhookLib.h> +#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) + #include <Library/SubhookLib.h> +#endif #include <type_traits> ////////////////////////////////////////////////////////////////////////////// @@ -52,6 +54,7 @@ ////////////////////////////////////////////////////////////////////////////// // The below macros are private and should not be used outside this file. +#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) #define MOCK_FUNCTION_HOOK_DECLARATIONS(FUNC) \ static subhook::Hook Hook##FUNC; \ struct MockContainer_##FUNC { \ @@ -59,11 +62,15 @@ ~MockContainer_##FUNC (); \ }; \ MockContainer_##FUNC MockContainerInst_##FUNC; +#else +#define MOCK_FUNCTION_HOOK_DECLARATIONS(FUNC) +#endif // This definition implements a constructor and destructor inside a nested // class to enable automatic installation of the hooks to the associated // MOCK_FUNC() when the mock object is instantiated in scope and automatic // removal when the instantiated mock object goes out of scope. +#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) #define MOCK_FUNCTION_HOOK_DEFINITIONS(MOCK, FUNC) \ subhook :: Hook MOCK :: Hook##FUNC; \ MOCK :: MockContainer_##FUNC :: MockContainer_##FUNC () { \ @@ -83,6 +90,9 @@ "different return type, arguments, or calling convention. See " \ "associated 'MOCK_FUNCTION_INTERNAL_DECLARATION' macro invocation " \ "for more details."); +#else +#define MOCK_FUNCTION_HOOK_DEFINITIONS(MOCK, FUNC) +#endif #define MOCK_FUNCTION_TYPE_DEFINITIONS(RET_TYPE, FUNC, ARGS) \ using FUNC##_ret_type = RET_TYPE; \ diff --git a/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf index 44c5946be5..9f7dc60bcd 100644 --- a/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf +++ b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf @@ -24,6 +24,8 @@ [LibraryClasses] GoogleTestLib + +[LibraryClasses.IA32, LibraryClasses.X64] SubhookLib [Packages] diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc index 1d45d4ba47..d9262a126c 100644 --- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc +++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc @@ -32,10 +32,12 @@ # Build HOST_APPLICATION Libraries # UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf - UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf - UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf + +[Components.IA32, Components.X64] + UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf + UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index d44bee505c..77221b2ebc 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -37,8 +37,6 @@ CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLibNull/BaseCacheMaintenanceLibNull.inf CmockaLib|UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf GoogleTestLib|UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf - SubhookLib|UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf - FunctionMockLib|UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf DebugLib|UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf @@ -54,19 +52,19 @@ # Operating System and Compiler Compatibility Matrix for Host-based unit tests # NOTE: Only NOOPT build target is supported for unit test builds # -# +--------------------+--------+----------+------------+-----+----+--------+ -# | OS/Compiler | VS2019 | CLANGPDB | CLANGDWARF | GCC | XCODE5 | -# | | VS2022 | | | GCCNOLTO | | -# | | VS2026 | | | | | -# +--------------------+--------+----------+------------+----------+--------+ -# | Windows/VS |IA32/X64| | | | | -# | Windows/LLVM/VS | | IA32/X64 | | | | -# | Windows/LLVM/MSYS2 | | | X64 | | | -# | Windows/LLVM/MINGW | | | IA32/X64 | | | -# | Linux/LLVM | | | IA32/X64 | | | -# | Linux/GCC | | | | IA32/X64 | | -# | macOS/XCODE5 | | | | |IA32/X64| -# +--------------------+--------+----------+------------+----------+--------+ +# +--------------------+--------+----------+------------+------------------+--------+ +# | OS/Compiler | VS2019 | CLANGPDB | CLANGDWARF | GCC | XCODE5 | +# | | VS2022 | | | GCCNOLTO | | +# | | VS2026 | | | | | +# +--------------------+--------+----------+------------+------------------+--------+ +# | Windows/VS |IA32/X64| | | | | +# | Windows/LLVM/VS | | IA32/X64 | | | | +# | Windows/LLVM/MSYS2 | | | X64 | | | +# | Windows/LLVM/MINGW | | | IA32/X64 | | | +# | Linux/LLVM | | | IA32/X64 | | | +# | Linux/GCC | | | | IA32/X64/AARCH64 | | +# | macOS/XCODE5 | | | | |IA32/X64| +# +--------------------+--------+----------+------------+------------------+--------+ # # * Windows/VS: Windows environment with Visual Studio installed # * Windows/LLVM/VS: Windows environment with Visual Studio and LLVM 20.1.8 or @@ -125,6 +123,10 @@ !endif !endif +[LibraryClasses.IA32.HOST_APPLICATION, LibraryClasses.X64.HOST_APPLICATION] + SubhookLib|UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf + FunctionMockLib|UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf + [BuildOptions] !if $(WIN_MINGW32_BUILD) GCC:*_CLANGDWARF_IA32_PP_FLAGS = -target i686-w64-mingw32 From 8cdd6f77b7b4cb059630ecfe502d6b7e6d56fbdc Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 20 Jan 2026 13:52:44 -0800 Subject: [PATCH 336/406] UnitTestFrameworkPkg: Test: Adding AArch64 target This change adds the AArch64 target for host based unit tests. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc | 2 +- .../Test/UnitTestFrameworkPkgHostTestExpectFail.dsc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc index d9262a126c..46d5a13cbb 100644 --- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc +++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc @@ -12,7 +12,7 @@ PLATFORM_VERSION = 0.1 DSC_SPECIFICATION = 0x00010005 OUTPUT_DIRECTORY = Build/UnitTestFrameworkPkg/HostTest - SUPPORTED_ARCHITECTURES = IA32|X64 + SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64 BUILD_TARGETS = NOOPT SKUID_IDENTIFIER = DEFAULT diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc index 662d552225..0a0e54450f 100644 --- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc +++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc @@ -19,7 +19,7 @@ PLATFORM_VERSION = 0.1 DSC_SPECIFICATION = 0x00010005 OUTPUT_DIRECTORY = Build/UnitTestFrameworkPkg/HostTestExpectFail - SUPPORTED_ARCHITECTURES = IA32|X64 + SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64 BUILD_TARGETS = NOOPT SKUID_IDENTIFIER = DEFAULT From 6c1505be6412a36e5d29f982cf345e9bbcbad6ec Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 20 Jan 2026 13:53:45 -0800 Subject: [PATCH 337/406] MdePkg: Host Test: Adding AArch64 target This change adds the AArch64 target for host based unit tests. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- MdePkg/Test/MdePkgHostTest.dsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdePkg/Test/MdePkgHostTest.dsc b/MdePkg/Test/MdePkgHostTest.dsc index ff021e76a1..8f3a9f0953 100644 --- a/MdePkg/Test/MdePkgHostTest.dsc +++ b/MdePkg/Test/MdePkgHostTest.dsc @@ -13,7 +13,7 @@ PLATFORM_VERSION = 0.1 DSC_SPECIFICATION = 0x00010005 OUTPUT_DIRECTORY = Build/MdePkg/HostTest - SUPPORTED_ARCHITECTURES = IA32|X64 + SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64 BUILD_TARGETS = NOOPT SKUID_IDENTIFIER = DEFAULT From 47c48984c5d5ab0caadc5d679ca3beb28c6e4433 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 20 Jan 2026 13:55:12 -0800 Subject: [PATCH 338/406] MdeModulePkg: Host Test: Adding AArch64 target This change adds the AArch64 target for host based unit tests. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc index 05fd4652ff..aeecc1a2f7 100644 --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc @@ -13,7 +13,7 @@ PLATFORM_VERSION = 0.1 DSC_SPECIFICATION = 0x00010005 OUTPUT_DIRECTORY = Build/MdeModulePkg/HostTest - SUPPORTED_ARCHITECTURES = IA32|X64 + SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64 BUILD_TARGETS = NOOPT SKUID_IDENTIFIER = DEFAULT From a57c5b6da450ea78ad53035d5b2d8337a6a0f00e Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 27 Jan 2026 16:40:21 -0800 Subject: [PATCH 339/406] FmpDevicePkg: Host Test: Adding AArch64 target This change adds the AArch64 target for host based unit tests. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- FmpDevicePkg/Test/FmpDeviceHostPkgTest.dsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FmpDevicePkg/Test/FmpDeviceHostPkgTest.dsc b/FmpDevicePkg/Test/FmpDeviceHostPkgTest.dsc index 83574399be..faa0608694 100644 --- a/FmpDevicePkg/Test/FmpDeviceHostPkgTest.dsc +++ b/FmpDevicePkg/Test/FmpDeviceHostPkgTest.dsc @@ -12,7 +12,7 @@ PLATFORM_VERSION = 0.1 DSC_SPECIFICATION = 0x00010005 OUTPUT_DIRECTORY = Build/FmpDevicePkg/HostTest - SUPPORTED_ARCHITECTURES = IA32|X64 + SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64 BUILD_TARGETS = NOOPT SKUID_IDENTIFIER = DEFAULT From 4eba9cd69cbf50364620f9431ee2153ae1452bf4 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 27 Jan 2026 16:34:58 -0800 Subject: [PATCH 340/406] DynamicTablesPkg: AcpiDbg2Lib: Adding host based instance The current instance does not support host based test on AArch64 host system due to its dependency on hardware UART library. This change created a new instance that does not initialize the serial port for host based test applications. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- .../AcpiDbg2Lib/AcpiDbg2LibHostTest.inf | 43 +++++++++++++++++++ .../Test/DynamicTablesPkgHostTest.dsc | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2LibHostTest.inf diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2LibHostTest.inf b/DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2LibHostTest.inf new file mode 100644 index 0000000000..8b513409c6 --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2LibHostTest.inf @@ -0,0 +1,43 @@ +## @file +# DBG2 Table Generator +# +# Copyright (c) 2017 - 2020, Arm Limited. All rights reserved.<BR> +# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010019 + BASE_NAME = AcpiDbg2Lib + FILE_GUID = A9C39504-531B-49E1-B639-25A86B85DAA1 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|HOST_APPLICATION + CONSTRUCTOR = AcpiDbg2LibConstructor + DESTRUCTOR = AcpiDbg2LibDestructor + +[Sources] + Dbg2Generator.c + Dbg2Generator.h + Dbg2GeneratorNull.c + +[Packages.ARM, Packages.AARCH64] + ArmPlatformPkg/ArmPlatformPkg.dec + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + BaseLib + PrintLib + SsdtSerialPortFixupLib + +[FixedPcd] + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits diff --git a/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc b/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc index c27cca1ec9..0682d16c7a 100644 --- a/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc +++ b/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc @@ -38,7 +38,7 @@ DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/GoogleTest/Dbg2GeneratorGoogleTest.inf { <LibraryClasses> - NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2Lib.inf + NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2LibHostTest.inf } DynamicTablesPkg/Library/Acpi/Common/AcpiCedtLib/GoogleTest/CedtGeneratorGoogleTest.inf { <LibraryClasses> From 2c74b5ecc9a40838e8f34ff8749f6380c9d6e880 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 27 Jan 2026 16:49:05 -0800 Subject: [PATCH 341/406] DynamicTablesPkg: Host Test: Adding AArch64 target This change adds the AArch64 target for host based unit tests. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc b/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc index 0682d16c7a..f91cffd04f 100644 --- a/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc +++ b/DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc @@ -15,7 +15,7 @@ PLATFORM_VERSION = 0.1 DSC_SPECIFICATION = 0x00010005 OUTPUT_DIRECTORY = Build/DynamicTablesPkg/HostTest - SUPPORTED_ARCHITECTURES = X64 + SUPPORTED_ARCHITECTURES = X64|AARCH64 BUILD_TARGETS = NOOPT SKUID_IDENTIFIER = DEFAULT From 2da91c23b9db73fff8ec4ed02b469530de689143 Mon Sep 17 00:00:00 2001 From: Kun Qin <kuqin@microsoft.com> Date: Tue, 27 Jan 2026 16:40:56 -0800 Subject: [PATCH 342/406] PrmPkg: Host Test: Adding AArch64 target This change adds the AArch64 target for host based unit tests. Signed-off-by: Kun Qin <kun.qin@microsoft.com> --- PrmPkg/Test/PrmPkgHostTest.dsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PrmPkg/Test/PrmPkgHostTest.dsc b/PrmPkg/Test/PrmPkgHostTest.dsc index 75d9046cc2..b6207f9dc2 100644 --- a/PrmPkg/Test/PrmPkgHostTest.dsc +++ b/PrmPkg/Test/PrmPkgHostTest.dsc @@ -12,7 +12,7 @@ PLATFORM_VERSION = 0.1 DSC_SPECIFICATION = 0x00010005 OUTPUT_DIRECTORY = Build/$(PLATFORM_NAME)/HostTest - SUPPORTED_ARCHITECTURES = IA32|X64 + SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64 BUILD_TARGETS = NOOPT SKUID_IDENTIFIER = DEFAULT From 158c70987bb3c919a3b4e91236e9dd9bd37b8f4b Mon Sep 17 00:00:00 2001 From: Jeff Brasen <jbrasen@nvidia.com> Date: Wed, 1 Jul 2026 21:04:35 -0600 Subject: [PATCH 343/406] CryptoPkg/BaseCryptLib: add AARCH64 host unit test Rand source The host-based BaseCryptLib instance (UnitTestHostBaseCryptLib.inf) built Rand/CryptRandTsc.c only for IA32/X64. Add Rand/CryptRand.c for AARCH64 so the openssl-backed RandomSeed() is available when linking AARCH64 host tests, and advertise AARCH64 in VALID_ARCHITECTURES. Signed-off-by: Jeff Brasen <jbrasen@nvidia.com> --- CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf index 9c60aa5f5a..ae98734336 100644 --- a/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf @@ -18,7 +18,7 @@ # # The following information is for reference only and not required by the build tools. # -# VALID_ARCHITECTURES = IA32 X64 +# VALID_ARCHITECTURES = IA32 X64 AARCH64 # [Sources] @@ -63,6 +63,9 @@ [Sources.X64] Rand/CryptRandTsc.c +[Sources.AARCH64] + Rand/CryptRand.c + [Packages] MdePkg/MdePkg.dec CryptoPkg/CryptoPkg.dec From 10732648fb0cb6ca6b804910dec92091406694aa Mon Sep 17 00:00:00 2001 From: Jeff Brasen <jbrasen@nvidia.com> Date: Wed, 1 Jul 2026 21:04:36 -0600 Subject: [PATCH 344/406] SecurityPkg/Test: use BaseRngLibNull for AARCH64 host tests BaseRngLib's AARCH64 backend uses an RNDR instruction path that does not link in the host environment. Map RngLib to BaseRngLibNull for AARCH64 host builds (IA32/X64 keep BaseRngLib) and hoist the common RngLib mapping so the per-component override can be dropped. Signed-off-by: Jeff Brasen <jbrasen@nvidia.com> --- SecurityPkg/Test/SecurityPkgHostTest.dsc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SecurityPkg/Test/SecurityPkgHostTest.dsc b/SecurityPkg/Test/SecurityPkgHostTest.dsc index 64973c26e9..6c455ae379 100644 --- a/SecurityPkg/Test/SecurityPkgHostTest.dsc +++ b/SecurityPkg/Test/SecurityPkgHostTest.dsc @@ -20,6 +20,10 @@ [LibraryClasses] SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf + +[LibraryClasses.AARCH64] + RngLib|MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf [Components] SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiRuntimeServicesTableLib.inf @@ -54,7 +58,6 @@ DxeImageVerificationLib|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf BaseCryptLib|CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibFull.inf - RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf UefiLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf DevicePathLib|MdePkg/Test/Mock/Library/GoogleTest/MockDevicePathLib/MockDevicePathLib.inf SecurityManagementLib|MdeModulePkg/Test/Mock/Library/GoogleTest/MockSecurityManagementLib/MockSecurityManagementLib.inf From 6a4e543b09acb85bf0b4e9e3d075c50950267047 Mon Sep 17 00:00:00 2001 From: Jeff Brasen <jbrasen@nvidia.com> Date: Wed, 1 Jul 2026 21:05:11 -0600 Subject: [PATCH 345/406] SecurityPkg/Test: add AARCH64 to host test DSC Add AARCH64 to SUPPORTED_ARCHITECTURES so the SecurityPkg host-based unit tests build and run on an AARCH64 host. Depends on the AARCH64 host-test framework enablement (UnitTestFrameworkPkg/MdePkg). Signed-off-by: Jeff Brasen <jbrasen@nvidia.com> --- SecurityPkg/Test/SecurityPkgHostTest.dsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SecurityPkg/Test/SecurityPkgHostTest.dsc b/SecurityPkg/Test/SecurityPkgHostTest.dsc index 6c455ae379..6d758ea74c 100644 --- a/SecurityPkg/Test/SecurityPkgHostTest.dsc +++ b/SecurityPkg/Test/SecurityPkgHostTest.dsc @@ -12,7 +12,7 @@ PLATFORM_VERSION = 0.1 DSC_SPECIFICATION = 0x00010005 OUTPUT_DIRECTORY = Build/SecurityPkg/HostTest - SUPPORTED_ARCHITECTURES = IA32|X64 + SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64 BUILD_TARGETS = NOOPT SKUID_IDENTIFIER = DEFAULT From ca8de19382c668cf8770ee788478edcd8a22d0e7 Mon Sep 17 00:00:00 2001 From: Jeff Brasen <jbrasen@nvidia.com> Date: Mon, 20 Jul 2026 14:54:49 -0600 Subject: [PATCH 346/406] MdeModulePkg: MemoryBins: make GoogleTest page-granularity aware MemoryBinGoogleTest.PopulatesFromValidHob asserted fixed page counts for each memory type. PopulateMemoryTypeInformation, however, rounds the runtime memory types (EfiReservedMemoryType, EfiACPIMemoryNVS, EfiRuntimeServicesCode, EfiRuntimeServicesData) up to RUNTIME_PAGE_ALLOCATION_GRANULARITY. That granularity equals EFI_PAGE_SIZE on IA32/X64, so the hard-coded values happened to match, but it is 64 KiB on AArch64, where the same inputs round up to different page counts and the test failed. Compute the expected page counts with the same granularity rounding the production code uses, so the test passes on all host architectures instead of only x86. Signed-off-by: Jeff Brasen <jbrasen@nvidia.com> --- .../Mem/GoogleTest/MemoryBinGoogleTest.cpp | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp b/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp index 486427bd93..ba5a50c82f 100644 --- a/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp +++ b/MdeModulePkg/Core/Dxe/Mem/GoogleTest/MemoryBinGoogleTest.cpp @@ -418,6 +418,36 @@ TEST_F (BaseMemoryBinLibTest, ReturnsNotFoundWhenMemoryTypeInformationHobMissing // // Test: PopulateMemoryTypeInformation populates from valid HOB // +// +// Align a page count to the allocation granularity that +// PopulateMemoryTypeInformation applies for the given memory type. Runtime +// memory types are rounded up to RUNTIME_PAGE_ALLOCATION_GRANULARITY, which is +// larger than EFI_PAGE_SIZE on some architectures (e.g. 64 KiB on AArch64), so +// the resulting page counts are architecture dependent. +// +static UINT32 +ExpectedAlignedPages ( + EFI_MEMORY_TYPE Type, + UINT32 NumberOfPages + ) +{ + UINT32 Granularity; + + if ((Type == EfiReservedMemoryType) || + (Type == EfiACPIMemoryNVS) || + (Type == EfiRuntimeServicesCode) || + (Type == EfiRuntimeServicesData)) + { + Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } else { + Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; + } + + return (UINT32)EFI_SIZE_TO_PAGES ( + ALIGN_VALUE (EFI_PAGES_TO_SIZE ((UINTN)NumberOfPages), Granularity) + ); +} + TEST_F (BaseMemoryBinLibTest, PopulatesFromValidHob) { EFI_STATUS Status; UINT8 GuidHobBuffer[sizeof (EFI_HOB_GUID_TYPE) + sizeof (EFI_MEMORY_TYPE_INFORMATION) * 7]; @@ -453,17 +483,17 @@ TEST_F (BaseMemoryBinLibTest, PopulatesFromValidHob) { ASSERT_EQ (Status, EFI_SUCCESS); ASSERT_EQ (gMemoryTypeInformation[0].Type, (UINT32)EfiReservedMemoryType); - ASSERT_EQ (gMemoryTypeInformation[0].NumberOfPages, (UINT32)5); + ASSERT_EQ (gMemoryTypeInformation[0].NumberOfPages, ExpectedAlignedPages (EfiReservedMemoryType, 5)); ASSERT_EQ (gMemoryTypeInformation[1].Type, (UINT32)EfiRuntimeServicesCode); - ASSERT_EQ (gMemoryTypeInformation[1].NumberOfPages, (UINT32)10); + ASSERT_EQ (gMemoryTypeInformation[1].NumberOfPages, ExpectedAlignedPages (EfiRuntimeServicesCode, 10)); ASSERT_EQ (gMemoryTypeInformation[2].Type, (UINT32)EfiRuntimeServicesData); - ASSERT_EQ (gMemoryTypeInformation[2].NumberOfPages, (UINT32)15); + ASSERT_EQ (gMemoryTypeInformation[2].NumberOfPages, ExpectedAlignedPages (EfiRuntimeServicesData, 15)); ASSERT_EQ (gMemoryTypeInformation[3].Type, (UINT32)EfiACPIReclaimMemory); - ASSERT_EQ (gMemoryTypeInformation[3].NumberOfPages, (UINT32)20); + ASSERT_EQ (gMemoryTypeInformation[3].NumberOfPages, ExpectedAlignedPages (EfiACPIReclaimMemory, 20)); ASSERT_EQ (gMemoryTypeInformation[4].Type, (UINT32)EfiACPIMemoryNVS); - ASSERT_EQ (gMemoryTypeInformation[4].NumberOfPages, (UINT32)25); + ASSERT_EQ (gMemoryTypeInformation[4].NumberOfPages, ExpectedAlignedPages (EfiACPIMemoryNVS, 25)); ASSERT_EQ (gMemoryTypeInformation[5].Type, (UINT32)EfiPalCode); - ASSERT_EQ (gMemoryTypeInformation[5].NumberOfPages, (UINT32)8); + ASSERT_EQ (gMemoryTypeInformation[5].NumberOfPages, ExpectedAlignedPages (EfiPalCode, 8)); } // From 0d9c10b3a211f2fbab86ef153f237d4efc2de8bb Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Mon, 27 Jul 2026 15:57:45 +0200 Subject: [PATCH 347/406] MdePkg: Update AML _STA macros Add a ACPI_AML_STA_DEVICE_STATUS_PRESENT macro without typo, the previous one should be removed ultimately. Introduce macros for _STA supported bits: - STA_BASE_SUPPORTED - STA_SUPPORTED Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- MdePkg/Include/IndustryStandard/Acpi65.h | 23 +++++++++++++++++++++++ MdePkg/Include/IndustryStandard/Acpi66.h | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/MdePkg/Include/IndustryStandard/Acpi65.h b/MdePkg/Include/IndustryStandard/Acpi65.h index 1df92f9858..2b747ff42a 100644 --- a/MdePkg/Include/IndustryStandard/Acpi65.h +++ b/MdePkg/Include/IndustryStandard/Acpi65.h @@ -21,12 +21,35 @@ /// /// _STA bit definitions ACPI 6.5 s6.3.7 /// +#define ACPI_AML_STA_DEVICE_STATUS_PRESENT 0x1 +/// @todo Remove this definition #define ACPI_AML_STA_DEVICE_STATUS_PRESET 0x1 #define ACPI_AML_STA_DEVICE_STATUS_ENABLED 0x2 #define ACPI_AML_STA_DEVICE_STATUS_UI 0x4 #define ACPI_AML_STA_DEVICE_STATUS_FUNCTIONING 0x8 #define ACPI_AML_STA_DEVICE_STATUS_BATTERY 0x10 +/// +/// Supported Status bits (base). +/// The battery bit is ignored and is reserved for +/// "Control Method Battery Device (PNP0C0A)". +/// +#define ACPI_AML_STA_BASE_SUPPORTED ( \ + ACPI_AML_STA_DEVICE_STATUS_PRESENT | \ + ACPI_AML_STA_DEVICE_STATUS_ENABLED | \ + ACPI_AML_STA_DEVICE_STATUS_UI | \ + ACPI_AML_STA_DEVICE_STATUS_FUNCTIONING) + +/// +/// Supported Status bits. +/// +#define ACPI_AML_STA_SUPPORTED ( \ + ACPI_AML_STA_DEVICE_STATUS_PRESENT | \ + ACPI_AML_STA_DEVICE_STATUS_ENABLED | \ + ACPI_AML_STA_DEVICE_STATUS_UI | \ + ACPI_AML_STA_DEVICE_STATUS_FUNCTIONING | \ + ACPI_AML_STA_DEVICE_STATUS_BATTERY) + /// /// _CSD Revision for ACPI 6.5 /// diff --git a/MdePkg/Include/IndustryStandard/Acpi66.h b/MdePkg/Include/IndustryStandard/Acpi66.h index 4b734b9687..49a7d369a4 100644 --- a/MdePkg/Include/IndustryStandard/Acpi66.h +++ b/MdePkg/Include/IndustryStandard/Acpi66.h @@ -21,12 +21,35 @@ /// /// _STA bit definitions ACPI 6.6 s6.3.7 /// +#define ACPI_AML_STA_DEVICE_STATUS_PRESENT 0x1 +/// @todo Remove this definition #define ACPI_AML_STA_DEVICE_STATUS_PRESET 0x1 #define ACPI_AML_STA_DEVICE_STATUS_ENABLED 0x2 #define ACPI_AML_STA_DEVICE_STATUS_UI 0x4 #define ACPI_AML_STA_DEVICE_STATUS_FUNCTIONING 0x8 #define ACPI_AML_STA_DEVICE_STATUS_BATTERY 0x10 +/// +/// Supported Status bits (base). +/// The battery bit is ignored and is reserved for +/// "Control Method Battery Device (PNP0C0A)". +/// +#define ACPI_AML_STA_BASE_SUPPORTED ( \ + ACPI_AML_STA_DEVICE_STATUS_PRESENT | \ + ACPI_AML_STA_DEVICE_STATUS_ENABLED | \ + ACPI_AML_STA_DEVICE_STATUS_UI | \ + ACPI_AML_STA_DEVICE_STATUS_FUNCTIONING) + +/// +/// Supported Status bits. +/// +#define ACPI_AML_STA_SUPPORTED ( \ + ACPI_AML_STA_DEVICE_STATUS_PRESENT | \ + ACPI_AML_STA_DEVICE_STATUS_ENABLED | \ + ACPI_AML_STA_DEVICE_STATUS_UI | \ + ACPI_AML_STA_DEVICE_STATUS_FUNCTIONING | \ + ACPI_AML_STA_DEVICE_STATUS_BATTERY) + /// /// _CSD Revision for ACPI 6.6 /// From d2936e9efa5250b60cdc3cf30b6ccfdbae403cc8 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Mon, 27 Jul 2026 15:55:07 +0200 Subject: [PATCH 348/406] DynamicTablesPkg: Add StaToken to ProcHierarch CmObj Add a new StaToken field to CM_ARCH_COMMON_PROC_HIERARCHY_INFO CmObj, allowing to describe the ASL "_STA" value the processor or processor container should return. CM_X64_LOCAL_APIC_X2APIC_INFO.StaToken already allows to reference a StaToken from a X2APIC CmObj. If ProcHierarchy objects are used, the SSDT CPU topology table will be generated using the X2APIC objects, so the new field should not collide with the new one. Add a note to CM_X64_LOCAL_APIC_X2APIC_INFO.StaToken to handle this case. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h | 5 +++++ DynamicTablesPkg/Include/X64NameSpaceObjects.h | 5 +++++ .../Common/TableHelperLib/ConfigurationManagerObjectParser.c | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h index ade806dda9..7aef112369 100644 --- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h @@ -553,6 +553,11 @@ typedef struct CmArchCommonProcHierarchyInfo { CHAR8 PartNumber[SMBIOS_MAX_STRING_SIZE]; /// SMBIOS: String stating processor socket type. CHAR8 SocketType[SMBIOS_MAX_STRING_SIZE]; + + /** Optional field: Reference Token for _STA info of this processor. + i.e. a token referencing a CM_ARCH_COMMON_STA_INFO object. + */ + CM_OBJECT_TOKEN StaToken; } CM_ARCH_COMMON_PROC_HIERARCHY_INFO; /** A structure that describes the Cache Type Structure (Type 1) in PPTT diff --git a/DynamicTablesPkg/Include/X64NameSpaceObjects.h b/DynamicTablesPkg/Include/X64NameSpaceObjects.h index fb303828cd..8aa742ae2b 100644 --- a/DynamicTablesPkg/Include/X64NameSpaceObjects.h +++ b/DynamicTablesPkg/Include/X64NameSpaceObjects.h @@ -278,6 +278,11 @@ typedef struct CmX64LocalApicX2ApicInfo { /** Optional field: Reference Token for _STA info of this processor. i.e. a token referencing a CM_ARCH_COMMON_STA_INFO object. + + Note: + This should not happen, but if CM_ARCH_COMMON_PROC_HIERARCHY_INFO + objects are used, CM_ARCH_COMMON_PROC_HIERARCHY_INFO.StaToken takes + precedence over this field. */ CM_OBJECT_TOKEN StaToken; } CM_X64_LOCAL_APIC_X2APIC_INFO; diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c index 5a9cdf58ef..012c8a8492 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c @@ -356,7 +356,8 @@ STATIC CONST CM_OBJ_PARSER CmArchCommonProcHierarchyInfoParser[] = { { "SerialNumber", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, { "AssetTag", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, { "PartNumber", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, - { "SocketType", SMBIOS_MAX_STRING_SIZE, "%a", PrintString } + { "SocketType", SMBIOS_MAX_STRING_SIZE, "%a", PrintString }, + { "StaToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL }, }; /** A parser for EArchCommonObjCacheInfo. From 475ed476ac6bbdb775acdd7c15b3dea1b98f76f8 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Mon, 27 Jul 2026 15:55:24 +0200 Subject: [PATCH 349/406] DynamicTablesPkg: Add support for _STA in SSDT topology tables Make use of the previously introduced StaToken field to generate a _STA method describing the status of a processor or processor container. staSupp Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../SsdtCpuTopologyGenerator.c | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtCpuTopologyLib/SsdtCpuTopologyGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtCpuTopologyLib/SsdtCpuTopologyGenerator.c index 311010b977..14b593586e 100644 --- a/DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtCpuTopologyLib/SsdtCpuTopologyGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtCpuTopologyLib/SsdtCpuTopologyGenerator.c @@ -45,6 +45,7 @@ Requirements: - EArchCommonObjCmRef (OPTIONAL) - EArchCommonObjLpiInfo (OPTIONAL) - EArchCommonObjPsdInfo (OPTIONAL) + - EArchCommonObjStaInfo (OPTIONAL) */ /** @@ -97,6 +98,15 @@ GET_OBJECT_LIST ( CM_ARCH_COMMON_PSD_INFO ); +/** This macro expands to a function that retrieves the + _STA (Device Status) information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArchCommon, + EArchCommonObjStaInfo, + CM_ARCH_COMMON_STA_INFO + ); + /** Initialize the TokenTable. One entry should be allocated for each CM_ARCH_COMMON_PROC_HIERARCHY_INFO @@ -696,6 +706,68 @@ CreateAmlCpu ( return Status; } +/** Create a "_STA" method and attach it to the parent node. + + The function generate the following ASL code: + Method (_STA, 0, NotSerialized) // _STA: Status + { + Return (0xXX) + } + + @param [in] Generator The SSDT Cpu Topology generator. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in] StaToken Token referencing a CM_ARCH_COMMON_STA_INFO obj. + @param [in] ParentNode Parent node to attach the "_STA" method to. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +CreateAmlStatus ( + IN ACPI_CPU_TOPOLOGY_GENERATOR *Generator, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN CM_OBJECT_TOKEN StaToken, + IN AML_NODE_HANDLE ParentNode + ) +{ + EFI_STATUS Status; + CM_ARCH_COMMON_STA_INFO *StaInfo; + + ASSERT (Generator != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (ParentNode != NULL); + ASSERT (StaToken != CM_NULL_TOKEN); + + Status = GetEArchCommonObjStaInfo ( + CfgMgrProtocol, + StaToken, + &StaInfo, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + /// check STA bits + if ((StaInfo->DeviceStatus & ~(ACPI_AML_STA_BASE_SUPPORTED)) != 0) { + ASSERT (FALSE); + return EFI_UNSUPPORTED; + } + + Status = AmlCodeGenMethodRetInteger ("_STA", StaInfo->DeviceStatus, 0, FALSE, 0, ParentNode, NULL); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + return Status; +} + /** Create a Cpu in the AML namespace from a CM_ARCH_COMMON_PROC_HIERARCHY_INFO CM object. @@ -793,6 +865,19 @@ CreateAmlCpuFromProcHierarchy ( return Status; } + if (ProcHierarchyNodeInfo->StaToken != CM_NULL_TOKEN) { + Status = CreateAmlStatus ( + Generator, + CfgMgrProtocol, + ProcHierarchyNodeInfo->StaToken, + CpuNode + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + } + return Status; } @@ -900,6 +985,19 @@ CreateAmlProcessorContainer ( } } + if (ProcHierarchyNodeInfo->StaToken != CM_NULL_TOKEN) { + Status = CreateAmlStatus ( + Generator, + CfgMgrProtocol, + ProcHierarchyNodeInfo->StaToken, + ProcContainerNode + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + } + *ProcContainerNodePtr = ProcContainerNode; return Status; From 21063e6b231962ae85ae80bf963b3432333c0201 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Mon, 27 Jul 2026 16:00:16 +0200 Subject: [PATCH 350/406] DynamicTablesPkg: Remove ACPI_AML_STA_PROC_SUPPORTED Remove the ACPI_AML_STA_PROC_SUPPORTED macro to make use of the new MdePkg macro: ACPI_AML_STA_BASE_SUPPORTED. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../X64/X64SsdtCpuTopologyGenerator.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtCpuTopologyLib/X64/X64SsdtCpuTopologyGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtCpuTopologyLib/X64/X64SsdtCpuTopologyGenerator.c index 48dc76e584..5ba1b1c83e 100644 --- a/DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtCpuTopologyLib/X64/X64SsdtCpuTopologyGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiSsdtCpuTopologyLib/X64/X64SsdtCpuTopologyGenerator.c @@ -25,19 +25,6 @@ #include "SsdtCpuTopologyGenerator.h" -/** This macro defines the supported ACPI Processor Status bits. - The following bits are supported: - - ACPI_AML_STA_DEVICE_STATUS_PRESET - - ACPI_AML_STA_DEVICE_STATUS_ENABLED - - ACPI_AML_STA_DEVICE_STATUS_UI - - ACPI_AML_STA_DEVICE_STATUS_FUNCTIONING -*/ -#define ACPI_AML_STA_PROC_SUPPORTED ( \ - ACPI_AML_STA_DEVICE_STATUS_PRESET | \ - ACPI_AML_STA_DEVICE_STATUS_ENABLED | \ - ACPI_AML_STA_DEVICE_STATUS_UI | \ - ACPI_AML_STA_DEVICE_STATUS_FUNCTIONING) - /** This macro expands to a function that retrieves the Local APIC or X2APIC information from the Configuration Manager. */ @@ -854,7 +841,7 @@ CreateTopologyFromIntC ( } /// check STA bits - if ((StaInfo->DeviceStatus & ~(ACPI_AML_STA_PROC_SUPPORTED)) != 0) { + if ((StaInfo->DeviceStatus & ~(ACPI_AML_STA_BASE_SUPPORTED)) != 0) { DEBUG (( DEBUG_ERROR, "Unsupported STA bits set for processor %d\n", From bc71cc972d5ea3cb38d4c454a68b02138b23c774 Mon Sep 17 00:00:00 2001 From: Theo <theo.tao@foxmail.com> Date: Thu, 8 Jan 2026 20:26:39 +0800 Subject: [PATCH 351/406] MdeModulePkg/NvmExpressHci.c: Save time when BIOS reset with NVMes Dispatch Shutdown Notification to every NVMe first, then polling every NVMe t omaake sure all NVMe's shutdown processing is completed.This will help to save a lot time when BIOS trigger reset for Servers whose have many NVMes. Tested on a platform with AMD EPYC cpu with 26 NVMes, this method reduce reset time from 3 minutes to 10 seconds. Signed-off-by: Theo <theo.tao@foxmail.com> --- .../Bus/Pci/NvmExpressDxe/NvmExpressHci.c | 148 +++++++++++------- 1 file changed, 93 insertions(+), 55 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c index e1b0ee6051..affe7b89f2 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c @@ -973,24 +973,26 @@ NvmeShutdownAllControllers ( UINTN Index; NVME_CONTROLLER_PRIVATE_DATA *Private; - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiPciIoProtocolGuid, - NULL, - &HandleCount, - &Handles - ); + Handles = NULL; + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciIoProtocolGuid, + NULL, + &HandleCount, + &Handles + ); if (EFI_ERROR (Status)) { HandleCount = 0; } for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { - Status = gBS->OpenProtocolInformation ( - Handles[HandleIndex], - &gEfiPciIoProtocolGuid, - &OpenInfos, - &OpenInfoCount - ); + OpenInfos = NULL; + Status = gBS->OpenProtocolInformation ( + Handles[HandleIndex], + &gEfiPciIoProtocolGuid, + &OpenInfos, + &OpenInfoCount + ); if (EFI_ERROR (Status)) { continue; } @@ -1011,53 +1013,89 @@ NvmeShutdownAllControllers ( NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); - if (EFI_ERROR (Status)) { - continue; - } + if (!EFI_ERROR (Status)) { + Private = NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (NvmePassThru); - Private = NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (NvmePassThru); - - // - // Read Controller Configuration Register. - // - Status = ReadNvmeControllerConfiguration (Private, &Cc); - if (EFI_ERROR (Status)) { - continue; - } - - // - // The host should set the Shutdown Notification (CC.SHN) field to 01b - // to indicate a normal shutdown operation. - // - Cc.Shn = NVME_CC_SHN_NORMAL_SHUTDOWN; - Status = WriteNvmeControllerConfiguration (Private, &Cc); - if (EFI_ERROR (Status)) { - continue; - } - - // - // The controller indicates when shutdown processing is completed by updating the - // Shutdown Status (CSTS.SHST) field to 10b. - // Wait up to 45 seconds (break down to 4500 x 10ms) for the shutdown to complete. - // - for (Index = 0; Index < NVME_SHUTDOWN_PROCESS_TIMEOUT * 100; Index++) { - Status = ReadNvmeControllerStatus (Private, &Csts); - if (!EFI_ERROR (Status) && (Csts.Shst == NVME_CSTS_SHST_SHUTDOWN_COMPLETED)) { - DEBUG ((DEBUG_INFO, "NvmeShutdownController: shutdown processing is completed after %dms.\n", Index * 10)); - break; + // + // Read Controller Configuration Register. + // + Status = ReadNvmeControllerConfiguration (Private, &Cc); + if (!EFI_ERROR (Status)) { + // + // The host should set the Shutdown Notification (CC.SHN) field to 01b + // to indicate a normal shutdown operation. + // + Cc.Shn = NVME_CC_SHN_NORMAL_SHUTDOWN; + WriteNvmeControllerConfiguration (Private, &Cc); } - - // - // Stall for 10ms - // - gBS->Stall (10 * 1000); - } - - if (Index == NVME_SHUTDOWN_PROCESS_TIMEOUT * 100) { - DEBUG ((DEBUG_ERROR, "NvmeShutdownController: shutdown processing is timed out\n")); } } } + + if (OpenInfos != NULL) { + gBS->FreePool (OpenInfos); + } + } + + // Another cycle to polling every disk to check the shutdown status, can save time + for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { + OpenInfos = NULL; + Status = gBS->OpenProtocolInformation ( + Handles[HandleIndex], + &gEfiPciIoProtocolGuid, + &OpenInfos, + &OpenInfoCount + ); + if (EFI_ERROR (Status)) { + continue; + } + + for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) { + if (((OpenInfos[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) && + (OpenInfos[OpenInfoIndex].AgentHandle == gImageHandle)) + { + Status = gBS->OpenProtocol ( + OpenInfos[OpenInfoIndex].ControllerHandle, + &gEfiNvmExpressPassThruProtocolGuid, + (VOID **)&NvmePassThru, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + Private = NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (NvmePassThru); + // + // The controller indicates when shutdown processing is completed by updating the + // Shutdown Status (CSTS.SHST) field to 10b. + // Wait up to 45 seconds (break down to 4500 x 10ms) for the shutdown to complete. + // + for (Index = 0; Index < NVME_SHUTDOWN_PROCESS_TIMEOUT * 100; Index++) { + Status = ReadNvmeControllerStatus (Private, &Csts); + if (!EFI_ERROR (Status) && (Csts.Shst == NVME_CSTS_SHST_SHUTDOWN_COMPLETED)) { + DEBUG ((DEBUG_INFO, "NvmeShutdownController: disk %d shutdown processing is completed after %dms.\n", OpenInfoIndex, Index * 10)); + break; + } + + // + // Stall for 10ms + // + gBS->Stall (10 * 1000); + } + + if (Index == NVME_SHUTDOWN_PROCESS_TIMEOUT * 100) { + DEBUG ((DEBUG_ERROR, "NvmeShutdownController: disk %d shutdown processing is timed out\n", OpenInfoIndex)); + } + } + } + } + + if (OpenInfos != NULL) { + gBS->FreePool (OpenInfos); + } + } + + if (Handles != NULL) { + gBS->FreePool (Handles); } } From 3f97b8bc7fd8eb8ab3af439bf521a7a73c0542b4 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann <kraxel@redhat.com> Date: Thu, 7 May 2026 08:35:00 +0200 Subject: [PATCH 352/406] MdeModulePkg/SmbiosDxe: fix table length check In case EntryPointStructure does not exist yet use a length of zero instead of skipping the check altogether. Fixes a heap overflow in the following code flow in case the first smbios table installed is larger than SMBIOS_TABLE_MAX_LENGTH. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c index 2ef7b8e21c..0841d1066a 100644 --- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c +++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c @@ -424,8 +424,8 @@ SmbiosAdd ( // in the Structure Table Length field of the SMBIOS Structure Table Entry Point, // which is a WORD field limited to 65,535 bytes. So the max size of 32-bit table should not exceed 65,535 bytes. // - if ((EntryPointStructure != NULL) && - (EntryPointStructure->TableLength + StructureSize > SMBIOS_TABLE_MAX_LENGTH)) + if (((EntryPointStructure != NULL) ? EntryPointStructure->TableLength : 0) + + StructureSize > SMBIOS_TABLE_MAX_LENGTH) { DEBUG ((DEBUG_INFO, "SmbiosAdd: Total length exceeds max 32-bit table length with type = %d size = 0x%x\n", Record->Type, StructureSize)); } else { From d91dff7cbeefe2841ba6fe88fd468d2d9120ecf6 Mon Sep 17 00:00:00 2001 From: Michael D Kinney <michael.d.kinney@intel.com> Date: Mon, 1 Jun 2026 21:47:02 -0700 Subject: [PATCH 353/406] UefiCpuPkg/CpuDxe: Read hardware interrupt state in GetInterruptState Fix CpuGetInterruptState() to read the actual hardware interrupt flag (RFLAGS.IF) via BaseLib's GetInterruptState() instead of returning a cached boolean variable. The cached variable becomes stale in interrupt context where hardware disables interrupts without going through the protocol's DisableInterrupt() call. This is a PI Spec conformance fix: EFI_CPU_ARCH_PROTOCOL.GetInterruptState() is specified to return the current processor interrupt state. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> --- UefiCpuPkg/CpuDxe/CpuDxe.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c index 798a8eb1b3..a7a1996d7f 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.c +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c @@ -13,8 +13,7 @@ // // Global Variables // -BOOLEAN InterruptState = FALSE; -EFI_HANDLE mCpuHandle = NULL; +EFI_HANDLE mCpuHandle = NULL; BOOLEAN mIsFlushingGCD; BOOLEAN mIsAllocatingPageTable = FALSE; UINT64 mTimerPeriod = 0; @@ -88,7 +87,6 @@ CpuEnableInterrupt ( { EnableInterrupts (); - InterruptState = TRUE; return EFI_SUCCESS; } @@ -109,7 +107,6 @@ CpuDisableInterrupt ( { DisableInterrupts (); - InterruptState = FALSE; return EFI_SUCCESS; } @@ -134,7 +131,7 @@ CpuGetInterruptState ( return EFI_INVALID_PARAMETER; } - *State = InterruptState; + *State = GetInterruptState (); return EFI_SUCCESS; } From 3120fb4b698dae91edff1080c839f4254a40fde4 Mon Sep 17 00:00:00 2001 From: Michael D Kinney <michael.d.kinney@intel.com> Date: Mon, 1 Jun 2026 21:47:09 -0700 Subject: [PATCH 354/406] UefiCpuPkg/CpuDxeRiscV64: Read hardware state in GetInterruptState Fix CpuGetInterruptState() to read the actual hardware interrupt flag (sstatus.SIE) via BaseLib's GetInterruptState() instead of returning a cached boolean variable. The cached variable becomes stale in interrupt context where hardware disables interrupts without going through the protocol's DisableInterrupt() call. This is a PI Spec conformance fix: EFI_CPU_ARCH_PROTOCOL.GetInterruptState() is specified to return the current processor interrupt state. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> --- UefiCpuPkg/CpuDxeRiscV64/CpuDxe.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/CpuDxeRiscV64/CpuDxe.c b/UefiCpuPkg/CpuDxeRiscV64/CpuDxe.c index 6bbcdaca36..8270548060 100644 --- a/UefiCpuPkg/CpuDxeRiscV64/CpuDxe.c +++ b/UefiCpuPkg/CpuDxeRiscV64/CpuDxe.c @@ -13,8 +13,7 @@ // // Global Variables // -STATIC BOOLEAN mInterruptState = FALSE; -STATIC EFI_HANDLE mCpuHandle = NULL; +STATIC EFI_HANDLE mCpuHandle = NULL; STATIC UINTN mBootHartId; RISCV_EFI_BOOT_PROTOCOL gRiscvBootProtocol; @@ -123,7 +122,6 @@ CpuEnableInterrupt ( ) { EnableInterrupts (); - mInterruptState = TRUE; return EFI_SUCCESS; } @@ -143,7 +141,6 @@ CpuDisableInterrupt ( ) { DisableInterrupts (); - mInterruptState = FALSE; return EFI_SUCCESS; } @@ -168,7 +165,7 @@ CpuGetInterruptState ( return EFI_INVALID_PARAMETER; } - *State = mInterruptState; + *State = GetInterruptState (); return EFI_SUCCESS; } From 46591c981f18d63c32394f3bc8d735c622c56c72 Mon Sep 17 00:00:00 2001 From: Nick Owens <mischief@offblast.org> Date: Wed, 29 Jul 2026 05:28:53 -0700 Subject: [PATCH 355/406] OvmfPkg/RiscVVirt: Add Hash2DxeCrypto for TcpDxe TcpDxe depends on gEfiHash2ServiceBindingProtocolGuid, which nothing on the platform produces, so it is built into the FV but never dispatched. Add Hash2DxeCrypto, as ArmVirtQemu does. The rest of NetworkPkg depends on gEfiRngProtocolGuid, produced by VirtioRngDxe when the VM is given a virtio-rng device. Signed-off-by: Nick Owens <mischief@offblast.org> --- OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc | 5 +++++ OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc index 09dd86f1a7..acbf161f04 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc @@ -456,6 +456,11 @@ OvmfPkg/VirtioNetDxe/VirtioNet.inf OvmfPkg/VirtioRngDxe/VirtioRng.inf + # + # Hash2 protocol, needed to dispatch TcpDxe + # + SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf + # # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs # diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf index 734b5887d1..cbba3d8520 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf +++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf @@ -154,6 +154,11 @@ INF OvmfPkg/VirtioNetDxe/VirtioNet.inf INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf INF OvmfPkg/VirtioRngDxe/VirtioRng.inf +# +# Hash2 protocol, needed to dispatch TcpDxe +# +INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf + !include OvmfPkg/Include/Fdf/ShellDxe.fdf.inc # From 6c4a9a7659bb918c443e5aaf927c4bc178053eb1 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann <kraxel@redhat.com> Date: Thu, 30 Jul 2026 10:44:31 +0200 Subject: [PATCH 356/406] OvmfPkg/EmuVariableFvbRuntimeDxe: fix ValidateFvHeader in tdx mode In TDX mode MmioRead* functions can not access memory, so avoid that. See added source code comments for details. Fixes: 0917ddad2529 ("OvmfPkg/EmuVariableFvbRuntimeDxe: avoid accessing varstore header with cmp") Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c | 41 +++++++++++++++++++++--- OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf | 1 + 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c index 66e3929ec8..b674ae67a3 100644 --- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c +++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c @@ -8,6 +8,9 @@ **/ #include "PiDxe.h" + +#include <ConfidentialComputingGuestAttr.h> + #include <Guid/EventGroup.h> #include <Guid/SystemNvDataGuid.h> #include <Guid/VariableFormat.h> @@ -567,16 +570,46 @@ ValidateFvHeader ( ) { UINT16 Checksum; + UINT8 Revision; + UINT32 Signature; + UINT64 FvLength; + UINT16 HeaderLength; + + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + /* + * When in tdx mode the varstore must be in ram not pflash, so there are no + * mmio reads/writes needed. Also in tdx mode BaseIoLibIntrinsic will + * translate the mmio access into TDVMCALL_MMIO calls instead of mov + * instructions, so memory access with MmioRead* functions does not work. + */ + Revision = FwVolHeader->Revision; + Signature = FwVolHeader->Signature; + FvLength = FwVolHeader->FvLength; + HeaderLength = FwVolHeader->HeaderLength; + } else { + /* + * In sev mode with varstore in pflash we must use MmioRead* functions so to + * make sure the mov instruction used to access pflash/memory is supported + * by the #VC handler instruction emulator. + * + * Note: Only sev + sev-es need proper pflash handling, sev-snp is like tdx + * incompatible with pflash emulation. + */ + Revision = MmioRead8 ((UINTN)(&FwVolHeader->Revision)); + Signature = MmioRead32 ((UINTN)(&FwVolHeader->Signature)); + FvLength = MmioRead64 ((UINTN)(&FwVolHeader->FvLength)); + HeaderLength = MmioRead16 ((UINTN)(&FwVolHeader->HeaderLength)); + } // // Verify the header revision, header signature, length // Length of FvBlock cannot be 2**64-1 // HeaderLength cannot be an odd number // - if ((MmioRead8 ((UINTN)(&FwVolHeader->Revision)) != EFI_FVH_REVISION) || - (MmioRead32 ((UINTN)(&FwVolHeader->Signature)) != EFI_FVH_SIGNATURE) || - (MmioRead64 ((UINTN)(&FwVolHeader->FvLength)) != EMU_FVB_SIZE) || - (MmioRead16 ((UINTN)(&FwVolHeader->HeaderLength)) != EMU_FV_HEADER_LENGTH) + if ((Revision != EFI_FVH_REVISION) || + (Signature != EFI_FVH_SIGNATURE) || + (FvLength != EMU_FVB_SIZE) || + (HeaderLength != EMU_FV_HEADER_LENGTH) ) { DEBUG ((DEBUG_INFO, "EMU Variable FVB: Basic FV headers were invalid\n")); diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf index 396e6028b4..da1da9e0bd 100644 --- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf +++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf @@ -63,6 +63,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved + gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr [Depex] TRUE From d45f882a1bf077f7e8e828fc9dfb14f3187142c1 Mon Sep 17 00:00:00 2001 From: Phil Noh <Phil.Noh@amd.com> Date: Tue, 21 Jul 2026 15:02:20 -0500 Subject: [PATCH 357/406] BaseTools: Fix Clang -Wtautological-overlap-compare in PcdValueInit.c For each structured-PCD field copied via memcpy, DscBuildData.py emits the clamp expression, '(FieldSize > 0 && FieldSize < ValueSize) ? FieldSize : ValueSize'. When ValueSize == 1 and FieldSize is unsigned, it reduces to (FieldSize > 0 && FieldSize < 1) - always-false comparison. Clang flags it under -Wtautological-overlap-compare, and because PcdValueInit builds with -Werror, autogen fails and the build aborts with 'PcdValueInit.c: error: overlapping comparisons always evaluate to false [-Werror,-Wtautological-overlap-compare]'. This is specific to Clang host. To fix it, this update changes '<' to '<=' at all five generator sites in DscBuildData.py (GenerateDefaultValueAssignFunction, GenerateInitValueFunction, GenerateCommandLineValue, GenerateModuleScopeValue, GenerateFdfValue). Behavior is unchanged: both branches copy the same byte count when FieldSize == ValueSize. GCC and MSVC builds are unaffected. Signed-off-by: Phil Noh <Phil.Noh@amd.com> --- BaseTools/Source/Python/Workspace/DscBuildData.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index 014f6d0805..bb9ba046ec 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -3,7 +3,7 @@ # # Copyright (c) 2008 - 2025, Intel Corporation. All rights reserved.<BR> # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR> -# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (C) 2025 - 2026 Advanced Micro Devices, Inc. All rights reserved. # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -2116,7 +2116,7 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName) CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + ' __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) - CApp = CApp + ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize) + CApp = CApp + ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize <= %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize) elif isinstance(Value, str): CApp = CApp + ' %s = %s; // From %s Line %d Value %s\n' % (indicator, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) else: @@ -2281,7 +2281,7 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName) CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + ' __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) - CApp = CApp + ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize) + CApp = CApp + ' memcpy (&%s, Value, (FieldSize > 0 && FieldSize <= %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize) else: if '[' in FieldName and ']' in FieldName: Index = int(FieldName.split('[')[1].split(']')[0]) @@ -2350,7 +2350,7 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName) CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + ' __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) - CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize) + CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize <= %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize) else: if '[' in FieldName and ']' in FieldName: Index = int(FieldName.split('[')[1].split(']')[0]) @@ -2419,7 +2419,7 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName) CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + ' __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) - CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize) + CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize <= %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize) else: if '[' in FieldName and ']' in FieldName: Index = int(FieldName.split('[')[1].split(']')[0]) @@ -2487,7 +2487,7 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName) CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + ' __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) - CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize) + CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize <= %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize) else: if '[' in FieldName and ']' in FieldName: Index = int(FieldName.split('[')[1].split(']')[0]) From 4bd628ce9844c04623ade7b875efaa19a6b57b35 Mon Sep 17 00:00:00 2001 From: Mikey Strauss <mdstrauss91@gmail.com> Date: Fri, 31 Jul 2026 16:29:59 +0300 Subject: [PATCH 358/406] SecurityPkg/DeviceSecurity: Update libspdm submodule to 3.8.2 The libspdm submodule was pinned at 3.7.0 (2025-04-03), three releases behind upstream 3.8.2 (2026-04-03). libspdm processes untrusted responder (device) data in the SPDM device attestation path, so tracking upstream keeps that parsing current with fixes and hardening. Two responder-side advisories were resolved between 3.7.0 and 3.8.2: - GHSA-j54w-759w-xj3m: out-of-bounds write in GET_CSR handling. - GHSA-m4wc-xmvg-369f: integer overflow / out-of-bounds read in GET_MEASUREMENT_EXTENSION_LOG handling. Both are responder-side. edk2 links SpdmRequesterLib (it acts as the SPDM Requester that verifies an untrusted device Responder), so these responder handlers are not built into edk2 images; this update is defense-in-depth rather than a fix for a path reachable in edk2 today. The libspdm sources referenced by the SpdmLib INFs are unchanged in 3.8.2 (the only additions are the optional ENDPOINT_INFO capability sources, which edk2 does not enable), so no INF change is required. Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Chris Fernald <chfernal@microsoft.com> Signed-off-by: Mikey Strauss <mdstrauss91@gmail.com> --- SecurityPkg/DeviceSecurity/SpdmLib/libspdm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SecurityPkg/DeviceSecurity/SpdmLib/libspdm b/SecurityPkg/DeviceSecurity/SpdmLib/libspdm index 1be116c7b7..f55cf6d48e 160000 --- a/SecurityPkg/DeviceSecurity/SpdmLib/libspdm +++ b/SecurityPkg/DeviceSecurity/SpdmLib/libspdm @@ -1 +1 @@ -Subproject commit 1be116c7b7713fa9003e1bd53b53a34758549eb9 +Subproject commit f55cf6d48ec69b4ac60a63903e9c6a2cb0fd155d From 0af5cb9cd046ec1b7016531f059874496faacc52 Mon Sep 17 00:00:00 2001 From: Herve ELTER <rvnvv74@gmail.com> Date: Thu, 20 Apr 2023 15:18:30 +0200 Subject: [PATCH 359/406] SecurityPkg/Tcg: Use TPM names in setup strings Use TPM 1.2 and TPM 2.0 in setup titles instead of the implementation-facing TCG and TCG2 names. Signed-off-by: Herve ELTER <rvnvv74@gmail.com> Signed-off-by: Matt DeVillier <matt.devillier@gmail.com> Signed-off-by: Sean Rhodes <sean@starlabs.systems> --- SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigStrings.uni | 4 ++-- SecurityPkg/Tcg/TcgConfigDxe/TcgConfigStrings.uni | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigStrings.uni b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigStrings.uni index dada07558f..a64067173e 100644 --- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigStrings.uni +++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigStrings.uni @@ -8,8 +8,8 @@ #langdef en-US "English" -#string STR_TCG2_TITLE #language en-US "TCG2 Configuration" -#string STR_TCG2_HELP #language en-US "Press <Enter> to select TCG2 Setup options." +#string STR_TCG2_TITLE #language en-US "TPM 2.0 Configuration" +#string STR_TCG2_HELP #language en-US "Press <Enter> to select TPM Setup options." #string STR_TCG2_DEVICE_STATE_PROMPT #language en-US "Current TPM Device" #string STR_TCG2_DEVICE_STATE_HELP #language en-US "Current TPM Device: Disable, TPM1.2, or TPM2.0" diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigStrings.uni b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigStrings.uni index 4bc348511d..0d01bced92 100644 --- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigStrings.uni +++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigStrings.uni @@ -8,8 +8,8 @@ #langdef en-US "English" -#string STR_TPM_TITLE #language en-US "TCG Configuration" -#string STR_TPM_HELP #language en-US "Press <Enter> to select TCG Setup options." +#string STR_TPM_TITLE #language en-US "TPM 1.2 Configuration" +#string STR_TPM_HELP #language en-US "Press <Enter> to select TPM Setup options." #string STR_TPM_STATE_PROMPT #language en-US "Current TPM State" #string STR_TPM_STATE_HELP #language en-US "Current TPM device state: enabled or disabled; activated or deactivated." #string STR_TPM_STATE_CONTENT #language en-US "" From ae8814ff6b3ae367ac2f059fad99eac9da884406 Mon Sep 17 00:00:00 2001 From: Qihang Gao <gaoqihang@loongson.cn> Date: Mon, 3 Aug 2026 17:46:45 +0800 Subject: [PATCH 360/406] OvmfPkg/LoongArchVirt: Add Hash2DxeCrypto to satisfy TcpDxe dependency The TcpDxe driver requires the Hash2 protocol to be available for its dispatch. On the LoongArchVirt QEMU platform, this protocol was not previously included, leading to failures when the network stack attempted to initialize. Add SecurityPkg/Hash2DxeCrypto to both the DSC and FDF files, ensuring that the Hash2 protocol is installed and can be consumed by TcpDxe. Signed-off-by: Qihang Gao <gaoqihang@loongson.cn> --- OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc | 5 +++++ OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc index aa8c10493b..bc930b2465 100644 --- a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc +++ b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc @@ -649,6 +649,11 @@ OvmfPkg/VirtioScsiDxe/VirtioScsi.inf OvmfPkg/VirtioRngDxe/VirtioRng.inf + # + # Hash2 protocol, needed to dispatch TcpDxe + # + SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf + # # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs # diff --git a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf index f11cb8e553..bd1d75a48a 100644 --- a/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf +++ b/OvmfPkg/LoongArchVirt/LoongArchVirtQemu.fdf @@ -117,6 +117,11 @@ INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf INF OvmfPkg/VirtioRngDxe/VirtioRng.inf INF OvmfPkg/VirtioNetDxe/VirtioNet.inf +# +# Hash2 protocol, needed to dispatch TcpDxe +# +INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf + # # Console # From f7052e2d029acbeda830dbf9a060eb4cda2ed47b Mon Sep 17 00:00:00 2001 From: rdiaz <raymonddiaz@microsoft.com> Date: Tue, 27 Jan 2026 22:04:42 +0000 Subject: [PATCH 361/406] SecurityPkg: Remove global use pre-memory Updated Tpm2DeviceLibFfa to no longer use globals. Updated the SEC version of Tpm2DeviceLibFfaBase to no longer use globals when including TPM libraries in the SEC phase. Includes various cleanup regarding the updated files. Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com> --- .../Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c | 17 +--- .../Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf | 2 +- .../Tpm2DeviceSecLibFfaBase.c | 48 ++++++++++ .../Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c | 92 +++++++------------ 4 files changed, 85 insertions(+), 74 deletions(-) create mode 100644 SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfaBase.c diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c index 058d131178..d5d83eca32 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c @@ -10,15 +10,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include <IndustryStandard/ArmFfaSvc.h> #include <Library/BaseLib.h> -#include <Library/BaseMemoryLib.h> -#include <Library/DebugLib.h> #include <Library/Tpm2DeviceLib.h> -#include <IndustryStandard/ArmStdSmc.h> -#include <IndustryStandard/Tpm20.h> -#include <Library/TimerLib.h> - #include "Tpm2DeviceLibFfa.h" UINT8 mCRBIdleByPass; @@ -54,19 +47,15 @@ InternalTpm2DeviceLibFfaConstructor ( mCRBIdleByPass = 0xFF; if (PcdGet64 (PcdTpmBaseAddress) == 0) { - Status = EFI_NO_MAPPING; - goto Exit; + return EFI_NO_MAPPING; } Status = ValidateTpmInterfaceType (); if (EFI_ERROR (Status)) { - goto Exit; + return Status; } mCRBIdleByPass = Tpm2GetIdleByPass ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress)); - Status = EFI_SUCCESS; - -Exit: - return Status; + return EFI_SUCCESS; } diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf index 2f4ae52619..97bb47be85 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf @@ -26,7 +26,7 @@ [Sources.common] Tpm2DeviceLibFfa.c Tpm2ServiceFfaRaw.c - Tpm2DeviceLibFfaBase.c + Tpm2DeviceSecLibFfaBase.c Tpm2Ptp.c Tpm2DeviceLibFfa.h Tpm2InfoSecFfa.c diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfaBase.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfaBase.c new file mode 100644 index 0000000000..3e61daa677 --- /dev/null +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfaBase.c @@ -0,0 +1,48 @@ +/** @file + This library provides an implementation of Tpm2DeviceLib + using ARM64 SMC calls to request TPM service. + + The implementation is only supporting the Command Response Buffer (CRB) + for sharing data with the TPM. + + Copyright (c), Microsoft Corporation. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Library/BaseLib.h> +#include <Library/Tpm2DeviceLib.h> +#include "Tpm2DeviceLibFfa.h" + +/** + Return cached PTP CRB interface IdleByPass state. + + @return Cached PTP CRB interface IdleByPass state. +**/ +UINT8 +GetCachedIdleByPass ( + VOID + ) +{ + return Tpm2GetIdleByPass ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress)); +} + +/** + Check that we have an address for the CRB + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval EFI_NO_MAPPING The TPM base address is not set up. + @retval EFI_UNSUPPORTED The TPM interface type is not supported. +**/ +EFI_STATUS +EFIAPI +InternalTpm2DeviceLibFfaConstructor ( + VOID + ) +{ + if (PcdGet64 (PcdTpmBaseAddress) == 0) { + return EFI_NO_MAPPING; + } + + return ValidateTpmInterfaceType (); +} diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c index 2314d1f22a..10a6cbcc0a 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c @@ -26,18 +26,16 @@ #include "Tpm2DeviceLibFfa.h" -UINT16 mFfaTpm2PartitionId = TPM2_FFA_PARTITION_ID_INVALID; - /** Check the return status from the FF-A call and returns EFI_STATUS - @param EFI_LOAD_ERROR FF-A status code returned in x0 + @param TpmReturnStatus FF-A status code returned in x0 @retval EFI_SUCCESS The entry point is executed successfully. **/ EFI_STATUS TranslateTpmReturnStatus ( - UINTN TpmReturnStatus + IN UINTN TpmReturnStatus ) { EFI_STATUS Status; @@ -142,27 +140,25 @@ Tpm2GetInterfaceVersion ( { EFI_STATUS Status; DIRECT_MSG_ARGS FfaDirectReq2Args; + UINT16 FfaTpm2PartitionId; if (Version == NULL) { - Status = EFI_INVALID_PARAMETER; - goto Exit; + return EFI_INVALID_PARAMETER; } - if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) { - GetTpmServicePartitionId (&mFfaTpm2PartitionId); - } + GetTpmServicePartitionId (&FfaTpm2PartitionId); ZeroMem (&FfaDirectReq2Args, sizeof (DIRECT_MSG_ARGS)); FfaDirectReq2Args.Arg0 = TPM2_FFA_GET_INTERFACE_VERSION; - Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); + Status = ArmFfaLibMsgSendDirectReq2 (FfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { - goto Exit; + return Status; } Status = TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); @@ -171,7 +167,6 @@ Tpm2GetInterfaceVersion ( *Version = FfaDirectReq2Args.Arg1; } -Exit: return Status; } @@ -193,34 +188,29 @@ Tpm2GetFeatureInfo ( { EFI_STATUS Status; DIRECT_MSG_ARGS FfaDirectReq2Args; + UINT16 FfaTpm2PartitionId; if (FeatureInfo == NULL) { - Status = EFI_INVALID_PARAMETER; - goto Exit; + return EFI_INVALID_PARAMETER; } - if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) { - GetTpmServicePartitionId (&mFfaTpm2PartitionId); - } + GetTpmServicePartitionId (&FfaTpm2PartitionId); ZeroMem (&FfaDirectReq2Args, sizeof (DIRECT_MSG_ARGS)); FfaDirectReq2Args.Arg0 = TPM2_FFA_GET_FEATURE_INFO; FfaDirectReq2Args.Arg1 = TPM_SERVICE_FEATURE_SUPPORT_NOTIFICATION; - Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); + Status = ArmFfaLibMsgSendDirectReq2 (FfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { - goto Exit; + return Status; } - Status = TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); - -Exit: - return Status; + return TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); } /** @@ -241,30 +231,26 @@ Tpm2ServiceStart ( { EFI_STATUS Status; DIRECT_MSG_ARGS FfaDirectReq2Args; + UINT16 FfaTpm2PartitionId; - if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) { - GetTpmServicePartitionId (&mFfaTpm2PartitionId); - } + GetTpmServicePartitionId (&FfaTpm2PartitionId); ZeroMem (&FfaDirectReq2Args, sizeof (DIRECT_MSG_ARGS)); FfaDirectReq2Args.Arg0 = TPM2_FFA_START; FfaDirectReq2Args.Arg1 = (FuncQualifier & 0xFF); FfaDirectReq2Args.Arg2 = (LocalityQualifier & 0xFF); - Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); + Status = ArmFfaLibMsgSendDirectReq2 (FfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { - goto Exit; + return Status; } - Status = TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); - -Exit: - return Status; + return TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); } /** @@ -286,30 +272,26 @@ Tpm2RegisterNotification ( { EFI_STATUS Status; DIRECT_MSG_ARGS FfaDirectReq2Args; + UINT16 FfaTpm2PartitionId; - if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) { - GetTpmServicePartitionId (&mFfaTpm2PartitionId); - } + GetTpmServicePartitionId (&FfaTpm2PartitionId); ZeroMem (&FfaDirectReq2Args, sizeof (DIRECT_MSG_ARGS)); FfaDirectReq2Args.Arg0 = TPM2_FFA_REGISTER_FOR_NOTIFICATION; FfaDirectReq2Args.Arg1 = (NotificationTypeQualifier << 16 | vCpuId); FfaDirectReq2Args.Arg2 = (NotificationId & 0xFF); - Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); + Status = ArmFfaLibMsgSendDirectReq2 (FfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { - goto Exit; + return Status; } - Status = TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); - -Exit: - return Status; + return TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); } /** @@ -325,28 +307,24 @@ Tpm2UnregisterNotification ( { EFI_STATUS Status; DIRECT_MSG_ARGS FfaDirectReq2Args; + UINT16 FfaTpm2PartitionId; - if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) { - GetTpmServicePartitionId (&mFfaTpm2PartitionId); - } + GetTpmServicePartitionId (&FfaTpm2PartitionId); ZeroMem (&FfaDirectReq2Args, sizeof (DIRECT_MSG_ARGS)); FfaDirectReq2Args.Arg0 = TPM2_FFA_UNREGISTER_FROM_NOTIFICATION; - Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); + Status = ArmFfaLibMsgSendDirectReq2 (FfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { - goto Exit; + return Status; } - Status = TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); - -Exit: - return Status; + return TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); } /** @@ -362,26 +340,22 @@ Tpm2FinishNotified ( { EFI_STATUS Status; DIRECT_MSG_ARGS FfaDirectReq2Args; + UINT16 FfaTpm2PartitionId; - if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) { - GetTpmServicePartitionId (&mFfaTpm2PartitionId); - } + GetTpmServicePartitionId (&FfaTpm2PartitionId); ZeroMem (&FfaDirectReq2Args, sizeof (DIRECT_MSG_ARGS)); FfaDirectReq2Args.Arg0 = TPM2_FFA_FINISH_NOTIFIED; - Status = ArmFfaLibMsgSendDirectReq2 (mFfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); + Status = ArmFfaLibMsgSendDirectReq2 (FfaTpm2PartitionId, &gTpm2ServiceFfaGuid, &FfaDirectReq2Args); while (Status == EFI_INTERRUPT_PENDING) { // We are assuming vCPU0 of the TPM SP since it is UP. Status = ArmFfaLibRun (GET_SOURCE_PARTITION_ID (FfaDirectReq2Args.Header.x1), 0x00, &FfaDirectReq2Args); } if (EFI_ERROR (Status)) { - goto Exit; + return Status; } - Status = TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); - -Exit: - return Status; + return TranslateTpmReturnStatus (FfaDirectReq2Args.Arg0); } From a3da9cde61fcc0082c5900106ebe66a4727ecf09 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Tue, 26 May 2026 11:06:51 +0200 Subject: [PATCH 362/406] ShellPkg/Edit: Remove unused code snippet The commented out code snippet seems to try to create a new file with the user input filename. FileBufferRead() seems to have replaced this code snippet in a better wrapper: - if the file exists, open it - otherwise, create the file Remove the commented-out code snippet. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c index c0539eb0ac..bcd3b56704 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c @@ -33,8 +33,6 @@ ShellCommandRunEdit ( CHAR16 *Spot; CONST CHAR16 *TempParam; - // SHELL_FILE_HANDLE TempHandle; - Buffer = NULL; ShellStatus = SHELL_SUCCESS; Nfs = NULL; @@ -108,13 +106,6 @@ ShellCommandRunEdit ( } else { FileBufferSetFileName (TempParam); } - - // if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) { - // Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0); - // if (!EFI_ERROR(Status)) { - // ShellCloseFile(&TempHandle); - // } - // } } Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE); From 4e1e7393384987244fdb824e80be24db2468da29 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Mon, 4 May 2026 10:28:34 +0200 Subject: [PATCH 363/406] ShellPkg/Ls: Remove double-free calls Package is always freed in ShellCommandRunLs(). Remove calls to ShellCommandLineFreeVarList() in MainCmdLs(). This double-free was introduced in: commit 531b0aa00211 ("ShellPkg/UefiShellLevel2: Extract MainCmdXXX() function") Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c index f33cbbe2f2..389f402d5c 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c @@ -984,7 +984,6 @@ MainCmdLs ( if (StrStr (PathName, L":") == NULL) { StrnCatGrow (&FullPath, &Size, gEfiShellProtocol->GetCurDir (NULL), 0); if (FullPath == NULL) { - ShellCommandLineFreeVarList (Package); return SHELL_OUT_OF_RESOURCES; } @@ -994,7 +993,6 @@ MainCmdLs ( StrnCatGrow (&FullPath, &Size, PathName, 0); if (FullPath == NULL) { - ShellCommandLineFreeVarList (Package); return SHELL_OUT_OF_RESOURCES; } @@ -1011,7 +1009,6 @@ MainCmdLs ( StrnCatGrow (&SearchString, NULL, FullPath, 0); if (SearchString == NULL) { FreePool (FullPath); - ShellCommandLineFreeVarList (Package); return SHELL_OUT_OF_RESOURCES; } From 7ee84dc437ec4df895ebe69a08352e3c13e99f17 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:15:37 +0200 Subject: [PATCH 364/406] ShellPkg/UefiShellDebug1: Return if ShellCommandLineParse() failed (1/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Return directly if ShellCommandLineParse() returned an error Status. In such case, the "Package" that should be allocated by ShellCommandLineParse() is already freed in: ShellCommandLineParse() \-ShellCommandLineParseEx() \-InternalCommandLineParse() so there is no need to free it with ShellCommandLineFreeVarList(). To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - Comp.c - Cxl.c - Dblk.c - Dmem.c - DmpStore.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../Library/UefiShellDebug1CommandsLib/Comp.c | 392 +++++++++--------- .../Library/UefiShellDebug1CommandsLib/Cxl.c | 350 ++++++++-------- .../Library/UefiShellDebug1CommandsLib/Dblk.c | 116 +++--- .../Library/UefiShellDebug1CommandsLib/Dmem.c | 64 +-- .../UefiShellDebug1CommandsLib/DmpStore.c | 246 +++++------ 5 files changed, 590 insertions(+), 578 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c index 5a03b7ccea..559b120ca7 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c @@ -271,161 +271,155 @@ ShellCommandRunComp ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) > 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount (Package) < 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"comp"); + ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ShellCommandLineGetCount (Package) > 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) < 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"comp"); + TempParam = ShellCommandLineGetRawValue (Package, 1); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_INVALID_PARAMETER; + goto Exit; + } + + FileName1 = ShellFindFilePath (TempParam); + if (FileName1 == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); + ShellStatus = SHELL_NOT_FOUND; } else { - TempParam = ShellCommandLineGetRawValue (Package, 1); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Exit; - } - - FileName1 = ShellFindFilePath (TempParam); - if (FileName1 == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); + Status = ShellOpenFileByName (FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; - } else { - Status = ShellOpenFileByName (FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } } + } - TempParam = ShellCommandLineGetRawValue (Package, 2); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Exit; - } + TempParam = ShellCommandLineGetRawValue (Package, 2); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Exit; + } - FileName2 = ShellFindFilePath (TempParam); - if (FileName2 == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); + FileName2 = ShellFindFilePath (TempParam); + if (FileName2 == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); + ShellStatus = SHELL_NOT_FOUND; + } else { + Status = ShellOpenFileByName (FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; - } else { - Status = ShellOpenFileByName (FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } } + } - if (ShellStatus == SHELL_SUCCESS) { - Status = gEfiShellProtocol->GetFileSize (FileHandle1, &Size1); - ASSERT_EFI_ERROR (Status); - Status = gEfiShellProtocol->GetFileSize (FileHandle2, &Size2); - ASSERT_EFI_ERROR (Status); + if (ShellStatus == SHELL_SUCCESS) { + Status = gEfiShellProtocol->GetFileSize (FileHandle1, &Size1); + ASSERT_EFI_ERROR (Status); + Status = gEfiShellProtocol->GetFileSize (FileHandle2, &Size2); + ASSERT_EFI_ERROR (Status); - if (ShellCommandLineGetFlag (Package, L"-n")) { - TempParam = ShellCommandLineGetValue (Package, L"-n"); - if (TempParam == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"comp", L"-n"); - ShellStatus = SHELL_INVALID_PARAMETER; + if (ShellCommandLineGetFlag (Package, L"-n")) { + TempParam = ShellCommandLineGetValue (Package, L"-n"); + if (TempParam == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"comp", L"-n"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16 *)TempParam, L"all") == 0) { + DifferentCount = MAX_UINTN; } else { - if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16 *)TempParam, L"all") == 0) { - DifferentCount = MAX_UINTN; - } else { - Status = ShellConvertStringToUint64 (TempParam, &DifferentCount, FALSE, TRUE); - if (EFI_ERROR (Status) || (DifferentCount == 0)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-n"); - ShellStatus = SHELL_INVALID_PARAMETER; - } - } - } - } - - if (ShellCommandLineGetFlag (Package, L"-s")) { - TempParam = ShellCommandLineGetValue (Package, L"-s"); - if (TempParam == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"comp", L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Status = ShellConvertStringToUint64 (TempParam, &DifferentBytes, FALSE, TRUE); - if (EFI_ERROR (Status) || (DifferentBytes == 0)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-s"); + Status = ShellConvertStringToUint64 (TempParam, &DifferentCount, FALSE, TRUE); + if (EFI_ERROR (Status) || (DifferentCount == 0)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-n"); ShellStatus = SHELL_INVALID_PARAMETER; - } else { - if (DifferentBytes > MAX (Size1, Size2)) { - DifferentBytes = MAX (Size1, Size2); - } } } } } - if (ShellStatus == SHELL_SUCCESS) { - DataFromFile1 = AllocateZeroPool ((UINTN)DifferentBytes); - DataFromFile2 = AllocateZeroPool ((UINTN)DifferentBytes); - FileBufferInit (&FileBuffer1); - FileBufferInit (&FileBuffer2); - if ((DataFromFile1 == NULL) || (DataFromFile2 == NULL) || - (FileBuffer1.Data == NULL) || (FileBuffer2.Data == NULL)) + if (ShellCommandLineGetFlag (Package, L"-s")) { + TempParam = ShellCommandLineGetValue (Package, L"-s"); + if (TempParam == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"comp", L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = ShellConvertStringToUint64 (TempParam, &DifferentBytes, FALSE, TRUE); + if (EFI_ERROR (Status) || (DifferentBytes == 0)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + if (DifferentBytes > MAX (Size1, Size2)) { + DifferentBytes = MAX (Size1, Size2); + } + } + } + } + } + + if (ShellStatus == SHELL_SUCCESS) { + DataFromFile1 = AllocateZeroPool ((UINTN)DifferentBytes); + DataFromFile2 = AllocateZeroPool ((UINTN)DifferentBytes); + FileBufferInit (&FileBuffer1); + FileBufferInit (&FileBuffer2); + if ((DataFromFile1 == NULL) || (DataFromFile2 == NULL) || + (FileBuffer1.Data == NULL) || (FileBuffer2.Data == NULL)) + { + ShellStatus = SHELL_OUT_OF_RESOURCES; + SHELL_FREE_NON_NULL (DataFromFile1); + SHELL_FREE_NON_NULL (DataFromFile2); + FileBufferUninit (&FileBuffer1); + FileBufferUninit (&FileBuffer2); + } + } + + if (ShellStatus == SHELL_SUCCESS) { + while ((UINT64)DiffPointNumber < DifferentCount) { + DataSizeFromFile1 = 1; + DataSizeFromFile2 = 1; + OneByteFromFile1 = 0; + OneByteFromFile2 = 0; + Status = FileBufferReadByte ( + FileHandle1, + &FileBuffer1, + &DataSizeFromFile1, + &OneByteFromFile1 + ); + ASSERT_EFI_ERROR (Status); + Status = FileBufferReadByte ( + FileHandle2, + &FileBuffer2, + &DataSizeFromFile2, + &OneByteFromFile2 + ); + ASSERT_EFI_ERROR (Status); + + TempAddress++; + + // + // 1.When end of file and no chars in DataFromFile buffer, then break while. + // 2.If no more char in File1 or File2, The ReadStatus is InPrevDiffPoint forever. + // So the previous different point is the last one, then break the while block. + // + if (((DataSizeFromFile1 == 0) && (InsertPosition1 == 0) && (DataSizeFromFile2 == 0) && (InsertPosition2 == 0)) || + ((ReadStatus == InPrevDiffPoint) && ((DataSizeFromFile1 == 0) || (DataSizeFromFile2 == 0))) + ) { - ShellStatus = SHELL_OUT_OF_RESOURCES; - SHELL_FREE_NON_NULL (DataFromFile1); - SHELL_FREE_NON_NULL (DataFromFile2); - FileBufferUninit (&FileBuffer1); - FileBufferUninit (&FileBuffer2); + break; } - } - if (ShellStatus == SHELL_SUCCESS) { - while ((UINT64)DiffPointNumber < DifferentCount) { - DataSizeFromFile1 = 1; - DataSizeFromFile2 = 1; - OneByteFromFile1 = 0; - OneByteFromFile2 = 0; - Status = FileBufferReadByte ( - FileHandle1, - &FileBuffer1, - &DataSizeFromFile1, - &OneByteFromFile1 - ); - ASSERT_EFI_ERROR (Status); - Status = FileBufferReadByte ( - FileHandle2, - &FileBuffer2, - &DataSizeFromFile2, - &OneByteFromFile2 - ); - ASSERT_EFI_ERROR (Status); - - TempAddress++; - - // - // 1.When end of file and no chars in DataFromFile buffer, then break while. - // 2.If no more char in File1 or File2, The ReadStatus is InPrevDiffPoint forever. - // So the previous different point is the last one, then break the while block. - // - if (((DataSizeFromFile1 == 0) && (InsertPosition1 == 0) && (DataSizeFromFile2 == 0) && (InsertPosition2 == 0)) || - ((ReadStatus == InPrevDiffPoint) && ((DataSizeFromFile1 == 0) || (DataSizeFromFile2 == 0))) - ) - { - break; - } - - if (ReadStatus == OutOfDiffPoint) { - if (OneByteFromFile1 != OneByteFromFile2) { - ReadStatus = InDiffPoint; - DiffPointAddress = TempAddress; - if (DataSizeFromFile1 == 1) { - DataFromFile1[InsertPosition1++] = OneByteFromFile1; - } - - if (DataSizeFromFile2 == 1) { - DataFromFile2[InsertPosition2++] = OneByteFromFile2; - } - } - } else if (ReadStatus == InDiffPoint) { + if (ReadStatus == OutOfDiffPoint) { + if (OneByteFromFile1 != OneByteFromFile2) { + ReadStatus = InDiffPoint; + DiffPointAddress = TempAddress; if (DataSizeFromFile1 == 1) { DataFromFile1[InsertPosition1++] = OneByteFromFile1; } @@ -433,84 +427,92 @@ ShellCommandRunComp ( if (DataSizeFromFile2 == 1) { DataFromFile2[InsertPosition2++] = OneByteFromFile2; } - } else if (ReadStatus == InPrevDiffPoint) { - if (OneByteFromFile1 == OneByteFromFile2) { + } + } else if (ReadStatus == InDiffPoint) { + if (DataSizeFromFile1 == 1) { + DataFromFile1[InsertPosition1++] = OneByteFromFile1; + } + + if (DataSizeFromFile2 == 1) { + DataFromFile2[InsertPosition2++] = OneByteFromFile2; + } + } else if (ReadStatus == InPrevDiffPoint) { + if (OneByteFromFile1 == OneByteFromFile2) { + ReadStatus = OutOfDiffPoint; + } + } + + // + // ReadStatus should be always equal InDiffPoint. + // + if ((InsertPosition1 == DifferentBytes) || + (InsertPosition2 == DifferentBytes) || + ((DataSizeFromFile1 == 0) && (DataSizeFromFile2 == 0)) + ) + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_DIFFERENCE_POINT), gShellDebug1HiiHandle, ++DiffPointNumber); + PrintDifferentPoint (FileName1, L"File1", DataFromFile1, InsertPosition1, DiffPointAddress, DifferentBytes); + PrintDifferentPoint (FileName2, L"File2", DataFromFile2, InsertPosition2, DiffPointAddress, DifferentBytes); + + // + // One of two buffuers is empty, it means this is the last different point. + // + if ((InsertPosition1 == 0) || (InsertPosition2 == 0)) { + break; + } + + for (Index = 1; Index < InsertPosition1 && Index < InsertPosition2; Index++) { + if (DataFromFile1[Index] == DataFromFile2[Index]) { ReadStatus = OutOfDiffPoint; + break; } } - // - // ReadStatus should be always equal InDiffPoint. - // - if ((InsertPosition1 == DifferentBytes) || - (InsertPosition2 == DifferentBytes) || - ((DataSizeFromFile1 == 0) && (DataSizeFromFile2 == 0)) - ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_DIFFERENCE_POINT), gShellDebug1HiiHandle, ++DiffPointNumber); - PrintDifferentPoint (FileName1, L"File1", DataFromFile1, InsertPosition1, DiffPointAddress, DifferentBytes); - PrintDifferentPoint (FileName2, L"File2", DataFromFile2, InsertPosition2, DiffPointAddress, DifferentBytes); - + if (ReadStatus == OutOfDiffPoint) { // - // One of two buffuers is empty, it means this is the last different point. + // Try to find a new different point in the rest of DataFromFile. // - if ((InsertPosition1 == 0) || (InsertPosition2 == 0)) { - break; - } - - for (Index = 1; Index < InsertPosition1 && Index < InsertPosition2; Index++) { - if (DataFromFile1[Index] == DataFromFile2[Index]) { - ReadStatus = OutOfDiffPoint; + for ( ; Index < MAX (InsertPosition1, InsertPosition2); Index++) { + if (DataFromFile1[Index] != DataFromFile2[Index]) { + ReadStatus = InDiffPoint; + DiffPointAddress += Index; break; } } - - if (ReadStatus == OutOfDiffPoint) { - // - // Try to find a new different point in the rest of DataFromFile. - // - for ( ; Index < MAX (InsertPosition1, InsertPosition2); Index++) { - if (DataFromFile1[Index] != DataFromFile2[Index]) { - ReadStatus = InDiffPoint; - DiffPointAddress += Index; - break; - } - } - } else { - // - // Doesn't find a new different point, still in the same different point. - // - ReadStatus = InPrevDiffPoint; - } - - CopyMem (DataFromFile1, DataFromFile1 + Index, InsertPosition1 - Index); - CopyMem (DataFromFile2, DataFromFile2 + Index, InsertPosition2 - Index); - - SetMem (DataFromFile1 + InsertPosition1 - Index, (UINTN)DifferentBytes - InsertPosition1 + Index, 0); - SetMem (DataFromFile2 + InsertPosition2 - Index, (UINTN)DifferentBytes - InsertPosition2 + Index, 0); - - InsertPosition1 -= Index; - InsertPosition2 -= Index; + } else { + // + // Doesn't find a new different point, still in the same different point. + // + ReadStatus = InPrevDiffPoint; } - } - SHELL_FREE_NON_NULL (DataFromFile1); - SHELL_FREE_NON_NULL (DataFromFile2); - FileBufferUninit (&FileBuffer1); - FileBufferUninit (&FileBuffer2); + CopyMem (DataFromFile1, DataFromFile1 + Index, InsertPosition1 - Index); + CopyMem (DataFromFile2, DataFromFile2 + Index, InsertPosition2 - Index); - if (DiffPointNumber == 0) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle); - } else { - ShellStatus = SHELL_NOT_EQUAL; - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle); + SetMem (DataFromFile1 + InsertPosition1 - Index, (UINTN)DifferentBytes - InsertPosition1 + Index, 0); + SetMem (DataFromFile2 + InsertPosition2 - Index, (UINTN)DifferentBytes - InsertPosition2 + Index, 0); + + InsertPosition1 -= Index; + InsertPosition2 -= Index; } } - } - ShellCommandLineFreeVarList (Package); + SHELL_FREE_NON_NULL (DataFromFile1); + SHELL_FREE_NON_NULL (DataFromFile2); + FileBufferUninit (&FileBuffer1); + FileBufferUninit (&FileBuffer2); + + if (DiffPointNumber == 0) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle); + } else { + ShellStatus = SHELL_NOT_EQUAL; + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle); + } + } } + ShellCommandLineFreeVarList (Package); + Exit: SHELL_FREE_NON_NULL (FileName1); SHELL_FREE_NON_NULL (FileName2); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c index 16a3c48089..0f529ea371 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c @@ -325,192 +325,194 @@ ShellCommandRunCxl ( } else { ASSERT (FALSE); } - } else { - // - // Argument Count == 1(no other argument): enumerate all CXL functions - // - if (ShellCommandLineGetCount (Package) == 1) { - Status = CxlFindEndpoints (&HandleBuf, &HandleCount); - if (EFI_ERROR (Status)) { - goto Done; - } - for (Index = 0; Index < HandleCount; Index++) { - Status = gBS->HandleProtocol (HandleBuf[Index], &gEdkiiCxlIoProtocolGuid, (VOID **)&CxlIo); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_HANDLE_CFG_ERR), gShellDebug1HiiHandle, L"cxl"); - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } + return ShellStatus; + } - PciIo = CxlIo->PciIo; - Status = PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Func); - if (EFI_ERROR (Status)) { - goto Done; - } - - Status = PciIo->Pci.Read ( - PciIo, - EfiPciIoWidthFifoUint32, - 0, - sizeof (PciHeader) / sizeof (UINT32), - &PciHeader - ); - if (EFI_ERROR (Status)) { - goto Done; - } - - ShellPrintHiiDefaultEx ( - STRING_TOKEN (STR_CXL_LINE_P1), - gShellDebug1HiiHandle, - Segment, - Bus, - Device, - Func - ); - - ShellPrintHiiDefaultEx ( - STRING_TOKEN (STR_CXL_LINE_P2), - gShellDebug1HiiHandle, - PciHeader.VendorId, - PciHeader.DeviceId - ); - } - - Status = EFI_SUCCESS; + // + // Argument Count == 1(no other argument): enumerate all CXL functions + // + if (ShellCommandLineGetCount (Package) == 1) { + Status = CxlFindEndpoints (&HandleBuf, &HandleCount); + if (EFI_ERROR (Status)) { goto Done; - } else { - // Dump extended information - TargetSegment = 0; - TargetBus = 0; - TargetDevice = 0; - TargetFunc = 0; - if ((ShellCommandLineGetCount (Package) < 4) || (ShellCommandLineGetCount (Package) == 5)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"cxl"); - ShellStatus = SHELL_INVALID_PARAMETER; + } + + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol (HandleBuf[Index], &gEdkiiCxlIoProtocolGuid, (VOID **)&CxlIo); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_HANDLE_CFG_ERR), gShellDebug1HiiHandle, L"cxl"); + ShellStatus = SHELL_NOT_FOUND; goto Done; } - if (ShellCommandLineGetCount (Package) > 6) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"cxl"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (ShellCommandLineGetFlag (Package, L"-s") && (ShellCommandLineGetValue (Package, L"-s") == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"cxl", L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - Temp = ShellCommandLineGetValue (Package, L"-s"); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - TargetSegment = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - // - // The first Argument is assumed to be Bus number, second - // to be Device number, and third to be Func number. - // - Temp = ShellCommandLineGetRawValue (Package, 1); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - TargetBus = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (TargetBus > PCI_MAX_BUS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - TargetDevice = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (TargetDevice > PCI_MAX_DEVICE) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - Temp = ShellCommandLineGetRawValue (Package, 3); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - TargetFunc = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (TargetFunc > PCI_MAX_FUNC) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - Status = CxlFindEndpoints (&HandleBuf, &HandleCount); + PciIo = CxlIo->PciIo; + Status = PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Func); if (EFI_ERROR (Status)) { goto Done; } - for (Index = 0; Index < HandleCount; Index++) { - Status = gBS->HandleProtocol (HandleBuf[Index], &gEdkiiCxlIoProtocolGuid, (VOID **)&CxlIo); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_HANDLE_CFG_ERR), gShellDebug1HiiHandle, L"cxl"); - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } - - PciIo = CxlIo->PciIo; - Status = PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Func); - if (EFI_ERROR (Status)) { - goto Done; - } - - if ((Segment != TargetSegment) || - (Bus != TargetBus) || - (Device != TargetDevice) || - (Func != TargetFunc)) - { - continue; - } - - PrintCdatInfo (CxlIo); + Status = PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthFifoUint32, + 0, + sizeof (PciHeader) / sizeof (UINT32), + &PciHeader + ); + if (EFI_ERROR (Status)) { goto Done; } + + ShellPrintHiiDefaultEx ( + STRING_TOKEN (STR_CXL_LINE_P1), + gShellDebug1HiiHandle, + Segment, + Bus, + Device, + Func + ); + + ShellPrintHiiDefaultEx ( + STRING_TOKEN (STR_CXL_LINE_P2), + gShellDebug1HiiHandle, + PciHeader.VendorId, + PciHeader.DeviceId + ); + } + + Status = EFI_SUCCESS; + goto Done; + } else { + // Dump extended information + TargetSegment = 0; + TargetBus = 0; + TargetDevice = 0; + TargetFunc = 0; + if ((ShellCommandLineGetCount (Package) < 4) || (ShellCommandLineGetCount (Package) == 5)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"cxl"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + if (ShellCommandLineGetCount (Package) > 6) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"cxl"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + if (ShellCommandLineGetFlag (Package, L"-s") && (ShellCommandLineGetValue (Package, L"-s") == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"cxl", L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + Temp = ShellCommandLineGetValue (Package, L"-s"); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + TargetSegment = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + + // + // The first Argument is assumed to be Bus number, second + // to be Device number, and third to be Func number. + // + Temp = ShellCommandLineGetRawValue (Package, 1); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + TargetBus = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + if (TargetBus > PCI_MAX_BUS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + + Temp = ShellCommandLineGetRawValue (Package, 2); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + TargetDevice = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + if (TargetDevice > PCI_MAX_DEVICE) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + + Temp = ShellCommandLineGetRawValue (Package, 3); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + TargetFunc = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + if (TargetFunc > PCI_MAX_FUNC) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + + Status = CxlFindEndpoints (&HandleBuf, &HandleCount); + if (EFI_ERROR (Status)) { + goto Done; + } + + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol (HandleBuf[Index], &gEdkiiCxlIoProtocolGuid, (VOID **)&CxlIo); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_HANDLE_CFG_ERR), gShellDebug1HiiHandle, L"cxl"); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + + PciIo = CxlIo->PciIo; + Status = PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Func); + if (EFI_ERROR (Status)) { + goto Done; + } + + if ((Segment != TargetSegment) || + (Bus != TargetBus) || + (Device != TargetDevice) || + (Func != TargetFunc)) + { + continue; + } + + PrintCdatInfo (CxlIo); + goto Done; } } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c index c0543ff9a1..b8134b5871 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c @@ -134,74 +134,76 @@ ShellCommandRunDblk ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) > 4) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dblk"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount (Package) < 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"dblk"); + ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ShellCommandLineGetCount (Package) > 4) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dblk"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) < 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"dblk"); - ShellStatus = SHELL_INVALID_PARAMETER; + // + // Parse the params + // + BlockName = ShellCommandLineGetRawValue (Package, 1); + LbaString = ShellCommandLineGetRawValue (Package, 2); + BlockCountString = ShellCommandLineGetRawValue (Package, 3); + + if (LbaString == NULL) { + Lba = 0; } else { - // - // Parse the params - // - BlockName = ShellCommandLineGetRawValue (Package, 1); - LbaString = ShellCommandLineGetRawValue (Package, 2); - BlockCountString = ShellCommandLineGetRawValue (Package, 3); - - if (LbaString == NULL) { - Lba = 0; - } else { - if (!ShellIsHexOrDecimalNumber (LbaString, TRUE, FALSE)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", LbaString); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - if (EFI_ERROR (ShellConvertStringToUint64 (LbaString, &Lba, TRUE, FALSE))) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", LbaString); - ShellStatus = SHELL_INVALID_PARAMETER; - } + if (!ShellIsHexOrDecimalNumber (LbaString, TRUE, FALSE)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", LbaString); + ShellStatus = SHELL_INVALID_PARAMETER; } - if (BlockCountString == NULL) { - BlockCount = 1; - } else { - if (!ShellIsHexOrDecimalNumber (BlockCountString, TRUE, FALSE)) { + if (EFI_ERROR (ShellConvertStringToUint64 (LbaString, &Lba, TRUE, FALSE))) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", LbaString); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } + + if (BlockCountString == NULL) { + BlockCount = 1; + } else { + if (!ShellIsHexOrDecimalNumber (BlockCountString, TRUE, FALSE)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockCountString); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + if (!EFI_ERROR (ShellConvertStringToUint64 (BlockCountString, &BlockCount, TRUE, FALSE))) { + if (BlockCount > 0x10) { + BlockCount = 0x10; + } else if (BlockCount == 0) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockCountString); ShellStatus = SHELL_INVALID_PARAMETER; } - - if (!EFI_ERROR (ShellConvertStringToUint64 (BlockCountString, &BlockCount, TRUE, FALSE))) { - if (BlockCount > 0x10) { - BlockCount = 0x10; - } else if (BlockCount == 0) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockCountString); - ShellStatus = SHELL_INVALID_PARAMETER; - } - } - } - - if (ShellStatus == SHELL_SUCCESS) { - // - // do the work if we have a valid block identifier - // - if ((BlockName == NULL) || (gEfiShellProtocol->GetDevicePathFromMap (BlockName) == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockName); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - DevPath = (EFI_DEVICE_PATH_PROTOCOL *)gEfiShellProtocol->GetDevicePathFromMap (BlockName); - if (gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &DevPath, NULL) == EFI_NOT_FOUND) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_MAP_PROTOCOL), gShellDebug1HiiHandle, L"dblk", BlockName, L"BlockIo"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ShellStatus = DisplayTheBlocks (gEfiShellProtocol->GetDevicePathFromMap (BlockName), Lba, (UINT8)BlockCount); - } - } } } - ShellCommandLineFreeVarList (Package); + if (ShellStatus == SHELL_SUCCESS) { + // + // do the work if we have a valid block identifier + // + if ((BlockName == NULL) || (gEfiShellProtocol->GetDevicePathFromMap (BlockName) == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockName); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + DevPath = (EFI_DEVICE_PATH_PROTOCOL *)gEfiShellProtocol->GetDevicePathFromMap (BlockName); + if (gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &DevPath, NULL) == EFI_NOT_FOUND) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_MAP_PROTOCOL), gShellDebug1HiiHandle, L"dblk", BlockName, L"BlockIo"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ShellStatus = DisplayTheBlocks (gEfiShellProtocol->GetDevicePathFromMap (BlockName), Lba, (UINT8)BlockCount); + } + } + } } + ShellCommandLineFreeVarList (Package); + return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c index 0e89fe069a..841acb9d99 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c @@ -483,47 +483,49 @@ ShellCommandRunDmem ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) > 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmem"); + ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ShellCommandLineGetCount (Package) > 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmem"); - ShellStatus = SHELL_INVALID_PARAMETER; + Temp1 = ShellCommandLineGetRawValue (Package, 1); + if (Temp1 == NULL) { + Address = gST; + Size = sizeof (*gST); } else { - Temp1 = ShellCommandLineGetRawValue (Package, 1); + if (!ShellIsHexOrDecimalNumber (Temp1, TRUE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, (UINT64 *)&Address, TRUE, FALSE))) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + Temp1 = ShellCommandLineGetRawValue (Package, 2); if (Temp1 == NULL) { - Address = gST; - Size = sizeof (*gST); + Size = 512; } else { - if (!ShellIsHexOrDecimalNumber (Temp1, TRUE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, (UINT64 *)&Address, TRUE, FALSE))) { + if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, &Size, TRUE, FALSE))) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); ShellStatus = SHELL_INVALID_PARAMETER; } - - Temp1 = ShellCommandLineGetRawValue (Package, 2); - if (Temp1 == NULL) { - Size = 512; - } else { - if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, &Size, TRUE, FALSE))) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); - ShellStatus = SHELL_INVALID_PARAMETER; - } - } } } - - if (ShellStatus == SHELL_SUCCESS) { - if (!ShellCommandLineGetFlag (Package, L"-mmio")) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size); - DumpHex (2, (UINTN)Address, (UINTN)Size, Address); - if (Address == (VOID *)gST) { - ShellStatus = DisplaySystemTable (Package, Address); - } - } else { - ShellStatus = DisplayMmioMemory (Address, (UINTN)Size); - } - } - - ShellCommandLineFreeVarList (Package); } + if (ShellStatus == SHELL_SUCCESS) { + if (!ShellCommandLineGetFlag (Package, L"-mmio")) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size); + DumpHex (2, (UINTN)Address, (UINTN)Size, Address); + if (Address == (VOID *)gST) { + ShellStatus = DisplaySystemTable (Package, Address); + } + } else { + ShellStatus = DisplayMmioMemory (Address, (UINTN)Size); + } + } + + ShellCommandLineFreeVarList (Package); + return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c index 311199e644..b9eaba6688 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c @@ -750,6 +750,8 @@ ShellCommandRunDmpStore ( Type = DmpStoreDisplay; StandardFormatOutput = FALSE; + ShellStatus = SHELL_SUCCESS; + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR (Status)) { if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { @@ -759,147 +761,149 @@ ShellCommandRunDmpStore ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) > 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmpstore"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetFlag (Package, L"-all") && ShellCommandLineGetFlag (Package, L"-guid")) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-all", L"-guid"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetFlag (Package, L"-s") && ShellCommandLineGetFlag (Package, L"-l")) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l", L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if ((ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-l")) && ShellCommandLineGetFlag (Package, L"-d")) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-d"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if ((ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-l")) && ShellCommandLineGetFlag (Package, L"-sfo")) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-sfo"); + ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ShellCommandLineGetCount (Package) > 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmpstore"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetFlag (Package, L"-all") && ShellCommandLineGetFlag (Package, L"-guid")) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-all", L"-guid"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetFlag (Package, L"-s") && ShellCommandLineGetFlag (Package, L"-l")) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l", L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if ((ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-l")) && ShellCommandLineGetFlag (Package, L"-d")) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-d"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if ((ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-l")) && ShellCommandLineGetFlag (Package, L"-sfo")) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-sfo"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - // - // Determine the GUID to search for based on -all and -guid parameters - // - if (!ShellCommandLineGetFlag (Package, L"-all")) { - GuidStr = ShellCommandLineGetValue (Package, L"-guid"); - if (GuidStr != NULL) { - RStatus = StrToGuid (GuidStr, &GuidData); - if (RETURN_ERROR (RStatus) || (GuidStr[GUID_STRING_LENGTH] != L'\0')) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmpstore", GuidStr); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - Guid = &GuidData; - } else { - Guid = &gEfiGlobalVariableGuid; + // + // Determine the GUID to search for based on -all and -guid parameters + // + if (!ShellCommandLineGetFlag (Package, L"-all")) { + GuidStr = ShellCommandLineGetValue (Package, L"-guid"); + if (GuidStr != NULL) { + RStatus = StrToGuid (GuidStr, &GuidData); + if (RETURN_ERROR (RStatus) || (GuidStr[GUID_STRING_LENGTH] != L'\0')) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmpstore", GuidStr); + ShellStatus = SHELL_INVALID_PARAMETER; } + + Guid = &GuidData; } else { - Guid = NULL; + Guid = &gEfiGlobalVariableGuid; } + } else { + Guid = NULL; + } - // - // Get the Name of the variable to find - // - Name = ShellCommandLineGetRawValue (Package, 1); + // + // Get the Name of the variable to find + // + Name = ShellCommandLineGetRawValue (Package, 1); - if (ShellStatus == SHELL_SUCCESS) { - if (ShellCommandLineGetFlag (Package, L"-s")) { - Type = DmpStoreSave; - File = ShellCommandLineGetValue (Package, L"-s"); - if (File == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0); - if (!EFI_ERROR (Status)) { - // - // Delete existing file, but do not delete existing directory - // - FileInfo = ShellGetFileInfo (FileHandle); - if (FileInfo == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); - Status = EFI_DEVICE_ERROR; - } else { - if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File); - Status = EFI_INVALID_PARAMETER; - } else { - Status = ShellDeleteFile (&FileHandle); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_DELETE_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); - } - } - - FreePool (FileInfo); - } - } else if (Status == EFI_NOT_FOUND) { - // - // Good when file doesn't exist - // - Status = EFI_SUCCESS; - } else { - // - // Otherwise it's bad. - // + if (ShellStatus == SHELL_SUCCESS) { + if (ShellCommandLineGetFlag (Package, L"-s")) { + Type = DmpStoreSave; + File = ShellCommandLineGetValue (Package, L"-s"); + if (File == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0); + if (!EFI_ERROR (Status)) { + // + // Delete existing file, but do not delete existing directory + // + FileInfo = ShellGetFileInfo (FileHandle); + if (FileInfo == NULL) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); - } - - if (!EFI_ERROR (Status)) { - Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + Status = EFI_DEVICE_ERROR; + } else { + if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File); + Status = EFI_INVALID_PARAMETER; + } else { + Status = ShellDeleteFile (&FileHandle); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_DELETE_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + } } - } - if (EFI_ERROR (Status)) { - ShellStatus = SHELL_INVALID_PARAMETER; + FreePool (FileInfo); } - } - } else if (ShellCommandLineGetFlag (Package, L"-l")) { - Type = DmpStoreLoad; - File = ShellCommandLineGetValue (Package, L"-l"); - if (File == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-l"); - ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Status == EFI_NOT_FOUND) { + // + // Good when file doesn't exist + // + Status = EFI_SUCCESS; } else { - Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_READ, 0); + // + // Otherwise it's bad. + // + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + } + + if (!EFI_ERROR (Status)) { + Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0); if (EFI_ERROR (Status)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - FileInfo = ShellGetFileInfo (FileHandle); - if (FileInfo == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); - ShellStatus = SHELL_DEVICE_ERROR; - } else { - if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - FreePool (FileInfo); - } } } - } else if (ShellCommandLineGetFlag (Package, L"-d")) { - Type = DmpStoreDelete; - } - if (ShellCommandLineGetFlag (Package, L"-sfo")) { - StandardFormatOutput = TRUE; + if (EFI_ERROR (Status)) { + ShellStatus = SHELL_INVALID_PARAMETER; + } } + } else if (ShellCommandLineGetFlag (Package, L"-l")) { + Type = DmpStoreLoad; + File = ShellCommandLineGetValue (Package, L"-l"); + if (File == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-l"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + FileInfo = ShellGetFileInfo (FileHandle); + if (FileInfo == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + ShellStatus = SHELL_DEVICE_ERROR; + } else { + if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + FreePool (FileInfo); + } + } + } + } else if (ShellCommandLineGetFlag (Package, L"-d")) { + Type = DmpStoreDelete; } - if (ShellStatus == SHELL_SUCCESS) { - if (Type == DmpStoreSave) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMPSTORE_SAVE), gShellDebug1HiiHandle, File); - } else if (Type == DmpStoreLoad) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMPSTORE_LOAD), gShellDebug1HiiHandle, File); - } + if (ShellCommandLineGetFlag (Package, L"-sfo")) { + StandardFormatOutput = TRUE; + } + } - ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle, StandardFormatOutput); - if ((Type == DmpStoreLoad) || (Type == DmpStoreSave)) { - ShellCloseFile (&FileHandle); - } + if (ShellStatus == SHELL_SUCCESS) { + if (Type == DmpStoreSave) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMPSTORE_SAVE), gShellDebug1HiiHandle, File); + } else if (Type == DmpStoreLoad) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMPSTORE_LOAD), gShellDebug1HiiHandle, File); + } + + ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle, StandardFormatOutput); + if ((Type == DmpStoreLoad) || (Type == DmpStoreSave)) { + ShellCloseFile (&FileHandle); } } } From d23559e847f41d9c8fa69cb801a31a9ffda9baa1 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:16:21 +0200 Subject: [PATCH 365/406] ShellPkg/UefiShellDebug1: Return if ShellCommandLineParse() failed (2/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Return directly if ShellCommandLineParse() returned an error Status. In such case, the "Package" that should be allocated by ShellCommandLineParse() is already freed in: ShellCommandLineParse() \-ShellCommandLineParseEx() \-InternalCommandLineParse() so there is no need to free it with ShellCommandLineFreeVarList(). To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - Edit/Edit.c - EfiCompress.c - EfiDecompress.c - HexEdit/HexEdit.c - LoadPciRom.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../UefiShellDebug1CommandsLib/Edit/Edit.c | 172 ++++----- .../UefiShellDebug1CommandsLib/EfiCompress.c | 132 +++---- .../EfiDecompress.c | 177 ++++----- .../HexEdit/HexEdit.c | 340 +++++++++--------- .../UefiShellDebug1CommandsLib/LoadPciRom.c | 154 ++++---- 5 files changed, 492 insertions(+), 483 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c index bcd3b56704..34e5ddc25c 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c @@ -58,101 +58,103 @@ ShellCommandRunEdit ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) > 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"edit"); + ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ShellCommandLineGetCount (Package) > 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"edit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Cwd = gEfiShellProtocol->GetCurDir (NULL); - if (Cwd == NULL) { - Cwd = ShellGetEnvironmentVariable (L"path"); - if (Cwd != NULL) { - Nfs = StrnCatGrow (&Nfs, NULL, Cwd+3, 0); - if (Nfs != NULL) { - Spot = StrStr (Nfs, L";"); - if (Spot != NULL) { - *Spot = CHAR_NULL; - } - - Spot = StrStr (Nfs, L"\\"); - if (Spot != NULL) { - Spot[1] = CHAR_NULL; - } - - gEfiShellProtocol->SetCurDir (NULL, Nfs); - FreePool (Nfs); + Cwd = gEfiShellProtocol->GetCurDir (NULL); + if (Cwd == NULL) { + Cwd = ShellGetEnvironmentVariable (L"path"); + if (Cwd != NULL) { + Nfs = StrnCatGrow (&Nfs, NULL, Cwd+3, 0); + if (Nfs != NULL) { + Spot = StrStr (Nfs, L";"); + if (Spot != NULL) { + *Spot = CHAR_NULL; } - } - } - Status = MainEditorInit (); - - if (EFI_ERROR (Status)) { - gST->ConOut->ClearScreen (gST->ConOut); - gST->ConOut->EnableCursor (gST->ConOut, TRUE); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_INIT_FAILED), gShellDebug1HiiHandle); - } else { - MainEditorBackup (); - - // - // if editor launched with file named - // - if (ShellCommandLineGetCount (Package) == 2) { - TempParam = ShellCommandLineGetRawValue (Package, 1); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"edit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - FileBufferSetFileName (TempParam); + Spot = StrStr (Nfs, L"\\"); + if (Spot != NULL) { + Spot[1] = CHAR_NULL; } - } - Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE); - if (!EFI_ERROR (Status)) { - MainEditorRefresh (); - - Status = MainEditorKeyInput (); - } - - if (Status != EFI_OUT_OF_RESOURCES) { - // - // back up the status string - // - Buffer = CatSPrint (NULL, L"%s", StatusBarGetString ()); - } - - MainEditorCleanup (); - - // - // print editor exit code on screen - // - if (Status == EFI_SUCCESS) { - } else if (Status == EFI_OUT_OF_RESOURCES) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"edit"); - } else { - if (Buffer != NULL) { - if (StrCmp (Buffer, L"") != 0) { - // - // print out the status string - // - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_BUFFER), gShellDebug1HiiHandle, Buffer); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle); - } - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle); - } - } - - if (Status != EFI_OUT_OF_RESOURCES) { - SHELL_FREE_NON_NULL (Buffer); + gEfiShellProtocol->SetCurDir (NULL, Nfs); + FreePool (Nfs); } } } - ShellCommandLineFreeVarList (Package); + Status = MainEditorInit (); + + if (EFI_ERROR (Status)) { + gST->ConOut->ClearScreen (gST->ConOut); + gST->ConOut->EnableCursor (gST->ConOut, TRUE); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_INIT_FAILED), gShellDebug1HiiHandle); + } else { + MainEditorBackup (); + + // + // if editor launched with file named + // + if (ShellCommandLineGetCount (Package) == 2) { + TempParam = ShellCommandLineGetRawValue (Package, 1); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"edit"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + FileBufferSetFileName (TempParam); + } + } + + Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE); + if (!EFI_ERROR (Status)) { + MainEditorRefresh (); + + Status = MainEditorKeyInput (); + } + + if (Status != EFI_OUT_OF_RESOURCES) { + // + // back up the status string + // + Buffer = CatSPrint (NULL, L"%s", StatusBarGetString ()); + } + + MainEditorCleanup (); + + // + // print editor exit code on screen + // + if (Status == EFI_SUCCESS) { + } else if (Status == EFI_OUT_OF_RESOURCES) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"edit"); + } else { + if (Buffer != NULL) { + if (StrCmp (Buffer, L"") != 0) { + // + // print out the status string + // + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_BUFFER), gShellDebug1HiiHandle, Buffer); + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle); + } + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle); + } + } + + if (Status != EFI_OUT_OF_RESOURCES) { + SHELL_FREE_NON_NULL (Buffer); + } + } } + ShellCommandLineFreeVarList (Package); + return ShellStatus; } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c index f31b4ffd27..9ee3ac6952 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c @@ -71,92 +71,94 @@ ShellCommandRunEfiCompress ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) > 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"eficompress"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount (Package) < 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"eficompress"); + ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ShellCommandLineGetCount (Package) > 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"eficompress"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) < 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"eficompress"); + TempParam = ShellCommandLineGetRawValue (Package, 1); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"eficompress"); ShellStatus = SHELL_INVALID_PARAMETER; + goto Exit; + } + + InFileName = ShellFindFilePath (TempParam); + OutFileName = ShellCommandLineGetRawValue (Package, 2); + if ((InFileName == NULL) || (OutFileName == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"eficompress", TempParam); + ShellStatus = SHELL_NOT_FOUND; } else { - TempParam = ShellCommandLineGetRawValue (Package, 1); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"eficompress"); + if (ShellIsDirectory (InFileName) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", InFileName); ShellStatus = SHELL_INVALID_PARAMETER; - goto Exit; } - InFileName = ShellFindFilePath (TempParam); - OutFileName = ShellCommandLineGetRawValue (Package, 2); - if ((InFileName == NULL) || (OutFileName == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"eficompress", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } else { - if (ShellIsDirectory (InFileName) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", InFileName); - ShellStatus = SHELL_INVALID_PARAMETER; + if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", OutFileName); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + if (ShellStatus == SHELL_SUCCESS) { + Status = ShellOpenFileByName (InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue (Package, 1)); + ShellStatus = SHELL_NOT_FOUND; } - if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", OutFileName); - ShellStatus = SHELL_INVALID_PARAMETER; + Status = ShellOpenFileByName (OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue (Package, 2)); + ShellStatus = SHELL_NOT_FOUND; } + } - if (ShellStatus == SHELL_SUCCESS) { - Status = ShellOpenFileByName (InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue (Package, 1)); - ShellStatus = SHELL_NOT_FOUND; - } - - Status = ShellOpenFileByName (OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue (Package, 2)); - ShellStatus = SHELL_NOT_FOUND; - } - } - - if (ShellStatus == SHELL_SUCCESS) { - Status = gEfiShellProtocol->GetFileSize (InShellFileHandle, &InSize); + if (ShellStatus == SHELL_SUCCESS) { + Status = gEfiShellProtocol->GetFileSize (InShellFileHandle, &InSize); + ASSERT_EFI_ERROR (Status); + InBuffer = AllocateZeroPool ((UINTN)InSize); + if (InBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + InSize2 = (UINTN)InSize; + Status = gEfiShellProtocol->ReadFile (InShellFileHandle, &InSize2, InBuffer); + InSize = InSize2; ASSERT_EFI_ERROR (Status); - InBuffer = AllocateZeroPool ((UINTN)InSize); - if (InBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - InSize2 = (UINTN)InSize; - Status = gEfiShellProtocol->ReadFile (InShellFileHandle, &InSize2, InBuffer); - InSize = InSize2; - ASSERT_EFI_ERROR (Status); - Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); - if (Status == EFI_BUFFER_TOO_SMALL) { - OutBuffer = AllocateZeroPool ((UINTN)OutSize); - if (OutBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); - } + Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); + if (Status == EFI_BUFFER_TOO_SMALL) { + OutBuffer = AllocateZeroPool ((UINTN)OutSize); + if (OutBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); } } + } + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); + ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); + } else { + OutSize2 = (UINTN)OutSize; + Status = gEfiShellProtocol->WriteFile (OutShellFileHandle, &OutSize2, OutBuffer); if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); - ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); - } else { - OutSize2 = (UINTN)OutSize; - Status = gEfiShellProtocol->WriteFile (OutShellFileHandle, &OutSize2, OutBuffer); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"eficompress", OutFileName); - ShellStatus = SHELL_DEVICE_ERROR; - } + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"eficompress", OutFileName); + ShellStatus = SHELL_DEVICE_ERROR; } } } } - - ShellCommandLineFreeVarList (Package); } + ShellCommandLineFreeVarList (Package); + Exit: if ((ShellStatus != SHELL_SUCCESS) && (Package != NULL)) { ShellCommandLineFreeVarList (Package); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c index 041fef71a8..a31183254d 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c @@ -76,118 +76,119 @@ ShellCommandRunEfiDecompress ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) > 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"efidecompress"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount (Package) < 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"efidecompress"); + ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ShellCommandLineGetCount (Package) > 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"efidecompress"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) < 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"efidecompress"); + TempParam = ShellCommandLineGetRawValue (Package, 1); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"efidecompress"); ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + InFileName = ShellFindFilePath (TempParam); + OutFileName = ShellCommandLineGetRawValue (Package, 2); + if ((InFileName == NULL) || (OutFileName == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"efidecompress", TempParam); + ShellStatus = SHELL_NOT_FOUND; } else { - TempParam = ShellCommandLineGetRawValue (Package, 1); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"efidecompress"); + if (ShellIsDirectory (InFileName) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", InFileName); ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; } - InFileName = ShellFindFilePath (TempParam); - OutFileName = ShellCommandLineGetRawValue (Package, 2); - if ((InFileName == NULL) || (OutFileName == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"efidecompress", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } else { - if (ShellIsDirectory (InFileName) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", InFileName); - ShellStatus = SHELL_INVALID_PARAMETER; + if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", OutFileName); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + if (ShellStatus == SHELL_SUCCESS) { + Status = ShellOpenFileByName (InFileName, &InFileHandle, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"efidecompress", ShellCommandLineGetRawValue (Package, 1)); + ShellStatus = SHELL_NOT_FOUND; + } + } + + if (ShellStatus == SHELL_SUCCESS) { + Status = FileHandleGetSize (InFileHandle, &Temp64Bit); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"efidecompress", ShellCommandLineGetRawValue (Package, 1)); + ShellStatus = SHELL_NOT_FOUND; + } + } + + if (ShellStatus == SHELL_SUCCESS) { + // + // Limit the File Size to UINT32, even though calls accept UINTN. + // 32 bits = 4gb. + // + Status = SafeUint64ToUint32 (Temp64Bit, (UINT32 *)&InSize); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + ShellStatus = SHELL_BAD_BUFFER_SIZE; + goto Done; } - if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", OutFileName); - ShellStatus = SHELL_INVALID_PARAMETER; + InBuffer = AllocateZeroPool (InSize); + if (InBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer); + ASSERT_EFI_ERROR (Status); + + Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress); + ASSERT_EFI_ERROR (Status); + + Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize); } - if (ShellStatus == SHELL_SUCCESS) { - Status = ShellOpenFileByName (InFileName, &InFileHandle, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status) || (OutSize == 0)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName); + ShellStatus = SHELL_NOT_FOUND; + } else { + Status = ShellOpenFileByName (OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"efidecompress", ShellCommandLineGetRawValue (Package, 1)); - ShellStatus = SHELL_NOT_FOUND; - } - } - - if (ShellStatus == SHELL_SUCCESS) { - Status = FileHandleGetSize (InFileHandle, &Temp64Bit); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"efidecompress", ShellCommandLineGetRawValue (Package, 1)); - ShellStatus = SHELL_NOT_FOUND; - } - } - - if (ShellStatus == SHELL_SUCCESS) { - // - // Limit the File Size to UINT32, even though calls accept UINTN. - // 32 bits = 4gb. - // - Status = SafeUint64ToUint32 (Temp64Bit, (UINT32 *)&InSize); - if (EFI_ERROR (Status)) { - ASSERT_EFI_ERROR (Status); - ShellStatus = SHELL_BAD_BUFFER_SIZE; - goto Done; - } - - InBuffer = AllocateZeroPool (InSize); - if (InBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer); - ASSERT_EFI_ERROR (Status); - - Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress); - ASSERT_EFI_ERROR (Status); - - Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize); - } - - if (EFI_ERROR (Status) || (OutSize == 0)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, 2), Status); ShellStatus = SHELL_NOT_FOUND; } else { - Status = ShellOpenFileByName (OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, 2), Status); - ShellStatus = SHELL_NOT_FOUND; + OutBuffer = AllocateZeroPool (OutSize); + ScratchBuffer = AllocateZeroPool (ScratchSize); + if ((OutBuffer == NULL) || (ScratchBuffer == NULL)) { + Status = EFI_OUT_OF_RESOURCES; } else { - OutBuffer = AllocateZeroPool (OutSize); - ScratchBuffer = AllocateZeroPool (ScratchSize); - if ((OutBuffer == NULL) || (ScratchBuffer == NULL)) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = Decompress->Decompress (Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize); - } + Status = Decompress->Decompress (Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize); } } + } + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status); + ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); + } else { + OutSizeTemp = OutSize; + Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer); + OutSize = (UINT32)OutSizeTemp; if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status); - ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); - } else { - OutSizeTemp = OutSize; - Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer); - OutSize = (UINT32)OutSizeTemp; - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"efidecompress", OutFileName, Status); - ShellStatus = SHELL_DEVICE_ERROR; - } + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"efidecompress", OutFileName, Status); + ShellStatus = SHELL_DEVICE_ERROR; } } } } + } Done: - - ShellCommandLineFreeVarList (Package); - } + ShellCommandLineFreeVarList (Package); if (InFileHandle != NULL) { gEfiShellProtocol->CloseFile (InFileHandle); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEdit.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEdit.c index 7385ccf88e..22a9c74954 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEdit.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEdit.c @@ -74,202 +74,204 @@ ShellCommandRunHexEdit ( } else { ASSERT (FALSE); } - } else { - // - // Check for -d - // - if (ShellCommandLineGetFlag (Package, L"-d")) { - if (ShellCommandLineGetCount (Package) < 4) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) > 4) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - WhatToDo = FileTypeDiskBuffer; - Name = ShellCommandLineGetRawValue (Package, 1); - Offset = ShellStrToUintn (ShellCommandLineGetRawValue (Package, 2)); - Size = ShellStrToUintn (ShellCommandLineGetRawValue (Package, 3)); - } - if ((Offset == (UINTN)-1) || (Size == (UINTN)-1)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"hexedit", L"-d"); - ShellStatus = SHELL_INVALID_PARAMETER; - } + return ShellStatus; + } + + // + // Check for -d + // + if (ShellCommandLineGetFlag (Package, L"-d")) { + if (ShellCommandLineGetCount (Package) < 4) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount (Package) > 4) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + WhatToDo = FileTypeDiskBuffer; + Name = ShellCommandLineGetRawValue (Package, 1); + Offset = ShellStrToUintn (ShellCommandLineGetRawValue (Package, 2)); + Size = ShellStrToUintn (ShellCommandLineGetRawValue (Package, 3)); } - // - // check for -f - // - if (ShellCommandLineGetFlag (Package, L"-f") && (WhatToDo == FileTypeNone)) { - if (ShellCommandLineGetCount (Package) < 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) > 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Name = ShellCommandLineGetRawValue (Package, 1); - if ((Name == NULL) || !IsValidFileName (Name)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"hexedit", Name); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - WhatToDo = FileTypeFileBuffer; - } - } + if ((Offset == (UINTN)-1) || (Size == (UINTN)-1)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"hexedit", L"-d"); + ShellStatus = SHELL_INVALID_PARAMETER; } + } - // - // check for -m - // - if (ShellCommandLineGetFlag (Package, L"-m") && (WhatToDo == FileTypeNone)) { - if (ShellCommandLineGetCount (Package) < 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) > 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - WhatToDo = FileTypeMemBuffer; - Offset = ShellStrToUintn (ShellCommandLineGetRawValue (Package, 1)); - Size = ShellStrToUintn (ShellCommandLineGetRawValue (Package, 2)); - } - } - - Name = ShellCommandLineGetRawValue (Package, 1); - if ((WhatToDo == FileTypeNone) && (Name != NULL)) { - if (ShellCommandLineGetCount (Package) > 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (!IsValidFileName (Name)) { + // + // check for -f + // + if (ShellCommandLineGetFlag (Package, L"-f") && (WhatToDo == FileTypeNone)) { + if (ShellCommandLineGetCount (Package) < 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount (Package) > 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Name = ShellCommandLineGetRawValue (Package, 1); + if ((Name == NULL) || !IsValidFileName (Name)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"hexedit", Name); ShellStatus = SHELL_INVALID_PARAMETER; } else { WhatToDo = FileTypeFileBuffer; } - } else if (WhatToDo == FileTypeNone) { - if (gEfiShellProtocol->GetCurDir (NULL) == NULL) { - ShellStatus = SHELL_NOT_FOUND; - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_CWD), gShellDebug1HiiHandle, L"hexedit"); - } else { - NewName = EditGetDefaultFileName (L"bin"); - Name = NewName; - WhatToDo = FileTypeFileBuffer; - } } + } - if ((ShellStatus == SHELL_SUCCESS) && (WhatToDo == FileTypeNone)) { + // + // check for -m + // + if (ShellCommandLineGetFlag (Package, L"-m") && (WhatToDo == FileTypeNone)) { + if (ShellCommandLineGetCount (Package) < 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; - } else if ((WhatToDo == FileTypeFileBuffer) && (ShellGetCurrentDir (NULL) == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_CWD), gShellDebug1HiiHandle, L"hexedit"); + } else if (ShellCommandLineGetCount (Package) > 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; + } else { + WhatToDo = FileTypeMemBuffer; + Offset = ShellStrToUintn (ShellCommandLineGetRawValue (Package, 1)); + Size = ShellStrToUintn (ShellCommandLineGetRawValue (Package, 2)); + } + } + + Name = ShellCommandLineGetRawValue (Package, 1); + if ((WhatToDo == FileTypeNone) && (Name != NULL)) { + if (ShellCommandLineGetCount (Package) > 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (!IsValidFileName (Name)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"hexedit", Name); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + WhatToDo = FileTypeFileBuffer; + } + } else if (WhatToDo == FileTypeNone) { + if (gEfiShellProtocol->GetCurDir (NULL) == NULL) { + ShellStatus = SHELL_NOT_FOUND; + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_CWD), gShellDebug1HiiHandle, L"hexedit"); + } else { + NewName = EditGetDefaultFileName (L"bin"); + Name = NewName; + WhatToDo = FileTypeFileBuffer; + } + } + + if ((ShellStatus == SHELL_SUCCESS) && (WhatToDo == FileTypeNone)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if ((WhatToDo == FileTypeFileBuffer) && (ShellGetCurrentDir (NULL) == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_CWD), gShellDebug1HiiHandle, L"hexedit"); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + if (ShellStatus == SHELL_SUCCESS) { + // + // Do the editor + // + Status = HMainEditorInit (); + if (EFI_ERROR (Status)) { + gST->ConOut->ClearScreen (gST->ConOut); + gST->ConOut->EnableCursor (gST->ConOut, TRUE); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_HEXEDIT_INIT_FAILED), gShellDebug1HiiHandle); + } else { + HMainEditorBackup (); + switch (WhatToDo) { + case FileTypeFileBuffer: + Status = HBufferImageRead ( + Name == NULL ? L"" : Name, + NULL, + 0, + 0, + 0, + 0, + FileTypeFileBuffer, + FALSE + ); + break; + + case FileTypeDiskBuffer: + Status = HBufferImageRead ( + NULL, + Name == NULL ? L"" : Name, + Offset, + Size, + 0, + 0, + FileTypeDiskBuffer, + FALSE + ); + break; + + case FileTypeMemBuffer: + Status = HBufferImageRead ( + NULL, + NULL, + 0, + 0, + (UINT32)Offset, + Size, + FileTypeMemBuffer, + FALSE + ); + break; + + default: + Status = EFI_NOT_FOUND; + break; + } + + if (!EFI_ERROR (Status)) { + HMainEditorRefresh (); + Status = HMainEditorKeyInput (); + } + + if (Status != EFI_OUT_OF_RESOURCES) { + // + // back up the status string + // + Buffer = CatSPrint (NULL, L"%s\r\n", StatusBarGetString ()); + } } - if (ShellStatus == SHELL_SUCCESS) { - // - // Do the editor - // - Status = HMainEditorInit (); - if (EFI_ERROR (Status)) { - gST->ConOut->ClearScreen (gST->ConOut); - gST->ConOut->EnableCursor (gST->ConOut, TRUE); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_HEXEDIT_INIT_FAILED), gShellDebug1HiiHandle); - } else { - HMainEditorBackup (); - switch (WhatToDo) { - case FileTypeFileBuffer: - Status = HBufferImageRead ( - Name == NULL ? L"" : Name, - NULL, - 0, - 0, - 0, - 0, - FileTypeFileBuffer, - FALSE - ); - break; + // + // cleanup + // + HMainEditorCleanup (); - case FileTypeDiskBuffer: - Status = HBufferImageRead ( - NULL, - Name == NULL ? L"" : Name, - Offset, - Size, - 0, - 0, - FileTypeDiskBuffer, - FALSE - ); - break; - - case FileTypeMemBuffer: - Status = HBufferImageRead ( - NULL, - NULL, - 0, - 0, - (UINT32)Offset, - Size, - FileTypeMemBuffer, - FALSE - ); - break; - - default: - Status = EFI_NOT_FOUND; - break; - } - - if (!EFI_ERROR (Status)) { - HMainEditorRefresh (); - Status = HMainEditorKeyInput (); - } - - if (Status != EFI_OUT_OF_RESOURCES) { - // - // back up the status string - // - Buffer = CatSPrint (NULL, L"%s\r\n", StatusBarGetString ()); - } + if (EFI_ERROR (Status)) { + if (ShellStatus == SHELL_SUCCESS) { + ShellStatus = SHELL_UNSUPPORTED; } + } - // - // cleanup - // - HMainEditorCleanup (); - - if (EFI_ERROR (Status)) { - if (ShellStatus == SHELL_SUCCESS) { - ShellStatus = SHELL_UNSUPPORTED; - } - } - - // - // print editor exit code on screen - // - if (Status == EFI_OUT_OF_RESOURCES) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"hexedit"); - } else if (EFI_ERROR (Status)) { - if (Buffer != NULL) { - if (StrCmp (Buffer, L"") != 0) { - // - // print out the status string - // - ShellPrintDefaultEx (L"%s", Buffer); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_HEXEDIT_UNKNOWN_EDITOR), gShellDebug1HiiHandle); - } + // + // print editor exit code on screen + // + if (Status == EFI_OUT_OF_RESOURCES) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"hexedit"); + } else if (EFI_ERROR (Status)) { + if (Buffer != NULL) { + if (StrCmp (Buffer, L"") != 0) { + // + // print out the status string + // + ShellPrintDefaultEx (L"%s", Buffer); } else { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_HEXEDIT_UNKNOWN_EDITOR), gShellDebug1HiiHandle); } + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_HEXEDIT_UNKNOWN_EDITOR), gShellDebug1HiiHandle); } } - - ShellCommandLineFreeVarList (Package); } + ShellCommandLineFreeVarList (Package); + SHELL_FREE_NON_NULL (Buffer); SHELL_FREE_NON_NULL (NewName); return ShellStatus; diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c index 81cf823597..8486303b79 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c @@ -93,93 +93,95 @@ ShellCommandRunLoadPciRom ( } else { ASSERT (FALSE); } - } else { - if (ShellCommandLineGetCount (Package) < 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"loadpcirom"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - if (ShellCommandLineGetFlag (Package, L"-nc")) { - Connect = FALSE; - } else { - Connect = TRUE; - } + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) < 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"loadpcirom"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + if (ShellCommandLineGetFlag (Package, L"-nc")) { + Connect = FALSE; + } else { + Connect = TRUE; + } + + // + // get a list with each file specified by parameters + // if parameter is a directory then add all the files below it to the list + // + for ( ParamCount = 1, Param = ShellCommandLineGetRawValue (Package, ParamCount) + ; Param != NULL + ; ParamCount++, Param = ShellCommandLineGetRawValue (Package, ParamCount) + ) + { + Status = ShellOpenFileMetaArg ((CHAR16 *)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Param); + ShellStatus = SHELL_ACCESS_DENIED; + break; + } + } + + if ((ShellStatus == SHELL_SUCCESS) && (FileList != NULL)) { // - // get a list with each file specified by parameters - // if parameter is a directory then add all the files below it to the list + // loop through the list and make sure we are not aborting... // - for ( ParamCount = 1, Param = ShellCommandLineGetRawValue (Package, ParamCount) - ; Param != NULL - ; ParamCount++, Param = ShellCommandLineGetRawValue (Package, ParamCount) + for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link) + ; !IsNull (&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag () + ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link) ) { - Status = ShellOpenFileMetaArg ((CHAR16 *)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); + if (EFI_ERROR (Node->Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); + ShellStatus = SHELL_INVALID_PARAMETER; + continue; + } + + if (FileHandleIsDirectory (Node->Handle) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); + ShellStatus = SHELL_INVALID_PARAMETER; + continue; + } + + SourceSize = (UINTN)Node->Info->FileSize; + File1Buffer = AllocateZeroPool (SourceSize); + if (File1Buffer == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"loadpcirom"); + ShellStatus = SHELL_OUT_OF_RESOURCES; + continue; + } + + Status = gEfiShellProtocol->ReadFile (Node->Handle, &SourceSize, File1Buffer); if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Param); - ShellStatus = SHELL_ACCESS_DENIED; - break; + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_READ_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = LoadEfiDriversFromRomImage ( + File1Buffer, + SourceSize, + Node->FullName + ); + + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_LOAD_PCI_ROM_RES), gShellDebug1HiiHandle, Node->FullName, Status); } + + FreePool (File1Buffer); } + } else if (ShellStatus == SHELL_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, "loadpcirom"); + ShellStatus = SHELL_NOT_FOUND; + } - if ((ShellStatus == SHELL_SUCCESS) && (FileList != NULL)) { - // - // loop through the list and make sure we are not aborting... - // - for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link) - ; !IsNull (&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag () - ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link) - ) - { - if (EFI_ERROR (Node->Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); - ShellStatus = SHELL_INVALID_PARAMETER; - continue; - } + if ((FileList != NULL) && !IsListEmpty (&FileList->Link)) { + Status = ShellCloseFileMetaArg (&FileList); + } - if (FileHandleIsDirectory (Node->Handle) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); - ShellStatus = SHELL_INVALID_PARAMETER; - continue; - } + FileList = NULL; - SourceSize = (UINTN)Node->Info->FileSize; - File1Buffer = AllocateZeroPool (SourceSize); - if (File1Buffer == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"loadpcirom"); - ShellStatus = SHELL_OUT_OF_RESOURCES; - continue; - } - - Status = gEfiShellProtocol->ReadFile (Node->Handle, &SourceSize, File1Buffer); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_READ_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Status = LoadEfiDriversFromRomImage ( - File1Buffer, - SourceSize, - Node->FullName - ); - - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_LOAD_PCI_ROM_RES), gShellDebug1HiiHandle, Node->FullName, Status); - } - - FreePool (File1Buffer); - } - } else if (ShellStatus == SHELL_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, "loadpcirom"); - ShellStatus = SHELL_NOT_FOUND; - } - - if ((FileList != NULL) && !IsListEmpty (&FileList->Link)) { - Status = ShellCloseFileMetaArg (&FileList); - } - - FileList = NULL; - - if (Connect) { - Status = LoadPciRomConnectAllDriversToAllControllers (); - } + if (Connect) { + Status = LoadPciRomConnectAllDriversToAllControllers (); } } From da181122b1640e603c668ef6e10e1aec9e1ca47d Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:16:44 +0200 Subject: [PATCH 366/406] ShellPkg/UefiShellDebug1: Return if ShellCommandLineParse() failed (3/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Return directly if ShellCommandLineParse() returned an error Status. In such case, the "Package" that should be allocated by ShellCommandLineParse() is already freed in: ShellCommandLineParse() \-ShellCommandLineParseEx() \-InternalCommandLineParse() so there is no need to free it with ShellCommandLineFreeVarList(). To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - MemMap.c - Mm.c - Mode.c - Pci.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../UefiShellDebug1CommandsLib/MemMap.c | 66 +- .../Library/UefiShellDebug1CommandsLib/Mm.c | 362 ++++----- .../Library/UefiShellDebug1CommandsLib/Mode.c | 120 +-- .../Library/UefiShellDebug1CommandsLib/Pci.c | 732 +++++++++--------- 4 files changed, 644 insertions(+), 636 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c index 1cf7843434..56adc4c0c3 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c @@ -377,44 +377,46 @@ ShellCommandRunMemMap ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) > 1) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"memmap"); + ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ShellCommandLineGetCount (Package) > 1) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"memmap"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { + Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version); + if (Status == EFI_BUFFER_TOO_SMALL) { + Size += SIZE_1KB; + Descriptors = AllocateZeroPool (Size); + if (Descriptors == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"memmap"); + ShellCommandLineFreeVarList (Package); + return SHELL_OUT_OF_RESOURCES; + } + Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version); - if (Status == EFI_BUFFER_TOO_SMALL) { - Size += SIZE_1KB; - Descriptors = AllocateZeroPool (Size); - if (Descriptors == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"memmap"); - ShellCommandLineFreeVarList (Package); - return SHELL_OUT_OF_RESOURCES; - } - - Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version); - } - - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_GET_FAILED), gShellDebug1HiiHandle, L"memmap"); - ShellStatus = SHELL_ACCESS_DENIED; - } else { - ASSERT (Version == EFI_MEMORY_DESCRIPTOR_VERSION); - - Sfo = ShellCommandLineGetFlag (Package, L"-sfo"); - if (!Sfo) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_LIST_HEAD), gShellDebug1HiiHandle); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"memmap"); - } - - ParseMemoryDescriptors (Descriptors, Size, ItemSize, Sfo); - } } - ShellCommandLineFreeVarList (Package); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_GET_FAILED), gShellDebug1HiiHandle, L"memmap"); + ShellStatus = SHELL_ACCESS_DENIED; + } else { + ASSERT (Version == EFI_MEMORY_DESCRIPTOR_VERSION); + + Sfo = ShellCommandLineGetFlag (Package, L"-sfo"); + if (!Sfo) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_LIST_HEAD), gShellDebug1HiiHandle); + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"memmap"); + } + + ParseMemoryDescriptors (Descriptors, Size, ItemSize, Sfo); + } } + ShellCommandLineFreeVarList (Package); + if (Descriptors != NULL) { FreePool (Descriptors); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c index f021f05479..de10f4ef6a 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c @@ -456,212 +456,214 @@ ShellCommandRunMm ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) < 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"mm"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } else if (ShellCommandLineGetCount (Package) > 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } else if (ShellCommandLineGetFlag (Package, L"-w") && (ShellCommandLineGetValue (Package, L"-w") == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"mm", L"-w"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; } else { - if (ShellCommandLineGetCount (Package) < 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } else if (ShellCommandLineGetCount (Package) > 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } else if (ShellCommandLineGetFlag (Package, L"-w") && (ShellCommandLineGetValue (Package, L"-w") == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"mm", L"-w"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } else { - if (ShellCommandLineGetFlag (Package, L"-mmio")) { - AccessType = ShellMmMemoryMappedIo; - if ( ShellCommandLineGetFlag (Package, L"-mem") - || ShellCommandLineGetFlag (Package, L"-io") - || ShellCommandLineGetFlag (Package, L"-pci") - || ShellCommandLineGetFlag (Package, L"-pcie") - ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } else if (ShellCommandLineGetFlag (Package, L"-mem")) { - AccessType = ShellMmMemory; - if ( ShellCommandLineGetFlag (Package, L"-io") - || ShellCommandLineGetFlag (Package, L"-pci") - || ShellCommandLineGetFlag (Package, L"-pcie") - ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } else if (ShellCommandLineGetFlag (Package, L"-io")) { - AccessType = ShellMmIo; - if ( ShellCommandLineGetFlag (Package, L"-pci") - || ShellCommandLineGetFlag (Package, L"-pcie") - ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } else if (ShellCommandLineGetFlag (Package, L"-pci")) { - AccessType = ShellMmPci; - if (ShellCommandLineGetFlag (Package, L"-pcie") + if (ShellCommandLineGetFlag (Package, L"-mmio")) { + AccessType = ShellMmMemoryMappedIo; + if ( ShellCommandLineGetFlag (Package, L"-mem") + || ShellCommandLineGetFlag (Package, L"-io") + || ShellCommandLineGetFlag (Package, L"-pci") + || ShellCommandLineGetFlag (Package, L"-pcie") ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } else if (ShellCommandLineGetFlag (Package, L"-pcie")) { - AccessType = ShellMmPciExpress; + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; } + } else if (ShellCommandLineGetFlag (Package, L"-mem")) { + AccessType = ShellMmMemory; + if ( ShellCommandLineGetFlag (Package, L"-io") + || ShellCommandLineGetFlag (Package, L"-pci") + || ShellCommandLineGetFlag (Package, L"-pcie") + ) + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } else if (ShellCommandLineGetFlag (Package, L"-io")) { + AccessType = ShellMmIo; + if ( ShellCommandLineGetFlag (Package, L"-pci") + || ShellCommandLineGetFlag (Package, L"-pcie") + ) + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } else if (ShellCommandLineGetFlag (Package, L"-pci")) { + AccessType = ShellMmPci; + if (ShellCommandLineGetFlag (Package, L"-pcie") + ) + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } else if (ShellCommandLineGetFlag (Package, L"-pcie")) { + AccessType = ShellMmPciExpress; } + } - // - // Non interactive for a script file or for the specific parameter - // - Interactive = TRUE; - if (gEfiShellProtocol->BatchIsActive () || ShellCommandLineGetFlag (Package, L"-n")) { - Interactive = FALSE; - } + // + // Non interactive for a script file or for the specific parameter + // + Interactive = TRUE; + if (gEfiShellProtocol->BatchIsActive () || ShellCommandLineGetFlag (Package, L"-n")) { + Interactive = FALSE; + } - Temp = ShellCommandLineGetValue (Package, L"-w"); - if (Temp != NULL) { - Size = ShellStrToUintn (Temp); - } + Temp = ShellCommandLineGetValue (Package, L"-w"); + if (Temp != NULL) { + Size = ShellStrToUintn (Temp); + } - if ((Size != 1) && (Size != 2) && (Size != 4) && (Size != 8)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"mm", Temp, L"-w"); - ShellStatus = SHELL_INVALID_PARAMETER; + if ((Size != 1) && (Size != 2) && (Size != 4) && (Size != 8)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"mm", Temp, L"-w"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + Temp = ShellCommandLineGetRawValue (Package, 1); + if (Temp == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mm", L"NULL"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + Status = ShellConvertStringToUint64 (Temp, &Address, TRUE, FALSE); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mm", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + if ((Address & (Size - 1)) != 0) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_NOT_ALIGNED), gShellDebug1HiiHandle, L"mm", Address); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + // + // locate IO protocol interface + // + HasPciRootBridgeIo = ShellMmLocateIoProtocol (AccessType, Address, &CpuIo, &PciRootBridgeIo); + if ((AccessType == ShellMmPci) || (AccessType == ShellMmPciExpress)) { + if (!HasPciRootBridgeIo) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle, L"mm"); + ShellStatus = SHELL_NOT_FOUND; goto Done; } - Temp = ShellCommandLineGetRawValue (Package, 1); - if (Temp == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mm", L"NULL"); + if (PciRootBridgeIo == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_PCIE_ADDRESS_RANGE), gShellDebug1HiiHandle, L"mm", Address); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } + } - Status = ShellConvertStringToUint64 (Temp, &Address, TRUE, FALSE); + // + // Mode 1: Directly set a value + // + Temp = ShellCommandLineGetRawValue (Package, 2); + if (Temp != NULL) { + Status = ShellConvertStringToUint64 (Temp, &Value, TRUE, FALSE); if (EFI_ERROR (Status)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mm", Temp); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } - if ((Address & (Size - 1)) != 0) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_NOT_ALIGNED), gShellDebug1HiiHandle, L"mm", Address); + if (Value > mShellMmMaxNumber[Size]) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mm", Temp); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } - // - // locate IO protocol interface - // - HasPciRootBridgeIo = ShellMmLocateIoProtocol (AccessType, Address, &CpuIo, &PciRootBridgeIo); - if ((AccessType == ShellMmPci) || (AccessType == ShellMmPciExpress)) { - if (!HasPciRootBridgeIo) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } - - if (PciRootBridgeIo == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_PCIE_ADDRESS_RANGE), gShellDebug1HiiHandle, L"mm", Address); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - // - // Mode 1: Directly set a value - // - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp != NULL) { - Status = ShellConvertStringToUint64 (Temp, &Value, TRUE, FALSE); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mm", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (Value > mShellMmMaxNumber[Size]) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mm", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, FALSE, Address, Size, &Value); - goto Done; - } - - // - // Mode 2: Directly show a value - // - if (!Interactive) { - if (!gEfiShellProtocol->BatchIsActive ()) { - ShellPrintHiiDefaultEx (mShellMmAccessTypeStr[AccessType], gShellDebug1HiiHandle); - } - - ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, TRUE, Address, Size, &Buffer); - - if (!gEfiShellProtocol->BatchIsActive ()) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address); - } - - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_BUF), gShellDebug1HiiHandle, Size * 2, Buffer & mShellMmMaxNumber[Size]); - ShellPrintDefaultEx (L"\r\n"); - goto Done; - } - - // - // Mode 3: Show or set values in interactive mode - // - Complete = FALSE; - do { - ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, TRUE, Address, Size, &Buffer); - ShellPrintHiiDefaultEx (mShellMmAccessTypeStr[AccessType], gShellDebug1HiiHandle); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_BUF), gShellDebug1HiiHandle, Size * 2, Buffer & mShellMmMaxNumber[Size]); - ShellPrintDefaultEx (L" > "); - // - // wait user input to modify - // - if (InputStr != NULL) { - FreePool (InputStr); - InputStr = NULL; - } - - ShellPromptForResponse (ShellPromptResponseTypeFreeform, NULL, (VOID **)&InputStr); - - if (InputStr != NULL) { - // - // skip space characters - // - for (Index = 0; InputStr[Index] == ' '; Index++) { - } - - if (InputStr[Index] != CHAR_NULL) { - if ((InputStr[Index] == '.') || (InputStr[Index] == 'q') || (InputStr[Index] == 'Q')) { - Complete = TRUE; - } else if (!EFI_ERROR (ShellConvertStringToUint64 (InputStr + Index, &Buffer, TRUE, TRUE)) && - (Buffer <= mShellMmMaxNumber[Size]) - ) - { - ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, FALSE, Address, Size, &Buffer); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_ERROR), gShellDebug1HiiHandle, L"mm"); - continue; - } - } - } - - Address += Size; - ShellPrintDefaultEx (L"\r\n"); - } while (!Complete); + ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, FALSE, Address, Size, &Value); + goto Done; } + // + // Mode 2: Directly show a value + // + if (!Interactive) { + if (!gEfiShellProtocol->BatchIsActive ()) { + ShellPrintHiiDefaultEx (mShellMmAccessTypeStr[AccessType], gShellDebug1HiiHandle); + } + + ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, TRUE, Address, Size, &Buffer); + + if (!gEfiShellProtocol->BatchIsActive ()) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address); + } + + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_BUF), gShellDebug1HiiHandle, Size * 2, Buffer & mShellMmMaxNumber[Size]); + ShellPrintDefaultEx (L"\r\n"); + goto Done; + } + + // + // Mode 3: Show or set values in interactive mode + // + Complete = FALSE; + do { + ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, TRUE, Address, Size, &Buffer); + ShellPrintHiiDefaultEx (mShellMmAccessTypeStr[AccessType], gShellDebug1HiiHandle); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_BUF), gShellDebug1HiiHandle, Size * 2, Buffer & mShellMmMaxNumber[Size]); + ShellPrintDefaultEx (L" > "); + // + // wait user input to modify + // + if (InputStr != NULL) { + FreePool (InputStr); + InputStr = NULL; + } + + ShellPromptForResponse (ShellPromptResponseTypeFreeform, NULL, (VOID **)&InputStr); + + if (InputStr != NULL) { + // + // skip space characters + // + for (Index = 0; InputStr[Index] == ' '; Index++) { + } + + if (InputStr[Index] != CHAR_NULL) { + if ((InputStr[Index] == '.') || (InputStr[Index] == 'q') || (InputStr[Index] == 'Q')) { + Complete = TRUE; + } else if (!EFI_ERROR (ShellConvertStringToUint64 (InputStr + Index, &Buffer, TRUE, TRUE)) && + (Buffer <= mShellMmMaxNumber[Size]) + ) + { + ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, FALSE, Address, Size, &Buffer); + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_ERROR), gShellDebug1HiiHandle, L"mm"); + continue; + } + } + } + + Address += Size; + ShellPrintDefaultEx (L"\r\n"); + } while (!Complete); + ASSERT (ShellStatus == SHELL_SUCCESS); Done: diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c index 650300eb85..e5d405638c 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c @@ -58,76 +58,78 @@ ShellCommandRunMode ( } else { ASSERT (FALSE); } - } else { - if (ShellCommandLineGetCount (Package) > 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mode"); + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) > 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mode"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount (Package) == 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"mode"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount (Package) == 3) { + Temp = ShellCommandLineGetRawValue (Package, 1); + if (Temp == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) == 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"mode"); + } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) == 3) { - Temp = ShellCommandLineGetRawValue (Package, 1); - if (Temp == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; + } + + NewCol = ShellStrToUintn (Temp); + Temp = ShellCommandLineGetRawValue (Package, 2); + if (Temp == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + NewRow = ShellStrToUintn (Temp); + + for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS; LoopVar++) { + Status = gST->ConOut->QueryMode (gST->ConOut, LoopVar, &Col, &Row); + if (EFI_ERROR (Status)) { + continue; } - NewCol = ShellStrToUintn (Temp); - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - NewRow = ShellStrToUintn (Temp); - - for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS; LoopVar++) { - Status = gST->ConOut->QueryMode (gST->ConOut, LoopVar, &Col, &Row); + if ((Col == NewCol) && (Row == NewRow)) { + Status = gST->ConOut->SetMode (gST->ConOut, LoopVar); if (EFI_ERROR (Status)) { - continue; + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_SET_FAIL), gShellDebug1HiiHandle, L"mode"); + ShellStatus = SHELL_DEVICE_ERROR; + } else { + // worked fine... + Done = TRUE; } - if ((Col == NewCol) && (Row == NewRow)) { - Status = gST->ConOut->SetMode (gST->ConOut, LoopVar); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_SET_FAIL), gShellDebug1HiiHandle, L"mode"); - ShellStatus = SHELL_DEVICE_ERROR; - } else { - // worked fine... - Done = TRUE; - } - - break; - } - } - - if (!Done) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_NO_MATCH), gShellDebug1HiiHandle, L"mode"); - ShellStatus = SHELL_INVALID_PARAMETER; - } - } else if (ShellCommandLineGetCount (Package) == 1) { - // - // print out valid - // - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_LIST_HEAD), gShellDebug1HiiHandle); - for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS; LoopVar++) { - Status = gST->ConOut->QueryMode (gST->ConOut, LoopVar, &Col, &Row); - if (EFI_ERROR (Status)) { - continue; - } - - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_LIST_ITEM), gShellDebug1HiiHandle, Col, Row, LoopVar == gST->ConOut->Mode->Mode ? L'*' : L' '); + break; } } - ShellCommandLineFreeVarList (Package); + if (!Done) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_NO_MATCH), gShellDebug1HiiHandle, L"mode"); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } else if (ShellCommandLineGetCount (Package) == 1) { + // + // print out valid + // + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_LIST_HEAD), gShellDebug1HiiHandle); + for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS; LoopVar++) { + Status = gST->ConOut->QueryMode (gST->ConOut, LoopVar, &Col, &Row); + if (EFI_ERROR (Status)) { + continue; + } + + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_LIST_ITEM), gShellDebug1HiiHandle, Col, Row, LoopVar == gST->ConOut->Mode->Mode ? L'*' : L' '); + } } + ShellCommandLineFreeVarList (Package); + return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c index 6410dda30b..191518e55d 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -2524,38 +2524,57 @@ ShellCommandRunPci ( } else { ASSERT (FALSE); } - } else { - if (ShellCommandLineGetCount (Package) == 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - if (ShellCommandLineGetCount (Package) > 4) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + return ShellStatus; + } - if (ShellCommandLineGetFlag (Package, L"-ec") && (ShellCommandLineGetValue (Package, L"-ec") == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"pci", L"-ec"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + if (ShellCommandLineGetCount (Package) == 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"pci"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } - if (ShellCommandLineGetFlag (Package, L"-s") && (ShellCommandLineGetValue (Package, L"-s") == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"pci", L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + if (ShellCommandLineGetCount (Package) > 4) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"pci"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } - // - // Get all instances of PciRootBridgeIo. Allocate space for 1 EFI_HANDLE and - // call LibLocateHandle(), if EFI_BUFFER_TOO_SMALL is returned, allocate enough - // space for handles and call it again. - // - HandleBufSize = sizeof (EFI_HANDLE); - HandleBuf = (EFI_HANDLE *)AllocateZeroPool (HandleBufSize); + if (ShellCommandLineGetFlag (Package, L"-ec") && (ShellCommandLineGetValue (Package, L"-ec") == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"pci", L"-ec"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + if (ShellCommandLineGetFlag (Package, L"-s") && (ShellCommandLineGetValue (Package, L"-s") == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"pci", L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + // + // Get all instances of PciRootBridgeIo. Allocate space for 1 EFI_HANDLE and + // call LibLocateHandle(), if EFI_BUFFER_TOO_SMALL is returned, allocate enough + // space for handles and call it again. + // + HandleBufSize = sizeof (EFI_HANDLE); + HandleBuf = (EFI_HANDLE *)AllocateZeroPool (HandleBufSize); + if (HandleBuf == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"pci"); + ShellStatus = SHELL_OUT_OF_RESOURCES; + goto Done; + } + + Status = gBS->LocateHandle ( + ByProtocol, + &gEfiPciRootBridgeIoProtocolGuid, + NULL, + &HandleBufSize, + HandleBuf + ); + + if (Status == EFI_BUFFER_TOO_SMALL) { + HandleBuf = ReallocatePool (sizeof (EFI_HANDLE), HandleBufSize, HandleBuf); if (HandleBuf == NULL) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"pci"); ShellStatus = SHELL_OUT_OF_RESOURCES; @@ -2569,407 +2588,390 @@ ShellCommandRunPci ( &HandleBufSize, HandleBuf ); + } - if (Status == EFI_BUFFER_TOO_SMALL) { - HandleBuf = ReallocatePool (sizeof (EFI_HANDLE), HandleBufSize, HandleBuf); - if (HandleBuf == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_OUT_OF_RESOURCES; + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle, L"pci"); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + + HandleCount = HandleBufSize / sizeof (EFI_HANDLE); + // + // Argument Count == 1(no other argument): enumerate all pci functions + // + if (ShellCommandLineGetCount (Package) == 1) { + gST->ConOut->QueryMode ( + gST->ConOut, + gST->ConOut->Mode->Mode, + &TempColumn, + &ScreenSize + ); + + ScreenCount = 0; + ScreenSize -= 4; + if ((ScreenSize & 1) == 1) { + ScreenSize -= 1; + } + + PrintTitle = TRUE; + + // + // For each handle, which decides a segment and a bus number range, + // enumerate all devices on it. + // + for (Index = 0; Index < HandleCount; Index++) { + Status = PciGetProtocolAndResource ( + HandleBuf[Index], + &IoDev, + &Descriptors + ); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_HANDLE_CFG_ERR), gShellDebug1HiiHandle, L"pci"); + ShellStatus = SHELL_NOT_FOUND; goto Done; } - Status = gBS->LocateHandle ( - ByProtocol, - &gEfiPciRootBridgeIoProtocolGuid, - NULL, - &HandleBufSize, - HandleBuf - ); - } - - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } - - HandleCount = HandleBufSize / sizeof (EFI_HANDLE); - // - // Argument Count == 1(no other argument): enumerate all pci functions - // - if (ShellCommandLineGetCount (Package) == 1) { - gST->ConOut->QueryMode ( - gST->ConOut, - gST->ConOut->Mode->Mode, - &TempColumn, - &ScreenSize - ); - - ScreenCount = 0; - ScreenSize -= 4; - if ((ScreenSize & 1) == 1) { - ScreenSize -= 1; - } - - PrintTitle = TRUE; - // - // For each handle, which decides a segment and a bus number range, - // enumerate all devices on it. + // No document say it's impossible for a RootBridgeIo protocol handle + // to have more than one address space descriptors, so find out every + // bus range and for each of them do device enumeration. // - for (Index = 0; Index < HandleCount; Index++) { - Status = PciGetProtocolAndResource ( - HandleBuf[Index], - &IoDev, - &Descriptors - ); + while (TRUE) { + Status = PciGetNextBusRange (&Descriptors, &MinBus, &MaxBus, &IsEnd); + if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_HANDLE_CFG_ERR), gShellDebug1HiiHandle, L"pci"); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_BUS_RANGE_ERR), gShellDebug1HiiHandle, L"pci"); ShellStatus = SHELL_NOT_FOUND; goto Done; } - // - // No document say it's impossible for a RootBridgeIo protocol handle - // to have more than one address space descriptors, so find out every - // bus range and for each of them do device enumeration. - // - while (TRUE) { - Status = PciGetNextBusRange (&Descriptors, &MinBus, &MaxBus, &IsEnd); + if (IsEnd) { + break; + } - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_BUS_RANGE_ERR), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } - - if (IsEnd) { - break; - } - - for (Bus = MinBus; Bus <= MaxBus; Bus++) { + for (Bus = MinBus; Bus <= MaxBus; Bus++) { + // + // For each devices, enumerate all functions it contains + // + for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) { // - // For each devices, enumerate all functions it contains + // For each function, read its configuration space and print summary // - for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) { + for (Func = 0; Func <= PCI_MAX_FUNC; Func++) { + if (ShellGetExecutionBreakFlag ()) { + ShellStatus = SHELL_ABORTED; + goto Done; + } + + Address = EFI_PCI_ADDRESS (Bus, Device, Func, 0); + IoDev->Pci.Read ( + IoDev, + EfiPciWidthUint16, + Address, + 1, + &PciHeader.VendorId + ); + // - // For each function, read its configuration space and print summary + // If VendorId = 0xffff, there does not exist a device at this + // location. For each device, if there is any function on it, + // there must be 1 function at Function 0. So if Func = 0, there + // will be no more functions in the same device, so we can break + // loop to deal with the next device. // - for (Func = 0; Func <= PCI_MAX_FUNC; Func++) { - if (ShellGetExecutionBreakFlag ()) { - ShellStatus = SHELL_ABORTED; - goto Done; + if ((PciHeader.VendorId == 0xffff) && (Func == 0)) { + break; + } + + if (PciHeader.VendorId != 0xffff) { + if (PrintTitle) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_TITLE), gShellDebug1HiiHandle); + PrintTitle = FALSE; } - Address = EFI_PCI_ADDRESS (Bus, Device, Func, 0); IoDev->Pci.Read ( IoDev, - EfiPciWidthUint16, + EfiPciWidthUint32, Address, - 1, - &PciHeader.VendorId + sizeof (PciHeader) / sizeof (UINT32), + &PciHeader ); - // - // If VendorId = 0xffff, there does not exist a device at this - // location. For each device, if there is any function on it, - // there must be 1 function at Function 0. So if Func = 0, there - // will be no more functions in the same device, so we can break - // loop to deal with the next device. - // - if ((PciHeader.VendorId == 0xffff) && (Func == 0)) { - break; + ShellPrintHiiDefaultEx ( + STRING_TOKEN (STR_PCI_LINE_P1), + gShellDebug1HiiHandle, + IoDev->SegmentNumber, + Bus, + Device, + Func + ); + + PciPrintClassCode (PciHeader.ClassCode, FALSE); + ShellPrintHiiDefaultEx ( + STRING_TOKEN (STR_PCI_LINE_P2), + gShellDebug1HiiHandle, + PciHeader.VendorId, + PciHeader.DeviceId, + PciHeader.ClassCode[0] + ); + + ScreenCount += 2; + if ((ScreenCount >= ScreenSize) && (ScreenSize != 0)) { + // + // If ScreenSize == 0 we have the console redirected so don't + // block updates + // + ScreenCount = 0; } - if (PciHeader.VendorId != 0xffff) { - if (PrintTitle) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_TITLE), gShellDebug1HiiHandle); - PrintTitle = FALSE; - } - - IoDev->Pci.Read ( - IoDev, - EfiPciWidthUint32, - Address, - sizeof (PciHeader) / sizeof (UINT32), - &PciHeader - ); - - ShellPrintHiiDefaultEx ( - STRING_TOKEN (STR_PCI_LINE_P1), - gShellDebug1HiiHandle, - IoDev->SegmentNumber, - Bus, - Device, - Func - ); - - PciPrintClassCode (PciHeader.ClassCode, FALSE); - ShellPrintHiiDefaultEx ( - STRING_TOKEN (STR_PCI_LINE_P2), - gShellDebug1HiiHandle, - PciHeader.VendorId, - PciHeader.DeviceId, - PciHeader.ClassCode[0] - ); - - ScreenCount += 2; - if ((ScreenCount >= ScreenSize) && (ScreenSize != 0)) { - // - // If ScreenSize == 0 we have the console redirected so don't - // block updates - // - ScreenCount = 0; - } - - // - // If this is not a multi-function device, we can leave the loop - // to deal with the next device. - // - if ((Func == 0) && ((PciHeader.HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00)) { - break; - } + // + // If this is not a multi-function device, we can leave the loop + // to deal with the next device. + // + if ((Func == 0) && ((PciHeader.HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00)) { + break; } } } } + } - // - // If Descriptor is NULL, Configuration() returns EFI_UNSUPPRORED, - // we assume the bus range is 0~PCI_MAX_BUS. After enumerated all - // devices on all bus, we can leave loop. - // - if (Descriptors == NULL) { - break; - } + // + // If Descriptor is NULL, Configuration() returns EFI_UNSUPPRORED, + // we assume the bus range is 0~PCI_MAX_BUS. After enumerated all + // devices on all bus, we can leave loop. + // + if (Descriptors == NULL) { + break; } } + } - Status = EFI_SUCCESS; + Status = EFI_SUCCESS; + goto Done; + } + + ExplainData = FALSE; + Segment = 0; + Bus = 0; + Device = 0; + Func = 0; + ExtendedCapability = 0xFFFF; + if (ShellCommandLineGetFlag (Package, L"-i")) { + ExplainData = TRUE; + } + + Temp = ShellCommandLineGetValue (Package, L"-s"); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + Segment = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + + // + // The first Argument(except "-i") is assumed to be Bus number, second + // to be Device number, and third to be Func number. + // + Temp = ShellCommandLineGetRawValue (Package, 1); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + Bus = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } - ExplainData = FALSE; - Segment = 0; - Bus = 0; - Device = 0; - Func = 0; - ExtendedCapability = 0xFFFF; - if (ShellCommandLineGetFlag (Package, L"-i")) { - ExplainData = TRUE; - } - - Temp = ShellCommandLineGetValue (Package, L"-s"); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - Segment = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + if (Bus > PCI_MAX_BUS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; } + } + Temp = ShellCommandLineGetRawValue (Package, 2); + if (Temp != NULL) { // - // The first Argument(except "-i") is assumed to be Bus number, second - // to be Device number, and third to be Func number. + // Input converted to hexadecimal number. // - Temp = ShellCommandLineGetRawValue (Package, 1); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - Bus = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (Bus > PCI_MAX_BUS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - Device = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (Device > PCI_MAX_DEVICE) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - Temp = ShellCommandLineGetRawValue (Package, 3); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - Func = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (Func > PCI_MAX_FUNC) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - Temp = ShellCommandLineGetValue (Package, L"-ec"); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - ExtendedCapability = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - // - // Find the protocol interface who's in charge of current segment, and its - // bus range covers the current bus - // - Status = PciFindProtocolInterface ( - HandleBuf, - HandleCount, - Segment, - Bus, - &IoDev - ); - - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx ( - STRING_TOKEN (STR_PCI_NO_FIND), - gShellDebug1HiiHandle, - L"pci", - Segment, - Bus - ); - ShellStatus = SHELL_NOT_FOUND; + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + Device = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } - Address = EFI_PCI_ADDRESS (Bus, Device, Func, 0); - Status = IoDev->Pci.Read ( - IoDev, - EfiPciWidthUint8, - Address, - sizeof (ConfigSpace), - &ConfigSpace - ); + if (Device > PCI_MAX_DEVICE) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_NO_CFG), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_ACCESS_DENIED; + Temp = ShellCommandLineGetRawValue (Package, 3); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + Func = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } - mConfigSpace = &ConfigSpace; + if (Func > PCI_MAX_FUNC) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + + Temp = ShellCommandLineGetValue (Package, L"-ec"); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + ExtendedCapability = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + + // + // Find the protocol interface who's in charge of current segment, and its + // bus range covers the current bus + // + Status = PciFindProtocolInterface ( + HandleBuf, + HandleCount, + Segment, + Bus, + &IoDev + ); + + if (EFI_ERROR (Status)) { ShellPrintHiiDefaultEx ( - STRING_TOKEN (STR_PCI_INFO), + STRING_TOKEN (STR_PCI_NO_FIND), gShellDebug1HiiHandle, + L"pci", Segment, - Bus, - Device, - Func, - Segment, - Bus, - Device, - Func + Bus ); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } - // - // Dump standard header of configuration space - // - SizeOfHeader = sizeof (ConfigSpace.Common) + sizeof (ConfigSpace.NonCommon); + Address = EFI_PCI_ADDRESS (Bus, Device, Func, 0); + Status = IoDev->Pci.Read ( + IoDev, + EfiPciWidthUint8, + Address, + sizeof (ConfigSpace), + &ConfigSpace + ); - DumpHex (2, 0, SizeOfHeader, &ConfigSpace); - ShellPrintDefaultEx (L"\r\n"); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_NO_CFG), gShellDebug1HiiHandle, L"pci"); + ShellStatus = SHELL_ACCESS_DENIED; + goto Done; + } + mConfigSpace = &ConfigSpace; + ShellPrintHiiDefaultEx ( + STRING_TOKEN (STR_PCI_INFO), + gShellDebug1HiiHandle, + Segment, + Bus, + Device, + Func, + Segment, + Bus, + Device, + Func + ); + + // + // Dump standard header of configuration space + // + SizeOfHeader = sizeof (ConfigSpace.Common) + sizeof (ConfigSpace.NonCommon); + + DumpHex (2, 0, SizeOfHeader, &ConfigSpace); + ShellPrintDefaultEx (L"\r\n"); + + // + // Dump device dependent Part of configuration space + // + DumpHex ( + 2, + SizeOfHeader, + sizeof (ConfigSpace) - SizeOfHeader, + ConfigSpace.Data + ); + + ExtendedConfigSpace = NULL; + ExtendedConfigSize = 0; + PcieCapabilityPtr = LocatePciCapability (&ConfigSpace, EFI_PCI_CAPABILITY_ID_PCIEXP); + if (PcieCapabilityPtr != 0) { + ExtendedConfigSize = 0x1000 - EFI_PCIE_CAPABILITY_BASE_OFFSET; + ExtendedConfigSpace = AllocatePool (ExtendedConfigSize); + if (ExtendedConfigSpace != NULL) { + Status = IoDev->Pci.Read ( + IoDev, + EfiPciWidthUint32, + EFI_PCI_ADDRESS (Bus, Device, Func, EFI_PCIE_CAPABILITY_BASE_OFFSET), + ExtendedConfigSize / sizeof (UINT32), + ExtendedConfigSpace + ); + if (EFI_ERROR (Status)) { + SHELL_FREE_NON_NULL (ExtendedConfigSpace); + } + } + } + + if ((ExtendedConfigSpace != NULL) && !ShellGetExecutionBreakFlag ()) { // - // Dump device dependent Part of configuration space + // Print the PciEx extend space in raw bytes ( 0xFF-0xFFF) // + ShellPrintDefaultEx (L"\r\n%HStart dumping PCIex extended configuration space (0x100 - 0xFFF).%N\r\n\r\n"); + DumpHex ( 2, - SizeOfHeader, - sizeof (ConfigSpace) - SizeOfHeader, - ConfigSpace.Data + EFI_PCIE_CAPABILITY_BASE_OFFSET, + ExtendedConfigSize, + ExtendedConfigSpace ); + } - ExtendedConfigSpace = NULL; - ExtendedConfigSize = 0; - PcieCapabilityPtr = LocatePciCapability (&ConfigSpace, EFI_PCI_CAPABILITY_ID_PCIEXP); - if (PcieCapabilityPtr != 0) { - ExtendedConfigSize = 0x1000 - EFI_PCIE_CAPABILITY_BASE_OFFSET; - ExtendedConfigSpace = AllocatePool (ExtendedConfigSize); - if (ExtendedConfigSpace != NULL) { - Status = IoDev->Pci.Read ( - IoDev, - EfiPciWidthUint32, - EFI_PCI_ADDRESS (Bus, Device, Func, EFI_PCIE_CAPABILITY_BASE_OFFSET), - ExtendedConfigSize / sizeof (UINT32), - ExtendedConfigSpace - ); - if (EFI_ERROR (Status)) { - SHELL_FREE_NON_NULL (ExtendedConfigSpace); - } - } - } - + // + // If "-i" appears in command line, interpret data in configuration space + // + if (ExplainData) { + PciExplainPci (&ConfigSpace, Address, IoDev); if ((ExtendedConfigSpace != NULL) && !ShellGetExecutionBreakFlag ()) { - // - // Print the PciEx extend space in raw bytes ( 0xFF-0xFFF) - // - ShellPrintDefaultEx (L"\r\n%HStart dumping PCIex extended configuration space (0x100 - 0xFFF).%N\r\n\r\n"); - - DumpHex ( - 2, - EFI_PCIE_CAPABILITY_BASE_OFFSET, + PciExplainPciExpress ( + (PCI_CAPABILITY_PCIEXP *)((UINT8 *)&ConfigSpace + PcieCapabilityPtr), + ExtendedConfigSpace, ExtendedConfigSize, - ExtendedConfigSpace + ExtendedCapability ); } - - // - // If "-i" appears in command line, interpret data in configuration space - // - if (ExplainData) { - PciExplainPci (&ConfigSpace, Address, IoDev); - if ((ExtendedConfigSpace != NULL) && !ShellGetExecutionBreakFlag ()) { - PciExplainPciExpress ( - (PCI_CAPABILITY_PCIEXP *)((UINT8 *)&ConfigSpace + PcieCapabilityPtr), - ExtendedConfigSpace, - ExtendedConfigSize, - ExtendedCapability - ); - } - } } Done: From 6dea226953e817a24519022b823b62326eaf9bf8 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:17:02 +0200 Subject: [PATCH 367/406] ShellPkg/UefiShellDebug1: Return if ShellCommandLineParse() failed (4/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Return directly if ShellCommandLineParse() returned an error Status. In such case, the "Package" that should be allocated by ShellCommandLineParse() is already freed in: ShellCommandLineParse() \-ShellCommandLineParseEx() \-InternalCommandLineParse() so there is no need to free it with ShellCommandLineFreeVarList(). To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - SerMode.c - SetSize.c - SetVar.c - SmbiosView/SmbiosView.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../UefiShellDebug1CommandsLib/SerMode.c | 210 ++++++++--------- .../UefiShellDebug1CommandsLib/SetSize.c | 92 ++++---- .../UefiShellDebug1CommandsLib/SetVar.c | 203 ++++++++--------- .../SmbiosView/SmbiosView.c | 212 +++++++++--------- 4 files changed, 363 insertions(+), 354 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c index 8fbb06e11b..a89fdb8934 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c @@ -285,119 +285,121 @@ ShellCommandRunSerMode ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if ((ShellCommandLineGetCount (Package) < 6) && (ShellCommandLineGetCount (Package) > 2)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"sermode"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount (Package) > 6) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"sermode"); + ShellStatus = SHELL_INVALID_PARAMETER; } else { - if ((ShellCommandLineGetCount (Package) < 6) && (ShellCommandLineGetCount (Package) > 2)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"sermode"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) > 6) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"sermode"); + Temp = ShellCommandLineGetRawValue (Package, 1); + if (Temp != NULL) { + Status = ShellConvertStringToUint64 (Temp, &Intermediate, TRUE, FALSE); + HandleIdx = (UINTN)Intermediate; + Temp = ShellCommandLineGetRawValue (Package, 2); + if (Temp == NULL) { + ShellStatus = DisplaySettings (HandleIdx, TRUE); + goto Done; + } + } else { + ShellStatus = DisplaySettings (0, FALSE); + goto Done; + } + + Temp = ShellCommandLineGetRawValue (Package, 2); + if (Temp != NULL) { + BaudRate = ShellStrToUintn (Temp); + } else { + ASSERT (FALSE); + BaudRate = 0; + } + + Temp = ShellCommandLineGetRawValue (Package, 3); + if ((Temp == NULL) || (StrLen (Temp) > 1)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); ShellStatus = SHELL_INVALID_PARAMETER; } else { - Temp = ShellCommandLineGetRawValue (Package, 1); - if (Temp != NULL) { - Status = ShellConvertStringToUint64 (Temp, &Intermediate, TRUE, FALSE); - HandleIdx = (UINTN)Intermediate; - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp == NULL) { - ShellStatus = DisplaySettings (HandleIdx, TRUE); - goto Done; - } - } else { - ShellStatus = DisplaySettings (0, FALSE); - goto Done; - } - - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp != NULL) { - BaudRate = ShellStrToUintn (Temp); - } else { - ASSERT (FALSE); - BaudRate = 0; - } - - Temp = ShellCommandLineGetRawValue (Package, 3); - if ((Temp == NULL) || (StrLen (Temp) > 1)) { + Status = GetParityType (Temp[0], &Parity); + if (EFI_ERROR (Status)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Status = GetParityType (Temp[0], &Parity); + goto Done; + } + } + + Temp = ShellCommandLineGetRawValue (Package, 4); + if (Temp != NULL) { + DataBits = ShellStrToUintn (Temp); + } else { + // + // make sure this is some number not in the list below. + // + DataBits = 0; + } + + if (!ValidDataBits (DataBits)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + Temp = ShellCommandLineGetRawValue (Package, 5); + if (Temp == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + Status = GetStopBits (ShellStrToUintn (Temp), &StopBits); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Handles); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + + for (Index = 0; Index < NoHandles; Index++) { + if (ConvertHandleIndexToHandle (HandleIdx) != Handles[Index]) { + continue; + } + + Status = gBS->HandleProtocol (Handles[Index], &gEfiSerialIoProtocolGuid, (VOID **)&SerialIo); + if (!EFI_ERROR (Status)) { + Status = SerialIo->SetAttributes ( + SerialIo, + (UINT64)BaudRate, + SerialIo->Mode->ReceiveFifoDepth, + SerialIo->Mode->Timeout, + Parity, + (UINT8)DataBits, + StopBits + ); if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - Temp = ShellCommandLineGetRawValue (Package, 4); - if (Temp != NULL) { - DataBits = ShellStrToUintn (Temp); - } else { - // - // make sure this is some number not in the list below. - // - DataBits = 0; - } - - if (!ValidDataBits (DataBits)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - Temp = ShellCommandLineGetRawValue (Package, 5); - if (Temp == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - Status = GetStopBits (ShellStrToUintn (Temp), &StopBits); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Handles); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - for (Index = 0; Index < NoHandles; Index++) { - if (ConvertHandleIndexToHandle (HandleIdx) != Handles[Index]) { - continue; - } - - Status = gBS->HandleProtocol (Handles[Index], &gEfiSerialIoProtocolGuid, (VOID **)&SerialIo); - if (!EFI_ERROR (Status)) { - Status = SerialIo->SetAttributes ( - SerialIo, - (UINT64)BaudRate, - SerialIo->Mode->ReceiveFifoDepth, - SerialIo->Mode->Timeout, - Parity, - (UINT8)DataBits, - StopBits - ); - if (EFI_ERROR (Status)) { - if (Status == EFI_INVALID_PARAMETER) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_UNSUPPORTED), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); - ShellStatus = SHELL_UNSUPPORTED; - } else if (Status == EFI_DEVICE_ERROR) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_DEV_ERROR), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); - ShellStatus = SHELL_ACCESS_DENIED; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_FAIL), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); - ShellStatus = SHELL_ACCESS_DENIED; - } + if (Status == EFI_INVALID_PARAMETER) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_UNSUPPORTED), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); + ShellStatus = SHELL_UNSUPPORTED; + } else if (Status == EFI_DEVICE_ERROR) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_DEV_ERROR), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); + ShellStatus = SHELL_ACCESS_DENIED; } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_HANDLE), gShellDebug1HiiHandle, ConvertHandleToHandleIndex (Handles[Index])); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_FAIL), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); + ShellStatus = SHELL_ACCESS_DENIED; } - - break; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_HANDLE), gShellDebug1HiiHandle, ConvertHandleToHandleIndex (Handles[Index])); } + + break; } } } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c index 16e24c6642..04348924b3 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c @@ -55,57 +55,59 @@ ShellCommandRunSetSize ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) < 3) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize"); + ShellStatus = SHELL_INVALID_PARAMETER; + NewSize = 0; } else { - if (ShellCommandLineGetCount (Package) < 3) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize"); + Temp1 = ShellCommandLineGetRawValue (Package, 1); + if (Temp1 == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setsize"); + ShellStatus = SHELL_INVALID_PARAMETER; + NewSize = 0; + } else if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize"); ShellStatus = SHELL_INVALID_PARAMETER; NewSize = 0; } else { - Temp1 = ShellCommandLineGetRawValue (Package, 1); - if (Temp1 == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setsize"); - ShellStatus = SHELL_INVALID_PARAMETER; - NewSize = 0; - } else if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize"); - ShellStatus = SHELL_INVALID_PARAMETER; - NewSize = 0; - } else { - NewSize = ShellStrToUintn (Temp1); - } + NewSize = ShellStrToUintn (Temp1); } - - for (LoopVar = 2; LoopVar < ShellCommandLineGetCount (Package) && ShellStatus == SHELL_SUCCESS; LoopVar++) { - Status = ShellOpenFileByName (ShellCommandLineGetRawValue (Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0); - if (EFI_ERROR (Status)) { - Status = ShellOpenFileByName (ShellCommandLineGetRawValue (Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); - } - - if (EFI_ERROR (Status) && (LoopVar == 2)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue (Package, LoopVar)); - ShellStatus = SHELL_INVALID_PARAMETER; - break; - } else { - Status = FileHandleSetSize (FileHandle, NewSize); - if (Status == EFI_VOLUME_FULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_VOLUME_FULL), gShellDebug1HiiHandle, L"setsize"); - ShellStatus = SHELL_VOLUME_FULL; - } else if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SET_SIZE_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue (Package, LoopVar)); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SET_SIZE_DONE), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, LoopVar)); - } - - ShellCloseFile (&FileHandle); - } - } - - ShellCommandLineFreeVarList (Package); } + for (LoopVar = 2; LoopVar < ShellCommandLineGetCount (Package) && ShellStatus == SHELL_SUCCESS; LoopVar++) { + Status = ShellOpenFileByName (ShellCommandLineGetRawValue (Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0); + if (EFI_ERROR (Status)) { + Status = ShellOpenFileByName (ShellCommandLineGetRawValue (Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); + } + + if (EFI_ERROR (Status) && (LoopVar == 2)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue (Package, LoopVar)); + ShellStatus = SHELL_INVALID_PARAMETER; + break; + } else { + Status = FileHandleSetSize (FileHandle, NewSize); + if (Status == EFI_VOLUME_FULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_VOLUME_FULL), gShellDebug1HiiHandle, L"setsize"); + ShellStatus = SHELL_VOLUME_FULL; + } else if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SET_SIZE_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue (Package, LoopVar)); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SET_SIZE_DONE), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, LoopVar)); + } + + ShellCloseFile (&FileHandle); + } + } + + ShellCommandLineFreeVarList (Package); + return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c index 61468ec93a..8f5d419c52 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c @@ -394,121 +394,124 @@ ShellCommandRunSetVar ( } else { ASSERT (FALSE); } + + return ShellStatus; } else if (ShellCommandLineCheckDuplicate (Package, &ProblemParam) != EFI_SUCCESS) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_DUPLICATE), gShellDebug1HiiHandle, L"setvar", ProblemParam); + ShellCommandLineFreeVarList (Package); FreePool (ProblemParam); + return SHELL_INVALID_PARAMETER; + } + + if (ShellCommandLineGetCount (Package) < 2) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setvar"); ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ShellCommandLineGetCount (Package) < 2) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setvar"); - ShellStatus = SHELL_INVALID_PARAMETER; + VariableName = ShellCommandLineGetRawValue (Package, 1); + if (VariableName == NULL) { + ShellCommandLineFreeVarList (Package); + return SHELL_INVALID_PARAMETER; + } + + if (!ShellCommandLineGetFlag (Package, L"-guid")) { + CopyGuid (&Guid, &gEfiGlobalVariableGuid); } else { - VariableName = ShellCommandLineGetRawValue (Package, 1); - if (VariableName == NULL) { + StringGuid = ShellCommandLineGetValue (Package, L"-guid"); + if (StringGuid != NULL) { + RStatus = StrToGuid (StringGuid, &Guid); + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid); ShellCommandLineFreeVarList (Package); return SHELL_INVALID_PARAMETER; } - if (!ShellCommandLineGetFlag (Package, L"-guid")) { - CopyGuid (&Guid, &gEfiGlobalVariableGuid); - } else { - StringGuid = ShellCommandLineGetValue (Package, L"-guid"); - if (StringGuid != NULL) { - RStatus = StrToGuid (StringGuid, &Guid); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid); - ShellCommandLineFreeVarList (Package); - return SHELL_INVALID_PARAMETER; - } - - if (RETURN_ERROR (RStatus) || (StringGuid[GUID_STRING_LENGTH] != L'\0')) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid); - ShellStatus = SHELL_INVALID_PARAMETER; - } - } - - if (ShellCommandLineGetCount (Package) == 2) { - // - // Display - // - Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); - if (Status == EFI_BUFFER_TOO_SMALL) { - Buffer = AllocateZeroPool (Size); - if (Buffer == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar"); - ShellCommandLineFreeVarList (Package); - return SHELL_OUT_OF_RESOURCES; - } - - Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); - } - - if (!EFI_ERROR (Status) && (Buffer != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_PRINT), gShellDebug1HiiHandle, &Guid, VariableName, Size); - for (LoopVar = 0; LoopVar < Size; LoopVar++) { - ShellPrintDefaultEx (L"%02x ", ((UINT8 *)Buffer)[LoopVar]); - } - - ShellPrintDefaultEx (L"\r\n"); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_ERROR_GET), gShellDebug1HiiHandle, L"setvar", &Guid, VariableName); - ShellStatus = SHELL_ACCESS_DENIED; - } - } else { - // - // Create, Delete or Modify. - // - Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); - if (Status == EFI_BUFFER_TOO_SMALL) { - Buffer = AllocateZeroPool (Size); - if (Buffer == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar"); - ShellCommandLineFreeVarList (Package); - return SHELL_OUT_OF_RESOURCES; - } - - Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); - } - - if (EFI_ERROR (Status) || (Buffer == NULL)) { - // - // Creating a new variable. determine attributes from command line. - // - Attributes = 0; - if (ShellCommandLineGetFlag (Package, L"-bs")) { - Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS; - } - - if (ShellCommandLineGetFlag (Package, L"-rt")) { - Attributes |= EFI_VARIABLE_RUNTIME_ACCESS | - EFI_VARIABLE_BOOTSERVICE_ACCESS; - } - - if (ShellCommandLineGetFlag (Package, L"-nv")) { - Attributes |= EFI_VARIABLE_NON_VOLATILE; - } - } - - SHELL_FREE_NON_NULL (Buffer); - - Size = 0; - Status = GetVariableDataFromParameter (Package, (UINT8 **)&Buffer, &Size); - if (!EFI_ERROR (Status)) { - Status = gRT->SetVariable ((CHAR16 *)VariableName, &Guid, Attributes, Size, Buffer); - } - - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, L"setvar", &Guid, VariableName); - ShellStatus = SHELL_ACCESS_DENIED; - } else { - ASSERT (ShellStatus == SHELL_SUCCESS); - } + if (RETURN_ERROR (RStatus) || (StringGuid[GUID_STRING_LENGTH] != L'\0')) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid); + ShellStatus = SHELL_INVALID_PARAMETER; } } - ShellCommandLineFreeVarList (Package); + if (ShellCommandLineGetCount (Package) == 2) { + // + // Display + // + Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); + if (Status == EFI_BUFFER_TOO_SMALL) { + Buffer = AllocateZeroPool (Size); + if (Buffer == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar"); + ShellCommandLineFreeVarList (Package); + return SHELL_OUT_OF_RESOURCES; + } + + Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); + } + + if (!EFI_ERROR (Status) && (Buffer != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_PRINT), gShellDebug1HiiHandle, &Guid, VariableName, Size); + for (LoopVar = 0; LoopVar < Size; LoopVar++) { + ShellPrintDefaultEx (L"%02x ", ((UINT8 *)Buffer)[LoopVar]); + } + + ShellPrintDefaultEx (L"\r\n"); + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_ERROR_GET), gShellDebug1HiiHandle, L"setvar", &Guid, VariableName); + ShellStatus = SHELL_ACCESS_DENIED; + } + } else { + // + // Create, Delete or Modify. + // + Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); + if (Status == EFI_BUFFER_TOO_SMALL) { + Buffer = AllocateZeroPool (Size); + if (Buffer == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar"); + ShellCommandLineFreeVarList (Package); + return SHELL_OUT_OF_RESOURCES; + } + + Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); + } + + if (EFI_ERROR (Status) || (Buffer == NULL)) { + // + // Creating a new variable. determine attributes from command line. + // + Attributes = 0; + if (ShellCommandLineGetFlag (Package, L"-bs")) { + Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS; + } + + if (ShellCommandLineGetFlag (Package, L"-rt")) { + Attributes |= EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_BOOTSERVICE_ACCESS; + } + + if (ShellCommandLineGetFlag (Package, L"-nv")) { + Attributes |= EFI_VARIABLE_NON_VOLATILE; + } + } + + SHELL_FREE_NON_NULL (Buffer); + + Size = 0; + Status = GetVariableDataFromParameter (Package, (UINT8 **)&Buffer, &Size); + if (!EFI_ERROR (Status)) { + Status = gRT->SetVariable ((CHAR16 *)VariableName, &Guid, Attributes, Size, Buffer); + } + + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, L"setvar", &Guid, VariableName); + ShellStatus = SHELL_ACCESS_DENIED; + } else { + ASSERT (ShellStatus == SHELL_SUCCESS); + } + } } + ShellCommandLineFreeVarList (Package); + if (Buffer != NULL) { FreePool (Buffer); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c index ee5eb07918..9162ef1f56 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c @@ -70,131 +70,133 @@ ShellCommandRunSmbiosView ( } else { ASSERT (FALSE); } + + return ShellStatus; + } + + if (ShellCommandLineGetCount (Package) > 1) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetFlag (Package, L"-t") && (ShellCommandLineGetValue (Package, L"-t") == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"smbiosview", L"-t"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetFlag (Package, L"-h") && (ShellCommandLineGetValue (Package, L"-h") == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"smbiosview", L"-h"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if ( + (ShellCommandLineGetFlag (Package, L"-t") && ShellCommandLineGetFlag (Package, L"-h")) || + (ShellCommandLineGetFlag (Package, L"-t") && ShellCommandLineGetFlag (Package, L"-s")) || + (ShellCommandLineGetFlag (Package, L"-t") && ShellCommandLineGetFlag (Package, L"-a")) || + (ShellCommandLineGetFlag (Package, L"-h") && ShellCommandLineGetFlag (Package, L"-s")) || + (ShellCommandLineGetFlag (Package, L"-h") && ShellCommandLineGetFlag (Package, L"-a")) || + (ShellCommandLineGetFlag (Package, L"-s") && ShellCommandLineGetFlag (Package, L"-a")) + ) + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); + ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ShellCommandLineGetCount (Package) > 1) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetFlag (Package, L"-t") && (ShellCommandLineGetValue (Package, L"-t") == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"smbiosview", L"-t"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetFlag (Package, L"-h") && (ShellCommandLineGetValue (Package, L"-h") == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"smbiosview", L"-h"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if ( - (ShellCommandLineGetFlag (Package, L"-t") && ShellCommandLineGetFlag (Package, L"-h")) || - (ShellCommandLineGetFlag (Package, L"-t") && ShellCommandLineGetFlag (Package, L"-s")) || - (ShellCommandLineGetFlag (Package, L"-t") && ShellCommandLineGetFlag (Package, L"-a")) || - (ShellCommandLineGetFlag (Package, L"-h") && ShellCommandLineGetFlag (Package, L"-s")) || - (ShellCommandLineGetFlag (Package, L"-h") && ShellCommandLineGetFlag (Package, L"-a")) || - (ShellCommandLineGetFlag (Package, L"-s") && ShellCommandLineGetFlag (Package, L"-a")) - ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { + // + // Init Lib + // + Status1 = LibSmbiosInit (); + Status2 = LibSmbios64BitInit (); + if (EFI_ERROR (Status1) && EFI_ERROR (Status2)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE), gShellDebug1HiiHandle); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + + StructType = STRUCTURE_TYPE_RANDOM; + RandomView = TRUE; + + Temp = ShellCommandLineGetValue (Package, L"-t"); + if (Temp != NULL) { + StructType = (UINT8)ShellStrToUintn (Temp); + } + + if (ShellCommandLineGetFlag (Package, L"-a")) { + gShowType = SHOW_ALL; + } + + if (!EFI_ERROR (Status1)) { // - // Init Lib + // Initialize the StructHandle to be the first handle // - Status1 = LibSmbiosInit (); - Status2 = LibSmbios64BitInit (); - if (EFI_ERROR (Status1) && EFI_ERROR (Status2)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE), gShellDebug1HiiHandle); + StructHandle = INVALID_HANDLE; + LibGetSmbiosStructure (&StructHandle, NULL, NULL); + + Temp = ShellCommandLineGetValue (Package, L"-h"); + if (Temp != NULL) { + RandomView = FALSE; + StructHandle = (UINT16)ShellStrToUintn (Temp); + } + + // + // build statistics table + // + Status = InitSmbiosTableStatistics (); + if (EFI_ERROR (Status)) { ShellStatus = SHELL_NOT_FOUND; goto Done; } - StructType = STRUCTURE_TYPE_RANDOM; - RandomView = TRUE; - - Temp = ShellCommandLineGetValue (Package, L"-t"); - if (Temp != NULL) { - StructType = (UINT8)ShellStrToUintn (Temp); - } - - if (ShellCommandLineGetFlag (Package, L"-a")) { - gShowType = SHOW_ALL; - } - - if (!EFI_ERROR (Status1)) { - // - // Initialize the StructHandle to be the first handle - // - StructHandle = INVALID_HANDLE; - LibGetSmbiosStructure (&StructHandle, NULL, NULL); - - Temp = ShellCommandLineGetValue (Package, L"-h"); - if (Temp != NULL) { - RandomView = FALSE; - StructHandle = (UINT16)ShellStrToUintn (Temp); - } - - // - // build statistics table - // - Status = InitSmbiosTableStatistics (); + if (ShellCommandLineGetFlag (Package, L"-s")) { + Status = DisplayStatisticsTable (SHOW_DETAIL); if (EFI_ERROR (Status)) { ShellStatus = SHELL_NOT_FOUND; - goto Done; } - if (ShellCommandLineGetFlag (Package, L"-s")) { - Status = DisplayStatisticsTable (SHOW_DETAIL); - if (EFI_ERROR (Status)) { - ShellStatus = SHELL_NOT_FOUND; - } - - goto Show64Bit; - } - - // - // Show SMBIOS structure information - // - Status = SMBiosView (StructType, StructHandle, gShowType, RandomView); - if (EFI_ERROR (Status)) { - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } + goto Show64Bit; } + // + // Show SMBIOS structure information + // + Status = SMBiosView (StructType, StructHandle, gShowType, RandomView); + if (EFI_ERROR (Status)) { + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + } + Show64Bit: - if (!EFI_ERROR (Status2)) { - // - // build statistics table - // - Status = InitSmbios64BitTableStatistics (); - if (EFI_ERROR (Status)) { - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } + if (!EFI_ERROR (Status2)) { + // + // build statistics table + // + Status = InitSmbios64BitTableStatistics (); + if (EFI_ERROR (Status)) { + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } - // - // Initialize the StructHandle to be the first handle - // - StructHandle = INVALID_HANDLE; - LibGetSmbios64BitStructure (&StructHandle, NULL, NULL); + // + // Initialize the StructHandle to be the first handle + // + StructHandle = INVALID_HANDLE; + LibGetSmbios64BitStructure (&StructHandle, NULL, NULL); - Temp = ShellCommandLineGetValue (Package, L"-h"); - if (Temp != NULL) { - RandomView = FALSE; - StructHandle = (UINT16)ShellStrToUintn (Temp); - } + Temp = ShellCommandLineGetValue (Package, L"-h"); + if (Temp != NULL) { + RandomView = FALSE; + StructHandle = (UINT16)ShellStrToUintn (Temp); + } - if (ShellCommandLineGetFlag (Package, L"-s")) { - Status = DisplaySmbios64BitStatisticsTable (SHOW_DETAIL); - if (EFI_ERROR (Status)) { - ShellStatus = SHELL_NOT_FOUND; - } - - goto Done; - } - - // - // Show SMBIOS structure information - // - Status = SMBios64View (StructType, StructHandle, gShowType, RandomView); + if (ShellCommandLineGetFlag (Package, L"-s")) { + Status = DisplaySmbios64BitStatisticsTable (SHOW_DETAIL); if (EFI_ERROR (Status)) { ShellStatus = SHELL_NOT_FOUND; } + + goto Done; + } + + // + // Show SMBIOS structure information + // + Status = SMBios64View (StructType, StructHandle, gShowType, RandomView); + if (EFI_ERROR (Status)) { + ShellStatus = SHELL_NOT_FOUND; } } } From c8279789102f699527e5e3060fdfd1f0c2188e76 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Mon, 4 May 2026 11:18:37 +0200 Subject: [PATCH 368/406] ShellPkg/LoadPciRom: Fix memory leak Package is never freed. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c index 8486303b79..61096bd3db 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c @@ -185,6 +185,8 @@ ShellCommandRunLoadPciRom ( } } + ShellCommandLineFreeVarList (Package); + return (ShellStatus); } From adad73339ddfe5b91d0cc00fea8ac1bdd7a15d81 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Mon, 4 May 2026 14:32:05 +0200 Subject: [PATCH 369/406] ShellPkg/ShellDebug1: Rationalize Package init/free Package is sometimes initialized to NULL and only freed if not NULL. Remove these as: - Package is initialized in ShellCommandLineParse(). - If ShellCommandLineFreeVarList() is reached, Package cannot be NULL. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c | 5 +---- ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c | 5 +---- ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c | 7 +------ ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c | 4 +--- ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c | 5 +---- ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c | 5 +---- .../UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c | 5 +---- 7 files changed, 7 insertions(+), 29 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c index 0f529ea371..4fac3492e8 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c @@ -302,7 +302,6 @@ ShellCommandRunCxl ( ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; HandleBuf = NULL; - Package = NULL; // // initialize the shell lib (we must be in non-auto-init...) @@ -521,9 +520,7 @@ Done: FreePool (HandleBuf); } - if (Package != NULL) { - ShellCommandLineFreeVarList (Package); - } + ShellCommandLineFreeVarList (Package); return ShellStatus; } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c index b9eaba6688..d5b8d6aed0 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c @@ -744,7 +744,6 @@ ShellCommandRunDmpStore ( BOOLEAN StandardFormatOutput; ShellStatus = SHELL_SUCCESS; - Package = NULL; FileHandle = NULL; File = NULL; Type = DmpStoreDisplay; @@ -908,9 +907,7 @@ ShellCommandRunDmpStore ( } } - if (Package != NULL) { - ShellCommandLineFreeVarList (Package); - } + ShellCommandLineFreeVarList (Package); return ShellStatus; } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c index 9ee3ac6952..f706f81586 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c @@ -48,7 +48,6 @@ ShellCommandRunEfiCompress ( InShellFileHandle = NULL; OutShellFileHandle = NULL; InBuffer = NULL; - Package = NULL; // // initialize the shell lib (we must be in non-auto-init...) @@ -157,12 +156,8 @@ ShellCommandRunEfiCompress ( } } - ShellCommandLineFreeVarList (Package); - Exit: - if ((ShellStatus != SHELL_SUCCESS) && (Package != NULL)) { - ShellCommandLineFreeVarList (Package); - } + ShellCommandLineFreeVarList (Package); if (InShellFileHandle != NULL) { gEfiShellProtocol->CloseFile (InShellFileHandle); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c index de10f4ef6a..86ca12ff39 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c @@ -671,9 +671,7 @@ Done: FreePool (InputStr); } - if (Package != NULL) { - ShellCommandLineFreeVarList (Package); - } + ShellCommandLineFreeVarList (Package); return ShellStatus; } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c index 191518e55d..59efccc5e4 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -2501,7 +2501,6 @@ ShellCommandRunPci ( Address = 0; IoDev = NULL; HandleBuf = NULL; - Package = NULL; // // initialize the shell lib (we must be in non-auto-init...) @@ -2979,9 +2978,7 @@ Done: FreePool (HandleBuf); } - if (Package != NULL) { - ShellCommandLineFreeVarList (Package); - } + ShellCommandLineFreeVarList (Package); mConfigSpace = NULL; return ShellStatus; diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c index a89fdb8934..baa3503fc4 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c @@ -274,7 +274,6 @@ ShellCommandRunSerMode ( Handles = NULL; NoHandles = 0; Index = 0; - Package = NULL; Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR (Status)) { @@ -410,9 +409,7 @@ ShellCommandRunSerMode ( } Done: - if (Package != NULL) { - ShellCommandLineFreeVarList (Package); - } + ShellCommandLineFreeVarList (Package); if (Handles != NULL) { FreePool (Handles); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c index 9162ef1f56..87cecf2ab1 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c @@ -58,7 +58,6 @@ ShellCommandRunSmbiosView ( mStatisticsTable = NULL; mSmbios64BitStatisticsTable = NULL; - Package = NULL; ShellStatus = SHELL_SUCCESS; Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); @@ -221,9 +220,7 @@ Done: mSmbios64BitStatisticsTable = NULL; } - if (Package != NULL) { - ShellCommandLineFreeVarList (Package); - } + ShellCommandLineFreeVarList (Package); LibSmbiosCleanup (); LibSmbios64BitCleanup (); From cb7f7262d51a92786bc44768bf0e69bdea29d0b1 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Mon, 4 May 2026 14:36:06 +0200 Subject: [PATCH 370/406] ShellPkg/Mm: Remove unnecessary goto If ShellCommandLineParse() fails, there is no need to free: - InputStr - Package Remove the goto statement. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c index 86ca12ff39..e765a6f9df 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c @@ -452,7 +452,6 @@ ShellCommandRunMm ( ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mm", ProblemParam); FreePool (ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; } else { ASSERT (FALSE); } From 6d0ef532c633f9924f3f416e744653a0639e7c4e Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:18:46 +0200 Subject: [PATCH 371/406] ShellPkg/UefiShellDebug1: Extract MainCmdXXX() function (1/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Extract a MainCmdXXX() function for each shell command. This command contains the possible operations the command aims to operate. The ShellCommandRunXXX() function from which it is extracted is only responsible of: - initializing the shell/command environment - parsing the command parameter and creating a Package - freeing the Package For the MemMap and SetVar commands, ShellCommandLineFreeVarList() calls are removed as the Package is now freed in the caller function: ShellCommandRunXXX(). To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - Comp.c - Cxl.c - Dblk.c - Dmem.c - DmpStore.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../Library/UefiShellDebug1CommandsLib/Comp.c | 95 ++++++++++------ .../Library/UefiShellDebug1CommandsLib/Cxl.c | 91 +++++++++------ .../Library/UefiShellDebug1CommandsLib/Dblk.c | 93 ++++++++++------ .../Library/UefiShellDebug1CommandsLib/Dmem.c | 105 +++++++++++------- .../UefiShellDebug1CommandsLib/DmpStore.c | 88 +++++++++------ 5 files changed, 285 insertions(+), 187 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c index 559b120ca7..78975cb18f 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c @@ -191,22 +191,17 @@ FileBufferReadByte ( return EFI_SUCCESS; } -/** - Function for 'comp' command. +/** Main function of the 'Comp' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunComp ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdComp ( + LIST_ENTRY *Package ) { EFI_STATUS Status; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; CHAR16 *FileName1; CHAR16 *FileName2; CONST CHAR16 *TempParam; @@ -250,31 +245,6 @@ ShellCommandRunComp ( TempAddress = 0; DiffPointAddress = 0; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"comp", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -511,8 +481,6 @@ ShellCommandRunComp ( } } - ShellCommandLineFreeVarList (Package); - Exit: SHELL_FREE_NON_NULL (FileName1); SHELL_FREE_NON_NULL (FileName2); @@ -525,5 +493,58 @@ Exit: gEfiShellProtocol->CloseFile (FileHandle2); } + return ShellStatus; +} + +/** + Function for 'comp' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunComp ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"comp", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdComp (Package); + + ShellCommandLineFreeVarList (Package); + return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c index 4fac3492e8..e79391ba6a 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c @@ -265,17 +265,14 @@ CxlFindEndpoints ( return Status; } -/** - Function for 'cxl' command. +/** Main function of the 'Cxl' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunCxl ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdCxl ( + LIST_ENTRY *Package ) { UINTN Segment; @@ -286,8 +283,6 @@ ShellCommandRunCxl ( UINTN Index; EFI_HANDLE *HandleBuf; UINTN HandleCount; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; EFI_PCI_IO_PROTOCOL *PciIo; EDKII_CXL_IO_PROTOCOL *CxlIo; @@ -303,31 +298,6 @@ ShellCommandRunCxl ( Status = EFI_SUCCESS; HandleBuf = NULL; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"cxl", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - // // Argument Count == 1(no other argument): enumerate all CXL functions // @@ -520,6 +490,57 @@ Done: FreePool (HandleBuf); } + return ShellStatus; +} + +/** + Function for 'cxl' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunCxl ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"cxl", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdCxl (Package); + ShellCommandLineFreeVarList (Package); return ShellStatus; diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c index b8134b5871..7f51b83897 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c @@ -84,22 +84,16 @@ DisplayTheBlocks ( return (ShellStatus); } -/** - Function for 'dblk' command. +/** Main function of the 'Dblk' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunDblk ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdDblk ( + LIST_ENTRY *Package ) { - EFI_STATUS Status; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *BlockName; CONST CHAR16 *LbaString; @@ -111,32 +105,6 @@ ShellCommandRunDblk ( Lba = 0; BlockCount = 0; ShellStatus = SHELL_SUCCESS; - Status = EFI_SUCCESS; - - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dblk", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } if (ShellCommandLineGetCount (Package) > 4) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dblk"); @@ -203,6 +171,57 @@ ShellCommandRunDblk ( } } + return ShellStatus; +} + +/** + Function for 'dblk' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDblk ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dblk", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdDblk (Package); + ShellCommandLineFreeVarList (Package); return (ShellStatus); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c index 841acb9d99..5c48a007b5 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c @@ -430,63 +430,25 @@ DisplaySystemTable ( return ShellStatus; } -STATIC CONST SHELL_PARAM_ITEM ParamList[] = { - { L"-mmio", TypeFlag }, - { L"-verbose", TypeFlag }, - { NULL, TypeMax } -}; +/** Main function of the 'Dmem' command. -/** - Function for 'dmem' command. - - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunDmem ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdDmem ( + LIST_ENTRY *Package ) { - EFI_STATUS Status; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; VOID *Address; UINT64 Size; CONST CHAR16 *Temp1; ShellStatus = SHELL_SUCCESS; - Status = EFI_SUCCESS; Address = NULL; Size = 0; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dmem", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmem"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -525,6 +487,63 @@ ShellCommandRunDmem ( } } + return ShellStatus; +} + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + { L"-mmio", TypeFlag }, + { L"-verbose", TypeFlag }, + { NULL, TypeMax } +}; + +/** + Function for 'dmem' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDmem ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dmem", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdDmem (Package); + ShellCommandLineFreeVarList (Package); return (ShellStatus); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c index d5b8d6aed0..bba6dbf078 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c @@ -705,33 +705,18 @@ ProcessVariables ( return (ShellStatus); } -STATIC CONST SHELL_PARAM_ITEM ParamList[] = { - { L"-d", TypeFlag }, - { L"-l", TypeValue }, - { L"-s", TypeValue }, - { L"-all", TypeFlag }, - { L"-guid", TypeValue }, - { L"-sfo", TypeFlag }, - { NULL, TypeMax } -}; +/** Main function of the 'DmpStore' command. -/** - Function for 'dmpstore' command. - - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunDmpStore ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdDmpStore ( + LIST_ENTRY *Package ) { EFI_STATUS Status; RETURN_STATUS RStatus; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *GuidStr; CONST CHAR16 *File; @@ -749,21 +734,6 @@ ShellCommandRunDmpStore ( Type = DmpStoreDisplay; StandardFormatOutput = FALSE; - ShellStatus = SHELL_SUCCESS; - - Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dmpstore", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) > 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmpstore"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -907,6 +877,54 @@ ShellCommandRunDmpStore ( } } + return ShellStatus; +} + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + { L"-d", TypeFlag }, + { L"-l", TypeValue }, + { L"-s", TypeValue }, + { L"-all", TypeFlag }, + { L"-guid", TypeValue }, + { L"-sfo", TypeFlag }, + { NULL, TypeMax } +}; + +/** + Function for 'dmpstore' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunDmpStore ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dmpstore", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdDmpStore (Package); + ShellCommandLineFreeVarList (Package); return ShellStatus; From 5bdbf4462bd50762b308a62498f587650ebaf656 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:19:05 +0200 Subject: [PATCH 372/406] ShellPkg/UefiShellDebug1: Extract MainCmdXXX() function (2/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Extract a MainCmdXXX() function for each shell command. This command contains the possible operations the command aims to operate. The ShellCommandRunXXX() function from which it is extracted is only responsible of: - initializing the shell/command environment - parsing the command parameter and creating a Package - freeing the Package For the MemMap and SetVar commands, ShellCommandLineFreeVarList() calls are removed as the Package is now freed in the caller function: ShellCommandRunXXX(). To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - Edit/Edit.c - EfiCompress.c - EfiDecompress.c - HexEdit/HexEdit.c - LoadPciRom.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../UefiShellDebug1CommandsLib/Edit/Edit.c | 92 +++++++++++------- .../UefiShellDebug1CommandsLib/EfiCompress.c | 96 ++++++++++++------- .../EfiDecompress.c | 95 +++++++++++------- .../HexEdit/HexEdit.c | 95 +++++++++++------- .../UefiShellDebug1CommandsLib/LoadPciRom.c | 85 ++++++++++------ 5 files changed, 286 insertions(+), 177 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c index 34e5ddc25c..2697e71c60 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c @@ -10,24 +10,19 @@ #include "UefiShellDebug1CommandsLib.h" #include "TextEditor.h" -/** - Function for 'edit' command. +/** Main function of the 'Edit' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunEdit ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdEdit ( + LIST_ENTRY *Package ) { EFI_STATUS Status; CHAR16 *Buffer; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; - LIST_ENTRY *Package; CONST CHAR16 *Cwd; CHAR16 *Nfs; CHAR16 *Spot; @@ -37,31 +32,6 @@ ShellCommandRunEdit ( ShellStatus = SHELL_SUCCESS; Nfs = NULL; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"edit", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) > 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"edit"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -154,6 +124,58 @@ ShellCommandRunEdit ( } } + return ShellStatus; +} + +/** + Function for 'edit' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunEdit ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + LIST_ENTRY *Package; + + // SHELL_FILE_HANDLE TempHandle; + + ShellStatus = SHELL_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"edit", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdEdit (Package); + ShellCommandLineFreeVarList (Package); return ShellStatus; diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c index f706f81586..7bf6ce87aa 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c @@ -10,22 +10,17 @@ #include "UefiShellDebug1CommandsLib.h" #include "Compress.h" -/** - Function for 'compress' command. +/** Main function of the 'EfiCompress' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunEfiCompress ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdEfiCompress ( + LIST_ENTRY *Package ) { EFI_STATUS Status; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; SHELL_FILE_HANDLE InShellFileHandle; SHELL_FILE_HANDLE OutShellFileHandle; @@ -49,31 +44,6 @@ ShellCommandRunEfiCompress ( OutShellFileHandle = NULL; InBuffer = NULL; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"eficompress", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"eficompress"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -157,8 +127,6 @@ ShellCommandRunEfiCompress ( } Exit: - ShellCommandLineFreeVarList (Package); - if (InShellFileHandle != NULL) { gEfiShellProtocol->CloseFile (InShellFileHandle); } @@ -171,5 +139,59 @@ Exit: SHELL_FREE_NON_NULL (InBuffer); SHELL_FREE_NON_NULL (OutBuffer); + return ShellStatus; +} + +/** + Function for 'compress' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunEfiCompress ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + Package = NULL; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"eficompress", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdEfiCompress (Package); + + ShellCommandLineFreeVarList (Package); + return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c index a31183254d..4fc547a359 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c @@ -10,22 +10,17 @@ #include "UefiShellDebug1CommandsLib.h" #include <Protocol/Decompress.h> -/** - Function for 'decompress' command. +/** Main function of the 'EfiDecompress' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunEfiDecompress ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdEfiDecompress ( + LIST_ENTRY *Package ) { EFI_STATUS Status; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; SHELL_FILE_HANDLE InFileHandle; SHELL_FILE_HANDLE OutFileHandle; @@ -55,31 +50,6 @@ ShellCommandRunEfiDecompress ( OutFileHandle = NULL; Decompress = NULL; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"efidecompress", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"efidecompress"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -188,8 +158,6 @@ ShellCommandRunEfiDecompress ( } Done: - ShellCommandLineFreeVarList (Package); - if (InFileHandle != NULL) { gEfiShellProtocol->CloseFile (InFileHandle); } @@ -203,5 +171,58 @@ Done: SHELL_FREE_NON_NULL (OutBuffer); SHELL_FREE_NON_NULL (ScratchBuffer); + return ShellStatus; +} + +/** + Function for 'decompress' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunEfiDecompress ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"efidecompress", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdEfiDecompress (Package); + + ShellCommandLineFreeVarList (Package); + return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEdit.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEdit.c index 22a9c74954..4cfa5720b0 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEdit.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEdit.c @@ -20,24 +20,19 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { { NULL, TypeMax } }; -/** - Function for 'hexedit' command. +/** Main function of the 'HexEdit' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunHexEdit ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdHexEdit ( + LIST_ENTRY *Package ) { EFI_STATUS Status; CHAR16 *Buffer; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; - LIST_ENTRY *Package; CHAR16 *NewName; CONST CHAR16 *Name; UINTN Offset; @@ -53,31 +48,6 @@ ShellCommandRunHexEdit ( Size = 0; WhatToDo = FileTypeNone; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"hexedit", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - // // Check for -d // @@ -270,9 +240,60 @@ ShellCommandRunHexEdit ( } } - ShellCommandLineFreeVarList (Package); - SHELL_FREE_NON_NULL (Buffer); SHELL_FREE_NON_NULL (NewName); + + return ShellStatus; +} + +/** + Function for 'hexedit' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunHexEdit ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + LIST_ENTRY *Package; + + ShellStatus = SHELL_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"hexedit", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdHexEdit (Package); + + ShellCommandLineFreeVarList (Package); + return ShellStatus; } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c index 61096bd3db..687757bd23 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c @@ -44,30 +44,20 @@ LoadEfiDriversFromRomImage ( CONST CHAR16 *FileName ); -STATIC CONST SHELL_PARAM_ITEM ParamList[] = { - { L"-nc", TypeFlag }, - { NULL, TypeMax } -}; +/** Main function of the 'LoadPciRom' command. -/** - Function for 'loadpcirom' command. - - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunLoadPciRom ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdLoadPciRom ( + LIST_ENTRY *Package ) { EFI_SHELL_FILE_INFO *FileList; UINTN SourceSize; UINT8 *File1Buffer; EFI_STATUS Status; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; BOOLEAN Connect; CONST CHAR16 *Param; @@ -81,22 +71,6 @@ ShellCommandRunLoadPciRom ( ShellStatus = SHELL_SUCCESS; FileList = NULL; - // - // verify number of arguments - // - Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"loadpcirom", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) < 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"loadpcirom"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -185,6 +159,55 @@ ShellCommandRunLoadPciRom ( } } + return ShellStatus; +} + +STATIC CONST SHELL_PARAM_ITEM ParamList[] = { + { L"-nc", TypeFlag }, + { NULL, TypeMax } +}; + +/** + Function for 'loadpcirom' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunLoadPciRom ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + // + // Local variable initializations + // + ShellStatus = SHELL_SUCCESS; + + // + // verify number of arguments + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"loadpcirom", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdLoadPciRom (Package); + ShellCommandLineFreeVarList (Package); return (ShellStatus); From 0b6156b43a545a0a571013293963290eb06c0865 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:19:21 +0200 Subject: [PATCH 373/406] ShellPkg/UefiShellDebug1: Extract MainCmdXXX() function (3/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Extract a MainCmdXXX() function for each shell command. This command contains the possible operations the command aims to operate. The ShellCommandRunXXX() function from which it is extracted is only responsible of: - initializing the shell/command environment - parsing the command parameter and creating a Package - freeing the Package For the MemMap and SetVar commands, ShellCommandLineFreeVarList() calls are removed as the Package is now freed in the caller function: ShellCommandRunXXX(). To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - MemMap.c - Mm.c - Mode.c - Pci.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../UefiShellDebug1CommandsLib/MemMap.c | 118 ++++++++++-------- .../Library/UefiShellDebug1CommandsLib/Mm.c | 72 +++++++---- .../Library/UefiShellDebug1CommandsLib/Mode.c | 91 ++++++++------ .../Library/UefiShellDebug1CommandsLib/Pci.c | 93 ++++++++------ 4 files changed, 228 insertions(+), 146 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c index 56adc4c0c3..2bfd5b5fd6 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c @@ -327,6 +327,70 @@ ParseMemoryDescriptors ( return SHELL_SUCCESS; } +/** Main function of the 'MemMap' command. + + @param[in] Package List of input parameter for the command. +**/ +STATIC +SHELL_STATUS +MainCmdMemMap ( + LIST_ENTRY *Package + ) +{ + EFI_STATUS Status; + SHELL_STATUS ShellStatus; + UINTN Size; + EFI_MEMORY_DESCRIPTOR *Descriptors; + UINTN MapKey; + UINTN ItemSize; + UINT32 Version; + BOOLEAN Sfo; + + Size = 0; + Descriptors = NULL; + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + + if (ShellCommandLineGetCount (Package) > 1) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"memmap"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version); + if (Status == EFI_BUFFER_TOO_SMALL) { + Size += SIZE_1KB; + Descriptors = AllocateZeroPool (Size); + if (Descriptors == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"memmap"); + return SHELL_OUT_OF_RESOURCES; + } + + Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version); + } + + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_GET_FAILED), gShellDebug1HiiHandle, L"memmap"); + ShellStatus = SHELL_ACCESS_DENIED; + } else { + ASSERT (Version == EFI_MEMORY_DESCRIPTOR_VERSION); + + Sfo = ShellCommandLineGetFlag (Package, L"-sfo"); + if (!Sfo) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_LIST_HEAD), gShellDebug1HiiHandle); + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"memmap"); + } + + ParseMemoryDescriptors (Descriptors, Size, ItemSize, Sfo); + } + } + + if (Descriptors != NULL) { + FreePool (Descriptors); + } + + return ShellStatus; +} + /** Function for 'memmap' command. @@ -340,19 +404,11 @@ ShellCommandRunMemMap ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; - SHELL_STATUS ShellStatus; - UINTN Size; - EFI_MEMORY_DESCRIPTOR *Descriptors; - UINTN MapKey; - UINTN ItemSize; - UINT32 Version; - BOOLEAN Sfo; + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; - Size = 0; - Descriptors = NULL; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; @@ -381,45 +437,9 @@ ShellCommandRunMemMap ( return ShellStatus; } - if (ShellCommandLineGetCount (Package) > 1) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"memmap"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version); - if (Status == EFI_BUFFER_TOO_SMALL) { - Size += SIZE_1KB; - Descriptors = AllocateZeroPool (Size); - if (Descriptors == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"memmap"); - ShellCommandLineFreeVarList (Package); - return SHELL_OUT_OF_RESOURCES; - } - - Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version); - } - - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_GET_FAILED), gShellDebug1HiiHandle, L"memmap"); - ShellStatus = SHELL_ACCESS_DENIED; - } else { - ASSERT (Version == EFI_MEMORY_DESCRIPTOR_VERSION); - - Sfo = ShellCommandLineGetFlag (Package, L"-sfo"); - if (!Sfo) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_LIST_HEAD), gShellDebug1HiiHandle); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"memmap"); - } - - ParseMemoryDescriptors (Descriptors, Size, ItemSize, Sfo); - } - } + ShellStatus = MainCmdMemMap (Package); ShellCommandLineFreeVarList (Package); - if (Descriptors != NULL) { - FreePool (Descriptors); - } - return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c index e765a6f9df..203e78bfad 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c @@ -405,17 +405,14 @@ ShellMmLocateIoProtocol ( return TRUE; } -/** - Function for 'mm' command. +/** Main function of the 'Mm' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunMm ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdMm ( + LIST_ENTRY *Package ) { EFI_STATUS Status; @@ -430,8 +427,6 @@ ShellCommandRunMm ( BOOLEAN Complete; CHAR16 *InputStr; BOOLEAN Interactive; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Temp; BOOLEAN HasPciRootBridgeIo; @@ -443,22 +438,6 @@ ShellCommandRunMm ( Size = 1; AccessType = ShellMmMemory; - // - // Parse arguments - // - Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mm", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) < 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"mm"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -670,6 +649,47 @@ Done: FreePool (InputStr); } + return ShellStatus; +} + +/** + Function for 'mm' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunMm ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + + // + // Parse arguments + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mm", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdMm (Package); + ShellCommandLineFreeVarList (Package); return ShellStatus; diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c index e5d405638c..3f1da155ac 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c @@ -9,22 +9,17 @@ #include "UefiShellDebug1CommandsLib.h" -/** - Function for 'mode' command. +/** Main function of the 'Mode' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunMode ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdMode ( + LIST_ENTRY *Package ) { EFI_STATUS Status; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; UINTN NewCol; UINTN NewRow; @@ -37,31 +32,6 @@ ShellCommandRunMode ( ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mode", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mode"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -129,6 +99,57 @@ ShellCommandRunMode ( } } + return ShellStatus; +} + +/** + Function for 'mode' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunMode ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mode", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdMode (Package); + ShellCommandLineFreeVarList (Package); return (ShellStatus); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c index 59efccc5e4..9446cca702 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -2450,17 +2450,14 @@ PciConfigSpaceDumpHex ( DumpHex (Indent, Offset, DataSize, UserData); } -/** - Function for 'pci' command. +/** Main function of the 'Pci' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunPci ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdPci ( + LIST_ENTRY *Package ) { UINT16 Segment; @@ -2486,8 +2483,6 @@ ShellCommandRunPci ( UINT16 MinBus; UINT16 MaxBus; BOOLEAN IsEnd; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Temp; UINT64 RetVal; @@ -2502,31 +2497,6 @@ ShellCommandRunPci ( IoDev = NULL; HandleBuf = NULL; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"pci", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) == 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"pci"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -2978,8 +2948,59 @@ Done: FreePool (HandleBuf); } - ShellCommandLineFreeVarList (Package); + return ShellStatus; +} +/** + Function for 'pci' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunPci ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + Package = NULL; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"pci", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdPci (Package); + + ShellCommandLineFreeVarList (Package); mConfigSpace = NULL; return ShellStatus; } From cebf8bc4ae7e0ecea95377a7eb9582fad92aaa3a Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:19:36 +0200 Subject: [PATCH 374/406] ShellPkg/UefiShellDebug1: Extract MainCmdXXX() function (4/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Extract a MainCmdXXX() function for each shell command. This command contains the possible operations the command aims to operate. The ShellCommandRunXXX() function from which it is extracted is only responsible of: - initializing the shell/command environment - parsing the command parameter and creating a Package - freeing the Package For the MemMap and SetVar commands, ShellCommandLineFreeVarList() calls are removed as the Package is now freed in the caller function: ShellCommandRunXXX(). To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - SerMode.c - SetSize.c - SetVar.c - SmbiosView/SmbiosView.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../UefiShellDebug1CommandsLib/SerMode.c | 71 ++++++++---- .../UefiShellDebug1CommandsLib/SetSize.c | 91 +++++++++------ .../UefiShellDebug1CommandsLib/SetVar.c | 109 ++++++++++-------- .../SmbiosView/SmbiosView.c | 70 +++++++---- 4 files changed, 211 insertions(+), 130 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c index baa3503fc4..055498ea42 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c @@ -239,17 +239,14 @@ ValidDataBits ( return (DataBits == 4) || (DataBits == 7) || (DataBits == 8); } -/** - Function for 'sermode' command. +/** Main function of the 'SerMode' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunSerMode ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdSerMode ( + LIST_ENTRY *Package ) { EFI_STATUS Status; @@ -263,8 +260,6 @@ ShellCommandRunSerMode ( UINTN BaudRate; UINTN DataBits; EFI_SERIAL_IO_PROTOCOL *SerialIo; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; CONST CHAR16 *Temp; UINT64 Intermediate; @@ -275,19 +270,6 @@ ShellCommandRunSerMode ( NoHandles = 0; Index = 0; - Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"sermode", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if ((ShellCommandLineGetCount (Package) < 6) && (ShellCommandLineGetCount (Package) > 2)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"sermode"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -409,11 +391,50 @@ ShellCommandRunSerMode ( } Done: - ShellCommandLineFreeVarList (Package); - if (Handles != NULL) { FreePool (Handles); } return ShellStatus; } + +/** + Function for 'sermode' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunSerMode ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + SHELL_STATUS ShellStatus; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + + ShellStatus = SHELL_SUCCESS; + Package = NULL; + + Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"sermode", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdSerMode (Package); + + ShellCommandLineFreeVarList (Package); + + return ShellStatus; +} diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c index 04348924b3..cebd831018 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c @@ -9,22 +9,17 @@ #include "UefiShellDebug1CommandsLib.h" -/** - Function for 'setsize' command. +/** Main function of the 'SetSize' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunSetSize ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdSetSize ( + LIST_ENTRY *Package ) { EFI_STATUS Status; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Temp1; UINTN NewSize; @@ -34,31 +29,6 @@ ShellCommandRunSetSize ( ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setsize", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) < 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -107,6 +77,57 @@ ShellCommandRunSetSize ( } } + return ShellStatus; +} + +/** + Function for 'setsize' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunSetSize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setsize", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdSetSize (Package); + ShellCommandLineFreeVarList (Package); return (ShellStatus); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c index 8f5d419c52..cc71540d75 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c @@ -341,23 +341,18 @@ GetVariableDataFromParameter ( return EFI_SUCCESS; } -/** - Function for 'setvar' command. +/** Main function of the 'SetVar' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunSetVar ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdSetVar ( + LIST_ENTRY *Package ) { EFI_STATUS Status; RETURN_STATUS RStatus; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *VariableName; EFI_GUID Guid; @@ -373,43 +368,12 @@ ShellCommandRunSetVar ( Size = 0; Attributes = 0; - // - // initialize the shell lib (we must be in non-auto-init...) - // - Status = ShellInitialize (); - ASSERT_EFI_ERROR (Status); - - Status = CommandInit (); - ASSERT_EFI_ERROR (Status); - - // - // parse the command line - // - Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setvar", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } else if (ShellCommandLineCheckDuplicate (Package, &ProblemParam) != EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_DUPLICATE), gShellDebug1HiiHandle, L"setvar", ProblemParam); - ShellCommandLineFreeVarList (Package); - FreePool (ProblemParam); - return SHELL_INVALID_PARAMETER; - } - if (ShellCommandLineGetCount (Package) < 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setvar"); ShellStatus = SHELL_INVALID_PARAMETER; } else { VariableName = ShellCommandLineGetRawValue (Package, 1); if (VariableName == NULL) { - ShellCommandLineFreeVarList (Package); return SHELL_INVALID_PARAMETER; } @@ -421,7 +385,6 @@ ShellCommandRunSetVar ( RStatus = StrToGuid (StringGuid, &Guid); } else { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid); - ShellCommandLineFreeVarList (Package); return SHELL_INVALID_PARAMETER; } @@ -440,7 +403,6 @@ ShellCommandRunSetVar ( Buffer = AllocateZeroPool (Size); if (Buffer == NULL) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar"); - ShellCommandLineFreeVarList (Package); return SHELL_OUT_OF_RESOURCES; } @@ -467,7 +429,6 @@ ShellCommandRunSetVar ( Buffer = AllocateZeroPool (Size); if (Buffer == NULL) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar"); - ShellCommandLineFreeVarList (Package); return SHELL_OUT_OF_RESOURCES; } @@ -510,11 +471,67 @@ ShellCommandRunSetVar ( } } - ShellCommandLineFreeVarList (Package); - if (Buffer != NULL) { FreePool (Buffer); } + return ShellStatus; +} + +/** + Function for 'setvar' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunSetVar ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setvar", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } else if (ShellCommandLineCheckDuplicate (Package, &ProblemParam) != EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_DUPLICATE), gShellDebug1HiiHandle, L"setvar", ProblemParam); + ShellCommandLineFreeVarList (Package); + FreePool (ProblemParam); + return SHELL_INVALID_PARAMETER; + } + + ShellStatus = MainCmdSetVar (Package); + + ShellCommandLineFreeVarList (Package); + return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c index 87cecf2ab1..70fc0a33b0 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c @@ -32,17 +32,14 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { { NULL, TypeMax } }; -/** - Function for 'smbiosview' command. +/** Main function of the 'SmbiosView' command. - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] Package List of input parameter for the command. **/ +STATIC SHELL_STATUS -EFIAPI -ShellCommandRunSmbiosView ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +MainCmdSmbiosView ( + LIST_ENTRY *Package ) { UINT8 StructType; @@ -51,8 +48,6 @@ ShellCommandRunSmbiosView ( EFI_STATUS Status1; EFI_STATUS Status2; BOOLEAN RandomView; - LIST_ENTRY *Package; - CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Temp; @@ -60,19 +55,6 @@ ShellCommandRunSmbiosView ( mSmbios64BitStatisticsTable = NULL; ShellStatus = SHELL_SUCCESS; - Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); - if (EFI_ERROR (Status)) { - if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"smbiosview", ProblemParam); - FreePool (ProblemParam); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ASSERT (FALSE); - } - - return ShellStatus; - } - if (ShellCommandLineGetCount (Package) > 1) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); ShellStatus = SHELL_INVALID_PARAMETER; @@ -220,8 +202,48 @@ Done: mSmbios64BitStatisticsTable = NULL; } - ShellCommandLineFreeVarList (Package); + return ShellStatus; +} +/** + Function for 'smbiosview' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunSmbiosView ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + + mStatisticsTable = NULL; + mSmbios64BitStatisticsTable = NULL; + Package = NULL; + ShellStatus = SHELL_SUCCESS; + + Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR (Status)) { + if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"smbiosview", ProblemParam); + FreePool (ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT (FALSE); + } + + return ShellStatus; + } + + ShellStatus = MainCmdSmbiosView (Package); + + ShellCommandLineFreeVarList (Package); LibSmbiosCleanup (); LibSmbios64BitCleanup (); From cad93da7e5efead7c9a7ddb774b968894a538cbd Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:20:45 +0200 Subject: [PATCH 375/406] ShellPkg/UefiShellDebug1: Lower indentation level in MainCmdXXX() (1/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Lower the indentation level in the newly created MainCmdXXX() functions. To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - Comp.c - Cxl.c - Dblk.c - Dmem.c - DmpStore.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../Library/UefiShellDebug1CommandsLib/Comp.c | 405 +++++++++--------- .../Library/UefiShellDebug1CommandsLib/Cxl.c | 224 +++++----- .../Library/UefiShellDebug1CommandsLib/Dblk.c | 98 +++-- .../Library/UefiShellDebug1CommandsLib/Dmem.c | 30 +- .../UefiShellDebug1CommandsLib/DmpStore.c | 224 +++++----- 5 files changed, 494 insertions(+), 487 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c index 78975cb18f..3b7bf34c7c 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c @@ -247,240 +247,245 @@ MainCmdComp ( if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount (Package) < 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"comp"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; + } + + TempParam = ShellCommandLineGetRawValue (Package, 1); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam); + return SHELL_INVALID_PARAMETER; + } + + FileName1 = ShellFindFilePath (TempParam); + if (FileName1 == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); + ShellStatus = SHELL_NOT_FOUND; } else { - TempParam = ShellCommandLineGetRawValue (Package, 1); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Exit; - } - - FileName1 = ShellFindFilePath (TempParam); - if (FileName1 == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); + Status = ShellOpenFileByName (FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; - } else { - Status = ShellOpenFileByName (FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } } + } - TempParam = ShellCommandLineGetRawValue (Package, 2); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Exit; - } + TempParam = ShellCommandLineGetRawValue (Package, 2); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Exit; + } - FileName2 = ShellFindFilePath (TempParam); - if (FileName2 == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); + FileName2 = ShellFindFilePath (TempParam); + if (FileName2 == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); + ShellStatus = SHELL_NOT_FOUND; + } else { + Status = ShellOpenFileByName (FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; - } else { - Status = ShellOpenFileByName (FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } } + } - if (ShellStatus == SHELL_SUCCESS) { - Status = gEfiShellProtocol->GetFileSize (FileHandle1, &Size1); - ASSERT_EFI_ERROR (Status); - Status = gEfiShellProtocol->GetFileSize (FileHandle2, &Size2); - ASSERT_EFI_ERROR (Status); + if (ShellStatus != SHELL_SUCCESS) { + goto Exit; + } - if (ShellCommandLineGetFlag (Package, L"-n")) { - TempParam = ShellCommandLineGetValue (Package, L"-n"); - if (TempParam == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"comp", L"-n"); + Status = gEfiShellProtocol->GetFileSize (FileHandle1, &Size1); + ASSERT_EFI_ERROR (Status); + Status = gEfiShellProtocol->GetFileSize (FileHandle2, &Size2); + ASSERT_EFI_ERROR (Status); + + if (ShellCommandLineGetFlag (Package, L"-n")) { + TempParam = ShellCommandLineGetValue (Package, L"-n"); + if (TempParam == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"comp", L"-n"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16 *)TempParam, L"all") == 0) { + DifferentCount = MAX_UINTN; + } else { + Status = ShellConvertStringToUint64 (TempParam, &DifferentCount, FALSE, TRUE); + if (EFI_ERROR (Status) || (DifferentCount == 0)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-n"); ShellStatus = SHELL_INVALID_PARAMETER; - } else { - if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16 *)TempParam, L"all") == 0) { - DifferentCount = MAX_UINTN; - } else { - Status = ShellConvertStringToUint64 (TempParam, &DifferentCount, FALSE, TRUE); - if (EFI_ERROR (Status) || (DifferentCount == 0)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-n"); - ShellStatus = SHELL_INVALID_PARAMETER; - } - } - } - } - - if (ShellCommandLineGetFlag (Package, L"-s")) { - TempParam = ShellCommandLineGetValue (Package, L"-s"); - if (TempParam == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"comp", L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Status = ShellConvertStringToUint64 (TempParam, &DifferentBytes, FALSE, TRUE); - if (EFI_ERROR (Status) || (DifferentBytes == 0)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - if (DifferentBytes > MAX (Size1, Size2)) { - DifferentBytes = MAX (Size1, Size2); - } - } } } } + } - if (ShellStatus == SHELL_SUCCESS) { - DataFromFile1 = AllocateZeroPool ((UINTN)DifferentBytes); - DataFromFile2 = AllocateZeroPool ((UINTN)DifferentBytes); - FileBufferInit (&FileBuffer1); - FileBufferInit (&FileBuffer2); - if ((DataFromFile1 == NULL) || (DataFromFile2 == NULL) || - (FileBuffer1.Data == NULL) || (FileBuffer2.Data == NULL)) - { - ShellStatus = SHELL_OUT_OF_RESOURCES; - SHELL_FREE_NON_NULL (DataFromFile1); - SHELL_FREE_NON_NULL (DataFromFile2); - FileBufferUninit (&FileBuffer1); - FileBufferUninit (&FileBuffer2); + if (ShellCommandLineGetFlag (Package, L"-s")) { + TempParam = ShellCommandLineGetValue (Package, L"-s"); + if (TempParam == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"comp", L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = ShellConvertStringToUint64 (TempParam, &DifferentBytes, FALSE, TRUE); + if (EFI_ERROR (Status) || (DifferentBytes == 0)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + if (DifferentBytes > MAX (Size1, Size2)) { + DifferentBytes = MAX (Size1, Size2); + } + } + } + } + + if (ShellStatus != SHELL_SUCCESS) { + goto Exit; + } + + DataFromFile1 = AllocateZeroPool ((UINTN)DifferentBytes); + DataFromFile2 = AllocateZeroPool ((UINTN)DifferentBytes); + FileBufferInit (&FileBuffer1); + FileBufferInit (&FileBuffer2); + if ((DataFromFile1 == NULL) || (DataFromFile2 == NULL) || + (FileBuffer1.Data == NULL) || (FileBuffer2.Data == NULL)) + { + ShellStatus = SHELL_OUT_OF_RESOURCES; + SHELL_FREE_NON_NULL (DataFromFile1); + SHELL_FREE_NON_NULL (DataFromFile2); + FileBufferUninit (&FileBuffer1); + FileBufferUninit (&FileBuffer2); + } + + if (ShellStatus != SHELL_SUCCESS) { + goto Exit; + } + + while ((UINT64)DiffPointNumber < DifferentCount) { + DataSizeFromFile1 = 1; + DataSizeFromFile2 = 1; + OneByteFromFile1 = 0; + OneByteFromFile2 = 0; + Status = FileBufferReadByte ( + FileHandle1, + &FileBuffer1, + &DataSizeFromFile1, + &OneByteFromFile1 + ); + ASSERT_EFI_ERROR (Status); + Status = FileBufferReadByte ( + FileHandle2, + &FileBuffer2, + &DataSizeFromFile2, + &OneByteFromFile2 + ); + ASSERT_EFI_ERROR (Status); + + TempAddress++; + + // + // 1.When end of file and no chars in DataFromFile buffer, then break while. + // 2.If no more char in File1 or File2, The ReadStatus is InPrevDiffPoint forever. + // So the previous different point is the last one, then break the while block. + // + if (((DataSizeFromFile1 == 0) && (InsertPosition1 == 0) && (DataSizeFromFile2 == 0) && (InsertPosition2 == 0)) || + ((ReadStatus == InPrevDiffPoint) && ((DataSizeFromFile1 == 0) || (DataSizeFromFile2 == 0))) + ) + { + break; + } + + if (ReadStatus == OutOfDiffPoint) { + if (OneByteFromFile1 != OneByteFromFile2) { + ReadStatus = InDiffPoint; + DiffPointAddress = TempAddress; + if (DataSizeFromFile1 == 1) { + DataFromFile1[InsertPosition1++] = OneByteFromFile1; + } + + if (DataSizeFromFile2 == 1) { + DataFromFile2[InsertPosition2++] = OneByteFromFile2; + } + } + } else if (ReadStatus == InDiffPoint) { + if (DataSizeFromFile1 == 1) { + DataFromFile1[InsertPosition1++] = OneByteFromFile1; + } + + if (DataSizeFromFile2 == 1) { + DataFromFile2[InsertPosition2++] = OneByteFromFile2; + } + } else if (ReadStatus == InPrevDiffPoint) { + if (OneByteFromFile1 == OneByteFromFile2) { + ReadStatus = OutOfDiffPoint; } } - if (ShellStatus == SHELL_SUCCESS) { - while ((UINT64)DiffPointNumber < DifferentCount) { - DataSizeFromFile1 = 1; - DataSizeFromFile2 = 1; - OneByteFromFile1 = 0; - OneByteFromFile2 = 0; - Status = FileBufferReadByte ( - FileHandle1, - &FileBuffer1, - &DataSizeFromFile1, - &OneByteFromFile1 - ); - ASSERT_EFI_ERROR (Status); - Status = FileBufferReadByte ( - FileHandle2, - &FileBuffer2, - &DataSizeFromFile2, - &OneByteFromFile2 - ); - ASSERT_EFI_ERROR (Status); + // + // ReadStatus should be always equal InDiffPoint. + // + if ((InsertPosition1 == DifferentBytes) || + (InsertPosition2 == DifferentBytes) || + ((DataSizeFromFile1 == 0) && (DataSizeFromFile2 == 0)) + ) + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_DIFFERENCE_POINT), gShellDebug1HiiHandle, ++DiffPointNumber); + PrintDifferentPoint (FileName1, L"File1", DataFromFile1, InsertPosition1, DiffPointAddress, DifferentBytes); + PrintDifferentPoint (FileName2, L"File2", DataFromFile2, InsertPosition2, DiffPointAddress, DifferentBytes); - TempAddress++; + // + // One of two buffuers is empty, it means this is the last different point. + // + if ((InsertPosition1 == 0) || (InsertPosition2 == 0)) { + break; + } - // - // 1.When end of file and no chars in DataFromFile buffer, then break while. - // 2.If no more char in File1 or File2, The ReadStatus is InPrevDiffPoint forever. - // So the previous different point is the last one, then break the while block. - // - if (((DataSizeFromFile1 == 0) && (InsertPosition1 == 0) && (DataSizeFromFile2 == 0) && (InsertPosition2 == 0)) || - ((ReadStatus == InPrevDiffPoint) && ((DataSizeFromFile1 == 0) || (DataSizeFromFile2 == 0))) - ) - { + for (Index = 1; Index < InsertPosition1 && Index < InsertPosition2; Index++) { + if (DataFromFile1[Index] == DataFromFile2[Index]) { + ReadStatus = OutOfDiffPoint; break; } + } - if (ReadStatus == OutOfDiffPoint) { - if (OneByteFromFile1 != OneByteFromFile2) { - ReadStatus = InDiffPoint; - DiffPointAddress = TempAddress; - if (DataSizeFromFile1 == 1) { - DataFromFile1[InsertPosition1++] = OneByteFromFile1; - } - - if (DataSizeFromFile2 == 1) { - DataFromFile2[InsertPosition2++] = OneByteFromFile2; - } - } - } else if (ReadStatus == InDiffPoint) { - if (DataSizeFromFile1 == 1) { - DataFromFile1[InsertPosition1++] = OneByteFromFile1; - } - - if (DataSizeFromFile2 == 1) { - DataFromFile2[InsertPosition2++] = OneByteFromFile2; - } - } else if (ReadStatus == InPrevDiffPoint) { - if (OneByteFromFile1 == OneByteFromFile2) { - ReadStatus = OutOfDiffPoint; - } - } - + if (ReadStatus == OutOfDiffPoint) { // - // ReadStatus should be always equal InDiffPoint. + // Try to find a new different point in the rest of DataFromFile. // - if ((InsertPosition1 == DifferentBytes) || - (InsertPosition2 == DifferentBytes) || - ((DataSizeFromFile1 == 0) && (DataSizeFromFile2 == 0)) - ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_DIFFERENCE_POINT), gShellDebug1HiiHandle, ++DiffPointNumber); - PrintDifferentPoint (FileName1, L"File1", DataFromFile1, InsertPosition1, DiffPointAddress, DifferentBytes); - PrintDifferentPoint (FileName2, L"File2", DataFromFile2, InsertPosition2, DiffPointAddress, DifferentBytes); - - // - // One of two buffuers is empty, it means this is the last different point. - // - if ((InsertPosition1 == 0) || (InsertPosition2 == 0)) { + for ( ; Index < MAX (InsertPosition1, InsertPosition2); Index++) { + if (DataFromFile1[Index] != DataFromFile2[Index]) { + ReadStatus = InDiffPoint; + DiffPointAddress += Index; break; } - - for (Index = 1; Index < InsertPosition1 && Index < InsertPosition2; Index++) { - if (DataFromFile1[Index] == DataFromFile2[Index]) { - ReadStatus = OutOfDiffPoint; - break; - } - } - - if (ReadStatus == OutOfDiffPoint) { - // - // Try to find a new different point in the rest of DataFromFile. - // - for ( ; Index < MAX (InsertPosition1, InsertPosition2); Index++) { - if (DataFromFile1[Index] != DataFromFile2[Index]) { - ReadStatus = InDiffPoint; - DiffPointAddress += Index; - break; - } - } - } else { - // - // Doesn't find a new different point, still in the same different point. - // - ReadStatus = InPrevDiffPoint; - } - - CopyMem (DataFromFile1, DataFromFile1 + Index, InsertPosition1 - Index); - CopyMem (DataFromFile2, DataFromFile2 + Index, InsertPosition2 - Index); - - SetMem (DataFromFile1 + InsertPosition1 - Index, (UINTN)DifferentBytes - InsertPosition1 + Index, 0); - SetMem (DataFromFile2 + InsertPosition2 - Index, (UINTN)DifferentBytes - InsertPosition2 + Index, 0); - - InsertPosition1 -= Index; - InsertPosition2 -= Index; } - } - - SHELL_FREE_NON_NULL (DataFromFile1); - SHELL_FREE_NON_NULL (DataFromFile2); - FileBufferUninit (&FileBuffer1); - FileBufferUninit (&FileBuffer2); - - if (DiffPointNumber == 0) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle); } else { - ShellStatus = SHELL_NOT_EQUAL; - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle); + // + // Doesn't find a new different point, still in the same different point. + // + ReadStatus = InPrevDiffPoint; } + + CopyMem (DataFromFile1, DataFromFile1 + Index, InsertPosition1 - Index); + CopyMem (DataFromFile2, DataFromFile2 + Index, InsertPosition2 - Index); + + SetMem (DataFromFile1 + InsertPosition1 - Index, (UINTN)DifferentBytes - InsertPosition1 + Index, 0); + SetMem (DataFromFile2 + InsertPosition2 - Index, (UINTN)DifferentBytes - InsertPosition2 + Index, 0); + + InsertPosition1 -= Index; + InsertPosition2 -= Index; } } + SHELL_FREE_NON_NULL (DataFromFile1); + SHELL_FREE_NON_NULL (DataFromFile2); + FileBufferUninit (&FileBuffer1); + FileBufferUninit (&FileBuffer2); + + if (DiffPointNumber == 0) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle); + } else { + ShellStatus = SHELL_NOT_EQUAL; + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle); + } + Exit: SHELL_FREE_NON_NULL (FileName1); SHELL_FREE_NON_NULL (FileName2); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c index e79391ba6a..fb0cebc765 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Cxl.c @@ -351,138 +351,138 @@ MainCmdCxl ( Status = EFI_SUCCESS; goto Done; - } else { - // Dump extended information - TargetSegment = 0; - TargetBus = 0; - TargetDevice = 0; - TargetFunc = 0; - if ((ShellCommandLineGetCount (Package) < 4) || (ShellCommandLineGetCount (Package) == 5)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"cxl"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + } - if (ShellCommandLineGetCount (Package) > 6) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"cxl"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + // Dump extended information + TargetSegment = 0; + TargetBus = 0; + TargetDevice = 0; + TargetFunc = 0; + if ((ShellCommandLineGetCount (Package) < 4) || (ShellCommandLineGetCount (Package) == 5)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"cxl"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } - if (ShellCommandLineGetFlag (Package, L"-s") && (ShellCommandLineGetValue (Package, L"-s") == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"cxl", L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + if (ShellCommandLineGetCount (Package) > 6) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"cxl"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } - Temp = ShellCommandLineGetValue (Package, L"-s"); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - TargetSegment = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } + if (ShellCommandLineGetFlag (Package, L"-s") && (ShellCommandLineGetValue (Package, L"-s") == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"cxl", L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + Temp = ShellCommandLineGetValue (Package, L"-s"); + if (Temp != NULL) { // - // The first Argument is assumed to be Bus number, second - // to be Device number, and third to be Func number. + // Input converted to hexadecimal number. // - Temp = ShellCommandLineGetRawValue (Package, 1); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - TargetBus = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + TargetSegment = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } - if (TargetBus > PCI_MAX_BUS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + // + // The first Argument is assumed to be Bus number, second + // to be Device number, and third to be Func number. + // + Temp = ShellCommandLineGetRawValue (Package, 1); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + TargetBus = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; } - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - TargetDevice = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + if (TargetBus > PCI_MAX_BUS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } - if (TargetDevice > PCI_MAX_DEVICE) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + Temp = ShellCommandLineGetRawValue (Package, 2); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + TargetDevice = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; } - Temp = ShellCommandLineGetRawValue (Package, 3); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - TargetFunc = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + if (TargetDevice > PCI_MAX_DEVICE) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } - if (TargetFunc > PCI_MAX_FUNC) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + Temp = ShellCommandLineGetRawValue (Package, 3); + if (Temp != NULL) { + // + // Input converted to hexadecimal number. + // + if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { + TargetFunc = (UINT16)RetVal; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; } - Status = CxlFindEndpoints (&HandleBuf, &HandleCount); + if (TargetFunc > PCI_MAX_FUNC) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"cxl", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; + } + } + + Status = CxlFindEndpoints (&HandleBuf, &HandleCount); + if (EFI_ERROR (Status)) { + goto Done; + } + + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol (HandleBuf[Index], &gEdkiiCxlIoProtocolGuid, (VOID **)&CxlIo); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_HANDLE_CFG_ERR), gShellDebug1HiiHandle, L"cxl"); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + + PciIo = CxlIo->PciIo; + Status = PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Func); if (EFI_ERROR (Status)) { goto Done; } - for (Index = 0; Index < HandleCount; Index++) { - Status = gBS->HandleProtocol (HandleBuf[Index], &gEdkiiCxlIoProtocolGuid, (VOID **)&CxlIo); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_HANDLE_CFG_ERR), gShellDebug1HiiHandle, L"cxl"); - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } - - PciIo = CxlIo->PciIo; - Status = PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Func); - if (EFI_ERROR (Status)) { - goto Done; - } - - if ((Segment != TargetSegment) || - (Bus != TargetBus) || - (Device != TargetDevice) || - (Func != TargetFunc)) - { - continue; - } - - PrintCdatInfo (CxlIo); - goto Done; + if ((Segment != TargetSegment) || + (Bus != TargetBus) || + (Device != TargetDevice) || + (Func != TargetFunc)) + { + continue; } + + PrintCdatInfo (CxlIo); + goto Done; } Done: diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c index 7f51b83897..325852cee9 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c @@ -103,71 +103,69 @@ MainCmdDblk ( EFI_DEVICE_PATH_PROTOCOL *DevPath; Lba = 0; - BlockCount = 0; + BlockCount = 1; ShellStatus = SHELL_SUCCESS; if (ShellCommandLineGetCount (Package) > 4) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dblk"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount (Package) < 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"dblk"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - // - // Parse the params - // - BlockName = ShellCommandLineGetRawValue (Package, 1); - LbaString = ShellCommandLineGetRawValue (Package, 2); - BlockCountString = ShellCommandLineGetRawValue (Package, 3); + return SHELL_INVALID_PARAMETER; + } - if (LbaString == NULL) { - Lba = 0; - } else { - if (!ShellIsHexOrDecimalNumber (LbaString, TRUE, FALSE)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", LbaString); - ShellStatus = SHELL_INVALID_PARAMETER; - } + // + // Parse the params + // + BlockName = ShellCommandLineGetRawValue (Package, 1); + LbaString = ShellCommandLineGetRawValue (Package, 2); + BlockCountString = ShellCommandLineGetRawValue (Package, 3); - if (EFI_ERROR (ShellConvertStringToUint64 (LbaString, &Lba, TRUE, FALSE))) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", LbaString); - ShellStatus = SHELL_INVALID_PARAMETER; - } + if (LbaString != NULL) { + if (!ShellIsHexOrDecimalNumber (LbaString, TRUE, FALSE)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", LbaString); + ShellStatus = SHELL_INVALID_PARAMETER; } - if (BlockCountString == NULL) { - BlockCount = 1; - } else { - if (!ShellIsHexOrDecimalNumber (BlockCountString, TRUE, FALSE)) { + if (EFI_ERROR (ShellConvertStringToUint64 (LbaString, &Lba, TRUE, FALSE))) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", LbaString); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } + + if (BlockCountString != NULL) { + if (!ShellIsHexOrDecimalNumber (BlockCountString, TRUE, FALSE)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockCountString); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + if (!EFI_ERROR (ShellConvertStringToUint64 (BlockCountString, &BlockCount, TRUE, FALSE))) { + if (BlockCount > 0x10) { + BlockCount = 0x10; + } else if (BlockCount == 0) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockCountString); ShellStatus = SHELL_INVALID_PARAMETER; } - - if (!EFI_ERROR (ShellConvertStringToUint64 (BlockCountString, &BlockCount, TRUE, FALSE))) { - if (BlockCount > 0x10) { - BlockCount = 0x10; - } else if (BlockCount == 0) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockCountString); - ShellStatus = SHELL_INVALID_PARAMETER; - } - } } + } - if (ShellStatus == SHELL_SUCCESS) { - // - // do the work if we have a valid block identifier - // - if ((BlockName == NULL) || (gEfiShellProtocol->GetDevicePathFromMap (BlockName) == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockName); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - DevPath = (EFI_DEVICE_PATH_PROTOCOL *)gEfiShellProtocol->GetDevicePathFromMap (BlockName); - if (gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &DevPath, NULL) == EFI_NOT_FOUND) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_MAP_PROTOCOL), gShellDebug1HiiHandle, L"dblk", BlockName, L"BlockIo"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - ShellStatus = DisplayTheBlocks (gEfiShellProtocol->GetDevicePathFromMap (BlockName), Lba, (UINT8)BlockCount); - } - } + if (ShellStatus != SHELL_SUCCESS) { + return ShellStatus; + } + + // + // do the work if we have a valid block identifier + // + if ((BlockName == NULL) || (gEfiShellProtocol->GetDevicePathFromMap (BlockName) == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockName); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + DevPath = (EFI_DEVICE_PATH_PROTOCOL *)gEfiShellProtocol->GetDevicePathFromMap (BlockName); + if (gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &DevPath, NULL) == EFI_NOT_FOUND) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_MAP_PROTOCOL), gShellDebug1HiiHandle, L"dblk", BlockName, L"BlockIo"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ShellStatus = DisplayTheBlocks (gEfiShellProtocol->GetDevicePathFromMap (BlockName), Lba, (UINT8)BlockCount); } } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c index 5c48a007b5..efce6cd09d 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c @@ -451,27 +451,27 @@ MainCmdDmem ( if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmem"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; + } + + Temp1 = ShellCommandLineGetRawValue (Package, 1); + if (Temp1 == NULL) { + Address = gST; + Size = sizeof (*gST); } else { - Temp1 = ShellCommandLineGetRawValue (Package, 1); + if (!ShellIsHexOrDecimalNumber (Temp1, TRUE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, (UINT64 *)&Address, TRUE, FALSE))) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + Temp1 = ShellCommandLineGetRawValue (Package, 2); if (Temp1 == NULL) { - Address = gST; - Size = sizeof (*gST); + Size = 512; } else { - if (!ShellIsHexOrDecimalNumber (Temp1, TRUE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, (UINT64 *)&Address, TRUE, FALSE))) { + if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, &Size, TRUE, FALSE))) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); ShellStatus = SHELL_INVALID_PARAMETER; } - - Temp1 = ShellCommandLineGetRawValue (Package, 2); - if (Temp1 == NULL) { - Size = 512; - } else { - if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, &Size, TRUE, FALSE))) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); - ShellStatus = SHELL_INVALID_PARAMETER; - } - } } } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c index bba6dbf078..c3670cc8d7 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c @@ -736,145 +736,149 @@ MainCmdDmpStore ( if (ShellCommandLineGetCount (Package) > 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmpstore"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetFlag (Package, L"-all") && ShellCommandLineGetFlag (Package, L"-guid")) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-all", L"-guid"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetFlag (Package, L"-s") && ShellCommandLineGetFlag (Package, L"-l")) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l", L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if ((ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-l")) && ShellCommandLineGetFlag (Package, L"-d")) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-d"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if ((ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-l")) && ShellCommandLineGetFlag (Package, L"-sfo")) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-sfo"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - // - // Determine the GUID to search for based on -all and -guid parameters - // - if (!ShellCommandLineGetFlag (Package, L"-all")) { - GuidStr = ShellCommandLineGetValue (Package, L"-guid"); - if (GuidStr != NULL) { - RStatus = StrToGuid (GuidStr, &GuidData); - if (RETURN_ERROR (RStatus) || (GuidStr[GUID_STRING_LENGTH] != L'\0')) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmpstore", GuidStr); - ShellStatus = SHELL_INVALID_PARAMETER; - } + return SHELL_INVALID_PARAMETER; + } - Guid = &GuidData; - } else { - Guid = &gEfiGlobalVariableGuid; + // + // Determine the GUID to search for based on -all and -guid parameters + // + if (!ShellCommandLineGetFlag (Package, L"-all")) { + GuidStr = ShellCommandLineGetValue (Package, L"-guid"); + if (GuidStr != NULL) { + RStatus = StrToGuid (GuidStr, &GuidData); + if (RETURN_ERROR (RStatus) || (GuidStr[GUID_STRING_LENGTH] != L'\0')) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmpstore", GuidStr); + ShellStatus = SHELL_INVALID_PARAMETER; } + + Guid = &GuidData; } else { - Guid = NULL; + Guid = &gEfiGlobalVariableGuid; } + } else { + Guid = NULL; + } - // - // Get the Name of the variable to find - // - Name = ShellCommandLineGetRawValue (Package, 1); + // + // Get the Name of the variable to find + // + Name = ShellCommandLineGetRawValue (Package, 1); - if (ShellStatus == SHELL_SUCCESS) { - if (ShellCommandLineGetFlag (Package, L"-s")) { - Type = DmpStoreSave; - File = ShellCommandLineGetValue (Package, L"-s"); - if (File == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; + if (ShellStatus != SHELL_SUCCESS) { + return ShellStatus; + } + + if (ShellCommandLineGetFlag (Package, L"-s")) { + Type = DmpStoreSave; + File = ShellCommandLineGetValue (Package, L"-s"); + if (File == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-s"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0); + if (!EFI_ERROR (Status)) { + // + // Delete existing file, but do not delete existing directory + // + FileInfo = ShellGetFileInfo (FileHandle); + if (FileInfo == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + Status = EFI_DEVICE_ERROR; } else { - Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0); - if (!EFI_ERROR (Status)) { - // - // Delete existing file, but do not delete existing directory - // - FileInfo = ShellGetFileInfo (FileHandle); - if (FileInfo == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); - Status = EFI_DEVICE_ERROR; - } else { - if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File); - Status = EFI_INVALID_PARAMETER; - } else { - Status = ShellDeleteFile (&FileHandle); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_DELETE_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); - } - } - - FreePool (FileInfo); - } - } else if (Status == EFI_NOT_FOUND) { - // - // Good when file doesn't exist - // - Status = EFI_SUCCESS; + if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File); + Status = EFI_INVALID_PARAMETER; } else { - // - // Otherwise it's bad. - // - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); - } - - if (!EFI_ERROR (Status)) { - Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0); + Status = ShellDeleteFile (&FileHandle); if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_DELETE_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); } } - if (EFI_ERROR (Status)) { - ShellStatus = SHELL_INVALID_PARAMETER; - } + FreePool (FileInfo); } - } else if (ShellCommandLineGetFlag (Package, L"-l")) { - Type = DmpStoreLoad; - File = ShellCommandLineGetValue (Package, L"-l"); - if (File == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-l"); - ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Status == EFI_NOT_FOUND) { + // + // Good when file doesn't exist + // + Status = EFI_SUCCESS; + } else { + // + // Otherwise it's bad. + // + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + } + + if (!EFI_ERROR (Status)) { + Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + } + } + + if (EFI_ERROR (Status)) { + ShellStatus = SHELL_INVALID_PARAMETER; + } + } + } else if (ShellCommandLineGetFlag (Package, L"-l")) { + Type = DmpStoreLoad; + File = ShellCommandLineGetValue (Package, L"-l"); + if (File == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-l"); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + FileInfo = ShellGetFileInfo (FileHandle); + if (FileInfo == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + ShellStatus = SHELL_DEVICE_ERROR; } else { - Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); + if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File); ShellStatus = SHELL_INVALID_PARAMETER; - } else { - FileInfo = ShellGetFileInfo (FileHandle); - if (FileInfo == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File); - ShellStatus = SHELL_DEVICE_ERROR; - } else { - if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - FreePool (FileInfo); - } } + + FreePool (FileInfo); } - } else if (ShellCommandLineGetFlag (Package, L"-d")) { - Type = DmpStoreDelete; - } - - if (ShellCommandLineGetFlag (Package, L"-sfo")) { - StandardFormatOutput = TRUE; } } + } else if (ShellCommandLineGetFlag (Package, L"-d")) { + Type = DmpStoreDelete; + } - if (ShellStatus == SHELL_SUCCESS) { - if (Type == DmpStoreSave) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMPSTORE_SAVE), gShellDebug1HiiHandle, File); - } else if (Type == DmpStoreLoad) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMPSTORE_LOAD), gShellDebug1HiiHandle, File); - } + if (ShellCommandLineGetFlag (Package, L"-sfo")) { + StandardFormatOutput = TRUE; + } - ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle, StandardFormatOutput); - if ((Type == DmpStoreLoad) || (Type == DmpStoreSave)) { - ShellCloseFile (&FileHandle); - } - } + if (ShellStatus != SHELL_SUCCESS) { + return ShellStatus; + } + + if (Type == DmpStoreSave) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMPSTORE_SAVE), gShellDebug1HiiHandle, File); + } else if (Type == DmpStoreLoad) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMPSTORE_LOAD), gShellDebug1HiiHandle, File); + } + + ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle, StandardFormatOutput); + if ((Type == DmpStoreLoad) || (Type == DmpStoreSave)) { + ShellCloseFile (&FileHandle); } return ShellStatus; From d395696428e7198a7369f52a61e579d7a2bf8cd6 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:21:00 +0200 Subject: [PATCH 376/406] ShellPkg/UefiShellDebug1: Lower indentation level in MainCmdXXX() (2/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Lower the indentation level in the newly created MainCmdXXX() functions. To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - Edit/Edit.c - EfiCompress.c - EfiDecompress.c - LoadPciRom.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../UefiShellDebug1CommandsLib/Edit/Edit.c | 171 ++++++++-------- .../UefiShellDebug1CommandsLib/EfiCompress.c | 146 +++++++------- .../EfiDecompress.c | 190 +++++++++--------- .../UefiShellDebug1CommandsLib/LoadPciRom.c | 146 +++++++------- 4 files changed, 328 insertions(+), 325 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c index 2697e71c60..fa179ff88d 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c @@ -22,109 +22,108 @@ MainCmdEdit ( { EFI_STATUS Status; CHAR16 *Buffer; - SHELL_STATUS ShellStatus; CONST CHAR16 *Cwd; CHAR16 *Nfs; CHAR16 *Spot; CONST CHAR16 *TempParam; - Buffer = NULL; - ShellStatus = SHELL_SUCCESS; - Nfs = NULL; + Buffer = NULL; + Nfs = NULL; if (ShellCommandLineGetCount (Package) > 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"edit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Cwd = gEfiShellProtocol->GetCurDir (NULL); - if (Cwd == NULL) { - Cwd = ShellGetEnvironmentVariable (L"path"); - if (Cwd != NULL) { - Nfs = StrnCatGrow (&Nfs, NULL, Cwd+3, 0); - if (Nfs != NULL) { - Spot = StrStr (Nfs, L";"); - if (Spot != NULL) { - *Spot = CHAR_NULL; - } + return SHELL_INVALID_PARAMETER; + } - Spot = StrStr (Nfs, L"\\"); - if (Spot != NULL) { - Spot[1] = CHAR_NULL; - } - - gEfiShellProtocol->SetCurDir (NULL, Nfs); - FreePool (Nfs); + Cwd = gEfiShellProtocol->GetCurDir (NULL); + if (Cwd == NULL) { + Cwd = ShellGetEnvironmentVariable (L"path"); + if (Cwd != NULL) { + Nfs = StrnCatGrow (&Nfs, NULL, Cwd+3, 0); + if (Nfs != NULL) { + Spot = StrStr (Nfs, L";"); + if (Spot != NULL) { + *Spot = CHAR_NULL; } - } - } - Status = MainEditorInit (); - - if (EFI_ERROR (Status)) { - gST->ConOut->ClearScreen (gST->ConOut); - gST->ConOut->EnableCursor (gST->ConOut, TRUE); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_INIT_FAILED), gShellDebug1HiiHandle); - } else { - MainEditorBackup (); - - // - // if editor launched with file named - // - if (ShellCommandLineGetCount (Package) == 2) { - TempParam = ShellCommandLineGetRawValue (Package, 1); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"edit"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - FileBufferSetFileName (TempParam); + Spot = StrStr (Nfs, L"\\"); + if (Spot != NULL) { + Spot[1] = CHAR_NULL; } - } - Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE); - if (!EFI_ERROR (Status)) { - MainEditorRefresh (); - - Status = MainEditorKeyInput (); - } - - if (Status != EFI_OUT_OF_RESOURCES) { - // - // back up the status string - // - Buffer = CatSPrint (NULL, L"%s", StatusBarGetString ()); - } - - MainEditorCleanup (); - - // - // print editor exit code on screen - // - if (Status == EFI_SUCCESS) { - } else if (Status == EFI_OUT_OF_RESOURCES) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"edit"); - } else { - if (Buffer != NULL) { - if (StrCmp (Buffer, L"") != 0) { - // - // print out the status string - // - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_BUFFER), gShellDebug1HiiHandle, Buffer); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle); - } - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle); - } - } - - if (Status != EFI_OUT_OF_RESOURCES) { - SHELL_FREE_NON_NULL (Buffer); + gEfiShellProtocol->SetCurDir (NULL, Nfs); + FreePool (Nfs); } } } - return ShellStatus; + Status = MainEditorInit (); + + if (EFI_ERROR (Status)) { + gST->ConOut->ClearScreen (gST->ConOut); + gST->ConOut->EnableCursor (gST->ConOut, TRUE); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_INIT_FAILED), gShellDebug1HiiHandle); + return SHELL_SUCCESS; + } + + MainEditorBackup (); + + // + // if editor launched with file named + // + if (ShellCommandLineGetCount (Package) == 2) { + TempParam = ShellCommandLineGetRawValue (Package, 1); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"edit"); + return SHELL_INVALID_PARAMETER; + } else { + FileBufferSetFileName (TempParam); + } + } + + Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE); + if (!EFI_ERROR (Status)) { + MainEditorRefresh (); + + Status = MainEditorKeyInput (); + } + + if (Status != EFI_OUT_OF_RESOURCES) { + // + // back up the status string + // + Buffer = CatSPrint (NULL, L"%s", StatusBarGetString ()); + } + + MainEditorCleanup (); + + // + // print editor exit code on screen + // + if (Status == EFI_SUCCESS) { + } else if (Status == EFI_OUT_OF_RESOURCES) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"edit"); + } else { + if (Buffer != NULL) { + if (StrCmp (Buffer, L"") != 0) { + // + // print out the status string + // + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_BUFFER), gShellDebug1HiiHandle, Buffer); + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle); + } + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle); + } + } + + if (Status != EFI_OUT_OF_RESOURCES) { + SHELL_FREE_NON_NULL (Buffer); + } + + return SHELL_SUCCESS; } /** diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c index 7bf6ce87aa..ed4840d434 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c @@ -46,83 +46,87 @@ MainCmdEfiCompress ( if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"eficompress"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount (Package) < 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"eficompress"); + return SHELL_INVALID_PARAMETER; + } + + TempParam = ShellCommandLineGetRawValue (Package, 1); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"eficompress"); + return SHELL_INVALID_PARAMETER; + } + + InFileName = ShellFindFilePath (TempParam); + OutFileName = ShellCommandLineGetRawValue (Package, 2); + if ((InFileName == NULL) || (OutFileName == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"eficompress", TempParam); + ShellStatus = SHELL_NOT_FOUND; + goto Exit; + } + + if (ShellIsDirectory (InFileName) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", InFileName); ShellStatus = SHELL_INVALID_PARAMETER; + } + + if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", OutFileName); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + if (ShellStatus != SHELL_SUCCESS) { + goto Exit; + } + + Status = ShellOpenFileByName (InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue (Package, 1)); + ShellStatus = SHELL_NOT_FOUND; + } + + Status = ShellOpenFileByName (OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue (Package, 2)); + ShellStatus = SHELL_NOT_FOUND; + } + + if (ShellStatus != SHELL_SUCCESS) { + goto Exit; + } + + Status = gEfiShellProtocol->GetFileSize (InShellFileHandle, &InSize); + ASSERT_EFI_ERROR (Status); + InBuffer = AllocateZeroPool ((UINTN)InSize); + if (InBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; } else { - TempParam = ShellCommandLineGetRawValue (Package, 1); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"eficompress"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Exit; + InSize2 = (UINTN)InSize; + Status = gEfiShellProtocol->ReadFile (InShellFileHandle, &InSize2, InBuffer); + InSize = InSize2; + ASSERT_EFI_ERROR (Status); + Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); + if (Status == EFI_BUFFER_TOO_SMALL) { + OutBuffer = AllocateZeroPool ((UINTN)OutSize); + if (OutBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); + } } + } - InFileName = ShellFindFilePath (TempParam); - OutFileName = ShellCommandLineGetRawValue (Package, 2); - if ((InFileName == NULL) || (OutFileName == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"eficompress", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } else { - if (ShellIsDirectory (InFileName) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", InFileName); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", OutFileName); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - if (ShellStatus == SHELL_SUCCESS) { - Status = ShellOpenFileByName (InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue (Package, 1)); - ShellStatus = SHELL_NOT_FOUND; - } - - Status = ShellOpenFileByName (OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue (Package, 2)); - ShellStatus = SHELL_NOT_FOUND; - } - } - - if (ShellStatus == SHELL_SUCCESS) { - Status = gEfiShellProtocol->GetFileSize (InShellFileHandle, &InSize); - ASSERT_EFI_ERROR (Status); - InBuffer = AllocateZeroPool ((UINTN)InSize); - if (InBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - InSize2 = (UINTN)InSize; - Status = gEfiShellProtocol->ReadFile (InShellFileHandle, &InSize2, InBuffer); - InSize = InSize2; - ASSERT_EFI_ERROR (Status); - Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); - if (Status == EFI_BUFFER_TOO_SMALL) { - OutBuffer = AllocateZeroPool ((UINTN)OutSize); - if (OutBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); - } - } - } - - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); - ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); - } else { - OutSize2 = (UINTN)OutSize; - Status = gEfiShellProtocol->WriteFile (OutShellFileHandle, &OutSize2, OutBuffer); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"eficompress", OutFileName); - ShellStatus = SHELL_DEVICE_ERROR; - } - } - } + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); + ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); + } else { + OutSize2 = (UINTN)OutSize; + Status = gEfiShellProtocol->WriteFile (OutShellFileHandle, &OutSize2, OutBuffer); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"eficompress", OutFileName); + ShellStatus = SHELL_DEVICE_ERROR; } } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c index 4fc547a359..0e15c79ed7 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c @@ -52,108 +52,108 @@ MainCmdEfiDecompress ( if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"efidecompress"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount (Package) < 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"efidecompress"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - TempParam = ShellCommandLineGetRawValue (Package, 1); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"efidecompress"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + return SHELL_INVALID_PARAMETER; + } - InFileName = ShellFindFilePath (TempParam); - OutFileName = ShellCommandLineGetRawValue (Package, 2); - if ((InFileName == NULL) || (OutFileName == NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"efidecompress", TempParam); + TempParam = ShellCommandLineGetRawValue (Package, 1); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"efidecompress"); + return SHELL_INVALID_PARAMETER; + } + + InFileName = ShellFindFilePath (TempParam); + OutFileName = ShellCommandLineGetRawValue (Package, 2); + if ((InFileName == NULL) || (OutFileName == NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"efidecompress", TempParam); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + + if (ShellIsDirectory (InFileName) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", InFileName); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", OutFileName); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + if (ShellStatus != SHELL_SUCCESS) { + goto Done; + } + + Status = ShellOpenFileByName (InFileName, &InFileHandle, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"efidecompress", ShellCommandLineGetRawValue (Package, 1)); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + + Status = FileHandleGetSize (InFileHandle, &Temp64Bit); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"efidecompress", ShellCommandLineGetRawValue (Package, 1)); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + + // + // Limit the File Size to UINT32, even though calls accept UINTN. + // 32 bits = 4gb. + // + Status = SafeUint64ToUint32 (Temp64Bit, (UINT32 *)&InSize); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + ShellStatus = SHELL_BAD_BUFFER_SIZE; + goto Done; + } + + InBuffer = AllocateZeroPool (InSize); + if (InBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer); + ASSERT_EFI_ERROR (Status); + + Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress); + ASSERT_EFI_ERROR (Status); + + Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize); + } + + if (EFI_ERROR (Status) || (OutSize == 0)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName); + ShellStatus = SHELL_NOT_FOUND; + } else { + Status = ShellOpenFileByName (OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, 2), Status); ShellStatus = SHELL_NOT_FOUND; } else { - if (ShellIsDirectory (InFileName) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", InFileName); - ShellStatus = SHELL_INVALID_PARAMETER; + OutBuffer = AllocateZeroPool (OutSize); + ScratchBuffer = AllocateZeroPool (ScratchSize); + if ((OutBuffer == NULL) || (ScratchBuffer == NULL)) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = Decompress->Decompress (Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize); } + } + } - if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", OutFileName); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - if (ShellStatus == SHELL_SUCCESS) { - Status = ShellOpenFileByName (InFileName, &InFileHandle, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"efidecompress", ShellCommandLineGetRawValue (Package, 1)); - ShellStatus = SHELL_NOT_FOUND; - } - } - - if (ShellStatus == SHELL_SUCCESS) { - Status = FileHandleGetSize (InFileHandle, &Temp64Bit); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"efidecompress", ShellCommandLineGetRawValue (Package, 1)); - ShellStatus = SHELL_NOT_FOUND; - } - } - - if (ShellStatus == SHELL_SUCCESS) { - // - // Limit the File Size to UINT32, even though calls accept UINTN. - // 32 bits = 4gb. - // - Status = SafeUint64ToUint32 (Temp64Bit, (UINT32 *)&InSize); - if (EFI_ERROR (Status)) { - ASSERT_EFI_ERROR (Status); - ShellStatus = SHELL_BAD_BUFFER_SIZE; - goto Done; - } - - InBuffer = AllocateZeroPool (InSize); - if (InBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer); - ASSERT_EFI_ERROR (Status); - - Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress); - ASSERT_EFI_ERROR (Status); - - Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize); - } - - if (EFI_ERROR (Status) || (OutSize == 0)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName); - ShellStatus = SHELL_NOT_FOUND; - } else { - Status = ShellOpenFileByName (OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, 2), Status); - ShellStatus = SHELL_NOT_FOUND; - } else { - OutBuffer = AllocateZeroPool (OutSize); - ScratchBuffer = AllocateZeroPool (ScratchSize); - if ((OutBuffer == NULL) || (ScratchBuffer == NULL)) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = Decompress->Decompress (Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize); - } - } - } - - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status); - ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); - } else { - OutSizeTemp = OutSize; - Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer); - OutSize = (UINT32)OutSizeTemp; - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"efidecompress", OutFileName, Status); - ShellStatus = SHELL_DEVICE_ERROR; - } - } - } + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status); + ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); + } else { + OutSizeTemp = OutSize; + Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer); + OutSize = (UINT32)OutSizeTemp; + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"efidecompress", OutFileName, Status); + ShellStatus = SHELL_DEVICE_ERROR; } } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c index 687757bd23..dd6b63f6dc 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c @@ -73,90 +73,90 @@ MainCmdLoadPciRom ( if (ShellCommandLineGetCount (Package) < 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"loadpcirom"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - if (ShellCommandLineGetFlag (Package, L"-nc")) { - Connect = FALSE; - } else { - Connect = TRUE; - } + return SHELL_INVALID_PARAMETER; + } + if (ShellCommandLineGetFlag (Package, L"-nc")) { + Connect = FALSE; + } else { + Connect = TRUE; + } + + // + // get a list with each file specified by parameters + // if parameter is a directory then add all the files below it to the list + // + for ( ParamCount = 1, Param = ShellCommandLineGetRawValue (Package, ParamCount) + ; Param != NULL + ; ParamCount++, Param = ShellCommandLineGetRawValue (Package, ParamCount) + ) + { + Status = ShellOpenFileMetaArg ((CHAR16 *)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Param); + ShellStatus = SHELL_ACCESS_DENIED; + break; + } + } + + if ((ShellStatus == SHELL_SUCCESS) && (FileList != NULL)) { // - // get a list with each file specified by parameters - // if parameter is a directory then add all the files below it to the list + // loop through the list and make sure we are not aborting... // - for ( ParamCount = 1, Param = ShellCommandLineGetRawValue (Package, ParamCount) - ; Param != NULL - ; ParamCount++, Param = ShellCommandLineGetRawValue (Package, ParamCount) + for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link) + ; !IsNull (&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag () + ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link) ) { - Status = ShellOpenFileMetaArg ((CHAR16 *)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); + if (EFI_ERROR (Node->Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); + ShellStatus = SHELL_INVALID_PARAMETER; + continue; + } + + if (FileHandleIsDirectory (Node->Handle) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); + ShellStatus = SHELL_INVALID_PARAMETER; + continue; + } + + SourceSize = (UINTN)Node->Info->FileSize; + File1Buffer = AllocateZeroPool (SourceSize); + if (File1Buffer == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"loadpcirom"); + ShellStatus = SHELL_OUT_OF_RESOURCES; + continue; + } + + Status = gEfiShellProtocol->ReadFile (Node->Handle, &SourceSize, File1Buffer); if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Param); - ShellStatus = SHELL_ACCESS_DENIED; - break; + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_READ_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = LoadEfiDriversFromRomImage ( + File1Buffer, + SourceSize, + Node->FullName + ); + + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_LOAD_PCI_ROM_RES), gShellDebug1HiiHandle, Node->FullName, Status); } + + FreePool (File1Buffer); } + } else if (ShellStatus == SHELL_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, "loadpcirom"); + ShellStatus = SHELL_NOT_FOUND; + } - if ((ShellStatus == SHELL_SUCCESS) && (FileList != NULL)) { - // - // loop through the list and make sure we are not aborting... - // - for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link) - ; !IsNull (&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag () - ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link) - ) - { - if (EFI_ERROR (Node->Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); - ShellStatus = SHELL_INVALID_PARAMETER; - continue; - } + if ((FileList != NULL) && !IsListEmpty (&FileList->Link)) { + Status = ShellCloseFileMetaArg (&FileList); + } - if (FileHandleIsDirectory (Node->Handle) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); - ShellStatus = SHELL_INVALID_PARAMETER; - continue; - } + FileList = NULL; - SourceSize = (UINTN)Node->Info->FileSize; - File1Buffer = AllocateZeroPool (SourceSize); - if (File1Buffer == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"loadpcirom"); - ShellStatus = SHELL_OUT_OF_RESOURCES; - continue; - } - - Status = gEfiShellProtocol->ReadFile (Node->Handle, &SourceSize, File1Buffer); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_READ_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Status = LoadEfiDriversFromRomImage ( - File1Buffer, - SourceSize, - Node->FullName - ); - - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_LOAD_PCI_ROM_RES), gShellDebug1HiiHandle, Node->FullName, Status); - } - - FreePool (File1Buffer); - } - } else if (ShellStatus == SHELL_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, "loadpcirom"); - ShellStatus = SHELL_NOT_FOUND; - } - - if ((FileList != NULL) && !IsListEmpty (&FileList->Link)) { - Status = ShellCloseFileMetaArg (&FileList); - } - - FileList = NULL; - - if (Connect) { - Status = LoadPciRomConnectAllDriversToAllControllers (); - } + if (Connect) { + Status = LoadPciRomConnectAllDriversToAllControllers (); } return ShellStatus; From 642954d2956420fa5855754ba41ab2cca7b73c3c Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:21:15 +0200 Subject: [PATCH 377/406] ShellPkg/UefiShellDebug1: Lower indentation level in MainCmdXXX() (3/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Lower the indentation level in the newly created MainCmdXXX() functions. To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - MemMap.c - Mm.c - Mode.c - Pci.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../UefiShellDebug1CommandsLib/MemMap.c | 48 +++---- .../Library/UefiShellDebug1CommandsLib/Mm.c | 122 ++++++++---------- .../Library/UefiShellDebug1CommandsLib/Mode.c | 111 ++++++++-------- .../Library/UefiShellDebug1CommandsLib/Pci.c | 15 +-- 4 files changed, 142 insertions(+), 154 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c index 2bfd5b5fd6..1c427ef761 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c @@ -353,35 +353,35 @@ MainCmdMemMap ( if (ShellCommandLineGetCount (Package) > 1) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"memmap"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { + return SHELL_INVALID_PARAMETER; + } + + Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version); + if (Status == EFI_BUFFER_TOO_SMALL) { + Size += SIZE_1KB; + Descriptors = AllocateZeroPool (Size); + if (Descriptors == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"memmap"); + return SHELL_OUT_OF_RESOURCES; + } + Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version); - if (Status == EFI_BUFFER_TOO_SMALL) { - Size += SIZE_1KB; - Descriptors = AllocateZeroPool (Size); - if (Descriptors == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"memmap"); - return SHELL_OUT_OF_RESOURCES; - } + } - Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version); - } + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_GET_FAILED), gShellDebug1HiiHandle, L"memmap"); + ShellStatus = SHELL_ACCESS_DENIED; + } else { + ASSERT (Version == EFI_MEMORY_DESCRIPTOR_VERSION); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_GET_FAILED), gShellDebug1HiiHandle, L"memmap"); - ShellStatus = SHELL_ACCESS_DENIED; + Sfo = ShellCommandLineGetFlag (Package, L"-sfo"); + if (!Sfo) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_LIST_HEAD), gShellDebug1HiiHandle); } else { - ASSERT (Version == EFI_MEMORY_DESCRIPTOR_VERSION); - - Sfo = ShellCommandLineGetFlag (Package, L"-sfo"); - if (!Sfo) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MEMMAP_LIST_HEAD), gShellDebug1HiiHandle); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"memmap"); - } - - ParseMemoryDescriptors (Descriptors, Size, ItemSize, Sfo); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"memmap"); } + + ParseMemoryDescriptors (Descriptors, Size, ItemSize, Sfo); } if (Descriptors != NULL) { diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c index 203e78bfad..15157fc8df 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c @@ -440,62 +440,55 @@ MainCmdMm ( if (ShellCommandLineGetCount (Package) < 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetFlag (Package, L"-w") && (ShellCommandLineGetValue (Package, L"-w") == NULL)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"mm", L"-w"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } else { - if (ShellCommandLineGetFlag (Package, L"-mmio")) { - AccessType = ShellMmMemoryMappedIo; - if ( ShellCommandLineGetFlag (Package, L"-mem") - || ShellCommandLineGetFlag (Package, L"-io") - || ShellCommandLineGetFlag (Package, L"-pci") - || ShellCommandLineGetFlag (Package, L"-pcie") - ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } else if (ShellCommandLineGetFlag (Package, L"-mem")) { - AccessType = ShellMmMemory; - if ( ShellCommandLineGetFlag (Package, L"-io") - || ShellCommandLineGetFlag (Package, L"-pci") - || ShellCommandLineGetFlag (Package, L"-pcie") - ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } else if (ShellCommandLineGetFlag (Package, L"-io")) { - AccessType = ShellMmIo; - if ( ShellCommandLineGetFlag (Package, L"-pci") - || ShellCommandLineGetFlag (Package, L"-pcie") - ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } else if (ShellCommandLineGetFlag (Package, L"-pci")) { - AccessType = ShellMmPci; - if (ShellCommandLineGetFlag (Package, L"-pcie") + return SHELL_INVALID_PARAMETER; + } + + if (ShellCommandLineGetFlag (Package, L"-mmio")) { + AccessType = ShellMmMemoryMappedIo; + if ( ShellCommandLineGetFlag (Package, L"-mem") + || ShellCommandLineGetFlag (Package, L"-io") + || ShellCommandLineGetFlag (Package, L"-pci") + || ShellCommandLineGetFlag (Package, L"-pcie") ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } else if (ShellCommandLineGetFlag (Package, L"-pcie")) { - AccessType = ShellMmPciExpress; + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); + return SHELL_INVALID_PARAMETER; } + } else if (ShellCommandLineGetFlag (Package, L"-mem")) { + AccessType = ShellMmMemory; + if ( ShellCommandLineGetFlag (Package, L"-io") + || ShellCommandLineGetFlag (Package, L"-pci") + || ShellCommandLineGetFlag (Package, L"-pcie") + ) + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); + return SHELL_INVALID_PARAMETER; + } + } else if (ShellCommandLineGetFlag (Package, L"-io")) { + AccessType = ShellMmIo; + if ( ShellCommandLineGetFlag (Package, L"-pci") + || ShellCommandLineGetFlag (Package, L"-pcie") + ) + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); + return SHELL_INVALID_PARAMETER; + } + } else if (ShellCommandLineGetFlag (Package, L"-pci")) { + AccessType = ShellMmPci; + if (ShellCommandLineGetFlag (Package, L"-pcie") + ) + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mm"); + return SHELL_INVALID_PARAMETER; + } + } else if (ShellCommandLineGetFlag (Package, L"-pcie")) { + AccessType = ShellMmPciExpress; } // @@ -513,28 +506,24 @@ MainCmdMm ( if ((Size != 1) && (Size != 2) && (Size != 4) && (Size != 8)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"mm", Temp, L"-w"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } Temp = ShellCommandLineGetRawValue (Package, 1); if (Temp == NULL) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mm", L"NULL"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } Status = ShellConvertStringToUint64 (Temp, &Address, TRUE, FALSE); if (EFI_ERROR (Status)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mm", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } if ((Address & (Size - 1)) != 0) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_NOT_ALIGNED), gShellDebug1HiiHandle, L"mm", Address); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } // @@ -544,14 +533,12 @@ MainCmdMm ( if ((AccessType == ShellMmPci) || (AccessType == ShellMmPciExpress)) { if (!HasPciRootBridgeIo) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle, L"mm"); - ShellStatus = SHELL_NOT_FOUND; - goto Done; + return SHELL_NOT_FOUND; } if (PciRootBridgeIo == NULL) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_PCIE_ADDRESS_RANGE), gShellDebug1HiiHandle, L"mm", Address); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } } @@ -563,18 +550,16 @@ MainCmdMm ( Status = ShellConvertStringToUint64 (Temp, &Value, TRUE, FALSE); if (EFI_ERROR (Status)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mm", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } if (Value > mShellMmMaxNumber[Size]) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mm", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, FALSE, Address, Size, &Value); - goto Done; + return ShellStatus; } // @@ -593,7 +578,7 @@ MainCmdMm ( ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MM_BUF), gShellDebug1HiiHandle, Size * 2, Buffer & mShellMmMaxNumber[Size]); ShellPrintDefaultEx (L"\r\n"); - goto Done; + return ShellStatus; } // @@ -644,7 +629,6 @@ MainCmdMm ( ASSERT (ShellStatus == SHELL_SUCCESS); -Done: if (InputStr != NULL) { FreePool (InputStr); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c index 3f1da155ac..75a4f1af0c 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c @@ -21,6 +21,7 @@ MainCmdMode ( { EFI_STATUS Status; SHELL_STATUS ShellStatus; + UINTN ArgCount; UINTN NewCol; UINTN NewRow; UINTN Col; @@ -32,59 +33,15 @@ MainCmdMode ( ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; - if (ShellCommandLineGetCount (Package) > 3) { + ArgCount = ShellCommandLineGetCount (Package); + + if (ArgCount > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mode"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) == 2) { + return SHELL_INVALID_PARAMETER; + } else if (ArgCount == 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"mode"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (ShellCommandLineGetCount (Package) == 3) { - Temp = ShellCommandLineGetRawValue (Package, 1); - if (Temp == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - NewCol = ShellStrToUintn (Temp); - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - NewRow = ShellStrToUintn (Temp); - - for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS; LoopVar++) { - Status = gST->ConOut->QueryMode (gST->ConOut, LoopVar, &Col, &Row); - if (EFI_ERROR (Status)) { - continue; - } - - if ((Col == NewCol) && (Row == NewRow)) { - Status = gST->ConOut->SetMode (gST->ConOut, LoopVar); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_SET_FAIL), gShellDebug1HiiHandle, L"mode"); - ShellStatus = SHELL_DEVICE_ERROR; - } else { - // worked fine... - Done = TRUE; - } - - break; - } - } - - if (!Done) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_NO_MATCH), gShellDebug1HiiHandle, L"mode"); - ShellStatus = SHELL_INVALID_PARAMETER; - } - } else if (ShellCommandLineGetCount (Package) == 1) { + return SHELL_INVALID_PARAMETER; + } else if (ArgCount == 1) { // // print out valid // @@ -97,6 +54,58 @@ MainCmdMode ( ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_LIST_ITEM), gShellDebug1HiiHandle, Col, Row, LoopVar == gST->ConOut->Mode->Mode ? L'*' : L' '); } + + return ShellStatus; + } + + // + // ArgCount == 3 + // + + Temp = ShellCommandLineGetRawValue (Package, 1); + if (Temp == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + NewCol = ShellStrToUintn (Temp); + Temp = ShellCommandLineGetRawValue (Package, 2); + if (Temp == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp); + ShellStatus = SHELL_INVALID_PARAMETER; + } + + NewRow = ShellStrToUintn (Temp); + + for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS; LoopVar++) { + Status = gST->ConOut->QueryMode (gST->ConOut, LoopVar, &Col, &Row); + if (EFI_ERROR (Status)) { + continue; + } + + if ((Col == NewCol) && (Row == NewRow)) { + Status = gST->ConOut->SetMode (gST->ConOut, LoopVar); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_SET_FAIL), gShellDebug1HiiHandle, L"mode"); + ShellStatus = SHELL_DEVICE_ERROR; + } else { + // worked fine... + Done = TRUE; + } + + break; + } + } + + if (!Done) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_MODE_NO_MATCH), gShellDebug1HiiHandle, L"mode"); + ShellStatus = SHELL_INVALID_PARAMETER; } return ShellStatus; diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c index 9446cca702..eccd3c46a1 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -2499,26 +2499,22 @@ MainCmdPci ( if (ShellCommandLineGetCount (Package) == 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } if (ShellCommandLineGetCount (Package) > 4) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } if (ShellCommandLineGetFlag (Package, L"-ec") && (ShellCommandLineGetValue (Package, L"-ec") == NULL)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"pci", L"-ec"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } if (ShellCommandLineGetFlag (Package, L"-s") && (ShellCommandLineGetValue (Package, L"-s") == NULL)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"pci", L"-s"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; + return SHELL_INVALID_PARAMETER; } // @@ -2530,8 +2526,7 @@ MainCmdPci ( HandleBuf = (EFI_HANDLE *)AllocateZeroPool (HandleBufSize); if (HandleBuf == NULL) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_OUT_OF_RESOURCES; - goto Done; + return SHELL_OUT_OF_RESOURCES; } Status = gBS->LocateHandle ( From 42f1d004c070e60d05281f98afca56d897d395e9 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Thu, 4 Jun 2026 11:21:31 +0200 Subject: [PATCH 378/406] ShellPkg/UefiShellDebug1: Lower indentation level in MainCmdXXX() (4/4) This patch aims to help breaking down the long functions present in the ShellPkg and reduce complexity/nested code and conditions. Lower the indentation level in the newly created MainCmdXXX() functions. To avoid having one large commit updating all the UefiShellDebug1 commands, only update these files: - SerMode.c - SetSize.c - SetVar.c - SmbiosView/SmbiosView.c No functional change should be induced by this patch. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../UefiShellDebug1CommandsLib/SerMode.c | 196 +++++++++--------- .../UefiShellDebug1CommandsLib/SetSize.c | 27 ++- .../UefiShellDebug1CommandsLib/SetVar.c | 172 +++++++-------- .../SmbiosView/SmbiosView.c | 178 ++++++++-------- 4 files changed, 281 insertions(+), 292 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c index 055498ea42..ab14def5ed 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c @@ -272,116 +272,109 @@ MainCmdSerMode ( if ((ShellCommandLineGetCount (Package) < 6) && (ShellCommandLineGetCount (Package) > 2)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"sermode"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount (Package) > 6) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"sermode"); + return SHELL_INVALID_PARAMETER; + } + + Temp = ShellCommandLineGetRawValue (Package, 1); + if (Temp == NULL) { + return DisplaySettings (0, FALSE); + } + + Status = ShellConvertStringToUint64 (Temp, &Intermediate, TRUE, FALSE); + HandleIdx = (UINTN)Intermediate; + Temp = ShellCommandLineGetRawValue (Package, 2); + if (Temp == NULL) { + return DisplaySettings (HandleIdx, TRUE); + } + + Temp = ShellCommandLineGetRawValue (Package, 2); + if (Temp != NULL) { + BaudRate = ShellStrToUintn (Temp); + } else { + ASSERT (FALSE); + BaudRate = 0; + } + + Temp = ShellCommandLineGetRawValue (Package, 3); + if ((Temp == NULL) || (StrLen (Temp) > 1)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); ShellStatus = SHELL_INVALID_PARAMETER; } else { - Temp = ShellCommandLineGetRawValue (Package, 1); - if (Temp != NULL) { - Status = ShellConvertStringToUint64 (Temp, &Intermediate, TRUE, FALSE); - HandleIdx = (UINTN)Intermediate; - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp == NULL) { - ShellStatus = DisplaySettings (HandleIdx, TRUE); - goto Done; - } - } else { - ShellStatus = DisplaySettings (0, FALSE); - goto Done; - } - - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp != NULL) { - BaudRate = ShellStrToUintn (Temp); - } else { - ASSERT (FALSE); - BaudRate = 0; - } - - Temp = ShellCommandLineGetRawValue (Package, 3); - if ((Temp == NULL) || (StrLen (Temp) > 1)) { + Status = GetParityType (Temp[0], &Parity); + if (EFI_ERROR (Status)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { - Status = GetParityType (Temp[0], &Parity); + return SHELL_INVALID_PARAMETER; + } + } + + Temp = ShellCommandLineGetRawValue (Package, 4); + if (Temp != NULL) { + DataBits = ShellStrToUintn (Temp); + } else { + // + // make sure this is some number not in the list below. + // + DataBits = 0; + } + + if (!ValidDataBits (DataBits)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); + return SHELL_INVALID_PARAMETER; + } + + Temp = ShellCommandLineGetRawValue (Package, 5); + if (Temp == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode"); + return SHELL_INVALID_PARAMETER; + } + + Status = GetStopBits (ShellStrToUintn (Temp), &StopBits); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); + return SHELL_INVALID_PARAMETER; + } + + Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Handles); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode"); + return SHELL_INVALID_PARAMETER; + } + + for (Index = 0; Index < NoHandles; Index++) { + if (ConvertHandleIndexToHandle (HandleIdx) != Handles[Index]) { + continue; + } + + Status = gBS->HandleProtocol (Handles[Index], &gEfiSerialIoProtocolGuid, (VOID **)&SerialIo); + if (!EFI_ERROR (Status)) { + Status = SerialIo->SetAttributes ( + SerialIo, + (UINT64)BaudRate, + SerialIo->Mode->ReceiveFifoDepth, + SerialIo->Mode->Timeout, + Parity, + (UINT8)DataBits, + StopBits + ); if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - Temp = ShellCommandLineGetRawValue (Package, 4); - if (Temp != NULL) { - DataBits = ShellStrToUintn (Temp); - } else { - // - // make sure this is some number not in the list below. - // - DataBits = 0; - } - - if (!ValidDataBits (DataBits)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - Temp = ShellCommandLineGetRawValue (Package, 5); - if (Temp == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - Status = GetStopBits (ShellStrToUintn (Temp), &StopBits); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Handles); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode"); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - for (Index = 0; Index < NoHandles; Index++) { - if (ConvertHandleIndexToHandle (HandleIdx) != Handles[Index]) { - continue; - } - - Status = gBS->HandleProtocol (Handles[Index], &gEfiSerialIoProtocolGuid, (VOID **)&SerialIo); - if (!EFI_ERROR (Status)) { - Status = SerialIo->SetAttributes ( - SerialIo, - (UINT64)BaudRate, - SerialIo->Mode->ReceiveFifoDepth, - SerialIo->Mode->Timeout, - Parity, - (UINT8)DataBits, - StopBits - ); - if (EFI_ERROR (Status)) { - if (Status == EFI_INVALID_PARAMETER) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_UNSUPPORTED), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); - ShellStatus = SHELL_UNSUPPORTED; - } else if (Status == EFI_DEVICE_ERROR) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_DEV_ERROR), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); - ShellStatus = SHELL_ACCESS_DENIED; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_FAIL), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); - ShellStatus = SHELL_ACCESS_DENIED; - } + if (Status == EFI_INVALID_PARAMETER) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_UNSUPPORTED), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); + ShellStatus = SHELL_UNSUPPORTED; + } else if (Status == EFI_DEVICE_ERROR) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_DEV_ERROR), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); + ShellStatus = SHELL_ACCESS_DENIED; } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_HANDLE), gShellDebug1HiiHandle, ConvertHandleToHandleIndex (Handles[Index])); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_FAIL), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index])); + ShellStatus = SHELL_ACCESS_DENIED; } - - break; + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SERMODE_SET_HANDLE), gShellDebug1HiiHandle, ConvertHandleToHandleIndex (Handles[Index])); } + + break; } } @@ -390,7 +383,6 @@ MainCmdSerMode ( ShellStatus = SHELL_INVALID_PARAMETER; } -Done: if (Handles != NULL) { FreePool (Handles); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c index cebd831018..25860edd71 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c @@ -31,23 +31,20 @@ MainCmdSetSize ( if (ShellCommandLineGetCount (Package) < 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize"); - ShellStatus = SHELL_INVALID_PARAMETER; - NewSize = 0; - } else { - Temp1 = ShellCommandLineGetRawValue (Package, 1); - if (Temp1 == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setsize"); - ShellStatus = SHELL_INVALID_PARAMETER; - NewSize = 0; - } else if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize"); - ShellStatus = SHELL_INVALID_PARAMETER; - NewSize = 0; - } else { - NewSize = ShellStrToUintn (Temp1); - } + return SHELL_INVALID_PARAMETER; } + Temp1 = ShellCommandLineGetRawValue (Package, 1); + if (Temp1 == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setsize"); + return SHELL_INVALID_PARAMETER; + } else if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize"); + return SHELL_INVALID_PARAMETER; + } + + NewSize = ShellStrToUintn (Temp1); + for (LoopVar = 2; LoopVar < ShellCommandLineGetCount (Package) && ShellStatus == SHELL_SUCCESS; LoopVar++) { Status = ShellOpenFileByName (ShellCommandLineGetRawValue (Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0); if (EFI_ERROR (Status)) { diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c index cc71540d75..82f829a730 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c @@ -370,104 +370,104 @@ MainCmdSetVar ( if (ShellCommandLineGetCount (Package) < 2) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setvar"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; + } + + VariableName = ShellCommandLineGetRawValue (Package, 1); + if (VariableName == NULL) { + return SHELL_INVALID_PARAMETER; + } + + if (!ShellCommandLineGetFlag (Package, L"-guid")) { + CopyGuid (&Guid, &gEfiGlobalVariableGuid); } else { - VariableName = ShellCommandLineGetRawValue (Package, 1); - if (VariableName == NULL) { + StringGuid = ShellCommandLineGetValue (Package, L"-guid"); + if (StringGuid != NULL) { + RStatus = StrToGuid (StringGuid, &Guid); + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid); return SHELL_INVALID_PARAMETER; } - if (!ShellCommandLineGetFlag (Package, L"-guid")) { - CopyGuid (&Guid, &gEfiGlobalVariableGuid); - } else { - StringGuid = ShellCommandLineGetValue (Package, L"-guid"); - if (StringGuid != NULL) { - RStatus = StrToGuid (StringGuid, &Guid); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid); - return SHELL_INVALID_PARAMETER; + if (RETURN_ERROR (RStatus) || (StringGuid[GUID_STRING_LENGTH] != L'\0')) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } + + if (ShellCommandLineGetCount (Package) == 2) { + // + // Display + // + Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); + if (Status == EFI_BUFFER_TOO_SMALL) { + Buffer = AllocateZeroPool (Size); + if (Buffer == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar"); + return SHELL_OUT_OF_RESOURCES; } - if (RETURN_ERROR (RStatus) || (StringGuid[GUID_STRING_LENGTH] != L'\0')) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid); - ShellStatus = SHELL_INVALID_PARAMETER; + Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); + } + + if (!EFI_ERROR (Status) && (Buffer != NULL)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_PRINT), gShellDebug1HiiHandle, &Guid, VariableName, Size); + for (LoopVar = 0; LoopVar < Size; LoopVar++) { + ShellPrintDefaultEx (L"%02x ", ((UINT8 *)Buffer)[LoopVar]); + } + + ShellPrintDefaultEx (L"\r\n"); + } else { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_ERROR_GET), gShellDebug1HiiHandle, L"setvar", &Guid, VariableName); + ShellStatus = SHELL_ACCESS_DENIED; + } + } else { + // + // Create, Delete or Modify. + // + Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); + if (Status == EFI_BUFFER_TOO_SMALL) { + Buffer = AllocateZeroPool (Size); + if (Buffer == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar"); + return SHELL_OUT_OF_RESOURCES; + } + + Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); + } + + if (EFI_ERROR (Status) || (Buffer == NULL)) { + // + // Creating a new variable. determine attributes from command line. + // + Attributes = 0; + if (ShellCommandLineGetFlag (Package, L"-bs")) { + Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS; + } + + if (ShellCommandLineGetFlag (Package, L"-rt")) { + Attributes |= EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_BOOTSERVICE_ACCESS; + } + + if (ShellCommandLineGetFlag (Package, L"-nv")) { + Attributes |= EFI_VARIABLE_NON_VOLATILE; } } - if (ShellCommandLineGetCount (Package) == 2) { - // - // Display - // - Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); - if (Status == EFI_BUFFER_TOO_SMALL) { - Buffer = AllocateZeroPool (Size); - if (Buffer == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar"); - return SHELL_OUT_OF_RESOURCES; - } + SHELL_FREE_NON_NULL (Buffer); - Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); - } + Size = 0; + Status = GetVariableDataFromParameter (Package, (UINT8 **)&Buffer, &Size); + if (!EFI_ERROR (Status)) { + Status = gRT->SetVariable ((CHAR16 *)VariableName, &Guid, Attributes, Size, Buffer); + } - if (!EFI_ERROR (Status) && (Buffer != NULL)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_PRINT), gShellDebug1HiiHandle, &Guid, VariableName, Size); - for (LoopVar = 0; LoopVar < Size; LoopVar++) { - ShellPrintDefaultEx (L"%02x ", ((UINT8 *)Buffer)[LoopVar]); - } - - ShellPrintDefaultEx (L"\r\n"); - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_ERROR_GET), gShellDebug1HiiHandle, L"setvar", &Guid, VariableName); - ShellStatus = SHELL_ACCESS_DENIED; - } + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, L"setvar", &Guid, VariableName); + ShellStatus = SHELL_ACCESS_DENIED; } else { - // - // Create, Delete or Modify. - // - Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); - if (Status == EFI_BUFFER_TOO_SMALL) { - Buffer = AllocateZeroPool (Size); - if (Buffer == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar"); - return SHELL_OUT_OF_RESOURCES; - } - - Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer); - } - - if (EFI_ERROR (Status) || (Buffer == NULL)) { - // - // Creating a new variable. determine attributes from command line. - // - Attributes = 0; - if (ShellCommandLineGetFlag (Package, L"-bs")) { - Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS; - } - - if (ShellCommandLineGetFlag (Package, L"-rt")) { - Attributes |= EFI_VARIABLE_RUNTIME_ACCESS | - EFI_VARIABLE_BOOTSERVICE_ACCESS; - } - - if (ShellCommandLineGetFlag (Package, L"-nv")) { - Attributes |= EFI_VARIABLE_NON_VOLATILE; - } - } - - SHELL_FREE_NON_NULL (Buffer); - - Size = 0; - Status = GetVariableDataFromParameter (Package, (UINT8 **)&Buffer, &Size); - if (!EFI_ERROR (Status)) { - Status = gRT->SetVariable ((CHAR16 *)VariableName, &Guid, Attributes, Size, Buffer); - } - - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, L"setvar", &Guid, VariableName); - ShellStatus = SHELL_ACCESS_DENIED; - } else { - ASSERT (ShellStatus == SHELL_SUCCESS); - } + ASSERT (ShellStatus == SHELL_SUCCESS); } } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c index 70fc0a33b0..a965b9c3e5 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c @@ -57,13 +57,13 @@ MainCmdSmbiosView ( if (ShellCommandLineGetCount (Package) > 1) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetFlag (Package, L"-t") && (ShellCommandLineGetValue (Package, L"-t") == NULL)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"smbiosview", L"-t"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetFlag (Package, L"-h") && (ShellCommandLineGetValue (Package, L"-h") == NULL)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"smbiosview", L"-h"); - ShellStatus = SHELL_INVALID_PARAMETER; + return SHELL_INVALID_PARAMETER; } else if ( (ShellCommandLineGetFlag (Package, L"-t") && ShellCommandLineGetFlag (Package, L"-h")) || (ShellCommandLineGetFlag (Package, L"-t") && ShellCommandLineGetFlag (Package, L"-s")) || @@ -74,111 +74,111 @@ MainCmdSmbiosView ( ) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); - ShellStatus = SHELL_INVALID_PARAMETER; - } else { + return SHELL_INVALID_PARAMETER; + } + + // + // Init Lib + // + Status1 = LibSmbiosInit (); + Status2 = LibSmbios64BitInit (); + if (EFI_ERROR (Status1) && EFI_ERROR (Status2)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE), gShellDebug1HiiHandle); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + + StructType = STRUCTURE_TYPE_RANDOM; + RandomView = TRUE; + + Temp = ShellCommandLineGetValue (Package, L"-t"); + if (Temp != NULL) { + StructType = (UINT8)ShellStrToUintn (Temp); + } + + if (ShellCommandLineGetFlag (Package, L"-a")) { + gShowType = SHOW_ALL; + } + + if (!EFI_ERROR (Status1)) { // - // Init Lib + // Initialize the StructHandle to be the first handle // - Status1 = LibSmbiosInit (); - Status2 = LibSmbios64BitInit (); - if (EFI_ERROR (Status1) && EFI_ERROR (Status2)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE), gShellDebug1HiiHandle); + StructHandle = INVALID_HANDLE; + LibGetSmbiosStructure (&StructHandle, NULL, NULL); + + Temp = ShellCommandLineGetValue (Package, L"-h"); + if (Temp != NULL) { + RandomView = FALSE; + StructHandle = (UINT16)ShellStrToUintn (Temp); + } + + // + // build statistics table + // + Status = InitSmbiosTableStatistics (); + if (EFI_ERROR (Status)) { ShellStatus = SHELL_NOT_FOUND; goto Done; } - StructType = STRUCTURE_TYPE_RANDOM; - RandomView = TRUE; - - Temp = ShellCommandLineGetValue (Package, L"-t"); - if (Temp != NULL) { - StructType = (UINT8)ShellStrToUintn (Temp); - } - - if (ShellCommandLineGetFlag (Package, L"-a")) { - gShowType = SHOW_ALL; - } - - if (!EFI_ERROR (Status1)) { - // - // Initialize the StructHandle to be the first handle - // - StructHandle = INVALID_HANDLE; - LibGetSmbiosStructure (&StructHandle, NULL, NULL); - - Temp = ShellCommandLineGetValue (Package, L"-h"); - if (Temp != NULL) { - RandomView = FALSE; - StructHandle = (UINT16)ShellStrToUintn (Temp); - } - - // - // build statistics table - // - Status = InitSmbiosTableStatistics (); + if (ShellCommandLineGetFlag (Package, L"-s")) { + Status = DisplayStatisticsTable (SHOW_DETAIL); if (EFI_ERROR (Status)) { ShellStatus = SHELL_NOT_FOUND; - goto Done; } - if (ShellCommandLineGetFlag (Package, L"-s")) { - Status = DisplayStatisticsTable (SHOW_DETAIL); - if (EFI_ERROR (Status)) { - ShellStatus = SHELL_NOT_FOUND; - } - - goto Show64Bit; - } - - // - // Show SMBIOS structure information - // - Status = SMBiosView (StructType, StructHandle, gShowType, RandomView); - if (EFI_ERROR (Status)) { - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } + goto Show64Bit; } + // + // Show SMBIOS structure information + // + Status = SMBiosView (StructType, StructHandle, gShowType, RandomView); + if (EFI_ERROR (Status)) { + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + } + Show64Bit: - if (!EFI_ERROR (Status2)) { - // - // build statistics table - // - Status = InitSmbios64BitTableStatistics (); - if (EFI_ERROR (Status)) { - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } + if (!EFI_ERROR (Status2)) { + // + // build statistics table + // + Status = InitSmbios64BitTableStatistics (); + if (EFI_ERROR (Status)) { + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } - // - // Initialize the StructHandle to be the first handle - // - StructHandle = INVALID_HANDLE; - LibGetSmbios64BitStructure (&StructHandle, NULL, NULL); + // + // Initialize the StructHandle to be the first handle + // + StructHandle = INVALID_HANDLE; + LibGetSmbios64BitStructure (&StructHandle, NULL, NULL); - Temp = ShellCommandLineGetValue (Package, L"-h"); - if (Temp != NULL) { - RandomView = FALSE; - StructHandle = (UINT16)ShellStrToUintn (Temp); - } + Temp = ShellCommandLineGetValue (Package, L"-h"); + if (Temp != NULL) { + RandomView = FALSE; + StructHandle = (UINT16)ShellStrToUintn (Temp); + } - if (ShellCommandLineGetFlag (Package, L"-s")) { - Status = DisplaySmbios64BitStatisticsTable (SHOW_DETAIL); - if (EFI_ERROR (Status)) { - ShellStatus = SHELL_NOT_FOUND; - } - - goto Done; - } - - // - // Show SMBIOS structure information - // - Status = SMBios64View (StructType, StructHandle, gShowType, RandomView); + if (ShellCommandLineGetFlag (Package, L"-s")) { + Status = DisplaySmbios64BitStatisticsTable (SHOW_DETAIL); if (EFI_ERROR (Status)) { ShellStatus = SHELL_NOT_FOUND; } + + goto Done; + } + + // + // Show SMBIOS structure information + // + Status = SMBios64View (StructType, StructHandle, gShowType, RandomView); + if (EFI_ERROR (Status)) { + ShellStatus = SHELL_NOT_FOUND; } } From ba2f2169863df9a5012eb2882cfe2822a49955e4 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Wed, 6 May 2026 11:47:14 +0200 Subject: [PATCH 379/406] ShellPkg/Pci: Extract PciEnumerateAll() Extract the default PCI enumeration path into a helper. No functional change. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../Library/UefiShellDebug1CommandsLib/Pci.c | 385 ++++++++++-------- 1 file changed, 207 insertions(+), 178 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c index eccd3c46a1..0e9ed64c96 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -2450,6 +2450,192 @@ PciConfigSpaceDumpHex ( DumpHex (Indent, Offset, DataSize, UserData); } +/** + Enumerate all PCI functions exposed by the discovered root bridge handles. + + @param[in] HandleBuf Buffer of handles exposing + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL. + @param[in] HandleCount Number of entries in HandleBuf. + + @retval SHELL_SUCCESS Enumeration completed successfully. + @retval SHELL_ABORTED The user interrupted enumeration. + @retval SHELL_NOT_FOUND A root bridge or bus range could not be read. +**/ +STATIC +SHELL_STATUS +PciEnumerateAll ( + IN EFI_HANDLE *HandleBuf, + IN UINTN HandleCount + ) +{ + EFI_STATUS Status; + UINT16 Bus; + UINT16 Device; + UINT16 Func; + UINT64 Address; + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoDev; + PCI_DEVICE_INDEPENDENT_REGION PciHeader; + UINTN ScreenCount; + UINTN TempColumn; + UINTN ScreenSize; + UINTN Index; + BOOLEAN PrintTitle; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors; + UINT16 MinBus; + UINT16 MaxBus; + BOOLEAN IsEnd; + + Status = EFI_SUCCESS; + Address = 0; + IoDev = NULL; + + gST->ConOut->QueryMode ( + gST->ConOut, + gST->ConOut->Mode->Mode, + &TempColumn, + &ScreenSize + ); + + ScreenCount = 0; + ScreenSize -= 4; + if ((ScreenSize & 1) == 1) { + ScreenSize -= 1; + } + + PrintTitle = TRUE; + + // + // For each handle, which decides a segment and a bus number range, + // enumerate all devices on it. + // + for (Index = 0; Index < HandleCount; Index++) { + Status = PciGetProtocolAndResource ( + HandleBuf[Index], + &IoDev, + &Descriptors + ); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_HANDLE_CFG_ERR), gShellDebug1HiiHandle, L"pci"); + return SHELL_NOT_FOUND; + } + + // + // No document say it's impossible for a RootBridgeIo protocol handle + // to have more than one address space descriptors, so find out every + // bus range and for each of them do device enumeration. + // + while (TRUE) { + Status = PciGetNextBusRange (&Descriptors, &MinBus, &MaxBus, &IsEnd); + + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_BUS_RANGE_ERR), gShellDebug1HiiHandle, L"pci"); + return SHELL_NOT_FOUND; + } + + if (IsEnd) { + break; + } + + for (Bus = MinBus; Bus <= MaxBus; Bus++) { + // + // For each devices, enumerate all functions it contains + // + for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) { + // + // For each function, read its configuration space and print summary + // + for (Func = 0; Func <= PCI_MAX_FUNC; Func++) { + if (ShellGetExecutionBreakFlag ()) { + return SHELL_ABORTED; + } + + Address = EFI_PCI_ADDRESS (Bus, Device, Func, 0); + IoDev->Pci.Read ( + IoDev, + EfiPciWidthUint16, + Address, + 1, + &PciHeader.VendorId + ); + + // + // If VendorId = 0xffff, there does not exist a device at this + // location. For each device, if there is any function on it, + // there must be 1 function at Function 0. So if Func = 0, there + // will be no more functions in the same device, so we can break + // loop to deal with the next device. + // + if ((PciHeader.VendorId == 0xffff) && (Func == 0)) { + break; + } + + if (PciHeader.VendorId != 0xffff) { + if (PrintTitle) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_TITLE), gShellDebug1HiiHandle); + PrintTitle = FALSE; + } + + IoDev->Pci.Read ( + IoDev, + EfiPciWidthUint32, + Address, + sizeof (PciHeader) / sizeof (UINT32), + &PciHeader + ); + + ShellPrintHiiDefaultEx ( + STRING_TOKEN (STR_PCI_LINE_P1), + gShellDebug1HiiHandle, + IoDev->SegmentNumber, + Bus, + Device, + Func + ); + + PciPrintClassCode (PciHeader.ClassCode, FALSE); + ShellPrintHiiDefaultEx ( + STRING_TOKEN (STR_PCI_LINE_P2), + gShellDebug1HiiHandle, + PciHeader.VendorId, + PciHeader.DeviceId, + PciHeader.ClassCode[0] + ); + + ScreenCount += 2; + if ((ScreenCount >= ScreenSize) && (ScreenSize != 0)) { + // + // If ScreenSize == 0 we have the console redirected so don't + // block updates. + // + ScreenCount = 0; + } + + // + // If this is not a multi-function device, we can leave the loop + // to deal with the next device. + // + if ((Func == 0) && ((PciHeader.HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00)) { + break; + } + } + } + } + } + + // + // If Descriptor is NULL, Configuration() returns EFI_UNSUPPRORED, + // we assume the bus range is 0~PCI_MAX_BUS. After enumerated all + // devices on all bus, we can leave loop. + // + if (Descriptors == NULL) { + break; + } + } + } + + return SHELL_SUCCESS; +} + /** Main function of the 'Pci' command. @param[in] Package List of input parameter for the command. @@ -2460,36 +2646,26 @@ MainCmdPci ( LIST_ENTRY *Package ) { - UINT16 Segment; - UINT16 Bus; - UINT16 Device; - UINT16 Func; - UINT64 Address; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoDev; - EFI_STATUS Status; - PCI_DEVICE_INDEPENDENT_REGION PciHeader; - PCI_CONFIG_SPACE ConfigSpace; - UINTN ScreenCount; - UINTN TempColumn; - UINTN ScreenSize; - BOOLEAN ExplainData; - UINTN Index; - UINTN SizeOfHeader; - BOOLEAN PrintTitle; - UINTN HandleBufSize; - EFI_HANDLE *HandleBuf; - UINTN HandleCount; - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors; - UINT16 MinBus; - UINT16 MaxBus; - BOOLEAN IsEnd; - SHELL_STATUS ShellStatus; - CONST CHAR16 *Temp; - UINT64 RetVal; - UINT16 ExtendedCapability; - UINT8 PcieCapabilityPtr; - UINT8 *ExtendedConfigSpace; - UINTN ExtendedConfigSize; + UINT16 Segment; + UINT16 Bus; + UINT16 Device; + UINT16 Func; + UINT64 Address; + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoDev; + EFI_STATUS Status; + PCI_CONFIG_SPACE ConfigSpace; + BOOLEAN ExplainData; + UINTN SizeOfHeader; + UINTN HandleBufSize; + EFI_HANDLE *HandleBuf; + UINTN HandleCount; + SHELL_STATUS ShellStatus; + CONST CHAR16 *Temp; + UINT64 RetVal; + UINT16 ExtendedCapability; + UINT8 PcieCapabilityPtr; + UINT8 *ExtendedConfigSpace; + UINTN ExtendedConfigSize; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; @@ -2565,154 +2741,7 @@ MainCmdPci ( // Argument Count == 1(no other argument): enumerate all pci functions // if (ShellCommandLineGetCount (Package) == 1) { - gST->ConOut->QueryMode ( - gST->ConOut, - gST->ConOut->Mode->Mode, - &TempColumn, - &ScreenSize - ); - - ScreenCount = 0; - ScreenSize -= 4; - if ((ScreenSize & 1) == 1) { - ScreenSize -= 1; - } - - PrintTitle = TRUE; - - // - // For each handle, which decides a segment and a bus number range, - // enumerate all devices on it. - // - for (Index = 0; Index < HandleCount; Index++) { - Status = PciGetProtocolAndResource ( - HandleBuf[Index], - &IoDev, - &Descriptors - ); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_HANDLE_CFG_ERR), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } - - // - // No document say it's impossible for a RootBridgeIo protocol handle - // to have more than one address space descriptors, so find out every - // bus range and for each of them do device enumeration. - // - while (TRUE) { - Status = PciGetNextBusRange (&Descriptors, &MinBus, &MaxBus, &IsEnd); - - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_BUS_RANGE_ERR), gShellDebug1HiiHandle, L"pci"); - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } - - if (IsEnd) { - break; - } - - for (Bus = MinBus; Bus <= MaxBus; Bus++) { - // - // For each devices, enumerate all functions it contains - // - for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) { - // - // For each function, read its configuration space and print summary - // - for (Func = 0; Func <= PCI_MAX_FUNC; Func++) { - if (ShellGetExecutionBreakFlag ()) { - ShellStatus = SHELL_ABORTED; - goto Done; - } - - Address = EFI_PCI_ADDRESS (Bus, Device, Func, 0); - IoDev->Pci.Read ( - IoDev, - EfiPciWidthUint16, - Address, - 1, - &PciHeader.VendorId - ); - - // - // If VendorId = 0xffff, there does not exist a device at this - // location. For each device, if there is any function on it, - // there must be 1 function at Function 0. So if Func = 0, there - // will be no more functions in the same device, so we can break - // loop to deal with the next device. - // - if ((PciHeader.VendorId == 0xffff) && (Func == 0)) { - break; - } - - if (PciHeader.VendorId != 0xffff) { - if (PrintTitle) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_PCI_TITLE), gShellDebug1HiiHandle); - PrintTitle = FALSE; - } - - IoDev->Pci.Read ( - IoDev, - EfiPciWidthUint32, - Address, - sizeof (PciHeader) / sizeof (UINT32), - &PciHeader - ); - - ShellPrintHiiDefaultEx ( - STRING_TOKEN (STR_PCI_LINE_P1), - gShellDebug1HiiHandle, - IoDev->SegmentNumber, - Bus, - Device, - Func - ); - - PciPrintClassCode (PciHeader.ClassCode, FALSE); - ShellPrintHiiDefaultEx ( - STRING_TOKEN (STR_PCI_LINE_P2), - gShellDebug1HiiHandle, - PciHeader.VendorId, - PciHeader.DeviceId, - PciHeader.ClassCode[0] - ); - - ScreenCount += 2; - if ((ScreenCount >= ScreenSize) && (ScreenSize != 0)) { - // - // If ScreenSize == 0 we have the console redirected so don't - // block updates - // - ScreenCount = 0; - } - - // - // If this is not a multi-function device, we can leave the loop - // to deal with the next device. - // - if ((Func == 0) && ((PciHeader.HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00)) { - break; - } - } - } - } - } - - // - // If Descriptor is NULL, Configuration() returns EFI_UNSUPPRORED, - // we assume the bus range is 0~PCI_MAX_BUS. After enumerated all - // devices on all bus, we can leave loop. - // - if (Descriptors == NULL) { - break; - } - } - } - - Status = EFI_SUCCESS; + ShellStatus = PciEnumerateAll (HandleBuf, HandleCount); goto Done; } From c089090278236fdd84404b9ec233835aa0accc96 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Wed, 6 May 2026 12:11:44 +0200 Subject: [PATCH 380/406] ShellPkg/Pci: Extract ParsePciBdf() Extract BDF argument parsing into a helper. No functional change. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../Library/UefiShellDebug1CommandsLib/Pci.c | 155 ++++++++++-------- 1 file changed, 90 insertions(+), 65 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c index 0e9ed64c96..57ed5cd201 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -2636,6 +2636,93 @@ PciEnumerateAll ( return SHELL_SUCCESS; } +/** + Parse the three positional PCI BDF fields from the command line. + + @param[in] Package Parsed command line package for the `pci` command. + @param[out] Bus Parsed bus number. + @param[out] Device Parsed device number. + @param[out] Func Parsed function number. + + @retval SHELL_SUCCESS The BDF fields were parsed successfully. + @retval SHELL_INVALID_PARAMETER One of the fields was not valid hexadecimal + input or exceeded the allowed PCI range. +**/ +STATIC +SHELL_STATUS +ParsePciBdf ( + IN LIST_ENTRY *Package, + OUT UINT16 *Bus, + OUT UINT16 *Device, + OUT UINT16 *Func + ) +{ + CONST CHAR16 *Temp; + UINT64 RetVal[3]; + UINTN Index; + + ASSERT (Package != NULL); + ASSERT (Bus != NULL); + ASSERT (Device != NULL); + ASSERT (Func != NULL); + + *Bus = 0; + *Device = 0; + *Func = 0; + + // + // The first Argument(except "-i") is assumed to be Bus number, second + // to be Device number, and third to be Func number. + // + + for (Index = 0; Index < 3; Index++) { + Temp = ShellCommandLineGetRawValue (Package, Index + 1); + if (Temp == NULL) { + continue; + } + + // + // Input converted to hexadecimal number. + // + if (EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal[Index], TRUE, TRUE))) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); + return SHELL_INVALID_PARAMETER; + } + + switch (Index) { + case 0: + *Bus = (UINT16)RetVal[Index]; + if (*Bus > PCI_MAX_BUS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); + return SHELL_INVALID_PARAMETER; + } + + break; + case 1: + *Device = (UINT16)RetVal[Index]; + if (*Device > PCI_MAX_DEVICE) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); + return SHELL_INVALID_PARAMETER; + } + + break; + case 2: + *Func = (UINT16)RetVal[Index]; + if (*Func > PCI_MAX_FUNC) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); + return SHELL_INVALID_PARAMETER; + } + + break; + default: + ASSERT (FALSE); + return SHELL_INVALID_PARAMETER; + } + } + + return SHELL_SUCCESS; +} + /** Main function of the 'Pci' command. @param[in] Package List of input parameter for the command. @@ -2747,9 +2834,6 @@ MainCmdPci ( ExplainData = FALSE; Segment = 0; - Bus = 0; - Device = 0; - Func = 0; ExtendedCapability = 0xFFFF; if (ShellCommandLineGetFlag (Package, L"-i")) { ExplainData = TRUE; @@ -2769,68 +2853,9 @@ MainCmdPci ( } } - // - // The first Argument(except "-i") is assumed to be Bus number, second - // to be Device number, and third to be Func number. - // - Temp = ShellCommandLineGetRawValue (Package, 1); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - Bus = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (Bus > PCI_MAX_BUS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - Temp = ShellCommandLineGetRawValue (Package, 2); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - Device = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (Device > PCI_MAX_DEVICE) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - } - - Temp = ShellCommandLineGetRawValue (Package, 3); - if (Temp != NULL) { - // - // Input converted to hexadecimal number. - // - if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) { - Func = (UINT16)RetVal; - } else { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } - - if (Func > PCI_MAX_FUNC) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"pci", Temp); - ShellStatus = SHELL_INVALID_PARAMETER; - goto Done; - } + ShellStatus = ParsePciBdf (Package, &Bus, &Device, &Func); + if (ShellStatus != SHELL_SUCCESS) { + goto Done; } Temp = ShellCommandLineGetValue (Package, L"-ec"); From f260ae0375876d2d8683d7dab54071b1d980b15b Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Wed, 6 May 2026 12:37:59 +0200 Subject: [PATCH 381/406] ShellPkg/EfiCompress: Extract OpenFileHelper() and CompressFile() Extract file opening and compression code into helpers. Upon calling: - gEfiShellProtocol->GetFileSize() - gEfiShellProtocol->ReadFile() the returned Status is now checked. Upon calling AllocateZeroPool, the failed status is now set to EFI_OUT_OF_RESOURCES. Other than that, no functional change. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../UefiShellDebug1CommandsLib/EfiCompress.c | 199 ++++++++++++------ 1 file changed, 131 insertions(+), 68 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c index ed4840d434..ff5240baf2 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c @@ -10,6 +10,133 @@ #include "UefiShellDebug1CommandsLib.h" #include "Compress.h" +/** + Compress the full contents of an input file and write the compressed payload + to an output file handle. + + @param[in] InShellFileHandle Source file to read and compress. + @param[in] OutShellFileHandle Destination file to receive compressed data. + @param[in] OutFileName Name of the output file for error reporting. + + @retval SHELL_SUCCESS Compression and write completed successfully. + @retval SHELL_OUT_OF_RESOURCES A required buffer allocation failed. + @retval SHELL_DEVICE_ERROR Read, compress, or write failed. +**/ +STATIC +SHELL_STATUS +CompressFile ( + IN SHELL_FILE_HANDLE InShellFileHandle, + IN SHELL_FILE_HANDLE OutShellFileHandle, + IN CONST CHAR16 *OutFileName + ) +{ + EFI_STATUS Status; + UINT64 OutSize; + UINTN OutSize2; + VOID *OutBuffer; + UINT64 InSize; + UINTN InSize2; + VOID *InBuffer; + SHELL_STATUS ShellStatus; + + OutSize = 0; + OutBuffer = NULL; + InBuffer = NULL; + ShellStatus = SHELL_SUCCESS; + + Status = gEfiShellProtocol->GetFileSize (InShellFileHandle, &InSize); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); + return SHELL_DEVICE_ERROR; + } + + InBuffer = AllocateZeroPool ((UINTN)InSize); + if (InBuffer == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, EFI_OUT_OF_RESOURCES); + return SHELL_OUT_OF_RESOURCES; + } + + InSize2 = (UINTN)InSize; + Status = gEfiShellProtocol->ReadFile (InShellFileHandle, &InSize2, InBuffer); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); + ShellStatus = SHELL_DEVICE_ERROR; + goto Exit; + } + + InSize = InSize2; + Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); + if (Status == EFI_BUFFER_TOO_SMALL) { + OutBuffer = AllocateZeroPool ((UINTN)OutSize); + if (OutBuffer == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, EFI_OUT_OF_RESOURCES); + ShellStatus = SHELL_OUT_OF_RESOURCES; + goto Exit; + } + + Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); + } + + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); + ShellStatus = SHELL_DEVICE_ERROR; + goto Exit; + } + + OutSize2 = (UINTN)OutSize; + Status = gEfiShellProtocol->WriteFile (OutShellFileHandle, &OutSize2, OutBuffer); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"eficompress", OutFileName); + ShellStatus = SHELL_DEVICE_ERROR; + goto Exit; + } + +Exit: + SHELL_FREE_NON_NULL (InBuffer); + SHELL_FREE_NON_NULL (OutBuffer); + + return ShellStatus; +} + +/** + Validate that a path is not a directory and open it with the requested mode. + + @param[in] FileName Path to open. + @param[in] OpenMode Mode passed to ShellOpenFileByName(). + @param[out] ShellFileHandle Opened shell file handle. + + @retval SHELL_SUCCESS The file was opened successfully. + @retval SHELL_INVALID_PARAMETER FileName names a directory. + @retval SHELL_NOT_FOUND The file could not be opened. +**/ +STATIC +SHELL_STATUS +OpenFileHelper ( + IN CONST CHAR16 *FileName, + IN UINT64 OpenMode, + OUT SHELL_FILE_HANDLE *ShellFileHandle + ) +{ + EFI_STATUS Status; + + ASSERT (ShellFileHandle != NULL); + + if (ShellIsDirectory (FileName) == EFI_SUCCESS) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", FileName); + return SHELL_INVALID_PARAMETER; + } + + Status = ShellOpenFileByName (FileName, ShellFileHandle, OpenMode, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", FileName); + return SHELL_NOT_FOUND; + } + + return SHELL_SUCCESS; +} + /** Main function of the 'EfiCompress' command. @param[in] Package List of input parameter for the command. @@ -20,29 +147,18 @@ MainCmdEfiCompress ( LIST_ENTRY *Package ) { - EFI_STATUS Status; SHELL_STATUS ShellStatus; SHELL_FILE_HANDLE InShellFileHandle; SHELL_FILE_HANDLE OutShellFileHandle; - UINT64 OutSize; - UINTN OutSize2; - VOID *OutBuffer; - UINT64 InSize; - UINTN InSize2; - VOID *InBuffer; CHAR16 *InFileName; CONST CHAR16 *OutFileName; CONST CHAR16 *TempParam; InFileName = NULL; OutFileName = NULL; - OutSize = 0; ShellStatus = SHELL_SUCCESS; - Status = EFI_SUCCESS; - OutBuffer = NULL; InShellFileHandle = NULL; OutShellFileHandle = NULL; - InBuffer = NULL; if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"eficompress"); @@ -60,75 +176,24 @@ MainCmdEfiCompress ( } InFileName = ShellFindFilePath (TempParam); - OutFileName = ShellCommandLineGetRawValue (Package, 2); + OutFileName = (CHAR16 *)ShellCommandLineGetRawValue (Package, 2); if ((InFileName == NULL) || (OutFileName == NULL)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"eficompress", TempParam); ShellStatus = SHELL_NOT_FOUND; goto Exit; } - if (ShellIsDirectory (InFileName) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", InFileName); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", OutFileName); - ShellStatus = SHELL_INVALID_PARAMETER; - } - + ShellStatus = OpenFileHelper (InFileName, EFI_FILE_MODE_READ, &InShellFileHandle); if (ShellStatus != SHELL_SUCCESS) { goto Exit; } - Status = ShellOpenFileByName (InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue (Package, 1)); - ShellStatus = SHELL_NOT_FOUND; - } - - Status = ShellOpenFileByName (OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue (Package, 2)); - ShellStatus = SHELL_NOT_FOUND; - } - + ShellStatus = OpenFileHelper (OutFileName, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, &OutShellFileHandle); if (ShellStatus != SHELL_SUCCESS) { goto Exit; } - Status = gEfiShellProtocol->GetFileSize (InShellFileHandle, &InSize); - ASSERT_EFI_ERROR (Status); - InBuffer = AllocateZeroPool ((UINTN)InSize); - if (InBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - InSize2 = (UINTN)InSize; - Status = gEfiShellProtocol->ReadFile (InShellFileHandle, &InSize2, InBuffer); - InSize = InSize2; - ASSERT_EFI_ERROR (Status); - Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); - if (Status == EFI_BUFFER_TOO_SMALL) { - OutBuffer = AllocateZeroPool ((UINTN)OutSize); - if (OutBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); - } - } - } - - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); - ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); - } else { - OutSize2 = (UINTN)OutSize; - Status = gEfiShellProtocol->WriteFile (OutShellFileHandle, &OutSize2, OutBuffer); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"eficompress", OutFileName); - ShellStatus = SHELL_DEVICE_ERROR; - } - } + ShellStatus = CompressFile (InShellFileHandle, OutShellFileHandle, OutFileName); Exit: if (InShellFileHandle != NULL) { @@ -140,8 +205,6 @@ Exit: } SHELL_FREE_NON_NULL (InFileName); - SHELL_FREE_NON_NULL (InBuffer); - SHELL_FREE_NON_NULL (OutBuffer); return ShellStatus; } From d9185d45c21ba5f385996b9d76309e2cc24cc2af Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Tue, 26 May 2026 11:29:15 +0200 Subject: [PATCH 382/406] ShellPkg/Dmem: Refactor MainCmdDmem() Refactor MainCmdDmem() to make it easier to understand. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../Library/UefiShellDebug1CommandsLib/Dmem.c | 81 ++++++++++++------- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c index efce6cd09d..6b408d409f 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c @@ -430,6 +430,30 @@ DisplaySystemTable ( return ShellStatus; } +/** + Display memory contents and, when applicable, the decoded system table. + + @param[in] Package List of input parameters. + @param[in] Address Base address to display. + @param[in] Size Number of bytes to display. +**/ +STATIC +SHELL_STATUS +DisplayMemory ( + IN LIST_ENTRY *Package, + IN VOID *Address, + IN UINT64 Size + ) +{ + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size); + DumpHex (2, (UINTN)Address, (UINTN)Size, Address); + if (Address == (VOID *)gST) { + return DisplaySystemTable (Package, Address); + } + + return SHELL_SUCCESS; +} + /** Main function of the 'Dmem' command. @param[in] Package List of input parameter for the command. @@ -440,14 +464,10 @@ MainCmdDmem ( LIST_ENTRY *Package ) { - SHELL_STATUS ShellStatus; VOID *Address; UINT64 Size; CONST CHAR16 *Temp1; - - ShellStatus = SHELL_SUCCESS; - Address = NULL; - Size = 0; + BOOLEAN HasAddress; if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmem"); @@ -456,38 +476,43 @@ MainCmdDmem ( Temp1 = ShellCommandLineGetRawValue (Package, 1); if (Temp1 == NULL) { - Address = gST; - Size = sizeof (*gST); + HasAddress = FALSE; } else { + HasAddress = TRUE; if (!ShellIsHexOrDecimalNumber (Temp1, TRUE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, (UINT64 *)&Address, TRUE, FALSE))) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); - ShellStatus = SHELL_INVALID_PARAMETER; - } - - Temp1 = ShellCommandLineGetRawValue (Package, 2); - if (Temp1 == NULL) { - Size = 512; - } else { - if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, &Size, TRUE, FALSE))) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); - ShellStatus = SHELL_INVALID_PARAMETER; - } + return SHELL_INVALID_PARAMETER; } } - if (ShellStatus == SHELL_SUCCESS) { - if (!ShellCommandLineGetFlag (Package, L"-mmio")) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size); - DumpHex (2, (UINTN)Address, (UINTN)Size, Address); - if (Address == (VOID *)gST) { - ShellStatus = DisplaySystemTable (Package, Address); - } - } else { - ShellStatus = DisplayMmioMemory (Address, (UINTN)Size); + Temp1 = ShellCommandLineGetRawValue (Package, 2); + if (Temp1 == NULL) { + Size = 512; + } else { + if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, &Size, TRUE, FALSE))) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); + return SHELL_INVALID_PARAMETER; } } - return ShellStatus; + if (ShellCommandLineGetFlag (Package, L"-mmio")) { + if (!HasAddress) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"dmem"); + return SHELL_INVALID_PARAMETER; + } + + return DisplayMmioMemory (Address, (UINTN)Size); + } + + // + // Default to gST for main system memory + // + if (!HasAddress) { + Address = gST; + Size = sizeof (*gST); + } + + return DisplayMemory (Package, Address, Size); } STATIC CONST SHELL_PARAM_ITEM ParamList[] = { From 35a2f2754615bb3e029d3c86da09f8a32e5b14a1 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Tue, 26 May 2026 12:31:10 +0200 Subject: [PATCH 383/406] ShellPkg/EfiDecompress: Check presence of decompression protocol Check the return value of LocateProtocol() before using the decompression protocol. This avoids a potential NULL pointer derefence spotted by codeql. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c index 0e15c79ed7..32788e7818 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c @@ -120,7 +120,11 @@ MainCmdEfiDecompress ( ASSERT_EFI_ERROR (Status); Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize); } From 383e680c3cf62b564783a5a26eae0b9ffd881b61 Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Tue, 26 May 2026 13:02:20 +0200 Subject: [PATCH 384/406] ShellPkg/Comp: Extract helper functions Refactor the Comp command and extract 2 functions: - OpenFileOperand() - CompareFiles() This allows to simplify the logic of MainCmdComp() and fix some codeql reported potential errors. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../Library/UefiShellDebug1CommandsLib/Comp.c | 447 ++++++++++-------- 1 file changed, 260 insertions(+), 187 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c index 3b7bf34c7c..38b78472fa 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c @@ -122,6 +122,58 @@ FileBufferUninit ( SHELL_FREE_NON_NULL (FileBuffer->Data); } +/** + Open the filename of the input Package at ParamIndex for reading. + + @param[in] Package Parsed command line package. + @param[in] ParamIndex Package Index to read. + @param[in] CommandName Command name used in user-facing diagnostics. + @param[out] FileName Resolved file path. The caller owns the returned + buffer on success. + @param[out] FileHandle Open handle for the resolved file on success. + + @retval SHELL_SUCCESS The file operand was resolved and opened. + @retval SHELL_INVALID_PARAMETER The positional operand is missing. + @retval SHELL_NOT_FOUND The file could not be resolved or opened. +**/ +STATIC +SHELL_STATUS +OpenFileOperand ( + IN LIST_ENTRY *Package, + IN UINTN ParamIndex, + IN CONST CHAR16 *CommandName, + OUT CHAR16 **FileName, + OUT SHELL_FILE_HANDLE *FileHandle + ) +{ + CONST CHAR16 *TempParam; + EFI_STATUS Status; + + *FileName = NULL; + *FileHandle = NULL; + + TempParam = ShellCommandLineGetRawValue (Package, ParamIndex); + if (TempParam == NULL) { + ASSERT (TempParam != NULL); + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, CommandName, TempParam); + return SHELL_INVALID_PARAMETER; + } + + *FileName = ShellFindFilePath (TempParam); + if (*FileName == NULL) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, CommandName, TempParam); + return SHELL_NOT_FOUND; + } + + Status = ShellOpenFileByName (*FileName, FileHandle, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, CommandName, TempParam); + return SHELL_NOT_FOUND; + } + + return SHELL_SUCCESS; +} + /** Read a byte from a SHELL_FILE_HANDLE, buffered with a FILE_BUFFER. @@ -191,6 +243,189 @@ FileBufferReadByte ( return EFI_SUCCESS; } +/** + Compare two files and report their differences. + + @param[in] FileHandle1 Handle for the first file. + @param[in] FileHandle2 Handle for the second file. + @param[in] FileName1 Name of the first file for reporting. + @param[in] FileName2 Name of the second file for reporting. + @param[in] DifferentCount Maximum number of difference points to + report. + @param[in] DifferentBytes Maximum number of bytes to show for each + difference point. + @param[in, out] DataFromFile1 Scratch buffer for bytes from the first + file. + @param[in, out] DataFromFile2 Scratch buffer for bytes from the second + file. + @param[in, out] FileBuffer1 Buffered reader state for the first file. + @param[in, out] FileBuffer2 Buffered reader state for the second file. + + @retval SHELL_SUCCESS The files compare equal. + @retval SHELL_NOT_EQUAL One or more difference points were reported. +**/ +STATIC +SHELL_STATUS +CompareFiles ( + IN SHELL_FILE_HANDLE FileHandle1, + IN SHELL_FILE_HANDLE FileHandle2, + IN CONST CHAR16 *FileName1, + IN CONST CHAR16 *FileName2, + IN UINT64 DifferentCount, + IN UINT64 DifferentBytes, + IN OUT UINT8 *DataFromFile1, + IN OUT UINT8 *DataFromFile2, + IN OUT FILE_BUFFER *FileBuffer1, + IN OUT FILE_BUFFER *FileBuffer2 + ) +{ + EFI_STATUS Status; + UINT8 OneByteFromFile1; + UINT8 OneByteFromFile2; + UINTN InsertPosition1; + UINTN InsertPosition2; + UINTN DataSizeFromFile1; + UINTN DataSizeFromFile2; + UINTN TempAddress; + UINTN Index; + UINTN DiffPointAddress; + UINT8 ReportedDiffPointCount; + READ_STATUS ReadStatus; + + ReadStatus = OutOfDiffPoint; + InsertPosition1 = 0; + InsertPosition2 = 0; + TempAddress = 0; + DiffPointAddress = 0; + Status = EFI_SUCCESS; + OneByteFromFile1 = 0; + OneByteFromFile2 = 0; + ReportedDiffPointCount = 0; + + while ((UINT64)ReportedDiffPointCount < DifferentCount) { + DataSizeFromFile1 = 1; + DataSizeFromFile2 = 1; + OneByteFromFile1 = 0; + OneByteFromFile2 = 0; + Status = FileBufferReadByte ( + FileHandle1, + FileBuffer1, + &DataSizeFromFile1, + &OneByteFromFile1 + ); + ASSERT_EFI_ERROR (Status); + Status = FileBufferReadByte ( + FileHandle2, + FileBuffer2, + &DataSizeFromFile2, + &OneByteFromFile2 + ); + ASSERT_EFI_ERROR (Status); + + TempAddress++; + + // + // 1.When end of file and no chars in DataFromFile buffer, then break while. + // 2.If no more char in File1 or File2, The ReadStatus is InPrevDiffPoint forever. + // So the previous different point is the last one, then break the while block. + // + if (((DataSizeFromFile1 == 0) && (InsertPosition1 == 0) && (DataSizeFromFile2 == 0) && (InsertPosition2 == 0)) || + ((ReadStatus == InPrevDiffPoint) && ((DataSizeFromFile1 == 0) || (DataSizeFromFile2 == 0))) + ) + { + break; + } + + if (ReadStatus == OutOfDiffPoint) { + if (OneByteFromFile1 != OneByteFromFile2) { + ReadStatus = InDiffPoint; + DiffPointAddress = TempAddress; + if (DataSizeFromFile1 == 1) { + DataFromFile1[InsertPosition1++] = OneByteFromFile1; + } + + if (DataSizeFromFile2 == 1) { + DataFromFile2[InsertPosition2++] = OneByteFromFile2; + } + } + } else if (ReadStatus == InDiffPoint) { + if (DataSizeFromFile1 == 1) { + DataFromFile1[InsertPosition1++] = OneByteFromFile1; + } + + if (DataSizeFromFile2 == 1) { + DataFromFile2[InsertPosition2++] = OneByteFromFile2; + } + } else if (ReadStatus == InPrevDiffPoint) { + if (OneByteFromFile1 == OneByteFromFile2) { + ReadStatus = OutOfDiffPoint; + } + } + + // + // ReadStatus should be always equal InDiffPoint. + // + if ((InsertPosition1 == DifferentBytes) || + (InsertPosition2 == DifferentBytes) || + ((DataSizeFromFile1 == 0) && (DataSizeFromFile2 == 0)) + ) + { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_DIFFERENCE_POINT), gShellDebug1HiiHandle, ++ReportedDiffPointCount); + PrintDifferentPoint (FileName1, L"File1", DataFromFile1, InsertPosition1, DiffPointAddress, DifferentBytes); + PrintDifferentPoint (FileName2, L"File2", DataFromFile2, InsertPosition2, DiffPointAddress, DifferentBytes); + + // + // One of two buffuers is empty, it means this is the last different point. + // + if ((InsertPosition1 == 0) || (InsertPosition2 == 0)) { + break; + } + + for (Index = 1; Index < InsertPosition1 && Index < InsertPosition2; Index++) { + if (DataFromFile1[Index] == DataFromFile2[Index]) { + ReadStatus = OutOfDiffPoint; + break; + } + } + + if (ReadStatus == OutOfDiffPoint) { + // + // Try to find a new different point in the rest of DataFromFile. + // + for ( ; Index < MAX (InsertPosition1, InsertPosition2); Index++) { + if (DataFromFile1[Index] != DataFromFile2[Index]) { + ReadStatus = InDiffPoint; + DiffPointAddress += Index; + break; + } + } + } else { + // + // Doesn't find a new different point, still in the same different point. + // + ReadStatus = InPrevDiffPoint; + } + + CopyMem (DataFromFile1, DataFromFile1 + Index, InsertPosition1 - Index); + CopyMem (DataFromFile2, DataFromFile2 + Index, InsertPosition2 - Index); + + SetMem (DataFromFile1 + InsertPosition1 - Index, (UINTN)DifferentBytes - InsertPosition1 + Index, 0); + SetMem (DataFromFile2 + InsertPosition2 - Index, (UINTN)DifferentBytes - InsertPosition2 + Index, 0); + + InsertPosition1 -= Index; + InsertPosition2 -= Index; + } + } + + if (ReportedDiffPointCount != 0) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle); + return SHELL_NOT_EQUAL; + } + + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle); + return SHELL_SUCCESS; +} + /** Main function of the 'Comp' command. @param[in] Package List of input parameter for the command. @@ -212,38 +447,21 @@ MainCmdComp ( UINT64 Size2; UINT64 DifferentBytes; UINT64 DifferentCount; - UINT8 DiffPointNumber; - UINT8 OneByteFromFile1; - UINT8 OneByteFromFile2; UINT8 *DataFromFile1; UINT8 *DataFromFile2; FILE_BUFFER FileBuffer1; FILE_BUFFER FileBuffer2; - UINTN InsertPosition1; - UINTN InsertPosition2; - UINTN DataSizeFromFile1; - UINTN DataSizeFromFile2; - UINTN TempAddress; - UINTN Index; - UINTN DiffPointAddress; - READ_STATUS ReadStatus; - ShellStatus = SHELL_SUCCESS; - Status = EFI_SUCCESS; - FileName1 = NULL; - FileName2 = NULL; - FileHandle1 = NULL; - FileHandle2 = NULL; - DataFromFile1 = NULL; - DataFromFile2 = NULL; - ReadStatus = OutOfDiffPoint; - DifferentCount = 10; - DifferentBytes = 4; - DiffPointNumber = 0; - InsertPosition1 = 0; - InsertPosition2 = 0; - TempAddress = 0; - DiffPointAddress = 0; + ShellStatus = SHELL_SUCCESS; + Status = EFI_SUCCESS; + FileName1 = NULL; + FileName2 = NULL; + FileHandle1 = NULL; + FileHandle2 = NULL; + DataFromFile1 = NULL; + DataFromFile2 = NULL; + DifferentCount = 10; + DifferentBytes = 4; if (ShellCommandLineGetCount (Package) > 3) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp"); @@ -253,45 +471,12 @@ MainCmdComp ( return SHELL_INVALID_PARAMETER; } - TempParam = ShellCommandLineGetRawValue (Package, 1); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam); - return SHELL_INVALID_PARAMETER; - } - - FileName1 = ShellFindFilePath (TempParam); - if (FileName1 == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } else { - Status = ShellOpenFileByName (FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } - } - - TempParam = ShellCommandLineGetRawValue (Package, 2); - if (TempParam == NULL) { - ASSERT (TempParam != NULL); - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_INVALID_PARAMETER; + ShellStatus = OpenFileOperand (Package, 1, L"comp", &FileName1, &FileHandle1); + if (ShellStatus != SHELL_SUCCESS) { goto Exit; } - FileName2 = ShellFindFilePath (TempParam); - if (FileName2 == NULL) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } else { - Status = ShellOpenFileByName (FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); - ShellStatus = SHELL_NOT_FOUND; - } - } - + ShellStatus = OpenFileOperand (Package, 2, L"comp", &FileName2, &FileHandle2); if (ShellStatus != SHELL_SUCCESS) { goto Exit; } @@ -353,139 +538,27 @@ MainCmdComp ( SHELL_FREE_NON_NULL (DataFromFile2); FileBufferUninit (&FileBuffer1); FileBufferUninit (&FileBuffer2); - } - - if (ShellStatus != SHELL_SUCCESS) { goto Exit; } - while ((UINT64)DiffPointNumber < DifferentCount) { - DataSizeFromFile1 = 1; - DataSizeFromFile2 = 1; - OneByteFromFile1 = 0; - OneByteFromFile2 = 0; - Status = FileBufferReadByte ( - FileHandle1, - &FileBuffer1, - &DataSizeFromFile1, - &OneByteFromFile1 - ); - ASSERT_EFI_ERROR (Status); - Status = FileBufferReadByte ( - FileHandle2, - &FileBuffer2, - &DataSizeFromFile2, - &OneByteFromFile2 - ); - ASSERT_EFI_ERROR (Status); - - TempAddress++; - - // - // 1.When end of file and no chars in DataFromFile buffer, then break while. - // 2.If no more char in File1 or File2, The ReadStatus is InPrevDiffPoint forever. - // So the previous different point is the last one, then break the while block. - // - if (((DataSizeFromFile1 == 0) && (InsertPosition1 == 0) && (DataSizeFromFile2 == 0) && (InsertPosition2 == 0)) || - ((ReadStatus == InPrevDiffPoint) && ((DataSizeFromFile1 == 0) || (DataSizeFromFile2 == 0))) - ) - { - break; - } - - if (ReadStatus == OutOfDiffPoint) { - if (OneByteFromFile1 != OneByteFromFile2) { - ReadStatus = InDiffPoint; - DiffPointAddress = TempAddress; - if (DataSizeFromFile1 == 1) { - DataFromFile1[InsertPosition1++] = OneByteFromFile1; - } - - if (DataSizeFromFile2 == 1) { - DataFromFile2[InsertPosition2++] = OneByteFromFile2; - } - } - } else if (ReadStatus == InDiffPoint) { - if (DataSizeFromFile1 == 1) { - DataFromFile1[InsertPosition1++] = OneByteFromFile1; - } - - if (DataSizeFromFile2 == 1) { - DataFromFile2[InsertPosition2++] = OneByteFromFile2; - } - } else if (ReadStatus == InPrevDiffPoint) { - if (OneByteFromFile1 == OneByteFromFile2) { - ReadStatus = OutOfDiffPoint; - } - } - - // - // ReadStatus should be always equal InDiffPoint. - // - if ((InsertPosition1 == DifferentBytes) || - (InsertPosition2 == DifferentBytes) || - ((DataSizeFromFile1 == 0) && (DataSizeFromFile2 == 0)) - ) - { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_DIFFERENCE_POINT), gShellDebug1HiiHandle, ++DiffPointNumber); - PrintDifferentPoint (FileName1, L"File1", DataFromFile1, InsertPosition1, DiffPointAddress, DifferentBytes); - PrintDifferentPoint (FileName2, L"File2", DataFromFile2, InsertPosition2, DiffPointAddress, DifferentBytes); - - // - // One of two buffuers is empty, it means this is the last different point. - // - if ((InsertPosition1 == 0) || (InsertPosition2 == 0)) { - break; - } - - for (Index = 1; Index < InsertPosition1 && Index < InsertPosition2; Index++) { - if (DataFromFile1[Index] == DataFromFile2[Index]) { - ReadStatus = OutOfDiffPoint; - break; - } - } - - if (ReadStatus == OutOfDiffPoint) { - // - // Try to find a new different point in the rest of DataFromFile. - // - for ( ; Index < MAX (InsertPosition1, InsertPosition2); Index++) { - if (DataFromFile1[Index] != DataFromFile2[Index]) { - ReadStatus = InDiffPoint; - DiffPointAddress += Index; - break; - } - } - } else { - // - // Doesn't find a new different point, still in the same different point. - // - ReadStatus = InPrevDiffPoint; - } - - CopyMem (DataFromFile1, DataFromFile1 + Index, InsertPosition1 - Index); - CopyMem (DataFromFile2, DataFromFile2 + Index, InsertPosition2 - Index); - - SetMem (DataFromFile1 + InsertPosition1 - Index, (UINTN)DifferentBytes - InsertPosition1 + Index, 0); - SetMem (DataFromFile2 + InsertPosition2 - Index, (UINTN)DifferentBytes - InsertPosition2 + Index, 0); - - InsertPosition1 -= Index; - InsertPosition2 -= Index; - } - } + ShellStatus = CompareFiles ( + FileHandle1, + FileHandle2, + FileName1, + FileName2, + DifferentCount, + DifferentBytes, + DataFromFile1, + DataFromFile2, + &FileBuffer1, + &FileBuffer2 + ); SHELL_FREE_NON_NULL (DataFromFile1); SHELL_FREE_NON_NULL (DataFromFile2); FileBufferUninit (&FileBuffer1); FileBufferUninit (&FileBuffer2); - if (DiffPointNumber == 0) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle); - } else { - ShellStatus = SHELL_NOT_EQUAL; - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle); - } - Exit: SHELL_FREE_NON_NULL (FileName1); SHELL_FREE_NON_NULL (FileName2); From fa41c179db1f9fc21eb425f44b85a16262c806ca Mon Sep 17 00:00:00 2001 From: Pierre Gondois <pierre.gondois@arm.com> Date: Wed, 27 May 2026 16:55:26 +0200 Subject: [PATCH 385/406] ShellPkg/EfiDecompress: Fix Codeql issues Fix codeql reported issues by flattening MainCmdEfiDecompress(), making it easier for the tool to evaluate potential risks. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> --- .../EfiDecompress.c | 82 ++++++++++--------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c index 32788e7818..9129844f36 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c @@ -76,14 +76,12 @@ MainCmdEfiDecompress ( if (ShellIsDirectory (InFileName) == EFI_SUCCESS) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", InFileName); ShellStatus = SHELL_INVALID_PARAMETER; + goto Done; } if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", OutFileName); ShellStatus = SHELL_INVALID_PARAMETER; - } - - if (ShellStatus != SHELL_SUCCESS) { goto Done; } @@ -114,51 +112,59 @@ MainCmdEfiDecompress ( InBuffer = AllocateZeroPool (InSize); if (InBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer); - ASSERT_EFI_ERROR (Status); - - Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress); - if (EFI_ERROR (Status)) { - ASSERT_EFI_ERROR (Status); - ShellStatus = SHELL_NOT_FOUND; - goto Done; - } - - Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize); + ShellStatus = SHELL_OUT_OF_RESOURCES; + goto Done; } + Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + ShellStatus = SHELL_DEVICE_ERROR; + goto Done; + } + + Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + + Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize); if (EFI_ERROR (Status) || (OutSize == 0)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName); ShellStatus = SHELL_NOT_FOUND; - } else { - Status = ShellOpenFileByName (OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, 2), Status); - ShellStatus = SHELL_NOT_FOUND; - } else { - OutBuffer = AllocateZeroPool (OutSize); - ScratchBuffer = AllocateZeroPool (ScratchSize); - if ((OutBuffer == NULL) || (ScratchBuffer == NULL)) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = Decompress->Decompress (Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize); - } - } + goto Done; } + Status = ShellOpenFileByName (OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, 2), Status); + ShellStatus = SHELL_NOT_FOUND; + goto Done; + } + + OutBuffer = AllocateZeroPool (OutSize); + ScratchBuffer = AllocateZeroPool (ScratchSize); + if ((OutBuffer == NULL) || (ScratchBuffer == NULL)) { + ShellStatus = SHELL_OUT_OF_RESOURCES; + goto Done; + } + + Status = Decompress->Decompress (Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize); if (EFI_ERROR (Status)) { ShellPrintHiiDefaultEx (STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status); ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); - } else { - OutSizeTemp = OutSize; - Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer); - OutSize = (UINT32)OutSizeTemp; - if (EFI_ERROR (Status)) { - ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"efidecompress", OutFileName, Status); - ShellStatus = SHELL_DEVICE_ERROR; - } + goto Done; + } + + OutSizeTemp = OutSize; + Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer); + OutSize = (UINT32)OutSizeTemp; + if (EFI_ERROR (Status)) { + ShellPrintHiiDefaultEx (STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"efidecompress", OutFileName, Status); + ShellStatus = SHELL_DEVICE_ERROR; + goto Done; } Done: From bf0dc7d78701c93a2edeeadcb0daca58f4af91a6 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Wed, 22 Oct 2025 11:33:02 -0700 Subject: [PATCH 386/406] MdeModulePkg: Fix comparison with wider widths https://codeql.github.com/codeql-query-help/cpp/cpp-comparison-with-wider-type If the narrow type (smaller range) is compared against a wide type (larger range), the narrow value may overflow before reaching the wide value. This can cause unexpected behavior, such as: Infinite loops (loop condition never becomes false). Incorrect logic (comparison results are misleading). Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c | 2 +- MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c | 2 +- MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c | 8 ++++---- .../Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c | 6 +++--- MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c | 2 +- MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 2 +- MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c | 2 +- MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c | 2 +- MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c index 19d7b4930c..f475cadcb5 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c @@ -943,7 +943,7 @@ AtaPioDataInOut ( IN ATA_NONBLOCK_TASK *Task ) { - UINTN WordCount; + UINT64 WordCount; UINTN Increment; UINT16 *Buffer16; EFI_STATUS Status; diff --git a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c index 7b390995b3..950ca0f098 100644 --- a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c +++ b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c @@ -517,7 +517,7 @@ AtapiEnumerateDevices ( IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev ) { - UINT8 Index1; + UINT32 Index1; UINT8 Index2; UINTN DevicePosition; EFI_PEI_BLOCK_IO_MEDIA MediaInfo; diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c index f818e48fc1..9dde95b5ea 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c @@ -219,10 +219,10 @@ NvmeCreatePrpList ( OUT VOID **Mapping ) { - UINTN PrpEntryNo; + UINT64 PrpEntryNo; UINT64 PrpListBase; - UINTN PrpListIndex; - UINTN PrpEntryIndex; + UINT64 PrpListIndex; + UINT64 PrpEntryIndex; UINT64 Remainder; EFI_PHYSICAL_ADDRESS PrpListPhyAddr; UINTN Bytes; @@ -236,7 +236,7 @@ NvmeCreatePrpList ( // // Calculate total PrpList number. // - *PrpListNo = (UINTN)DivU64x64Remainder ((UINT64)Pages, (UINT64)PrpEntryNo - 1, &Remainder); + *PrpListNo = (UINTN)DivU64x64Remainder ((UINT64)Pages, PrpEntryNo - 1, &Remainder); if (*PrpListNo == 0) { *PrpListNo = 1; } else if ((Remainder != 0) && (Remainder != 1)) { diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c index ac9328047f..b329dbe979 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c @@ -27,12 +27,12 @@ NvmeCreatePrpList ( IN UINTN Pages ) { - UINTN PrpEntryNo; + UINT64 PrpEntryNo; UINTN PrpListNo; UINT64 PrpListBase; VOID *PrpListHost; UINTN PrpListIndex; - UINTN PrpEntryIndex; + UINT64 PrpEntryIndex; UINT64 Remainder; EFI_PHYSICAL_ADDRESS PrpListPhyAddr; UINTN Bytes; @@ -47,7 +47,7 @@ NvmeCreatePrpList ( // // Calculate total PrpList number. // - PrpListNo = (UINTN)DivU64x64Remainder ((UINT64)Pages, (UINT64)PrpEntryNo, &Remainder); + PrpListNo = (UINTN)DivU64x64Remainder ((UINT64)Pages, PrpEntryNo, &Remainder); if (Remainder != 0) { PrpListNo += 1; } diff --git a/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c b/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c index dcdaa6cf9b..fe8cb834b3 100644 --- a/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c +++ b/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c @@ -1234,7 +1234,7 @@ SerialRead ( ) { SERIAL_DEV *SerialDevice; - UINT32 Index; + UINTN Index; UINT8 *CharBuffer; UINTN Elapsed; EFI_STATUS Status; diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c index 9e8a7f4e43..4b95028e4a 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c @@ -1476,7 +1476,7 @@ BuildAdmaDescTable ( EFI_PHYSICAL_ADDRESS Data; UINT64 DataLen; UINT64 Entries; - UINT32 Index; + UINT64 Index; UINT64 Remaining; UINT64 Address; UINTN TableSize; diff --git a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c index bafd71e9b5..89df43c9dd 100644 --- a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c +++ b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c @@ -934,7 +934,7 @@ BuildAdmaDescTable ( EFI_PHYSICAL_ADDRESS Data; UINT64 DataLen; UINT64 Entries; - UINT32 Index; + UINT64 Index; UINT64 Remaining; UINT32 Address; diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c index 805037e942..305eb8193d 100644 --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c @@ -317,7 +317,7 @@ UfsInitUtpPrdt ( IN UINT32 BufferSize ) { - UINT32 PrdtIndex; + UINTN PrdtIndex; UINT32 RemainingLen; UINT8 *Remaining; UINTN PrdtNumber; diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c index a67994000c..6b433f18e9 100644 --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c @@ -389,7 +389,7 @@ UfsInitUtpPrdt ( IN UINT32 BufferSize ) { - UINT32 PrdtIndex; + UINTN PrdtIndex; UINT32 RemainingLen; UINT8 *Remaining; UINTN PrdtNumber; From 0bc1db4adfbdf0160a9c60eec18a23f3e282f4ab Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Wed, 22 Oct 2025 11:33:02 -0700 Subject: [PATCH 387/406] MdeModulePkg: Fix missing NULL tests https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp For items which allocate memory, or get a pointer from another structure, it is important to validate that the pointers are not null before they are dereferenced. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../Bus/Ata/AtaBusDxe/AtaPassThruExecute.c | 15 +- .../NonDiscoverablePciDeviceIo.c | 2 +- .../Bus/Pci/PciBusDxe/PciDeviceSupport.c | 6 +- .../Bus/Pci/PciBusDxe/PciEnumerator.c | 59 ++++-- MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c | 45 ++++- .../Bus/Pci/PciBusDxe/PciOptionRomSupport.c | 4 +- .../Bus/Pci/PciBusDxe/PciResourceSupport.c | 183 ++++++++++-------- .../Bus/Pci/PciHostBridgeDxe/PciHostBridge.c | 5 +- .../Pci/PciHostBridgeDxe/PciRootBridgeIo.c | 21 +- MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c | 28 ++- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 48 ++++- MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c | 44 ++++- 12 files changed, 328 insertions(+), 132 deletions(-) diff --git a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c index 57aefa04c2..bcd5b374c2 100644 --- a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c +++ b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c @@ -929,12 +929,19 @@ EXIT: if (EFI_ERROR (Status)) { OldTpl = gBS->RaiseTPL (TPL_NOTIFY); Token->TransactionStatus = Status; - *EventCount = (*EventCount) - (TempCount - Index); - *IsError = TRUE; + if (EventCount != NULL) { + *EventCount = (*EventCount) - (TempCount - Index); + } - if (*EventCount == 0) { + if (IsError != NULL) { + *IsError = TRUE; + } + + if ((EventCount != NULL) && (*EventCount == 0)) { FreePool (EventCount); - FreePool (IsError); + if (IsError != NULL) { + FreePool (IsError); + } } if (SubTask != NULL) { diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c index 4daf51761b..8cf80e5c9d 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c @@ -1008,7 +1008,7 @@ NonCoherentPciIoFreeBuffer ( } } - if (!Found) { + if (!Found || (Alloc == NULL)) { ASSERT_EFI_ERROR (EFI_NOT_FOUND); return EFI_NOT_FOUND; } diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c index 409c01d107..3d3e064f37 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c @@ -781,7 +781,11 @@ StartPciDevices ( LIST_ENTRY *CurrentLink; RootBridge = GetRootBridgeByHandle (Controller); - ASSERT (RootBridge != NULL); + if (RootBridge == NULL ) { + ASSERT (RootBridge != NULL); + return EFI_NOT_READY; + } + ThisHostBridge = RootBridge->PciRootBridgeIo->ParentHandle; CurrentLink = mPciDevicePool.ForwardLink; diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c index 3f8c6e6da7..f49ff4f798 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c @@ -881,7 +881,9 @@ GetMaxResourceConsumerDevice ( && (Temp->ResourceUsage != PciResUsagePadding)) { PPBResNode = GetMaxResourceConsumerDevice (Temp); - PciResNode = GetLargerConsumerDevice (PciResNode, PPBResNode); + if (PPBResNode != NULL) { + PciResNode = GetLargerConsumerDevice (PciResNode, PPBResNode); + } } else { PciResNode = GetLargerConsumerDevice (PciResNode, Temp); } @@ -1445,6 +1447,8 @@ PciBridgeResourceAllocator ( UINT64 PMem64Base; EFI_STATUS Status; + Status = EFI_OUT_OF_RESOURCES; + IoBridge = CreateResourceNode ( Bridge, 0, @@ -1453,6 +1457,9 @@ PciBridgeResourceAllocator ( PciBarTypeIo16, PciResUsageTypical ); + if (IoBridge == NULL) { + goto Exit; + } Mem32Bridge = CreateResourceNode ( Bridge, @@ -1462,6 +1469,9 @@ PciBridgeResourceAllocator ( PciBarTypeMem32, PciResUsageTypical ); + if (Mem32Bridge == NULL) { + goto Exit1; + } PMem32Bridge = CreateResourceNode ( Bridge, @@ -1471,6 +1481,9 @@ PciBridgeResourceAllocator ( PciBarTypePMem32, PciResUsageTypical ); + if (PMem32Bridge == NULL) { + goto Exit2; + } Mem64Bridge = CreateResourceNode ( Bridge, @@ -1480,6 +1493,9 @@ PciBridgeResourceAllocator ( PciBarTypeMem64, PciResUsageTypical ); + if (Mem64Bridge == NULL) { + goto Exit3; + } PMem64Bridge = CreateResourceNode ( Bridge, @@ -1489,6 +1505,9 @@ PciBridgeResourceAllocator ( PciBarTypePMem64, PciResUsageTypical ); + if (PMem64Bridge == NULL) { + goto Exit4; + } // // Create resourcemap by going through all the devices subject to this root bridge @@ -1512,7 +1531,7 @@ PciBridgeResourceAllocator ( ); if (EFI_ERROR (Status)) { - return Status; + goto Exit5; } // @@ -1555,19 +1574,29 @@ PciBridgeResourceAllocator ( PMem64Bridge ); - DestroyResourceTree (IoBridge); - DestroyResourceTree (Mem32Bridge); - DestroyResourceTree (PMem32Bridge); +Exit5: DestroyResourceTree (PMem64Bridge); - DestroyResourceTree (Mem64Bridge); - - gBS->FreePool (IoBridge); - gBS->FreePool (Mem32Bridge); - gBS->FreePool (PMem32Bridge); gBS->FreePool (PMem64Bridge); + +Exit4: + DestroyResourceTree (Mem64Bridge); gBS->FreePool (Mem64Bridge); - return EFI_SUCCESS; +Exit3: + DestroyResourceTree (PMem32Bridge); + gBS->FreePool (PMem32Bridge); + +Exit2: + DestroyResourceTree (Mem32Bridge); + gBS->FreePool (Mem32Bridge); + +Exit1: + DestroyResourceTree (IoBridge); + gBS->FreePool (IoBridge); + +Exit: + + return Status; } /** @@ -2015,12 +2044,10 @@ PciHotPlugRequestNotify ( return EFI_INVALID_PARAMETER; } - if (Operation == EfiPciHotPlugRequestAdd) { - if (ChildHandleBuffer == NULL) { + if (ChildHandleBuffer == NULL) { + if (Operation == EfiPciHotPlugRequestAdd) { return EFI_INVALID_PARAMETER; - } - } else if ((Operation == EfiPciHotplugRequestRemove) && (*NumberOfChildren != 0)) { - if (ChildHandleBuffer == NULL) { + } else if ((Operation == EfiPciHotplugRequestRemove) && (*NumberOfChildren != 0)) { return EFI_INVALID_PARAMETER; } } diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c index e75b18eaa1..5b4b77ed07 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c @@ -381,6 +381,10 @@ DumpResourceMap ( } ChildResources = AllocatePool (sizeof (PCI_RESOURCE_NODE *) * ChildResourceCount); + if (ChildResources == NULL) { + return; + } + ASSERT (ChildResources != NULL); ChildResourceCount = 0; for (Index = 0; Index < ResourceCount; Index++) { @@ -523,7 +527,6 @@ PciHostBridgeResourceAllocator ( // Get Root Bridge Device by handle // RootBridgeDev = GetRootBridgeByHandle (RootBridgeHandle); - if (RootBridgeDev == NULL) { return EFI_NOT_FOUND; } @@ -545,6 +548,9 @@ PciHostBridgeResourceAllocator ( PciBarTypeIo16, PciResUsageTypical ); + if (IoBridge == NULL) { + return EFI_OUT_OF_RESOURCES; + } Mem32Bridge = CreateResourceNode ( RootBridgeDev, @@ -554,6 +560,10 @@ PciHostBridgeResourceAllocator ( PciBarTypeMem32, PciResUsageTypical ); + if (Mem32Bridge == NULL) { + FreePool (IoBridge); + return EFI_OUT_OF_RESOURCES; + } PMem32Bridge = CreateResourceNode ( RootBridgeDev, @@ -563,6 +573,11 @@ PciHostBridgeResourceAllocator ( PciBarTypePMem32, PciResUsageTypical ); + if (PMem32Bridge == NULL) { + FreePool (IoBridge); + FreePool (Mem32Bridge); + return EFI_OUT_OF_RESOURCES; + } Mem64Bridge = CreateResourceNode ( RootBridgeDev, @@ -572,6 +587,12 @@ PciHostBridgeResourceAllocator ( PciBarTypeMem64, PciResUsageTypical ); + if (Mem64Bridge == NULL) { + FreePool (IoBridge); + FreePool (Mem32Bridge); + FreePool (PMem32Bridge); + return EFI_OUT_OF_RESOURCES; + } PMem64Bridge = CreateResourceNode ( RootBridgeDev, @@ -581,6 +602,13 @@ PciHostBridgeResourceAllocator ( PciBarTypePMem64, PciResUsageTypical ); + if (PMem64Bridge == NULL) { + FreePool (IoBridge); + FreePool (Mem32Bridge); + FreePool (PMem32Bridge); + FreePool (Mem64Bridge); + return EFI_OUT_OF_RESOURCES; + } // // Get the max ROM size that the root bridge can process @@ -667,10 +695,13 @@ PciHostBridgeResourceAllocator ( } } - // - // End while, at least one Root Bridge should be found. - // - ASSERT (RootBridgeDev != NULL); + if (RootBridgeDev == NULL) { + // + // End while, at least one Root Bridge should be found. + // + ASSERT (RootBridgeDev != NULL); + return EFI_NOT_FOUND; + } // // Notify platform to start to program the resource @@ -764,6 +795,10 @@ PciHostBridgeResourceAllocator ( } } + if (RootBridgeDev == NULL) { + return EFI_NOT_FOUND; + } + // // End while // diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c index c290884110..1e5f5212a3 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -727,7 +727,9 @@ ProcessOpRomImage ( EfiOpRomImageNode.EndingOffset = (UINTN)RomBarOffset + ImageSize - 1 - (UINTN)RomBar; PciOptionRomImageDevicePath = AppendDevicePathNode (PciDevice->DevicePath, &EfiOpRomImageNode.Header); - ASSERT (PciOptionRomImageDevicePath != NULL); + if (PciOptionRomImageDevicePath == NULL) { + return EFI_NOT_FOUND; + } // // load image and start image diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c index 8ffd05f327..8f3cff3eaa 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c @@ -430,12 +430,15 @@ GetResourceFromDevice ( { UINT8 Index; PCI_RESOURCE_NODE *Node; + PCI_RESOURCE_NODE *DestNode; BOOLEAN ResourceRequested; Node = NULL; ResourceRequested = FALSE; for (Index = 0; Index < PCI_MAX_BAR; Index++) { + DestNode = NULL; + Node = NULL; switch ((PciDev->PciBar)[Index].BarType) { case PciBarTypeMem32: case PciBarTypeOpRom: @@ -448,13 +451,8 @@ GetResourceFromDevice ( (PciDev->PciBar)[Index].BarType, PciResUsageTypical ); + DestNode = Mem32Node; - InsertResourceNode ( - Mem32Node, - Node - ); - - ResourceRequested = TRUE; break; case PciBarTypeMem64: @@ -467,13 +465,8 @@ GetResourceFromDevice ( PciBarTypeMem64, PciResUsageTypical ); + DestNode = Mem64Node; - InsertResourceNode ( - Mem64Node, - Node - ); - - ResourceRequested = TRUE; break; case PciBarTypePMem64: @@ -486,13 +479,8 @@ GetResourceFromDevice ( PciBarTypePMem64, PciResUsageTypical ); + DestNode = PMem64Node; - InsertResourceNode ( - PMem64Node, - Node - ); - - ResourceRequested = TRUE; break; case PciBarTypePMem32: @@ -505,12 +493,7 @@ GetResourceFromDevice ( PciBarTypePMem32, PciResUsageTypical ); - - InsertResourceNode ( - PMem32Node, - Node - ); - ResourceRequested = TRUE; + DestNode = PMem32Node; break; case PciBarTypeIo16: @@ -524,12 +507,8 @@ GetResourceFromDevice ( PciBarTypeIo16, PciResUsageTypical ); + DestNode = IoNode; - InsertResourceNode ( - IoNode, - Node - ); - ResourceRequested = TRUE; break; case PciBarTypeUnknown: @@ -538,12 +517,20 @@ GetResourceFromDevice ( default: break; } + + if ((DestNode != NULL) && (Node != NULL)) { + InsertResourceNode (DestNode, Node); + ResourceRequested = TRUE; + } } // // Add VF resource // for (Index = 0; Index < PCI_MAX_BAR; Index++) { + DestNode = NULL; + Node = NULL; + switch ((PciDev->VfPciBar)[Index].BarType) { case PciBarTypeMem32: @@ -555,11 +542,7 @@ GetResourceFromDevice ( PciBarTypeMem32, PciResUsageTypical ); - - InsertResourceNode ( - Mem32Node, - Node - ); + DestNode = Mem32Node; break; @@ -573,11 +556,7 @@ GetResourceFromDevice ( PciBarTypeMem64, PciResUsageTypical ); - - InsertResourceNode ( - Mem64Node, - Node - ); + DestNode = Mem64Node; break; @@ -591,12 +570,7 @@ GetResourceFromDevice ( PciBarTypePMem64, PciResUsageTypical ); - - InsertResourceNode ( - PMem64Node, - Node - ); - + DestNode = PMem64Node; break; case PciBarTypePMem32: @@ -609,11 +583,8 @@ GetResourceFromDevice ( PciBarTypePMem32, PciResUsageTypical ); + DestNode = PMem32Node; - InsertResourceNode ( - PMem32Node, - Node - ); break; case PciBarTypeIo16: @@ -626,6 +597,10 @@ GetResourceFromDevice ( default: break; } + + if ((DestNode != NULL) && (Node != NULL)) { + InsertResourceNode (DestNode, Node); + } } // If there is no resource requested from this device, @@ -783,6 +758,9 @@ CreateResourceMap ( PciBarTypeIo16, PciResUsageTypical ); + if (IoBridge == NULL) { + return; + } Mem32Bridge = CreateResourceNode ( Temp, @@ -792,6 +770,10 @@ CreateResourceMap ( PciBarTypeMem32, PciResUsageTypical ); + if (Mem32Bridge == NULL) { + FreePool (IoBridge); + return; + } PMem32Bridge = CreateResourceNode ( Temp, @@ -801,6 +783,11 @@ CreateResourceMap ( PciBarTypePMem32, PciResUsageTypical ); + if (PMem32Bridge == NULL) { + FreePool (Mem32Bridge); + FreePool (IoBridge); + return; + } Mem64Bridge = CreateResourceNode ( Temp, @@ -810,6 +797,12 @@ CreateResourceMap ( PciBarTypeMem64, PciResUsageTypical ); + if (Mem64Bridge == NULL) { + FreePool (PMem32Bridge); + FreePool (Mem32Bridge); + FreePool (IoBridge); + return; + } PMem64Bridge = CreateResourceNode ( Temp, @@ -819,6 +812,13 @@ CreateResourceMap ( PciBarTypePMem64, PciResUsageTypical ); + if (PMem64Bridge == NULL) { + FreePool (Mem64Bridge); + FreePool (PMem32Bridge); + FreePool (Mem32Bridge); + FreePool (IoBridge); + return; + } // // Recursively create resource map on this bridge @@ -1813,12 +1813,11 @@ ResourcePaddingForCardBusBridge ( PciBarTypeMem32, PciResUsagePadding ); + if (Node == NULL) { + return; + } - InsertResourceNode ( - Mem32Node, - Node - ); - + InsertResourceNode (Mem32Node, Node); // // Memory Base/Limit Register 1 // Bar 2 decodes memory range1 @@ -1831,11 +1830,11 @@ ResourcePaddingForCardBusBridge ( PciBarTypePMem32, PciResUsagePadding ); + if (Node == NULL) { + return; + } - InsertResourceNode ( - PMem32Node, - Node - ); + InsertResourceNode (PMem32Node, Node); // // Io Base/Limit @@ -1850,10 +1849,11 @@ ResourcePaddingForCardBusBridge ( PciResUsagePadding ); - InsertResourceNode ( - IoNode, - Node - ); + if (Node == NULL) { + return; + } + + InsertResourceNode (IoNode, Node); // // Io Base/Limit @@ -1867,11 +1867,11 @@ ResourcePaddingForCardBusBridge ( PciBarTypeIo16, PciResUsagePadding ); + if (Node == NULL) { + return; + } - InsertResourceNode ( - IoNode, - Node - ); + InsertResourceNode (IoNode, Node); } /** @@ -2142,10 +2142,13 @@ ApplyResourcePadding ( PciBarTypeIo16, PciResUsagePadding ); - InsertResourceNode ( - IoNode, - Node - ); + + if (Node != NULL) { + InsertResourceNode ( + IoNode, + Node + ); + } } Ptr++; @@ -2167,10 +2170,12 @@ ApplyResourcePadding ( PciBarTypePMem32, PciResUsagePadding ); - InsertResourceNode ( - PMem32Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + PMem32Node, + Node + ); + } } Ptr++; @@ -2190,10 +2195,12 @@ ApplyResourcePadding ( PciBarTypeMem32, PciResUsagePadding ); - InsertResourceNode ( - Mem32Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + Mem32Node, + Node + ); + } } Ptr++; @@ -2215,10 +2222,12 @@ ApplyResourcePadding ( PciBarTypePMem64, PciResUsagePadding ); - InsertResourceNode ( - PMem64Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + PMem64Node, + Node + ); + } } Ptr++; @@ -2238,10 +2247,12 @@ ApplyResourcePadding ( PciBarTypeMem64, PciResUsagePadding ); - InsertResourceNode ( - Mem64Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + Mem64Node, + Node + ); + } } Ptr++; diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c index 120aef31c0..e9e827887a 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c @@ -667,7 +667,10 @@ ResourceConflict ( RootBridgeCount * (TypeMax * sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR)) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR) ); - ASSERT (Resources != NULL); + if (Resources == NULL) { + ASSERT (Resources != NULL); + return; + } for (Link = GetFirstNode (&HostBridge->RootBridges), Descriptor = Resources ; !IsNull (&HostBridge->RootBridges, Link) diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c index 419f47a426..2dfaa22b57 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c @@ -196,7 +196,11 @@ CreateRootBridge ( } RootBridge = AllocateZeroPool (sizeof (PCI_ROOT_BRIDGE_INSTANCE)); - ASSERT (RootBridge != NULL); + if (RootBridge == NULL) { + DEBUG ((DEBUG_ERROR, "Failed to allocate RootBridge\n")); + ASSERT (RootBridge != NULL); + return NULL; + } RootBridge->Signature = PCI_ROOT_BRIDGE_SIGNATURE; RootBridge->Supports = Bridge->Supports; @@ -209,7 +213,12 @@ CreateRootBridge ( RootBridge->ConfigBuffer = AllocatePool ( TypeMax * sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR) ); - ASSERT (RootBridge->ConfigBuffer != NULL); + if (RootBridge->ConfigBuffer == NULL) { + ASSERT (RootBridge->ConfigBuffer != NULL); + FreePool (RootBridge); + return NULL; + } + InitializeListHead (&RootBridge->Maps); CopyMem (&RootBridge->Bus, &Bridge->Bus, sizeof (PCI_ROOT_BRIDGE_APERTURE)); @@ -245,6 +254,14 @@ CreateRootBridge ( break; } + if (Aperture == NULL) { + DEBUG ((DEBUG_ERROR, "%a - Failed to Get Resource!!!\n", __func__)); + DEBUG ((DEBUG_ERROR, "No EFI_PCI_ROOT_BRIDGE_INSTANCE created\n")); + FreePool (RootBridge->ConfigBuffer); + FreePool (RootBridge); + return NULL; + } + RootBridge->ResAllocNode[Index].Type = Index; if (Bridge->ResourceAssigned && (Aperture->Limit >= Aperture->Base)) { // diff --git a/MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c b/MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c index 8b1ce70118..1f522145d1 100644 --- a/MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c +++ b/MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c @@ -758,7 +758,10 @@ GetChildSerialDevices ( } SerialDevices = AllocatePool (EntryCount * sizeof (SERIAL_DEV *)); - ASSERT (SerialDevices != NULL); + if (SerialDevices == NULL) { + ASSERT (SerialDevices != NULL); + return NULL; + } *Count = 0; OpenByDriver = FALSE; @@ -905,7 +908,11 @@ SerialControllerDriverStart ( // Uart = (UART_DEVICE_PATH *)SkipControllerDevicePathNode (RemainingDevicePath, &ContainsControllerNode, &ControllerNumber); for (Index = 0; Index < SerialDeviceCount; Index++) { - ASSERT ((SerialDevices != NULL) && (SerialDevices[Index] != NULL)); + if ((SerialDevices == NULL) || (SerialDevices[Index] == NULL)) { + ASSERT ((SerialDevices != NULL) && (SerialDevices[Index] != NULL)); + continue; + } + if ((!SerialDevices[Index]->ContainsControllerNode && !ContainsControllerNode) || (SerialDevices[Index]->ContainsControllerNode && ContainsControllerNode && (SerialDevices[Index]->Instance == ControllerNumber)) ) @@ -1016,7 +1023,11 @@ SerialControllerDriverStart ( // Restore the PCI attributes when all children is destroyed (PciDeviceInfo->ChildCount == 0). // PciDeviceInfo = AllocatePool (sizeof (PCI_DEVICE_INFO)); - ASSERT (PciDeviceInfo != NULL); + if (PciDeviceInfo == NULL) { + ASSERT (PciDeviceInfo != NULL); + return EFI_OUT_OF_RESOURCES; + } + PciDeviceInfo->ChildCount = 0; PciDeviceInfo->PciIo = ParentIo.PciIo; Status = ParentIo.PciIo->Attributes ( @@ -1047,9 +1058,16 @@ SerialControllerDriverStart ( // // Re-use the PciDeviceInfo stored in existing children. // - ASSERT ((SerialDevices != NULL) && (SerialDevices[0] != NULL)); + if ((SerialDevices == NULL) || (SerialDevices[0] == NULL)) { + ASSERT ((SerialDevices != NULL) && (SerialDevices[0] != NULL)); + return EFI_UNSUPPORTED; + } + PciDeviceInfo = SerialDevices[0]->PciDeviceInfo; - ASSERT (PciDeviceInfo != NULL); + if (PciDeviceInfo == NULL) { + ASSERT (PciDeviceInfo != NULL); + return EFI_UNSUPPORTED; + } } Status = EFI_NOT_FOUND; diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 52551a3709..e8cb7ede54 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -521,7 +521,11 @@ XhcInitSched ( Entries = (Xhc->MaxSlotsEn + 1) * sizeof (UINT64); Dcbaa = UsbHcAllocateMem (Xhc->MemPool, Entries, FALSE); ASSERT (Dcbaa != NULL); - ZeroMem (Dcbaa, Entries); + if (Dcbaa != NULL) { + ZeroMem (Dcbaa, Entries); + } else { + return; + } // // A Scratchpad Buffer is a PAGESIZE block of system memory located on a PAGESIZE boundary. @@ -809,8 +813,13 @@ CreateEventRing ( Size = sizeof (TRB_TEMPLATE) * EVENT_RING_TRB_NUMBER; Buf = UsbHcAllocateMem (Xhc->MemPool, Size, TRUE); - ASSERT (Buf != NULL); + if (Buf == NULL) { + ASSERT (Buf != NULL); + return; + } + ASSERT (((UINTN)Buf & 0x3F) == 0); + ZeroMem (Buf, Size); EventRing->EventRingSeg0 = Buf; @@ -828,8 +837,13 @@ CreateEventRing ( Size = sizeof (EVENT_RING_SEG_TABLE_ENTRY) * ERST_NUMBER; Buf = UsbHcAllocateMem (Xhc->MemPool, Size, FALSE); - ASSERT (Buf != NULL); + if (Buf == NULL) { + ASSERT (Buf != NULL); + return; + } + ASSERT (((UINTN)Buf & 0x3F) == 0); + ZeroMem (Buf, Size); ERSTBase = (EVENT_RING_SEG_TABLE_ENTRY *)Buf; @@ -908,6 +922,10 @@ CreateTransferRing ( Buf = UsbHcAllocateMem (Xhc->MemPool, sizeof (TRB_TEMPLATE) * TrbNum, TRUE); ASSERT (Buf != NULL); ASSERT (((UINTN)Buf & 0x3F) == 0); + if (Buf == NULL) { + return; + } + ZeroMem (Buf, sizeof (TRB_TEMPLATE) * TrbNum); TransferRing->RingSeg0 = Buf; @@ -1041,6 +1059,10 @@ IsTransferRingTrb ( EFI_PHYSICAL_ADDRESS PhyAddr; CheckedTrb = Urb->TrbStart; + if (CheckedTrb == NULL) { + return FALSE; + } + for (Index = 0; Index < Urb->TrbNum; Index++) { if (Trb == CheckedTrb) { return TRUE; @@ -1164,6 +1186,10 @@ XhcCheckUrbResult ( // PhyAddr = (EFI_PHYSICAL_ADDRESS)(EvtTrb->TRBPtrLo | LShiftU64 ((UINT64)EvtTrb->TRBPtrHi, 32)); TRBPtr = (TRB_TEMPLATE *)(UINTN)UsbHcGetHostAddrForPciAddr (Xhc->MemPool, (VOID *)(UINTN)PhyAddr, sizeof (TRB_TEMPLATE), FALSE); + if (TRBPtr == NULL) { + ASSERT (TRBPtr != NULL); + goto EXIT; + } // // Update the status of URB including the pending URB, the URB that is currently checked, @@ -2246,6 +2272,10 @@ XhcInitializeDeviceSlot ( InputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (INPUT_CONTEXT), FALSE); ASSERT (InputContext != NULL); ASSERT (((UINTN)InputContext & 0x3F) == 0); + if (InputContext == NULL) { + return RETURN_OUT_OF_RESOURCES; + } + ZeroMem (InputContext, sizeof (INPUT_CONTEXT)); Xhc->UsbDevContext[SlotId].InputContext = (VOID *)InputContext; @@ -2349,6 +2379,10 @@ XhcInitializeDeviceSlot ( OutputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (DEVICE_CONTEXT), FALSE); ASSERT (OutputContext != NULL); ASSERT (((UINTN)OutputContext & 0x3F) == 0); + if (OutputContext == NULL) { + return EFI_OUT_OF_RESOURCES; + } + ZeroMem (OutputContext, sizeof (DEVICE_CONTEXT)); Xhc->UsbDevContext[SlotId].OutputContext = OutputContext; @@ -2472,6 +2506,10 @@ XhcInitializeDeviceSlot64 ( InputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (INPUT_CONTEXT_64), FALSE); ASSERT (InputContext != NULL); ASSERT (((UINTN)InputContext & 0x3F) == 0); + if (InputContext == NULL) { + return EFI_OUT_OF_RESOURCES; + } + ZeroMem (InputContext, sizeof (INPUT_CONTEXT_64)); Xhc->UsbDevContext[SlotId].InputContext = (VOID *)InputContext; @@ -2575,6 +2613,10 @@ XhcInitializeDeviceSlot64 ( OutputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (DEVICE_CONTEXT_64), FALSE); ASSERT (OutputContext != NULL); ASSERT (((UINTN)OutputContext & 0x3F) == 0); + if (OutputContext == NULL) { + return EFI_OUT_OF_RESOURCES; + } + ZeroMem (OutputContext, sizeof (DEVICE_CONTEXT_64)); Xhc->UsbDevContext[SlotId].OutputContext = OutputContext; diff --git a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c index 158749b53c..2c3d1495b9 100644 --- a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c @@ -676,6 +676,9 @@ XhcPeiCheckUrbResult ( // PhyAddr = (EFI_PHYSICAL_ADDRESS)(EvtTrb->TRBPtrLo | LShiftU64 ((UINT64)EvtTrb->TRBPtrHi, 32)); TRBPtr = (TRB_TEMPLATE *)(UINTN)UsbHcGetHostAddrForPciAddr (Xhc->MemPool, (VOID *)(UINTN)PhyAddr, sizeof (TRB_TEMPLATE), FALSE); + if (TRBPtr == NULL) { + return FALSE; + } // // Update the status of Urb according to the finished event regardless of whether @@ -1120,7 +1123,11 @@ XhcPeiInitializeDeviceSlot ( // 1) Allocate an Input Context data structure (6.2.5) and initialize all fields to '0'. // InputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (INPUT_CONTEXT)); - ASSERT (InputContext != NULL); + if (InputContext == NULL) { + ASSERT (InputContext != NULL); + return EFI_OUT_OF_RESOURCES; + } + ASSERT (((UINTN)InputContext & 0x3F) == 0); ZeroMem (InputContext, sizeof (INPUT_CONTEXT)); @@ -1223,7 +1230,11 @@ XhcPeiInitializeDeviceSlot ( // 6) Allocate the Output Device Context data structure (6.2.1) and initialize it to '0'. // OutputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (DEVICE_CONTEXT)); - ASSERT (OutputContext != NULL); + if (OutputContext == NULL) { + ASSERT (OutputContext != NULL); + return EFI_OUT_OF_RESOURCES; + } + ASSERT (((UINTN)OutputContext & 0x3F) == 0); ZeroMem (OutputContext, sizeof (DEVICE_CONTEXT)); @@ -1335,7 +1346,11 @@ XhcPeiInitializeDeviceSlot64 ( // 1) Allocate an Input Context data structure (6.2.5) and initialize all fields to '0'. // InputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (INPUT_CONTEXT_64)); - ASSERT (InputContext != NULL); + if (InputContext == NULL) { + ASSERT (InputContext != NULL); + return EFI_OUT_OF_RESOURCES; + } + ASSERT (((UINTN)InputContext & 0x3F) == 0); ZeroMem (InputContext, sizeof (INPUT_CONTEXT_64)); @@ -1438,7 +1453,11 @@ XhcPeiInitializeDeviceSlot64 ( // 6) Allocate the Output Device Context data structure (6.2.1) and initialize it to '0'. // OutputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (DEVICE_CONTEXT_64)); - ASSERT (OutputContext != NULL); + if (OutputContext == NULL) { + ASSERT (OutputContext != NULL); + return EFI_OUT_OF_RESOURCES; + } + ASSERT (((UINTN)OutputContext & 0x3F) == 0); ZeroMem (OutputContext, sizeof (DEVICE_CONTEXT_64)); @@ -2682,7 +2701,11 @@ XhcPeiCreateEventRing ( Size = sizeof (TRB_TEMPLATE) * EVENT_RING_TRB_NUMBER; Buf = UsbHcAllocateMem (Xhc->MemPool, Size); - ASSERT (Buf != NULL); + if (Buf == NULL ) { + ASSERT (Buf != NULL); + return; + } + ASSERT (((UINTN)Buf & 0x3F) == 0); ZeroMem (Buf, Size); @@ -2701,7 +2724,11 @@ XhcPeiCreateEventRing ( Size = sizeof (EVENT_RING_SEG_TABLE_ENTRY) * ERST_NUMBER; Buf = UsbHcAllocateMem (Xhc->MemPool, Size); - ASSERT (Buf != NULL); + if (Buf == NULL) { + ASSERT (Buf != NULL); + return; + } + ASSERT (((UINTN)Buf & 0x3F) == 0); ZeroMem (Buf, Size); @@ -2918,7 +2945,10 @@ XhcPeiInitSched ( // Size = (Xhc->MaxSlotsEn + 1) * sizeof (UINT64); Dcbaa = UsbHcAllocateMem (Xhc->MemPool, Size); - ASSERT (Dcbaa != NULL); + if (Dcbaa == NULL) { + ASSERT (Dcbaa != NULL); + return; + } // // A Scratchpad Buffer is a PAGESIZE block of system memory located on a PAGESIZE boundary. From 0f0515f71ba3645823ae17638532099d1e5d5144 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Wed, 22 Oct 2025 11:33:02 -0700 Subject: [PATCH 388/406] MdeModulePkg: Fix unchecked return status https://github.com/github/codeql/blob/codeql-cli-2.7.3/csharp/ql/src/API%20Abuse/UncheckedReturnValue.qhelp When a function has a return status, it should be checked to verify the function completed successfully. Failing to check the return status can result in null pointer dereferences or use of uninitialized variables. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c | 17 +++++++++++++---- MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c | 3 +++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c index fc7b684940..d8357f4ecb 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c @@ -564,13 +564,22 @@ NvmeControllerInit ( // // Dump the NVME controller implementation version // - NVME_GET_VER (Private, &Ver); - DEBUG ((DEBUG_INFO, "NVME controller implementation version: %d.%d\n", Ver.Mjr, Ver.Mnr)); + Status = NVME_GET_VER (Private, &Ver); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "NVME controller implementation version: %d.%d\n", Ver.Mjr, Ver.Mnr)); + } // - // Read the controller Capabilities register and verify that the NVM command set is supported + // Read the controller Capabilities register + // + Status = NVME_GET_CAP (Private, &Private->Cap); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + // + // Verify that the NVM command set is supported // - NVME_GET_CAP (Private, &Private->Cap); if ((Private->Cap.Css & BIT0) == 0) { DEBUG ((DEBUG_ERROR, "%a: The NVME controller doesn't support NVMe command set.\n", __func__)); return EFI_UNSUPPORTED; diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c index 07da9bec2f..1262c6075f 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c @@ -1446,6 +1446,9 @@ SupportPaletteSnoopAttributes ( // if (Temp->Parent == PciIoDevice->Parent) { Status = PCI_READ_COMMAND_REGISTER (Temp, &VGACommand); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } // // If they are on the same bus, either one can From 699382e3429a4ecd3ccd58d333f413e14bb10edc Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Wed, 22 Oct 2025 11:33:02 -0700 Subject: [PATCH 389/406] MdeModulePkg: Fix unchecked return status https://github.com/github/codeql/blob/codeql-cli-2.7.3/csharp/ql/src/API%20Abuse/UncheckedReturnValue.qhelp When a function has a return status, it should be checked to verify the function completed successfully. Failing to check the return status can result in null pointer dereferences or use of uninitialized variables. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../Application/BootManagerMenuApp/BootManagerMenu.c | 5 +++++ MdeModulePkg/Application/CapsuleApp/CapsuleDump.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c index ef19319614..5bba6ea816 100644 --- a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c +++ b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c @@ -1096,6 +1096,11 @@ BootManagerMenuEntry ( // Initialize Boot menu data // Status = InitializeBootMenuData (BootOption, BootOptionCount, &BootMenuData); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a Failed InitializeBootMenuData %r\n", __func__, Status)); + return EFI_NOT_FOUND; + } + // // According to boot menu data to draw boot popup menu // diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c index 7605153e97..b218e00d1b 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c @@ -993,7 +993,7 @@ DumpProvisionedCapsule ( // // Display description and device path // - GetEfiSysPartitionFromBootOptionFilePath (BootNextOptionEntry.FilePath, &DevicePath, &Fs); + Status = GetEfiSysPartitionFromBootOptionFilePath (BootNextOptionEntry.FilePath, &DevicePath, &Fs); if (!EFI_ERROR (Status)) { Print (L"Capsules are provisioned on BootOption: %s\n", BootNextOptionEntry.Description); Print (L" %s %s\n", ShellProtocol->GetMapFromDevicePath (&DevicePath), ConvertDevicePathToText (DevicePath, TRUE, TRUE)); From dfd0edeb4e71f01f83cf9aa53285db4f14e5487d Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Wed, 22 Oct 2025 11:33:02 -0700 Subject: [PATCH 390/406] MdeModulePkg: Fix missing NULL tests https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp For items which allocate memory, or get a pointer from another structure, it is important to validate that the pointers are not null before they are dereferenced. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../Application/CapsuleApp/CapsuleOnDisk.c | 6 ++++- .../SmiHandlerProfileInfo.c | 7 +++++- MdeModulePkg/Application/UiApp/FrontPage.c | 20 ++++++++++++--- .../UiApp/FrontPageCustomizedUiSupport.c | 25 ++++++++++++++++--- .../Application/VariableInfo/VariableInfo.c | 7 +++++- 5 files changed, 55 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c index 5ce5a50f7b..f1501ebcf4 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c @@ -518,7 +518,11 @@ GetUpdateFileSystem ( // If map is assigned, try to get ESP from mapped Fs. // DevicePath = DuplicateDevicePath (MappedDevicePath); - Status = GetEfiSysPartitionFromDevPath (DevicePath, &FullPath, Fs); + if (DevicePath == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = GetEfiSysPartitionFromDevPath (DevicePath, &FullPath, Fs); if (EFI_ERROR (Status)) { Print (L"Error: Cannot get EFI system partition from '%s' - %r\n", Map, Status); return EFI_NOT_FOUND; diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c index 68c2e35791..18415c056e 100644 --- a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c +++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c @@ -610,7 +610,12 @@ DumpSmiHandler ( Print (L">\n"); ImageStruct = GetImageFromRef ((UINTN)SmiHandlerStruct->ImageRef); - NameString = GetDriverNameString (ImageStruct); + if (ImageStruct != NULL) { + NameString = GetDriverNameString (ImageStruct); + } else { + NameString = "\0"; + } + Print (L" <Module RefId=\"0x%x\" Name=\"%a\">\n", SmiHandlerStruct->ImageRef, NameString); if ((ImageStruct != NULL) && (ImageStruct->PdbStringOffset != 0)) { Print (L" <Pdb>%a</Pdb>\n", (UINT8 *)ImageStruct + ImageStruct->PdbStringOffset); diff --git a/MdeModulePkg/Application/UiApp/FrontPage.c b/MdeModulePkg/Application/UiApp/FrontPage.c index 56e174fe56..84fba400a2 100644 --- a/MdeModulePkg/Application/UiApp/FrontPage.c +++ b/MdeModulePkg/Application/UiApp/FrontPage.c @@ -203,10 +203,17 @@ UpdateFrontPageForm ( // Allocate space for creation of UpdateData Buffer // StartOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (StartOpCodeHandle != NULL); + if (StartOpCodeHandle == NULL) { + ASSERT (StartOpCodeHandle != NULL); + return; + } EndOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (EndOpCodeHandle != NULL); + if (EndOpCodeHandle == NULL) { + ASSERT (EndOpCodeHandle != NULL); + goto Exit; + } + // // Create Hii Extend Label OpCode as the start opcode // @@ -236,8 +243,10 @@ UpdateFrontPageForm ( EndOpCodeHandle ); - HiiFreeOpCodeHandle (StartOpCodeHandle); HiiFreeOpCodeHandle (EndOpCodeHandle); +Exit: + HiiFreeOpCodeHandle (StartOpCodeHandle); + return; } /** @@ -966,7 +975,10 @@ InitializeUserInterface ( // Install customized fonts needed by Front Page // HiiHandle = ExportFonts (); - ASSERT (HiiHandle != NULL); + if (HiiHandle == NULL) { + ASSERT (HiiHandle != NULL); + return EFI_NOT_FOUND; + } InitializeStringSupport (); diff --git a/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c b/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c index 24f9f1e3fb..ef6b527d18 100644 --- a/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c +++ b/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c @@ -191,6 +191,11 @@ UiSupportLibCallbackHandler ( if (Action == EFI_BROWSER_ACTION_RETRIEVE) { if (QuestionId == FRONT_PAGE_KEY_LANGUAGE) { + if (Value == NULL) { + *Status = EFI_INVALID_PARAMETER; + return FALSE; + } + Value->u8 = gCurrentLanguageIndex; *Status = EFI_SUCCESS; } else { @@ -346,7 +351,10 @@ UiCreateLanguageMenu ( OptionCount = 0; if (Lang == NULL) { Lang = AllocatePool (AsciiStrSize (gLanguageString)); - ASSERT (Lang != NULL); + if (Lang == NULL) { + ASSERT (Lang != NULL); + goto Exit; + } } while (*LangCode != 0) { @@ -393,6 +401,7 @@ UiCreateLanguageMenu ( NULL ); +Exit: HiiFreeOpCodeHandle (OptionsOpCodeHandle); } @@ -592,10 +601,20 @@ UiListThirdPartyDrivers ( } HiiHandles = HiiGetHiiHandles (NULL); - ASSERT (HiiHandles != NULL); + if ( HiiHandles == NULL) { + ASSERT (HiiHandles != NULL); + DEBUG ((DEBUG_ERROR, "%a No HII handles found in the HII database\n", __func__)); + return EFI_NOT_FOUND; + } gHiiDriverList = AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE * sizeof (UI_HII_DRIVER_INSTANCE)); - ASSERT (gHiiDriverList != NULL); + if (gHiiDriverList == NULL) { + ASSERT (gHiiDriverList != NULL); + DEBUG ((DEBUG_VERBOSE, "%a No memory for gHiiDriverList\n", __func__)); + FreePool (HiiHandles); + return EFI_OUT_OF_RESOURCES; + } + DriverListPtr = gHiiDriverList; CurrentSize = UI_HII_DRIVER_LIST_SIZE; diff --git a/MdeModulePkg/Application/VariableInfo/VariableInfo.c b/MdeModulePkg/Application/VariableInfo/VariableInfo.c index 3dee41eb4b..13c4acc2f2 100644 --- a/MdeModulePkg/Application/VariableInfo/VariableInfo.c +++ b/MdeModulePkg/Application/VariableInfo/VariableInfo.c @@ -131,7 +131,12 @@ PrintInfoFromSmm ( Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize); } - ASSERT (CommBuffer != NULL); + if (CommBuffer == NULL) { + DEBUG ((DEBUG_ERROR, "Warning: No SMM communication buffer found!\n")); + ASSERT (CommBuffer != NULL); + return EFI_NOT_FOUND; + } + ZeroMem (CommBuffer, RealCommSize); Print (L"SMM Driver Non-Volatile Variables:\n"); From 9b3ceeb254db5151df1ec5f2cacaea7a3cf0518c Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Wed, 22 Oct 2025 11:33:02 -0700 Subject: [PATCH 391/406] MdeModulePkg: Fix missing NULL tests https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp For items which allocate memory, or get a pointer from another structure, it is important to validate that the pointers are not null before they are dereferenced. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../Universal/Disk/CdExpressPei/PeiCdExpress.c | 5 +++-- .../Universal/Disk/RamDiskDxe/RamDiskImpl.c | 13 ++++++++++--- .../Universal/Disk/RamDiskDxe/RamDiskProtocol.c | 6 +++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.c b/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.c index 6a84f9efd1..55d0f4d790 100644 --- a/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.c +++ b/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.c @@ -168,13 +168,14 @@ UpdateBlocksAndVolumes ( EFI_PEI_SERVICES **PeiServices; IndexBlockDevice = 0; - BlockIo2Ppi = NULL; - BlockIoPpi = NULL; + // // Find out all Block Io Ppi instances within the system // Assuming all device Block Io Peims are dispatched already // for (BlockIoPpiInstance = 0; BlockIoPpiInstance < PEI_CD_EXPRESS_MAX_BLOCK_IO_PPI; BlockIoPpiInstance++) { + BlockIo2Ppi = NULL; + BlockIoPpi = NULL; if (BlockIo2) { Status = PeiServicesLocatePpi ( &gEfiPeiVirtualBlockIo2PpiGuid, diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c index 2dac121c47..2afa4ea327 100644 --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c @@ -477,10 +477,16 @@ UpdateMainForm ( // Init OpCode Handle // StartOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (StartOpCodeHandle != NULL); + if (StartOpCodeHandle == NULL) { + ASSERT (StartOpCodeHandle != NULL); + return; + } EndOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (EndOpCodeHandle != NULL); + if (EndOpCodeHandle == NULL) { + ASSERT (EndOpCodeHandle != NULL); + goto Exit; + } // // Create Hii Extend Label OpCode as the start opcode @@ -552,8 +558,9 @@ UpdateMainForm ( EndOpCodeHandle ); - HiiFreeOpCodeHandle (StartOpCodeHandle); HiiFreeOpCodeHandle (EndOpCodeHandle); +Exit: + HiiFreeOpCodeHandle (StartOpCodeHandle); } /** diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c index 780cf0a016..9eeb77a4bb 100644 --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c @@ -167,7 +167,11 @@ RamDiskPublishNfit ( ASSERT (Status == EFI_BUFFER_TOO_SMALL); do { MemoryMap = (EFI_MEMORY_DESCRIPTOR *)AllocatePool (MemoryMapSize); - ASSERT (MemoryMap != NULL); + if (MemoryMap == NULL) { + ASSERT (MemoryMap != NULL); + return EFI_OUT_OF_RESOURCES; + } + Status = gBS->GetMemoryMap ( &MemoryMapSize, MemoryMap, From 8c66d989635db3b512036c9388d57a8edec42e2c Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Oct 2025 11:13:38 -0700 Subject: [PATCH 392/406] MdeModulePkg: Fix comparison with wider widths https://codeql.github.com/codeql-query-help/cpp/cpp-comparison-with-wider-type If the narrow type (smaller range) is compared against a wide type (larger range), the narrow value may overflow before reaching the wide value. This can cause unexpected behavior, such as: Infinite loops (loop condition never becomes false). Incorrect logic (comparison results are misleading). Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index 63a37ab59a..266efb6ad0 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -1164,7 +1164,7 @@ ValidateQuestionFromVfr ( EFI_IFR_TYPE_VALUE TmpValue; EFI_STATUS Status; EFI_HII_PACKAGE_HEADER PackageHeader; - UINT32 PackageOffset; + UINTN PackageOffset; UINT8 *PackageData; UINTN IfrOffset; EFI_IFR_OP_HEADER *IfrOpHdr; From 1d63461c915990f10366a581771a34a426a3574f Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Oct 2025 12:57:49 -0700 Subject: [PATCH 393/406] MdeModulePkg: Fix missing NULL tests https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp For items which allocate memory, or get a pointer from another structure, it is important to validate that the pointers are not null before they are dereferenced. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 77 +++++++++++++++++++----- 1 file changed, 62 insertions(+), 15 deletions(-) diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index 266efb6ad0..7625fe8e3d 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -51,10 +51,12 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList = { If HiiHandle could not be found in the HII database, then ASSERT. If Guid is NULL, then ASSERT. - @param Handle Hii handle - @param Guid Package list GUID + @param Handle Hii handle + @param Guid Package list GUID - @retval EFI_SUCCESS Successfully extract GUID from Hii database. + @retval EFI_SUCCESS Successfully extract GUID from Hii database. + @retval EFI_INVALID_PARAMETER Invalid inputs received. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources to perform a necessary memory allocation. **/ EFI_STATUS @@ -68,8 +70,11 @@ InternalHiiExtractGuidFromHiiHandle ( UINTN BufferSize; EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; - ASSERT (Guid != NULL); - ASSERT (Handle != NULL); + if ((Handle == NULL) || (Guid == NULL)) { + ASSERT (Guid != NULL); + ASSERT (Handle != NULL); + return EFI_INVALID_PARAMETER; + } // // Get HII PackageList @@ -82,7 +87,10 @@ InternalHiiExtractGuidFromHiiHandle ( if (Status == EFI_BUFFER_TOO_SMALL) { HiiPackageList = AllocatePool (BufferSize); - ASSERT (HiiPackageList != NULL); + if (HiiPackageList == NULL) { + ASSERT (HiiPackageList != NULL); + return EFI_OUT_OF_RESOURCES; + } Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList); } @@ -1359,7 +1367,10 @@ ValidateQuestionFromVfr ( if (NameValueType) { QuestionName = HiiGetString (HiiHandle, IfrOneOf->Question.VarStoreInfo.VarName, NULL); - ASSERT (QuestionName != NULL); + if (QuestionName == NULL) { + ASSERT (QuestionName != NULL); + return EFI_INVALID_PARAMETER; + } if (StrStr (RequestElement, QuestionName) == NULL) { // @@ -1455,7 +1466,10 @@ ValidateQuestionFromVfr ( if (NameValueType) { QuestionName = HiiGetString (HiiHandle, IfrNumeric->Question.VarStoreInfo.VarName, NULL); - ASSERT (QuestionName != NULL); + if (QuestionName == NULL) { + ASSERT (QuestionName != NULL); + return EFI_INVALID_PARAMETER; + } if (StrStr (RequestElement, QuestionName) == NULL) { // @@ -1647,7 +1661,10 @@ ValidateQuestionFromVfr ( if (NameValueType) { QuestionName = HiiGetString (HiiHandle, IfrCheckBox->Question.VarStoreInfo.VarName, NULL); - ASSERT (QuestionName != NULL); + if (QuestionName == NULL) { + ASSERT (QuestionName != NULL); + return EFI_INVALID_PARAMETER; + } if (StrStr (RequestElement, QuestionName) == NULL) { // @@ -1749,7 +1766,10 @@ ValidateQuestionFromVfr ( Width = (UINT16)(IfrString->MaxSize * sizeof (UINT16)); if (NameValueType) { QuestionName = HiiGetString (HiiHandle, IfrString->Question.VarStoreInfo.VarName, NULL); - ASSERT (QuestionName != NULL); + if (QuestionName == NULL) { + ASSERT (QuestionName != NULL); + return EFI_INVALID_PARAMETER; + } StringPtr = StrStr (RequestElement, QuestionName); if (StringPtr == NULL) { @@ -1952,10 +1972,14 @@ GetBlockDataInfo ( goto Done; } - InitializeListHead (&BlockArray->Entry); - StringPtr = StrStr (ConfigElement, L"&OFFSET="); - ASSERT (StringPtr != NULL); + if (StringPtr == NULL) { + ASSERT (StringPtr != NULL); + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + + InitializeListHead (&BlockArray->Entry); // // Parse each <RequestElement> if exists @@ -2210,7 +2234,10 @@ InternalHiiValidateCurrentSetting ( // Skip header part. // StringPtr = StrStr (ConfigResp, L"PATH="); - ASSERT (StringPtr != NULL); + if (StringPtr == NULL) { + ASSERT (StringPtr != NULL); + return EFI_INVALID_PARAMETER; + } if (StrStr (StringPtr, L"&") != NULL) { NameValueType = TRUE; @@ -2273,7 +2300,10 @@ GetElementsFromRequest ( EFI_STRING TmpRequest; TmpRequest = StrStr (ConfigRequest, L"PATH="); - ASSERT (TmpRequest != NULL); + if (TmpRequest == NULL) { + ASSERT (TmpRequest != NULL); + return FALSE; + } if ((StrStr (TmpRequest, L"&OFFSET=") != NULL) || (StrStr (TmpRequest, L"&") != NULL)) { return TRUE; @@ -2887,6 +2917,7 @@ HiiGetBrowserData ( // ResultsData = InternalHiiBrowserCallback (VariableGuid, VariableName, NULL); if (ResultsData == NULL) { + ASSERT (ResultsData != NULL); return FALSE; } @@ -2896,6 +2927,12 @@ HiiGetBrowserData ( Size = (StrLen (mConfigHdrTemplate) + 1) * sizeof (CHAR16); Size = Size + (StrLen (ResultsData) + 1) * sizeof (CHAR16); ConfigResp = AllocateZeroPool (Size); + if (ConfigResp == NULL) { + FreePool (ResultsData); + ASSERT (ConfigResp != NULL); + return FALSE; + } + UnicodeSPrint (ConfigResp, Size, L"%s&%s", mConfigHdrTemplate, ResultsData); // @@ -2976,6 +3013,11 @@ HiiSetBrowserData ( // Size = (StrLen (mConfigHdrTemplate) + 32 + 1) * sizeof (CHAR16); ConfigRequest = AllocateZeroPool (Size); + if (ConfigRequest == NULL) { + ASSERT (ConfigRequest != NULL); + return FALSE; + } + UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate, (UINT64)BufferSize); } else { // @@ -2985,6 +3027,11 @@ HiiSetBrowserData ( Size = StrLen (mConfigHdrTemplate) * sizeof (CHAR16); Size = Size + (StrLen (RequestElement) + 1) * sizeof (CHAR16); ConfigRequest = AllocateZeroPool (Size); + if (ConfigRequest == NULL) { + ASSERT (ConfigRequest != NULL); + return FALSE; + } + UnicodeSPrint (ConfigRequest, Size, L"%s%s", mConfigHdrTemplate, RequestElement); } From 476b78bbad7e2c126002a7dde332dbf67ae7b172 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Oct 2025 15:23:51 -0700 Subject: [PATCH 394/406] MdeModulePkg: Fix Comparison overflow https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Security/CWE/CWE-190/ComparisonWithWiderType.qhelp Switch to using SafeUint16Add for calculating offsets into block data. The data being used in the calculation comes from config block strings, and there is no validation of the values before the calculation occurs. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 24 +++++++++++++------ .../Library/UefiHiiLib/UefiHiiLib.inf | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index 7625fe8e3d..476b69eec3 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -8,6 +8,8 @@ #include "InternalHiiLib.h" +#include <Library/SafeIntLib.h> + #define GUID_CONFIG_STRING_TYPE 0x00 #define NAME_CONFIG_STRING_TYPE 0x01 #define PATH_CONFIG_STRING_TYPE 0x02 @@ -1948,6 +1950,8 @@ GetBlockDataInfo ( EFI_STATUS Status; IFR_BLOCK_DATA *BlockArray; UINT8 *DataBuffer; + UINT16 Sum1; + UINT16 Sum2; // // Initialize the local variables. @@ -2144,14 +2148,20 @@ GetBlockDataInfo ( while ((Link != &BlockArray->Entry) && (Link->ForwardLink != &BlockArray->Entry)) { BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); NewBlockData = BASE_CR (Link->ForwardLink, IFR_BLOCK_DATA, Entry); - if ((NewBlockData->Offset >= BlockData->Offset) && (NewBlockData->Offset <= (BlockData->Offset + BlockData->Width))) { - if ((NewBlockData->Offset + NewBlockData->Width) > (BlockData->Offset + BlockData->Width)) { - BlockData->Width = (UINT16)(NewBlockData->Offset + NewBlockData->Width - BlockData->Offset); + if ((!EFI_ERROR (SafeUint16Add (BlockData->Offset, BlockData->Width, &Sum1))) && + (!EFI_ERROR (SafeUint16Add (NewBlockData->Offset, NewBlockData->Width, &Sum2))) && + (NewBlockData->Offset >= BlockData->Offset) && + (NewBlockData->Offset <= Sum1) && + (Sum2 > Sum1)) + { + Sum1 = BlockData->Width; + if (!EFI_ERROR (SafeUint16Sub (Sum2, BlockData->Offset, &BlockData->Width))) { + RemoveEntryList (Link->ForwardLink); + FreePool (NewBlockData); + continue; + } else { + BlockData->Width = Sum1; } - - RemoveEntryList (Link->ForwardLink); - FreePool (NewBlockData); - continue; } Link = Link->ForwardLink; diff --git a/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf b/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf index d432b439bc..be0c417578 100644 --- a/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf +++ b/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf @@ -41,6 +41,7 @@ UefiLib UefiHiiServicesLib PrintLib + SafeIntLib [Protocols] gEfiFormBrowser2ProtocolGuid ## SOMETIMES_CONSUMES From 77cf8c8c10160c886bb932309c3498db435ff7c6 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Oct 2025 12:57:49 -0700 Subject: [PATCH 395/406] MdeModulePkg: Fix missing NULL tests https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp For items which allocate memory, or get a pointer from another structure, it is important to validate that the pointers are not null before they are dereferenced. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../Library/UefiBootManagerLib/BmBoot.c | 128 ++++++++++++++---- .../UefiBootManagerLib/BmBootDescription.c | 38 ++++-- .../Library/UefiBootManagerLib/BmConsole.c | 48 ++++--- .../UefiBootManagerLib/BmDriverHealth.c | 17 ++- .../Library/UefiBootManagerLib/BmHotkey.c | 33 +++-- .../Library/UefiBootManagerLib/BmLoadOption.c | 50 ++++++- .../Library/UefiBootManagerLib/BmMisc.c | 1 + 7 files changed, 246 insertions(+), 69 deletions(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c index e3d34afc4f..44f4556f80 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c @@ -147,9 +147,8 @@ BmFindBootOptionInVariable ( if (OptionNumber == LoadOptionNumberUnassigned) { BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); - // Only assert if the BootOption is non-zero - if ((BootOptions == NULL) && (BootOptionCount > 0)) { - ASSERT (BootOptions != NULL); + // If no boot options found + if (BootOptions == NULL) { return LoadOptionNumberUnassigned; } @@ -214,7 +213,12 @@ BmAdjustFvFilePath ( (VOID **)&LoadedImage ); NewDevicePath = AppendDevicePathNode (DevicePathFromHandle (LoadedImage->DeviceHandle), FvFileNode); - FullPath = BmAdjustFvFilePath (NewDevicePath); + if (NewDevicePath == NULL) { + ASSERT (NewDevicePath != NULL); + return NULL; + } + + FullPath = BmAdjustFvFilePath (NewDevicePath); FreePool (NewDevicePath); if (FullPath != NULL) { return FullPath; @@ -239,7 +243,13 @@ BmAdjustFvFilePath ( } NewDevicePath = AppendDevicePathNode (DevicePathFromHandle (FvHandles[Index]), FvFileNode); - FullPath = BmAdjustFvFilePath (NewDevicePath); + if (NewDevicePath == NULL) { + ASSERT (NewDevicePath != NULL); + FreePool (FvHandles); + return NULL; + } + + FullPath = BmAdjustFvFilePath (NewDevicePath); FreePool (NewDevicePath); if (FullPath != NULL) { break; @@ -524,7 +534,10 @@ BmFindUsbDevice ( UINTN Index; BOOLEAN Matched; - ASSERT (UsbIoHandleCount != NULL); + if (UsbIoHandleCount == NULL) { + ASSERT (UsbIoHandleCount != NULL); + return NULL; + } // // Get all UsbIo Handles. @@ -622,6 +635,10 @@ BmExpandUsbDevicePath ( ParentDevicePathSize = (UINTN)ShortformNode - (UINTN)FilePath; RemainingDevicePath = NextDevicePathNode (ShortformNode); Handles = BmFindUsbDevice (FilePath, ParentDevicePathSize, &HandleCount); + if (Handles == NULL) { + ASSERT (Handles != NULL); + return NULL; + } for (Index = 0; Index < HandleCount; Index++) { FilePath = AppendDevicePath (DevicePathFromHandle (Handles[Index]), RemainingDevicePath); @@ -686,8 +703,7 @@ BmExpandFileDevicePath ( EfiBootManagerConnectAll (); Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles); if (EFI_ERROR (Status)) { - HandleCount = 0; - Handles = NULL; + return NULL; } GetNext = (BOOLEAN)(FullPath == NULL); @@ -923,6 +939,11 @@ BmExpandPartitionDevicePath ( // partial partition boot option. Second, check whether the instance could be connected. // Instance = GetNextDevicePathInstance (&TempNewDevicePath, &Size); + if (Instance == NULL) { + FreePool (CachedDevicePath); + return NULL; + } + if (BmMatchPartitionDevicePathNode (Instance, (HARDDRIVE_DEVICE_PATH *)FilePath)) { // // Connect the device path instance, the device path point to hard drive media device path node @@ -941,6 +962,11 @@ BmExpandPartitionDevicePath ( // 2. ACPI()/PCI()/ATA()/Partition()/Partition(A2)/EFI/BootX64.EFI // For simplicity, only #1 is returned. // + if (TempDevicePath == NULL) { + FreePool (CachedDevicePath); + return NULL; + } + FullPath = BmGetNextLoadOptionDevicePath (TempDevicePath, NULL); FreePool (TempDevicePath); @@ -992,8 +1018,7 @@ BmExpandPartitionDevicePath ( Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &BlockIoHandleCount, &BlockIoBuffer); if (EFI_ERROR (Status)) { - BlockIoHandleCount = 0; - BlockIoBuffer = NULL; + return NULL; } // @@ -1103,7 +1128,10 @@ BmExpandMediaDevicePath ( if (GetNext) { return NextFullPath; } else { - FreePool (NextFullPath); + if (NextFullPath != NULL) { + FreePool (NextFullPath); + } + return NULL; } } @@ -1160,7 +1188,11 @@ BmExpandMediaDevicePath ( // Get the device path size of SimpleFileSystem handle // TempDevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]); - TempSize = GetDevicePathSize (TempDevicePath) - END_DEVICE_PATH_LENGTH; + if (TempDevicePath == NULL) { + goto Exit; + } + + TempSize = GetDevicePathSize (TempDevicePath) - END_DEVICE_PATH_LENGTH; // // Check whether the device path of boot option is part of the SimpleFileSystem handle's device path // @@ -1169,13 +1201,16 @@ BmExpandMediaDevicePath ( if (GetNext) { break; } else { - GetNext = (BOOLEAN)(CompareMem (NextFullPath, FullPath, GetDevicePathSize (NextFullPath)) == 0); - FreePool (NextFullPath); - NextFullPath = NULL; + if (NextFullPath != NULL) { + GetNext = (BOOLEAN)(CompareMem (NextFullPath, FullPath, GetDevicePathSize (NextFullPath)) == 0); + FreePool (NextFullPath); + NextFullPath = NULL; + } } } } +Exit: if (SimpleFileSystemHandles != NULL) { FreePool (SimpleFileSystemHandles); } @@ -1256,8 +1291,7 @@ BmExpandNetworkFileSystem ( &Handles ); if (EFI_ERROR (Status)) { - Handles = NULL; - HandleCount = 0; + return NULL; } Handle = NULL; @@ -1581,7 +1615,7 @@ BmExpandLoadFiles ( } for (Index = 0; Index < HandleCount; Index++) { - if (BmMatchHttpBootDevicePath (DevicePathFromHandle (Handles[Index]), FilePath)) { + if ((Handles != NULL) && BmMatchHttpBootDevicePath (DevicePathFromHandle (Handles[Index]), FilePath)) { // // Matches HTTP Boot Device Path described as // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv4(...)[/Dns(...)]/Uri(...) @@ -2307,12 +2341,20 @@ BmEnumerateBootOptions ( } Description = BmGetBootDescription (Handles[Index]); + if (Description == NULL) { + continue; + } + BootOptions = ReallocatePool ( sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount), sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount + 1), BootOptions ); - ASSERT (BootOptions != NULL); + if (BootOptions == NULL) { + ASSERT (BootOptions != NULL); + FreePool (Description); + goto Exit; + } Status = EfiBootManagerInitializeLoadOption ( &BootOptions[(*BootOptionCount)++], @@ -2358,12 +2400,20 @@ BmEnumerateBootOptions ( } Description = BmGetBootDescription (Handles[Index]); + if (Description == NULL) { + continue; + } + BootOptions = ReallocatePool ( sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount), sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount + 1), BootOptions ); - ASSERT (BootOptions != NULL); + if (BootOptions == NULL) { + ASSERT (BootOptions != NULL); + FreePool (Description); + goto Exit; + } Status = EfiBootManagerInitializeLoadOption ( &BootOptions[(*BootOptionCount)++], @@ -2402,12 +2452,20 @@ BmEnumerateBootOptions ( } Description = BmGetBootDescription (Handles[Index]); + if (Description == NULL) { + continue; + } + BootOptions = ReallocatePool ( sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount), sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount + 1), BootOptions ); - ASSERT (BootOptions != NULL); + if (BootOptions == NULL) { + ASSERT (BootOptions != NULL); + FreePool (Description); + goto Exit; + } Status = EfiBootManagerInitializeLoadOption ( &BootOptions[(*BootOptionCount)++], @@ -2423,11 +2481,15 @@ BmEnumerateBootOptions ( FreePool (Description); } +Exit: if (HandleCount != 0) { FreePool (Handles); } - BmMakeBootOptionDescriptionUnique (BootOptions, *BootOptionCount); + if (BootOptions != NULL) { + BmMakeBootOptionDescriptionUnique (BootOptions, *BootOptionCount); + } + return BootOptions; } @@ -2494,6 +2556,9 @@ EfiBootManagerRefreshAllBootOption ( } NvBootOptions = EfiBootManagerGetLoadOptions (&NvBootOptionCount, LoadOptionTypeBoot); + if (NvBootOptions == NULL) { + goto Exit; + } // // Remove invalid EFI boot options from NV @@ -2530,8 +2595,14 @@ EfiBootManagerRefreshAllBootOption ( } } - EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); - EfiBootManagerFreeLoadOptions (NvBootOptions, NvBootOptionCount); +Exit: + if (BootOptions != NULL) { + EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); + } + + if (NvBootOptions != NULL) { + EfiBootManagerFreeLoadOptions (NvBootOptions, NvBootOptionCount); + } } /** @@ -2635,8 +2706,11 @@ BmRegisterBootManagerMenu ( UINTN BootOptionCount; BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); + if (BootOptions != NULL) { ASSERT (EfiBootManagerFindLoadOption (BootOption, BootOptions, BootOptionCount) == -1); EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); + } + ); return EfiBootManagerAddLoadOptionVariable (BootOption, (UINTN)-1); @@ -2666,6 +2740,11 @@ EfiBootManagerGetBootManagerMenu ( UINTN Index; BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); + if ((BootOptions == NULL) || (BootOptionCount == 0)) { + BootOptionCount = 0; + Index = 0; + goto Exit; + } for (Index = 0; Index < BootOptionCount; Index++) { if (BmIsBootManagerMenuFilePath (BootOptions[Index].FilePath)) { @@ -2689,6 +2768,7 @@ EfiBootManagerGetBootManagerMenu ( // // Automatically create the Boot#### for Boot Manager Menu when not found. // +Exit: if (Index == BootOptionCount) { return BmRegisterBootManagerMenu (BootOption); } else { diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c index 6106aa5fc5..46f3c4c8dc 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c @@ -379,7 +379,11 @@ BmGetDescriptionFromDiskInfo ( ); if (!EFI_ERROR (Status)) { Description = AllocateZeroPool ((ModelNameLength + SerialNumberLength + 2) * sizeof (CHAR16)); - ASSERT (Description != NULL); + if (Description == NULL) { + ASSERT (Description != NULL); + return NULL; + } + for (Index = 0; Index + 1 < ModelNameLength; Index += 2) { Description[Index] = (CHAR16)IdentifyData.ModelName[Index + 1]; Description[Index + 1] = (CHAR16)IdentifyData.ModelName[Index]; @@ -410,7 +414,10 @@ BmGetDescriptionFromDiskInfo ( ); if (!EFI_ERROR (Status)) { Description = AllocateZeroPool ((VENDOR_IDENTIFICATION_LENGTH + PRODUCT_IDENTIFICATION_LENGTH + 2) * sizeof (CHAR16)); - ASSERT (Description != NULL); + if (Description == NULL) { + ASSERT (Description != NULL); + return NULL; + } // // Per SCSI spec, EFI_SCSI_INQUIRY_DATA.Reserved_5_95[3 - 10] save the Verdor identification @@ -571,7 +578,11 @@ BmGetUsbDescription ( DescMaxSize = StrSize (Manufacturer) + StrSize (Product) + StrSize (SerialNumber); Description = AllocateZeroPool (DescMaxSize); - ASSERT (Description != NULL); + if (Description == NULL) { + ASSERT (Description != NULL); + return NULL; + } + StrCatS (Description, DescMaxSize/sizeof (CHAR16), Manufacturer); StrCatS (Description, DescMaxSize/sizeof (CHAR16), L" "); @@ -602,7 +613,7 @@ BmGetUsbDescription ( @param Handle Controller handle. - @return The description string. + @return The description string or NULL if the string could not be created. **/ CHAR16 * BmGetNetworkDescription ( @@ -734,7 +745,11 @@ BmGetNetworkDescription ( // DescriptionSize = sizeof (L"HTTPv6 (MAC:112233445566 VLAN65535)"); Description = AllocatePool (DescriptionSize); - ASSERT (Description != NULL); + if (Description == NULL) { + ASSERT (Description != NULL); + return NULL; + } + UnicodeSPrint ( Description, DescriptionSize, @@ -1027,7 +1042,7 @@ BM_GET_BOOT_DESCRIPTION mBmBootDescriptionHandlers[] = { @param Handle Controller handle. - @return The description string. + @return The description string or NULL if the string could not be created. **/ CHAR16 * BmGetBootDescription ( @@ -1053,7 +1068,11 @@ BmGetBootDescription ( // ONLY for core provided boot description handler. // Temp = AllocatePool (StrSize (DefaultDescription) + sizeof (mBmUefiPrefix)); - ASSERT (Temp != NULL); + if (Temp == NULL) { + ASSERT (Temp != NULL); + return NULL; + } + StrCpyS (Temp, (StrSize (DefaultDescription) + sizeof (mBmUefiPrefix)) / sizeof (CHAR16), mBmUefiPrefix); StrCatS (Temp, (StrSize (DefaultDescription) + sizeof (mBmUefiPrefix)) / sizeof (CHAR16), DefaultDescription); FreePool (DefaultDescription); @@ -1117,7 +1136,10 @@ BmMakeBootOptionDescriptionUnique ( } Visited = AllocateZeroPool (sizeof (BOOLEAN) * BootOptionCount); - ASSERT (Visited != NULL); + if (Visited == NULL) { + ASSERT (Visited != NULL); + return; + } for (Base = 0; Base < BootOptionCount; Base++) { if (!Visited[Base]) { diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c b/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c index 60e7b1099a..178dfcce3e 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c @@ -193,7 +193,9 @@ EfiBootManagerGetGopDevicePath ( // TempDevicePath = GopPool; GopPool = AppendDevicePathInstance (GopPool, DevicePath); - gBS->FreePool (TempDevicePath); + if (TempDevicePath != NULL) { + gBS->FreePool (TempDevicePath); + } } } @@ -204,9 +206,19 @@ EfiBootManagerGetGopDevicePath ( DEBUG ((DEBUG_INFO, "[Bds] Looking for GOP child deeper ... \n")); TempDevicePath = GopPool; ReturnDevicePath = EfiBootManagerGetGopDevicePath (OpenInfoBuffer[Index].ControllerHandle); - GopPool = AppendDevicePathInstance (GopPool, ReturnDevicePath); - gBS->FreePool (ReturnDevicePath); - gBS->FreePool (TempDevicePath); + if (ReturnDevicePath != NULL) { + TempDevicePath = GopPool; + GopPool = AppendDevicePathInstance (GopPool, ReturnDevicePath); + if (TempDevicePath != NULL) { + gBS->FreePool (TempDevicePath); + } + + gBS->FreePool (ReturnDevicePath); + } + + if (TempDevicePath != NULL) { + gBS->FreePool (TempDevicePath); + } } } } @@ -464,29 +476,33 @@ EfiBootManagerUpdateConsoleVariable ( // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it. // NewDevicePath = BmDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath); + // // In the first check, the default console variable will be _ModuleEntryPoint, // just append current customized device path // TempNewDevicePath = NewDevicePath; - NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath); + + NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath); if (TempNewDevicePath != NULL) { FreePool (TempNewDevicePath); } } } - // - // Finally, Update the variable of the default console by NewDevicePath - // - Status = gRT->SetVariable ( - mConVarName[ConsoleType], - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS - | ((ConsoleType < ConInDev) ? EFI_VARIABLE_NON_VOLATILE : 0), - GetDevicePathSize (NewDevicePath), - NewDevicePath - ); + if (NewDevicePath != NULL) { + // + // Finally, Update the variable of the default console by NewDevicePath + // + Status = gRT->SetVariable ( + mConVarName[ConsoleType], + &gEfiGlobalVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS + | ((ConsoleType < ConInDev) ? EFI_VARIABLE_NON_VOLATILE : 0), + GetDevicePathSize (NewDevicePath), + NewDevicePath + ); + } if (VarConsole == NewDevicePath) { if (VarConsole != NULL) { diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c index 1f6786f353..1b1cdf6759 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c @@ -548,7 +548,10 @@ BmRepairAllControllers ( } Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **)&FormBrowser2); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return; + } MaxRepairCount = PcdGet32 (PcdMaxRepairCount); RepairCount = 0; @@ -561,6 +564,10 @@ BmRepairAllControllers ( // Deal with Repair Required // DriverHealthInfo = EfiBootManagerGetDriverHealthInfo (&Count); + if (DriverHealthInfo == NULL) { + return; + } + for (Index = 0; Index < Count; Index++) { if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusConfigurationRequired) { ConfigurationRequired = TRUE; @@ -622,6 +629,10 @@ BmRepairAllControllers ( RebootRequired = FALSE; ReconnectRequired = FALSE; DriverHealthInfo = EfiBootManagerGetDriverHealthInfo (&Count); + if (DriverHealthInfo == NULL) { + return; + } + for (Index = 0; Index < Count; Index++) { BmDisplayMessages (&DriverHealthInfo[Index]); @@ -651,6 +662,10 @@ BmRepairAllControllers ( CHAR16 String[512]; DriverHealthInfo = EfiBootManagerGetDriverHealthInfo (&Count); + if (DriverHealthInfo == NULL) { + return; + } + for (Index = 0; Index < Count; Index++) { if (DriverHealthInfo == NULL) { continue; diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c index 90bee73a23..7e65261034 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c @@ -1019,23 +1019,25 @@ EfiBootManagerAddKeyOptionVariable ( // Check if the hot key sequence was defined already // KeyOptions = BmGetKeyOptions (&KeyOptionCount); - for (Index = 0; Index < KeyOptionCount; Index++) { - if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) && - (CompareMem (KeyOptions[Index].Keys, KeyOption.Keys, KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY)) == 0)) - { - break; + if (KeyOptions != NULL) { + for (Index = 0; Index < KeyOptionCount; Index++) { + if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) && + (CompareMem (KeyOptions[Index].Keys, KeyOption.Keys, KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY)) == 0)) + { + break; + } + + if ((KeyOptionNumber == LoadOptionNumberUnassigned) && + (KeyOptions[Index].OptionNumber > Index) + ) + { + KeyOptionNumber = Index; + } } - if ((KeyOptionNumber == LoadOptionNumberUnassigned) && - (KeyOptions[Index].OptionNumber > Index) - ) - { - KeyOptionNumber = Index; - } + BmFreeKeyOptions (KeyOptions, KeyOptionCount); } - BmFreeKeyOptions (KeyOptions, KeyOptionCount); - if (Index < KeyOptionCount) { return EFI_ALREADY_STARTED; } @@ -1155,6 +1157,10 @@ EfiBootManagerDeleteKeyOptionVariable ( // Status = EFI_NOT_FOUND; KeyOptions = BmGetKeyOptions (&KeyOptionCount); + if (KeyOptions == NULL) { + goto Exit; + } + for (Index = 0; Index < KeyOptionCount; Index++) { if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) && (CompareMem ( @@ -1185,6 +1191,7 @@ EfiBootManagerDeleteKeyOptionVariable ( BmFreeKeyOptions (KeyOptions, KeyOptionCount); +Exit: EfiReleaseLock (&mBmHotkeyLock); return Status; diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c index 7813c87cce..66faf57322 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c @@ -45,7 +45,11 @@ BmForEachVariable ( NameSize = sizeof (CHAR16); Name = AllocateZeroPool (NameSize); - ASSERT (Name != NULL); + if (Name == NULL) { + ASSERT (Name != NULL); + return; + } + while (TRUE) { NewNameSize = NameSize; Status = gRT->GetNextVariableName (&NewNameSize, Name, &Guid); @@ -218,7 +222,10 @@ structure. + Option->OptionalDataSize; Variable = AllocatePool (VariableSize); - ASSERT (Variable != NULL); + if (Variable == NULL) { + ASSERT (Variable != NULL); + return EFI_OUT_OF_RESOURCES; + } Ptr = Variable; WriteUnaligned32 ((UINT32 *)Ptr, Option->Attributes); @@ -280,6 +287,8 @@ structure. @param Position Position of the new load option to put in the ****Order variable. @retval EFI_SUCCESS The boot#### or driver#### have been successfully registered. + @retval EFI_NOT_FOUND The boot option order variable could not be found. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources to allocate a memory buffer. @retval EFI_ALREADY_STARTED The option number of Option is being used already. @retval EFI_STATUS Return the status of gRT->SetVariable (). @@ -315,7 +324,12 @@ BmAddOptionNumberToOrderVariable ( Position = MIN (Position, OptionOrderSize / sizeof (UINT16)); NewOptionOrder = AllocatePool (OptionOrderSize + sizeof (UINT16)); - ASSERT (NewOptionOrder != NULL); + if (NewOptionOrder == NULL) { + ASSERT (NewOptionOrder != NULL); + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + if (OptionOrderSize != 0) { CopyMem (NewOptionOrder, OptionOrder, Position * sizeof (UINT16)); CopyMem (&NewOptionOrder[Position + 1], &OptionOrder[Position], OptionOrderSize - Position * sizeof (UINT16)); @@ -333,6 +347,7 @@ BmAddOptionNumberToOrderVariable ( FreePool (NewOptionOrder); } +Exit: if (OptionOrder != NULL) { FreePool (OptionOrder); } @@ -435,7 +450,12 @@ EfiBootManagerSortLoadOptionVariable ( UINTN Index; UINT16 *OptionOrder; + OptionOrder = NULL; + LoadOption = EfiBootManagerGetLoadOptions (&LoadOptionCount, OptionType); + if (LoadOption == NULL) { + goto Exit; + } if (LoadOptionCount == 0) { return; @@ -455,7 +475,11 @@ EfiBootManagerSortLoadOptionVariable ( // Create new ****Order variable // OptionOrder = AllocatePool (LoadOptionCount * sizeof (UINT16)); - ASSERT (OptionOrder != NULL); + if (OptionOrder == NULL) { + ASSERT (OptionOrder != NULL); + goto Exit; + } + for (Index = 0; Index < LoadOptionCount; Index++) { OptionOrder[Index] = (UINT16)LoadOption[Index].OptionNumber; } @@ -472,7 +496,11 @@ EfiBootManagerSortLoadOptionVariable ( // ASSERT_EFI_ERROR (Status); - FreePool (OptionOrder); +Exit: + if (OptionOrder != NULL) { + FreePool (OptionOrder); + } + EfiBootManagerFreeLoadOptions (LoadOption, LoadOptionCount); } @@ -1107,7 +1135,10 @@ EfiBootManagerGetLoadOptions ( *OptionCount = OptionOrderSize / sizeof (UINT16); Options = AllocatePool (*OptionCount * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION)); - ASSERT (Options != NULL); + if (Options == NULL) { + ASSERT (Options != NULL); + return NULL; + } OptionIndex = 0; for (Index = 0; Index < *OptionCount; Index++) { @@ -1130,7 +1161,12 @@ EfiBootManagerGetLoadOptions ( if (OptionIndex < *OptionCount) { Options = ReallocatePool (*OptionCount * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION), OptionIndex * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION), Options); - ASSERT (Options != NULL); + if (Options == NULL) { + ASSERT (Options != NULL); + FreePool (OptionOrder); + return NULL; + } + *OptionCount = OptionIndex; } } else if (LoadOptionType == LoadOptionTypePlatformRecovery) { diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c index a5e32ebdba..5449b55961 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c @@ -58,6 +58,7 @@ BmDelPartMatchInstance ( } FreePool (Instance); + Instance = GetNextDevicePathInstance (&Multi, &InstanceSize); InstanceSize -= END_DEVICE_PATH_LENGTH; } From 72d0846c4c0ceab2dd228d82be94b88237e8dde3 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Oct 2025 12:57:49 -0700 Subject: [PATCH 396/406] MdeModulePkg: Fix conditionally uninitialized variables https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Security/CWE/CWE-457/ConditionallyUninitializedVariable.qhelp Some local variables, when going through a code path, can end up uninitialized (using the value they had at the start of the function). This is generally due to an error path that can occur based on the library instances, or the unchecked error (i.e. a allocation failing). These variables should be initialized with a known value that will result in the function being able to exit gracefully. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../Library/UefiBootManagerLib/BmBoot.c | 17 +++++++++++++---- .../Library/UefiBootManagerLib/BmConsole.c | 3 +++ .../Library/UefiBootManagerLib/BmDriverHealth.c | 1 + .../Library/UefiBootManagerLib/BmHotkey.c | 2 ++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c index 44f4556f80..0d84d386ee 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c @@ -551,7 +551,7 @@ BmFindUsbDevice ( ); if (EFI_ERROR (Status)) { *UsbIoHandleCount = 0; - UsbIoHandles = NULL; + return NULL; } for (Index = 0; Index < *UsbIoHandleCount; ) { @@ -725,6 +725,10 @@ BmExpandFileDevicePath ( ) { NextFullPath = AppendDevicePath (DevicePathFromHandle (Handles[Index]), FilePath); + if (NextFullPath == NULL) { + goto Exit; + } + if (GetNext) { break; } else { @@ -740,6 +744,7 @@ BmExpandFileDevicePath ( } } +Exit: if (Handles != NULL) { FreePool (Handles); } @@ -775,8 +780,7 @@ BmExpandUriDevicePath ( EfiBootManagerConnectAll (); Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiLoadFileProtocolGuid, NULL, &HandleCount, &Handles); if (EFI_ERROR (Status)) { - HandleCount = 0; - Handles = NULL; + return NULL; } NextFullPath = NULL; @@ -1009,6 +1013,7 @@ BmExpandPartitionDevicePath ( // to search all devices in the system for a matched partition // BlockIoBuffer = NULL; + BlockIoHandleCount = 0; MatchFound = FALSE; ConnectAllAttempted = FALSE; do { @@ -1035,7 +1040,11 @@ BmExpandPartitionDevicePath ( // Find the matched partition device path // TempDevicePath = AppendDevicePath (BlockIoDevicePath, NextDevicePathNode (FilePath)); - FullPath = BmGetNextLoadOptionDevicePath (TempDevicePath, NULL); + if (TempDevicePath == NULL) { + continue; + } + + FullPath = BmGetNextLoadOptionDevicePath (TempDevicePath, NULL); FreePool (TempDevicePath); if (FullPath != NULL) { diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c b/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c index 178dfcce3e..97267e0ab7 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c @@ -438,6 +438,9 @@ EfiBootManagerUpdateConsoleVariable ( EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath; + Status = EFI_SUCCESS; + TempNewDevicePath = NULL; + if (ConsoleType >= ARRAY_SIZE (mConVarName)) { return EFI_INVALID_PARAMETER; } diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c index 1b1cdf6759..6fb325875c 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c @@ -540,6 +540,7 @@ BmRepairAllControllers ( UINT32 MaxRepairCount; UINT32 RepairCount; + Count = 0; // // Configure PcdDriverHealthConfigureForm to ZeroGuid to disable driver health check. // diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c index 7e65261034..2f17bcd853 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c @@ -1014,6 +1014,8 @@ EfiBootManagerAddKeyOptionVariable ( return Status; } + Index = 0; + KeyOptionCount = 0; KeyOptionNumber = LoadOptionNumberUnassigned; // // Check if the hot key sequence was defined already From af24f366a42503b3b5ebbb0bcb9742a6785b6833 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Oct 2025 11:13:38 -0700 Subject: [PATCH 397/406] MdeModulePkg: Fix comparison with wider widths https://codeql.github.com/codeql-query-help/cpp/cpp-comparison-with-wider-type If the narrow type (smaller range) is compared against a wide type (larger range), the narrow value may overflow before reaching the wide value. This can cause unexpected behavior, such as: Infinite loops (loop condition never becomes false). Incorrect logic (comparison results are misleading). Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../BootMaintenanceManagerUiLib/BootMaintenance.c | 14 +++++++------- .../BootMaintenanceManagerCustomizedUiSupport.c | 4 ++-- .../BootMaintenanceManagerUiLib/BootOption.c | 6 +++--- .../BootMaintenanceManagerUiLib/ConsoleOption.c | 8 ++++---- .../BootMaintenanceManagerUiLib/UpdatePage.c | 14 +++++++------- .../Library/BootMaintenanceManagerUiLib/Variable.c | 8 ++++---- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c index 19751642a3..773c978c9f 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c @@ -539,7 +539,7 @@ UpdateTerminalContent ( IN BMM_FAKE_NV_DATA *BmmData ) { - UINT16 Index; + UINTN Index; BM_TERMINAL_CONTEXT *NewTerminalContext; BM_MENU_ENTRY *NewMenuEntry; @@ -581,7 +581,7 @@ UpdateConsoleContent ( IN BMM_FAKE_NV_DATA *BmmData ) { - UINT16 Index; + UINTN Index; BM_CONSOLE_CONTEXT *NewConsoleContext; BM_TERMINAL_CONTEXT *NewTerminalContext; BM_MENU_ENTRY *NewMenuEntry; @@ -784,7 +784,7 @@ BootMaintRouteConfig ( BMM_FAKE_NV_DATA *OldBmmData; BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; - UINT16 Index; + UINTN Index; BOOLEAN TerminalAttChange; BMM_CALLBACK_DATA *Private; UINTN Offset; @@ -1353,7 +1353,7 @@ DiscardChangeHandler ( IN BMM_FAKE_NV_DATA *CurrentFakeNVMap ) { - UINT16 Index; + UINTN Index; switch (Private->BmmPreviousPageId) { case FORM_BOOT_CHG_ID: @@ -1411,7 +1411,7 @@ CleanUselessBeforeSubmit ( IN BMM_CALLBACK_DATA *Private ) { - UINT16 Index; + UINTN Index; if (Private->BmmPreviousPageId != FORM_BOOT_DEL_ID) { for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { @@ -1502,7 +1502,7 @@ InitializeBmmConfig ( { BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; - UINT16 Index; + UINTN Index; ASSERT (CallbackData != NULL); @@ -1515,7 +1515,7 @@ InitializeBmmConfig ( NewLoadContext = (BM_LOAD_CONTEXT *)NewMenuEntry->VariableContext; if (NewLoadContext->IsBootNext) { - CallbackData->BmmFakeNvData.BootNext = Index; + CallbackData->BmmFakeNvData.BootNext = (UINT32)Index; break; } } diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c index e16936041a..bbc86dea18 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c @@ -36,7 +36,7 @@ BmmCreateBootNextMenu ( { BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; - UINT16 Index; + UINTN Index; VOID *OptionsOpCodeHandle; UINT32 BootNextIndex; @@ -61,7 +61,7 @@ BmmCreateBootNextMenu ( EFI_IFR_TYPE_NUM_SIZE_32, Index ); - BootNextIndex = Index; + BootNextIndex = (UINT32)Index; } else { HiiCreateOneOfOptionOpCode ( OptionsOpCodeHandle, diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c index a47106d43b..73c985c169 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c @@ -813,7 +813,7 @@ GetBootOrder ( ) { BMM_FAKE_NV_DATA *BmmConfig; - UINT16 Index; + UINTN Index; UINT16 OptionOrderIndex; UINTN DeviceType; BM_MENU_ENTRY *NewMenuEntry; @@ -860,8 +860,8 @@ GetDriverOrder ( ) { BMM_FAKE_NV_DATA *BmmConfig; - UINT16 Index; - UINT16 OptionOrderIndex; + UINTN Index; + UINTN OptionOrderIndex; UINTN DeviceType; BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c index 7c02a78166..cc84f46592 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c @@ -1019,7 +1019,7 @@ GetConsoleInCheck ( IN BMM_CALLBACK_DATA *CallbackData ) { - UINT16 Index; + UINTN Index; BM_MENU_ENTRY *NewMenuEntry; UINT8 *ConInCheck; BM_CONSOLE_CONTEXT *NewConsoleContext; @@ -1057,7 +1057,7 @@ GetConsoleOutCheck ( IN BMM_CALLBACK_DATA *CallbackData ) { - UINT16 Index; + UINTN Index; BM_MENU_ENTRY *NewMenuEntry; UINT8 *ConOutCheck; BM_CONSOLE_CONTEXT *NewConsoleContext; @@ -1094,7 +1094,7 @@ GetConsoleErrCheck ( IN BMM_CALLBACK_DATA *CallbackData ) { - UINT16 Index; + UINTN Index; BM_MENU_ENTRY *NewMenuEntry; UINT8 *ConErrCheck; BM_CONSOLE_CONTEXT *NewConsoleContext; @@ -1134,7 +1134,7 @@ GetTerminalAttribute ( BMM_FAKE_NV_DATA *CurrentFakeNVMap; BM_MENU_ENTRY *NewMenuEntry; BM_TERMINAL_CONTEXT *NewTerminalContext; - UINT16 TerminalIndex; + UINTN TerminalIndex; UINT8 AttributeIndex; ASSERT (CallbackData != NULL); diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c index b1d1e2ee44..84becdfd84 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c @@ -194,7 +194,7 @@ UpdateConCOMPage ( ) { BM_MENU_ENTRY *NewMenuEntry; - UINT16 Index; + UINTN Index; CallbackData->BmmAskSaveOrNot = TRUE; @@ -230,7 +230,7 @@ UpdateBootDelPage ( { BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; - UINT16 Index; + UINTN Index; CallbackData->BmmAskSaveOrNot = TRUE; @@ -285,7 +285,7 @@ UpdateDrvAddHandlePage ( ) { BM_MENU_ENTRY *NewMenuEntry; - UINT16 Index; + UINTN Index; CallbackData->BmmAskSaveOrNot = FALSE; @@ -321,7 +321,7 @@ UpdateDrvDelPage ( { BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; - UINT16 Index; + UINTN Index; CallbackData->BmmAskSaveOrNot = TRUE; @@ -451,8 +451,8 @@ UpdateConsolePage ( BM_MENU_ENTRY *NewMenuEntry; BM_CONSOLE_CONTEXT *NewConsoleContext; BM_TERMINAL_CONTEXT *NewTerminalContext; - UINT16 Index; - UINT16 Index2; + UINTN Index; + UINTN Index2; UINT8 CheckFlags; UINT8 *ConsoleCheck; EFI_QUESTION_ID QuestionIdBase; @@ -571,7 +571,7 @@ UpdateOrderPage ( ) { BM_MENU_ENTRY *NewMenuEntry; - UINT16 Index; + UINTN Index; UINT16 OptionIndex; VOID *OptionsOpCodeHandle; BOOLEAN BootOptionFound; diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c index 82a0ed66a7..25158f99d6 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c @@ -537,7 +537,7 @@ Var_UpdateBootNext ( BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; BMM_FAKE_NV_DATA *CurrentFakeNVMap; - UINT16 Index; + UINTN Index; EFI_STATUS Status; Status = EFI_SUCCESS; @@ -592,8 +592,8 @@ Var_UpdateBootOrder ( ) { EFI_STATUS Status; - UINT16 Index; - UINT16 OrderIndex; + UINTN Index; + UINTN OrderIndex; UINT16 *BootOrder; UINTN BootOrderSize; UINT16 OptionNumber; @@ -654,7 +654,7 @@ Var_UpdateDriverOrder ( ) { EFI_STATUS Status; - UINT16 Index; + UINTN Index; UINT16 *DriverOrderList; UINT16 *NewDriverOrderList; UINTN DriverOrderListSize; From 1cc0af9d6de69b803189c3f86c1f80fe86caf8a6 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Oct 2025 12:57:49 -0700 Subject: [PATCH 398/406] MdeModulePkg: Fix missing NULL tests https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp For items which allocate memory, or get a pointer from another structure, it is important to validate that the pointers are not null before they are dereferenced. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- .../BootMaintenance.c | 12 ++++++++++-- .../BootMaintenanceManagerCustomizedUiSupport.c | 12 ++++++++++-- .../BootMaintenanceManagerUiLib/BootOption.c | 9 ++++++++- .../BootMaintenanceManagerUiLib/ConsoleOption.c | 10 +++++++++- .../BootMaintenanceManagerUiLib/UpdatePage.c | 17 +++++++++++++---- .../BootMaintenanceManagerUiLib/Variable.c | 6 +++++- 6 files changed, 55 insertions(+), 11 deletions(-) diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c index 773c978c9f..8c2bf870ba 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c @@ -1451,10 +1451,17 @@ CustomizeMenus ( // Allocate space for creation of UpdateData Buffer // StartOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (StartOpCodeHandle != NULL); + if (StartOpCodeHandle == NULL) { + ASSERT (StartOpCodeHandle != NULL); + return; + } EndOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (EndOpCodeHandle != NULL); + if (EndOpCodeHandle == NULL) { + ASSERT (EndOpCodeHandle != NULL); + goto Exit; + } + // // Create Hii Extend Label OpCode as the start opcode // @@ -1485,6 +1492,7 @@ CustomizeMenus ( ); HiiFreeOpCodeHandle (StartOpCodeHandle); +Exit: HiiFreeOpCodeHandle (EndOpCodeHandle); } diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c index bbc86dea18..7cfbf5aac0 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c @@ -378,10 +378,18 @@ BmmListThirdPartyDrivers ( } HiiHandles = HiiGetHiiHandles (NULL); - ASSERT (HiiHandles != NULL); + if (HiiHandles == NULL) { + ASSERT (HiiHandles != NULL); + return EFI_OUT_OF_RESOURCES; + } gHiiDriverList = AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE * sizeof (UI_HII_DRIVER_INSTANCE)); - ASSERT (gHiiDriverList != NULL); + if (gHiiDriverList == NULL) { + ASSERT (gHiiDriverList != NULL); + FreePool (HiiHandles); + return EFI_OUT_OF_RESOURCES; + } + DriverListPtr = gHiiDriverList; CurrentSize = UI_HII_DRIVER_LIST_SIZE; diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c index 73c985c169..aea573b979 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c @@ -340,6 +340,10 @@ BOpt_GetBootOptions ( BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); for (Index = 0; Index < BootOrderListSize / sizeof (UINT16); Index++) { + if (BootOption == NULL) { + continue; + } + // // Don't display the hidden/inactive boot option // @@ -363,7 +367,10 @@ BOpt_GetBootOptions ( } NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT); - ASSERT (NULL != NewMenuEntry); + if (NewMenuEntry == NULL) { + ASSERT (NULL != NewMenuEntry); + return EFI_OUT_OF_RESOURCES; + } NewLoadContext = (BM_LOAD_CONTEXT *)NewMenuEntry->VariableContext; diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c index cc84f46592..c97c657db4 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c @@ -803,6 +803,10 @@ GetConsoleMenu ( Index2 = 0; for (Index = 0; Index < AllCount; Index++) { DevicePathInst = GetNextDevicePathInstance (&MultiDevicePath, &Size); + if (DevicePathInst == NULL) { + ASSERT (DevicePathInst != NULL); + continue; + } NewMenuEntry = BOpt_CreateMenuEntry (BM_CONSOLE_CONTEXT_SELECT); if (NULL == NewMenuEntry) { @@ -813,7 +817,11 @@ GetConsoleMenu ( NewMenuEntry->OptionNumber = Index2; NewConsoleContext->DevicePath = DuplicateDevicePath (DevicePathInst); - ASSERT (NewConsoleContext->DevicePath != NULL); + if (NewConsoleContext->DevicePath == NULL) { + ASSERT (NewConsoleContext->DevicePath != NULL); + return EFI_OUT_OF_RESOURCES; + } + NewMenuEntry->DisplayString = EfiLibStrFromDatahub (NewConsoleContext->DevicePath); if (NULL == NewMenuEntry->DisplayString) { NewMenuEntry->DisplayString = UiDevicePathToStr (NewConsoleContext->DevicePath); diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c index 84becdfd84..0cf53104b2 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c @@ -486,7 +486,10 @@ UpdateConsolePage ( break; } - ASSERT (ConsoleCheck != NULL); + if (ConsoleCheck == NULL) { + ASSERT (ConsoleCheck != NULL); + return; + } for (Index = 0; ((Index < ConsoleMenu->MenuNumber) && \ (Index < MAX_MENU_NUMBER)); Index++) @@ -619,10 +622,16 @@ UpdateOrderPage ( break; } - ASSERT (OptionOrder != NULL); + if (OptionOrder == NULL ) { + ASSERT (OptionOrder != NULL); + return; + } OptionsOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (OptionsOpCodeHandle != NULL); + if (OptionsOpCodeHandle == NULL) { + ASSERT (OptionsOpCodeHandle != NULL); + return; + } NewMenuEntry = NULL; for (OptionIndex = 0; (OptionIndex < MAX_MENU_NUMBER && OptionOrder[OptionIndex] != 0); OptionIndex++) { @@ -635,7 +644,7 @@ UpdateOrderPage ( } } - if (BootOptionFound) { + if (BootOptionFound && (NewMenuEntry != NULL)) { HiiCreateOneOfOptionOpCode ( OptionsOpCodeHandle, NewMenuEntry->DisplayStringToken, diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c index 25158f99d6..2003f65620 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c @@ -197,7 +197,11 @@ Var_UpdateConsoleOption ( NewTerminalContext->DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&Vendor ); - ASSERT (TerminalDevicePath != NULL); + if (TerminalDevicePath == NULL) { + ASSERT (TerminalDevicePath != NULL); + return EFI_OUT_OF_RESOURCES; + } + ChangeTerminalDevicePath (TerminalDevicePath, TRUE); ConDevicePath = AppendDevicePathInstance ( ConDevicePath, From d1c5d47014b10ab9d59c785410dbb8b3f990bc98 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Thu, 23 Oct 2025 14:57:30 -0700 Subject: [PATCH 399/406] MdeModulePkg: Fix unchecked return status https://github.com/github/codeql/blob/codeql-cli-2.7.3/csharp/ql/src/API%20Abuse/UncheckedReturnValue.qhelp When a function has a return status, it should be checked to verify the function completed successfully. Failing to check the return status can result in null pointer dereferences or use of uninitialized variables. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c index 0cf53104b2..156a84c0b4 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c @@ -484,6 +484,9 @@ UpdateConsolePage ( QuestionIdBase = CON_ERR_DEVICE_QUESTION_ID; VariableOffsetBase = CON_ERR_DEVICE_VAR_OFFSET; break; + + default: + return; } if (ConsoleCheck == NULL) { From 4074b5db5df85965e26c5b647a9576c96fe04aaf Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Fri, 31 Jul 2026 11:43:11 -0400 Subject: [PATCH 400/406] .pytool/Plugin/UncrustifyCheck: Better support multi-repo workspaces The plugin previously assumed that the workspace was a git repository and made that pacakges would largely reside in that same repository. A few changes are made to better support multi-repo workspaces: 1. Added a new method to find the git repo that contains the package being checked: `_get_git_repo_path()`. 2. Removes exceptions on git not being present and ignore/submodule exceptions. 3. Checks for git ignored files (and similar) in the repo containing the package being checked in `_get_git_ignored_paths()`. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- .../Plugin/UncrustifyCheck/UncrustifyCheck.py | 80 ++++++++++++------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py index 5aaed2bda4..ece4239874 100644 --- a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py +++ b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py @@ -24,7 +24,7 @@ from edk2toollib.log.junit_report_format import JunitReportTestCase from edk2toollib.uefi.edk2.path_utilities import Edk2Path from edk2toollib.utility_functions import RunCmd from io import StringIO -from typing import Any, Dict, List, Tuple +from typing import Any, Dict, List, Optional, Tuple # # Provide more user friendly messages for certain scenarios @@ -63,15 +63,6 @@ class UncrustifyInvalidIgnoreStandardPathsException(UncrustifyException): def __init__(self, message): super().__init__(message, -122) -class UncrustifyGitIgnoreFileException(UncrustifyException): - def __init__(self, message): - super().__init__(message, -140) - - -class UncrustifyGitSubmoduleException(UncrustifyException): - def __init__(self, message): - super().__init__(message, -141) - class UncrustifyCheck(ICiBuildPlugin): """ @@ -303,56 +294,81 @@ class UncrustifyCheck(ICiBuildPlugin): return parse_gitignore_lines(ignored_files, "Package configuration file", self._abs_package_path) def _get_git_ignored_paths(self) -> List[str]: - """" + """ Returns a list of file absolute path strings to all files ignored in this git repository. - If git is not found, an empty list will be returned. + If the package's git repository could not be determined, or the command otherwise + fails, an empty list is returned instead. """ - if not shutil.which("git"): - logging.warning( - "Git is not found on this system. Git submodule paths will not be considered.") + if self._abs_git_repo_path is None: return [] outstream_buffer = StringIO() exit_code = RunCmd("git", "ls-files --other", - workingdir=self._abs_workspace_path, outstream=outstream_buffer, logging_level=logging.NOTSET) - if (exit_code != 0): - raise UncrustifyGitIgnoreFileException( - f"An error occurred reading git ignore settings. This will prevent Uncrustify from running against the expected set of files.") + workingdir=self._abs_git_repo_path, outstream=outstream_buffer, logging_level=logging.NOTSET) + if exit_code != 0: + logging.warning( + "An error occurred reading git ignore settings. Git ignored paths will not be considered.") + return [] # Note: This will potentially be a large list, but at least sorted rel_paths = outstream_buffer.getvalue().strip().splitlines() abs_paths = [] for path in rel_paths: abs_paths.append( - os.path.normpath(os.path.join(self._abs_workspace_path, path))) + os.path.normpath(os.path.join(self._abs_git_repo_path, path))) return abs_paths - def _get_git_submodule_paths(self) -> List[str]: + def _get_git_repo_path(self) -> Optional[str]: """ - Returns a list of directory absolute path strings to the root of each submodule in the workspace repository. + Returns the absolute path to the root of the git repository that contains the package + currently being checked. This is not necessarily the edk2 repository, since the package + may belong to a different repository combined into the workspace (e.g. via + PACKAGES_PATH). - If git is not found, an empty list will be returned. + Returns None if git is not found or the package is not within a git workspace. """ if not shutil.which("git"): logging.warning( - "Git is not found on this system. Git submodule paths will not be considered.") + "Git is not found on this system. Git exclusions will not be considered.") + return None + + outstream_buffer = StringIO() + exit_code = RunCmd("git", "rev-parse --show-toplevel", + workingdir=self._abs_package_path, outstream=outstream_buffer, logging_level=logging.NOTSET) + if exit_code != 0: + logging.warning( + f"{self._package_name} does not appear to be in a git workspace. Git exclusions will not be considered.") + return None + + return os.path.normpath(outstream_buffer.getvalue().strip()) + + def _get_git_submodule_paths(self) -> List[str]: + """ + Returns a list of directory absolute path strings to the root of each submodule in the + package's git repository. + + If the package's git repository could not be determined, there is no .gitmodules file, + or the command otherwise fails, an empty list is returned instead. + """ + if self._abs_git_repo_path is None: return [] - if os.path.isfile(os.path.join(self._abs_workspace_path, ".gitmodules")): + if os.path.isfile(os.path.join(self._abs_git_repo_path, ".gitmodules")): logging.info( f".gitmodules file found. Excluding submodules in {self._package_name}.") outstream_buffer = StringIO() - exit_code = RunCmd("git", "config --file .gitmodules --get-regexp path", workingdir=self._abs_workspace_path, outstream=outstream_buffer, logging_level=logging.NOTSET) - if (exit_code != 0): - raise UncrustifyGitSubmoduleException( - f".gitmodule file detected but an error occurred reading the file. Cannot proceed with unknown submodule paths.") + exit_code = RunCmd("git", "config --file .gitmodules --get-regexp path", workingdir=self._abs_git_repo_path, outstream=outstream_buffer, logging_level=logging.NOTSET) + if exit_code != 0: + logging.warning( + ".gitmodules file detected but an error occurred reading it. Git submodule paths will not be considered.") + return [] submodule_paths = [] for line in outstream_buffer.getvalue().strip().splitlines(): submodule_paths.append( - os.path.normpath(os.path.join(self._abs_workspace_path, line.split()[1]))) + os.path.normpath(os.path.join(self._abs_git_repo_path, line.split()[1]))) return submodule_paths else: @@ -508,6 +524,10 @@ class UncrustifyCheck(ICiBuildPlugin): f"{self._package_name} file count after plugin ignore file exclusion: {len(self._abs_file_paths_to_format)}") if not "SkipGitExclusions" in self._package_config or not self._package_config["SkipGitExclusions"]: + # Determine the git repository that contains this package. This is not necessarily + # the edk2 repository if the package is in a different repo (e.g. PACKAGES_PATH). + self._abs_git_repo_path = self._get_git_repo_path() + # Remove files ignored by git logging.info( f"{self._package_name} file count before git ignore file exclusion: {len(self._abs_file_paths_to_format)}") From e0d2cb29fea69a32efaaa5d67563dda2cfa76948 Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Fri, 31 Jul 2026 12:24:02 -0400 Subject: [PATCH 401/406] .pytool/Plugin/UncrustifyCheck: Run Black formatter Runs the Black formatter against UncrustifyCheck.py so is formatted to PEP-8. No functional changes are made. https://pypi.org/project/black/ Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- .../Plugin/UncrustifyCheck/UncrustifyCheck.py | 372 ++++++++++++------ 1 file changed, 258 insertions(+), 114 deletions(-) diff --git a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py index ece4239874..120c45b5bf 100644 --- a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py +++ b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py @@ -22,10 +22,11 @@ from edk2toolext.environment.var_dict import VarDict from edk2toollib.gitignore_parser import parse_gitignore_lines from edk2toollib.log.junit_report_format import JunitReportTestCase from edk2toollib.uefi.edk2.path_utilities import Edk2Path -from edk2toollib.utility_functions import RunCmd +from edk2toollib.utility_functions import RunCmd from io import StringIO from typing import Any, Dict, List, Optional, Tuple + # # Provide more user friendly messages for certain scenarios # @@ -59,6 +60,7 @@ class UncrustifyInputFileCreationErrorException(UncrustifyException): def __init__(self, message): super().__init__(message, -121) + class UncrustifyInvalidIgnoreStandardPathsException(UncrustifyException): def __init__(self, message): super().__init__(message, -122) @@ -91,7 +93,8 @@ class UncrustifyCheck(ICiBuildPlugin): # Note: Values specified via "ConfigFilePath" are relative to the package # DEFAULT_CONFIG_FILE_PATH = os.path.join( - pathlib.Path(__file__).parent.resolve(), "uncrustify.cfg") + pathlib.Path(__file__).parent.resolve(), "uncrustify.cfg" + ) # # The extension used for formatted files produced by this plugin @@ -110,20 +113,33 @@ class UncrustifyCheck(ICiBuildPlugin): UNCRUSTIFY_PATH_ENV_KEY = "UNCRUSTIFY_CI_PATH" def GetTestName(self, packagename: str, environment: VarDict) -> Tuple: - """ Provide the testcase name and classname for use in reporting + """Provide the testcase name and classname for use in reporting - Args: - packagename: string containing name of package to build - environment: The VarDict for the test to run in - Returns: - A tuple containing the testcase name and the classname - (testcasename, classname) - testclassname: a descriptive string for the testcase can include whitespace - classname: should be patterned <packagename>.<plugin>.<optionally any unique condition> + Args: + packagename: string containing name of package to build + environment: The VarDict for the test to run in + Returns: + A tuple containing the testcase name and the classname + (testcasename, classname) + testclassname: a descriptive string for the testcase can include whitespace + classname: should be patterned <packagename>.<plugin>.<optionally any unique condition> """ - return ("Check file coding standard compliance in " + packagename, packagename + ".UncrustifyCheck") + return ( + "Check file coding standard compliance in " + packagename, + packagename + ".UncrustifyCheck", + ) - def RunBuildPlugin(self, package_rel_path: str, edk2_path: Edk2Path, package_config: Dict[str, List[str]], environment_config: Any, plugin_manager: PluginManager, plugin_manager_helper: HelperFunctions, tc: JunitReportTestCase, output_stream=None) -> int: + def RunBuildPlugin( + self, + package_rel_path: str, + edk2_path: Edk2Path, + package_config: Dict[str, List[str]], + environment_config: Any, + plugin_manager: PluginManager, + plugin_manager_helper: HelperFunctions, + tc: JunitReportTestCase, + output_stream=None, + ) -> int: """ External function of plugin. This function is used to perform the task of the CiBuild Plugin. @@ -146,7 +162,8 @@ class UncrustifyCheck(ICiBuildPlugin): # Initialize plugin and check pre-requisites. self._env = environment_config self._initialize_environment_info( - package_rel_path, edk2_path, package_config, tc) + package_rel_path, edk2_path, package_config, tc + ) self._initialize_configuration() self._check_for_preexisting_formatted_files() @@ -167,20 +184,21 @@ class UncrustifyCheck(ICiBuildPlugin): except UncrustifyException as e: self._tc.LogStdError( - f"Uncrustify error {e.exit_code}. Details:\n\n{str(e)}") - logging.warning( - f"Uncrustify error {e.exit_code}. Details:\n\n{str(e)}") + f"Uncrustify error {e.exit_code}. Details:\n\n{str(e)}" + ) + logging.warning(f"Uncrustify error {e.exit_code}. Details:\n\n{str(e)}") return -1 else: if self._formatted_file_error_count > 0: if self._audit_only_mode: - logging.info( - "Setting test as skipped since AuditOnly is enabled") + logging.info("Setting test as skipped since AuditOnly is enabled") self._tc.SetSkipped() return -1 else: self._tc.SetFailed( - f"{self._plugin_name} failed due to {self._formatted_file_error_count} incorrectly formatted files.", "CHECK_FAILED") + f"{self._plugin_name} failed due to {self._formatted_file_error_count} incorrectly formatted files.", + "CHECK_FAILED", + ) else: self._tc.SetSuccess() return self._formatted_file_error_count @@ -205,11 +223,18 @@ class UncrustifyCheck(ICiBuildPlugin): from an error that occurred during a previous run or a premature exit from a debug scenario. In any case, the package should be clean before starting a new run. """ pre_existing_formatted_file_count = len( - [str(path.resolve()) for path in pathlib.Path(self._abs_package_path).rglob(f'*{UncrustifyCheck.FORMATTED_FILE_EXTENSION}')]) + [ + str(path.resolve()) + for path in pathlib.Path(self._abs_package_path).rglob( + f"*{UncrustifyCheck.FORMATTED_FILE_EXTENSION}" + ) + ] + ) if pre_existing_formatted_file_count > 0: raise UncrustifyStalePluginFormattedFilesException( - f"{pre_existing_formatted_file_count} formatted files already exist. To prevent overwriting these files, please remove them before running this plugin.") + f"{pre_existing_formatted_file_count} formatted files already exist. To prevent overwriting these files, please remove them before running this plugin." + ) def _cleanup_temporary_directory(self) -> None: """ @@ -217,7 +242,7 @@ class UncrustifyCheck(ICiBuildPlugin): This removes the directory and all files created during this instance. """ - if hasattr(self, '_working_dir'): + if hasattr(self, "_working_dir"): self._remove_tree(self._working_dir) def _cleanup_temporary_formatted_files(self) -> None: @@ -227,9 +252,13 @@ class UncrustifyCheck(ICiBuildPlugin): This will recursively remove all formatted files generated by Uncrustify during this execution instance. """ - if hasattr(self, '_abs_package_path'): - formatted_files = [str(path.resolve()) for path in pathlib.Path( - self._abs_package_path).rglob(f'*{UncrustifyCheck.FORMATTED_FILE_EXTENSION}')] + if hasattr(self, "_abs_package_path"): + formatted_files = [ + str(path.resolve()) + for path in pathlib.Path(self._abs_package_path).rglob( + f"*{UncrustifyCheck.FORMATTED_FILE_EXTENSION}" + ) + ] for formatted_file in formatted_files: os.remove(formatted_file) @@ -239,22 +268,29 @@ class UncrustifyCheck(ICiBuildPlugin): Creates the temporary directory used for this execution instance. """ self._working_dir = os.path.join( - self._abs_workspace_path, "Build", ".pytool", "Plugin", f"{self._plugin_name}") + self._abs_workspace_path, + "Build", + ".pytool", + "Plugin", + f"{self._plugin_name}", + ) try: pathlib.Path(self._working_dir).mkdir(parents=True, exist_ok=True) except OSError as e: raise UncrustifyInputFileCreationErrorException( - f"Error creating plugin directory {self._working_dir}.\n\n{repr(e)}.") + f"Error creating plugin directory {self._working_dir}.\n\n{repr(e)}." + ) def _create_uncrustify_file_list_file(self) -> None: """ Creates the file with the list of source files for Uncrustify to process. """ self._app_input_file_path = os.path.join( - self._working_dir, "uncrustify_file_list.txt") + self._working_dir, "uncrustify_file_list.txt" + ) - with open(self._app_input_file_path, 'w', encoding='utf8') as f: + with open(self._app_input_file_path, "w", encoding="utf8") as f: f.writelines(f"\n".join(self._abs_file_paths_to_format)) def _execute_uncrustify(self) -> None: @@ -262,21 +298,18 @@ class UncrustifyCheck(ICiBuildPlugin): Executes Uncrustify with the initialized configuration. """ output = StringIO() - params = ['-c', self._app_config_file] - params += ['-F', self._app_input_file_path] - params += ['--if-changed'] + params = ["-c", self._app_config_file] + params += ["-F", self._app_input_file_path] + params += ["--if-changed"] if self._env.GetValue("UNCRUSTIFY_IN_PLACE", "FALSE") == "TRUE": - params += ['--replace', '--no-backup'] + params += ["--replace", "--no-backup"] else: - params += ['--suffix', UncrustifyCheck.FORMATTED_FILE_EXTENSION] - self._app_exit_code = RunCmd( - self._app_path, - " ".join(params), - outstream=output) + params += ["--suffix", UncrustifyCheck.FORMATTED_FILE_EXTENSION] + self._app_exit_code = RunCmd(self._app_path, " ".join(params), outstream=output) self._app_output = output.getvalue().strip().splitlines() def _get_files_ignored_in_config(self): - """" + """ " Returns a function that returns true if a given file string path is ignored in the plugin configuration file and false otherwise. """ ignored_files = [] @@ -291,7 +324,9 @@ class UncrustifyCheck(ICiBuildPlugin): # This information is only used for reporting (not used here) and # the ignore lines are being passed directly as they are given to # this plugin. - return parse_gitignore_lines(ignored_files, "Package configuration file", self._abs_package_path) + return parse_gitignore_lines( + ignored_files, "Package configuration file", self._abs_package_path + ) def _get_git_ignored_paths(self) -> List[str]: """ @@ -304,11 +339,17 @@ class UncrustifyCheck(ICiBuildPlugin): return [] outstream_buffer = StringIO() - exit_code = RunCmd("git", "ls-files --other", - workingdir=self._abs_git_repo_path, outstream=outstream_buffer, logging_level=logging.NOTSET) + exit_code = RunCmd( + "git", + "ls-files --other", + workingdir=self._abs_git_repo_path, + outstream=outstream_buffer, + logging_level=logging.NOTSET, + ) if exit_code != 0: logging.warning( - "An error occurred reading git ignore settings. Git ignored paths will not be considered.") + "An error occurred reading git ignore settings. Git ignored paths will not be considered." + ) return [] # Note: This will potentially be a large list, but at least sorted @@ -316,7 +357,8 @@ class UncrustifyCheck(ICiBuildPlugin): abs_paths = [] for path in rel_paths: abs_paths.append( - os.path.normpath(os.path.join(self._abs_git_repo_path, path))) + os.path.normpath(os.path.join(self._abs_git_repo_path, path)) + ) return abs_paths def _get_git_repo_path(self) -> Optional[str]: @@ -330,15 +372,22 @@ class UncrustifyCheck(ICiBuildPlugin): """ if not shutil.which("git"): logging.warning( - "Git is not found on this system. Git exclusions will not be considered.") + "Git is not found on this system. Git exclusions will not be considered." + ) return None outstream_buffer = StringIO() - exit_code = RunCmd("git", "rev-parse --show-toplevel", - workingdir=self._abs_package_path, outstream=outstream_buffer, logging_level=logging.NOTSET) + exit_code = RunCmd( + "git", + "rev-parse --show-toplevel", + workingdir=self._abs_package_path, + outstream=outstream_buffer, + logging_level=logging.NOTSET, + ) if exit_code != 0: logging.warning( - f"{self._package_name} does not appear to be in a git workspace. Git exclusions will not be considered.") + f"{self._package_name} does not appear to be in a git workspace. Git exclusions will not be considered." + ) return None return os.path.normpath(outstream_buffer.getvalue().strip()) @@ -356,19 +405,30 @@ class UncrustifyCheck(ICiBuildPlugin): if os.path.isfile(os.path.join(self._abs_git_repo_path, ".gitmodules")): logging.info( - f".gitmodules file found. Excluding submodules in {self._package_name}.") + f".gitmodules file found. Excluding submodules in {self._package_name}." + ) outstream_buffer = StringIO() - exit_code = RunCmd("git", "config --file .gitmodules --get-regexp path", workingdir=self._abs_git_repo_path, outstream=outstream_buffer, logging_level=logging.NOTSET) + exit_code = RunCmd( + "git", + "config --file .gitmodules --get-regexp path", + workingdir=self._abs_git_repo_path, + outstream=outstream_buffer, + logging_level=logging.NOTSET, + ) if exit_code != 0: logging.warning( - ".gitmodules file detected but an error occurred reading it. Git submodule paths will not be considered.") + ".gitmodules file detected but an error occurred reading it. Git submodule paths will not be considered." + ) return [] submodule_paths = [] for line in outstream_buffer.getvalue().strip().splitlines(): submodule_paths.append( - os.path.normpath(os.path.join(self._abs_git_repo_path, line.split()[1]))) + os.path.normpath( + os.path.join(self._abs_git_repo_path, line.split()[1]) + ) + ) return submodule_paths else: @@ -386,7 +446,7 @@ class UncrustifyCheck(ICiBuildPlugin): # Allow no value to allow "set" statements in the config file which do # not specify value assignment parser = configparser.ConfigParser(allow_no_value=True) - with open(self._app_config_file, 'r') as cf: + with open(self._app_config_file, "r") as cf: parser.read_string("[dummy_section]\n" + cf.read()) try: @@ -395,7 +455,9 @@ class UncrustifyCheck(ICiBuildPlugin): file_template_path = pathlib.Path(file_template_name) if not file_template_path.is_file(): - file_template_path = pathlib.Path(os.path.join(self._plugin_path, file_template_name)) + file_template_path = pathlib.Path( + os.path.join(self._plugin_path, file_template_name) + ) self._file_template_contents = file_template_path.read_text() except KeyError: logging.info("A file header template is not specified in the config file.") @@ -407,10 +469,14 @@ class UncrustifyCheck(ICiBuildPlugin): func_template_path = pathlib.Path(func_template_name) if not func_template_path.is_file(): - func_template_path = pathlib.Path(os.path.join(self._plugin_path, func_template_name)) + func_template_path = pathlib.Path( + os.path.join(self._plugin_path, func_template_name) + ) self._func_template_contents = func_template_path.read_text() except KeyError: - logging.info("A function header template is not specified in the config file.") + logging.info( + "A function header template is not specified in the config file." + ) except FileNotFoundError: logging.info("The specified function header template file was not found.") @@ -423,32 +489,39 @@ class UncrustifyCheck(ICiBuildPlugin): # Verify Uncrustify is specified in the environment. if UncrustifyCheck.UNCRUSTIFY_PATH_ENV_KEY not in os.environ: raise UncrustifyAppEnvVarNotFoundException( - f"Uncrustify environment variable {UncrustifyCheck.UNCRUSTIFY_PATH_ENV_KEY} is not present.") + f"Uncrustify environment variable {UncrustifyCheck.UNCRUSTIFY_PATH_ENV_KEY} is not present." + ) - self._app_path = shutil.which('uncrustify', path=os.environ[UncrustifyCheck.UNCRUSTIFY_PATH_ENV_KEY]) + self._app_path = shutil.which( + "uncrustify", path=os.environ[UncrustifyCheck.UNCRUSTIFY_PATH_ENV_KEY] + ) if self._app_path is None: raise FileNotFoundError( - errno.ENOENT, os.strerror(errno.ENOENT), self._app_path) + errno.ENOENT, os.strerror(errno.ENOENT), self._app_path + ) self._app_path = os.path.normcase(os.path.normpath(self._app_path)) if not os.path.isfile(self._app_path): raise FileNotFoundError( - errno.ENOENT, os.strerror(errno.ENOENT), self._app_path) + errno.ENOENT, os.strerror(errno.ENOENT), self._app_path + ) # Verify Uncrustify is present at the expected path. return_buffer = StringIO() ret = RunCmd(self._app_path, "--version", outstream=return_buffer) - if (ret != 0): + if ret != 0: raise UncrustifyAppVersionErrorException( - f"Error occurred executing --version: {ret}.") + f"Error occurred executing --version: {ret}." + ) # Log Uncrustify version information. self._app_version = return_buffer.getvalue().strip() self._tc.LogStdOut(f"Uncrustify version: {self._app_version}") version_aggregator.GetVersionAggregator().ReportVersion( - "Uncrustify", self._app_version, version_aggregator.VersionTypes.INFO) + "Uncrustify", self._app_version, version_aggregator.VersionTypes.INFO + ) def _initialize_config_file_info(self) -> None: """ @@ -461,22 +534,30 @@ class UncrustifyCheck(ICiBuildPlugin): self._app_config_file = self._package_config["ConfigFilePath"].strip() self._app_config_file = os.path.normpath( - os.path.join(self._abs_package_path, self._app_config_file)) + os.path.join(self._abs_package_path, self._app_config_file) + ) if not os.path.isfile(self._app_config_file): raise FileNotFoundError( - errno.ENOENT, os.strerror(errno.ENOENT), self._app_config_file) + errno.ENOENT, os.strerror(errno.ENOENT), self._app_config_file + ) - def _initialize_environment_info(self, package_rel_path: str, edk2_path: Edk2Path, package_config: Dict[str, List[str]], tc: JunitReportTestCase) -> None: + def _initialize_environment_info( + self, + package_rel_path: str, + edk2_path: Edk2Path, + package_config: Dict[str, List[str]], + tc: JunitReportTestCase, + ) -> None: """ Initializes plugin environment information. """ - self._abs_package_path = edk2_path.GetAbsolutePathOnThisSystemFromEdk2RelativePath( - package_rel_path) + self._abs_package_path = ( + edk2_path.GetAbsolutePathOnThisSystemFromEdk2RelativePath(package_rel_path) + ) self._abs_workspace_path = edk2_path.WorkspacePath self._package_config = package_config - self._package_name = os.path.basename( - os.path.normpath(package_rel_path)) + self._package_name = os.path.basename(os.path.normpath(package_rel_path)) self._plugin_name = self.__class__.__name__ self._plugin_path = os.path.dirname(os.path.realpath(__file__)) self._rel_package_path = package_rel_path @@ -487,71 +568,93 @@ class UncrustifyCheck(ICiBuildPlugin): Forms the list of source files for Uncrustify to process. """ # Create a list of all the package relative file paths in the package to run against Uncrustify. - rel_file_paths_to_format = list( - UncrustifyCheck.STANDARD_PLUGIN_DEFINED_PATHS) + rel_file_paths_to_format = list(UncrustifyCheck.STANDARD_PLUGIN_DEFINED_PATHS) # Allow the ci.yaml to remove any of the pre-defined standard paths if "IgnoreStandardPaths" in self._package_config: for a in self._package_config["IgnoreStandardPaths"]: if a.strip() in rel_file_paths_to_format: self._tc.LogStdOut( - f"Ignoring standard path due to ci.yaml ignore: {a}") + f"Ignoring standard path due to ci.yaml ignore: {a}" + ) rel_file_paths_to_format.remove(a.strip()) else: - raise UncrustifyInvalidIgnoreStandardPathsException(f"Invalid IgnoreStandardPaths value: {a}") + raise UncrustifyInvalidIgnoreStandardPathsException( + f"Invalid IgnoreStandardPaths value: {a}" + ) # Allow the ci.yaml to specify additional include paths for this package if "AdditionalIncludePaths" in self._package_config: rel_file_paths_to_format.extend( - self._package_config["AdditionalIncludePaths"]) + self._package_config["AdditionalIncludePaths"] + ) self._abs_file_paths_to_format = [] for path in rel_file_paths_to_format: self._abs_file_paths_to_format.extend( - [str(path.resolve()) for path in pathlib.Path(self._abs_package_path).rglob(path)]) + [ + str(path.resolve()) + for path in pathlib.Path(self._abs_package_path).rglob(path) + ] + ) # Remove files ignore in the plugin configuration file - plugin_ignored_files = list(filter(self._get_files_ignored_in_config(), self._abs_file_paths_to_format)) + plugin_ignored_files = list( + filter(self._get_files_ignored_in_config(), self._abs_file_paths_to_format) + ) if plugin_ignored_files: logging.info( - f"{self._package_name} file count before plugin ignore file exclusion: {len(self._abs_file_paths_to_format)}") + f"{self._package_name} file count before plugin ignore file exclusion: {len(self._abs_file_paths_to_format)}" + ) for path in plugin_ignored_files: if path in self._abs_file_paths_to_format: logging.info(f" File ignored in plugin config file: {path}") self._abs_file_paths_to_format.remove(path) logging.info( - f"{self._package_name} file count after plugin ignore file exclusion: {len(self._abs_file_paths_to_format)}") + f"{self._package_name} file count after plugin ignore file exclusion: {len(self._abs_file_paths_to_format)}" + ) - if not "SkipGitExclusions" in self._package_config or not self._package_config["SkipGitExclusions"]: + if ( + not "SkipGitExclusions" in self._package_config + or not self._package_config["SkipGitExclusions"] + ): # Determine the git repository that contains this package. This is not necessarily # the edk2 repository if the package is in a different repo (e.g. PACKAGES_PATH). self._abs_git_repo_path = self._get_git_repo_path() # Remove files ignored by git logging.info( - f"{self._package_name} file count before git ignore file exclusion: {len(self._abs_file_paths_to_format)}") + f"{self._package_name} file count before git ignore file exclusion: {len(self._abs_file_paths_to_format)}" + ) ignored_paths = self._get_git_ignored_paths() self._abs_file_paths_to_format = list( - set(self._abs_file_paths_to_format).difference(ignored_paths)) + set(self._abs_file_paths_to_format).difference(ignored_paths) + ) logging.info( - f"{self._package_name} file count after git ignore file exclusion: {len(self._abs_file_paths_to_format)}") + f"{self._package_name} file count after git ignore file exclusion: {len(self._abs_file_paths_to_format)}" + ) # Remove files in submodules logging.info( - f"{self._package_name} file count before submodule exclusion: {len(self._abs_file_paths_to_format)}") + f"{self._package_name} file count before submodule exclusion: {len(self._abs_file_paths_to_format)}" + ) submodule_paths = tuple(self._get_git_submodule_paths()) for path in submodule_paths: logging.info(f" submodule path: {path}") self._abs_file_paths_to_format = [ - f for f in self._abs_file_paths_to_format if not f.startswith(submodule_paths)] + f + for f in self._abs_file_paths_to_format + if not f.startswith(submodule_paths) + ] logging.info( - f"{self._package_name} file count after submodule exclusion: {len(self._abs_file_paths_to_format)}") + f"{self._package_name} file count after submodule exclusion: {len(self._abs_file_paths_to_format)}" + ) # Sort the files for more consistent results self._abs_file_paths_to_format.sort() @@ -566,7 +669,10 @@ class UncrustifyCheck(ICiBuildPlugin): if "AuditOnly" in self._package_config and self._package_config["AuditOnly"]: self._audit_only_mode = True - if "OutputFileDiffs" in self._package_config and not self._package_config["OutputFileDiffs"]: + if ( + "OutputFileDiffs" in self._package_config + and not self._package_config["OutputFileDiffs"] + ): self._output_file_diffs = False def _log_uncrustify_app_info(self) -> None: @@ -575,10 +681,10 @@ class UncrustifyCheck(ICiBuildPlugin): """ self._tc.LogStdOut(f"Found Uncrustify at {self._app_path}") self._tc.LogStdOut(f"Uncrustify version: {self._app_version}") - self._tc.LogStdOut('\n') + self._tc.LogStdOut("\n") logging.info(f"Found Uncrustify at {self._app_path}") logging.info(f"Uncrustify version: {self._app_version}") - logging.info('\n') + logging.info("\n") def _process_uncrustify_results(self) -> None: """ @@ -586,55 +692,90 @@ class UncrustifyCheck(ICiBuildPlugin): Determines whether formatting errors are present and logs failures. """ - formatted_files = [str(path.resolve()) for path in pathlib.Path( - self._abs_package_path).rglob(f'*{UncrustifyCheck.FORMATTED_FILE_EXTENSION}')] + formatted_files = [ + str(path.resolve()) + for path in pathlib.Path(self._abs_package_path).rglob( + f"*{UncrustifyCheck.FORMATTED_FILE_EXTENSION}" + ) + ] self._formatted_file_error_count = len(formatted_files) if self._formatted_file_error_count > 0: - logging.error(f'Uncrustify found {self._formatted_file_error_count} files with formatting errors\n') - self._tc.LogStdError(f"Uncrustify found {self._formatted_file_error_count} files with formatting errors:\n") + logging.error( + f"Uncrustify found {self._formatted_file_error_count} files with formatting errors\n" + ) + self._tc.LogStdError( + f"Uncrustify found {self._formatted_file_error_count} files with formatting errors:\n" + ) logging.warning( "Visit the following instructions to learn " "more about uncrustify setup instructions and CI:" - "https://www.tianocore.org/tianocore-wiki.github.io/development/coding-standards/edk_ii_code_formatting.html\n") + "https://www.tianocore.org/tianocore-wiki.github.io/development/coding-standards/edk_ii_code_formatting.html\n" + ) if self._output_file_diffs: logging.info("Calculating file diffs. This might take a while...") for formatted_file in formatted_files: - pre_formatted_file = formatted_file[:-len(UncrustifyCheck.FORMATTED_FILE_EXTENSION)] + pre_formatted_file = formatted_file[ + : -len(UncrustifyCheck.FORMATTED_FILE_EXTENSION) + ] - logging.error(f"Formatting errors in {os.path.relpath(pre_formatted_file, self._abs_package_path)}") - self._tc.LogStdError(f"Formatting errors in {os.path.relpath(pre_formatted_file, self._abs_package_path)}\n") + logging.error( + f"Formatting errors in {os.path.relpath(pre_formatted_file, self._abs_package_path)}" + ) + self._tc.LogStdError( + f"Formatting errors in {os.path.relpath(pre_formatted_file, self._abs_package_path)}\n" + ) - if (self._output_file_diffs or - self._file_template_contents is not None or - self._func_template_contents is not None): + if ( + self._output_file_diffs + or self._file_template_contents is not None + or self._func_template_contents is not None + ): with open(formatted_file) as ff: formatted_file_text = ff.read() - if (self._file_template_contents is not None and - self._file_template_contents in formatted_file_text): - logging.info(f"File header is missing in {os.path.relpath(pre_formatted_file, self._abs_package_path)}") - self._tc.LogStdError(f"File header is missing in {os.path.relpath(pre_formatted_file, self._abs_package_path)}\n") + if ( + self._file_template_contents is not None + and self._file_template_contents in formatted_file_text + ): + logging.info( + f"File header is missing in {os.path.relpath(pre_formatted_file, self._abs_package_path)}" + ) + self._tc.LogStdError( + f"File header is missing in {os.path.relpath(pre_formatted_file, self._abs_package_path)}\n" + ) - if (self._func_template_contents is not None and - self._func_template_contents in formatted_file_text): - logging.info(f"A function header is missing in {os.path.relpath(pre_formatted_file, self._abs_package_path)}") - self._tc.LogStdError(f"A function header is missing in {os.path.relpath(pre_formatted_file, self._abs_package_path)}\n") + if ( + self._func_template_contents is not None + and self._func_template_contents in formatted_file_text + ): + logging.info( + f"A function header is missing in {os.path.relpath(pre_formatted_file, self._abs_package_path)}" + ) + self._tc.LogStdError( + f"A function header is missing in {os.path.relpath(pre_formatted_file, self._abs_package_path)}\n" + ) if self._output_file_diffs: with open(pre_formatted_file) as pf: pre_formatted_file_text = pf.read() - for line in difflib.unified_diff(pre_formatted_file_text.split('\n'), formatted_file_text.split('\n'), fromfile=pre_formatted_file, tofile=formatted_file, n=3): + for line in difflib.unified_diff( + pre_formatted_file_text.split("\n"), + formatted_file_text.split("\n"), + fromfile=pre_formatted_file, + tofile=formatted_file, + n=3, + ): logging.error(line) self._tc.LogStdError(line) - logging.error('\n') - self._tc.LogStdError('\n') + logging.error("\n") + self._tc.LogStdError("\n") def _remove_tree(self, dir_path: str, ignore_errors: bool = False) -> None: """ @@ -664,7 +805,9 @@ class UncrustifyCheck(ICiBuildPlugin): for _ in range(3): # retry up to 3 times try: - shutil.rmtree(dir_path, ignore_errors=ignore_errors, onerror=_remove_readonly) + shutil.rmtree( + dir_path, ignore_errors=ignore_errors, onerror=_remove_readonly + ) except OSError as err: logging.warning(f"Failed to fully remove {dir_path}: {err}") else: @@ -688,4 +831,5 @@ class UncrustifyCheck(ICiBuildPlugin): if self._app_exit_code != 0 and self._app_exit_code != 1: raise UncrustifyAppExecutionException( - f"Error {str(self._app_exit_code)} returned from Uncrustify:\n\n{str(self._app_output)}") + f"Error {str(self._app_exit_code)} returned from Uncrustify:\n\n{str(self._app_output)}" + ) From 909d1db4cb3ba6a3b2d8d239592f388423cbef11 Mon Sep 17 00:00:00 2001 From: Michael Kubacki <michael.kubacki@microsoft.com> Date: Fri, 31 Jul 2026 12:30:39 -0400 Subject: [PATCH 402/406] .pytool/Plugin/UncrustifyCheck: Update fork location in Readme.md Updates the fork repo to the TianoCore Uncrustify fork at: https://github.com/tianocore/uncrustify Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- .pytool/Plugin/UncrustifyCheck/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pytool/Plugin/UncrustifyCheck/Readme.md b/.pytool/Plugin/UncrustifyCheck/Readme.md index 43ff7ba5f8..708199c9ac 100644 --- a/.pytool/Plugin/UncrustifyCheck/Readme.md +++ b/.pytool/Plugin/UncrustifyCheck/Readme.md @@ -13,7 +13,7 @@ By default, an Uncrustify configuration file named "uncrustify.cfg" located in t used. The value can be overridden to a package-specific path with the `ConfigFilePath` configuration file option. * Uncrustify source code and documentation: https://github.com/uncrustify/uncrustify -* Project Mu Uncrustify fork source code and documentation: https://dev.azure.com/projectmu/Uncrustify +* TianoCore Uncrustify fork source code and documentation: https://github.com/tianocore/uncrustify ## Files Checked in a Package From c5aa7e7d94c0e6b3c0202e15dbf7a5c92dd6a01d Mon Sep 17 00:00:00 2001 From: Joey Vagedes <joey.vagedes@gmail.com> Date: Tue, 2 Jul 2024 10:27:02 -0700 Subject: [PATCH 403/406] BaseTools/Build: Output warning message for library class mismatch Performs a check that will verify that the library instance implements the library specified in the dsc by ensuring a LIBRARY_CLASS definition exists in the INF [Defines] section and the value matches the library it says it is implementing. As an example, from a platform dsc file: BaseBmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf BaseBmpSupportLib is supposed to be of library class BmpSupportLib, but the dsc defines it incorrectly, the warning message will be displayed during build. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> Co-authored-by: Poncho Figueroa <poncho.figueroa.esqueda@intel.com> --- .../Source/Python/AutoGen/AutoGenWorker.py | 1 + BaseTools/Source/Python/Common/GlobalData.py | 1 + .../Source/Python/Workspace/DscBuildData.py | 60 +++++++++++++++++-- .../Source/Python/Workspace/MetaFileParser.py | 20 +++++++ .../Source/Python/Workspace/MetaFileTable.py | 39 ++++++++++++ 5 files changed, 117 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/AutoGenWorker.py b/BaseTools/Source/Python/AutoGen/AutoGenWorker.py index 0ba2339bed..8adbab8120 100755 --- a/BaseTools/Source/Python/AutoGen/AutoGenWorker.py +++ b/BaseTools/Source/Python/AutoGen/AutoGenWorker.py @@ -218,6 +218,7 @@ class AutoGenWorkerInProcess(mp.Process): GlobalData.gEnableGenfdsMultiThread = self.data_pipe.Get("EnableGenfdsMultiThread") GlobalData.gPlatformFinalPcds = self.data_pipe.Get("gPlatformFinalPcds") GlobalData.file_lock = self.file_lock + GlobalData.gLogLibraryMismatch = False CommandTarget = self.data_pipe.Get("CommandTarget") pcd_from_build_option = [] for pcd_tuple in self.data_pipe.Get("BuildOptPcd"): diff --git a/BaseTools/Source/Python/Common/GlobalData.py b/BaseTools/Source/Python/Common/GlobalData.py index dd5316d283..3efcbaabd0 100755 --- a/BaseTools/Source/Python/Common/GlobalData.py +++ b/BaseTools/Source/Python/Common/GlobalData.py @@ -124,3 +124,4 @@ gSikpAutoGenCache = set() file_lock = None gStackCookieValues32 = [] gStackCookieValues64 = [] +gLogLibraryMismatch = True diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index bb9ba046ec..5e44911c63 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -43,6 +43,7 @@ import os import shutil import sys +LoggedLibraryWarnings = set() def _IsFieldValueAnArray (Value): Value = Value.strip() if Value.startswith(TAB_GUID) and Value.endswith(')'): @@ -767,9 +768,8 @@ class DscBuildData(PlatformBuildClassObject): # get module private library instance RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, ModuleId] for Record in RecordList: - LibraryClass = Record[0] - LibraryPath = PathClass(NormPath(Record[1], Macros), GlobalData.gWorkspace, Arch=self._Arch) - LineNo = Record[-1] + LibraryClass, LibraryInstance, Dummy, Dummy, Dummy, Dummy, RecordId, LineNo = Record + LibraryPath = PathClass(NormPath(LibraryInstance, Macros), GlobalData.gWorkspace, Arch=self._Arch) # check the file validation ErrorCode, ErrorInfo = LibraryPath.Validate('.inf') @@ -777,6 +777,16 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo, ExtraData=ErrorInfo) + # Validate that the Library instance implements the specified Library Class + if not self._ValidateLibraryClass(LibraryClass, LibraryPath, self._Arch): + # LineNo counts against the file the entry was written in, which + # is not this DSC when the entry came from an !include. + OriginFile = self._RawData.GetOriginFile(RecordId) + if self._ShouldLogLibrary(OriginFile, LineNo): + EdkLogger.warn("build", + f"{str(LibraryPath)} does not support LIBRARY_CLASS {LibraryClass}", + File=OriginFile, Line=LineNo) + if LibraryClass == '' or LibraryClass == 'NULL': self._NullLibraryNumber += 1 LibraryClass = 'NULL%d' % self._NullLibraryNumber @@ -867,19 +877,30 @@ class DscBuildData(PlatformBuildClassObject): RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, -1] Macros = self._Macros for Record in RecordList: - LibraryClass, LibraryInstance, Dummy, Arch, ModuleType, Dummy, Dummy, LineNo = Record + LibraryClass, LibraryInstance, Dummy, Arch, ModuleType, Dummy, RecordId, LineNo = Record if LibraryClass == '' or LibraryClass == 'NULL': self._NullLibraryNumber += 1 LibraryClass = 'NULL%d' % self._NullLibraryNumber EdkLogger.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch, LibraryInstance, LibraryClass)) LibraryClassSet.add(LibraryClass) LibraryInstance = PathClass(NormPath(LibraryInstance, Macros), GlobalData.gWorkspace, Arch=self._Arch) + # check the file validation ErrorCode, ErrorInfo = LibraryInstance.Validate('.inf') if ErrorCode != 0: EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo, ExtraData=ErrorInfo) + # Validate that the Library instance implements the specified Library Class + if not self._ValidateLibraryClass(LibraryClass, LibraryInstance, Arch): + # LineNo counts against the file the entry was written in, which + # is not this DSC when the entry came from an !include. + OriginFile = self._RawData.GetOriginFile(RecordId) + if self._ShouldLogLibrary(OriginFile, LineNo): + EdkLogger.warn("build", + f"{str(LibraryInstance)} does not support LIBRARY_CLASS {LibraryClass}", + File=OriginFile, Line=LineNo) + if ModuleType != TAB_COMMON and ModuleType not in SUP_MODULE_LIST: EdkLogger.error('build', OPTION_UNKNOWN, "Unknown module type [%s]" % ModuleType, File=self.MetaFile, ExtraData=LibraryInstance, Line=LineNo) @@ -1139,6 +1160,37 @@ class DscBuildData(PlatformBuildClassObject): for item in delete_assign: GlobalData.BuildOptionPcd.remove(item) + def _ValidateLibraryClass(self, LibraryClass: str, LibraryInstance: PathClass, Arch: str) -> bool: + # + # Forced library instances have no class to match against. They are spelled + # 'NULL' (or left empty) in the DSC and renamed to 'NULL<n>' while parsing, so + # both spellings can reach here depending on the caller. + # + if LibraryClass in ('', 'NULL'): + return True + if LibraryClass.startswith('NULL') and LibraryClass[4:].isdigit(): + return True + + ParsedLibraryInfo = self._Bdb[LibraryInstance, Arch, self._Target, self._Toolchain] + + for LibraryClassObject in ParsedLibraryInfo.LibraryClass: + if LibraryClassObject.LibraryClass == LibraryClass: + return True + return False + + def _ShouldLogLibrary(self, OriginFile, LineNo) -> bool: + if not GlobalData.gLogLibraryMismatch: + return False + + # Key on the file as well as the line, otherwise entries that share a line + # number across different DSC files silently suppress each other. + Key = (str(OriginFile), LineNo) + if Key in LoggedLibraryWarnings: + return False + + LoggedLibraryWarnings.add(Key) + return True + @staticmethod def HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, PcdValue, PcdDatumType, GuidDict, FieldName=''): if FieldName: diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index 1880148a6d..862f4fc436 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -1728,6 +1728,26 @@ class DscParser(MetaFileParser): self._ValueList = [ReplaceMacro(Value, self._Macros, RaiseError=False) for Value in self._ValueList] + ## Find the file a record's line number refers to + # + # !include'd records are spliced into the including file's record list, so + # a record's line number is not necessarily an offset into self.MetaFile. + # Callers reporting a line number to the user should report this path with + # it rather than assuming the top-level DSC. + # + # @param RecordId: ID of the record to locate + # + # @retval: Path of the file the record was parsed from + # + def GetOriginFile(self, RecordId): + for Table in (self._Table, self._RawTable): + if Table is None: + continue + OriginFile = Table.GetOriginFile(RecordId) + if OriginFile is not None: + return OriginFile + return self.MetaFile + def DisableOverrideComponent(self,module_id): for ori_id in self._IdMapping: if self._IdMapping[ori_id] == module_id: diff --git a/BaseTools/Source/Python/Workspace/MetaFileTable.py b/BaseTools/Source/Python/Workspace/MetaFileTable.py index 7ff5f2011d..3b9060b465 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileTable.py +++ b/BaseTools/Source/Python/Workspace/MetaFileTable.py @@ -23,6 +23,11 @@ class MetaFileTable(): _ID_STEP_ = 1 _ID_MAX_ = 99999999 + # Column offsets into the rows this class appends to DB.TblFile. Keep in + # sync with the list built in __init__. + _FILE_PATH_ = 3 + _FILE_FROM_ITEM_ = 6 + ## Constructor def __init__(self, DB, MetaFile, FileType, Temporary, FromItem=None): self.MetaFile = MetaFile @@ -30,6 +35,7 @@ class MetaFileTable(): self.DB = DB self.CurrentContent = [] + # Columns here are addressed by the _FILE_*_ offsets above. DB.TblFile.append([MetaFile.Name, MetaFile.Ext, MetaFile.Dir, @@ -297,6 +303,10 @@ class PlatformTable(MetaFileTable): # used as table end flag, in case the changes to database is not committed to db file _DUMMY_ = [-1, -1, '====', '====', '====', '====', '====','====', -1, -1, -1, -1, -1, -1, -1] + # Column offsets into the rows built by Insert(), matching _COLUMN_ above. + _ID_ = 0 + _FROM_ITEM_ = 9 + ## Constructor def __init__(self, Cursor, MetaFile, Temporary, FromItem=0): MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_DSC, Temporary, FromItem) @@ -386,6 +396,35 @@ class PlatformTable(MetaFileTable): if item[0] == comp_id or item[8] == comp_id: item[-1] = -1 + ## Find the file a record's line number refers to + # + # Records brought in by !include are spliced into the including file's + # record list, so this table's MetaFile is not necessarily the file the + # record's StartLine counts against. Such a record keeps the ID of the + # !include statement that pulled it in as its FromItem, and the table + # built for the included file stored that same ID, so FromItem maps back + # to the included file's path. + # + # @param RecordId: ID of the record to locate + # + # @retval: Path of the file the record was parsed from, or None if + # this table holds no such record + # + def GetOriginFile(self, RecordId): + for Record in self.CurrentContent: + if Record[self._ID_] != RecordId: + continue + FromItem = Record[self._FROM_ITEM_] + # A record parsed straight out of this file has no originating + # !include statement to resolve. + if not FromItem or FromItem < 0: + return self.MetaFile + for File in self.DB.TblFile: + if File[self._FILE_FROM_ITEM_] == FromItem: + return File[self._FILE_PATH_] + return self.MetaFile + return None + ## Factory class to produce different storage for different type of meta-file class MetaFileStorage(object): _FILE_TABLE_ = { From 816b35fe52388564498c5885ced765ea2d5394a5 Mon Sep 17 00:00:00 2001 From: Aaron Pop <aaronpop@microsoft.com> Date: Mon, 10 Aug 2026 12:08:52 -0700 Subject: [PATCH 404/406] MdeModulePkg/UefiHiiLib: Fix regression from 12828 12828 introduced an ASSERT in HiiGetBrowserData() that fires when InternalHiiBrowserCallback() returns NULL. This is a valid return value indicating the browser has no data for the requested variable, and callers already handle this by checking the FALSE return value. The ASSERT is incorrect because it triggers on a non-error path, causing a crash when the browser callback legitimately returns no data. Remove the unnecessary ASSERT while keeping the existing FALSE return so callers continue to handle this case gracefully. Cc: Qihang Gao <gaoqihang@loongson.cn> Signed-off-by: Aaron Pop <aaronpop@microsoft.com> --- MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 1 - 1 file changed, 1 deletion(-) diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index 476b69eec3..18796aba72 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -2927,7 +2927,6 @@ HiiGetBrowserData ( // ResultsData = InternalHiiBrowserCallback (VariableGuid, VariableName, NULL); if (ResultsData == NULL) { - ASSERT (ResultsData != NULL); return FALSE; } From 86ecae29c69ee6b4fd471ff395989c358bbec14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corvin=20K=C3=B6hne?= <corvink@FreeBSD.org> Date: Fri, 7 Aug 2026 07:56:32 +0200 Subject: [PATCH 405/406] Maintainers.txt: use my correct GitHub handle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I've missed that this handle should be my GitHub handle. Correct it to point contributors to the right GitHub account. Fixes: d795fb571b9b ("Maintainer.txt: add myself as reviewer for bhyve's OvmfPkg") Signed-off-by: Corvin Köhne <corvink@FreeBSD.org> --- Maintainers.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maintainers.txt b/Maintainers.txt index 61b1a08d3c..753ac10ca3 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -514,7 +514,7 @@ F: OvmfPkg/Library/PlatformBootManagerLibBhyve/ F: OvmfPkg/Library/ResetSystemLib/BaseResetShutdownBhyve.c F: OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf R: Rebecca Cran <rebecca@bsdio.com> [bexcran] -R: Corvin Köhne <corvink@freebsd.org> [corvink] +R: Corvin Köhne <corvink@freebsd.org> [ckoehne] OvmfPkg: cloudhv-related modules F: OvmfPkg/CloudHv/ From 2970e5699ba6267f3384ffab20f96647578aebc8 Mon Sep 17 00:00:00 2001 From: "Johnny.Fan" <Johnny.Fan@cixtech.com> Date: Tue, 7 Jul 2026 17:11:34 +0800 Subject: [PATCH 406/406] EmbeddedPkg/AcpiLib: Fix memory corruption in AcpiAmlObjectUpdateInteger The original implementation of AcpiAmlObjectUpdateInteger had a critical bug when updating integer objects that were encoded with AML_ZERO_OP(0x00) or AML_ONE_OP(0x01), which are 1-byte optimized encodings. When the caller tried to update such an object to a value other than 0 or 1, the code would: 1. Overwrite the opcode byte with the new value's LSB 2. This changed the opcode itself, e.g. 0x0B becomes AML_WORD_PREFIX 3. Subsequent AML bytes (name segments of following objects) get misinterpreted as integer data 4. Result: silent AML structure is silently corrupted, causing the OS to fail parsing ACPI tables and eventually crash. The fix: 1. Only allow 0 -> 0 or 1 updates using the original 1-byte encoding 2. For any other value, explicitly fail with a diagnostic 3. Provide clear debug instructions on how to fix the ASL source Reviewed-by: jie.fu <jie.fu@cixtech.com> Signed-off-by: Johnny.Fan <Johnny.Fan@cixtech.com> --- EmbeddedPkg/Library/AcpiLib/AcpiLib.c | 58 +++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/EmbeddedPkg/Library/AcpiLib/AcpiLib.c b/EmbeddedPkg/Library/AcpiLib/AcpiLib.c index 00bcddefd1..7c23d36582 100644 --- a/EmbeddedPkg/Library/AcpiLib/AcpiLib.c +++ b/EmbeddedPkg/Library/AcpiLib/AcpiLib.c @@ -291,7 +291,7 @@ AcpiLocateTableBySignature ( /** This function updates the integer value of an AML Object. - @param AcpiTableSdtProtocol Pointer to ACPI SDT protocol. + @param AcpiSdtProtocol Pointer to ACPI SDT protocol. @param TableHandle Points to the table representing the starting point for the object path search. @param AsciiObjectPath Pointer to the ACPI path of the object being updated. @@ -301,6 +301,19 @@ AcpiLocateTableBySignature ( @return EFI_INVALID_PARAMETER At least one of parameters is invalid or the data type of the ACPI object is not an integer value. @retval EFI_NOT_FOUND The object is not found with the given path. + @retval EFI_UNSUPPORTED The object uses ZeroOp/OneOp encoding and cannot be + safely updated to a value other than 0 or 1. + + @attention IMPORTANT LIMITATION: + If the original ASL code uses Name (XXX, 0) or Name (XXX, 1), + the iASL compiler optimizes it to 1-byte ZeroOp/OneOp encoding. + This function CANNOT safely update such objects to values other than 0 or 1, + because there is no space to expand to BytePrefix encoding (2 bytes). + + WORKAROUND: In ASL source, use an initial value >= 2, e.g.: + Name (_STA, 0xF) // Forces BytePrefix encoding, reserves 2 bytes + instead of: + Name (_STA, 0x0) // Optimized to ZeroOp, only 1 byte! **/ EFI_STATUS @@ -357,8 +370,47 @@ AcpiAmlObjectUpdateInteger ( ASSERT (Buffer != NULL); if ((Buffer[0] == AML_ZERO_OP) || (Buffer[0] == AML_ONE_OP)) { - Status = AcpiSdtProtocol->SetOption (DataHandle, 0, (VOID *)&Value, sizeof (UINT8)); - ASSERT_EFI_ERROR (Status); + // + // ZeroOp (0x00) and OneOp (0x01) are optimized 1-byte encodings where + // the value is implicit in the opcode itself. + // + // Only values 0 and 1 can be updated safely because they can be represented + // using the same 1-byte encoding. + // + // Values >= 2 require BytePrefix encoding (opcode + data), which + // needs 2 bytes total. Since the ACPI table is byte-exact encoding with + // no reserved space, we CANNOT expand from 1 byte to 2 bytes. + // + // Attempting to do so (as the original code did) would silently + // corrupt the AML byte stream, causing subsequent ACPI name segments + // to be misinterpreted as data bytes, ultimately leading to kernel + // crashes when the OS parses the corrupted ACPI table. + // + if ((Value == 0) || (Value == 1)) { + UINT8 Opcode; + + Opcode = (Value == 0) ? AML_ZERO_OP : AML_ONE_OP; + Status = AcpiSdtProtocol->SetOption ( + DataHandle, + 0, + &Opcode, + sizeof (UINT8) + ); + ASSERT_EFI_ERROR (Status); + } else { + DEBUG (( + DEBUG_ERROR, + "ACPI: ERROR: Cannot update object '%a' from ZeroOp/OneOp to 0x%lx\n" + "ACPI: No space to expand to BytePrefix encoding.\n" + "ACPI: FIX: In ASL source, use an initial value >= 2 to\n" + "ACPI: force BytePrefix, e.g. Name (_STA, 0xF)\n", + AsciiObjectPath, + Value + )); + ASSERT (FALSE); + Status = EFI_UNSUPPORTED; + goto Exit; + } } else { // // Check the size of data object