Skip to content

Conversation

@Flickdm
Copy link
Member

@Flickdm Flickdm commented Nov 14, 2025

Description

This pull request adds support for forwarding cryptographic library calls to the new OneCrypto protocol across DXE, SMM, and Standalone MM phases, enabling modular and version-aware cryptographic provider integration. It introduces new protocol GUIDs, implements library constructors for protocol lookup, and updates build configuration to support these changes. Additionally, it provides documentation and abstracts for the new libraries, and adds a disabled external binary dependency descriptor.

OneCrypto Protocol Integration:

  • Introduced new protocol GUIDs for OneCrypto Private, MM, and DXE protocols in CryptoPkg.dec to support phase-specific cryptographic operations.
  • Implemented DXE, SMM, and Standalone MM library modules (DxeCryptLib.c, SmmCryptLib.c, StandaloneMmCryptLib.c) that locate and expose the OneCrypto protocol for cryptographic services, with corresponding INF build files for each phase. [1] [2] [3] [4] [5] [6]

Documentation and Descriptions:

---
config:
  layout: elk
---
classDiagram

    namespace Protocol {
        class OneCrypto:::highlight {
            <<Protocol Interface>>
            UINT16 Major;
            UINT16 Minor;
            // v1.0 ------------------------------------------
            ONE_CRYPTO_PROVIDED_FUNC ONE_CRYPTO_PROVIDED_FUNC;
            // ...
        }
    }

    namespace Library {
        class BaseCryptLib:::highlight {
        }

        class TlsLib:::library {

        }

        class HashApiLib:::library {

        }
    }

    namespace LibraryInstance {
        class BaseCryptOnOneCrypto:::highlight  {
            <<Library Interface>>
            EFI_STATUS CryptoFunc(..)
        }
    }

    namespace Driver {
        class OneCryptoBinSupvMm:::driver {
            <<Driver>>
            Phase Agnostic Crypto Driver
            Shared across Phases

            Crypto Entry(..) // phase agnostic code
            SupvMm Entry(..) // stub entry
        }

        class OneCryptoLoaderSupvMm:::driver {
            <<Driver>>
        }

        class OneCryptoLoaderDxe:::driver {
            <<Driver>>
        }
    }

    namespace GenericModules {
        class GenericDriver:::module {
            <<Driver>>
            Any driver that needs crypto
        }

        class GenericLibrary:::module {
            <<Library Interface>>
            Any library that needs crypto
        }

    }

    OneCryptoLoaderSupvMm --> OneCryptoBinSupvMm : Loads Phase Agnostic Code
    OneCryptoLoaderDxe --> OneCryptoBinSupvMm : Loads Phase Agnostic Code

    OneCryptoBinSupvMm ..> OneCryptoLoaderSupvMm : Provides Crypto
    OneCryptoBinSupvMm ..> OneCryptoLoaderDxe : Provides Crypto

    OneCryptoLoaderSupvMm ..|> OneCrypto : Publishes
    OneCryptoLoaderDxe ..|> OneCrypto : Publishes

    BaseCryptOnOneCrypto ..|> OneCrypto : Locates

    BaseCryptOnOneCrypto <.. BaseCryptLib : Backed By
    BaseCryptOnOneCrypto <.. TlsLib : Backed By

    TlsLib ..> BaseCryptLib : Uses
    HashApiLib ..> BaseCryptLib : Uses
    
    GenericLibrary ..> BaseCryptLib : Uses
    GenericDriver ..> BaseCryptLib : Uses
    GenericLibrary ..> TlsLib : Uses
    GenericDriver ..> HashApiLib : Uses

    classDef driver fill:#187286,stroke:#333,stroke-width:2px
    classDef protocol fill:#d63230,stroke:#333,stroke-width:2px
    classDef library fill:#1c77c3,stroke:#333,stroke-width:2px
    classDef module fill:#ff8c00,stroke:#333,stroke-width:2px
    classDef highlight fill:#69995d,stroke:#333,stroke-width:2px
Loading

Specifically this PR is addressing the following (sage green in the chart):

Build and Configuration Updates:

  • Removed inclusion of test-specific PCDs from the main DSC configuration to streamline production builds.
  • Added a disabled external dependency descriptor for the OneCrypto binary driver in OneCrypto_ext_dep.json.disabled.

BaseCryptLib API Enhancements:

  • Added a new API to retrieve cryptographic provider version information in BaseCryptLib.h, improving diagnostics and compatibility checks.

Code Organization and Comments:

  • Improved comments and documentation in CryptoPkg.dec regarding deprecated usage and auto-generated sections for cryptographic provider configuration.

BaseCryptOnOneCrypto

  • Library implementation and safe calling usage of the phase agnostic code.

OneCryptoProtocol

  • Protocol implementation and strict guidance.
  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

QemuQ35

Integration Instructions

N/A

@Flickdm Flickdm force-pushed the dev/onecrypto-rebase branch from ebff900 to d50126f Compare November 14, 2025 23:15
@codecov-commenter
Copy link

codecov-commenter commented Nov 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release/202502@f6015c4). Learn more about missing BASE report.

Additional details and impacted files
@@                Coverage Diff                @@
##             release/202502    #1570   +/-   ##
=================================================
  Coverage                  ?    0.66%           
=================================================
  Files                     ?      939           
  Lines                     ?   329534           
  Branches                  ?     2647           
=================================================
  Hits                      ?     2195           
  Misses                    ?   327161           
  Partials                  ?      178           
Flag Coverage Δ
MdeModulePkg 0.21% <ø> (?)
NetworkPkg 0.55% <ø> (?)
UefiCpuPkg 4.92% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Flickdm Flickdm force-pushed the dev/onecrypto-rebase branch 3 times, most recently from 5193c91 to 97a90e5 Compare November 18, 2025 22:53
@Flickdm Flickdm changed the title BaseCryptOnOneCrypto BaseCryptOnOneCrypto Support Nov 18, 2025
@Flickdm Flickdm marked this pull request as ready for review November 18, 2025 23:23
@Flickdm
Copy link
Member Author

Flickdm commented Nov 18, 2025

Working on fixing the failing gates - uncrustify is failing.

@Flickdm Flickdm force-pushed the dev/onecrypto-rebase branch 3 times, most recently from faed009 to acbc9d3 Compare November 24, 2025 20:46
@Flickdm Flickdm force-pushed the dev/onecrypto-rebase branch from 44569c4 to cc0e40d Compare November 24, 2025 23:54
@Flickdm Flickdm requested a review from makubacki November 25, 2025 21:07
…ffixes

Remove _EX suffix from crypto macro names in unit tests to align with
standardized naming conventions. This simplifies the API and makes it
consistent across all cryptographic functions.

Changes:
- Remove _EX from HMAC, hash, and cipher function calls
- Update test variable naming for clarity
- Delete obsolete Crypto.pcd.ALL.inc.dsc file
- Update TestBaseCryptLibHost.inf to reflect current test structure
Add comprehensive OneCrypto.h protocol header defining a unified interface
for cryptographic operations across all firmware phases (DXE, SMM, MM).

Features:
- 171+ cryptographic function typedefs organized into 14 functional groups:
  * HMAC (SHA256, SHA384)
  * Big Number operations
  * AES operations
  * Hash functions (MD5, SHA1, SHA256, SHA384, SHA512, SM3)
  * Key derivation (HKDF)
  * Asymmetric crypto (RSA, EC, DH)
  * PKCS operations
  * X.509 certificate handling
  * TLS primitives
  * Random number generation
  * Timestamp verification
  * Provider version info
- Complete doxygen documentation with @SInCE version tags
- Protocol versioning support (Major.Minor)
- Support for Asn1GetTag and X509CompareDateTime
- Buffer-based GetCryptoProviderVersionText API

The protocol enables a single cryptographic binary to serve all firmware
phases, reducing code duplication and improving security consistency.
@Flickdm Flickdm force-pushed the dev/onecrypto-rebase branch from b53141d to e2c6d15 Compare December 1, 2025 22:48
@os-d
Copy link
Contributor

os-d commented Dec 2, 2025

A couple notes on the mermaid diagram for clarity:

image

I would label this as the library class/interface that is used. In the current diagram it could be seen that BaseCryptLib is different than BaseCryptLibOnOneCrypto, when it is not, the latter implements the former.

Just want to make sure this is correct:

image

HashApiLib doesn't interact with BaseCryptLib at all?

Comment on lines +2 to +3
Implements the BaseCryptLib and TlsLib using the services of the OneCrypto
Protocol/PPI.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Implements the BaseCryptLib and TlsLib using the services of the OneCrypto
Protocol/PPI.
Implements the backend crypto services of BaseCryptLib and TlsLib using the OneCrypto
Protocol.

Add GetCryptoProviderVersionText function declaration to BaseCryptLib.h
with buffer-based API design.

Changes:
- Add GetCryptoProviderVersionText function with buffer/size parameters
- Function supports query mode (Buffer=NULL returns required size)
- Returns EFI_SUCCESS, EFI_BUFFER_TOO_SMALL, or EFI_INVALID_PARAMETER
- Replaces previous pointer-returning API for better safety
- Enables callers to control memory allocation

This API allows cryptographic provider version information (e.g., OpenSSL
version) to be retrieved safely without exposing internal string pointers.
Add library implementations that wrap the OneCrypto protocol for use
across DXE, SMM, and Standalone MM firmware phases.

New libraries:
- DxeCryptLib: DXE phase wrapper (locates gOneCryptoDxeProtocolGuid)
- SmmCryptLib: SMM phase wrapper (locates gOneCryptoSmmProtocolGuid)
- StandaloneMmCryptLib: Standalone MM wrapper (locates gOneCryptoMmProtocolGuid)

All libraries share common implementation:
- OneCryptoLib.c (6520 lines): Complete BaseCryptLib API wrappers
  * All 171+ functions call through protocol using CALL_CRYPTO_SERVICE macro
  * Version checking ensures protocol supports requested operations
  * Automatic fallback to 'not available' for unsupported operations
  * Includes Asn1GetTag and X509CompareDateTime support
  * Buffer-based GetCryptoProviderVersionText implementation

- Phase-specific constructors locate the appropriate protocol variant
- Unified GetCryptoServices() API returns protocol pointer
- Complete error handling with DEBUG output

Benefits:
- Single protocol implementation serves all phases
- Consistent crypto behavior across firmware
- Reduced code duplication
- Simplified maintenance and updates
- Version-aware protocol consumption
- Add gOneCryptoSmmProtocolGuid to CryptoPkg.dec [Protocols] section
- Add GuidCheck exception for OneCryptoBinStandaloneMm and OneCryptoBinSupvMm
  which intentionally share the same GUID for loader identification
Moved the GetCryptoServices() function definition to a new private
header file OneCryptoLib.h to improve code organization. Updated all
consumers in DxeCryptLib, OneCryptoLib, SmmCryptLib, and
StandaloneMmCryptLib to include the new header.
Removes the Dxe and Mm specific OneCrypto protocol GUIDs and replaces
them with a single OneCrypto protocol GUID. This simplifies the protocol
usage and reduces redundancy.
Fix compiler warning C4319 where bitwise NOT was being applied to a
UINT32 before zero-extending to PHYSICAL_ADDRESS. Move the UINTN cast
to wrap the entire expression before the bitwise NOT operation to
ensure proper width handling across 32-bit and 64-bit platforms.

This resolves the "zero extending 'UINT32' to 'PHYSICAL_ADDRESS' of
greater size" warning when compiling for IA32 with VS2022.
@Flickdm Flickdm force-pushed the dev/onecrypto-rebase branch from b9fdcac to 4fe2038 Compare December 3, 2025 19:08
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convert this to an extern and drop the function

PI_SPECIFICATION_VERSION = 0x00010032
MODULE_TYPE = MM_STANDALONE
LIBRARY_CLASS = BaseCryptLib | MM_STANDALONE
LIBRARY_CLASS = TlsLib | MM_STANDALONE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LIBRARY_CLASS = TlsLib | MM_STANDALONE
LIBRARY_CLASS = TlsLib | MM_STANDALONE

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add document to top level level of CryptoPkg describing what the options are for backing and write out that if a function is added to BaseCryptLib.h that all providers (specifically OneCrypto) needs to be updated to create the WYSIWYG contract

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants